Replaced tab bar areas LeftTop, LeftBottom, RightTop, RightBottom with Left and Right to reduce complexity

This commit is contained in:
Uwe Kindler 2022-10-17 11:34:59 +02:00
parent bb630ca605
commit 14312442db
7 changed files with 34 additions and 50 deletions

View File

@ -47,7 +47,7 @@ CMainWindow::CMainWindow(QWidget *parent)
TableDockWidget->resize(250, 150);
TableDockWidget->setMinimumSize(200,150);
TableDockWidget->setDefaultAutoHideDockProportion(0.5);
DockManager->addAutoHideDockWidget(CDockWidgetSideTab::SideTabBarArea::LeftTop, TableDockWidget, CDockWidget::Last);
DockManager->addAutoHideDockWidget(CDockWidgetSideTab::SideTabBarArea::Left, TableDockWidget, CDockWidget::Last);
ui->menuView->addAction(TableDockWidget->toggleViewAction());
table = new QTableWidget();
@ -58,7 +58,7 @@ CMainWindow::CMainWindow(QWidget *parent)
TableDockWidget->setMinimumSizeHintMode(CDockWidget::MinimumSizeHintFromDockWidget);
TableDockWidget->resize(250, 150);
TableDockWidget->setMinimumSize(200,150);
DockManager->addAutoHideDockWidget(CDockWidgetSideTab::SideTabBarArea::LeftTop, TableDockWidget, CDockWidget::Last);
DockManager->addAutoHideDockWidget(CDockWidgetSideTab::SideTabBarArea::Left, TableDockWidget, CDockWidget::Last);
ui->menuView->addAction(TableDockWidget->toggleViewAction());
QTableWidget* propertiesTable = new QTableWidget();

View File

@ -66,13 +66,11 @@ struct AutoHideDockContainerPrivate
{
switch (area)
{
case CDockWidgetSideTab::LeftBottom:
case CDockWidgetSideTab::LeftTop:
case CDockWidgetSideTab::Left:
{
return LeftDockWidgetArea;
}
case CDockWidgetSideTab::RightBottom:
case CDockWidgetSideTab::RightTop:
case CDockWidgetSideTab::Right:
{
return RightDockWidgetArea;
}
@ -96,13 +94,11 @@ struct AutoHideDockContainerPrivate
{
switch (SideTabBarArea)
{
case CDockWidgetSideTab::LeftTop:
case CDockWidgetSideTab::LeftBottom:
case CDockWidgetSideTab::Left:
{
return QPoint(1, _this->height() / 2);
}
case CDockWidgetSideTab::RightTop:
case CDockWidgetSideTab::RightBottom:
case CDockWidgetSideTab::Right:
{
return QPoint(_this->width() - 1, _this->height() / 2);
}
@ -139,7 +135,7 @@ struct AutoHideDockContainerPrivate
}
auto offset = 0;
if (SideTabBarArea == CDockWidgetSideTab::SideTabBarArea::RightTop || SideTabBarArea == CDockWidgetSideTab::SideTabBarArea::RightBottom)
if (SideTabBarArea == CDockWidgetSideTab::SideTabBarArea::Right)
{
offset = handleSize;
}
@ -189,15 +185,13 @@ CAutoHideDockContainer::CAutoHideDockContainer(CDockManager* DockManager, CDockW
addWidget(emptyWidget);
break;
}
case CDockWidgetSideTab::LeftBottom:
case CDockWidgetSideTab::LeftTop:
case CDockWidgetSideTab::Left:
{
addWidget(d->DockArea);
addWidget(emptyWidget);
break;
}
case CDockWidgetSideTab::RightBottom:
case CDockWidgetSideTab::RightTop:
case CDockWidgetSideTab::Right:
{
addWidget(emptyWidget);
addWidget(d->DockArea);
@ -305,14 +299,12 @@ void CAutoHideDockContainer::setDockSizeProportion(float SplitterProportion)
const auto remainingSize = INT_MAX - dockSize;
switch (d->SideTabBarArea)
{
case CDockWidgetSideTab::LeftBottom:
case CDockWidgetSideTab::LeftTop:
case CDockWidgetSideTab::Left:
{
setSizes({ dockSize, remainingSize });
break;
}
case CDockWidgetSideTab::RightBottom:
case CDockWidgetSideTab::RightTop:
case CDockWidgetSideTab::Right:
case CDockWidgetSideTab::Bottom:
{
setSizes({ remainingSize, dockSize });
@ -467,13 +459,11 @@ bool CAutoHideDockContainer::areaExistsInConfig(CDockWidgetSideTab::SideTabBarAr
{
switch (area)
{
case CDockWidgetSideTab::LeftBottom:
case CDockWidgetSideTab::LeftTop:
case CDockWidgetSideTab::Left:
{
return CDockManager::testConfigFlag(CDockManager::DockContainerHasLeftSideBar);
}
case CDockWidgetSideTab::RightBottom:
case CDockWidgetSideTab::RightTop:
case CDockWidgetSideTab::Right:
{
return CDockManager::testConfigFlag(CDockManager::DockContainerHasRightSideBar);
}

View File

@ -1099,7 +1099,7 @@ void CDockAreaWidget::closeArea()
//============================================================================
void CDockAreaWidget::toggleAutoHideArea(bool Enable)
{
const auto area = dockContainer()->getDockAreaPosition(this);
const auto area = dockContainer()->calculateSideTabBarArea(this);
const auto DockWidget = currentDockWidget();
if (Enable == isAutoHide())
{

View File

@ -1520,8 +1520,9 @@ CAutoHideDockContainer* CDockContainerWidget::createAndInitializeAutoHideDockWid
return dockContainer;
}
//============================================================================
CDockWidgetSideTab::SideTabBarArea CDockContainerWidget::getDockAreaPosition(CDockAreaWidget* DockAreaWidget)
CDockWidgetSideTab::SideTabBarArea CDockContainerWidget::calculateSideTabBarArea(CDockAreaWidget* DockAreaWidget)
{
// 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
@ -1542,39 +1543,39 @@ CDockWidgetSideTab::SideTabBarArea CDockContainerWidget::getDockAreaPosition(CDo
// Then handle left and right
const auto dockWidgetCenter = DockAreaWidget->mapToGlobal(dockWidgetFrameGeometry.center());
const auto calculatedPosition = dockWidgetCenter.x() <= splitterCenter.x() ? CDockWidgetSideTab::LeftTop : CDockWidgetSideTab::RightTop;
if (calculatedPosition == CDockWidgetSideTab::RightTop)
const auto calculatedPosition = dockWidgetCenter.x() <= splitterCenter.x() ? CDockWidgetSideTab::Left : CDockWidgetSideTab::Right;
if (calculatedPosition == CDockWidgetSideTab::Right)
{
if (CDockManager::testConfigFlag(CDockManager::DockContainerHasRightSideBar))
{
return CDockWidgetSideTab::RightTop;
return CDockWidgetSideTab::Right;
}
if (CDockManager::testConfigFlag(CDockManager::DockContainerHasLeftSideBar))
{
return CDockWidgetSideTab::LeftTop;
return CDockWidgetSideTab::Left;
}
return CDockWidgetSideTab::Bottom;
}
if (calculatedPosition == CDockWidgetSideTab::LeftTop)
if (calculatedPosition == CDockWidgetSideTab::Left)
{
if (CDockManager::testConfigFlag(CDockManager::DockContainerHasLeftSideBar))
{
return CDockWidgetSideTab::LeftTop;
return CDockWidgetSideTab::Left;
}
if (CDockManager::testConfigFlag(CDockManager::DockContainerHasRightSideBar))
{
return CDockWidgetSideTab::RightTop;
return CDockWidgetSideTab::Right;
}
return CDockWidgetSideTab::Bottom;
}
Q_ASSERT_X(false, "CDockContainerWidget::getDockAreaPosition", "Unhandled branch. All positions should be accounted for.");
return CDockWidgetSideTab::LeftTop;
return CDockWidgetSideTab::Left;
}
@ -2055,22 +2056,18 @@ void CDockContainerWidget::createSideTabBarWidgets()
if (CDockManager::testConfigFlag(CDockManager::DockContainerHasLeftSideBar))
{
auto leftLayout = new QVBoxLayout();
d->SideTabBarWidgets[CDockWidgetSideTab::LeftTop] = new CSideTabBar(this, Qt::Vertical);
leftLayout->addWidget(d->SideTabBarWidgets[CDockWidgetSideTab::LeftTop]);
d->SideTabBarWidgets[CDockWidgetSideTab::Left] = new CSideTabBar(this, Qt::Vertical);
leftLayout->addWidget(d->SideTabBarWidgets[CDockWidgetSideTab::Left]);
leftLayout->addStretch(1);
d->SideTabBarWidgets[CDockWidgetSideTab::LeftBottom] = new CSideTabBar(this, Qt::Vertical);
leftLayout->addWidget(d->SideTabBarWidgets[CDockWidgetSideTab::LeftBottom]);
d->Layout->addLayout(leftLayout, 1, 0);
}
if (CDockManager::testConfigFlag(CDockManager::DockContainerHasRightSideBar))
{
auto rightLayout = new QVBoxLayout();
d->SideTabBarWidgets[CDockWidgetSideTab::RightTop] = new CSideTabBar(this, Qt::Vertical);
rightLayout->addWidget(d->SideTabBarWidgets[CDockWidgetSideTab::RightTop]);
d->SideTabBarWidgets[CDockWidgetSideTab::Right] = new CSideTabBar(this, Qt::Vertical);
rightLayout->addWidget(d->SideTabBarWidgets[CDockWidgetSideTab::Right]);
rightLayout->addStretch(1);
d->SideTabBarWidgets[CDockWidgetSideTab::RightBottom] = new CSideTabBar(this, Qt::Vertical);
rightLayout->addWidget(d->SideTabBarWidgets[CDockWidgetSideTab::RightBottom]);
d->Layout->addLayout(rightLayout, 1, 2);
}

View File

@ -220,7 +220,7 @@ public:
/**
* Get's the auto hide dock side tab bar area based on the dock area widget position
*/
CDockWidgetSideTab::SideTabBarArea getDockAreaPosition(CDockAreaWidget* DockAreaWidget);
CDockWidgetSideTab::SideTabBarArea calculateSideTabBarArea(CDockAreaWidget* DockAreaWidget);
/**
* Removes dockwidget

View File

@ -216,7 +216,7 @@ CDockWidgetSideTab::SideTabBarArea CDockWidgetSideTab::sideTabBarArea() const
return dockAreaWidget->autoHideDockContainer()->sideTabBarArea();
}
return LeftTop;
return Left;
}
@ -289,14 +289,14 @@ void CDockWidgetSideTab::updateOrientationAndSpacing(SideTabBarArea area)
QFontMetrics fm(d->TitleLabel->font());
int Spacing = qRound(fm.height() / 2.0);
if (CDockManager::testConfigFlag(CDockManager::LeftSideBarPrioritizeIconOnly) && (area == LeftTop || area == LeftBottom))
if (CDockManager::testConfigFlag(CDockManager::LeftSideBarPrioritizeIconOnly) && area == Left)
{
d->TitleLabel->hide();
d->TitleLayout->setContentsMargins(0, 0, 0, 0);
d->IconLabel->setContentsMargins(Spacing / 2, Spacing / 2, Spacing / 2, Spacing / 2);
return;
}
if (CDockManager::testConfigFlag(CDockManager::RightSideBarPrioritizeIconOnly) && (area == RightTop || area == RightBottom))
if (CDockManager::testConfigFlag(CDockManager::RightSideBarPrioritizeIconOnly) && area == Right)
{
d->TitleLabel->hide();
d->TitleLayout->setContentsMargins(0, 0, 0, 0);

View File

@ -79,13 +79,10 @@ public:
enum SideTabBarArea
{
Top,
LeftTop,
LeftBottom,
RightTop,
RightBottom,
Left,
Right,
Bottom
};
Q_ENUM(SideTabBarArea)
/**