diff --git a/src/core/Commands.cpp b/src/core/Commands.cpp index 914c5c8..144ee65 100644 --- a/src/core/Commands.cpp +++ b/src/core/Commands.cpp @@ -148,7 +148,7 @@ int MoveVertexCommand::id() const { return (_option == STEP ? CMD_KEY_MOVE_VERTE void MoveVertexCommand::_doTransform(MShape::ptr shape) { - shape->setVertex(_movedVertex, _vertexPosition); + shape->setVertex(_movedVertex, _vertexPosition); } bool MoveVertexCommand::mergeWith(const QUndoCommand* other) @@ -168,10 +168,10 @@ bool MoveVertexCommand::mergeWith(const QUndoCommand* other) } -ScaleRotateShapeCommand::ScaleRotateShapeCommand(MapperGLCanvas* canvas, TransformShapeOption option, int activeVertex, const QPointF &point, const QPointF& initialPositionPoint, const MShape::ptr& initialShape, QUndoCommand *parent) +ScaleRotateShapeCommand::ScaleRotateShapeCommand(MapperGLCanvas* canvas, TransformShapeOption option, int activeVertex, const QPointF &point, const QPointF& initialPositionPoint, const MShape::ptr& initialShape, MShape::ShapeMode mode, QUndoCommand *parent) : TransformShapeCommand(canvas, option, parent), _movedVertex(activeVertex), - _initialShape(initialShape) + _initialShape(initialShape) { setText(QObject::tr("Scale and rotate shape")); @@ -186,11 +186,12 @@ ScaleRotateShapeCommand::ScaleRotateShapeCommand(MapperGLCanvas* canvas, Transfo // Compute rotation. qreal rotation = currentVector.angleTo(initialVector); - // Create transform object. - // transform.rotate(rotation); + // Create transform object. _transform.translate(+center.x(), +center.y()); - _transform.rotate(rotation); - _transform.scale(scale, scale); + if (mode == MShape::RotateMode) + _transform.rotate(rotation); + if (mode == MShape::ScaleMode) + _transform.scale(scale, scale); _transform.translate(-center.x(), -center.y()); } @@ -214,10 +215,10 @@ bool ScaleRotateShapeCommand::mergeWith(const QUndoCommand* other) if (cmd->_movedVertex != _movedVertex) return false; - _option = cmd->_option; + _option = cmd->_option; _transform = cmd->_transform; - return true; + return true; } diff --git a/src/core/Commands.h b/src/core/Commands.h index 5af334b..3110e8b 100644 --- a/src/core/Commands.h +++ b/src/core/Commands.h @@ -32,8 +32,8 @@ enum CommandId { CMD_MOUSE_MOVE_VERTEX, CMD_KEY_TRANSLATE_SHAPE, CMD_MOUSE_TRANSLATE_SHAPE, - CMD_KEY_SCALE_ROTATE_SHAPE, - CMD_MOUSE_SCALE_ROTATE_SHAPE, + CMD_KEY_SCALE_ROTATE_SHAPE, + CMD_MOUSE_SCALE_ROTATE_SHAPE, }; class MainWindow; @@ -125,7 +125,7 @@ protected: class ScaleRotateShapeCommand : public TransformShapeCommand { public: - ScaleRotateShapeCommand(MapperGLCanvas* canvas, TransformShapeOption option, int activeVertex, const QPointF &point, const QPointF& initialPositionPoint, const MShape::ptr& initialShape, QUndoCommand *parent = 0); + ScaleRotateShapeCommand(MapperGLCanvas* canvas, TransformShapeOption option, int activeVertex, const QPointF &point, const QPointF& initialPositionPoint, const MShape::ptr& initialShape, MShape::ShapeMode mode, QUndoCommand *parent = 0); int id() const; bool mergeWith(const QUndoCommand* other); @@ -136,8 +136,8 @@ protected: // Information pertaining to the moving of vertex. int _movedVertex; - QTransform _transform; - MShape::ptr _initialShape; + QTransform _transform; + MShape::ptr _initialShape; }; class TranslateShapeCommand : public TransformShapeCommand diff --git a/src/gui/MapperGLCanvas.cpp b/src/gui/MapperGLCanvas.cpp index 4122f6b..b40a457 100644 --- a/src/gui/MapperGLCanvas.cpp +++ b/src/gui/MapperGLCanvas.cpp @@ -28,13 +28,13 @@ namespace mmp { MapperGLCanvas::MapperGLCanvas(MainWindow* mainWindow, - bool isOutput, QWidget* parent, const QGLWidget * shareWidget, - QGraphicsScene* scene) + bool isOutput, QWidget* parent, const QGLWidget * shareWidget, + QGraphicsScene* scene) : QGraphicsView(parent), _mainWindow(mainWindow), _isOutput(isOutput), - _scaleRotateMode(false), _vertexGrabbed(false), + _vertexMoved(false), _activeVertex(NO_VERTEX), _shapeGrabbed(false), // comment out? _shapeFirstGrab(false), // comment out? @@ -129,7 +129,7 @@ void MapperGLCanvas::drawForeground(QPainter *painter , const QRectF &rect) { QMap paintMappings = _mainWindow->getMappingManager().getPaintMappings( _mainWindow->getCurrentPaint() ); for (QMap::const_iterator it = paintMappings.constBegin(); - it != paintMappings.constEnd(); ++it) + it != paintMappings.constEnd(); ++it) { if (it.key() != mid) { @@ -218,7 +218,7 @@ void MapperGLCanvas::dropEvent(QDropEvent *event) if (!fileName.isEmpty()) { // Test if is mmp file and exit loop if (MainWindow::window()->fileSupported(fileName, MM::FILE_EXTENSION)) { - MainWindow::window()->loadFile(fileName); + MainWindow::window()->loadFile(fileName); // Exit for prevent drag to many project files break; } @@ -247,72 +247,31 @@ void MapperGLCanvas::mousePressEvent(QMouseEvent* event) QPointF pos = mapToScene(event->pos()); // Drag the scene with middle button. - if (event->buttons() & Qt::MiddleButton) - { - // NOTE: This is a trick code to implement scroll hand drag using the middle button. - QMouseEvent releaseEvent(QEvent::MouseButtonRelease, event->pos(), - event->globalPos(), Qt::LeftButton, 0, event->modifiers()); - QGraphicsView::mouseReleaseEvent(&releaseEvent); - setDragMode(QGraphicsView::ScrollHandDrag); + // if (event->buttons() & Qt::MiddleButton) + // { + // // NOTE: This is a trick code to implement scroll hand drag using the middle button. + // QMouseEvent releaseEvent(QEvent::MouseButtonRelease, event->pos(), + // event->globalPos(), Qt::LeftButton, 0, event->modifiers()); + // QGraphicsView::mouseReleaseEvent(&releaseEvent); + // setDragMode(QGraphicsView::ScrollHandDrag); - // We need to pretend it is actually the left button that was pressed! - QMouseEvent fakeEvent(event->type(), event->pos(), event->globalPos(), - Qt::LeftButton, event->buttons() | Qt::LeftButton, event->modifiers()); - QGraphicsView::mousePressEvent(&fakeEvent); - } - - // Check for vertex selection first. - else if (event->buttons() & Qt::LeftButton) - { - MShape::ptr shape = getCurrentShape(); - if (shape) - { - // Switch mode to scale&rotate on pressing CTLR. - _scaleRotateMode = (event->modifiers() & Qt::ControlModifier); - - // Shape is locked either if either itself or its mapping is locked. - bool shapeIsLocked = _mainWindow->getCurrentMapping()->isLocked() || shape->isLocked(); - - // Note: we compare with the square value for fastest computation of the distance - int minDistance = sq(MM::VERTEX_SELECT_RADIUS); - - _grabbedShapeStartCenterScenePosition = shape->getCenter(); - _grabbedShapeCopy.reset(shape->clone()); - - // Find the ID of the nearest vertex (from currently selected shape) - for (int i = 0; i < shape->nVertices(); i++) - { - int dist = distSq(_mousePressedPosition, mapFromScene(shape->getVertex(i))); // squared distance - if (dist < minDistance) - { - _activeVertex = i; - minDistance = dist; - - // Vertex can be grabbed only if the mapping is not locked - _vertexGrabbed = !shapeIsLocked; - mousePressedOnSomething = true; - - _grabbedObjectStartScenePosition = shape->getVertex(i); - } - } - } - } - - if (mousePressedOnSomething) - { - return; - } + // // We need to pretend it is actually the left button that was pressed! + // QMouseEvent fakeEvent(event->type(), event->pos(), event->globalPos(), + // Qt::LeftButton, event->buttons() | Qt::LeftButton, event->modifiers()); + // QGraphicsView::mousePressEvent(&fakeEvent); + // } // Check for shape selection. - if (event->buttons() & (Qt::LeftButton | Qt::RightButton)) // Add Right click for context menu + if (event->buttons() & (Qt::LeftButton | Qt::RightButton)) { MShape::ptr selectedShape = getCurrentShape(); + bool shapeSelectionChange = false; // Possibility of changing shape in output by clicking on it. MappingManager manager = getMainWindow()->getMappingManager(); QVector mappings = manager.getVisibleMappings(); for (QVector::const_iterator it = mappings.end() - 1; - it >= mappings.begin(); --it) + it >= mappings.begin(); --it) { MShape::ptr shape = getShapeFromMapping(*it); @@ -332,31 +291,66 @@ void MapperGLCanvas::mousePressEvent(QMouseEvent* event) // Reset selected shape to new one. selectedShape = getCurrentShape(); + shapeSelectionChange = true; } - break; + break; // Exit loop } } - // Grab the shape. - if (event->buttons() & Qt::LeftButton) // This preserve me from duplicate code above - { - if (selectedShape && selectedShape->includesPoint(pos)) - { + if (selectedShape && selectedShape->includesPoint(pos)) { + if (event->buttons() & Qt::LeftButton) { // Shape can be grabbed only if it is not locked - _shapeGrabbed = selectedShape->isLocked() ? false : true; + _shapeGrabbed = !selectedShape->isLocked(); _shapeFirstGrab = true; _grabbedObjectStartScenePosition = pos; -// _grabbedShapeStartCenterScenePosition = selectedShape->getCenter(); + // _grabbedShapeStartCenterScenePosition = selectedShape->getCenter(); + + if (shapeSelectionChange) { // if fresh selected shape + // Reset shape Mode + selectedShape->setShapeMode(MShape::DefaultMode); + } else { + // Move to the next mode + selectedShape->setShapeMode(selectedShape->shapeModeState(), true); + } + } + + // Add Right click for context menu + if (event->buttons() & Qt::RightButton) { + emit shapeContextMenuRequested(event->pos()); // Show the shape/mapping context menu } } - // Show the shape/mapping context menu - if (event->button() & Qt::RightButton) + + // Check for vertex selection first. + if (event->buttons() & Qt::LeftButton) { - if (selectedShape && selectedShape->includesPoint(pos)) + // MShape::ptr shape = getCurrentShape(); + if (selectedShape) { - emit shapeContextMenuRequested(event->pos()); + // Note: we compare with the square value for fastest computation of the distance + int minDistance = sq(MM::VERTEX_SELECT_RADIUS); + + _grabbedShapeStartCenterScenePosition = selectedShape->getCenter(); + _grabbedShapeCopy.reset(selectedShape->clone()); + + // Find the ID of the nearest vertex (from currently selected shape) + for (int i = 0; i < selectedShape->nVertices(); i++) + { + int dist = distSq(_mousePressedPosition, mapFromScene(selectedShape->getVertex(i))); // squared distance + if (dist < minDistance) + { + _activeVertex = i; + minDistance = dist; + + // Vertex can be grabbed only if the mapping is not locked + _vertexGrabbed = !selectedShape->isLocked(); + _vertexMoved = false; // Active vertex may not movedl + mousePressedOnSomething = true; + + _grabbedObjectStartScenePosition = selectedShape->getVertex(i); + } + } } } } @@ -378,18 +372,18 @@ void MapperGLCanvas::mouseReleaseEvent(QMouseEvent* event) if (event->buttons() & Qt::MiddleButton) { QMouseEvent fakeEvent( - event->type(), event->pos(), event->globalPos(), - Qt::LeftButton, event->buttons() & ~Qt::LeftButton, - event->modifiers()); + event->type(), event->pos(), event->globalPos(), + Qt::LeftButton, event->buttons() & ~Qt::LeftButton, + event->modifiers()); QGraphicsView::mouseReleaseEvent(&fakeEvent); setDragMode(QGraphicsView::NoDrag); setCursor(Qt::ArrowCursor); } -// // Click on vertex ==> select the vertex. -// if ((event->buttons() & Qt::LeftButton) && _mousePressedOnVertex) -// { -// } - if (_vertexGrabbed) + // // Click on vertex ==> select the vertex. + // if ((event->buttons() & Qt::LeftButton) && _mousePressedOnVertex) + // { + // } + if (_vertexGrabbed && _vertexMoved) { // TODO : code repetition here!!! QPointF p = mapToScene(event->pos()); @@ -400,19 +394,31 @@ void MapperGLCanvas::mouseReleaseEvent(QMouseEvent* event) _snapVertex(&p); } - if (_scaleRotateMode) - undoStack->push(new ScaleRotateShapeCommand(this, - TransformShapeCommand::RELEASE, _activeVertex, p, _grabbedObjectStartScenePosition, _grabbedShapeCopy)); - else - undoStack->push(new MoveVertexCommand(this, - TransformShapeCommand::RELEASE, _activeVertex, p)); + switch (getCurrentShape()->shapeModeState()) { + case MShape::RotateMode: + undoStack->push(new ScaleRotateShapeCommand(this, + TransformShapeCommand::RELEASE, _activeVertex, p, _grabbedObjectStartScenePosition, _grabbedShapeCopy, MShape::RotateMode)); + break; + case MShape::ScaleMode: + undoStack->push(new ScaleRotateShapeCommand(this, + TransformShapeCommand::RELEASE, _activeVertex, p, _grabbedObjectStartScenePosition, _grabbedShapeCopy, MShape::ScaleMode)); + break; + default: + undoStack->push(new MoveVertexCommand(this, + TransformShapeCommand::RELEASE, _activeVertex, p)); + break; + } + + } else if (_shapeGrabbed) { undoStack->push(new TranslateShapeCommand(this, - TransformShapeCommand::RELEASE, QPointF())); + TransformShapeCommand::RELEASE, QPointF())); } + _vertexGrabbed = false; + _vertexMoved = false; _shapeGrabbed = false; } @@ -432,12 +438,13 @@ void MapperGLCanvas::mouseMoveEvent(QMouseEvent* event) MShape::ptr shape = getCurrentShape(); if (shape && hasActiveVertex()) { -// QPointF p = shape->getVertex(_activeVertex); -// // Set point to mouse coordinates. -// p.setX(pos.x()); -// p.setY(pos.y()); + // QPointF p = shape->getVertex(_activeVertex); + // // Set point to mouse coordinates. + // p.setX(pos.x()); + // p.setY(pos.y()); QPointF p = scenePos; + _vertexMoved = true; // The active vertex is actually moved // Stick to vertices. if (xOr(_mainWindow->isStickyVertices(), (event->modifiers() & Qt::ShiftModifier))) @@ -445,12 +452,20 @@ void MapperGLCanvas::mouseMoveEvent(QMouseEvent* event) _snapVertex(&p); } - if (_scaleRotateMode) - undoStack->push(new ScaleRotateShapeCommand(this, - TransformShapeCommand::FREE, _activeVertex, p, _grabbedObjectStartScenePosition, _grabbedShapeCopy)); - else - undoStack->push(new MoveVertexCommand(this, - TransformShapeCommand::FREE, _activeVertex, p)); + switch (getCurrentShape()->shapeModeState()) { + case MShape::RotateMode: + undoStack->push(new ScaleRotateShapeCommand(this, + TransformShapeCommand::FREE, _activeVertex, p, _grabbedObjectStartScenePosition, _grabbedShapeCopy, MShape::RotateMode)); + break; + case MShape::ScaleMode: + undoStack->push(new ScaleRotateShapeCommand(this, + TransformShapeCommand::FREE, _activeVertex, p, _grabbedObjectStartScenePosition, _grabbedShapeCopy, MShape::ScaleMode)); + break; + default: + undoStack->push(new MoveVertexCommand(this, + TransformShapeCommand::FREE, _activeVertex, p)); + break; + } } } @@ -465,6 +480,8 @@ void MapperGLCanvas::mouseMoveEvent(QMouseEvent* event) { lastMousePos = _mousePressedPosition; _shapeFirstGrab = false; + // Reset the mode after moved shape + getCurrentShape()->setShapeMode(MShape::DefaultMode); } } QPointF diff = scenePos - mapToScene(lastMousePos); @@ -505,77 +522,76 @@ void MapperGLCanvas::keyPressEvent(QKeyEvent* event) // SHIFT + directional keys allow move with large steps switch (event->key()) { - case Qt::Key_Up: - pos.ry() -= MM::BigStep; - break; - case Qt::Key_Down: - pos.ry() += MM::BigStep; - break; - case Qt::Key_Right: - pos.rx() += MM::BigStep; - break; - case Qt::Key_Left: - pos.rx() -= MM::BigStep; - break; - // SHIFT+Space to switch between vertex - case Qt::Key_Space: - _activeVertex = (_activeVertex + 1) % shape->nVertices(); - pos = mapFromScene(shape->getVertex(_activeVertex)); // reset to new vertex - break; - default: - handledKey = false; - break; + case Qt::Key_Up: + pos.ry() -= MM::BigStep; + break; + case Qt::Key_Down: + pos.ry() += MM::BigStep; + break; + case Qt::Key_Right: + pos.rx() += MM::BigStep; + break; + case Qt::Key_Left: + pos.rx() -= MM::BigStep; + break; + // SHIFT+Space to switch between vertex + case Qt::Key_Space: + _activeVertex = (_activeVertex + 1) % shape->nVertices(); + pos = mapFromScene(shape->getVertex(_activeVertex)); // reset to new vertex + break; + default: + handledKey = false; + break; } } else if (event->modifiers() & Qt::AltModifier) { switch (event->key()) { - case Qt::Key_Up: - pos.ry() -= MM::SmallStep; - break; - case Qt::Key_Down: - pos.ry() += MM::SmallStep; - break; - case Qt::Key_Right: - pos.rx() += MM::SmallStep; - break; - case Qt::Key_Left: - pos.rx() -= MM::SmallStep; - break; - default: - handledKey = false; - break; + case Qt::Key_Up: + pos.ry() -= MM::SmallStep; + break; + case Qt::Key_Down: + pos.ry() += MM::SmallStep; + break; + case Qt::Key_Right: + pos.rx() += MM::SmallStep; + break; + case Qt::Key_Left: + pos.rx() -= MM::SmallStep; + break; + default: + handledKey = false; + break; } } else { switch (event->key()) { - case Qt::Key_Up: - pos.ry() -= MM::MediumStep; - break; - case Qt::Key_Down: - pos.ry() += MM::MediumStep; - break; - case Qt::Key_Right: - pos.rx() += MM::MediumStep; - break; - case Qt::Key_Left: - pos.rx() -= MM::MediumStep; - break; - default: - handledKey = false; - break; + case Qt::Key_Up: + pos.ry() -= MM::MediumStep; + break; + case Qt::Key_Down: + pos.ry() += MM::MediumStep; + break; + case Qt::Key_Right: + pos.rx() += MM::MediumStep; + break; + case Qt::Key_Left: + pos.rx() -= MM::MediumStep; + break; + default: + handledKey = false; + break; } } if (handledKey) { - if (!_scaleRotateMode) - // Enable to Undo and Redo when arrow keys move the position of vertices - undoStack->push(new MoveVertexCommand(this, - TransformShapeCommand::STEP, _activeVertex, mapToScene(pos))); + // Enable to Undo and Redo when arrow keys move the position of vertices + undoStack->push(new MoveVertexCommand(this, + TransformShapeCommand::STEP, _activeVertex, mapToScene(pos))); } } else @@ -611,7 +627,7 @@ void MapperGLCanvas::keyPressEvent(QKeyEvent* event) // Case 2: zoom in with CTRL+= else if (event->key() == Qt::Key_Equal || // Case 3: zoom in with CTRL+SHIFT++ - ((event->modifiers() & Qt::ShiftModifier) && event->key() == Qt::Key_Plus)) + ((event->modifiers() & Qt::ShiftModifier) && event->key() == Qt::Key_Plus)) { increaseZoomLevel(); } @@ -642,6 +658,22 @@ void MapperGLCanvas::keyPressEvent(QKeyEvent* event) this->horizontalScrollBar()->setValue(scrollX); } + if (getCurrentShape()) { + switch (event->key()) { + case Qt::Key_M: + getCurrentShape()->setShapeMode(MShape::DefaultMode); + break; + case Qt::Key_S: + getCurrentShape()->setShapeMode(MShape::ScaleMode); + break; + case Qt::Key_R: + getCurrentShape()->setShapeMode(MShape::RotateMode); + break; + default: + break; + } + } + // Defer unhandled keys to parent. if (! handledKey) { @@ -659,6 +691,7 @@ void MapperGLCanvas::deselectVertices() { _activeVertex = NO_VERTEX; _vertexGrabbed = false; + _vertexMoved = false; } void MapperGLCanvas::deselectAll() @@ -692,20 +725,20 @@ void MapperGLCanvas::wheelEvent(QWheelEvent *event) // Accept wheel scrolling event. event->accept(); } else { // control is not pressed: scroll - QScrollBar* scrollbar; - if (shift_is_pressed) { // shift is pressed: pans horizontally - scrollbar = this->horizontalScrollBar(); - } else { // shift is not pressed: scrolls vertically - scrollbar = this->verticalScrollBar(); - } - // FIXME: scrolling with the mouse doesn't currently work - int scroll = scrollbar->value(); - if (deltaLevel > 0) { - scrollbar->setValue(scroll + 50); - } else { - scrollbar->setValue(scroll - 50); - } - event->accept(); + QScrollBar* scrollbar; + if (shift_is_pressed) { // shift is pressed: pans horizontally + scrollbar = this->horizontalScrollBar(); + } else { // shift is not pressed: scrolls vertically + scrollbar = this->verticalScrollBar(); + } + // FIXME: scrolling with the mouse doesn't currently work + int scroll = scrollbar->value(); + if (deltaLevel > 0) { + scrollbar->setValue(scroll + 50); + } else { + scrollbar->setValue(scroll - 50); + } + event->accept(); } } diff --git a/src/gui/MapperGLCanvas.h b/src/gui/MapperGLCanvas.h index d33277f..a965a5c 100644 --- a/src/gui/MapperGLCanvas.h +++ b/src/gui/MapperGLCanvas.h @@ -152,11 +152,10 @@ private: QPointF _grabbedShapeStartCenterScenePosition; MShape::ptr _grabbedShapeCopy; - // Scale and rotate mode selected. - bool _scaleRotateMode; - // Mouse currently pressed inside a vertex. bool _vertexGrabbed; + // If current vertex is moved + bool _vertexMoved; // Index of currently active vertex. int _activeVertex; diff --git a/src/shape/Shape.cpp b/src/shape/Shape.cpp index 6c21924..be83e12 100644 --- a/src/shape/Shape.cpp +++ b/src/shape/Shape.cpp @@ -38,11 +38,20 @@ MShape* MShape::clone() const { return copyShape; } +void MShape::setShapeMode(MShape::ShapeMode mode, bool next) +{ + if (!next) + _shapeMode = mode; + else + _shapeMode = static_cast((mode + 1) % 3); + +} + void MShape::applyTransform(const QTransform& transform) { - for (QVector::iterator it = vertices.begin(); + for (QVector::iterator it = vertices.begin(); it != vertices.end(); ++it) - (*it) = transform.map(*it); + (*it) = transform.map(*it); } void MShape::transform(const QPointF& translate, qreal scale, qreal rotate) @@ -85,11 +94,11 @@ void MShape::scale(qreal scaling) QPointF MShape::getCenter() const { - QPointF center; + QPointF center; for (QVector::const_iterator it = vertices.begin(); it != vertices.end(); ++it) center += (*it); - center /= nVertices(); - return center; + center /= nVertices(); + return center; } void MShape::read(const QDomElement& obj) diff --git a/src/shape/Shape.h b/src/shape/Shape.h index 5931f8a..5fdb4c6 100644 --- a/src/shape/Shape.h +++ b/src/shape/Shape.h @@ -53,6 +53,14 @@ class MShape : public Serializable Q_PROPERTY(bool locked READ isLocked WRITE setLocked) Q_PROPERTY(QVector vertices READ getVertices WRITE setVertices STORED false) public: + + // Enumerations + enum ShapeMode { + DefaultMode, + ScaleMode, + RotateMode + }; + typedef QSharedPointer ptr; MShape() : _isLocked(false) {} @@ -82,7 +90,7 @@ public: setVertex(i, QPointF(x, y)); } - virtual void applyTransform(const QTransform& transform); + virtual void applyTransform(const QTransform& transform); virtual QString getType() const = 0; @@ -96,7 +104,7 @@ public: virtual bool includesPoint(const QPointF& p) = 0; - virtual void transform(const QPointF& translate, qreal scale, qreal rotate); + virtual void transform(const QPointF& translate, qreal scale, qreal rotate); /// Translate all vertices of shape by the vector (x,y). virtual void translate(const QPointF& offset); @@ -105,14 +113,17 @@ public: virtual void rotate(qreal angle); virtual void scale(qreal scaling); - virtual void copyFrom(const MShape& shape); + virtual void copyFrom(const MShape& shape); - virtual MShape* clone() const; + virtual MShape* clone() const; bool isLocked() const { return _isLocked; } void setLocked(bool locked) { _isLocked = locked; } void toggleLocked() { _isLocked = !_isLocked; } + MShape::ShapeMode shapeModeState() const { return _shapeMode; } + void setShapeMode(MShape::ShapeMode mode, bool next = false); + const QVector& getVertices() const { return vertices; } virtual void setVertices(const QVector& vertices_) { @@ -146,6 +157,9 @@ protected: // Lists QProperties that should NOT be parsed automatically. virtual QList _propertiesSpecial() const { return Serializable::_propertiesSpecial() << "vertices"; } + +private: + MShape::ShapeMode _shapeMode = MShape::DefaultMode; };