diff options
author | Aleks Kissinger <aleks0@gmail.com> | 2017-12-18 15:29:33 +0000 |
---|---|---|
committer | Aleks Kissinger <aleks0@gmail.com> | 2017-12-18 15:29:33 +0000 |
commit | 2bf85f71dc07b2c4785b9408e3c426ccaab55b74 (patch) | |
tree | 29ed038fa42f7ba5f11a2af305b6c350149a1a9b /tikzit/src/gui | |
parent | 5816cd5d5e3edf7ee7a7273c7c3a3d907dc54a4a (diff) |
introduced some comments for source navigation
Diffstat (limited to 'tikzit/src/gui')
-rw-r--r-- | tikzit/src/gui/edgeitem.h | 4 | ||||
-rw-r--r-- | tikzit/src/gui/mainwindow.h | 4 | ||||
-rw-r--r-- | tikzit/src/gui/nodeitem.cpp | 25 | ||||
-rw-r--r-- | tikzit/src/gui/nodeitem.h | 5 | ||||
-rw-r--r-- | tikzit/src/gui/propertypalette.h | 4 | ||||
-rw-r--r-- | tikzit/src/gui/tikzscene.cpp | 61 | ||||
-rw-r--r-- | tikzit/src/gui/tikzscene.h | 3 | ||||
-rw-r--r-- | tikzit/src/gui/tikzview.h | 5 | ||||
-rw-r--r-- | tikzit/src/gui/toolpalette.cpp | 9 | ||||
-rw-r--r-- | tikzit/src/gui/toolpalette.h | 12 | ||||
-rw-r--r-- | tikzit/src/gui/undocommands.cpp | 16 | ||||
-rw-r--r-- | tikzit/src/gui/undocommands.h | 22 |
12 files changed, 152 insertions, 18 deletions
diff --git a/tikzit/src/gui/edgeitem.h b/tikzit/src/gui/edgeitem.h index ed04772..5bdf3be 100644 --- a/tikzit/src/gui/edgeitem.h +++ b/tikzit/src/gui/edgeitem.h @@ -1,3 +1,7 @@ +/** + * A QGraphicsItem that handles drawing a single edge. + */ + #ifndef EDGEITEM_H #define EDGEITEM_H diff --git a/tikzit/src/gui/mainwindow.h b/tikzit/src/gui/mainwindow.h index 66df23f..4af3357 100644 --- a/tikzit/src/gui/mainwindow.h +++ b/tikzit/src/gui/mainwindow.h @@ -1,3 +1,7 @@ +/** + * A top-level window, which contains a single TikzDocument. + */ + #ifndef MAINWINDOW_H #define MAINWINDOW_H diff --git a/tikzit/src/gui/nodeitem.cpp b/tikzit/src/gui/nodeitem.cpp index 6e21ea4..bf4830b 100644 --- a/tikzit/src/gui/nodeitem.cpp +++ b/tikzit/src/gui/nodeitem.cpp @@ -25,6 +25,16 @@ void NodeItem::syncPos() setPos(toScreen(_node->point())); } +QRectF NodeItem::labelRect() const { + QString label = _node->label(); + //QFont f("Courier", 9); + QFontMetrics fm(Tikzit::LABEL_FONT); + + QRectF rect = fm.boundingRect(label); + //rect.adjust(-2,-2,2,2); + rect.moveCenter(QPointF(0,0)); + return rect; +} void NodeItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) { @@ -50,15 +60,7 @@ void NodeItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, } if (_node->label() != "") { - QString label = _node->label(); - QFont f("Monaco", 9); - QFontMetrics fm(f); - int w = fm.width(label) + 4; - int h = fm.height() + 2; - - QRectF rect = fm.boundingRect(label); - rect.adjust(-2,-2,2,2); - rect.moveCenter(QPointF(0,0)); + QRectF rect = labelRect(); QPen pen(QColor(200,0,0,120)); QVector<qreal> d; d << 2.0 << 2.0; @@ -68,7 +70,7 @@ void NodeItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, painter->drawRect(rect); painter->setPen(QPen(Qt::black)); - painter->setFont(f); + painter->setFont(Tikzit::LABEL_FONT); painter->drawText(rect, Qt::AlignCenter, _node->label()); } @@ -93,7 +95,8 @@ QPainterPath NodeItem::shape() const QRectF NodeItem::boundingRect() const { - return shape().boundingRect().adjusted(-4,-4,4,4); + QRectF r = labelRect(); + return r.united(shape().boundingRect()).adjusted(-4,-4,4,4); } QVariant NodeItem::itemChange(GraphicsItemChange change, const QVariant &value) diff --git a/tikzit/src/gui/nodeitem.h b/tikzit/src/gui/nodeitem.h index 107871e..2228874 100644 --- a/tikzit/src/gui/nodeitem.h +++ b/tikzit/src/gui/nodeitem.h @@ -1,3 +1,7 @@ +/** + * A QGraphicsItem that handles drawing a single node. + */ + #ifndef NODEITEM_H #define NODEITEM_H @@ -19,6 +23,7 @@ public: QRectF boundingRect() const; private: Node *_node; + QRectF labelRect() const; }; #endif // NODEITEM_H diff --git a/tikzit/src/gui/propertypalette.h b/tikzit/src/gui/propertypalette.h index f2f1955..7910d70 100644 --- a/tikzit/src/gui/propertypalette.h +++ b/tikzit/src/gui/propertypalette.h @@ -1,3 +1,7 @@ +/** + * Enables the user to edit properties of the graph, as well as the selected node/edge. + */ + #ifndef PROPERTYPALETTE_H #define PROPERTYPALETTE_H diff --git a/tikzit/src/gui/tikzscene.cpp b/tikzit/src/gui/tikzscene.cpp index 058835d..cd88f4e 100644 --- a/tikzit/src/gui/tikzscene.cpp +++ b/tikzit/src/gui/tikzscene.cpp @@ -1,3 +1,8 @@ +/** + * Manage the scene, which contains a single Graph, and respond to user input. This serves as + * the controller for the MVC (Graph, TikzView, TikzScene). + */ + #include "tikzit.h" #include "tikzscene.h" @@ -9,7 +14,9 @@ TikzScene::TikzScene(Graph *graph, QObject *parent) : QGraphicsScene(parent), _graph(graph) { +} +TikzScene::~TikzScene() { } Graph *TikzScene::graph() const @@ -52,23 +59,65 @@ void TikzScene::graphReplaced() void TikzScene::mousePressEvent(QGraphicsSceneMouseEvent *event) { - // TODO: check if we grabbed a control point + QPointF mousePos(event->buttonDownScenePos(Qt::LeftButton).x(), + event->buttonDownScenePos(Qt::LeftButton).y()); - QGraphicsScene::mousePressEvent(event); + + switch (tikzit->toolPalette()->currentTool()) { + case ToolPalette::SELECT: + // TODO: check if we grabbed a control point + QGraphicsScene::mousePressEvent(event); + if (!selectedItems().empty() && !items(mousePos).empty()) { + _oldNodePositions = new QHash<NodeItem*,QPointF>(); + for (QGraphicsItem *gi : selectedItems()) { + if (NodeItem *ni = dynamic_cast<NodeItem*>(gi)) { + _oldNodePositions-> + } + } + qDebug() << "I am dragging"; + } + break; + case ToolPalette::VERTEX: + break; + case ToolPalette::EDGE: + break; + case ToolPalette::CROP: + break; + } } void TikzScene::mouseMoveEvent(QGraphicsSceneMouseEvent *event) { - //foreach (Edge *e, _graph->edges()) { e->updateControls(); } + switch (tikzit->toolPalette()->currentTool()) { + case ToolPalette::SELECT: + QGraphicsScene::mouseMoveEvent(event); + break; + case ToolPalette::VERTEX: + break; + case ToolPalette::EDGE: + break; + case ToolPalette::CROP: + break; + } + + // TODO: only sync edges that change foreach (EdgeItem *ei, edgeItems) { ei->edge()->updateControls(); ei->syncPos(); } - - QGraphicsScene::mouseMoveEvent(event); } void TikzScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) { - QGraphicsScene::mouseReleaseEvent(event); + switch (tikzit->toolPalette()->currentTool()) { + case ToolPalette::SELECT: + QGraphicsScene::mouseReleaseEvent(event); + break; + case ToolPalette::VERTEX: + break; + case ToolPalette::EDGE: + break; + case ToolPalette::CROP: + break; + } } diff --git a/tikzit/src/gui/tikzscene.h b/tikzit/src/gui/tikzscene.h index 2c77389..e0e75c1 100644 --- a/tikzit/src/gui/tikzscene.h +++ b/tikzit/src/gui/tikzscene.h @@ -18,6 +18,7 @@ class TikzScene : public QGraphicsScene Q_OBJECT public: TikzScene(Graph *graph, QObject *parent); + ~TikzScene(); Graph *graph() const; void setGraph(Graph *graph); public slots: @@ -30,7 +31,7 @@ private: Graph *_graph; QVector<NodeItem*> nodeItems; QVector<EdgeItem*> edgeItems; - + QHash<Node*,QPointF> *_oldNodePositions; }; #endif // TIKZSCENE_H diff --git a/tikzit/src/gui/tikzview.h b/tikzit/src/gui/tikzview.h index b16e0df..6d09b21 100644 --- a/tikzit/src/gui/tikzview.h +++ b/tikzit/src/gui/tikzview.h @@ -1,3 +1,8 @@ +/** + * Display a Graph, and manage any user input that purely changes the view (e.g. Zoom). This + * serves as the view in the MVC (Graph, TikzView, TikzScene). + */ + #ifndef TIKZVIEW_H #define TIKZVIEW_H diff --git a/tikzit/src/gui/toolpalette.cpp b/tikzit/src/gui/toolpalette.cpp index 3ee2106..3c08bce 100644 --- a/tikzit/src/gui/toolpalette.cpp +++ b/tikzit/src/gui/toolpalette.cpp @@ -39,3 +39,12 @@ ToolPalette::ToolPalette(QWidget *parent) : addAction(crop); } +ToolPalette::Tool ToolPalette::currentTool() const +{ + QAction *a = tools->checkedAction(); + if (a == vertex) return VERTEX; + else if (a == edge) return EDGE; + else if (a == crop) return CROP; + else return SELECT; +} + diff --git a/tikzit/src/gui/toolpalette.h b/tikzit/src/gui/toolpalette.h index 05b2e12..ba6aed5 100644 --- a/tikzit/src/gui/toolpalette.h +++ b/tikzit/src/gui/toolpalette.h @@ -1,3 +1,7 @@ +/** + * A small window that lets the user select the current editing tool. + */ + #ifndef TOOLPALETTE_H #define TOOLPALETTE_H @@ -11,6 +15,14 @@ class ToolPalette : public QToolBar Q_OBJECT public: ToolPalette(QWidget *parent = 0); + enum Tool { + SELECT, + VERTEX, + EDGE, + CROP + }; + + Tool currentTool() const; private: QActionGroup *tools; QAction *select; diff --git a/tikzit/src/gui/undocommands.cpp b/tikzit/src/gui/undocommands.cpp new file mode 100644 index 0000000..38f7569 --- /dev/null +++ b/tikzit/src/gui/undocommands.cpp @@ -0,0 +1,16 @@ +#include "undocommands.h" + +MoveCommand::MoveCommand(TikzScene *scene, QUndoCommand *parent) : QUndoCommand(parent) +{ + _scene = scene; +} + +void MoveCommand::undo() +{ + +} + +void MoveCommand::redo() +{ + +} diff --git a/tikzit/src/gui/undocommands.h b/tikzit/src/gui/undocommands.h new file mode 100644 index 0000000..bbdf6c3 --- /dev/null +++ b/tikzit/src/gui/undocommands.h @@ -0,0 +1,22 @@ +/** + * These classes store the data required to undo/redo a single UI action. + */ + +#ifndef UNDOCOMMANDS_H +#define UNDOCOMMANDS_H + +#include "tikzscene.h" + +#include <QUndoCommand> + +class MoveCommand : public QUndoCommand +{ +public: + explicit MoveCommand(TikzScene *scene, QUndoCommand *parent = 0); + void undo() override; + void redo() override; +private: + TikzScene *_scene; +}; + +#endif // UNDOCOMMANDS_H |