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.
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -28,10 +28,13 @@
|
||||
#include <QStyleFactory>
|
||||
#include <QTextStream>
|
||||
|
||||
#include "config/config.h"
|
||||
#include "ui/icons/icons.h"
|
||||
|
||||
OLIVE_NAMESPACE_ENTER
|
||||
|
||||
QString StyleManager::current_style_;
|
||||
|
||||
QList<StyleDescriptor> StyleManager::ListInternal()
|
||||
{
|
||||
QList<StyleDescriptor> 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);
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user