From f9b62234b0615dc720953d167a12b9f1445d628b Mon Sep 17 00:00:00 2001 From: Syarif Fakhri Date: Fri, 14 Oct 2022 21:13:32 +0800 Subject: [PATCH] Add top area --- src/AutoHideDockContainer.cpp | 25 +++++++++++++++++- src/DockContainerWidget.cpp | 31 +++++++++++++++-------- src/DockManager.h | 15 ++++++----- src/DockWidgetSideTab.cpp | 11 ++++++-- src/DockWidgetSideTab.h | 1 + src/stylesheets/focus_highlighting.css | 35 +++++++++++++++++++------- 6 files changed, 90 insertions(+), 28 deletions(-) diff --git a/src/AutoHideDockContainer.cpp b/src/AutoHideDockContainer.cpp index 408d383..0d6f700 100644 --- a/src/AutoHideDockContainer.cpp +++ b/src/AutoHideDockContainer.cpp @@ -80,6 +80,10 @@ struct AutoHideDockContainerPrivate { return BottomDockWidgetArea; } + case CDockWidgetSideTab::Top: + { + return TopDockWidgetArea; + } } return LeftDockWidgetArea; @@ -106,6 +110,10 @@ struct AutoHideDockContainerPrivate { return QPoint(_this->width() / 2, _this->height() - 1); } + case CDockWidgetSideTab::Top: + { + return QPoint(_this->width() / 2, 1); + } } return QPoint(); @@ -125,6 +133,11 @@ struct AutoHideDockContainerPrivate return QRect(QPoint(topLeft.x(), topLeft.y() - handleSize), QSize(rect.size().width(), rect.size().height() + handleSize)); } + if (SideTabBarArea == CDockWidgetSideTab::Top) + { + return QRect(QPoint(topLeft.x(), topLeft.y()), QSize(rect.size().width(), rect.size().height() + handleSize)); + } + auto offset = 0; if (SideTabBarArea == CDockWidgetSideTab::SideTabBarArea::RightTop || SideTabBarArea == CDockWidgetSideTab::SideTabBarArea::RightBottom) { @@ -150,7 +163,7 @@ CDockContainerWidget* CAutoHideDockContainer::parentContainer() const //============================================================================ CAutoHideDockContainer::CAutoHideDockContainer(CDockManager* DockManager, CDockWidgetSideTab::SideTabBarArea area, CDockContainerWidget* parent) : - QSplitter(area == CDockWidgetSideTab::Bottom ? Qt::Orientation::Vertical : Qt::Orientation::Horizontal, parent), + QSplitter((area == CDockWidgetSideTab::Bottom || area == CDockWidgetSideTab::Top) ? Qt::Orientation::Vertical : Qt::Orientation::Horizontal, parent), d(new AutoHideDockContainerPrivate(this)) { d->DockManager = DockManager; @@ -170,6 +183,12 @@ CAutoHideDockContainer::CAutoHideDockContainer(CDockManager* DockManager, CDockW switch (area) { + case CDockWidgetSideTab::Top: + { + addWidget(d->DockArea); + addWidget(emptyWidget); + break; + } case CDockWidgetSideTab::LeftBottom: case CDockWidgetSideTab::LeftTop: { @@ -469,6 +488,10 @@ bool CAutoHideDockContainer::areaExistsInConfig(CDockWidgetSideTab::SideTabBarAr { return CDockManager::testConfigFlag(CDockManager::DockContainerHasBottomSideBar); } + case CDockWidgetSideTab::Top: + { + return CDockManager::testConfigFlag(CDockManager::DockContainerHasTopSideBar); + } } return true; diff --git a/src/DockContainerWidget.cpp b/src/DockContainerWidget.cpp index eccfec8..77b4304 100644 --- a/src/DockContainerWidget.cpp +++ b/src/DockContainerWidget.cpp @@ -1440,7 +1440,7 @@ CDockContainerWidget::CDockContainerWidget(CDockManager* DockManager, QWidget *p d->Layout->setContentsMargins(0, 0, 0, 0); d->Layout->setSpacing(0); d->Layout->setColumnStretch(1, 1); - d->Layout->setRowStretch(0, 1); + d->Layout->setRowStretch(1, 1); setLayout(d->Layout); // The function d->newSplitter() accesses the config flags from dock @@ -1523,16 +1523,21 @@ CAutoHideDockContainer* CDockContainerWidget::createAndInitializeAutoHideDockWid //============================================================================ CDockWidgetSideTab::SideTabBarArea CDockContainerWidget::getDockAreaPosition(CDockAreaWidget* DockAreaWidget) { - // Handle bottom case + // Handle bottom case and top case // It's bottom if the width is wider than the height, and if it's below 50% of the window const auto dockWidgetFrameGeometry = DockAreaWidget->frameGeometry(); const auto splitterCenter = rootSplitter()->mapToGlobal(rootSplitter()->frameGeometry().center()); - if (dockWidgetFrameGeometry.width() > dockWidgetFrameGeometry.height() - && DockAreaWidget->mapToGlobal(dockWidgetFrameGeometry.topLeft()).y() > splitterCenter.y() - && CDockManager::testConfigFlag(CDockManager::DockContainerHasBottomSideBar)) + if (dockWidgetFrameGeometry.width() > dockWidgetFrameGeometry.height()) { - return CDockWidgetSideTab::Bottom; + if (DockAreaWidget->mapToGlobal(dockWidgetFrameGeometry.topLeft()).y() > splitterCenter.y() && CDockManager::testConfigFlag(CDockManager::DockContainerHasBottomSideBar)) + { + return CDockWidgetSideTab::Bottom; + } + if (CDockManager::testConfigFlag(CDockManager::DockContainerHasTopSideBar)) + { + return CDockWidgetSideTab::Top; + } } // Then handle left and right @@ -2040,7 +2045,7 @@ void CDockContainerWidget::createRootSplitter() return; } d->RootSplitter = d->newSplitter(Qt::Horizontal); - d->Layout->addWidget(d->RootSplitter, 0, 1); // Add it to the center - the 0 and 2 indexes are used for the SideTabBar widgets + d->Layout->addWidget(d->RootSplitter, 1, 1); // Add it to the center - the 0 and 2 indexes are used for the SideTabBar widgets } @@ -2055,7 +2060,7 @@ void CDockContainerWidget::createSideTabBarWidgets() leftLayout->addStretch(1); d->SideTabBarWidgets[CDockWidgetSideTab::LeftBottom] = new CSideTabBar(this, Qt::Vertical); leftLayout->addWidget(d->SideTabBarWidgets[CDockWidgetSideTab::LeftBottom]); - d->Layout->addLayout(leftLayout, 0, 0); + d->Layout->addLayout(leftLayout, 1, 0); } if (CDockManager::testConfigFlag(CDockManager::DockContainerHasRightSideBar)) @@ -2066,13 +2071,19 @@ void CDockContainerWidget::createSideTabBarWidgets() rightLayout->addStretch(1); d->SideTabBarWidgets[CDockWidgetSideTab::RightBottom] = new CSideTabBar(this, Qt::Vertical); rightLayout->addWidget(d->SideTabBarWidgets[CDockWidgetSideTab::RightBottom]); - d->Layout->addLayout(rightLayout, 0, 2); + 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], 1, 1); + 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 e1f23c0..e9599cc 100644 --- a/src/DockManager.h +++ b/src/DockManager.h @@ -229,15 +229,18 @@ public: DockContainerHasLeftSideBar = 0x01, //!< If the flag is set left side bar will prioritize showing icons only over text DockContainerHasRightSideBar = 0x02, //!< If the flag is set right side bar will prioritize showing icons only over text DockContainerHasBottomSideBar = 0x04, //!< If the flag is set right side bar will prioritize showing icons only over text - DockAreaHasAutoHideButton = 0x08, //!< If the flag is set each dock area has a auto hide menu button - LeftSideBarPrioritizeIconOnly = 0x10, //!< If the flag is set each container will have a left side bar - RightSideBarPrioritizeIconOnly = 0x20, //!< If the flag is set each container will have a right side bar - BottomSideBarPrioritizeIconOnly = 0x40, //!< If the flag is set bottom side bar will prioritize showing icons only over text - AutoHideDockAreaHasTitle = 0x80, //!< If the flag is set overlay dock area title bar will show the window title + DockContainerHasTopSideBar = 0x08, //!< If the flag is set right side bar will prioritize showing icons only over text + DockAreaHasAutoHideButton = 0x10, //!< If the flag is set each dock area has a auto hide menu button + LeftSideBarPrioritizeIconOnly = 0x20, //!< If the flag is set each container will have a left side bar + RightSideBarPrioritizeIconOnly = 0x40, //!< If the flag is set each container will have a right side bar + BottomSideBarPrioritizeIconOnly = 0x80, //!< If the flag is set bottom side bar will prioritize showing icons only over text + TopSideBarPrioritizeIconOnly = 0x100, //!< If the flag is set bottom 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 - DefaultAutoHideConfig = DockContainerHasLeftSideBar + DefaultAutoHideConfig = DockContainerHasLeftSideBar | BottomSideBarPrioritizeIconOnly | TopSideBarPrioritizeIconOnly | DockContainerHasRightSideBar | DockContainerHasBottomSideBar + | DockContainerHasTopSideBar | DockAreaHasAutoHideButton | AutoHideDockAreaHasTitle, ///< the default configuration for left and right side bars }; diff --git a/src/DockWidgetSideTab.cpp b/src/DockWidgetSideTab.cpp index 6307707..1ee9a7d 100644 --- a/src/DockWidgetSideTab.cpp +++ b/src/DockWidgetSideTab.cpp @@ -106,7 +106,7 @@ struct DockWidgetSideTabPrivate } else if (Orientation == Qt::Horizontal) { - TitleLayout->setContentsMargins(Spacing / 2, Spacing / 2, Spacing, Spacing); + TitleLayout->setContentsMargins(Spacing / 2, Spacing, Spacing, Spacing); if (IconLabel) { IconLabel->setContentsMargins(Spacing / 2, Spacing / 2, 0, Spacing / 2); @@ -276,7 +276,7 @@ void CDockWidgetSideTab::setOrientation(Qt::Orientation Orientation) //============================================================================ void CDockWidgetSideTab::updateOrientationAndSpacing(SideTabBarArea area) { - setOrientation(area == Bottom ? Qt::Horizontal : Qt::Vertical); + setOrientation((area == Bottom || area == Top) ? Qt::Horizontal : Qt::Vertical); d->updateContentsMargins(); @@ -304,6 +304,13 @@ void CDockWidgetSideTab::updateOrientationAndSpacing(SideTabBarArea area) return; } if (CDockManager::testConfigFlag(CDockManager::BottomSideBarPrioritizeIconOnly) && area == Bottom) + { + d->TitleLabel->hide(); + d->TitleLayout->setContentsMargins(0, 0, 0, 0); + d->IconLabel->setContentsMargins(Spacing / 2, Spacing / 2, Spacing / 2, Spacing); + return; + } + if (CDockManager::testConfigFlag(CDockManager::TopSideBarPrioritizeIconOnly) && area == Top) { d->TitleLabel->hide(); d->TitleLayout->setContentsMargins(0, 0, 0, 0); diff --git a/src/DockWidgetSideTab.h b/src/DockWidgetSideTab.h index 42ebdca..3a6e716 100644 --- a/src/DockWidgetSideTab.h +++ b/src/DockWidgetSideTab.h @@ -77,6 +77,7 @@ public: */ enum SideTabBarArea { + Top, LeftTop, LeftBottom, RightTop, diff --git a/src/stylesheets/focus_highlighting.css b/src/stylesheets/focus_highlighting.css index 672783c..1a6fe77 100644 --- a/src/stylesheets/focus_highlighting.css +++ b/src/stylesheets/focus_highlighting.css @@ -27,17 +27,22 @@ ads--CDockWidgetSideTab { qproperty-iconSize: 16px 16px;/* this is optional in case you would like to change icon size*/ } -ads--CDockWidgetSideTab[sideTabBarArea="0"],[sideTabBarArea="1"] { +ads--CDockWidgetSideTab[sideTabBarArea="0"] { + border-top: 3px solid grey; + border-right: 1px solid white; +} + +ads--CDockWidgetSideTab[sideTabBarArea="1"],[sideTabBarArea="2"] { border-left: 3px solid grey; border-bottom: 1px solid white; } -ads--CDockWidgetSideTab[sideTabBarArea="2"],[sideTabBarArea="3"] { +ads--CDockWidgetSideTab[sideTabBarArea="3"],[sideTabBarArea="4"] { border-right: 3px solid grey; border-bottom: 1px solid white; } -ads--CDockWidgetSideTab[sideTabBarArea="4"] { +ads--CDockWidgetSideTab[sideTabBarArea="5"] { border-bottom: 3px solid grey; border-right: 1px solid white; } @@ -120,27 +125,39 @@ ads--CDockSplitter::handle { } /* Focus related styling */ -ads--CDockWidgetSideTab:hover[sideTabBarArea="0"],:hover[sideTabBarArea="1"] { +ads--CDockWidgetSideTab:hover[sideTabBarArea="0"] { + border-top: 3px solid palette(highlight); +} + +ads--CDockWidgetSideTab:hover[sideTabBarArea="1"],:hover[sideTabBarArea="2"] { border-left: 3px solid palette(highlight); } -ads--CDockWidgetSideTab:hover[sideTabBarArea="2"],:hover[sideTabBarArea="3"] { +ads--CDockWidgetSideTab:hover[sideTabBarArea="3"],:hover[sideTabBarArea="4"] { border-right: 3px solid palette(highlight); } -ads--CDockWidgetSideTab:hover[sideTabBarArea="4"] { +ads--CDockWidgetSideTab:hover[sideTabBarArea="5"] { border-bottom: 3px solid palette(highlight); } -ads--CDockWidgetSideTab[sideTabBarArea="0"][focused="true"],[sideTabBarArea="1"][focused="true"] { +ads--CDockWidgetSideTab:hover[sideTabBarArea="0"][focused="true"] { + border-top: 3px solid palette(highlight); +} + +ads--CDockWidgetSideTab[sideTabBarArea="0"][focused="true"] { + border-top: 3px solid palette(highlight); +} + +ads--CDockWidgetSideTab[sideTabBarArea="1"][focused="true"],[sideTabBarArea="2"][focused="true"] { border-left: 3px solid palette(highlight); } -ads--CDockWidgetSideTab[sideTabBarArea="2"][focused="true"],[sideTabBarArea="3"][focused="true"] { +ads--CDockWidgetSideTab[sideTabBarArea="3"][focused="true"],[sideTabBarArea="4"][focused="true"] { border-right: 3px solid palette(highlight); } -ads--CDockWidgetSideTab[sideTabBarArea="4"][focused="true"] { +ads--CDockWidgetSideTab[sideTabBarArea="5"][focused="true"] { border-bottom: 3px solid palette(highlight); }