From 59e93d41d38a933b987f705fdbb6e638d80dcc5f Mon Sep 17 00:00:00 2001 From: apa420 <17131426+apa420@users.noreply.github.com> Date: Tue, 11 Mar 2025 15:16:33 +0000 Subject: [PATCH] feat: Add tab style option (Normal & Combat) (#5858) --- CHANGELOG.md | 1 + src/singletons/Settings.hpp | 9 ++++ src/widgets/helper/NotebookTab.cpp | 54 +++++++++++++++++++---- src/widgets/helper/NotebookTab.hpp | 2 +- src/widgets/settingspages/GeneralPage.cpp | 2 + 5 files changed, 59 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 66bb3dec..cba28c29 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,7 @@ - Minor: The `/watching` channel is now supported on all platforms. (#6031, #6043) - Minor: The font weight of chat messages can now be changed. (#6037) - Minor: Messages from restricted users can now be hidden when in streamer mode. This is enabled by default. (#6042, #6049) +- Minor: Added a tab style option allowing you to make your tabs more compact. (#5858) - Bugfix: Fixed a potential way to escape the Lua Plugin sandbox. (#5846) - Bugfix: Fixed a crash relating to Lua HTTP. (#5800) - Bugfix: Fixed a crash that could occur on Linux and macOS when clicking "Install" from the update prompt. (#5818) diff --git a/src/singletons/Settings.hpp b/src/singletons/Settings.hpp index 9b7b76d3..01f09cc1 100644 --- a/src/singletons/Settings.hpp +++ b/src/singletons/Settings.hpp @@ -92,6 +92,11 @@ enum StreamerModeSetting { DetectStreamingSoftware = 2, }; +enum class TabStyle : std::uint8_t { + Normal, + Compact, +}; + /// Settings which are availlable for reading and writing on the gui thread. // These settings are still accessed concurrently in the code but it is bad practice. class Settings @@ -182,6 +187,10 @@ public: FloatSetting boldScale = {"/appearance/boldScale", 63}; BoolSetting showTabCloseButton = {"/appearance/showTabCloseButton", true}; BoolSetting showTabLive = {"/appearance/showTabLiveButton", true}; + EnumStringSetting tabStyle = { + "/appearance/tabStyle", + TabStyle::Normal, + }; BoolSetting hidePreferencesButton = {"/appearance/hidePreferencesButton", false}; BoolSetting hideUserButton = {"/appearance/hideUserButton", false}; diff --git a/src/widgets/helper/NotebookTab.cpp b/src/widgets/helper/NotebookTab.cpp index 563084d3..1ecd55a5 100644 --- a/src/widgets/helper/NotebookTab.cpp +++ b/src/widgets/helper/NotebookTab.cpp @@ -54,6 +54,30 @@ namespace { break; } } + + float getCompactDivider(TabStyle tabStyle) + { + switch (tabStyle) + { + case TabStyle::Compact: + return 1.5; + case TabStyle::Normal: + default: + return 1.0; + } + } + + float getCompactReducer(TabStyle tabStyle) + { + switch (tabStyle) + { + case TabStyle::Compact: + return 4.0; + case TabStyle::Normal: + default: + return 0.0; + } + } } // namespace NotebookTab::NotebookTab(Notebook *notebook) @@ -67,8 +91,15 @@ NotebookTab::NotebookTab(Notebook *notebook) this->positionChangedAnimation_.setEasingCurve( QEasingCurve(QEasingCurve::InCubic)); - getSettings()->showTabCloseButton.connectSimple( - boost::bind(&NotebookTab::hideTabXChanged, this), + getSettings()->showTabCloseButton.connect( + [this] { + this->tabSizeChanged(); + }, + this->managedConnections_); + getSettings()->tabStyle.connect( + [this] { + this->tabSizeChanged(); + }, this->managedConnections_); getSettings()->showTabLive.connect( [this](auto, auto) { @@ -204,13 +235,16 @@ int NotebookTab::normalTabWidthForHeight(int height) const QFontMetrics metrics = getApp()->getFonts()->getFontMetrics(FontStyle::UiTabs, scale); + float compactDivider = getCompactDivider(getSettings()->tabStyle); if (this->hasXButton()) { - width = (metrics.horizontalAdvance(this->getTitle()) + int(32 * scale)); + width = (metrics.horizontalAdvance(this->getTitle()) + + int(32 / compactDivider * scale)); } else { - width = (metrics.horizontalAdvance(this->getTitle()) + int(16 * scale)); + width = (metrics.horizontalAdvance(this->getTitle()) + + int(16 / compactDivider * scale)); } if (static_cast(height) > 150 * scale) @@ -608,7 +642,7 @@ QRect NotebookTab::getDesiredRect() const return QRect(this->positionAnimationDesiredPoint_, size()); } -void NotebookTab::hideTabXChanged() +void NotebookTab::tabSizeChanged() { this->updateSize(); this->update(); @@ -760,12 +794,15 @@ void NotebookTab::paintEvent(QPaintEvent *) // set the pen color painter.setPen(colors.text); + float compactDivider = getCompactDivider(getSettings()->tabStyle); // set area for text - int rectW = (!getSettings()->showTabCloseButton ? 0 : int(16 * scale)); + int rectW = + (!getSettings()->showTabCloseButton ? 0 + : int(16 * scale / compactDivider)); QRect rect(0, 0, this->width() - rectW, height); // draw text - int offset = int(scale * 8); + int offset = int(scale * 4 / compactDivider); QRect textRect(offset, 0, this->width() - offset - offset, height); translateRectForLocation(textRect, this->tabLocation_, this->selected_ ? -1 : -2); @@ -1044,7 +1081,8 @@ QRect NotebookTab::getXRect() const ? (size / 3) // slightly off true center : (size / 2); // true center - QRect xRect(rect.right() - static_cast(20 * s), + float compactReducer = getCompactReducer(getSettings()->tabStyle); + QRect xRect(rect.right() - static_cast((20 - compactReducer) * s), rect.center().y() - centerAdjustment, size, size); if (this->selected_) diff --git a/src/widgets/helper/NotebookTab.hpp b/src/widgets/helper/NotebookTab.hpp index ae3bfbc2..74c48586 100644 --- a/src/widgets/helper/NotebookTab.hpp +++ b/src/widgets/helper/NotebookTab.hpp @@ -82,7 +82,7 @@ public: void moveAnimated(QPoint targetPos, bool animated = true); QRect getDesiredRect() const; - void hideTabXChanged(); + void tabSizeChanged(); void growWidth(int width); int normalTabWidth() const; diff --git a/src/widgets/settingspages/GeneralPage.cpp b/src/widgets/settingspages/GeneralPage.cpp index 59667eb9..70bee3a0 100644 --- a/src/widgets/settingspages/GeneralPage.cpp +++ b/src/widgets/settingspages/GeneralPage.cpp @@ -279,6 +279,8 @@ void GeneralPage::initLayout(GeneralPageView &layout) }, false, "Choose which tabs are visible in the notebook"); + SettingWidget::dropdown("Tab style", s.tabStyle)->addTo(layout); + SettingWidget::inverseCheckbox("Show message reply context", s.hideReplyContext) ->setTooltip(