forked from blue/squawk
color theme setting is now working
This commit is contained in:
parent
0ff9f12157
commit
da19eb86bb
@ -2,10 +2,15 @@
|
||||
|
||||
## Squawk 0.2.1 (UNRELEASED)
|
||||
### Bug fixes
|
||||
- build in release mode now no longer spams warnings
|
||||
- build now correctly installs all build plugin libs
|
||||
|
||||
### Improvements
|
||||
|
||||
### New features
|
||||
- the settings are here! You con config different stuff from there
|
||||
- now it's possible to set up different qt styles from settings
|
||||
- if you have KConfig nad KConfigWidgets packages installed - you can chose from global color schemes
|
||||
|
||||
## Squawk 0.2.0 (Jan 10, 2022)
|
||||
### Bug fixes
|
||||
|
@ -14,6 +14,8 @@
|
||||
- qxmpp 1.1.0 or higher
|
||||
- KDE Frameworks: kwallet (optional)
|
||||
- KDE Frameworks: KIO (optional)
|
||||
- KDE Frameworks: KConfig (optional)
|
||||
- KDE Frameworks: KConfigWidgets (optional)
|
||||
- Boost (just one little hpp from there)
|
||||
- Imagemagick (for compilation, to rasterize an SVG logo)
|
||||
|
||||
@ -92,6 +94,7 @@ Here is the list of keys you can pass to configuration phase of `cmake ..`.
|
||||
- `SYSTEM_QXMPP` - `True` tries to link against `qxmpp` installed in the system, `False` builds bundled `qxmpp` library (default is `True`)
|
||||
- `WITH_KWALLET` - `True` builds the `KWallet` capability module if `KWallet` is installed and if not goes to `False`. `False` disables `KWallet` support (default is `True`)
|
||||
- `WITH_KIO` - `True` builds the `KIO` capability module if `KIO` is installed and if not goes to `False`. `False` disables `KIO` support (default is `True`)
|
||||
- `WITH_KCONFIG` - `True` builds the `KConfig` and `KConfigWidgets` capability module if such packages are installed and if not goes to `False`. `False` disables `KConfig` and `KConfigWidgets` support (default is `True`)
|
||||
|
||||
## License
|
||||
|
||||
|
@ -90,13 +90,24 @@ int main(int argc, char *argv[])
|
||||
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);
|
||||
QVariant vs = settings.value("style");
|
||||
if (vs.isValid()) {
|
||||
QString style = vs.toString().toLower();
|
||||
if (style != "system") {
|
||||
Shared::Global::setStyle(style);
|
||||
}
|
||||
}
|
||||
if (Shared::Global::supported("colorSchemeTools")) {
|
||||
QVariant vt = settings.value("theme");
|
||||
if (vt.isValid()) {
|
||||
QString theme = vt.toString();
|
||||
if (theme.toLower() != "system") {
|
||||
Shared::Global::setTheme(theme);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Squawk w;
|
||||
w.show();
|
||||
|
@ -1,2 +1,4 @@
|
||||
add_library(kwalletWrapper SHARED kwallet.cpp)
|
||||
target_link_libraries(kwalletWrapper PRIVATE KF5::Wallet)
|
||||
|
||||
install(TARGETS kwalletWrapper LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
|
||||
|
@ -8,7 +8,10 @@ url="https://git.macaw.me/blue/squawk"
|
||||
license=('GPL3')
|
||||
depends=('hicolor-icon-theme' 'desktop-file-utils' 'lmdb' 'qxmpp>=1.1.0')
|
||||
makedepends=('cmake>=3.3' 'imagemagick' 'qt5-tools' 'boost')
|
||||
optdepends=('kwallet: secure password storage (requires rebuild)' 'kio: better show in folder action (requires rebuild)')
|
||||
optdepends=('kwallet: secure password storage (requires rebuild)'
|
||||
'kconfig: system themes support (requires rebuild)'
|
||||
'kconfigwidgets: system themes support (requires rebuild)'
|
||||
'kio: better show in folder action (requires rebuild)')
|
||||
|
||||
source=("$pkgname-$pkgver.tar.gz")
|
||||
sha256sums=('8e93d3dbe1fc35cfecb7783af409c6a264244d11609b2241d4fe77d43d068419')
|
||||
|
@ -1,10 +1,14 @@
|
||||
if (WITH_KIO)
|
||||
add_library(openFileManagerWindowJob SHARED openfilemanagerwindowjob.cpp)
|
||||
target_link_libraries(openFileManagerWindowJob PRIVATE KF5::KIOWidgets)
|
||||
|
||||
install(TARGETS openFileManagerWindowJob LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
|
||||
endif ()
|
||||
|
||||
if (WITH_KCONFIG)
|
||||
add_library(colorSchemeTools SHARED colorschemetools.cpp)
|
||||
target_link_libraries(colorSchemeTools PRIVATE KF5::ConfigCore)
|
||||
target_link_libraries(colorSchemeTools PRIVATE KF5::ConfigWidgets)
|
||||
|
||||
install(TARGETS colorSchemeTools LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
|
||||
endif()
|
||||
|
@ -1,7 +1,9 @@
|
||||
#include <QIcon>
|
||||
#include <QPainter>
|
||||
#include <QFileInfo>
|
||||
|
||||
#include <KConfigCore/KSharedConfig>
|
||||
#include <KConfigCore/KConfigGroup>
|
||||
#include <KConfigWidgets/KColorScheme>
|
||||
|
||||
QPixmap createPixmap(int size, const QBrush& window, const QBrush& button, const QBrush& view, const QBrush& selection);
|
||||
@ -24,6 +26,17 @@ extern "C" void deletePreview(QIcon* icon) {
|
||||
delete icon;
|
||||
}
|
||||
|
||||
extern "C" void colorSchemeName(const QString& path, QString& answer) {
|
||||
KSharedConfigPtr config = KSharedConfig::openConfig(path);
|
||||
KConfigGroup group(config, QStringLiteral("General"));
|
||||
answer = group.readEntry("Name", QFileInfo(path).baseName());
|
||||
}
|
||||
|
||||
extern "C" void createPalette(const QString& path, QPalette& answer) {
|
||||
KSharedConfigPtr config = KSharedConfig::openConfig(path);
|
||||
answer = KColorScheme::createApplicationPalette(config);
|
||||
}
|
||||
|
||||
QPixmap createPixmap(int size, const QBrush& window, const QBrush& button, const QBrush& view, const QBrush& selection) {
|
||||
QPixmap pix(size, size);
|
||||
pix.fill(Qt::black);
|
||||
|
@ -32,6 +32,8 @@ Shared::Global::HighlightInFileManager Shared::Global::hfm = 0;
|
||||
QLibrary Shared::Global::colorSchemeTools("colorSchemeTools");
|
||||
Shared::Global::CreatePreview Shared::Global::createPreview = 0;
|
||||
Shared::Global::DeletePreview Shared::Global::deletePreview = 0;
|
||||
Shared::Global::ColorSchemeName Shared::Global::colorSchemeName = 0;
|
||||
Shared::Global::CreatePalette Shared::Global::createPalette = 0;
|
||||
#endif
|
||||
|
||||
Shared::Global::Global():
|
||||
@ -91,6 +93,7 @@ Shared::Global::Global():
|
||||
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()),
|
||||
defaultSystemPalette(QApplication::palette()),
|
||||
pluginSupport({
|
||||
{"KWallet", false},
|
||||
{"openFileManagerWindowJob", false},
|
||||
@ -124,7 +127,9 @@ Shared::Global::Global():
|
||||
if (colorSchemeTools.isLoaded()) {
|
||||
createPreview = (CreatePreview) colorSchemeTools.resolve("createPreview");
|
||||
deletePreview = (DeletePreview) colorSchemeTools.resolve("deletePreview");
|
||||
if (createPreview && deletePreview) {
|
||||
colorSchemeName = (ColorSchemeName) colorSchemeTools.resolve("colorSchemeName");
|
||||
createPalette = (CreatePalette) colorSchemeTools.resolve("createPalette");
|
||||
if (createPreview && deletePreview && colorSchemeName && createPalette) {
|
||||
setSupported("colorSchemeTools", true);
|
||||
qDebug() << "Color Schemes support enabled";
|
||||
} else {
|
||||
@ -311,6 +316,38 @@ QIcon Shared::Global::createThemePreview(const QString& path)
|
||||
}
|
||||
}
|
||||
|
||||
QString Shared::Global::getColorSchemeName(const QString& path)
|
||||
{
|
||||
if (supported("colorSchemeTools")) {
|
||||
QString res;
|
||||
colorSchemeName(path, res);
|
||||
return res;
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
void Shared::Global::setTheme(const QString& path)
|
||||
{
|
||||
if (supported("colorSchemeTools")) {
|
||||
if (path.toLower() == "system") {
|
||||
QApplication::setPalette(getInstance()->defaultSystemPalette);
|
||||
} else {
|
||||
QPalette pallete;
|
||||
createPalette(path, pallete);
|
||||
QApplication::setPalette(pallete);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Shared::Global::setStyle(const QString& style)
|
||||
{
|
||||
if (style.toLower() == "system") {
|
||||
QApplication::setStyle(getInstance()->defaultSystemStyle);
|
||||
} else {
|
||||
QApplication::setStyle(style);
|
||||
}
|
||||
}
|
||||
|
||||
#define FROM_INT_INPL(Enum) \
|
||||
template<> \
|
||||
|
@ -87,6 +87,7 @@ namespace Shared {
|
||||
const std::deque<QString> accountPasswordDescription;
|
||||
|
||||
const QString defaultSystemStyle;
|
||||
const QPalette defaultSystemPalette;
|
||||
|
||||
static bool supported(const QString& pluginName);
|
||||
static void setSupported(const QString& pluginName, bool support);
|
||||
@ -96,6 +97,9 @@ namespace Shared {
|
||||
static FileInfo getFileInfo(const QString& path);
|
||||
static void highlightInFileManager(const QString& path);
|
||||
static QIcon createThemePreview(const QString& path);
|
||||
static QString getColorSchemeName(const QString& path);
|
||||
static void setTheme(const QString& path);
|
||||
static void setStyle(const QString& style);
|
||||
|
||||
template<typename T>
|
||||
static T fromInt(int src);
|
||||
@ -135,9 +139,13 @@ namespace Shared {
|
||||
|
||||
typedef QIcon* (*CreatePreview)(const QString&);
|
||||
typedef void (*DeletePreview)(QIcon*);
|
||||
typedef void (*ColorSchemeName)(const QString&, QString&);
|
||||
typedef void (*CreatePalette)(const QString&, QPalette&);
|
||||
|
||||
static CreatePreview createPreview;
|
||||
static DeletePreview deletePreview;
|
||||
static ColorSchemeName colorSchemeName;
|
||||
static CreatePalette createPalette;
|
||||
#endif
|
||||
};
|
||||
}
|
||||
|
@ -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…
Reference in New Issue
Block a user