libs/flake
KoPathPointMoveStrategy.cppGo to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "KoPathPointMoveStrategy.h"
00023
00024 #include "commands/KoPathPointMoveCommand.h"
00025 #include "KoPathTool.h"
00026 #include "KoPathToolSelection.h"
00027 #include "KoSnapGuide.h"
00028 #include <KoCanvasBase.h>
00029
00030 KoPathPointMoveStrategy::KoPathPointMoveStrategy(KoPathTool *tool, KoCanvasBase *canvas, const QPointF &pos)
00031 : KoInteractionStrategy(tool, canvas)
00032 , m_originalPosition(pos)
00033 , m_tool(tool)
00034 {
00035 }
00036
00037 KoPathPointMoveStrategy::~KoPathPointMoveStrategy()
00038 {
00039 }
00040
00041 void KoPathPointMoveStrategy::handleMouseMove(const QPointF &mouseLocation, Qt::KeyboardModifiers modifiers)
00042 {
00043 m_tool->canvas()->updateCanvas(m_tool->canvas()->snapGuide()->boundingRect());
00044 QPointF newPosition = m_tool->canvas()->snapGuide()->snap(mouseLocation, modifiers);
00045 m_tool->canvas()->updateCanvas(m_tool->canvas()->snapGuide()->boundingRect());
00046 QPointF move = newPosition - m_originalPosition;
00047
00048 if (modifiers & Qt::ControlModifier) {
00049 if (qAbs(move.x()) > qAbs(move.y()))
00050 move.setY(0);
00051 else
00052 move.setX(0);
00053 }
00054
00055 KoPathToolSelection * selection = dynamic_cast<KoPathToolSelection*>(m_tool->selection());
00056 if (! selection)
00057 return;
00058
00059 KoPathPointMoveCommand cmd(selection->selectedPointsData(), move - m_move);
00060 cmd.redo();
00061 m_move = move;
00062 }
00063
00064 void KoPathPointMoveStrategy::finishInteraction(Qt::KeyboardModifiers modifiers)
00065 {
00066 Q_UNUSED(modifiers);
00067 }
00068
00069 QUndoCommand* KoPathPointMoveStrategy::createCommand()
00070 {
00071 m_tool->canvas()->updateCanvas(m_tool->canvas()->snapGuide()->boundingRect());
00072
00073 KoPathToolSelection * selection = dynamic_cast<KoPathToolSelection*>(m_tool->selection());
00074 if (! selection)
00075 return 0;
00076
00077 QUndoCommand *cmd = 0;
00078 if (!m_move.isNull()) {
00079
00080 KoPathPointMoveCommand revert(selection->selectedPointsData(), -m_move);
00081 revert.redo();
00082 cmd = new KoPathPointMoveCommand(selection->selectedPointsData(), m_move);
00083 }
00084 return cmd;
00085 }
|