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 27 of file ShapeMoveStrategy.cpp.

29 , m_start(clicked)
30 , m_canvas(tool->canvas())
31{
32 QList<KoShape *> selectedShapes = selection->selectedEditableShapes();
33
34 Q_FOREACH (KoShape *shape, selectedShapes) {
35 m_selectedShapes << shape;
38 }
39
42 m_canvas->resourceManager()->resource(KoFlake::HotPosition).toInt());
43
44 m_initialOffset = selection->absolutePosition(anchor) - m_start;
45 m_canvas->snapGuide()->setIgnoredShapes(KoShape::linearizeSubtree(m_selectedShapes));
46
47 tool->setStatusText(i18n("Press Shift to hold x- or y-position."));
48}
KoInteractionStrategy(KoToolBase *parent)
constructor
const QList< KoShape * > selectedEditableShapes() const
QPointF absolutePosition(KoFlake::AnchorPosition anchor=KoFlake::Center) const
Definition KoShape.cpp:653
static QList< KoShape * > linearizeSubtree(const QList< KoShape * > &shapes)
Definition KoShape.cpp:1381
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 91 of file ShapeMoveStrategy.cpp.

92{
93 tool()->canvas()->snapGuide()->reset();
94 if (m_finalMove.isNull()) {
95 return 0;
96 }
98}
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 100 of file ShapeMoveStrategy.cpp.

101{
102 Q_UNUSED(modifiers);
103}

◆ 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 50 of file ShapeMoveStrategy.cpp.

51{
52 if (m_selectedShapes.isEmpty()) {
53 return;
54 }
55 QPointF diff = point - m_start;
56
57 if (modifiers & Qt::ShiftModifier) {
58 // Limit change to one direction only
59 diff = snapToClosestAxis(diff);
60 } else {
61 QPointF positionToSnap = point + m_initialOffset;
62 QPointF snappedPosition = tool()->canvas()->snapGuide()->snap(positionToSnap, modifiers);
63 diff = snappedPosition - m_initialOffset - m_start;
64 }
65
66 moveSelection(diff);
67 m_finalMove = diff;
68}
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 70 of file ShapeMoveStrategy.cpp.

71{
72 Q_ASSERT(m_newPositions.count());
73
74 int i = 0;
75 Q_FOREACH (KoShape *shape, m_selectedShapes) {
76 QPointF delta = m_previousPositions.at(i) + diff - shape->absolutePosition(KoFlake::Center);
77 if (shape->parent()) {
78 shape->parent()->model()->proposeMove(shape, delta);
79 }
80 tool()->canvas()->clipToDocument(shape, delta);
81 QPointF newPos(shape->absolutePosition(KoFlake::Center) + delta);
82 m_newPositions[i] = newPos;
83
84 const QRectF oldDirtyRect = shape->boundingRect();
86 shape->updateAbsolute(oldDirtyRect | oldDirtyRect.translated(delta));
87 i++;
88 }
89}
virtual void clipToDocument(const KoShape *shape, QPointF &move) const
virtual void proposeMove(KoShape *shape, QPointF &move)
KoShapeContainerModel * model
virtual QRectF boundingRect() const
Get the bounding box of the shape.
Definition KoShape.cpp:335
KoShapeContainer * parent() const
Definition KoShape.cpp:1039
virtual void updateAbsolute(const QRectF &rect) const
Definition KoShape.cpp:616
void setAbsolutePosition(const QPointF &newPosition, KoFlake::AnchorPosition anchor=KoFlake::Center)
Definition KoShape.cpp:668

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

◆ 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 105 of file ShapeMoveStrategy.cpp.

106{
107 Q_UNUSED(painter);
108 Q_UNUSED(converter);
109}

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: