]> sigrok.org Git - pulseview.git/commitdiff
Ask user about adjusting UI colors when choosing a theme
authorSoeren Apel <redacted>
Fri, 26 Oct 2018 21:44:45 +0000 (23:44 +0200)
committerUwe Hermann <redacted>
Sat, 27 Oct 2018 19:17:52 +0000 (21:17 +0200)
pv/dialogs/settings.cpp
pv/globalsettings.cpp
pv/globalsettings.hpp

index b79772ff0dc078e99916cc678aef7a849043184d..1119b8fafe69e0ba2e091da13f0857d4cf220f6f 100644 (file)
@@ -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();
        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)
 }
 
 void Settings::on_general_style_changed(int state)
index c15adf7446e9f6523526b26cc860b5985f1bc578..1cd6566530590f2d5d52ba14c0d06fe9ccf39f72 100644 (file)
@@ -70,11 +70,21 @@ QString GlobalSettings::default_style_;
 QPalette GlobalSettings::default_palette_;
 
 GlobalSettings::GlobalSettings() :
 QPalette GlobalSettings::default_palette_;
 
 GlobalSettings::GlobalSettings() :
-       QSettings()
+       QSettings(),
+       is_dark_theme_(false)
 {
        beginGroup("Settings");
 }
 
 {
        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
 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);
        // 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,
 
        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);
        // 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()
 }
 
 void GlobalSettings::apply_theme()
@@ -157,6 +175,8 @@ void GlobalSettings::apply_theme()
        else
                qApp->setStyle(style);
 
        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));
        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);
                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));
        } 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);
                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();
        }
 
        QPixmapCache::clear();
index d8374a354ff432c3d2edbfff810e6fb909c3389c..6f32bf01ebbb8d959ce531a17ef1e55b0a16bba8 100644 (file)
@@ -81,9 +81,12 @@ public:
 public:
        GlobalSettings();
 
 public:
        GlobalSettings();
 
-       void set_defaults_where_needed();
        void save_internal_defaults();
        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);
        void apply_theme();
 
        static void add_change_handler(GlobalSettingsInterface *cb);
@@ -125,6 +128,8 @@ private:
 
        static QString default_style_;
        static QPalette default_palette_;
 
        static QString default_style_;
        static QPalette default_palette_;
+
+       bool is_dark_theme_;
 };
 
 } // namespace pv
 };
 
 } // namespace pv