kexi

commands.h

00001 /* This file is part of the KDE project
00002    Copyright (C) 2004 Cedric Pasteur <cedric.pasteur@free.fr>
00003    Copyright (C) 2005 Jaroslaw Staniek <js@iidea.pl>
00004 
00005    This library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Library General Public
00007    License as published by the Free Software Foundation; either
00008    version 2 of the License, or (at your option) any later version.
00009 
00010    This library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Library General Public License for more details.
00014 
00015    You should have received a copy of the GNU Library General Public License
00016    along with this library; see the file COPYING.LIB.  If not, write to
00017    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00018  * Boston, MA 02110-1301, USA.
00019 */
00020 
00021 #ifndef KFORMEDITOR_COMMANDS_H
00022 #define KFORMEDITOR_COMMANDS_H
00023 
00024 #include <qmap.h>
00025 #include <qdict.h>
00026 #include <qptrlist.h>
00027 #include <qptrdict.h>
00028 #include <qvariant.h>
00029 #include <qdom.h>
00030 
00031 #include <kcommand.h>
00032 #include "utils.h"
00033 
00034 class QWidget;
00035 class QRect;
00036 class QPoint;
00037 class QStringList;
00038 class QCString;
00039 
00040 namespace KFormDesigner {
00041 
00042 class WidgetPropertySet;
00043 class ObjectTreeItem;
00044 class Container;
00045 class Form;
00046 
00048 class KFORMEDITOR_EXPORT Command : public KCommand
00049 {
00050     public:
00051         Command();
00052         virtual ~Command();
00053 
00054         virtual void debug() = 0;
00055 };
00056 
00061 class KFORMEDITOR_EXPORT PropertyCommand : public Command
00062 {
00063     public:
00064         PropertyCommand(WidgetPropertySet *set, const QCString &wname, const QVariant &oldValue,
00065             const QVariant &value, const QCString &property);
00066         PropertyCommand(WidgetPropertySet *set, const QMap<QCString, QVariant> &oldvalues,
00067              const QVariant &value, const QCString &property);
00068 
00069         virtual void execute();
00070         virtual void unexecute();
00071         virtual QString name() const;
00072         QCString property() const { return m_property; }
00073 
00074         void  setValue(const QVariant &value);
00075         const QMap<QCString, QVariant>& oldValues() const { return m_oldvalues; }
00076         virtual void debug();
00077 
00078     protected:
00079         WidgetPropertySet *m_propSet;
00080         QVariant m_value;
00081         QMap<QCString, QVariant> m_oldvalues;
00082         QCString m_property;
00083 };
00084 
00088 class KFORMEDITOR_EXPORT GeometryPropertyCommand : public Command
00089 {
00090     public:
00091         GeometryPropertyCommand(WidgetPropertySet *set, const QStringList &names, const QPoint& oldPos);
00092 
00093         virtual void execute();
00094         virtual void unexecute();
00095         virtual QString name() const;
00096         void setPos(const QPoint& pos);
00097         virtual void debug();
00098 
00099     protected:
00100         WidgetPropertySet *m_propSet;
00101         QStringList m_names;
00102         QPoint m_oldPos;
00103         QPoint m_pos;
00104 };
00105 
00109 class KFORMEDITOR_EXPORT AlignWidgetsCommand : public Command
00110 {
00111     public:
00112         enum { AlignToGrid = 100, AlignToLeft, AlignToRight, AlignToTop, AlignToBottom };
00113 
00114         AlignWidgetsCommand(int type, WidgetList &list, Form *form);
00115 
00116         virtual void execute();
00117         virtual void unexecute();
00118         virtual QString name() const;
00119         virtual void debug();
00120 
00121     protected:
00122         Form *m_form;
00123         int m_type;
00124         QMap<QCString, QPoint> m_pos;
00125 };
00126 
00130 class KFORMEDITOR_EXPORT AdjustSizeCommand : public Command
00131 {
00132     public:
00133         enum { SizeToGrid = 200, SizeToFit, SizeToSmallWidth, SizeToBigWidth,
00134             SizeToSmallHeight, SizeToBigHeight };
00135 
00136         AdjustSizeCommand(int type, WidgetList &list, Form *form);
00137 
00138         virtual void execute();
00139         virtual void unexecute();
00140         virtual QString name() const;
00141         virtual void debug();
00142 
00143     protected:
00144         QSize  getSizeFromChildren(ObjectTreeItem *item);
00145 
00146     protected:
00147         Form *m_form;
00148         int m_type;
00149         QMap<QCString, QPoint> m_pos;
00150         QMap<QCString, QSize> m_sizes;
00151 };
00152 
00155 class KFORMEDITOR_EXPORT LayoutPropertyCommand : public PropertyCommand
00156 {
00157     public:
00158         LayoutPropertyCommand(WidgetPropertySet *set, const QCString &wname,
00159             const QVariant &oldValue, const QVariant &value);
00160 
00161         virtual void execute();
00162         virtual void unexecute();
00163         virtual QString name() const;
00164         virtual void debug();
00165 
00166     protected:
00167         Form *m_form;
00168         QMap<QCString,QRect>  m_geometries;
00169 };
00170 
00174 class KFORMEDITOR_EXPORT InsertWidgetCommand : public Command
00175 {
00176     public:
00177         InsertWidgetCommand(Container *container);
00178 
00186         InsertWidgetCommand(Container *container, const QCString& className, 
00187             const QPoint& pos, const QCString& namePrefix = QCString());
00188 
00189         virtual void execute();
00190         virtual void unexecute();
00191         virtual QString name() const;
00192         virtual void debug();
00193 
00195         QCString widgetName() const { return m_name; }
00196 
00197     protected:
00198         Form *m_form;
00199         QString m_containername;
00200         QPoint m_point;
00201         QCString m_name;
00202         QCString m_class;
00203         QRect m_insertRect;
00204 };
00205 
00209 class KFORMEDITOR_EXPORT CreateLayoutCommand : public Command
00210 {
00211     public:
00212         CreateLayoutCommand(int layoutType, WidgetList &list, Form *form);
00213         CreateLayoutCommand() {;} // for BreakLayoutCommand
00214 
00215         virtual void execute();
00216         virtual void unexecute();
00217         virtual QString name() const;
00218         virtual void debug();
00219 
00220     protected:
00221         Form *m_form;
00222         QString m_containername;
00223         QString m_name;
00224         QMap<QCString,QRect> m_pos;
00225         int m_type;
00226 };
00227 
00230 class KFORMEDITOR_EXPORT BreakLayoutCommand : public CreateLayoutCommand
00231 {
00232     public:
00233         BreakLayoutCommand(Container *container);
00234 
00235         virtual void execute();
00236         virtual void unexecute();
00237         virtual QString name() const;
00238         virtual void debug();
00239 };
00240 
00243 class KFORMEDITOR_EXPORT PasteWidgetCommand : public Command
00244 {
00245     public:
00246         PasteWidgetCommand(QDomDocument &domDoc, Container *container, const QPoint& p = QPoint());
00247 
00248         virtual void execute();
00249         virtual void unexecute();
00250         virtual QString name() const;
00251         virtual void debug();
00252 
00253     protected:
00257         void changePos(QDomElement &widg, const QPoint &newpos);
00261         void fixPos(QDomElement &el, Container *container);
00262         void moveWidgetBy(QDomElement &el, Container *container, const QPoint &p);
00269         void fixNames(QDomElement &el);
00270 
00271     protected:
00272         Form *m_form;
00273         QCString m_data;
00274         QString m_containername;
00275         QPoint m_point;
00276         QStringList m_names;
00277 };
00278 
00281 class KFORMEDITOR_EXPORT DeleteWidgetCommand : public Command
00282 {
00283     public:
00284         DeleteWidgetCommand(WidgetList &list, Form *form);
00285 
00286         virtual void execute();
00287         virtual void unexecute();
00288         virtual QString name() const;
00289         virtual void debug();
00290 
00291     protected:
00292         QDomDocument m_domDoc;
00293         Form *m_form;
00294         QMap<QCString, QCString>  m_containers;
00295         QMap<QCString, QCString>  m_parents;
00296 };
00297 
00300 class KFORMEDITOR_EXPORT CutWidgetCommand : public DeleteWidgetCommand
00301 {
00302     public:
00303         CutWidgetCommand(WidgetList &list, Form *form);
00304 
00305         virtual void execute();
00306         virtual void unexecute();
00307         virtual QString name() const;
00308         virtual void debug();
00309 
00310     protected:
00311         QCString m_data;
00312 };
00313 
00321 class KFORMEDITOR_EXPORT CommandGroup : public Command
00322 {
00323     public:
00324         CommandGroup( const QString & name, WidgetPropertySet *propSet );
00325         virtual ~CommandGroup();
00326 
00343         void addCommand(KCommand *command, bool allowExecute);
00344 
00349         virtual void execute();
00350 
00353         virtual void unexecute();
00354 
00355         virtual QString name() const;
00356 
00360         const QPtrList<KCommand>& commands() const;
00361 
00365         void resetAllowExecuteFlags();
00366 
00367         virtual void debug();
00368 
00369     protected:
00370         class SubCommands;
00371         SubCommands *m_subCommands;
00374         QPtrDict<char> m_commandsShouldntBeExecuted;
00375         WidgetPropertySet *m_propSet;
00376 };
00377 
00378 }
00379 
00380 #endif
KDE Home | KDE Accessibility Home | Description of Access Keys