mirror of
https://github.com/mapmapteam/mapmap.git
synced 2026-06-16 12:33:19 +02:00
Undo Command to restore position of vertices moved by mouse or arrow key
This commit is contained in:
@@ -22,3 +22,29 @@ void AddShapesCommand::redo()
|
||||
m_mainWindow->addMappingItem(currentId);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
MoveVertexCommand::MoveVertexCommand(MapperGLCanvas *mapperGLCanvas, Shape *shape, int activeVertex, const QPointF &point, QUndoCommand *parent) :
|
||||
QUndoCommand(parent)
|
||||
{
|
||||
m_mapperGLCanvas = mapperGLCanvas;
|
||||
m_shape = shape;
|
||||
m_activeVertex = activeVertex;
|
||||
newPosition = point;
|
||||
|
||||
oldPosition = m_shape->getVertex(m_activeVertex);
|
||||
}
|
||||
|
||||
void MoveVertexCommand::undo()
|
||||
{
|
||||
m_shape->setVertex(m_activeVertex, oldPosition);
|
||||
m_mapperGLCanvas->update();
|
||||
emit m_mapperGLCanvas->shapeChanged(m_mapperGLCanvas->getCurrentShape());
|
||||
}
|
||||
|
||||
void MoveVertexCommand::redo()
|
||||
{
|
||||
m_shape->setVertex(m_activeVertex, newPosition);
|
||||
m_mapperGLCanvas->update();
|
||||
emit m_mapperGLCanvas->shapeChanged(m_mapperGLCanvas->getCurrentShape());
|
||||
}
|
||||
|
||||
+19
@@ -24,6 +24,7 @@
|
||||
|
||||
#include <QUndoCommand>
|
||||
#include "MainWindow.h"
|
||||
#include "MapperGLCanvas.h"
|
||||
|
||||
class AddShapesCommand : public QUndoCommand
|
||||
{
|
||||
@@ -39,4 +40,22 @@ private:
|
||||
|
||||
};
|
||||
|
||||
class MoveVertexCommand : public QUndoCommand
|
||||
{
|
||||
public:
|
||||
MoveVertexCommand(MapperGLCanvas *mapperGLCanvas, Shape *shape, int activeVertex, const QPointF &point, QUndoCommand *parent = 0);
|
||||
void undo();
|
||||
void redo();
|
||||
|
||||
signals:
|
||||
void shapeChanged(Shape*);
|
||||
|
||||
private:
|
||||
MapperGLCanvas *m_mapperGLCanvas;
|
||||
Shape *m_shape;
|
||||
int m_activeVertex;
|
||||
QPointF newPosition, oldPosition;
|
||||
|
||||
};
|
||||
|
||||
#endif /* COMMANDS_H_ */
|
||||
|
||||
@@ -374,6 +374,9 @@ public:
|
||||
void removeCurrentPaint();
|
||||
void removeCurrentMapping();
|
||||
|
||||
// Use the same undoStack for whole program
|
||||
QUndoStack* getUndoStack() { return undoStack; }
|
||||
|
||||
void startFullScreen();
|
||||
bool setOscPort(QString portNumber);
|
||||
bool setOscPort(int portNumber);
|
||||
|
||||
+5
-6
@@ -21,6 +21,7 @@
|
||||
#include "MapperGLCanvas.h"
|
||||
|
||||
#include "MainWindow.h"
|
||||
#include "Commands.h"
|
||||
|
||||
MapperGLCanvas::MapperGLCanvas(MainWindow* mainWindow, QWidget* parent, const QGLWidget * shareWidget)
|
||||
: QGLWidget(QGLFormat(QGL::SampleBuffers), parent, shareWidget),
|
||||
@@ -202,10 +203,9 @@ void MapperGLCanvas::mouseMoveEvent(QMouseEvent* event)
|
||||
// Stick to vertices.
|
||||
if (stickyVertices())
|
||||
glueVertex(shape, &p);
|
||||
shape->setVertex(_activeVertex, p);
|
||||
|
||||
update();
|
||||
emit shapeChanged(getCurrentShape());
|
||||
// Enable to Undo and Redo when mouse move the position of vertices
|
||||
getMainWindow()->getUndoStack()->push(new MoveVertexCommand(this, shape, _activeVertex, p));
|
||||
}
|
||||
}
|
||||
else if (_shapeGrabbed)
|
||||
@@ -268,9 +268,8 @@ void MapperGLCanvas::keyPressEvent(QKeyEvent* event)
|
||||
break;
|
||||
}
|
||||
// TODO: this will always be called even if no arrow key has been pressed (small performance issue).
|
||||
shape->setVertex(_activeVertex, p);
|
||||
update();
|
||||
emit shapeChanged(getCurrentShape());
|
||||
// Enable to Undo and Redo when arrow keys move the position of vertices
|
||||
getMainWindow()->getUndoStack()->push(new MoveVertexCommand(this, shape, _activeVertex, p));
|
||||
}
|
||||
|
||||
// Defer unhandled keys to parent.
|
||||
|
||||
Reference in New Issue
Block a user