kexi
container.h00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef FORMEDITORCONTAINER_H
00022 #define FORMEDITORCONTAINER_H
00023
00024 #include <qobject.h>
00025 #include <qguardedptr.h>
00026 #include <qptrlist.h>
00027 #include <qwidget.h>
00028
00029 #include "utils.h"
00030
00031 class QEvent;
00032 class QWidget;
00033 class QLayout;
00034
00035 namespace KFormDesigner {
00036
00037 class Container;
00038 class WidgetLibrary;
00039 class ObjectTreeItem;
00040 class Form;
00041
00046
00047 class KFORMEDITOR_EXPORT EventEater : public QObject
00048 {
00049 Q_OBJECT
00050
00051 public:
00055 EventEater(QWidget *widget, QObject *container);
00056 ~EventEater();
00057
00059 void setContainer(QObject *container) { m_container = container; }
00060 bool eventFilter(QObject *o, QEvent *ev);
00061
00062 private:
00063 QGuardedPtr<QWidget> m_widget;
00064 QGuardedPtr<QObject> m_container;
00065 };
00066
00071
00072 class KFORMEDITOR_EXPORT Container : public QObject
00073 {
00074 Q_OBJECT
00075
00076 public:
00077 enum LayoutType { NoLayout=0, HBox, VBox, Grid, HFlow, VFlow, HSplitter, VSplitter };
00078
00082 Container(Container *toplevel, QWidget *container, QObject *parent=0, const char *name=0);
00083 virtual ~Container();
00084
00086 Container* toplevel();
00087
00089 Form* form() const { return m_form; }
00090
00092 QWidget* widget() const { return m_container; }
00093
00095 ObjectTreeItem* objectTree() const { return m_tree; }
00096
00098 void setForm(Form *form);
00099
00102 void setObjectTree(ObjectTreeItem *t) { m_tree = t; }
00103
00105 QLayout* layout() const { return m_layout; }
00106
00108 LayoutType layoutType() const { return m_layType; }
00109
00111 int layoutMargin() { return m_margin; }
00112
00114 int layoutSpacing() { return m_spacing; }
00115
00119 void setLayout(LayoutType type);
00120
00122 void setLayoutSpacing(int spacing) { m_spacing = spacing;}
00123
00125 void setLayoutMargin(int margin) { m_margin = margin;}
00126
00128 static QString layoutTypeToString(int type);
00129
00131 static LayoutType stringToLayoutType(const QString &name);
00132
00135 void stopInlineEditing() { m_state = DoingNothing; }
00136
00141 virtual bool eventFilter(QObject *o, QEvent *e);
00142
00143 public slots:
00151 void setSelectedWidget(QWidget *selected, bool add, bool dontRaise=false,
00152 bool moreWillBeSelected = false);
00153
00156 void unSelectWidget(QWidget *w);
00157
00160 void deleteWidget(QWidget *w);
00161
00164 void reloadLayout();
00165
00166 protected slots:
00168 void widgetDeleted();
00169
00170 protected:
00174 void createBoxLayout(WidgetList *list);
00175
00177 void createFlowLayout();
00178
00181 void createGridLayout(bool testOnly=false);
00182
00183 void drawConnection(QMouseEvent *mev);
00184 void drawSelectionRect(QMouseEvent *mev);
00185 void drawInsertRect(QMouseEvent *mev, QObject *s);
00186 void drawCopiedWidgetRect(QMouseEvent *mev);
00187
00188 void moveSelectedWidgetsBy(int realdx, int realdy, QMouseEvent *mev=0);
00189
00190 private:
00191 bool handleMouseReleaseEvent(QObject *s, QMouseEvent *mev);
00192
00193
00194 QGuardedPtr<QWidget> m_container;
00195 QGuardedPtr<Container> m_toplevel;
00196
00197 int m_state;
00198 enum { DoingNothing = 100, DrawingSelectionRect, CopyingWidget,
00199 MovingWidget, InlineEditing };
00200
00201
00202 QLayout *m_layout;
00203 LayoutType m_layType;
00204 int m_margin, m_spacing;
00205
00206
00207 QPoint m_grab;
00208
00209 QGuardedPtr<QWidget> m_moving;
00210
00211
00212
00213 QPoint m_insertBegin;
00214 QRect m_insertRect;
00215 ObjectTreeItem *m_tree;
00216
00217 QGuardedPtr<Form> m_form;
00218 bool m_mousePressEventReceived;
00219 QMouseEvent m_mouseReleaseEvent;
00220 QGuardedPtr<QObject> m_objectForMouseReleaseEvent;
00221
00222 friend class InsertWidgetCommand;
00223 friend class PasteWidgetCommand;
00224 friend class DeleteWidgetCommand;
00225 friend class FormIO;
00226 };
00227
00229
00230 class KFORMEDITOR_EXPORT DesignTimeDynamicChildWidgetHandler
00231 {
00232 public:
00233 DesignTimeDynamicChildWidgetHandler();
00234 ~DesignTimeDynamicChildWidgetHandler();
00235
00236 protected:
00237 void childWidgetAdded(QWidget* w);
00238 void assignItem(ObjectTreeItem* item) { m_item = item; }
00239
00240 private:
00241 ObjectTreeItem* m_item;
00242 friend class InsertWidgetCommand;
00243 friend class FormIO;
00244 };
00245
00246 }
00247
00248 #endif
|