Skip to content

Commit 9339457

Browse files
Merge branch 'master' into custom_titlebar
2 parents 5b60e39 + f387c6a commit 9339457

12 files changed

+279
-33
lines changed

CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ set(ads_SRCS
4242
src/FloatingDockContainer.cpp
4343
src/FloatingDragPreview.cpp
4444
src/IconProvider.cpp
45+
src/DockComponentsFactory.cpp
4546
src/ads.qrc
4647
src/linux/FloatingWidgetTitleBar.cpp
4748
)
@@ -61,6 +62,7 @@ set(ads_INSTALL_INCLUDE
6162
src/FloatingDockContainer.h
6263
src/FloatingDragPreview.h
6364
src/IconProvider.h
65+
src/DockComponentsFactory.h
6466
src/linux/FloatingWidgetTitleBar.h
6567
)
6668
if("${CMAKE_SIZEOF_VOID_P}" STREQUAL "4")

demo/MainWindow.cpp

Lines changed: 52 additions & 20 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 = new ads::CDockAreaTitleBar(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,9 +340,13 @@ 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

323-
// We create a calender widget and clear all flags to prevent the dock area
349+
// We create a calendar widget and clear all flags to prevent the dock area
324350
// from closing
325351
DockWidget = createCalendarDockWidget(ViewMenu);
326352
DockWidget->setFeature(ads::CDockWidget::DockWidgetClosable, false);
@@ -481,6 +507,12 @@ CMainWindow::CMainWindow(QWidget *parent) :
481507
// uncomment the following line if you want to show tabs menu button on DockArea's title bar only when there are more than one tab and at least of them has elided title
482508
//CDockManager::setConfigFlag(CDockManager::DockAreaDynamicTabsMenuButtonVisibility, true);
483509

510+
// uncomment the following line if you want floating container to always show application title instead of active dock widget's title
511+
//CDockManager::setConfigFlag(CDockManager::FloatingContainerHasWidgetTitle, false);
512+
513+
// uncomment the following line if you want floating container to show active dock widget's icon instead of always showing application icon
514+
//CDockManager::setConfigFlag(CDockManager::FloatingContainerHasWidgetIcon, true);
515+
484516
// Now create the dock manager and its content
485517
d->DockManager = new CDockManager(this);
486518

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>

demo/images/help_outline.svg

Lines changed: 6 additions & 0 deletions
Loading

src/DockAreaTitleBar.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
#include "DockWidgetTab.h"
5050
#include "DockAreaTabBar.h"
5151
#include "IconProvider.h"
52+
#include "DockComponentsFactory.h"
5253

5354
#include <iostream>
5455

@@ -273,7 +274,7 @@ void DockAreaTitleBarPrivate::createButtons()
273274
//============================================================================
274275
void DockAreaTitleBarPrivate::createTabBar()
275276
{
276-
TabBar = new CDockAreaTabBar(DockArea);
277+
TabBar = componentsFactory()->createDockAreaTabBar(DockArea);
277278
TabBar->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Preferred);
278279
Layout->addWidget(TabBar);
279280
_this->connect(TabBar, SIGNAL(tabClosed(int)), SLOT(markTabsMenuOutdated()));

src/DockAreaWidget.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,10 @@
2828
//============================================================================
2929
// INCLUDES
3030
//============================================================================
31-
#include "DockWidgetTab.h"
3231
#include "DockAreaWidget.h"
3332

33+
#include <iostream>
34+
3435
#include <QStackedLayout>
3536
#include <QScrollBar>
3637
#include <QScrollArea>
@@ -53,8 +54,8 @@
5354
#include "DockAreaTabBar.h"
5455
#include "DockSplitter.h"
5556
#include "DockAreaTitleBar.h"
56-
57-
#include <iostream>
57+
#include "DockComponentsFactory.h"
58+
#include "DockWidgetTab.h"
5859

5960

6061
namespace ads
@@ -317,7 +318,7 @@ DockAreaWidgetPrivate::DockAreaWidgetPrivate(CDockAreaWidget* _public) :
317318
//============================================================================
318319
void DockAreaWidgetPrivate::createTitleBar()
319320
{
320-
TitleBar = new CDockAreaTitleBar(_this);
321+
TitleBar = componentsFactory()->createDockAreaTitleBar(_this);
321322
Layout->addWidget(TitleBar);
322323
QObject::connect(tabBar(), &CDockAreaTabBar::tabCloseRequested, _this, &CDockAreaWidget::onTabCloseRequested);
323324
QObject::connect(TitleBar, &CDockAreaTitleBar::tabBarClicked, _this, &CDockAreaWidget::setCurrentIndex);

src/DockComponentsFactory.cpp

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
//============================================================================
2+
/// \file DockComponentsFactory.cpp
3+
/// \author Uwe Kindler
4+
/// \date 10.02.2020
5+
/// \brief Implementation of DockComponentsFactory
6+
//============================================================================
7+
8+
//============================================================================
9+
// INCLUDES
10+
//============================================================================
11+
#include <DockComponentsFactory.h>
12+
13+
#include <memory>
14+
15+
#include "DockWidgetTab.h"
16+
#include "DockAreaTabBar.h"
17+
#include "DockAreaTitleBar.h"
18+
#include "DockWidget.h"
19+
#include "DockAreaWidget.h"
20+
21+
namespace ads
22+
{
23+
static std::unique_ptr<CDockComponentsFactory> DefaultFactory(new CDockComponentsFactory());
24+
25+
26+
//============================================================================
27+
CDockWidgetTab* CDockComponentsFactory::createDockWidgetTab(CDockWidget* DockWidget) const
28+
{
29+
return new CDockWidgetTab(DockWidget);
30+
}
31+
32+
33+
//============================================================================
34+
CDockAreaTabBar* CDockComponentsFactory::createDockAreaTabBar(CDockAreaWidget* DockArea) const
35+
{
36+
return new CDockAreaTabBar(DockArea);
37+
}
38+
39+
40+
//============================================================================
41+
CDockAreaTitleBar* CDockComponentsFactory::createDockAreaTitleBar(CDockAreaWidget* DockArea) const
42+
{
43+
return new CDockAreaTitleBar(DockArea);
44+
}
45+
46+
47+
//============================================================================
48+
const CDockComponentsFactory* CDockComponentsFactory::factory()
49+
{
50+
return DefaultFactory.get();
51+
}
52+
53+
54+
//============================================================================
55+
void CDockComponentsFactory::setFactory(CDockComponentsFactory* Factory)
56+
{
57+
DefaultFactory.reset(Factory);
58+
}
59+
60+
61+
//============================================================================
62+
void CDockComponentsFactory::resetDefaultFactory()
63+
{
64+
DefaultFactory.reset(new CDockComponentsFactory());
65+
}
66+
} // namespace ads
67+
68+
//---------------------------------------------------------------------------
69+
// EOF DockComponentsFactory.cpp

src/DockComponentsFactory.h

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
#ifndef DockComponentsFactoryH
2+
#define DockComponentsFactoryH
3+
//============================================================================
4+
/// \file DockComponentsFactory.h
5+
/// \author Uwe Kindler
6+
/// \date 10.02.2020
7+
/// \brief Declaration of DockComponentsFactory
8+
//============================================================================
9+
10+
//============================================================================
11+
// INCLUDES
12+
//============================================================================
13+
#include "ads_globals.h"
14+
15+
namespace ads
16+
{
17+
class CDockWidgetTab;
18+
class CDockAreaTitleBar;
19+
class CDockAreaTabBar;
20+
class CDockAreaWidget;
21+
class CDockWidget;
22+
23+
24+
25+
/**
26+
* Factory for creation of certain GUI elements for the docking framework.
27+
* A default unique instance provided by CDockComponentsFactory is used for
28+
* creation of all supported components. To inject your custom components,
29+
* you can create your own derived dock components factory and register
30+
* it via setDefaultFactory() function.
31+
* \code
32+
* CDockComponentsFactory::setDefaultFactory(new MyComponentsFactory()));
33+
* \endcode
34+
*/
35+
class ADS_EXPORT CDockComponentsFactory
36+
{
37+
public:
38+
/**
39+
* Force virtual destructor
40+
*/
41+
virtual ~CDockComponentsFactory() {}
42+
43+
/**
44+
* This default implementation just creates a dock widget tab with
45+
* new CDockWidgetTab(DockWIdget).
46+
*/
47+
virtual CDockWidgetTab* createDockWidgetTab(CDockWidget* DockWidget) const;
48+
49+
/**
50+
* This default implementation just creates a dock area tab bar with
51+
* new CDockAreaTabBar(DockArea).
52+
*/
53+
virtual CDockAreaTabBar* createDockAreaTabBar(CDockAreaWidget* DockArea) const;
54+
55+
/**
56+
* This default implementation just creates a dock area title bar with
57+
* new CDockAreaTitleBar(DockArea).
58+
*/
59+
virtual CDockAreaTitleBar* createDockAreaTitleBar(CDockAreaWidget* DockArea) const;
60+
61+
/**
62+
* Returns the default components factory
63+
*/
64+
static const CDockComponentsFactory* factory();
65+
66+
/**
67+
* Sets a new default factory for creation of GUI elements.
68+
* This function takes ownership of the given Factory.
69+
*/
70+
static void setFactory(CDockComponentsFactory* Factory);
71+
72+
/**
73+
* Resets the current factory to the
74+
*/
75+
static void resetDefaultFactory();
76+
};
77+
78+
79+
/**
80+
* Convenience function to ease factory instance access
81+
*/
82+
inline const CDockComponentsFactory* componentsFactory()
83+
{
84+
return CDockComponentsFactory::factory();
85+
}
86+
87+
} // namespace ads
88+
89+
//---------------------------------------------------------------------------
90+
#endif // DockComponentsFactoryH

src/DockManager.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ class CDockWidgetTab;
5959
struct DockWidgetTabPrivate;
6060
struct DockAreaWidgetPrivate;
6161
class CIconProvider;
62+
class CDockComponentsFactory;
6263

6364
/**
6465
* The central dock manager that maintains the complete docking system.
@@ -162,6 +163,8 @@ class ADS_EXPORT CDockManager : public CDockContainerWidget
162163
DockAreaHasTabsMenuButton = 0x8000, //!< If the flag is set each dock area has a tabs menu button
163164
DockAreaHideDisabledButtons = 0x10000, //!< If the flag is set disabled dock area buttons will not appear on the tollbar at all (enabling them will bring them back)
164165
DockAreaDynamicTabsMenuButtonVisibility = 0x20000, //!< If the flag is set dock area will disable a tabs menu button when there is only one tab in the area
166+
FloatingContainerHasWidgetTitle = 0x40000,
167+
FloatingContainerHasWidgetIcon = 0x80000,
165168

166169

167170
DefaultDockAreaButtons = DockAreaHasCloseButton
@@ -170,7 +173,8 @@ class ADS_EXPORT CDockManager : public CDockContainerWidget
170173

171174
DefaultBaseConfig = DefaultDockAreaButtons
172175
| ActiveTabHasCloseButton
173-
| XmlCompressionEnabled,///< default base configuration settings
176+
| XmlCompressionEnabled
177+
| FloatingContainerHasWidgetTitle,///< default base configuration settings
174178

175179
DefaultOpaqueConfig = DefaultBaseConfig
176180
| OpaqueSplitterResize

src/DockWidget.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
#include "DockManager.h"
5555
#include "FloatingDockContainer.h"
5656
#include "DockSplitter.h"
57+
#include "DockComponentsFactory.h"
5758
#include "ads_globals.h"
5859

5960

@@ -220,7 +221,7 @@ CDockWidget::CDockWidget(const QString &title, QWidget *parent) :
220221
setWindowTitle(title);
221222
setObjectName(title);
222223

223-
d->TabWidget = new CDockWidgetTab(this);
224+
d->TabWidget = componentsFactory()->createDockWidgetTab(this);
224225
d->ToggleViewAction = new QAction(title, this);
225226
d->ToggleViewAction->setCheckable(true);
226227
connect(d->ToggleViewAction, SIGNAL(triggered(bool)), this,

0 commit comments

Comments
 (0)