~ubuntu-branches/ubuntu/oneiric/kig/oneiric

« back to all changes in this revision

Viewing changes to kig/kig_commands.h

  • Committer: Bazaar Package Importer
  • Author(s): Harald Sitter
  • Date: 2011-07-10 11:57:38 UTC
  • Revision ID: james.westby@ubuntu.com-20110710115738-gdjnn1kctr49lmy9
Tags: upstream-4.6.90+repack
ImportĀ upstreamĀ versionĀ 4.6.90+repack

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 This file is part of Kig, a KDE program for Interactive Geometry...
 
3
 Copyright (C) 2002  Dominique Devriese <devriese@kde.org>
 
4
 
 
5
 This program is free software; you can redistribute it and/or modify
 
6
 it under the terms of the GNU General Public License as published by
 
7
 the Free Software Foundation; either version 2 of the License, or
 
8
 (at your option) any later version.
 
9
 
 
10
 This program is distributed in the hope that it will be useful,
 
11
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
 GNU General Public License for more details.
 
14
 
 
15
 You should have received a copy of the GNU General Public License
 
16
 along with this program; if not, write to the Free Software
 
17
 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301
 
18
 USA
 
19
*/
 
20
 
 
21
 
 
22
#ifndef KIG_COMMANDS_H
 
23
#define KIG_COMMANDS_H
 
24
 
 
25
#include <qundostack.h>
 
26
 
 
27
#include <klocale.h>
 
28
#include <kdebug.h>
 
29
 
 
30
#include "../objects/object_holder.h"
 
31
 
 
32
class KigDocument;
 
33
class KigPart;
 
34
class CoordinateSystem;
 
35
 
 
36
class KigCommandTask;
 
37
class KigWidget;
 
38
class Rect;
 
39
 
 
40
/**
 
41
 * a KigCommand represents almost every action performed in Kig.
 
42
 * Used mainly in the Undo/Redo stuff...
 
43
 */
 
44
class KigCommand
 
45
  : public QUndoCommand
 
46
{
 
47
  class Private;
 
48
  Private* d;
 
49
public:
 
50
  KigCommand( KigPart& inDoc, const QString& name );
 
51
  ~KigCommand();
 
52
 
 
53
  /**
 
54
   * To avoid confusion, this doesn't add a command to anything, this
 
55
   * creates an AddCommand ;)
 
56
   */
 
57
  static KigCommand* addCommand( KigPart& doc, const std::vector<ObjectHolder*>& os );
 
58
  /**
 
59
   * \overload
 
60
   */
 
61
  static KigCommand* addCommand( KigPart& doc, ObjectHolder* os );
 
62
  /**
 
63
   * make sure that when you delete something, you are also deleting
 
64
   * its parents.  This class assumes you've done that.
 
65
   * \ref KigDocument::delObjects() takes care of this for you.
 
66
   */
 
67
  static KigCommand* removeCommand( KigPart& doc, const std::vector<ObjectHolder*>& os );
 
68
  /**
 
69
   * \overload
 
70
   */
 
71
  static KigCommand* removeCommand( KigPart& doc, ObjectHolder* o );
 
72
 
 
73
  /**
 
74
   * This creates directly a command to change the coordinate system
 
75
   * to \p s .
 
76
   * \sa ChangeCoordSystemTask
 
77
   */
 
78
  static KigCommand* changeCoordSystemCommand( KigPart& doc, CoordinateSystem* s );
 
79
 
 
80
  void addTask( KigCommandTask* );
 
81
 
 
82
  void redo();
 
83
  void undo();
 
84
private:
 
85
  Q_DISABLE_COPY( KigCommand )
 
86
};
 
87
 
 
88
/**
 
89
 * This represents a single task to be executed in a KigCommand.
 
90
 */
 
91
class KigCommandTask
 
92
{
 
93
public:
 
94
  KigCommandTask();
 
95
  virtual ~KigCommandTask();
 
96
 
 
97
  virtual void execute( KigPart& doc ) = 0;
 
98
  virtual void unexecute( KigPart& doc ) = 0;
 
99
};
 
100
 
 
101
class AddObjectsTask
 
102
  : public KigCommandTask
 
103
{
 
104
public:
 
105
  AddObjectsTask( const std::vector<ObjectHolder*>& os);
 
106
  ~AddObjectsTask ();
 
107
  void execute( KigPart& doc );
 
108
  void unexecute( KigPart& doc );
 
109
protected:
 
110
  bool undone;
 
111
 
 
112
  std::vector<ObjectHolder*> mobjs;
 
113
};
 
114
 
 
115
class RemoveObjectsTask
 
116
  : public AddObjectsTask
 
117
{
 
118
public:
 
119
  RemoveObjectsTask( const std::vector<ObjectHolder*>& os );
 
120
  void execute( KigPart& );
 
121
  void unexecute( KigPart& );
 
122
};
 
123
 
 
124
class ChangeObjectConstCalcerTask
 
125
  : public KigCommandTask
 
126
{
 
127
public:
 
128
  ChangeObjectConstCalcerTask( ObjectConstCalcer* calcer, ObjectImp* newimp );
 
129
  ~ChangeObjectConstCalcerTask();
 
130
 
 
131
  void execute( KigPart& );
 
132
  void unexecute( KigPart& );
 
133
protected:
 
134
  ObjectConstCalcer::shared_ptr mcalcer;
 
135
  ObjectImp* mnewimp;
 
136
};
 
137
 
 
138
/**
 
139
 * this class monitors a set of DataObjects for changes and returns an
 
140
 * appropriate ChangeObjectImpsCommand if necessary..
 
141
 * E.g.  MovingMode wants to move certain objects, so it monitors all
 
142
 * the parents of the explicitly moving objects:
 
143
 * \code
 
144
 *   MonitorDataObjects mon( getAllParents( emo ) );
 
145
 * \endcode
 
146
 * It then moves them around, and when it is finished, it asks to add
 
147
 * the KigCommandTasks to a KigCommand, and applies that..
 
148
 * \code
 
149
 *   KigCommand* comm = new KigCommand( doc, i18n( "Move Stuff" ) );
 
150
 *   mon.finish( comm );
 
151
 * \endcode
 
152
 */
 
153
class MonitorDataObjects
 
154
{
 
155
  class Private;
 
156
  Private* d;
 
157
public:
 
158
  /**
 
159
   * all the DataObjects in \p objs will be watched..
 
160
   */
 
161
  MonitorDataObjects( const std::vector<ObjectCalcer*>& objs );
 
162
  MonitorDataObjects( ObjectCalcer* c );
 
163
  ~MonitorDataObjects();
 
164
 
 
165
  /**
 
166
   * add \p objs to the list of objs to be watched, and save their
 
167
   * current imp's..
 
168
   */
 
169
  void monitor( const std::vector<ObjectCalcer*>& objs );
 
170
 
 
171
  /**
 
172
   * add the generated KigCommandTasks to the command \p comm ..
 
173
   * monitoring stops after this is called..
 
174
   */
 
175
  void finish( KigCommand* comm );
 
176
};
 
177
 
 
178
/**
 
179
 * A task to change the coordinate system.
 
180
 */
 
181
class ChangeCoordSystemTask
 
182
  : public KigCommandTask
 
183
{
 
184
  CoordinateSystem* mcs;
 
185
public:
 
186
  /**
 
187
   * a command that changes the coordinate-system to \p s ..
 
188
   */
 
189
  ChangeCoordSystemTask( CoordinateSystem* s );
 
190
  ~ChangeCoordSystemTask();
 
191
 
 
192
  void execute( KigPart& doc );
 
193
  void unexecute( KigPart& doc );
 
194
};
 
195
 
 
196
class ChangeParentsAndTypeTask
 
197
  : public KigCommandTask
 
198
{
 
199
  class Private;
 
200
  Private* d;
 
201
public:
 
202
  ChangeParentsAndTypeTask( ObjectTypeCalcer* o, const std::vector<ObjectCalcer*>& newparents,
 
203
                            const ObjectType* newtype );
 
204
  ~ChangeParentsAndTypeTask();
 
205
 
 
206
  void execute( KigPart& doc );
 
207
  void unexecute( KigPart& doc );
 
208
};
 
209
 
 
210
class KigViewShownRectChangeTask
 
211
  : public KigCommandTask
 
212
{
 
213
  class Private;
 
214
  Private* d;
 
215
public:
 
216
  KigViewShownRectChangeTask( KigWidget& v, const Rect& newrect );
 
217
  ~KigViewShownRectChangeTask();
 
218
 
 
219
  void execute( KigPart& doc );
 
220
  void unexecute( KigPart& doc );
 
221
};
 
222
 
 
223
class ChangeObjectDrawerTask
 
224
  : public KigCommandTask
 
225
{
 
226
  ObjectHolder* mholder;
 
227
  ObjectDrawer* mnewdrawer;
 
228
public:
 
229
  ChangeObjectDrawerTask( ObjectHolder* holder, ObjectDrawer* newdrawer );
 
230
  ~ChangeObjectDrawerTask();
 
231
 
 
232
  void execute( KigPart& doc );
 
233
  void unexecute( KigPart& doc );
 
234
};
 
235
 
 
236
#endif