From ac1b6c01454b8969e59becf066bba14f9ed0d310 Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Thu, 5 Mar 2015 11:00:53 +0100 Subject: Add QMainWindow::GroupedDragging DockOption If this setting is enabled, the entire group of docked tabs will be draggable by the title bar of the group and and individual dock can be dragged by dragging the tab. When tabs are detached, the docks that are contained are reparented to a QDockWidgetGroupWindow. [ChangeLog][QtWidgets][QMainWindow] Added GroupedDragging as a DockOption which allow users to drag all the tabs together when dragging the title of a QDockWidget which is tabbed with others. Change-Id: I5285685b129770498eb3e4fd5f4556e41225a595 Reviewed-by: Friedemann Kleint Reviewed-by: Paul Olav Tvete --- examples/widgets/mainwindows/mainwindow/colorswatch.cpp | 8 ++------ examples/widgets/mainwindows/mainwindow/colorswatch.h | 4 +++- examples/widgets/mainwindows/mainwindow/mainwindow.cpp | 7 +++++++ 3 files changed, 12 insertions(+), 7 deletions(-) (limited to 'examples/widgets/mainwindows/mainwindow') diff --git a/examples/widgets/mainwindows/mainwindow/colorswatch.cpp b/examples/widgets/mainwindows/mainwindow/colorswatch.cpp index 408f6c4b0f..7499389dc3 100644 --- a/examples/widgets/mainwindows/mainwindow/colorswatch.cpp +++ b/examples/widgets/mainwindows/mainwindow/colorswatch.cpp @@ -248,8 +248,8 @@ void ColorDock::setCustomSizeHint(const QSize &size) updateGeometry(); } -ColorSwatch::ColorSwatch(const QString &colorName, QWidget *parent, Qt::WindowFlags flags) - : QDockWidget(parent, flags) +ColorSwatch::ColorSwatch(const QString &colorName, QMainWindow *parent, Qt::WindowFlags flags) + : QDockWidget(parent, flags), mainWindow(parent) { setObjectName(colorName + QLatin1String(" Dock Widget")); setWindowTitle(objectName() + QLatin1String(" [*]")); @@ -390,7 +390,6 @@ ColorSwatch::ColorSwatch(const QString &colorName, QWidget *parent, Qt::WindowFl void ColorSwatch::updateContextMenu() { - QMainWindow *mainWindow = qobject_cast(parentWidget()); const Qt::DockWidgetArea area = mainWindow->dockWidgetArea(this); const Qt::DockWidgetAreas areas = allowedAreas(); @@ -458,7 +457,6 @@ void ColorSwatch::updateContextMenu() void ColorSwatch::splitInto(QAction *action) { - QMainWindow *mainWindow = qobject_cast(parentWidget()); QList dock_list = mainWindow->findChildren(); ColorSwatch *target = 0; foreach (ColorSwatch *dock, dock_list) { @@ -477,7 +475,6 @@ void ColorSwatch::splitInto(QAction *action) void ColorSwatch::tabInto(QAction *action) { - QMainWindow *mainWindow = qobject_cast(parentWidget()); QList dock_list = mainWindow->findChildren(); ColorSwatch *target = 0; foreach (ColorSwatch *dock, dock_list) { @@ -525,7 +522,6 @@ void ColorSwatch::place(Qt::DockWidgetArea area, bool p) { if (!p) return; - QMainWindow *mainWindow = qobject_cast(parentWidget()); mainWindow->addDockWidget(area, this); if (allowedAreasActions->isEnabled()) { diff --git a/examples/widgets/mainwindows/mainwindow/colorswatch.h b/examples/widgets/mainwindows/mainwindow/colorswatch.h index 6d02592b22..78f267c320 100644 --- a/examples/widgets/mainwindows/mainwindow/colorswatch.h +++ b/examples/widgets/mainwindows/mainwindow/colorswatch.h @@ -70,8 +70,10 @@ class ColorSwatch : public QDockWidget QAction *windowModifiedAction; + QMainWindow *mainWindow; + public: - explicit ColorSwatch(const QString &colorName, QWidget *parent = 0, Qt::WindowFlags flags = 0); + explicit ColorSwatch(const QString &colorName, QMainWindow *parent = 0, Qt::WindowFlags flags = 0); QMenu *menu; void setCustomSizeHint(const QSize &size); diff --git a/examples/widgets/mainwindows/mainwindow/mainwindow.cpp b/examples/widgets/mainwindows/mainwindow/mainwindow.cpp index 70a8644b47..ea557c7aa9 100644 --- a/examples/widgets/mainwindows/mainwindow/mainwindow.cpp +++ b/examples/widgets/mainwindows/mainwindow/mainwindow.cpp @@ -156,6 +156,11 @@ void MainWindow::setupMenuBar() action->setChecked(dockOptions() & VerticalTabs); connect(action, SIGNAL(toggled(bool)), this, SLOT(setDockOptions())); + action = mainWindowMenu->addAction(tr("Grouped dragging")); + action->setCheckable(true); + action->setChecked(dockOptions() & GroupedDragging); + connect(action, SIGNAL(toggled(bool)), this, SLOT(setDockOptions())); + QMenu *toolBarMenu = menuBar()->addMenu(tr("Tool bars")); for (int i = 0; i < toolBars.count(); ++i) toolBarMenu->addMenu(toolBars.at(i)->menu); @@ -187,6 +192,8 @@ void MainWindow::setDockOptions() opts |= ForceTabbedDocks; if (actions.at(4)->isChecked()) opts |= VerticalTabs; + if (actions.at(5)->isChecked()) + opts |= GroupedDragging; QMainWindow::setDockOptions(opts); } -- cgit v1.2.3