kexi

container.h
1/* This file is part of the KDE project
2 Copyright (C) 2003 Lucijan Busch <lucijan@gmx.at>
3 Copyright (C) 2004 Cedric Pasteur <cedric.pasteur@free.fr>
4
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.
9
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.
14
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.
19*/
20
21#ifndef FORMEDITORCONTAINER_H
22#define FORMEDITORCONTAINER_H
23
24#include <tqobject.h>
25#include <tqguardedptr.h>
26#include <tqptrlist.h>
27#include <tqwidget.h>
28
29#include "utils.h"
30
31class TQEvent;
32class TQWidget;
33class TQLayout;
34
35namespace KFormDesigner {
36
37class Container;
38class WidgetLibrary;
39class ObjectTreeItem;
40class Form;
41
47class KFORMEDITOR_EXPORT EventEater : public TQObject
48{
49 TQ_OBJECT
50
51
52 public:
56 EventEater(TQWidget *widget, TQObject *container);
58
60 void setContainer(TQObject *container) { m_container = container; }
61 bool eventFilter(TQObject *o, TQEvent *ev);
62
63 private:
64 TQGuardedPtr<TQWidget> m_widget;
65 TQGuardedPtr<TQObject> m_container;
66};
67
73class KFORMEDITOR_EXPORT Container : public TQObject
74{
75 TQ_OBJECT
76
77
78 public:
79 enum LayoutType { NoLayout=0, HBox, VBox, Grid, HFlow, VFlow, /* special types */ HSplitter, VSplitter };
80
84 Container(Container *toplevel, TQWidget *container, TQObject *parent=0, const char *name=0);
85 virtual ~Container();
86
89
91 Form* form() const { return m_form; }
92
94 TQWidget* widget() const { return m_container; }
95
97 ObjectTreeItem* objectTree() const { return m_tree; }
98
100 void setForm(Form *form);
101
104 void setObjectTree(ObjectTreeItem *t) { m_tree = t; }
105
107 TQLayout* layout() const { return m_layout; }
108
110 LayoutType layoutType() const { return m_layType; }
111
113 int layoutMargin() { return m_margin; }
114
116 int layoutSpacing() { return m_spacing; }
117
121 void setLayout(LayoutType type);
122
124 void setLayoutSpacing(int spacing) { m_spacing = spacing;}
125
127 void setLayoutMargin(int margin) { m_margin = margin;}
128
130 static TQString layoutTypeToString(int type);
131
133 static LayoutType stringToLayoutType(const TQString &name);
134
137 void stopInlineEditing() { m_state = DoingNothing; }
138
143 virtual bool eventFilter(TQObject *o, TQEvent *e);
144
145 public slots:
153 void setSelectedWidget(TQWidget *selected, bool add, bool dontRaise=false,
154 bool moreWillBeSelected = false);
155
158 void unSelectWidget(TQWidget *w);
159
162 void deleteWidget(TQWidget *w);
163
166 void reloadLayout();
167
168 protected slots:
170 void widgetDeleted();
171
172 protected:
176 void createBoxLayout(WidgetList *list);
177
179 void createFlowLayout();
180
183 void createGridLayout(bool testOnly=false);
184
185 void drawConnection(TQMouseEvent *mev);
186 void drawSelectionRect(TQMouseEvent *mev);
187 void drawInsertRect(TQMouseEvent *mev, TQObject *s);
188 void drawCopiedWidgetRect(TQMouseEvent *mev);
189
190 void moveSelectedWidgetsBy(int realdx, int realdy, TQMouseEvent *mev=0);
191
192 private:
193 bool handleMouseReleaseEvent(TQObject *s, TQMouseEvent *mev);
194
195 // the watched container and it's toplevel one...
196 TQGuardedPtr<TQWidget> m_container;
197 TQGuardedPtr<Container> m_toplevel;
198
199 int m_state;
200 enum { DoingNothing = 100, DrawingSelectionRect, CopyingWidget,
201 MovingWidget, InlineEditing };
202
203 // Layout
204 TQLayout *m_layout;
205 LayoutType m_layType;
206 int m_margin, m_spacing;
207
208 // moving etc.
209 TQPoint m_grab;
210 //TQPoint m_initialPos;
211 TQGuardedPtr<TQWidget> m_moving;
212 //TQRect m_copyRect;
213
214 //inserting
215 TQPoint m_insertBegin;
216 TQRect m_insertRect;
217 ObjectTreeItem *m_tree;
218
219 TQGuardedPtr<Form> m_form;
220 bool m_mousePressEventReceived;
221 TQMouseEvent m_mouseReleaseEvent;
222 TQGuardedPtr<TQObject> m_objectForMouseReleaseEvent;
223
224 friend class InsertWidgetCommand;
225 friend class PasteWidgetCommand;
226 friend class DeleteWidgetCommand;
227 friend class FormIO;
228};
229
231
232class KFORMEDITOR_EXPORT DesignTimeDynamicChildWidgetHandler
233{
234 public:
235 DesignTimeDynamicChildWidgetHandler();
236 ~DesignTimeDynamicChildWidgetHandler();
237
238 protected:
239 void childWidgetAdded(TQWidget* w);
240 void assignItem(ObjectTreeItem* item) { m_item = item; }
241
242 private:
243 ObjectTreeItem* m_item;
244 friend class InsertWidgetCommand;
245 friend class FormIO;
246};
247
248}
249
250#endif
This class makes a container out of any TQWidget.
Definition container.h:74
void setLayoutMargin(int margin)
Sets the margin of this Container.
Definition container.h:127
TQWidget * widget() const
Definition container.h:94
void setLayoutSpacing(int spacing)
Sets the spacing of this Container.
Definition container.h:124
ObjectTreeItem * objectTree() const
Definition container.h:97
LayoutType layoutType() const
Definition container.h:110
Container(Container *toplevel, TQWidget *container, TQObject *parent=0, const char *name=0)
Creates a Container from the widget container, which have toplevel as parent Container.
Definition container.cpp:91
TQLayout * layout() const
Definition container.h:107
void setObjectTree(ObjectTreeItem *t)
Definition container.h:104
Form * form() const
Definition container.h:91
void setContainer(TQObject *container)
Sets the object which will receive the events.
Definition container.h:60
EventEater(TQWidget *widget, TQObject *container)
Definition container.cpp:47
A simple class representing a form.
Definition form.h:136
An item representing a widget Holds the properties of a widget (classname, name, parent,...
Definition objecttree.h:59
This class searches for factories and provides TDEActions for widget creation.
TQPtrList< TQWidget > WidgetList
A list of widget pointers.