1
/* This file is part of the KDE project
2
Copyright (C) 2004 Cedric Pasteur <cedric.pasteur@free.fr>
3
Copyright (C) 2005-2010 JarosÅaw Staniek <staniek@kde.org>
5
This library is free software; you can redistribute it and/or
6
modify it under the terms of the GNU Library General Public
7
License as published by the Free Software Foundation; either
8
version 2 of the License, or (at your option) any later version.
10
This library 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 GNU
13
Library General Public License for more details.
15
You should have received a copy of the GNU Library General Public License
16
along with this library; see the file COPYING.LIB. If not, write to
17
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18
* Boston, MA 02110-1301, USA.
21
#ifndef KFORMEDITOR_COMMANDS_H
22
#define KFORMEDITOR_COMMANDS_H
24
#include "kformdesigner_export.h"
26
#include "objecttree.h"
32
#include <kundo2command.h>
40
namespace KFormDesigner
47
//! Base class for KFormDesigner's commands
48
class KFORMDESIGNER_EXPORT Command : public KUndo2Command
51
explicit Command(Command *parent = 0);
53
explicit Command(const QString &text, Command *parent = 0);
57
//! Reimplemented to support effect of blockRedoOnce().
60
//! Implement instead of redo().
61
virtual void execute() = 0;
63
virtual void debug() const;
65
friend KFORMDESIGNER_EXPORT QDebug operator<<(QDebug dbg, const Command &c);
67
//! Used to block execution of redo() once, on adding the command to the stack.
71
bool m_blockRedoOnce; //!< Used to block redo() once
74
//! qDebug() stream operator. Writes command @a c to the debug output in a nicely formatted way.
75
KFORMDESIGNER_EXPORT QDebug operator<<(QDebug dbg, const Command &c);
77
//! Command is used when changing a property for one or more widgets.
78
class KFORMDESIGNER_EXPORT PropertyCommand : public Command
81
/*! @a oldValue is the old property value for selected widget.
82
This enables reverting the change. @a value is the new property value. */
83
PropertyCommand(Form& form, const QByteArray &wname, const QVariant &oldValue,
84
const QVariant &value, const QByteArray &propertyName, Command *parent = 0);
86
/*! @a oldValues is a QHash of the old property values for every widget,
87
to allow reverting the change. @a value is the new property value.
88
You can use the simpler constructor for a single widget. */
89
PropertyCommand(Form& form, const QHash<QByteArray, QVariant> &oldValues,
90
const QVariant &value, const QByteArray &propertyName, Command *parent = 0);
92
virtual ~PropertyCommand();
96
virtual int id() const;
98
void setUniqueId(int id);
100
virtual void execute();
104
bool mergeWith(const KUndo2Command * command);
106
QByteArray propertyName() const;
108
QVariant value() const;
110
void setValue(const QVariant &value);
112
const QHash<QByteArray, QVariant>& oldValues() const;
114
//! @return old value if there is single value, otherwise null value.
115
QVariant oldValue() const;
117
//! @return widget name in case when there is only one widget
118
//! with changed property in this command
119
/*! Otherwise empty value is returned. */
120
QByteArray widgetName() const;
122
virtual void debug() const;
124
friend KFORMDESIGNER_EXPORT QDebug operator<<(QDebug dbg, const PropertyCommand &c);
131
//! qDebug() stream operator. Writes command @a c to the debug output in a nicely formatted way.
132
KFORMDESIGNER_EXPORT QDebug operator<<(QDebug dbg, const PropertyCommand &c);
134
//! Command used when moving multiples widgets at the same time, while holding Ctrl or Shift.
135
/*! You need to supply a list of widget names, and the position of the cursor before moving. Use setPos()
136
to tell the new cursor pos every time it changes.*/
137
class KFORMDESIGNER_EXPORT GeometryPropertyCommand : public Command
140
GeometryPropertyCommand(Form& form, const QStringList &names,
141
const QPoint& oldPos, Command *parent = 0);
143
virtual ~GeometryPropertyCommand();
145
virtual int id() const;
147
virtual void execute();
151
void setPos(const QPoint& pos);
155
QPoint oldPos() const;
157
virtual void debug() const;
159
friend KFORMDESIGNER_EXPORT QDebug operator<<(QDebug dbg, const GeometryPropertyCommand &c);
165
//! qDebug() stream operator. Writes command @a c to the debug output in a nicely formatted way.
166
KFORMDESIGNER_EXPORT QDebug operator<<(QDebug dbg, const GeometryPropertyCommand &c);
168
//! Command used when an "Align Widgets position" action is activated.
169
/* You just need to give the list of widget names (the selected ones), and the
170
type of alignment (see the enum for possible values). */
171
class KFORMDESIGNER_EXPORT AlignWidgetsCommand : public Command
174
AlignWidgetsCommand(Form &form, Form::WidgetAlignment alignment, const QWidgetList &list,
175
Command *parent = 0);
177
virtual ~AlignWidgetsCommand();
179
virtual int id() const;
181
virtual void execute();
185
virtual void debug() const;
187
friend KFORMDESIGNER_EXPORT QDebug operator<<(QDebug dbg, const AlignWidgetsCommand &c);
193
//! qDebug() stream operator. Writes command @a c to the debug output in a nicely formatted way.
194
KFORMDESIGNER_EXPORT QDebug operator<<(QDebug dbg, const AlignWidgetsCommand &c);
196
//! Command used when an "Adjust Widgets Size" action is activated.
197
/*! You just need to give the list of widget names (the selected ones),
198
and the type of size modification (see the enum for possible values). */
199
class KFORMDESIGNER_EXPORT AdjustSizeCommand : public Command
211
AdjustSizeCommand(Form& form, Adjustment type, const QWidgetList &list, Command *parent = 0);
213
virtual ~AdjustSizeCommand();
215
virtual int id() const;
217
virtual void execute();
221
virtual void debug() const;
223
friend KFORMDESIGNER_EXPORT QDebug operator<<(QDebug dbg, const AdjustSizeCommand &c);
225
QSize getSizeFromChildren(ObjectTreeItem *item);
232
//! qDebug() stream operator. Writes command @a c to the debug output in a nicely formatted way.
233
KFORMDESIGNER_EXPORT QDebug operator<<(QDebug dbg, const AdjustSizeCommand &c);
235
//! Command used when switching the layout of a container.
236
/*! It remembers the old pos of every widget inside the container. */
237
class KFORMDESIGNER_EXPORT LayoutPropertyCommand : public PropertyCommand
240
LayoutPropertyCommand(Form& form, const QByteArray &wname,
241
const QVariant &oldValue, const QVariant &value,
242
Command *parent = 0);
244
virtual ~LayoutPropertyCommand();
246
virtual int id() const;
248
virtual void execute();
252
virtual void debug() const;
254
friend KFORMDESIGNER_EXPORT QDebug operator<<(QDebug dbg, const LayoutPropertyCommand &c);
260
//! qDebug() stream operator. Writes command @a c to the debug output in a nicely formatted way.
261
KFORMDESIGNER_EXPORT QDebug operator<<(QDebug dbg, const LayoutPropertyCommand &c);
263
//! Command used when inserting a widget using toolbar or menu.
264
/*! You only have to give the parent Container and the widget pos.
265
The other information is taken from the form. */
266
class KFORMDESIGNER_EXPORT InsertWidgetCommand : public Command
269
explicit InsertWidgetCommand(const Container& container, Command *parent = 0);
271
/*! This ctor allows to set explicit class name and position.
272
Used for dropping widgets on the form surface.
273
If \a namePrefix is empty, widget's unique name is constructed using
274
hint for \a className (WidgetLibrary::namePrefix()),
275
otherwise, \a namePrefix is used to generate widget's name.
276
This allows e.g. inserting a widgets having name constructed using
278
InsertWidgetCommand(const Container& container, const QByteArray& className,
279
const QPoint& pos, const QByteArray& namePrefix = QByteArray(),
280
Command *parent = 0);
282
virtual ~InsertWidgetCommand();
284
virtual int id() const;
286
virtual void execute();
290
//! @return inserted widget's name
291
QByteArray widgetName() const;
293
virtual void debug() const;
295
friend KFORMDESIGNER_EXPORT QDebug operator<<(QDebug dbg, const InsertWidgetCommand &c);
303
//! qDebug() stream operator. Writes command @a c to the debug output in a nicely formatted way.
304
KFORMDESIGNER_EXPORT QDebug operator<<(QDebug dbg, const InsertWidgetCommand &c);
306
//! @todo add CopyWidgetCommand
308
//! Command used when pasting widgets.
309
/*! You need to give the QDomDocument containing
310
the widget(s) to paste, and optionally the point where to paste widgets. */
311
class KFORMDESIGNER_EXPORT PasteWidgetCommand : public Command
314
PasteWidgetCommand(const QDomDocument &domDoc, const Container& container,
315
const QPoint& p = QPoint(), Command *parent = 0);
317
virtual ~PasteWidgetCommand();
319
virtual int id() const;
321
virtual void execute();
325
virtual void debug() const;
327
friend KFORMDESIGNER_EXPORT QDebug operator<<(QDebug dbg, const PasteWidgetCommand &c);
330
/*! Internal function used to change the coordinates of a widget to \a newPos
331
before pasting it (to paste it at the position of the contextual menu). It modifies
332
the "geometry" property of the QDomElement representing the widget. */
333
void changePos(QDomElement &el, const QPoint &newPos);
335
/*! Internal function used to fix the coordinates of a widget before pasting it
336
(to avoid having two widgets at the same position). It moves the widget by
337
(10, 10) increment (several times if there are already pasted widgets at this position). */
338
void fixPos(QDomElement &el, Container *container);
340
void moveWidgetBy(QDomElement &el, Container *container, const QPoint &p);
342
/*! Internal function used to fix the names of the widgets before pasting them.
343
It prevents from pasting a widget with
344
the same name as an actual widget. The child widgets are also fixed recursively.\n
345
If the name of the widget ends with a number (eg "QLineEdit1"), the new name is
346
just incremented by one (eg becomes "QLineEdit2"). Otherwise, a "2" is just
347
appended at the end of the name (eg "myWidget" becomes "myWidget2"). */
348
void fixNames(QDomElement &el);
355
//! qDebug() stream operator. Writes command @a c to the debug output in a nicely formatted way.
356
KFORMDESIGNER_EXPORT QDebug operator<<(QDebug dbg, const PasteWidgetCommand &c);
358
//! Command used when deleting widgets using the "Delete" menu item.
359
/*! You need to give a QWidgetList of the selected widgets. */
360
class KFORMDESIGNER_EXPORT DeleteWidgetCommand : public Command
363
DeleteWidgetCommand(Form& form, const QWidgetList &list, Command *parent = 0);
365
virtual ~DeleteWidgetCommand();
367
virtual int id() const;
369
virtual void execute();
373
virtual void debug() const;
375
friend KFORMDESIGNER_EXPORT QDebug operator<<(QDebug dbg, const DeleteWidgetCommand &c);
381
//! qDebug() stream operator. Writes command @a c to the debug output in a nicely formatted way.
382
KFORMDESIGNER_EXPORT QDebug operator<<(QDebug dbg, const DeleteWidgetCommand &c);
384
//! Command used when duplicating widgets.
385
/*! You need to give a QWidgetList of the selected widgets. */
386
class KFORMDESIGNER_EXPORT DuplicateWidgetCommand : public Command
389
DuplicateWidgetCommand(const Container& container, const QWidgetList &list,
390
const QPoint& copyToPoint, Command *parent = 0);
392
virtual ~DuplicateWidgetCommand();
394
virtual int id() const;
396
virtual void execute();
400
virtual void debug() const;
402
friend KFORMDESIGNER_EXPORT QDebug operator<<(QDebug dbg, const DuplicateWidgetCommand &c);
408
//! qDebug() stream operator. Writes command @a c to the debug output in a nicely formatted way.
409
KFORMDESIGNER_EXPORT QDebug operator<<(QDebug dbg, const DuplicateWidgetCommand &c);
411
//! Command used when cutting widgets.
412
/*! It is basically a DeleteWidgetCommand which also updates the clipboard contents. */
413
class KFORMDESIGNER_EXPORT CutWidgetCommand : public DeleteWidgetCommand
416
CutWidgetCommand(Form &form, const QWidgetList &list, Command *parent = 0);
418
virtual ~CutWidgetCommand();
420
virtual int id() const;
422
virtual void execute();
426
virtual void debug() const;
428
friend KFORMDESIGNER_EXPORT QDebug operator<<(QDebug dbg, const CutWidgetCommand &c);
434
//! qDebug() stream operator. Writes command @a c to the debug output in a nicely formatted way.
435
KFORMDESIGNER_EXPORT QDebug operator<<(QDebug dbg, const CutWidgetCommand &c);
437
//! Command that holds several PropertyCommand subcommands.
438
/*! It appears as one to the user and in the command history. */
439
class KFORMDESIGNER_EXPORT PropertyCommandGroup : public Command
442
explicit PropertyCommandGroup(const QString &text, Command *parent = 0);
444
virtual ~PropertyCommandGroup();
446
virtual int id() const;
448
virtual void execute();
450
virtual void debug() const;
452
friend KFORMDESIGNER_EXPORT QDebug operator<<(QDebug dbg, const PropertyCommandGroup &c);
458
//! qDebug() stream operator. Writes command @a c to the debug output in a nicely formatted way.
459
KFORMDESIGNER_EXPORT QDebug operator<<(QDebug dbg, const PropertyCommandGroup &c);
461
//! Command is used when inline text is edited for a single widget.
462
class KFORMDESIGNER_EXPORT InlineTextEditingCommand : public Command
465
/*! @a oldValue is the old property value for selected widget.
466
This enables reverting the change. @a value is the new property value. */
467
InlineTextEditingCommand(
468
Form& form, QWidget *widget, const QByteArray &editedWidgetClass,
469
const QString &text, Command *parent = 0);
471
virtual ~InlineTextEditingCommand();
473
virtual int id() const;
475
virtual bool mergeWith(const KUndo2Command * command);
477
virtual void execute();
479
virtual void debug() const;
485
QString text() const;
487
QString oldText() const;
489
friend KFORMDESIGNER_EXPORT QDebug operator<<(QDebug dbg, const InlineTextEditingCommand &c);
496
//! qDebug() stream operator. Writes command group @a c to the debug output in a nicely formatted way.
497
KFORMDESIGNER_EXPORT QDebug operator<<(QDebug dbg, const InlineTextEditingCommand &c);
499
class KFORMDESIGNER_EXPORT InsertPageCommand : public Command
502
InsertPageCommand(Container *container, QWidget *widget);
504
virtual ~InsertPageCommand();
506
virtual int id() const;
508
virtual void execute();
510
void execute(const QString& pageWidgetName, const QString& pageName, int pageIndex);
512
virtual void debug() const;
516
void undo(const QString& name);
518
friend KFORMDESIGNER_EXPORT QDebug operator<<(QDebug dbg, const InsertPageCommand &c);
525
//! qDebug() stream operator. Writes command @a c to the debug output in a nicely formatted way.
526
KFORMDESIGNER_EXPORT QDebug operator<<(QDebug dbg, const InsertPageCommand &c);
528
class KFORMDESIGNER_EXPORT RemovePageCommand : public Command
531
RemovePageCommand(Container *container, QWidget *widget);
533
virtual ~RemovePageCommand();
535
virtual int id() const;
537
virtual void execute();
539
virtual void debug() const;
543
int pageIndex() const;
545
QString pageName() const;
547
friend KFORMDESIGNER_EXPORT QDebug operator<<(QDebug dbg, const RemovePageCommand &c);
554
//! qDebug() stream operator. Writes command @a c to the debug output in a nicely formatted way.
555
KFORMDESIGNER_EXPORT QDebug operator<<(QDebug dbg, const RemovePageCommand &c);