Merge branch 'staged' into dev

This commit is contained in:
YiFang Xiao 2023-09-07 22:37:29 +08:00
commit 4d24085c44
6 changed files with 56 additions and 5 deletions

View file

@ -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 );

View file

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

View file

@ -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() ) ) {

View file

@ -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 )

View file

@ -19,6 +19,7 @@ class Preferences: public QDialog
Config::CustomFonts prevWebFontFamily;
QString prevSysFont;
Config::Class & cfg;
QAction helpAction;

View file

@ -284,6 +284,20 @@ the application.</string>
<string>Appearance</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_16">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_17">
<item>
<widget class="QLabel" name="label_29">
<property name="text">
<string>Interface Font</string>
</property>
</widget>
</item>
<item>
<widget class="QFontComboBox" name="systemFont"/>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_4">
<item>