Gui: Display workbench icon in the middle for icon-only

It ensures that for icon-only style it is displayed in the middle and
empty text is not accounted while calculating tab size hint. Custom
styles may need to target `QTabBar[style="icon-only"]` to apply specific
fixes like disabling padding.

Fixes: #14282
This commit is contained in:
Kacper Donat
2024-06-09 20:18:15 +02:00
committed by Chris Hennes
parent eb90d295aa
commit 8d1ca9de35
2 changed files with 75 additions and 12 deletions

View File

@@ -102,7 +102,6 @@ void WorkbenchComboBox::refreshList(QList<QAction*> actionList)
}
}
WorkbenchTabWidget::WorkbenchTabWidget(WorkbenchGroup* aGroup, QWidget* parent)
: QWidget(parent)
, wbActionGroup(aGroup)
@@ -112,7 +111,7 @@ WorkbenchTabWidget::WorkbenchTabWidget(WorkbenchGroup* aGroup, QWidget* parent)
setWhatsThis(aGroup->action()->whatsThis());
setObjectName(QString::fromLatin1("WbTabBar"));
tabBar = new QTabBar(this);
tabBar = new WbTabBar(this);
moreButton = new QToolButton(this);
layout = new QBoxLayout(QBoxLayout::LeftToRight, this);
@@ -205,6 +204,12 @@ int WorkbenchTabWidget::tabIndexForWorkbenchActivateAction(QAction* workbenchAct
return actionToTabIndex.at(workbenchActivateAction);
}
WorkbenchItemStyle Gui::WorkbenchTabWidget::itemStyle() const
{
ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Workbenches");
return static_cast<WorkbenchItemStyle>(hGrp->GetInt("WorkbenchSelectorItem", 0));
}
void WorkbenchTabWidget::updateLayout()
{
if (!parentWidget()) {
@@ -293,6 +298,8 @@ void WorkbenchTabWidget::updateWorkbenchList()
return;
}
tabBar->setItemStyle(itemStyle());
// As clearing and adding tabs can cause changing current tab in QTabBar.
// This in turn will cause workbench to change, so we need to prevent
// processing of such events until the QTabBar is fully prepared.
@@ -320,8 +327,7 @@ void WorkbenchTabWidget::updateWorkbenchList()
int WorkbenchTabWidget::addWorkbenchTab(QAction* action, int tabIndex)
{
ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Workbenches");
auto itemStyle = static_cast<WorkbenchItemStyle>(hGrp->GetInt("WorkbenchSelectorItem", 0));
auto itemStyle = this->itemStyle();
// if tabIndex is negative we assume that tab must be placed at the end of tabBar (default behavior)
if (tabIndex < 0) {
@@ -422,5 +428,3 @@ void WorkbenchTabWidget::adjustSize()
parentWidget()->adjustSize();
}
#include "moc_WorkbenchSelector.cpp"