File indexing completed on 2024-12-22 04:09:13

0001 /* This file is part of the KDE project
0002  * SPDX-FileCopyrightText: 2006 Jan Hambrecht <jaham@gmx.net>
0003  * SPDX-FileCopyrightText: 2006, 2007 Thorsten Zachmann <zachmann@kde.org>
0004  *
0005  * SPDX-License-Identifier: LGPL-2.0-or-later
0006  */
0007 
0008 #include "KoPathControlPointMoveStrategy.h"
0009 #include "KoCanvasBase.h"
0010 #include "KoSnapGuide.h"
0011 
0012 #include "KoPathTool.h"
0013 #include "commands/KoPathControlPointMoveCommand.h"
0014 #include "kis_command_utils.h"
0015 
0016 KoPathControlPointMoveStrategy::KoPathControlPointMoveStrategy(KoPathTool *tool, const KoPathPointData &pointData, KoPathPoint::PointType type, const QPointF &pos)
0017         : KoInteractionStrategy(tool)
0018         , m_lastPosition(pos)
0019         , m_move(0, 0)
0020         , m_tool(tool)
0021         , m_pointData(pointData)
0022         , m_pointType(type)
0023 {
0024     m_path = m_pointData.pathShape;
0025 }
0026 
0027 KoPathControlPointMoveStrategy::~KoPathControlPointMoveStrategy()
0028 {
0029 }
0030 
0031 void KoPathControlPointMoveStrategy::handleMouseMove(const QPointF &mouseLocation, Qt::KeyboardModifiers modifiers)
0032 {
0033     QPointF docPoint = m_tool->canvas()->snapGuide()->snap(mouseLocation, modifiers);
0034     QPointF localPos = m_path->documentToShape(docPoint);
0035     QPointF move = localPos - m_path->documentToShape(m_lastPosition);
0036     // as the last position can change when the top left is changed we have
0037     // to save it in document pos and not in shape pos
0038     m_lastPosition = docPoint;
0039 
0040     m_move += move;
0041 
0042     KoPathControlPointMoveCommand *cmd = new KoPathControlPointMoveCommand(m_pointData, move, m_pointType);
0043 
0044     cmd->redo();
0045     if (m_intermediateCommand) {
0046         m_intermediateCommand->mergeWith(cmd);
0047     } else {
0048         m_intermediateCommand.reset(cmd);
0049     }
0050 }
0051 
0052 void KoPathControlPointMoveStrategy::finishInteraction(Qt::KeyboardModifiers modifiers)
0053 {
0054     Q_UNUSED(modifiers);
0055 }
0056 
0057 KUndo2Command* KoPathControlPointMoveStrategy::createCommand()
0058 {
0059     if (m_intermediateCommand) {
0060         return new KisCommandUtils::SkipFirstRedoWrapper(m_intermediateCommand.take());
0061     }
0062     return nullptr;
0063 }