From 0cbc810a5afe0c7c08e8d321d2282f26c66d9553 Mon Sep 17 00:00:00 2001 From: Uwe Kindler Date: Tue, 18 Oct 2022 15:29:31 +0200 Subject: [PATCH 1/5] Renamed SideTabIconLabel - added C prefix CSideTabIconLabel --- src/DockWidgetSideTab.cpp | 21 +++++++++++---------- src/DockWidgetSideTab.h | 7 ++++--- src/stylesheets/default.css | 14 ++++++++++++++ 3 files changed, 29 insertions(+), 13 deletions(-) diff --git a/src/DockWidgetSideTab.cpp b/src/DockWidgetSideTab.cpp index eafe96b..d3a7a1d 100644 --- a/src/DockWidgetSideTab.cpp +++ b/src/DockWidgetSideTab.cpp @@ -57,7 +57,7 @@ struct DockWidgetSideTabPrivate CSideTabBar* SideTabBar; QSize IconSize; Qt::Orientation Orientation{Qt::Vertical}; - SideTabIconLabel* IconLabel = nullptr; + CSideTabIconLabel* IconLabel = nullptr; QIcon Icon; /** @@ -129,7 +129,7 @@ void DockWidgetSideTabPrivate::createLayout() TitleLabel = new tTabLabel(); TitleLabel->setElideMode(Qt::ElideRight); TitleLabel->setText(DockWidget->windowTitle()); - TitleLabel->setObjectName("dockWidgetTabLabel"); + TitleLabel->setObjectName("sideTabLabel"); _this->connect(TitleLabel, SIGNAL(elidedChanged(bool)), SIGNAL(elidedChanged(bool))); // Fill the layout @@ -231,7 +231,7 @@ void CDockWidgetSideTab::setIcon(const QIcon& Icon) if (!d->IconLabel) { - d->IconLabel = new SideTabIconLabel(); + d->IconLabel = new CSideTabIconLabel(); internal::setToolTip(d->IconLabel, d->TitleLabel->toolTip()); Layout->insertWidget(0, d->IconLabel, Qt::AlignHCenter); } @@ -345,27 +345,28 @@ CDockWidget* CDockWidgetSideTab::dockWidget() const */ struct SideTabIconLabelPrivate { - SideTabIconLabel* _this; + CSideTabIconLabel* _this; QLabel* IconLabel; QBoxLayout* Layout; - SideTabIconLabelPrivate(SideTabIconLabel* _public); + SideTabIconLabelPrivate(CSideTabIconLabel* _public); }; // struct SideTabIconLabelPrivate //============================================================================ -SideTabIconLabelPrivate::SideTabIconLabelPrivate(SideTabIconLabel* _public) : +SideTabIconLabelPrivate::SideTabIconLabelPrivate(CSideTabIconLabel* _public) : _this(_public) { } //============================================================================ -SideTabIconLabel::SideTabIconLabel(QWidget* parent) : QWidget(parent), +CSideTabIconLabel::CSideTabIconLabel(QWidget* parent) : QFrame(parent), d(new SideTabIconLabelPrivate(this)) { d->Layout = new QBoxLayout(QBoxLayout::TopToBottom); d->Layout->addWidget(d->IconLabel = new QLabel()); + d->IconLabel->setObjectName("sideTabIconLabel"); d->Layout->setAlignment(Qt::AlignCenter); d->IconLabel->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred); setLayout(d->Layout); @@ -373,21 +374,21 @@ SideTabIconLabel::SideTabIconLabel(QWidget* parent) : QWidget(parent), //============================================================================ -SideTabIconLabel::~SideTabIconLabel() +CSideTabIconLabel::~CSideTabIconLabel() { delete d; } //============================================================================ -void SideTabIconLabel::setPixmap(const QPixmap& pixmap) +void CSideTabIconLabel::setPixmap(const QPixmap& pixmap) { d->IconLabel->setPixmap(pixmap); } //============================================================================ -void SideTabIconLabel::setContentsMargins(int left, int top, int right, int bottom) +void CSideTabIconLabel::setContentsMargins(int left, int top, int right, int bottom) { d->Layout->setContentsMargins(left, top, right, bottom); } diff --git a/src/DockWidgetSideTab.h b/src/DockWidgetSideTab.h index 76560e2..7e50dd8 100644 --- a/src/DockWidgetSideTab.h +++ b/src/DockWidgetSideTab.h @@ -152,14 +152,15 @@ Q_SIGNALS: void clicked(); }; // class DockWidgetSideTab -class SideTabIconLabel : public QWidget +class CSideTabIconLabel : public QFrame { + Q_OBJECT private: SideTabIconLabelPrivate *d; ///< private data (pimpl) public: - SideTabIconLabel(QWidget* parent = nullptr); - virtual ~SideTabIconLabel(); + CSideTabIconLabel(QWidget* parent = nullptr); + virtual ~CSideTabIconLabel(); void setPixmap(const QPixmap &pixmap); void setContentsMargins(int left, int top, int right, int bottom); diff --git a/src/stylesheets/default.css b/src/stylesheets/default.css index 10eac4a..342967b 100644 --- a/src/stylesheets/default.css +++ b/src/stylesheets/default.css @@ -116,10 +116,24 @@ ads--CDockWidgetSideTab { ads--CDockWidgetSideTab[sideTabBarArea="0"] { border-right: 1px solid white; + background: red; +} + +#sideTabLabel { + background: green; +} + +#sideTabIconLabel { + background: blue; +} + +ads--CSideTabIconLabel { + border: 1px solid yellow } ads--CDockWidgetSideTab[sideTabBarArea="1"] { border-bottom: 1px solid white; + background: red; } ads--CDockWidgetSideTab[sideTabBarArea="2"] { From 3a3c3a96d6d318c94b8b2444352c407542130711 Mon Sep 17 00:00:00 2001 From: Uwe Kindler Date: Tue, 18 Oct 2022 15:46:53 +0200 Subject: [PATCH 2/5] Fixed namespace comment in ElidingLabel --- src/ElidingLabel.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ElidingLabel.h b/src/ElidingLabel.h index f1525e2..811a974 100644 --- a/src/ElidingLabel.h +++ b/src/ElidingLabel.h @@ -124,7 +124,7 @@ public: void setOrientation(Qt::Orientation orientation); }; // class CVerticalElidingLabel -} // namespace QtLabb +} // namespace ads //--------------------------------------------------------------------------- #endif // ElidingLabelH From cbc43e5e0e75150a277759c74be14ad83a7a9811 Mon Sep 17 00:00:00 2001 From: Uwe Kindler Date: Tue, 18 Oct 2022 15:47:34 +0200 Subject: [PATCH 3/5] Added PushButton to test new CDockWidgetSideTab --- src/PushButton.cpp | 69 ++++++++++++++++++++++++++++++++++++++++++++++ src/PushButton.h | 49 ++++++++++++++++++++++++++++++++ src/src.pro | 6 ++-- 3 files changed, 122 insertions(+), 2 deletions(-) create mode 100644 src/PushButton.cpp create mode 100644 src/PushButton.h diff --git a/src/PushButton.cpp b/src/PushButton.cpp new file mode 100644 index 0000000..ad120cf --- /dev/null +++ b/src/PushButton.cpp @@ -0,0 +1,69 @@ +//============================================================================ +/// \file PushButton.cpp +/// \author Uwe Kindler +/// \date 18.10.2022 +/// \brief Implementation of CPushButton +//============================================================================ + +//============================================================================ +// INCLUDES +//============================================================================ +#include "PushButton.h" + +#include +#include +#include +#include + + +namespace ads +{ +QSize CPushButton::sizeHint() const +{ + QSize sh = QPushButton::sizeHint(); + + if (m_Orientation != CPushButton::Horizontal) + { + sh.transpose(); + } + + return sh; +} + +void CPushButton::paintEvent(QPaintEvent *event) +{ + Q_UNUSED(event); + + QStylePainter painter(this); + QStyleOptionButton option; + initStyleOption(&option); + + if (m_Orientation == CPushButton::VerticalTopToBottom) + { + painter.rotate(90); + painter.translate(0, -1 * width()); + option.rect = option.rect.transposed(); + } + else if (m_Orientation == CPushButton::VerticalBottomToTop) + { + painter.rotate(-90); + painter.translate(-1 * height(), 0); + option.rect = option.rect.transposed(); + } + + painter.drawControl(QStyle::CE_PushButton, option); +} + +CPushButton::Orientation CPushButton::orientation() const +{ + return m_Orientation; +} + +void CPushButton::setOrientation(Orientation &orientation) +{ + m_Orientation = orientation; +} +} // namespace ads + +//--------------------------------------------------------------------------- +// EOF PushButton.cpp diff --git a/src/PushButton.h b/src/PushButton.h new file mode 100644 index 0000000..9eac3bc --- /dev/null +++ b/src/PushButton.h @@ -0,0 +1,49 @@ +#ifndef PushButtonH +#define PushButtonH +//============================================================================ +/// \file PushButton.h +/// \author Uwe Kindler +/// \date 18.10.2022 +/// \brief Declaration of CPushButton +//============================================================================ + +//============================================================================ +// INCLUDES +//============================================================================ +#include + +namespace ads +{ + +/** + * ADS specific push button class + */ +class CPushButton : public QPushButton +{ + Q_OBJECT +public: + enum Orientation { + Horizontal, + VerticalTopToBottom, + VerticalBottomToTop + }; + + using QPushButton::QPushButton; + + virtual QSize sizeHint() const override; + + Orientation orientation() const; + void setOrientation(Orientation &orientation); + +protected: + virtual void paintEvent(QPaintEvent *event) override; + +private: + Orientation m_Orientation = Horizontal; +}; + +} // namespace ads + +//--------------------------------------------------------------------------- +#endif // PushButtonH + diff --git a/src/src.pro b/src/src.pro index e86ebad..d0422db 100644 --- a/src/src.pro +++ b/src/src.pro @@ -50,7 +50,8 @@ HEADERS += \ DockFocusController.h \ AutoHideDockContainer.h \ SideTabBar.h \ - DockWidgetSideTab.h + DockWidgetSideTab.h \ + PushButton.h SOURCES += \ @@ -73,7 +74,8 @@ SOURCES += \ DockFocusController.cpp \ AutoHideDockContainer.cpp \ SideTabBar.cpp \ - DockWidgetSideTab.cpp + DockWidgetSideTab.cpp \ + PushButton.cpp unix:!macx { From 866ccb2c4e32435b76267052ce84f6a66d8daa5d Mon Sep 17 00:00:00 2001 From: Uwe Kindler Date: Tue, 18 Oct 2022 16:43:39 +0200 Subject: [PATCH 4/5] Reimplemented DockWidgetSideTab based on QPushButton --- src/DockWidget.cpp | 2 +- src/DockWidgetSideTab.cpp | 216 ++---------------------------------- src/DockWidgetSideTab.h | 43 +------ src/PushButton.cpp | 2 +- src/PushButton.h | 2 +- src/stylesheets/default.css | 19 +--- 6 files changed, 16 insertions(+), 268 deletions(-) diff --git a/src/DockWidget.cpp b/src/DockWidget.cpp index 50eaf15..15fb9c4 100644 --- a/src/DockWidget.cpp +++ b/src/DockWidget.cpp @@ -326,7 +326,7 @@ CDockWidget::CDockWidget(const QString &title, QWidget *parent) : d->TabWidget = componentsFactory()->createDockWidgetTab(this); d->SideTabWidget = componentsFactory()->createDockWidgetSideTab(this); - connect(d->SideTabWidget, &CDockWidgetSideTab::clicked, this, &CDockWidget::onDockWidgetSideTabClicked); + connect(d->SideTabWidget, &CDockWidgetSideTab::pressed, this, &CDockWidget::onDockWidgetSideTabClicked); d->ToggleViewAction = new QAction(title, this); d->ToggleViewAction->setCheckable(true); diff --git a/src/DockWidgetSideTab.cpp b/src/DockWidgetSideTab.cpp index d3a7a1d..673a3b3 100644 --- a/src/DockWidgetSideTab.cpp +++ b/src/DockWidgetSideTab.cpp @@ -51,68 +51,13 @@ struct DockWidgetSideTabPrivate { CDockWidgetSideTab* _this; CDockWidget* DockWidget; - tTabLabel* TitleLabel; - QBoxLayout* Layout; - QBoxLayout* TitleLayout; // To have independent spacing from the icon CSideTabBar* SideTabBar; - QSize IconSize; Qt::Orientation Orientation{Qt::Vertical}; - CSideTabIconLabel* IconLabel = nullptr; - QIcon Icon; /** * Private data constructor */ DockWidgetSideTabPrivate(CDockWidgetSideTab* _public); - - /** - * Creates the complete layout - */ - void createLayout(); - - /** - * Update the icon in case the icon size changed - */ - void updateIcon() - { - if (!IconLabel || Icon.isNull()) - { - return; - } - - if (IconSize.isValid()) - { - IconLabel->setPixmap(Icon.pixmap(IconSize)); - } - else - { - IconLabel->setPixmap(Icon.pixmap(_this->style()->pixelMetric(QStyle::PM_SmallIconSize, nullptr, _this))); - } - IconLabel->setVisible(true); - } - - void updateContentsMargins() - { - QFontMetrics fm(TitleLabel->font()); - int Spacing = qRound(fm.height() / 2.0); - - if (Orientation == Qt::Vertical) - { - TitleLayout->setContentsMargins(Spacing, Spacing, 0, Spacing); - if (IconLabel) - { - IconLabel->setContentsMargins(Spacing / 2, Spacing / 2, Spacing / 2, 0); - } - } - else if (Orientation == Qt::Horizontal) - { - TitleLayout->setContentsMargins(Spacing / 2, Spacing, Spacing, Spacing); - if (IconLabel) - { - IconLabel->setContentsMargins(Spacing / 2, Spacing / 2, 0, Spacing / 2); - } - } - } }; // struct DockWidgetTabPrivate @@ -123,45 +68,6 @@ DockWidgetSideTabPrivate::DockWidgetSideTabPrivate(CDockWidgetSideTab* _public) } -//============================================================================ -void DockWidgetSideTabPrivate::createLayout() -{ - TitleLabel = new tTabLabel(); - TitleLabel->setElideMode(Qt::ElideRight); - TitleLabel->setText(DockWidget->windowTitle()); - TitleLabel->setObjectName("sideTabLabel"); - _this->connect(TitleLabel, SIGNAL(elidedChanged(bool)), SIGNAL(elidedChanged(bool))); - - // Fill the layout - // Purely for spacing on the text without messing up spacing on the icon - TitleLayout = new QBoxLayout(QBoxLayout::TopToBottom); - TitleLayout->setAlignment(Qt::AlignCenter); - TitleLayout->addWidget(TitleLabel); - TitleLayout->setSpacing(0); - - Layout = new QBoxLayout(QBoxLayout::TopToBottom); - Layout->setAlignment(Qt::AlignCenter); - Layout->setContentsMargins(0,0,0,0); - Layout->setSpacing(0); - _this->setLayout(Layout); - Layout->addLayout(TitleLayout); - - updateContentsMargins(); - - TitleLabel->setVisible(true); -} - -//============================================================================ -void CDockWidgetSideTab::mousePressEvent(QMouseEvent* event) -{ - if (event->button() == Qt::LeftButton) - { - emit clicked(); - } - - QFrame::mousePressEvent(event); -} - //============================================================================ void CDockWidgetSideTab::setSideTabBar(CSideTabBar* SideTabBar) @@ -183,13 +89,14 @@ void CDockWidgetSideTab::removeFromSideTabBar() //============================================================================ CDockWidgetSideTab::CDockWidgetSideTab(CDockWidget* DockWidget, QWidget* parent) : - QFrame(parent), + Super(parent), d(new DockWidgetSideTabPrivate(this)) { setAttribute(Qt::WA_NoMousePropagation); d->DockWidget = DockWidget; - d->createLayout(); + setText(DockWidget->windowTitle()); setFocusPolicy(Qt::NoFocus); + setFlat(true); } @@ -219,56 +126,12 @@ CDockWidgetSideTab::SideTabBarArea CDockWidgetSideTab::sideTabBarArea() const return Left; } - -//============================================================================ -void CDockWidgetSideTab::setIcon(const QIcon& Icon) -{ - QBoxLayout* Layout = qobject_cast(layout()); - if (!d->IconLabel && Icon.isNull()) - { - return; - } - - if (!d->IconLabel) - { - d->IconLabel = new CSideTabIconLabel(); - internal::setToolTip(d->IconLabel, d->TitleLabel->toolTip()); - Layout->insertWidget(0, d->IconLabel, Qt::AlignHCenter); - } - else if (Icon.isNull()) - { - // Remove icon label - Layout->removeWidget(d->IconLabel); - delete d->IconLabel; - d->IconLabel = nullptr; - } - - d->Icon = Icon; - d->updateIcon(); -} - - -//============================================================================ -QSize CDockWidgetSideTab::iconSize() const -{ - return d->IconSize; -} - - -//============================================================================ -void CDockWidgetSideTab::setIconSize(const QSize& Size) -{ - d->IconSize = Size; - d->updateIcon(); -} - - //============================================================================ void CDockWidgetSideTab::setOrientation(Qt::Orientation Orientation) { d->Orientation = Orientation; - d->Layout->setDirection(Orientation == Qt::Vertical ? QBoxLayout::TopToBottom : QBoxLayout::LeftToRight); - d->TitleLabel->setOrientation(Orientation); + CPushButton::setOrientation((Qt::Horizontal == Orientation) + ? CPushButton::Horizontal : CPushButton::VerticalTopToBottom); updateStyle(); } @@ -278,18 +141,7 @@ void CDockWidgetSideTab::updateOrientationAndSpacing(SideTabBarArea area) { setOrientation((area == Bottom || area == Top) ? Qt::Horizontal : Qt::Vertical); - d->updateContentsMargins(); - - // Handle Icon changes - if (d->Icon.isNull()) - { - return; - } - - QFontMetrics fm(d->TitleLabel->font()); - int Spacing = qRound(fm.height() / 2.0); - - if (CDockManager::testConfigFlag(CDockManager::LeftSideBarPrioritizeIconOnly) && area == Left) + /*if (CDockManager::testConfigFlag(CDockManager::LeftSideBarPrioritizeIconOnly) && area == Left) { d->TitleLabel->hide(); d->TitleLayout->setContentsMargins(0, 0, 0, 0); @@ -316,9 +168,7 @@ void CDockWidgetSideTab::updateOrientationAndSpacing(SideTabBarArea area) d->TitleLayout->setContentsMargins(0, 0, 0, 0); d->IconLabel->setContentsMargins(Spacing / 2, Spacing / 2, Spacing / 2, Spacing / 2); return; - } - - d->TitleLabel->show(); + }*/ } @@ -340,56 +190,4 @@ CDockWidget* CDockWidgetSideTab::dockWidget() const return d->DockWidget; } -/** - * Private data class of SideTabIcon class (pimpl) - */ -struct SideTabIconLabelPrivate -{ - CSideTabIconLabel* _this; - QLabel* IconLabel; - QBoxLayout* Layout; - - SideTabIconLabelPrivate(CSideTabIconLabel* _public); -}; // struct SideTabIconLabelPrivate - - -//============================================================================ -SideTabIconLabelPrivate::SideTabIconLabelPrivate(CSideTabIconLabel* _public) : - _this(_public) -{ -} - - -//============================================================================ -CSideTabIconLabel::CSideTabIconLabel(QWidget* parent) : QFrame(parent), - d(new SideTabIconLabelPrivate(this)) -{ - d->Layout = new QBoxLayout(QBoxLayout::TopToBottom); - d->Layout->addWidget(d->IconLabel = new QLabel()); - d->IconLabel->setObjectName("sideTabIconLabel"); - d->Layout->setAlignment(Qt::AlignCenter); - d->IconLabel->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred); - setLayout(d->Layout); -} - - -//============================================================================ -CSideTabIconLabel::~CSideTabIconLabel() -{ - delete d; -} - - -//============================================================================ -void CSideTabIconLabel::setPixmap(const QPixmap& pixmap) -{ - d->IconLabel->setPixmap(pixmap); -} - - -//============================================================================ -void CSideTabIconLabel::setContentsMargins(int left, int top, int right, int bottom) -{ - d->Layout->setContentsMargins(left, top, right, bottom); -} } diff --git a/src/DockWidgetSideTab.h b/src/DockWidgetSideTab.h index 7e50dd8..9246876 100644 --- a/src/DockWidgetSideTab.h +++ b/src/DockWidgetSideTab.h @@ -29,7 +29,7 @@ //============================================================================ // INCLUDES //============================================================================ -#include +#include "PushButton.h" #include "ads_globals.h" @@ -46,12 +46,11 @@ struct SideTabIconLabelPrivate; * The dock widget tab is shown in the side tab bar to switch between * pinned dock widgets */ -class ADS_EXPORT CDockWidgetSideTab : public QFrame +class ADS_EXPORT CDockWidgetSideTab : public CPushButton { Q_OBJECT Q_PROPERTY(SideTabBarArea sideTabBarArea READ sideTabBarArea) - Q_PROPERTY(QSize iconSize READ iconSize WRITE setIconSize) Q_PROPERTY(bool activeTab READ isActiveTab) private: @@ -65,13 +64,11 @@ protected: friend class CDockAreaWidget; friend class CDockContainerWidget; - void mousePressEvent(QMouseEvent* event) override; - void setSideTabBar(CSideTabBar *SideTabBar); void removeFromSideTabBar(); public: - using Super = QFrame; + using Super = CPushButton; /** * Dock widget side tab bar locations @@ -108,25 +105,6 @@ public: */ SideTabBarArea sideTabBarArea() const; - /** - * Sets the icon to show in title bar - */ - void setIcon(const QIcon& Icon); - - /** - * Returns the icon size. - * If no explicit icon size has been set, the function returns an invalid - * QSize - */ - QSize iconSize() const; - - /** - * Set an explicit icon size. - * If no icon size has been set explicitly, than the tab sets the icon size - * depending on the style - */ - void setIconSize(const QSize& Size); - /** * Set orientation vertical or horizontal */ @@ -149,22 +127,7 @@ public: Q_SIGNALS: void elidedChanged(bool elided); - void clicked(); }; // class DockWidgetSideTab - -class CSideTabIconLabel : public QFrame -{ - Q_OBJECT -private: - SideTabIconLabelPrivate *d; ///< private data (pimpl) - -public: - CSideTabIconLabel(QWidget* parent = nullptr); - virtual ~CSideTabIconLabel(); - - void setPixmap(const QPixmap &pixmap); - void setContentsMargins(int left, int top, int right, int bottom); -}; // class SideTabIconLabel } // namespace ads //----------------------------------------------------------------------------- diff --git a/src/PushButton.cpp b/src/PushButton.cpp index ad120cf..e88a500 100644 --- a/src/PushButton.cpp +++ b/src/PushButton.cpp @@ -59,7 +59,7 @@ CPushButton::Orientation CPushButton::orientation() const return m_Orientation; } -void CPushButton::setOrientation(Orientation &orientation) +void CPushButton::setOrientation(Orientation orientation) { m_Orientation = orientation; } diff --git a/src/PushButton.h b/src/PushButton.h index 9eac3bc..2d36961 100644 --- a/src/PushButton.h +++ b/src/PushButton.h @@ -33,7 +33,7 @@ public: virtual QSize sizeHint() const override; Orientation orientation() const; - void setOrientation(Orientation &orientation); + void setOrientation(Orientation orientation); protected: virtual void paintEvent(QPaintEvent *event) override; diff --git a/src/stylesheets/default.css b/src/stylesheets/default.css index 342967b..09cf2e0 100644 --- a/src/stylesheets/default.css +++ b/src/stylesheets/default.css @@ -110,30 +110,17 @@ QScrollArea#dockWidgetScrollArea { *---------------------------------------------------------------------------- */ ads--CDockWidgetSideTab { - background: palette(window); + /*background: palette(window);*/ qproperty-iconSize: 16px 16px;/* this is optional in case you would like to change icon size*/ } ads--CDockWidgetSideTab[sideTabBarArea="0"] { - border-right: 1px solid white; - background: red; + /*border-right: 1px solid white;*/ } -#sideTabLabel { - background: green; -} - -#sideTabIconLabel { - background: blue; -} - -ads--CSideTabIconLabel { - border: 1px solid yellow -} ads--CDockWidgetSideTab[sideTabBarArea="1"] { - border-bottom: 1px solid white; - background: red; + /*border-bottom: 1px solid white;*/ } ads--CDockWidgetSideTab[sideTabBarArea="2"] { From 63fed89f26f2eb2829b3a398cc35fcca10253661 Mon Sep 17 00:00:00 2001 From: Uwe Kindler Date: Tue, 18 Oct 2022 17:00:42 +0200 Subject: [PATCH 5/5] Removed individual config flags for each sidebar with the global AutoHideFeatureEnabled flag --- demo/MainWindow.cpp | 2 +- src/AutoHideDockContainer.cpp | 27 --------------------------- src/AutoHideDockContainer.h | 5 ----- src/DockAreaTitleBar.cpp | 2 +- src/DockContainerWidget.cpp | 13 ++++++------- src/DockManager.h | 26 ++++++++++---------------- 6 files changed, 18 insertions(+), 57 deletions(-) diff --git a/demo/MainWindow.cpp b/demo/MainWindow.cpp index 8b43e2e..8a028e5 100644 --- a/demo/MainWindow.cpp +++ b/demo/MainWindow.cpp @@ -653,7 +653,7 @@ CMainWindow::CMainWindow(QWidget *parent) : //CDockManager::setConfigFlag(CDockManager::FocusHighlighting, true); // uncomment if you would like to enable dock widget auto hiding - // CDockManager::setConfigFlag(CDockManager::DefaultAutoHideConfig, true); + CDockManager::setConfigFlag(CDockManager::DefaultAutoHideConfig, true); // uncomment if you would like to enable an equal distribution of the // available size of a splitter to all contained dock widgets diff --git a/src/AutoHideDockContainer.cpp b/src/AutoHideDockContainer.cpp index 3206380..6d28843 100644 --- a/src/AutoHideDockContainer.cpp +++ b/src/AutoHideDockContainer.cpp @@ -454,33 +454,6 @@ void CAutoHideDockContainer::toggleCollapseState() } -//============================================================================ -bool CAutoHideDockContainer::areaExistsInConfig(CDockWidgetSideTab::SideTabBarArea area) -{ - switch (area) - { - case CDockWidgetSideTab::Left: - { - return CDockManager::testConfigFlag(CDockManager::DockContainerHasLeftSideBar); - } - case CDockWidgetSideTab::Right: - { - return CDockManager::testConfigFlag(CDockManager::DockContainerHasRightSideBar); - } - case CDockWidgetSideTab::Bottom: - { - return CDockManager::testConfigFlag(CDockManager::DockContainerHasBottomSideBar); - } - case CDockWidgetSideTab::Top: - { - return CDockManager::testConfigFlag(CDockManager::DockContainerHasTopSideBar); - } - } - - return true; -} - - //============================================================================ bool CAutoHideDockContainer::eventFilter(QObject* watched, QEvent* event) { diff --git a/src/AutoHideDockContainer.h b/src/AutoHideDockContainer.h index 6ba264e..7aa90f5 100644 --- a/src/AutoHideDockContainer.h +++ b/src/AutoHideDockContainer.h @@ -152,11 +152,6 @@ public: * Toggles the current collapse state */ void toggleCollapseState(); - - /* - * Convenience function fr determining if area exists in config - */ - static bool areaExistsInConfig(CDockWidgetSideTab::SideTabBarArea area); }; } diff --git a/src/DockAreaTitleBar.cpp b/src/DockAreaTitleBar.cpp index ff0ce6e..9ef1501 100644 --- a/src/DockAreaTitleBar.cpp +++ b/src/DockAreaTitleBar.cpp @@ -191,7 +191,7 @@ void DockAreaTitleBarPrivate::createButtons() _this->connect(UndockButton, SIGNAL(clicked()), SLOT(onUndockButtonClicked())); // AutoHide Button - const auto autoHideEnabled = testConfigFlag(CDockManager::DockContainerHasRightSideBar) || testConfigFlag(CDockManager::DockContainerHasLeftSideBar) || testConfigFlag(CDockManager::DockContainerHasBottomSideBar); + const auto autoHideEnabled = testConfigFlag(CDockManager::AutoHideFeatureEnabled); AutoHideButton = new CTitleBarButton(testConfigFlag(CDockManager::DockAreaHasAutoHideButton) && autoHideEnabled); AutoHideButton->setObjectName("dockAreaAutoHideButton"); AutoHideButton->setAutoRaise(true); diff --git a/src/DockContainerWidget.cpp b/src/DockContainerWidget.cpp index 70e481d..5aba7e1 100644 --- a/src/DockContainerWidget.cpp +++ b/src/DockContainerWidget.cpp @@ -1048,7 +1048,7 @@ bool DockContainerWidgetPrivate::restoreAutoHideDockArea(CDockingStateReader& s, ADS_PRINT("Restore NodeDockArea Tabs: " << Tabs << " Current: " << CurrentDockWidget); - if (!CAutoHideDockContainer::areaExistsInConfig(area)) + if (!CDockManager::testConfigFlag(CDockManager::AutoHideFeatureEnabled)) { return false; } @@ -1452,7 +1452,10 @@ CDockContainerWidget::CDockContainerWidget(CDockManager* DockManager, QWidget *p { d->DockManager->registerDockContainer(this); createRootSplitter(); - createSideTabBarWidgets(); + if (CDockManager::testConfigFlag(CDockManager::AutoHideFeatureEnabled)) + { + createSideTabBarWidgets(); + } } } @@ -1503,7 +1506,7 @@ CAutoHideDockContainer* CDockContainerWidget::createAndInitializeAutoHideDockWid { DockWidget->setDockManager(d->DockManager); // Overlay Dock Container needs a valid dock manager } - if (!CAutoHideDockContainer::areaExistsInConfig(area)) + if (!CDockManager::testConfigFlag(CDockManager::AutoHideFeatureEnabled)) { Q_ASSERT_X(false, "CDockContainerWidget::createAndInitializeDockWidgetOverlayContainer", "Requested area does not exist in config"); @@ -2094,7 +2097,6 @@ void CDockContainerWidget::createRootSplitter() //============================================================================ void CDockContainerWidget::createSideTabBarWidgets() { - if (CDockManager::testConfigFlag(CDockManager::DockContainerHasLeftSideBar)) { auto leftLayout = new QVBoxLayout(); d->SideTabBarWidgets[CDockWidgetSideTab::Left] = new CSideTabBar(this, Qt::Vertical); @@ -2103,7 +2105,6 @@ void CDockContainerWidget::createSideTabBarWidgets() d->Layout->addLayout(leftLayout, 1, 0); } - if (CDockManager::testConfigFlag(CDockManager::DockContainerHasRightSideBar)) { auto rightLayout = new QVBoxLayout(); d->SideTabBarWidgets[CDockWidgetSideTab::Right] = new CSideTabBar(this, Qt::Vertical); @@ -2112,13 +2113,11 @@ void CDockContainerWidget::createSideTabBarWidgets() d->Layout->addLayout(rightLayout, 1, 2); } - if (CDockManager::testConfigFlag(CDockManager::DockContainerHasBottomSideBar)) { d->SideTabBarWidgets[CDockWidgetSideTab::Bottom] = new CSideTabBar(this, Qt::Horizontal); d->Layout->addWidget(d->SideTabBarWidgets[CDockWidgetSideTab::Bottom], 2, 1); } - if (CDockManager::testConfigFlag(CDockManager::DockContainerHasTopSideBar)) { d->SideTabBarWidgets[CDockWidgetSideTab::Top] = new CSideTabBar(this, Qt::Horizontal); d->Layout->addWidget(d->SideTabBarWidgets[CDockWidgetSideTab::Top], 0, 1); diff --git a/src/DockManager.h b/src/DockManager.h index a378486..1aa4952 100644 --- a/src/DockManager.h +++ b/src/DockManager.h @@ -226,23 +226,17 @@ public: enum eAutoHideFlag { - DockContainerHasLeftSideBar = 0x01, //!< If the flag is set the dock manager will have a left side bar - DockContainerHasRightSideBar = 0x02, //!< If the flag is set the dock manager will have a right side bar - DockContainerHasBottomSideBar = 0x04, //!< If the flag is set the dock manager will have a bottom side bar - DockContainerHasTopSideBar = 0x08, //!< If the flag is set the dock manager will have a top side bar - DockAreaHasAutoHideButton = 0x10, //!< If the flag is set each dock area has a auto hide menu button - LeftSideBarPrioritizeIconOnly = 0x20, //!< If the flag is set left side bar will prioritize showing icons only over text - RightSideBarPrioritizeIconOnly = 0x40, //!< If the flag is set right side bar will prioritize showing icons only over text - BottomSideBarPrioritizeIconOnly = 0x80,//!< If the flag is set bottom side bar will prioritize showing icons only over text - TopSideBarPrioritizeIconOnly = 0x100, //!< If the flag is set top side bar will prioritize showing icons only over text - AutoHideDockAreaHasTitle = 0x200, //!< If the flag is set overlay dock area title bar will show the window title - AutoHideButtonTogglesArea = 0x400, //!< If the flag is set, the auto hide button enables auto hiding for all dock widgets in an area, if disabled, only the current dock widget will be toggled + AutoHideFeatureEnabled = 0x01, + DockAreaHasAutoHideButton = 0x02, //!< If the flag is set each dock area has a auto hide menu button + LeftSideBarPrioritizeIconOnly = 0x04, //!< If the flag is set left side bar will prioritize showing icons only over text + RightSideBarPrioritizeIconOnly = 0x08, //!< If the flag is set right side bar will prioritize showing icons only over text + BottomSideBarPrioritizeIconOnly = 0x10,//!< If the flag is set bottom side bar will prioritize showing icons only over text + TopSideBarPrioritizeIconOnly = 0x20, //!< If the flag is set top side bar will prioritize showing icons only over text + AutoHideDockAreaHasTitle = 0x40, //!< If the flag is set overlay dock area title bar will show the window title + AutoHideButtonTogglesArea = 0x80, //!< If the flag is set, the auto hide button enables auto hiding for all dock widgets in an area, if disabled, only the current dock widget will be toggled - DefaultAutoHideConfig = DockContainerHasLeftSideBar - | DockContainerHasRightSideBar - | DockContainerHasBottomSideBar - | DockContainerHasTopSideBar - | DockAreaHasAutoHideButton + DefaultAutoHideConfig = AutoHideFeatureEnabled + | DockAreaHasAutoHideButton | AutoHideDockAreaHasTitle, ///< the default configuration for left and right side bars }; Q_DECLARE_FLAGS(AutoHideFlags, eAutoHideFlag)