1
/****************************************************************************
3
** Copyright (C) 1992-2005 Trolltech AS. All rights reserved.
5
** This file is part of the designer application of the Qt Toolkit.
7
** This file may be distributed under the terms of the Q Public License
8
** as defined by Trolltech AS of Norway and appearing in the file
9
** LICENSE.QPL included in the packaging of this file.
11
** This file may be distributed and/or modified under the terms of the
12
** GNU General Public License version 2 as published by the Free Software
13
** Foundation and appearing in the file LICENSE.GPL included in the
14
** packaging of this file.
16
** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
17
** information about Qt Commercial License Agreements.
18
** See http://www.trolltech.com/qpl/ for QPL licensing information.
19
** See http://www.trolltech.com/gpl/ for GPL licensing information.
21
** Contact info@trolltech.com if any conditions of this licensing are
24
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
25
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
27
****************************************************************************/
32
#include "formeditor_global.h"
33
#include "formeditor.h"
36
#include <QtDesigner/QtDesigner>
39
#include <QtCore/QHash>
40
#include <QtCore/QList>
41
#include <QtCore/QMap>
42
#include <QtCore/QSet>
44
#include <QtGui/QWidget>
45
#include <QtGui/QPixmap>
56
class BreakLayoutCommand;
58
namespace qdesigner_internal {
61
class FormWindowCursor;
62
class WidgetSelection;
63
class WidgetEditorTool;
64
class FormWindowWidgetStack;
65
class FormWindowManager;
66
class FormWindowDnDItem;
68
class QT_FORMEDITOR_EXPORT FormWindow: public QDesignerFormWindowInterface
79
FormWindow(FormEditor *core, QWidget *parent = 0, Qt::WindowFlags flags = 0);
80
virtual ~FormWindow();
82
virtual QDesignerFormEditorInterface *core() const;
84
virtual QDesignerFormWindowCursorInterface *cursor() const;
86
virtual int toolCount() const;
87
virtual int currentTool() const;
88
virtual void setCurrentTool(int index);
89
virtual QDesignerFormWindowToolInterface *tool(int index) const;
90
virtual void registerTool(QDesignerFormWindowToolInterface *tool);
92
virtual bool hasFeature(Feature f) const;
93
virtual Feature features() const;
94
virtual void setFeatures(Feature f);
96
virtual QString author() const;
97
virtual void setAuthor(const QString &author);
99
virtual QString comment() const;
100
virtual void setComment(const QString &comment);
102
virtual void layoutDefault(int *margin, int *spacing);
103
virtual void setLayoutDefault(int margin, int spacing);
105
virtual void layoutFunction(QString *margin, QString *spacing);
106
virtual void setLayoutFunction(const QString &margin, const QString &spacing);
108
virtual QString pixmapFunction() const;
109
virtual void setPixmapFunction(const QString &pixmapFunction);
111
virtual QString exportMacro() const;
112
virtual void setExportMacro(const QString &exportMacro);
114
virtual QStringList includeHints() const;
115
virtual void setIncludeHints(const QStringList &includeHints);
117
virtual QString fileName() const;
118
virtual void setFileName(const QString &fileName);
120
virtual QString contents() const;
121
virtual void setContents(const QString &contents);
122
virtual void setContents(QIODevice *dev);
124
virtual QDir absoluteDir() const;
126
virtual QPoint grid() const { return m_grid; }
127
virtual void setGrid(const QPoint &grid) { m_grid = grid; }
129
virtual void simplifySelection(QList<QWidget*> *sel) const;
131
virtual void ensureUniqueObjectName(QObject *object);
133
virtual QWidget *mainContainer() const;
134
void setMainContainer(QWidget *mainContainer);
135
bool isMainContainer(const QWidget *w) const;
137
QWidget *currentWidget() const;
138
void setCurrentWidget(QWidget *currentWidget);
140
virtual QSize sizeHint() const
141
{ return QSize(400, 300); } /// ### remove me
143
bool hasInsertedChildren(QWidget *w) const;
145
QList<QWidget *> selectedWidgets() const;
146
void clearSelection(bool changePropertyDisplay=true);
147
bool isWidgetSelected(QWidget *w) const;
148
void selectWidget(QWidget *w, bool select=true);
150
void selectWidgets();
151
void repaintSelection();
152
void repaintSelection(QWidget *w);
153
void updateSelection(QWidget *w);
154
void updateChildSelections(QWidget *w);
155
void raiseChildSelections(QWidget *w);
156
void raiseSelection(QWidget *w);
157
void hideSelection(QWidget *w);
159
inline QList<QWidget *> widgets() const { return m_widgets; }
160
inline int widgetCount() const { return m_widgets.count(); }
161
inline QWidget *widgetAt(int index) const { return m_widgets.at(index); }
163
QList<QWidget *> widgets(QWidget *widget) const;
165
QWidget *createWidget(DomUI *ui, const QRect &rect, QWidget *target);
166
void deleteWidgets(const QList<QWidget*> &widget_list);
168
bool isManaged(QWidget *w) const;
170
void manageWidget(QWidget *w);
171
void unmanageWidget(QWidget *w);
173
inline QtUndoStack *commandHistory() const
174
{ return m_commandHistory; }
176
void beginCommand(const QString &description);
179
bool blockSelectionChanged(bool blocked);
180
void emitSelectionChanged();
182
bool unify(QObject *w, QString &s, bool changeIt);
184
bool isDirty() const;
185
void setDirty(bool dirty);
187
static FormWindow *findFormWindow(QWidget *w);
189
virtual QWidget *containerAt(const QPoint &pos);
190
virtual QWidget *widgetAt(const QPoint &pos);
191
virtual void highlightWidget(QWidget *w, const QPoint &pos,
192
HighlightMode mode = Highlight);
194
void updateOrderIndicators();
196
bool handleEvent(QWidget *widget, QWidget *managedWidget, QEvent *event);
198
QStringList resourceFiles() const;
199
void addResourceFile(const QString &path);
200
void removeResourceFile(const QString &path);
202
void resizeWidget(QWidget *widget, const QRect &geometry);
204
void dropWidgets(QList<QDesignerDnDItemInterface*> &item_list, QWidget *target,
205
const QPoint &global_mouse_pos);
208
void showContextMenu(QWidget *w, const QPoint &pos);
211
void deleteWidgets();
219
void layoutHorizontal();
220
void layoutVertical();
222
void layoutHorizontalSplit();
223
void layoutVerticalSplit();
224
void layoutHorizontalContainer(QWidget *w);
225
void layoutVerticalContainer(QWidget *w);
226
void layoutGridContainer(QWidget *w);
227
void breakLayout(QWidget *w);
233
virtual QMenu *createPopupMenu(QWidget *w);
234
virtual void resizeEvent(QResizeEvent *e);
236
void insertWidget(QWidget *w, const QRect &rect, QWidget *target);
239
void selectionChangedTimerDone();
241
void checkSelection();
242
void checkSelectionNow();
246
void initializeCoreTools();
248
QPoint gridPoint(const QPoint &p) const;
250
enum RectType { Insert, Rubber };
252
void startRectDraw(const QPoint &global, QWidget *, RectType t);
253
void continueRectDraw(const QPoint &global, QWidget *, RectType t);
256
QWidget *containerAt(const QPoint &pos, QWidget *notParentOf);
258
void checkPreviewGeometry(QRect &r);
260
void finishContextMenu(QWidget *w, QWidget *menuParent, QContextMenuEvent *e);
262
bool handleContextMenu(QWidget *widget, QWidget *managedWidget, QContextMenuEvent *e);
263
bool handleMouseButtonDblClickEvent(QWidget *widget, QWidget *managedWidget, QMouseEvent *e);
264
bool handleMousePressEvent(QWidget *widget, QWidget *managedWidget, QMouseEvent *e);
265
bool handleMouseMoveEvent(QWidget *widget, QWidget *managedWidget, QMouseEvent *e);
266
bool handleMouseReleaseEvent(QWidget *widget, QWidget *managedWidget, QMouseEvent *e);
267
bool handleKeyPressEvent(QWidget *widget, QWidget *managedWidget, QKeyEvent *e);
268
bool handleKeyReleaseEvent(QWidget *widget, QWidget *managedWidget, QKeyEvent *e);
270
bool isCentralWidget(QWidget *w) const;
271
QWidget *designerWidget(QWidget *w) const;
273
BreakLayoutCommand *breakLayoutCommand(QWidget *w);
275
void setCursorToAll(const QCursor &c, QWidget *start);
277
QPoint mapToForm(const QWidget *w, const QPoint &pos) const;
278
bool canBeBuddy(QWidget *w) const;
280
QWidget *findContainer(QWidget *w, bool excludeLayout) const;
281
QWidget *findTargetContainer(QWidget *widget) const;
283
static int widgetDepth(QWidget *w);
284
static bool isChildOf(QWidget *c, const QWidget *p);
288
void updateWidgets();
289
void bfs(QWidget *widget);
294
FormWindowCursor *m_cursor;
295
QWidget *m_mainContainer;
296
QWidget *m_currentWidget;
299
uint m_blockSelectionChanged: 1;
301
uint oldRectValid: 1;
302
uint hadOwnPalette: 1;
308
QList<QWidget*> m_widgets;
309
QSet<QWidget*> m_insertedWidgets;
311
QList<WidgetSelection *> selections;
312
QHash<QWidget *, WidgetSelection *> usedSelections;
320
QWidget *startWidget;
323
QWidget *targetContainer;
324
QPalette restorePalette;
326
QtUndoStack *m_commandHistory;
330
QList<QWidget*> orderedWidgets;
331
QList<QWidget*> stackedWidgets;
333
QMap<QWidget*, QPalette> palettesBeforeHighlight;
335
QRubberBand *m_rubberBand;
337
QTimer *m_selectionChangedTimer;
338
QTimer *m_checkSelectionTimer;
339
QTimer *m_geometryChangedTimer;
344
FormWindowWidgetStack *m_widgetStack;
345
WidgetEditorTool *m_widgetEditor;
347
QStringList m_resourceFiles;
351
QString m_pixmapFunction;
352
int m_defaultMargin, m_defaultSpacing;
353
QString m_marginFunction, m_spacingFunction;
354
QString m_exportMacro;
355
QStringList m_includeHints;
358
// friend class FormWindowManager;
359
friend class WidgetHandle;
360
friend class WidgetSelection;
361
friend class QDesignerWidget;
362
friend class WidgetEditorTool;
365
} // namespace qdesigner_internal
367
#endif // FORMWINDOW_H