Krita Source Code Documentation
Loading...
Searching...
No Matches
KoPathPointMoveStrategy.cpp
Go to the documentation of this file.
1/* This file is part of the KDE project
2 * SPDX-FileCopyrightText: 2006 Jan Hambrecht <jaham@gmx.net>
3 * SPDX-FileCopyrightText: 2006 Thorsten Zachmann <zachmann@kde.org>
4 * SPDX-FileCopyrightText: 2007 Thomas Zander <zander@kde.org>
5 *
6 * SPDX-License-Identifier: LGPL-2.0-or-later
7 */
8
11
13#include "KoPathTool.h"
14#include "KoPathToolSelection.h"
15#include "KoSnapGuide.h"
16#include "KoCanvasBase.h"
17#include "kis_global.h"
18#include "kis_command_utils.h"
19
20KoPathPointMoveStrategy::KoPathPointMoveStrategy(KoPathTool *tool, const QPointF &mousePosition, const QPointF &pointPosition)
22 m_startMousePosition(mousePosition),
23 m_startPointPosition(pointPosition),
24 m_tool(tool)
25{
26}
27
31
32void KoPathPointMoveStrategy::handleMouseMove(const QPointF &mouseLocation, Qt::KeyboardModifiers modifiers)
33{
34 QPointF deltaMovement = mouseLocation - m_startMousePosition;
35 QPointF newPosition = m_tool->canvas()->snapGuide()->snap(m_startPointPosition + deltaMovement, modifiers);
36 QPointF move = newPosition - m_startPointPosition;
37
38 if (modifiers & Qt::ShiftModifier) {
39 // Limit change to one direction only
40 move = snapToClosestAxis(move);
41 }
42
43 KoPathToolSelection * selection = dynamic_cast<KoPathToolSelection*>(m_tool->selection());
44 if (! selection)
45 return;
46
48 new KoPathPointMoveCommand(selection->selectedPointsData(), move - m_move),
50
51 m_move = move;
52}
53
54void KoPathPointMoveStrategy::finishInteraction(Qt::KeyboardModifiers modifiers)
55{
56 Q_UNUSED(modifiers);
57}
58
KoSnapGuide * snapGuide
The undo / redo command for path point moving.
KoPathPointMoveStrategy(KoPathTool *tool, const QPointF &mousePosition, const QPointF &pointPosition)
QPointF m_move
the accumulated point move amount
void finishInteraction(Qt::KeyboardModifiers modifiers) override
KoPathTool * m_tool
pointer to the path tool
KUndo2Command * createCommand() override
void handleMouseMove(const QPointF &mouseLocation, Qt::KeyboardModifiers modifiers) override
QScopedPointer< KUndo2Command > m_intermediateCommand
Handle the selection of points.
QList< KoPathPointData > selectedPointsData() const
Get the point data of all selected points.
KoToolSelection * selection() override
QPointF snap(const QPointF &mousePosition, Qt::KeyboardModifiers modifiers)
snaps the mouse position, returns if mouse was snapped
KoCanvasBase * canvas() const
Returns the canvas the tool is working on.
PointType snapToClosestAxis(PointType P)
Definition kis_global.h:199
void redoAndMergeIntoAccumulatingCommand(KUndo2Command *cmd, QScopedPointer< KUndo2Command > &accumulatingCommand)