Changeset View
Changeset View
Standalone View
Standalone View
plugins/tools/defaulttool/defaulttool/ShapeMoveStrategy.cpp
Show All 26 Lines | |||||
27 | #include <KoShapeContainer.h> | 27 | #include <KoShapeContainer.h> | ||
28 | #include <KoShapeContainerModel.h> | 28 | #include <KoShapeContainerModel.h> | ||
29 | #include <commands/KoShapeMoveCommand.h> | 29 | #include <commands/KoShapeMoveCommand.h> | ||
30 | #include <KoSnapGuide.h> | 30 | #include <KoSnapGuide.h> | ||
31 | #include <KoPointerEvent.h> | 31 | #include <KoPointerEvent.h> | ||
32 | #include <KoToolBase.h> | 32 | #include <KoToolBase.h> | ||
33 | #include <KoSelection.h> | 33 | #include <KoSelection.h> | ||
34 | #include <klocalizedstring.h> | 34 | #include <klocalizedstring.h> | ||
35 | #include <kis_global.h> | ||||
35 | 36 | | |||
36 | ShapeMoveStrategy::ShapeMoveStrategy(KoToolBase *tool, const QPointF &clicked) | 37 | ShapeMoveStrategy::ShapeMoveStrategy(KoToolBase *tool, const QPointF &clicked) | ||
37 | : KoInteractionStrategy(tool) | 38 | : KoInteractionStrategy(tool) | ||
38 | , m_start(clicked) | 39 | , m_start(clicked) | ||
39 | , m_canvas(tool->canvas()) | 40 | , m_canvas(tool->canvas()) | ||
40 | { | 41 | { | ||
41 | QList<KoShape *> selectedShapes = m_canvas->shapeManager()->selection()->selectedShapes(KoFlake::StrippedSelection); | 42 | QList<KoShape *> selectedShapes = m_canvas->shapeManager()->selection()->selectedShapes(KoFlake::StrippedSelection); | ||
42 | QRectF boundingRect; | 43 | QRectF boundingRect; | ||
Show All 16 Lines | |||||
59 | 60 | | |||
60 | void ShapeMoveStrategy::handleMouseMove(const QPointF &point, Qt::KeyboardModifiers modifiers) | 61 | void ShapeMoveStrategy::handleMouseMove(const QPointF &point, Qt::KeyboardModifiers modifiers) | ||
61 | { | 62 | { | ||
62 | if (m_selectedShapes.isEmpty()) { | 63 | if (m_selectedShapes.isEmpty()) { | ||
63 | return; | 64 | return; | ||
64 | } | 65 | } | ||
65 | QPointF diff = point - m_start; | 66 | QPointF diff = point - m_start; | ||
66 | 67 | | |||
67 | if (modifiers & (Qt::AltModifier | Qt::ControlModifier)) { | 68 | if (modifiers & Qt::ShiftModifier) { | ||
68 | // keep x or y position unchanged | 69 | // Limit change to one direction only | ||
69 | if (qAbs(diff.x()) < qAbs(diff.y())) { | 70 | diff = snapToClosestAxis(diff); | ||
70 | diff.setX(0); | | |||
71 | } else { | | |||
72 | diff.setY(0); | | |||
73 | } | | |||
74 | } else { | 71 | } else { | ||
75 | QPointF positionToSnap = point + m_initialOffset; | 72 | QPointF positionToSnap = point + m_initialOffset; | ||
76 | tool()->canvas()->updateCanvas(tool()->canvas()->snapGuide()->boundingRect()); | 73 | tool()->canvas()->updateCanvas(tool()->canvas()->snapGuide()->boundingRect()); | ||
77 | QPointF snappedPosition = tool()->canvas()->snapGuide()->snap(positionToSnap, modifiers); | 74 | QPointF snappedPosition = tool()->canvas()->snapGuide()->snap(positionToSnap, modifiers); | ||
78 | tool()->canvas()->updateCanvas(tool()->canvas()->snapGuide()->boundingRect()); | 75 | tool()->canvas()->updateCanvas(tool()->canvas()->snapGuide()->boundingRect()); | ||
79 | diff = snappedPosition - m_initialOffset - m_start; | 76 | diff = snappedPosition - m_initialOffset - m_start; | ||
80 | } | 77 | } | ||
81 | 78 | | |||
82 | m_diff = diff; | 79 | m_diff = diff; | ||
83 | 80 | | |||
84 | moveSelection(); | 81 | moveSelection(); | ||
85 | } | 82 | } | ||
86 | 83 | | |||
87 | void ShapeMoveStrategy::handleCustomEvent(KoPointerEvent *event) | 84 | void ShapeMoveStrategy::handleCustomEvent(KoPointerEvent *event) | ||
88 | { | 85 | { | ||
89 | QPointF diff = tool()->canvas()->viewConverter()->viewToDocument(event->pos()); | 86 | QPointF diff = tool()->canvas()->viewConverter()->viewToDocument(event->pos()); | ||
90 | 87 | | |||
91 | if (event->modifiers() & (Qt::AltModifier | Qt::ControlModifier)) { | 88 | if (event->modifiers() & Qt::ShiftModifier) { | ||
92 | // keep x or y position unchanged | 89 | // Limit change to one direction only | ||
93 | if (qAbs(diff.x()) < qAbs(diff.y())) { | 90 | diff = snapToClosestAxis(diff); | ||
94 | diff.setX(0); | | |||
95 | } else { | | |||
96 | diff.setY(0); | | |||
97 | } | | |||
98 | } | 91 | } | ||
99 | 92 | | |||
100 | m_diff += 0.1 * diff; | 93 | m_diff += 0.1 * diff; | ||
101 | 94 | | |||
102 | moveSelection(); | 95 | moveSelection(); | ||
103 | } | 96 | } | ||
104 | 97 | | |||
105 | void ShapeMoveStrategy::moveSelection() | 98 | void ShapeMoveStrategy::moveSelection() | ||
▲ Show 20 Lines • Show All 42 Lines • Show Last 20 Lines |