0
|
1 |
/****************************************************************************
|
|
2 |
**
|
|
3 |
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
4 |
** All rights reserved.
|
|
5 |
** Contact: Nokia Corporation (qt-info@nokia.com)
|
|
6 |
**
|
|
7 |
** This file is part of the QtGui module of the Qt Toolkit.
|
|
8 |
**
|
|
9 |
** $QT_BEGIN_LICENSE:LGPL$
|
|
10 |
** No Commercial Usage
|
|
11 |
** This file contains pre-release code and may not be distributed.
|
|
12 |
** You may use this file in accordance with the terms and conditions
|
|
13 |
** contained in the Technology Preview License Agreement accompanying
|
|
14 |
** this package.
|
|
15 |
**
|
|
16 |
** GNU Lesser General Public License Usage
|
|
17 |
** Alternatively, this file may be used under the terms of the GNU Lesser
|
|
18 |
** General Public License version 2.1 as published by the Free Software
|
|
19 |
** Foundation and appearing in the file LICENSE.LGPL included in the
|
|
20 |
** packaging of this file. Please review the following information to
|
|
21 |
** ensure the GNU Lesser General Public License version 2.1 requirements
|
|
22 |
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|
23 |
**
|
|
24 |
** In addition, as a special exception, Nokia gives you certain additional
|
|
25 |
** rights. These rights are described in the Nokia Qt LGPL Exception
|
|
26 |
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
27 |
**
|
|
28 |
** If you have questions regarding the use of this file, please contact
|
|
29 |
** Nokia at qt-info@nokia.com.
|
|
30 |
**
|
|
31 |
**
|
|
32 |
**
|
|
33 |
**
|
|
34 |
**
|
|
35 |
**
|
|
36 |
**
|
|
37 |
**
|
|
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 "QtCore/qbasictimer.h"
|
|
65 |
#include "private/qlayoutengine_p.h"
|
|
66 |
#include "private/qwidgetanimator_p.h"
|
|
67 |
|
|
68 |
#include "qdockarealayout_p.h"
|
|
69 |
#include "qtoolbararealayout_p.h"
|
|
70 |
|
|
71 |
//#define Q_DEBUG_MAINWINDOW_LAYOUT
|
|
72 |
|
|
73 |
#ifdef Q_DEBUG_MAINWINDOW_LAYOUT
|
|
74 |
QT_BEGIN_NAMESPACE
|
|
75 |
class QTextStream;
|
|
76 |
Q_GUI_EXPORT void qt_dumpLayout(QTextStream &qout, QMainWindow *window);
|
|
77 |
QT_END_NAMESPACE
|
|
78 |
#endif // Q_DEBUG_MAINWINDOW_LAYOUT
|
|
79 |
|
|
80 |
#ifdef Q_WS_MAC
|
|
81 |
// Forward defs to make avoid including Carbon.h (faster compile you know ;).
|
|
82 |
struct OpaqueHIObjectRef;
|
|
83 |
typedef struct OpaqueHIObjectRef* HIObjectRef;
|
|
84 |
typedef HIObjectRef HIToolbarItemRef;
|
|
85 |
typedef const void * CFTypeRef;
|
|
86 |
typedef const struct __CFString * CFStringRef;
|
|
87 |
|
|
88 |
#endif
|
|
89 |
|
|
90 |
QT_BEGIN_NAMESPACE
|
|
91 |
|
|
92 |
class QToolBar;
|
|
93 |
class QRubberBand;
|
|
94 |
|
|
95 |
/* This data structure represents the state of all the tool-bars and dock-widgets. It's value based
|
|
96 |
so it can be easilly copied into a temporary variable. All operations are performed without moving
|
|
97 |
any widgets. Only when we are sure we have the desired state, we call apply(), which moves the
|
|
98 |
widgets.
|
|
99 |
*/
|
|
100 |
|
|
101 |
class QMainWindowLayoutState
|
|
102 |
{
|
|
103 |
public:
|
|
104 |
QRect rect;
|
|
105 |
QMainWindow *mainWindow;
|
|
106 |
|
|
107 |
QMainWindowLayoutState(QMainWindow *win);
|
|
108 |
|
|
109 |
#ifndef QT_NO_TOOLBAR
|
|
110 |
QToolBarAreaLayout toolBarAreaLayout;
|
|
111 |
#endif
|
|
112 |
|
|
113 |
#ifndef QT_NO_DOCKWIDGET
|
|
114 |
QDockAreaLayout dockAreaLayout;
|
|
115 |
#else
|
|
116 |
QLayoutItem *centralWidgetItem;
|
|
117 |
QRect centralWidgetRect;
|
|
118 |
#endif
|
|
119 |
|
|
120 |
void apply(bool animated);
|
|
121 |
void deleteAllLayoutItems();
|
|
122 |
void deleteCentralWidgetItem();
|
|
123 |
|
|
124 |
QSize sizeHint() const;
|
|
125 |
QSize minimumSize() const;
|
|
126 |
void fitLayout();
|
|
127 |
|
|
128 |
QLayoutItem *itemAt(int index, int *x) const;
|
|
129 |
QLayoutItem *takeAt(int index, int *x);
|
|
130 |
QList<int> indexOf(QWidget *widget) const;
|
|
131 |
QLayoutItem *item(const QList<int> &path);
|
|
132 |
QRect itemRect(const QList<int> &path) const;
|
|
133 |
QRect gapRect(const QList<int> &path) const; // ### get rid of this, use itemRect() instead
|
|
134 |
|
|
135 |
bool contains(QWidget *widget) const;
|
|
136 |
|
|
137 |
void setCentralWidget(QWidget *widget);
|
|
138 |
QWidget *centralWidget() const;
|
|
139 |
|
|
140 |
QList<int> gapIndex(QWidget *widget, const QPoint &pos) const;
|
|
141 |
bool insertGap(const QList<int> &path, QLayoutItem *item);
|
|
142 |
void remove(const QList<int> &path);
|
|
143 |
void remove(QLayoutItem *item);
|
|
144 |
void clear();
|
|
145 |
bool isValid() const;
|
|
146 |
|
|
147 |
QLayoutItem *plug(const QList<int> &path);
|
|
148 |
QLayoutItem *unplug(const QList<int> &path, QMainWindowLayoutState *savedState = 0);
|
|
149 |
|
|
150 |
void saveState(QDataStream &stream) const;
|
|
151 |
bool checkFormat(QDataStream &stream, bool pre43);
|
|
152 |
bool restoreState(QDataStream &stream, const QMainWindowLayoutState &oldState);
|
|
153 |
};
|
|
154 |
|
|
155 |
class Q_AUTOTEST_EXPORT QMainWindowLayout : public QLayout
|
|
156 |
{
|
|
157 |
Q_OBJECT
|
|
158 |
|
|
159 |
public:
|
|
160 |
QMainWindowLayoutState layoutState, savedState;
|
|
161 |
|
|
162 |
explicit QMainWindowLayout(QMainWindow *mainwindow);
|
|
163 |
~QMainWindowLayout();
|
|
164 |
|
|
165 |
QMainWindow::DockOptions dockOptions;
|
|
166 |
void setDockOptions(QMainWindow::DockOptions opts);
|
|
167 |
bool usesHIToolBar(QToolBar *toolbar) const;
|
|
168 |
|
|
169 |
void timerEvent(QTimerEvent *e);
|
|
170 |
|
|
171 |
// status bar
|
|
172 |
|
|
173 |
QLayoutItem *statusbar;
|
|
174 |
|
|
175 |
#ifndef QT_NO_STATUSBAR
|
|
176 |
QStatusBar *statusBar() const;
|
|
177 |
void setStatusBar(QStatusBar *sb);
|
|
178 |
#endif
|
|
179 |
|
|
180 |
// central widget
|
|
181 |
|
|
182 |
QWidget *centralWidget() const;
|
|
183 |
void setCentralWidget(QWidget *cw);
|
|
184 |
|
|
185 |
// toolbars
|
|
186 |
|
|
187 |
#ifndef QT_NO_TOOLBAR
|
|
188 |
void addToolBarBreak(Qt::ToolBarArea area);
|
|
189 |
void insertToolBarBreak(QToolBar *before);
|
|
190 |
void removeToolBarBreak(QToolBar *before);
|
|
191 |
|
|
192 |
void addToolBar(Qt::ToolBarArea area, QToolBar *toolbar, bool needAddChildWidget = true);
|
|
193 |
void insertToolBar(QToolBar *before, QToolBar *toolbar);
|
|
194 |
Qt::ToolBarArea toolBarArea(QToolBar *toolbar) const;
|
|
195 |
bool toolBarBreak(QToolBar *toolBar) const;
|
|
196 |
void getStyleOptionInfo(QStyleOptionToolBar *option, QToolBar *toolBar) const;
|
|
197 |
void removeToolBar(QToolBar *toolbar);
|
|
198 |
void toggleToolBarsVisible();
|
|
199 |
void moveToolBar(QToolBar *toolbar, int pos);
|
|
200 |
#endif
|
|
201 |
|
|
202 |
// dock widgets
|
|
203 |
|
|
204 |
#ifndef QT_NO_DOCKWIDGET
|
|
205 |
void setCorner(Qt::Corner corner, Qt::DockWidgetArea area);
|
|
206 |
Qt::DockWidgetArea corner(Qt::Corner corner) const;
|
|
207 |
void addDockWidget(Qt::DockWidgetArea area,
|
|
208 |
QDockWidget *dockwidget,
|
|
209 |
Qt::Orientation orientation);
|
|
210 |
void splitDockWidget(QDockWidget *after,
|
|
211 |
QDockWidget *dockwidget,
|
|
212 |
Qt::Orientation orientation);
|
|
213 |
void tabifyDockWidget(QDockWidget *first, QDockWidget *second);
|
|
214 |
Qt::DockWidgetArea dockWidgetArea(QDockWidget *dockwidget) const;
|
|
215 |
void raise(QDockWidget *widget);
|
|
216 |
void setVerticalTabsEnabled(bool enabled);
|
|
217 |
bool restoreDockWidget(QDockWidget *dockwidget);
|
|
218 |
|
|
219 |
#ifndef QT_NO_TABBAR
|
|
220 |
bool _documentMode;
|
|
221 |
bool documentMode() const;
|
|
222 |
void setDocumentMode(bool enabled);
|
|
223 |
|
|
224 |
QTabBar *getTabBar();
|
|
225 |
QSet<QTabBar*> usedTabBars;
|
|
226 |
QList<QTabBar*> unusedTabBars;
|
|
227 |
bool verticalTabsEnabled;
|
|
228 |
|
|
229 |
QWidget *getSeparatorWidget();
|
|
230 |
QSet<QWidget*> usedSeparatorWidgets;
|
|
231 |
QList<QWidget*> unusedSeparatorWidgets;
|
|
232 |
int sep; // separator extent
|
|
233 |
|
|
234 |
#ifndef QT_NO_TABWIDGET
|
|
235 |
QTabWidget::TabPosition tabPositions[4];
|
|
236 |
QTabWidget::TabShape _tabShape;
|
|
237 |
|
|
238 |
QTabWidget::TabShape tabShape() const;
|
|
239 |
void setTabShape(QTabWidget::TabShape tabShape);
|
|
240 |
QTabWidget::TabPosition tabPosition(Qt::DockWidgetArea area) const;
|
|
241 |
void setTabPosition(Qt::DockWidgetAreas areas, QTabWidget::TabPosition tabPosition);
|
|
242 |
#endif // QT_NO_TABWIDGET
|
|
243 |
#endif // QT_NO_TABBAR
|
|
244 |
|
|
245 |
// separators
|
|
246 |
|
|
247 |
QList<int> movingSeparator;
|
|
248 |
QPoint movingSeparatorOrigin, movingSeparatorPos;
|
|
249 |
QBasicTimer separatorMoveTimer;
|
|
250 |
|
|
251 |
bool startSeparatorMove(const QPoint &pos);
|
|
252 |
bool separatorMove(const QPoint &pos);
|
|
253 |
bool endSeparatorMove(const QPoint &pos);
|
|
254 |
void keepSize(QDockWidget *w);
|
|
255 |
#endif // QT_NO_DOCKWIDGET
|
|
256 |
|
|
257 |
// save/restore
|
|
258 |
|
|
259 |
enum { // sentinel values used to validate state data
|
|
260 |
VersionMarker = 0xff
|
|
261 |
};
|
|
262 |
void saveState(QDataStream &stream) const;
|
|
263 |
bool restoreState(QDataStream &stream);
|
|
264 |
|
|
265 |
// QLayout interface
|
|
266 |
|
|
267 |
void addItem(QLayoutItem *item);
|
|
268 |
void setGeometry(const QRect &r);
|
|
269 |
QLayoutItem *itemAt(int index) const;
|
|
270 |
QLayoutItem *takeAt(int index);
|
|
271 |
int count() const;
|
|
272 |
|
|
273 |
QSize sizeHint() const;
|
|
274 |
QSize minimumSize() const;
|
|
275 |
mutable QSize szHint;
|
|
276 |
mutable QSize minSize;
|
|
277 |
void invalidate();
|
|
278 |
|
|
279 |
// animations
|
|
280 |
|
|
281 |
QWidgetAnimator widgetAnimator;
|
|
282 |
QList<int> currentGapPos;
|
|
283 |
QRect currentGapRect;
|
|
284 |
QWidget *pluggingWidget;
|
|
285 |
#ifndef QT_NO_RUBBERBAND
|
|
286 |
QRubberBand *gapIndicator;
|
|
287 |
#endif
|
|
288 |
|
|
289 |
QList<int> hover(QLayoutItem *widgetItem, const QPoint &mousePos);
|
|
290 |
bool plug(QLayoutItem *widgetItem);
|
|
291 |
QLayoutItem *unplug(QWidget *widget);
|
|
292 |
void revert(QLayoutItem *widgetItem);
|
|
293 |
void updateGapIndicator();
|
|
294 |
void paintDropIndicator(QPainter *p, QWidget *widget, const QRegion &clip);
|
|
295 |
void applyState(QMainWindowLayoutState &newState, bool animate = true);
|
|
296 |
void restore(bool keepSavedState = false);
|
|
297 |
void updateHIToolBarStatus();
|
|
298 |
void animationFinished(QWidget *widget);
|
|
299 |
|
|
300 |
private Q_SLOTS:
|
|
301 |
#ifndef QT_NO_DOCKWIDGET
|
|
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 |
void syncUnifiedToolbarVisibility();
|
|
339 |
bool blockVisiblityCheck;
|
|
340 |
#endif
|
|
341 |
};
|
|
342 |
QT_END_NAMESPACE
|
|
343 |
|
|
344 |
#endif // QT_NO_MAINWINDOW
|
|
345 |
|
|
346 |
#endif // QDYNAMICMAINWINDOWLAYOUT_P_H
|