From 6e35a9e7a79367eba5daec70a93a9c3634d57a89 Mon Sep 17 00:00:00 2001 From: Syarif Fakhri Date: Tue, 6 Sep 2022 15:35:18 +0800 Subject: [PATCH] - Add an example folder for auto hide functionality Note: this does not include the py file, To be added in a different commit - Added a better API to programatically add the overlay areas in the CDockManager --- examples/autohide/CMakeLists.txt | 28 ++++ examples/autohide/main.cpp | 10 ++ examples/autohide/main.py | 106 ++++++++++++++ examples/autohide/mainwindow.cpp | 133 ++++++++++++++++++ examples/autohide/mainwindow.h | 43 ++++++ examples/autohide/mainwindow.ui | 47 +++++++ examples/centralwidget/CMakeLists.txt | 14 +- .../{centralwidget.pro => autohide.pro} | 5 +- examples/centralwidget/mainwindow.cpp | 4 +- src/DockAreaWidget.cpp | 2 +- src/DockContainerWidget.cpp | 21 ++- src/DockContainerWidget.h | 13 +- src/DockManager.cpp | 20 ++- src/DockManager.h | 14 ++ src/OverlayDockContainer.cpp | 19 ++- src/OverlayDockContainer.h | 5 + 16 files changed, 452 insertions(+), 32 deletions(-) create mode 100644 examples/autohide/CMakeLists.txt create mode 100644 examples/autohide/main.cpp create mode 100644 examples/autohide/main.py create mode 100644 examples/autohide/mainwindow.cpp create mode 100644 examples/autohide/mainwindow.h create mode 100644 examples/autohide/mainwindow.ui rename examples/centralwidget/{centralwidget.pro => autohide.pro} (92%) diff --git a/examples/autohide/CMakeLists.txt b/examples/autohide/CMakeLists.txt new file mode 100644 index 0000000..7f57821 --- /dev/null +++ b/examples/autohide/CMakeLists.txt @@ -0,0 +1,28 @@ +cmake_minimum_required(VERSION 3.5) +project(ads_example_centralwidget VERSION ${VERSION_SHORT}) +find_package(QT NAMES Qt6 Qt5 COMPONENTS Core REQUIRED) +find_package(Qt${QT_VERSION_MAJOR} 5.5 COMPONENTS Core Gui Widgets REQUIRED) +set(CMAKE_INCLUDE_CURRENT_DIR ON) +add_executable(CentralWidgetExample WIN32 + main.cpp + mainwindow.cpp + mainwindow.ui +) +target_include_directories(CentralWidgetExample PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/../../src") +target_link_libraries(CentralWidgetExample PRIVATE qtadvanceddocking) +target_link_libraries(CentralWidgetExample PUBLIC Qt${QT_VERSION_MAJOR}::Core + Qt${QT_VERSION_MAJOR}::Gui + Qt${QT_VERSION_MAJOR}::Widgets) +set_target_properties(CentralWidgetExample PROPERTIES + AUTOMOC ON + AUTORCC ON + AUTOUIC ON + CXX_STANDARD 14 + CXX_STANDARD_REQUIRED ON + CXX_EXTENSIONS OFF + VERSION ${VERSION_SHORT} + EXPORT_NAME "Qt Advanced Docking System Central Widget Example" + ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${ads_PlatformDir}/lib" + LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${ads_PlatformDir}/lib" + RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${ads_PlatformDir}/bin" +) diff --git a/examples/autohide/main.cpp b/examples/autohide/main.cpp new file mode 100644 index 0000000..fa4c4fd --- /dev/null +++ b/examples/autohide/main.cpp @@ -0,0 +1,10 @@ +#include +#include + +int main(int argc, char *argv[]) +{ + QApplication a(argc, argv); + CMainWindow w; + w.show(); + return a.exec(); +} diff --git a/examples/autohide/main.py b/examples/autohide/main.py new file mode 100644 index 0000000..5fe6a49 --- /dev/null +++ b/examples/autohide/main.py @@ -0,0 +1,106 @@ +import os +import sys + +from PyQt5 import uic +from PyQt5.QtCore import Qt, QTimer, QDir, QSignalBlocker +from PyQt5.QtGui import QCloseEvent, QIcon +from PyQt5.QtWidgets import (QApplication, QLabel, QCalendarWidget, QFrame, QTreeView, + QTableWidget, QFileSystemModel, QPlainTextEdit, QToolBar, + QWidgetAction, QComboBox, QAction, QSizePolicy, QInputDialog) + +from PyQtAds import QtAds + +UI_FILE = os.path.join(os.path.dirname(__file__), 'mainwindow.ui') +MainWindowUI, MainWindowBase = uic.loadUiType(UI_FILE) + +class MainWindow(MainWindowUI, MainWindowBase): + + def __init__(self, parent=None): + super().__init__(parent) + + self.setupUi(self) + + QtAds.CDockManager.setConfigFlag(QtAds.CDockManager.OpaqueSplitterResize, True) + QtAds.CDockManager.setConfigFlag(QtAds.CDockManager.XmlCompressionEnabled, False) + QtAds.CDockManager.setConfigFlag(QtAds.CDockManager.FocusHighlighting, True) + self.dock_manager = QtAds.CDockManager(self) + + # Set central widget + text_edit = QPlainTextEdit() + text_edit.setPlaceholderText("This is the central editor. Enter your text here.") + central_dock_widget = QtAds.CDockWidget("CentralWidget") + central_dock_widget.setWidget(text_edit) + central_dock_area = self.dock_manager.setCentralWidget(central_dock_widget) + central_dock_area.setAllowedAreas(QtAds.DockWidgetArea.OuterDockAreas) + + # create other dock widgets + table = QTableWidget() + table.setColumnCount(3) + table.setRowCount(10) + table_dock_widget = QtAds.CDockWidget("Table 1") + table_dock_widget.setWidget(table) + table_dock_widget.setMinimumSizeHintMode(QtAds.CDockWidget.MinimumSizeHintFromDockWidget) + table_dock_widget.resize(250, 150) + table_dock_widget.setMinimumSize(200, 150) + table_area = self.dock_manager.addDockWidget(QtAds.DockWidgetArea.LeftDockWidgetArea, table_dock_widget) + self.menuView.addAction(table_dock_widget.toggleViewAction()) + + table = QTableWidget() + table.setColumnCount(5) + table.setRowCount(1020) + table_dock_widget = QtAds.CDockWidget("Table 2") + table_dock_widget.setWidget(table) + table_dock_widget.setMinimumSizeHintMode(QtAds.CDockWidget.MinimumSizeHintFromDockWidget) + table_dock_widget.resize(250, 150) + table_dock_widget.setMinimumSize(200, 150) + table_area = self.dock_manager.addDockWidget(QtAds.DockWidgetArea.BottomDockWidgetArea, table_dock_widget, table_area) + self.menuView.addAction(table_dock_widget.toggleViewAction()) + + properties_table = QTableWidget() + properties_table.setColumnCount(3) + properties_table.setRowCount(10) + properties_dock_widget = QtAds.CDockWidget("Properties") + properties_dock_widget.setWidget(properties_table) + properties_dock_widget.setMinimumSizeHintMode(QtAds.CDockWidget.MinimumSizeHintFromDockWidget) + properties_dock_widget.resize(250, 150) + properties_dock_widget.setMinimumSize(200, 150) + self.dock_manager.addDockWidget(QtAds.DockWidgetArea.RightDockWidgetArea, properties_dock_widget, central_dock_area) + self.menuView.addAction(properties_dock_widget.toggleViewAction()) + + self.create_perspective_ui() + + def create_perspective_ui(self): + save_perspective_action = QAction("Create Perspective", self) + save_perspective_action.triggered.connect(self.save_perspective) + perspective_list_action = QWidgetAction(self) + self.perspective_combobox = QComboBox(self) + self.perspective_combobox.setSizeAdjustPolicy(QComboBox.AdjustToContents) + self.perspective_combobox.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Preferred) + self.perspective_combobox.activated[str].connect(self.dock_manager.openPerspective) + perspective_list_action.setDefaultWidget(self.perspective_combobox) + self.toolBar.addSeparator() + self.toolBar.addAction(perspective_list_action) + self.toolBar.addAction(save_perspective_action) + + def save_perspective(self): + perspective_name, ok = QInputDialog.getText(self, "Save Perspective", "Enter Unique name:") + if not ok or not perspective_name: + return + + self.dock_manager.addPerspective(perspective_name) + blocker = QSignalBlocker(self.perspective_combobox) + self.perspective_combobox.clear() + self.perspective_combobox.addItems(self.dock_manager.perspectiveNames()) + self.perspective_combobox.setCurrentText(perspective_name) + + def closeEvent(self, event: QCloseEvent): + self.dock_manager.deleteLater() + super().closeEvent(event) + + +if __name__ == '__main__': + app = QApplication(sys.argv) + + w = MainWindow() + w.show() + app.exec_() diff --git a/examples/autohide/mainwindow.cpp b/examples/autohide/mainwindow.cpp new file mode 100644 index 0000000..3ad0056 --- /dev/null +++ b/examples/autohide/mainwindow.cpp @@ -0,0 +1,133 @@ +#include "mainwindow.h" + +#include "ui_mainwindow.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "DockAreaWidget.h" +#include "DockAreaTitleBar.h" +#include "DockAreaTabBar.h" +#include "FloatingDockContainer.h" +#include "DockComponentsFactory.h" + +using namespace ads; + + +CMainWindow::CMainWindow(QWidget *parent) + : QMainWindow(parent) + , ui(new Ui::CMainWindow) +{ + ui->setupUi(this); + CDockManager::setConfigFlag(CDockManager::OpaqueSplitterResize, true); + CDockManager::setConfigFlag(CDockManager::XmlCompressionEnabled, false); + CDockManager::setConfigFlag(CDockManager::FocusHighlighting, true); + DockManager = new CDockManager(this); + + // Set central widget + QPlainTextEdit* w = new QPlainTextEdit(); + w->setPlaceholderText("This is the central editor. Enter your text here."); + CDockWidget* CentralDockWidget = new CDockWidget("CentralWidget"); + CentralDockWidget->setWidget(w); + auto* CentralDockArea = DockManager->setCentralWidget(CentralDockWidget); + CentralDockArea->setAllowedAreas(DockWidgetArea::OuterDockAreas); + + // create other dock widgets + QTableWidget* table = new QTableWidget(); + table->setColumnCount(3); + table->setRowCount(10); + CDockWidget* TableDockWidget = new CDockWidget("Table 1"); + TableDockWidget->setWidget(table); + TableDockWidget->setMinimumSizeHintMode(CDockWidget::MinimumSizeHintFromDockWidget); + TableDockWidget->resize(250, 150); + TableDockWidget->setMinimumSize(200,150); + auto TableArea = DockManager->addDockWidget(DockWidgetArea::LeftDockWidgetArea, TableDockWidget); + ui->menuView->addAction(TableDockWidget->toggleViewAction()); + + table = new QTableWidget(); + table->setColumnCount(5); + table->setRowCount(1020); + TableDockWidget = new CDockWidget("Table 2"); + TableDockWidget->setWidget(table); + TableDockWidget->setMinimumSizeHintMode(CDockWidget::MinimumSizeHintFromDockWidget); + TableDockWidget->resize(250, 150); + TableDockWidget->setMinimumSize(200,150); + DockManager->addDockWidget(DockWidgetArea::BottomDockWidgetArea, TableDockWidget, TableArea); + ui->menuView->addAction(TableDockWidget->toggleViewAction()); + + QTableWidget* propertiesTable = new QTableWidget(); + propertiesTable->setColumnCount(3); + propertiesTable->setRowCount(10); + CDockWidget* PropertiesDockWidget = new CDockWidget("Properties"); + PropertiesDockWidget->setWidget(propertiesTable); + PropertiesDockWidget->setMinimumSizeHintMode(CDockWidget::MinimumSizeHintFromDockWidget); + PropertiesDockWidget->resize(250, 150); + PropertiesDockWidget->setMinimumSize(200,150); + DockManager->addDockWidget(DockWidgetArea::RightDockWidgetArea, PropertiesDockWidget, CentralDockArea); + ui->menuView->addAction(PropertiesDockWidget->toggleViewAction()); + + createPerspectiveUi(); +} + +CMainWindow::~CMainWindow() +{ + delete ui; +} + + +void CMainWindow::createPerspectiveUi() +{ + SavePerspectiveAction = new QAction("Create Perspective", this); + connect(SavePerspectiveAction, SIGNAL(triggered()), SLOT(savePerspective())); + PerspectiveListAction = new QWidgetAction(this); + PerspectiveComboBox = new QComboBox(this); + PerspectiveComboBox->setSizeAdjustPolicy(QComboBox::AdjustToContents); + PerspectiveComboBox->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred); + connect(PerspectiveComboBox, SIGNAL(currentTextChanged(const QString&)), + DockManager, SLOT(openPerspective(const QString&))); + PerspectiveListAction->setDefaultWidget(PerspectiveComboBox); + ui->toolBar->addSeparator(); + ui->toolBar->addAction(PerspectiveListAction); + ui->toolBar->addAction(SavePerspectiveAction); +} + + +void CMainWindow::savePerspective() +{ + QString PerspectiveName = QInputDialog::getText(this, "Save Perspective", "Enter unique name:"); + if (PerspectiveName.isEmpty()) + { + return; + } + + DockManager->addPerspective(PerspectiveName); + QSignalBlocker Blocker(PerspectiveComboBox); + PerspectiveComboBox->clear(); + PerspectiveComboBox->addItems(DockManager->perspectiveNames()); + PerspectiveComboBox->setCurrentText(PerspectiveName); +} + + +//============================================================================ +void CMainWindow::closeEvent(QCloseEvent* event) +{ + // Delete dock manager here to delete all floating widgets. This ensures + // that all top level windows of the dock manager are properly closed + DockManager->deleteLater(); + QMainWindow::closeEvent(event); +} + + diff --git a/examples/autohide/mainwindow.h b/examples/autohide/mainwindow.h new file mode 100644 index 0000000..75869da --- /dev/null +++ b/examples/autohide/mainwindow.h @@ -0,0 +1,43 @@ +#ifndef MAINWINDOW_H +#define MAINWINDOW_H + +#include +#include +#include + +#include "DockManager.h" +#include "DockAreaWidget.h" +#include "DockWidget.h" + +QT_BEGIN_NAMESPACE +namespace Ui { class CMainWindow; } +QT_END_NAMESPACE + +class CMainWindow : public QMainWindow +{ + Q_OBJECT + +public: + CMainWindow(QWidget *parent = nullptr); + ~CMainWindow(); + +protected: + virtual void closeEvent(QCloseEvent* event) override; + +private: + QAction* SavePerspectiveAction = nullptr; + QWidgetAction* PerspectiveListAction = nullptr; + QComboBox* PerspectiveComboBox = nullptr; + + Ui::CMainWindow *ui; + + ads::CDockManager* DockManager; + ads::CDockAreaWidget* StatusDockArea; + ads::CDockWidget* TimelineDockWidget; + + void createPerspectiveUi(); + +private slots: + void savePerspective(); +}; +#endif // MAINWINDOW_H diff --git a/examples/autohide/mainwindow.ui b/examples/autohide/mainwindow.ui new file mode 100644 index 0000000..f7d3b09 --- /dev/null +++ b/examples/autohide/mainwindow.ui @@ -0,0 +1,47 @@ + + + CMainWindow + + + + 0 + 0 + 1284 + 757 + + + + MainWindow + + + + + + 0 + 0 + 1284 + 21 + + + + + View + + + + + + + toolBar + + + TopToolBarArea + + + false + + + + + + diff --git a/examples/centralwidget/CMakeLists.txt b/examples/centralwidget/CMakeLists.txt index 7f57821..cec3910 100644 --- a/examples/centralwidget/CMakeLists.txt +++ b/examples/centralwidget/CMakeLists.txt @@ -1,19 +1,19 @@ cmake_minimum_required(VERSION 3.5) -project(ads_example_centralwidget VERSION ${VERSION_SHORT}) +project(ads_example_autohide VERSION ${VERSION_SHORT}) find_package(QT NAMES Qt6 Qt5 COMPONENTS Core REQUIRED) find_package(Qt${QT_VERSION_MAJOR} 5.5 COMPONENTS Core Gui Widgets REQUIRED) set(CMAKE_INCLUDE_CURRENT_DIR ON) -add_executable(CentralWidgetExample WIN32 +add_executable(AutoHideExample WIN32 main.cpp mainwindow.cpp mainwindow.ui ) -target_include_directories(CentralWidgetExample PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/../../src") -target_link_libraries(CentralWidgetExample PRIVATE qtadvanceddocking) -target_link_libraries(CentralWidgetExample PUBLIC Qt${QT_VERSION_MAJOR}::Core +target_include_directories(AutoHideExample PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/../../src") +target_link_libraries(AutoHideExample PRIVATE qtadvanceddocking) +target_link_libraries(AutoHideExample PUBLIC Qt${QT_VERSION_MAJOR}::Core Qt${QT_VERSION_MAJOR}::Gui Qt${QT_VERSION_MAJOR}::Widgets) -set_target_properties(CentralWidgetExample PROPERTIES +set_target_properties(AutoHideExample PROPERTIES AUTOMOC ON AUTORCC ON AUTOUIC ON @@ -21,7 +21,7 @@ set_target_properties(CentralWidgetExample PROPERTIES CXX_STANDARD_REQUIRED ON CXX_EXTENSIONS OFF VERSION ${VERSION_SHORT} - EXPORT_NAME "Qt Advanced Docking System Central Widget Example" + EXPORT_NAME "Qt Advanced Docking System Auto Hide Example" ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${ads_PlatformDir}/lib" LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${ads_PlatformDir}/lib" RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${ads_PlatformDir}/bin" diff --git a/examples/centralwidget/centralwidget.pro b/examples/centralwidget/autohide.pro similarity index 92% rename from examples/centralwidget/centralwidget.pro rename to examples/centralwidget/autohide.pro index 738ae78..824b451 100644 --- a/examples/centralwidget/centralwidget.pro +++ b/examples/centralwidget/autohide.pro @@ -2,7 +2,7 @@ ADS_OUT_ROOT = $${OUT_PWD}/../.. QT += core gui widgets -TARGET = CentralWidgetExample +TARGET = AutoHideExample DESTDIR = $${ADS_OUT_ROOT}/lib TEMPLATE = app CONFIG += c++14 @@ -24,9 +24,6 @@ SOURCES += \ HEADERS += \ mainwindow.h -FORMS += \ - mainwindow.ui - LIBS += -L$${ADS_OUT_ROOT}/lib include(../../ads.pri) INCLUDEPATH += ../../src diff --git a/examples/centralwidget/mainwindow.cpp b/examples/centralwidget/mainwindow.cpp index 3ad0056..eca2e94 100644 --- a/examples/centralwidget/mainwindow.cpp +++ b/examples/centralwidget/mainwindow.cpp @@ -54,7 +54,7 @@ CMainWindow::CMainWindow(QWidget *parent) TableDockWidget->setMinimumSizeHintMode(CDockWidget::MinimumSizeHintFromDockWidget); TableDockWidget->resize(250, 150); TableDockWidget->setMinimumSize(200,150); - auto TableArea = DockManager->addDockWidget(DockWidgetArea::LeftDockWidgetArea, TableDockWidget); + DockManager->addOverlayDockWidget(SideTabBarArea::Left, TableDockWidget); ui->menuView->addAction(TableDockWidget->toggleViewAction()); table = new QTableWidget(); @@ -65,7 +65,7 @@ CMainWindow::CMainWindow(QWidget *parent) TableDockWidget->setMinimumSizeHintMode(CDockWidget::MinimumSizeHintFromDockWidget); TableDockWidget->resize(250, 150); TableDockWidget->setMinimumSize(200,150); - DockManager->addDockWidget(DockWidgetArea::BottomDockWidgetArea, TableDockWidget, TableArea); + DockManager->addOverlayDockWidget(SideTabBarArea::Left, TableDockWidget); ui->menuView->addAction(TableDockWidget->toggleViewAction()); QTableWidget* propertiesTable = new QTableWidget(); diff --git a/src/DockAreaWidget.cpp b/src/DockAreaWidget.cpp index dba2568..6026486 100644 --- a/src/DockAreaWidget.cpp +++ b/src/DockAreaWidget.cpp @@ -1030,7 +1030,7 @@ void CDockAreaWidget::onAutoHideToggleRequested(CDockWidget* DockWidget, bool En { dockContainer()->sideTabBar(area)->insertSideTab(0, DockWidget->sideTabWidget()); DockWidget->sideTabWidget()->show(); - dockContainer()->createDockWidgetOverlayContainer(area, DockWidget); + dockContainer()->createAndInitializeDockWidgetOverlayContainer(area, DockWidget); toggleView(false); } else diff --git a/src/DockContainerWidget.cpp b/src/DockContainerWidget.cpp index eaca38d..bd261af 100644 --- a/src/DockContainerWidget.cpp +++ b/src/DockContainerWidget.cpp @@ -1046,12 +1046,7 @@ bool DockContainerWidgetPrivate::restoreOverlayDockArea(CDockingStateReader& s, ADS_PRINT("Restore NodeDockArea Tabs: " << Tabs << " Current: " << CurrentDockWidget); - if (area == Left && !CDockManager::testConfigFlag(CDockManager::DockContainerHasLeftSideBar)) - { - return false; - } - - if (area == Right && !CDockManager::testConfigFlag(CDockManager::DockContainerHasRightSideBar)) + if (!COverlayDockContainer::areaExistsInConfig(area)) { return false; } @@ -1497,14 +1492,26 @@ CDockAreaWidget* CDockContainerWidget::addDockWidget(DockWidgetArea area, CDockW } } -void CDockContainerWidget::createDockWidgetOverlayContainer(SideTabBarArea area, CDockWidget* DockWidget) + +//============================================================================ +COverlayDockContainer* CDockContainerWidget::createAndInitializeDockWidgetOverlayContainer(SideTabBarArea area, CDockWidget* DockWidget) { if (d->DockManager != DockWidget->dockManager()) { DockWidget->setDockManager(d->DockManager); // Overlay Dock Container needs a valid dock manager } + if (!COverlayDockContainer::areaExistsInConfig(area)) + { + assert(false, "Requested area does not exist in config"); + return nullptr; + } + + sideTabBar(area)->insertSideTab(0, DockWidget->sideTabWidget()); + DockWidget->sideTabWidget()->show(); + const auto dockContainer = new COverlayDockContainer(DockWidget, area); dockContainer->hide(); + return dockContainer; } //============================================================================ diff --git a/src/DockContainerWidget.h b/src/DockContainerWidget.h index e895fd5..9d93b6f 100644 --- a/src/DockContainerWidget.h +++ b/src/DockContainerWidget.h @@ -88,6 +88,14 @@ protected: */ QSplitter* rootSplitter() const; + + /** + * Creates and initializes a dockwidget overlay container into the given area. + * Initializing inserts the tabs into the side tab widget and hides it + * Returns nullptr if you try and insert into an area where the configuration is not enabled + */ + COverlayDockContainer* createAndInitializeDockWidgetOverlayContainer(SideTabBarArea area, CDockWidget* DockWidget); + /** * Helper function for creation of the root splitter */ @@ -191,11 +199,6 @@ public: CDockAreaWidget* addDockWidget(DockWidgetArea area, CDockWidget* Dockwidget, CDockAreaWidget* DockAreaWidget = nullptr); - /** - * Creates and adds a dockwidget overlay container into the given area. - */ - void createDockWidgetOverlayContainer(SideTabBarArea area, CDockWidget* DockWidget); - /** * Get's the overlay dock side tab bar area based on the dock area widget position */ diff --git a/src/DockManager.cpp b/src/DockManager.cpp index 33c402e..4f4787d 100644 --- a/src/DockManager.cpp +++ b/src/DockManager.cpp @@ -865,7 +865,7 @@ CDockAreaWidget* CDockManager::addDockWidget(DockWidgetArea area, CDockWidget* Dockwidget, CDockAreaWidget* DockAreaWidget) { d->DockWidgetsMap.insert(Dockwidget->objectName(), Dockwidget); - auto Container = DockAreaWidget ? DockAreaWidget->dockContainer(): this; + auto Container = DockAreaWidget ? DockAreaWidget->dockContainer() : this; auto AreaOfAddedDockWidget = Container->addDockWidget(area, Dockwidget, DockAreaWidget); Q_EMIT dockWidgetAdded(Dockwidget); return AreaOfAddedDockWidget; @@ -881,6 +881,24 @@ CDockAreaWidget* CDockManager::addDockWidgetToContainer(DockWidgetArea area, return AreaOfAddedDockWidget; } +//============================================================================ +COverlayDockContainer* CDockManager::addOverlayDockWidget(SideTabBarArea area, CDockWidget* Dockwidget) +{ + return addOverlayDockWidgetToContainer(area, Dockwidget, this); +} + +//============================================================================ +COverlayDockContainer* CDockManager::addOverlayDockWidgetToContainer(SideTabBarArea area, CDockWidget* Dockwidget, CDockContainerWidget* DockContainerWidget) +{ + d->DockWidgetsMap.insert(Dockwidget->objectName(), Dockwidget); + auto container = DockContainerWidget->createAndInitializeDockWidgetOverlayContainer(area, Dockwidget); + container->dockAreaWidget()->toggleView(false); + Dockwidget->toggleView(false); + + Q_EMIT dockWidgetAdded(Dockwidget); + return container; +} + //============================================================================ CDockAreaWidget* CDockManager::addDockWidgetTab(DockWidgetArea area, diff --git a/src/DockManager.h b/src/DockManager.h index 17b8bc2..272aa19 100644 --- a/src/DockManager.h +++ b/src/DockManager.h @@ -315,6 +315,20 @@ public: CDockAreaWidget* addDockWidgetToContainer(DockWidgetArea area, CDockWidget* Dockwidget, CDockContainerWidget* DockContainerWidget); + /** + * Adds a dock widget overlayed into the dock manager container based on the side tab bar area. + * An overlay widget is used for auto hide functionality + * \return Returns the COverlayDockContainer that contains the new DockWidget + */ + COverlayDockContainer* addOverlayDockWidget(SideTabBarArea area, CDockWidget* Dockwidget); + + /** + * Adds dock widget overlayed into the given container based on the SideTabBarArea. + * An overlay widget is used for auto hide functionality + * \return Returns the COverlayDockContainer that contains the new DockWidget + */ + COverlayDockContainer* addOverlayDockWidgetToContainer(SideTabBarArea area, CDockWidget* Dockwidget, CDockContainerWidget* DockContainerWidget); + /** * This function will add the given Dockwidget to the given dock area as * a new tab. diff --git a/src/OverlayDockContainer.cpp b/src/OverlayDockContainer.cpp index 75b6a14..0eaf84d 100644 --- a/src/OverlayDockContainer.cpp +++ b/src/OverlayDockContainer.cpp @@ -105,11 +105,6 @@ COverlayDockContainer::COverlayDockContainer(CDockManager* DockManager, SideTabB d->Splitter->addWidget(d->DockArea); } - // Allows an equal distribution between the empty widget and the splitter - const auto frameGeometry = d->DockManager->frameGeometry(); - const auto leftSize = area == SideTabBarArea::Left ? frameGeometry.width() / 3 : frameGeometry.width(); - const auto rightSize = area == SideTabBarArea::Left ? frameGeometry.width() : frameGeometry.width() / 3; - d->Splitter->setSizes(QList({ leftSize, rightSize })); l->setContentsMargins(QMargins()); l->setSpacing(0); l->addWidget(d->Splitter); @@ -282,6 +277,20 @@ bool COverlayDockContainer::restoreState(CDockingStateReader& s, bool Testing) return true; } +bool COverlayDockContainer::areaExistsInConfig(SideTabBarArea area) +{ + if (area == Left && !CDockManager::testConfigFlag(CDockManager::DockContainerHasLeftSideBar)) + { + return false; + } + if (area == Right && !CDockManager::testConfigFlag(CDockManager::DockContainerHasRightSideBar)) + { + return false; + } + + return true; +} + //============================================================================ bool COverlayDockContainer::eventFilter(QObject* watched, QEvent* event) { diff --git a/src/OverlayDockContainer.h b/src/OverlayDockContainer.h index 1fe7e15..e826e9c 100644 --- a/src/OverlayDockContainer.h +++ b/src/OverlayDockContainer.h @@ -122,6 +122,11 @@ public: * Restores the size of the splitter */ bool restoreState(CDockingStateReader& Stream, bool Testing); + + /* + * Convenience function fr determining if area exists in config + */ + static bool areaExistsInConfig(SideTabBarArea area); }; }