From ff1439c719ac7eefafb175f488a13dd2134eec0b Mon Sep 17 00:00:00 2001 From: Uwe Kindler Date: Tue, 11 Feb 2020 08:32:49 +0100 Subject: [PATCH] Added CDockComponentsFactory for creation of components for the docking framework --- CMakeLists.txt | 2 + src/DockAreaTitleBar.cpp | 3 +- src/DockAreaWidget.cpp | 9 +++-- src/DockComponentsFactory.cpp | 61 +++++++++++++++++++++++++++++++ src/DockComponentsFactory.h | 69 +++++++++++++++++++++++++++++++++++ src/DockManager.h | 1 + src/DockWidget.cpp | 3 +- src/src.pro | 6 ++- 8 files changed, 146 insertions(+), 8 deletions(-) create mode 100644 src/DockComponentsFactory.cpp create mode 100644 src/DockComponentsFactory.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 9a4b6b1..578dfc1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -42,6 +42,7 @@ set(ads_SRCS src/FloatingDockContainer.cpp src/FloatingDragPreview.cpp src/IconProvider.cpp + src/DockComponentsFactory.cpp src/ads.qrc src/linux/FloatingWidgetTitleBar.cpp ) @@ -61,6 +62,7 @@ set(ads_INSTALL_INCLUDE src/FloatingDockContainer.h src/FloatingDragPreview.h src/IconProvider.h + src/DockComponentsFactory.h src/linux/FloatingWidgetTitleBar.h ) if("${CMAKE_SIZEOF_VOID_P}" STREQUAL "4") diff --git a/src/DockAreaTitleBar.cpp b/src/DockAreaTitleBar.cpp index 8aa724e..a5024e5 100644 --- a/src/DockAreaTitleBar.cpp +++ b/src/DockAreaTitleBar.cpp @@ -49,6 +49,7 @@ #include "DockWidgetTab.h" #include "DockAreaTabBar.h" #include "IconProvider.h" +#include "DockComponentsFactory.h" #include @@ -273,7 +274,7 @@ void DockAreaTitleBarPrivate::createButtons() //============================================================================ void DockAreaTitleBarPrivate::createTabBar() { - TabBar = new CDockAreaTabBar(DockArea); + TabBar = componentsFactory()->createDockAreaTabBar(DockArea); TabBar->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Preferred); Layout->addWidget(TabBar); _this->connect(TabBar, SIGNAL(tabClosed(int)), SLOT(markTabsMenuOutdated())); diff --git a/src/DockAreaWidget.cpp b/src/DockAreaWidget.cpp index 354102d..cda1d65 100644 --- a/src/DockAreaWidget.cpp +++ b/src/DockAreaWidget.cpp @@ -28,9 +28,10 @@ //============================================================================ // INCLUDES //============================================================================ -#include "DockWidgetTab.h" #include "DockAreaWidget.h" +#include + #include #include #include @@ -53,8 +54,8 @@ #include "DockAreaTabBar.h" #include "DockSplitter.h" #include "DockAreaTitleBar.h" - -#include +#include "DockComponentsFactory.h" +#include "DockWidgetTab.h" namespace ads @@ -317,7 +318,7 @@ DockAreaWidgetPrivate::DockAreaWidgetPrivate(CDockAreaWidget* _public) : //============================================================================ void DockAreaWidgetPrivate::createTitleBar() { - TitleBar = new CDockAreaTitleBar(_this); + TitleBar = componentsFactory()->createDockAreaTitleBar(_this); Layout->addWidget(TitleBar); QObject::connect(tabBar(), &CDockAreaTabBar::tabCloseRequested, _this, &CDockAreaWidget::onTabCloseRequested); QObject::connect(TitleBar, &CDockAreaTitleBar::tabBarClicked, _this, &CDockAreaWidget::setCurrentIndex); diff --git a/src/DockComponentsFactory.cpp b/src/DockComponentsFactory.cpp new file mode 100644 index 0000000..e41dff1 --- /dev/null +++ b/src/DockComponentsFactory.cpp @@ -0,0 +1,61 @@ +//============================================================================ +/// \file DockComponentsFactory.cpp +/// \author Uwe Kindler +/// \date 10.02.2020 +/// \brief Implementation of DockComponentsFactory +//============================================================================ + +//============================================================================ +// INCLUDES +//============================================================================ +#include +#include + +#include "DockWidgetTab.h" +#include "DockAreaTabBar.h" +#include "DockAreaTitleBar.h" +#include "DockWidget.h" +#include "DockAreaWidget.h" + +namespace ads +{ +static QScopedPointer DefaultFactory(new CDockComponentsFactory()); + + +//============================================================================ +CDockWidgetTab* CDockComponentsFactory::createDockWidgetTab(CDockWidget* DockWidget) const +{ + return new CDockWidgetTab(DockWidget); +} + + +//============================================================================ +CDockAreaTabBar* CDockComponentsFactory::createDockAreaTabBar(CDockAreaWidget* DockArea) const +{ + return new CDockAreaTabBar(DockArea); +} + + +//============================================================================ +CDockAreaTitleBar* CDockComponentsFactory::createDockAreaTitleBar(CDockAreaWidget* DockArea) const +{ + return new CDockAreaTitleBar(DockArea); +} + + +//============================================================================ +const CDockComponentsFactory* CDockComponentsFactory::defaultFactory() +{ + return DefaultFactory.get(); +} + + +//============================================================================ +void CDockComponentsFactory::setDefaultFactory(CDockComponentsFactory* Factory) +{ + DefaultFactory.reset(Factory); +} +} // namespace ads + +//--------------------------------------------------------------------------- +// EOF DockComponentsFactory.cpp diff --git a/src/DockComponentsFactory.h b/src/DockComponentsFactory.h new file mode 100644 index 0000000..8b9925a --- /dev/null +++ b/src/DockComponentsFactory.h @@ -0,0 +1,69 @@ +#ifndef DockComponentsFactoryH +#define DockComponentsFactoryH +//============================================================================ +/// \file DockComponentsFactory.h +/// \author Uwe Kindler +/// \date 10.02.2020 +/// \brief Declaration of DockComponentsFactory +//============================================================================ + +//============================================================================ +// INCLUDES +//============================================================================ +namespace ads +{ +class CDockWidgetTab; +class CDockAreaTitleBar; +class CDockAreaTabBar; +class CDockAreaWidget; +class CDockWidget; + + + +/** + * Factory for creation of certain GUI elements for the docking framework. + * A default unique instance provided by CDockComponentsFactory is used for + * creation of all supported components. To inject your custom components, + * you can create your own derived dock components factory and register + * it via setDefaultFactory() function. + * \code + * CDockComponentsFactory::setDefaultFactory(new MyComponentsFactory())); + * \endcode + */ +class CDockComponentsFactory +{ +public: + /** + * Force virtual destructor + */ + virtual ~CDockComponentsFactory() {} + + virtual CDockWidgetTab* createDockWidgetTab(CDockWidget* DockWidget) const; + virtual CDockAreaTabBar* createDockAreaTabBar(CDockAreaWidget* DockArea) const; + virtual CDockAreaTitleBar* createDockAreaTitleBar(CDockAreaWidget* DockArea) const; + + /** + * Returns the default components factory + */ + static const CDockComponentsFactory* defaultFactory(); + + /** + * Sets a new default factory for creation of GUI elements. + * This function takes ownership of the given Factory. + */ + static void setDefaultFactory(CDockComponentsFactory* Factory); +}; + + +/** + * Convenience function to ease factory instance access + */ +inline const CDockComponentsFactory* componentsFactory() +{ + return CDockComponentsFactory::defaultFactory(); +} + +} // namespace ads + +//--------------------------------------------------------------------------- +#endif // DockComponentsFactoryH diff --git a/src/DockManager.h b/src/DockManager.h index 73f6c22..dc099a2 100644 --- a/src/DockManager.h +++ b/src/DockManager.h @@ -59,6 +59,7 @@ class CDockWidgetTab; struct DockWidgetTabPrivate; struct DockAreaWidgetPrivate; class CIconProvider; +class CDockComponentsFactory; /** * The central dock manager that maintains the complete docking system. diff --git a/src/DockWidget.cpp b/src/DockWidget.cpp index 3080a62..338a5fa 100644 --- a/src/DockWidget.cpp +++ b/src/DockWidget.cpp @@ -54,6 +54,7 @@ #include "DockManager.h" #include "FloatingDockContainer.h" #include "DockSplitter.h" +#include "DockComponentsFactory.h" #include "ads_globals.h" @@ -220,7 +221,7 @@ CDockWidget::CDockWidget(const QString &title, QWidget *parent) : setWindowTitle(title); setObjectName(title); - d->TabWidget = new CDockWidgetTab(this); + d->TabWidget = componentsFactory()->createDockWidgetTab(this); d->ToggleViewAction = new QAction(title, this); d->ToggleViewAction->setCheckable(true); connect(d->ToggleViewAction, SIGNAL(triggered(bool)), this, diff --git a/src/src.pro b/src/src.pro index 755c7e5..73367b0 100644 --- a/src/src.pro +++ b/src/src.pro @@ -43,7 +43,8 @@ HEADERS += \ DockSplitter.h \ DockAreaTitleBar.h \ ElidingLabel.h \ - IconProvider.h + IconProvider.h \ + DockComponentsFactory.h SOURCES += \ @@ -61,7 +62,8 @@ SOURCES += \ DockSplitter.cpp \ DockAreaTitleBar.cpp \ ElidingLabel.cpp \ - IconProvider.cpp + IconProvider.cpp \ + DockComponentsFactory.cpp unix {