diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/data/edge.cpp | 5 | ||||
-rw-r--r-- | src/data/edge.h | 1 | ||||
-rw-r--r-- | src/data/graphelementdata.h | 1 | ||||
-rw-r--r-- | src/gui/mainmenu.cpp | 5 | ||||
-rw-r--r-- | src/gui/mainmenu.h | 1 | ||||
-rw-r--r-- | src/gui/mainmenu.ui | 7 | ||||
-rw-r--r-- | src/gui/mainwindow.cpp | 17 | ||||
-rw-r--r-- | src/gui/mainwindow.h | 4 | ||||
-rw-r--r-- | src/gui/mainwindow.ui | 8 | ||||
-rw-r--r-- | src/gui/propertypalette.cpp | 2 | ||||
-rw-r--r-- | src/gui/tikzscene.cpp | 24 | ||||
-rw-r--r-- | src/gui/tikzscene.h | 5 | ||||
-rw-r--r-- | src/gui/tikzview.cpp | 1 | ||||
-rw-r--r-- | src/gui/toolpalette.cpp | 10 | ||||
-rw-r--r-- | src/gui/undocommands.cpp | 22 | ||||
-rw-r--r-- | src/gui/undocommands.h | 11 | ||||
-rw-r--r-- | src/main.cpp | 5 | ||||
-rw-r--r-- | src/tikzit.cpp | 17 | ||||
-rw-r--r-- | src/tikzit.h | 1 |
19 files changed, 128 insertions, 19 deletions
diff --git a/src/data/edge.cpp b/src/data/edge.cpp index 6802b2d..e4d5d69 100644 --- a/src/data/edge.cpp +++ b/src/data/edge.cpp @@ -278,6 +278,11 @@ float Edge::cpDist() const return _cpDist; } +void Edge::setBasicBendMode(bool mode) +{ + _basicBendMode = mode; +} + void Edge::setBend(int bend) { _bend = bend; diff --git a/src/data/edge.h b/src/data/edge.h index d2913b8..595b094 100644 --- a/src/data/edge.h +++ b/src/data/edge.h @@ -50,6 +50,7 @@ public: bool basicBendMode() const; float cpDist() const; + void setBasicBendMode(bool mode); void setBend(int bend); void setInAngle(int inAngle); void setOutAngle(int outAngle); diff --git a/src/data/graphelementdata.h b/src/data/graphelementdata.h index 1139a00..0d43bb8 100644 --- a/src/data/graphelementdata.h +++ b/src/data/graphelementdata.h @@ -22,6 +22,7 @@ public: QString property(QString key); bool atom(QString atom); + QVariant data(const QModelIndex &index, int role) const Q_DECL_OVERRIDE; QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const Q_DECL_OVERRIDE; diff --git a/src/gui/mainmenu.cpp b/src/gui/mainmenu.cpp index c9e83ba..714ed34 100644 --- a/src/gui/mainmenu.cpp +++ b/src/gui/mainmenu.cpp @@ -32,6 +32,11 @@ void MainMenu::on_actionSave_As_triggered() // TODO } +void MainMenu::on_actionExit_triggered() +{ + tikzit->quit(); +} + // Edit void MainMenu::on_actionUndo_triggered() diff --git a/src/gui/mainmenu.h b/src/gui/mainmenu.h index d85e271..ee167e6 100644 --- a/src/gui/mainmenu.h +++ b/src/gui/mainmenu.h @@ -21,6 +21,7 @@ public slots: void on_actionClose_triggered(); void on_actionSave_triggered(); void on_actionSave_As_triggered(); + void on_actionExit_triggered(); // Edit void on_actionUndo_triggered(); diff --git a/src/gui/mainmenu.ui b/src/gui/mainmenu.ui index c9b6f44..2f15d5a 100644 --- a/src/gui/mainmenu.ui +++ b/src/gui/mainmenu.ui @@ -20,6 +20,8 @@ <addaction name="actionClose"/> <addaction name="actionSave"/> <addaction name="actionSave_As"/> + <addaction name="separator"/> + <addaction name="actionExit"/> </widget> <widget class="QMenu" name="menuEdit"> <property name="title"> @@ -177,6 +179,11 @@ <string>Ctrl+-</string> </property> </action> + <action name="actionExit"> + <property name="text"> + <string>Exit</string> + </property> + </action> <addaction name="menuFile"/> <addaction name="menuEdit"/> <addaction name="menuView"/> diff --git a/src/gui/mainwindow.cpp b/src/gui/mainwindow.cpp index 54474ae..eac7c44 100644 --- a/src/gui/mainwindow.cpp +++ b/src/gui/mainwindow.cpp @@ -1,5 +1,7 @@ #include "mainwindow.h" #include "ui_mainwindow.h" + +#include "mainmenu.h" #include "tikzassembler.h" #include "toolpalette.h" #include "tikzit.h" @@ -22,11 +24,22 @@ MainWindow::MainWindow(QWidget *parent) : ui->setupUi(this); setAttribute(Qt::WA_DeleteOnClose, true); _tikzDocument = new TikzDocument(this); - _tikzScene = new TikzScene(_tikzDocument, this); + + _tools = new ToolPalette(this); + addToolBar(_tools); + + _tikzScene = new TikzScene(_tikzDocument, _tools, this); ui->tikzView->setScene(_tikzScene); _fileName = ""; _pristine = true; + + // TODO: check if each window should have a menu + _menu = new MainMenu(); + _menu->setParent(this); + + setMenuBar(_menu); + // initially, the source view should be collapsed QList<int> sz = ui->splitter->sizes(); sz[0] = sz[0] + sz[1]; @@ -59,7 +72,7 @@ void MainWindow::open(QString fileName) void MainWindow::closeEvent(QCloseEvent *event) { - //qDebug() << "got close event"; + qDebug() << "got close event"; QMainWindow::closeEvent(event); } diff --git a/src/gui/mainwindow.h b/src/gui/mainwindow.h index 8adf1bc..ba680b0 100644 --- a/src/gui/mainwindow.h +++ b/src/gui/mainwindow.h @@ -9,6 +9,8 @@ #include "tikzview.h" #include "graph.h" #include "tikzdocument.h" +#include "mainmenu.h" +#include "toolpalette.h" #include <QMainWindow> #include <QGraphicsView> @@ -38,6 +40,8 @@ protected: private: TikzScene *_tikzScene; TikzDocument *_tikzDocument; + MainMenu *_menu; + ToolPalette *_tools; Ui::MainWindow *ui; QString _fileName; bool _pristine; diff --git a/src/gui/mainwindow.ui b/src/gui/mainwindow.ui index 56a5c2d..137d6cf 100644 --- a/src/gui/mainwindow.ui +++ b/src/gui/mainwindow.ui @@ -7,13 +7,19 @@ <x>0</x> <y>0</y> <width>640</width> - <height>480</height> + <height>580</height> </rect> </property> <property name="windowTitle"> <string>TikZiT - untitled</string> </property> <widget class="QWidget" name="centralWidget"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Expanding" vsizetype="Preferred"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> <layout class="QVBoxLayout" name="verticalLayout"> <property name="leftMargin"> <number>0</number> diff --git a/src/gui/propertypalette.cpp b/src/gui/propertypalette.cpp index b06e866..3e4ba88 100644 --- a/src/gui/propertypalette.cpp +++ b/src/gui/propertypalette.cpp @@ -22,7 +22,7 @@ PropertyPalette::PropertyPalette(QWidget *parent) : d->setProperty("key 2", "value 2"); //QModelIndex i = d->index(0,0); - ui->treeView->setModel(d); + //ui->treeView->setModel(d); QSettings settings("tikzit", "tikzit"); QVariant geom = settings.value("property-palette-geometry"); diff --git a/src/gui/tikzscene.cpp b/src/gui/tikzscene.cpp index 746e9dc..a3dd8ce 100644 --- a/src/gui/tikzscene.cpp +++ b/src/gui/tikzscene.cpp @@ -8,8 +8,8 @@ #include <QDebug> -TikzScene::TikzScene(TikzDocument *tikzDocument, QObject *parent) : - QGraphicsScene(parent), _tikzDocument(tikzDocument) +TikzScene::TikzScene(TikzDocument *tikzDocument, ToolPalette *tools, QObject *parent) : + QGraphicsScene(parent), _tikzDocument(tikzDocument), _tools(tools) { _modifyEdgeItem = 0; _edgeStartNodeItem = 0; @@ -73,7 +73,7 @@ void TikzScene::mousePressEvent(QGraphicsSceneMouseEvent *event) qreal cpR = GLOBAL_SCALEF * (0.05); qreal cpR2 = cpR * cpR; - switch (tikzit->toolPalette()->currentTool()) { + switch (_tools->currentTool()) { case ToolPalette::SELECT: // check if we grabbed a control point of an edge foreach (QGraphicsItem *gi, selectedItems()) { @@ -145,8 +145,10 @@ void TikzScene::mouseMoveEvent(QGraphicsSceneMouseEvent *event) { // current mouse position, in scene coordinates QPointF mousePos = event->scenePos(); + QRectF rb = views()[0]->rubberBandRect(); + invalidate(-800,-800,1600,1600); - switch (tikzit->toolPalette()->currentTool()) { + switch (_tools->currentTool()) { case ToolPalette::SELECT: if (_modifyEdgeItem != 0) { Edge *e = _modifyEdgeItem->edge(); @@ -262,7 +264,7 @@ void TikzScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) // current mouse position, in scene coordinates QPointF mousePos = event->scenePos(); - switch (tikzit->toolPalette()->currentTool()) { + switch (_tools->currentTool()) { case ToolPalette::SELECT: if (_modifyEdgeItem != 0) { // finished dragging a control point @@ -361,6 +363,18 @@ void TikzScene::keyReleaseEvent(QKeyEvent *event) } } +void TikzScene::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) +{ + QPointF mousePos = event->scenePos(); + foreach (QGraphicsItem *gi, items(mousePos)) { + if (EdgeItem *ei = dynamic_cast<EdgeItem*>(gi)) { + ChangeEdgeModeCommand *cmd = new ChangeEdgeModeCommand(this, ei->edge()); + _tikzDocument->undoStack()->push(cmd); + break; + } + } +} + void TikzScene::getSelection(QSet<Node *> &selNodes, QSet<Edge *> &selEdges) { foreach (QGraphicsItem *gi, selectedItems()) { diff --git a/src/gui/tikzscene.h b/src/gui/tikzscene.h index 5e236d7..cb684b2 100644 --- a/src/gui/tikzscene.h +++ b/src/gui/tikzscene.h @@ -10,6 +10,7 @@ #include "nodeitem.h" #include "edgeitem.h" #include "tikzdocument.h" +#include "toolpalette.h" #include <QWidget> #include <QGraphicsScene> @@ -23,7 +24,7 @@ class TikzScene : public QGraphicsScene { Q_OBJECT public: - TikzScene(TikzDocument *tikzDocument, QObject *parent); + TikzScene(TikzDocument *tikzDocument, ToolPalette *tools, QObject *parent); ~TikzScene(); Graph *graph(); QMap<Node*,NodeItem*> &nodeItems(); @@ -42,8 +43,10 @@ protected: void mouseMoveEvent(QGraphicsSceneMouseEvent *event) override; void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override; void keyReleaseEvent(QKeyEvent *event) override; + void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) override; private: TikzDocument *_tikzDocument; + ToolPalette *_tools; QMap<Node*,NodeItem*> _nodeItems; QMap<Edge*,EdgeItem*> _edgeItems; QGraphicsLineItem *_drawEdgeItem; diff --git a/src/gui/tikzview.cpp b/src/gui/tikzview.cpp index fe6c401..b8ae1c0 100644 --- a/src/gui/tikzview.cpp +++ b/src/gui/tikzview.cpp @@ -2,6 +2,7 @@ #include "tikzit.h" #include <QDebug> +#include <QScrollBar> TikzView::TikzView(QWidget *parent) : QGraphicsView(parent) { diff --git a/src/gui/toolpalette.cpp b/src/gui/toolpalette.cpp index 3c08bce..430df3f 100644 --- a/src/gui/toolpalette.cpp +++ b/src/gui/toolpalette.cpp @@ -13,14 +13,14 @@ ToolPalette::ToolPalette(QWidget *parent) : | Qt::WindowDoesNotAcceptFocus); setOrientation(Qt::Vertical); setFocusPolicy(Qt::NoFocus); - setGeometry(100,200,30,195); + //setGeometry(100,200,30,195); tools = new QActionGroup(this); - select = new QAction(QIcon(":/images/select-rectangular.png"), "Select"); - vertex = new QAction(QIcon(":/images/draw-ellipse.png"), "Add Vertex"); - edge = new QAction(QIcon(":/images/draw-path.png"), "Add Edge"); - crop = new QAction(QIcon(":/images/transform-crop-and-resize.png"), "Bounding Box"); + select = new QAction(QIcon(":/images/Inkscape_icons_edit_select_all.svg"), "Select"); + vertex = new QAction(QIcon(":/images/Inkscape_icons_draw_ellipse.svg"), "Add Vertex"); + edge = new QAction(QIcon(":/images/Inkscape_icons_draw_path.svg"), "Add Edge"); + crop = new QAction(QIcon(":/images/Inkscape_icons_draw_rectangle.svg"), "Bounding Box"); tools->addAction(select); tools->addAction(vertex); diff --git a/src/gui/undocommands.cpp b/src/gui/undocommands.cpp index 0fb235d..9c6a9c3 100644 --- a/src/gui/undocommands.cpp +++ b/src/gui/undocommands.cpp @@ -183,4 +183,26 @@ void AddEdgeCommand::redo() EdgeItem *ei = new EdgeItem(_edge); _scene->edgeItems().insert(_edge, ei); _scene->addItem(ei); + + // edges should always be stacked below nodes + if (!_scene->graph()->nodes().isEmpty()) { + ei->stackBefore(_scene->nodeItems()[_scene->graph()->nodes().first()]); + } +} + +ChangeEdgeModeCommand::ChangeEdgeModeCommand(TikzScene *scene, Edge *edge) : + _scene(scene), _edge(edge) +{ +} + +void ChangeEdgeModeCommand::undo() +{ + _edge->setBasicBendMode(!_edge->basicBendMode()); + _scene->edgeItems()[_edge]->readPos(); +} + +void ChangeEdgeModeCommand::redo() +{ + _edge->setBasicBendMode(!_edge->basicBendMode()); + _scene->edgeItems()[_edge]->readPos(); } diff --git a/src/gui/undocommands.h b/src/gui/undocommands.h index 9032274..eea39ae 100644 --- a/src/gui/undocommands.h +++ b/src/gui/undocommands.h @@ -90,4 +90,15 @@ private: Edge *_edge; }; +class ChangeEdgeModeCommand : public QUndoCommand +{ +public: + explicit ChangeEdgeModeCommand(TikzScene *scene, Edge *edge); + void undo() override; + void redo() override; +private: + TikzScene *_scene; + Edge *_edge; +}; + #endif // UNDOCOMMANDS_H diff --git a/src/main.cpp b/src/main.cpp index 6b14549..96069ef 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -10,8 +10,13 @@ #include <QMenuBar> + + int main(int argc, char *argv[]) { + QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); + QCoreApplication::setAttribute(Qt::AA_UseHighDpiPixmaps); + //QCoreApplication::setAttribute(Qt::AA_DisableHighDpiScaling); QApplication a(argc, argv); a.setQuitOnLastWindowClosed(false); tikzit = new Tikzit(); diff --git a/src/tikzit.cpp b/src/tikzit.cpp index a488b8a..746268c 100644 --- a/src/tikzit.cpp +++ b/src/tikzit.cpp @@ -22,8 +22,8 @@ Tikzit::Tikzit() loadStyles(); - _toolPalette->show(); - _propertyPalette->show(); + //_toolPalette->show(); + //_propertyPalette->show(); _stylePalette->show(); _windows << new MainWindow(); @@ -73,8 +73,11 @@ void Tikzit::removeWindow(MainWindow *w) { _windows.removeAll(w); if (_activeWindow == w) { - if (_windows.isEmpty()) _activeWindow = 0; - else _activeWindow = _windows[0]; + if (_windows.isEmpty()) { + _activeWindow = 0; + // TODO: check if we should quit when last window closed + quit(); + } else _activeWindow = _windows[0]; } } @@ -105,3 +108,9 @@ void Tikzit::open() } } } + +void Tikzit::quit() +{ + _stylePalette->close(); + QApplication::quit(); +} diff --git a/src/tikzit.h b/src/tikzit.h index a241a78..07878aa 100644 --- a/src/tikzit.h +++ b/src/tikzit.h @@ -76,6 +76,7 @@ public: void newDoc(); void open(); + void quit(); private: // void createMenu(); |