From 0087a1b3602fd865cb09603e849725e65e562bd1 Mon Sep 17 00:00:00 2001 From: Syarif Fakhri Date: Thu, 8 Sep 2022 11:30:56 +0800 Subject: [PATCH] Add left right styling to the dock widget side tab --- src/DockAreaWidget.cpp | 2 +- src/DockAreaWidget.h | 3 +- src/DockContainerWidget.cpp | 40 +++++++++++++------------- src/DockContainerWidget.h | 7 +++-- src/DockManager.cpp | 4 +-- src/DockManager.h | 14 ++++----- src/DockWidgetSideTab.cpp | 13 +++++++++ src/DockWidgetSideTab.h | 21 ++++++++++++++ src/OverlayDockContainer.cpp | 24 ++++++++-------- src/OverlayDockContainer.h | 15 ++++++---- src/ads_globals.h | 11 ------- src/stylesheets/focus_highlighting.css | 9 +++++- 12 files changed, 99 insertions(+), 64 deletions(-) diff --git a/src/DockAreaWidget.cpp b/src/DockAreaWidget.cpp index 4c51b91..502c8b3 100644 --- a/src/DockAreaWidget.cpp +++ b/src/DockAreaWidget.cpp @@ -1040,7 +1040,7 @@ void CDockAreaWidget::toggleAutoHideArea(bool Enable) } //============================================================================ -void CDockAreaWidget::onAutoHideToggleRequested(CDockWidget* DockWidget, bool Enable, SideTabBarArea area) +void CDockAreaWidget::onAutoHideToggleRequested(CDockWidget* DockWidget, bool Enable, CDockWidgetSideTab::SideTabBarArea area) { if (Enable) { diff --git a/src/DockAreaWidget.h b/src/DockAreaWidget.h index 9c39c2a..67063b6 100644 --- a/src/DockAreaWidget.h +++ b/src/DockAreaWidget.h @@ -34,6 +34,7 @@ #include "ads_globals.h" #include "DockWidget.h" +#include "DockWidgetSideTab.h" QT_FORWARD_DECLARE_CLASS(QXmlStreamWriter) QT_FORWARD_DECLARE_CLASS(QAbstractButton) @@ -161,7 +162,7 @@ protected Q_SLOTS: /** * Auto hides the dock area and all dock widgets in this area */ - void onAutoHideToggleRequested(CDockWidget* DockWidget, bool Enable, SideTabBarArea area); + void onAutoHideToggleRequested(CDockWidget* DockWidget, bool Enable, CDockWidgetSideTab::SideTabBarArea area); public: using Super = QFrame; diff --git a/src/DockContainerWidget.cpp b/src/DockContainerWidget.cpp index ff64c25..dd5e396 100644 --- a/src/DockContainerWidget.cpp +++ b/src/DockContainerWidget.cpp @@ -138,7 +138,7 @@ public: unsigned int zOrderIndex = 0; QList DockAreas; QList OverlayWidgets; - QMap SideTabBarWidgets; + QMap SideTabBarWidgets; QGridLayout* Layout = nullptr; QSplitter* RootSplitter = nullptr; bool isFloating = false; @@ -254,7 +254,7 @@ public: * Assumes that there are no overlay dock areas, and then restores all the dock areas that * exist in the XML */ - bool restoreOverlayDockArea(CDockingStateReader& s, SideTabBarArea area, bool Testing); + bool restoreOverlayDockArea(CDockingStateReader& s, CDockWidgetSideTab::SideTabBarArea area, bool Testing); /** * Restores either a dock area or an overlay dock area depending on the value in the XML @@ -1032,7 +1032,7 @@ bool DockContainerWidgetPrivate::restoreSplitter(CDockingStateReader& s, } //============================================================================ -bool DockContainerWidgetPrivate::restoreOverlayDockArea(CDockingStateReader& s, SideTabBarArea area, bool Testing) +bool DockContainerWidgetPrivate::restoreOverlayDockArea(CDockingStateReader& s, CDockWidgetSideTab::SideTabBarArea area, bool Testing) { bool Ok; #ifdef ADS_DEBUG_PRINT @@ -1128,12 +1128,12 @@ bool DockContainerWidgetPrivate::restoreDockOrOverlayDockArea(CDockingStateReade const auto sideTabAreaValue = Stream.attributes().value("SideTabBarArea"); if (!sideTabAreaValue.isNull()) { - auto sideTabBarArea = static_cast(sideTabAreaValue.toInt(&Ok)); + auto sideTabBarArea = static_cast(sideTabAreaValue.toInt(&Ok)); if (!Ok) { return false; } - if (sideTabBarArea != SideTabBarArea::None) + if (sideTabBarArea != CDockWidgetSideTab::None) { return restoreOverlayDockArea(Stream, sideTabBarArea, Testing); } @@ -1500,7 +1500,7 @@ CDockAreaWidget* CDockContainerWidget::addDockWidget(DockWidgetArea area, CDockW //============================================================================ -COverlayDockContainer* CDockContainerWidget::createAndInitializeDockWidgetOverlayContainer(SideTabBarArea area, CDockWidget* DockWidget) +COverlayDockContainer* CDockContainerWidget::createAndInitializeDockWidgetOverlayContainer(CDockWidgetSideTab::SideTabBarArea area, CDockWidget* DockWidget) { if (d->DockManager != DockWidget->dockManager()) { @@ -1522,31 +1522,31 @@ COverlayDockContainer* CDockContainerWidget::createAndInitializeDockWidgetOverla } //============================================================================ -SideTabBarArea CDockContainerWidget::getDockAreaPosition(CDockAreaWidget* DockAreaWidget) +CDockWidgetSideTab::SideTabBarArea CDockContainerWidget::getDockAreaPosition(CDockAreaWidget* DockAreaWidget) { const auto dockWidgetCenter = DockAreaWidget->mapToGlobal(DockAreaWidget->frameGeometry().center()); const auto splitterCenter = rootSplitter()->mapToGlobal(rootSplitter()->frameGeometry().center()); - const auto calculatedPosition = dockWidgetCenter.x() <= splitterCenter.x() ? Left : Right; - if (calculatedPosition == Right) + const auto calculatedPosition = dockWidgetCenter.x() <= splitterCenter.x() ? CDockWidgetSideTab::Left : CDockWidgetSideTab::Right; + if (calculatedPosition == CDockWidgetSideTab::Right) { if (CDockManager::testConfigFlag(CDockManager::DockContainerHasRightSideBar)) { - return Right; + return CDockWidgetSideTab::Right; } - return Left; + return CDockWidgetSideTab::Left; } - if (calculatedPosition == Left) + if (calculatedPosition == CDockWidgetSideTab::Left) { if (CDockManager::testConfigFlag(CDockManager::DockContainerHasLeftSideBar)) { - return Left; + return CDockWidgetSideTab::Left; } - return Right; + return CDockWidgetSideTab::Right; } - return Left; + return CDockWidgetSideTab::Left; } @@ -2025,14 +2025,14 @@ void CDockContainerWidget::createSideTabBarWidgets() { if (CDockManager::testConfigFlag(CDockManager::DockContainerHasLeftSideBar)) { - d->SideTabBarWidgets[SideTabBarArea::Left] = new CSideTabBar(this); - d->Layout->addWidget(d->SideTabBarWidgets[SideTabBarArea::Left], 0, 0); + d->SideTabBarWidgets[CDockWidgetSideTab::Left] = new CSideTabBar(this); + d->Layout->addWidget(d->SideTabBarWidgets[CDockWidgetSideTab::Left], 0, 0); } if (CDockManager::testConfigFlag(CDockManager::DockContainerHasRightSideBar)) { - d->SideTabBarWidgets[SideTabBarArea::Right] = new CSideTabBar(this); - d->Layout->addWidget(d->SideTabBarWidgets[SideTabBarArea::Right], 0, 2); + d->SideTabBarWidgets[CDockWidgetSideTab::Right] = new CSideTabBar(this); + d->Layout->addWidget(d->SideTabBarWidgets[CDockWidgetSideTab::Right], 0, 2); } } @@ -2181,7 +2181,7 @@ void CDockContainerWidget::closeOtherAreas(CDockAreaWidget* KeepOpenArea) } //============================================================================ -CSideTabBar* CDockContainerWidget::sideTabBar(SideTabBarArea area) const +CSideTabBar* CDockContainerWidget::sideTabBar(CDockWidgetSideTab::SideTabBarArea area) const { return d->SideTabBarWidgets[area]; } diff --git a/src/DockContainerWidget.h b/src/DockContainerWidget.h index 281602d..5588f65 100644 --- a/src/DockContainerWidget.h +++ b/src/DockContainerWidget.h @@ -34,6 +34,7 @@ #include "ads_globals.h" #include "DockWidget.h" +#include "DockWidgetSideTab.h" QT_FORWARD_DECLARE_CLASS(QXmlStreamWriter) @@ -105,7 +106,7 @@ protected: * Initializing inserts the tabs into the side tab widget and hides it * Returns nullptr if you try and insert into an area where the configuration is not enabled */ - COverlayDockContainer* createAndInitializeDockWidgetOverlayContainer(SideTabBarArea area, CDockWidget* DockWidget); + COverlayDockContainer* createAndInitializeDockWidgetOverlayContainer(CDockWidgetSideTab::SideTabBarArea area, CDockWidget* DockWidget); /** * Helper function for creation of the root splitter @@ -226,7 +227,7 @@ public: /** * Get's the overlay dock side tab bar area based on the dock area widget position */ - SideTabBarArea getDockAreaPosition(CDockAreaWidget* DockAreaWidget); + CDockWidgetSideTab::SideTabBarArea getDockAreaPosition(CDockAreaWidget* DockAreaWidget); /** * Removes dockwidget @@ -326,7 +327,7 @@ public: /** * Returns the side tab widget for the given area */ - CSideTabBar* sideTabBar(SideTabBarArea area) const; + CSideTabBar* sideTabBar(CDockWidgetSideTab::SideTabBarArea area) const; Q_SIGNALS: /** diff --git a/src/DockManager.cpp b/src/DockManager.cpp index e3e2a87..6708552 100644 --- a/src/DockManager.cpp +++ b/src/DockManager.cpp @@ -863,13 +863,13 @@ CDockAreaWidget* CDockManager::addDockWidgetToContainer(DockWidgetArea area, } //============================================================================ -COverlayDockContainer* CDockManager::addOverlayDockWidget(SideTabBarArea area, CDockWidget* Dockwidget) +COverlayDockContainer* CDockManager::addOverlayDockWidget(CDockWidgetSideTab::SideTabBarArea area, CDockWidget* Dockwidget) { return addOverlayDockWidgetToContainer(area, Dockwidget, this); } //============================================================================ -COverlayDockContainer* CDockManager::addOverlayDockWidgetToContainer(SideTabBarArea area, CDockWidget* Dockwidget, CDockContainerWidget* DockContainerWidget) +COverlayDockContainer* CDockManager::addOverlayDockWidgetToContainer(CDockWidgetSideTab::SideTabBarArea area, CDockWidget* Dockwidget, CDockContainerWidget* DockContainerWidget) { d->DockWidgetsMap.insert(Dockwidget->objectName(), Dockwidget); auto container = DockContainerWidget->createAndInitializeDockWidgetOverlayContainer(area, Dockwidget); diff --git a/src/DockManager.h b/src/DockManager.h index d7930b4..14b3331 100644 --- a/src/DockManager.h +++ b/src/DockManager.h @@ -212,14 +212,14 @@ public: | DockAreaHasUndockButton | DockAreaHasTabsMenuButton, ///< default configuration of dock area title bar buttons - DefaultDockContainerSideBars = DockContainerHasLeftSideBar - | DockContainerHasRightSideBar, ///< the default configuration for left and right side bars + DefaultDockContainerConfig = DockContainerHasLeftSideBar + | DockContainerHasRightSideBar + | DockAreaHasAutoHideButton, ///< the default configuration for left and right side bars DefaultBaseConfig = DefaultDockAreaButtons | ActiveTabHasCloseButton | XmlCompressionEnabled - | FloatingContainerHasWidgetTitle - | DefaultDockContainerSideBars, ///< default base configuration settings + | FloatingContainerHasWidgetTitle, ///< default base configuration settings DefaultOpaqueConfig = DefaultBaseConfig | OpaqueSplitterResize @@ -307,14 +307,14 @@ public: * An overlay widget is used for auto hide functionality * \return Returns the COverlayDockContainer that contains the new DockWidget */ - COverlayDockContainer* addOverlayDockWidget(SideTabBarArea area, CDockWidget* Dockwidget); + COverlayDockContainer* addOverlayDockWidget(CDockWidgetSideTab::SideTabBarArea area, CDockWidget* Dockwidget); /** - * Adds dock widget overlayed into the given container based on the SideTabBarArea. + * Adds dock widget overlayed into the given container based on the CDockWidgetSideTab::SideTabBarArea. * An overlay widget is used for auto hide functionality * \return Returns the COverlayDockContainer that contains the new DockWidget */ - COverlayDockContainer* addOverlayDockWidgetToContainer(SideTabBarArea area, CDockWidget* Dockwidget, CDockContainerWidget* DockContainerWidget); + COverlayDockContainer* addOverlayDockWidgetToContainer(CDockWidgetSideTab::SideTabBarArea area, CDockWidget* Dockwidget, CDockContainerWidget* DockContainerWidget); /** * This function will add the given Dockwidget to the given dock area as diff --git a/src/DockWidgetSideTab.cpp b/src/DockWidgetSideTab.cpp index a3d2b23..1913d8d 100644 --- a/src/DockWidgetSideTab.cpp +++ b/src/DockWidgetSideTab.cpp @@ -32,9 +32,11 @@ #include +#include "DockAreaWidget.h" #include "ElidingLabel.h" #include "DockWidget.h" +#include "OverlayDockContainer.h" namespace ads { @@ -148,4 +150,15 @@ void CDockWidgetSideTab::updateStyle() { internal::repolishStyle(this, internal::RepolishDirectChildren); } + +CDockWidgetSideTab::SideTabBarArea CDockWidgetSideTab::sideTabBarArea() const +{ + auto dockAreaWidget = d->DockWidget->dockAreaWidget(); + if (dockAreaWidget && dockAreaWidget->isOverlayed()) + { + return dockAreaWidget->overlayDockContainer()->sideTabBarArea(); + } + + return Left; +} } diff --git a/src/DockWidgetSideTab.h b/src/DockWidgetSideTab.h index e99ada0..73f1adb 100644 --- a/src/DockWidgetSideTab.h +++ b/src/DockWidgetSideTab.h @@ -49,6 +49,8 @@ class ADS_EXPORT CDockWidgetSideTab : public QFrame { Q_OBJECT + Q_PROPERTY(SideTabBarArea sideTabBarArea READ sideTabBarArea) + private: DockWidgetSideTabPrivate* d; ///< private data (pimpl) friend struct DockWidgetSideTabPrivate; @@ -67,6 +69,20 @@ protected: public: using Super = QFrame; + + /** + * Dock widget side tab bar locations + */ + enum SideTabBarArea + { + None, + Left, + Right, + Bottom + }; + + Q_ENUM(SideTabBarArea) + /** * Default Constructor * param[in] DockWidget The dock widget this title bar belongs to @@ -85,6 +101,11 @@ public: */ void updateStyle(); + /** + * Getter for side tab bar area property + */ + SideTabBarArea sideTabBarArea() const; + Q_SIGNALS: void elidedChanged(bool elided); void clicked(); diff --git a/src/OverlayDockContainer.cpp b/src/OverlayDockContainer.cpp index 489e96f..9ff8e3b 100644 --- a/src/OverlayDockContainer.cpp +++ b/src/OverlayDockContainer.cpp @@ -52,7 +52,7 @@ struct OverlayDockContainerPrivate CDockWidget* DockWidget{nullptr}; QPointer DockManager{nullptr}; QSplitter* Splitter; - SideTabBarArea Area; + CDockWidgetSideTab::SideTabBarArea Area; /** * Private data constructor @@ -74,7 +74,7 @@ CDockContainerWidget* COverlayDockContainer::parentContainer() const } //============================================================================ -COverlayDockContainer::COverlayDockContainer(CDockManager* DockManager, SideTabBarArea area, CDockContainerWidget* parent) : +COverlayDockContainer::COverlayDockContainer(CDockManager* DockManager, CDockWidgetSideTab::SideTabBarArea area, CDockContainerWidget* parent) : QFrame(parent), d(new OverlayDockContainerPrivate(this)) { @@ -92,7 +92,7 @@ COverlayDockContainer::COverlayDockContainer(CDockManager* DockManager, SideTabB const auto emptyWidget = new QWidget(); emptyWidget->setMinimumWidth(50); - if (area == SideTabBarArea::Left) + if (area == CDockWidgetSideTab::SideTabBarArea::Left) { d->Splitter->addWidget(d->DockArea); d->Splitter->addWidget(emptyWidget); @@ -123,7 +123,7 @@ void COverlayDockContainer::updateMask() const auto rect = d->DockArea->frameGeometry(); const auto topLeft = rect.topLeft(); const auto handleSize = d->Splitter->handleWidth(); - const auto offset = d->Area == SideTabBarArea::Left ? 0 : handleSize; + const auto offset = d->Area == CDockWidgetSideTab::SideTabBarArea::Left ? 0 : handleSize; setMask(QRect(QPoint(topLeft.x() - offset, topLeft.y()), QSize(rect.size().width() + handleSize, rect.size().height()))); } @@ -138,7 +138,7 @@ void COverlayDockContainer::updateSize() } //============================================================================ -COverlayDockContainer::COverlayDockContainer(CDockWidget* DockWidget, SideTabBarArea area, CDockContainerWidget* parent) : +COverlayDockContainer::COverlayDockContainer(CDockWidget* DockWidget, CDockWidgetSideTab::SideTabBarArea area, CDockContainerWidget* parent) : COverlayDockContainer(DockWidget->dockManager(), area, parent) { addDockWidget(DockWidget); @@ -195,7 +195,7 @@ void COverlayDockContainer::addDockWidget(CDockWidget* DockWidget) //============================================================================ -SideTabBarArea COverlayDockContainer::sideTabBarArea() const +CDockWidgetSideTab::SideTabBarArea COverlayDockContainer::sideTabBarArea() const { return d->Area; } @@ -209,7 +209,7 @@ CDockAreaWidget* COverlayDockContainer::dockAreaWidget() const //============================================================================ void COverlayDockContainer::moveContentsToParent() { - const auto position = mapToGlobal(d->Area == Left ? QPoint(1,height() / 2) : QPoint(width() - 1, height() / 2)); + const auto position = mapToGlobal(d->Area == CDockWidgetSideTab::Left ? QPoint(1,height() / 2) : QPoint(width() - 1, height() / 2)); const auto dockAreaWidget = parentContainer()->dockAreaAt(position); if (dockAreaWidget != nullptr && !dockAreaWidget->isCentralWidgetArea()) @@ -218,7 +218,7 @@ void COverlayDockContainer::moveContentsToParent() } else { - parentContainer()->addDockWidget(d->Area == Left ? LeftDockWidgetArea : RightDockWidgetArea, d->DockWidget); + parentContainer()->addDockWidget(d->Area == CDockWidgetSideTab::Left ? LeftDockWidgetArea : RightDockWidgetArea, d->DockWidget); } cleanupAndDelete(); } @@ -239,7 +239,7 @@ void COverlayDockContainer::cleanupAndDelete() void COverlayDockContainer::saveState(QXmlStreamWriter& s) { - s.writeAttribute("SideTabBarArea", QString::number(sideTabBarArea())); + s.writeAttribute("CDockWidgetSideTab::SideTabBarArea", QString::number(sideTabBarArea())); QStringList Sizes; for (auto Size : d->Splitter->sizes()) { @@ -275,13 +275,13 @@ bool COverlayDockContainer::restoreState(CDockingStateReader& s, bool Testing) return true; } -bool COverlayDockContainer::areaExistsInConfig(SideTabBarArea area) +bool COverlayDockContainer::areaExistsInConfig(CDockWidgetSideTab::SideTabBarArea area) { - if (area == Left && !CDockManager::testConfigFlag(CDockManager::DockContainerHasLeftSideBar)) + if (area == CDockWidgetSideTab::Left && !CDockManager::testConfigFlag(CDockManager::DockContainerHasLeftSideBar)) { return false; } - if (area == Right && !CDockManager::testConfigFlag(CDockManager::DockContainerHasRightSideBar)) + if (area == CDockWidgetSideTab::Right && !CDockManager::testConfigFlag(CDockManager::DockContainerHasRightSideBar)) { return false; } diff --git a/src/OverlayDockContainer.h b/src/OverlayDockContainer.h index ad42e4d..4a53172 100644 --- a/src/OverlayDockContainer.h +++ b/src/OverlayDockContainer.h @@ -31,6 +31,8 @@ //============================================================================ #include "ads_globals.h" +#include "DockWidgetSideTab.h" + #include class QXmlStreamWriter; @@ -48,12 +50,11 @@ class CDockingStateReader; class ADS_EXPORT COverlayDockContainer : public QFrame { Q_OBJECT + private: OverlayDockContainerPrivate* d; ///< private data (pimpl) friend struct OverlayDockContainerPrivate; - CDockContainerWidget* parentContainer() const; - protected: bool eventFilter(QObject* watched, QEvent* event) override; void mousePressEvent(QMouseEvent* event) override; @@ -61,16 +62,18 @@ protected: void updateMask(); void updateSize(); + CDockContainerWidget* parentContainer() const; + public: /** * Create overlay widget with a dock manager */ - COverlayDockContainer(CDockManager* DockManager, SideTabBarArea area, CDockContainerWidget* parent); + COverlayDockContainer(CDockManager* DockManager, CDockWidgetSideTab::SideTabBarArea area, CDockContainerWidget* parent); /** * Create overlay widget with the given dock widget */ - COverlayDockContainer(CDockWidget* DockWidget, SideTabBarArea area, CDockContainerWidget* parent); + COverlayDockContainer(CDockWidget* DockWidget, CDockWidgetSideTab::SideTabBarArea area, CDockContainerWidget* parent); /** * Virtual Destructor @@ -95,7 +98,7 @@ public: /** * Returns the side tab bar area of this overlay dock container */ - SideTabBarArea sideTabBarArea() const; + CDockWidgetSideTab::SideTabBarArea sideTabBarArea() const; /** * Returns the dock area widget of this overlay dock container @@ -126,7 +129,7 @@ public: /* * Convenience function fr determining if area exists in config */ - static bool areaExistsInConfig(SideTabBarArea area); + static bool areaExistsInConfig(CDockWidgetSideTab::SideTabBarArea area); }; } diff --git a/src/ads_globals.h b/src/ads_globals.h index 2df6459..4748c27 100644 --- a/src/ads_globals.h +++ b/src/ads_globals.h @@ -106,17 +106,6 @@ enum eDragState DraggingFloatingWidget//!< DraggingFloatingWidget }; -/** - * Dock widget side tab bar locations - */ -enum SideTabBarArea -{ - None, - Left, - Right, - Bottom -}; - /** * The different icons used in the UI */ diff --git a/src/stylesheets/focus_highlighting.css b/src/stylesheets/focus_highlighting.css index 912166a..3a2563b 100644 --- a/src/stylesheets/focus_highlighting.css +++ b/src/stylesheets/focus_highlighting.css @@ -26,10 +26,17 @@ ads--CDockWidgetSideTab { background: palette(window); border-color: palette(light); border-style: solid; - border-width: 1px 1px 1px 1px; padding: 0 0px; } +ads--CDockWidgetSideTab[sideTabBarArea="Left"] { + border-width: 0px 0px 0px 3px; +} + +ads--CDockWidgetSideTab[sideTabBarArea="Right"] { + border-width: 0px 3px 0px 0px; +} + ads--CDockWidgetTab[activeTab="true"] { background: qlineargradient(spread : pad, x1 : 0, y1 : 0, x2 : 0, y2 : 0.5, stop : 0 palette(window), stop:1 palette(light));