mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-23 20:14:05 +00:00
perfect_dark: add toggle option to enable Dark Reader mode
This commit is contained in:
parent
e5a0fa864c
commit
9828ef9dc8
6
.gitignore
vendored
6
.gitignore
vendored
|
@ -41,4 +41,8 @@ GoldenDict.xcodeproj/
|
|||
# cmake files
|
||||
/cmake-build-**/
|
||||
/build**/
|
||||
CMakeLists.txt.user
|
||||
CMakeLists.txt.user
|
||||
|
||||
# kdevelop
|
||||
.kdev4/
|
||||
*.kdev4
|
||||
|
|
|
@ -149,20 +149,19 @@ std::string ArticleMaker::makeHtmlHeader( QString const & word,
|
|||
"</script>";
|
||||
result+= R"(<script type="text/javascript" src="qrc:///scripts/gd-builtin.js"></script>)";
|
||||
|
||||
#ifdef Q_OS_WIN32
|
||||
if( GlobalBroadcaster::instance()->getPreference()->darkMode )
|
||||
if( GlobalBroadcaster::instance()->getPreference()->darkReaderMode )
|
||||
{
|
||||
result += "<script type=\"text/javascript\" src=\"qrc:///scripts/darkreader.js\"></script>";
|
||||
result +=
|
||||
"<script type=\"text/javascript\">"
|
||||
"DarkReader.enable({"
|
||||
" brightness: 100,"
|
||||
" contrast: 90,"
|
||||
" sepia: 10"
|
||||
"});"
|
||||
"</script>";
|
||||
result += R"(
|
||||
<script src="qrc:///scripts/darkreader.js"></script>
|
||||
<script>
|
||||
DarkReader.enable({
|
||||
brightness: 100,
|
||||
contrast: 90,
|
||||
sepia: 10
|
||||
});
|
||||
</script>
|
||||
)";
|
||||
}
|
||||
#endif
|
||||
result += "</head><body>";
|
||||
|
||||
return result;
|
||||
|
|
|
@ -230,6 +230,7 @@ Preferences::Preferences():
|
|||
autoScrollToTargetArticle( true ),
|
||||
escKeyHidesMainWindow( false ),
|
||||
darkMode( false ),
|
||||
darkReaderMode ( false ),
|
||||
alwaysOnTop ( false ),
|
||||
searchInDock ( false ),
|
||||
|
||||
|
@ -892,6 +893,9 @@ Class load()
|
|||
if ( !preferences.namedItem( "darkMode" ).isNull() )
|
||||
c.preferences.darkMode = ( preferences.namedItem( "darkMode" ).toElement().text() == "1" );
|
||||
|
||||
if ( !preferences.namedItem("darkReaderMode").isNull())
|
||||
c.preferences.darkReaderMode = (preferences.namedItem("darkReaderMode").toElement().text() == "1");
|
||||
|
||||
if ( !preferences.namedItem( "zoomFactor" ).isNull() )
|
||||
c.preferences.zoomFactor = preferences.namedItem( "zoomFactor" ).toElement().text().toDouble();
|
||||
|
||||
|
@ -1757,6 +1761,10 @@ void save( Class const & c )
|
|||
opt.appendChild( dd.createTextNode( c.preferences.darkMode ? "1":"0" ) );
|
||||
preferences.appendChild( opt );
|
||||
|
||||
opt = dd.createElement( "darkReaderMode" );
|
||||
opt.appendChild( dd.createTextNode( c.preferences.darkReaderMode ? "1":"0" ) );
|
||||
preferences.appendChild( opt );
|
||||
|
||||
opt = dd.createElement( "zoomFactor" );
|
||||
opt.appendChild( dd.createTextNode( QString::number( c.preferences.zoomFactor ) ) );
|
||||
preferences.appendChild( opt );
|
||||
|
|
|
@ -308,6 +308,7 @@ struct Preferences
|
|||
bool autoScrollToTargetArticle;
|
||||
bool escKeyHidesMainWindow;
|
||||
bool darkMode;
|
||||
bool darkReaderMode;
|
||||
bool alwaysOnTop;
|
||||
|
||||
/// An old UI mode when tranlateLine and wordList
|
||||
|
|
|
@ -786,7 +786,7 @@ MainWindow::MainWindow( Config::Class & cfg_ ):
|
|||
|
||||
translateLine->setFocus();
|
||||
|
||||
applyQtStyleSheet( cfg.preferences.displayStyle, cfg.preferences.addonStyle, cfg.preferences.darkMode );
|
||||
applyQtStyleSheet( cfg.preferences.addonStyle, cfg.preferences.darkMode );
|
||||
|
||||
makeScanPopup();
|
||||
|
||||
|
@ -1125,7 +1125,7 @@ QPrinter & MainWindow::getPrinter()
|
|||
return *printer;
|
||||
}
|
||||
|
||||
void MainWindow::applyQtStyleSheet( QString const & displayStyle, QString const & addonStyle, bool const & darkMode )
|
||||
void MainWindow::applyQtStyleSheet( QString const & addonStyle, bool const & darkMode )
|
||||
{
|
||||
#ifdef Q_OS_WIN32
|
||||
if( darkMode )
|
||||
|
@ -2207,10 +2207,10 @@ void MainWindow::editPreferences()
|
|||
|
||||
bool needReload = false;
|
||||
|
||||
// See if we need to reapply stylesheets
|
||||
if ( cfg.preferences.displayStyle != p.displayStyle || cfg.preferences.addonStyle != p.addonStyle || cfg.preferences.darkMode != p.darkMode)
|
||||
// See if we need to reapply Qt stylesheets
|
||||
if ( cfg.preferences.addonStyle != p.addonStyle || cfg.preferences.darkMode != p.darkMode)
|
||||
{
|
||||
applyQtStyleSheet( p.displayStyle, p.addonStyle, p.darkMode );
|
||||
applyQtStyleSheet( p.addonStyle, p.darkMode );
|
||||
articleMaker.setDisplayStyle( p.displayStyle, p.addonStyle );
|
||||
needReload = true;
|
||||
}
|
||||
|
|
|
@ -181,8 +181,8 @@ private:
|
|||
IframeSchemeHandler * iframeSchemeHandler;
|
||||
ResourceSchemeHandler * resourceSchemeHandler;
|
||||
|
||||
/// Applies the qt's stylesheet, given the style's name.
|
||||
void applyQtStyleSheet( QString const & displayStyle, QString const & addonStyle, bool const & darkMode );
|
||||
/// Applies the custom Qt stylesheet
|
||||
void applyQtStyleSheet( QString const & addonStyle, bool const & darkMode );
|
||||
|
||||
/// Creates, destroys or otherwise updates tray icon, according to the
|
||||
/// current configuration and situation.
|
||||
|
|
|
@ -172,6 +172,7 @@ Preferences::Preferences( QWidget * parent, Config::Class & cfg_ ):
|
|||
ui.autoScrollToTargetArticle->setChecked( p.autoScrollToTargetArticle );
|
||||
ui.escKeyHidesMainWindow->setChecked( p.escKeyHidesMainWindow );
|
||||
ui.darkMode->setChecked(p.darkMode);
|
||||
ui.darkReaderMode -> setChecked(p.darkReaderMode);
|
||||
#ifndef Q_OS_WIN32
|
||||
ui.darkMode->hide();
|
||||
#endif
|
||||
|
@ -395,6 +396,7 @@ Config::Preferences Preferences::getPreferences()
|
|||
p.escKeyHidesMainWindow = ui.escKeyHidesMainWindow->isChecked();
|
||||
|
||||
p.darkMode = ui.darkMode->isChecked();
|
||||
p.darkReaderMode = ui.darkReaderMode->isChecked();
|
||||
p.enableMainWindowHotkey = ui.enableMainWindowHotkey->isChecked();
|
||||
p.mainWindowHotkey = ui.mainWindowHotkey->getHotKey();
|
||||
p.enableClipboardHotkey = ui.enableClipboardHotkey->isChecked();
|
||||
|
|
|
@ -123,7 +123,7 @@
|
|||
<item>
|
||||
<widget class="QLabel" name="label_9">
|
||||
<property name="text">
|
||||
<string>Display style:</string>
|
||||
<string>Article Display style:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
|
@ -157,8 +157,21 @@
|
|||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="darkMode">
|
||||
<property name="toolTip">
|
||||
<string>Turn the UI to dark.</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>dark mode</string>
|
||||
<string>Dark Mode</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="darkReaderMode">
|
||||
<property name="toolTip">
|
||||
<string>Turn the article display style to dark.</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Dark Reader Mode</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
|
|
Loading…
Reference in a new issue