~oif-team/ubuntu/natty/qt4-x11/xi2.1

« back to all changes in this revision

Viewing changes to tools/designer/src/components/formeditor/formwindow.h

  • Committer: Bazaar Package Importer
  • Author(s): Adam Conrad
  • Date: 2005-08-24 04:09:09 UTC
  • Revision ID: james.westby@ubuntu.com-20050824040909-xmxe9jfr4a0w5671
Tags: upstream-4.0.0
ImportĀ upstreamĀ versionĀ 4.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/****************************************************************************
 
2
**
 
3
** Copyright (C) 1992-2005 Trolltech AS. All rights reserved.
 
4
**
 
5
** This file is part of the designer application of the Qt Toolkit.
 
6
**
 
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.
 
10
**
 
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.
 
15
**
 
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.
 
20
**
 
21
** Contact info@trolltech.com if any conditions of this licensing are
 
22
** not clear to you.
 
23
**
 
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.
 
26
**
 
27
****************************************************************************/
 
28
 
 
29
#ifndef FORMWINDOW_H
 
30
#define FORMWINDOW_H
 
31
 
 
32
#include "formeditor_global.h"
 
33
#include "formeditor.h"
 
34
 
 
35
// sdk
 
36
#include <QtDesigner/QtDesigner>
 
37
 
 
38
// Qt
 
39
#include <QtCore/QHash>
 
40
#include <QtCore/QList>
 
41
#include <QtCore/QMap>
 
42
#include <QtCore/QSet>
 
43
 
 
44
#include <QtGui/QWidget>
 
45
#include <QtGui/QPixmap>
 
46
 
 
47
class DomConnections;
 
48
class Connection;
 
49
 
 
50
class QLabel;
 
51
class QTimer;
 
52
class QAction;
 
53
class QMenu;
 
54
class QtUndoStack;
 
55
class QRubberBand;
 
56
class BreakLayoutCommand;
 
57
 
 
58
namespace qdesigner_internal {
 
59
 
 
60
class FormEditor;
 
61
class FormWindowCursor;
 
62
class WidgetSelection;
 
63
class WidgetEditorTool;
 
64
class FormWindowWidgetStack;
 
65
class FormWindowManager;
 
66
class FormWindowDnDItem;
 
67
 
 
68
class QT_FORMEDITOR_EXPORT FormWindow: public QDesignerFormWindowInterface
 
69
{
 
70
    Q_OBJECT
 
71
public:
 
72
    enum HighlightMode
 
73
    {
 
74
        Restore,
 
75
        Highlight
 
76
    };
 
77
 
 
78
public:
 
79
    FormWindow(FormEditor *core, QWidget *parent = 0, Qt::WindowFlags flags = 0);
 
80
    virtual ~FormWindow();
 
81
 
 
82
    virtual QDesignerFormEditorInterface *core() const;
 
83
 
 
84
    virtual QDesignerFormWindowCursorInterface *cursor() const;
 
85
 
 
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);
 
91
 
 
92
    virtual bool hasFeature(Feature f) const;
 
93
    virtual Feature features() const;
 
94
    virtual void setFeatures(Feature f);
 
95
 
 
96
    virtual QString author() const;
 
97
    virtual void setAuthor(const QString &author);
 
98
 
 
99
    virtual QString comment() const;
 
100
    virtual void setComment(const QString &comment);
 
101
 
 
102
    virtual void layoutDefault(int *margin, int *spacing);
 
103
    virtual void setLayoutDefault(int margin, int spacing);
 
104
 
 
105
    virtual void layoutFunction(QString *margin, QString *spacing);
 
106
    virtual void setLayoutFunction(const QString &margin, const QString &spacing);
 
107
 
 
108
    virtual QString pixmapFunction() const;
 
109
    virtual void setPixmapFunction(const QString &pixmapFunction);
 
110
 
 
111
    virtual QString exportMacro() const;
 
112
    virtual void setExportMacro(const QString &exportMacro);
 
113
 
 
114
    virtual QStringList includeHints() const;
 
115
    virtual void setIncludeHints(const QStringList &includeHints);
 
116
 
 
117
    virtual QString fileName() const;
 
118
    virtual void setFileName(const QString &fileName);
 
119
 
 
120
    virtual QString contents() const;
 
121
    virtual void setContents(const QString &contents);
 
122
    virtual void setContents(QIODevice *dev);
 
123
 
 
124
    virtual QDir absoluteDir() const;
 
125
 
 
126
    virtual QPoint grid() const { return m_grid; }
 
127
    virtual void setGrid(const QPoint &grid) { m_grid = grid; }
 
128
 
 
129
    virtual void simplifySelection(QList<QWidget*> *sel) const;
 
130
 
 
131
    virtual void ensureUniqueObjectName(QObject *object);
 
132
 
 
133
    virtual QWidget *mainContainer() const;
 
134
    void setMainContainer(QWidget *mainContainer);
 
135
    bool isMainContainer(const QWidget *w) const;
 
136
 
 
137
    QWidget *currentWidget() const;
 
138
    void setCurrentWidget(QWidget *currentWidget);
 
139
 
 
140
    virtual QSize sizeHint() const
 
141
    { return QSize(400, 300); }  /// ### remove me
 
142
 
 
143
    bool hasInsertedChildren(QWidget *w) const;
 
144
 
 
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);
 
149
 
 
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);
 
158
 
 
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); }
 
162
 
 
163
    QList<QWidget *> widgets(QWidget *widget) const;
 
164
 
 
165
    QWidget *createWidget(DomUI *ui, const QRect &rect, QWidget *target);
 
166
    void deleteWidgets(const QList<QWidget*> &widget_list);
 
167
 
 
168
    bool isManaged(QWidget *w) const;
 
169
 
 
170
    void manageWidget(QWidget *w);
 
171
    void unmanageWidget(QWidget *w);
 
172
 
 
173
    inline QtUndoStack *commandHistory() const
 
174
    { return m_commandHistory; }
 
175
 
 
176
    void beginCommand(const QString &description);
 
177
    void endCommand();
 
178
 
 
179
    bool blockSelectionChanged(bool blocked);
 
180
    void emitSelectionChanged();
 
181
 
 
182
    bool unify(QObject *w, QString &s, bool changeIt);
 
183
 
 
184
    bool isDirty() const;
 
185
    void setDirty(bool dirty);
 
186
 
 
187
    static FormWindow *findFormWindow(QWidget *w);
 
188
 
 
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);
 
193
 
 
194
    void updateOrderIndicators();
 
195
 
 
196
    bool handleEvent(QWidget *widget, QWidget *managedWidget, QEvent *event);
 
197
 
 
198
    QStringList resourceFiles() const;
 
199
    void addResourceFile(const QString &path);
 
200
    void removeResourceFile(const QString &path);
 
201
 
 
202
    void resizeWidget(QWidget *widget, const QRect &geometry);
 
203
 
 
204
    void dropWidgets(QList<QDesignerDnDItemInterface*> &item_list, QWidget *target,
 
205
                        const QPoint &global_mouse_pos);
 
206
 
 
207
signals:
 
208
    void showContextMenu(QWidget *w, const QPoint &pos);
 
209
 
 
210
public slots:
 
211
    void deleteWidgets();
 
212
    void raiseWidgets();
 
213
    void lowerWidgets();
 
214
    void copy();
 
215
    void cut();
 
216
    void paste();
 
217
    void selectAll();
 
218
 
 
219
    void layoutHorizontal();
 
220
    void layoutVertical();
 
221
    void layoutGrid();
 
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);
 
228
 
 
229
    void breakLayout();
 
230
    void editContents();
 
231
 
 
232
protected:
 
233
    virtual QMenu *createPopupMenu(QWidget *w);
 
234
    virtual void resizeEvent(QResizeEvent *e);
 
235
 
 
236
    void insertWidget(QWidget *w, const QRect &rect, QWidget *target);
 
237
 
 
238
private slots:
 
239
    void selectionChangedTimerDone();
 
240
    void updateDirty();
 
241
    void checkSelection();
 
242
    void checkSelectionNow();
 
243
 
 
244
private:
 
245
    void init();
 
246
    void initializeCoreTools();
 
247
 
 
248
    QPoint gridPoint(const QPoint &p) const;
 
249
 
 
250
    enum RectType { Insert, Rubber };
 
251
 
 
252
    void startRectDraw(const QPoint &global, QWidget *, RectType t);
 
253
    void continueRectDraw(const QPoint &global, QWidget *, RectType t);
 
254
    void endRectDraw();
 
255
 
 
256
    QWidget *containerAt(const QPoint &pos, QWidget *notParentOf);
 
257
 
 
258
    void checkPreviewGeometry(QRect &r);
 
259
 
 
260
    void finishContextMenu(QWidget *w, QWidget *menuParent, QContextMenuEvent *e);
 
261
 
 
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);
 
269
 
 
270
    bool isCentralWidget(QWidget *w) const;
 
271
    QWidget *designerWidget(QWidget *w) const;
 
272
 
 
273
    BreakLayoutCommand *breakLayoutCommand(QWidget *w);
 
274
 
 
275
    void setCursorToAll(const QCursor &c, QWidget *start);
 
276
 
 
277
    QPoint mapToForm(const QWidget *w, const QPoint &pos) const;
 
278
    bool canBeBuddy(QWidget *w) const;
 
279
 
 
280
    QWidget *findContainer(QWidget *w, bool excludeLayout) const;
 
281
    QWidget *findTargetContainer(QWidget *widget) const;
 
282
 
 
283
    static int widgetDepth(QWidget *w);
 
284
    static bool isChildOf(QWidget *c, const QWidget *p);
 
285
 
 
286
    void editWidgets();
 
287
 
 
288
    void updateWidgets();
 
289
    void bfs(QWidget *widget);
 
290
 
 
291
private:
 
292
    Feature m_feature;
 
293
    FormEditor *m_core;
 
294
    FormWindowCursor *m_cursor;
 
295
    QWidget *m_mainContainer;
 
296
    QWidget *m_currentWidget;
 
297
    QPoint m_grid;
 
298
 
 
299
    uint m_blockSelectionChanged: 1;
 
300
    uint drawRubber: 1;
 
301
    uint oldRectValid: 1;
 
302
    uint hadOwnPalette: 1;
 
303
    uint pad[28];
 
304
 
 
305
    QPoint rectAnchor;
 
306
    QRect currRect;
 
307
 
 
308
    QList<QWidget*> m_widgets;
 
309
    QSet<QWidget*> m_insertedWidgets;
 
310
 
 
311
    QList<WidgetSelection *> selections;
 
312
    QHash<QWidget *, WidgetSelection *> usedSelections;
 
313
 
 
314
    QPoint startPos;
 
315
    QPoint currentPos;
 
316
 
 
317
    QRect widgetGeom;
 
318
    QPoint oldPressPos;
 
319
    QPoint origPressPos;
 
320
    QWidget *startWidget;
 
321
    QWidget *endWidget;
 
322
 
 
323
    QWidget *targetContainer;
 
324
    QPalette restorePalette;
 
325
 
 
326
    QtUndoStack *m_commandHistory;
 
327
 
 
328
    QString m_fileName;
 
329
 
 
330
    QList<QWidget*> orderedWidgets;
 
331
    QList<QWidget*> stackedWidgets;
 
332
 
 
333
    QMap<QWidget*, QPalette> palettesBeforeHighlight;
 
334
 
 
335
    QRubberBand *m_rubberBand;
 
336
 
 
337
    QTimer *m_selectionChangedTimer;
 
338
    QTimer *m_checkSelectionTimer;
 
339
    QTimer *m_geometryChangedTimer;
 
340
 
 
341
    int m_dirty;
 
342
    int m_lastIndex;
 
343
 
 
344
    FormWindowWidgetStack *m_widgetStack;
 
345
    WidgetEditorTool *m_widgetEditor;
 
346
 
 
347
    QStringList m_resourceFiles;
 
348
 
 
349
    QString m_comment;
 
350
    QString m_author;
 
351
    QString m_pixmapFunction;
 
352
    int m_defaultMargin, m_defaultSpacing;
 
353
    QString m_marginFunction, m_spacingFunction;
 
354
    QString m_exportMacro;
 
355
    QStringList m_includeHints;
 
356
 
 
357
private:
 
358
//    friend class FormWindowManager;
 
359
    friend class WidgetHandle;
 
360
    friend class WidgetSelection;
 
361
    friend class QDesignerWidget;
 
362
    friend class WidgetEditorTool;
 
363
};
 
364
 
 
365
}  // namespace qdesigner_internal
 
366
 
 
367
#endif // FORMWINDOW_H