summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAleks Kissinger <aleks0@gmail.com>2018-08-21 16:49:59 +0200
committerAleks Kissinger <aleks0@gmail.com>2018-08-21 16:49:59 +0200
commitea4fffa590b1bf7cb936cf6e5ab4e8090dc38910 (patch)
treeb6969c0496b0d463396817739e568bcccd45c3c7 /src
parent20e06dd885819f7b16711ac5359fcdcfb8d26c86 (diff)
style categories
Diffstat (limited to 'src')
-rw-r--r--src/data/graphelementdata.cpp91
-rw-r--r--src/data/graphelementdata.h36
-rw-r--r--src/data/graphelementproperty.cpp30
-rw-r--r--src/data/graphelementproperty.h15
-rw-r--r--src/data/style.cpp5
-rw-r--r--src/data/style.h1
-rw-r--r--src/data/tikzstyles.cpp89
-rw-r--r--src/data/tikzstyles.h8
-rw-r--r--src/gui/styleeditor.cpp226
-rw-r--r--src/gui/styleeditor.h18
-rw-r--r--src/gui/stylepalette.cpp14
-rw-r--r--src/gui/stylepalette.h1
-rw-r--r--src/gui/stylepalette.ui17
13 files changed, 409 insertions, 142 deletions
diff --git a/src/data/graphelementdata.cpp b/src/data/graphelementdata.cpp
index 85ae4cd..66ef16f 100644
--- a/src/data/graphelementdata.cpp
+++ b/src/data/graphelementdata.cpp
@@ -43,8 +43,7 @@ GraphElementData *GraphElementData::copy()
void GraphElementData::setProperty(QString key, QString value)
{
- GraphElementProperty m(key, true);
- int i = _properties.indexOf(m);
+ int i = indexOfKey(key);
if (i != -1) {
_properties[i].setValue(value);
} else {
@@ -55,15 +54,17 @@ void GraphElementData::setProperty(QString key, QString value)
void GraphElementData::unsetProperty(QString key)
{
- GraphElementProperty m(key, true);
- int i = _properties.indexOf(m);
+ int i = indexOfKey(key);
if (i != -1)
_properties.remove(i);
}
void GraphElementData::add(GraphElementProperty p)
{
+ int i = _properties.size();
+ beginInsertRows(QModelIndex(), i, i);
_properties << p;
+ endInsertRows();
}
void GraphElementData::operator <<(GraphElementProperty p)
@@ -73,24 +74,21 @@ void GraphElementData::operator <<(GraphElementProperty p)
void GraphElementData::setAtom(QString atom)
{
- GraphElementProperty a(atom);
- int i = _properties.indexOf(a);
+ int i = indexOfKey(atom);
if (i == -1)
- _properties << a;
+ _properties << GraphElementProperty(atom);
}
void GraphElementData::unsetAtom(QString atom)
{
- GraphElementProperty a(atom);
- int i = _properties.indexOf(a);
+ int i = indexOfKey(atom);
if (i != -1)
_properties.remove(i);
}
QString GraphElementData::property(QString key)
{
- GraphElementProperty m(key, true);
- int i = _properties.indexOf(m);
+ int i = indexOfKey(key);
if (i != -1) {
return _properties[i].value();
} else {
@@ -100,22 +98,29 @@ QString GraphElementData::property(QString key)
bool GraphElementData::atom(QString atom)
{
- GraphElementProperty a(atom);
- return (_properties.indexOf(a) != -1);
+ return (indexOfKey(atom) != -1);
+}
+
+int GraphElementData::indexOfKey(QString key)
+{
+ for (int i = 0; i < _properties.size(); ++i) {
+ QString key1 = _properties[i].key();
+ if (key1 == key) return i;
+ }
+ return -1;
}
QVariant GraphElementData::data(const QModelIndex &index, int role) const
{
- if (role != Qt::DisplayRole && role != Qt::EditRole)
+ if (role == Qt::DisplayRole || role == Qt::EditRole) {
+ if (index.row() >= 0 && index.row() < _properties.length()) {
+ const GraphElementProperty &p = _properties[index.row()];
+ QString s = (index.column() == 0) ? p.key() : p.value();
+ return QVariant(s);
+ }
+ } else {
return QVariant();
-
- if (index.row() >= 0 && index.row() < _properties.length()) {
- const GraphElementProperty &p = _properties[index.row()];
- QString s = (index.column() == 0) ? p.key() : p.value();
- return QVariant(s);
}
-
- return QVariant();
}
QVariant GraphElementData::headerData(int section, Qt::Orientation orientation, int role) const
@@ -135,9 +140,7 @@ QModelIndex GraphElementData::index(int row, int column, const QModelIndex &pare
QModelIndex GraphElementData::parent(const QModelIndex &index) const
{
- //GraphElementProperty *p = static_cast<GraphElementProperty*>(index.internalPointer());
- //if (p == root) return QModelIndex();
- //else return createIndex(0,0,static_cast<void*>(root));
+ // there is no nesting, so always return an invalid index
return QModelIndex();
}
@@ -157,23 +160,37 @@ int GraphElementData::columnCount(const QModelIndex &) const
Qt::ItemFlags GraphElementData::flags(const QModelIndex &index) const
{
- return QAbstractItemModel::flags(index) | Qt::ItemIsEditable;
+ if (index.row() >= 0 && index.row() < _properties.length()) {
+ if (index.column() == 0 ||
+ (!_properties[index.row()].atom() && index.column() == 1))
+ {
+ return QAbstractItemModel::flags(index) | Qt::ItemIsEditable;
+ }
+ }
+ return QAbstractItemModel::flags(index);
}
-//bool GraphElementData::setData(const QModelIndex &index, const QVariant &value, int role)
-//{
-
-//}
-
-//bool GraphElementData::insertRows(int position, int rows, const QModelIndex &parent)
-//{
-
-//}
+bool GraphElementData::setData(const QModelIndex &index, const QVariant &value, int role)
+{
+ bool success = false;
+ if (index.row() >= 0 && index.row() < _properties.length()) {
+ if (index.column() == 0) {
+ _properties[index.row()].setKey(value.toString());
+ success = true;
+ } else if (index.column() == 1 && !_properties[index.row()].atom()) {
+ _properties[index.row()].setValue(value.toString());
+ success = true;
+ }
+ }
-//bool GraphElementData::removeRows(int position, int rows, const QModelIndex &parent)
-//{
+ if (success) {
+ QVector<int> roles;
+ roles << role;
+ emit dataChanged(index, index, roles);
+ }
-//}
+ return success;
+}
QString GraphElementData::tikz() {
if (_properties.length() == 0) return "";
diff --git a/src/data/graphelementdata.h b/src/data/graphelementdata.h
index 2b27384..e57cf49 100644
--- a/src/data/graphelementdata.h
+++ b/src/data/graphelementdata.h
@@ -42,33 +42,23 @@ public:
void unsetAtom(QString atom);
QString property(QString key);
bool atom(QString atom);
+ int indexOfKey(QString key);
- QVariant data(const QModelIndex &index, int role) const Q_DECL_OVERRIDE;
+ QVariant data(const QModelIndex &index, int role) const override;
QVariant headerData(int section, Qt::Orientation orientation,
- int role = Qt::DisplayRole) const Q_DECL_OVERRIDE;
+ int role = Qt::DisplayRole) const override;
QModelIndex index(int row, int column,
- const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE;
- QModelIndex parent(const QModelIndex &index) const Q_DECL_OVERRIDE;
-
- int rowCount(const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE;
- int columnCount(const QModelIndex &) const Q_DECL_OVERRIDE;
-
- Qt::ItemFlags flags(const QModelIndex &index) const Q_DECL_OVERRIDE;
-
-// bool setData(const QModelIndex &index, const QVariant &value,
-// int role = Qt::EditRole) Q_DECL_OVERRIDE;
-// bool setHeaderData(int section, Qt::Orientation orientation,
-// const QVariant &value, int role = Qt::EditRole) Q_DECL_OVERRIDE;
-
-// bool insertColumns(int position, int columns,
-// const QModelIndex &parent = QModelIndex()) Q_DECL_OVERRIDE;
-// bool removeColumns(int position, int columns,
-// const QModelIndex &parent = QModelIndex()) Q_DECL_OVERRIDE;
-// bool insertRows(int position, int rows,
-// const QModelIndex &parent = QModelIndex()) Q_DECL_OVERRIDE;
-// bool removeRows(int position, int rows,
-// const QModelIndex &parent = QModelIndex()) Q_DECL_OVERRIDE;
+ const QModelIndex &parent = QModelIndex()) const override;
+ QModelIndex parent(const QModelIndex &index) const override;
+
+ int rowCount(const QModelIndex &parent = QModelIndex()) const override;
+ int columnCount(const QModelIndex &) const override;
+
+ Qt::ItemFlags flags(const QModelIndex &index) const override;
+
+ bool setData(const QModelIndex &index, const QVariant &value,
+ int role = Qt::EditRole) override;
void operator <<(GraphElementProperty p);
void add(GraphElementProperty p);
diff --git a/src/data/graphelementproperty.cpp b/src/data/graphelementproperty.cpp
index 79a8280..aa1bfc8 100644
--- a/src/data/graphelementproperty.cpp
+++ b/src/data/graphelementproperty.cpp
@@ -21,19 +21,19 @@
#include <QRegExp>
GraphElementProperty::GraphElementProperty ():
- _key(""), _value(""), _atom(false), _keyMatch(false)
+ _key(""), _value(""), _atom(false)
{}
-GraphElementProperty::GraphElementProperty(QString key, QString value, bool atom, bool keyMatch) :
- _key(key), _value(value), _atom(atom), _keyMatch(keyMatch)
+GraphElementProperty::GraphElementProperty(QString key, QString value, bool atom) :
+ _key(key), _value(value), _atom(atom)
{}
GraphElementProperty::GraphElementProperty(QString key, QString value) :
- _key(key), _value(value), _atom(false), _keyMatch(false)
+ _key(key), _value(value), _atom(false)
{}
-GraphElementProperty::GraphElementProperty(QString key, bool keyMatch) :
- _key(key), _value(""), _atom(!keyMatch), _keyMatch(keyMatch)
+GraphElementProperty::GraphElementProperty(QString key) :
+ _key(key), _value(""), _atom(true)
{}
QString GraphElementProperty::key() const
@@ -48,20 +48,11 @@ void GraphElementProperty::setValue(const QString &value)
bool GraphElementProperty::atom() const
{ return _atom; }
-bool GraphElementProperty::keyMatch() const
-{ return _keyMatch; }
-
-bool GraphElementProperty::matches(const GraphElementProperty &p)
-{
- if (p.atom()) return _atom && _key == p.key();
- if (p.keyMatch()) return !_atom && _key == p.key();
- if (_keyMatch) return !p.atom() && _key == p.key();
- return !_atom && _key == p.key() && _value == p.value();
-}
bool GraphElementProperty::operator==(const GraphElementProperty &p)
{
- return matches(p);
+ if (_atom) return p.atom() && p.key() == _key;
+ else return !p.atom() && p.key() == _key && p.value() == _value;
}
QString GraphElementProperty::tikzEscape(QString str)
@@ -75,3 +66,8 @@ QString GraphElementProperty::tikz() {
if (_atom) return tikzEscape(_key);
return tikzEscape(_key) + "=" + tikzEscape(_value);
}
+
+void GraphElementProperty::setKey(const QString &key)
+{
+ _key = key;
+}
diff --git a/src/data/graphelementproperty.h b/src/data/graphelementproperty.h
index af4ae91..e9f82d0 100644
--- a/src/data/graphelementproperty.h
+++ b/src/data/graphelementproperty.h
@@ -25,25 +25,26 @@ class GraphElementProperty
{
public:
GraphElementProperty();
- GraphElementProperty(QString key, QString value, bool atom, bool keyMatch);
- // construct a property
+ // full constructor
+ GraphElementProperty(QString key, QString value, bool atom);
+
+ // construct a proper property
GraphElementProperty(QString key, QString value);
- // construct an atom or keymatch
- GraphElementProperty(QString key, bool keyMatch = false);
+ // construct an atom
+ GraphElementProperty(QString key);
QString key() const;
+ void setKey(const QString &key);
QString value() const;
void setValue(const QString &value);
bool atom() const;
- bool keyMatch() const;
-
- bool matches(const GraphElementProperty &p);
bool operator==(const GraphElementProperty &p);
static QString tikzEscape(QString str);
QString tikz();
+
signals:
public slots:
diff --git a/src/data/style.cpp b/src/data/style.cpp
index 0128d36..63747ec 100644
--- a/src/data/style.cpp
+++ b/src/data/style.cpp
@@ -77,6 +77,11 @@ QString Style::propertyWithDefault(QString prop, QString def, bool tikzitOverrid
return val;
}
+QString Style::tikz() const
+{
+ return "\\tikzstyle{" + _name + "}=" + _data->tikz();
+}
+
void Style::setName(const QString &name)
{
_name = name;
diff --git a/src/data/style.h b/src/data/style.h
index 1b0618e..cef7c7b 100644
--- a/src/data/style.h
+++ b/src/data/style.h
@@ -49,6 +49,7 @@ public:
void setName(const QString &name);
QString propertyWithDefault(QString prop, QString def, bool tikzitOverride=true) const;
+ QString tikz() const;
protected:
QString _name;
GraphElementData *_data;
diff --git a/src/data/tikzstyles.cpp b/src/data/tikzstyles.cpp
index a743d0c..68b3dcd 100644
--- a/src/data/tikzstyles.cpp
+++ b/src/data/tikzstyles.cpp
@@ -70,7 +70,19 @@ bool TikzStyles::loadStyles(QString fileName)
}
}
-void TikzStyles::refreshModels(QStandardItemModel *nodeModel, QStandardItemModel *edgeModel)
+bool TikzStyles::saveStyles(QString fileName)
+{
+ QFile file(fileName);
+ if (file.open(QIODevice::WriteOnly)) {
+ QTextStream stream(&file);
+ stream << tikz();
+ file.close();
+ return true;
+ }
+ return false;
+}
+
+void TikzStyles::refreshModels(QStandardItemModel *nodeModel, QStandardItemModel *edgeModel, QString category, bool includeNone)
{
nodeModel->clear();
edgeModel->clear();
@@ -81,32 +93,42 @@ void TikzStyles::refreshModels(QStandardItemModel *nodeModel, QStandardItemModel
QStandardItem *it;
- it = new QStandardItem(noneStyle->icon(), noneStyle->name());
- it->setEditable(false);
- it->setData(noneStyle->name());
- nodeModel->appendRow(it);
- it->setTextAlignment(Qt::AlignCenter);
- it->setSizeHint(QSize(48,48));
-
- foreach(NodeStyle *ns, _nodeStyles) {
- it = new QStandardItem(ns->icon(), ns->name());
+ if (includeNone) {
+ it = new QStandardItem(noneStyle->icon(), noneStyle->name());
it->setEditable(false);
- it->setData(ns->name());
- it->setSizeHint(QSize(48,48));
+ it->setData(noneStyle->name());
nodeModel->appendRow(it);
+ it->setTextAlignment(Qt::AlignCenter);
+ it->setSizeHint(QSize(48,48));
}
- it = new QStandardItem(noneEdgeStyle->icon(), noneEdgeStyle->name());
- it->setEditable(false);
- it->setData(noneEdgeStyle->name());
- edgeModel->appendRow(it);
+ foreach(NodeStyle *ns, _nodeStyles) {
+ if (category == "" || category == ns->propertyWithDefault("tikzit category", "", false))
+ {
+ it = new QStandardItem(ns->icon(), ns->name());
+ it->setEditable(false);
+ it->setData(ns->name());
+ it->setSizeHint(QSize(48,48));
+ nodeModel->appendRow(it);
+ }
+ }
- foreach(EdgeStyle *es, _edgeStyles) {
- it = new QStandardItem(es->icon(), es->name());
+ if (includeNone) {
+ it = new QStandardItem(noneEdgeStyle->icon(), noneEdgeStyle->name());
it->setEditable(false);
- it->setData(es->name());
+ it->setData(noneEdgeStyle->name());
edgeModel->appendRow(it);
}
+
+ foreach(EdgeStyle *es, _edgeStyles) {
+ //if (category == "" || category == es->propertyWithDefault("tikzit category", "", false))
+ //{
+ it = new QStandardItem(es->icon(), es->name());
+ it->setEditable(false);
+ it->setData(es->name());
+ edgeModel->appendRow(it);
+ //}
+ }
}
QVector<EdgeStyle *> TikzStyles::edgeStyles() const
@@ -114,6 +136,35 @@ QVector<EdgeStyle *> TikzStyles::edgeStyles() const
return _edgeStyles;
}
+QStringList TikzStyles::categories() const
+{
+ QMap<QString,bool> cats; // use a QMap to keep keys sorted
+ cats.insert("", true);
+ foreach (NodeStyle *s, _nodeStyles) cats.insert(s->propertyWithDefault("tikzit category", "", false), true);
+ //foreach (EdgeStyle *s, _edgeStyles) cats << s->propertyWithDefault("tikzit category", "", false);
+ return QStringList(cats.keys());
+}
+
+QString TikzStyles::tikz() const
+{
+ QString str;
+ QTextStream code(&str);
+
+ code << "% TiKZ style file generated by TikZiT. You may edit this file manually,\n";
+ code << "% but some things (e.g. comments) may be overwritten. To be readable in\n";
+ code << "% TikZiT, the only non-comment lines must be of the form:\n";
+ code << "% \\tikzstyle{NAME}=[PROPERTY LIST]\n\n";
+
+ code << "% Node styles\n";
+ foreach (NodeStyle *s, nodeStyles()) code << s->tikz() << "\n";
+
+ code << "\n% Edge styles\n";
+ foreach (EdgeStyle *s, edgeStyles()) code << s->tikz() << "\n";
+
+ code.flush();
+ return str;
+}
+
void TikzStyles::addStyle(QString name, GraphElementData *data)
{
if (data->atom("-") || data->atom("->") || data->atom("-|") ||
diff --git a/src/data/tikzstyles.h b/src/data/tikzstyles.h
index 26ff0a3..558901e 100644
--- a/src/data/tikzstyles.h
+++ b/src/data/tikzstyles.h
@@ -39,10 +39,16 @@ public:
EdgeStyle *edgeStyle(QString name) const;
QVector<NodeStyle *> nodeStyles() const;
QVector<EdgeStyle *> edgeStyles() const;
+ QStringList categories() const;
+ QString tikz() const;
void clear();
bool loadStyles(QString fileName);
- void refreshModels(QStandardItemModel *nodeModel, QStandardItemModel *edgeModel);
+ bool saveStyles(QString fileName);
+ void refreshModels(QStandardItemModel *nodeModel,
+ QStandardItemModel *edgeModel,
+ QString category="",
+ bool includeNone=true);
signals:
diff --git a/src/gui/styleeditor.cpp b/src/gui/styleeditor.cpp
index e113c6c..fbf73a9 100644
--- a/src/gui/styleeditor.cpp
+++ b/src/gui/styleeditor.cpp
@@ -18,11 +18,6 @@ StyleEditor::StyleEditor(QWidget *parent) :
ui->leftArrow << ui->rightArrow <<
ui->properties;
- setColor(ui->fillColor, QColor(Qt::white));
- setColor(ui->drawColor, QColor(Qt::black));
- setColor(ui->tikzitFillColor, QColor(Qt::white));
- setColor(ui->tikzitDrawColor, QColor(Qt::black));
-
_styles = 0;
_nodeModel = new QStandardItemModel(this);
@@ -44,6 +39,12 @@ StyleEditor::StyleEditor(QWidget *parent) :
connect(ui->edgeStyleListView->selectionModel(),
SIGNAL(currentChanged(QModelIndex,QModelIndex)),
this, SLOT(edgeItemChanged(QModelIndex)));
+ connect(ui->category->lineEdit(),
+ SIGNAL(editingFinished()),
+ this, SLOT(categoryChanged()));
+ connect(ui->category,
+ SIGNAL(currentIndexChanged(int)),
+ this, SLOT(categoryChanged()));
// setup the color dialog to display only the named colors that tikzit/xcolor knows
// about as "standard colors".
@@ -81,6 +82,7 @@ StyleEditor::StyleEditor(QWidget *parent) :
_activeNodeStyle = 0;
_activeEdgeStyle = 0;
+ _activeItem = 0;
refreshDisplay();
}
@@ -92,9 +94,16 @@ StyleEditor::~StyleEditor()
void StyleEditor::open() {
if (_styles != 0) delete _styles;
_styles = new TikzStyles;
+ _activeNodeStyle = 0;
+ _activeEdgeStyle = 0;
+ _activeItem = 0;
+ ui->styleListView->selectionModel()->clear();
+ ui->edgeStyleListView->selectionModel()->clear();
if (_styles->loadStyles(tikzit->styleFilePath())) {
- _styles->refreshModels(_nodeModel, _edgeModel);
_dirty = false;
+ _styles->refreshModels(_nodeModel, _edgeModel, "", false);
+ refreshCategories();
+ refreshDisplay();
show();
} else {
QMessageBox::warning(0,
@@ -130,16 +139,17 @@ void StyleEditor::nodeItemChanged(QModelIndex sel)
//ui->edgeStyleListView->blockSignals(true);
ui->edgeStyleListView->selectionModel()->clear();
//ui->edgeStyleListView->blockSignals(false);
- qDebug() << "got node item change";
+ //qDebug() << "got node item change";
_activeNodeStyle = 0;
_activeEdgeStyle = 0;
+ _activeItem = 0;
QString sty;
if (sel.isValid()) {
_activeItem = _nodeModel->itemFromIndex(sel);
sty = _activeItem->text();
if (sty != "none")
- _activeNodeStyle = tikzit->styles()->nodeStyle(sty);
+ _activeNodeStyle = _styles->nodeStyle(sty);
}
refreshDisplay();
}
@@ -149,21 +159,106 @@ void StyleEditor::edgeItemChanged(QModelIndex sel)
//ui->styleListView->blockSignals(true);
ui->styleListView->selectionModel()->clear();
//ui->styleListView->blockSignals(false);
- qDebug() << "got edge item change";
+ //qDebug() << "got edge item change";
_activeNodeStyle = 0;
_activeEdgeStyle = 0;
+ _activeItem = 0;
QString sty;
if (sel.isValid()) {
_activeItem = _edgeModel->itemFromIndex(sel);
sty = _activeItem->text();
if (sty != "none")
- _activeEdgeStyle = tikzit->styles()->edgeStyle(sty);
+ _activeEdgeStyle = _styles->edgeStyle(sty);
}
refreshDisplay();
}
+void StyleEditor::categoryChanged()
+{
+ Style *s = activeStyle();
+ QString cat = ui->category->currentText();
+ //qDebug() << "got category: " << cat;
+
+ if (s != 0 && s->data()->property("tikzit category") != cat) {
+ if (cat.isEmpty()) s->data()->unsetProperty("tikzit category");
+ else s->data()->setProperty("tikzit category", cat);
+ _dirty = true;
+ refreshCategories();
+ refreshDisplay();
+ }
+}
+
+void StyleEditor::currentCategoryChanged()
+{
+ qDebug() << "refreshing models on category change";
+ _styles->refreshModels(_nodeModel, _edgeModel, ui->currentCategory->currentText(), false);
+ _activeItem = 0;
+
+ // try to keep the selection as is, or clear the current style
+ if (_activeNodeStyle != 0) {
+ ui->styleListView->selectionModel()->clear();
+ for (int i = 0; i < _nodeModel->rowCount(); ++i) {
+ if (_activeNodeStyle->name() == _nodeModel->item(i)->data()) {
+ _activeItem = _nodeModel->item(i);
+ ui->styleListView->selectionModel()->select(
+ _nodeModel->index(i,0),
+ QItemSelectionModel::SelectCurrent);
+ }
+ }
+ } else if (_activeEdgeStyle != 0) {
+ ui->edgeStyleListView->selectionModel()->clear();
+ for (int i = 0; i < _edgeModel->rowCount(); ++i) {
+ if (_activeEdgeStyle->name() == _edgeModel->item(i)->data()) {
+ _activeItem = _edgeModel->item(i);
+ ui->edgeStyleListView->selectionModel()->select(
+ _edgeModel->index(i,0),
+ QItemSelectionModel::SelectCurrent);
+ }
+ }
+ }
+
+ if (_activeItem == 0) {
+ _activeNodeStyle = 0;
+ _activeEdgeStyle = 0;
+ }
+}
+
+void StyleEditor::refreshCategories()
+{
+ ui->currentCategory->blockSignals(true);
+ ui->category->blockSignals(true);
+ QString curCat = ui->currentCategory->currentText();
+ QString cat = ui->category->currentText();
+ ui->currentCategory->clear();
+ ui->category->clear();
+
+ if (_styles != 0) {
+ foreach(QString c, _styles->categories()) {
+ ui->category->addItem(c);
+ ui->currentCategory->addItem(c);
+ }
+ }
+
+ ui->currentCategory->setCurrentText(curCat);
+ ui->category->setCurrentText(cat);
+ ui->currentCategory->blockSignals(false);
+ ui->category->blockSignals(false);
+}
+
+void StyleEditor::propertyChanged()
+{
+ if (_activeNodeStyle != 0) {
+ _activeItem->setIcon(_activeNodeStyle->icon());
+ refreshCategories();
+ } else if (_activeEdgeStyle != 0) {
+ _activeItem->setIcon(_activeEdgeStyle->icon());
+ }
+ _dirty = true;
+ refreshDisplay();
+}
+
void StyleEditor::refreshDisplay()
{
// disable all fields and block signals while we set their values
@@ -175,6 +270,8 @@ void StyleEditor::refreshDisplay()
// set to default values
ui->name->setText("none");
ui->category->setCurrentText("");
+ //ui->category->clear();
+
setColor(ui->fillColor, QColor(Qt::gray));
setColor(ui->drawColor, QColor(Qt::gray));
setColor(ui->tikzitFillColor, QColor(Qt::gray));
@@ -189,14 +286,15 @@ void StyleEditor::refreshDisplay()
ui->properties->setModel(0);
if (_activeNodeStyle != 0) {
- _activeItem->setText(_activeNodeStyle->name());
- _activeItem->setIcon(_activeNodeStyle->icon());
+ //_activeItem->setText(_activeNodeStyle->name());
+ //_activeItem->setIcon(_activeNodeStyle->icon());
ui->name->setEnabled(true);
ui->name->setText(_activeNodeStyle->name());
ui->category->setEnabled(true);
- // TODO
+ ui->category->setCurrentText(
+ _activeNodeStyle->propertyWithDefault("tikzit category", "", false));
// passing 'false' to these methods prevents 'tikzit foo' from overriding property 'foo'
QColor realFill = _activeNodeStyle->fillColor(false);
@@ -236,16 +334,17 @@ void StyleEditor::refreshDisplay()
if (shapeOverride) ui->tikzitShape->setCurrentText(shape);
ui->properties->setEnabled(true);
- ui->properties->setModel(_activeNodeStyle->data());
+ setPropertyModel(_activeNodeStyle->data());
qDebug() << _activeNodeStyle->data()->tikz();
} else if (_activeEdgeStyle != 0) {
- _activeItem->setText(_activeEdgeStyle->name());
- _activeItem->setIcon(_activeEdgeStyle->icon());
+ //_activeItem->setText(_activeEdgeStyle->name());
+ //_activeItem->setIcon(_activeEdgeStyle->icon());
ui->name->setEnabled(true);
ui->name->setText(_activeEdgeStyle->name());
- // TODO
- ui->category->setEnabled(true);
+ //ui->category->setEnabled(true);
+ //ui->category->setCurrentText(
+ // _activeEdgeStyle->propertyWithDefault("tikzit category", "", false));
setColor(ui->fillColor, QColor(Qt::gray));
setColor(ui->tikzitFillColor, QColor(Qt::gray));
@@ -293,8 +392,8 @@ void StyleEditor::refreshDisplay()
break;
}
- // TODO
ui->properties->setEnabled(true);
+ setPropertyModel(_activeEdgeStyle->data());
} else {
setColor(ui->fillColor, QColor(Qt::gray));
setColor(ui->drawColor, QColor(Qt::gray));
@@ -328,16 +427,63 @@ void StyleEditor::on_tikzitDrawColor_clicked()
updateColor(ui->tikzitDrawColor, "TikZiT Draw Color", "tikzit draw");
}
+void StyleEditor::on_addProperty_clicked()
+{
+ Style *s = activeStyle();
+ if (s != 0) {
+ s->data()->add(GraphElementProperty("new property", ""));
+ _dirty = true;
+ }
+}
+
+void StyleEditor::on_addAtom_clicked()
+{
+ Style *s = activeStyle();
+ if (s != 0) {
+ s->data()->add(GraphElementProperty("new atom"));
+ _dirty = true;
+ }
+}
+
+void StyleEditor::on_removeProperty_clicked()
+{
+
+}
+
+void StyleEditor::on_propertyUp_clicked()
+{
+
+}
+
+void StyleEditor::on_propertyDown_clicked()
+{
+
+}
+
void StyleEditor::on_save_clicked()
{
save();
close();
}
+void StyleEditor::on_currentCategory_currentIndexChanged(int)
+{
+ currentCategoryChanged();
+}
+
+
void StyleEditor::save()
{
- _dirty = false;
- // TODO
+ QString p = tikzit->styleFilePath();
+
+ if (_styles->saveStyles(p)) {
+ _dirty = false;
+ tikzit->loadStyles(p);
+ } else {
+ QMessageBox::warning(0,
+ "Unabled to save style file",
+ "Unable to write to file: '" + tikzit->styleFile() + "'.");
+ }
}
void StyleEditor::on_styleListView_clicked()
@@ -350,22 +496,21 @@ void StyleEditor::on_edgeStyleListView_clicked()
void StyleEditor::on_name_editingFinished()
{
- Style *s;
- if (_activeNodeStyle != 0) s = _activeNodeStyle;
- else if (_activeEdgeStyle != 0) s = _activeEdgeStyle;
- else return;
+ Style *s = activeStyle();
- s->setName(ui->name->text());
- //_activeItem->setText(ui->name->text());
- refreshDisplay();
- _dirty = true;
+ if (s != 0) {
+ s->setName(ui->name->text());
+ _activeItem->setText(ui->name->text());
+ refreshDisplay();
+ _dirty = true;
+ }
}
void StyleEditor::on_shape_currentTextChanged()
{
if (_activeNodeStyle != 0) {
_activeNodeStyle->data()->setProperty("shape", ui->shape->currentText());
- //_activeItem->setIcon(_activeNodeStyle->icon());
+ _activeItem->setIcon(_activeNodeStyle->icon());
refreshDisplay();
_dirty = true;
}
@@ -379,12 +524,29 @@ void StyleEditor::setColor(QPushButton *btn, QColor col)
btn->update();
}
+void StyleEditor::setPropertyModel(GraphElementData *d)
+{
+ if (ui->properties->model() != 0) {
+ disconnect(ui->properties->model(), SIGNAL(dataChanged(QModelIndex,QModelIndex,QVector<int>)),
+ this, SLOT(propertyChanged()));
+ }
+ ui->properties->setModel(d);
+ connect(d, SIGNAL(dataChanged(QModelIndex,QModelIndex,QVector<int>)),
+ this, SLOT(propertyChanged()));
+}
+
QColor StyleEditor::color(QPushButton *btn)
{
QPalette pal = btn->palette();
return pal.color(QPalette::Button);
}
+Style *StyleEditor::activeStyle()
+{
+ if (_activeNodeStyle != 0) return _activeNodeStyle;
+ else return _activeEdgeStyle;
+}
+
void StyleEditor::updateColor(QPushButton *btn, QString name, QString propName)
{
QColor col = QColorDialog::getColor(
@@ -396,10 +558,10 @@ void StyleEditor::updateColor(QPushButton *btn, QString name, QString propName)
setColor(btn, col);
if (_activeNodeStyle != 0) {
_activeNodeStyle->data()->setProperty(propName, tikzit->nameForColor(col));
-// _activeItem->setIcon(_activeNodeStyle->icon());
+ _activeItem->setIcon(_activeNodeStyle->icon());
} else if (_activeEdgeStyle != 0) {
_activeEdgeStyle->data()->setProperty(propName, tikzit->nameForColor(col));
-// _activeItem->setIcon(_activeEdgeStyle->icon());
+ _activeItem->setIcon(_activeEdgeStyle->icon());
}
refreshDisplay();
diff --git a/src/gui/styleeditor.h b/src/gui/styleeditor.h
index 82f019e..f5df025 100644
--- a/src/gui/styleeditor.h
+++ b/src/gui/styleeditor.h
@@ -21,14 +21,18 @@ public:
explicit StyleEditor(QWidget *parent = 0);
~StyleEditor();
- void refreshDisplay();
void open();
void save();
void closeEvent(QCloseEvent *event) override;
public slots:
+ void refreshDisplay();
void nodeItemChanged(QModelIndex sel);
void edgeItemChanged(QModelIndex sel);
+ void categoryChanged();
+ void currentCategoryChanged();
+ void refreshCategories();
+ void propertyChanged();
void on_styleListView_clicked();
void on_edgeStyleListView_clicked();
@@ -39,17 +43,29 @@ public slots:
void on_tikzitFillColor_clicked();
void on_tikzitDrawColor_clicked();
+ void on_addProperty_clicked();
+ void on_addAtom_clicked();
+ void on_removeProperty_clicked();
+ void on_propertyUp_clicked();
+ void on_propertyDown_clicked();
+
void on_save_clicked();
+ void on_currentCategory_currentIndexChanged(int);
+
+
private:
Ui::StyleEditor *ui;
void setColor(QPushButton *btn, QColor col);
+ void setPropertyModel(GraphElementData *d);
QColor color(QPushButton *btn);
QStandardItemModel *_nodeModel;
QStandardItemModel *_edgeModel;
QStandardItem *_activeItem;
NodeStyle *_activeNodeStyle;
EdgeStyle *_activeEdgeStyle;
+ //QString _activeCategory;
+ Style *activeStyle();
TikzStyles *_styles;
void updateColor(QPushButton *btn, QString name, QString propName);
QVector<QWidget*> _formWidgets;
diff --git a/src/gui/stylepalette.cpp b/src/gui/stylepalette.cpp
index 500384b..447e7a4 100644
--- a/src/gui/stylepalette.cpp
+++ b/src/gui/stylepalette.cpp
@@ -70,7 +70,14 @@ void StylePalette::reloadStyles()
QString f = tikzit->styleFile();
ui->styleFile->setText(f);
- tikzit->styles()->refreshModels(_nodeModel, _edgeModel);
+ QString cat = ui->currentCategory->currentText();
+ ui->currentCategory->clear();
+
+ // TODO: styleFile() should return invalid string if no style file loaded
+ if (f != "[default]") {
+ ui->currentCategory->addItems(tikzit->styles()->categories());
+ ui->currentCategory->setCurrentText(cat);
+ }
}
void StylePalette::changeNodeStyle(int increment)
@@ -147,6 +154,11 @@ void StylePalette::on_buttonRefreshTikzstyles_clicked()
if (!path.isEmpty()) tikzit->loadStyles(path);
}
+void StylePalette::on_currentCategory_currentTextChanged(const QString &cat)
+{
+ tikzit->styles()->refreshModels(_nodeModel, _edgeModel, cat);
+}
+
//void StylePalette::on_buttonApplyNodeStyle_clicked()
//{
// if (tikzit->activeWindow() != 0) tikzit->activeWindow()->tikzScene()->applyActiveStyleToNodes();
diff --git a/src/gui/stylepalette.h b/src/gui/stylepalette.h
index 3c0c721..5943e52 100644
--- a/src/gui/stylepalette.h
+++ b/src/gui/stylepalette.h
@@ -46,6 +46,7 @@ public slots:
void on_buttonOpenTikzstyles_clicked();
void on_buttonEditTikzstyles_clicked();
void on_buttonRefreshTikzstyles_clicked();
+ void on_currentCategory_currentTextChanged(const QString &cat);
//void on_buttonApplyNodeStyle_clicked();
private:
diff --git a/src/gui/stylepalette.ui b/src/gui/stylepalette.ui
index 044bd02..10e7392 100644
--- a/src/gui/stylepalette.ui
+++ b/src/gui/stylepalette.ui
@@ -6,7 +6,7 @@
<rect>
<x>0</x>
<y>0</y>
- <width>88</width>
+ <width>130</width>
<height>506</height>
</rect>
</property>
@@ -18,13 +18,13 @@
</property>
<property name="minimumSize">
<size>
- <width>88</width>
- <height>191</height>
+ <width>130</width>
+ <height>218</height>
</size>
</property>
<property name="maximumSize">
<size>
- <width>88</width>
+ <width>130</width>
<height>524287</height>
</size>
</property>
@@ -115,6 +115,9 @@
</widget>
</item>
<item>
+ <widget class="QComboBox" name="currentCategory"/>
+ </item>
+ <item>
<widget class="QListView" name="styleListView">
<property name="font">
<font>
@@ -122,6 +125,12 @@
<italic>true</italic>
</font>
</property>
+ <property name="verticalScrollBarPolicy">
+ <enum>Qt::ScrollBarAlwaysOn</enum>
+ </property>
+ <property name="horizontalScrollBarPolicy">
+ <enum>Qt::ScrollBarAlwaysOff</enum>
+ </property>
</widget>
</item>
<item>