mirror of
https://github.com/githubuser0xFFFF/Qt-Advanced-Docking-System.git
synced 2024-12-24 23:31:32 +08:00
Implemented support for custom DockWidget actions for display in DockArea title bar
This commit is contained in:
parent
094fa37135
commit
b727274cd9
@ -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
|
||||
|
@ -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>
|
||||
|
@ -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";
|
||||
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user