kexi

form.h

00001 /* This file is part of the KDE project
00002    Copyright (C) 2003 Lucijan Busch <lucijan@gmx.at>
00003    Copyright (C) 2004 Cedric Pasteur <cedric.pasteur@free.fr>
00004    Copyright (C) 2004-2005 Jaroslaw Staniek <js@iidea.pl>
00005 
00006    This library is free software; you can redistribute it and/or
00007    modify it under the terms of the GNU Library General Public
00008    License as published by the Free Software Foundation; either
00009    version 2 of the License, or (at your option) any later version.
00010 
00011    This library is distributed in the hope that it will be useful,
00012    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014    Library General Public License for more details.
00015 
00016    You should have received a copy of the GNU Library General Public License
00017    along with this library; see the file COPYING.LIB.  If not, write to
00018    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00019  * Boston, MA 02110-1301, USA.
00020 */
00021 
00022 #ifndef KFORMDESIGNERFORM_H
00023 #define KFORMDESIGNERFORM_H
00024 
00025 #include <qobject.h>
00026 #include <qptrlist.h>
00027 
00028 #include "resizehandle.h"
00029 #include "utils.h"
00030 #include "objecttree.h"
00031 
00032 class QWidget;
00033 class QDomElement;
00034 class KActionCollection;
00035 class KCommandHistory;
00036 class KCommand;
00037 class PixmapCollection;
00038 
00039 namespace KFormDesigner {
00040 
00041 class Container;
00042 class WidgetPropertySet;
00043 class WidgetLibrary;
00044 class FormManager;
00045 class ObjectTree;
00046 class ObjectTreeItem;
00047 class ConnectionBuffer;
00048 
00050 
00053 class KFORMEDITOR_EXPORT FormWidget
00054 {
00055     public:
00056         FormWidget();
00057         virtual ~FormWidget();
00058 
00063         virtual void drawRects(const QValueList<QRect> &list, int type) = 0;
00064 
00065         virtual void drawRect(const QRect &r, int type) = 0;
00066 
00068         virtual void initBuffer() = 0;
00069 
00071         virtual void clearForm() = 0;
00072 
00075         virtual void highlightWidgets(QWidget *from, QWidget *to) = 0;
00076     
00077     protected:
00078         Form *m_form;
00079 
00080     friend class Form;
00081 };
00082 
00084 class FormPrivate
00085 {
00086     public:
00087         FormPrivate();
00088         ~FormPrivate();
00089 
00090 //      FormManager  *manager;
00091         QGuardedPtr<Container>  toplevel;
00092         ObjectTree  *topTree;
00093         QGuardedPtr<QWidget> widget;
00094 
00095         WidgetList  selected;
00096         ResizeHandleSet::Dict resizeHandles;
00097 
00098         bool  dirty;
00099         bool  interactive;
00100         bool  design;
00101         QString  filename;
00102 
00103         KCommandHistory  *history;
00104         KActionCollection  *collection;
00105 
00106         ObjectTreeList  tabstops;
00107         bool  autoTabstops;
00108         ConnectionBuffer  *connBuffer;
00109 
00110         PixmapCollection  *pixcollection;
00111 
00113         QMap<QObject*,QCursor> cursors;
00114 
00116         QStringList *mouseTrackers;
00117 
00118         FormWidget  *formWidget;
00119 
00122         QMap<QCString,QString> headerProperties;
00123 
00125         uint formatVersion;
00127         uint originalFormatVersion;
00128 };
00129 
00134 
00135 class KFORMEDITOR_EXPORT Form : public QObject
00136 {
00137     Q_OBJECT
00138 
00139     public:
00142         Form(WidgetLibrary* library, const char *name=0, bool designMode = true);
00143         ~Form();
00144 
00146         WidgetLibrary* library() const { return m_lib; }
00147 
00155         void createToplevel(QWidget *container, FormWidget *formWidget =0,
00156             const QCString &classname="QWidget");
00157 
00160         Container* toplevelContainer() const { return d->toplevel; }
00161 
00163         FormWidget* formWidget() const { return d->formWidget; }
00164 
00166         ObjectTree* objectTree() const { return d->topTree; }
00167 
00169         QWidget* widget() const;
00170 
00171 //      //! \return the FormManager parent of this form.
00172 //      FormManager* manager() const { return d->manager; }
00173 
00177         Container* activeContainer();
00178 
00183         Container* parentContainer(QWidget *w=0);
00184 
00188         ObjectTreeItem* commonParentContainer(WidgetList *wlist);
00189 
00191         WidgetList* selectedWidgets() const {return &(d->selected);}
00192 
00196         QWidget* selectedWidget() const { return d->selected.count()==1 ? d->selected.first() : 0; }
00197 
00200         void emitActionSignals(bool withUndoAction=true);
00201 
00204         void  emitSelectionSignals();
00205 
00209         void setInteractiveMode(bool interactive) { d->interactive = interactive; }
00210 
00217         bool interactiveMode() const { return d->interactive; }
00218 
00222         void setDesignMode(bool design);
00223 
00225         bool designMode() const { return d->design; }
00226 
00227         bool isModified() { return d->dirty; }
00228 
00231         int gridSize() { return 10; }
00232 
00234         int defaultMargin() { return 11;}
00235 
00237         int defaultSpacing() { return 6;}
00238 
00240         void emitChildAdded(ObjectTreeItem *item);
00241 
00243         void emitChildRemoved(ObjectTreeItem *item);
00244 
00247         QString filename() const { return d->filename; }
00248 
00250         void setFilename(const QString &file) { d->filename = file; }
00251 
00252         KCommandHistory* commandHistory() const { return d->history; }
00253         ConnectionBuffer* connectionBuffer() const { return d->connBuffer; }
00254         PixmapCollection* pixmapCollection() const { return d->pixcollection; }
00255 
00258         void addCommand(KCommand *command, bool execute);
00259 
00261         void clearCommandHistory();
00262 
00266         ObjectTreeList* tabStops() const { return &(d->tabstops); }
00267 
00268         inline ObjectTreeListIterator tabStopsIterator() const { return ObjectTreeListIterator(d->tabstops); }
00269 
00272         void updateTabStopsOrder();
00273 
00275         void addWidgetToTabStops(ObjectTreeItem *c);
00276 
00278         bool autoTabStops() const { return d->autoTabstops; }
00279 
00285         void setAutoTabStops(bool autoTab) { d->autoTabstops = autoTab;}
00286 
00289         void autoAssignTabStops();
00290 
00291 #ifdef KEXI_DEBUG_GUI
00293         QString m_recentlyLoadedUICode;
00294 #endif
00295 
00299 //      void resizeHandleDraggingStarted(QWidget *draggedWidget);
00300 
00301         ResizeHandleSet* resizeHandlesForWidget(QWidget* w);
00302 
00305         QMap<QCString,QString>* headerProperties() const { return &d->headerProperties; }
00306 
00309         uint formatVersion() const;
00310         void setFormatVersion(uint ver);
00311 
00314         uint originalFormatVersion() const;
00315         void setOriginalFormatVersion(uint ver);
00316 
00317     public slots:
00321         void changeName(const QCString &oldname, const QCString &newname);
00322 
00329         void setSelectedWidget(QWidget *selected, bool add=false, bool dontRaise=false,
00330             bool moreWillBeSelected = false);
00331 
00334         void unSelectWidget(QWidget *w);
00335 
00337         void selectFormWidget();
00338 
00339         void clearSelection();
00340 
00341     protected slots:
00345         void formDeleted();
00346 
00347         void emitUndoEnabled();
00348         void emitRedoEnabled();
00349 
00352         void slotCommandExecuted();
00353 
00357         void slotFormRestored();
00358 
00359     signals:
00364         void selectionChanged(QWidget *w, bool add, bool moreWillBeSelected = false);
00365 
00369         void childAdded(ObjectTreeItem *it);
00370 
00374         void childRemoved(ObjectTreeItem *it);
00375 
00377         void destroying();
00378 
00379     protected:
00380         void setConnectionBuffer(ConnectionBuffer *b) { d->connBuffer = b; }
00381 
00382         void setFormWidget(FormWidget* w);
00383     private:
00384         WidgetLibrary *m_lib;
00385         FormPrivate *d;
00386 
00387         friend class FormManager;
00388         friend class FormWidget;
00389         friend class ConnectionDialog;
00390 };
00391 
00392 }
00393 
00394 #endif
KDE Home | KDE Accessibility Home | Description of Access Keys