diff --git a/Commands.cpp b/Commands.cpp index 782107d..6958b67 100644 --- a/Commands.cpp +++ b/Commands.cpp @@ -24,37 +24,35 @@ void AddShapesCommand::redo() } -MoveVertexCommand::MoveVertexCommand(MapperGLCanvas *mapperGLCanvas, Shape *shape, int activeVertex, const QPointF &point, QUndoCommand *parent) : +MoveVertexCommand::MoveVertexCommand(MapperGLCanvas *mapperGLCanvas, int activeVertex, const QPointF &point, QUndoCommand *parent) : QUndoCommand(parent) { m_mapperGLCanvas = mapperGLCanvas; - m_shape = shape; + m_shape = m_mapperGLCanvas->getCurrentShape(); m_activeVertex = activeVertex; - newPosition = point; - - oldPosition = m_shape->getVertex(m_activeVertex); + vertexPosition = point; } void MoveVertexCommand::undo() { - m_shape->setVertex(m_activeVertex, oldPosition); + m_shape->setVertex(m_activeVertex, vertexPosition); m_mapperGLCanvas->update(); emit m_mapperGLCanvas->shapeChanged(m_mapperGLCanvas->getCurrentShape()); } void MoveVertexCommand::redo() { - m_shape->setVertex(m_activeVertex, newPosition); + m_shape->setVertex(m_activeVertex, vertexPosition); m_mapperGLCanvas->update(); emit m_mapperGLCanvas->shapeChanged(m_mapperGLCanvas->getCurrentShape()); } -MoveShapesCommand::MoveShapesCommand(MapperGLCanvas *mapperGLCanvas, Shape *shape, QMouseEvent *event, const QPointF &point, QUndoCommand *parent) : +MoveShapesCommand::MoveShapesCommand(MapperGLCanvas *mapperGLCanvas, QMouseEvent *event, const QPointF &point, QUndoCommand *parent) : QUndoCommand(parent) { m_mapperGLCanvas = mapperGLCanvas; - m_shape = shape; + m_shape = m_mapperGLCanvas->getCurrentShape(); m_event = event; newPosition = point; } diff --git a/Commands.h b/Commands.h index b83cb4c..7c8d155 100644 --- a/Commands.h +++ b/Commands.h @@ -43,7 +43,7 @@ private: class MoveVertexCommand : public QUndoCommand { public: - MoveVertexCommand(MapperGLCanvas *mapperGLCanvas, Shape *shape, int activeVertex, const QPointF &point, QUndoCommand *parent = 0); + MoveVertexCommand(MapperGLCanvas *mapperGLCanvas, int activeVertex, const QPointF &point, QUndoCommand *parent = 0); void undo(); void redo(); @@ -51,14 +51,14 @@ private: MapperGLCanvas *m_mapperGLCanvas; Shape *m_shape; int m_activeVertex; - QPointF newPosition, oldPosition; + QPointF vertexPosition; }; class MoveShapesCommand : public QUndoCommand { public: - MoveShapesCommand(MapperGLCanvas *mapperGLCanvas, Shape *shape, QMouseEvent *event, const QPointF &point, QUndoCommand *parent = 0); + MoveShapesCommand(MapperGLCanvas *mapperGLCanvas, QMouseEvent *event, const QPointF &point, QUndoCommand *parent = 0); void undo(); void redo(); diff --git a/MainWindow.cpp b/MainWindow.cpp index 0096a59..e5596ef 100644 --- a/MainWindow.cpp +++ b/MainWindow.cpp @@ -27,10 +27,6 @@ MainWindow::MainWindow() { - - // UndoStack - undoStack = new QUndoStack(this); - // Create model. if (Media::hasVideoSupport()) std::cout << "Video support: yes" << std::endl; @@ -58,10 +54,6 @@ MainWindow::MainWindow() createToolBars(); createStatusBar(); - // Update Recent files and video - updateRecentFileActions(); - updateRecentVideoActions(); - // Load settings. readSettings(); @@ -1175,6 +1167,9 @@ void MainWindow::createLayout() void MainWindow::createActions() { + // UndoStack + undoStack = new QUndoStack(this); + // New. newAction = new QAction(tr("&New"), this); newAction->setIcon(QIcon(":/new")); @@ -1645,6 +1640,9 @@ void MainWindow::readSettings() } config_osc_receive_port = settings.value("osc_receive_port", 12345).toInt(); + // Update Recent files and video + updateRecentFileActions(); + updateRecentVideoActions(); } void MainWindow::writeSettings() diff --git a/MainWindow.h b/MainWindow.h index 07b6f76..5e9d1b1 100644 --- a/MainWindow.h +++ b/MainWindow.h @@ -375,7 +375,7 @@ public: void removeCurrentMapping(); // Use the same undoStack for whole program - QUndoStack* getUndoStack() { return undoStack; } + QUndoStack* getUndoStack() const { return undoStack; } void startFullScreen(); bool setOscPort(QString portNumber); diff --git a/MapperGLCanvas.cpp b/MapperGLCanvas.cpp index eee6d87..9723200 100644 --- a/MapperGLCanvas.cpp +++ b/MapperGLCanvas.cpp @@ -208,7 +208,7 @@ void MapperGLCanvas::mouseMoveEvent(QMouseEvent* event) glueVertex(shape, &p); // Enable to Undo and Redo when mouse move the position of vertices - undoStack->push(new MoveVertexCommand(this, shape, _activeVertex, p)); + undoStack->push(new MoveVertexCommand(this, _activeVertex, p)); } } else if (_shapeGrabbed) @@ -220,7 +220,7 @@ void MapperGLCanvas::mouseMoveEvent(QMouseEvent* event) { if (!_shapeFirstGrab) { - undoStack->push(new MoveShapesCommand(this, shape, event, prevMousePosition)); + undoStack->push(new MoveShapesCommand(this, event, prevMousePosition)); } else _shapeFirstGrab = false; @@ -279,7 +279,7 @@ void MapperGLCanvas::keyPressEvent(QKeyEvent* event) } // TODO: this will always be called even if no arrow key has been pressed (small performance issue). // Enable to Undo and Redo when arrow keys move the position of vertices - undoStack->push(new MoveVertexCommand(this, shape, _activeVertex, p)); + undoStack->push(new MoveVertexCommand(this, _activeVertex, p)); } // Defer unhandled keys to parent.