summaryrefslogtreecommitdiff
path: root/tikzit
diff options
context:
space:
mode:
authorAleks Kissinger <aleks0@gmail.com>2017-12-18 15:29:33 +0000
committerAleks Kissinger <aleks0@gmail.com>2017-12-18 15:29:33 +0000
commit2bf85f71dc07b2c4785b9408e3c426ccaab55b74 (patch)
tree29ed038fa42f7ba5f11a2af305b6c350149a1a9b /tikzit
parent5816cd5d5e3edf7ee7a7273c7c3a3d907dc54a4a (diff)
introduced some comments for source navigation
Diffstat (limited to 'tikzit')
-rw-r--r--tikzit/src/data/graph.h4
-rw-r--r--tikzit/src/data/tikzdocument.h4
-rw-r--r--tikzit/src/gui/edgeitem.h4
-rw-r--r--tikzit/src/gui/mainwindow.h4
-rw-r--r--tikzit/src/gui/nodeitem.cpp25
-rw-r--r--tikzit/src/gui/nodeitem.h5
-rw-r--r--tikzit/src/gui/propertypalette.h4
-rw-r--r--tikzit/src/gui/tikzscene.cpp61
-rw-r--r--tikzit/src/gui/tikzscene.h3
-rw-r--r--tikzit/src/gui/tikzview.h5
-rw-r--r--tikzit/src/gui/toolpalette.cpp9
-rw-r--r--tikzit/src/gui/toolpalette.h12
-rw-r--r--tikzit/src/gui/undocommands.cpp16
-rw-r--r--tikzit/src/gui/undocommands.h22
-rw-r--r--tikzit/src/tikzit.cpp3
-rw-r--r--tikzit/src/tikzit.h3
-rw-r--r--tikzit/tikzit.pro6
17 files changed, 170 insertions, 20 deletions
diff --git a/tikzit/src/data/graph.h b/tikzit/src/data/graph.h
index 37bbff9..952b8b4 100644
--- a/tikzit/src/data/graph.h
+++ b/tikzit/src/data/graph.h
@@ -1,3 +1,7 @@
+/**
+ * A tikz graph. This serves as the model in the MVC (Graph, TikzView, TikzScene).
+ */
+
#ifndef GRAPH_H
#define GRAPH_H
diff --git a/tikzit/src/data/tikzdocument.h b/tikzit/src/data/tikzdocument.h
index 0e97b13..7d81742 100644
--- a/tikzit/src/data/tikzdocument.h
+++ b/tikzit/src/data/tikzdocument.h
@@ -1,3 +1,7 @@
+/**
+ * Contains a tikz Graph, source code, file info, and undo stack.
+ */
+
#ifndef TIKZDOCUMENT_H
#define TIKZDOCUMENT_H
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
diff --git a/tikzit/src/tikzit.cpp b/tikzit/src/tikzit.cpp
index 9abf33e..0c9fdb1 100644
--- a/tikzit/src/tikzit.cpp
+++ b/tikzit/src/tikzit.cpp
@@ -6,6 +6,9 @@
// application-level instance of Tikzit
Tikzit *tikzit;
+// font to use for node labels
+QFont Tikzit::LABEL_FONT("Courrier", 9);
+
Tikzit::Tikzit()
{
_activeWindow = 0;
diff --git a/tikzit/src/tikzit.h b/tikzit/src/tikzit.h
index 74a7ea6..252bf35 100644
--- a/tikzit/src/tikzit.h
+++ b/tikzit/src/tikzit.h
@@ -11,6 +11,7 @@
#include <QPointF>
#include <QMenuBar>
#include <QMainWindow>
+#include <QFont>
// Number of pixels between (0,0) and (1,0) at 100% zoom level. This should be
// divisible by 8 to avoid rounding errors with e.g. grid-snapping.
@@ -50,6 +51,8 @@ public:
void removeWindow(MainWindow *w);
NodeStyle nodeStyle(QString name);
+ static QFont LABEL_FONT;
+
private:
void createMenu();
void loadStyles();
diff --git a/tikzit/tikzit.pro b/tikzit/tikzit.pro
index 1d2a866..aa18381 100644
--- a/tikzit/tikzit.pro
+++ b/tikzit/tikzit.pro
@@ -45,7 +45,8 @@ SOURCES += src/gui/mainwindow.cpp \
src/tikzit.cpp \
src/data/nodestyle.cpp \
src/gui/commands.cpp \
- src/data/tikzdocument.cpp
+ src/data/tikzdocument.cpp \
+ src/gui/undocommands.cpp
HEADERS += src/gui/mainwindow.h \
src/gui/toolpalette.h \
@@ -64,7 +65,8 @@ HEADERS += src/gui/mainwindow.h \
src/gui/edgeitem.h \
src/data/nodestyle.h \
src/gui/commands.h \
- src/data/tikzdocument.h
+ src/data/tikzdocument.h \
+ src/gui/undocommands.h
FORMS += src/gui/mainwindow.ui \
src/gui/propertypalette.ui \