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
00155 void unSelectWidget(QWidget *w);
00156
00159 void deleteWidget(QWidget *w);
00160
00163 void reloadLayout();
00164
00165 protected slots:
00167 void widgetDeleted();
00168
00169 protected:
00173 void createBoxLayout(WidgetList *list);
00174
00176 void createFlowLayout();
00177
00180 void createGridLayout(bool testOnly=false);
00181
00182 void drawConnection(QMouseEvent *mev);
00183 void drawSelectionRect(QMouseEvent *mev);
00184 void drawInsertRect(QMouseEvent *mev, QObject *s);
00185 void drawCopiedWidgetRect(QMouseEvent *mev);
00186
00187 void moveSelectedWidgetsBy(int realdx, int realdy, QMouseEvent *mev=0);
00188
00189 private:
00190 bool handleMouseReleaseEvent(QObject *s, QMouseEvent *mev);
00191
00192
00193 QGuardedPtr<QWidget> m_container;
00194 QGuardedPtr<Container> m_toplevel;
00195
00196 int m_state;
00197 enum { DoingNothing = 100, DrawingSelectionRect, CopyingWidget,
00198 MovingWidget, InlineEditing };
00199
00200
00201 QLayout *m_layout;
00202 LayoutType m_layType;
00203 int m_margin, m_spacing;
00204
00205
00206 QPoint m_grab;
00207
00208 QGuardedPtr<QWidget> m_moving;
00209
00210
00211
00212 QPoint m_insertBegin;
00213 QRect m_insertRect;
00214 ObjectTreeItem *m_tree;
00215
00216 QGuardedPtr<Form> m_form;
00217 bool m_mousePressEventReceived;
00218 QMouseEvent m_mouseReleaseEvent;
00219 QGuardedPtr<QObject> m_objectForMouseReleaseEvent;
00220
00221 friend class InsertWidgetCommand;
00222 friend class PasteWidgetCommand;
00223 friend class DeleteWidgetCommand;
00224 friend class FormIO;
00225 };
00226
00228
00229 class KFORMEDITOR_EXPORT DesignTimeDynamicChildWidgetHandler
00230 {
00231 public:
00232 DesignTimeDynamicChildWidgetHandler();
00233 ~DesignTimeDynamicChildWidgetHandler();
00234
00235 protected:
00236 void childWidgetAdded(QWidget* w);
00237 void assignItem(ObjectTreeItem* item) { m_item = item; }
00238
00239 private:
00240 ObjectTreeItem* m_item;
00241 friend class InsertWidgetCommand;
00242 friend class FormIO;
00243 };
00244
00245 }
00246
00247 #endif
|