mirror of
https://github.com/mapmapteam/mapmap.git
synced 2026-06-16 12:33:19 +02:00
Implement scale/rotate icons and minor fix
This commit is contained in:
@@ -56,5 +56,7 @@
|
||||
<file alias="pref-interface">images/icons/interface.png</file>
|
||||
<file alias="solo-mapping">images/icons/solo.png</file>
|
||||
<file alias="toggle-test-signal">images/icons/testsignal.png</file>
|
||||
<file alias="vertex-scale">images/icons/scale-vertex.svg</file>
|
||||
<file alias="vertex-rotate">images/icons/rotate-vertex.svg</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -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;
|
||||
|
||||
+22
-6
@@ -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)
|
||||
|
||||
+1
-1
@@ -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.
|
||||
|
||||
+33
-34
@@ -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<Mapping::ptr> 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)
|
||||
|
||||
@@ -42,7 +42,7 @@ void ShapeControlPainter::_paintVertices(QPainter *painter, MapperGLCanvas* canv
|
||||
qreal strokeWidth = MM::VERTEX_SELECT_STROKE_WIDTH / zoomFactor;
|
||||
|
||||
for (int i=0; i<getShape()->nVertices(); 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)
|
||||
|
||||
@@ -312,7 +312,7 @@ void TextureGraphicsItem::_postPaint(QPainter* painter,
|
||||
|
||||
QSharedPointer<Texture> TextureGraphicsItem::_getTexture()
|
||||
{
|
||||
return qSharedPointerCast<Texture>(_textureMapping.toStrongRef()->getPaint());
|
||||
return qSharedPointerCast<Texture>(_textureMapping.toStrongRef()->getPaint());
|
||||
}
|
||||
|
||||
QPainterPath PolygonTextureGraphicsItem::shape() const
|
||||
|
||||
Reference in New Issue
Block a user