1
/****************************************************************************
3
** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
4
** Contact: http://www.qt-project.org/legal
6
** This file is part of the demonstration applications of the Qt Toolkit.
8
** $QT_BEGIN_LICENSE:LGPL$
9
** Commercial License Usage
10
** Licensees holding valid commercial Qt licenses may use this file in
11
** accordance with the commercial license agreement provided with the
12
** Software or, alternatively, in accordance with the terms contained in
13
** a written agreement between you and Digia. For licensing terms and
14
** conditions see http://qt.digia.com/licensing. For further information
15
** use the contact form at http://qt.digia.com/contact-us.
17
** GNU Lesser General Public License Usage
18
** Alternatively, this file may be used under the terms of the GNU Lesser
19
** General Public License version 2.1 as published by the Free Software
20
** Foundation and appearing in the file LICENSE.LGPL included in the
21
** packaging of this file. Please review the following information to
22
** ensure the GNU Lesser General Public License version 2.1 requirements
23
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25
** In addition, as a special exception, Digia gives you certain additional
26
** rights. These rights are described in the Digia Qt LGPL Exception
27
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29
** GNU General Public License Usage
30
** Alternatively, this file may be used under the terms of the GNU
31
** General Public License version 3.0 as published by the Free Software
32
** Foundation and appearing in the file LICENSE.GPL included in the
33
** packaging of this file. Please review the following information to
34
** ensure the GNU General Public License version 3.0 requirements will be
35
** met: http://www.gnu.org/copyleft/gpl.html.
40
****************************************************************************/
44
static const int setShapeRectCommandId = 1;
45
static const int setShapeColorCommandId = 2;
47
/******************************************************************************
51
AddShapeCommand::AddShapeCommand(Document *doc, const Shape &shape, QUndoCommand *parent)
52
: QUndoCommand(parent)
58
void AddShapeCommand::undo()
60
m_doc->deleteShape(m_shapeName);
63
void AddShapeCommand::redo()
65
// A shape only gets a name when it is inserted into a document
66
m_shapeName = m_doc->addShape(m_shape);
67
setText(QObject::tr("Add %1").arg(m_shapeName));
70
/******************************************************************************
74
RemoveShapeCommand::RemoveShapeCommand(Document *doc, const QString &shapeName,
76
: QUndoCommand(parent)
78
setText(QObject::tr("Remove %1").arg(shapeName));
80
m_shape = doc->shape(shapeName);
81
m_shapeName = shapeName;
84
void RemoveShapeCommand::undo()
86
m_shapeName = m_doc->addShape(m_shape);
89
void RemoveShapeCommand::redo()
91
m_doc->deleteShape(m_shapeName);
94
/******************************************************************************
95
** SetShapeColorCommand
98
SetShapeColorCommand::SetShapeColorCommand(Document *doc, const QString &shapeName,
99
const QColor &color, QUndoCommand *parent)
100
: QUndoCommand(parent)
102
setText(QObject::tr("Set %1's color").arg(shapeName));
105
m_shapeName = shapeName;
106
m_oldColor = doc->shape(shapeName).color();
110
void SetShapeColorCommand::undo()
112
m_doc->setShapeColor(m_shapeName, m_oldColor);
115
void SetShapeColorCommand::redo()
117
m_doc->setShapeColor(m_shapeName, m_newColor);
120
bool SetShapeColorCommand::mergeWith(const QUndoCommand *command)
122
if (command->id() != setShapeColorCommandId)
125
const SetShapeColorCommand *other = static_cast<const SetShapeColorCommand*>(command);
126
if (m_shapeName != other->m_shapeName)
129
m_newColor = other->m_newColor;
133
int SetShapeColorCommand::id() const
135
return setShapeColorCommandId;
138
/******************************************************************************
139
** SetShapeRectCommand
142
SetShapeRectCommand::SetShapeRectCommand(Document *doc, const QString &shapeName,
143
const QRect &rect, QUndoCommand *parent)
144
: QUndoCommand(parent)
146
setText(QObject::tr("Change %1's geometry").arg(shapeName));
149
m_shapeName = shapeName;
150
m_oldRect = doc->shape(shapeName).rect();
154
void SetShapeRectCommand::undo()
156
m_doc->setShapeRect(m_shapeName, m_oldRect);
159
void SetShapeRectCommand::redo()
161
m_doc->setShapeRect(m_shapeName, m_newRect);
164
bool SetShapeRectCommand::mergeWith(const QUndoCommand *command)
166
if (command->id() != setShapeRectCommandId)
169
const SetShapeRectCommand *other = static_cast<const SetShapeRectCommand*>(command);
170
if (m_shapeName != other->m_shapeName)
173
m_newRect = other->m_newRect;
177
int SetShapeRectCommand::id() const
179
return setShapeRectCommandId;