From 1208ca3ad4973c316b7cba236035bdc70ed614f8 Mon Sep 17 00:00:00 2001 From: Jonas Kvinge Date: Wed, 3 May 2023 01:59:13 +0200 Subject: [PATCH] ContextView: Simplify font code --- src/context/contextview.cpp | 26 ++++++++++++-------------- src/context/contextview.h | 7 +++---- 2 files changed, 15 insertions(+), 18 deletions(-) diff --git a/src/context/contextview.cpp b/src/context/contextview.cpp index 236fb070d..3158cc7e3 100644 --- a/src/context/contextview.cpp +++ b/src/context/contextview.cpp @@ -120,9 +120,7 @@ ContextView::ContextView(QWidget *parent) label_device_icon_(new QLabel(this)), label_engine_icon_(new QLabel(this)), lyrics_tried_(false), - lyrics_id_(-1), - font_size_headline_(0), - font_size_normal_(0) { + lyrics_id_(-1) { setLayout(layout_container_); @@ -341,10 +339,12 @@ void ContextView::ReloadSettings() { action_show_output_->setChecked(s.value(ContextSettingsPage::kSettingsGroupEnable[static_cast(ContextSettingsPage::ContextSettingsOrder::ENGINE_AND_DEVICE)], false).toBool()); action_show_lyrics_->setChecked(s.value(ContextSettingsPage::kSettingsGroupEnable[static_cast(ContextSettingsPage::ContextSettingsOrder::SONG_LYRICS)], true).toBool()); action_search_lyrics_->setChecked(s.value(ContextSettingsPage::kSettingsGroupEnable[static_cast(ContextSettingsPage::ContextSettingsOrder::SEARCH_LYRICS)], true).toBool()); - font_headline_ = s.value("font_headline", font().family()).toString(); - font_normal_ = s.value("font_normal", font().family()).toString(); - font_size_headline_ = s.value("font_size_headline", ContextSettingsPage::kDefaultFontSizeHeadline).toReal(); - font_size_normal_ = s.value("font_size_normal", font().pointSizeF()).toReal(); + font_headline_.setFamily(s.value("font_headline", font().family()).toString()); + font_headline_.setPointSizeF(s.value("font_size_headline", ContextSettingsPage::kDefaultFontSizeHeadline).toReal()); + font_nosong_.setFamily(font_headline_.family()); + font_nosong_.setPointSizeF(font_headline_.pointSizeF() * 1.6F); + font_normal_.setFamily(s.value("font_normal", font().family()).toString()); + font_normal_.setPointSizeF(s.value("font_size_normal", font().pointSizeF()).toReal()); s.endGroup(); UpdateFonts(); @@ -433,7 +433,7 @@ void ContextView::NoSong() { widget_album_->show(); } - textedit_top_->setFont(QFont(font_headline_, static_cast(font_size_headline_ * 1.6))); + textedit_top_->setFont(font_nosong_); textedit_top_->SetText(tr("No song playing")); QString html; @@ -449,27 +449,25 @@ void ContextView::NoSong() { else html += tr("%1 albums").arg(collectionview_->TotalAlbums()); html += "
"; - label_stop_summary_->setFont(QFont(font_normal_, static_cast(font_size_normal_))); + label_stop_summary_->setFont(font_normal_); label_stop_summary_->setText(html); } void ContextView::UpdateFonts() { - QFont font(font_normal_, static_cast(font_size_normal_)); - font.setBold(false); for (QLabel *l : labels_play_all_) { - l->setFont(font); + l->setFont(font_normal_); } for (QTextEdit *e : textedit_play_) { - e->setFont(font); + e->setFont(font_normal_); } } void ContextView::SetSong() { - textedit_top_->setFont(QFont(font_headline_, static_cast(font_size_headline_))); + textedit_top_->setFont(font_headline_); textedit_top_->SetText(QString("%1
%2").arg(Utilities::ReplaceMessage(title_fmt_, song_playing_, "
", true), Utilities::ReplaceMessage(summary_fmt_, song_playing_, "
", true))); label_stop_summary_->clear(); diff --git a/src/context/contextview.h b/src/context/contextview.h index a813ccf6e..6ed9706c2 100644 --- a/src/context/contextview.h +++ b/src/context/contextview.h @@ -166,10 +166,9 @@ class ContextView : public QWidget { QString lyrics_; QString title_fmt_; QString summary_fmt_; - QString font_headline_; - QString font_normal_; - qreal font_size_headline_; - qreal font_size_normal_; + QFont font_headline_; + QFont font_normal_; + QFont font_nosong_; QList labels_play_; QList textedit_play_;