From 717f3298f5c7b352bbd9090dd96005d0ea849198 Mon Sep 17 00:00:00 2001 From: Feng <59535397+Obertura777@users.noreply.github.com> Date: Sun, 28 Sep 2025 09:46:11 -0400 Subject: [PATCH] Refactor font update logic in SplitInput (#6473) --- src/widgets/splits/SplitInput.cpp | 37 ++++++++++++++++--------------- src/widgets/splits/SplitInput.hpp | 2 ++ 2 files changed, 21 insertions(+), 18 deletions(-) diff --git a/src/widgets/splits/SplitInput.cpp b/src/widgets/splits/SplitInput.cpp index 735f2a16..d0869279 100644 --- a/src/widgets/splits/SplitInput.cpp +++ b/src/widgets/splits/SplitInput.cpp @@ -213,15 +213,10 @@ void SplitInput::initLayout() QObject::connect(this->ui_.textEdit, &QTextEdit::textChanged, this, &SplitInput::onTextChanged); - this->managedConnections_.managedConnect( - app->getFonts()->fontChanged, [=, this]() { - this->ui_.textEdit->setFont( - app->getFonts()->getFont(FontStyle::ChatMedium, this->scale())); - this->ui_.textEditLength->setFont(app->getFonts()->getFont( - FontStyle::TimestampMedium, this->scale())); - this->ui_.replyLabel->setFont(app->getFonts()->getFont( - FontStyle::ChatMediumBold, this->scale())); - }); + this->managedConnections_.managedConnect(app->getFonts()->fontChanged, + [this] { + this->updateFonts(); + }); // open emote popup QObject::connect(this->ui_.emoteButton, &Button::leftClicked, [this] { @@ -277,15 +272,7 @@ void SplitInput::scaleChangedEvent(float scale) this->ui_.vbox->setSpacing(this->marginForTheme()); } } - this->ui_.textEdit->setFont( - app->getFonts()->getFont(FontStyle::ChatMedium, scale)); - - // NOTE: We're using TimestampMedium here to get a font that uses the tnum font feature, - // meaning numbers get equal width & don't bounce around while the user is typing. - this->ui_.textEditLength->setFont( - app->getFonts()->getFont(FontStyle::TimestampMedium, scale)); - this->ui_.replyLabel->setFont( - app->getFonts()->getFont(FontStyle::ChatMediumBold, scale)); + this->updateFonts(); } void SplitInput::themeChangedEvent() @@ -1339,4 +1326,18 @@ void SplitInput::setBackgroundColor(QColor newColor) this->updateTextEditPalette(); } +void SplitInput::updateFonts() +{ + auto *app = getApp(); + this->ui_.textEdit->setFont( + app->getFonts()->getFont(FontStyle::ChatMedium, this->scale())); + + // NOTE: We're using TimestampMedium here to get a font that uses the tnum font feature, + // meaning numbers get equal width & don't bounce around while the user is typing. + this->ui_.textEditLength->setFont( + app->getFonts()->getFont(FontStyle::TimestampMedium, this->scale())); + this->ui_.replyLabel->setFont( + app->getFonts()->getFont(FontStyle::ChatMediumBold, this->scale())); +} + } // namespace chatterino diff --git a/src/widgets/splits/SplitInput.hpp b/src/widgets/splits/SplitInput.hpp index 14a04905..ee617d7f 100644 --- a/src/widgets/splits/SplitInput.hpp +++ b/src/widgets/splits/SplitInput.hpp @@ -188,6 +188,8 @@ protected: QPropertyAnimation backgroundColorAnimation; + void updateFonts(); + private Q_SLOTS: void editTextChanged();