Fixed CDockManager::DockAreaHasCloseButton == false issue

This commit is contained in:
Uwe Kindler 2020-02-02 11:16:38 +01:00
parent 102e65a548
commit 9fe8f291fb
2 changed files with 70 additions and 27 deletions

View File

@ -411,6 +411,7 @@ CMainWindow::CMainWindow(QWidget *parent) :
// comment the following line if you want to use opaque undocking and // comment the following line if you want to use opaque undocking and
// opaque splitter resizing // opaque splitter resizing
CDockManager::setConfigFlags(CDockManager::DefaultNonOpaqueConfig); CDockManager::setConfigFlags(CDockManager::DefaultNonOpaqueConfig);
//CDockManager::setConfigFlag(CDockManager::DockAreaHasCloseButton, false);
// uncomment the following line if you want a fixed tab width that does // uncomment the following line if you want a fixed tab width that does
// not change if the visibility of the close button changes // not change if the visibility of the close button changes

View File

@ -37,6 +37,7 @@
#include <QScrollArea> #include <QScrollArea>
#include <QMouseEvent> #include <QMouseEvent>
#include <QDebug> #include <QDebug>
#include <QPointer>
#include "ads_globals.h" #include "ads_globals.h"
#include "FloatingDockContainer.h" #include "FloatingDockContainer.h"
@ -52,16 +53,40 @@
namespace ads namespace ads
{ {
using tTileBarButton = QToolButton; using tTitleBarButton = QToolButton;
/**
* Some kind of dummy button that is used if certain buttons are hidden
* by dock manager config flags (i.e CDockManager::DockAreaHasCloseButton is
* disabled)
*/
class CInvisibleButton : public tTitleBarButton
{
public:
CInvisibleButton(QWidget* parent = nullptr)
: tTitleBarButton(parent)
{
this->hide();
}
virtual void setVisible(bool visible) override
{
Q_UNUSED(visible);
tTitleBarButton::setVisible(false);
}
};
/** /**
* Private data class of CDockAreaTitleBar class (pimpl) * Private data class of CDockAreaTitleBar class (pimpl)
*/ */
struct DockAreaTitleBarPrivate struct DockAreaTitleBarPrivate
{ {
CDockAreaTitleBar* _this; CDockAreaTitleBar* _this;
tTileBarButton* TabsMenuButton; QPointer<tTitleBarButton> TabsMenuButton;
tTileBarButton* UndockButton; QPointer<tTitleBarButton> UndockButton;
tTileBarButton* CloseButton; QPointer<tTitleBarButton> CloseButton;
QBoxLayout* TopLayout; QBoxLayout* TopLayout;
CDockAreaWidget* DockArea; CDockAreaWidget* DockArea;
CDockAreaTabBar* TabBar; CDockAreaTabBar* TabBar;
@ -106,7 +131,7 @@ struct DockAreaTitleBarPrivate
* If the global IconPovider of the dockmanager provides a custom * If the global IconPovider of the dockmanager provides a custom
* Icon for the given CustomIconId, the this icon will be used. * Icon for the given CustomIconId, the this icon will be used.
*/ */
void setTitleBarButtonIcon(tTileBarButton* Button, QStyle::StandardPixmap StandarPixmap, void setTitleBarButtonIcon(tTitleBarButton* Button, QStyle::StandardPixmap StandarPixmap,
ads::eIcon CustomIconId) ads::eIcon CustomIconId)
{ {
// First we try to use custom icons if available // First we try to use custom icons if available
@ -143,7 +168,7 @@ void DockAreaTitleBarPrivate::createButtons()
{ {
QSizePolicy ButtonSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding); QSizePolicy ButtonSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding);
// Tabs menu button // Tabs menu button
TabsMenuButton = new tTileBarButton(); TabsMenuButton = new tTitleBarButton();
TabsMenuButton->setObjectName("tabsMenuButton"); TabsMenuButton->setObjectName("tabsMenuButton");
TabsMenuButton->setAutoRaise(true); TabsMenuButton->setAutoRaise(true);
TabsMenuButton->setPopupMode(QToolButton::InstantPopup); TabsMenuButton->setPopupMode(QToolButton::InstantPopup);
@ -164,7 +189,7 @@ void DockAreaTitleBarPrivate::createButtons()
// Undock button // Undock button
UndockButton = new tTileBarButton(); UndockButton = new tTitleBarButton();
UndockButton->setObjectName("undockButton"); UndockButton->setObjectName("undockButton");
UndockButton->setAutoRaise(true); UndockButton->setAutoRaise(true);
#ifndef QT_NO_TOOLTIP #ifndef QT_NO_TOOLTIP
@ -175,9 +200,10 @@ void DockAreaTitleBarPrivate::createButtons()
TopLayout->addWidget(UndockButton, 0); TopLayout->addWidget(UndockButton, 0);
_this->connect(UndockButton, SIGNAL(clicked()), SLOT(onUndockButtonClicked())); _this->connect(UndockButton, SIGNAL(clicked()), SLOT(onUndockButtonClicked()));
if (testConfigFlag(CDockManager::DockAreaHasCloseButton))
{
// Close button // Close button
CloseButton = new tTileBarButton(); CloseButton = new tTitleBarButton();
CloseButton->setObjectName("closeButton"); CloseButton->setObjectName("closeButton");
CloseButton->setAutoRaise(true); CloseButton->setAutoRaise(true);
setTitleBarButtonIcon(CloseButton, QStyle::SP_TitleBarCloseButton, ads::DockAreaCloseIcon); setTitleBarButtonIcon(CloseButton, QStyle::SP_TitleBarCloseButton, ads::DockAreaCloseIcon);
@ -193,12 +219,14 @@ void DockAreaTitleBarPrivate::createButtons()
#endif #endif
CloseButton->setSizePolicy(ButtonSizePolicy); CloseButton->setSizePolicy(ButtonSizePolicy);
CloseButton->setIconSize(QSize(16, 16)); CloseButton->setIconSize(QSize(16, 16));
if (testConfigFlag(CDockManager::DockAreaHasCloseButton))
{
TopLayout->addWidget(CloseButton, 0); TopLayout->addWidget(CloseButton, 0);
}
_this->connect(CloseButton, SIGNAL(clicked()), SLOT(onCloseButtonClicked())); _this->connect(CloseButton, SIGNAL(clicked()), SLOT(onCloseButtonClicked()));
} }
else
{
CloseButton = new CInvisibleButton();
}
}
//============================================================================ //============================================================================
@ -243,6 +271,20 @@ CDockAreaTitleBar::CDockAreaTitleBar(CDockAreaWidget* parent) :
//============================================================================ //============================================================================
CDockAreaTitleBar::~CDockAreaTitleBar() CDockAreaTitleBar::~CDockAreaTitleBar()
{ {
if (!d->CloseButton.isNull())
{
delete d->CloseButton;
}
if (!d->TabsMenuButton.isNull())
{
delete d->TabsMenuButton;
}
if (!d->UndockButton.isNull())
{
delete d->UndockButton;
}
delete d; delete d;
} }