| Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/widgets/widgets/qmainwindow.cpp | 
| Source code | Switch to Preprocessed file | 
| Line | Source | Count | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | /**************************************************************************** | - | ||||||||||||||||||
| 2 | ** | - | ||||||||||||||||||
| 3 | ** Copyright (C) 2015 The Qt Company Ltd. | - | ||||||||||||||||||
| 4 | ** Contact: http://www.qt.io/licensing/ | - | ||||||||||||||||||
| 5 | ** | - | ||||||||||||||||||
| 6 | ** This file is part of the QtWidgets module of the Qt Toolkit. | - | ||||||||||||||||||
| 7 | ** | - | ||||||||||||||||||
| 8 | ** $QT_BEGIN_LICENSE:LGPL21$ | - | ||||||||||||||||||
| 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 The Qt Company. For licensing terms | - | ||||||||||||||||||
| 14 | ** and conditions see http://www.qt.io/terms-conditions. For further | - | ||||||||||||||||||
| 15 | ** information use the contact form at http://www.qt.io/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 or version 3 as published by the Free | - | ||||||||||||||||||
| 20 | ** Software Foundation and appearing in the file LICENSE.LGPLv21 and | - | ||||||||||||||||||
| 21 | ** LICENSE.LGPLv3 included in the packaging of this file. Please review the | - | ||||||||||||||||||
| 22 | ** following information to ensure the GNU Lesser General Public License | - | ||||||||||||||||||
| 23 | ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and | - | ||||||||||||||||||
| 24 | ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | - | ||||||||||||||||||
| 25 | ** | - | ||||||||||||||||||
| 26 | ** As a special exception, The Qt Company gives you certain additional | - | ||||||||||||||||||
| 27 | ** rights. These rights are described in The Qt Company LGPL Exception | - | ||||||||||||||||||
| 28 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | - | ||||||||||||||||||
| 29 | ** | - | ||||||||||||||||||
| 30 | ** $QT_END_LICENSE$ | - | ||||||||||||||||||
| 31 | ** | - | ||||||||||||||||||
| 32 | ****************************************************************************/ | - | ||||||||||||||||||
| 33 | - | |||||||||||||||||||
| 34 | //#define QT_EXPERIMENTAL_CLIENT_DECORATIONS | - | ||||||||||||||||||
| 35 | - | |||||||||||||||||||
| 36 | #include "qmainwindow.h" | - | ||||||||||||||||||
| 37 | #include "qmainwindowlayout_p.h" | - | ||||||||||||||||||
| 38 | - | |||||||||||||||||||
| 39 | #ifndef QT_NO_MAINWINDOW | - | ||||||||||||||||||
| 40 | - | |||||||||||||||||||
| 41 | #include "qdockwidget.h" | - | ||||||||||||||||||
| 42 | #include "qtoolbar.h" | - | ||||||||||||||||||
| 43 | - | |||||||||||||||||||
| 44 | #include <qapplication.h> | - | ||||||||||||||||||
| 45 | #include <qmenubar.h> | - | ||||||||||||||||||
| 46 | #include <qstatusbar.h> | - | ||||||||||||||||||
| 47 | #include <qevent.h> | - | ||||||||||||||||||
| 48 | #include <qstyle.h> | - | ||||||||||||||||||
| 49 | #include <qdebug.h> | - | ||||||||||||||||||
| 50 | #include <qpainter.h> | - | ||||||||||||||||||
| 51 | - | |||||||||||||||||||
| 52 | #include <private/qwidget_p.h> | - | ||||||||||||||||||
| 53 | #include "qtoolbar_p.h" | - | ||||||||||||||||||
| 54 | #include "qwidgetanimator_p.h" | - | ||||||||||||||||||
| 55 | #ifdef Q_OS_OSX | - | ||||||||||||||||||
| 56 | #include <qpa/qplatformnativeinterface.h> | - | ||||||||||||||||||
| 57 | #endif | - | ||||||||||||||||||
| 58 | #ifdef Q_DEAD_CODE_FROM_QT4_MAC | - | ||||||||||||||||||
| 59 | #include <private/qt_mac_p.h> | - | ||||||||||||||||||
| 60 | #include <private/qt_cocoa_helpers_mac_p.h> | - | ||||||||||||||||||
| 61 | QT_BEGIN_NAMESPACE | - | ||||||||||||||||||
| 62 | extern OSWindowRef qt_mac_window_for(const QWidget *); // qwidget_mac.cpp | - | ||||||||||||||||||
| 63 | QT_END_NAMESPACE | - | ||||||||||||||||||
| 64 | #endif | - | ||||||||||||||||||
| 65 | - | |||||||||||||||||||
| 66 | QT_BEGIN_NAMESPACE | - | ||||||||||||||||||
| 67 | - | |||||||||||||||||||
| 68 | class QMainWindowPrivate : public QWidgetPrivate | - | ||||||||||||||||||
| 69 | { | - | ||||||||||||||||||
| 70 | Q_DECLARE_PUBLIC(QMainWindow) | - | ||||||||||||||||||
| 71 | public: | - | ||||||||||||||||||
| 72 | inline QMainWindowPrivate() | - | ||||||||||||||||||
| 73 | : layout(0), explicitIconSize(false), toolButtonStyle(Qt::ToolButtonIconOnly) | - | ||||||||||||||||||
| 74 | #ifdef Q_OS_OSX | - | ||||||||||||||||||
| 75 | , useUnifiedToolBar(false) | - | ||||||||||||||||||
| 76 | #endif | - | ||||||||||||||||||
| 77 | #ifdef Q_DEAD_CODE_FROM_QT4_MAC | - | ||||||||||||||||||
| 78 | , useHIToolBar(false) | - | ||||||||||||||||||
| 79 | , activateUnifiedToolbarAfterFullScreen(false) | - | ||||||||||||||||||
| 80 | #endif | - | ||||||||||||||||||
| 81 | #if !defined(QT_NO_DOCKWIDGET) && !defined(QT_NO_CURSOR) | - | ||||||||||||||||||
| 82 | , hasOldCursor(false) , cursorAdjusted(false) | - | ||||||||||||||||||
| 83 | #endif | - | ||||||||||||||||||
| 84 | { } never executed:  end of block | 0 | ||||||||||||||||||
| 85 | QMainWindowLayout *layout; | - | ||||||||||||||||||
| 86 | QSize iconSize; | - | ||||||||||||||||||
| 87 | bool explicitIconSize; | - | ||||||||||||||||||
| 88 | Qt::ToolButtonStyle toolButtonStyle; | - | ||||||||||||||||||
| 89 | #ifdef Q_OS_OSX | - | ||||||||||||||||||
| 90 | bool useUnifiedToolBar; | - | ||||||||||||||||||
| 91 | #endif | - | ||||||||||||||||||
| 92 | #ifdef Q_DEAD_CODE_FROM_QT4_MAC | - | ||||||||||||||||||
| 93 | bool useHIToolBar; | - | ||||||||||||||||||
| 94 | bool activateUnifiedToolbarAfterFullScreen; | - | ||||||||||||||||||
| 95 | #endif | - | ||||||||||||||||||
| 96 | void init(); | - | ||||||||||||||||||
| 97 | QList<int> hoverSeparator; | - | ||||||||||||||||||
| 98 | QPoint hoverPos; | - | ||||||||||||||||||
| 99 | - | |||||||||||||||||||
| 100 | #if !defined(QT_NO_DOCKWIDGET) && !defined(QT_NO_CURSOR) | - | ||||||||||||||||||
| 101 | QCursor separatorCursor(const QList<int> &path) const; | - | ||||||||||||||||||
| 102 | void adjustCursor(const QPoint &pos); | - | ||||||||||||||||||
| 103 | QCursor oldCursor; | - | ||||||||||||||||||
| 104 | QCursor adjustedCursor; | - | ||||||||||||||||||
| 105 | uint hasOldCursor : 1; | - | ||||||||||||||||||
| 106 | uint cursorAdjusted : 1; | - | ||||||||||||||||||
| 107 | #endif | - | ||||||||||||||||||
| 108 | - | |||||||||||||||||||
| 109 | static inline QMainWindowLayout *mainWindowLayout(const QMainWindow *mainWindow) | - | ||||||||||||||||||
| 110 | { | - | ||||||||||||||||||
| 111 | return mainWindow ? mainWindow->d_func()->layout : static_cast<QMainWindowLayout *>(0); never executed:  return mainWindow ? mainWindow->d_func()->layout : static_cast<QMainWindowLayout *>(0);
 | 0 | ||||||||||||||||||
| 112 | } | - | ||||||||||||||||||
| 113 | }; | - | ||||||||||||||||||
| 114 | - | |||||||||||||||||||
| 115 | QMainWindowLayout *qt_mainwindow_layout(const QMainWindow *mainWindow) | - | ||||||||||||||||||
| 116 | { | - | ||||||||||||||||||
| 117 | return QMainWindowPrivate::mainWindowLayout(mainWindow); never executed:  return QMainWindowPrivate::mainWindowLayout(mainWindow); | 0 | ||||||||||||||||||
| 118 | } | - | ||||||||||||||||||
| 119 | - | |||||||||||||||||||
| 120 | #ifdef QT_EXPERIMENTAL_CLIENT_DECORATIONS | - | ||||||||||||||||||
| 121 | Q_WIDGETS_EXPORT void qt_setMainWindowTitleWidget(QMainWindow *mainWindow, Qt::DockWidgetArea area, QWidget *widget) | - | ||||||||||||||||||
| 122 | { | - | ||||||||||||||||||
| 123 | QGridLayout *topLayout = qobject_cast<QGridLayout *>(mainWindow->layout()); | - | ||||||||||||||||||
| 124 | Q_ASSERT(topLayout); | - | ||||||||||||||||||
| 125 | - | |||||||||||||||||||
| 126 | int row = 0; | - | ||||||||||||||||||
| 127 | int column = 0; | - | ||||||||||||||||||
| 128 | - | |||||||||||||||||||
| 129 | switch (area) { | - | ||||||||||||||||||
| 130 | case Qt::LeftDockWidgetArea: | - | ||||||||||||||||||
| 131 | row = 1; | - | ||||||||||||||||||
| 132 | column = 0; | - | ||||||||||||||||||
| 133 | break; | - | ||||||||||||||||||
| 134 | case Qt::TopDockWidgetArea: | - | ||||||||||||||||||
| 135 | row = 0; | - | ||||||||||||||||||
| 136 | column = 1; | - | ||||||||||||||||||
| 137 | break; | - | ||||||||||||||||||
| 138 | case Qt::BottomDockWidgetArea: | - | ||||||||||||||||||
| 139 | row = 2; | - | ||||||||||||||||||
| 140 | column = 1; | - | ||||||||||||||||||
| 141 | break; | - | ||||||||||||||||||
| 142 | case Qt::RightDockWidgetArea: | - | ||||||||||||||||||
| 143 | row = 1; | - | ||||||||||||||||||
| 144 | column = 2; | - | ||||||||||||||||||
| 145 | break; | - | ||||||||||||||||||
| 146 | default: | - | ||||||||||||||||||
| 147 | Q_ASSERT_X(false, "qt_setMainWindowTitleWidget", "Unknown area"); | - | ||||||||||||||||||
| 148 | return; | - | ||||||||||||||||||
| 149 | } | - | ||||||||||||||||||
| 150 | - | |||||||||||||||||||
| 151 | if (QLayoutItem *oldItem = topLayout->itemAtPosition(row, column)) | - | ||||||||||||||||||
| 152 | delete oldItem->widget(); | - | ||||||||||||||||||
| 153 | topLayout->addWidget(widget, row, column); | - | ||||||||||||||||||
| 154 | } | - | ||||||||||||||||||
| 155 | #endif | - | ||||||||||||||||||
| 156 | - | |||||||||||||||||||
| 157 | void QMainWindowPrivate::init() | - | ||||||||||||||||||
| 158 | { | - | ||||||||||||||||||
| 159 | Q_Q(QMainWindow); | - | ||||||||||||||||||
| 160 | - | |||||||||||||||||||
| 161 | #ifdef QT_EXPERIMENTAL_CLIENT_DECORATIONS | - | ||||||||||||||||||
| 162 | QGridLayout *topLayout = new QGridLayout(q); | - | ||||||||||||||||||
| 163 | topLayout->setContentsMargins(0, 0, 0, 0); | - | ||||||||||||||||||
| 164 | - | |||||||||||||||||||
| 165 | layout = new QMainWindowLayout(q, topLayout); | - | ||||||||||||||||||
| 166 | - | |||||||||||||||||||
| 167 | topLayout->addItem(layout, 1, 1); | - | ||||||||||||||||||
| 168 | #else | - | ||||||||||||||||||
| 169 | layout = new QMainWindowLayout(q, 0); | - | ||||||||||||||||||
| 170 | #endif | - | ||||||||||||||||||
| 171 | - | |||||||||||||||||||
| 172 | const int metric = q->style()->pixelMetric(QStyle::PM_ToolBarIconSize, 0, q); | - | ||||||||||||||||||
| 173 | iconSize = QSize(metric, metric); | - | ||||||||||||||||||
| 174 | q->setAttribute(Qt::WA_Hover); | - | ||||||||||||||||||
| 175 | } never executed:  end of block | 0 | ||||||||||||||||||
| 176 | - | |||||||||||||||||||
| 177 | /* | - | ||||||||||||||||||
| 178 | The Main Window: | - | ||||||||||||||||||
| 179 | - | |||||||||||||||||||
| 180 | +----------------------------------------------------------+ | - | ||||||||||||||||||
| 181 | | Menu Bar | | - | ||||||||||||||||||
| 182 | +----------------------------------------------------------+ | - | ||||||||||||||||||
| 183 | | Tool Bar Area | | - | ||||||||||||||||||
| 184 | | +--------------------------------------------------+ | | - | ||||||||||||||||||
| 185 | | | Dock Window Area | | | - | ||||||||||||||||||
| 186 | | | +------------------------------------------+ | | | - | ||||||||||||||||||
| 187 | | | | | | | | - | ||||||||||||||||||
| 188 | | | | Central Widget | | | | - | ||||||||||||||||||
| 189 | | | | | | | | - | ||||||||||||||||||
| 190 | | | | | | | | - | ||||||||||||||||||
| 191 | | | | | | | | - | ||||||||||||||||||
| 192 | | | | | | | | - | ||||||||||||||||||
| 193 | | | | | | | | - | ||||||||||||||||||
| 194 | | | | | | | | - | ||||||||||||||||||
| 195 | | | | | | | | - | ||||||||||||||||||
| 196 | | | | | | | | - | ||||||||||||||||||
| 197 | | | | | | | | - | ||||||||||||||||||
| 198 | | | | | | | | - | ||||||||||||||||||
| 199 | | | +------------------------------------------+ | | | - | ||||||||||||||||||
| 200 | | | | | | - | ||||||||||||||||||
| 201 | | +--------------------------------------------------+ | | - | ||||||||||||||||||
| 202 | | | | - | ||||||||||||||||||
| 203 | +----------------------------------------------------------+ | - | ||||||||||||||||||
| 204 | | Status Bar | | - | ||||||||||||||||||
| 205 | +----------------------------------------------------------+ | - | ||||||||||||||||||
| 206 | - | |||||||||||||||||||
| 207 | */ | - | ||||||||||||||||||
| 208 | - | |||||||||||||||||||
| 209 | /*! | - | ||||||||||||||||||
| 210 | \class QMainWindow | - | ||||||||||||||||||
| 211 | \brief The QMainWindow class provides a main application | - | ||||||||||||||||||
| 212 | window. | - | ||||||||||||||||||
| 213 | \ingroup mainwindow-classes | - | ||||||||||||||||||
| 214 | \inmodule QtWidgets | - | ||||||||||||||||||
| 215 | - | |||||||||||||||||||
| 216 | \tableofcontents | - | ||||||||||||||||||
| 217 | - | |||||||||||||||||||
| 218 | \section1 Qt Main Window Framework | - | ||||||||||||||||||
| 219 | - | |||||||||||||||||||
| 220 | A main window provides a framework for building an | - | ||||||||||||||||||
| 221 | application's user interface. Qt has QMainWindow and its \l{Main | - | ||||||||||||||||||
| 222 | Window and Related Classes}{related classes} for main window | - | ||||||||||||||||||
| 223 | management. QMainWindow has its own layout to which you can add | - | ||||||||||||||||||
| 224 | \l{QToolBar}s, \l{QDockWidget}s, a | - | ||||||||||||||||||
| 225 | QMenuBar, and a QStatusBar. The layout has a center area that can | - | ||||||||||||||||||
| 226 | be occupied by any kind of widget. You can see an image of the | - | ||||||||||||||||||
| 227 | layout below. | - | ||||||||||||||||||
| 228 | - | |||||||||||||||||||
| 229 | \image mainwindowlayout.png | - | ||||||||||||||||||
| 230 | - | |||||||||||||||||||
| 231 | \note Creating a main window without a central widget is not supported. | - | ||||||||||||||||||
| 232 | You must have a central widget even if it is just a placeholder. | - | ||||||||||||||||||
| 233 | - | |||||||||||||||||||
| 234 | \section1 Creating Main Window Components | - | ||||||||||||||||||
| 235 | - | |||||||||||||||||||
| 236 | A central widget will typically be a standard Qt widget such | - | ||||||||||||||||||
| 237 | as a QTextEdit or a QGraphicsView. Custom widgets can also be | - | ||||||||||||||||||
| 238 | used for advanced applications. You set the central widget with \c | - | ||||||||||||||||||
| 239 | setCentralWidget(). | - | ||||||||||||||||||
| 240 | - | |||||||||||||||||||
| 241 | Main windows have either a single (SDI) or multiple (MDI) | - | ||||||||||||||||||
| 242 | document interface. You create MDI applications in Qt by using a | - | ||||||||||||||||||
| 243 | QMdiArea as the central widget. | - | ||||||||||||||||||
| 244 | - | |||||||||||||||||||
| 245 | We will now examine each of the other widgets that can be | - | ||||||||||||||||||
| 246 | added to a main window. We give examples on how to create and add | - | ||||||||||||||||||
| 247 | them. | - | ||||||||||||||||||
| 248 | - | |||||||||||||||||||
| 249 | \section2 Creating Menus | - | ||||||||||||||||||
| 250 | - | |||||||||||||||||||
| 251 | Qt implements menus in QMenu and QMainWindow keeps them in a | - | ||||||||||||||||||
| 252 | QMenuBar. \l{QAction}{QAction}s are added to the menus, which | - | ||||||||||||||||||
| 253 | display them as menu items. | - | ||||||||||||||||||
| 254 | - | |||||||||||||||||||
| 255 | You can add new menus to the main window's menu bar by calling | - | ||||||||||||||||||
| 256 | \c menuBar(), which returns the QMenuBar for the window, and then | - | ||||||||||||||||||
| 257 | add a menu with QMenuBar::addMenu(). | - | ||||||||||||||||||
| 258 | - | |||||||||||||||||||
| 259 | QMainWindow comes with a default menu bar, but you can also | - | ||||||||||||||||||
| 260 | set one yourself with \c setMenuBar(). If you wish to implement a | - | ||||||||||||||||||
| 261 | custom menu bar (i.e., not use the QMenuBar widget), you can set it | - | ||||||||||||||||||
| 262 | with \c setMenuWidget(). | - | ||||||||||||||||||
| 263 | - | |||||||||||||||||||
| 264 | An example of how to create menus follows: | - | ||||||||||||||||||
| 265 | - | |||||||||||||||||||
| 266 | \code | - | ||||||||||||||||||
| 267 | void MainWindow::createMenus() | - | ||||||||||||||||||
| 268 | { | - | ||||||||||||||||||
| 269 | fileMenu = menuBar()->addMenu(tr("&File")); | - | ||||||||||||||||||
| 270 | fileMenu->addAction(newAct); | - | ||||||||||||||||||
| 271 | fileMenu->addAction(openAct); | - | ||||||||||||||||||
| 272 | fileMenu->addAction(saveAct); | - | ||||||||||||||||||
| 273 | \endcode | - | ||||||||||||||||||
| 274 | - | |||||||||||||||||||
| 275 | The \c createPopupMenu() function creates popup menus when the | - | ||||||||||||||||||
| 276 | main window receives context menu events. The default | - | ||||||||||||||||||
| 277 | implementation generates a menu with the checkable actions from | - | ||||||||||||||||||
| 278 | the dock widgets and toolbars. You can reimplement \c | - | ||||||||||||||||||
| 279 | createPopupMenu() for a custom menu. | - | ||||||||||||||||||
| 280 | - | |||||||||||||||||||
| 281 | \section2 Creating Toolbars | - | ||||||||||||||||||
| 282 | - | |||||||||||||||||||
| 283 | Toolbars are implemented in the QToolBar class. You add a | - | ||||||||||||||||||
| 284 | toolbar to a main window with \c addToolBar(). | - | ||||||||||||||||||
| 285 | - | |||||||||||||||||||
| 286 | You control the initial position of toolbars by assigning them | - | ||||||||||||||||||
| 287 | to a specific Qt::ToolBarArea. You can split an area by inserting | - | ||||||||||||||||||
| 288 | a toolbar break - think of this as a line break in text editing - | - | ||||||||||||||||||
| 289 | with \c addToolBarBreak() or \c insertToolBarBreak(). You can also | - | ||||||||||||||||||
| 290 | restrict placement by the user with QToolBar::setAllowedAreas() | - | ||||||||||||||||||
| 291 | and QToolBar::setMovable(). | - | ||||||||||||||||||
| 292 | - | |||||||||||||||||||
| 293 | The size of toolbar icons can be retrieved with \c iconSize(). | - | ||||||||||||||||||
| 294 | The sizes are platform dependent; you can set a fixed size with \c | - | ||||||||||||||||||
| 295 | setIconSize(). You can alter the appearance of all tool buttons in | - | ||||||||||||||||||
| 296 | the toolbars with \c setToolButtonStyle(). | - | ||||||||||||||||||
| 297 | - | |||||||||||||||||||
| 298 | An example of toolbar creation follows: | - | ||||||||||||||||||
| 299 | - | |||||||||||||||||||
| 300 | \code | - | ||||||||||||||||||
| 301 | void MainWindow::createToolBars() | - | ||||||||||||||||||
| 302 | { | - | ||||||||||||||||||
| 303 | fileToolBar = addToolBar(tr("File")); | - | ||||||||||||||||||
| 304 | fileToolBar->addAction(newAct); | - | ||||||||||||||||||
| 305 | \endcode | - | ||||||||||||||||||
| 306 | - | |||||||||||||||||||
| 307 | \section2 Creating Dock Widgets | - | ||||||||||||||||||
| 308 | - | |||||||||||||||||||
| 309 | Dock widgets are implemented in the QDockWidget class. A dock | - | ||||||||||||||||||
| 310 | widget is a window that can be docked into the main window. You | - | ||||||||||||||||||
| 311 | add dock widgets to a main window with \c addDockWidget(). | - | ||||||||||||||||||
| 312 | - | |||||||||||||||||||
| 313 | There are four dock widget areas as given by the | - | ||||||||||||||||||
| 314 | Qt::DockWidgetArea enum: left, right, top, and bottom. You can | - | ||||||||||||||||||
| 315 | specify which dock widget area that should occupy the corners | - | ||||||||||||||||||
| 316 | where the areas overlap with \c setCorner(). By default | - | ||||||||||||||||||
| 317 | each area can only contain one row (vertical or horizontal) of | - | ||||||||||||||||||
| 318 | dock widgets, but if you enable nesting with \c | - | ||||||||||||||||||
| 319 | setDockNestingEnabled(), dock widgets can be added in either | - | ||||||||||||||||||
| 320 | direction. | - | ||||||||||||||||||
| 321 | - | |||||||||||||||||||
| 322 | Two dock widgets may also be stacked on top of each other. A | - | ||||||||||||||||||
| 323 | QTabBar is then used to select which of the widgets should be | - | ||||||||||||||||||
| 324 | displayed. | - | ||||||||||||||||||
| 325 | - | |||||||||||||||||||
| 326 | We give an example of how to create and add dock widgets to a | - | ||||||||||||||||||
| 327 | main window: | - | ||||||||||||||||||
| 328 | - | |||||||||||||||||||
| 329 | \snippet mainwindowsnippet.cpp 0 | - | ||||||||||||||||||
| 330 | - | |||||||||||||||||||
| 331 | \section2 The Status Bar | - | ||||||||||||||||||
| 332 | - | |||||||||||||||||||
| 333 | You can set a status bar with \c setStatusBar(), but one is | - | ||||||||||||||||||
| 334 | created the first time \c statusBar() (which returns the main | - | ||||||||||||||||||
| 335 | window's status bar) is called. See QStatusBar for information on | - | ||||||||||||||||||
| 336 | how to use it. | - | ||||||||||||||||||
| 337 | - | |||||||||||||||||||
| 338 | \section1 Storing State | - | ||||||||||||||||||
| 339 | - | |||||||||||||||||||
| 340 | QMainWindow can store the state of its layout with \c | - | ||||||||||||||||||
| 341 | saveState(); it can later be retrieved with \c restoreState(). It | - | ||||||||||||||||||
| 342 | is the position and size (relative to the size of the main window) | - | ||||||||||||||||||
| 343 | of the toolbars and dock widgets that are stored. | - | ||||||||||||||||||
| 344 | - | |||||||||||||||||||
| 345 | \sa QMenuBar, QToolBar, QStatusBar, QDockWidget, {Application | - | ||||||||||||||||||
| 346 | Example}, {Dock Widgets Example}, {MDI Example}, {SDI Example}, | - | ||||||||||||||||||
| 347 | {Menus Example} | - | ||||||||||||||||||
| 348 | */ | - | ||||||||||||||||||
| 349 | - | |||||||||||||||||||
| 350 | /*! | - | ||||||||||||||||||
| 351 | \fn void QMainWindow::iconSizeChanged(const QSize &iconSize) | - | ||||||||||||||||||
| 352 | - | |||||||||||||||||||
| 353 | This signal is emitted when the size of the icons used in the | - | ||||||||||||||||||
| 354 | window is changed. The new icon size is passed in \a iconSize. | - | ||||||||||||||||||
| 355 | - | |||||||||||||||||||
| 356 | You can connect this signal to other components to help maintain | - | ||||||||||||||||||
| 357 | a consistent appearance for your application. | - | ||||||||||||||||||
| 358 | - | |||||||||||||||||||
| 359 | \sa setIconSize() | - | ||||||||||||||||||
| 360 | */ | - | ||||||||||||||||||
| 361 | - | |||||||||||||||||||
| 362 | /*! | - | ||||||||||||||||||
| 363 | \fn void QMainWindow::toolButtonStyleChanged(Qt::ToolButtonStyle toolButtonStyle) | - | ||||||||||||||||||
| 364 | - | |||||||||||||||||||
| 365 | This signal is emitted when the style used for tool buttons in the | - | ||||||||||||||||||
| 366 | window is changed. The new style is passed in \a toolButtonStyle. | - | ||||||||||||||||||
| 367 | - | |||||||||||||||||||
| 368 | You can connect this signal to other components to help maintain | - | ||||||||||||||||||
| 369 | a consistent appearance for your application. | - | ||||||||||||||||||
| 370 | - | |||||||||||||||||||
| 371 | \sa setToolButtonStyle() | - | ||||||||||||||||||
| 372 | */ | - | ||||||||||||||||||
| 373 | - | |||||||||||||||||||
| 374 | /*! | - | ||||||||||||||||||
| 375 | Constructs a QMainWindow with the given \a parent and the specified | - | ||||||||||||||||||
| 376 | widget \a flags. | - | ||||||||||||||||||
| 377 | - | |||||||||||||||||||
| 378 | QMainWindow sets the Qt::Window flag itself, and will hence | - | ||||||||||||||||||
| 379 | always be created as a top-level widget. | - | ||||||||||||||||||
| 380 | */ | - | ||||||||||||||||||
| 381 | QMainWindow::QMainWindow(QWidget *parent, Qt::WindowFlags flags) | - | ||||||||||||||||||
| 382 | : QWidget(*(new QMainWindowPrivate()), parent, flags | Qt::Window) | - | ||||||||||||||||||
| 383 | { | - | ||||||||||||||||||
| 384 | d_func()->init(); | - | ||||||||||||||||||
| 385 | } never executed:  end of block | 0 | ||||||||||||||||||
| 386 | - | |||||||||||||||||||
| 387 | - | |||||||||||||||||||
| 388 | /*! | - | ||||||||||||||||||
| 389 | Destroys the main window. | - | ||||||||||||||||||
| 390 | */ | - | ||||||||||||||||||
| 391 | QMainWindow::~QMainWindow() | - | ||||||||||||||||||
| 392 | { } | - | ||||||||||||||||||
| 393 | - | |||||||||||||||||||
| 394 | /*! \property QMainWindow::iconSize | - | ||||||||||||||||||
| 395 | \brief size of toolbar icons in this mainwindow. | - | ||||||||||||||||||
| 396 | - | |||||||||||||||||||
| 397 | The default is the default tool bar icon size of the GUI style. | - | ||||||||||||||||||
| 398 | Note that the icons used must be at least of this size as the | - | ||||||||||||||||||
| 399 | icons are only scaled down. | - | ||||||||||||||||||
| 400 | */ | - | ||||||||||||||||||
| 401 | - | |||||||||||||||||||
| 402 | /*! | - | ||||||||||||||||||
| 403 | \property QMainWindow::dockOptions | - | ||||||||||||||||||
| 404 | \brief the docking behavior of QMainWindow | - | ||||||||||||||||||
| 405 | \since 4.3 | - | ||||||||||||||||||
| 406 | - | |||||||||||||||||||
| 407 | The default value is AnimatedDocks | AllowTabbedDocks. | - | ||||||||||||||||||
| 408 | */ | - | ||||||||||||||||||
| 409 | - | |||||||||||||||||||
| 410 | /*! | - | ||||||||||||||||||
| 411 | \enum QMainWindow::DockOption | - | ||||||||||||||||||
| 412 | \since 4.3 | - | ||||||||||||||||||
| 413 | - | |||||||||||||||||||
| 414 | This enum contains flags that specify the docking behavior of QMainWindow. | - | ||||||||||||||||||
| 415 | - | |||||||||||||||||||
| 416 | \value AnimatedDocks Identical to the \l animated property. | - | ||||||||||||||||||
| 417 | - | |||||||||||||||||||
| 418 | \value AllowNestedDocks Identical to the \l dockNestingEnabled property. | - | ||||||||||||||||||
| 419 | - | |||||||||||||||||||
| 420 | \value AllowTabbedDocks The user can drop one dock widget "on top" of | - | ||||||||||||||||||
| 421 | another. The two widgets are stacked and a tab | - | ||||||||||||||||||
| 422 | bar appears for selecting which one is visible. | - | ||||||||||||||||||
| 423 | - | |||||||||||||||||||
| 424 | \value ForceTabbedDocks Each dock area contains a single stack of tabbed | - | ||||||||||||||||||
| 425 | dock widgets. In other words, dock widgets cannot | - | ||||||||||||||||||
| 426 | be placed next to each other in a dock area. If | - | ||||||||||||||||||
| 427 | this option is set, AllowNestedDocks has no effect. | - | ||||||||||||||||||
| 428 | - | |||||||||||||||||||
| 429 | \value VerticalTabs The two vertical dock areas on the sides of the | - | ||||||||||||||||||
| 430 | main window show their tabs vertically. If this | - | ||||||||||||||||||
| 431 | option is not set, all dock areas show their tabs | - | ||||||||||||||||||
| 432 | at the bottom. Implies AllowTabbedDocks. See also | - | ||||||||||||||||||
| 433 | \l setTabPosition(). | - | ||||||||||||||||||
| 434 | - | |||||||||||||||||||
| 435 | \value GroupedDragging When dragging the titlebar of a dock, all the tabs | - | ||||||||||||||||||
| 436 | that are tabbed with it are going to be dragged. | - | ||||||||||||||||||
| 437 | Implies AllowTabbedDocks. Does not work well if | - | ||||||||||||||||||
| 438 | some QDockWidgets have restrictions in which area | - | ||||||||||||||||||
| 439 | they are allowed. (This enum value was added in Qt | - | ||||||||||||||||||
| 440 | 5.6.) | - | ||||||||||||||||||
| 441 | - | |||||||||||||||||||
| 442 | These options only control how dock widgets may be dropped in a QMainWindow. | - | ||||||||||||||||||
| 443 | They do not re-arrange the dock widgets to conform with the specified | - | ||||||||||||||||||
| 444 | options. For this reason they should be set before any dock widgets | - | ||||||||||||||||||
| 445 | are added to the main window. Exceptions to this are the AnimatedDocks and | - | ||||||||||||||||||
| 446 | VerticalTabs options, which may be set at any time. | - | ||||||||||||||||||
| 447 | */ | - | ||||||||||||||||||
| 448 | - | |||||||||||||||||||
| 449 | void QMainWindow::setDockOptions(DockOptions opt) | - | ||||||||||||||||||
| 450 | { | - | ||||||||||||||||||
| 451 | Q_D(QMainWindow); | - | ||||||||||||||||||
| 452 | d->layout->setDockOptions(opt); | - | ||||||||||||||||||
| 453 | } never executed:  end of block | 0 | ||||||||||||||||||
| 454 | - | |||||||||||||||||||
| 455 | QMainWindow::DockOptions QMainWindow::dockOptions() const | - | ||||||||||||||||||
| 456 | { | - | ||||||||||||||||||
| 457 | Q_D(const QMainWindow); | - | ||||||||||||||||||
| 458 | return d->layout->dockOptions; never executed:  return d->layout->dockOptions; | 0 | ||||||||||||||||||
| 459 | } | - | ||||||||||||||||||
| 460 | - | |||||||||||||||||||
| 461 | QSize QMainWindow::iconSize() const | - | ||||||||||||||||||
| 462 | { never executed: return d_func()->iconSize; } return d_func()->iconSize;never executed:  return d_func()->iconSize; | 0 | ||||||||||||||||||
| 463 | - | |||||||||||||||||||
| 464 | void QMainWindow::setIconSize(const QSize &iconSize) | - | ||||||||||||||||||
| 465 | { | - | ||||||||||||||||||
| 466 | Q_D(QMainWindow); | - | ||||||||||||||||||
| 467 | QSize sz = iconSize; | - | ||||||||||||||||||
| 468 | if (!sz.isValid()) { 
 | 0 | ||||||||||||||||||
| 469 | const int metric = style()->pixelMetric(QStyle::PM_ToolBarIconSize, 0, this); | - | ||||||||||||||||||
| 470 | sz = QSize(metric, metric); | - | ||||||||||||||||||
| 471 | } never executed:  end of block | 0 | ||||||||||||||||||
| 472 | if (d->iconSize != sz) { 
 | 0 | ||||||||||||||||||
| 473 | d->iconSize = sz; | - | ||||||||||||||||||
| 474 | emit iconSizeChanged(d->iconSize); | - | ||||||||||||||||||
| 475 | } never executed:  end of block | 0 | ||||||||||||||||||
| 476 | d->explicitIconSize = iconSize.isValid(); | - | ||||||||||||||||||
| 477 | } never executed:  end of block | 0 | ||||||||||||||||||
| 478 | - | |||||||||||||||||||
| 479 | /*! \property QMainWindow::toolButtonStyle | - | ||||||||||||||||||
| 480 | \brief style of toolbar buttons in this mainwindow. | - | ||||||||||||||||||
| 481 | - | |||||||||||||||||||
| 482 | To have the style of toolbuttons follow the system settings, set this property to Qt::ToolButtonFollowStyle. | - | ||||||||||||||||||
| 483 | On Unix, the user settings from the desktop environment will be used. | - | ||||||||||||||||||
| 484 | On other platforms, Qt::ToolButtonFollowStyle means icon only. | - | ||||||||||||||||||
| 485 | - | |||||||||||||||||||
| 486 | The default is Qt::ToolButtonIconOnly. | - | ||||||||||||||||||
| 487 | */ | - | ||||||||||||||||||
| 488 | - | |||||||||||||||||||
| 489 | Qt::ToolButtonStyle QMainWindow::toolButtonStyle() const | - | ||||||||||||||||||
| 490 | { never executed: return d_func()->toolButtonStyle; } return d_func()->toolButtonStyle;never executed:  return d_func()->toolButtonStyle; | 0 | ||||||||||||||||||
| 491 | - | |||||||||||||||||||
| 492 | void QMainWindow::setToolButtonStyle(Qt::ToolButtonStyle toolButtonStyle) | - | ||||||||||||||||||
| 493 | { | - | ||||||||||||||||||
| 494 | Q_D(QMainWindow); | - | ||||||||||||||||||
| 495 | if (d->toolButtonStyle == toolButtonStyle) 
 | 0 | ||||||||||||||||||
| 496 | return; never executed:  return; | 0 | ||||||||||||||||||
| 497 | d->toolButtonStyle = toolButtonStyle; | - | ||||||||||||||||||
| 498 | emit toolButtonStyleChanged(d->toolButtonStyle); | - | ||||||||||||||||||
| 499 | } never executed:  end of block | 0 | ||||||||||||||||||
| 500 | - | |||||||||||||||||||
| 501 | #ifndef QT_NO_MENUBAR | - | ||||||||||||||||||
| 502 | /*! | - | ||||||||||||||||||
| 503 | Returns the menu bar for the main window. This function creates | - | ||||||||||||||||||
| 504 | and returns an empty menu bar if the menu bar does not exist. | - | ||||||||||||||||||
| 505 | - | |||||||||||||||||||
| 506 | If you want all windows in a Mac application to share one menu | - | ||||||||||||||||||
| 507 | bar, don't use this function to create it, because the menu bar | - | ||||||||||||||||||
| 508 | created here will have this QMainWindow as its parent. Instead, | - | ||||||||||||||||||
| 509 | you must create a menu bar that does not have a parent, which you | - | ||||||||||||||||||
| 510 | can then share among all the Mac windows. Create a parent-less | - | ||||||||||||||||||
| 511 | menu bar this way: | - | ||||||||||||||||||
| 512 | - | |||||||||||||||||||
| 513 | \snippet code/src_gui_widgets_qmenubar.cpp 1 | - | ||||||||||||||||||
| 514 | - | |||||||||||||||||||
| 515 | \sa setMenuBar() | - | ||||||||||||||||||
| 516 | */ | - | ||||||||||||||||||
| 517 | QMenuBar *QMainWindow::menuBar() const | - | ||||||||||||||||||
| 518 | { | - | ||||||||||||||||||
| 519 | QMenuBar *menuBar = qobject_cast<QMenuBar *>(layout()->menuBar()); | - | ||||||||||||||||||
| 520 | if (!menuBar) { 
 | 0 | ||||||||||||||||||
| 521 | QMainWindow *self = const_cast<QMainWindow *>(this); | - | ||||||||||||||||||
| 522 | menuBar = new QMenuBar(self); | - | ||||||||||||||||||
| 523 | self->setMenuBar(menuBar); | - | ||||||||||||||||||
| 524 | } never executed:  end of block | 0 | ||||||||||||||||||
| 525 | return menuBar; never executed:  return menuBar; | 0 | ||||||||||||||||||
| 526 | } | - | ||||||||||||||||||
| 527 | - | |||||||||||||||||||
| 528 | /*! | - | ||||||||||||||||||
| 529 | Sets the menu bar for the main window to \a menuBar. | - | ||||||||||||||||||
| 530 | - | |||||||||||||||||||
| 531 | Note: QMainWindow takes ownership of the \a menuBar pointer and | - | ||||||||||||||||||
| 532 | deletes it at the appropriate time. | - | ||||||||||||||||||
| 533 | - | |||||||||||||||||||
| 534 | \sa menuBar() | - | ||||||||||||||||||
| 535 | */ | - | ||||||||||||||||||
| 536 | void QMainWindow::setMenuBar(QMenuBar *menuBar) | - | ||||||||||||||||||
| 537 | { | - | ||||||||||||||||||
| 538 | QLayout *topLayout = layout(); | - | ||||||||||||||||||
| 539 | - | |||||||||||||||||||
| 540 | if (topLayout->menuBar() && topLayout->menuBar() != menuBar) { 
 
 | 0 | ||||||||||||||||||
| 541 | // Reparent corner widgets before we delete the old menu bar. | - | ||||||||||||||||||
| 542 | QMenuBar *oldMenuBar = qobject_cast<QMenuBar *>(topLayout->menuBar()); | - | ||||||||||||||||||
| 543 | if (menuBar) { 
 | 0 | ||||||||||||||||||
| 544 | // TopLeftCorner widget. | - | ||||||||||||||||||
| 545 | QWidget *cornerWidget = oldMenuBar->cornerWidget(Qt::TopLeftCorner); | - | ||||||||||||||||||
| 546 | if (cornerWidget) 
 | 0 | ||||||||||||||||||
| 547 | menuBar->setCornerWidget(cornerWidget, Qt::TopLeftCorner); never executed:  menuBar->setCornerWidget(cornerWidget, Qt::TopLeftCorner); | 0 | ||||||||||||||||||
| 548 | // TopRightCorner widget. | - | ||||||||||||||||||
| 549 | cornerWidget = oldMenuBar->cornerWidget(Qt::TopRightCorner); | - | ||||||||||||||||||
| 550 | if (cornerWidget) 
 | 0 | ||||||||||||||||||
| 551 | menuBar->setCornerWidget(cornerWidget, Qt::TopRightCorner); never executed:  menuBar->setCornerWidget(cornerWidget, Qt::TopRightCorner); | 0 | ||||||||||||||||||
| 552 | } never executed:  end of block | 0 | ||||||||||||||||||
| 553 | oldMenuBar->hide(); | - | ||||||||||||||||||
| 554 | oldMenuBar->deleteLater(); | - | ||||||||||||||||||
| 555 | } never executed:  end of block | 0 | ||||||||||||||||||
| 556 | topLayout->setMenuBar(menuBar); | - | ||||||||||||||||||
| 557 | } never executed:  end of block | 0 | ||||||||||||||||||
| 558 | - | |||||||||||||||||||
| 559 | /*! | - | ||||||||||||||||||
| 560 | \since 4.2 | - | ||||||||||||||||||
| 561 | - | |||||||||||||||||||
| 562 | Returns the menu bar for the main window. This function returns | - | ||||||||||||||||||
| 563 | null if a menu bar hasn't been constructed yet. | - | ||||||||||||||||||
| 564 | */ | - | ||||||||||||||||||
| 565 | QWidget *QMainWindow::menuWidget() const | - | ||||||||||||||||||
| 566 | { | - | ||||||||||||||||||
| 567 | QWidget *menuBar = d_func()->layout->menuBar(); | - | ||||||||||||||||||
| 568 | return menuBar; never executed:  return menuBar; | 0 | ||||||||||||||||||
| 569 | } | - | ||||||||||||||||||
| 570 | - | |||||||||||||||||||
| 571 | /*! | - | ||||||||||||||||||
| 572 | \since 4.2 | - | ||||||||||||||||||
| 573 | - | |||||||||||||||||||
| 574 | Sets the menu bar for the main window to \a menuBar. | - | ||||||||||||||||||
| 575 | - | |||||||||||||||||||
| 576 | QMainWindow takes ownership of the \a menuBar pointer and | - | ||||||||||||||||||
| 577 | deletes it at the appropriate time. | - | ||||||||||||||||||
| 578 | */ | - | ||||||||||||||||||
| 579 | void QMainWindow::setMenuWidget(QWidget *menuBar) | - | ||||||||||||||||||
| 580 | { | - | ||||||||||||||||||
| 581 | Q_D(QMainWindow); | - | ||||||||||||||||||
| 582 | if (d->layout->menuBar() && d->layout->menuBar() != menuBar) { 
 
 | 0 | ||||||||||||||||||
| 583 | d->layout->menuBar()->hide(); | - | ||||||||||||||||||
| 584 | d->layout->menuBar()->deleteLater(); | - | ||||||||||||||||||
| 585 | } never executed:  end of block | 0 | ||||||||||||||||||
| 586 | d->layout->setMenuBar(menuBar); | - | ||||||||||||||||||
| 587 | } never executed:  end of block | 0 | ||||||||||||||||||
| 588 | #endif // QT_NO_MENUBAR | - | ||||||||||||||||||
| 589 | - | |||||||||||||||||||
| 590 | #ifndef QT_NO_STATUSBAR | - | ||||||||||||||||||
| 591 | /*! | - | ||||||||||||||||||
| 592 | Returns the status bar for the main window. This function creates | - | ||||||||||||||||||
| 593 | and returns an empty status bar if the status bar does not exist. | - | ||||||||||||||||||
| 594 | - | |||||||||||||||||||
| 595 | \sa setStatusBar() | - | ||||||||||||||||||
| 596 | */ | - | ||||||||||||||||||
| 597 | QStatusBar *QMainWindow::statusBar() const | - | ||||||||||||||||||
| 598 | { | - | ||||||||||||||||||
| 599 | QStatusBar *statusbar = d_func()->layout->statusBar(); | - | ||||||||||||||||||
| 600 | if (!statusbar) { 
 | 0 | ||||||||||||||||||
| 601 | QMainWindow *self = const_cast<QMainWindow *>(this); | - | ||||||||||||||||||
| 602 | statusbar = new QStatusBar(self); | - | ||||||||||||||||||
| 603 | statusbar->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Fixed); | - | ||||||||||||||||||
| 604 | self->setStatusBar(statusbar); | - | ||||||||||||||||||
| 605 | } never executed:  end of block | 0 | ||||||||||||||||||
| 606 | return statusbar; never executed:  return statusbar; | 0 | ||||||||||||||||||
| 607 | } | - | ||||||||||||||||||
| 608 | - | |||||||||||||||||||
| 609 | /*! | - | ||||||||||||||||||
| 610 | Sets the status bar for the main window to \a statusbar. | - | ||||||||||||||||||
| 611 | - | |||||||||||||||||||
| 612 | Setting the status bar to 0 will remove it from the main window. | - | ||||||||||||||||||
| 613 | Note that QMainWindow takes ownership of the \a statusbar pointer | - | ||||||||||||||||||
| 614 | and deletes it at the appropriate time. | - | ||||||||||||||||||
| 615 | - | |||||||||||||||||||
| 616 | \sa statusBar() | - | ||||||||||||||||||
| 617 | */ | - | ||||||||||||||||||
| 618 | void QMainWindow::setStatusBar(QStatusBar *statusbar) | - | ||||||||||||||||||
| 619 | { | - | ||||||||||||||||||
| 620 | Q_D(QMainWindow); | - | ||||||||||||||||||
| 621 | if (d->layout->statusBar() && d->layout->statusBar() != statusbar) { 
 
 | 0 | ||||||||||||||||||
| 622 | d->layout->statusBar()->hide(); | - | ||||||||||||||||||
| 623 | d->layout->statusBar()->deleteLater(); | - | ||||||||||||||||||
| 624 | } never executed:  end of block | 0 | ||||||||||||||||||
| 625 | d->layout->setStatusBar(statusbar); | - | ||||||||||||||||||
| 626 | } never executed:  end of block | 0 | ||||||||||||||||||
| 627 | #endif // QT_NO_STATUSBAR | - | ||||||||||||||||||
| 628 | - | |||||||||||||||||||
| 629 | /*! | - | ||||||||||||||||||
| 630 | Returns the central widget for the main window. This function | - | ||||||||||||||||||
| 631 | returns zero if the central widget has not been set. | - | ||||||||||||||||||
| 632 | - | |||||||||||||||||||
| 633 | \sa setCentralWidget() | - | ||||||||||||||||||
| 634 | */ | - | ||||||||||||||||||
| 635 | QWidget *QMainWindow::centralWidget() const | - | ||||||||||||||||||
| 636 | { never executed: return d_func()->layout->centralWidget(); } return d_func()->layout->centralWidget();never executed:  return d_func()->layout->centralWidget(); | 0 | ||||||||||||||||||
| 637 | - | |||||||||||||||||||
| 638 | /*! | - | ||||||||||||||||||
| 639 | Sets the given \a widget to be the main window's central widget. | - | ||||||||||||||||||
| 640 | - | |||||||||||||||||||
| 641 | Note: QMainWindow takes ownership of the \a widget pointer and | - | ||||||||||||||||||
| 642 | deletes it at the appropriate time. | - | ||||||||||||||||||
| 643 | - | |||||||||||||||||||
| 644 | \sa centralWidget() | - | ||||||||||||||||||
| 645 | */ | - | ||||||||||||||||||
| 646 | void QMainWindow::setCentralWidget(QWidget *widget) | - | ||||||||||||||||||
| 647 | { | - | ||||||||||||||||||
| 648 | Q_D(QMainWindow); | - | ||||||||||||||||||
| 649 | if (d->layout->centralWidget() && d->layout->centralWidget() != widget) { 
 
 | 0 | ||||||||||||||||||
| 650 | d->layout->centralWidget()->hide(); | - | ||||||||||||||||||
| 651 | d->layout->centralWidget()->deleteLater(); | - | ||||||||||||||||||
| 652 | } never executed:  end of block | 0 | ||||||||||||||||||
| 653 | d->layout->setCentralWidget(widget); | - | ||||||||||||||||||
| 654 | } never executed:  end of block | 0 | ||||||||||||||||||
| 655 | - | |||||||||||||||||||
| 656 | /*! | - | ||||||||||||||||||
| 657 | Removes the central widget from this main window. | - | ||||||||||||||||||
| 658 | - | |||||||||||||||||||
| 659 | The ownership of the removed widget is passed to the caller. | - | ||||||||||||||||||
| 660 | - | |||||||||||||||||||
| 661 | \since Qt 5.2 | - | ||||||||||||||||||
| 662 | */ | - | ||||||||||||||||||
| 663 | QWidget *QMainWindow::takeCentralWidget() | - | ||||||||||||||||||
| 664 | { | - | ||||||||||||||||||
| 665 | Q_D(QMainWindow); | - | ||||||||||||||||||
| 666 | QWidget *oldcentralwidget = d->layout->centralWidget(); | - | ||||||||||||||||||
| 667 | if (oldcentralwidget) { 
 | 0 | ||||||||||||||||||
| 668 | oldcentralwidget->setParent(0); | - | ||||||||||||||||||
| 669 | d->layout->setCentralWidget(0); | - | ||||||||||||||||||
| 670 | } never executed:  end of block | 0 | ||||||||||||||||||
| 671 | return oldcentralwidget; never executed:  return oldcentralwidget; | 0 | ||||||||||||||||||
| 672 | } | - | ||||||||||||||||||
| 673 | - | |||||||||||||||||||
| 674 | #ifndef QT_NO_DOCKWIDGET | - | ||||||||||||||||||
| 675 | /*! | - | ||||||||||||||||||
| 676 | Sets the given dock widget \a area to occupy the specified \a | - | ||||||||||||||||||
| 677 | corner. | - | ||||||||||||||||||
| 678 | - | |||||||||||||||||||
| 679 | \sa corner() | - | ||||||||||||||||||
| 680 | */ | - | ||||||||||||||||||
| 681 | void QMainWindow::setCorner(Qt::Corner corner, Qt::DockWidgetArea area) | - | ||||||||||||||||||
| 682 | { | - | ||||||||||||||||||
| 683 | bool valid = false; | - | ||||||||||||||||||
| 684 | switch (corner) { | - | ||||||||||||||||||
| 685 | case Qt::TopLeftCorner: never executed:  case Qt::TopLeftCorner: | 0 | ||||||||||||||||||
| 686 | valid = (area == Qt::TopDockWidgetArea || area == Qt::LeftDockWidgetArea); 
 
 | 0 | ||||||||||||||||||
| 687 | break; never executed:  break; | 0 | ||||||||||||||||||
| 688 | case Qt::TopRightCorner: never executed:  case Qt::TopRightCorner: | 0 | ||||||||||||||||||
| 689 | valid = (area == Qt::TopDockWidgetArea || area == Qt::RightDockWidgetArea); 
 
 | 0 | ||||||||||||||||||
| 690 | break; never executed:  break; | 0 | ||||||||||||||||||
| 691 | case Qt::BottomLeftCorner: never executed:  case Qt::BottomLeftCorner: | 0 | ||||||||||||||||||
| 692 | valid = (area == Qt::BottomDockWidgetArea || area == Qt::LeftDockWidgetArea); 
 
 | 0 | ||||||||||||||||||
| 693 | break; never executed:  break; | 0 | ||||||||||||||||||
| 694 | case Qt::BottomRightCorner: never executed:  case Qt::BottomRightCorner: | 0 | ||||||||||||||||||
| 695 | valid = (area == Qt::BottomDockWidgetArea || area == Qt::RightDockWidgetArea); 
 
 | 0 | ||||||||||||||||||
| 696 | break; never executed:  break; | 0 | ||||||||||||||||||
| 697 | } | - | ||||||||||||||||||
| 698 | if (!valid) 
 | 0 | ||||||||||||||||||
| 699 | qWarning("QMainWindow::setCorner(): 'area' is not valid for 'corner'"); never executed:  QMessageLogger(__FILE__, 699, __PRETTY_FUNCTION__).warning("QMainWindow::setCorner(): 'area' is not valid for 'corner'"); | 0 | ||||||||||||||||||
| 700 | else | - | ||||||||||||||||||
| 701 | d_func()->layout->setCorner(corner, area); never executed:  d_func()->layout->setCorner(corner, area); | 0 | ||||||||||||||||||
| 702 | } | - | ||||||||||||||||||
| 703 | - | |||||||||||||||||||
| 704 | /*! | - | ||||||||||||||||||
| 705 | Returns the dock widget area that occupies the specified \a | - | ||||||||||||||||||
| 706 | corner. | - | ||||||||||||||||||
| 707 | - | |||||||||||||||||||
| 708 | \sa setCorner() | - | ||||||||||||||||||
| 709 | */ | - | ||||||||||||||||||
| 710 | Qt::DockWidgetArea QMainWindow::corner(Qt::Corner corner) const | - | ||||||||||||||||||
| 711 | { never executed: return d_func()->layout->corner(corner); } return d_func()->layout->corner(corner);never executed:  return d_func()->layout->corner(corner); | 0 | ||||||||||||||||||
| 712 | #endif | - | ||||||||||||||||||
| 713 | - | |||||||||||||||||||
| 714 | #ifndef QT_NO_TOOLBAR | - | ||||||||||||||||||
| 715 | - | |||||||||||||||||||
| 716 | static bool checkToolBarArea(Qt::ToolBarArea area, const char *where) | - | ||||||||||||||||||
| 717 | { | - | ||||||||||||||||||
| 718 | switch (area) { | - | ||||||||||||||||||
| 719 | case Qt::LeftToolBarArea: never executed:  case Qt::LeftToolBarArea: | 0 | ||||||||||||||||||
| 720 | case Qt::RightToolBarArea: never executed:  case Qt::RightToolBarArea: | 0 | ||||||||||||||||||
| 721 | case Qt::TopToolBarArea: never executed:  case Qt::TopToolBarArea: | 0 | ||||||||||||||||||
| 722 | case Qt::BottomToolBarArea: never executed:  case Qt::BottomToolBarArea: | 0 | ||||||||||||||||||
| 723 | return true; never executed:  return true; | 0 | ||||||||||||||||||
| 724 | default: never executed:  default: | 0 | ||||||||||||||||||
| 725 | break; never executed:  break; | 0 | ||||||||||||||||||
| 726 | } | - | ||||||||||||||||||
| 727 | qWarning("%s: invalid 'area' argument", where); | - | ||||||||||||||||||
| 728 | return false; never executed:  return false; | 0 | ||||||||||||||||||
| 729 | } | - | ||||||||||||||||||
| 730 | - | |||||||||||||||||||
| 731 | /*! | - | ||||||||||||||||||
| 732 | Adds a toolbar break to the given \a area after all the other | - | ||||||||||||||||||
| 733 | objects that are present. | - | ||||||||||||||||||
| 734 | */ | - | ||||||||||||||||||
| 735 | void QMainWindow::addToolBarBreak(Qt::ToolBarArea area) | - | ||||||||||||||||||
| 736 | { | - | ||||||||||||||||||
| 737 | if (!checkToolBarArea(area, "QMainWindow::addToolBarBreak")) 
 | 0 | ||||||||||||||||||
| 738 | return; never executed:  return; | 0 | ||||||||||||||||||
| 739 | d_func()->layout->addToolBarBreak(area); | - | ||||||||||||||||||
| 740 | } never executed:  end of block | 0 | ||||||||||||||||||
| 741 | - | |||||||||||||||||||
| 742 | /*! | - | ||||||||||||||||||
| 743 | Inserts a toolbar break before the toolbar specified by \a before. | - | ||||||||||||||||||
| 744 | */ | - | ||||||||||||||||||
| 745 | void QMainWindow::insertToolBarBreak(QToolBar *before) | - | ||||||||||||||||||
| 746 | { never executed: d_func()->layout->insertToolBarBreak(before); } end of blocknever executed:  end of block | 0 | ||||||||||||||||||
| 747 | - | |||||||||||||||||||
| 748 | /*! | - | ||||||||||||||||||
| 749 | Removes a toolbar break previously inserted before the toolbar specified by \a before. | - | ||||||||||||||||||
| 750 | */ | - | ||||||||||||||||||
| 751 | - | |||||||||||||||||||
| 752 | void QMainWindow::removeToolBarBreak(QToolBar *before) | - | ||||||||||||||||||
| 753 | { | - | ||||||||||||||||||
| 754 | Q_D(QMainWindow); | - | ||||||||||||||||||
| 755 | d->layout->removeToolBarBreak(before); | - | ||||||||||||||||||
| 756 | } never executed:  end of block | 0 | ||||||||||||||||||
| 757 | - | |||||||||||||||||||
| 758 | /*! | - | ||||||||||||||||||
| 759 | Adds the \a toolbar into the specified \a area in this main | - | ||||||||||||||||||
| 760 | window. The \a toolbar is placed at the end of the current tool | - | ||||||||||||||||||
| 761 | bar block (i.e. line). If the main window already manages \a toolbar | - | ||||||||||||||||||
| 762 | then it will only move the toolbar to \a area. | - | ||||||||||||||||||
| 763 | - | |||||||||||||||||||
| 764 | \sa insertToolBar(), addToolBarBreak(), insertToolBarBreak() | - | ||||||||||||||||||
| 765 | */ | - | ||||||||||||||||||
| 766 | void QMainWindow::addToolBar(Qt::ToolBarArea area, QToolBar *toolbar) | - | ||||||||||||||||||
| 767 | { | - | ||||||||||||||||||
| 768 | if (!checkToolBarArea(area, "QMainWindow::addToolBar")) 
 | 0 | ||||||||||||||||||
| 769 | return; never executed:  return; | 0 | ||||||||||||||||||
| 770 | - | |||||||||||||||||||
| 771 | Q_D(QMainWindow); | - | ||||||||||||||||||
| 772 | - | |||||||||||||||||||
| 773 | disconnect(this, SIGNAL(iconSizeChanged(QSize)), | - | ||||||||||||||||||
| 774 | toolbar, SLOT(_q_updateIconSize(QSize))); | - | ||||||||||||||||||
| 775 | disconnect(this, SIGNAL(toolButtonStyleChanged(Qt::ToolButtonStyle)), | - | ||||||||||||||||||
| 776 | toolbar, SLOT(_q_updateToolButtonStyle(Qt::ToolButtonStyle))); | - | ||||||||||||||||||
| 777 | - | |||||||||||||||||||
| 778 | if(toolbar->d_func()->state && toolbar->d_func()->state->dragging) { 
 
 | 0 | ||||||||||||||||||
| 779 | //removing a toolbar which is dragging will cause crash | - | ||||||||||||||||||
| 780 | #ifndef QT_NO_DOCKWIDGET | - | ||||||||||||||||||
| 781 | bool animated = isAnimated(); | - | ||||||||||||||||||
| 782 | setAnimated(false); | - | ||||||||||||||||||
| 783 | #endif | - | ||||||||||||||||||
| 784 | toolbar->d_func()->endDrag(); | - | ||||||||||||||||||
| 785 | #ifndef QT_NO_DOCKWIDGET | - | ||||||||||||||||||
| 786 | setAnimated(animated); | - | ||||||||||||||||||
| 787 | #endif | - | ||||||||||||||||||
| 788 | } never executed:  end of block | 0 | ||||||||||||||||||
| 789 | - | |||||||||||||||||||
| 790 | if (!d->layout->usesHIToolBar(toolbar)) { 
 | 0 | ||||||||||||||||||
| 791 | d->layout->removeWidget(toolbar); | - | ||||||||||||||||||
| 792 | } else { never executed:  end of block | 0 | ||||||||||||||||||
| 793 | d->layout->removeToolBar(toolbar); | - | ||||||||||||||||||
| 794 | } never executed:  end of block | 0 | ||||||||||||||||||
| 795 | - | |||||||||||||||||||
| 796 | toolbar->d_func()->_q_updateIconSize(d->iconSize); | - | ||||||||||||||||||
| 797 | toolbar->d_func()->_q_updateToolButtonStyle(d->toolButtonStyle); | - | ||||||||||||||||||
| 798 | connect(this, SIGNAL(iconSizeChanged(QSize)), | - | ||||||||||||||||||
| 799 | toolbar, SLOT(_q_updateIconSize(QSize))); | - | ||||||||||||||||||
| 800 | connect(this, SIGNAL(toolButtonStyleChanged(Qt::ToolButtonStyle)), | - | ||||||||||||||||||
| 801 | toolbar, SLOT(_q_updateToolButtonStyle(Qt::ToolButtonStyle))); | - | ||||||||||||||||||
| 802 | - | |||||||||||||||||||
| 803 | d->layout->addToolBar(area, toolbar); | - | ||||||||||||||||||
| 804 | } never executed:  end of block | 0 | ||||||||||||||||||
| 805 | - | |||||||||||||||||||
| 806 | /*! \overload | - | ||||||||||||||||||
| 807 | Equivalent of calling addToolBar(Qt::TopToolBarArea, \a toolbar) | - | ||||||||||||||||||
| 808 | */ | - | ||||||||||||||||||
| 809 | void QMainWindow::addToolBar(QToolBar *toolbar) | - | ||||||||||||||||||
| 810 | { never executed: addToolBar(Qt::TopToolBarArea, toolbar); } end of blocknever executed:  end of block | 0 | ||||||||||||||||||
| 811 | - | |||||||||||||||||||
| 812 | /*! | - | ||||||||||||||||||
| 813 | \overload | - | ||||||||||||||||||
| 814 | - | |||||||||||||||||||
| 815 | Creates a QToolBar object, setting its window title to \a title, | - | ||||||||||||||||||
| 816 | and inserts it into the top toolbar area. | - | ||||||||||||||||||
| 817 | - | |||||||||||||||||||
| 818 | \sa setWindowTitle() | - | ||||||||||||||||||
| 819 | */ | - | ||||||||||||||||||
| 820 | QToolBar *QMainWindow::addToolBar(const QString &title) | - | ||||||||||||||||||
| 821 | { | - | ||||||||||||||||||
| 822 | QToolBar *toolBar = new QToolBar(this); | - | ||||||||||||||||||
| 823 | toolBar->setWindowTitle(title); | - | ||||||||||||||||||
| 824 | addToolBar(toolBar); | - | ||||||||||||||||||
| 825 | return toolBar; never executed:  return toolBar; | 0 | ||||||||||||||||||
| 826 | } | - | ||||||||||||||||||
| 827 | - | |||||||||||||||||||
| 828 | /*! | - | ||||||||||||||||||
| 829 | Inserts the \a toolbar into the area occupied by the \a before toolbar | - | ||||||||||||||||||
| 830 | so that it appears before it. For example, in normal left-to-right | - | ||||||||||||||||||
| 831 | layout operation, this means that \a toolbar will appear to the left | - | ||||||||||||||||||
| 832 | of the toolbar specified by \a before in a horizontal toolbar area. | - | ||||||||||||||||||
| 833 | - | |||||||||||||||||||
| 834 | \sa insertToolBarBreak(), addToolBar(), addToolBarBreak() | - | ||||||||||||||||||
| 835 | */ | - | ||||||||||||||||||
| 836 | void QMainWindow::insertToolBar(QToolBar *before, QToolBar *toolbar) | - | ||||||||||||||||||
| 837 | { | - | ||||||||||||||||||
| 838 | Q_D(QMainWindow); | - | ||||||||||||||||||
| 839 | - | |||||||||||||||||||
| 840 | d->layout->removeToolBar(toolbar); | - | ||||||||||||||||||
| 841 | - | |||||||||||||||||||
| 842 | toolbar->d_func()->_q_updateIconSize(d->iconSize); | - | ||||||||||||||||||
| 843 | toolbar->d_func()->_q_updateToolButtonStyle(d->toolButtonStyle); | - | ||||||||||||||||||
| 844 | connect(this, SIGNAL(iconSizeChanged(QSize)), | - | ||||||||||||||||||
| 845 | toolbar, SLOT(_q_updateIconSize(QSize))); | - | ||||||||||||||||||
| 846 | connect(this, SIGNAL(toolButtonStyleChanged(Qt::ToolButtonStyle)), | - | ||||||||||||||||||
| 847 | toolbar, SLOT(_q_updateToolButtonStyle(Qt::ToolButtonStyle))); | - | ||||||||||||||||||
| 848 | - | |||||||||||||||||||
| 849 | d->layout->insertToolBar(before, toolbar); | - | ||||||||||||||||||
| 850 | } never executed:  end of block | 0 | ||||||||||||||||||
| 851 | - | |||||||||||||||||||
| 852 | /*! | - | ||||||||||||||||||
| 853 | Removes the \a toolbar from the main window layout and hides | - | ||||||||||||||||||
| 854 | it. Note that the \a toolbar is \e not deleted. | - | ||||||||||||||||||
| 855 | */ | - | ||||||||||||||||||
| 856 | void QMainWindow::removeToolBar(QToolBar *toolbar) | - | ||||||||||||||||||
| 857 | { | - | ||||||||||||||||||
| 858 | if (toolbar) { 
 | 0 | ||||||||||||||||||
| 859 | d_func()->layout->removeToolBar(toolbar); | - | ||||||||||||||||||
| 860 | toolbar->hide(); | - | ||||||||||||||||||
| 861 | } never executed:  end of block | 0 | ||||||||||||||||||
| 862 | } never executed:  end of block | 0 | ||||||||||||||||||
| 863 | - | |||||||||||||||||||
| 864 | /*! | - | ||||||||||||||||||
| 865 | Returns the Qt::ToolBarArea for \a toolbar. If \a toolbar has not | - | ||||||||||||||||||
| 866 | been added to the main window, this function returns \c | - | ||||||||||||||||||
| 867 | Qt::NoToolBarArea. | - | ||||||||||||||||||
| 868 | - | |||||||||||||||||||
| 869 | \sa addToolBar(), addToolBarBreak(), Qt::ToolBarArea | - | ||||||||||||||||||
| 870 | */ | - | ||||||||||||||||||
| 871 | Qt::ToolBarArea QMainWindow::toolBarArea(QToolBar *toolbar) const | - | ||||||||||||||||||
| 872 | { never executed: return d_func()->layout->toolBarArea(toolbar); } return d_func()->layout->toolBarArea(toolbar);never executed:  return d_func()->layout->toolBarArea(toolbar); | 0 | ||||||||||||||||||
| 873 | - | |||||||||||||||||||
| 874 | /*! | - | ||||||||||||||||||
| 875 | - | |||||||||||||||||||
| 876 | Returns whether there is a toolbar | - | ||||||||||||||||||
| 877 | break before the \a toolbar. | - | ||||||||||||||||||
| 878 | - | |||||||||||||||||||
| 879 | \sa addToolBarBreak(), insertToolBarBreak() | - | ||||||||||||||||||
| 880 | */ | - | ||||||||||||||||||
| 881 | bool QMainWindow::toolBarBreak(QToolBar *toolbar) const | - | ||||||||||||||||||
| 882 | { | - | ||||||||||||||||||
| 883 | return d_func()->layout->toolBarBreak(toolbar); never executed:  return d_func()->layout->toolBarBreak(toolbar); | 0 | ||||||||||||||||||
| 884 | } | - | ||||||||||||||||||
| 885 | - | |||||||||||||||||||
| 886 | #endif // QT_NO_TOOLBAR | - | ||||||||||||||||||
| 887 | - | |||||||||||||||||||
| 888 | #ifndef QT_NO_DOCKWIDGET | - | ||||||||||||||||||
| 889 | - | |||||||||||||||||||
| 890 | /*! \property QMainWindow::animated | - | ||||||||||||||||||
| 891 | \brief whether manipulating dock widgets and tool bars is animated | - | ||||||||||||||||||
| 892 | \since 4.2 | - | ||||||||||||||||||
| 893 | - | |||||||||||||||||||
| 894 | When a dock widget or tool bar is dragged over the | - | ||||||||||||||||||
| 895 | main window, the main window adjusts its contents | - | ||||||||||||||||||
| 896 | to indicate where the dock widget or tool bar will | - | ||||||||||||||||||
| 897 | be docked if it is dropped. Setting this property | - | ||||||||||||||||||
| 898 | causes QMainWindow to move its contents in a smooth | - | ||||||||||||||||||
| 899 | animation. Clearing this property causes the contents | - | ||||||||||||||||||
| 900 | to snap into their new positions. | - | ||||||||||||||||||
| 901 | - | |||||||||||||||||||
| 902 | By default, this property is set. It may be cleared if | - | ||||||||||||||||||
| 903 | the main window contains widgets which are slow at resizing | - | ||||||||||||||||||
| 904 | or repainting themselves. | - | ||||||||||||||||||
| 905 | - | |||||||||||||||||||
| 906 | Setting this property is identical to setting the AnimatedDocks | - | ||||||||||||||||||
| 907 | option using setDockOptions(). | - | ||||||||||||||||||
| 908 | */ | - | ||||||||||||||||||
| 909 | - | |||||||||||||||||||
| 910 | bool QMainWindow::isAnimated() const | - | ||||||||||||||||||
| 911 | { | - | ||||||||||||||||||
| 912 | Q_D(const QMainWindow); | - | ||||||||||||||||||
| 913 | return d->layout->dockOptions & AnimatedDocks; never executed:  return d->layout->dockOptions & AnimatedDocks; | 0 | ||||||||||||||||||
| 914 | } | - | ||||||||||||||||||
| 915 | - | |||||||||||||||||||
| 916 | void QMainWindow::setAnimated(bool enabled) | - | ||||||||||||||||||
| 917 | { | - | ||||||||||||||||||
| 918 | Q_D(QMainWindow); | - | ||||||||||||||||||
| 919 | - | |||||||||||||||||||
| 920 | DockOptions opts = d->layout->dockOptions; | - | ||||||||||||||||||
| 921 | if (enabled) 
 | 0 | ||||||||||||||||||
| 922 | opts |= AnimatedDocks; never executed:  opts |= AnimatedDocks; | 0 | ||||||||||||||||||
| 923 | else | - | ||||||||||||||||||
| 924 | opts &= ~AnimatedDocks; never executed:  opts &= ~AnimatedDocks; | 0 | ||||||||||||||||||
| 925 | - | |||||||||||||||||||
| 926 | d->layout->setDockOptions(opts); | - | ||||||||||||||||||
| 927 | } never executed:  end of block | 0 | ||||||||||||||||||
| 928 | - | |||||||||||||||||||
| 929 | /*! \property QMainWindow::dockNestingEnabled | - | ||||||||||||||||||
| 930 | \brief whether docks can be nested | - | ||||||||||||||||||
| 931 | \since 4.2 | - | ||||||||||||||||||
| 932 | - | |||||||||||||||||||
| 933 | If this property is \c false, dock areas can only contain a single row | - | ||||||||||||||||||
| 934 | (horizontal or vertical) of dock widgets. If this property is \c true, | - | ||||||||||||||||||
| 935 | the area occupied by a dock widget can be split in either direction to contain | - | ||||||||||||||||||
| 936 | more dock widgets. | - | ||||||||||||||||||
| 937 | - | |||||||||||||||||||
| 938 | Dock nesting is only necessary in applications that contain a lot of | - | ||||||||||||||||||
| 939 | dock widgets. It gives the user greater freedom in organizing their | - | ||||||||||||||||||
| 940 | main window. However, dock nesting leads to more complex | - | ||||||||||||||||||
| 941 | (and less intuitive) behavior when a dock widget is dragged over the | - | ||||||||||||||||||
| 942 | main window, since there are more ways in which a dropped dock widget | - | ||||||||||||||||||
| 943 | may be placed in the dock area. | - | ||||||||||||||||||
| 944 | - | |||||||||||||||||||
| 945 | Setting this property is identical to setting the AllowNestedDocks option | - | ||||||||||||||||||
| 946 | using setDockOptions(). | - | ||||||||||||||||||
| 947 | */ | - | ||||||||||||||||||
| 948 | - | |||||||||||||||||||
| 949 | bool QMainWindow::isDockNestingEnabled() const | - | ||||||||||||||||||
| 950 | { | - | ||||||||||||||||||
| 951 | Q_D(const QMainWindow); | - | ||||||||||||||||||
| 952 | return d->layout->dockOptions & AllowNestedDocks; never executed:  return d->layout->dockOptions & AllowNestedDocks; | 0 | ||||||||||||||||||
| 953 | } | - | ||||||||||||||||||
| 954 | - | |||||||||||||||||||
| 955 | void QMainWindow::setDockNestingEnabled(bool enabled) | - | ||||||||||||||||||
| 956 | { | - | ||||||||||||||||||
| 957 | Q_D(QMainWindow); | - | ||||||||||||||||||
| 958 | - | |||||||||||||||||||
| 959 | DockOptions opts = d->layout->dockOptions; | - | ||||||||||||||||||
| 960 | if (enabled) 
 | 0 | ||||||||||||||||||
| 961 | opts |= AllowNestedDocks; never executed:  opts |= AllowNestedDocks; | 0 | ||||||||||||||||||
| 962 | else | - | ||||||||||||||||||
| 963 | opts &= ~AllowNestedDocks; never executed:  opts &= ~AllowNestedDocks; | 0 | ||||||||||||||||||
| 964 | - | |||||||||||||||||||
| 965 | d->layout->setDockOptions(opts); | - | ||||||||||||||||||
| 966 | } never executed:  end of block | 0 | ||||||||||||||||||
| 967 | - | |||||||||||||||||||
| 968 | #if 0 | - | ||||||||||||||||||
| 969 | /*! \property QMainWindow::verticalTabsEnabled | - | ||||||||||||||||||
| 970 | \brief whether left and right dock areas use vertical tabs | - | ||||||||||||||||||
| 971 | \since 4.2 | - | ||||||||||||||||||
| 972 | - | |||||||||||||||||||
| 973 | If this property is set to false, dock areas containing tabbed dock widgets | - | ||||||||||||||||||
| 974 | display horizontal tabs, simmilar to Visual Studio. | - | ||||||||||||||||||
| 975 | - | |||||||||||||||||||
| 976 | If this property is set to true, then the right and left dock areas display vertical | - | ||||||||||||||||||
| 977 | tabs, simmilar to KDevelop. | - | ||||||||||||||||||
| 978 | - | |||||||||||||||||||
| 979 | This property should be set before any dock widgets are added to the main window. | - | ||||||||||||||||||
| 980 | */ | - | ||||||||||||||||||
| 981 | - | |||||||||||||||||||
| 982 | bool QMainWindow::verticalTabsEnabled() const | - | ||||||||||||||||||
| 983 | { | - | ||||||||||||||||||
| 984 | return d_func()->layout->verticalTabsEnabled(); | - | ||||||||||||||||||
| 985 | } | - | ||||||||||||||||||
| 986 | - | |||||||||||||||||||
| 987 | void QMainWindow::setVerticalTabsEnabled(bool enabled) | - | ||||||||||||||||||
| 988 | { | - | ||||||||||||||||||
| 989 | d_func()->layout->setVerticalTabsEnabled(enabled); | - | ||||||||||||||||||
| 990 | } | - | ||||||||||||||||||
| 991 | #endif | - | ||||||||||||||||||
| 992 | - | |||||||||||||||||||
| 993 | static bool checkDockWidgetArea(Qt::DockWidgetArea area, const char *where) | - | ||||||||||||||||||
| 994 | { | - | ||||||||||||||||||
| 995 | switch (area) { | - | ||||||||||||||||||
| 996 | case Qt::LeftDockWidgetArea: never executed:  case Qt::LeftDockWidgetArea: | 0 | ||||||||||||||||||
| 997 | case Qt::RightDockWidgetArea: never executed:  case Qt::RightDockWidgetArea: | 0 | ||||||||||||||||||
| 998 | case Qt::TopDockWidgetArea: never executed:  case Qt::TopDockWidgetArea: | 0 | ||||||||||||||||||
| 999 | case Qt::BottomDockWidgetArea: never executed:  case Qt::BottomDockWidgetArea: | 0 | ||||||||||||||||||
| 1000 | return true; never executed:  return true; | 0 | ||||||||||||||||||
| 1001 | default: never executed:  default: | 0 | ||||||||||||||||||
| 1002 | break; never executed:  break; | 0 | ||||||||||||||||||
| 1003 | } | - | ||||||||||||||||||
| 1004 | qWarning("%s: invalid 'area' argument", where); | - | ||||||||||||||||||
| 1005 | return false; never executed:  return false; | 0 | ||||||||||||||||||
| 1006 | } | - | ||||||||||||||||||
| 1007 | - | |||||||||||||||||||
| 1008 | #ifndef QT_NO_TABBAR | - | ||||||||||||||||||
| 1009 | /*! | - | ||||||||||||||||||
| 1010 | \property QMainWindow::documentMode | - | ||||||||||||||||||
| 1011 | \brief whether the tab bar for tabbed dockwidgets is set to document mode. | - | ||||||||||||||||||
| 1012 | \since 4.5 | - | ||||||||||||||||||
| 1013 | - | |||||||||||||||||||
| 1014 | The default is false. | - | ||||||||||||||||||
| 1015 | - | |||||||||||||||||||
| 1016 | \sa QTabBar::documentMode | - | ||||||||||||||||||
| 1017 | */ | - | ||||||||||||||||||
| 1018 | bool QMainWindow::documentMode() const | - | ||||||||||||||||||
| 1019 | { | - | ||||||||||||||||||
| 1020 | return d_func()->layout->documentMode(); never executed:  return d_func()->layout->documentMode(); | 0 | ||||||||||||||||||
| 1021 | } | - | ||||||||||||||||||
| 1022 | - | |||||||||||||||||||
| 1023 | void QMainWindow::setDocumentMode(bool enabled) | - | ||||||||||||||||||
| 1024 | { | - | ||||||||||||||||||
| 1025 | d_func()->layout->setDocumentMode(enabled); | - | ||||||||||||||||||
| 1026 | } never executed:  end of block | 0 | ||||||||||||||||||
| 1027 | #endif // QT_NO_TABBAR | - | ||||||||||||||||||
| 1028 | - | |||||||||||||||||||
| 1029 | #ifndef QT_NO_TABWIDGET | - | ||||||||||||||||||
| 1030 | /*! | - | ||||||||||||||||||
| 1031 | \property QMainWindow::tabShape | - | ||||||||||||||||||
| 1032 | \brief the tab shape used for tabbed dock widgets. | - | ||||||||||||||||||
| 1033 | \since 4.5 | - | ||||||||||||||||||
| 1034 | - | |||||||||||||||||||
| 1035 | The default is \l QTabWidget::Rounded. | - | ||||||||||||||||||
| 1036 | - | |||||||||||||||||||
| 1037 | \sa setTabPosition() | - | ||||||||||||||||||
| 1038 | */ | - | ||||||||||||||||||
| 1039 | QTabWidget::TabShape QMainWindow::tabShape() const | - | ||||||||||||||||||
| 1040 | { | - | ||||||||||||||||||
| 1041 | return d_func()->layout->tabShape(); never executed:  return d_func()->layout->tabShape(); | 0 | ||||||||||||||||||
| 1042 | } | - | ||||||||||||||||||
| 1043 | - | |||||||||||||||||||
| 1044 | void QMainWindow::setTabShape(QTabWidget::TabShape tabShape) | - | ||||||||||||||||||
| 1045 | { | - | ||||||||||||||||||
| 1046 | d_func()->layout->setTabShape(tabShape); | - | ||||||||||||||||||
| 1047 | } never executed:  end of block | 0 | ||||||||||||||||||
| 1048 | - | |||||||||||||||||||
| 1049 | /*! | - | ||||||||||||||||||
| 1050 | \since 4.5 | - | ||||||||||||||||||
| 1051 | - | |||||||||||||||||||
| 1052 | Returns the tab position for \a area. | - | ||||||||||||||||||
| 1053 | - | |||||||||||||||||||
| 1054 | \note The \l VerticalTabs dock option overrides the tab positions returned | - | ||||||||||||||||||
| 1055 | by this function. | - | ||||||||||||||||||
| 1056 | - | |||||||||||||||||||
| 1057 | \sa setTabPosition(), tabShape() | - | ||||||||||||||||||
| 1058 | */ | - | ||||||||||||||||||
| 1059 | QTabWidget::TabPosition QMainWindow::tabPosition(Qt::DockWidgetArea area) const | - | ||||||||||||||||||
| 1060 | { | - | ||||||||||||||||||
| 1061 | if (!checkDockWidgetArea(area, "QMainWindow::tabPosition")) 
 | 0 | ||||||||||||||||||
| 1062 | return QTabWidget::South; never executed:  return QTabWidget::South; | 0 | ||||||||||||||||||
| 1063 | return d_func()->layout->tabPosition(area); never executed:  return d_func()->layout->tabPosition(area); | 0 | ||||||||||||||||||
| 1064 | } | - | ||||||||||||||||||
| 1065 | - | |||||||||||||||||||
| 1066 | /*! | - | ||||||||||||||||||
| 1067 | \since 4.5 | - | ||||||||||||||||||
| 1068 | - | |||||||||||||||||||
| 1069 | Sets the tab position for the given dock widget \a areas to the specified | - | ||||||||||||||||||
| 1070 | \a tabPosition. By default, all dock areas show their tabs at the bottom. | - | ||||||||||||||||||
| 1071 | - | |||||||||||||||||||
| 1072 | \note The \l VerticalTabs dock option overrides the tab positions set by | - | ||||||||||||||||||
| 1073 | this method. | - | ||||||||||||||||||
| 1074 | - | |||||||||||||||||||
| 1075 | \sa tabPosition(), setTabShape() | - | ||||||||||||||||||
| 1076 | */ | - | ||||||||||||||||||
| 1077 | void QMainWindow::setTabPosition(Qt::DockWidgetAreas areas, QTabWidget::TabPosition tabPosition) | - | ||||||||||||||||||
| 1078 | { | - | ||||||||||||||||||
| 1079 | d_func()->layout->setTabPosition(areas, tabPosition); | - | ||||||||||||||||||
| 1080 | } never executed:  end of block | 0 | ||||||||||||||||||
| 1081 | #endif // QT_NO_TABWIDGET | - | ||||||||||||||||||
| 1082 | - | |||||||||||||||||||
| 1083 | /*! | - | ||||||||||||||||||
| 1084 | Adds the given \a dockwidget to the specified \a area. | - | ||||||||||||||||||
| 1085 | */ | - | ||||||||||||||||||
| 1086 | void QMainWindow::addDockWidget(Qt::DockWidgetArea area, QDockWidget *dockwidget) | - | ||||||||||||||||||
| 1087 | { | - | ||||||||||||||||||
| 1088 | if (!checkDockWidgetArea(area, "QMainWindow::addDockWidget")) 
 | 0 | ||||||||||||||||||
| 1089 | return; never executed:  return; | 0 | ||||||||||||||||||
| 1090 | - | |||||||||||||||||||
| 1091 | Qt::Orientation orientation = Qt::Vertical; | - | ||||||||||||||||||
| 1092 | switch (area) { | - | ||||||||||||||||||
| 1093 | case Qt::TopDockWidgetArea: never executed:  case Qt::TopDockWidgetArea: | 0 | ||||||||||||||||||
| 1094 | case Qt::BottomDockWidgetArea: never executed:  case Qt::BottomDockWidgetArea: | 0 | ||||||||||||||||||
| 1095 | orientation = Qt::Horizontal; | - | ||||||||||||||||||
| 1096 | break; never executed:  break; | 0 | ||||||||||||||||||
| 1097 | default: never executed:  default: | 0 | ||||||||||||||||||
| 1098 | break; never executed:  break; | 0 | ||||||||||||||||||
| 1099 | } | - | ||||||||||||||||||
| 1100 | d_func()->layout->removeWidget(dockwidget); // in case it was already in here | - | ||||||||||||||||||
| 1101 | addDockWidget(area, dockwidget, orientation); | - | ||||||||||||||||||
| 1102 | - | |||||||||||||||||||
| 1103 | #ifdef Q_DEAD_CODE_FROM_QT4_MAC //drawer support | - | ||||||||||||||||||
| 1104 | QMacAutoReleasePool pool; | - | ||||||||||||||||||
| 1105 | extern bool qt_mac_is_macdrawer(const QWidget *); //qwidget_mac.cpp | - | ||||||||||||||||||
| 1106 | if (qt_mac_is_macdrawer(dockwidget)) { | - | ||||||||||||||||||
| 1107 | extern bool qt_mac_set_drawer_preferred_edge(QWidget *, Qt::DockWidgetArea); //qwidget_mac.cpp | - | ||||||||||||||||||
| 1108 | window()->createWinId(); | - | ||||||||||||||||||
| 1109 | dockwidget->window()->createWinId(); | - | ||||||||||||||||||
| 1110 | qt_mac_set_drawer_preferred_edge(dockwidget, area); | - | ||||||||||||||||||
| 1111 | if (dockwidget->isVisible()) { | - | ||||||||||||||||||
| 1112 | dockwidget->hide(); | - | ||||||||||||||||||
| 1113 | dockwidget->show(); | - | ||||||||||||||||||
| 1114 | } | - | ||||||||||||||||||
| 1115 | } | - | ||||||||||||||||||
| 1116 | #endif | - | ||||||||||||||||||
| 1117 | } never executed:  end of block | 0 | ||||||||||||||||||
| 1118 | - | |||||||||||||||||||
| 1119 | /*! | - | ||||||||||||||||||
| 1120 | Restores the state of \a dockwidget if it is created after the call | - | ||||||||||||||||||
| 1121 | to restoreState(). Returns \c true if the state was restored; otherwise | - | ||||||||||||||||||
| 1122 | returns \c false. | - | ||||||||||||||||||
| 1123 | - | |||||||||||||||||||
| 1124 | \sa restoreState(), saveState() | - | ||||||||||||||||||
| 1125 | */ | - | ||||||||||||||||||
| 1126 | - | |||||||||||||||||||
| 1127 | bool QMainWindow::restoreDockWidget(QDockWidget *dockwidget) | - | ||||||||||||||||||
| 1128 | { | - | ||||||||||||||||||
| 1129 | return d_func()->layout->restoreDockWidget(dockwidget); never executed:  return d_func()->layout->restoreDockWidget(dockwidget); | 0 | ||||||||||||||||||
| 1130 | } | - | ||||||||||||||||||
| 1131 | - | |||||||||||||||||||
| 1132 | /*! | - | ||||||||||||||||||
| 1133 | Adds \a dockwidget into the given \a area in the direction | - | ||||||||||||||||||
| 1134 | specified by the \a orientation. | - | ||||||||||||||||||
| 1135 | */ | - | ||||||||||||||||||
| 1136 | void QMainWindow::addDockWidget(Qt::DockWidgetArea area, QDockWidget *dockwidget, | - | ||||||||||||||||||
| 1137 | Qt::Orientation orientation) | - | ||||||||||||||||||
| 1138 | { | - | ||||||||||||||||||
| 1139 | if (!checkDockWidgetArea(area, "QMainWindow::addDockWidget")) 
 | 0 | ||||||||||||||||||
| 1140 | return; never executed:  return; | 0 | ||||||||||||||||||
| 1141 | - | |||||||||||||||||||
| 1142 | // add a window to an area, placing done relative to the previous | - | ||||||||||||||||||
| 1143 | d_func()->layout->addDockWidget(area, dockwidget, orientation); | - | ||||||||||||||||||
| 1144 | } never executed:  end of block | 0 | ||||||||||||||||||
| 1145 | - | |||||||||||||||||||
| 1146 | /*! | - | ||||||||||||||||||
| 1147 | \fn void QMainWindow::splitDockWidget(QDockWidget *first, QDockWidget *second, Qt::Orientation orientation) | - | ||||||||||||||||||
| 1148 | - | |||||||||||||||||||
| 1149 | Splits the space covered by the \a first dock widget into two parts, | - | ||||||||||||||||||
| 1150 | moves the \a first dock widget into the first part, and moves the | - | ||||||||||||||||||
| 1151 | \a second dock widget into the second part. | - | ||||||||||||||||||
| 1152 | - | |||||||||||||||||||
| 1153 | The \a orientation specifies how the space is divided: A Qt::Horizontal | - | ||||||||||||||||||
| 1154 | split places the second dock widget to the right of the first; a | - | ||||||||||||||||||
| 1155 | Qt::Vertical split places the second dock widget below the first. | - | ||||||||||||||||||
| 1156 | - | |||||||||||||||||||
| 1157 | \e Note: if \a first is currently in a tabbed docked area, \a second will | - | ||||||||||||||||||
| 1158 | be added as a new tab, not as a neighbor of \a first. This is because a | - | ||||||||||||||||||
| 1159 | single tab can contain only one dock widget. | - | ||||||||||||||||||
| 1160 | - | |||||||||||||||||||
| 1161 | \e Note: The Qt::LayoutDirection influences the order of the dock widgets | - | ||||||||||||||||||
| 1162 | in the two parts of the divided area. When right-to-left layout direction | - | ||||||||||||||||||
| 1163 | is enabled, the placing of the dock widgets will be reversed. | - | ||||||||||||||||||
| 1164 | - | |||||||||||||||||||
| 1165 | \sa tabifyDockWidget(), addDockWidget(), removeDockWidget() | - | ||||||||||||||||||
| 1166 | */ | - | ||||||||||||||||||
| 1167 | void QMainWindow::splitDockWidget(QDockWidget *after, QDockWidget *dockwidget, | - | ||||||||||||||||||
| 1168 | Qt::Orientation orientation) | - | ||||||||||||||||||
| 1169 | { | - | ||||||||||||||||||
| 1170 | d_func()->layout->splitDockWidget(after, dockwidget, orientation); | - | ||||||||||||||||||
| 1171 | } never executed:  end of block | 0 | ||||||||||||||||||
| 1172 | - | |||||||||||||||||||
| 1173 | /*! | - | ||||||||||||||||||
| 1174 | \fn void QMainWindow::tabifyDockWidget(QDockWidget *first, QDockWidget *second) | - | ||||||||||||||||||
| 1175 | - | |||||||||||||||||||
| 1176 | Moves \a second dock widget on top of \a first dock widget, creating a tabbed | - | ||||||||||||||||||
| 1177 | docked area in the main window. | - | ||||||||||||||||||
| 1178 | - | |||||||||||||||||||
| 1179 | \sa tabifiedDockWidgets() | - | ||||||||||||||||||
| 1180 | */ | - | ||||||||||||||||||
| 1181 | void QMainWindow::tabifyDockWidget(QDockWidget *first, QDockWidget *second) | - | ||||||||||||||||||
| 1182 | { | - | ||||||||||||||||||
| 1183 | d_func()->layout->tabifyDockWidget(first, second); | - | ||||||||||||||||||
| 1184 | } never executed:  end of block | 0 | ||||||||||||||||||
| 1185 | - | |||||||||||||||||||
| 1186 | - | |||||||||||||||||||
| 1187 | /*! | - | ||||||||||||||||||
| 1188 | \fn QList<QDockWidget*> QMainWindow::tabifiedDockWidgets(QDockWidget *dockwidget) const | - | ||||||||||||||||||
| 1189 | - | |||||||||||||||||||
| 1190 | Returns the dock widgets that are tabified together with \a dockwidget. | - | ||||||||||||||||||
| 1191 | - | |||||||||||||||||||
| 1192 | \since 4.5 | - | ||||||||||||||||||
| 1193 | \sa tabifyDockWidget() | - | ||||||||||||||||||
| 1194 | */ | - | ||||||||||||||||||
| 1195 | - | |||||||||||||||||||
| 1196 | QList<QDockWidget*> QMainWindow::tabifiedDockWidgets(QDockWidget *dockwidget) const | - | ||||||||||||||||||
| 1197 | { | - | ||||||||||||||||||
| 1198 | QList<QDockWidget*> ret; | - | ||||||||||||||||||
| 1199 | #if defined(QT_NO_TABBAR) | - | ||||||||||||||||||
| 1200 | Q_UNUSED(dockwidget); | - | ||||||||||||||||||
| 1201 | #else | - | ||||||||||||||||||
| 1202 | const QDockAreaLayoutInfo *info = d_func()->layout->layoutState.dockAreaLayout.info(dockwidget); | - | ||||||||||||||||||
| 1203 | if (info && info->tabbed && info->tabBar) { 
 
 
 | 0 | ||||||||||||||||||
| 1204 | for(int i = 0; i < info->item_list.count(); ++i) { 
 | 0 | ||||||||||||||||||
| 1205 | const QDockAreaLayoutItem &item = info->item_list.at(i); | - | ||||||||||||||||||
| 1206 | if (item.widgetItem) { 
 | 0 | ||||||||||||||||||
| 1207 | if (QDockWidget *dock = qobject_cast<QDockWidget*>(item.widgetItem->widget())) { 
 | 0 | ||||||||||||||||||
| 1208 | if (dock != dockwidget) { 
 | 0 | ||||||||||||||||||
| 1209 | ret += dock; | - | ||||||||||||||||||
| 1210 | } never executed:  end of block | 0 | ||||||||||||||||||
| 1211 | } never executed:  end of block | 0 | ||||||||||||||||||
| 1212 | } never executed:  end of block | 0 | ||||||||||||||||||
| 1213 | } never executed:  end of block | 0 | ||||||||||||||||||
| 1214 | } never executed:  end of block | 0 | ||||||||||||||||||
| 1215 | #endif | - | ||||||||||||||||||
| 1216 | return ret; never executed:  return ret; | 0 | ||||||||||||||||||
| 1217 | } | - | ||||||||||||||||||
| 1218 | - | |||||||||||||||||||
| 1219 | - | |||||||||||||||||||
| 1220 | /*! | - | ||||||||||||||||||
| 1221 | Removes the \a dockwidget from the main window layout and hides | - | ||||||||||||||||||
| 1222 | it. Note that the \a dockwidget is \e not deleted. | - | ||||||||||||||||||
| 1223 | */ | - | ||||||||||||||||||
| 1224 | void QMainWindow::removeDockWidget(QDockWidget *dockwidget) | - | ||||||||||||||||||
| 1225 | { | - | ||||||||||||||||||
| 1226 | if (dockwidget) { 
 | 0 | ||||||||||||||||||
| 1227 | d_func()->layout->removeWidget(dockwidget); | - | ||||||||||||||||||
| 1228 | dockwidget->hide(); | - | ||||||||||||||||||
| 1229 | } never executed:  end of block | 0 | ||||||||||||||||||
| 1230 | } never executed:  end of block | 0 | ||||||||||||||||||
| 1231 | - | |||||||||||||||||||
| 1232 | /*! | - | ||||||||||||||||||
| 1233 | Returns the Qt::DockWidgetArea for \a dockwidget. If \a dockwidget | - | ||||||||||||||||||
| 1234 | has not been added to the main window, this function returns \c | - | ||||||||||||||||||
| 1235 | Qt::NoDockWidgetArea. | - | ||||||||||||||||||
| 1236 | - | |||||||||||||||||||
| 1237 | \sa addDockWidget(), splitDockWidget(), Qt::DockWidgetArea | - | ||||||||||||||||||
| 1238 | */ | - | ||||||||||||||||||
| 1239 | Qt::DockWidgetArea QMainWindow::dockWidgetArea(QDockWidget *dockwidget) const | - | ||||||||||||||||||
| 1240 | { never executed: return d_func()->layout->dockWidgetArea(dockwidget); } return d_func()->layout->dockWidgetArea(dockwidget);never executed:  return d_func()->layout->dockWidgetArea(dockwidget); | 0 | ||||||||||||||||||
| 1241 | - | |||||||||||||||||||
| 1242 | - | |||||||||||||||||||
| 1243 | /*! | - | ||||||||||||||||||
| 1244 | \since 5.6 | - | ||||||||||||||||||
| 1245 | Resizes the dock widgets in the list \a docks to the corresponding size in | - | ||||||||||||||||||
| 1246 | pixels from the list \a sizes. If \a orientation is Qt::Horizontal, adjusts | - | ||||||||||||||||||
| 1247 | the width, otherwise adjusts the height of the dock widgets. | - | ||||||||||||||||||
| 1248 | The sizes will be adjusted such that the maximum and the minimum sizes are | - | ||||||||||||||||||
| 1249 | respected and the QMainWindow itself will not be resized. | - | ||||||||||||||||||
| 1250 | Any additional/missing space is distributed amongst the widgets according | - | ||||||||||||||||||
| 1251 | to the relative weight of the sizes. | - | ||||||||||||||||||
| 1252 | - | |||||||||||||||||||
| 1253 | Example: | - | ||||||||||||||||||
| 1254 | \code | - | ||||||||||||||||||
| 1255 | resizeDocks({blueWidget, yellowWidget}, {20 , 40}, Qt::Horizontal); | - | ||||||||||||||||||
| 1256 | \endcode | - | ||||||||||||||||||
| 1257 | If the blue and the yellow widget are nested on the same level they will be | - | ||||||||||||||||||
| 1258 | resized such that the yellowWidget is twice as big as the blueWidget | - | ||||||||||||||||||
| 1259 | - | |||||||||||||||||||
| 1260 | If some widgets are grouped in tabs, only one widget per group should be | - | ||||||||||||||||||
| 1261 | specified. Widgets not in the list might be changed to repect the constraints. | - | ||||||||||||||||||
| 1262 | */ | - | ||||||||||||||||||
| 1263 | void QMainWindow::resizeDocks(const QList<QDockWidget *> &docks, | - | ||||||||||||||||||
| 1264 | const QList<int> &sizes, Qt::Orientation orientation) | - | ||||||||||||||||||
| 1265 | { | - | ||||||||||||||||||
| 1266 | d_func()->layout->layoutState.dockAreaLayout.resizeDocks(docks, sizes, orientation); | - | ||||||||||||||||||
| 1267 | d_func()->layout->invalidate(); | - | ||||||||||||||||||
| 1268 | } never executed:  end of block | 0 | ||||||||||||||||||
| 1269 | - | |||||||||||||||||||
| 1270 | - | |||||||||||||||||||
| 1271 | #endif // QT_NO_DOCKWIDGET | - | ||||||||||||||||||
| 1272 | - | |||||||||||||||||||
| 1273 | /*! | - | ||||||||||||||||||
| 1274 | Saves the current state of this mainwindow's toolbars and | - | ||||||||||||||||||
| 1275 | dockwidgets. This includes the corner settings which can | - | ||||||||||||||||||
| 1276 | be set with setCorner(). The \a version number is stored | - | ||||||||||||||||||
| 1277 | as part of the data. | - | ||||||||||||||||||
| 1278 | - | |||||||||||||||||||
| 1279 | The \l{QObject::objectName}{objectName} property is used | - | ||||||||||||||||||
| 1280 | to identify each QToolBar and QDockWidget. You should make sure | - | ||||||||||||||||||
| 1281 | that this property is unique for each QToolBar and QDockWidget you | - | ||||||||||||||||||
| 1282 | add to the QMainWindow | - | ||||||||||||||||||
| 1283 | - | |||||||||||||||||||
| 1284 | To restore the saved state, pass the return value and \a version | - | ||||||||||||||||||
| 1285 | number to restoreState(). | - | ||||||||||||||||||
| 1286 | - | |||||||||||||||||||
| 1287 | To save the geometry when the window closes, you can | - | ||||||||||||||||||
| 1288 | implement a close event like this: | - | ||||||||||||||||||
| 1289 | - | |||||||||||||||||||
| 1290 | \snippet code/src_gui_widgets_qmainwindow.cpp 0 | - | ||||||||||||||||||
| 1291 | - | |||||||||||||||||||
| 1292 | \sa restoreState(), QWidget::saveGeometry(), QWidget::restoreGeometry() | - | ||||||||||||||||||
| 1293 | */ | - | ||||||||||||||||||
| 1294 | QByteArray QMainWindow::saveState(int version) const | - | ||||||||||||||||||
| 1295 | { | - | ||||||||||||||||||
| 1296 | QByteArray data; | - | ||||||||||||||||||
| 1297 | QDataStream stream(&data, QIODevice::WriteOnly); | - | ||||||||||||||||||
| 1298 | stream << QMainWindowLayout::VersionMarker; | - | ||||||||||||||||||
| 1299 | stream << version; | - | ||||||||||||||||||
| 1300 | d_func()->layout->saveState(stream); | - | ||||||||||||||||||
| 1301 | return data; never executed:  return data; | 0 | ||||||||||||||||||
| 1302 | } | - | ||||||||||||||||||
| 1303 | - | |||||||||||||||||||
| 1304 | /*! | - | ||||||||||||||||||
| 1305 | Restores the \a state of this mainwindow's toolbars and | - | ||||||||||||||||||
| 1306 | dockwidgets. Also restores the corner settings too. The | - | ||||||||||||||||||
| 1307 | \a version number is compared with that stored in \a state. | - | ||||||||||||||||||
| 1308 | If they do not match, the mainwindow's state is left | - | ||||||||||||||||||
| 1309 | unchanged, and this function returns \c false; otherwise, the state | - | ||||||||||||||||||
| 1310 | is restored, and this function returns \c true. | - | ||||||||||||||||||
| 1311 | - | |||||||||||||||||||
| 1312 | To restore geometry saved using QSettings, you can use code like | - | ||||||||||||||||||
| 1313 | this: | - | ||||||||||||||||||
| 1314 | - | |||||||||||||||||||
| 1315 | \snippet code/src_gui_widgets_qmainwindow.cpp 1 | - | ||||||||||||||||||
| 1316 | - | |||||||||||||||||||
| 1317 | \sa saveState(), QWidget::saveGeometry(), | - | ||||||||||||||||||
| 1318 | QWidget::restoreGeometry(), restoreDockWidget() | - | ||||||||||||||||||
| 1319 | */ | - | ||||||||||||||||||
| 1320 | bool QMainWindow::restoreState(const QByteArray &state, int version) | - | ||||||||||||||||||
| 1321 | { | - | ||||||||||||||||||
| 1322 | if (state.isEmpty()) 
 | 0 | ||||||||||||||||||
| 1323 | return false; never executed:  return false; | 0 | ||||||||||||||||||
| 1324 | QByteArray sd = state; | - | ||||||||||||||||||
| 1325 | QDataStream stream(&sd, QIODevice::ReadOnly); | - | ||||||||||||||||||
| 1326 | int marker, v; | - | ||||||||||||||||||
| 1327 | stream >> marker; | - | ||||||||||||||||||
| 1328 | stream >> v; | - | ||||||||||||||||||
| 1329 | if (stream.status() != QDataStream::Ok || marker != QMainWindowLayout::VersionMarker || v != version) 
 
 
 | 0 | ||||||||||||||||||
| 1330 | return false; never executed:  return false; | 0 | ||||||||||||||||||
| 1331 | bool restored = d_func()->layout->restoreState(stream); | - | ||||||||||||||||||
| 1332 | return restored; never executed:  return restored; | 0 | ||||||||||||||||||
| 1333 | } | - | ||||||||||||||||||
| 1334 | - | |||||||||||||||||||
| 1335 | #if !defined(QT_NO_DOCKWIDGET) && !defined(QT_NO_CURSOR) | - | ||||||||||||||||||
| 1336 | QCursor QMainWindowPrivate::separatorCursor(const QList<int> &path) const | - | ||||||||||||||||||
| 1337 | { | - | ||||||||||||||||||
| 1338 | QDockAreaLayoutInfo *info = layout->layoutState.dockAreaLayout.info(path); | - | ||||||||||||||||||
| 1339 | Q_ASSERT(info != 0); | - | ||||||||||||||||||
| 1340 | if (path.size() == 1) { // is this the "top-level" separator which separates a dock area 
 | 0 | ||||||||||||||||||
| 1341 | // from the central widget? | - | ||||||||||||||||||
| 1342 | switch (path.first()) { | - | ||||||||||||||||||
| 1343 | case QInternal::LeftDock: never executed:  case QInternal::LeftDock: | 0 | ||||||||||||||||||
| 1344 | case QInternal::RightDock: never executed:  case QInternal::RightDock: | 0 | ||||||||||||||||||
| 1345 | return Qt::SplitHCursor; never executed:  return Qt::SplitHCursor; | 0 | ||||||||||||||||||
| 1346 | case QInternal::TopDock: never executed:  case QInternal::TopDock: | 0 | ||||||||||||||||||
| 1347 | case QInternal::BottomDock: never executed:  case QInternal::BottomDock: | 0 | ||||||||||||||||||
| 1348 | return Qt::SplitVCursor; never executed:  return Qt::SplitVCursor; | 0 | ||||||||||||||||||
| 1349 | default: never executed:  default: | 0 | ||||||||||||||||||
| 1350 | break; never executed:  break; | 0 | ||||||||||||||||||
| 1351 | } | - | ||||||||||||||||||
| 1352 | } | - | ||||||||||||||||||
| 1353 | - | |||||||||||||||||||
| 1354 | // no, it's a splitter inside a dock area, separating two dock widgets | - | ||||||||||||||||||
| 1355 | - | |||||||||||||||||||
| 1356 | return info->o == Qt::Horizontal never executed:  return info->o == Qt::Horizontal ? Qt::SplitHCursor : Qt::SplitVCursor;
 | 0 | ||||||||||||||||||
| 1357 | ? Qt::SplitHCursor : Qt::SplitVCursor; never executed:  return info->o == Qt::Horizontal ? Qt::SplitHCursor : Qt::SplitVCursor; | 0 | ||||||||||||||||||
| 1358 | } | - | ||||||||||||||||||
| 1359 | - | |||||||||||||||||||
| 1360 | void QMainWindowPrivate::adjustCursor(const QPoint &pos) | - | ||||||||||||||||||
| 1361 | { | - | ||||||||||||||||||
| 1362 | Q_Q(QMainWindow); | - | ||||||||||||||||||
| 1363 | - | |||||||||||||||||||
| 1364 | hoverPos = pos; | - | ||||||||||||||||||
| 1365 | - | |||||||||||||||||||
| 1366 | if (pos == QPoint(0, 0)) { 
 | 0 | ||||||||||||||||||
| 1367 | if (!hoverSeparator.isEmpty()) 
 | 0 | ||||||||||||||||||
| 1368 | q->update(layout->layoutState.dockAreaLayout.separatorRect(hoverSeparator)); never executed:  q->update(layout->layoutState.dockAreaLayout.separatorRect(hoverSeparator)); | 0 | ||||||||||||||||||
| 1369 | hoverSeparator.clear(); | - | ||||||||||||||||||
| 1370 | - | |||||||||||||||||||
| 1371 | if (cursorAdjusted) { 
 | 0 | ||||||||||||||||||
| 1372 | cursorAdjusted = false; | - | ||||||||||||||||||
| 1373 | if (hasOldCursor) 
 | 0 | ||||||||||||||||||
| 1374 | q->setCursor(oldCursor); never executed:  q->setCursor(oldCursor); | 0 | ||||||||||||||||||
| 1375 | else | - | ||||||||||||||||||
| 1376 | q->unsetCursor(); never executed:  q->unsetCursor(); | 0 | ||||||||||||||||||
| 1377 | } | - | ||||||||||||||||||
| 1378 | } else if (layout->movingSeparator.isEmpty()) { // Don't change cursor when moving separator never executed:  end of block
 | 0 | ||||||||||||||||||
| 1379 | QList<int> pathToSeparator | - | ||||||||||||||||||
| 1380 | = layout->layoutState.dockAreaLayout.findSeparator(pos); | - | ||||||||||||||||||
| 1381 | - | |||||||||||||||||||
| 1382 | if (pathToSeparator != hoverSeparator) { 
 | 0 | ||||||||||||||||||
| 1383 | if (!hoverSeparator.isEmpty()) 
 | 0 | ||||||||||||||||||
| 1384 | q->update(layout->layoutState.dockAreaLayout.separatorRect(hoverSeparator)); never executed:  q->update(layout->layoutState.dockAreaLayout.separatorRect(hoverSeparator)); | 0 | ||||||||||||||||||
| 1385 | - | |||||||||||||||||||
| 1386 | hoverSeparator = pathToSeparator; | - | ||||||||||||||||||
| 1387 | - | |||||||||||||||||||
| 1388 | if (hoverSeparator.isEmpty()) { 
 | 0 | ||||||||||||||||||
| 1389 | if (cursorAdjusted) { 
 | 0 | ||||||||||||||||||
| 1390 | cursorAdjusted = false; | - | ||||||||||||||||||
| 1391 | if (hasOldCursor) 
 | 0 | ||||||||||||||||||
| 1392 | q->setCursor(oldCursor); never executed:  q->setCursor(oldCursor); | 0 | ||||||||||||||||||
| 1393 | else | - | ||||||||||||||||||
| 1394 | q->unsetCursor(); never executed:  q->unsetCursor(); | 0 | ||||||||||||||||||
| 1395 | } | - | ||||||||||||||||||
| 1396 | } else { never executed:  end of block | 0 | ||||||||||||||||||
| 1397 | q->update(layout->layoutState.dockAreaLayout.separatorRect(hoverSeparator)); | - | ||||||||||||||||||
| 1398 | if (!cursorAdjusted) { 
 | 0 | ||||||||||||||||||
| 1399 | oldCursor = q->cursor(); | - | ||||||||||||||||||
| 1400 | hasOldCursor = q->testAttribute(Qt::WA_SetCursor); | - | ||||||||||||||||||
| 1401 | } never executed:  end of block | 0 | ||||||||||||||||||
| 1402 | adjustedCursor = separatorCursor(hoverSeparator); | - | ||||||||||||||||||
| 1403 | q->setCursor(adjustedCursor); | - | ||||||||||||||||||
| 1404 | cursorAdjusted = true; | - | ||||||||||||||||||
| 1405 | } never executed:  end of block | 0 | ||||||||||||||||||
| 1406 | } | - | ||||||||||||||||||
| 1407 | } never executed:  end of block | 0 | ||||||||||||||||||
| 1408 | } never executed:  end of block | 0 | ||||||||||||||||||
| 1409 | #endif | - | ||||||||||||||||||
| 1410 | - | |||||||||||||||||||
| 1411 | /*! \reimp */ | - | ||||||||||||||||||
| 1412 | bool QMainWindow::event(QEvent *event) | - | ||||||||||||||||||
| 1413 | { | - | ||||||||||||||||||
| 1414 | Q_D(QMainWindow); | - | ||||||||||||||||||
| 1415 | switch (event->type()) { | - | ||||||||||||||||||
| 1416 | - | |||||||||||||||||||
| 1417 | #ifndef QT_NO_DOCKWIDGET | - | ||||||||||||||||||
| 1418 | case QEvent::Paint: { never executed:  case QEvent::Paint: | 0 | ||||||||||||||||||
| 1419 | QPainter p(this); | - | ||||||||||||||||||
| 1420 | QRegion r = static_cast<QPaintEvent*>(event)->region(); | - | ||||||||||||||||||
| 1421 | d->layout->layoutState.dockAreaLayout.paintSeparators(&p, this, r, d->hoverPos); | - | ||||||||||||||||||
| 1422 | break; never executed:  break; | 0 | ||||||||||||||||||
| 1423 | } | - | ||||||||||||||||||
| 1424 | - | |||||||||||||||||||
| 1425 | #ifndef QT_NO_CURSOR | - | ||||||||||||||||||
| 1426 | case QEvent::HoverMove:  { never executed:  case QEvent::HoverMove: | 0 | ||||||||||||||||||
| 1427 | d->adjustCursor(static_cast<QHoverEvent*>(event)->pos()); | - | ||||||||||||||||||
| 1428 | break; never executed:  break; | 0 | ||||||||||||||||||
| 1429 | } | - | ||||||||||||||||||
| 1430 | - | |||||||||||||||||||
| 1431 | // We don't want QWidget to call update() on the entire QMainWindow | - | ||||||||||||||||||
| 1432 | // on HoverEnter and HoverLeave, hence accept the event (return true). | - | ||||||||||||||||||
| 1433 | case QEvent::HoverEnter: never executed:  case QEvent::HoverEnter: | 0 | ||||||||||||||||||
| 1434 | return true; never executed:  return true; | 0 | ||||||||||||||||||
| 1435 | case QEvent::HoverLeave: never executed:  case QEvent::HoverLeave: | 0 | ||||||||||||||||||
| 1436 | d->adjustCursor(QPoint(0, 0)); | - | ||||||||||||||||||
| 1437 | return true; never executed:  return true; | 0 | ||||||||||||||||||
| 1438 | case QEvent::ShortcutOverride: // when a menu pops up never executed:  case QEvent::ShortcutOverride: | 0 | ||||||||||||||||||
| 1439 | d->adjustCursor(QPoint(0, 0)); | - | ||||||||||||||||||
| 1440 | break; never executed:  break; | 0 | ||||||||||||||||||
| 1441 | #endif // QT_NO_CURSOR | - | ||||||||||||||||||
| 1442 | - | |||||||||||||||||||
| 1443 | case QEvent::MouseButtonPress: { never executed:  case QEvent::MouseButtonPress: | 0 | ||||||||||||||||||
| 1444 | QMouseEvent *e = static_cast<QMouseEvent*>(event); | - | ||||||||||||||||||
| 1445 | if (e->button() == Qt::LeftButton && d->layout->startSeparatorMove(e->pos())) { 
 
 | 0 | ||||||||||||||||||
| 1446 | // The click was on a separator, eat this event | - | ||||||||||||||||||
| 1447 | e->accept(); | - | ||||||||||||||||||
| 1448 | return true; never executed:  return true; | 0 | ||||||||||||||||||
| 1449 | } | - | ||||||||||||||||||
| 1450 | break; never executed:  break; | 0 | ||||||||||||||||||
| 1451 | } | - | ||||||||||||||||||
| 1452 | - | |||||||||||||||||||
| 1453 | case QEvent::MouseMove: { never executed:  case QEvent::MouseMove: | 0 | ||||||||||||||||||
| 1454 | QMouseEvent *e = static_cast<QMouseEvent*>(event); | - | ||||||||||||||||||
| 1455 | - | |||||||||||||||||||
| 1456 | #ifndef QT_NO_CURSOR | - | ||||||||||||||||||
| 1457 | d->adjustCursor(e->pos()); | - | ||||||||||||||||||
| 1458 | #endif | - | ||||||||||||||||||
| 1459 | if (e->buttons() & Qt::LeftButton) { 
 | 0 | ||||||||||||||||||
| 1460 | if (d->layout->separatorMove(e->pos())) { 
 | 0 | ||||||||||||||||||
| 1461 | // We're moving a separator, eat this event | - | ||||||||||||||||||
| 1462 | e->accept(); | - | ||||||||||||||||||
| 1463 | return true; never executed:  return true; | 0 | ||||||||||||||||||
| 1464 | } | - | ||||||||||||||||||
| 1465 | } never executed:  end of block | 0 | ||||||||||||||||||
| 1466 | - | |||||||||||||||||||
| 1467 | break; never executed:  break; | 0 | ||||||||||||||||||
| 1468 | } | - | ||||||||||||||||||
| 1469 | - | |||||||||||||||||||
| 1470 | case QEvent::MouseButtonRelease: { never executed:  case QEvent::MouseButtonRelease: | 0 | ||||||||||||||||||
| 1471 | QMouseEvent *e = static_cast<QMouseEvent*>(event); | - | ||||||||||||||||||
| 1472 | if (d->layout->endSeparatorMove(e->pos())) { 
 | 0 | ||||||||||||||||||
| 1473 | // We've released a separator, eat this event | - | ||||||||||||||||||
| 1474 | e->accept(); | - | ||||||||||||||||||
| 1475 | return true; never executed:  return true; | 0 | ||||||||||||||||||
| 1476 | } | - | ||||||||||||||||||
| 1477 | break; never executed:  break; | 0 | ||||||||||||||||||
| 1478 | } | - | ||||||||||||||||||
| 1479 | - | |||||||||||||||||||
| 1480 | #endif | - | ||||||||||||||||||
| 1481 | - | |||||||||||||||||||
| 1482 | #ifndef QT_NO_TOOLBAR | - | ||||||||||||||||||
| 1483 | case QEvent::ToolBarChange: { never executed:  case QEvent::ToolBarChange: | 0 | ||||||||||||||||||
| 1484 | d->layout->toggleToolBarsVisible(); | - | ||||||||||||||||||
| 1485 | return true; never executed:  return true; | 0 | ||||||||||||||||||
| 1486 | } | - | ||||||||||||||||||
| 1487 | #endif | - | ||||||||||||||||||
| 1488 | - | |||||||||||||||||||
| 1489 | #ifndef QT_NO_STATUSTIP | - | ||||||||||||||||||
| 1490 | case QEvent::StatusTip: never executed:  case QEvent::StatusTip: | 0 | ||||||||||||||||||
| 1491 | #ifndef QT_NO_STATUSBAR | - | ||||||||||||||||||
| 1492 | if (QStatusBar *sb = d->layout->statusBar()) 
 | 0 | ||||||||||||||||||
| 1493 | sb->showMessage(static_cast<QStatusTipEvent*>(event)->tip()); never executed:  sb->showMessage(static_cast<QStatusTipEvent*>(event)->tip()); | 0 | ||||||||||||||||||
| 1494 | else | - | ||||||||||||||||||
| 1495 | #endif | - | ||||||||||||||||||
| 1496 | static_cast<QStatusTipEvent*>(event)->ignore(); never executed:  static_cast<QStatusTipEvent*>(event)->ignore(); | 0 | ||||||||||||||||||
| 1497 | return true; never executed:  return true; | 0 | ||||||||||||||||||
| 1498 | #endif // QT_NO_STATUSTIP | - | ||||||||||||||||||
| 1499 | - | |||||||||||||||||||
| 1500 | case QEvent::StyleChange: never executed:  case QEvent::StyleChange: | 0 | ||||||||||||||||||
| 1501 | #ifndef QT_NO_DOCKWIDGET | - | ||||||||||||||||||
| 1502 | d->layout->layoutState.dockAreaLayout.styleChangedEvent(); | - | ||||||||||||||||||
| 1503 | #endif | - | ||||||||||||||||||
| 1504 | if (!d->explicitIconSize) 
 | 0 | ||||||||||||||||||
| 1505 | setIconSize(QSize()); never executed:  setIconSize(QSize()); | 0 | ||||||||||||||||||
| 1506 | break; never executed:  break; | 0 | ||||||||||||||||||
| 1507 | #ifdef Q_DEAD_CODE_FROM_QT4_MAC | - | ||||||||||||||||||
| 1508 | case QEvent::Show: | - | ||||||||||||||||||
| 1509 | if (unifiedTitleAndToolBarOnMac()) | - | ||||||||||||||||||
| 1510 | d->layout->syncUnifiedToolbarVisibility(); | - | ||||||||||||||||||
| 1511 | d->layout->blockVisiblityCheck = false; | - | ||||||||||||||||||
| 1512 | break; | - | ||||||||||||||||||
| 1513 | case QEvent::WindowStateChange: | - | ||||||||||||||||||
| 1514 | { | - | ||||||||||||||||||
| 1515 | if (isHidden()) { | - | ||||||||||||||||||
| 1516 | // We are coming out of a minimize, leave things as is. | - | ||||||||||||||||||
| 1517 | d->layout->blockVisiblityCheck = true; | - | ||||||||||||||||||
| 1518 | } | - | ||||||||||||||||||
| 1519 | // We need to update the HIToolbar status when we go out of or into fullscreen. | - | ||||||||||||||||||
| 1520 | QWindowStateChangeEvent *wce = static_cast<QWindowStateChangeEvent *>(event); | - | ||||||||||||||||||
| 1521 | if ((windowState() & Qt::WindowFullScreen) || (wce->oldState() & Qt::WindowFullScreen)) { | - | ||||||||||||||||||
| 1522 | d->layout->updateHIToolBarStatus(); | - | ||||||||||||||||||
| 1523 | } | - | ||||||||||||||||||
| 1524 | } | - | ||||||||||||||||||
| 1525 | break; | - | ||||||||||||||||||
| 1526 | #endif // Q_DEAD_CODE_FROM_QT4_MAC | - | ||||||||||||||||||
| 1527 | #if !defined(QT_NO_DOCKWIDGET) && !defined(QT_NO_CURSOR) | - | ||||||||||||||||||
| 1528 | case QEvent::CursorChange: never executed:  case QEvent::CursorChange: | 0 | ||||||||||||||||||
| 1529 | // CursorChange events are triggered as mouse moves to new widgets even | - | ||||||||||||||||||
| 1530 | // if the cursor doesn't actually change, so do not change oldCursor if | - | ||||||||||||||||||
| 1531 | // the "changed" cursor has same shape as adjusted cursor. | - | ||||||||||||||||||
| 1532 | if (d->cursorAdjusted && d->adjustedCursor.shape() != cursor().shape()) { 
 
 | 0 | ||||||||||||||||||
| 1533 | d->oldCursor = cursor(); | - | ||||||||||||||||||
| 1534 | d->hasOldCursor = testAttribute(Qt::WA_SetCursor); | - | ||||||||||||||||||
| 1535 | - | |||||||||||||||||||
| 1536 | // Ensure our adjusted cursor stays visible | - | ||||||||||||||||||
| 1537 | setCursor(d->adjustedCursor); | - | ||||||||||||||||||
| 1538 | } never executed:  end of block | 0 | ||||||||||||||||||
| 1539 | break; never executed:  break; | 0 | ||||||||||||||||||
| 1540 | #endif | - | ||||||||||||||||||
| 1541 | default: never executed:  default: | 0 | ||||||||||||||||||
| 1542 | break; never executed:  break; | 0 | ||||||||||||||||||
| 1543 | } | - | ||||||||||||||||||
| 1544 | - | |||||||||||||||||||
| 1545 | return QWidget::event(event); never executed:  return QWidget::event(event); | 0 | ||||||||||||||||||
| 1546 | } | - | ||||||||||||||||||
| 1547 | - | |||||||||||||||||||
| 1548 | #ifndef QT_NO_TOOLBAR | - | ||||||||||||||||||
| 1549 | - | |||||||||||||||||||
| 1550 | /*! | - | ||||||||||||||||||
| 1551 | \property QMainWindow::unifiedTitleAndToolBarOnMac | - | ||||||||||||||||||
| 1552 | \brief whether the window uses the unified title and toolbar look on \macos | - | ||||||||||||||||||
| 1553 | - | |||||||||||||||||||
| 1554 | Note that the Qt 5 implementation has several limitations compared to Qt 4: | - | ||||||||||||||||||
| 1555 | \list | - | ||||||||||||||||||
| 1556 | \li Use in windows with OpenGL content is not supported. This includes QGLWidget and QOpenGLWidget. | - | ||||||||||||||||||
| 1557 | \li Using dockable or movable toolbars may result in painting errors and is not recommended | - | ||||||||||||||||||
| 1558 | \endlist | - | ||||||||||||||||||
| 1559 | - | |||||||||||||||||||
| 1560 | \since 5.2 | - | ||||||||||||||||||
| 1561 | */ | - | ||||||||||||||||||
| 1562 | void QMainWindow::setUnifiedTitleAndToolBarOnMac(bool set) | - | ||||||||||||||||||
| 1563 | { | - | ||||||||||||||||||
| 1564 | #ifdef Q_OS_OSX | - | ||||||||||||||||||
| 1565 | Q_D(QMainWindow); | - | ||||||||||||||||||
| 1566 | if (isWindow()) { | - | ||||||||||||||||||
| 1567 | d->useUnifiedToolBar = set; | - | ||||||||||||||||||
| 1568 | createWinId(); | - | ||||||||||||||||||
| 1569 | - | |||||||||||||||||||
| 1570 | QPlatformNativeInterface *nativeInterface = QGuiApplication::platformNativeInterface(); | - | ||||||||||||||||||
| 1571 | QPlatformNativeInterface::NativeResourceForIntegrationFunction function = | - | ||||||||||||||||||
| 1572 | nativeInterface->nativeResourceFunctionForIntegration("setContentBorderEnabled"); | - | ||||||||||||||||||
| 1573 | if (!function) | - | ||||||||||||||||||
| 1574 | return; // Not Cocoa platform plugin. | - | ||||||||||||||||||
| 1575 | - | |||||||||||||||||||
| 1576 | typedef void (*SetContentBorderEnabledFunction)(QWindow *window, bool enable); | - | ||||||||||||||||||
| 1577 | (reinterpret_cast<SetContentBorderEnabledFunction>(function))(window()->windowHandle(), set); | - | ||||||||||||||||||
| 1578 | update(); | - | ||||||||||||||||||
| 1579 | } | - | ||||||||||||||||||
| 1580 | #endif | - | ||||||||||||||||||
| 1581 | - | |||||||||||||||||||
| 1582 | #ifdef Q_DEAD_CODE_FROM_QT4_MAC | - | ||||||||||||||||||
| 1583 | Q_D(QMainWindow); | - | ||||||||||||||||||
| 1584 | if (!isWindow() || d->useHIToolBar == set || QSysInfo::MacintoshVersion < QSysInfo::MV_10_3) | - | ||||||||||||||||||
| 1585 | return; | - | ||||||||||||||||||
| 1586 | - | |||||||||||||||||||
| 1587 | d->useHIToolBar = set; | - | ||||||||||||||||||
| 1588 | createWinId(); // We need the hiview for down below. | - | ||||||||||||||||||
| 1589 | - | |||||||||||||||||||
| 1590 | // Activate the unified toolbar with the raster engine. | - | ||||||||||||||||||
| 1591 | if (windowSurface() && set) { | - | ||||||||||||||||||
| 1592 | d->layout->unifiedSurface = new QUnifiedToolbarSurface(this); | - | ||||||||||||||||||
| 1593 | } | - | ||||||||||||||||||
| 1594 | - | |||||||||||||||||||
| 1595 | d->layout->updateHIToolBarStatus(); | - | ||||||||||||||||||
| 1596 | - | |||||||||||||||||||
| 1597 | // Deactivate the unified toolbar with the raster engine. | - | ||||||||||||||||||
| 1598 | if (windowSurface() && !set) { | - | ||||||||||||||||||
| 1599 | if (d->layout->unifiedSurface) { | - | ||||||||||||||||||
| 1600 | delete d->layout->unifiedSurface; | - | ||||||||||||||||||
| 1601 | d->layout->unifiedSurface = 0; | - | ||||||||||||||||||
| 1602 | } | - | ||||||||||||||||||
| 1603 | } | - | ||||||||||||||||||
| 1604 | - | |||||||||||||||||||
| 1605 | // Enabling the unified toolbar clears the opaque size grip setting, update it. | - | ||||||||||||||||||
| 1606 | d->macUpdateOpaqueSizeGrip(); | - | ||||||||||||||||||
| 1607 | #else | - | ||||||||||||||||||
| 1608 | Q_UNUSED(set) | - | ||||||||||||||||||
| 1609 | #endif | - | ||||||||||||||||||
| 1610 | } never executed:  end of block | 0 | ||||||||||||||||||
| 1611 | - | |||||||||||||||||||
| 1612 | bool QMainWindow::unifiedTitleAndToolBarOnMac() const | - | ||||||||||||||||||
| 1613 | { | - | ||||||||||||||||||
| 1614 | #ifdef Q_OS_OSX | - | ||||||||||||||||||
| 1615 | return d_func()->useUnifiedToolBar; | - | ||||||||||||||||||
| 1616 | #endif | - | ||||||||||||||||||
| 1617 | #ifdef Q_DEAD_CODE_FROM_QT4_MAC | - | ||||||||||||||||||
| 1618 | return d_func()->useHIToolBar && !testAttribute(Qt::WA_MacBrushedMetal) && !(windowFlags() & Qt::FramelessWindowHint); | - | ||||||||||||||||||
| 1619 | #endif | - | ||||||||||||||||||
| 1620 | return false; never executed:  return false; | 0 | ||||||||||||||||||
| 1621 | } | - | ||||||||||||||||||
| 1622 | - | |||||||||||||||||||
| 1623 | #endif // QT_NO_TOOLBAR | - | ||||||||||||||||||
| 1624 | - | |||||||||||||||||||
| 1625 | /*! | - | ||||||||||||||||||
| 1626 | \internal | - | ||||||||||||||||||
| 1627 | */ | - | ||||||||||||||||||
| 1628 | bool QMainWindow::isSeparator(const QPoint &pos) const | - | ||||||||||||||||||
| 1629 | { | - | ||||||||||||||||||
| 1630 | #ifndef QT_NO_DOCKWIDGET | - | ||||||||||||||||||
| 1631 | Q_D(const QMainWindow); | - | ||||||||||||||||||
| 1632 | return !d->layout->layoutState.dockAreaLayout.findSeparator(pos).isEmpty(); never executed:  return !d->layout->layoutState.dockAreaLayout.findSeparator(pos).isEmpty(); | 0 | ||||||||||||||||||
| 1633 | #else | - | ||||||||||||||||||
| 1634 | Q_UNUSED(pos); | - | ||||||||||||||||||
| 1635 | return false; | - | ||||||||||||||||||
| 1636 | #endif | - | ||||||||||||||||||
| 1637 | } | - | ||||||||||||||||||
| 1638 | - | |||||||||||||||||||
| 1639 | #ifndef QT_NO_CONTEXTMENU | - | ||||||||||||||||||
| 1640 | /*! | - | ||||||||||||||||||
| 1641 | \reimp | - | ||||||||||||||||||
| 1642 | */ | - | ||||||||||||||||||
| 1643 | void QMainWindow::contextMenuEvent(QContextMenuEvent *event) | - | ||||||||||||||||||
| 1644 | { | - | ||||||||||||||||||
| 1645 | event->ignore(); | - | ||||||||||||||||||
| 1646 | // only show the context menu for direct QDockWidget and QToolBar | - | ||||||||||||||||||
| 1647 | // children and for the menu bar as well | - | ||||||||||||||||||
| 1648 | QWidget *child = childAt(event->pos()); | - | ||||||||||||||||||
| 1649 | while (child && child != this) { 
 
 | 0 | ||||||||||||||||||
| 1650 | #ifndef QT_NO_MENUBAR | - | ||||||||||||||||||
| 1651 | if (QMenuBar *mb = qobject_cast<QMenuBar *>(child)) { 
 | 0 | ||||||||||||||||||
| 1652 | if (mb->parentWidget() != this) 
 | 0 | ||||||||||||||||||
| 1653 | return; never executed:  return; | 0 | ||||||||||||||||||
| 1654 | break; never executed:  break; | 0 | ||||||||||||||||||
| 1655 | } | - | ||||||||||||||||||
| 1656 | #endif | - | ||||||||||||||||||
| 1657 | #ifndef QT_NO_DOCKWIDGET | - | ||||||||||||||||||
| 1658 | if (QDockWidget *dw = qobject_cast<QDockWidget *>(child)) { 
 | 0 | ||||||||||||||||||
| 1659 | if (dw->parentWidget() != this) 
 | 0 | ||||||||||||||||||
| 1660 | return; never executed:  return; | 0 | ||||||||||||||||||
| 1661 | if (dw->widget() 
 | 0 | ||||||||||||||||||
| 1662 | && dw->widget()->geometry().contains(child->mapFrom(this, event->pos()))) { 
 | 0 | ||||||||||||||||||
| 1663 | // ignore the event if the mouse is over the QDockWidget contents | - | ||||||||||||||||||
| 1664 | return; never executed:  return; | 0 | ||||||||||||||||||
| 1665 | } | - | ||||||||||||||||||
| 1666 | break; never executed:  break; | 0 | ||||||||||||||||||
| 1667 | } | - | ||||||||||||||||||
| 1668 | #endif // QT_NO_DOCKWIDGET | - | ||||||||||||||||||
| 1669 | #ifndef QT_NO_TOOLBAR | - | ||||||||||||||||||
| 1670 | if (QToolBar *tb = qobject_cast<QToolBar *>(child)) { 
 | 0 | ||||||||||||||||||
| 1671 | if (tb->parentWidget() != this) 
 | 0 | ||||||||||||||||||
| 1672 | return; never executed:  return; | 0 | ||||||||||||||||||
| 1673 | break; never executed:  break; | 0 | ||||||||||||||||||
| 1674 | } | - | ||||||||||||||||||
| 1675 | #endif | - | ||||||||||||||||||
| 1676 | child = child->parentWidget(); | - | ||||||||||||||||||
| 1677 | } never executed:  end of block | 0 | ||||||||||||||||||
| 1678 | if (child == this) 
 | 0 | ||||||||||||||||||
| 1679 | return; never executed:  return; | 0 | ||||||||||||||||||
| 1680 | - | |||||||||||||||||||
| 1681 | #ifndef QT_NO_MENU | - | ||||||||||||||||||
| 1682 | QMenu *popup = createPopupMenu(); | - | ||||||||||||||||||
| 1683 | if (popup) { 
 | 0 | ||||||||||||||||||
| 1684 | if (!popup->isEmpty()) { 
 | 0 | ||||||||||||||||||
| 1685 | popup->setAttribute(Qt::WA_DeleteOnClose); | - | ||||||||||||||||||
| 1686 | popup->popup(event->globalPos()); | - | ||||||||||||||||||
| 1687 | event->accept(); | - | ||||||||||||||||||
| 1688 | } else { never executed:  end of block | 0 | ||||||||||||||||||
| 1689 | delete popup; | - | ||||||||||||||||||
| 1690 | } never executed:  end of block | 0 | ||||||||||||||||||
| 1691 | } | - | ||||||||||||||||||
| 1692 | #endif | - | ||||||||||||||||||
| 1693 | } never executed:  end of block | 0 | ||||||||||||||||||
| 1694 | #endif // QT_NO_CONTEXTMENU | - | ||||||||||||||||||
| 1695 | - | |||||||||||||||||||
| 1696 | #ifndef QT_NO_MENU | - | ||||||||||||||||||
| 1697 | /*! | - | ||||||||||||||||||
| 1698 | Returns a popup menu containing checkable entries for the toolbars and | - | ||||||||||||||||||
| 1699 | dock widgets present in the main window. If there are no toolbars and | - | ||||||||||||||||||
| 1700 | dock widgets present, this function returns a null pointer. | - | ||||||||||||||||||
| 1701 | - | |||||||||||||||||||
| 1702 | By default, this function is called by the main window when the user | - | ||||||||||||||||||
| 1703 | activates a context menu, typically by right-clicking on a toolbar or a dock | - | ||||||||||||||||||
| 1704 | widget. | - | ||||||||||||||||||
| 1705 | - | |||||||||||||||||||
| 1706 | If you want to create a custom popup menu, reimplement this function and | - | ||||||||||||||||||
| 1707 | return a newly-created popup menu. Ownership of the popup menu is transferred | - | ||||||||||||||||||
| 1708 | to the caller. | - | ||||||||||||||||||
| 1709 | - | |||||||||||||||||||
| 1710 | \sa addDockWidget(), addToolBar(), menuBar() | - | ||||||||||||||||||
| 1711 | */ | - | ||||||||||||||||||
| 1712 | QMenu *QMainWindow::createPopupMenu() | - | ||||||||||||||||||
| 1713 | { | - | ||||||||||||||||||
| 1714 | Q_D(QMainWindow); | - | ||||||||||||||||||
| 1715 | QMenu *menu = 0; | - | ||||||||||||||||||
| 1716 | #ifndef QT_NO_DOCKWIDGET | - | ||||||||||||||||||
| 1717 | QList<QDockWidget *> dockwidgets = findChildren<QDockWidget *>(); | - | ||||||||||||||||||
| 1718 | if (dockwidgets.size()) { 
 | 0 | ||||||||||||||||||
| 1719 | menu = new QMenu(this); | - | ||||||||||||||||||
| 1720 | for (int i = 0; i < dockwidgets.size(); ++i) { 
 | 0 | ||||||||||||||||||
| 1721 | QDockWidget *dockWidget = dockwidgets.at(i); | - | ||||||||||||||||||
| 1722 | // filter to find out if we own this QDockWidget | - | ||||||||||||||||||
| 1723 | if (dockWidget->parentWidget() == this) { 
 | 0 | ||||||||||||||||||
| 1724 | if (d->layout->layoutState.dockAreaLayout.indexOf(dockWidget).isEmpty()) 
 | 0 | ||||||||||||||||||
| 1725 | continue; never executed:  continue; | 0 | ||||||||||||||||||
| 1726 | } else if (QDockWidgetGroupWindow *dwgw = never executed:  end of block
 | 0 | ||||||||||||||||||
| 1727 | qobject_cast<QDockWidgetGroupWindow *>(dockWidget->parentWidget())) { 
 | 0 | ||||||||||||||||||
| 1728 | if (dwgw->parentWidget() != this) 
 | 0 | ||||||||||||||||||
| 1729 | continue; never executed:  continue; | 0 | ||||||||||||||||||
| 1730 | if (dwgw->layoutInfo()->indexOf(dockWidget).isEmpty()) 
 | 0 | ||||||||||||||||||
| 1731 | continue; never executed:  continue; | 0 | ||||||||||||||||||
| 1732 | } else { never executed:  end of block | 0 | ||||||||||||||||||
| 1733 | continue; never executed:  continue; | 0 | ||||||||||||||||||
| 1734 | } | - | ||||||||||||||||||
| 1735 | menu->addAction(dockwidgets.at(i)->toggleViewAction()); | - | ||||||||||||||||||
| 1736 | } never executed:  end of block | 0 | ||||||||||||||||||
| 1737 | menu->addSeparator(); | - | ||||||||||||||||||
| 1738 | } never executed:  end of block | 0 | ||||||||||||||||||
| 1739 | #endif // QT_NO_DOCKWIDGET | - | ||||||||||||||||||
| 1740 | #ifndef QT_NO_TOOLBAR | - | ||||||||||||||||||
| 1741 | QList<QToolBar *> toolbars = findChildren<QToolBar *>(); | - | ||||||||||||||||||
| 1742 | if (toolbars.size()) { 
 | 0 | ||||||||||||||||||
| 1743 | if (!menu) 
 | 0 | ||||||||||||||||||
| 1744 | menu = new QMenu(this); never executed:  menu = new QMenu(this); | 0 | ||||||||||||||||||
| 1745 | for (int i = 0; i < toolbars.size(); ++i) { 
 | 0 | ||||||||||||||||||
| 1746 | QToolBar *toolBar = toolbars.at(i); | - | ||||||||||||||||||
| 1747 | if (toolBar->parentWidget() == this 
 | 0 | ||||||||||||||||||
| 1748 | && (!d->layout->layoutState.toolBarAreaLayout.indexOf(toolBar).isEmpty())) { 
 | 0 | ||||||||||||||||||
| 1749 | menu->addAction(toolbars.at(i)->toggleViewAction()); | - | ||||||||||||||||||
| 1750 | } never executed:  end of block | 0 | ||||||||||||||||||
| 1751 | } never executed:  end of block | 0 | ||||||||||||||||||
| 1752 | } never executed:  end of block | 0 | ||||||||||||||||||
| 1753 | #endif | - | ||||||||||||||||||
| 1754 | Q_UNUSED(d); | - | ||||||||||||||||||
| 1755 | return menu; never executed:  return menu; | 0 | ||||||||||||||||||
| 1756 | } | - | ||||||||||||||||||
| 1757 | #endif // QT_NO_MENU | - | ||||||||||||||||||
| 1758 | - | |||||||||||||||||||
| 1759 | QT_END_NAMESPACE | - | ||||||||||||||||||
| 1760 | - | |||||||||||||||||||
| 1761 | #include "moc_qmainwindow.cpp" | - | ||||||||||||||||||
| 1762 | - | |||||||||||||||||||
| 1763 | #endif // QT_NO_MAINWINDOW | - | ||||||||||||||||||
| Source code | Switch to Preprocessed file |