config: save style

This commit is contained in:
itsmattkc
2020-08-10 21:37:04 +10:00
parent 03e33227b3
commit 08d4c7b385
6 changed files with 43 additions and 85 deletions
+2
View File
@@ -31,6 +31,7 @@
#include "common/filefunctions.h"
#include "common/xmlutils.h"
#include "core.h"
#include "ui/style/style.h"
#include "window/mainwindow/mainwindow.h"
OLIVE_NAMESPACE_ENTER
@@ -60,6 +61,7 @@ Config &Config::Current()
void Config::SetDefaults()
{
config_map_.clear();
SetEntryInternal(QStringLiteral("Style"), NodeParam::kString, StyleManager::kDefaultStyle);
SetEntryInternal(QStringLiteral("TimecodeDisplay"), NodeParam::kInt, Timecode::kTimecodeDropFrame);
SetEntryInternal(QStringLiteral("DefaultStillLength"), NodeParam::kRational, QVariant::fromValue(rational(2)));
SetEntryInternal(QStringLiteral("HoverFocus"), NodeParam::kBoolean, false);
+1 -2
View File
@@ -669,8 +669,7 @@ void Core::OpenStartupProject()
void Core::StartGUI(bool full_screen)
{
// Set UI style
qApp->setStyle(QStyleFactory::create("Fusion"));
StyleManager::SetStyle(StyleManager::DefaultStyle());
StyleManager::Init();
// Set up shared menus
MenuShared::CreateInstance();
@@ -44,19 +44,19 @@ PreferencesAppearanceTab::PreferencesAppearanceTab()
// Appearance -> Theme
appearance_layout->addWidget(new QLabel(tr("Theme")), row, 0);
style_ = new QComboBox();
style_combobox_ = new QComboBox();
style_list_ = StyleManager::ListInternal();
const QMap<QString, QString>& themes = StyleManager::available_themes();
QMap<QString, QString>::const_iterator i;
for (i=themes.cbegin(); i!=themes.cend(); i++) {
style_combobox_->addItem(i.value(), i.key());
foreach (const StyleDescriptor& s, style_list_) {
style_->addItem(s.name(), s.path());
if (s.path() == StyleManager::GetStyle()) {
style_->setCurrentIndex(style_->count()-1);
if (StyleManager::GetStyle() == i.key()) {
style_combobox_->setCurrentIndex(style_combobox_->count()-1);
}
}
appearance_layout->addWidget(style_, row, 1);
appearance_layout->addWidget(style_combobox_, row, 1);
row++;
@@ -89,7 +89,7 @@ PreferencesAppearanceTab::PreferencesAppearanceTab()
void PreferencesAppearanceTab::Accept()
{
QString style_path = style_->currentData().toString();
QString style_path = style_combobox_->currentData().toString();
if (style_path != StyleManager::GetStyle()) {
StyleManager::SetStyle(style_path);
@@ -49,14 +49,7 @@ private:
/**
* @brief UI widget for selecting the current UI style
*/
QComboBox* style_;
/**
* @brief List of internal styles
*/
QList<StyleDescriptor> style_list_;
QString custom_style_path_;
QComboBox* style_combobox_;
QList<QColor> colors_;
+20 -47
View File
@@ -33,17 +33,9 @@
OLIVE_NAMESPACE_ENTER
const char* StyleManager::kDefaultStyle = "olive-dark";
QString StyleManager::current_style_;
QList<StyleDescriptor> StyleManager::ListInternal()
{
QList<StyleDescriptor> style_list;
style_list.append(StyleDescriptor(tr("Olive Dark"), ":/style/olive-dark"));
style_list.append(StyleDescriptor(tr("Olive Light"), ":/style/olive-light"));
return style_list;
}
QMap<QString, QString> StyleManager::available_themes_;
void StyleManager::UseOSNativeStyling(QWidget *widget)
{
@@ -145,9 +137,20 @@ void StyleManager::ParsePaletteColor(QSettings *ini, QPalette *palette, QPalette
palette->setColor(group, role, QColor(ini->value(role_name).toString()));
}
StyleDescriptor StyleManager::DefaultStyle()
void StyleManager::Init()
{
return ListInternal().first();
qApp->setStyle(QStyleFactory::create("Fusion"));
available_themes_.insert(QStringLiteral("olive-dark"), QStringLiteral("Olive Dark"));
available_themes_.insert(QStringLiteral("olive-light"), QStringLiteral("Olive Light"));
QString config_style = Config::Current()["Style"].toString();
if (config_style.isEmpty() || !available_themes_.contains(config_style)) {
SetStyle(kDefaultStyle);
} else {
SetStyle(config_style);
}
}
const QString &StyleManager::GetStyle()
@@ -155,31 +158,17 @@ 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());
}
void StyleManager::SetStyle(const QString &style_path)
{
current_style_ = style_path;
QString abs_style_path = QStringLiteral(":/style/%1").arg(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);
icon::LoadAll(abs_style_path);
// Set palette for this
QString palette_file = QStringLiteral("%1/palette.ini").arg(style_path);
QString palette_file = QStringLiteral("%1/palette.ini").arg(abs_style_path);
if (QFileInfo::exists(palette_file)) {
qApp->setPalette(ParsePalette(palette_file));
} else {
@@ -187,7 +176,7 @@ void StyleManager::SetStyle(const QString &style_path)
}
// Set CSS style for this
QFile css_file(QStringLiteral("%1/style.css").arg(style_path));
QFile css_file(QStringLiteral("%1/style.css").arg(abs_style_path));
if (css_file.exists() && css_file.open(QFile::ReadOnly | QFile::Text)) {
// Read in entire CSS from file and set as the application stylesheet
@@ -201,20 +190,4 @@ void StyleManager::SetStyle(const QString &style_path)
}
}
StyleDescriptor::StyleDescriptor(const QString &name, const QString &path) :
name_(name),
path_(path)
{
}
const QString &StyleDescriptor::name() const
{
return name_;
}
const QString &StyleDescriptor::path() const
{
return path_;
}
OLIVE_NAMESPACE_EXIT
+10 -19
View File
@@ -28,34 +28,23 @@
OLIVE_NAMESPACE_ENTER
class StyleDescriptor {
public:
StyleDescriptor(const QString& name, const QString& path);
const QString& name() const;
const QString& path() const;
private:
QString name_;
QString path_;
};
class StyleManager : public QObject {
public:
static StyleDescriptor DefaultStyle();
static void Init();
static const QString& GetStyle();
static void SetStyleFromConfig();
static void SetStyle(const StyleDescriptor& style);
static void SetStyle(const QString& style_path);
static QList<StyleDescriptor> ListInternal();
static void UseOSNativeStyling(QWidget* widget);
static const char* kDefaultStyle;
static const QMap<QString, QString>& available_themes()
{
return available_themes_;
}
private:
static QPalette ParsePalette(const QString& ini_path);
@@ -65,6 +54,8 @@ private:
static QString current_style_;
static QMap<QString, QString> available_themes_;
};
OLIVE_NAMESPACE_EXIT