Implemented support for custom DockWidget actions for display in DockArea title bar

This commit is contained in:
Uwe Kindler 2020-02-06 09:15:13 +01:00
parent 094fa37135
commit b727274cd9
8 changed files with 48 additions and 20 deletions

View File

@ -192,6 +192,8 @@ static ads::CDockWidget* createEditorWidget(QMenu* ViewMenu)
// styling // styling
MenuAction->setObjectName("optionsMenu"); MenuAction->setObjectName("optionsMenu");
DockWidget->setTitleBarActions({OptionsMenu->menuAction()}); DockWidget->setTitleBarActions({OptionsMenu->menuAction()});
auto a = OptionsMenu->addAction(QObject::tr("Clear Editor"));
w->connect(a, SIGNAL(triggered()), SLOT(clear()));
return DockWidget; return DockWidget;
} }
@ -424,6 +426,7 @@ CMainWindow::CMainWindow(QWidget *parent) :
{ {
using namespace ads; using namespace ads;
d->ui.setupUi(this); d->ui.setupUi(this);
d->createActions(); d->createActions();
// uncomment the following line if the tab close button should be // uncomment the following line if the tab close button should be

View File

@ -10,5 +10,6 @@
<file>images/edit.svg</file> <file>images/edit.svg</file>
<file>images/grid_on.svg</file> <file>images/grid_on.svg</file>
<file>images/custom-menu-button.svg</file> <file>images/custom-menu-button.svg</file>
<file>app.css</file>
</qresource> </qresource>
</RCC> </RCC>

View File

@ -42,6 +42,13 @@ int main(int argc, char *argv[])
std::shared_ptr<int> b; std::shared_ptr<int> b;
QApplication a(argc, argv); QApplication a(argc, argv);
a.setQuitOnLastWindowClosed(true); a.setQuitOnLastWindowClosed(true);
QFile StyleSheetFile(":/adsdemo/app.css");
StyleSheetFile.open(QIODevice::ReadOnly);
QTextStream StyleSheetStream(&StyleSheetFile);
a.setStyleSheet(StyleSheetStream.readAll());
StyleSheetFile.close();
qInstallMessageHandler(myMessageOutput); qInstallMessageHandler(myMessageOutput);
qDebug() << "Message handler test"; qDebug() << "Message handler test";

View File

@ -113,6 +113,7 @@ struct DockAreaTitleBarPrivate
*/ */
class CTitleBarButton : public tTitleBarButton class CTitleBarButton : public tTitleBarButton
{ {
Q_OBJECT
bool Visible = true; bool Visible = true;
bool HideWhenDisabled = false; bool HideWhenDisabled = false;
public: public:
@ -354,19 +355,9 @@ void CDockAreaTitleBar::onTabsMenuActionTriggered(QAction* Action)
//============================================================================ //============================================================================
void CDockAreaTitleBar::onCurrentTabChanged(int Index) void CDockAreaTitleBar::updateDockWidgetActionsButtons()
{ {
if (Index < 0) CDockWidget* DockWidget = d->TabBar->currentTab()->dockWidget();
{
return;
}
CDockWidget* DockWidget = d->TabBar->tab(Index)->dockWidget();
if (d->testConfigFlag(CDockManager::DockAreaCloseButtonClosesTab))
{
d->CloseButton->setEnabled(DockWidget->features().testFlag(CDockWidget::DockWidgetClosable));
}
if (!d->DockWidgetActionsButtons.isEmpty()) if (!d->DockWidgetActionsButtons.isEmpty())
{ {
for (auto Button : d->DockWidgetActionsButtons) for (auto Button : d->DockWidgetActionsButtons)
@ -397,6 +388,24 @@ void CDockAreaTitleBar::onCurrentTabChanged(int Index)
} }
//============================================================================
void CDockAreaTitleBar::onCurrentTabChanged(int Index)
{
if (Index < 0)
{
return;
}
if (d->testConfigFlag(CDockManager::DockAreaCloseButtonClosesTab))
{
CDockWidget* DockWidget = d->TabBar->tab(Index)->dockWidget();
d->CloseButton->setEnabled(DockWidget->features().testFlag(CDockWidget::DockWidgetClosable));
}
updateDockWidgetActionsButtons();
}
//============================================================================ //============================================================================
QAbstractButton* CDockAreaTitleBar::button(TitleBarButton which) const QAbstractButton* CDockAreaTitleBar::button(TitleBarButton which) const
{ {
@ -440,5 +449,7 @@ void CDockAreaTitleBar::showContextMenu(const QPoint& pos)
} // namespace ads } // namespace ads
#include "DockAreaTitleBar.moc"
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
// EOF DockAreaTitleBar.cpp // EOF DockAreaTitleBar.cpp

View File

@ -92,6 +92,11 @@ public:
*/ */
QAbstractButton* button(TitleBarButton which) const; QAbstractButton* button(TitleBarButton which) const;
/**
* Updates the visibility of the dock widget actions in the title bar
*/
void updateDockWidgetActionsButtons();
/** /**
* Marks the tabs menu outdated before it calls its base class * Marks the tabs menu outdated before it calls its base class
* implementation * implementation

View File

@ -338,6 +338,7 @@ void DockAreaWidgetPrivate::updateTitleBarButtonStates()
_this->features().testFlag(CDockWidget::DockWidgetClosable)); _this->features().testFlag(CDockWidget::DockWidgetClosable));
TitleBar->button(TitleBarButtonUndock)->setEnabled( TitleBar->button(TitleBarButtonUndock)->setEnabled(
_this->features().testFlag(CDockWidget::DockWidgetFloatable)); _this->features().testFlag(CDockWidget::DockWidgetFloatable));
TitleBar->updateDockWidgetActionsButtons();
UpdateTitleBarButtons = false; UpdateTitleBarButtons = false;
} }

View File

@ -59,11 +59,11 @@ ads--CDockWidget
border-width: 1px 0 0 0; border-width: 1px 0 0 0;
} }
#tabsMenuButton, ads--CTitleBarButton
#closeButton,
#undockButton
{ {
padding: 0px -2px; padding: 0px 0px;
margin-top: -1px;
margin-botton: -1px;
} }

View File

@ -59,14 +59,14 @@ ads--CDockWidget
border-width: 1px 0 0 0; border-width: 1px 0 0 0;
} }
#tabsMenuButton,
#closeButton, ads--CTitleBarButton
#undockButton
{ {
padding: 0px -2px; padding: 0px 0px;
} }
QScrollArea#dockWidgetScrollArea QScrollArea#dockWidgetScrollArea
{ {
padding: 0px; padding: 0px;