1 | /****************************************************************************
|
---|
2 | **
|
---|
3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
---|
4 | ** Contact: Qt Software Information ([email protected])
|
---|
5 | **
|
---|
6 | ** This file is part of the QtGui module of the Qt Toolkit.
|
---|
7 | **
|
---|
8 | ** $QT_BEGIN_LICENSE:LGPL$
|
---|
9 | ** Commercial Usage
|
---|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
---|
11 | ** accordance with the Qt Commercial License Agreement provided with the
|
---|
12 | ** Software or, alternatively, in accordance with the terms contained in
|
---|
13 | ** a written agreement between you and Nokia.
|
---|
14 | **
|
---|
15 | ** GNU Lesser General Public License Usage
|
---|
16 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
---|
17 | ** General Public License version 2.1 as published by the Free Software
|
---|
18 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
---|
19 | ** packaging of this file. Please review the following information to
|
---|
20 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
---|
21 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
---|
22 | **
|
---|
23 | ** In addition, as a special exception, Nokia gives you certain
|
---|
24 | ** additional rights. These rights are described in the Nokia Qt LGPL
|
---|
25 | ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
|
---|
26 | ** package.
|
---|
27 | **
|
---|
28 | ** GNU General Public License Usage
|
---|
29 | ** Alternatively, this file may be used under the terms of the GNU
|
---|
30 | ** General Public License version 3.0 as published by the Free Software
|
---|
31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
---|
32 | ** packaging of this file. Please review the following information to
|
---|
33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
---|
34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
---|
35 | **
|
---|
36 | ** If you are unsure which license is appropriate for your use, please
|
---|
37 | ** contact the sales department at [email protected].
|
---|
38 | ** $QT_END_LICENSE$
|
---|
39 | **
|
---|
40 | ****************************************************************************/
|
---|
41 |
|
---|
42 | #ifndef QDYNAMICMAINWINDOWLAYOUT_P_H
|
---|
43 | #define QDYNAMICMAINWINDOWLAYOUT_P_H
|
---|
44 |
|
---|
45 | //
|
---|
46 | // W A R N I N G
|
---|
47 | // -------------
|
---|
48 | //
|
---|
49 | // This file is not part of the Qt API. It exists purely as an
|
---|
50 | // implementation detail. This header file may change from version to
|
---|
51 | // version without notice, or even be removed.
|
---|
52 | //
|
---|
53 | // We mean it.
|
---|
54 | //
|
---|
55 |
|
---|
56 | #include "qmainwindow.h"
|
---|
57 |
|
---|
58 | #ifndef QT_NO_MAINWINDOW
|
---|
59 |
|
---|
60 | #include "QtGui/qlayout.h"
|
---|
61 | #include "QtGui/qtabbar.h"
|
---|
62 | #include "QtCore/qvector.h"
|
---|
63 | #include "QtCore/qset.h"
|
---|
64 | #include "private/qlayoutengine_p.h"
|
---|
65 |
|
---|
66 | #include "qdockarealayout_p.h"
|
---|
67 | #include "qtoolbararealayout_p.h"
|
---|
68 |
|
---|
69 | //#define Q_DEBUG_MAINWINDOW_LAYOUT
|
---|
70 |
|
---|
71 | #ifdef Q_DEBUG_MAINWINDOW_LAYOUT
|
---|
72 | QT_BEGIN_NAMESPACE
|
---|
73 | class QTextStream;
|
---|
74 | Q_GUI_EXPORT void qt_dumpLayout(QTextStream &qout, QMainWindow *window);
|
---|
75 | QT_END_NAMESPACE
|
---|
76 | #endif // Q_DEBUG_MAINWINDOW_LAYOUT
|
---|
77 |
|
---|
78 | #ifdef Q_WS_MAC
|
---|
79 | // Forward defs to make avoid including Carbon.h (faster compile you know ;).
|
---|
80 | struct OpaqueHIObjectRef;
|
---|
81 | typedef struct OpaqueHIObjectRef* HIObjectRef;
|
---|
82 | typedef HIObjectRef HIToolbarItemRef;
|
---|
83 | typedef const void * CFTypeRef;
|
---|
84 | typedef const struct __CFString * CFStringRef;
|
---|
85 |
|
---|
86 | #endif
|
---|
87 |
|
---|
88 | QT_BEGIN_NAMESPACE
|
---|
89 |
|
---|
90 | class QToolBar;
|
---|
91 | class QWidgetAnimator;
|
---|
92 | class QRubberBand;
|
---|
93 |
|
---|
94 | /* This data structure represents the state of all the tool-bars and dock-widgets. It's value based
|
---|
95 | so it can be easilly copied into a temporary variable. All operations are performed without moving
|
---|
96 | any widgets. Only when we are sure we have the desired state, we call apply(), which moves the
|
---|
97 | widgets.
|
---|
98 | */
|
---|
99 |
|
---|
100 | class QMainWindowLayoutState
|
---|
101 | {
|
---|
102 | public:
|
---|
103 | QRect rect;
|
---|
104 | QMainWindow *mainWindow;
|
---|
105 |
|
---|
106 | QMainWindowLayoutState(QMainWindow *win);
|
---|
107 |
|
---|
108 | #ifndef QT_NO_TOOLBAR
|
---|
109 | QToolBarAreaLayout toolBarAreaLayout;
|
---|
110 | #endif
|
---|
111 |
|
---|
112 | #ifndef QT_NO_DOCKWIDGET
|
---|
113 | QDockAreaLayout dockAreaLayout;
|
---|
114 | #else
|
---|
115 | QLayoutItem *centralWidgetItem;
|
---|
116 | QRect centralWidgetRect;
|
---|
117 | #endif
|
---|
118 |
|
---|
119 | void apply(bool animated);
|
---|
120 | void deleteAllLayoutItems();
|
---|
121 | void deleteCentralWidgetItem();
|
---|
122 |
|
---|
123 | QSize sizeHint() const;
|
---|
124 | QSize minimumSize() const;
|
---|
125 | void fitLayout();
|
---|
126 |
|
---|
127 | QLayoutItem *itemAt(int index, int *x) const;
|
---|
128 | QLayoutItem *takeAt(int index, int *x);
|
---|
129 | QList<int> indexOf(QWidget *widget) const;
|
---|
130 | QLayoutItem *item(QList<int> path);
|
---|
131 | QRect itemRect(QList<int> path) const;
|
---|
132 | QRect gapRect(QList<int> path) const; // ### get rid of this, use itemRect() instead
|
---|
133 |
|
---|
134 | bool contains(QWidget *widget) const;
|
---|
135 |
|
---|
136 | void setCentralWidget(QWidget *widget);
|
---|
137 | QWidget *centralWidget() const;
|
---|
138 |
|
---|
139 | QList<int> gapIndex(QWidget *widget, const QPoint &pos) const;
|
---|
140 | bool insertGap(QList<int> path, QLayoutItem *item);
|
---|
141 | void remove(QList<int> path);
|
---|
142 | void remove(QLayoutItem *item);
|
---|
143 | void clear();
|
---|
144 | bool isValid() const;
|
---|
145 |
|
---|
146 | QLayoutItem *plug(QList<int> path);
|
---|
147 | QLayoutItem *unplug(QList<int> path, QMainWindowLayoutState *savedState = 0);
|
---|
148 |
|
---|
149 | void saveState(QDataStream &stream) const;
|
---|
150 | bool checkFormat(QDataStream &stream, bool pre43);
|
---|
151 | bool restoreState(QDataStream &stream, const QMainWindowLayoutState &oldState);
|
---|
152 | };
|
---|
153 |
|
---|
154 | class Q_AUTOTEST_EXPORT QMainWindowLayout : public QLayout
|
---|
155 | {
|
---|
156 | Q_OBJECT
|
---|
157 |
|
---|
158 | public:
|
---|
159 | QMainWindowLayoutState layoutState, savedState;
|
---|
160 |
|
---|
161 | explicit QMainWindowLayout(QMainWindow *mainwindow);
|
---|
162 | ~QMainWindowLayout();
|
---|
163 |
|
---|
164 | QMainWindow::DockOptions dockOptions;
|
---|
165 | void setDockOptions(QMainWindow::DockOptions opts);
|
---|
166 | bool usesHIToolBar(QToolBar *toolbar) const;
|
---|
167 |
|
---|
168 | // status bar
|
---|
169 |
|
---|
170 | QLayoutItem *statusbar;
|
---|
171 |
|
---|
172 | #ifndef QT_NO_STATUSBAR
|
---|
173 | QStatusBar *statusBar() const;
|
---|
174 | void setStatusBar(QStatusBar *sb);
|
---|
175 | #endif
|
---|
176 |
|
---|
177 | // central widget
|
---|
178 |
|
---|
179 | QWidget *centralWidget() const;
|
---|
180 | void setCentralWidget(QWidget *cw);
|
---|
181 |
|
---|
182 | // toolbars
|
---|
183 |
|
---|
184 | #ifndef QT_NO_TOOLBAR
|
---|
185 | void addToolBarBreak(Qt::ToolBarArea area);
|
---|
186 | void insertToolBarBreak(QToolBar *before);
|
---|
187 | void removeToolBarBreak(QToolBar *before);
|
---|
188 |
|
---|
189 | void addToolBar(Qt::ToolBarArea area, QToolBar *toolbar, bool needAddChildWidget = true);
|
---|
190 | void insertToolBar(QToolBar *before, QToolBar *toolbar);
|
---|
191 | Qt::ToolBarArea toolBarArea(QToolBar *toolbar) const;
|
---|
192 | bool toolBarBreak(QToolBar *toolBar) const;
|
---|
193 | void getStyleOptionInfo(QStyleOptionToolBar *option, QToolBar *toolBar) const;
|
---|
194 | void removeToolBar(QToolBar *toolbar);
|
---|
195 | void toggleToolBarsVisible();
|
---|
196 | void moveToolBar(QToolBar *toolbar, int pos);
|
---|
197 | #endif
|
---|
198 |
|
---|
199 | // dock widgets
|
---|
200 |
|
---|
201 | #ifndef QT_NO_DOCKWIDGET
|
---|
202 | void setCorner(Qt::Corner corner, Qt::DockWidgetArea area);
|
---|
203 | Qt::DockWidgetArea corner(Qt::Corner corner) const;
|
---|
204 | void addDockWidget(Qt::DockWidgetArea area,
|
---|
205 | QDockWidget *dockwidget,
|
---|
206 | Qt::Orientation orientation);
|
---|
207 | void splitDockWidget(QDockWidget *after,
|
---|
208 | QDockWidget *dockwidget,
|
---|
209 | Qt::Orientation orientation);
|
---|
210 | void tabifyDockWidget(QDockWidget *first, QDockWidget *second);
|
---|
211 | Qt::DockWidgetArea dockWidgetArea(QDockWidget *dockwidget) const;
|
---|
212 | void raise(QDockWidget *widget);
|
---|
213 | void setVerticalTabsEnabled(bool enabled);
|
---|
214 | bool restoreDockWidget(QDockWidget *dockwidget);
|
---|
215 |
|
---|
216 | #ifndef QT_NO_TABBAR
|
---|
217 | bool _documentMode;
|
---|
218 | bool documentMode() const;
|
---|
219 | void setDocumentMode(bool enabled);
|
---|
220 |
|
---|
221 | QTabBar *getTabBar();
|
---|
222 | QSet<QTabBar*> usedTabBars;
|
---|
223 | QList<QTabBar*> unusedTabBars;
|
---|
224 | bool verticalTabsEnabled;
|
---|
225 |
|
---|
226 | QWidget *getSeparatorWidget();
|
---|
227 | QSet<QWidget*> usedSeparatorWidgets;
|
---|
228 | QList<QWidget*> unusedSeparatorWidgets;
|
---|
229 | int sep; // separator extent
|
---|
230 |
|
---|
231 | #ifndef QT_NO_TABWIDGET
|
---|
232 | QTabWidget::TabPosition tabPositions[4];
|
---|
233 | QTabWidget::TabShape _tabShape;
|
---|
234 |
|
---|
235 | QTabWidget::TabShape tabShape() const;
|
---|
236 | void setTabShape(QTabWidget::TabShape tabShape);
|
---|
237 | QTabWidget::TabPosition tabPosition(Qt::DockWidgetArea area) const;
|
---|
238 | void setTabPosition(Qt::DockWidgetAreas areas, QTabWidget::TabPosition tabPosition);
|
---|
239 | #endif // QT_NO_TABWIDGET
|
---|
240 | #endif // QT_NO_TABBAR
|
---|
241 |
|
---|
242 | // separators
|
---|
243 |
|
---|
244 | QList<int> movingSeparator;
|
---|
245 | QPoint movingSeparatorOrigin, movingSeparatorPos;
|
---|
246 | QTimer *separatorMoveTimer;
|
---|
247 | QVector<QLayoutStruct> separatorMoveCache;
|
---|
248 |
|
---|
249 | bool startSeparatorMove(const QPoint &pos);
|
---|
250 | bool separatorMove(const QPoint &pos);
|
---|
251 | bool endSeparatorMove(const QPoint &pos);
|
---|
252 | void keepSize(QDockWidget *w);
|
---|
253 | #endif // QT_NO_DOCKWIDGET
|
---|
254 |
|
---|
255 | // save/restore
|
---|
256 |
|
---|
257 | enum { // sentinel values used to validate state data
|
---|
258 | VersionMarker = 0xff
|
---|
259 | };
|
---|
260 | void saveState(QDataStream &stream) const;
|
---|
261 | bool restoreState(QDataStream &stream);
|
---|
262 |
|
---|
263 | // QLayout interface
|
---|
264 |
|
---|
265 | void addItem(QLayoutItem *item);
|
---|
266 | void setGeometry(const QRect &r);
|
---|
267 | QLayoutItem *itemAt(int index) const;
|
---|
268 | QLayoutItem *takeAt(int index);
|
---|
269 | int count() const;
|
---|
270 |
|
---|
271 | QSize sizeHint() const;
|
---|
272 | QSize minimumSize() const;
|
---|
273 | mutable QSize szHint;
|
---|
274 | mutable QSize minSize;
|
---|
275 | void invalidate();
|
---|
276 |
|
---|
277 | // animations
|
---|
278 |
|
---|
279 | QWidgetAnimator *widgetAnimator;
|
---|
280 | QList<int> currentGapPos;
|
---|
281 | QRect currentGapRect;
|
---|
282 | QWidget *pluggingWidget;
|
---|
283 | #ifndef QT_NO_RUBBERBAND
|
---|
284 | QRubberBand *gapIndicator;
|
---|
285 | #endif
|
---|
286 |
|
---|
287 | QList<int> hover(QLayoutItem *widgetItem, const QPoint &mousePos);
|
---|
288 | bool plug(QLayoutItem *widgetItem);
|
---|
289 | QLayoutItem *unplug(QWidget *widget);
|
---|
290 | void revert(QLayoutItem *widgetItem);
|
---|
291 | void updateGapIndicator();
|
---|
292 | void paintDropIndicator(QPainter *p, QWidget *widget, const QRegion &clip);
|
---|
293 | void applyState(QMainWindowLayoutState &newState, bool animate = true);
|
---|
294 | void restore(bool keepSavedState = false);
|
---|
295 | void updateHIToolBarStatus();
|
---|
296 |
|
---|
297 | private slots:
|
---|
298 | void animationFinished(QWidget *widget);
|
---|
299 | void allAnimationsFinished();
|
---|
300 | #ifndef QT_NO_DOCKWIDGET
|
---|
301 | void doSeparatorMove();
|
---|
302 | #ifndef QT_NO_TABBAR
|
---|
303 | void tabChanged();
|
---|
304 | #endif
|
---|
305 | #endif
|
---|
306 | private:
|
---|
307 | #ifndef QT_NO_TABBAR
|
---|
308 | void updateTabBarShapes();
|
---|
309 | #endif
|
---|
310 | #ifdef Q_WS_MAC
|
---|
311 | # ifndef QT_MAC_USE_COCOA
|
---|
312 | static OSStatus qtmacToolbarDelegate(EventHandlerCallRef, EventRef , void *);
|
---|
313 | static OSStatus qtoolbarInHIToolbarHandler(EventHandlerCallRef inCallRef, EventRef event,
|
---|
314 | void *data);
|
---|
315 | static void qtMacHIToolbarRegisterQToolBarInHIToolborItemClass();
|
---|
316 | static HIToolbarItemRef CreateToolbarItemForIdentifier(CFStringRef identifier, CFTypeRef data);
|
---|
317 | static HIToolbarItemRef createQToolBarInHIToolbarItem(QToolBar *toolbar,
|
---|
318 | QMainWindowLayout *layout);
|
---|
319 | # endif
|
---|
320 | public:
|
---|
321 | struct ToolBarSaveState {
|
---|
322 | ToolBarSaveState() : movable(false) { }
|
---|
323 | ToolBarSaveState(bool newMovable, const QSize &newMax)
|
---|
324 | : movable(newMovable), maximumSize(newMax) { }
|
---|
325 | bool movable;
|
---|
326 | QSize maximumSize;
|
---|
327 | };
|
---|
328 | QList<QToolBar *> qtoolbarsInUnifiedToolbarList;
|
---|
329 | QList<void *> toolbarItemsCopy;
|
---|
330 | QHash<void *, QToolBar *> unifiedToolbarHash;
|
---|
331 | QHash<QToolBar *, ToolBarSaveState> toolbarSaveState;
|
---|
332 | QHash<QString, QToolBar *> cocoaItemIDToToolbarHash;
|
---|
333 | void insertIntoMacToolbar(QToolBar *before, QToolBar *after);
|
---|
334 | void removeFromMacToolbar(QToolBar *toolbar);
|
---|
335 | void cleanUpMacToolbarItems();
|
---|
336 | void fixSizeInUnifiedToolbar(QToolBar *tb) const;
|
---|
337 | bool useHIToolBar;
|
---|
338 | #endif
|
---|
339 | };
|
---|
340 | QT_END_NAMESPACE
|
---|
341 |
|
---|
342 | #endif // QT_NO_MAINWINDOW
|
---|
343 |
|
---|
344 | QT_BEGIN_NAMESPACE
|
---|
345 | static inline int pick(Qt::Orientation o, const QPoint &pos)
|
---|
346 | { return o == Qt::Horizontal ? pos.x() : pos.y(); }
|
---|
347 |
|
---|
348 | static inline int pick(Qt::Orientation o, const QSize &size)
|
---|
349 | { return o == Qt::Horizontal ? size.width() : size.height(); }
|
---|
350 |
|
---|
351 | static inline int &rpick(Qt::Orientation o, QPoint &pos)
|
---|
352 | { return o == Qt::Horizontal ? pos.rx() : pos.ry(); }
|
---|
353 |
|
---|
354 | static inline int &rpick(Qt::Orientation o, QSize &size)
|
---|
355 | { return o == Qt::Horizontal ? size.rwidth() : size.rheight(); }
|
---|
356 |
|
---|
357 | static inline QSizePolicy::Policy pick(Qt::Orientation o, const QSizePolicy &policy)
|
---|
358 | { return o == Qt::Horizontal ? policy.horizontalPolicy() : policy.verticalPolicy(); }
|
---|
359 |
|
---|
360 | static inline int perp(Qt::Orientation o, const QPoint &pos)
|
---|
361 | { return o == Qt::Vertical ? pos.x() : pos.y(); }
|
---|
362 |
|
---|
363 | static inline int perp(Qt::Orientation o, const QSize &size)
|
---|
364 | { return o == Qt::Vertical ? size.width() : size.height(); }
|
---|
365 |
|
---|
366 | static inline int &rperp(Qt::Orientation o, QPoint &pos)
|
---|
367 | { return o == Qt::Vertical ? pos.rx() : pos.ry(); }
|
---|
368 |
|
---|
369 | static inline int &rperp(Qt::Orientation o, QSize &size)
|
---|
370 | { return o == Qt::Vertical ? size.rwidth() : size.rheight(); }
|
---|
371 |
|
---|
372 | QT_END_NAMESPACE
|
---|
373 |
|
---|
374 | #endif // QDYNAMICMAINWINDOWLAYOUT_P_H
|
---|