diff --git a/resources/interface.qrc b/resources/interface.qrc index 1f1474e..d2c5642 100644 --- a/resources/interface.qrc +++ b/resources/interface.qrc @@ -56,5 +56,7 @@ images/icons/interface.png images/icons/solo.png images/icons/testsignal.png + images/icons/scale-vertex.svg + images/icons/rotate-vertex.svg diff --git a/src/core/Commands.cpp b/src/core/Commands.cpp index 144ee65..232fa68 100644 --- a/src/core/Commands.cpp +++ b/src/core/Commands.cpp @@ -173,8 +173,6 @@ ScaleRotateShapeCommand::ScaleRotateShapeCommand(MapperGLCanvas* canvas, Transfo _movedVertex(activeVertex), _initialShape(initialShape) { - setText(QObject::tr("Scale and rotate shape")); - // Initial vector from center. QPointF center = initialShape->getCenter(); QLineF initialVector(center, initialPositionPoint); @@ -188,10 +186,14 @@ ScaleRotateShapeCommand::ScaleRotateShapeCommand(MapperGLCanvas* canvas, Transfo // Create transform object. _transform.translate(+center.x(), +center.y()); - if (mode == MShape::RotateMode) + if (mode == MShape::RotateMode) { + setText(QObject::tr("Rotate shape")); _transform.rotate(rotation); - if (mode == MShape::ScaleMode) + } + if (mode == MShape::ScaleMode) { + setText(QObject::tr("Scale shape")); _transform.scale(scale, scale); + } _transform.translate(-center.x(), -center.y()); } diff --git a/src/core/MM.cpp b/src/core/MM.cpp index 6fb311d..49912d0 100644 --- a/src/core/MM.cpp +++ b/src/core/MM.cpp @@ -45,7 +45,7 @@ const QColor MM::CONTROL_COLOR(WHITE); const QColor MM::CONTROL_COLOR_NON_SELECTED(QColor(CONTROL_COLOR.red(), CONTROL_COLOR.green(), CONTROL_COLOR.blue(), 63)); const QColor MM::CONTROL_LOCKED_COLOR(LIGHT_RED); const QBrush MM::VERTEX_BACKGROUND(QColor(CROSSHAIR_STROKE.red(), CROSSHAIR_STROKE.green(), CROSSHAIR_STROKE.blue(), 63)); -const QBrush MM::VERTEX_SELECTED_BACKGROUND(QColor(CONTROL_COLOR.red(), CONTROL_COLOR.green(), CONTROL_COLOR.blue(), 127)); +const QBrush MM::VERTEX_SELECTED_BACKGROUND(QColor(CONTROL_COLOR.red(), CONTROL_COLOR.green(), CONTROL_COLOR.blue(), 192)); //const QBrush MM::VERTEX_LOCKED_BACKGROUND(QColor(CONTROL_LOCKED_COLOR.red(), CONTROL_LOCKED_COLOR.green(), CONTROL_LOCKED_COLOR.blue(), 63)); const QBrush MM::VERTEX_LOCKED_BACKGROUND(CONTROL_LOCKED_COLOR); @@ -57,7 +57,7 @@ const QPen MM::SHAPE_INNER_STROKE(QBrush(CONTROL_COLOR), SHAPE_INNER_STROKE_WIDT const qreal MM::VERTEX_STICK_RADIUS = 20; const qreal MM::VERTEX_SELECT_RADIUS = 10; const qreal MM::VERTEX_LOCKED_RADIUS = 6; -const qreal MM::VERTEX_SELECT_STROKE_WIDTH = 1; +const qreal MM::VERTEX_SELECT_STROKE_WIDTH = 1.5; // Time. const qreal MM::DEFAULT_FRAMES_PER_SECOND = 29.97f; diff --git a/src/core/Util.cpp b/src/core/Util.cpp index fbe3538..0f84a3f 100644 --- a/src/core/Util.cpp +++ b/src/core/Util.cpp @@ -150,7 +150,7 @@ Ellipse* createEllipseForColor(int frameWidth, int frameHeight) ); } -void drawControlsVertex(QPainter* painter, const QPointF& vertex, bool selected, bool locked, qreal radius, qreal strokeWidth) +void drawControlsVertex(QPainter* painter, const QPointF& vertex, bool selected, bool locked, MShape::ShapeMode shapeMode, qreal radius, qreal strokeWidth) { // Init colors and stroke. if (locked) @@ -160,13 +160,29 @@ void drawControlsVertex(QPainter* painter, const QPointF& vertex, bool selected, painter->setPen(locked ? QPen(MM::CONTROL_LOCKED_COLOR) : QPen(MM::CONTROL_COLOR, strokeWidth)); - // Draw ellipse. - painter->drawEllipse(vertex, radius, radius); + QRect target(vertex.x() - radius, vertex.y() - radius, radius * 2, radius * 2); + + switch (shapeMode) { + case MShape::ScaleMode: + if (!locked) + // Draw scale icons + painter->drawPixmap(target, QPixmap(":/vertex-scale")); + break; + case MShape::RotateMode: + if (!locked) + // Draw rotate icons + painter->drawPixmap(target, QPixmap(":/vertex-rotate")); + break; + default: + // Draw ellipse. + painter->drawEllipse(vertex, radius, radius); + break; + } // Draw cross. - qreal offset = sin(M_PI/4) * radius; - painter->drawLine( vertex + QPointF(offset, offset), vertex + QPointF(-offset, -offset) ); - painter->drawLine( vertex + QPointF(offset, -offset), vertex + QPointF(-offset, offset) ); + // qreal offset = sin(M_PI/4) * radius; + // painter->drawLine( vertex + QPointF(offset, offset), vertex + QPointF(-offset, -offset) ); + // painter->drawLine( vertex + QPointF(offset, -offset), vertex + QPointF(-offset, offset) ); } bool fileExists(const QString& filename) diff --git a/src/core/Util.h b/src/core/Util.h index c41ddc6..d9e91b8 100644 --- a/src/core/Util.h +++ b/src/core/Util.h @@ -68,7 +68,7 @@ Mesh* createMeshForColor(int frameWidth, int frameHeight); Triangle* createTriangleForColor(int frameWidth, int frameHeight); Ellipse* createEllipseForColor(int frameWidth, int frameHeight); -void drawControlsVertex(QPainter* painter, const QPointF& vertex, bool selected, bool locked, qreal radius = MM::VERTEX_SELECT_RADIUS, qreal strokeWidth = MM::VERTEX_SELECT_STROKE_WIDTH); +void drawControlsVertex(QPainter* painter, const QPointF& vertex, bool selected, bool locked, MShape::ShapeMode shapeMode, qreal radius = MM::VERTEX_SELECT_RADIUS, qreal strokeWidth = MM::VERTEX_SELECT_STROKE_WIDTH); /** * Checks if a file exists or not. diff --git a/src/gui/MapperGLCanvas.cpp b/src/gui/MapperGLCanvas.cpp index b40a457..eaa823f 100644 --- a/src/gui/MapperGLCanvas.cpp +++ b/src/gui/MapperGLCanvas.cpp @@ -267,6 +267,37 @@ void MapperGLCanvas::mousePressEvent(QMouseEvent* event) MShape::ptr selectedShape = getCurrentShape(); bool shapeSelectionChange = false; + // Check for vertex selection first. + if (event->buttons() & Qt::LeftButton) + { + if (selectedShape) + { + // 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 moved + mousePressedOnSomething = true; + + _grabbedObjectStartScenePosition = selectedShape->getVertex(i); + } + } + } + } + // Possibility of changing shape in output by clicking on it. MappingManager manager = getMainWindow()->getMappingManager(); QVector mappings = manager.getVisibleMappings(); @@ -276,7 +307,7 @@ void MapperGLCanvas::mousePressEvent(QMouseEvent* event) MShape::ptr shape = getShapeFromMapping(*it); // Check if mouse was pressed on that shape. - if (shape && shape->includesPoint(pos)) + if (shape && !_vertexGrabbed && shape->includesPoint(pos)) { mousePressedOnSomething = true; @@ -298,7 +329,7 @@ void MapperGLCanvas::mousePressEvent(QMouseEvent* event) } } - if (selectedShape && selectedShape->includesPoint(pos)) { + if (selectedShape && !_vertexGrabbed && selectedShape->includesPoint(pos)) { if (event->buttons() & Qt::LeftButton) { // Shape can be grabbed only if it is not locked _shapeGrabbed = !selectedShape->isLocked(); @@ -321,38 +352,6 @@ void MapperGLCanvas::mousePressEvent(QMouseEvent* event) emit shapeContextMenuRequested(event->pos()); // Show the shape/mapping context menu } } - - // Check for vertex selection first. - if (event->buttons() & Qt::LeftButton) - { - // MShape::ptr shape = getCurrentShape(); - if (selectedShape) - { - // 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); - } - } - } - } } if (mousePressedOnSomething) diff --git a/src/gui/ShapeControlPainter.cpp b/src/gui/ShapeControlPainter.cpp index 038a5f0..0000e24 100644 --- a/src/gui/ShapeControlPainter.cpp +++ b/src/gui/ShapeControlPainter.cpp @@ -42,7 +42,7 @@ void ShapeControlPainter::_paintVertices(QPainter *painter, MapperGLCanvas* canv qreal strokeWidth = MM::VERTEX_SELECT_STROKE_WIDTH / zoomFactor; for (int i=0; inVertices(); i++) - Util::drawControlsVertex(painter, getShape()->getVertex(i), selectedVertices.contains(i), getShape()->isLocked(), selectRadius, strokeWidth); + Util::drawControlsVertex(painter, getShape()->getVertex(i), selectedVertices.contains(i), getShape()->isLocked(), getShape()->shapeModeState(), selectRadius, strokeWidth); } QPen ShapeControlPainter::getRescaledShapeStroke(MapperGLCanvas* canvas, bool selected, bool innerStroke) diff --git a/src/gui/ShapeGraphicsItem.cpp b/src/gui/ShapeGraphicsItem.cpp index a33a00e..a95e618 100644 --- a/src/gui/ShapeGraphicsItem.cpp +++ b/src/gui/ShapeGraphicsItem.cpp @@ -312,7 +312,7 @@ void TextureGraphicsItem::_postPaint(QPainter* painter, QSharedPointer TextureGraphicsItem::_getTexture() { - return qSharedPointerCast(_textureMapping.toStrongRef()->getPaint()); + return qSharedPointerCast(_textureMapping.toStrongRef()->getPaint()); } QPainterPath PolygonTextureGraphicsItem::shape() const