create reversed color scheme for plasma theme

pull/3/head
Michail Vourlakos 7 years ago
parent a011333bf8
commit 7c484afa91

@ -18,13 +18,20 @@
*
*/
#include "dockcorona.h"
#include "plasmathemeextended.h"
#include "dockcorona.h"
#include "schemecolors.h"
#include <QDebug>
#include <QDir>
#include <KDirWatch>
#include <KConfigGroup>
#include <KSharedConfig>
#define REVERSEDCOLORSCHEME "reversed.colors"
namespace Latte {
PlasmaThemeExtended::PlasmaThemeExtended(KSharedConfig::Ptr config, QObject *parent) :
@ -40,7 +47,7 @@ PlasmaThemeExtended::PlasmaThemeExtended(KSharedConfig::Ptr config, QObject *par
void PlasmaThemeExtended::load()
{
loadThemePath();
loadThemePaths();
loadRoundness();
}
@ -94,6 +101,79 @@ bool PlasmaThemeExtended::themeHasExtendedInfo() const
return m_themeHasExtendedInfo;
}
void PlasmaThemeExtended::setNormalSchemeFile(const QString &file)
{
if (m_normalSchemePath == file) {
return;
}
m_normalSchemePath = file;
qDebug() << "plasma theme normal colors ::: " << m_normalSchemePath;
updateReversedScheme();
}
void PlasmaThemeExtended::updateReversedScheme()
{
QString reversedFilePath = m_extendedThemeDir.path() + "/" + REVERSEDCOLORSCHEME;
QFile(m_normalSchemePath).copy(reversedFilePath);
m_reversedSchemePath = reversedFilePath;
updateReversedSchemeValues();
qDebug() << "plasma theme reversed colors ::: " << m_reversedSchemePath;
}
void PlasmaThemeExtended::updateReversedSchemeValues()
{
//! reverse values based on original scheme
KSharedConfigPtr normalPtr = KSharedConfig::openConfig(m_normalSchemePath);
KSharedConfigPtr reversePtr = KSharedConfig::openConfig(m_reversedSchemePath);
if (normalPtr && reversePtr) {
foreach (auto groupName, reversePtr->groupList()) {
KConfigGroup reverseGroup(reversePtr, groupName);
if (reverseGroup.keyList().contains("BackgroundNormal")
&& reverseGroup.keyList().contains("ForegroundNormal")) {
//! reverse usual text/background values
KConfigGroup normalGroup(normalPtr, groupName);
reverseGroup.writeEntry("BackgroundNormal", normalGroup.readEntry("ForegroundNormal", QColor()));
reverseGroup.writeEntry("ForegroundNormal", normalGroup.readEntry("BackgroundNormal", QColor()));
reverseGroup.sync();
}
}
//! update WM group
KConfigGroup reverseGroup(reversePtr, "WM");
if (reverseGroup.keyList().contains("activeBackground")
&& reverseGroup.keyList().contains("activeForeground")
&& reverseGroup.keyList().contains("inactiveBackground")
&& reverseGroup.keyList().contains("inactiveForeground")) {
//! reverse usual wm titlebar values
KConfigGroup normalGroup(normalPtr, "WM");
reverseGroup.writeEntry("activeBackground", normalGroup.readEntry("inactiveBackground", QColor()));
reverseGroup.writeEntry("activeForeground", normalGroup.readEntry("inactiveForeground", QColor()));
reverseGroup.writeEntry("inactiveBackground", normalGroup.readEntry("activeBackground", QColor()));
reverseGroup.writeEntry("inactiveForeground", normalGroup.readEntry("activeForeground", QColor()));
reverseGroup.sync();
}
if (reverseGroup.keyList().contains("activeBlend")
&& reverseGroup.keyList().contains("inactiveBlend")) {
KConfigGroup normalGroup(normalPtr, "WM");
reverseGroup.writeEntry("activeBlend", normalGroup.readEntry("inactiveBlend", QColor()));
reverseGroup.writeEntry("inactiveBlend", normalGroup.readEntry("activeBlend", QColor()));
reverseGroup.sync();
}
}
}
void PlasmaThemeExtended::loadRoundness()
{
if (!m_corona) {
@ -136,7 +216,7 @@ void PlasmaThemeExtended::loadRoundness()
emit roundnessChanged();
}
void PlasmaThemeExtended::loadThemePath()
void PlasmaThemeExtended::loadThemePaths()
{
m_themePath = "";
@ -149,9 +229,40 @@ void PlasmaThemeExtended::loadThemePath()
m_themePath = globalD;
}
qDebug() << "current theme ::: " << m_theme.themeName();
qDebug() << "theme path :: " << m_themePath;
qDebug() << "current plasma theme ::: " << m_theme.themeName();
qDebug() << "theme path ::: " << m_themePath;
//! clear kde connections
for (auto &c : m_kdeConnections) {
disconnect(c);
}
//! assign color schemes
QString themeColorScheme = m_themePath + "/colors";
if (QFileInfo(themeColorScheme).exists()) {
setNormalSchemeFile(themeColorScheme);
} else {
//! when plasma theme uses the kde colors
//! we track when kde color scheme is changing
QString kdeSettingsFile = QDir::homePath() + "/.config/kdeglobals";
KDirWatch::self()->addFile(kdeSettingsFile);
m_kdeConnections[0] = connect(KDirWatch::self(), &KDirWatch::dirty, this, [ &, kdeSettingsFile](const QString & path) {
if (path == kdeSettingsFile) {
this->setNormalSchemeFile(SchemeColors::possibleSchemeFile("kdeglobals"));
}
});
m_kdeConnections[1] = connect(KDirWatch::self(), &KDirWatch::created, this, [ &, kdeSettingsFile](const QString & path) {
if (path == kdeSettingsFile) {
this->setNormalSchemeFile(SchemeColors::possibleSchemeFile("kdeglobals"));
}
});
setNormalSchemeFile(SchemeColors::possibleSchemeFile("kdeglobals"));
}
}

@ -23,6 +23,10 @@
#include <QObject>
#include <array>
#include <QTemporaryDir>
#include <KConfigGroup>
#include <KSharedConfig>
@ -62,9 +66,13 @@ private slots:
void saveConfig();
private:
void loadThemePath();
void loadThemePaths();
void loadRoundness();
void setNormalSchemeFile(const QString &file);
void updateReversedScheme();
void updateReversedSchemeValues();
bool themeHasExtendedInfo() const;
private:
@ -77,9 +85,13 @@ private:
int m_userRoundness{0};
QString m_themePath;
QString m_normalSchemePath;
QString m_reversedSchemePath;
KConfigGroup m_themeGroup;
std::array<QMetaObject::Connection, 2> m_kdeConnections;
QTemporaryDir m_extendedThemeDir;
KConfigGroup m_themeGroup;
Plasma::Theme m_theme;
DockCorona *m_corona;

Loading…
Cancel
Save