color theme setting is now working

This commit is contained in:
Blue 2022-01-27 20:44:32 +03:00
parent 0ff9f12157
commit da19eb86bb
Signed by untrusted user: blue
GPG Key ID: 9B203B252A63EE38
13 changed files with 142 additions and 33 deletions

View File

@ -2,10 +2,15 @@
## Squawk 0.2.1 (UNRELEASED) ## Squawk 0.2.1 (UNRELEASED)
### Bug fixes ### Bug fixes
- build in release mode now no longer spams warnings
- build now correctly installs all build plugin libs
### Improvements ### Improvements
### New features ### 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) ## Squawk 0.2.0 (Jan 10, 2022)
### Bug fixes ### Bug fixes

View File

@ -14,6 +14,8 @@
- qxmpp 1.1.0 or higher - qxmpp 1.1.0 or higher
- KDE Frameworks: kwallet (optional) - KDE Frameworks: kwallet (optional)
- KDE Frameworks: KIO (optional) - KDE Frameworks: KIO (optional)
- KDE Frameworks: KConfig (optional)
- KDE Frameworks: KConfigWidgets (optional)
- Boost (just one little hpp from there) - Boost (just one little hpp from there)
- Imagemagick (for compilation, to rasterize an SVG logo) - 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`) - `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_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_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 ## License

View File

@ -90,13 +90,24 @@ int main(int argc, char *argv[])
new Shared::Global(); //translates enums new Shared::Global(); //translates enums
QSettings settings; QSettings settings;
QVariant vtheme = settings.value("theme"); QVariant vs = settings.value("style");
if (vtheme.isValid()) { if (vs.isValid()) {
QString theme = vtheme.toString().toLower(); QString style = vs.toString().toLower();
if (theme != "system") { if (style != "system") {
QApplication::setStyle(theme); 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; Squawk w;
w.show(); w.show();

View File

@ -1,2 +1,4 @@
add_library(kwalletWrapper SHARED kwallet.cpp) add_library(kwalletWrapper SHARED kwallet.cpp)
target_link_libraries(kwalletWrapper PRIVATE KF5::Wallet) target_link_libraries(kwalletWrapper PRIVATE KF5::Wallet)
install(TARGETS kwalletWrapper LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})

View File

@ -8,7 +8,10 @@ url="https://git.macaw.me/blue/squawk"
license=('GPL3') license=('GPL3')
depends=('hicolor-icon-theme' 'desktop-file-utils' 'lmdb' 'qxmpp>=1.1.0') depends=('hicolor-icon-theme' 'desktop-file-utils' 'lmdb' 'qxmpp>=1.1.0')
makedepends=('cmake>=3.3' 'imagemagick' 'qt5-tools' 'boost') 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") source=("$pkgname-$pkgver.tar.gz")
sha256sums=('8e93d3dbe1fc35cfecb7783af409c6a264244d11609b2241d4fe77d43d068419') sha256sums=('8e93d3dbe1fc35cfecb7783af409c6a264244d11609b2241d4fe77d43d068419')

View File

@ -1,10 +1,14 @@
if (WITH_KIO) if (WITH_KIO)
add_library(openFileManagerWindowJob SHARED openfilemanagerwindowjob.cpp) add_library(openFileManagerWindowJob SHARED openfilemanagerwindowjob.cpp)
target_link_libraries(openFileManagerWindowJob PRIVATE KF5::KIOWidgets) target_link_libraries(openFileManagerWindowJob PRIVATE KF5::KIOWidgets)
install(TARGETS openFileManagerWindowJob LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
endif () endif ()
if (WITH_KCONFIG) if (WITH_KCONFIG)
add_library(colorSchemeTools SHARED colorschemetools.cpp) add_library(colorSchemeTools SHARED colorschemetools.cpp)
target_link_libraries(colorSchemeTools PRIVATE KF5::ConfigCore) target_link_libraries(colorSchemeTools PRIVATE KF5::ConfigCore)
target_link_libraries(colorSchemeTools PRIVATE KF5::ConfigWidgets) target_link_libraries(colorSchemeTools PRIVATE KF5::ConfigWidgets)
install(TARGETS colorSchemeTools LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
endif() endif()

View File

@ -1,7 +1,9 @@
#include <QIcon> #include <QIcon>
#include <QPainter> #include <QPainter>
#include <QFileInfo>
#include <KConfigCore/KSharedConfig> #include <KConfigCore/KSharedConfig>
#include <KConfigCore/KConfigGroup>
#include <KConfigWidgets/KColorScheme> #include <KConfigWidgets/KColorScheme>
QPixmap createPixmap(int size, const QBrush& window, const QBrush& button, const QBrush& view, const QBrush& selection); 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; 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 createPixmap(int size, const QBrush& window, const QBrush& button, const QBrush& view, const QBrush& selection) {
QPixmap pix(size, size); QPixmap pix(size, size);
pix.fill(Qt::black); pix.fill(Qt::black);

View File

@ -32,6 +32,8 @@ Shared::Global::HighlightInFileManager Shared::Global::hfm = 0;
QLibrary Shared::Global::colorSchemeTools("colorSchemeTools"); QLibrary Shared::Global::colorSchemeTools("colorSchemeTools");
Shared::Global::CreatePreview Shared::Global::createPreview = 0; Shared::Global::CreatePreview Shared::Global::createPreview = 0;
Shared::Global::DeletePreview Shared::Global::deletePreview = 0; Shared::Global::DeletePreview Shared::Global::deletePreview = 0;
Shared::Global::ColorSchemeName Shared::Global::colorSchemeName = 0;
Shared::Global::CreatePalette Shared::Global::createPalette = 0;
#endif #endif
Shared::Global::Global(): 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") 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()), defaultSystemStyle(QApplication::style()->objectName()),
defaultSystemPalette(QApplication::palette()),
pluginSupport({ pluginSupport({
{"KWallet", false}, {"KWallet", false},
{"openFileManagerWindowJob", false}, {"openFileManagerWindowJob", false},
@ -124,7 +127,9 @@ Shared::Global::Global():
if (colorSchemeTools.isLoaded()) { if (colorSchemeTools.isLoaded()) {
createPreview = (CreatePreview) colorSchemeTools.resolve("createPreview"); createPreview = (CreatePreview) colorSchemeTools.resolve("createPreview");
deletePreview = (DeletePreview) colorSchemeTools.resolve("deletePreview"); 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); setSupported("colorSchemeTools", true);
qDebug() << "Color Schemes support enabled"; qDebug() << "Color Schemes support enabled";
} else { } 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) \ #define FROM_INT_INPL(Enum) \
template<> \ template<> \

View File

@ -87,6 +87,7 @@ namespace Shared {
const std::deque<QString> accountPasswordDescription; const std::deque<QString> accountPasswordDescription;
const QString defaultSystemStyle; const QString defaultSystemStyle;
const QPalette defaultSystemPalette;
static bool supported(const QString& pluginName); static bool supported(const QString& pluginName);
static void setSupported(const QString& pluginName, bool support); static void setSupported(const QString& pluginName, bool support);
@ -96,6 +97,9 @@ namespace Shared {
static FileInfo getFileInfo(const QString& path); static FileInfo getFileInfo(const QString& path);
static void highlightInFileManager(const QString& path); static void highlightInFileManager(const QString& path);
static QIcon createThemePreview(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> template<typename T>
static T fromInt(int src); static T fromInt(int src);
@ -135,9 +139,13 @@ namespace Shared {
typedef QIcon* (*CreatePreview)(const QString&); typedef QIcon* (*CreatePreview)(const QString&);
typedef void (*DeletePreview)(QIcon*); typedef void (*DeletePreview)(QIcon*);
typedef void (*ColorSchemeName)(const QString&, QString&);
typedef void (*CreatePalette)(const QString&, QPalette&);
static CreatePreview createPreview; static CreatePreview createPreview;
static DeletePreview deletePreview; static DeletePreview deletePreview;
static ColorSchemeName colorSchemeName;
static CreatePalette createPalette;
#endif #endif
}; };
} }

View File

@ -10,41 +10,59 @@ static const QStringList filters = {"*.colors"};
PageAppearance::PageAppearance(QWidget* parent): PageAppearance::PageAppearance(QWidget* parent):
QWidget(parent), QWidget(parent),
m_ui(new Ui::PageAppearance()), m_ui(new Ui::PageAppearance()),
styles() styles(),
themes()
{ {
m_ui->setupUi(this); m_ui->setupUi(this);
m_ui->themeInput->addItem(tr("System")); m_ui->styleInput->addItem(tr("System"));
styles.push_back("system"); styles.push_back("system");
QStringList themes = QStyleFactory::keys(); QStringList systemStyles = QStyleFactory::keys();
for (const QString& key : themes) { for (const QString& key : systemStyles) {
m_ui->themeInput->addItem(key); m_ui->styleInput->addItem(key);
styles.push_back(key); styles.push_back(key);
} }
QSettings settings; QSettings settings;
QVariant vtheme = settings.value("theme"); QVariant vs = settings.value("style");
if (vtheme.isValid()) { if (vs.isValid()) {
QString theme = vtheme.toString(); m_ui->styleInput->setCurrentText(vs.toString());
m_ui->themeInput->setCurrentText(theme);
} else { } 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")) { 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); const QStringList dirs = QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, "color-schemes", QStandardPaths::LocateDirectory);
QStringList schemeFiles; QStringList schemeFiles;
QString currentTheme(tr("System"));
QString requestedTheme("");
QVariant vtheme = settings.value("theme");
if (vtheme.isValid()) {
requestedTheme = vtheme.toString();
}
for (const QString &dir : dirs) { for (const QString &dir : dirs) {
const QStringList fileNames = QDir(dir).entryList(filters); const QStringList fileNames = QDir(dir).entryList(filters);
for (const QString &file : fileNames) { 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 { } else {
m_ui->colorInput->setEnabled(false); m_ui->themeInput->setEnabled(false);
} }
} }
@ -55,8 +73,14 @@ PageAppearance::~PageAppearance()
void PageAppearance::onThemeChanged(int index) void PageAppearance::onThemeChanged(int index)
{ {
if (index >= 0) { 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]);
}
}

View File

@ -29,11 +29,13 @@ signals:
void variableModified(const QString& key, const QVariant& value); void variableModified(const QString& key, const QVariant& value);
protected slots: protected slots:
void onStyleChanged(int index);
void onThemeChanged(int index); void onThemeChanged(int index);
private: private:
QScopedPointer<Ui::PageAppearance> m_ui; QScopedPointer<Ui::PageAppearance> m_ui;
std::vector<QString> styles; std::vector<QString> styles;
std::vector<QString> themes;
}; };
#endif // PAGEAPPEARANCE_H #endif // PAGEAPPEARANCE_H

View File

@ -12,20 +12,20 @@
</property> </property>
<layout class="QFormLayout" name="formLayout"> <layout class="QFormLayout" name="formLayout">
<item row="0" column="0"> <item row="0" column="0">
<widget class="QLabel" name="themeLabel"> <widget class="QLabel" name="styleLabel">
<property name="text"> <property name="text">
<string>Theme</string> <string>Theme</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="0" column="1"> <item row="0" column="1">
<widget class="QComboBox" name="themeInput"/> <widget class="QComboBox" name="styleInput"/>
</item> </item>
<item row="1" column="1"> <item row="1" column="1">
<widget class="QComboBox" name="colorInput"/> <widget class="QComboBox" name="themeInput"/>
</item> </item>
<item row="1" column="0"> <item row="1" column="0">
<widget class="QLabel" name="colorLabel"> <widget class="QLabel" name="themeLabel">
<property name="text"> <property name="text">
<string>Color scheme</string> <string>Color scheme</string>
</property> </property>

View File

@ -40,13 +40,10 @@ void Settings::apply()
{ {
QSettings settings; QSettings settings;
for (const std::pair<const QString, QVariant>& pair: modifiedSettings) { for (const std::pair<const QString, QVariant>& pair: modifiedSettings) {
if (pair.first == "theme") { if (pair.first == "style") {
QString theme = pair.second.toString(); Shared::Global::setStyle(pair.second.toString());
if (theme.toLower() == "system") { } else if (pair.first == "theme") {
QApplication::setStyle(Shared::Global::getInstance()->defaultSystemStyle); Shared::Global::setTheme(pair.second.toString());
} else {
QApplication::setStyle(theme);
}
} }
settings.setValue(pair.first, pair.second); settings.setValue(pair.first, pair.second);