From 6c3f82547de846a30797adac738083e07dd09edd Mon Sep 17 00:00:00 2001 From: mvidelgauz Date: Sun, 2 Feb 2020 16:56:31 +0200 Subject: [PATCH] setAllowedAreas for individual DockAreaWidget (#107) * setAllowedAreas for individual DockAreaWidget * alligning tab policy with master --- demo/MainWindow.cpp | 9 ++++++++- src/DockAreaWidget.cpp | 10 ++++++++++ src/DockAreaWidget.h | 10 ++++++++++ src/DockContainerWidget.cpp | 6 +++--- src/FloatingDockContainer.cpp | 2 +- src/FloatingDragPreview.cpp | 2 +- 6 files changed, 33 insertions(+), 6 deletions(-) diff --git a/demo/MainWindow.cpp b/demo/MainWindow.cpp index a1415dc..8f1567f 100644 --- a/demo/MainWindow.cpp +++ b/demo/MainWindow.cpp @@ -276,7 +276,14 @@ void MainWindowPrivate::createContent() QMenu* ViewMenu = ui.menuView; auto DockWidget = createCalendarDockWidget(ViewMenu); DockWidget->setFeature(ads::CDockWidget::DockWidgetClosable, false); - DockManager->addDockWidget(ads::LeftDockWidgetArea, DockWidget); + auto SpecialDockArea = DockManager->addDockWidget(ads::LeftDockWidgetArea, DockWidget); + + // For this Special Dock Area we want to avoid dropping on the center of it (i.e. we don't want this widget to be ever tabbified): + { + SpecialDockArea->setAllowedAreas(ads::OuterDockAreas); + //SpecialDockArea->setAllowedAreas({ads::LeftDockWidgetArea, ads::RightDockWidgetArea}); // just for testing + } + DockManager->addDockWidget(ads::LeftDockWidgetArea, createLongTextLabelDockWidget(ViewMenu)); auto FileSystemWidget = createFileSystemTreeDockWidget(ViewMenu); auto ToolBar = FileSystemWidget->createDefaultToolBar(); diff --git a/src/DockAreaWidget.cpp b/src/DockAreaWidget.cpp index b26b0bd..70d66c1 100644 --- a/src/DockAreaWidget.cpp +++ b/src/DockAreaWidget.cpp @@ -245,6 +245,7 @@ struct DockAreaWidgetPrivate CDockAreaTitleBar* TitleBar = nullptr; CDockManager* DockManager = nullptr; bool UpdateTitleBarButtons = false; + DockWidgetAreas AllowedAreas = AllDockAreas; /** * Private data constructor @@ -812,6 +813,15 @@ void CDockAreaWidget::setVisible(bool Visible) } } +void CDockAreaWidget::setAllowedAreas(DockWidgetAreas areas) +{ + d->AllowedAreas = areas; +} + +DockWidgetAreas CDockAreaWidget::allowedAreas() const +{ + return d->AllowedAreas; +} //============================================================================ QAbstractButton* CDockAreaWidget::titleBarButton(TitleBarButton which) const diff --git a/src/DockAreaWidget.h b/src/DockAreaWidget.h index 03688b4..42ca5c8 100644 --- a/src/DockAreaWidget.h +++ b/src/DockAreaWidget.h @@ -254,6 +254,16 @@ public: */ virtual void setVisible(bool Visible) override; + /** + * Configures the areas of this particular dock area that are allowed for docking + */ + void setAllowedAreas(DockWidgetAreas areas); + + /** + * Returns flags with all allowed drop areas of this particular dock area + */ + DockWidgetAreas allowedAreas() const; + public slots: /** * This activates the tab for the given tab index. diff --git a/src/DockContainerWidget.cpp b/src/DockContainerWidget.cpp index a3bc785..101f853 100644 --- a/src/DockContainerWidget.cpp +++ b/src/DockContainerWidget.cpp @@ -334,7 +334,7 @@ eDropMode DockContainerWidgetPrivate::getDropMode(const QPoint& TargetPos) if (DockArea) { auto dropOverlay = DockManager->dockAreaOverlay(); - dropOverlay->setAllowedAreas(AllDockAreas); + dropOverlay->setAllowedAreas(DockArea->allowedAreas()); dropArea = dropOverlay->showOverlay(DockArea); if (ContainerDropArea != InvalidDockWidgetArea && ContainerDropArea != dropArea) @@ -1392,7 +1392,7 @@ void CDockContainerWidget::dropFloatingWidget(CFloatingDockContainer* FloatingWi if (DockArea) { auto dropOverlay = d->DockManager->dockAreaOverlay(); - dropOverlay->setAllowedAreas(AllDockAreas); + dropOverlay->setAllowedAreas(DockArea->allowedAreas()); dropArea = dropOverlay->showOverlay(DockArea); if (ContainerDropArea != InvalidDockWidgetArea && ContainerDropArea != dropArea) @@ -1447,7 +1447,7 @@ void CDockContainerWidget::dropWidget(QWidget* Widget, const QPoint& TargetPos) if (DockArea) { auto dropOverlay = d->DockManager->dockAreaOverlay(); - dropOverlay->setAllowedAreas(AllDockAreas); + dropOverlay->setAllowedAreas(DockArea->allowedAreas()); dropArea = dropOverlay->showOverlay(DockArea); if (ContainerDropArea != InvalidDockWidgetArea && ContainerDropArea != dropArea) diff --git a/src/FloatingDockContainer.cpp b/src/FloatingDockContainer.cpp index 2e1bcbb..e04dce5 100644 --- a/src/FloatingDockContainer.cpp +++ b/src/FloatingDockContainer.cpp @@ -207,7 +207,7 @@ void FloatingDockContainerPrivate::updateDropOverlays(const QPoint &GlobalPos) { DockAreaOverlay->enableDropPreview(true); DockAreaOverlay->setAllowedAreas( - (VisibleDockAreas == 1) ? NoDockWidgetArea : AllDockAreas); + (VisibleDockAreas == 1) ? NoDockWidgetArea : DockArea->allowedAreas()); DockWidgetArea Area = DockAreaOverlay->showOverlay(DockArea); // A CenterDockWidgetArea for the dockAreaOverlay() indicates that diff --git a/src/FloatingDragPreview.cpp b/src/FloatingDragPreview.cpp index aec9449..e34cce1 100644 --- a/src/FloatingDragPreview.cpp +++ b/src/FloatingDragPreview.cpp @@ -127,7 +127,7 @@ void FloatingDragPreviewPrivate::updateDropOverlays(const QPoint &GlobalPos) { DockAreaOverlay->enableDropPreview(true); DockAreaOverlay->setAllowedAreas( - (VisibleDockAreas == 1) ? NoDockWidgetArea : AllDockAreas); + (VisibleDockAreas == 1) ? NoDockWidgetArea : DockArea->allowedAreas()); DockWidgetArea Area = DockAreaOverlay->showOverlay(DockArea); // A CenterDockWidgetArea for the dockAreaOverlay() indicates that