Krita Source Code Documentation
Loading...
Searching...
No Matches
ShapeMoveStrategy Class Reference

#include <ShapeMoveStrategy.h>

+ Inheritance diagram for ShapeMoveStrategy:

Public Member Functions

KUndo2CommandcreateCommand () override
 
void finishInteraction (Qt::KeyboardModifiers modifiers) override
 
void handleMouseMove (const QPointF &mouseLocation, Qt::KeyboardModifiers modifiers) override
 
void paint (QPainter &painter, const KoViewConverter &converter) override
 
 ShapeMoveStrategy (KoToolBase *tool, KoSelection *selection, const QPointF &clicked)
 
 ~ShapeMoveStrategy () override
 
- Public Member Functions inherited from KoInteractionStrategy
virtual void cancelInteraction ()
 
 KoInteractionStrategy (KoToolBase *parent)
 constructor
 
KoToolBasetool () const
 
virtual ~KoInteractionStrategy ()
 Destructor.
 

Private Member Functions

void moveSelection (const QPointF &diff)
 

Private Attributes

QPointer< KoCanvasBasem_canvas
 
QPointF m_finalMove
 
QPointF m_initialOffset
 
QList< QPointF > m_newPositions
 
QList< QPointF > m_previousPositions
 
QList< KoShape * > m_selectedShapes
 
QPointF m_start
 

Additional Inherited Members

- Protected Member Functions inherited from KoInteractionStrategy
uint decorationThickness () const
 
uint grabSensitivity () const
 Convenience function to get the global grab sensitivity.
 
uint handleRadius () const
 Convenience function to get the global handle radius.
 
 KoInteractionStrategy (KoInteractionStrategyPrivate &)
 constructor
 
- Protected Attributes inherited from KoInteractionStrategy
KoInteractionStrategyPrivated_ptr
 

Detailed Description

Implements the Move action on an object or selected objects.

Definition at line 27 of file ShapeMoveStrategy.h.

Constructor & Destructor Documentation

◆ ShapeMoveStrategy()

ShapeMoveStrategy::ShapeMoveStrategy ( KoToolBase * tool,
KoSelection * selection,
const QPointF & clicked )

Constructor that starts to move the objects.

Parameters
toolthe parent tool which controls this strategy
canvasthe canvas interface which will supply things like a selection object
clickedthe initial point that the user depressed (in pt).

Definition at line 28 of file ShapeMoveStrategy.cpp.

30 , m_start(clicked)
31 , m_canvas(tool->canvas())
32{
33 QList<KoShape *> selectedShapes = selection->selectedEditableShapes();
34
35 Q_FOREACH (KoShape *shape, selectedShapes) {
36 m_selectedShapes << shape;
39 }
40
43 m_canvas->resourceManager()->resource(KoFlake::HotPosition).toInt());
44
45 m_initialOffset = selection->absolutePosition(anchor) - m_start;
46 m_canvas->snapGuide()->setIgnoredShapes(KoShape::linearizeSubtree(m_selectedShapes));
47
48 tool->setStatusText(i18n("Press Shift to hold x- or y-position."));
49}
KoInteractionStrategy(KoToolBase *parent)
constructor
const QList< KoShape * > selectedEditableShapes() const
QPointF absolutePosition(KoFlake::AnchorPosition anchor=KoFlake::Center) const
Definition KoShape.cpp:573
static QList< KoShape * > linearizeSubtree(const QList< KoShape * > &shapes)
Definition KoShape.cpp:1178
KoCanvasBase * canvas() const
Returns the canvas the tool is working on.
void setStatusText(const QString &statusText)
QList< QPointF > m_newPositions
QList< QPointF > m_previousPositions
QList< KoShape * > m_selectedShapes
QPointer< KoCanvasBase > m_canvas
AnchorPosition
Definition KoFlake.h:85
@ Center
Definition KoFlake.h:90
@ HotPosition
Definition KoFlake.h:102

References KoShape::absolutePosition(), KoFlake::Center, KoFlake::HotPosition, KoShape::linearizeSubtree(), m_canvas, m_initialOffset, m_newPositions, m_previousPositions, m_selectedShapes, m_start, KoSelection::selectedEditableShapes(), KoToolBase::setStatusText(), and KoInteractionStrategy::tool().

◆ ~ShapeMoveStrategy()

ShapeMoveStrategy::~ShapeMoveStrategy ( )
inlineoverride

Definition at line 37 of file ShapeMoveStrategy.h.

37{}

Member Function Documentation

◆ createCommand()

KUndo2Command * ShapeMoveStrategy::createCommand ( )
overridevirtual

For interactions that are undo-able this method should be implemented to return such a command. Implementations should return 0 otherwise.

Returns
a command, or 0.

Implements KoInteractionStrategy.

Definition at line 94 of file ShapeMoveStrategy.cpp.

95{
96 tool()->canvas()->snapGuide()->reset();
97 if (m_finalMove.isNull()) {
98 return 0;
99 }
101}
KoSnapGuide * snapGuide
The undo / redo command for shape moving.
void reset()
Resets the snap guide.

References KoToolBase::canvas(), m_finalMove, m_newPositions, m_previousPositions, m_selectedShapes, KoSnapGuide::reset(), KoCanvasBase::snapGuide, and KoInteractionStrategy::tool().

◆ finishInteraction()

void ShapeMoveStrategy::finishInteraction ( Qt::KeyboardModifiers modifiers)
overridevirtual

Override to make final changes to the data on the end of an interaction.

Implements KoInteractionStrategy.

Definition at line 103 of file ShapeMoveStrategy.cpp.

104{
105 Q_UNUSED(modifiers);
106}

◆ handleMouseMove()

void ShapeMoveStrategy::handleMouseMove ( const QPointF & mouseLocation,
Qt::KeyboardModifiers modifiers )
overridevirtual

Extending classes should implement this method to update the selectedShapes based on the new mouse position.

Parameters
mouseLocationthe new location in pt
modifiersOR-ed set of keys pressed.

Implements KoInteractionStrategy.

Definition at line 51 of file ShapeMoveStrategy.cpp.

52{
53 if (m_selectedShapes.isEmpty()) {
54 return;
55 }
56 QPointF diff = point - m_start;
57
58 if (modifiers & Qt::ShiftModifier) {
59 // Limit change to one direction only
60 diff = snapToClosestAxis(diff);
61 } else {
62 QPointF positionToSnap = point + m_initialOffset;
63 QPointF snappedPosition = tool()->canvas()->snapGuide()->snap(positionToSnap, modifiers);
64 diff = snappedPosition - m_initialOffset - m_start;
65 }
66
67 moveSelection(diff);
68 m_finalMove = diff;
69}
QPointF snap(const QPointF &mousePosition, Qt::KeyboardModifiers modifiers)
snaps the mouse position, returns if mouse was snapped
void moveSelection(const QPointF &diff)
PointType snapToClosestAxis(PointType P)
Definition kis_global.h:199

References KoToolBase::canvas(), m_finalMove, m_initialOffset, m_selectedShapes, m_start, moveSelection(), KoSnapGuide::snap(), KoCanvasBase::snapGuide, snapToClosestAxis(), and KoInteractionStrategy::tool().

◆ moveSelection()

void ShapeMoveStrategy::moveSelection ( const QPointF & diff)
private

Definition at line 71 of file ShapeMoveStrategy.cpp.

72{
73 Q_ASSERT(m_newPositions.count());
74
76
77 int i = 0;
78 Q_FOREACH (KoShape *shape, m_selectedShapes) {
79 QPointF delta = m_previousPositions.at(i) + diff - shape->absolutePosition(KoFlake::Center);
80 if (shape->parent()) {
81 shape->parent()->model()->proposeMove(shape, delta);
82 }
83 tool()->canvas()->clipToDocument(shape, delta);
84 QPointF newPos(shape->absolutePosition(KoFlake::Center) + delta);
85 m_newPositions[i] = newPos;
86
88 i++;
89 }
90
92}
virtual void clipToDocument(const KoShape *shape, QPointF &move) const
static void bulkShapesUpdate(const UpdatesList &updates)
virtual void proposeMove(KoShape *shape, QPointF &move)
KoShapeContainerModel * model
KoShapeContainer * parent() const
Definition KoShape.cpp:862
void setAbsolutePosition(const QPointF &newPosition, KoFlake::AnchorPosition anchor=KoFlake::Center)
Definition KoShape.cpp:588

References KoShape::absolutePosition(), KoShapeBulkActionLock::bulkShapesUpdate(), KoToolBase::canvas(), KoFlake::Center, KoCanvasBase::clipToDocument(), m_newPositions, m_previousPositions, m_selectedShapes, KoShapeContainer::model, KoShape::parent(), KoShapeContainerModel::proposeMove(), KoShape::setAbsolutePosition(), KoInteractionStrategy::tool(), and KoShapeBulkActionLock::unlock().

◆ paint()

void ShapeMoveStrategy::paint ( QPainter & painter,
const KoViewConverter & converter )
overridevirtual

Reimplement this if the action needs to draw a "blob" on the canvas; that is, a transient decoration like a rubber band.

Reimplemented from KoInteractionStrategy.

Definition at line 108 of file ShapeMoveStrategy.cpp.

109{
110 Q_UNUSED(painter);
111 Q_UNUSED(converter);
112}

Member Data Documentation

◆ m_canvas

QPointer<KoCanvasBase> ShapeMoveStrategy::m_canvas
private

Definition at line 49 of file ShapeMoveStrategy.h.

◆ m_finalMove

QPointF ShapeMoveStrategy::m_finalMove
private

Definition at line 47 of file ShapeMoveStrategy.h.

◆ m_initialOffset

QPointF ShapeMoveStrategy::m_initialOffset
private

Definition at line 47 of file ShapeMoveStrategy.h.

◆ m_newPositions

QList<QPointF> ShapeMoveStrategy::m_newPositions
private

Definition at line 46 of file ShapeMoveStrategy.h.

◆ m_previousPositions

QList<QPointF> ShapeMoveStrategy::m_previousPositions
private

Definition at line 45 of file ShapeMoveStrategy.h.

◆ m_selectedShapes

QList<KoShape *> ShapeMoveStrategy::m_selectedShapes
private

Definition at line 48 of file ShapeMoveStrategy.h.

◆ m_start

QPointF ShapeMoveStrategy::m_start
private

Definition at line 47 of file ShapeMoveStrategy.h.


The documentation for this class was generated from the following files: