From 9cf52340efe6a3958285a796e52420db227d739e Mon Sep 17 00:00:00 2001 From: Ismael Asensio Date: Sat, 7 Nov 2020 02:26:06 +0100 Subject: [PATCH] kcm/decorations: Simplify border selection Use a single combobox instead of checkbox + combobox. Adds a new property that acts as a proxy for the configuration value, while internal configuration properties are kept unchanged. BUG: 426157 BUG: 417430 FIXED-IN: 5.21 --- kcmkwin/kwindecoration/kcm.cpp | 23 +++++++++- kcmkwin/kwindecoration/kcm.h | 8 +++- .../package/contents/ui/main.qml | 45 +++---------------- 3 files changed, 35 insertions(+), 41 deletions(-) diff --git a/kcmkwin/kwindecoration/kcm.cpp b/kcmkwin/kwindecoration/kcm.cpp index 0b4de6da68..2110692cea 100644 --- a/kcmkwin/kwindecoration/kcm.cpp +++ b/kcmkwin/kwindecoration/kcm.cpp @@ -68,6 +68,10 @@ KCMKWinDecoration::KCMKWinDecoration(QObject *parent, const QVariantList &argume connect(m_data->settings(), &KWinDecorationSettings::themeChanged, this, &KCMKWinDecoration::themeChanged); connect(m_data->settings(), &KWinDecorationSettings::borderSizeChanged, this, &KCMKWinDecoration::borderSizeChanged); + connect(m_data->settings(), &KWinDecorationSettings::borderSizeAutoChanged, this, &KCMKWinDecoration::borderIndexChanged); + connect(this, &KCMKWinDecoration::borderSizeChanged, this, &KCMKWinDecoration::borderIndexChanged); + connect(this, &KCMKWinDecoration::themeChanged, this, &KCMKWinDecoration::borderIndexChanged); + connect(m_leftButtonsModel, &QAbstractItemModel::rowsInserted, this, &KCMKWinDecoration::onLeftButtonsChanged); connect(m_leftButtonsModel, &QAbstractItemModel::rowsMoved, this, &KCMKWinDecoration::onLeftButtonsChanged); connect(m_leftButtonsModel, &QAbstractItemModel::rowsRemoved, this, &KCMKWinDecoration::onLeftButtonsChanged); @@ -188,7 +192,24 @@ QAbstractListModel *KCMKWinDecoration::availableButtonsModel() const QStringList KCMKWinDecoration::borderSizesModel() const { - return Utils::getBorderSizeNames().values(); + // Use index 0 for borderSizeAuto == true + // The rest of indexes get offset by 1 + QStringList model = Utils::getBorderSizeNames().values(); + model.insert(0, i18nc("%1 is the name of a border size", + "Theme's default (%1)", model.at(recommendedBorderSize()))); + return model; +} + +int KCMKWinDecoration::borderIndex() const +{ + return settings()->borderSizeAuto() ? 0 : m_borderSizeIndex + 1; +} + +void KCMKWinDecoration::setBorderIndex(int index) +{ + const bool borderAuto = (index == 0); + settings()->setBorderSizeAuto(borderAuto); + setBorderSize(borderAuto ? recommendedBorderSize() : index - 1); } int KCMKWinDecoration::borderSize() const diff --git a/kcmkwin/kwindecoration/kcm.h b/kcmkwin/kwindecoration/kcm.h index f5f1c3cdf4..97e0043a54 100644 --- a/kcmkwin/kwindecoration/kcm.h +++ b/kcmkwin/kwindecoration/kcm.h @@ -43,8 +43,9 @@ class KCMKWinDecoration : public KQuickAddons::ManagedConfigModule Q_OBJECT Q_PROPERTY(KWinDecorationSettings *settings READ settings CONSTANT) Q_PROPERTY(QSortFilterProxyModel *themesModel READ themesModel CONSTANT) - Q_PROPERTY(QStringList borderSizesModel READ borderSizesModel CONSTANT) - Q_PROPERTY(int borderSize READ borderSize WRITE setBorderSize NOTIFY borderSizeChanged) + Q_PROPERTY(QStringList borderSizesModel READ borderSizesModel NOTIFY themeChanged) + Q_PROPERTY(int borderIndex READ borderIndex WRITE setBorderIndex NOTIFY borderIndexChanged) + Q_PROPERTY(int borderSize READ borderSize NOTIFY borderSizeChanged) Q_PROPERTY(int recommendedBorderSize READ recommendedBorderSize CONSTANT) Q_PROPERTY(int theme READ theme WRITE setTheme NOTIFY themeChanged) Q_PROPERTY(QAbstractListModel *leftButtonsModel READ leftButtonsModel NOTIFY buttonsChanged) @@ -60,10 +61,12 @@ public: QAbstractListModel *rightButtonsModel(); QAbstractListModel *availableButtonsModel() const; QStringList borderSizesModel() const; + int borderIndex() const; int borderSize() const; int recommendedBorderSize() const; int theme() const; + void setBorderIndex(int index); void setBorderSize(int index); void setBorderSize(KDecoration2::BorderSize size); void setTheme(int index); @@ -73,6 +76,7 @@ public: Q_SIGNALS: void themeChanged(); void buttonsChanged(); + void borderIndexChanged(); void borderSizeChanged(); public Q_SLOTS: diff --git a/kcmkwin/kwindecoration/package/contents/ui/main.qml b/kcmkwin/kwindecoration/package/contents/ui/main.qml index 0380018bce..4fa14d4316 100644 --- a/kcmkwin/kwindecoration/package/contents/ui/main.qml +++ b/kcmkwin/kwindecoration/package/contents/ui/main.qml @@ -7,7 +7,7 @@ import QtQuick 2.7 import QtQuick.Layouts 1.3 import QtQuick.Controls 2.4 as Controls -import org.kde.kcm 1.3 as KCM +import org.kde.kcm 1.5 as KCM import org.kde.kconfig 1.0 // for KAuthorized import org.kde.kirigami 2.4 as Kirigami @@ -81,49 +81,18 @@ Kirigami.Page { } RowLayout { - Controls.CheckBox { - id: borderSizeAutoCheckbox - // Let it elide but don't make it push the ComboBox away from it - Layout.fillWidth: true - Layout.maximumWidth: implicitWidth - text: i18nc("checkbox label", "Use theme's default window border size") - checked: kcm.settings.borderSizeAuto - onToggled: { - kcm.settings.borderSizeAuto = checked; - borderSizeComboBox.autoBorderUpdate() - } - - KCM.SettingStateBinding { - configObject: kcm.settings - settingName: "borderSizeAuto" - } - + Controls.Label { + text: i18nc("Selector label", "Window border size:") } Controls.ComboBox { id: borderSizeComboBox model: kcm.borderSizesModel - currentIndex: kcm.borderSize + currentIndex: kcm.borderIndex onActivated: { - kcm.borderSize = currentIndex + kcm.borderIndex = currentIndex } - - KCM.SettingStateBinding { - configObject: kcm.settings - settingName: "borderSize" - extraEnabledConditions: !borderSizeAutoCheckbox.checked - } - - function autoBorderUpdate() { - if (borderSizeAutoCheckbox.checked) { - kcm.borderSize = kcm.recommendedBorderSize - } - } - - Connections { - target: kcm - function onThemeChanged() { - borderSizeComboBox.autoBorderUpdate() - } + KCM.SettingHighlighter { + highlight: kcm.borderIndex != 0 } } Item {