X-Git-Url: https://sigrok.org/gitweb/?p=pulseview.git;a=blobdiff_plain;f=pv%2Fglobalsettings.cpp;h=19ce0cd79104cce58878f1ee194fd4ac452f1736;hp=3f3711b8ec63a8397892f26eafc1db845e8dfab1;hb=8962d7b3b640b5f07f26a4b4ebee839c4880b69d;hpb=f4ab4b5c657e5613caba82feaa81a8a400e4f331 diff --git a/pv/globalsettings.cpp b/pv/globalsettings.cpp index 3f3711b8..19ce0cd7 100644 --- a/pv/globalsettings.cpp +++ b/pv/globalsettings.cpp @@ -26,6 +26,8 @@ #include #include #include +#include +#include using std::map; using std::pair; @@ -41,6 +43,8 @@ const vector< pair > Themes { }; const QString GlobalSettings::Key_General_Theme = "General_Theme"; +const QString GlobalSettings::Key_General_Style = "General_Style"; +const QString GlobalSettings::Key_General_SaveWithSetup = "General_SaveWithSetup"; const QString GlobalSettings::Key_View_ZoomToFitDuringAcq = "View_ZoomToFitDuringAcq"; const QString GlobalSettings::Key_View_ZoomToFitAfterAcq = "View_ZoomToFitAfterAcq"; const QString GlobalSettings::Key_View_TriggerIsZeroTime = "View_TriggerIsZeroTime"; @@ -55,6 +59,7 @@ const QString GlobalSettings::Key_View_DefaultDivHeight = "View_DefaultDivHeight const QString GlobalSettings::Key_View_DefaultLogicHeight = "View_DefaultLogicHeight"; const QString GlobalSettings::Key_View_ShowHoverMarker = "View_ShowHoverMarker"; const QString GlobalSettings::Key_View_SnapDistance = "View_SnapDistance"; +const QString GlobalSettings::Key_View_CursorFillColor = "View_CursorFillColor"; const QString GlobalSettings::Key_Dec_InitialStateConfigurable = "Dec_InitialStateConfigurable"; const QString GlobalSettings::Key_Dec_ExportFormat = "Dec_ExportFormat"; const QString GlobalSettings::Key_Log_BufferSize = "Log_BufferSize"; @@ -63,19 +68,36 @@ const QString GlobalSettings::Key_Log_NotifyOfStacktrace = "Log_NotifyOfStacktra vector GlobalSettings::callbacks_; bool GlobalSettings::tracking_ = false; map GlobalSettings::tracked_changes_; +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 if (!contains(Key_General_Theme)) setValue(Key_General_Theme, 0); + if (!contains(Key_General_Style)) + setValue(Key_General_Style, ""); + + // Save setup with .sr files by default + if (!contains(Key_General_SaveWithSetup)) + setValue(Key_General_SaveWithSetup, true); // Enable zoom-to-fit after acquisition by default if (!contains(Key_View_ZoomToFitAfterAcq)) @@ -92,9 +114,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, @@ -120,11 +139,33 @@ 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 if undefined + if (!contains(Key_View_CursorFillColor)) + set_bright_theme_default_colors(); } -void GlobalSettings::save_default_palette() +void GlobalSettings::set_bright_theme_default_colors() { - default_palette_ = QApplication::palette(); + setValue(Key_View_FillSignalHighAreaColor, + QColor(0, 0, 0, 5 * 256 / 100).rgba()); + + setValue(Key_View_CursorFillColor, + QColor(220, 231, 243).rgba()); +} + +void GlobalSettings::set_dark_theme_default_colors() +{ + setValue(Key_View_FillSignalHighAreaColor, + QColor(188, 188, 188, 9 * 256 / 100).rgba()); + + setValue(Key_View_CursorFillColor, + QColor(60, 60, 60).rgba()); +} + +bool GlobalSettings::current_theme_is_dark() +{ + return is_dark_theme_; } void GlobalSettings::apply_theme() @@ -141,6 +182,14 @@ 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); + + is_dark_theme_ = false; + if (theme_name.compare("QDarkStyleSheet") == 0) { QPalette dark_palette; dark_palette.setColor(QPalette::Window, QColor(53, 53, 53)); @@ -149,6 +198,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)); @@ -172,6 +222,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();