diff --git a/kcms/colors/colors.cpp b/kcms/colors/colors.cpp index 83342ce5e..fea3cdf43 100644 --- a/kcms/colors/colors.cpp +++ b/kcms/colors/colors.cpp @@ -135,7 +135,14 @@ bool KCMColors::applyAccentColorFromWallpaper() const } void KCMColors::setApplyAccentColorFromWallpaper(bool boolean) { + if (boolean == colorsSettings()->accentColorFromWallpaper()) { + return; + } + if (boolean) { + applyWallpaperAccentColor(); + } colorsSettings()->setAccentColorFromWallpaper(boolean); + Q_EMIT applyAccentColorFromWallpaperChanged(); Q_EMIT settingsChanged(); } diff --git a/kcms/colors/colors.h b/kcms/colors/colors.h index 7676896e2..77b6a432b 100644 --- a/kcms/colors/colors.h +++ b/kcms/colors/colors.h @@ -69,10 +69,10 @@ public: void setAccentColor(const QColor &accentColor); void resetAccentColor(); Q_SIGNAL void accentColorChanged(); - Q_SIGNAL void applyAccentColorFromWallpaperChanged(); bool applyAccentColorFromWallpaper() const; void setApplyAccentColorFromWallpaper(bool boolean); + Q_SIGNAL void applyAccentColorFromWallpaperChanged(); Q_INVOKABLE void installSchemeFromFile(const QUrl &url); @@ -83,7 +83,6 @@ public: Q_INVOKABLE QColor tinted(const QColor& color, const QColor& accent, bool tints, qreal tintFactor); Q_INVOKABLE QColor accentBackground(const QColor &accent, const QColor &background); Q_INVOKABLE QColor accentForeground(const QColor &accent, const bool &isActive); - Q_INVOKABLE void applyWallpaperAccentColor(); public Q_SLOTS: void load() override; @@ -106,6 +105,8 @@ private: void saveColors(); void processPendingDeletions(); + void applyWallpaperAccentColor(); + void installSchemeFile(const QString &path); ColorsModel *m_model; diff --git a/kcms/colors/package/contents/ui/main.qml b/kcms/colors/package/contents/ui/main.qml index 1f305a689..6e696c0ba 100644 --- a/kcms/colors/package/contents/ui/main.qml +++ b/kcms/colors/package/contents/ui/main.qml @@ -39,13 +39,6 @@ KCM.GridViewKCM { restoreMode: Binding.RestoreBinding } - Binding { - target: kcm - property: "applyAccentColorFromWallpaper" - value: wallpaperAccentBox.checked - restoreMode: Binding.RestoreBinding - } - KCM.SettingStateBinding { configObject: kcm.colorsSettings settingName: "colorScheme" @@ -149,10 +142,10 @@ KCM.GridViewKCM { Kirigami.FormData.label: i18n("Use accent color:") text: i18n("From current color scheme") - checked: Qt.colorEqual(kcm.accentColor, "transparent") && !kcm.applyAccentColorFromWallpaper + checked: Qt.colorEqual(kcm.accentColor, "transparent") onToggled: { - if (enabled) { + if (checked) { kcm.accentColor = "transparent" } } @@ -164,8 +157,8 @@ KCM.GridViewKCM { checked: kcm.applyAccentColorFromWallpaper onToggled: { - if (enabled) { - kcm.applyWallpaperAccentColor(); + if (checked) { + kcm.applyAccentColorFromWallpaper = true; } } } @@ -177,23 +170,10 @@ KCM.GridViewKCM { checked: !Qt.colorEqual(kcm.accentColor, "transparent") && !kcm.applyAccentColorFromWallpaper onToggled: { - if (enabled) { + if (checked) { kcm.accentColor = colorRepeater.model[0] } } - /* This required when someone directly clicks one of the accent color buttons or the color picker instead - * of first checking this button. Failing to call this function in those situations will leave this button unchecked - * which was the previous behaviour. - * NOTE: Currently user is able to dicrectly toggle the accentColor buttons or the color picker. If in future the situation - * becomes such that the user must toggle this button first then just remove all the occurrences of this function - */ - - function restartBindingWithCheckedAsTrue() { - if(!accentBox.checked) { - accentBox.checked = true - accentBox.checked = Qt.binding(() => !Qt.colorEqual(kcm.accentColor, "transparent") && !kcm.applyAccentColorFromWallpaper) - } - } } RowLayout { @@ -257,7 +237,6 @@ KCM.GridViewKCM { checked: Qt.colorEqual(kcm.accentColor, modelData) onToggled: { - accentBox.restartBindingWithCheckedAsTrue() kcm.accentColor = modelData checked = Qt.binding(() => Qt.colorEqual(kcm.accentColor, modelData)); } @@ -278,7 +257,6 @@ KCM.GridViewKCM { modality: Qt.ApplicationModal color: kcm.accentColor onAccepted: { - accentBox.restartBindingWithCheckedAsTrue() kcm.accentColor = colorDialog.color } } @@ -286,8 +264,8 @@ KCM.GridViewKCM { ColorRadioButton { id: customColorIndicator - readonly property bool isCustomColor: !wallpaperAccentBox.checked - && root.accentColor + readonly property bool isCustomColor: !kcm.applyAccentColorFromWallpaper + && !Qt.colorEqual(kcm.accentColor, "transparent") && !colorRepeater.model.some(color => Qt.colorEqual(color, root.accentColor)) /* The qt binding will keep the binding alive as well as uncheck the button