diff options
author | Aleks Kissinger <aleks0@gmail.com> | 2017-12-05 17:55:04 +0000 |
---|---|---|
committer | Aleks Kissinger <aleks0@gmail.com> | 2017-12-05 17:55:04 +0000 |
commit | 5816cd5d5e3edf7ee7a7273c7c3a3d907dc54a4a (patch) | |
tree | 1b9022c3671225f06151fb9bbb5cb92dcb0e93a7 /tikzit/src/gui | |
parent | cb322a3acee9debf40c48ad1e3fb4458b0f51b7f (diff) |
Qt
Diffstat (limited to 'tikzit/src/gui')
-rw-r--r-- | tikzit/src/gui/commands.cpp | 0 | ||||
-rw-r--r-- | tikzit/src/gui/commands.h | 4 | ||||
-rw-r--r-- | tikzit/src/gui/edgeitem.cpp | 39 | ||||
-rw-r--r-- | tikzit/src/gui/edgeitem.h | 1 | ||||
-rw-r--r-- | tikzit/src/gui/mainmenu.ui | 146 | ||||
-rw-r--r-- | tikzit/src/gui/mainwindow.cpp | 36 | ||||
-rw-r--r-- | tikzit/src/gui/mainwindow.h | 3 | ||||
-rw-r--r-- | tikzit/src/gui/nodeitem.cpp | 18 | ||||
-rw-r--r-- | tikzit/src/gui/nodeitem.h | 1 | ||||
-rw-r--r-- | tikzit/src/gui/propertypalette.cpp | 1 | ||||
-rw-r--r-- | tikzit/src/gui/tikzscene.cpp | 6 |
11 files changed, 215 insertions, 40 deletions
diff --git a/tikzit/src/gui/commands.cpp b/tikzit/src/gui/commands.cpp new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/tikzit/src/gui/commands.cpp diff --git a/tikzit/src/gui/commands.h b/tikzit/src/gui/commands.h new file mode 100644 index 0000000..73bfaa7 --- /dev/null +++ b/tikzit/src/gui/commands.h @@ -0,0 +1,4 @@ +#ifndef COMMANDS_H +#define COMMANDS_H + +#endif // COMMANDS_H diff --git a/tikzit/src/gui/edgeitem.cpp b/tikzit/src/gui/edgeitem.cpp index f45493d..cb275a5 100644 --- a/tikzit/src/gui/edgeitem.cpp +++ b/tikzit/src/gui/edgeitem.cpp @@ -14,8 +14,16 @@ EdgeItem::EdgeItem(Edge *edge) setPen(pen); _cp1Item = new QGraphicsEllipseItem(this); _cp1Item->setParentItem(this); + _cp1Item->setRect(GLOBAL_SCALEF * (-0.05), GLOBAL_SCALEF * (-0.05), + GLOBAL_SCALEF * 0.1, GLOBAL_SCALEF * 0.1); + _cp1Item->setVisible(false); + _cp2Item = new QGraphicsEllipseItem(this); _cp2Item->setParentItem(this); + _cp2Item->setRect(GLOBAL_SCALEF * (-0.05), GLOBAL_SCALEF * (-0.05), + GLOBAL_SCALEF * 0.1, GLOBAL_SCALEF * 0.1); + _cp2Item->setVisible(false); + syncPos(); } @@ -31,9 +39,8 @@ void EdgeItem::syncPos() toScreen(_edge->head())); setPath(path); - float r = GLOBAL_SCALEF * 0.05; - //painter->drawEllipse(toScreen(_edge->cp1()), r, r); - //painter->drawEllipse(toScreen(_edge->cp2()), r, r); + _cp1Item->setPos(toScreen(_edge->cp1())); + _cp2Item->setPos(toScreen(_edge->cp2())); } void EdgeItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) @@ -43,8 +50,6 @@ void EdgeItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, painter->setBrush(Qt::NoBrush); painter->drawPath(path()); - - if (isSelected()) { QColor draw; QColor draw1; @@ -72,18 +77,34 @@ void EdgeItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, painter->drawLine(toScreen(_edge->tail()), toScreen(_edge->cp1())); painter->drawLine(toScreen(_edge->head()), toScreen(_edge->cp2())); - r = GLOBAL_SCALEF * 0.05; - painter->drawEllipse(toScreen(_edge->cp1()), r, r); - painter->drawEllipse(toScreen(_edge->cp2()), r, r); + //painter->drawEllipse(toScreen(_edge->cp1()), r, r); + //painter->drawEllipse(toScreen(_edge->cp2()), r, r); + + _cp1Item->setPen(QPen(draw)); + _cp1Item->setBrush(QBrush(fill)); + _cp1Item->setVisible(true); + _cp2Item->setPen(QPen(draw)); + _cp2Item->setBrush(QBrush(fill)); + _cp2Item->setVisible(true); + + r = GLOBAL_SCALEF * 0.05; painter->setPen(QPen(Qt::black)); painter->setBrush(QBrush(QColor(255,255,255,200))); painter->drawEllipse(toScreen(_edge->mid()), r, r); + } else { + _cp1Item->setVisible(false); + _cp2Item->setVisible(false); } } QRectF EdgeItem::boundingRect() const { float r = GLOBAL_SCALEF * (_edge->cpDist() + 0.2); - return QGraphicsPathItem::boundingRect().adjusted(-r,-r,r,r); + return shape().boundingRect().adjusted(-r,-r,r,r); +} + +Edge *EdgeItem::edge() const +{ + return _edge; } diff --git a/tikzit/src/gui/edgeitem.h b/tikzit/src/gui/edgeitem.h index 935138b..ed04772 100644 --- a/tikzit/src/gui/edgeitem.h +++ b/tikzit/src/gui/edgeitem.h @@ -18,6 +18,7 @@ public: void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); QRectF boundingRect() const; + Edge *edge() const; private: Edge *_edge; diff --git a/tikzit/src/gui/mainmenu.ui b/tikzit/src/gui/mainmenu.ui new file mode 100644 index 0000000..d3eed0a --- /dev/null +++ b/tikzit/src/gui/mainmenu.ui @@ -0,0 +1,146 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>MainMenu</class> + <widget class="QMenuBar" name="MainMenu"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>476</width> + <height>22</height> + </rect> + </property> + <widget class="QMenu" name="menuFile"> + <property name="title"> + <string>File</string> + </property> + <addaction name="actionNew"/> + <addaction name="actionOpen"/> + <addaction name="separator"/> + <addaction name="actionClose"/> + <addaction name="actionSave"/> + <addaction name="actionSave_As"/> + </widget> + <widget class="QMenu" name="menuEdit"> + <property name="title"> + <string>Edit</string> + </property> + <addaction name="actionUndo"/> + <addaction name="actionRedo"/> + <addaction name="separator"/> + <addaction name="actionCut"/> + <addaction name="actionCopy"/> + <addaction name="actionPase"/> + <addaction name="actionDelete"/> + <addaction name="separator"/> + <addaction name="actionSelect_All"/> + <addaction name="actionDeselect_All"/> + </widget> + <widget class="QMenu" name="menuTikz"> + <property name="title"> + <string>Tikz</string> + </property> + <addaction name="actionParse"/> + </widget> + <widget class="QMenu" name="menuView"> + <property name="title"> + <string>View</string> + </property> + <addaction name="actionZoom_In"/> + <addaction name="actionZoom_Out"/> + </widget> + <addaction name="menuFile"/> + <addaction name="menuEdit"/> + <addaction name="menuView"/> + <addaction name="menuTikz"/> + <action name="actionNew"> + <property name="text"> + <string>New...</string> + </property> + </action> + <action name="actionOpen"> + <property name="text"> + <string>Open...</string> + </property> + </action> + <action name="actionClose"> + <property name="text"> + <string>Close</string> + </property> + </action> + <action name="actionSave"> + <property name="text"> + <string>Save</string> + </property> + </action> + <action name="actionSave_As"> + <property name="text"> + <string>Save As...</string> + </property> + </action> + <action name="actionUndo"> + <property name="text"> + <string>Undo</string> + </property> + </action> + <action name="actionRedo"> + <property name="text"> + <string>Redo</string> + </property> + </action> + <action name="actionCut"> + <property name="text"> + <string>Cut</string> + </property> + </action> + <action name="actionCopy"> + <property name="text"> + <string>Copy</string> + </property> + </action> + <action name="actionPase"> + <property name="text"> + <string>Paste</string> + </property> + </action> + <action name="actionDelete"> + <property name="text"> + <string>Delete</string> + </property> + </action> + <action name="actionSelect_All"> + <property name="text"> + <string>Select All</string> + </property> + </action> + <action name="actionDeselect_All"> + <property name="text"> + <string>Deselect All</string> + </property> + </action> + <action name="actionParse"> + <property name="text"> + <string>Parse</string> + </property> + <property name="shortcut"> + <string>Ctrl+T</string> + </property> + </action> + <action name="actionZoom_In"> + <property name="text"> + <string>Zoom In</string> + </property> + <property name="shortcut"> + <string>Ctrl+=</string> + </property> + </action> + <action name="actionZoom_Out"> + <property name="text"> + <string>Zoom Out</string> + </property> + <property name="shortcut"> + <string>Ctrl+-</string> + </property> + </action> +</widget> +</ui> diff --git a/tikzit/src/gui/mainwindow.cpp b/tikzit/src/gui/mainwindow.cpp index 7d7ab04..980a312 100644 --- a/tikzit/src/gui/mainwindow.cpp +++ b/tikzit/src/gui/mainwindow.cpp @@ -21,8 +21,8 @@ MainWindow::MainWindow(QWidget *parent) : _numWindows++; ui->setupUi(this); setAttribute(Qt::WA_DeleteOnClose, true); - _graph = new Graph(this); - _tikzScene = new TikzScene(_graph, this); + _tikzDocument = new TikzDocument(this); + _tikzScene = new TikzScene(_tikzDocument->graph(), this); ui->tikzView->setScene(_tikzScene); _fileName = ""; _pristine = true; @@ -41,39 +41,17 @@ MainWindow::~MainWindow() void MainWindow::open(QString fileName) { - _fileName = fileName; _pristine = false; - QFile file(fileName); - QFileInfo fi(file); - QSettings settings("tikzit", "tikzit"); - settings.setValue("previous-file-path", fi.absolutePath()); + _tikzDocument->open(fileName); + ui->tikzSource->setText(_tikzDocument->tikz()); - setWindowTitle("TiKZiT - " + fi.fileName()); - if (!file.open(QIODevice::ReadOnly)) { - QMessageBox::critical(this, tr("Error"), - tr("Could not open file")); - return; - } - - QTextStream in(&file); - QString tikz = in.readAll(); - file.close(); - - ui->tikzSource->setText(tikz); - - Graph *newGraph = new Graph(this); - TikzGraphAssembler ass(newGraph); - if (ass.parse(tikz)) { + if (_tikzDocument->parseSuccess()) { statusBar()->showMessage("TiKZ parsed successfully", 2000); - delete _graph; - _graph = newGraph; - foreach (Node *n, _graph->nodes()) n->attachStyle(); - foreach (Edge *e, _graph->edges()) e->updateControls(); - _tikzScene->setGraph(_graph); + setWindowTitle("TiKZiT - " + _tikzDocument->shortName()); + _tikzScene->setGraph(_tikzDocument->graph()); } else { statusBar()->showMessage("Cannot read TiKZ source"); - delete newGraph; } } diff --git a/tikzit/src/gui/mainwindow.h b/tikzit/src/gui/mainwindow.h index 2e52cd5..66df23f 100644 --- a/tikzit/src/gui/mainwindow.h +++ b/tikzit/src/gui/mainwindow.h @@ -4,6 +4,7 @@ #include "tikzscene.h" #include "tikzview.h" #include "graph.h" +#include "tikzdocument.h" #include <QMainWindow> #include <QGraphicsView> @@ -31,8 +32,8 @@ protected: void changeEvent(QEvent *event); private: TikzScene *_tikzScene; + TikzDocument *_tikzDocument; Ui::MainWindow *ui; - Graph *_graph; QString _fileName; bool _pristine; int _windowId; diff --git a/tikzit/src/gui/nodeitem.cpp b/tikzit/src/gui/nodeitem.cpp index d91bfd6..6e21ea4 100644 --- a/tikzit/src/gui/nodeitem.cpp +++ b/tikzit/src/gui/nodeitem.cpp @@ -1,7 +1,10 @@ #include "tikzit.h" #include "nodeitem.h" +#include "tikzscene.h" +#include <cmath> #include <QPen> +#include <QApplication> #include <QBrush> #include <QDebug> #include <QFont> @@ -13,6 +16,7 @@ NodeItem::NodeItem(Node *node) _node = node; setFlag(QGraphicsItem::ItemIsSelectable); setFlag(QGraphicsItem::ItemIsMovable); + setFlag(QGraphicsItem::ItemSendsGeometryChanges); syncPos(); } @@ -91,3 +95,17 @@ QRectF NodeItem::boundingRect() const { return shape().boundingRect().adjusted(-4,-4,4,4); } + +QVariant NodeItem::itemChange(GraphicsItemChange change, const QVariant &value) +{ + if (change == ItemPositionChange) { + QPointF newPos = value.toPointF(); + int gridSize = GLOBAL_SCALE / 8; + QPointF gridPos(round(newPos.x()/gridSize)*gridSize, round(newPos.y()/gridSize)*gridSize); + _node->setPoint(fromScreen(gridPos)); + + return gridPos; + } else { + return QGraphicsItem::itemChange(change, value); + } +} diff --git a/tikzit/src/gui/nodeitem.h b/tikzit/src/gui/nodeitem.h index 867d8a3..107871e 100644 --- a/tikzit/src/gui/nodeitem.h +++ b/tikzit/src/gui/nodeitem.h @@ -14,6 +14,7 @@ public: NodeItem(Node *node); void syncPos(); void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); + QVariant itemChange(GraphicsItemChange change, const QVariant &value); QPainterPath shape() const; QRectF boundingRect() const; private: diff --git a/tikzit/src/gui/propertypalette.cpp b/tikzit/src/gui/propertypalette.cpp index ea906a7..5fc763f 100644 --- a/tikzit/src/gui/propertypalette.cpp +++ b/tikzit/src/gui/propertypalette.cpp @@ -12,7 +12,6 @@ PropertyPalette::PropertyPalette(QWidget *parent) : ui(new Ui::PropertyPalette) { setWindowFlags(Qt::Window - | Qt::WindowStaysOnTopHint | Qt::CustomizeWindowHint | Qt::WindowTitleHint); //setFocusPolicy(Qt::NoFocus); diff --git a/tikzit/src/gui/tikzscene.cpp b/tikzit/src/gui/tikzscene.cpp index cf7cde5..058835d 100644 --- a/tikzit/src/gui/tikzscene.cpp +++ b/tikzit/src/gui/tikzscene.cpp @@ -59,6 +59,12 @@ void TikzScene::mousePressEvent(QGraphicsSceneMouseEvent *event) void TikzScene::mouseMoveEvent(QGraphicsSceneMouseEvent *event) { + //foreach (Edge *e, _graph->edges()) { e->updateControls(); } + foreach (EdgeItem *ei, edgeItems) { + ei->edge()->updateControls(); + ei->syncPos(); + } + QGraphicsScene::mouseMoveEvent(event); } |