From 738ecbd5fad2b46836bfd6a94aeebf165ae2bbca Mon Sep 17 00:00:00 2001 From: Aleks Kissinger Date: Thu, 4 Jan 2018 16:00:52 +0100 Subject: relocated source code to the root --- tikzit/src/gui/commands.cpp | 0 tikzit/src/gui/commands.h | 4 - tikzit/src/gui/edgeitem.cpp | 131 ------------- tikzit/src/gui/edgeitem.h | 36 ---- tikzit/src/gui/mainmenu.cpp | 96 ---------- tikzit/src/gui/mainmenu.h | 43 ----- tikzit/src/gui/mainmenu.ui | 187 ------------------ tikzit/src/gui/mainwindow.cpp | 99 ---------- tikzit/src/gui/mainwindow.h | 48 ----- tikzit/src/gui/mainwindow.ui | 199 ------------------- tikzit/src/gui/nodeitem.cpp | 124 ------------ tikzit/src/gui/nodeitem.h | 32 ---- tikzit/src/gui/propertypalette.cpp | 43 ----- tikzit/src/gui/propertypalette.h | 28 --- tikzit/src/gui/propertypalette.ui | 30 --- tikzit/src/gui/tikzscene.cpp | 384 ------------------------------------- tikzit/src/gui/tikzscene.h | 62 ------ tikzit/src/gui/tikzview.cpp | 84 -------- tikzit/src/gui/tikzview.h | 32 ---- tikzit/src/gui/toolpalette.cpp | 50 ----- tikzit/src/gui/toolpalette.h | 34 ---- tikzit/src/gui/undocommands.cpp | 162 ---------------- tikzit/src/gui/undocommands.h | 80 -------- 23 files changed, 1988 deletions(-) delete mode 100644 tikzit/src/gui/commands.cpp delete mode 100644 tikzit/src/gui/commands.h delete mode 100644 tikzit/src/gui/edgeitem.cpp delete mode 100644 tikzit/src/gui/edgeitem.h delete mode 100644 tikzit/src/gui/mainmenu.cpp delete mode 100644 tikzit/src/gui/mainmenu.h delete mode 100644 tikzit/src/gui/mainmenu.ui delete mode 100644 tikzit/src/gui/mainwindow.cpp delete mode 100644 tikzit/src/gui/mainwindow.h delete mode 100644 tikzit/src/gui/mainwindow.ui delete mode 100644 tikzit/src/gui/nodeitem.cpp delete mode 100644 tikzit/src/gui/nodeitem.h delete mode 100644 tikzit/src/gui/propertypalette.cpp delete mode 100644 tikzit/src/gui/propertypalette.h delete mode 100644 tikzit/src/gui/propertypalette.ui delete mode 100644 tikzit/src/gui/tikzscene.cpp delete mode 100644 tikzit/src/gui/tikzscene.h delete mode 100644 tikzit/src/gui/tikzview.cpp delete mode 100644 tikzit/src/gui/tikzview.h delete mode 100644 tikzit/src/gui/toolpalette.cpp delete mode 100644 tikzit/src/gui/toolpalette.h delete mode 100644 tikzit/src/gui/undocommands.cpp delete mode 100644 tikzit/src/gui/undocommands.h (limited to 'tikzit/src/gui') diff --git a/tikzit/src/gui/commands.cpp b/tikzit/src/gui/commands.cpp deleted file mode 100644 index e69de29..0000000 diff --git a/tikzit/src/gui/commands.h b/tikzit/src/gui/commands.h deleted file mode 100644 index 73bfaa7..0000000 --- a/tikzit/src/gui/commands.h +++ /dev/null @@ -1,4 +0,0 @@ -#ifndef COMMANDS_H -#define COMMANDS_H - -#endif // COMMANDS_H diff --git a/tikzit/src/gui/edgeitem.cpp b/tikzit/src/gui/edgeitem.cpp deleted file mode 100644 index 497fa07..0000000 --- a/tikzit/src/gui/edgeitem.cpp +++ /dev/null @@ -1,131 +0,0 @@ -#include "tikzit.h" -#include "edgeitem.h" - -#include -#include - -EdgeItem::EdgeItem(Edge *edge) -{ - _edge = edge; - setFlag(QGraphicsItem::ItemIsSelectable); - - QPen pen(Qt::black); - pen.setWidth(2); - 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); - - readPos(); -} - -void EdgeItem::readPos() -{ - //_edge->setAttributesFromData(); - _edge->updateControls(); - QPainterPath path; - - path.moveTo (toScreen(_edge->tail())); - path.cubicTo(toScreen(_edge->cp1()), - toScreen(_edge->cp2()), - toScreen(_edge->head())); - setPath(path); - - _cp1Item->setPos(toScreen(_edge->cp1())); - _cp2Item->setPos(toScreen(_edge->cp2())); -} - -void EdgeItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) -{ - //QGraphicsPathItem::paint(painter, option, widget); - painter->setPen(pen()); - painter->setBrush(Qt::NoBrush); - painter->drawPath(path()); - - if (isSelected()) { - QColor draw; - QColor draw1; - QColor fill; - - if (_edge->basicBendMode()) { - draw = Qt::blue; - draw1 = QColor(100,100,255,100); - fill = QColor(200,200,255,50); - } else { - draw = Qt::darkGreen; - draw1 = QColor(0, 150, 0, 50); - fill = QColor(200,255,200,150); - } - - painter->setPen(QPen(draw1)); - - float r = GLOBAL_SCALEF * _edge->cpDist(); - painter->drawEllipse(toScreen(_edge->source()->point()), r, r); - painter->drawEllipse(toScreen(_edge->target()->point()), r, r); - - painter->setPen(QPen(draw)); - painter->setBrush(QBrush(fill)); - - painter->drawLine(toScreen(_edge->tail()), toScreen(_edge->cp1())); - painter->drawLine(toScreen(_edge->head()), toScreen(_edge->cp2())); - - //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 shape().boundingRect().adjusted(-r,-r,r,r); -} - -QPainterPath EdgeItem::shape() const -{ - // get the shape of the edge, and expand a bit to make selection easier - QPainterPath oldShape = QGraphicsPathItem::shape(); - QPainterPathStroker stroker; - stroker.setWidth(5); - stroker.setJoinStyle(Qt::MiterJoin); - QPainterPath newShape = (stroker.createStroke(oldShape) + oldShape).simplified(); - return newShape; -} - -Edge *EdgeItem::edge() const -{ - return _edge; -} - -QGraphicsEllipseItem *EdgeItem::cp1Item() const -{ - return _cp1Item; -} - -QGraphicsEllipseItem *EdgeItem::cp2Item() const -{ - return _cp2Item; -} diff --git a/tikzit/src/gui/edgeitem.h b/tikzit/src/gui/edgeitem.h deleted file mode 100644 index b017265..0000000 --- a/tikzit/src/gui/edgeitem.h +++ /dev/null @@ -1,36 +0,0 @@ -/** - * A QGraphicsItem that handles drawing a single edge. - */ - -#ifndef EDGEITEM_H -#define EDGEITEM_H - -#include "edge.h" - -#include -#include -#include -#include -#include -#include - -class EdgeItem : public QGraphicsPathItem -{ -public: - EdgeItem(Edge *edge); - void readPos(); - void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, - QWidget *widget); - QRectF boundingRect() const; - QPainterPath shape() const; - Edge *edge() const; - QGraphicsEllipseItem *cp1Item() const; - QGraphicsEllipseItem *cp2Item() const; - -private: - Edge *_edge; - QGraphicsEllipseItem *_cp1Item; - QGraphicsEllipseItem *_cp2Item; -}; - -#endif // EDGEITEM_H diff --git a/tikzit/src/gui/mainmenu.cpp b/tikzit/src/gui/mainmenu.cpp deleted file mode 100644 index c9e83ba..0000000 --- a/tikzit/src/gui/mainmenu.cpp +++ /dev/null @@ -1,96 +0,0 @@ -#include "mainmenu.h" -#include "tikzit.h" - -MainMenu::MainMenu() -{ - ui.setupUi(this); -} - -// File -void MainMenu::on_actionNew_triggered() -{ - tikzit->newDoc(); -} - -void MainMenu::on_actionOpen_triggered() -{ - tikzit->open(); -} - -void MainMenu::on_actionClose_triggered() -{ - // TODO -} - -void MainMenu::on_actionSave_triggered() -{ - // TODO -} - -void MainMenu::on_actionSave_As_triggered() -{ - // TODO -} - - -// Edit -void MainMenu::on_actionUndo_triggered() -{ - if (tikzit->activeWindow() != 0) - tikzit->activeWindow()->tikzDocument()->undoStack()->undo(); -} - -void MainMenu::on_actionRedo_triggered() -{ - if (tikzit->activeWindow() != 0) - tikzit->activeWindow()->tikzDocument()->undoStack()->redo(); -} - -void MainMenu::on_actionCut_triggered() -{ - // TODO -} - -void MainMenu::on_actionCopy_triggered() -{ - // TODO -} - -void MainMenu::on_actionPaste_triggered() -{ - // TODO -} - -void MainMenu::on_actionDelete_triggered() -{ - // TODO -} - -void MainMenu::on_actionSelect_All_triggered() -{ - // TODO -} - -void MainMenu::on_actionDeselect_All_triggered() -{ - // TODO -} - - -// Tikz -void MainMenu::on_actionParse_triggered() -{ - // TODO -} - - -// View -void MainMenu::on_actionZoom_In_triggered() -{ - if (tikzit->activeWindow() != 0) tikzit->activeWindow()->tikzView()->zoomIn(); -} - -void MainMenu::on_actionZoom_Out_triggered() -{ - if (tikzit->activeWindow() != 0) tikzit->activeWindow()->tikzView()->zoomOut(); -} diff --git a/tikzit/src/gui/mainmenu.h b/tikzit/src/gui/mainmenu.h deleted file mode 100644 index d85e271..0000000 --- a/tikzit/src/gui/mainmenu.h +++ /dev/null @@ -1,43 +0,0 @@ -#ifndef MAINMENU_H -#define MAINMENU_H - -#include "ui_mainmenu.h" - -#include - -class MainMenu : public QMenuBar -{ - Q_OBJECT -public: - MainMenu(); - -private: - Ui::MainMenu ui; - -public slots: - // File - void on_actionNew_triggered(); - void on_actionOpen_triggered(); - void on_actionClose_triggered(); - void on_actionSave_triggered(); - void on_actionSave_As_triggered(); - - // Edit - void on_actionUndo_triggered(); - void on_actionRedo_triggered(); - void on_actionCut_triggered(); - void on_actionCopy_triggered(); - void on_actionPaste_triggered(); - void on_actionDelete_triggered(); - void on_actionSelect_All_triggered(); - void on_actionDeselect_All_triggered(); - - // Tikz - void on_actionParse_triggered(); - - // View - void on_actionZoom_In_triggered(); - void on_actionZoom_Out_triggered(); -}; - -#endif // MAINMENU_H diff --git a/tikzit/src/gui/mainmenu.ui b/tikzit/src/gui/mainmenu.ui deleted file mode 100644 index c9b6f44..0000000 --- a/tikzit/src/gui/mainmenu.ui +++ /dev/null @@ -1,187 +0,0 @@ - - - MainMenu - - - - 0 - 0 - 476 - 22 - - - - - File - - - - - - - - - - - Edit - - - - - - - - - - - - - - - Tikz - - - - - - View - - - - - - - New... - - - Ctrl+N - - - - - Open... - - - Ctrl+O - - - - - Close - - - Ctrl+W - - - - - Save - - - Ctrl+S - - - - - Save As... - - - Ctrl+Shift+S - - - - - Undo - - - Ctrl+Z - - - - - Redo - - - Ctrl+Shift+Z - - - - - Cut - - - Ctrl+X - - - - - Copy - - - Ctrl+C - - - - - Paste - - - Ctrl+V - - - - - Delete - - - Backspace - - - - - Select All - - - Ctrl+A - - - - - Deselect All - - - Ctrl+D - - - - - Parse - - - Ctrl+T - - - - - Zoom In - - - Ctrl+= - - - - - Zoom Out - - - Ctrl+- - - - - - - - - - - diff --git a/tikzit/src/gui/mainwindow.cpp b/tikzit/src/gui/mainwindow.cpp deleted file mode 100644 index 19b6a59..0000000 --- a/tikzit/src/gui/mainwindow.cpp +++ /dev/null @@ -1,99 +0,0 @@ -#include "mainwindow.h" -#include "ui_mainwindow.h" -#include "tikzgraphassembler.h" -#include "toolpalette.h" -#include "tikzit.h" - -#include -#include -#include -#include -#include -#include - -int MainWindow::_numWindows = 0; - -MainWindow::MainWindow(QWidget *parent) : - QMainWindow(parent), - ui(new Ui::MainWindow) -{ - _windowId = _numWindows; - _numWindows++; - ui->setupUi(this); - setAttribute(Qt::WA_DeleteOnClose, true); - _tikzDocument = new TikzDocument(this); - _tikzScene = new TikzScene(_tikzDocument, this); - ui->tikzView->setScene(_tikzScene); - _fileName = ""; - _pristine = true; - - // initially, the source view should be collapsed - QList sz = ui->splitter->sizes(); - sz[0] = sz[0] + sz[1]; - sz[1] = 0; - ui->splitter->setSizes(sz); -} - -MainWindow::~MainWindow() -{ - tikzit->removeWindow(this); - delete ui; -} - -void MainWindow::open(QString fileName) -{ - _pristine = false; - _tikzDocument->open(fileName); - ui->tikzSource->setText(_tikzDocument->tikz()); - - - if (_tikzDocument->parseSuccess()) { - statusBar()->showMessage("TiKZ parsed successfully", 2000); - setWindowTitle("TiKZiT - " + _tikzDocument->shortName()); - _tikzScene->setTikzDocument(_tikzDocument); - } else { - statusBar()->showMessage("Cannot read TiKZ source"); - } - -} - -void MainWindow::closeEvent(QCloseEvent *event) -{ - //qDebug() << "got close event"; - QMainWindow::closeEvent(event); -} - -void MainWindow::changeEvent(QEvent *event) -{ - if (event->type() == QEvent::ActivationChange && isActiveWindow()) { - tikzit->setActiveWindow(this); - } - QMainWindow::changeEvent(event); -} - -TikzDocument *MainWindow::tikzDocument() const -{ - return _tikzDocument; -} - -TikzScene *MainWindow::tikzScene() const -{ - return _tikzScene; -} - -int MainWindow::windowId() const -{ - return _windowId; -} - -TikzView *MainWindow::tikzView() const -{ - return ui->tikzView; -} - -bool MainWindow::pristine() const -{ - return _pristine; -} - - diff --git a/tikzit/src/gui/mainwindow.h b/tikzit/src/gui/mainwindow.h deleted file mode 100644 index f27677a..0000000 --- a/tikzit/src/gui/mainwindow.h +++ /dev/null @@ -1,48 +0,0 @@ -/** - * A top-level window, which contains a single TikzDocument. - */ - -#ifndef MAINWINDOW_H -#define MAINWINDOW_H - -#include "tikzscene.h" -#include "tikzview.h" -#include "graph.h" -#include "tikzdocument.h" - -#include -#include - -namespace Ui { -class MainWindow; -} - -class MainWindow : public QMainWindow -{ - Q_OBJECT - -public: - explicit MainWindow(QWidget *parent = 0); - ~MainWindow(); - - void open(QString fileName); - bool pristine() const; - int windowId() const; - TikzView *tikzView() const; - TikzScene *tikzScene() const; - TikzDocument *tikzDocument() const; - -protected: - void closeEvent(QCloseEvent *event); - void changeEvent(QEvent *event); -private: - TikzScene *_tikzScene; - TikzDocument *_tikzDocument; - Ui::MainWindow *ui; - QString _fileName; - bool _pristine; - int _windowId; - static int _numWindows; -}; - -#endif // MAINWINDOW_H diff --git a/tikzit/src/gui/mainwindow.ui b/tikzit/src/gui/mainwindow.ui deleted file mode 100644 index 56a5c2d..0000000 --- a/tikzit/src/gui/mainwindow.ui +++ /dev/null @@ -1,199 +0,0 @@ - - - MainWindow - - - - 0 - 0 - 640 - 480 - - - - TikZiT - untitled - - - - - 0 - - - 0 - - - 0 - - - 0 - - - - - Qt::Vertical - - - - - - Courier New - 10 - - - - QTextEdit::NoWrap - - - <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> -<html><head><meta name="qrichtext" content="1" /><style type="text/css"> -p, li { white-space: pre-wrap; } -</style></head><body style=" font-family:'Courier New'; font-size:10pt; font-weight:400; font-style:normal;"> -<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:'.SF NS Text'; font-size:13pt;"><br /></p></body></html> - - - 20 - - - - - - - - - - New... - - - - - Open... - - - - - Close - - - - - Save - - - - - Save As... - - - - - Undo - - - - - Redo - - - - - Cut - - - - - Copy - - - - - Paste - - - - - Delete - - - - - Select All - - - - - Deselect All - - - - - Parse - - - Ctrl+T - - - - - Zoom In - - - Ctrl+= - - - - - Zoom Out - - - Ctrl+- - - - - - - - TikzView - QGraphicsView -
tikzview.h
- - zoomIn() - zoomOut() - -
-
- - - - actionZoom_In - triggered() - tikzView - zoomIn() - - - -1 - -1 - - - 237 - 103 - - - - - actionZoom_Out - triggered() - tikzView - zoomOut() - - - -1 - -1 - - - 237 - 103 - - - - -
diff --git a/tikzit/src/gui/nodeitem.cpp b/tikzit/src/gui/nodeitem.cpp deleted file mode 100644 index 71226f3..0000000 --- a/tikzit/src/gui/nodeitem.cpp +++ /dev/null @@ -1,124 +0,0 @@ -#include "tikzit.h" -#include "nodeitem.h" -#include "tikzscene.h" -#include - -#include -#include -#include -#include -#include -#include -#include - -NodeItem::NodeItem(Node *node) -{ - _node = node; - setFlag(QGraphicsItem::ItemIsSelectable); - setFlag(QGraphicsItem::ItemIsMovable); - setFlag(QGraphicsItem::ItemSendsGeometryChanges); - readPos(); -} - -void NodeItem::readPos() -{ - setPos(toScreen(_node->point())); -} - -void NodeItem::writePos() -{ - _node->setPoint(fromScreen(pos())); -} - -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 *, QWidget *) -{ - if (_node->style()->isNone()) { - QColor c(180,180,200); - painter->setPen(QPen(c)); - painter->setBrush(QBrush(c)); - painter->drawEllipse(QPointF(0,0), 1,1); - - QPen pen(QColor(180,180,220)); - QVector p; - p << 2.0 << 2.0; - pen.setDashPattern(p); - painter->setPen(pen); - painter->setBrush(Qt::NoBrush); - painter->drawPath(shape()); - } else { - QPen pen(_node->style()->strokeColor); - pen.setWidth(_node->style()->strokeThickness); - painter->setPen(pen); - painter->setBrush(QBrush(_node->style()->fillColor)); - painter->drawPath(shape()); - } - - if (_node->label() != "") { - QRectF rect = labelRect(); - QPen pen(QColor(200,0,0,120)); - QVector d; - d << 2.0 << 2.0; - pen.setDashPattern(d); - painter->setPen(pen); - painter->setBrush(QBrush(QColor(255,255,100,120))); - painter->drawRect(rect); - - painter->setPen(QPen(Qt::black)); - painter->setFont(Tikzit::LABEL_FONT); - painter->drawText(rect, Qt::AlignCenter, _node->label()); - } - - if (isSelected()) { - QPainterPath sh = shape(); - QPainterPathStroker stroker; - stroker.setWidth(4); - QPainterPath outline = (stroker.createStroke(sh) + sh).simplified(); - painter->setPen(Qt::NoPen); - painter->setBrush(QBrush(QColor(150,200,255,100))); - painter->drawPath(outline); - } - -} - -QPainterPath NodeItem::shape() const -{ - QPainterPath path; - path.addEllipse(QPointF(0,0), GLOBAL_SCALEF * 0.1, GLOBAL_SCALEF * 0.1); - return path; -} - -QRectF NodeItem::boundingRect() const -{ - QRectF r = labelRect(); - return r.united(shape().boundingRect()).adjusted(-4,-4,4,4); -} - -Node *NodeItem::node() const -{ - return _node; -} - -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 deleted file mode 100644 index 9a3edb0..0000000 --- a/tikzit/src/gui/nodeitem.h +++ /dev/null @@ -1,32 +0,0 @@ -/** - * A QGraphicsItem that handles drawing a single node. - */ - -#ifndef NODEITEM_H -#define NODEITEM_H - -#include "node.h" - -#include -#include -#include -#include - -class NodeItem : public QGraphicsItem -{ -public: - NodeItem(Node *node); - void readPos(); - void writePos(); - void paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *); - QVariant itemChange(GraphicsItemChange change, const QVariant &value); - QPainterPath shape() const; - QRectF boundingRect() const; - Node *node() const; - -private: - Node *_node; - QRectF labelRect() const; -}; - -#endif // NODEITEM_H diff --git a/tikzit/src/gui/propertypalette.cpp b/tikzit/src/gui/propertypalette.cpp deleted file mode 100644 index 5fc763f..0000000 --- a/tikzit/src/gui/propertypalette.cpp +++ /dev/null @@ -1,43 +0,0 @@ -#include "propertypalette.h" -#include "graphelementdata.h" -#include "ui_propertypalette.h" - -#include -#include -#include -#include - -PropertyPalette::PropertyPalette(QWidget *parent) : - QDockWidget(parent), - ui(new Ui::PropertyPalette) -{ - setWindowFlags(Qt::Window - | Qt::CustomizeWindowHint - | Qt::WindowTitleHint); - //setFocusPolicy(Qt::NoFocus); - ui->setupUi(this); - GraphElementData *d = new GraphElementData(); - d->setProperty("key 1", "value 1"); - d->setAtom("atom 1"); - d->setProperty("key 2", "value 2"); - - QModelIndex i = d->index(0,0); - ui->treeView->setModel(d); - - QSettings settings("tikzit", "tikzit"); - QVariant geom = settings.value("property-palette-geometry"); - if (geom != QVariant()) { - restoreGeometry(geom.toByteArray()); - } -} - -PropertyPalette::~PropertyPalette() -{ - delete ui; -} - -void PropertyPalette::closeEvent(QCloseEvent *event) { - QSettings settings("tikzit", "tikzit"); - settings.setValue("property-palette-geometry", saveGeometry()); - QDockWidget::closeEvent(event); -} diff --git a/tikzit/src/gui/propertypalette.h b/tikzit/src/gui/propertypalette.h deleted file mode 100644 index 7910d70..0000000 --- a/tikzit/src/gui/propertypalette.h +++ /dev/null @@ -1,28 +0,0 @@ -/** - * Enables the user to edit properties of the graph, as well as the selected node/edge. - */ - -#ifndef PROPERTYPALETTE_H -#define PROPERTYPALETTE_H - -#include - -namespace Ui { -class PropertyPalette; -} - -class PropertyPalette : public QDockWidget -{ - Q_OBJECT - -public: - explicit PropertyPalette(QWidget *parent = 0); - ~PropertyPalette(); - -protected: - void closeEvent(QCloseEvent *event); -private: - Ui::PropertyPalette *ui; -}; - -#endif // PROPERTYPALETTE_H diff --git a/tikzit/src/gui/propertypalette.ui b/tikzit/src/gui/propertypalette.ui deleted file mode 100644 index 83d586e..0000000 --- a/tikzit/src/gui/propertypalette.ui +++ /dev/null @@ -1,30 +0,0 @@ - - - PropertyPalette - - - - 0 - 0 - 194 - 341 - - - - Properties - - - - - - - 0 - - - - - - - - - diff --git a/tikzit/src/gui/tikzscene.cpp b/tikzit/src/gui/tikzscene.cpp deleted file mode 100644 index 3431c0c..0000000 --- a/tikzit/src/gui/tikzscene.cpp +++ /dev/null @@ -1,384 +0,0 @@ -#include "tikzit.h" -#include "util.h" -#include "tikzscene.h" -#include "undocommands.h" - -#include -#include -#include - - -TikzScene::TikzScene(TikzDocument *tikzDocument, QObject *parent) : - QGraphicsScene(parent), _tikzDocument(tikzDocument) -{ - _modifyEdgeItem = 0; - _drawEdgeItem = new QGraphicsLineItem(); - setSceneRect(-310,-230,620,450); - - QPen pen; - pen.setColor(QColor::fromRgbF(0.5f, 0.0f, 0.5f)); - pen.setWidth(3); - _drawEdgeItem->setPen(pen); - _drawEdgeItem->setLine(0,0,0,0); - _drawEdgeItem->setVisible(false); - addItem(_drawEdgeItem); -} - -TikzScene::~TikzScene() { -} - -Graph *TikzScene::graph() -{ - return _tikzDocument->graph(); -} - -void TikzScene::graphReplaced() -{ - foreach (NodeItem *ni, _nodeItems) { - removeItem(ni); - delete ni; - } - _nodeItems.clear(); - - foreach (EdgeItem *ei, _edgeItems) { - removeItem(ei); - delete ei; - } - _edgeItems.clear(); - - foreach (Edge *e, graph()->edges()) { - EdgeItem *ei = new EdgeItem(e); - _edgeItems.insert(e, ei); - addItem(ei); - } - - foreach (Node *n, graph()->nodes()) { - NodeItem *ni = new NodeItem(n); - _nodeItems.insert(n, ni); - addItem(ni); - } -} - -void TikzScene::mousePressEvent(QGraphicsSceneMouseEvent *event) -{ - // current mouse position, in scene coordinates - QPointF mousePos = event->scenePos(); - - // disable rubber band drag, which will clear the selection. Only re-enable it - // for the SELECT tool, and when no control point has been clicked. - views()[0]->setDragMode(QGraphicsView::NoDrag); - - // radius of a control point for bezier edges, in scene coordinates - qreal cpR = GLOBAL_SCALEF * (0.05); - qreal cpR2 = cpR * cpR; - - switch (tikzit->toolPalette()->currentTool()) { - case ToolPalette::SELECT: - // check if we grabbed a control point of an edge - foreach (QGraphicsItem *gi, selectedItems()) { - if (EdgeItem *ei = dynamic_cast(gi)) { - qreal dx, dy; - - dx = ei->cp1Item()->pos().x() - mousePos.x(); - dy = ei->cp1Item()->pos().y() - mousePos.y(); - - if (dx*dx + dy*dy <= cpR2) { - _modifyEdgeItem = ei; - _firstControlPoint = true; - break; - } - - dx = ei->cp2Item()->pos().x() - mousePos.x(); - dy = ei->cp2Item()->pos().y() - mousePos.y(); - - if (dx*dx + dy*dy <= cpR2) { - _modifyEdgeItem = ei; - _firstControlPoint = false; - break; - } - } - } - - if (_modifyEdgeItem != 0) { - // store for undo purposes - Edge *e = _modifyEdgeItem->edge(); - _oldBend = e->bend(); - _oldInAngle = e->inAngle(); - _oldOutAngle = e->outAngle(); - _oldWeight = e->weight(); - } else { - // since we are not dragging a control point, process the click normally - views()[0]->setDragMode(QGraphicsView::RubberBandDrag); - QGraphicsScene::mousePressEvent(event); - - // save current node positions for undo support - _oldNodePositions.clear(); - foreach (QGraphicsItem *gi, selectedItems()) { - if (NodeItem *ni = dynamic_cast(gi)) { - _oldNodePositions.insert(ni->node(), ni->node()->point()); - } - } - } - - break; - case ToolPalette::VERTEX: - break; - case ToolPalette::EDGE: - break; - case ToolPalette::CROP: - break; - } -} - -void TikzScene::mouseMoveEvent(QGraphicsSceneMouseEvent *event) -{ - // current mouse position, in scene coordinates - QPointF mousePos = event->scenePos(); - - switch (tikzit->toolPalette()->currentTool()) { - case ToolPalette::SELECT: - if (_modifyEdgeItem != 0) { - Edge *e = _modifyEdgeItem->edge(); - - // dragging a control point - QPointF src = toScreen(e->source()->point()); - QPointF targ = toScreen(e->target()->point()); - float dx1 = targ.x() - src.x(); - float dy1 = targ.y() - src.y(); - float dx2, dy2; - if (_firstControlPoint) { - dx2 = mousePos.x() - src.x(); - dy2 = mousePos.y() - src.y(); - } else { - dx2 = mousePos.x() - targ.x(); - dy2 = mousePos.y() - targ.y(); - } - - float baseDist = sqrt(dx1*dx1 + dy1*dy1); - float handleDist = sqrt(dx2*dx2 + dy2*dy2); - float wcoarseness = 0.1f; - - if (!e->isSelfLoop()) { - if (baseDist != 0) { - e->setWeight(roundToNearest(wcoarseness, handleDist/baseDist)); - } else { - e->setWeight(roundToNearest(wcoarseness, handleDist/GLOBAL_SCALEF)); - } - } - - float control_angle = atan2(-dy2, dx2); - - int bcoarseness = 15; - - if(e->basicBendMode()) { - float bnd; - float base_angle = atan2(-dy1, dx1); - if (_firstControlPoint) { - bnd = base_angle - control_angle; - } else { - bnd = control_angle - base_angle + M_PI; - if (bnd > M_PI) bnd -= 2*M_PI; - } - - e->setBend(round(bnd * (180.0f / M_PI) * (1.0f / (float)bcoarseness)) * bcoarseness); - - } else { - int bnd = round(control_angle * (180.0f / M_PI) * - (1.0f / (float)bcoarseness)) * - bcoarseness; - if (_firstControlPoint) { - // TODO: enable moving both control points -// if ([theEvent modifierFlags] & NSAlternateKeyMask) { -// if ([modifyEdge isSelfLoop]) { -// [modifyEdge setInAngle:[modifyEdge inAngle] + -// (bnd - [modifyEdge outAngle])]; -// } else { -// [modifyEdge setInAngle:[modifyEdge inAngle] - -// (bnd - [modifyEdge outAngle])]; -// } -// } - - e->setOutAngle(bnd); - } else { -// if (theEvent.modifierFlags & NSAlternateKeyMask) { -// if ([modifyEdge isSelfLoop]) { -// [modifyEdge setOutAngle:[modifyEdge outAngle] + -// (bnd - [modifyEdge inAngle])]; -// } else { -// [modifyEdge setOutAngle:[modifyEdge outAngle] - -// (bnd - [modifyEdge inAngle])]; -// } -// } - - e->setInAngle(bnd); - } - } - - _modifyEdgeItem->readPos(); - - } else { - // otherwise, process mouse move normally - QGraphicsScene::mouseMoveEvent(event); - refreshAdjacentEdges(_oldNodePositions.keys()); - } - - break; - case ToolPalette::VERTEX: - break; - case ToolPalette::EDGE: - break; - case ToolPalette::CROP: - break; - } -} - -void TikzScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) -{ - // current mouse position, in scene coordinates - QPointF mousePos = event->scenePos(); - - switch (tikzit->toolPalette()->currentTool()) { - case ToolPalette::SELECT: - if (_modifyEdgeItem != 0) { - // finished dragging a control point - Edge *e = _modifyEdgeItem->edge(); - - if (_oldWeight != e->weight() || - _oldBend != e->bend() || - _oldInAngle != e->inAngle() || - _oldOutAngle != e->outAngle()) - { - EdgeBendCommand *cmd = new EdgeBendCommand(this, e, _oldWeight, _oldBend, _oldInAngle, _oldOutAngle); - _tikzDocument->undoStack()->push(cmd); - } - - _modifyEdgeItem = 0; - } else { - // otherwise, process mouse move normally - QGraphicsScene::mouseReleaseEvent(event); - - if (!_oldNodePositions.empty()) { - QMap newNodePositions; - - foreach (QGraphicsItem *gi, selectedItems()) { - if (NodeItem *ni = dynamic_cast(gi)) { - ni->writePos(); - newNodePositions.insert(ni->node(), ni->node()->point()); - } - } - - //qDebug() << _oldNodePositions; - //qDebug() << newNodePositions; - - _tikzDocument->undoStack()->push(new MoveCommand(this, _oldNodePositions, newNodePositions)); - _oldNodePositions.clear(); - } - } - - break; - case ToolPalette::VERTEX: - { - int gridSize = GLOBAL_SCALE / 8; - QPointF gridPos(round(mousePos.x()/gridSize)*gridSize, round(mousePos.y()/gridSize)*gridSize); - Node *n = new Node(); - n->setPoint(fromScreen(gridPos)); - - QRectF grow(gridPos.x() - GLOBAL_SCALEF, gridPos.y() - GLOBAL_SCALEF, 2 * GLOBAL_SCALEF, 2 * GLOBAL_SCALEF); - QRectF newBounds = sceneRect().united(grow); - qDebug() << grow; - qDebug() << newBounds; - - AddNodeCommand *cmd = new AddNodeCommand(this, n, newBounds); - _tikzDocument->undoStack()->push(cmd); - } - break; - case ToolPalette::EDGE: - break; - case ToolPalette::CROP: - break; - } -} - -void TikzScene::keyReleaseEvent(QKeyEvent *event) -{ - if (event->key() == Qt::Key_Backspace || event->key() == Qt::Key_Delete) { - QSet selNodes; - QSet selEdges; - getSelection(selNodes, selEdges); - - QMap deleteNodes; - QMap deleteEdges; - - for (int i = 0; i < _tikzDocument->graph()->nodes().length(); ++i) { - Node *n = _tikzDocument->graph()->nodes()[i]; - if (selNodes.contains(n)) deleteNodes.insert(i, n); - } - - for (int i = 0; i < _tikzDocument->graph()->edges().length(); ++i) { - Edge *e = _tikzDocument->graph()->edges()[i]; - if (selEdges.contains(e) || - selNodes.contains(e->source()) || - selNodes.contains(e->target())) deleteEdges.insert(i, e); - } - - //qDebug() << "nodes:" << deleteNodes; - //qDebug() << "edges:" << deleteEdges; - DeleteCommand *cmd = new DeleteCommand(this, deleteNodes, deleteEdges, selEdges); - _tikzDocument->undoStack()->push(cmd); - } -} - -void TikzScene::getSelection(QSet &selNodes, QSet &selEdges) -{ - foreach (QGraphicsItem *gi, selectedItems()) { - if (NodeItem *ni = dynamic_cast(gi)) selNodes << ni->node(); - if (EdgeItem *ei = dynamic_cast(gi)) selEdges << ei->edge(); - } -} - - -TikzDocument *TikzScene::tikzDocument() const -{ - return _tikzDocument; -} - -void TikzScene::setTikzDocument(TikzDocument *tikzDocument) -{ - _tikzDocument = tikzDocument; - graphReplaced(); -} - -void TikzScene::refreshAdjacentEdges(QList nodes) -{ - if (nodes.empty()) return; - foreach (EdgeItem *ei, _edgeItems) { - if (nodes.contains(ei->edge()->source()) || nodes.contains(ei->edge()->target())) { - ei->edge()->updateControls(); - ei->readPos(); - } - } -} - -void TikzScene::setBounds(QRectF bounds) -{ - if (bounds != sceneRect()) { - if (!views().empty()) { - QGraphicsView *v = views().first(); - QPointF c = v->mapToScene(v->viewport()->rect().center()); - setSceneRect(bounds); - v->centerOn(c); - } else { - setSceneRect(bounds); - } - } -} - -QMap &TikzScene::nodeItems() -{ - return _nodeItems; -} - -QMap &TikzScene::edgeItems() -{ - return _edgeItems; -} diff --git a/tikzit/src/gui/tikzscene.h b/tikzit/src/gui/tikzscene.h deleted file mode 100644 index 6817792..0000000 --- a/tikzit/src/gui/tikzscene.h +++ /dev/null @@ -1,62 +0,0 @@ -/** - * Manage the scene, which contains a single Graph, and respond to user input. This serves as - * the controller for the MVC (TikzDocument, TikzView, TikzScene). - */ - -#ifndef TIKZSCENE_H -#define TIKZSCENE_H - -#include "graph.h" -#include "nodeitem.h" -#include "edgeitem.h" -#include "tikzdocument.h" - -#include -#include -#include -#include -#include -#include -#include - -class TikzScene : public QGraphicsScene -{ - Q_OBJECT -public: - TikzScene(TikzDocument *tikzDocument, QObject *parent); - ~TikzScene(); - Graph *graph(); - QMap &nodeItems(); - QMap &edgeItems(); - void refreshAdjacentEdges(QList nodes); - void setBounds(QRectF bounds); - - TikzDocument *tikzDocument() const; - void setTikzDocument(TikzDocument *tikzDocument); - -public slots: - void graphReplaced(); - -protected: - void mousePressEvent(QGraphicsSceneMouseEvent *event) override; - void mouseMoveEvent(QGraphicsSceneMouseEvent *event) override; - void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override; - void keyReleaseEvent(QKeyEvent *event) override; -private: - TikzDocument *_tikzDocument; - QMap _nodeItems; - QMap _edgeItems; - QGraphicsLineItem *_drawEdgeItem; - EdgeItem *_modifyEdgeItem; - bool _firstControlPoint; - - QMap _oldNodePositions; - float _oldWeight; - int _oldBend; - int _oldInAngle; - int _oldOutAngle; - - void getSelection(QSet &selNodes, QSet &selEdges); -}; - -#endif // TIKZSCENE_H diff --git a/tikzit/src/gui/tikzview.cpp b/tikzit/src/gui/tikzview.cpp deleted file mode 100644 index fe6c401..0000000 --- a/tikzit/src/gui/tikzview.cpp +++ /dev/null @@ -1,84 +0,0 @@ -#include "tikzview.h" -#include "tikzit.h" - -#include - -TikzView::TikzView(QWidget *parent) : QGraphicsView(parent) -{ - setRenderHint(QPainter::Antialiasing); - setDragMode(QGraphicsView::RubberBandDrag); - - _scale = 1.0f; -} - -void TikzView::zoomIn() -{ - _scale *= 1.6f; - scale(1.6,1.6); -} - -void TikzView::zoomOut() -{ - _scale *= 0.625f; - scale(0.625,0.625); -} - -void TikzView::drawBackground(QPainter *painter, const QRectF &rect) -{ - // draw the grid - int step = GLOBAL_SCALE / 8; - - QPen pen1; - pen1.setWidth(1); - pen1.setCosmetic(true); - pen1.setColor(QColor(230,230,230)); - - QPen pen2 = pen1; - pen2.setColor(QColor(200,200,200)); - - QPen pen3 = pen1; - pen3.setColor(QColor(160,160,160)); - - painter->setPen(pen1); - - if (_scale > 0.2f) { - for (int x = -step; x > rect.left(); x -= step) { - if (x % (step * 8) != 0) painter->drawLine(x, rect.top(), x, rect.bottom()); - } - - for (int x = step; x < rect.right(); x += step) { - if (x % (step * 8) != 0) painter->drawLine(x, rect.top(), x, rect.bottom()); - } - - for (int y = -step; y > rect.top(); y -= step) { - if (y % (step * 8) != 0) painter->drawLine(rect.left(), y, rect.right(), y); - } - - for (int y = step; y < rect.bottom(); y += step) { - if (y % (step * 8) != 0) painter->drawLine(rect.left(), y, rect.right(), y); - } - } - - painter->setPen(pen2); - - for (int x = -step*8; x > rect.left(); x -= step*8) { - painter->drawLine(x, rect.top(), x, rect.bottom()); - } - - for (int x = step*8; x < rect.right(); x += step*8) { - painter->drawLine(x, rect.top(), x, rect.bottom()); - } - - for (int y = -step*8; y > rect.top(); y -= step*8) { - painter->drawLine(rect.left(), y, rect.right(), y); - } - - for (int y = step*8; y < rect.bottom(); y += step*8) { - painter->drawLine(rect.left(), y, rect.right(), y); - } - - painter->setPen(pen3); - painter->drawLine(rect.left(), 0, rect.right(), 0); - painter->drawLine(0, rect.top(), 0, rect.bottom()); -} - diff --git a/tikzit/src/gui/tikzview.h b/tikzit/src/gui/tikzview.h deleted file mode 100644 index fc3cba4..0000000 --- a/tikzit/src/gui/tikzview.h +++ /dev/null @@ -1,32 +0,0 @@ -/** - * Display a Graph, and manage any user input that purely changes the view (e.g. Zoom). This - * serves as the view in the MVC (TikzDocument, TikzView, TikzScene). - */ - -#ifndef TIKZVIEW_H -#define TIKZVIEW_H - -#include -#include -#include -#include -#include -#include -#include -#include - -class TikzView : public QGraphicsView -{ - Q_OBJECT -public: - explicit TikzView(QWidget *parent = 0); -public slots: - void zoomIn(); - void zoomOut(); -protected: - void drawBackground(QPainter *painter, const QRectF &rect); -private: - float _scale; -}; - -#endif // TIKZVIEW_H diff --git a/tikzit/src/gui/toolpalette.cpp b/tikzit/src/gui/toolpalette.cpp deleted file mode 100644 index 3c08bce..0000000 --- a/tikzit/src/gui/toolpalette.cpp +++ /dev/null @@ -1,50 +0,0 @@ -#include "toolpalette.h" - -#include -#include -#include -#include - -ToolPalette::ToolPalette(QWidget *parent) : - QToolBar(parent) -{ - setWindowFlags(Qt::Window - | Qt::CustomizeWindowHint - | Qt::WindowDoesNotAcceptFocus); - setOrientation(Qt::Vertical); - setFocusPolicy(Qt::NoFocus); - 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"); - - tools->addAction(select); - tools->addAction(vertex); - tools->addAction(edge); - tools->addAction(crop); - - select->setCheckable(true); - vertex->setCheckable(true); - edge->setCheckable(true); - crop->setCheckable(true); - select->setChecked(true); - - addAction(select); - addAction(vertex); - addAction(edge); - 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 deleted file mode 100644 index ba6aed5..0000000 --- a/tikzit/src/gui/toolpalette.h +++ /dev/null @@ -1,34 +0,0 @@ -/** - * A small window that lets the user select the current editing tool. - */ - -#ifndef TOOLPALETTE_H -#define TOOLPALETTE_H - -#include -#include -#include -#include - -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; - QAction *vertex; - QAction *edge; - QAction *crop; -}; - -#endif // TOOLPALETTE_H diff --git a/tikzit/src/gui/undocommands.cpp b/tikzit/src/gui/undocommands.cpp deleted file mode 100644 index 736c258..0000000 --- a/tikzit/src/gui/undocommands.cpp +++ /dev/null @@ -1,162 +0,0 @@ -#include "undocommands.h" -#include "nodeitem.h" -#include "edgeitem.h" - -#include - -MoveCommand::MoveCommand(TikzScene *scene, - QMap oldNodePositions, - QMap newNodePositions, - QUndoCommand *parent) : - QUndoCommand(parent), - _scene(scene), - _oldNodePositions(oldNodePositions), - _newNodePositions(newNodePositions) -{} - - -void MoveCommand::undo() -{ - foreach (NodeItem *ni, _scene->nodeItems()) { - if (_oldNodePositions.contains(ni->node())) { - ni->node()->setPoint(_oldNodePositions.value(ni->node())); - ni->readPos(); - } - } - - _scene->refreshAdjacentEdges(_oldNodePositions.keys()); -} - -void MoveCommand::redo() -{ - foreach (NodeItem *ni, _scene->nodeItems()) { - if (_newNodePositions.contains(ni->node())) { - ni->node()->setPoint(_newNodePositions.value(ni->node())); - ni->readPos(); - } - } - - _scene->refreshAdjacentEdges(_newNodePositions.keys()); -} - -EdgeBendCommand::EdgeBendCommand(TikzScene *scene, Edge *edge, - float oldWeight, int oldBend, - int oldInAngle, int oldOutAngle) : - _scene(scene), _edge(edge), - _oldWeight(oldWeight), _oldBend(oldBend), - _oldInAngle(oldInAngle), _oldOutAngle(oldOutAngle) -{ - _newWeight = edge->weight(); - _newBend = edge->bend(); - _newInAngle = edge->inAngle(); - _newOutAngle = edge->outAngle(); -} - -void EdgeBendCommand::undo() -{ - _edge->setWeight(_oldWeight); - _edge->setBend(_oldBend); - _edge->setInAngle(_oldInAngle); - _edge->setOutAngle(_oldOutAngle); - - foreach(EdgeItem *ei, _scene->edgeItems()) { - if (ei->edge() == _edge) { - ei->readPos(); - break; - } - } -} - -void EdgeBendCommand::redo() -{ - _edge->setWeight(_newWeight); - _edge->setBend(_newBend); - _edge->setInAngle(_newInAngle); - _edge->setOutAngle(_newOutAngle); - - foreach(EdgeItem *ei, _scene->edgeItems()) { - if (ei->edge() == _edge) { - ei->readPos(); - break; - } - } -} - -DeleteCommand::DeleteCommand(TikzScene *scene, - QMap deleteNodes, - QMap deleteEdges, - QSet selEdges) : - _scene(scene), _deleteNodes(deleteNodes), - _deleteEdges(deleteEdges), _selEdges(selEdges) -{} - -void DeleteCommand::undo() -{ - for (auto it = _deleteNodes.begin(); it != _deleteNodes.end(); ++it) { - Node *n = it.value(); - _scene->graph()->addNode(n, it.key()); - NodeItem *ni = new NodeItem(n); - _scene->nodeItems().insert(n, ni); - _scene->addItem(ni); - ni->setSelected(true); - } - - for (auto it = _deleteEdges.begin(); it != _deleteEdges.end(); ++it) { - Edge *e = it.value(); - _scene->graph()->addEdge(e, it.key()); - EdgeItem *ei = new EdgeItem(e); - _scene->edgeItems().insert(e, ei); - _scene->addItem(ei); - - if (_selEdges.contains(e)) ei->setSelected(true); - } -} - -void DeleteCommand::redo() -{ - foreach (Edge *e, _deleteEdges.values()) { - EdgeItem *ei = _scene->edgeItems()[e]; - _scene->edgeItems().remove(e); - _scene->removeItem(ei); - delete ei; - - _scene->graph()->removeEdge(e); - } - - foreach (Node *n, _deleteNodes.values()) { - NodeItem *ni = _scene->nodeItems()[n]; - _scene->nodeItems().remove(n); - _scene->removeItem(ni); - delete ni; - - _scene->graph()->removeNode(n); - } -} - -AddNodeCommand::AddNodeCommand(TikzScene *scene, Node *node, QRectF newBounds) : - _scene(scene), _node(node), _oldBounds(_scene->sceneRect()), _newBounds(newBounds) -{ -} - -void AddNodeCommand::undo() -{ - NodeItem *ni = _scene->nodeItems()[_node]; - _scene->removeItem(ni); - _scene->nodeItems().remove(_node); - delete ni; - - _scene->graph()->removeNode(_node); - - _scene->setBounds(_oldBounds); -} - -void AddNodeCommand::redo() -{ - // TODO: get the current style - _scene->graph()->addNode(_node); - NodeItem *ni = new NodeItem(_node); - _scene->nodeItems().insert(_node, ni); - _scene->addItem(ni); - - _scene->setBounds(_newBounds); -} diff --git a/tikzit/src/gui/undocommands.h b/tikzit/src/gui/undocommands.h deleted file mode 100644 index ffff876..0000000 --- a/tikzit/src/gui/undocommands.h +++ /dev/null @@ -1,80 +0,0 @@ -/** - * All changes to a TikzDocument are done via subclasses of QUndoCommand. When a controller - * (e.g. TikzScene) gets input from the user to change the document, it will push one of - * these commands onto the TikzDocument's undo stack, which automatically calls the redo() - * method of the command. - */ - -#ifndef UNDOCOMMANDS_H -#define UNDOCOMMANDS_H - -#include "tikzscene.h" - -#include - -class MoveCommand : public QUndoCommand -{ -public: - explicit MoveCommand(TikzScene *scene, - QMap oldNodePositions, - QMap newNodePositions, - QUndoCommand *parent = 0); - void undo() override; - void redo() override; -private: - TikzScene *_scene; - QMap _oldNodePositions; - QMap _newNodePositions; -}; - -class EdgeBendCommand : public QUndoCommand -{ -public: - explicit EdgeBendCommand(TikzScene *scene, Edge *edge, - float oldWeight, int oldBend, - int oldInAngle, int oldOutAngle); - void undo() override; - void redo() override; -private: - TikzScene *_scene; - Edge *_edge; - float _oldWeight; - int _oldBend; - int _oldInAngle; - int _oldOutAngle; - float _newWeight; - int _newBend; - int _newInAngle; - int _newOutAngle; -}; - -class DeleteCommand : public QUndoCommand -{ -public: - explicit DeleteCommand(TikzScene *scene, - QMap deleteNodes, - QMap deleteEdges, - QSet selEdges); - void undo() override; - void redo() override; -private: - TikzScene *_scene; - QMap _deleteNodes; - QMap _deleteEdges; - QSet _selEdges; -}; - -class AddNodeCommand : public QUndoCommand -{ -public: - explicit AddNodeCommand(TikzScene *scene, Node *node, QRectF newBounds); - void undo() override; - void redo() override; -private: - TikzScene *_scene; - Node *_node; - QRectF _oldBounds; - QRectF _newBounds; -}; - -#endif // UNDOCOMMANDS_H -- cgit v1.2.3