diff --git a/.gitignore b/.gitignore index 5668694c..991eb5f7 100644 --- a/.gitignore +++ b/.gitignore @@ -41,4 +41,8 @@ GoldenDict.xcodeproj/ # cmake files /cmake-build-**/ /build**/ -CMakeLists.txt.user \ No newline at end of file +CMakeLists.txt.user + +# kdevelop +.kdev4/ +*.kdev4 diff --git a/article_maker.cc b/article_maker.cc index aacb996c..0a6a885d 100644 --- a/article_maker.cc +++ b/article_maker.cc @@ -149,20 +149,19 @@ std::string ArticleMaker::makeHtmlHeader( QString const & word, ""; result+= R"()"; -#ifdef Q_OS_WIN32 - if( GlobalBroadcaster::instance()->getPreference()->darkMode ) + if( GlobalBroadcaster::instance()->getPreference()->darkReaderMode ) { - result += ""; - result += - ""; + result += R"( + + +)"; } -#endif result += ""; return result; diff --git a/config.cc b/config.cc index d968e722..d56cbd55 100644 --- a/config.cc +++ b/config.cc @@ -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 ); diff --git a/config.hh b/config.hh index 247692ab..0b3fa9d2 100644 --- a/config.hh +++ b/config.hh @@ -308,6 +308,7 @@ struct Preferences bool autoScrollToTargetArticle; bool escKeyHidesMainWindow; bool darkMode; + bool darkReaderMode; bool alwaysOnTop; /// An old UI mode when tranlateLine and wordList diff --git a/mainwindow.cc b/mainwindow.cc index 2bf1f9e5..26cf7e17 100644 --- a/mainwindow.cc +++ b/mainwindow.cc @@ -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; } diff --git a/mainwindow.hh b/mainwindow.hh index 1c7d9a5b..d96e4ec6 100644 --- a/mainwindow.hh +++ b/mainwindow.hh @@ -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. diff --git a/preferences.cc b/preferences.cc index 61d00df1..6cdebbc8 100644 --- a/preferences.cc +++ b/preferences.cc @@ -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(); diff --git a/preferences.ui b/preferences.ui index 74225b3d..d0f40859 100644 --- a/preferences.ui +++ b/preferences.ui @@ -123,7 +123,7 @@ - Display style: + Article Display style: @@ -157,8 +157,21 @@ + + Turn the UI to dark. + - dark mode + Dark Mode + + + + + + + Turn the article display style to dark. + + + Dark Reader Mode