libs/flake

KoPathControlPointMoveStrategy.cpp

Go to the documentation of this file.
00001 /* This file is part of the KDE project
00002  * Copyright (C) 2006 Jan Hambrecht <jaham@gmx.net>
00003  * Copyright (C) 2006,2007 Thorsten Zachmann <zachmann@kde.org>
00004  *
00005  * This library is free software; you can redistribute it and/or
00006  * modify it under the terms of the GNU Library General Public
00007  * License as published by the Free Software Foundation; either
00008  * version 2 of the License, or (at your option) any later version.
00009  *
00010  * This library is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013  * Library General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU Library General Public License
00016  * along with this library; see the file COPYING.LIB.  If not, write to
00017  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00018  * Boston, MA 02110-1301, USA.
00019  */
00020 
00021 #include "KoPathControlPointMoveStrategy.h"
00022 #include "KoCanvasBase.h"
00023 #include "KoSnapGuide.h"
00024 
00025 #include "KoPathTool.h"
00026 #include "commands/KoPathControlPointMoveCommand.h"
00027 
00028 KoPathControlPointMoveStrategy::KoPathControlPointMoveStrategy(KoPathTool *tool, KoCanvasBase *canvas, const KoPathPointData &pointData, KoPathPoint::KoPointType type, const QPointF &pos)
00029         : KoInteractionStrategy(tool, canvas)
00030         , m_lastPosition(pos)
00031         , m_move(0, 0)
00032         , m_tool(tool)
00033         , m_pointData(pointData)
00034         , m_pointType(type)
00035 {
00036 }
00037 
00038 KoPathControlPointMoveStrategy::~KoPathControlPointMoveStrategy()
00039 {
00040 }
00041 
00042 void KoPathControlPointMoveStrategy::handleMouseMove(const QPointF &mouseLocation, Qt::KeyboardModifiers modifiers)
00043 {
00044     QPointF docPoint = m_tool->canvas()->snapGuide()->snap(mouseLocation, modifiers);
00045     QPointF move = docPoint - m_lastPosition;
00046     // as the last position can change when the top left is changed we have
00047     // to save it in document pos and not in shape pos
00048     m_lastPosition = docPoint;
00049 
00050     m_move += move;
00051 
00052     KoPathControlPointMoveCommand cmd(m_pointData, move, m_pointType);
00053     cmd.redo();
00054 }
00055 
00056 void KoPathControlPointMoveStrategy::finishInteraction(Qt::KeyboardModifiers modifiers)
00057 {
00058     Q_UNUSED(modifiers);
00059 }
00060 
00061 QUndoCommand* KoPathControlPointMoveStrategy::createCommand()
00062 {
00063     QUndoCommand *cmd = 0;
00064     if (!m_move.isNull()) {
00065         cmd = new KoPathControlPointMoveCommand(m_pointData, m_move, m_pointType);
00066         cmd->undo();
00067     }
00068     return cmd;
00069 }