From c84f7fe72406583ca11fda07314566e90cd9d13a Mon Sep 17 00:00:00 2001 From: itsmattkc Date: Tue, 21 Apr 2020 19:35:04 +1000 Subject: [PATCH] style/preferences: don't set style if it hasn't changed Improves Preferences dialog's "accept" speed. Before it would try changing the style no matter what which took a noticeable amount of time to do for no real purpose if the style didn't change. --- .../tabs/preferencesappearancetab.cpp | 12 ++++------- app/ui/style/style.cpp | 21 +++++++++++++++++++ app/ui/style/style.h | 9 ++++++-- 3 files changed, 32 insertions(+), 10 deletions(-) diff --git a/app/dialog/preferences/tabs/preferencesappearancetab.cpp b/app/dialog/preferences/tabs/preferencesappearancetab.cpp index a8044d2f9..0324fc661 100644 --- a/app/dialog/preferences/tabs/preferencesappearancetab.cpp +++ b/app/dialog/preferences/tabs/preferencesappearancetab.cpp @@ -47,7 +47,7 @@ PreferencesAppearanceTab::PreferencesAppearanceTab() foreach (StyleDescriptor s, style_list_) { style_->addItem(s.name(), s.path()); - if (s.path() == Config::Current()["Style"]) { + if (s.path() == StyleManager::GetStyle()) { style_->setCurrentIndex(style_->count()-1); } } @@ -62,14 +62,10 @@ PreferencesAppearanceTab::PreferencesAppearanceTab() void PreferencesAppearanceTab::Accept() { QString style_path = style_->currentData().toString(); - StyleManager::SetStyle(style_path); - Config::Current()["Style"] = style_path; - if (style_->currentIndex() < style_list_.size()) { - // This is an internal style, set accordingly - - } else { - StyleManager::SetStyle(style_->currentData().toString()); + if (style_path != StyleManager::GetStyle()) { + StyleManager::SetStyle(style_path); + Config::Current()["Style"] = style_path; } } diff --git a/app/ui/style/style.cpp b/app/ui/style/style.cpp index b85ee80f1..832202450 100644 --- a/app/ui/style/style.cpp +++ b/app/ui/style/style.cpp @@ -28,10 +28,13 @@ #include #include +#include "config/config.h" #include "ui/icons/icons.h" OLIVE_NAMESPACE_ENTER +QString StyleManager::current_style_; + QList StyleManager::ListInternal() { QList style_list; @@ -143,6 +146,22 @@ StyleDescriptor StyleManager::DefaultStyle() return ListInternal().first(); } +const QString &StyleManager::GetStyle() +{ + return current_style_; +} + +void StyleManager::SetStyleFromConfig() +{ + QString config_style = Config::Current()["Style"].toString(); + + if (config_style.isEmpty()) { + SetStyle(DefaultStyle()); + } else { + SetStyle(config_style); + } +} + void StyleManager::SetStyle(const StyleDescriptor &style) { SetStyle(style.path()); @@ -150,6 +169,8 @@ void StyleManager::SetStyle(const StyleDescriptor &style) void StyleManager::SetStyle(const QString &style_path) { + current_style_ = style_path; + // Load all icons for this style (icons must be loaded first because the style change below triggers the icon change) icon::LoadAll(style_path); diff --git a/app/ui/style/style.h b/app/ui/style/style.h index 7b146886d..77f980263 100644 --- a/app/ui/style/style.h +++ b/app/ui/style/style.h @@ -42,10 +42,12 @@ private: class StyleManager : public QObject { public: - StyleManager(); - static StyleDescriptor DefaultStyle(); + static const QString& GetStyle(); + + static void SetStyleFromConfig(); + static void SetStyle(const StyleDescriptor& style); static void SetStyle(const QString& style_path); @@ -62,6 +64,9 @@ private: static void ParsePaletteGroup(QSettings* ini, QPalette* palette, QPalette::ColorGroup group); static void ParsePaletteColor(QSettings* ini, QPalette* palette, QPalette::ColorGroup group, const QString& role_name); + + static QString current_style_; + }; OLIVE_NAMESPACE_EXIT