From bff9d83efae206b64597d8f3c483448c35cb2fb9 Mon Sep 17 00:00:00 2001 From: xiaoyifang <105986+xiaoyifang@users.noreply.github.com> Date: Thu, 7 Sep 2023 09:53:51 +0800 Subject: [PATCH] opt: add system font configuration (#1125) * opt: add system font configuration * [autofix.ci] apply automated fixes * opt: add option to change the interface font --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> --- src/config.cc | 5 +++++ src/config.hh | 1 + src/main.cc | 6 ++++++ src/ui/preferences.cc | 34 +++++++++++++++++++++++++++++----- src/ui/preferences.hh | 1 + src/ui/preferences.ui | 14 ++++++++++++++ 6 files changed, 56 insertions(+), 5 deletions(-) diff --git a/src/config.cc b/src/config.cc index c241be0f..9a975dcb 100644 --- a/src/config.cc +++ b/src/config.cc @@ -856,6 +856,7 @@ Class load() if ( !preferences.isNull() ) { c.preferences.interfaceLanguage = preferences.namedItem( "interfaceLanguage" ).toElement().text(); c.preferences.displayStyle = preferences.namedItem( "displayStyle" ).toElement().text(); + c.preferences.interfaceFont = preferences.namedItem( "interfaceFont" ).toElement().text(); #if !defined( Q_OS_WIN ) c.preferences.interfaceStyle = preferences.namedItem( "interfaceStyle" ).toElement().text(); #endif @@ -1702,6 +1703,10 @@ void save( Class const & c ) opt.appendChild( dd.createTextNode( c.preferences.interfaceLanguage ) ); preferences.appendChild( opt ); + opt = dd.createElement( "interfaceFont" ); + opt.appendChild( dd.createTextNode( c.preferences.interfaceFont ) ); + preferences.appendChild( opt ); + opt = dd.createElement( "customFonts" ); auto customFont = c.preferences.customFonts.toElement( dd ); preferences.appendChild( customFont ); diff --git a/src/config.hh b/src/config.hh index 4ec14bac..de15f0c3 100644 --- a/src/config.hh +++ b/src/config.hh @@ -345,6 +345,7 @@ ScanPopupWindowFlags spwfFromInt( int id ); struct Preferences { QString interfaceLanguage; // Empty value corresponds to system default + QString interfaceFont; //Empty as default value. CustomFonts customFonts; bool newTabsOpenAfterCurrentOne; diff --git a/src/main.cc b/src/main.cc index 4768c34b..138cfed4 100644 --- a/src/main.cc +++ b/src/main.cc @@ -508,6 +508,12 @@ int main( int argc, char ** argv ) localeName = cfg.preferences.interfaceLanguage; } + //System Font + auto font = QApplication::font(); + if ( !cfg.preferences.interfaceFont.isEmpty() && font.family() != cfg.preferences.interfaceFont ) { + app.setFont( QFont( cfg.preferences.interfaceFont ) ); + } + QLocale locale( localeName ); QLocale::setDefault( locale ); if ( !qtTranslator.load( "qt_extra_" + localeName, Config::getLocDir() ) ) { diff --git a/src/ui/preferences.cc b/src/ui/preferences.cc index 69b8d694..f42079fd 100644 --- a/src/ui/preferences.cc +++ b/src/ui/preferences.cc @@ -97,7 +97,14 @@ Preferences::Preferences( QWidget * parent, Config::Class & cfg_ ): } } + //System Font + if ( !p.interfaceFont.isEmpty() ) { + ui.systemFont->setCurrentText( p.interfaceFont ); + } + + prevWebFontFamily = p.customFonts; + prevSysFont = p.interfaceFont; if ( !p.customFonts.standard.isEmpty() ) ui.font_standard->setCurrentText( p.customFonts.standard ); @@ -397,6 +404,8 @@ Config::Preferences Preferences::getPreferences() p.interfaceLanguage = ui.interfaceLanguage->itemData( ui.interfaceLanguage->currentIndex() ).toString(); + p.interfaceFont = ui.systemFont->currentText(); + Config::CustomFonts c; c.standard = ui.font_standard->currentText(); c.serif = ui.font_serif->currentText(); @@ -602,17 +611,27 @@ void Preferences::on_enableClipboardHotkey_toggled( bool checked ) void Preferences::on_buttonBox_accepted() { - if ( prevInterfaceLanguage != ui.interfaceLanguage->currentIndex() ) - QMessageBox::information( this, - tr( "Changing Language" ), - tr( "Restart the program to apply the language change." ) ); + QString promptText; + + if ( prevInterfaceLanguage != ui.interfaceLanguage->currentIndex() ) { + promptText = tr( "Restart the program to apply the language change." ); + promptText += "\n"; + } #if !defined( Q_OS_WIN ) if ( prevInterfaceStyle != ui.InterfaceStyle->currentIndex() ) { - QMessageBox::information( this, tr( "Restart needed" ), tr( "Restart to apply the interface style change." ) ); + promptText += tr( "Restart to apply the interface style change." ); + promptText += "\n"; } #endif + if ( ui.systemFont->currentText() != prevSysFont ) { + promptText += tr( "Restart to apply the interface font change." ); + } + + if ( !promptText.isEmpty() ) { + QMessageBox::information( this, tr( "Restart needed" ), promptText ); + } auto c = getPreferences(); if ( c.customFonts != prevWebFontFamily ) { @@ -625,6 +644,11 @@ void Preferences::on_buttonBox_accepted() QWebEngineProfile::defaultProfile()->settings()->setFontFamily( QWebEngineSettings::FixedFont, c.customFonts.monospace ); } + + //change interface font. + if ( ui.systemFont->currentText() != prevSysFont ) { + QApplication::setFont( QFont( ui.systemFont->currentText() ) ); + } } void Preferences::on_useExternalPlayer_toggled( bool enabled ) diff --git a/src/ui/preferences.hh b/src/ui/preferences.hh index c5dc6eaa..3bc1ea78 100644 --- a/src/ui/preferences.hh +++ b/src/ui/preferences.hh @@ -19,6 +19,7 @@ class Preferences: public QDialog Config::CustomFonts prevWebFontFamily; + QString prevSysFont; Config::Class & cfg; QAction helpAction; diff --git a/src/ui/preferences.ui b/src/ui/preferences.ui index 8522cf72..c3c18768 100644 --- a/src/ui/preferences.ui +++ b/src/ui/preferences.ui @@ -284,6 +284,20 @@ the application. Appearance + + + + + + Interface Font + + + + + + + +