mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-30 17:24:08 +00:00
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>
This commit is contained in:
parent
5c9beab96c
commit
bff9d83efa
|
@ -856,6 +856,7 @@ Class load()
|
||||||
if ( !preferences.isNull() ) {
|
if ( !preferences.isNull() ) {
|
||||||
c.preferences.interfaceLanguage = preferences.namedItem( "interfaceLanguage" ).toElement().text();
|
c.preferences.interfaceLanguage = preferences.namedItem( "interfaceLanguage" ).toElement().text();
|
||||||
c.preferences.displayStyle = preferences.namedItem( "displayStyle" ).toElement().text();
|
c.preferences.displayStyle = preferences.namedItem( "displayStyle" ).toElement().text();
|
||||||
|
c.preferences.interfaceFont = preferences.namedItem( "interfaceFont" ).toElement().text();
|
||||||
#if !defined( Q_OS_WIN )
|
#if !defined( Q_OS_WIN )
|
||||||
c.preferences.interfaceStyle = preferences.namedItem( "interfaceStyle" ).toElement().text();
|
c.preferences.interfaceStyle = preferences.namedItem( "interfaceStyle" ).toElement().text();
|
||||||
#endif
|
#endif
|
||||||
|
@ -1702,6 +1703,10 @@ void save( Class const & c )
|
||||||
opt.appendChild( dd.createTextNode( c.preferences.interfaceLanguage ) );
|
opt.appendChild( dd.createTextNode( c.preferences.interfaceLanguage ) );
|
||||||
preferences.appendChild( opt );
|
preferences.appendChild( opt );
|
||||||
|
|
||||||
|
opt = dd.createElement( "interfaceFont" );
|
||||||
|
opt.appendChild( dd.createTextNode( c.preferences.interfaceFont ) );
|
||||||
|
preferences.appendChild( opt );
|
||||||
|
|
||||||
opt = dd.createElement( "customFonts" );
|
opt = dd.createElement( "customFonts" );
|
||||||
auto customFont = c.preferences.customFonts.toElement( dd );
|
auto customFont = c.preferences.customFonts.toElement( dd );
|
||||||
preferences.appendChild( customFont );
|
preferences.appendChild( customFont );
|
||||||
|
|
|
@ -345,6 +345,7 @@ ScanPopupWindowFlags spwfFromInt( int id );
|
||||||
struct Preferences
|
struct Preferences
|
||||||
{
|
{
|
||||||
QString interfaceLanguage; // Empty value corresponds to system default
|
QString interfaceLanguage; // Empty value corresponds to system default
|
||||||
|
QString interfaceFont; //Empty as default value.
|
||||||
|
|
||||||
CustomFonts customFonts;
|
CustomFonts customFonts;
|
||||||
bool newTabsOpenAfterCurrentOne;
|
bool newTabsOpenAfterCurrentOne;
|
||||||
|
|
|
@ -508,6 +508,12 @@ int main( int argc, char ** argv )
|
||||||
localeName = cfg.preferences.interfaceLanguage;
|
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 locale( localeName );
|
||||||
QLocale::setDefault( locale );
|
QLocale::setDefault( locale );
|
||||||
if ( !qtTranslator.load( "qt_extra_" + localeName, Config::getLocDir() ) ) {
|
if ( !qtTranslator.load( "qt_extra_" + localeName, Config::getLocDir() ) ) {
|
||||||
|
|
|
@ -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;
|
prevWebFontFamily = p.customFonts;
|
||||||
|
prevSysFont = p.interfaceFont;
|
||||||
|
|
||||||
if ( !p.customFonts.standard.isEmpty() )
|
if ( !p.customFonts.standard.isEmpty() )
|
||||||
ui.font_standard->setCurrentText( p.customFonts.standard );
|
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.interfaceLanguage = ui.interfaceLanguage->itemData( ui.interfaceLanguage->currentIndex() ).toString();
|
||||||
|
|
||||||
|
p.interfaceFont = ui.systemFont->currentText();
|
||||||
|
|
||||||
Config::CustomFonts c;
|
Config::CustomFonts c;
|
||||||
c.standard = ui.font_standard->currentText();
|
c.standard = ui.font_standard->currentText();
|
||||||
c.serif = ui.font_serif->currentText();
|
c.serif = ui.font_serif->currentText();
|
||||||
|
@ -602,17 +611,27 @@ void Preferences::on_enableClipboardHotkey_toggled( bool checked )
|
||||||
|
|
||||||
void Preferences::on_buttonBox_accepted()
|
void Preferences::on_buttonBox_accepted()
|
||||||
{
|
{
|
||||||
if ( prevInterfaceLanguage != ui.interfaceLanguage->currentIndex() )
|
QString promptText;
|
||||||
QMessageBox::information( this,
|
|
||||||
tr( "Changing Language" ),
|
if ( prevInterfaceLanguage != ui.interfaceLanguage->currentIndex() ) {
|
||||||
tr( "Restart the program to apply the language change." ) );
|
promptText = tr( "Restart the program to apply the language change." );
|
||||||
|
promptText += "\n";
|
||||||
|
}
|
||||||
|
|
||||||
#if !defined( Q_OS_WIN )
|
#if !defined( Q_OS_WIN )
|
||||||
if ( prevInterfaceStyle != ui.InterfaceStyle->currentIndex() ) {
|
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
|
#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();
|
auto c = getPreferences();
|
||||||
if ( c.customFonts != prevWebFontFamily ) {
|
if ( c.customFonts != prevWebFontFamily ) {
|
||||||
|
@ -625,6 +644,11 @@ void Preferences::on_buttonBox_accepted()
|
||||||
QWebEngineProfile::defaultProfile()->settings()->setFontFamily( QWebEngineSettings::FixedFont,
|
QWebEngineProfile::defaultProfile()->settings()->setFontFamily( QWebEngineSettings::FixedFont,
|
||||||
c.customFonts.monospace );
|
c.customFonts.monospace );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//change interface font.
|
||||||
|
if ( ui.systemFont->currentText() != prevSysFont ) {
|
||||||
|
QApplication::setFont( QFont( ui.systemFont->currentText() ) );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Preferences::on_useExternalPlayer_toggled( bool enabled )
|
void Preferences::on_useExternalPlayer_toggled( bool enabled )
|
||||||
|
|
|
@ -19,6 +19,7 @@ class Preferences: public QDialog
|
||||||
|
|
||||||
|
|
||||||
Config::CustomFonts prevWebFontFamily;
|
Config::CustomFonts prevWebFontFamily;
|
||||||
|
QString prevSysFont;
|
||||||
|
|
||||||
Config::Class & cfg;
|
Config::Class & cfg;
|
||||||
QAction helpAction;
|
QAction helpAction;
|
||||||
|
|
|
@ -284,6 +284,20 @@ the application.</string>
|
||||||
<string>Appearance</string>
|
<string>Appearance</string>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QVBoxLayout" name="verticalLayout_16">
|
<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>
|
<item>
|
||||||
<layout class="QHBoxLayout" name="horizontalLayout_4">
|
<layout class="QHBoxLayout" name="horizontalLayout_4">
|
||||||
<item>
|
<item>
|
||||||
|
|
Loading…
Reference in a new issue