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 "DockAreaTabBar.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)
{
@ -202,28 +223,29 @@ static ads::CDockWidget* createEditorWidget(QMenu* ViewMenu)
return DockWidget;
}
//============================================================================
static ads::CDockWidget* createTableWidget(QMenu* ViewMenu)
{
static int TableCount = 0;
QTableWidget* w = new QTableWidget();
ads::CDockWidget* DockWidget = new ads::CDockWidget(QString("Table %1").arg(TableCount++));
static int colCount = 5;
static int rowCount = 30;
w->setColumnCount(colCount);
w->setRowCount(rowCount);
for (int col = 0; col < colCount; ++col)
{
w->setHorizontalHeaderItem(col, new QTableWidgetItem(QString("Col %1").arg(col+1)));
for (int row = 0; row < rowCount; ++row)
{
w->setItem(row, col, new QTableWidgetItem(QString("T %1-%2").arg(row + 1).arg(col+1)));
}
}
DockWidget->setWidget(w);
DockWidget->setIcon(svgIcon(":/adsdemo/images/grid_on.svg"));
ViewMenu->addAction(DockWidget->toggleViewAction());
return DockWidget;
static int TableCount = 0;
QTableWidget* w = new QTableWidget();
ads::CDockWidget* DockWidget = new ads::CDockWidget(QString("Table %1").arg(TableCount++));
static int colCount = 5;
static int rowCount = 30;
w->setColumnCount(colCount);
w->setRowCount(rowCount);
for (int col = 0; col < colCount; ++col)
{
w->setHorizontalHeaderItem(col, new QTableWidgetItem(QString("Col %1").arg(col+1)));
for (int row = 0; row < rowCount; ++row)
{
w->setItem(row, col, new QTableWidgetItem(QString("T %1-%2").arg(row + 1).arg(col+1)));
}
}
DockWidget->setWidget(w);
DockWidget->setIcon(svgIcon(":/adsdemo/images/grid_on.svg"));
ViewMenu->addAction(DockWidget->toggleViewAction());
return DockWidget;
}
@ -318,7 +340,11 @@ void MainWindowPrivate::createContent()
FileSystemWidget->setFeature(ads::CDockWidget::DockWidgetMovable, false);
FileSystemWidget->setFeature(ads::CDockWidget::DockWidgetFloatable, false);
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);
ads::CDockComponentsFactory::resetDefaultFactory();
// We create a calender widget and clear all flags to prevent the dock area
// from closing

View File

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

View File

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

View File

@ -10,6 +10,8 @@
//============================================================================
// INCLUDES
//============================================================================
#include "ads_globals.h"
namespace ads
{
class CDockWidgetTab;
@ -30,7 +32,7 @@ class CDockWidget;
* CDockComponentsFactory::setDefaultFactory(new MyComponentsFactory()));
* \endcode
*/
class CDockComponentsFactory
class ADS_EXPORT CDockComponentsFactory
{
public:
/**
@ -45,13 +47,18 @@ public:
/**
* Returns the default components factory
*/
static const CDockComponentsFactory* defaultFactory();
static const CDockComponentsFactory* factory();
/**
* Sets a new default factory for creation of GUI elements.
* 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()
{
return CDockComponentsFactory::defaultFactory();
return CDockComponentsFactory::factory();
}
} // namespace ads