color theme setting is now working
This commit is contained in:
parent
0ff9f12157
commit
da19eb86bb
13 changed files with 142 additions and 33 deletions
|
@ -10,41 +10,59 @@ static const QStringList filters = {"*.colors"};
|
|||
PageAppearance::PageAppearance(QWidget* parent):
|
||||
QWidget(parent),
|
||||
m_ui(new Ui::PageAppearance()),
|
||||
styles()
|
||||
styles(),
|
||||
themes()
|
||||
{
|
||||
m_ui->setupUi(this);
|
||||
|
||||
m_ui->themeInput->addItem(tr("System"));
|
||||
m_ui->styleInput->addItem(tr("System"));
|
||||
styles.push_back("system");
|
||||
QStringList themes = QStyleFactory::keys();
|
||||
for (const QString& key : themes) {
|
||||
m_ui->themeInput->addItem(key);
|
||||
QStringList systemStyles = QStyleFactory::keys();
|
||||
for (const QString& key : systemStyles) {
|
||||
m_ui->styleInput->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);
|
||||
QVariant vs = settings.value("style");
|
||||
if (vs.isValid()) {
|
||||
m_ui->styleInput->setCurrentText(vs.toString());
|
||||
} else {
|
||||
m_ui->themeInput->setCurrentText("System");
|
||||
m_ui->styleInput->setCurrentText(tr("System"));
|
||||
}
|
||||
|
||||
connect(m_ui->themeInput, qOverload<int>(&QComboBox::currentIndexChanged), this, &PageAppearance::onThemeChanged);
|
||||
connect(m_ui->styleInput, qOverload<int>(&QComboBox::currentIndexChanged), this, &PageAppearance::onStyleChanged);
|
||||
|
||||
if (Shared::Global::supported("colorSchemeTools")) {
|
||||
m_ui->colorInput->addItem(tr("System"));
|
||||
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) {
|
||||
m_ui->colorInput->addItem(Shared::Global::createThemePreview(dir + QDir::separator() + file), file);
|
||||
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->colorInput->setEnabled(false);
|
||||
m_ui->themeInput->setEnabled(false);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -55,8 +73,14 @@ PageAppearance::~PageAppearance()
|
|||
void PageAppearance::onThemeChanged(int index)
|
||||
{
|
||||
if (index >= 0) {
|
||||
emit variableModified("theme", styles[index]);
|
||||
emit variableModified("theme", themes[index]);
|
||||
}
|
||||
}
|
||||
|
||||
void PageAppearance::onStyleChanged(int index)
|
||||
{
|
||||
if (index >= 0) {
|
||||
emit variableModified("style", styles[index]);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -29,11 +29,13 @@ signals:
|
|||
void variableModified(const QString& key, const QVariant& value);
|
||||
|
||||
protected slots:
|
||||
void onStyleChanged(int index);
|
||||
void onThemeChanged(int index);
|
||||
|
||||
private:
|
||||
QScopedPointer<Ui::PageAppearance> m_ui;
|
||||
std::vector<QString> styles;
|
||||
std::vector<QString> themes;
|
||||
};
|
||||
|
||||
#endif // PAGEAPPEARANCE_H
|
||||
|
|
|
@ -12,20 +12,20 @@
|
|||
</property>
|
||||
<layout class="QFormLayout" name="formLayout">
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="themeLabel">
|
||||
<widget class="QLabel" name="styleLabel">
|
||||
<property name="text">
|
||||
<string>Theme</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QComboBox" name="themeInput"/>
|
||||
<widget class="QComboBox" name="styleInput"/>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QComboBox" name="colorInput"/>
|
||||
<widget class="QComboBox" name="themeInput"/>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="colorLabel">
|
||||
<widget class="QLabel" name="themeLabel">
|
||||
<property name="text">
|
||||
<string>Color scheme</string>
|
||||
</property>
|
||||
|
|
|
@ -40,13 +40,10 @@ 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);
|
||||
}
|
||||
if (pair.first == "style") {
|
||||
Shared::Global::setStyle(pair.second.toString());
|
||||
} else if (pair.first == "theme") {
|
||||
Shared::Global::setTheme(pair.second.toString());
|
||||
}
|
||||
|
||||
settings.setValue(pair.first, pair.second);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue