Skip to content

Commit b727274

Browse files
Implemented support for custom DockWidget actions for display in DockArea title bar
1 parent 094fa37 commit b727274

File tree

8 files changed

+48
-20
lines changed

8 files changed

+48
-20
lines changed

demo/MainWindow.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,8 @@ static ads::CDockWidget* createEditorWidget(QMenu* ViewMenu)
192192
// styling
193193
MenuAction->setObjectName("optionsMenu");
194194
DockWidget->setTitleBarActions({OptionsMenu->menuAction()});
195+
auto a = OptionsMenu->addAction(QObject::tr("Clear Editor"));
196+
w->connect(a, SIGNAL(triggered()), SLOT(clear()));
195197

196198
return DockWidget;
197199
}
@@ -424,6 +426,7 @@ CMainWindow::CMainWindow(QWidget *parent) :
424426
{
425427
using namespace ads;
426428
d->ui.setupUi(this);
429+
427430
d->createActions();
428431

429432
// uncomment the following line if the tab close button should be

demo/demo.qrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,6 @@
1010
<file>images/edit.svg</file>
1111
<file>images/grid_on.svg</file>
1212
<file>images/custom-menu-button.svg</file>
13+
<file>app.css</file>
1314
</qresource>
1415
</RCC>

demo/main.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,13 @@ int main(int argc, char *argv[])
4242
std::shared_ptr<int> b;
4343
QApplication a(argc, argv);
4444
a.setQuitOnLastWindowClosed(true);
45+
46+
QFile StyleSheetFile(":/adsdemo/app.css");
47+
StyleSheetFile.open(QIODevice::ReadOnly);
48+
QTextStream StyleSheetStream(&StyleSheetFile);
49+
a.setStyleSheet(StyleSheetStream.readAll());
50+
StyleSheetFile.close();
51+
4552
qInstallMessageHandler(myMessageOutput);
4653
qDebug() << "Message handler test";
4754

src/DockAreaTitleBar.cpp

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ struct DockAreaTitleBarPrivate
113113
*/
114114
class CTitleBarButton : public tTitleBarButton
115115
{
116+
Q_OBJECT
116117
bool Visible = true;
117118
bool HideWhenDisabled = false;
118119
public:
@@ -354,19 +355,9 @@ void CDockAreaTitleBar::onTabsMenuActionTriggered(QAction* Action)
354355

355356

356357
//============================================================================
357-
void CDockAreaTitleBar::onCurrentTabChanged(int Index)
358+
void CDockAreaTitleBar::updateDockWidgetActionsButtons()
358359
{
359-
if (Index < 0)
360-
{
361-
return;
362-
}
363-
364-
CDockWidget* DockWidget = d->TabBar->tab(Index)->dockWidget();
365-
if (d->testConfigFlag(CDockManager::DockAreaCloseButtonClosesTab))
366-
{
367-
d->CloseButton->setEnabled(DockWidget->features().testFlag(CDockWidget::DockWidgetClosable));
368-
}
369-
360+
CDockWidget* DockWidget = d->TabBar->currentTab()->dockWidget();
370361
if (!d->DockWidgetActionsButtons.isEmpty())
371362
{
372363
for (auto Button : d->DockWidgetActionsButtons)
@@ -397,6 +388,24 @@ void CDockAreaTitleBar::onCurrentTabChanged(int Index)
397388
}
398389

399390

391+
//============================================================================
392+
void CDockAreaTitleBar::onCurrentTabChanged(int Index)
393+
{
394+
if (Index < 0)
395+
{
396+
return;
397+
}
398+
399+
if (d->testConfigFlag(CDockManager::DockAreaCloseButtonClosesTab))
400+
{
401+
CDockWidget* DockWidget = d->TabBar->tab(Index)->dockWidget();
402+
d->CloseButton->setEnabled(DockWidget->features().testFlag(CDockWidget::DockWidgetClosable));
403+
}
404+
405+
updateDockWidgetActionsButtons();
406+
}
407+
408+
400409
//============================================================================
401410
QAbstractButton* CDockAreaTitleBar::button(TitleBarButton which) const
402411
{
@@ -440,5 +449,7 @@ void CDockAreaTitleBar::showContextMenu(const QPoint& pos)
440449

441450
} // namespace ads
442451

452+
#include "DockAreaTitleBar.moc"
453+
443454
//---------------------------------------------------------------------------
444455
// EOF DockAreaTitleBar.cpp

src/DockAreaTitleBar.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,11 @@ public slots:
9292
*/
9393
QAbstractButton* button(TitleBarButton which) const;
9494

95+
/**
96+
* Updates the visibility of the dock widget actions in the title bar
97+
*/
98+
void updateDockWidgetActionsButtons();
99+
95100
/**
96101
* Marks the tabs menu outdated before it calls its base class
97102
* implementation

src/DockAreaWidget.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,7 @@ void DockAreaWidgetPrivate::updateTitleBarButtonStates()
338338
_this->features().testFlag(CDockWidget::DockWidgetClosable));
339339
TitleBar->button(TitleBarButtonUndock)->setEnabled(
340340
_this->features().testFlag(CDockWidget::DockWidgetFloatable));
341+
TitleBar->updateDockWidgetActionsButtons();
341342
UpdateTitleBarButtons = false;
342343
}
343344

src/stylesheets/default.css

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,11 @@ ads--CDockWidget
5959
border-width: 1px 0 0 0;
6060
}
6161

62-
#tabsMenuButton,
63-
#closeButton,
64-
#undockButton
62+
ads--CTitleBarButton
6563
{
66-
padding: 0px -2px;
64+
padding: 0px 0px;
65+
margin-top: -1px;
66+
margin-botton: -1px;
6767
}
6868

6969

src/stylesheets/default_linux.css

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,14 @@ ads--CDockWidget
5959
border-width: 1px 0 0 0;
6060
}
6161

62-
#tabsMenuButton,
63-
#closeButton,
64-
#undockButton
62+
63+
ads--CTitleBarButton
6564
{
66-
padding: 0px -2px;
65+
padding: 0px 0px;
6766
}
6867

6968

69+
7070
QScrollArea#dockWidgetScrollArea
7171
{
7272
padding: 0px;

0 commit comments

Comments
 (0)