From 3f40c997e5fe5387a5b116f1f70b6cd5eabb4325 Mon Sep 17 00:00:00 2001 From: Uwe Kindler Date: Fri, 24 Aug 2018 14:04:21 +0200 Subject: [PATCH] Improved and fixed handling of CDockWidget::DockWidgetMovable - moving the tab in the tabbar is always allowed, only moving the complete dock widget can be blocked by clearing this flag --- src/DockAreaTabBar.h | 6 +++--- src/DockAreaWidget.h | 2 +- src/DockWidgetTab.cpp | 42 +++++++++++++++++++----------------------- 3 files changed, 23 insertions(+), 27 deletions(-) diff --git a/src/DockAreaTabBar.h b/src/DockAreaTabBar.h index aa2c76e..ad51043 100644 --- a/src/DockAreaTabBar.h +++ b/src/DockAreaTabBar.h @@ -18,9 +18,9 @@ class CDockAreaWidget; struct DockAreaTabBarPrivate; /** - * Custom scroll bar implementation for dock area tab bar - * This scroll area enables floating of a whole dock area including all - * dock widgets + * Custom tabbar implementation for tab area that is shown on top of a + * dock area widget. + * The tabbar displays the tab widgets of the contained dock widgets. */ class CDockAreaTabBar : public QScrollArea { diff --git a/src/DockAreaWidget.h b/src/DockAreaWidget.h index 0079f8b..2471ae4 100644 --- a/src/DockAreaWidget.h +++ b/src/DockAreaWidget.h @@ -45,7 +45,7 @@ class CDockWidget; /** - * DockAreaWidget manages multiple instances of DckWidgets. + * DockAreaWidget manages multiple instances of DockWidgets. * It displays a title tab, which is clickable and will switch to * the contents associated to the title when clicked. */ diff --git a/src/DockWidgetTab.cpp b/src/DockWidgetTab.cpp index 6c629ff..039f727 100644 --- a/src/DockWidgetTab.cpp +++ b/src/DockWidgetTab.cpp @@ -240,19 +240,16 @@ void CDockWidgetTab::mouseReleaseEvent(QMouseEvent* ev) // End of tab moving, change order now if (d->isDraggingState(DraggingTab) && d->DockArea) { - if (d->DockWidget->features() & CDockWidget::DockWidgetMovable) { - // Find tab under mouse - QPoint pos = d->DockArea->mapFromGlobal(ev->globalPos()); - int fromIndex = d->DockArea->tabIndex(d->DockWidget); - int toIndex = d->DockArea->indexOfContentByTitlePos(pos, this); - if (-1 == toIndex) - { - toIndex = d->DockArea->count() - 1; - } - qDebug() << "Move tab from " << fromIndex << " to " << toIndex; - d->DockArea->reorderDockWidget(fromIndex, toIndex); - } - + // Find tab under mouse + QPoint pos = d->DockArea->mapFromGlobal(ev->globalPos()); + int fromIndex = d->DockArea->tabIndex(d->DockWidget); + int toIndex = d->DockArea->indexOfContentByTitlePos(pos, this); + if (-1 == toIndex) + { + toIndex = d->DockArea->count() - 1; + } + qDebug() << "Move tab from " << fromIndex << " to " << toIndex; + d->DockArea->reorderDockWidget(fromIndex, toIndex); } if (!d->DragStartMousePosition.isNull()) @@ -276,11 +273,10 @@ void CDockWidgetTab::mouseMoveEvent(QMouseEvent* ev) return; } + // move floating winwdow if (d->isDraggingState(DraggingFloatingWidget)) { - if (d->DockWidget->features() & CDockWidget::DockWidgetMovable) { - d->FloatingWidget->moveFloating(); - } + d->FloatingWidget->moveFloating(); QFrame::mouseMoveEvent(ev); return; } @@ -288,15 +284,17 @@ void CDockWidgetTab::mouseMoveEvent(QMouseEvent* ev) // move tab if (d->isDraggingState(DraggingTab)) { - if (d->DockWidget->features() & CDockWidget::DockWidgetMovable) { - d->moveTab(ev); - } + // Moving the tab is always allowed because it does not mean moving the + // dock widget around + d->moveTab(ev); } bool MouseInsideTitleArea = d->titleAreaGeometryContains(ev->globalPos()); if (!MouseInsideTitleArea) { - if (d->DockWidget->features() & CDockWidget::DockWidgetMovable) { + // Floating is only allowed for widgets that are movable + if (d->DockWidget->features().testFlag(CDockWidget::DockWidgetMovable)) + { d->startFloating(); } return; @@ -304,9 +302,7 @@ void CDockWidgetTab::mouseMoveEvent(QMouseEvent* ev) else if (d->DockArea->count() > 1 && (ev->pos() - d->DragStartMousePosition).manhattanLength() >= QApplication::startDragDistance()) // Wait a few pixels before start moving { - if (d->DockWidget->features() & CDockWidget::DockWidgetMovable) { - d->DragState = DraggingTab; - } + d->DragState = DraggingTab; return; }