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