mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-27 19:24:08 +00:00
opt : set webengine font family
make it take effect immediately
This commit is contained in:
parent
949f46313d
commit
a1ef0313ab
|
@ -318,25 +318,19 @@ ArticleView::ArticleView( QWidget * parent, ArticleNetworkAccessManager & nm, Au
|
|||
QWebEngineSettings * settings = ui.definition->settings();
|
||||
settings->setUnknownUrlSchemePolicy(QWebEngineSettings::UnknownUrlSchemePolicy::DisallowUnknownUrlSchemes);
|
||||
#if( QT_VERSION < QT_VERSION_CHECK( 6, 0, 0 ) )
|
||||
settings->defaultSettings()->setAttribute( QWebEngineSettings::WebAttribute::LocalContentCanAccessRemoteUrls, true );
|
||||
settings->defaultSettings()->setAttribute( QWebEngineSettings::WebAttribute::LocalContentCanAccessFileUrls, true );
|
||||
settings->defaultSettings()->setAttribute( QWebEngineSettings::WebAttribute::ErrorPageEnabled, false );
|
||||
settings->defaultSettings()->setAttribute( QWebEngineSettings::LocalContentCanAccessRemoteUrls, true );
|
||||
settings->defaultSettings()->setAttribute( QWebEngineSettings::LocalContentCanAccessFileUrls, true );
|
||||
settings->defaultSettings()->setAttribute( QWebEngineSettings::ErrorPageEnabled, false );
|
||||
settings->defaultSettings()->setAttribute( QWebEngineSettings::PluginsEnabled, cfg.preferences.enableWebPlugins );
|
||||
settings->defaultSettings()->setAttribute( QWebEngineSettings::PlaybackRequiresUserGesture, false );
|
||||
settings->defaultSettings()->setAttribute( QWebEngineSettings::JavascriptCanAccessClipboard, true );
|
||||
|
||||
if( !cfg.preferences.webFontFamily.isEmpty() )
|
||||
settings->defaultSettings()->setFontFamily( QWebEngineSettings::StandardFont, cfg.preferences.webFontFamily );
|
||||
#else
|
||||
settings->setAttribute( QWebEngineSettings::WebAttribute::LocalContentCanAccessRemoteUrls, true );
|
||||
settings->setAttribute( QWebEngineSettings::WebAttribute::LocalContentCanAccessFileUrls, true );
|
||||
settings->setAttribute( QWebEngineSettings::WebAttribute::ErrorPageEnabled, false );
|
||||
settings->setAttribute( QWebEngineSettings::LocalContentCanAccessRemoteUrls, true );
|
||||
settings->setAttribute( QWebEngineSettings::LocalContentCanAccessFileUrls, true );
|
||||
settings->setAttribute( QWebEngineSettings::ErrorPageEnabled, false );
|
||||
settings->setAttribute( QWebEngineSettings::PluginsEnabled, cfg.preferences.enableWebPlugins );
|
||||
settings->setAttribute( QWebEngineSettings::PlaybackRequiresUserGesture, false );
|
||||
settings->setAttribute( QWebEngineSettings::JavascriptCanAccessClipboard, true );
|
||||
|
||||
if( !cfg.preferences.webFontFamily.isEmpty() )
|
||||
settings->setFontFamily( QWebEngineSettings::StandardFont, cfg.preferences.webFontFamily );
|
||||
#endif
|
||||
|
||||
expandOptionalParts = cfg.preferences.alwaysExpandOptionalParts;
|
||||
|
|
|
@ -5,6 +5,8 @@
|
|||
#include <QMessageBox>
|
||||
#include "broken_xrecord.hh"
|
||||
#include "mainwindow.hh"
|
||||
#include <QWebEngineSettings>
|
||||
#include <QWebEngineProfile>
|
||||
|
||||
Preferences::Preferences( QWidget * parent, Config::Class & cfg_ ):
|
||||
QDialog( parent ), prevInterfaceLanguage( 0 )
|
||||
|
@ -105,7 +107,9 @@ Preferences::Preferences( QWidget * parent, Config::Class & cfg_ ):
|
|||
ui.fontFamilies->addItem( family );
|
||||
}
|
||||
prevWebFontFamily = p.webFontFamily;
|
||||
ui.fontFamilies->setCurrentText( p.webFontFamily );
|
||||
|
||||
if(!p.webFontFamily.isEmpty())
|
||||
ui.fontFamilies->setCurrentText( p.webFontFamily );
|
||||
// Fill help languages combobox
|
||||
|
||||
ui.helpLanguage->addItem( tr( "Default" ), QString() );
|
||||
|
@ -373,7 +377,9 @@ Config::Preferences Preferences::getPreferences()
|
|||
ui.interfaceLanguage->itemData(
|
||||
ui.interfaceLanguage->currentIndex() ).toString();
|
||||
|
||||
p.webFontFamily = ui.fontFamilies->currentText();
|
||||
//bypass the first default
|
||||
if(ui.fontFamilies->currentIndex()>0)
|
||||
p.webFontFamily = ui.fontFamilies->currentText();
|
||||
|
||||
p.helpLanguage =
|
||||
ui.helpLanguage->itemData(
|
||||
|
@ -645,9 +651,20 @@ void Preferences::on_buttonBox_accepted()
|
|||
QMessageBox::information( this, tr( "Changing Language" ),
|
||||
tr( "Restart the program to apply the language change." ) );
|
||||
|
||||
if ( prevWebFontFamily != ui.fontFamilies->currentText() )
|
||||
QMessageBox::information( this, tr( "Changing Dictionary Font Family" ),
|
||||
tr( "Restart the program to apply the dictionary font family change." ) );
|
||||
auto currentFontFamily = ui.fontFamilies->currentText();
|
||||
if( prevWebFontFamily != currentFontFamily )
|
||||
{
|
||||
//reset to default font .
|
||||
if( currentFontFamily.isEmpty() )
|
||||
{
|
||||
QWebEngineProfile::defaultProfile()->settings()->resetFontFamily( QWebEngineSettings::StandardFont );
|
||||
}
|
||||
else
|
||||
{
|
||||
QWebEngineProfile::defaultProfile()->settings()->setFontFamily( QWebEngineSettings::StandardFont,
|
||||
currentFontFamily );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Preferences::on_useExternalPlayer_toggled( bool enabled )
|
||||
|
|
Loading…
Reference in a new issue