summaryrefslogtreecommitdiffstats
path: root/kig/kig/kig_commands.h
blob: 5bd3ae29a2e73e30a32542587514d8c5dee70b94 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
/*
 This file is part of Kig, a KDE program for Interactive Geometry...
 Copyright (C) 2002  Dominique Devriese <devriese@kde.org>

 This program is free software; you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation; either version 2 of the License, or
 (at your option) any later version.

 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.

 You should have received a copy of the GNU General Public License
 along with this program; if not, write to the Free Software
 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301
 USA
*/


#ifndef KIG_COMMANDS_H
#define KIG_COMMANDS_H

#include <kcommand.h>
#include <klocale.h>
#include <kdebug.h>

#include "../objects/object_holder.h"

class KigDocument;
class KigPart;
class CoordinateSystem;

class KigCommandTask;
class KigWidget;
class Rect;

/**
 * a KigCommand represents almost every action performed in Kig.
 * Used mainly in the Undo/Redo stuff...
 */
class KigCommand
  : public TQObject, public KNamedCommand
{
  Q_OBJECT
  TQ_OBJECT
  class Private;
  Private* d;
public:
  KigCommand( KigPart& inDoc, const TQString& name );
  ~KigCommand();

  /**
   * To avoid confusion, this doesn't add a command to anything, this
   * creates an AddCommand ;)
   */
  static KigCommand* addCommand( KigPart& doc, const std::vector<ObjectHolder*>& os );
  static KigCommand* addCommand( KigPart& doc, ObjectHolder* os );
  /**
   * make sure that when you delete something, you are also deleting
   * its parents.  This class assumes you've done that.
   * \ref KigDocument::delObjects() takes care of this for you.
   */
  static KigCommand* removeCommand( KigPart& doc, const std::vector<ObjectHolder*>& os );
  static KigCommand* removeCommand( KigPart& doc, ObjectHolder* o );

  static KigCommand* changeCoordSystemCommand( KigPart& doc, CoordinateSystem* s );

  void addTask( KigCommandTask* );

  void execute();
  void unexecute();
};

class KigCommandTask
{
public:
  KigCommandTask();
  virtual ~KigCommandTask();

  virtual void execute( KigPart& doc ) = 0;
  virtual void unexecute( KigPart& doc ) = 0;
};

class AddObjectsTask
  : public KigCommandTask
{
public:
  AddObjectsTask( const std::vector<ObjectHolder*>& os);
  ~AddObjectsTask ();
  void execute( KigPart& doc );
  void unexecute( KigPart& doc );
protected:
  bool undone;

  std::vector<ObjectHolder*> mobjs;
};

class RemoveObjectsTask
  : public AddObjectsTask
{
public:
  RemoveObjectsTask( const std::vector<ObjectHolder*>& os );
  void execute( KigPart& );
  void unexecute( KigPart& );
};

class ChangeObjectConstCalcerTask
  : public KigCommandTask
{
public:
  ChangeObjectConstCalcerTask( ObjectConstCalcer* calcer, ObjectImp* newimp );
  ~ChangeObjectConstCalcerTask();

  void execute( KigPart& );
  void unexecute( KigPart& );
protected:
  ObjectConstCalcer::shared_ptr mcalcer;
  ObjectImp* mnewimp;
};

/**
 * this class monitors a set of DataObjects for changes and returns an
 * appropriate ChangeObjectImpsCommand if necessary..
 * E.g.  MovingMode wants to move certain objects, so it monitors all
 * the parents of the explicitly moving objects:
 * \code
 *   MonitorDataObjects mon( getAllParents( emo ) );
 * \endcode
 * It then moves them around, and when it is finished, it asks to add
 * the KigCommandTasks to a KigCommand, and applies that..
 * \code
 *   KigCommand* comm = new KigCommand( doc, i18n( "Move Stuff" ) );
 *   mon.finish( comm );
 * \endcode
 */
class MonitorDataObjects
{
  class Private;
  Private* d;
public:
  /**
   * all the DataObjects in \p objs will be watched..
   */
  MonitorDataObjects( const std::vector<ObjectCalcer*>& objs );
  MonitorDataObjects( ObjectCalcer* c );
  ~MonitorDataObjects();

  /**
   * add \p objs to the list of objs to be watched, and save their
   * current imp's..
   */
  void monitor( const std::vector<ObjectCalcer*>& objs );

  /**
   * add the generated KigCommandTasks to the command \p comm ..
   * monitoring stops after this is called..
   */
  void finish( KigCommand* comm );
};

class ChangeCoordSystemTask
  : public KigCommandTask
{
  CoordinateSystem* mcs;
public:
  /**
   * a command that changes the coordinate-system to \p s ..
   */
  ChangeCoordSystemTask( CoordinateSystem* s );
  ~ChangeCoordSystemTask();

  void execute( KigPart& doc );
  void unexecute( KigPart& doc );
};

class ChangeParentsAndTypeTask
  : public KigCommandTask
{
  class Private;
  Private* d;
public:
  ChangeParentsAndTypeTask( ObjectTypeCalcer* o, const std::vector<ObjectCalcer*>& newparents,
                            const ObjectType* newtype );
  ~ChangeParentsAndTypeTask();

  void execute( KigPart& doc );
  void unexecute( KigPart& doc );
};

class KigViewShownRectChangeTask
  : public KigCommandTask
{
  class Private;
  Private* d;
public:
  KigViewShownRectChangeTask( KigWidget& v, const Rect& newrect );
  ~KigViewShownRectChangeTask();

  void execute( KigPart& doc );
  void unexecute( KigPart& doc );
};

class ChangeObjectDrawerTask
  : public KigCommandTask
{
  ObjectHolder* mholder;
  ObjectDrawer* mnewdrawer;
public:
  ChangeObjectDrawerTask( ObjectHolder* holder, ObjectDrawer* newdrawer );
  ~ChangeObjectDrawerTask();

  void execute( KigPart& doc );
  void unexecute( KigPart& doc );
};

#endif