1
0
forked from blue/squawk
squawk/ui/widgets/settings/pageappearance.cpp

87 lines
2.5 KiB
C++
Raw Normal View History

#include "pageappearance.h"
#include "ui_pageappearance.h"
2022-01-21 19:02:50 +00:00
#include <QDebug>
2022-01-25 20:35:55 +00:00
#include <QStandardPaths>
#include <QDir>
static const QStringList filters = {"*.colors"};
2022-01-21 19:02:50 +00:00
PageAppearance::PageAppearance(QWidget* parent):
QWidget(parent),
2022-01-21 19:02:50 +00:00
m_ui(new Ui::PageAppearance()),
2022-01-27 17:44:32 +00:00
styles(),
themes()
{
m_ui->setupUi(this);
2022-01-21 19:02:50 +00:00
2022-01-27 17:44:32 +00:00
m_ui->styleInput->addItem(tr("System"));
2022-01-21 19:02:50 +00:00
styles.push_back("system");
2022-01-27 17:44:32 +00:00
QStringList systemStyles = QStyleFactory::keys();
for (const QString& key : systemStyles) {
m_ui->styleInput->addItem(key);
2022-01-21 19:02:50 +00:00
styles.push_back(key);
}
QSettings settings;
2022-01-27 17:44:32 +00:00
QVariant vs = settings.value("style");
if (vs.isValid()) {
m_ui->styleInput->setCurrentText(vs.toString());
2022-01-21 19:02:50 +00:00
} else {
2022-01-27 17:44:32 +00:00
m_ui->styleInput->setCurrentText(tr("System"));
2022-01-21 19:02:50 +00:00
}
2022-01-27 17:44:32 +00:00
connect(m_ui->styleInput, qOverload<int>(&QComboBox::currentIndexChanged), this, &PageAppearance::onStyleChanged);
2022-01-25 20:35:55 +00:00
if (Shared::Global::supported("colorSchemeTools")) {
2022-01-27 17:44:32 +00:00
themes.push_back("system");
m_ui->themeInput->addItem(tr("System"));
const QStringList dirs = QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, "color-schemes", QStandardPaths::LocateDirectory);
QStringList schemeFiles;
2022-01-27 17:44:32 +00:00
QString currentTheme(tr("System"));
QString requestedTheme("");
QVariant vtheme = settings.value("theme");
if (vtheme.isValid()) {
requestedTheme = vtheme.toString();
}
for (const QString &dir : dirs) {
const QStringList fileNames = QDir(dir).entryList(filters);
for (const QString &file : fileNames) {
2022-01-27 17:44:32 +00:00
QString path = dir + QDir::separator() + file;
themes.push_back(path);
QString themeName = Shared::Global::getColorSchemeName(path);
m_ui->themeInput->addItem(Shared::Global::createThemePreview(path), themeName);
if (path == requestedTheme) {
currentTheme = themeName;
}
}
2022-01-25 20:35:55 +00:00
}
2022-01-27 17:44:32 +00:00
m_ui->themeInput->setCurrentText(currentTheme);
connect(m_ui->themeInput, qOverload<int>(&QComboBox::currentIndexChanged), this, &PageAppearance::onThemeChanged);
} else {
2022-01-27 17:44:32 +00:00
m_ui->themeInput->setEnabled(false);
2022-01-25 20:35:55 +00:00
}
}
PageAppearance::~PageAppearance()
{
}
2022-01-21 19:02:50 +00:00
void PageAppearance::onThemeChanged(int index)
{
if (index >= 0) {
2022-01-27 17:44:32 +00:00
emit variableModified("theme", themes[index]);
2022-01-21 19:02:50 +00:00
}
}
2022-01-27 17:44:32 +00:00
void PageAppearance::onStyleChanged(int index)
{
if (index >= 0) {
emit variableModified("style", styles[index]);
}
}