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

@ -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<> \

View file

@ -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
};
}