diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/data/graphelementdata.cpp | 5 | ||||
-rw-r--r-- | src/data/graphelementdata.h | 1 | ||||
-rw-r--r-- | src/data/graphelementproperty.h | 1 | ||||
-rw-r--r-- | src/data/style.cpp | 17 | ||||
-rw-r--r-- | src/data/style.h | 1 | ||||
-rw-r--r-- | src/gui/styleeditor.cpp | 169 | ||||
-rw-r--r-- | src/gui/styleeditor.h | 10 | ||||
-rw-r--r-- | src/main.cpp | 2 |
8 files changed, 165 insertions, 41 deletions
diff --git a/src/data/graphelementdata.cpp b/src/data/graphelementdata.cpp index b478842..810ebd6 100644 --- a/src/data/graphelementdata.cpp +++ b/src/data/graphelementdata.cpp @@ -96,6 +96,11 @@ QString GraphElementData::property(QString key) }
}
+bool GraphElementData::hasProperty(QString key)
+{
+ return (indexOfKey(key) != -1);
+}
+
bool GraphElementData::atom(QString atom)
{
return (indexOfKey(atom) != -1);
diff --git a/src/data/graphelementdata.h b/src/data/graphelementdata.h index f48f228..23f0466 100644 --- a/src/data/graphelementdata.h +++ b/src/data/graphelementdata.h @@ -41,6 +41,7 @@ public: void setAtom(QString atom);
void unsetAtom(QString atom);
QString property(QString key);
+ bool hasProperty(QString key);
bool atom(QString atom);
int indexOfKey(QString key);
bool removeRows(int row, int count, const QModelIndex &parent) override;
diff --git a/src/data/graphelementproperty.h b/src/data/graphelementproperty.h index e9f82d0..4ebe104 100644 --- a/src/data/graphelementproperty.h +++ b/src/data/graphelementproperty.h @@ -53,7 +53,6 @@ private: QString _key;
QString _value;
bool _atom;
- bool _keyMatch;
};
#endif // GRAPHELEMENTPROPERTY_H
diff --git a/src/data/style.cpp b/src/data/style.cpp index 7af95ca..d0f011d 100644 --- a/src/data/style.cpp +++ b/src/data/style.cpp @@ -106,6 +106,23 @@ QString Style::tikz() const return "\\tikzstyle{" + _name + "}=" + _data->tikz();
}
+void Style::setArrowAtom(QString atom)
+{
+ _data->unsetAtom("-");
+ _data->unsetAtom("->");
+ _data->unsetAtom("-|");
+
+ _data->unsetAtom("<-");
+ _data->unsetAtom("<->");
+ _data->unsetAtom("<-|");
+
+ _data->unsetAtom("|-");
+ _data->unsetAtom("|->");
+ _data->unsetAtom("|-|");
+
+ _data->setAtom(atom);
+}
+
void Style::setName(const QString &name)
{
_name = name;
diff --git a/src/data/style.h b/src/data/style.h index 476af77..78e11dc 100644 --- a/src/data/style.h +++ b/src/data/style.h @@ -57,6 +57,7 @@ public: void setName(const QString &name);
QString propertyWithDefault(QString prop, QString def, bool tikzitOverride=true) const;
QString tikz() const;
+ void setArrowAtom(QString atom);
// only relevant for node styles
QColor fillColor(bool tikzitOverride=true) const;
diff --git a/src/gui/styleeditor.cpp b/src/gui/styleeditor.cpp index 40706ff..29192d6 100644 --- a/src/gui/styleeditor.cpp +++ b/src/gui/styleeditor.cpp @@ -37,6 +37,13 @@ StyleEditor::StyleEditor(QWidget *parent) : SIGNAL(currentIndexChanged(int)), this, SLOT(categoryChanged())); + connect(ui->shape->lineEdit(), + SIGNAL(editingFinished()), + this, SLOT(shapeChanged())); + connect(ui->shape, + SIGNAL(currentIndexChanged(int)), + this, SLOT(shapeChanged())); + // setup the color dialog to display only the named colors that tikzit/xcolor knows // about as "standard colors". for (int i = 0; i < 48; ++i) { @@ -128,7 +135,7 @@ void StyleEditor::closeEvent(QCloseEvent *event) void StyleEditor::nodeItemChanged(QModelIndex sel) { - qDebug() << "nodeItemChanged, new index:" << sel.row(); + //qDebug() << "nodeItemChanged, new index:" << sel.row(); if (sel.isValid()) { ui->edgeStyleListView->selectionModel()->clear(); _activeStyle = _styles->nodeStyles()->styleInCategory(sel.row()); @@ -171,8 +178,6 @@ void StyleEditor::currentCategoryChanged() { if (_styles != nullptr) { QString cat = ui->currentCategory->currentText(); - qDebug() << "got category:" << cat; - qDebug() << "node style category:" << _styles->nodeStyles()->category(); if (cat != _styles->nodeStyles()->category()) { ui->styleListView->selectionModel()->clear(); _styles->nodeStyles()->setCategory(cat); @@ -192,6 +197,17 @@ void StyleEditor::currentCategoryChanged() } } +void StyleEditor::shapeChanged() +{ + Style *s = activeStyle(); + if (s != 0) { + s->data()->setProperty("shape", ui->shape->currentText()); + refreshActiveStyle(); + refreshDisplay(); + setDirty(true); + } +} + void StyleEditor::refreshCategories() { ui->currentCategory->blockSignals(true); @@ -233,9 +249,8 @@ void StyleEditor::propertyChanged() void StyleEditor::refreshDisplay() { - // disable all fields and block signals while we set their values + // enable all fields and block signals while we set their values foreach (QWidget *w, _formWidgets) { - w->setEnabled(false); w->blockSignals(true); } @@ -259,7 +274,10 @@ void StyleEditor::refreshDisplay() Style *s = activeStyle(); +// qDebug() << "style" << s; if (s != nullptr && !s->isNone()) { +// qDebug() << "non-null style update"; + // name ui->name->setEnabled(true); ui->name->setText(s->name()); @@ -275,7 +293,7 @@ void StyleEditor::refreshDisplay() setColor(ui->drawColor, realDraw); // tikzit draw - bool drawOverride = realDraw != draw; + bool drawOverride = s->data()->hasProperty("tikzit draw"); ui->hasTikzitDrawColor->setEnabled(true); ui->hasTikzitDrawColor->setChecked(drawOverride); @@ -283,6 +301,7 @@ void StyleEditor::refreshDisplay() if (drawOverride) setColor(ui->tikzitDrawColor, draw); if (!s->isEdgeStyle()) { +// qDebug() << "node style update"; // category ui->category->setEnabled(true); ui->category->setCurrentText( @@ -295,7 +314,7 @@ void StyleEditor::refreshDisplay() setColor(ui->fillColor, realFill); // tikzit fill - bool fillOverride = realFill != fill; + bool fillOverride = s->data()->hasProperty("tikzit fill"); ui->hasTikzitFillColor->setEnabled(true); ui->hasTikzitFillColor->setChecked(fillOverride); ui->tikzitFillColor->setEnabled(fillOverride); @@ -308,15 +327,22 @@ void StyleEditor::refreshDisplay() ui->shape->setCurrentText(realShape); // tikzit shape - bool shapeOverride = shape != realShape; + bool shapeOverride = s->data()->hasProperty("tikzit shape"); ui->hasTikzitShape->setEnabled(true); + ui->hasTikzitShape->setChecked(shapeOverride); ui->tikzitShape->setEnabled(shapeOverride); if (shapeOverride) ui->tikzitShape->setCurrentText(shape); } else { +// qDebug() << "edge style update"; + // set fill to gray (disabled) - setColor(ui->fillColor, QColor(Qt::gray)); - setColor(ui->tikzitFillColor, QColor(Qt::gray)); - ui->hasTikzitFillColor->setChecked(false); + ui->fillColor->setEnabled(false); + ui->tikzitFillColor->setEnabled(false); + ui->hasTikzitFillColor->setEnabled(false); + + ui->shape->setEnabled(false); + ui->tikzitShape->setEnabled(false); + ui->hasTikzitShape->setEnabled(false); // arrow tail @@ -350,10 +376,11 @@ void StyleEditor::refreshDisplay() } } else { - setColor(ui->fillColor, QColor(Qt::gray)); - setColor(ui->drawColor, QColor(Qt::gray)); - setColor(ui->tikzitDrawColor, QColor(Qt::gray)); - setColor(ui->tikzitFillColor, QColor(Qt::gray)); +// qDebug() << "null style update"; + + foreach (QWidget *w, _formWidgets) { + w->setEnabled(false); + } } // unblock signals so we are ready for user input @@ -382,10 +409,78 @@ void StyleEditor::on_tikzitDrawColor_clicked() updateColor(ui->tikzitDrawColor, "TikZiT Draw Color", "tikzit draw"); } +void StyleEditor::on_hasTikzitFillColor_stateChanged(int state) +{ + Style *s = activeStyle(); + if (s != nullptr) { + if (state == Qt::Checked) s->data()->setProperty("tikzit fill", s->data()->property("fill")); + else s->data()->unsetProperty("tikzit fill"); + refreshDisplay(); + setDirty(true); + } +} + +void StyleEditor::on_hasTikzitDrawColor_stateChanged(int state) +{ + Style *s = activeStyle(); + if (s != nullptr) { + if (state == Qt::Checked) s->data()->setProperty("tikzit draw", s->data()->property("draw")); + else s->data()->unsetProperty("tikzit draw"); + refreshDisplay(); + setDirty(true); + } +} + +void StyleEditor::on_hasTikzitShape_stateChanged(int state) +{ + Style *s = activeStyle(); + if (s != nullptr) { + if (state == Qt::Checked) s->data()->setProperty("tikzit shape", s->data()->property("shape")); + else s->data()->unsetProperty("tikzit shape"); + refreshDisplay(); + setDirty(true); + } +} + +void StyleEditor::on_tikzitShape_currentIndexChanged(int) +{ + Style *s = activeStyle(); + if (s != nullptr) { + s->data()->setProperty("tikzit shape", ui->tikzitShape->currentText()); + refreshActiveStyle(); + refreshDisplay(); + setDirty(true); + } +} + +void StyleEditor::on_leftArrow_currentIndexChanged(int) +{ + Style *s = activeStyle(); + if (s != nullptr) { + s->setArrowAtom(ui->leftArrow->currentText() + "-" + + ui->rightArrow->currentText()); + refreshActiveStyle(); + refreshDisplay(); + setDirty(true); + } +} + +void StyleEditor::on_rightArrow_currentIndexChanged(int) +{ + Style *s = activeStyle(); + if (s != nullptr) { + s->setArrowAtom(ui->leftArrow->currentText() + "-" + + ui->rightArrow->currentText()); + refreshActiveStyle(); + refreshDisplay(); + setDirty(true); + } +} + void StyleEditor::on_addProperty_clicked() { Style *s = activeStyle(); - if (s != 0) { + if (s != nullptr) { s->data()->add(GraphElementProperty("new property", "")); setDirty(true); } @@ -459,12 +554,18 @@ void StyleEditor::on_addStyle_clicked() // add the style to the current category Style *s; if (_styles->nodeStyles()->category() == "") { - s = new Style(name, new GraphElementData()); + s = new Style(name, new GraphElementData({ + GraphElementProperty("fill", "white"), + GraphElementProperty("draw", "black"), + GraphElementProperty("shape", "circle") + })); } else { - s = new Style(name, - new GraphElementData({ - GraphElementProperty("category",_styles->nodeStyles()->category()) - })); + s = new Style(name, new GraphElementData({ + GraphElementProperty("fill", "white"), + GraphElementProperty("draw", "black"), + GraphElementProperty("shape", "circle"), + GraphElementProperty("category", _styles->nodeStyles()->category()), + })); } _styles->nodeStyles()->addStyle(s); @@ -634,16 +735,6 @@ void StyleEditor::on_name_editingFinished() } } -void StyleEditor::on_shape_currentTextChanged() -{ - Style *s = activeStyle(); - if (s != 0) { - s->data()->setProperty("shape", ui->shape->currentText()); - refreshActiveStyle(); -// refreshDisplay(); - setDirty(true); - } -} void StyleEditor::setColor(QPushButton *btn, QColor col) { @@ -709,13 +800,15 @@ void StyleEditor::updateColor(QPushButton *btn, QString name, QString propName) this, name, QColorDialog::DontUseNativeDialog); - setColor(btn, col); - Style *s = activeStyle(); - if (s != nullptr) { - s->data()->setProperty(propName, tikzit->nameForColor(col)); - refreshActiveStyle(); -// refreshDisplay(); - setDirty(true); + if (col.isValid()) { + setColor(btn, col); + Style *s = activeStyle(); + if (s != nullptr) { + s->data()->setProperty(propName, tikzit->nameForColor(col)); + refreshActiveStyle(); + refreshDisplay(); + setDirty(true); + } } } diff --git a/src/gui/styleeditor.h b/src/gui/styleeditor.h index b8bf646..4bae7db 100644 --- a/src/gui/styleeditor.h +++ b/src/gui/styleeditor.h @@ -33,17 +33,25 @@ public slots: void edgeItemChanged(QModelIndex sel); void categoryChanged(); void currentCategoryChanged(); + void shapeChanged(); void refreshCategories(); void propertyChanged(); void on_styleListView_clicked(); void on_edgeStyleListView_clicked(); void on_name_editingFinished(); - void on_shape_currentTextChanged(); void on_fillColor_clicked(); void on_drawColor_clicked(); void on_tikzitFillColor_clicked(); void on_tikzitDrawColor_clicked(); + void on_hasTikzitFillColor_stateChanged(int state); + void on_hasTikzitDrawColor_stateChanged(int state); + + void on_hasTikzitShape_stateChanged(int state); + void on_tikzitShape_currentIndexChanged(int); + + void on_leftArrow_currentIndexChanged(int); + void on_rightArrow_currentIndexChanged(int); void on_addProperty_clicked(); void on_addAtom_clicked(); diff --git a/src/main.cpp b/src/main.cpp index ac8ab13..2fa81d1 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -45,7 +45,7 @@ int main(int argc, char *argv[]) // dummy application for detecting DPI QApplication *a0 = new QApplication(argc, argv); - qDebug() << "physical DPI" << QApplication::screens()[0]->physicalDotsPerInch(); +// qDebug() << "physical DPI" << QApplication::screens()[0]->physicalDotsPerInch(); if (QApplication::screens()[0]->physicalDotsPerInch() >= 100) { QApplication::setAttribute(Qt::AA_EnableHighDpiScaling); |