diff --git a/src/DockAreaTabBar.cpp b/src/DockAreaTabBar.cpp index 33ade65..aa08c95 100644 --- a/src/DockAreaTabBar.cpp +++ b/src/DockAreaTabBar.cpp @@ -233,11 +233,11 @@ void CDockAreaTabBar::mouseDoubleClickEvent(QMouseEvent *event) //============================================================================ -CFloatingDockContainer* CDockAreaTabBar::makeAreaFloating(const QPoint& Pos) +CFloatingDockContainer* CDockAreaTabBar::makeAreaFloating(const QPoint& Offset) { QSize Size = d->DockArea->size(); CFloatingDockContainer* FloatingWidget = new CFloatingDockContainer(d->DockArea); - FloatingWidget->startFloating(Pos, Size); + FloatingWidget->startFloating(Offset, Size); auto TopLevelDockWidget = FloatingWidget->topLevelDockWidget(); if (TopLevelDockWidget) { @@ -249,9 +249,9 @@ CFloatingDockContainer* CDockAreaTabBar::makeAreaFloating(const QPoint& Pos) //============================================================================ -void CDockAreaTabBar::startFloating(const QPoint& Pos) +void CDockAreaTabBar::startFloating(const QPoint& Offset) { - d->FloatingWidget = makeAreaFloating(Pos); + d->FloatingWidget = makeAreaFloating(Offset); } diff --git a/src/DockAreaTabBar.h b/src/DockAreaTabBar.h index baf4eb1..474ac46 100644 --- a/src/DockAreaTabBar.h +++ b/src/DockAreaTabBar.h @@ -84,12 +84,12 @@ protected: /** * Starts floating */ - void startFloating(const QPoint& Pos); + void startFloating(const QPoint& Offset); /** - * Makes the dock area loating + * Makes the dock area floating */ - CFloatingDockContainer* makeAreaFloating(const QPoint& Pos); + CFloatingDockContainer* makeAreaFloating(const QPoint& Offset); public: diff --git a/src/DockAreaTitleBar.cpp b/src/DockAreaTitleBar.cpp index 0bcc7e4..957abb7 100644 --- a/src/DockAreaTitleBar.cpp +++ b/src/DockAreaTitleBar.cpp @@ -47,6 +47,7 @@ #include "DockWidgetTab.h" #include "DockAreaTabBar.h" +#include namespace ads { @@ -173,6 +174,10 @@ void DockAreaTitleBarPrivate::createTabBar() _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))); + + TabBar->setContextMenuPolicy(Qt::CustomContextMenu); + _this->connect(TabBar, SIGNAL(customContextMenuRequested(const QPoint&)), + SLOT(showContextMenu(const QPoint&))); } @@ -310,6 +315,19 @@ void CDockAreaTitleBar::setVisible(bool Visible) } +//============================================================================ +void CDockAreaTitleBar::showContextMenu(const QPoint& pos) +{ + QMenu Menu(this); + Menu.addAction(tr("Detach Area"), this, SLOT(onUndockButtonClicked())); + Menu.addSeparator(); + auto Action = Menu.addAction(tr("Close Area"), this, SLOT(onCloseButtonClicked())); + Action->setEnabled(d->DockArea->features().testFlag(CDockWidget::DockWidgetClosable)); + Menu.addAction(tr("Close Other Areas"), d->DockArea, SLOT(closeOtherAreas())); + Menu.exec(mapToGlobal(pos)); +} + + } // namespace ads //--------------------------------------------------------------------------- diff --git a/src/DockAreaTitleBar.h b/src/DockAreaTitleBar.h index 09993fd..9e30963 100644 --- a/src/DockAreaTitleBar.h +++ b/src/DockAreaTitleBar.h @@ -59,6 +59,7 @@ private slots: void onUndockButtonClicked(); void onTabsMenuActionTriggered(QAction* Action); void onCurrentTabChanged(int Index); + void showContextMenu(const QPoint& pos); public: using Super = QFrame; diff --git a/src/DockAreaWidget.cpp b/src/DockAreaWidget.cpp index e63f34a..b065cf1 100644 --- a/src/DockAreaWidget.cpp +++ b/src/DockAreaWidget.cpp @@ -779,6 +779,13 @@ void CDockAreaWidget::closeArea() DockWidget->toggleView(false); } } + + +//============================================================================ +void CDockAreaWidget::closeOtherAreas() +{ + dockContainer()->closeOtherAreas(this); +} } // namespace ads //--------------------------------------------------------------------------- diff --git a/src/DockAreaWidget.h b/src/DockAreaWidget.h index c48ca5f..d227fa4 100644 --- a/src/DockAreaWidget.h +++ b/src/DockAreaWidget.h @@ -259,6 +259,11 @@ public slots: */ void closeArea(); + /** + * This function closes all other areas except of this area + */ + void closeOtherAreas(); + signals: /** * This signal is emitted when user clicks on a tab at an index. diff --git a/src/DockContainerWidget.cpp b/src/DockContainerWidget.cpp index 3b56f22..8292cb9 100644 --- a/src/DockContainerWidget.cpp +++ b/src/DockContainerWidget.cpp @@ -1378,6 +1378,19 @@ CFloatingDockContainer* CDockContainerWidget::floatingWidget() const } +//============================================================================ +void CDockContainerWidget::closeOtherAreas(CDockAreaWidget* KeepOpenArea) +{ + for (const auto DockArea : d->DockAreas) + { + if (DockArea != KeepOpenArea && DockArea->features().testFlag(CDockWidget::DockWidgetClosable)) + { + DockArea->closeArea(); + } + } +} + + } // namespace ads #include "moc_DockContainerWidget.cpp" diff --git a/src/DockContainerWidget.h b/src/DockContainerWidget.h index 0d0a2a8..75bf54d 100644 --- a/src/DockContainerWidget.h +++ b/src/DockContainerWidget.h @@ -233,6 +233,11 @@ public: */ CFloatingDockContainer* floatingWidget() const; + /** + * Call this function to close all dock areas except the KeepOpenArea + */ + void closeOtherAreas(CDockAreaWidget* KeepOpenArea); + signals: /** * This signal is emitted if one or multiple dock areas has been added to diff --git a/src/DockManager.cpp b/src/DockManager.cpp index 8ae17d2..35d79c0 100644 --- a/src/DockManager.cpp +++ b/src/DockManager.cpp @@ -759,6 +759,7 @@ void CDockManager::setConfigFlags(const ConfigFlags Flags) d->ConfigFlags = Flags; } + } // namespace ads //--------------------------------------------------------------------------- diff --git a/src/DockWidgetTab.cpp b/src/DockWidgetTab.cpp index c644a20..ee3f53f 100644 --- a/src/DockWidgetTab.cpp +++ b/src/DockWidgetTab.cpp @@ -123,7 +123,7 @@ struct DockWidgetTabPrivate * Returns true, if floating has been started and false if floating * is not possible for any reason */ - bool startFloating(); + bool startFloating(eDragState DraggingState = DraggingFloatingWidget); /** * Returns true if the given config flag is set @@ -197,7 +197,7 @@ void DockWidgetTabPrivate::moveTab(QMouseEvent* ev) //============================================================================ -bool DockWidgetTabPrivate::startFloating() +bool DockWidgetTabPrivate::startFloating(eDragState DraggingState) { auto dockContainer = DockWidget->dockContainer(); qDebug() << "isFloating " << dockContainer->isFloating(); @@ -214,7 +214,7 @@ bool DockWidgetTabPrivate::startFloating() } qDebug() << "startFloating"; - DragState = DraggingFloatingWidget; + DragState = DraggingState; QSize Size = DockArea->size(); CFloatingDockContainer* FloatingWidget = nullptr; if (DockArea->dockWidgetsCount() > 1) @@ -230,10 +230,13 @@ bool DockWidgetTabPrivate::startFloating() } FloatingWidget->startFloating(DragStartMousePosition, Size); - auto Overlay = DockWidget->dockManager()->containerOverlay(); - Overlay->setAllowedAreas(OuterDockAreas); - this->FloatingWidget = FloatingWidget; - DockWidget->emitTopLevelChanged(true); + if (DraggingFloatingWidget == DraggingState) + { + auto Overlay = DockWidget->dockManager()->containerOverlay(); + Overlay->setAllowedAreas(OuterDockAreas); + this->FloatingWidget = FloatingWidget; + } + DockWidget->emitTopLevelChanged(true); return true; } @@ -471,7 +474,7 @@ void CDockWidgetTab::mouseDoubleClickEvent(QMouseEvent *event) if (!d->DockArea->dockContainer()->isFloating() || d->DockArea->dockWidgetsCount() > 1) { d->DragStartMousePosition = event->pos(); - d->startFloating(); + d->startFloating(DraggingInactive); } Super::mouseDoubleClickEvent(event); @@ -497,7 +500,7 @@ bool CDockWidgetTab::isClosable() const void CDockWidgetTab::onDetachActionTriggered() { d->DragStartMousePosition = mapFromGlobal(QCursor::pos()); - d->startFloating(); + d->startFloating(DraggingInactive); } } // namespace ads diff --git a/src/FloatingDockContainer.cpp b/src/FloatingDockContainer.cpp index 9d789b4..2331e32 100644 --- a/src/FloatingDockContainer.cpp +++ b/src/FloatingDockContainer.cpp @@ -435,14 +435,14 @@ bool CFloatingDockContainer::eventFilter(QObject *watched, QEvent *event) //============================================================================ -void CFloatingDockContainer::startFloating(const QPoint& Pos, const QSize& Size) +void CFloatingDockContainer::startFloating(const QPoint& DragStartMousePos, const QSize& Size) { resize(Size); d->setState(StateDraggingActive); - QPoint TargetPos = QCursor::pos() - Pos; - move(TargetPos); + d->DragStartMousePosition = DragStartMousePos; + moveFloating(); show(); - d->DragStartMousePosition = Pos; + } diff --git a/src/FloatingDockContainer.h b/src/FloatingDockContainer.h index 49c9f0d..ad1ae76 100644 --- a/src/FloatingDockContainer.h +++ b/src/FloatingDockContainer.h @@ -81,7 +81,7 @@ protected: * Use moveToGlobalPos() to move the widget to a new position * depending on the start position given in Pos parameter */ - void startFloating(const QPoint& Pos, const QSize& Size = QSize()); + void startFloating(const QPoint& DragStartMousePos, const QSize& Size = QSize()); /** * Moves the widget to a new position relative to the position given when