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

View File

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

View File

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

View File

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

View File

@ -92,6 +92,11 @@ public:
*/
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
* implementation

View File

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

View File

@ -59,11 +59,11 @@ ads--CDockWidget
border-width: 1px 0 0 0;
}
#tabsMenuButton,
#closeButton,
#undockButton
ads--CTitleBarButton
{
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;
}
#tabsMenuButton,
#closeButton,
#undockButton
ads--CTitleBarButton
{
padding: 0px -2px;
padding: 0px 0px;
}
QScrollArea#dockWidgetScrollArea
{
padding: 0px;