Skip to content

Commit 65eeffd

Browse files
Added showcase for DockComponentsFactory - a help button is injected into a title bar
1 parent ff1439c commit 65eeffd

File tree

4 files changed

+66
-25
lines changed

4 files changed

+66
-25
lines changed

demo/MainWindow.cpp

Lines changed: 45 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@
7373
#include "DockAreaTitleBar.h"
7474
#include "DockAreaTabBar.h"
7575
#include "FloatingDockContainer.h"
76+
#include "DockComponentsFactory.h"
77+
7678

7779

7880
//============================================================================
@@ -142,6 +144,25 @@ static QIcon svgIcon(const QString& File)
142144
}
143145

144146

147+
//============================================================================
148+
class CCustomComponentsFactory : public ads::CDockComponentsFactory
149+
{
150+
public:
151+
using Super = ads::CDockComponentsFactory;
152+
ads::CDockAreaTitleBar* createDockAreaTitleBar(ads::CDockAreaWidget* DockArea) const override
153+
{
154+
auto TitleBar = Super::createDockAreaTitleBar(DockArea);
155+
auto CustomButton = new QToolButton(DockArea);
156+
CustomButton->setToolTip(QObject::tr("Help"));
157+
CustomButton->setIcon(svgIcon(":/adsdemo/images/help_outline.svg"));
158+
CustomButton->setAutoRaise(true);
159+
int Index = TitleBar->indexOf(TitleBar->button(ads::TitleBarButtonTabsMenu));
160+
TitleBar->insertWidget(Index + 1, CustomButton);
161+
return TitleBar;
162+
}
163+
};
164+
165+
145166
//============================================================================
146167
static ads::CDockWidget* createCalendarDockWidget(QMenu* ViewMenu)
147168
{
@@ -202,28 +223,29 @@ static ads::CDockWidget* createEditorWidget(QMenu* ViewMenu)
202223
return DockWidget;
203224
}
204225

226+
205227
//============================================================================
206228
static ads::CDockWidget* createTableWidget(QMenu* ViewMenu)
207229
{
208-
static int TableCount = 0;
209-
QTableWidget* w = new QTableWidget();
210-
ads::CDockWidget* DockWidget = new ads::CDockWidget(QString("Table %1").arg(TableCount++));
211-
static int colCount = 5;
212-
static int rowCount = 30;
213-
w->setColumnCount(colCount);
214-
w->setRowCount(rowCount);
215-
for (int col = 0; col < colCount; ++col)
216-
{
217-
w->setHorizontalHeaderItem(col, new QTableWidgetItem(QString("Col %1").arg(col+1)));
218-
for (int row = 0; row < rowCount; ++row)
219-
{
220-
w->setItem(row, col, new QTableWidgetItem(QString("T %1-%2").arg(row + 1).arg(col+1)));
221-
}
222-
}
223-
DockWidget->setWidget(w);
224-
DockWidget->setIcon(svgIcon(":/adsdemo/images/grid_on.svg"));
225-
ViewMenu->addAction(DockWidget->toggleViewAction());
226-
return DockWidget;
230+
static int TableCount = 0;
231+
QTableWidget* w = new QTableWidget();
232+
ads::CDockWidget* DockWidget = new ads::CDockWidget(QString("Table %1").arg(TableCount++));
233+
static int colCount = 5;
234+
static int rowCount = 30;
235+
w->setColumnCount(colCount);
236+
w->setRowCount(rowCount);
237+
for (int col = 0; col < colCount; ++col)
238+
{
239+
w->setHorizontalHeaderItem(col, new QTableWidgetItem(QString("Col %1").arg(col+1)));
240+
for (int row = 0; row < rowCount; ++row)
241+
{
242+
w->setItem(row, col, new QTableWidgetItem(QString("T %1-%2").arg(row + 1).arg(col+1)));
243+
}
244+
}
245+
DockWidget->setWidget(w);
246+
DockWidget->setIcon(svgIcon(":/adsdemo/images/grid_on.svg"));
247+
ViewMenu->addAction(DockWidget->toggleViewAction());
248+
return DockWidget;
227249
}
228250

229251

@@ -318,7 +340,11 @@ void MainWindowPrivate::createContent()
318340
FileSystemWidget->setFeature(ads::CDockWidget::DockWidgetMovable, false);
319341
FileSystemWidget->setFeature(ads::CDockWidget::DockWidgetFloatable, false);
320342
appendFeaturStringToWindowTitle(FileSystemWidget);
343+
344+
// Test custom factory - we inject a help button into the title bar
345+
ads::CDockComponentsFactory::setFactory(new CCustomComponentsFactory());
321346
auto TopDockArea = DockManager->addDockWidget(ads::TopDockWidgetArea, FileSystemWidget);
347+
ads::CDockComponentsFactory::resetDefaultFactory();
322348

323349
// We create a calender widget and clear all flags to prevent the dock area
324350
// from closing

demo/demo.qrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,6 @@
1212
<file>images/custom-menu-button.svg</file>
1313
<file>app.css</file>
1414
<file>images/plus.svg</file>
15+
<file>images/help_outline.svg</file>
1516
</qresource>
1617
</RCC>

src/DockComponentsFactory.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,17 +44,24 @@ CDockAreaTitleBar* CDockComponentsFactory::createDockAreaTitleBar(CDockAreaWidge
4444

4545

4646
//============================================================================
47-
const CDockComponentsFactory* CDockComponentsFactory::defaultFactory()
47+
const CDockComponentsFactory* CDockComponentsFactory::factory()
4848
{
4949
return DefaultFactory.get();
5050
}
5151

5252

5353
//============================================================================
54-
void CDockComponentsFactory::setDefaultFactory(CDockComponentsFactory* Factory)
54+
void CDockComponentsFactory::setFactory(CDockComponentsFactory* Factory)
5555
{
5656
DefaultFactory.reset(Factory);
5757
}
58+
59+
60+
//============================================================================
61+
void CDockComponentsFactory::resetDefaultFactory()
62+
{
63+
DefaultFactory.reset(new CDockComponentsFactory());
64+
}
5865
} // namespace ads
5966

6067
//---------------------------------------------------------------------------

src/DockComponentsFactory.h

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
//============================================================================
1111
// INCLUDES
1212
//============================================================================
13+
#include "ads_globals.h"
14+
1315
namespace ads
1416
{
1517
class CDockWidgetTab;
@@ -30,7 +32,7 @@ class CDockWidget;
3032
* CDockComponentsFactory::setDefaultFactory(new MyComponentsFactory()));
3133
* \endcode
3234
*/
33-
class CDockComponentsFactory
35+
class ADS_EXPORT CDockComponentsFactory
3436
{
3537
public:
3638
/**
@@ -45,13 +47,18 @@ class CDockComponentsFactory
4547
/**
4648
* Returns the default components factory
4749
*/
48-
static const CDockComponentsFactory* defaultFactory();
50+
static const CDockComponentsFactory* factory();
4951

5052
/**
5153
* Sets a new default factory for creation of GUI elements.
5254
* This function takes ownership of the given Factory.
5355
*/
54-
static void setDefaultFactory(CDockComponentsFactory* Factory);
56+
static void setFactory(CDockComponentsFactory* Factory);
57+
58+
/**
59+
* Resets the current factory to the
60+
*/
61+
static void resetDefaultFactory();
5562
};
5663

5764

@@ -60,7 +67,7 @@ class CDockComponentsFactory
6067
*/
6168
inline const CDockComponentsFactory* componentsFactory()
6269
{
63-
return CDockComponentsFactory::defaultFactory();
70+
return CDockComponentsFactory::factory();
6471
}
6572

6673
} // namespace ads

0 commit comments

Comments
 (0)