basic theme changing

This commit is contained in:
Blue 2022-01-21 22:02:50 +03:00
parent a8a7ce2538
commit c708c33a92
Signed by: blue
GPG Key ID: 9B203B252A63EE38
8 changed files with 108 additions and 4 deletions

View File

@ -55,7 +55,7 @@ int main(int argc, char *argv[])
QApplication::setApplicationName("squawk"); QApplication::setApplicationName("squawk");
QApplication::setApplicationDisplayName("Squawk"); QApplication::setApplicationDisplayName("Squawk");
QApplication::setApplicationVersion("0.2.1"); QApplication::setApplicationVersion("0.2.1");
QTranslator qtTranslator; QTranslator qtTranslator;
qtTranslator.load("qt_" + QLocale::system().name(), QLibraryInfo::location(QLibraryInfo::TranslationsPath)); qtTranslator.load("qt_" + QLocale::system().name(), QLibraryInfo::location(QLibraryInfo::TranslationsPath));
app.installTranslator(&qtTranslator); app.installTranslator(&qtTranslator);
@ -88,6 +88,15 @@ int main(int argc, char *argv[])
QApplication::setWindowIcon(icon); QApplication::setWindowIcon(icon);
new Shared::Global(); //translates enums new Shared::Global(); //translates enums
QSettings settings;
QVariant vtheme = settings.value("theme");
if (vtheme.isValid()) {
QString theme = vtheme.toString().toLower();
if (theme != "system") {
QApplication::setStyle(theme);
}
}
Squawk w; Squawk w;
w.show(); w.show();

View File

@ -84,6 +84,7 @@ Shared::Global::Global():
tr("Squawk is going to query you for the password on every start of the program", "AccountPasswordDescription"), tr("Squawk is going to query you for the password on every start of the program", "AccountPasswordDescription"),
tr("Your password is going to be stored in KDE wallet storage (KWallet). You're going to be queried for permissions", "AccountPasswordDescription") tr("Your password is going to be stored in KDE wallet storage (KWallet). You're going to be queried for permissions", "AccountPasswordDescription")
}), }),
defaultSystemStyle(QApplication::style()->objectName()),
pluginSupport({ pluginSupport({
{"KWallet", false}, {"KWallet", false},
{"openFileManagerWindowJob", false} {"openFileManagerWindowJob", false}

View File

@ -27,7 +27,8 @@
#include <set> #include <set>
#include <deque> #include <deque>
#include <QCoreApplication> #include <QApplication>
#include <QStyle>
#include <QDebug> #include <QDebug>
#include <QMimeType> #include <QMimeType>
#include <QMimeDatabase> #include <QMimeDatabase>
@ -84,6 +85,8 @@ namespace Shared {
const std::deque<QString> accountPassword; const std::deque<QString> accountPassword;
const std::deque<QString> accountPasswordDescription; const std::deque<QString> accountPasswordDescription;
const QString defaultSystemStyle;
static bool supported(const QString& pluginName); static bool supported(const QString& pluginName);
static void setSupported(const QString& pluginName, bool support); static void setSupported(const QString& pluginName, bool support);

View File

@ -1,13 +1,42 @@
#include "pageappearance.h" #include "pageappearance.h"
#include "ui_pageappearance.h" #include "ui_pageappearance.h"
#include <QDebug>
PageAppearance::PageAppearance(QWidget* parent): PageAppearance::PageAppearance(QWidget* parent):
QWidget(parent), QWidget(parent),
m_ui(new Ui::PageAppearance()) m_ui(new Ui::PageAppearance()),
styles()
{ {
m_ui->setupUi(this); m_ui->setupUi(this);
m_ui->themeInput->addItem(tr("System"));
styles.push_back("system");
QStringList themes = QStyleFactory::keys();
for (const QString& key : themes) {
m_ui->themeInput->addItem(key);
styles.push_back(key);
}
QSettings settings;
QVariant vtheme = settings.value("theme");
if (vtheme.isValid()) {
QString theme = vtheme.toString();
m_ui->themeInput->setCurrentText(theme);
} else {
m_ui->themeInput->setCurrentText("System");
}
connect(m_ui->themeInput, qOverload<int>(&QComboBox::currentIndexChanged), this, &PageAppearance::onThemeChanged);
} }
PageAppearance::~PageAppearance() PageAppearance::~PageAppearance()
{ {
} }
void PageAppearance::onThemeChanged(int index)
{
if (index >= 0) {
emit variableModified("theme", styles[index]);
}
}

View File

@ -3,6 +3,10 @@
#include <QWidget> #include <QWidget>
#include <QScopedPointer> #include <QScopedPointer>
#include <QStyleFactory>
#include <QVariant>
#include <QSettings>
#include <vector>
namespace Ui namespace Ui
{ {
@ -19,8 +23,15 @@ public:
PageAppearance(QWidget* parent = nullptr); PageAppearance(QWidget* parent = nullptr);
~PageAppearance(); ~PageAppearance();
signals:
void variableModified(const QString& key, const QVariant& value);
protected slots:
void onThemeChanged(int index);
private: private:
QScopedPointer<Ui::PageAppearance> m_ui; QScopedPointer<Ui::PageAppearance> m_ui;
std::vector<QString> styles;
}; };
#endif // PAGEAPPEARANCE_H #endif // PAGEAPPEARANCE_H

View File

@ -3,6 +3,7 @@
#include <QWidget> #include <QWidget>
#include <QScopedPointer> #include <QScopedPointer>
#include <QVariant>
namespace Ui namespace Ui
{ {
@ -19,6 +20,9 @@ public:
PageGeneral(QWidget* parent = nullptr); PageGeneral(QWidget* parent = nullptr);
~PageGeneral(); ~PageGeneral();
signals:
void variableModified(const QString& key, const QVariant& value);
private: private:
QScopedPointer<Ui::PageGeneral> m_ui; QScopedPointer<Ui::PageGeneral> m_ui;
}; };

View File

@ -3,11 +3,19 @@
Settings::Settings(QWidget* parent): Settings::Settings(QWidget* parent):
QWidget(parent), QWidget(parent),
m_ui(new Ui::Settings()) m_ui(new Ui::Settings()),
modifiedSettings()
{ {
m_ui->setupUi(this); m_ui->setupUi(this);
connect(m_ui->list, &QListWidget::currentItemChanged, this, &Settings::onCurrentPageChanged); connect(m_ui->list, &QListWidget::currentItemChanged, this, &Settings::onCurrentPageChanged);
connect(m_ui->General, &PageGeneral::variableModified, this, &Settings::onVariableModified);
connect(m_ui->Appearance, &PageAppearance::variableModified, this, &Settings::onVariableModified);
connect(m_ui->applyButton, &QPushButton::clicked, this, &Settings::apply);
connect(m_ui->okButton, &QPushButton::clicked, this, &Settings::confirm);
connect(m_ui->cancelButton, &QPushButton::clicked, this, &Settings::close);
} }
Settings::~Settings() Settings::~Settings()
@ -22,3 +30,33 @@ void Settings::onCurrentPageChanged(QListWidgetItem* current)
m_ui->content->setCurrentIndex(m_ui->list->currentRow()); m_ui->content->setCurrentIndex(m_ui->list->currentRow());
} }
} }
void Settings::onVariableModified(const QString& key, const QVariant& value)
{
modifiedSettings[key] = value;
}
void Settings::apply()
{
QSettings settings;
for (const std::pair<const QString, QVariant>& pair: modifiedSettings) {
if (pair.first == "theme") {
QString theme = pair.second.toString();
if (theme.toLower() == "system") {
QApplication::setStyle(Shared::Global::getInstance()->defaultSystemStyle);
} else {
QApplication::setStyle(theme);
}
}
settings.setValue(pair.first, pair.second);
}
modifiedSettings.clear();
}
void Settings::confirm()
{
apply();
close();
}

View File

@ -4,6 +4,9 @@
#include <QWidget> #include <QWidget>
#include <QListWidgetItem> #include <QListWidgetItem>
#include <QScopedPointer> #include <QScopedPointer>
#include <QSettings>
#include "shared/global.h"
namespace Ui namespace Ui
{ {
@ -20,11 +23,17 @@ public:
Settings(QWidget* parent = nullptr); Settings(QWidget* parent = nullptr);
~Settings(); ~Settings();
public slots:
void apply();
void confirm();
protected slots: protected slots:
void onCurrentPageChanged(QListWidgetItem* current); void onCurrentPageChanged(QListWidgetItem* current);
void onVariableModified(const QString& key, const QVariant& value);
private: private:
QScopedPointer<Ui::Settings> m_ui; QScopedPointer<Ui::Settings> m_ui;
std::map<QString, QVariant> modifiedSettings;
}; };
#endif // SETTINGS_H #endif // SETTINGS_H