1 /* This file is part of the KDE project
2  * Copyright (C) 2006 Jan Hambrecht <jaham@gmx.net>
3  * Copyright (C) 2006,2007 Thorsten Zachmann <zachmann@kde.org>
4  * Copyright (C) 2007 Thomas Zander <zander@kde.org>
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Library General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Library General Public License for more details.
15  *
16  * You should have received a copy of the GNU Library General Public License
17  * along with this library; see the file COPYING.LIB.  If not, write to
18  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19  * Boston, MA 02110-1301, USA.
20  */
21 
22 #include "KoParameterHandleMoveCommand.h"
23 #include "KoParameterShape.h"
24 #include <klocalizedstring.h>
25 #include "kis_command_ids.h"
26 
KoParameterHandleMoveCommand(KoParameterShape * shape,int handleId,const QPointF & startPoint,const QPointF & endPoint,Qt::KeyboardModifiers keyModifiers,KUndo2Command * parent)27 KoParameterHandleMoveCommand::KoParameterHandleMoveCommand(KoParameterShape *shape, int handleId, const QPointF &startPoint, const QPointF &endPoint, Qt::KeyboardModifiers keyModifiers, KUndo2Command *parent)
28         : KUndo2Command(parent)
29         , m_shape(shape)
30         , m_handleId(handleId)
31         , m_startPoint(startPoint)
32         , m_endPoint(endPoint)
33         , m_keyModifiers(keyModifiers)
34 {
35     setText(kundo2_i18n("Change parameter"));
36 }
37 
~KoParameterHandleMoveCommand()38 KoParameterHandleMoveCommand::~KoParameterHandleMoveCommand()
39 {
40 }
41 
42 /// redo the command
redo()43 void KoParameterHandleMoveCommand::redo()
44 {
45     KUndo2Command::redo();
46     m_shape->update();
47     m_shape->moveHandle(m_handleId, m_endPoint, m_keyModifiers);
48     m_shape->update();
49 }
50 
51 /// revert the actions done in redo
undo()52 void KoParameterHandleMoveCommand::undo()
53 {
54     KUndo2Command::undo();
55     m_shape->update();
56     m_shape->moveHandle(m_handleId, m_startPoint);
57     m_shape->update();
58 }
59 
id() const60 int KoParameterHandleMoveCommand::id() const
61 {
62     return KisCommandUtils::ChangeShapeParameterId;
63 }
64 
mergeWith(const KUndo2Command * command)65 bool KoParameterHandleMoveCommand::mergeWith(const KUndo2Command *command)
66 {
67     const KoParameterHandleMoveCommand *other = dynamic_cast<const KoParameterHandleMoveCommand*>(command);
68 
69     if (!other ||
70         other->m_shape != m_shape ||
71         other->m_handleId != m_handleId ||
72         other->m_keyModifiers != m_keyModifiers) {
73 
74         return false;
75     }
76 
77     m_endPoint = other->m_endPoint;
78 
79     return true;
80 }
81 
82