From 760aacca26636ba5d8d80e71d432a54e655e9e65 Mon Sep 17 00:00:00 2001 From: Jonas Kvinge Date: Tue, 28 Apr 2020 01:11:00 +0200 Subject: [PATCH] Make context fonts configurable Fixes #362 --- data/data.qrc | 1 + data/text/ghosts.txt | 42 +++++++++++++ src/context/contextview.cpp | 63 ++++++++++++++------ src/context/contextview.h | 11 ++++ src/settings/contextsettingspage.cpp | 58 ++++++++++++++++++ src/settings/contextsettingspage.h | 7 ++- src/settings/contextsettingspage.ui | 88 +++++++++++++++++++++++++++- 7 files changed, 249 insertions(+), 21 deletions(-) create mode 100644 data/text/ghosts.txt diff --git a/data/data.qrc b/data/data.qrc index 4dc238bb..1a09a181 100644 --- a/data/data.qrc +++ b/data/data.qrc @@ -42,5 +42,6 @@ pictures/rainbowdash.png fonts/HumongousofEternitySt.ttf mood/sample.mood + text/ghosts.txt diff --git a/data/text/ghosts.txt b/data/text/ghosts.txt new file mode 100644 index 00000000..b207c65e --- /dev/null +++ b/data/text/ghosts.txt @@ -0,0 +1,42 @@ +Go to sleep my babies +Don't you wake up +The stars will keep you company +So close your eyes +Old Uncle Moon will shine his dearest sweetest dreams +And hold you in your arms +Until the morning comes. + +Night Light + +Dark the night, not a sound +Damp and cold, frosty ground +Above your head the lion screams +To tear you from your moonlit dreams. +Damp with sweat, mouth is dry +Twisted branches catch the eye +Beside your bed the angel stands +You cannot touch his withered hands. + +Guardian Angel + +As the lion's eyes dance before me +They are kindly yet bloody red +I can see that he is smiling +But I cannot live inside his head. +There the needle stands before me +I climb inside it towards the light +Where the angel stands in glory +His sword of peace defends the night. +So the world is spread before +As I fly high on angel wings +But the angel is deceiving +For he is weeping as he sings. + +Night Light (continued) + +Early birds, morning breeze +Spinning leaves, sleepy trees +Gently tap the window pane +It's good to see the sun again. + +(Dave Cousins) diff --git a/src/context/contextview.cpp b/src/context/contextview.cpp index ce127b80..a0e27b98 100644 --- a/src/context/contextview.cpp +++ b/src/context/contextview.cpp @@ -28,6 +28,7 @@ #include #include #include +#include #include #include #include @@ -244,6 +245,8 @@ ContextView::ContextView(QWidget *parent) : label_play_lyrics_->setWordWrap(true); label_play_lyrics_->setTextInteractionFlags(Qt::TextSelectableByMouse); + label_play_albums_->setWordWrap(true); + layout_play_->setContentsMargins(5, 0, 40, 0); layout_play_->addWidget(widget_play_output_); layout_play_->addSpacerItem(spacer_play_output_); @@ -255,6 +258,30 @@ ContextView::ContextView(QWidget *parent) : layout_play_->addWidget(label_play_lyrics_); layout_play_->addSpacerItem(spacer_play_bottom_); + labels_play_ << label_engine_title_ + << label_device_title_ + << label_filetype_title_ + << label_length_title_ + << label_samplerate_title_ + << label_bitdepth_title_ + << label_bitrate_title_ + << label_play_albums_ + << label_play_lyrics_; + + labels_play_data_ << label_engine_icon_ + << label_engine_ + << label_device_ + << label_device_icon_ + << label_filetype_ + << label_length_ + << label_samplerate_ + << label_bitdepth_ + << label_bitrate_ + << label_play_albums_ + << label_play_lyrics_; + + labels_play_all_ = labels_play_ << labels_play_data_; + QFontDatabase::addApplicationFont(":/fonts/HumongousofEternitySt.ttf"); connect(widget_album_, SIGNAL(FadeStopFinished()), SLOT(FadeStopFinished())); @@ -343,8 +370,14 @@ void ContextView::ReloadSettings() { action_show_albums_->setChecked(s.value(ContextSettingsPage::kSettingsGroupEnable[ContextSettingsPage::ContextSettingsOrder::ALBUMS_BY_ARTIST], false).toBool()); action_show_lyrics_->setChecked(s.value(ContextSettingsPage::kSettingsGroupEnable[ContextSettingsPage::ContextSettingsOrder::SONG_LYRICS], true).toBool()); action_search_lyrics_->setChecked(s.value(ContextSettingsPage::kSettingsGroupEnable[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(); s.endGroup(); + UpdateFonts(); + if (widget_stacked_->currentWidget() == widget_stop_) { NoSong(); } @@ -435,14 +468,23 @@ void ContextView::NoSong() { else html += tr("%1 albums").arg(collectionview_->TotalAlbums()); html += "
"; - label_stop_summary_->setStyleSheet("font: 12pt; font-weight: regular;"); + label_stop_summary_->setStyleSheet(QString("font: %1pt \"%2\"; font-weight: regular;").arg(font_size_normal_).arg(font_normal_)); label_stop_summary_->setText(html); } +void ContextView::UpdateFonts() { + + for (QLabel *l: labels_play_all_) { + l->setStyleSheet(QString("font: %2pt \"%1\"; font-weight: regular;").arg(font_normal_).arg(font_size_normal_)); + } + label_play_albums_->setStyleSheet(QString("background-color: #3DADE8; color: rgb(255, 255, 255); font: %1pt \"%2\"; font-weight: regular;").arg(font_size_normal_).arg(font_normal_)); + +} + void ContextView::SetSong() { - label_top_->setStyleSheet("font: 11pt; font-weight: regular;"); + label_top_->setStyleSheet(QString("font: %2pt \"%1\"; font-weight: regular;").arg(font_headline_).arg(font_size_headline_)); label_top_->setText(QString("%1
%2").arg(Utilities::ReplaceMessage(title_fmt_, song_playing_, "
"), Utilities::ReplaceMessage(summary_fmt_, song_playing_, "
"))); label_stop_summary_->clear(); @@ -565,7 +607,6 @@ void ContextView::SetSong() { label_play_albums_->show(); widget_albums_->show(); label_play_albums_->setText("" + tr("Albums by %1").arg( song_playing_.artist().toHtmlEscaped()) + ""); - label_play_albums_->setStyleSheet("background-color: #3DADE8; color: rgb(255, 255, 255); font: 11pt;"); for (CollectionBackend::Album album : albumlist) { SongList songs = app_->collection_backend()->GetSongs(song_playing_.artist(), album.album_name, opt); widget_albums_->albums_model()->AddSongs(songs); @@ -662,21 +703,7 @@ void ContextView::UpdateSong(const Song &song) { void ContextView::ResetSong() { - QList labels_play_data; - - labels_play_data << label_engine_icon_ - << label_engine_ - << label_device_ - << label_device_icon_ - << label_filetype_ - << label_length_ - << label_samplerate_ - << label_bitdepth_ - << label_bitrate_ - << label_play_albums_ - << label_play_lyrics_; - - for (QLabel *l: labels_play_data) { + for (QLabel *l: labels_play_data_) { l->clear(); } diff --git a/src/context/contextview.h b/src/context/contextview.h index 5e677eca..7c598cf4 100644 --- a/src/context/contextview.h +++ b/src/context/contextview.h @@ -25,6 +25,7 @@ #include #include #include +#include #include #include @@ -78,6 +79,7 @@ class ContextView : public QWidget { void ResetSong(); void GetCoverAutomatically(); void SearchLyrics(); + void UpdateFonts(); signals: void AlbumEnabledChanged(); @@ -173,6 +175,15 @@ 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_; + + QList labels_play_; + QList labels_play_data_; + QList labels_play_all_; + int prev_width_; }; diff --git a/src/settings/contextsettingspage.cpp b/src/settings/contextsettingspage.cpp index 3c694975..af4abeaa 100644 --- a/src/settings/contextsettingspage.cpp +++ b/src/settings/contextsettingspage.cpp @@ -24,12 +24,17 @@ #include #include #include +#include +#include +#include #include #include #include #include #include #include +#include +#include #include #include "core/iconloader.h" @@ -58,6 +63,8 @@ const char *ContextSettingsPage::kSettingsGroupEnable[ContextSettingsOrder::NELE "SearchLyricsEnable", }; +const qreal ContextSettingsPage::kDefaultFontSizeHeadline = 11; + ContextSettingsPage::ContextSettingsPage(SettingsDialog* dialog) : SettingsPage(dialog), ui_(new Ui_ContextSettingsPage) { ui_->setupUi(this); @@ -103,6 +110,18 @@ ContextSettingsPage::ContextSettingsPage(SettingsDialog* dialog) : SettingsPage( ui_->context_exp_chooser1->setIcon(IconLoader::Load("list-add")); ui_->context_exp_chooser2->setIcon(IconLoader::Load("list-add")); + connect(ui_->font_headline, SIGNAL(currentFontChanged(QFont)), SLOT(HeadlineFontChanged())); + connect(ui_->font_size_headline, SIGNAL(valueChanged(double)), SLOT(HeadlineFontChanged())); + connect(ui_->font_normal, SIGNAL(currentFontChanged(QFont)), SLOT(NormalFontChanged())); + connect(ui_->font_size_normal, SIGNAL(valueChanged(double)), SLOT(NormalFontChanged())); + + QFile file(":/text/ghosts.txt"); + if (file.open(QIODevice::ReadOnly)) { + QString text = file.readAll(); + ui_->preview_headline->setText(text); + ui_->preview_normal->setText(text); + } + } ContextSettingsPage::~ContextSettingsPage() { delete ui_; } @@ -117,6 +136,21 @@ void ContextSettingsPage::Load() { for (int i = 0 ; i < ContextSettingsOrder::NELEMS ; ++i) { checkboxes[i]->setChecked(s.value(kSettingsGroupEnable[i], i != ContextSettingsOrder::ALBUMS_BY_ARTIST).toBool()); } + + // Fonts + QString default_font; + int i = ui_->font_headline->findText("Noto Sans"); + if (i >= 0) { + default_font = "Noto Sans"; + } + else { + default_font = QWidget().font().family(); + } + ui_->font_headline->setCurrentFont(s.value("font_headline", default_font).toString()); + ui_->font_normal->setCurrentFont(s.value("font_normal", default_font).toString()); + ui_->font_size_headline->setValue(s.value("font_size_headline", kDefaultFontSizeHeadline).toReal()); + ui_->font_size_normal->setValue(s.value("font_size_normal", font().pointSizeF()).toReal()); + s.endGroup(); } @@ -131,6 +165,10 @@ void ContextSettingsPage::Save() { for (int i = 0; i < ContextSettingsOrder::NELEMS; ++i) { s.setValue(kSettingsGroupEnable[i], checkboxes[i]->isChecked()); } + s.setValue("font_headline", ui_->font_headline->currentFont().family()); + s.setValue("font_normal", ui_->font_normal->currentFont().family()); + s.setValue("font_size_headline", ui_->font_size_headline->value()); + s.setValue("font_size_normal", ui_->font_size_normal->value()); s.endGroup(); } @@ -148,3 +186,23 @@ void ContextSettingsPage::InsertVariableSecondLine(QAction* action) { void ContextSettingsPage::ShowMenuTooltip(QAction* action) { QToolTip::showText(QCursor::pos(), action->toolTip()); } + +void ContextSettingsPage::HeadlineFontChanged() { + + QFont font(ui_->font_headline->currentFont()); + if (ui_->font_size_headline->value() > 0) { + font.setPointSizeF(ui_->font_size_headline->value()); + } + ui_->preview_headline->setFont(font); + +} + +void ContextSettingsPage::NormalFontChanged() { + + QFont font(ui_->font_normal->currentFont()); + if (ui_->font_size_normal->value() > 0) { + font.setPointSizeF(ui_->font_size_normal->value()); + } + ui_->preview_normal->setFont(font); + +} diff --git a/src/settings/contextsettingspage.h b/src/settings/contextsettingspage.h index e21256d0..80767ce6 100644 --- a/src/settings/contextsettingspage.h +++ b/src/settings/contextsettingspage.h @@ -57,16 +57,19 @@ public: static const char *kSettingsSummaryFmt; static const char *kSettingsGroupLabels[ContextSettingsOrder::NELEMS]; static const char *kSettingsGroupEnable[ContextSettingsOrder::NELEMS]; + static const qreal kDefaultFontSizeHeadline; void Load(); void Save(); -private slots: + private slots: void InsertVariableFirstLine(QAction *action); void InsertVariableSecondLine(QAction *action); void ShowMenuTooltip(QAction *action); + void HeadlineFontChanged(); + void NormalFontChanged(); -private: + private: Ui_ContextSettingsPage *ui_; QCheckBox *checkboxes[ContextSettingsOrder::NELEMS]; }; diff --git a/src/settings/contextsettingspage.ui b/src/settings/contextsettingspage.ui index 1af712d2..ed56f834 100644 --- a/src/settings/contextsettingspage.ui +++ b/src/settings/contextsettingspage.ui @@ -7,7 +7,7 @@ 0 0 500 - 600 + 774 @@ -209,6 +209,92 @@ + + + + Font for headline + + + + + + Font + + + + + + + Font size + + + + + + + + + + + + + Preview + + + + + + + Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse + + + + + + + + + + Font for data and lyrics + + + + + + Font + + + + + + + + + + Font size + + + + + + + + + + Preview + + + + + + + Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse + + + + + +