]> sigrok.org Git - pulseview.git/commitdiff
Settings: Allow user to choose the Qt UI style
authorSoeren Apel <redacted>
Fri, 26 Oct 2018 20:10:22 +0000 (22:10 +0200)
committerUwe Hermann <redacted>
Sat, 27 Oct 2018 19:17:52 +0000 (21:17 +0200)
main.cpp
pv/dialogs/settings.cpp
pv/dialogs/settings.hpp
pv/globalsettings.cpp
pv/globalsettings.hpp

index 455d7afd3d2b7e49f182da829437b0d459f785df..12d3bb6e30748ca9278e39477a1c7b2042c18848 100644 (file)
--- a/main.cpp
+++ b/main.cpp
@@ -256,7 +256,7 @@ int main(int argc, char *argv[])
 
        // Prepare the global settings since logging needs them early on
        pv::GlobalSettings settings;
-       settings.save_default_palette();
+       settings.save_internal_defaults();
        settings.set_defaults_where_needed();
        settings.apply_theme();
 
index 491bbfc2b6c13e88c67d0dad6efc73f636b4bcfd..b79772ff0dc078e99916cc678aef7a849043184d 100644 (file)
@@ -35,6 +35,7 @@
 #include <QScrollBar>
 #include <QSpinBox>
 #include <QString>
+#include <QStyleFactory>
 #include <QTextBrowser>
 #include <QTextDocument>
 #include <QTextStream>
@@ -228,6 +229,26 @@ QWidget *Settings::get_general_settings_form(QWidget *parent) const
        description_1->setAlignment(Qt::AlignRight);
        general_layout->addRow(description_1);
 
+       QComboBox *style_cb = new QComboBox();
+       style_cb->addItem(tr("System Default"), "");
+       for (QString& s : QStyleFactory::keys())
+               style_cb->addItem(s, s);
+
+       const QString current_style =
+               settings.value(GlobalSettings::Key_General_Style).toString();
+       if (current_style.isEmpty())
+               style_cb->setCurrentIndex(0);
+       else
+               style_cb->setCurrentIndex(style_cb->findText(current_style, 0));
+
+       connect(style_cb, SIGNAL(currentIndexChanged(int)),
+               this, SLOT(on_general_style_changed(int)));
+       general_layout->addRow(tr("Qt widget style"), style_cb);
+
+       QLabel *description_2 = new QLabel(tr("(Dark themes look best with the Fusion style)"));
+       description_2->setAlignment(Qt::AlignRight);
+       general_layout->addRow(description_2);
+
        return form;
 }
 
@@ -553,6 +574,19 @@ void Settings::on_general_theme_changed_changed(int state)
        settings.apply_theme();
 }
 
+void Settings::on_general_style_changed(int state)
+{
+       GlobalSettings settings;
+
+       if (state == 0)
+               settings.setValue(GlobalSettings::Key_General_Style, "");
+       else
+               settings.setValue(GlobalSettings::Key_General_Style,
+                       QStyleFactory::keys().at(state - 1));
+
+       settings.apply_theme();
+}
+
 void Settings::on_view_zoomToFitDuringAcq_changed(int state)
 {
        GlobalSettings settings;
index 1473aa59298ebf62fb6cebcc078d4dbe8eedbbd6..4aa54580ebc56d3b670622faa7e003a308375411 100644 (file)
@@ -59,6 +59,7 @@ public:
 private Q_SLOTS:
        void on_page_changed(QListWidgetItem *current, QListWidgetItem *previous);
        void on_general_theme_changed_changed(int state);
+       void on_general_style_changed(int state);
        void on_view_zoomToFitDuringAcq_changed(int state);
        void on_view_zoomToFitAfterAcq_changed(int state);
        void on_view_triggerIsZero_changed(int state);
index af89671cbadeb6b52b77fe707aaf86a265703f12..c15adf7446e9f6523526b26cc860b5985f1bc578 100644 (file)
@@ -26,7 +26,7 @@
 #include <QFontMetrics>
 #include <QPixmapCache>
 #include <QString>
-#include <QStyleFactory>
+#include <QStyle>
 #include <QtGlobal>
 
 using std::map;
@@ -43,6 +43,7 @@ const vector< pair<QString, QString> > Themes {
 };
 
 const QString GlobalSettings::Key_General_Theme = "General_Theme";
+const QString GlobalSettings::Key_General_Style = "General_Style";
 const QString GlobalSettings::Key_View_ZoomToFitDuringAcq = "View_ZoomToFitDuringAcq";
 const QString GlobalSettings::Key_View_ZoomToFitAfterAcq = "View_ZoomToFitAfterAcq";
 const QString GlobalSettings::Key_View_TriggerIsZeroTime = "View_TriggerIsZeroTime";
@@ -65,6 +66,7 @@ const QString GlobalSettings::Key_Log_NotifyOfStacktrace = "Log_NotifyOfStacktra
 vector<GlobalSettingsInterface*> GlobalSettings::callbacks_;
 bool GlobalSettings::tracking_ = false;
 map<QString, QVariant> GlobalSettings::tracked_changes_;
+QString GlobalSettings::default_style_;
 QPalette GlobalSettings::default_palette_;
 
 GlobalSettings::GlobalSettings() :
@@ -78,6 +80,8 @@ void GlobalSettings::set_defaults_where_needed()
        // Use no theme by default
        if (!contains(Key_General_Theme))
                setValue(Key_General_Theme, 0);
+       if (!contains(Key_General_Style))
+               setValue(Key_General_Style, "");
 
        // Enable zoom-to-fit after acquisition by default
        if (!contains(Key_View_ZoomToFitAfterAcq))
@@ -124,8 +128,12 @@ void GlobalSettings::set_defaults_where_needed()
                setValue(Key_Log_NotifyOfStacktrace, true);
 }
 
-void GlobalSettings::save_default_palette()
+void GlobalSettings::save_internal_defaults()
 {
+       default_style_ = qApp->style()->objectName();
+       if (default_style_.isEmpty())
+               default_style_ = "fusion";
+
        default_palette_ = QApplication::palette();
 }
 
@@ -143,10 +151,13 @@ void GlobalSettings::apply_theme()
 
        qApp->setPalette(default_palette_);
 
+       const QString style = value(Key_General_Style).toString();
+       if (style.isEmpty())
+               qApp->setStyle(default_style_);
+       else
+               qApp->setStyle(style);
+
        if (theme_name.compare("QDarkStyleSheet") == 0) {
-#ifdef Q_OS_WIN
-               qApp->setStyle(QStyleFactory::create("Fusion"));
-#endif
                QPalette dark_palette;
                dark_palette.setColor(QPalette::Window, QColor(53, 53, 53));
                dark_palette.setColor(QPalette::WindowText, Qt::white);
@@ -155,9 +166,6 @@ void GlobalSettings::apply_theme()
                dark_palette.setColor(QPalette::Highlight, QColor(42, 130, 218));
                qApp->setPalette(dark_palette);
        } else if (theme_name.compare("DarkStyle") == 0) {
-#ifdef Q_OS_WIN
-               qApp->setStyle(QStyleFactory::create("Fusion"));
-#endif
                QPalette dark_palette;
                dark_palette.setColor(QPalette::Window, QColor(53, 53, 53));
                dark_palette.setColor(QPalette::WindowText, Qt::white);
index d23bf637153a093b277671aad684d506ec31a561..d8374a354ff432c3d2edbfff810e6fb909c3389c 100644 (file)
@@ -52,6 +52,7 @@ class GlobalSettings : public QSettings
 
 public:
        static const QString Key_General_Theme;
+       static const QString Key_General_Style;
        static const QString Key_View_ZoomToFitDuringAcq;
        static const QString Key_View_ZoomToFitAfterAcq;
        static const QString Key_View_TriggerIsZeroTime;
@@ -81,8 +82,8 @@ public:
        GlobalSettings();
 
        void set_defaults_where_needed();
+       void save_internal_defaults();
 
-       void save_default_palette();
        void apply_theme();
 
        static void add_change_handler(GlobalSettingsInterface *cb);
@@ -122,6 +123,7 @@ private:
        static bool tracking_;
        static map<QString, QVariant> tracked_changes_;
 
+       static QString default_style_;
        static QPalette default_palette_;
 };