]> sigrok.org Git - pulseview.git/blobdiff - pv/globalsettings.cpp
Settings: Allow user to choose the Qt UI style
[pulseview.git] / pv / globalsettings.cpp
index 55ceb5a9e4e382b80cef0ad61cde72f0e0142888..c15adf7446e9f6523526b26cc860b5985f1bc578 100644 (file)
@@ -26,6 +26,8 @@
 #include <QFontMetrics>
 #include <QPixmapCache>
 #include <QString>
+#include <QStyle>
+#include <QtGlobal>
 
 using std::map;
 using std::pair;
@@ -41,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";
@@ -63,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() :
@@ -76,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))
@@ -122,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();
 }
 
@@ -141,6 +151,12 @@ 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) {
                QPalette dark_palette;
                dark_palette.setColor(QPalette::Window, QColor(53, 53, 53));
@@ -224,7 +240,7 @@ void GlobalSettings::undo_tracked_changes()
 {
        tracking_ = false;
 
-       for (auto entry : tracked_changes_)
+       for (auto& entry : tracked_changes_)
                setValue(entry.first, entry.second);
 
        tracked_changes_.clear();