Added showcase for DockComponentsFactory - a help button is injected into a title bar

This commit is contained in:
Uwe Kindler 2020-02-11 09:31:57 +01:00
parent ff1439c719
commit 65eeffd5e1
4 changed files with 66 additions and 25 deletions

View File

@ -73,6 +73,8 @@
#include "DockAreaTitleBar.h" #include "DockAreaTitleBar.h"
#include "DockAreaTabBar.h" #include "DockAreaTabBar.h"
#include "FloatingDockContainer.h" #include "FloatingDockContainer.h"
#include "DockComponentsFactory.h"
//============================================================================ //============================================================================
@ -142,6 +144,25 @@ static QIcon svgIcon(const QString& File)
} }
//============================================================================
class CCustomComponentsFactory : public ads::CDockComponentsFactory
{
public:
using Super = ads::CDockComponentsFactory;
ads::CDockAreaTitleBar* createDockAreaTitleBar(ads::CDockAreaWidget* DockArea) const override
{
auto TitleBar = Super::createDockAreaTitleBar(DockArea);
auto CustomButton = new QToolButton(DockArea);
CustomButton->setToolTip(QObject::tr("Help"));
CustomButton->setIcon(svgIcon(":/adsdemo/images/help_outline.svg"));
CustomButton->setAutoRaise(true);
int Index = TitleBar->indexOf(TitleBar->button(ads::TitleBarButtonTabsMenu));
TitleBar->insertWidget(Index + 1, CustomButton);
return TitleBar;
}
};
//============================================================================ //============================================================================
static ads::CDockWidget* createCalendarDockWidget(QMenu* ViewMenu) static ads::CDockWidget* createCalendarDockWidget(QMenu* ViewMenu)
{ {
@ -202,6 +223,7 @@ static ads::CDockWidget* createEditorWidget(QMenu* ViewMenu)
return DockWidget; return DockWidget;
} }
//============================================================================ //============================================================================
static ads::CDockWidget* createTableWidget(QMenu* ViewMenu) static ads::CDockWidget* createTableWidget(QMenu* ViewMenu)
{ {
@ -318,7 +340,11 @@ void MainWindowPrivate::createContent()
FileSystemWidget->setFeature(ads::CDockWidget::DockWidgetMovable, false); FileSystemWidget->setFeature(ads::CDockWidget::DockWidgetMovable, false);
FileSystemWidget->setFeature(ads::CDockWidget::DockWidgetFloatable, false); FileSystemWidget->setFeature(ads::CDockWidget::DockWidgetFloatable, false);
appendFeaturStringToWindowTitle(FileSystemWidget); appendFeaturStringToWindowTitle(FileSystemWidget);
// Test custom factory - we inject a help button into the title bar
ads::CDockComponentsFactory::setFactory(new CCustomComponentsFactory());
auto TopDockArea = DockManager->addDockWidget(ads::TopDockWidgetArea, FileSystemWidget); auto TopDockArea = DockManager->addDockWidget(ads::TopDockWidgetArea, FileSystemWidget);
ads::CDockComponentsFactory::resetDefaultFactory();
// We create a calender widget and clear all flags to prevent the dock area // We create a calender widget and clear all flags to prevent the dock area
// from closing // from closing

View File

@ -12,5 +12,6 @@
<file>images/custom-menu-button.svg</file> <file>images/custom-menu-button.svg</file>
<file>app.css</file> <file>app.css</file>
<file>images/plus.svg</file> <file>images/plus.svg</file>
<file>images/help_outline.svg</file>
</qresource> </qresource>
</RCC> </RCC>

View File

@ -44,17 +44,24 @@ CDockAreaTitleBar* CDockComponentsFactory::createDockAreaTitleBar(CDockAreaWidge
//============================================================================ //============================================================================
const CDockComponentsFactory* CDockComponentsFactory::defaultFactory() const CDockComponentsFactory* CDockComponentsFactory::factory()
{ {
return DefaultFactory.get(); return DefaultFactory.get();
} }
//============================================================================ //============================================================================
void CDockComponentsFactory::setDefaultFactory(CDockComponentsFactory* Factory) void CDockComponentsFactory::setFactory(CDockComponentsFactory* Factory)
{ {
DefaultFactory.reset(Factory); DefaultFactory.reset(Factory);
} }
//============================================================================
void CDockComponentsFactory::resetDefaultFactory()
{
DefaultFactory.reset(new CDockComponentsFactory());
}
} // namespace ads } // namespace ads
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------

View File

@ -10,6 +10,8 @@
//============================================================================ //============================================================================
// INCLUDES // INCLUDES
//============================================================================ //============================================================================
#include "ads_globals.h"
namespace ads namespace ads
{ {
class CDockWidgetTab; class CDockWidgetTab;
@ -30,7 +32,7 @@ class CDockWidget;
* CDockComponentsFactory::setDefaultFactory(new MyComponentsFactory())); * CDockComponentsFactory::setDefaultFactory(new MyComponentsFactory()));
* \endcode * \endcode
*/ */
class CDockComponentsFactory class ADS_EXPORT CDockComponentsFactory
{ {
public: public:
/** /**
@ -45,13 +47,18 @@ public:
/** /**
* Returns the default components factory * Returns the default components factory
*/ */
static const CDockComponentsFactory* defaultFactory(); static const CDockComponentsFactory* factory();
/** /**
* Sets a new default factory for creation of GUI elements. * Sets a new default factory for creation of GUI elements.
* This function takes ownership of the given Factory. * This function takes ownership of the given Factory.
*/ */
static void setDefaultFactory(CDockComponentsFactory* Factory); static void setFactory(CDockComponentsFactory* Factory);
/**
* Resets the current factory to the
*/
static void resetDefaultFactory();
}; };
@ -60,7 +67,7 @@ public:
*/ */
inline const CDockComponentsFactory* componentsFactory() inline const CDockComponentsFactory* componentsFactory()
{ {
return CDockComponentsFactory::defaultFactory(); return CDockComponentsFactory::factory();
} }
} // namespace ads } // namespace ads