squawk/ui/widgets/settings/pageappearance.cpp

105 lines
3.3 KiB
C++
Raw Normal View History

/*
* Squawk messenger.
* Copyright (C) 2019 Yury Gubich <blue@macaw.me>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#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]);
}
}