Add left right styling to the dock widget side tab

This commit is contained in:
Syarif Fakhri 2022-09-08 11:30:56 +08:00
parent 8bfb98ea20
commit 0087a1b360
12 changed files with 99 additions and 64 deletions

View File

@ -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)
{

View File

@ -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;

View File

@ -138,7 +138,7 @@ public:
unsigned int zOrderIndex = 0;
QList<CDockAreaWidget*> DockAreas;
QList<COverlayDockContainer*> OverlayWidgets;
QMap<SideTabBarArea, CSideTabBar*> SideTabBarWidgets;
QMap<CDockWidgetSideTab::SideTabBarArea, CSideTabBar*> 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<SideTabBarArea>(sideTabAreaValue.toInt(&Ok));
auto sideTabBarArea = static_cast<CDockWidgetSideTab::SideTabBarArea>(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];
}

View File

@ -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:
/**

View File

@ -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);

View File

@ -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

View File

@ -32,9 +32,11 @@
#include <QBoxLayout>
#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;
}
}

View File

@ -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();

View File

@ -52,7 +52,7 @@ struct OverlayDockContainerPrivate
CDockWidget* DockWidget{nullptr};
QPointer<CDockManager> 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;
}

View File

@ -31,6 +31,8 @@
//============================================================================
#include "ads_globals.h"
#include "DockWidgetSideTab.h"
#include <QFrame>
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);
};
}

View File

@ -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
*/

View File

@ -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));