Qt 4.8
qmainwindowlayout_p.h
Go to the documentation of this file.
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)
75 class QTextStream;
76 Q_GUI_EXPORT void qt_dumpLayout(QTextStream &qout, QMainWindow *window);
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 ;).
82 struct OpaqueHIObjectRef;
83 typedef struct OpaqueHIObjectRef* HIObjectRef;
85 typedef const void * CFTypeRef;
86 typedef 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 
95 
96 class QToolBar;
97 class 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 
106 {
107 public:
110 
112 
113 #ifndef QT_NO_TOOLBAR
115 #endif
116 
117 #ifndef QT_NO_DOCKWIDGET
119 #else
120  QLayoutItem *centralWidgetItem;
121  QRect centralWidgetRect;
122 #endif
123 
124  void apply(bool animated);
125  void deleteAllLayoutItems();
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);
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 
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 
160 {
161  Q_OBJECT
162 
163 public:
165 
166  QMainWindowLayout(QMainWindow *mainwindow, QLayout *parentLayout);
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 
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
225  bool documentMode() const;
226  void setDocumentMode(bool enabled);
227 
228  QTabBar *getTabBar();
232 
233  QWidget *getSeparatorWidget();
236  int sep; // separator extent
237 
238 #ifndef QT_NO_TABWIDGET
239  QTabWidget::TabPosition tabPositions[4];
241 
242  QTabWidget::TabShape tabShape() const;
243  void setTabShape(QTabWidget::TabShape tabShape);
245  void setTabPosition(Qt::DockWidgetAreas areas, QTabWidget::TabPosition tabPosition);
246 #endif // QT_NO_TABWIDGET
247 #endif // QT_NO_TABBAR
248 
249  // separators
250 
252  QPoint movingSeparatorOrigin, movingSeparatorPos;
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;
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 
289 #ifndef QT_NO_RUBBERBAND
291 #endif
292 
293  QList<int> hover(QLayoutItem *widgetItem, const QPoint &mousePos);
294  bool plug(QLayoutItem *widgetItem);
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 
304 private Q_SLOTS:
305 #ifndef QT_NO_DOCKWIDGET
306 #ifndef QT_NO_TABBAR
307  void tabChanged();
308 #endif
309 #endif
310 private:
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,
323 # endif
324 public:
326  ToolBarSaveState() : movable(false) { }
327  ToolBarSaveState(bool newMovable, const QSize &newMax)
328  : movable(newMovable), maximumSize(newMax) { }
329  bool movable;
331  };
337  void insertIntoMacToolbar(QToolBar *before, QToolBar *after);
338  void removeFromMacToolbar(QToolBar *toolbar);
339  void cleanUpMacToolbarItems();
340  void fixSizeInUnifiedToolbar(QToolBar *tb) const;
342  void syncUnifiedToolbarVisibility();
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 };
353 
354 #endif // QT_NO_MAINWINDOW
355 
356 #endif // QDYNAMICMAINWINDOWLAYOUT_P_H
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
QMainWindowLayoutState(QMainWindow *win)
const struct __CFString * CFStringRef
QSet< QTabBar * > usedTabBars
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
EventRef event
QPointer< QWidget > widget
The QDockWidget class provides a widget that can be docked inside a QMainWindow or floated as a top-l...
Definition: qdockwidget.h:60
QLayoutItem * itemAt(int index, int *x) const
QLayoutItem * plug(const QList< int > &path)
QRect itemRect(const QList< int > &path) const
QList< int > currentGapPos
TabPosition
This enum type defines where QTabWidget draws the tab row:
Definition: qtabwidget.h:112
#define Q_GUI_EXPORT
Definition: qglobal.h:1450
bool checkFormat(QDataStream &stream, bool pre43)
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
QList< int > gapIndex(QWidget *widget, const QPoint &pos) const
The QStyleOptionToolBar class is used to describe the parameters for drawing a toolbar.
Definition: qstyleoption.h:369
The QTabBar class provides a tab bar, e.g.
Definition: qtabbar.h:59
#define Q_SLOTS
Definition: qobjectdefs.h:71
The QHash class is a template class that provides a hash-table-based dictionary.
Definition: qdatastream.h:66
bool activateUnifiedToolbarAfterFullScreen
NSToolbar * toolbar
void apply(bool animated)
QDockAreaLayout dockAreaLayout
void setCentralWidget(QWidget *widget)
The QStatusBar class provides a horizontal bar suitable for presenting status information.
Definition: qstatusbar.h:57
QRect gapRect(const QList< int > &path) const
QMainWindow::DockOptions dockOptions
NSWindow * window
QLayoutItem * takeAt(int index, int *x)
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
The QLayoutItem class provides an abstract item that a QLayout manipulates.
Definition: qlayoutitem.h:64
static FILE * stream
QWidget * centralWidget() const
The QToolBar class provides a movable panel that contains a set of controls.
Definition: qtoolbar.h:62
The QLayout class is the base class of geometry managers.
Definition: qlayout.h:90
const char * layout
QRubberBand * gapIndicator
static const char * data(const QByteArray &arr)
QList< QToolBar * > qtoolbarsInUnifiedToolbarList
The QRegion class specifies a clip region for a painter.
Definition: qregion.h:68
QSet< QWidget * > usedSeparatorWidgets
signed long OSStatus
bool restoreState(QDataStream &stream, const QMainWindowLayoutState &oldState)
QHash< QToolBar *, ToolBarSaveState > toolbarSaveState
#define Q_OBJECT
Definition: qobjectdefs.h:157
struct OpaqueEventRef * EventRef
bool insertGap(const QList< int > &path, QLayoutItem *item)
const void * CFTypeRef
ToolBarArea
Definition: qnamespace.h:1353
Corner
Definition: qnamespace.h:1456
HIObjectRef HIToolbarItemRef
DockWidgetArea
Definition: qnamespace.h:1337
The QTimerEvent class contains parameters that describe a timer event.
Definition: qcoreevent.h:341
QLayoutItem * item(const QList< int > &path)
The QTextStream class provides a convenient interface for reading and writing text.
Definition: qtextstream.h:73
QHash< void *, QToolBar * > unifiedToolbarHash
QList< QWidget * > unusedSeparatorWidgets
bool contains(QWidget *widget) const
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53
QHash< QString, QToolBar * > cocoaItemIDToToolbarHash
The QMainWindow class provides a main application window.
Definition: qmainwindow.h:63
QList< int > indexOf(QWidget *widget) const
struct OpaqueHIObjectRef * HIObjectRef
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
#define Q_AUTOTEST_EXPORT
Definition: qglobal.h:1510
QList< QTabBar * > unusedTabBars
quint16 index
QBasicTimer separatorMoveTimer
QWidgetAnimator widgetAnimator
The QBasicTimer class provides timer events for objects.
Definition: qbasictimer.h:55
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53
struct OpaqueEventHandlerCallRef * EventHandlerCallRef
The QDataStream class provides serialization of binary data to a QIODevice.
Definition: qdatastream.h:71
ToolBarSaveState(bool newMovable, const QSize &newMax)
void saveState(QDataStream &stream) const
Orientation
Definition: qnamespace.h:174
QToolBarAreaLayout toolBarAreaLayout
The QRubberBand class provides a rectangle or line that can indicate a selection or a boundary...
Definition: qrubberband.h:58
QMainWindowLayoutState savedState
QLayoutItem * unplug(const QList< int > &path, QMainWindowLayoutState *savedState=0)
#define enabled
TabShape
This enum type defines the shape of the tabs:
Definition: qtabwidget.h:126
QList< void * > toolbarItemsCopy
QTabWidget::TabShape _tabShape
QList< int > movingSeparator
static int area(const QSize &s)
Definition: qicon.cpp:155