Resize tabs when width is small

This commit is contained in:
Adam Honse
2026-03-24 07:33:45 -05:00
parent b422f1b3ce
commit f710fb7709
5 changed files with 107 additions and 42 deletions

View File

@@ -33,6 +33,7 @@
#include <QStyleFactory>
#include <QKeyEvent>
#include <QCheckBox>
#include <QScreen>
#include <QSpinBox>
#include <string>
@@ -563,6 +564,41 @@ void OpenRGBDialog::keyPressEvent(QKeyEvent *event)
}
}
void OpenRGBDialog::resizeEvent(QResizeEvent *event)
{
QScreen* screen = QGuiApplication::primaryScreen();
qreal scale = screen->devicePixelRatio();
bool compact_mode = (event->size().width() < (700 * scale));
for(int i = 0; i < ui->DevicesTabBar->count(); i++)
{
((TabLabel *)ui->DevicesTabBar->tabBar()->tabButton(i, QTabBar::LeftSide))->blockSignals(true);
((TabLabel *)ui->DevicesTabBar->tabBar()->tabButton(i, QTabBar::LeftSide))->SetTextHidden(compact_mode);
((TabLabel *)ui->DevicesTabBar->tabBar()->tabButton(i, QTabBar::LeftSide))->blockSignals(false);
}
for(int i = 0; i < ui->InformationTabBar->count(); i++)
{
((TabLabel *)ui->InformationTabBar->tabBar()->tabButton(i, QTabBar::LeftSide))->blockSignals(true);
((TabLabel *)ui->InformationTabBar->tabBar()->tabButton(i, QTabBar::LeftSide))->SetTextHidden(compact_mode);
((TabLabel *)ui->InformationTabBar->tabBar()->tabButton(i, QTabBar::LeftSide))->blockSignals(false);
}
for(int i = 0; i < ui->SettingsTabBar->count(); i++)
{
((TabLabel *)ui->SettingsTabBar->tabBar()->tabButton(i, QTabBar::LeftSide))->blockSignals(true);
((TabLabel *)ui->SettingsTabBar->tabBar()->tabButton(i, QTabBar::LeftSide))->SetTextHidden(compact_mode);
((TabLabel *)ui->SettingsTabBar->tabBar()->tabButton(i, QTabBar::LeftSide))->blockSignals(false);
}
ui->DevicesTabBar->tabBar()->setIconSize(ui->DevicesTabBar->tabBar()->iconSize());
ui->InformationTabBar->tabBar()->setIconSize(ui->InformationTabBar->tabBar()->iconSize());
ui->SettingsTabBar->tabBar()->setIconSize(ui->SettingsTabBar->tabBar()->iconSize());
QWidget::resizeEvent(event);
}
void OpenRGBDialog::AddPluginsPage()
{
/*-----------------------------------------------------*\

View File

@@ -67,6 +67,7 @@ signals:
public slots:
void changeEvent(QEvent *event) override;
void resizeEvent(QResizeEvent* event) override;
void SetTrayIcon(bool tray_icon);
void handleAboutToQuit();

View File

@@ -18,14 +18,31 @@ TabLabel::TabLabel(int icon, QString name, char* original, char* context) :
{
ui->setupUi(this);
/*-----------------------------------------------------*\
| Store initial widths for icon and name |
\*-----------------------------------------------------*/
icon_initial_width = ui->icon->width();
name_initial_width = ui->name->width();
/*-----------------------------------------------------*\
| Initialize icon font |
\*-----------------------------------------------------*/
QFont font = OpenRGBFont::GetFont();
font.setPointSize(18);
/*-----------------------------------------------------*\
| Set icon |
\*-----------------------------------------------------*/
ui->icon->setFont(font);
ui->icon->setText(OpenRGBFont::icon(icon));
/*-----------------------------------------------------*\
| Set name |
\*-----------------------------------------------------*/
ui->name->setText(name);
SetTextHidden(false);
label = original;
ctxt = context;
}
@@ -35,6 +52,22 @@ TabLabel::~TabLabel()
delete ui;
}
void TabLabel::SetTextHidden(bool hidden)
{
if(hidden)
{
ui->name->setFixedWidth(0);
setFixedWidth(ui->icon->width());
}
else
{
ui->name->setFixedWidth(name_initial_width);
setFixedWidth(ui->icon->width() + ui->name->width());
}
ui->name->setHidden(hidden);
}
void TabLabel::changeEvent(QEvent *event)
{
if(event->type() == QEvent::LanguageChange)

View File

@@ -24,11 +24,17 @@ public:
TabLabel(int icon, QString name, char* original, char* context);
~TabLabel();
void SetTextHidden(bool hidden);
private:
Ui::TabLabel *ui;
char* label;
char* ctxt;
int icon_initial_width;
int name_initial_width;
private slots:
void changeEvent(QEvent *event);
};

View File

@@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>222</width>
<height>16</height>
<width>0</width>
<height>24</height>
</rect>
</property>
<property name="sizePolicy">
@@ -21,7 +21,7 @@
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="sizeConstraint">
<enum>QLayout::SetMinAndMaxSize</enum>
<enum>QLayout::SizeConstraint::SetMinAndMaxSize</enum>
</property>
<property name="topMargin">
<number>0</number>
@@ -29,45 +29,40 @@
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>10</width>
<height>0</height>
</size>
</property>
</spacer>
</item>
<property name="leftMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<item>
<widget class="QLabel" name="icon">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>57</width>
<height>24</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>57</width>
<height>24</height>
</size>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>10</width>
<height>0</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="name">
<property name="sizePolicy">
@@ -78,16 +73,10 @@
</property>
<property name="minimumSize">
<size>
<width>150</width>
<width>165</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>150</width>
<height>16777215</height>
</size>
</property>
<property name="text">
<string>device name</string>
</property>