diff --git a/kcms/colors/colors.h b/kcms/colors/colors.h --- a/kcms/colors/colors.h +++ b/kcms/colors/colors.h @@ -21,6 +21,7 @@ #pragma once +#include #include #include #include @@ -51,6 +52,12 @@ Q_PROPERTY(ColorsSettings *colorsSettings READ colorsSettings CONSTANT) Q_PROPERTY(bool downloadingFile READ downloadingFile NOTIFY downloadingFileChanged) + Q_PROPERTY(bool hasAccent READ hasAccent CONSTANT) + Q_PROPERTY(QColor accentForeground READ accentForeground CONSTANT) + + Q_PROPERTY(bool pendingHasAccent MEMBER m_pendingHasAccent NOTIFY pendingHasAccentChanged) + Q_PROPERTY(QColor pendingAccent MEMBER m_pendingAccent NOTIFY pendingAccentChanged) + public: KCMColors(QObject *parent, const QVariantList &args); ~KCMColors() override; @@ -66,6 +73,8 @@ FilterProxyModel *filteredModel() const; ColorsSettings *colorsSettings() const; bool downloadingFile() const; + bool hasAccent() const; + QColor accentForeground() const; Q_INVOKABLE void reloadModel(const QQmlListReference &changedEntries); Q_INVOKABLE void installSchemeFromFile(const QUrl &url); @@ -84,6 +93,9 @@ void showSchemeNotInstalledWarning(const QString &schemeName); + void pendingHasAccentChanged(bool hasAccent); + void pendingAccentChanged(QColor accent); + private: bool isSaveNeeded() const override; @@ -99,6 +111,9 @@ bool m_selectedSchemeDirty = false; bool m_activeSchemeEdited = false; + bool m_pendingHasAccent; + QColor m_pendingAccent; + bool m_applyToAlien = true; QProcess *m_editDialogProcess = nullptr; diff --git a/kcms/colors/colors.cpp b/kcms/colors/colors.cpp --- a/kcms/colors/colors.cpp +++ b/kcms/colors/colors.cpp @@ -24,6 +24,7 @@ #include "colors.h" +#include #include #include #include @@ -74,6 +75,9 @@ qmlRegisterType(); qmlRegisterType(); + m_pendingHasAccent = hasAccent(); + m_pendingAccent = accentForeground(); + KAboutData *about = new KAboutData(QStringLiteral("kcm_colors"), i18n("Colors"), QStringLiteral("2.0"), QString(), KAboutLicense::GPL); about->addAuthor(i18n("Kai Uwe Broulik"), QString(), QStringLiteral("kde@privat.broulik.de")); @@ -114,6 +118,27 @@ return m_settings; } +bool KCMColors::hasAccent() const +{ + KSharedConfigPtr config = KSharedConfig::openConfig("kdeglobals"); + KConfigGroup accent(config, "Accent"); + return accent.hasKey("Foreground") || accent.hasKey("Background"); +} + +QColor KCMColors::accentForeground() const +{ + KSharedConfigPtr config = KSharedConfig::openConfig("kdeglobals"); + KConfigGroup accent(config, "Accent"); + + auto split = accent.readEntry("Foreground", "61,174,233").split(","); + + if (split.length() < 3) { + return QColor(61, 174, 233); + } + + return QColor(split[0].toInt(), split[1].toInt(), split[2].toInt()); +} + bool KCMColors::downloadingFile() const { return m_tempCopyJob; @@ -307,7 +332,10 @@ bool KCMColors::isSaveNeeded() const { - return m_activeSchemeEdited || !m_model->match(m_model->index(0, 0), ColorsModel::PendingDeletionRole, true).isEmpty(); + return m_activeSchemeEdited || + !m_model->match(m_model->index(0, 0), ColorsModel::PendingDeletionRole, true).isEmpty() || + accentForeground() != m_pendingAccent || + hasAccent() != m_pendingHasAccent; } @@ -349,6 +377,27 @@ } m_activeSchemeEdited = false; + if (m_pendingAccent != accentForeground()) { + KSharedConfigPtr config = KSharedConfig::openConfig("kdeglobals"); + KConfigGroup accent(config, "Accent"); + accent.writeEntry("Foreground", m_pendingAccent); + accent.writeEntry("Background", KColorUtils::darken(m_pendingAccent)); + accent.sync(); + QDBusMessage message = QDBusMessage::createSignal(QStringLiteral("/KGlobalSettings"), + QStringLiteral("org.kde.KGlobalSettings"), + QStringLiteral("notifyChange")); + message.setArguments({0,0}); + QDBusConnection::sessionBus().send(message); + } + + if (m_pendingHasAccent != hasAccent()) { + if (m_pendingHasAccent == false) { + KSharedConfigPtr config = KSharedConfig::openConfig("kdeglobals"); + config.data()->deleteGroup("Accent"); + config.data()->sync(); + } + } + processPendingDeletions(); } diff --git a/kcms/colors/editor/scmeditorcolors.cpp b/kcms/colors/editor/scmeditorcolors.cpp --- a/kcms/colors/editor/scmeditorcolors.cpp +++ b/kcms/colors/editor/scmeditorcolors.cpp @@ -374,6 +374,10 @@ m_colorSchemes.append(KColorScheme(QPalette::Active, KColorScheme::Tooltip, m_config)); m_colorSchemes.append(KColorScheme(QPalette::Active, KColorScheme::Complementary, m_config)); + for (KColorScheme &scheme : m_colorSchemes) { + scheme.dropAccentColors(); + } + m_wmColors.load(m_config); } diff --git a/kcms/colors/package/contents/ui/main.qml b/kcms/colors/package/contents/ui/main.qml --- a/kcms/colors/package/contents/ui/main.qml +++ b/kcms/colors/package/contents/ui/main.qml @@ -26,6 +26,7 @@ import org.kde.kirigami 2.4 as Kirigami import org.kde.newstuff 1.62 as NewStuff import org.kde.kcm 1.1 as KCM +import org.kde.kquickcontrols 2.0 as KQuickControls import org.kde.private.kcms.colors 1.0 as Private KCM.GridViewKCM { @@ -155,6 +156,25 @@ } } } + + RowLayout { + QtControls.CheckBox { + checked: kcm.hasAccent + text: i18nc("'this accent color' refers to the color in the button after the checkbox", "Use this accent color instead of the one provided by the current colorscheme:") + onCheckedChanged: { + kcm.pendingHasAccent = checked + kcm.settingsChanged() + } + } + KQuickControls.ColorButton { + Layout.preferredWidth: height + color: kcm.accentForeground + onAccepted: (color) => { + kcm.pendingAccent = color + kcm.settingsChanged() + } + } + } } view.delegate: KCM.GridDelegate {