From 927be9a7d9d3ccd61ddce63eb7e72e85be413871 Mon Sep 17 00:00:00 2001 From: Uwe Kindler Date: Mon, 15 Oct 2018 15:09:59 +0200 Subject: [PATCH] Improved detection of dock widget dragging - uses a distance now (half the height of dock area title bar) --- src/DockAreaTabBar.cpp | 4 +++- src/DockAreaTabBar.h | 2 +- src/DockAreaTitleBar.cpp | 6 ++++-- src/DockAreaTitleBar.h | 7 +++++++ src/DockAreaWidget.cpp | 2 +- src/DockManager.cpp | 6 ++++++ src/DockWidgetTab.cpp | 6 ++++-- 7 files changed, 26 insertions(+), 7 deletions(-) diff --git a/src/DockAreaTabBar.cpp b/src/DockAreaTabBar.cpp index b922fe1..6b40e8f 100644 --- a/src/DockAreaTabBar.cpp +++ b/src/DockAreaTabBar.cpp @@ -186,7 +186,9 @@ void CDockAreaTabBar::mouseMoveEvent(QMouseEvent* ev) return; } - if (!this->geometry().contains(ev->pos())) + int DragDistanceY = qAbs(d->DragStartMousePos.y() - ev->pos().y()); + int MinDragDistanceY = this->height() / 2; + if (DragDistanceY >= MinDragDistanceY) { qDebug() << "CTabsScrollArea::startFloating"; startFloating(d->DragStartMousePos); diff --git a/src/DockAreaTabBar.h b/src/DockAreaTabBar.h index b1275ee..5756643 100644 --- a/src/DockAreaTabBar.h +++ b/src/DockAreaTabBar.h @@ -163,7 +163,7 @@ signals: void currentChanged(int Index); /** - * This signal is emitted when user clicks on a tab at an index. + * This signal is emitted when user clicks on a tab */ void tabBarClicked(int index); diff --git a/src/DockAreaTitleBar.cpp b/src/DockAreaTitleBar.cpp index 59cc688..22c9f09 100644 --- a/src/DockAreaTitleBar.cpp +++ b/src/DockAreaTitleBar.cpp @@ -84,7 +84,7 @@ void DockAreaTitleBarPrivate::createButtons() _this->connect(TabsMenu, SIGNAL(aboutToShow()), SLOT(onTabsMenuAboutToShow())); TabsMenuButton->setMenu(TabsMenu); TopLayout->addWidget(TabsMenuButton, 0); - TabsMenuButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); + TabsMenuButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding); _this->connect(TabsMenuButton->menu(), SIGNAL(triggered(QAction*)), SLOT(onTabsMenuActionTriggered(QAction*))); @@ -93,7 +93,7 @@ void DockAreaTitleBarPrivate::createButtons() CloseButton->setFlat(true); CloseButton->setIcon(_this->style()->standardIcon(QStyle::SP_TitleBarCloseButton)); CloseButton->setToolTip(QObject::tr("Close")); - CloseButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); + CloseButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding); TopLayout->addWidget(CloseButton, 0); _this->connect(CloseButton, SIGNAL(clicked()), SLOT(onCloseButtonClicked())); } @@ -110,6 +110,7 @@ void DockAreaTitleBarPrivate::createTabBar() _this->connect(TabBar, SIGNAL(removingTab(int)), SLOT(markTabsMenuOutdated())); _this->connect(TabBar, SIGNAL(tabMoved(int, int)), SLOT(markTabsMenuOutdated())); _this->connect(TabBar, SIGNAL(currentChanged(int)), SLOT(onCurrentTabChanged(int))); + _this->connect(TabBar, SIGNAL(tabBarClicked(int)), SIGNAL(tabBarClicked(int))); } @@ -192,6 +193,7 @@ void CDockAreaTitleBar::onTabsMenuActionTriggered(QAction* Action) { int Index = Action->data().toInt(); d->TabBar->setCurrentIndex(Index); + emit tabBarClicked(Index); } diff --git a/src/DockAreaTitleBar.h b/src/DockAreaTitleBar.h index ad4dd23..8b54931 100644 --- a/src/DockAreaTitleBar.h +++ b/src/DockAreaTitleBar.h @@ -71,6 +71,13 @@ public: * Returns the pointer to the tabBar() */ CDockAreaTabBar* tabBar() const; + +signals: + /** + * This signal is emitted if a tab in the tab bar is clicked by the user + * or if the user clicks on a tab item in the title bar tab menu. + */ + void tabBarClicked(int index); }; // class name } // namespace ads diff --git a/src/DockAreaWidget.cpp b/src/DockAreaWidget.cpp index 209d647..9886f43 100644 --- a/src/DockAreaWidget.cpp +++ b/src/DockAreaWidget.cpp @@ -289,7 +289,7 @@ void DockAreaWidgetPrivate::createTitleBar() Layout->addWidget(TitleBar); _this->connect(tabBar(), SIGNAL(tabCloseRequested(int)), SLOT(onTabCloseRequested(int))); - _this->connect(tabBar(), SIGNAL(tabBarClicked(int)), + _this->connect(TitleBar, SIGNAL(tabBarClicked(int)), SLOT(setCurrentIndex(int))); _this->connect(tabBar(), SIGNAL(tabMoved(int, int)), SLOT(reorderDockWidget(int, int))); diff --git a/src/DockManager.cpp b/src/DockManager.cpp index 5ab722f..9d046ca 100644 --- a/src/DockManager.cpp +++ b/src/DockManager.cpp @@ -225,6 +225,12 @@ bool DockManagerPrivate::restoreState(const QByteArray &state, int version) return false; } + // Hide updates of floatingf widgets from use + for (auto FloatingWidget : FloatingWidgets) + { + FloatingWidget->hide(); + } + for (auto DockWidget : DockWidgetsMap) { DockWidget->setProperty("dirty", true); diff --git a/src/DockWidgetTab.cpp b/src/DockWidgetTab.cpp index cb41a78..8912ad0 100644 --- a/src/DockWidgetTab.cpp +++ b/src/DockWidgetTab.cpp @@ -279,8 +279,10 @@ void CDockWidgetTab::mouseMoveEvent(QMouseEvent* ev) d->moveTab(ev); } - bool MouseInsideTitleArea = d->titleAreaGeometryContains(ev->globalPos()); - if (!MouseInsideTitleArea) + // Maybe a fixed drag distance is better here ? + int DragDistanceY = qAbs(d->DragStartMousePosition.y() - ev->pos().y()); + int MinDragDistanceY = d->DockArea->titleBarGeometry().height() / 2; + if (DragDistanceY >= MinDragDistanceY) { // If this is the last dock area in a dock container with only // one single dock widget it does not make sense to move it to a new