From 2af4b1f75c14e9f99756e83adf5c5be7daa448bc Mon Sep 17 00:00:00 2001 From: Uwe Kindler Date: Mon, 16 Dec 2019 13:56:20 +0100 Subject: [PATCH] Blocked display of context menu when dragging floating widget --- src/DockAreaTabBar.cpp | 14 +++++++++++--- src/DockAreaTabBar.h | 5 +++++ src/DockAreaTitleBar.cpp | 5 +++++ src/DockWidgetTab.cpp | 41 +++++++++++++++++++++++----------------- 4 files changed, 45 insertions(+), 20 deletions(-) diff --git a/src/DockAreaTabBar.cpp b/src/DockAreaTabBar.cpp index 3d44934..3fe74ae 100644 --- a/src/DockAreaTabBar.cpp +++ b/src/DockAreaTabBar.cpp @@ -173,7 +173,7 @@ void CDockAreaTabBar::mousePressEvent(QMouseEvent* ev) d->DragState = DraggingMousePressed; return; } - QScrollArea::mousePressEvent(ev); + Super::mousePressEvent(ev); } @@ -193,14 +193,14 @@ void CDockAreaTabBar::mouseReleaseEvent(QMouseEvent* ev) } return; } - QScrollArea::mouseReleaseEvent(ev); + Super::mouseReleaseEvent(ev); } //============================================================================ void CDockAreaTabBar::mouseMoveEvent(QMouseEvent* ev) { - QScrollArea::mouseMoveEvent(ev); + Super::mouseMoveEvent(ev); if (!(ev->buttons() & Qt::LeftButton) || d->isDraggingState(DraggingInactive)) { d->DragState = DraggingInactive; @@ -618,6 +618,7 @@ QSize CDockAreaTabBar::minimumSizeHint() const return Size; } + //=========================================================================== QSize CDockAreaTabBar::sizeHint() const { @@ -626,6 +627,13 @@ QSize CDockAreaTabBar::sizeHint() const return Size; } + +//=========================================================================== +eDragState CDockAreaTabBar::dragState() const +{ + return d->DragState; +} + } // namespace ads //--------------------------------------------------------------------------- diff --git a/src/DockAreaTabBar.h b/src/DockAreaTabBar.h index 83504cf..13ea615 100644 --- a/src/DockAreaTabBar.h +++ b/src/DockAreaTabBar.h @@ -98,6 +98,11 @@ protected: */ IFloatingWidget* makeAreaFloating(const QPoint& Offset, eDragState DragState); + /** + * Returns the current drag state + */ + eDragState dragState() const; + public: using Super = QScrollArea; diff --git a/src/DockAreaTitleBar.cpp b/src/DockAreaTitleBar.cpp index b552784..b662b16 100644 --- a/src/DockAreaTitleBar.cpp +++ b/src/DockAreaTitleBar.cpp @@ -364,6 +364,11 @@ void CDockAreaTitleBar::setVisible(bool Visible) //============================================================================ void CDockAreaTitleBar::showContextMenu(const QPoint& pos) { + if (d->TabBar->dragState() == DraggingFloatingWidget) + { + return; + } + QMenu Menu(this); auto Action = Menu.addAction(tr("Detach Area"), this, SLOT(onUndockButtonClicked())); Action->setEnabled(d->DockArea->features().testFlag(CDockWidget::DockWidgetFloatable)); diff --git a/src/DockWidgetTab.cpp b/src/DockWidgetTab.cpp index 6c5329e..044c88e 100644 --- a/src/DockWidgetTab.cpp +++ b/src/DockWidgetTab.cpp @@ -317,26 +317,29 @@ void CDockWidgetTab::mousePressEvent(QMouseEvent* ev) //============================================================================ void CDockWidgetTab::mouseReleaseEvent(QMouseEvent* ev) { - auto CurrentDragState = d->DragState; - d->DragStartMousePosition = QPoint(); - d->DragState = DraggingInactive; + if (ev->button() == Qt::LeftButton) + { + auto CurrentDragState = d->DragState; + d->DragStartMousePosition = QPoint(); + d->DragState = DraggingInactive; - switch (CurrentDragState) - { - case DraggingTab: - // End of tab moving, emit signal - if (d->DockArea) + switch (CurrentDragState) { - emit moved(ev->globalPos()); + case DraggingTab: + // End of tab moving, emit signal + if (d->DockArea) + { + emit moved(ev->globalPos()); + } + break; + + case DraggingFloatingWidget: + d->FloatingWidget->finishDragging(); + break; + + default:; // do nothing } - break; - - case DraggingFloatingWidget: - d->FloatingWidget->finishDragging(); - break; - - default:; // do nothing - } + } Super::mouseReleaseEvent(ev); } @@ -416,6 +419,10 @@ void CDockWidgetTab::mouseMoveEvent(QMouseEvent* ev) void CDockWidgetTab::contextMenuEvent(QContextMenuEvent* ev) { ev->accept(); + if (d->isDraggingState(DraggingFloatingWidget)) + { + return; + } d->DragStartMousePosition = ev->pos(); QMenu Menu(this);