From 48382ccd82ccb6eae17b95746b6851d6fb12f3f1 Mon Sep 17 00:00:00 2001 From: Uwe Kindler Date: Thu, 20 Dec 2018 16:25:30 +0100 Subject: [PATCH] Merged the two draging state enumerations into a single one and reused it in FloatingDockContainer --- src/DockAreaTabBar.cpp | 9 ++++---- src/DockAreaTabBar.h | 4 +++- src/DockAreaTitleBar.cpp | 2 +- src/DockWidget.cpp | 1 + src/DockWidget.h | 1 + src/DockWidgetTab.cpp | 16 +++++--------- src/FloatingDockContainer.cpp | 41 ++++++++++++++--------------------- src/FloatingDockContainer.h | 20 ++++++++++++++++- src/ads_globals.h | 11 ++++++++++ 9 files changed, 62 insertions(+), 43 deletions(-) diff --git a/src/DockAreaTabBar.cpp b/src/DockAreaTabBar.cpp index aa08c95..a579a6c 100644 --- a/src/DockAreaTabBar.cpp +++ b/src/DockAreaTabBar.cpp @@ -228,16 +228,17 @@ void CDockAreaTabBar::mouseDoubleClickEvent(QMouseEvent *event) { return; } - startFloating(event->pos()); + makeAreaFloating(event->pos(), DraggingInactive); } //============================================================================ -CFloatingDockContainer* CDockAreaTabBar::makeAreaFloating(const QPoint& Offset) +CFloatingDockContainer* CDockAreaTabBar::makeAreaFloating(const QPoint& Offset, + eDragState DragState) { QSize Size = d->DockArea->size(); CFloatingDockContainer* FloatingWidget = new CFloatingDockContainer(d->DockArea); - FloatingWidget->startFloating(Offset, Size); + FloatingWidget->startFloating(Offset, Size, DragState); auto TopLevelDockWidget = FloatingWidget->topLevelDockWidget(); if (TopLevelDockWidget) { @@ -251,7 +252,7 @@ CFloatingDockContainer* CDockAreaTabBar::makeAreaFloating(const QPoint& Offset) //============================================================================ void CDockAreaTabBar::startFloating(const QPoint& Offset) { - d->FloatingWidget = makeAreaFloating(Offset); + d->FloatingWidget = makeAreaFloating(Offset, DraggingFloatingWidget); } diff --git a/src/DockAreaTabBar.h b/src/DockAreaTabBar.h index 474ac46..f065ebd 100644 --- a/src/DockAreaTabBar.h +++ b/src/DockAreaTabBar.h @@ -30,6 +30,7 @@ // INCLUDES //============================================================================ #include +#include "ads_globals.h" namespace ads { @@ -89,7 +90,8 @@ protected: /** * Makes the dock area floating */ - CFloatingDockContainer* makeAreaFloating(const QPoint& Offset); + CFloatingDockContainer* makeAreaFloating(const QPoint& Offset, + eDragState DragState); public: diff --git a/src/DockAreaTitleBar.cpp b/src/DockAreaTitleBar.cpp index 957abb7..5c1e151 100644 --- a/src/DockAreaTitleBar.cpp +++ b/src/DockAreaTitleBar.cpp @@ -265,7 +265,7 @@ void CDockAreaTitleBar::onCloseButtonClicked() //============================================================================ void CDockAreaTitleBar::onUndockButtonClicked() { - d->TabBar->makeAreaFloating(mapFromGlobal(QCursor::pos())); + d->TabBar->makeAreaFloating(mapFromGlobal(QCursor::pos()), DraggingInactive); } diff --git a/src/DockWidget.cpp b/src/DockWidget.cpp index bcdd7f7..0333d57 100644 --- a/src/DockWidget.cpp +++ b/src/DockWidget.cpp @@ -671,6 +671,7 @@ QSize CDockWidget::minimumSizeHint() const return QSize(60, 40); } + } // namespace ads //--------------------------------------------------------------------------- diff --git a/src/DockWidget.h b/src/DockWidget.h index 9cf1bd5..a50e0c1 100644 --- a/src/DockWidget.h +++ b/src/DockWidget.h @@ -45,6 +45,7 @@ class CDockManager; class CDockContainerWidget; class CDockAreaWidget; class DockContainerWidgetPrivate; +class CFloatingDockContainer; /** * The QDockWidget class provides a widget that can be docked inside a diff --git a/src/DockWidgetTab.cpp b/src/DockWidgetTab.cpp index ee3f53f..5e629d8 100644 --- a/src/DockWidgetTab.cpp +++ b/src/DockWidgetTab.cpp @@ -53,16 +53,6 @@ namespace ads { -/** - * The different dragging states - */ -enum eDragState -{ - DraggingInactive, //!< DraggingInactive - DraggingMousePressed, //!< DraggingMousePressed - DraggingTab, //!< DraggingTab - DraggingFloatingWidget//!< DraggingFloatingWidget -}; using tTabLabel = CElidingLabel; using tCloseButton = QPushButton; @@ -229,13 +219,17 @@ bool DockWidgetTabPrivate::startFloating(eDragState DraggingState) FloatingWidget = new CFloatingDockContainer(DockArea); } - FloatingWidget->startFloating(DragStartMousePosition, Size); if (DraggingFloatingWidget == DraggingState) { + FloatingWidget->startDragging(DragStartMousePosition, Size); auto Overlay = DockWidget->dockManager()->containerOverlay(); Overlay->setAllowedAreas(OuterDockAreas); this->FloatingWidget = FloatingWidget; } + else + { + FloatingWidget->initFloatingGeometry(DragStartMousePosition, Size); + } DockWidget->emitTopLevelChanged(true); return true; } diff --git a/src/FloatingDockContainer.cpp b/src/FloatingDockContainer.cpp index 2331e32..df586ad 100644 --- a/src/FloatingDockContainer.cpp +++ b/src/FloatingDockContainer.cpp @@ -50,16 +50,6 @@ namespace ads { static unsigned int zOrderCounter = 0; -/** - * The different dragging states - */ -enum eDragState -{ - StateInactive, //!< DraggingInactive - StateMousePressed, //!< DraggingMousePressed - StateDraggingActive//!< DraggingFloatingWidget -}; - /** * Private data class of CFloatingDockContainer class (pimpl) */ @@ -69,7 +59,7 @@ struct FloatingDockContainerPrivate CDockContainerWidget* DockContainer; unsigned int zOrderIndex = ++zOrderCounter; QPointer DockManager; - eDragState DraggingState = StateInactive; + eDragState DraggingState = DraggingInactive; QPoint DragStartMousePosition; CDockContainerWidget* DropContainer = nullptr; CDockAreaWidget* SingleDockArea = nullptr; @@ -111,7 +101,7 @@ FloatingDockContainerPrivate::FloatingDockContainerPrivate(CFloatingDockContaine //============================================================================ void FloatingDockContainerPrivate::titleMouseReleaseEvent() { - setState(StateInactive); + setState(DraggingInactive); if (!DropContainer) { return; @@ -301,12 +291,12 @@ void CFloatingDockContainer::moveEvent(QMoveEvent *event) QWidget::moveEvent(event); switch (d->DraggingState) { - case StateMousePressed: - d->setState(StateDraggingActive); + case DraggingMousePressed: + d->setState(DraggingFloatingWidget); d->updateDropOverlays(QCursor::pos()); break; - case StateDraggingActive: + case DraggingFloatingWidget: d->updateDropOverlays(QCursor::pos()); break; default: @@ -319,7 +309,7 @@ void CFloatingDockContainer::moveEvent(QMoveEvent *event) void CFloatingDockContainer::closeEvent(QCloseEvent *event) { qDebug() << "CFloatingDockContainer closeEvent"; - d->setState(StateInactive); + d->setState(DraggingInactive); if (isClosable()) { @@ -365,20 +355,20 @@ bool CFloatingDockContainer::event(QEvent *e) { switch (d->DraggingState) { - case StateInactive: + case DraggingInactive: if (e->type() == QEvent::NonClientAreaMouseButtonPress && QGuiApplication::mouseButtons() == Qt::LeftButton) { qDebug() << "FloatingWidget::event Event::NonClientAreaMouseButtonPress" << e->type(); - d->setState(StateMousePressed); + d->setState(DraggingMousePressed); } break; - case StateMousePressed: + case DraggingMousePressed: switch (e->type()) { case QEvent::NonClientAreaMouseButtonDblClick: qDebug() << "FloatingWidget::event QEvent::NonClientAreaMouseButtonDblClick"; - d->setState(StateInactive); + d->setState(DraggingInactive); break; case QEvent::Resize: @@ -392,7 +382,7 @@ bool CFloatingDockContainer::event(QEvent *e) // change, we check, if we are not in maximized state. if (!isMaximized()) { - d->setState(StateInactive); + d->setState(DraggingInactive); } break; @@ -401,7 +391,7 @@ bool CFloatingDockContainer::event(QEvent *e) } break; - case StateDraggingActive: + case DraggingFloatingWidget: if (e->type() == QEvent::NonClientAreaMouseButtonRelease) { qDebug() << "FloatingWidget::event QEvent::NonClientAreaMouseButtonRelease"; @@ -424,7 +414,7 @@ bool CFloatingDockContainer::event(QEvent *e) bool CFloatingDockContainer::eventFilter(QObject *watched, QEvent *event) { Q_UNUSED(watched); - if (event->type() == QEvent::MouseButtonRelease && d->isState(StateDraggingActive)) + if (event->type() == QEvent::MouseButtonRelease && d->isState(DraggingFloatingWidget)) { qDebug() << "FloatingWidget::eventFilter QEvent::MouseButtonRelease"; d->titleMouseReleaseEvent(); @@ -435,10 +425,11 @@ bool CFloatingDockContainer::eventFilter(QObject *watched, QEvent *event) //============================================================================ -void CFloatingDockContainer::startFloating(const QPoint& DragStartMousePos, const QSize& Size) +void CFloatingDockContainer::startFloating(const QPoint& DragStartMousePos, const QSize& Size, + eDragState DragState) { resize(Size); - d->setState(StateDraggingActive); + d->setState(DragState); d->DragStartMousePosition = DragStartMousePos; moveFloating(); show(); diff --git a/src/FloatingDockContainer.h b/src/FloatingDockContainer.h index ad1ae76..31af860 100644 --- a/src/FloatingDockContainer.h +++ b/src/FloatingDockContainer.h @@ -81,7 +81,25 @@ protected: * Use moveToGlobalPos() to move the widget to a new position * depending on the start position given in Pos parameter */ - void startFloating(const QPoint& DragStartMousePos, const QSize& Size = QSize()); + void startFloating(const QPoint& DragStartMousePos, const QSize& Size, + eDragState DragState); + + /** + * Call this function to start dragging the floating widget + */ + void startDragging(const QPoint& DragStartMousePos, const QSize& Size) + { + startFloating(DragStartMousePos, Size, DraggingFloatingWidget); + } + + /** + * Call this function if you just want to initialize the position + * and size of the floating widget + */ + void initFloatingGeometry(const QPoint& DragStartMousePos, const QSize& Size) + { + startFloating(DragStartMousePos, Size, DraggingInactive); + } /** * Moves the widget to a new position relative to the position given when diff --git a/src/ads_globals.h b/src/ads_globals.h index 3284b76..637661b 100644 --- a/src/ads_globals.h +++ b/src/ads_globals.h @@ -72,6 +72,17 @@ enum TitleBarButton TitleBarButtonClose }; +/** + * The different dragging states + */ +enum eDragState +{ + DraggingInactive, //!< DraggingInactive + DraggingMousePressed, //!< DraggingMousePressed + DraggingTab, //!< DraggingTab + DraggingFloatingWidget//!< DraggingFloatingWidget +}; + namespace internal { static const bool RestoreTesting = true;