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
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
|
/* This file is part of the KDE project
Copyright (C) 2004 Cedric Pasteur <[email protected]>
Copyright (C) 2005 Jaroslaw Staniek <[email protected]>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library 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
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#ifndef KFORMEDITOR_COMMANDS_H
#define KFORMEDITOR_COMMANDS_H
#include <qmap.h>
#include <qdict.h>
#include <qptrlist.h>
#include <qptrdict.h>
#include <qvariant.h>
#include <qdom.h>
#include <kcommand.h>
#include "utils.h"
class QWidget;
class QRect;
class QPoint;
class QStringList;
class QCString;
namespace KFormDesigner {
class WidgetPropertySet;
class ObjectTreeItem;
class Container;
class Form;
//! Base class for KFormDesigner's commands
class KFORMEDITOR_EXPORT Command : public KCommand
{
public:
Command();
virtual ~Command();
virtual void debug() = 0;
};
/*! This command is used when changing a property for one or more widgets. \a oldvalues is a QMap
of the old values of the property for every widget, to allow reverting the change. \a value is
the new value of the property. You can use the simpler constructor for a single widget.
*/
class KFORMEDITOR_EXPORT PropertyCommand : public Command
{
public:
PropertyCommand(WidgetPropertySet *set, const QCString &wname, const QVariant &oldValue,
const QVariant &value, const QCString &property);
PropertyCommand(WidgetPropertySet *set, const QMap<QCString, QVariant> &oldvalues,
const QVariant &value, const QCString &property);
virtual void execute();
virtual void unexecute();
virtual QString name() const;
QCString property() const { return m_property; }
void setValue(const QVariant &value);
const QMap<QCString, QVariant>& oldValues() const { return m_oldvalues; }
virtual void debug();
protected:
WidgetPropertySet *m_propSet;
QVariant m_value;
QMap<QCString, QVariant> m_oldvalues;
QCString m_property;
};
/*! This command is used when moving multiples widgets at the same time, while holding Ctrl or Shift.
You need to supply a list of widget names, and the position of the cursor before moving. Use setPos()
to tell the new cursor pos every time it changes.*/
class KFORMEDITOR_EXPORT GeometryPropertyCommand : public Command
{
public:
GeometryPropertyCommand(WidgetPropertySet *set, const QStringList &names, const QPoint& oldPos);
virtual void execute();
virtual void unexecute();
virtual QString name() const;
void setPos(const QPoint& pos);
virtual void debug();
protected:
WidgetPropertySet *m_propSet;
QStringList m_names;
QPoint m_oldPos;
QPoint m_pos;
};
/*! This command is used when an item in 'Align Widgets position' is selected. You just need
to give the list of widget names (the selected ones), and the
type of alignment (see the enum for possible values). */
class KFORMEDITOR_EXPORT AlignWidgetsCommand : public Command
{
public:
enum { AlignToGrid = 100, AlignToLeft, AlignToRight, AlignToTop, AlignToBottom };
AlignWidgetsCommand(int type, WidgetList &list, Form *form);
virtual void execute();
virtual void unexecute();
virtual QString name() const;
virtual void debug();
protected:
Form *m_form;
int m_type;
QMap<QCString, QPoint> m_pos;
};
/*! This command is used when an item in 'Adjust Widgets Size' is selected. You just need
to give the list of widget names (the selected ones), and the
type of size modification (see the enum for possible values). */
class KFORMEDITOR_EXPORT AdjustSizeCommand : public Command
{
public:
enum { SizeToGrid = 200, SizeToFit, SizeToSmallWidth, SizeToBigWidth,
SizeToSmallHeight, SizeToBigHeight };
AdjustSizeCommand(int type, WidgetList &list, Form *form);
virtual void execute();
virtual void unexecute();
virtual QString name() const;
virtual void debug();
protected:
QSize getSizeFromChildren(ObjectTreeItem *item);
protected:
Form *m_form;
int m_type;
QMap<QCString, QPoint> m_pos;
QMap<QCString, QSize> m_sizes;
};
/*! This command is used when switching the layout of a Container. It remembers the old pos
of every widget inside the Container. */
class KFORMEDITOR_EXPORT LayoutPropertyCommand : public PropertyCommand
{
public:
LayoutPropertyCommand(WidgetPropertySet *set, const QCString &wname,
const QVariant &oldValue, const QVariant &value);
virtual void execute();
virtual void unexecute();
virtual QString name() const;
virtual void debug();
protected:
Form *m_form;
QMap<QCString,QRect> m_geometries;
};
/*! This command is used when inserting a widger using toolbar or menu. You only need to give
the parent Container and the widget pos.
The other information is taken from FormManager. */
class KFORMEDITOR_EXPORT InsertWidgetCommand : public Command
{
public:
InsertWidgetCommand(Container *container);
/*! This ctor allows to set explicit class name and position.
Used for dropping widgets on the form surface.
If \a namePrefix is empty, widget's unique name is constructed using
hint for \a className (WidgetLibrary::namePrefix()),
otherwise, \a namePrefix is used to generate widget's name.
This allows e.g. inserting a widgets having name constructed using
*/
InsertWidgetCommand(Container *container, const QCString& className,
const QPoint& pos, const QCString& namePrefix = QCString());
virtual void execute();
virtual void unexecute();
virtual QString name() const;
virtual void debug();
//! \return inserted widget's name
QCString widgetName() const { return m_name; }
protected:
Form *m_form;
QString m_containername;
QPoint m_point;
QCString m_name;
QCString m_class;
QRect m_insertRect;
};
/*! This command is used when creating a layout from some widgets using "Lay out in..." menu item.
It remembers the old pos of every widget, and takes care of updating ObjectTree too. You need
to supply a WidgetList of the selected widgets. */
class KFORMEDITOR_EXPORT CreateLayoutCommand : public Command
{
public:
CreateLayoutCommand(int layoutType, WidgetList &list, Form *form);
CreateLayoutCommand() {;} // for BreakLayoutCommand
virtual void execute();
virtual void unexecute();
virtual QString name() const;
virtual void debug();
protected:
Form *m_form;
QString m_containername;
QString m_name;
QMap<QCString,QRect> m_pos;
int m_type;
};
/*! This command is used when the 'Break Layout' menu item is selected. It does exactly the
opposite of CreateLayoutCommand. */
class KFORMEDITOR_EXPORT BreakLayoutCommand : public CreateLayoutCommand
{
public:
BreakLayoutCommand(Container *container);
virtual void execute();
virtual void unexecute();
virtual QString name() const;
virtual void debug();
};
/*! This command is used when pasting widgets. You need to give the QDomDocument containing
the widget(s) to paste, and optionnally the point where to paste widgets. */
class KFORMEDITOR_EXPORT PasteWidgetCommand : public Command
{
public:
PasteWidgetCommand(QDomDocument &domDoc, Container *container, const QPoint& p = QPoint());
virtual void execute();
virtual void unexecute();
virtual QString name() const;
virtual void debug();
protected:
/*! Internal function used to change the coordinates of a widget to \a newpos
before pasting it (to paste it at the position of the contextual menu). It modifies
the "geometry" property of the QDomElement representing the widget. */
void changePos(QDomElement &widg, const QPoint &newpos);
/*! Internal function used to fix the coordinates of a widget before pasting it
(to avoid having two widgets at the same position). It moves the widget by
(10, 10) increment (several times if there are already pasted widgets at this position). */
void fixPos(QDomElement &el, Container *container);
void moveWidgetBy(QDomElement &el, Container *container, const QPoint &p);
/*! Internal function used to fix the names of the widgets before pasting them.
It prevents from pasting a widget with
the same name as an actual widget. The child widgets are also fixed recursively.\n
If the name of the widget ends with a number (eg "QLineEdit1"), the new name is
just incremented by one (eg becomes "QLineEdit2"). Otherwise, a "2" is just
appended at the end of the name (eg "myWidget" becomes "myWidget2"). */
void fixNames(QDomElement &el);
protected:
Form *m_form;
QCString m_data;
QString m_containername;
QPoint m_point;
QStringList m_names;
};
/*! This command is used when deleting a widget using the "Delete" menu item.
You need to give a WidgetList of the selected widgets. */
class KFORMEDITOR_EXPORT DeleteWidgetCommand : public Command
{
public:
DeleteWidgetCommand(WidgetList &list, Form *form);
virtual void execute();
virtual void unexecute();
virtual QString name() const;
virtual void debug();
protected:
QDomDocument m_domDoc;
Form *m_form;
QMap<QCString, QCString> m_containers;
QMap<QCString, QCString> m_parents;
};
/*! This command is used when cutting widgets. It is basically a DeleteWidgetCommand
which also updates the clipboard contents. */
class KFORMEDITOR_EXPORT CutWidgetCommand : public DeleteWidgetCommand
{
public:
CutWidgetCommand(WidgetList &list, Form *form);
virtual void execute();
virtual void unexecute();
virtual QString name() const;
virtual void debug();
protected:
QCString m_data;
};
/*! A Command Group is a command that holds several subcommands.
It will appear as one to the user and in the command history,
but it can use the implementation of multiple commands internally.
It extends KMacroCommand by providing the list of commands executed.
Selected subcommands can be marked as nonexecutable by adding them using
addCommand(KCommand *command, bool allowExecute) special method.
*/
class KFORMEDITOR_EXPORT CommandGroup : public Command
{
public:
CommandGroup( const QString & name, WidgetPropertySet *propSet );
virtual ~CommandGroup();
/*! Like KmacroCommand::addCommand(KCommand*)
but if \a allowExecute is false, \a command will not be executed
as a subcommand when CommandGroup::execute() is called.
This is useful e.g. in KexiFormView::insertAutoFields(),
where a number of subcommands of InsertWidgetCommand type and subcommands
is groupped using CommandGroup but some of these subcommands are executed
before executing CommandGroup::execute().
If \a allowExecute is true, this method behaves exactly like
KmacroCommand::addCommand(KCommand*).
Note that unexecute() doesn't check \a allowExecute flag:
all subcommands will be unexecuted (in reverse order
to the one in which they were added).
*/
void addCommand(KCommand *command, bool allowExecute);
/*! Executes all subcommands added to this group
in the same order as they were added. Subcommands added with
addCommand(KCommand *command, bool allowExecute) where allowExecute == false,
will not be executed. */
virtual void execute();
/*! Unexecutes all subcommands added to this group,
(in reversed order). */
virtual void unexecute();
virtual QString name() const;
/*! \return a list of all subcommands of this group.
Note that if a given subcommand is a group itself,
it will not be expanded to subcommands on this list. */
const QPtrList<KCommand>& commands() const;
/*! Resets all 'allowExecute' flags that was set in addCommand().
Call this after calling CommandGroup::execute() to ensure that
in the future, when REDO is be executed, all subcommands will be executed. */
void resetAllowExecuteFlags();
virtual void debug();
protected:
class SubCommands;
SubCommands *m_subCommands;
//! Used to store pointers to subcommands that shouldn't be executed
//! on CommandGroup::execute()
QPtrDict<char> m_commandsShouldntBeExecuted;
WidgetPropertySet *m_propSet;
};
}
#endif
|