87 lines
2.5 KiB
C++
87 lines
2.5 KiB
C++
#include "pageappearance.h"
|
|
#include "ui_pageappearance.h"
|
|
|
|
#include <QDebug>
|
|
#include <QStandardPaths>
|
|
#include <QDir>
|
|
|
|
static const QStringList filters = {"*.colors"};
|
|
|
|
PageAppearance::PageAppearance(QWidget* parent):
|
|
QWidget(parent),
|
|
m_ui(new Ui::PageAppearance()),
|
|
styles(),
|
|
themes()
|
|
{
|
|
m_ui->setupUi(this);
|
|
|
|
m_ui->styleInput->addItem(tr("System"));
|
|
styles.push_back("system");
|
|
QStringList systemStyles = QStyleFactory::keys();
|
|
for (const QString& key : systemStyles) {
|
|
m_ui->styleInput->addItem(key);
|
|
styles.push_back(key);
|
|
}
|
|
|
|
QSettings settings;
|
|
QVariant vs = settings.value("style");
|
|
if (vs.isValid()) {
|
|
m_ui->styleInput->setCurrentText(vs.toString());
|
|
} else {
|
|
m_ui->styleInput->setCurrentText(tr("System"));
|
|
}
|
|
|
|
connect(m_ui->styleInput, qOverload<int>(&QComboBox::currentIndexChanged), this, &PageAppearance::onStyleChanged);
|
|
|
|
if (Shared::Global::supported("colorSchemeTools")) {
|
|
themes.push_back("system");
|
|
m_ui->themeInput->addItem(tr("System"));
|
|
const QStringList dirs = QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, "color-schemes", QStandardPaths::LocateDirectory);
|
|
QStringList schemeFiles;
|
|
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) {
|
|
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;
|
|
}
|
|
}
|
|
}
|
|
|
|
m_ui->themeInput->setCurrentText(currentTheme);
|
|
|
|
connect(m_ui->themeInput, qOverload<int>(&QComboBox::currentIndexChanged), this, &PageAppearance::onThemeChanged);
|
|
} else {
|
|
m_ui->themeInput->setEnabled(false);
|
|
}
|
|
}
|
|
|
|
PageAppearance::~PageAppearance()
|
|
{
|
|
}
|
|
|
|
void PageAppearance::onThemeChanged(int index)
|
|
{
|
|
if (index >= 0) {
|
|
emit variableModified("theme", themes[index]);
|
|
}
|
|
}
|
|
|
|
void PageAppearance::onStyleChanged(int index)
|
|
{
|
|
if (index >= 0) {
|
|
emit variableModified("style", styles[index]);
|
|
}
|
|
}
|
|
|