Make context fonts configurable

Fixes #362
This commit is contained in:
Jonas Kvinge
2020-04-28 01:11:00 +02:00
parent 1a4f0dcf5a
commit 760aacca26
7 changed files with 249 additions and 21 deletions

View File

@@ -28,6 +28,7 @@
#include <QUrl>
#include <QImage>
#include <QIcon>
#include <QFont>
#include <QSize>
#include <QSizePolicy>
#include <QMenu>
@@ -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 += "<br />";
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("<b>%1</b><br/>%2").arg(Utilities::ReplaceMessage(title_fmt_, song_playing_, "<br/>"), Utilities::ReplaceMessage(summary_fmt_, song_playing_, "<br/>")));
label_stop_summary_->clear();
@@ -565,7 +607,6 @@ void ContextView::SetSong() {
label_play_albums_->show();
widget_albums_->show();
label_play_albums_->setText("<b>" + tr("Albums by %1").arg( song_playing_.artist().toHtmlEscaped()) + "</b>");
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 <QLabel *> 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();
}

View File

@@ -25,6 +25,7 @@
#include <QtGlobal>
#include <QObject>
#include <QWidget>
#include <QList>
#include <QString>
#include <QImage>
@@ -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<QLabel*> labels_play_;
QList<QLabel*> labels_play_data_;
QList<QLabel*> labels_play_all_;
int prev_width_;
};

View File

@@ -24,12 +24,17 @@
#include <QtGlobal>
#include <QAction>
#include <QVariant>
#include <QIODevice>
#include <QFile>
#include <QFont>
#include <QMenu>
#include <QCursor>
#include <QCheckBox>
#include <QToolButton>
#include <QToolTip>
#include <QLineEdit>
#include <QTextEdit>
#include <QFontComboBox>
#include <QSettings>
#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);
}

View File

@@ -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];
};

View File

@@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>500</width>
<height>600</height>
<height>774</height>
</rect>
</property>
<property name="windowTitle">
@@ -209,6 +209,92 @@
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupbox_font_headline">
<property name="title">
<string>Font for headline</string>
</property>
<layout class="QFormLayout" name="formLayout">
<item row="0" column="0">
<widget class="QLabel" name="label_1_font">
<property name="text">
<string>Font</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_1_font_size">
<property name="text">
<string>Font size</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QDoubleSpinBox" name="font_size_headline"/>
</item>
<item row="0" column="1">
<widget class="QFontComboBox" name="font_headline"/>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_1_preview">
<property name="text">
<string>Preview</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QTextEdit" name="preview_headline">
<property name="textInteractionFlags">
<set>Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse</set>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupbox_font_normal">
<property name="title">
<string>Font for data and lyrics</string>
</property>
<layout class="QFormLayout" name="formLayout_2">
<item row="0" column="0">
<widget class="QLabel" name="label_2_font">
<property name="text">
<string>Font</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QFontComboBox" name="font_normal"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_2_font_size">
<property name="text">
<string>Font size</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QDoubleSpinBox" name="font_size_normal"/>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_1_preview_2">
<property name="text">
<string>Preview</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QTextEdit" name="preview_normal">
<property name="textInteractionFlags">
<set>Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse</set>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<spacer name="spacer_bottom">
<property name="orientation">