Skip to content

Commit c4872c6

Browse files
Added showcase for custom title bar widget to demo application
1 parent efb9b87 commit c4872c6

File tree

6 files changed

+165
-2
lines changed

6 files changed

+165
-2
lines changed

demo/MainWindow.cpp

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@
5757
#include <QStyle>
5858
#include <QMessageBox>
5959
#include <QMenu>
60+
#include <QToolButton>
61+
6062

6163
#ifdef Q_OS_WIN
6264
#include <QAxWidget>
@@ -68,6 +70,8 @@
6870
#include "DockManager.h"
6971
#include "DockWidget.h"
7072
#include "DockAreaWidget.h"
73+
#include "DockAreaTitleBar.h"
74+
#include "DockAreaTabBar.h"
7175
#include "FloatingDockContainer.h"
7276

7377

@@ -315,10 +319,32 @@ void MainWindowPrivate::createContent()
315319
FileSystemWidget->setFeature(ads::CDockWidget::DockWidgetFloatable, false);
316320
appendFeaturStringToWindowTitle(FileSystemWidget);
317321
auto TopDockArea = DockManager->addDockWidget(ads::TopDockWidgetArea, FileSystemWidget);
322+
323+
// We create a calender widget and clear all flags to prevent the dock area
324+
// from closing
318325
DockWidget = createCalendarDockWidget(ViewMenu);
319326
DockWidget->setFeature(ads::CDockWidget::DockWidgetClosable, false);
327+
DockWidget->setFeature(ads::CDockWidget::DockWidgetMovable, false);
328+
DockWidget->setFeature(ads::CDockWidget::DockWidgetFloatable, false);
320329
DockWidget->setTabToolTip(QString("Tab ToolTip\nHodie est dies magna"));
321-
DockManager->addDockWidget(ads::CenterDockWidgetArea, DockWidget, TopDockArea);
330+
auto DockArea = DockManager->addDockWidget(ads::CenterDockWidgetArea, DockWidget, TopDockArea);
331+
332+
// Now we add a custom button to the dock area title bar that will create
333+
// new editor widgets when clicked
334+
auto CustomButton = new QToolButton(DockArea);
335+
CustomButton->setToolTip(QObject::tr("Create Editor"));
336+
CustomButton->setIcon(svgIcon(":/adsdemo/images/plus.svg"));
337+
CustomButton->setAutoRaise(true);
338+
auto TitleBar = DockArea->titleBar();
339+
int Index = TitleBar->indexOf(TitleBar->tabBar());
340+
TitleBar->insertWidget(Index + 1, CustomButton);
341+
QObject::connect(CustomButton, &QToolButton::clicked, [=]()
342+
{
343+
auto DockWidget = createEditorWidget(ui.menuView);
344+
DockWidget->setFeature(ads::CDockWidget::DockWidgetDeleteOnClose, true);
345+
DockManager->addDockWidgetTabToArea(DockWidget, DockArea);
346+
_this->connect(DockWidget, SIGNAL(closeRequested()), SLOT(onEditorCloseRequested()));
347+
});
322348

323349
// Test dock area docking
324350
auto RighDockArea = DockManager->addDockWidget(ads::RightDockWidgetArea, createLongTextLabelDockWidget(ViewMenu), TopDockArea);

demo/demo.qrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,6 @@
1111
<file>images/grid_on.svg</file>
1212
<file>images/custom-menu-button.svg</file>
1313
<file>app.css</file>
14+
<file>images/plus.svg</file>
1415
</qresource>
1516
</RCC>

demo/images/plus.svg

Lines changed: 123 additions & 0 deletions
Loading

src/DockAreaTitleBar.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@ void CDockAreaTitleBar::updateDockWidgetActionsButtons()
460460
return;
461461
}
462462

463-
int InsertIndex = 2;
463+
int InsertIndex = indexOf(d->TabsMenuButton);
464464
for (auto Action : Actions)
465465
{
466466
auto Button = new CTitleBarButton(true, this);

src/DockAreaWidget.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -856,6 +856,13 @@ void CDockAreaWidget::closeOtherAreas()
856856
{
857857
dockContainer()->closeOtherAreas(this);
858858
}
859+
860+
861+
//============================================================================
862+
CDockAreaTitleBar* CDockAreaWidget::titleBar() const
863+
{
864+
return d->TitleBar;
865+
}
859866
} // namespace ads
860867

861868
//---------------------------------------------------------------------------

src/DockAreaWidget.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ struct DockAreaWidgetPrivate;
4444
class CDockManager;
4545
class CDockContainerWidget;
4646
class DockContainerWidgetPrivate;
47+
class CDockAreaTitleBar;
4748

4849

4950
/**
@@ -264,6 +265,11 @@ protected slots:
264265
*/
265266
DockWidgetAreas allowedAreas() const;
266267

268+
/**
269+
* Returns the title bar of this dock area
270+
*/
271+
CDockAreaTitleBar* titleBar() const;
272+
267273
public slots:
268274
/**
269275
* This activates the tab for the given tab index.

0 commit comments

Comments
 (0)