From: Soeren Apel Date: Fri, 26 Oct 2018 21:44:45 +0000 (+0200) Subject: Ask user about adjusting UI colors when choosing a theme X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=a42d2514a57051f971e7b239bc3765ebf93669ae;p=pulseview.git Ask user about adjusting UI colors when choosing a theme --- diff --git a/pv/dialogs/settings.cpp b/pv/dialogs/settings.cpp index b79772ff..1119b8fa 100644 --- a/pv/dialogs/settings.cpp +++ b/pv/dialogs/settings.cpp @@ -572,6 +572,24 @@ void Settings::on_general_theme_changed_changed(int state) GlobalSettings settings; settings.setValue(GlobalSettings::Key_General_Theme, state); settings.apply_theme(); + + QMessageBox msg(this); + msg.setStandardButtons(QMessageBox::Yes | QMessageBox::No); + msg.setIcon(QMessageBox::Question); + + if (settings.current_theme_is_dark()) { + msg.setText(tr("You selected a dark theme.\n" \ + "Should I set the user-adjustable colors to better suit your choice?\n\n" \ + "Please keep in mind that PulseView may need a restart to display correctly.")); + if (msg.exec() == QMessageBox::Yes) + settings.set_dark_theme_default_colors(); + } else { + msg.setText(tr("You selected a bright theme.\n" \ + "Should I set the user-adjustable colors to better suit your choice?\n\n" \ + "Please keep in mind that PulseView may need a restart to display correctly.")); + if (msg.exec() == QMessageBox::Yes) + settings.set_bright_theme_default_colors(); + } } void Settings::on_general_style_changed(int state) diff --git a/pv/globalsettings.cpp b/pv/globalsettings.cpp index c15adf74..1cd65665 100644 --- a/pv/globalsettings.cpp +++ b/pv/globalsettings.cpp @@ -70,11 +70,21 @@ QString GlobalSettings::default_style_; QPalette GlobalSettings::default_palette_; GlobalSettings::GlobalSettings() : - QSettings() + QSettings(), + is_dark_theme_(false) { beginGroup("Settings"); } +void GlobalSettings::save_internal_defaults() +{ + default_style_ = qApp->style()->objectName(); + if (default_style_.isEmpty()) + default_style_ = "fusion"; + + default_palette_ = QApplication::palette(); +} + void GlobalSettings::set_defaults_where_needed() { // Use no theme by default @@ -98,9 +108,6 @@ void GlobalSettings::set_defaults_where_needed() // Enable filling logic signal high areas by default if (!contains(Key_View_FillSignalHighAreas)) setValue(Key_View_FillSignalHighAreas, true); - if (!contains(Key_View_FillSignalHighAreaColor)) - setValue(Key_View_FillSignalHighAreaColor, - QColor(0, 0, 0, 5 * 256 / 100).rgba()); if (!contains(Key_View_DefaultDivHeight)) setValue(Key_View_DefaultDivHeight, @@ -126,15 +133,26 @@ void GlobalSettings::set_defaults_where_needed() // Notify user of existing stack trace by default if (!contains(Key_Log_NotifyOfStacktrace)) setValue(Key_Log_NotifyOfStacktrace, true); + + // Default theme is bright, so use its color scheme + set_bright_theme_default_colors(); } -void GlobalSettings::save_internal_defaults() +void GlobalSettings::set_bright_theme_default_colors() { - default_style_ = qApp->style()->objectName(); - if (default_style_.isEmpty()) - default_style_ = "fusion"; + setValue(Key_View_FillSignalHighAreaColor, + QColor(0, 0, 0, 5 * 256 / 100).rgba()); +} - default_palette_ = QApplication::palette(); +void GlobalSettings::set_dark_theme_default_colors() +{ + setValue(Key_View_FillSignalHighAreaColor, + QColor(188, 188, 188, 9 * 256 / 100).rgba()); +} + +bool GlobalSettings::current_theme_is_dark() +{ + return is_dark_theme_; } void GlobalSettings::apply_theme() @@ -157,6 +175,8 @@ void GlobalSettings::apply_theme() else qApp->setStyle(style); + is_dark_theme_ = false; + if (theme_name.compare("QDarkStyleSheet") == 0) { QPalette dark_palette; dark_palette.setColor(QPalette::Window, QColor(53, 53, 53)); @@ -165,6 +185,7 @@ void GlobalSettings::apply_theme() dark_palette.setColor(QPalette::Dark, QColor(35, 35, 35)); dark_palette.setColor(QPalette::Highlight, QColor(42, 130, 218)); qApp->setPalette(dark_palette); + is_dark_theme_ = true; } else if (theme_name.compare("DarkStyle") == 0) { QPalette dark_palette; dark_palette.setColor(QPalette::Window, QColor(53, 53, 53)); @@ -188,6 +209,7 @@ void GlobalSettings::apply_theme() dark_palette.setColor(QPalette::HighlightedText, Qt::white); dark_palette.setColor(QPalette::Disabled, QPalette::HighlightedText, QColor(127, 127, 127)); qApp->setPalette(dark_palette); + is_dark_theme_ = true; } QPixmapCache::clear(); diff --git a/pv/globalsettings.hpp b/pv/globalsettings.hpp index d8374a35..6f32bf01 100644 --- a/pv/globalsettings.hpp +++ b/pv/globalsettings.hpp @@ -81,9 +81,12 @@ public: public: GlobalSettings(); - void set_defaults_where_needed(); void save_internal_defaults(); + void set_defaults_where_needed(); + void set_bright_theme_default_colors(); + void set_dark_theme_default_colors(); + bool current_theme_is_dark(); void apply_theme(); static void add_change_handler(GlobalSettingsInterface *cb); @@ -125,6 +128,8 @@ private: static QString default_style_; static QPalette default_palette_; + + bool is_dark_theme_; }; } // namespace pv