From 221799828d55cb1c0431a56779aadf17266d7df2 Mon Sep 17 00:00:00 2001 From: Devin Lin Date: Mon, 30 May 2022 23:37:00 -0400 Subject: [PATCH] kcm: Add ability to customise mode of action drawer swipe down --- .../mobileshell/mobileshellsettings.cpp | 28 ++++++ components/mobileshell/mobileshellsettings.h | 36 ++++++++ .../actiondrawer/ActionDrawerOpenSurface.qml | 13 ++- kcms/mobileshell/package/contents/ui/main.qml | 88 +++++++++++++++++++ 4 files changed, 162 insertions(+), 3 deletions(-) diff --git a/components/mobileshell/mobileshellsettings.cpp b/components/mobileshell/mobileshellsettings.cpp index 29db4b69..1fcd92a4 100644 --- a/components/mobileshell/mobileshellsettings.cpp +++ b/components/mobileshell/mobileshellsettings.cpp @@ -32,6 +32,8 @@ MobileShellSettings::MobileShellSettings(QObject *parent) Q_EMIT animationsEnabledChanged(); Q_EMIT navigationPanelEnabledChanged(); Q_EMIT taskSwitcherPreviewsEnabledChanged(); + Q_EMIT actionDrawerTopLeftModeChanged(); + Q_EMIT actionDrawerTopRightModeChanged(); } else if (group.name() == QUICKSETTINGS_CONFIG_GROUP) { Q_EMIT enabledQuickSettingsChanged(); Q_EMIT disabledQuickSettingsChanged(); @@ -117,6 +119,32 @@ void MobileShellSettings::setTaskSwitcherPreviewsEnabled(bool taskSwitcherPrevie m_config->sync(); } +MobileShellSettings::ActionDrawerMode MobileShellSettings::actionDrawerTopLeftMode() const +{ + auto group = KConfigGroup{m_config, GENERAL_CONFIG_GROUP}; + return (ActionDrawerMode)group.readEntry("actionDrawerTopLeftMode", (int)ActionDrawerMode::Pinned); +} + +void MobileShellSettings::setActionDrawerTopLeftMode(ActionDrawerMode actionDrawerMode) +{ + auto group = KConfigGroup{m_config, GENERAL_CONFIG_GROUP}; + group.writeEntry("actionDrawerTopLeftMode", (int)actionDrawerMode, KConfigGroup::Notify); + m_config->sync(); +} + +MobileShellSettings::ActionDrawerMode MobileShellSettings::actionDrawerTopRightMode() const +{ + auto group = KConfigGroup{m_config, GENERAL_CONFIG_GROUP}; + return (ActionDrawerMode)group.readEntry("actionDrawerTopRightMode", (int)ActionDrawerMode::Expanded); +} + +void MobileShellSettings::setActionDrawerTopRightMode(ActionDrawerMode actionDrawerMode) +{ + auto group = KConfigGroup{m_config, GENERAL_CONFIG_GROUP}; + group.writeEntry("actionDrawerTopRightMode", (int)actionDrawerMode, KConfigGroup::Notify); + m_config->sync(); +} + QList MobileShellSettings::enabledQuickSettings() const { auto group = KConfigGroup{m_config, QUICKSETTINGS_CONFIG_GROUP}; diff --git a/components/mobileshell/mobileshellsettings.h b/components/mobileshell/mobileshellsettings.h index 8f2ab43c..fbe3ba2b 100644 --- a/components/mobileshell/mobileshellsettings.h +++ b/components/mobileshell/mobileshellsettings.h @@ -32,11 +32,21 @@ class MobileShellSettings : public QObject // task switcher Q_PROPERTY(bool taskSwitcherPreviewsEnabled READ taskSwitcherPreviewsEnabled WRITE setTaskSwitcherPreviewsEnabled NOTIFY taskSwitcherPreviewsEnabledChanged) + // action drawer + Q_PROPERTY(ActionDrawerMode actionDrawerTopLeftMode READ actionDrawerTopLeftMode WRITE setActionDrawerTopLeftMode NOTIFY actionDrawerTopLeftModeChanged) + Q_PROPERTY(ActionDrawerMode actionDrawerTopRightMode READ actionDrawerTopRightMode WRITE setActionDrawerTopRightMode NOTIFY actionDrawerTopRightModeChanged) + public: static MobileShellSettings *self(); MobileShellSettings(QObject *parent = nullptr); + enum ActionDrawerMode { + Pinned = 0, /** The drawer when pulled down is in its pinned mode. A second swipe fully expands it.*/ + Expanded /** The drawer is fully expanded when pulled down.*/ + }; + Q_ENUM(ActionDrawerMode) + /** * Get whether shell vibrations are enabled. */ @@ -117,6 +127,30 @@ public: */ void setTaskSwitcherPreviewsEnabled(bool taskSwitcherPreviewsEnabled); + /** + * The mode of the action drawer when swiped down from the top left. + */ + ActionDrawerMode actionDrawerTopLeftMode() const; + + /** + * Set the mode of the action drawer when swiped down from the top left. + * + * @param actionDrawerMode The mode of the action drawer. + */ + void setActionDrawerTopLeftMode(ActionDrawerMode actionDrawerMode); + + /** + * The mode of the action drawer when swiped down from the top right. + */ + ActionDrawerMode actionDrawerTopRightMode() const; + + /** + * Set the mode of the action drawer when swiped down from the top right. + * + * @param actionDrawerMode The mode of the action drawer. + */ + void setActionDrawerTopRightMode(ActionDrawerMode actionDrawerMode); + /** * Get the list of IDs of quick settings that are enabled. */ @@ -148,6 +182,8 @@ Q_SIGNALS: void navigationPanelEnabledChanged(); void animationsEnabledChanged(); void taskSwitcherPreviewsEnabledChanged(); + void actionDrawerTopLeftModeChanged(); + void actionDrawerTopRightModeChanged(); void enabledQuickSettingsChanged(); void disabledQuickSettingsChanged(); diff --git a/components/mobileshell/qml/actiondrawer/ActionDrawerOpenSurface.qml b/components/mobileshell/qml/actiondrawer/ActionDrawerOpenSurface.qml index 3e84ea1a..c6ce24e0 100644 --- a/components/mobileshell/qml/actiondrawer/ActionDrawerOpenSurface.qml +++ b/components/mobileshell/qml/actiondrawer/ActionDrawerOpenSurface.qml @@ -1,11 +1,13 @@ /* - * SPDX-FileCopyrightText: 2021 Devin Lin + * SPDX-FileCopyrightText: 2021-2022 Devin Lin * * SPDX-License-Identifier: LGPL-2.0-or-later */ import QtQuick 2.15 +import org.kde.plasma.private.mobileshell 1.0 as MobileShell + /** * Component that triggers the opening and closing of an ActionDrawer when dragged on with touch or mouse. */ @@ -43,8 +45,13 @@ MouseArea { anchors.fill: parent onPressed: { oldMouseY = mouse.y; - - actionDrawer.openToPinnedMode = mouse.x < root.width/2 ? false : true; + + // if the user swiped from the top left, otherwise it's from the top right + if (mouse.x < root.width / 2) { + actionDrawer.openToPinnedMode = MobileShell.MobileShellSettings.actionDrawerTopLeftMode == MobileShell.MobileShellSettings.Pinned; + } else { + actionDrawer.openToPinnedMode = MobileShell.MobileShellSettings.actionDrawerTopRightMode == MobileShell.MobileShellSettings.Pinned; + } startSwipe(); } diff --git a/kcms/mobileshell/package/contents/ui/main.qml b/kcms/mobileshell/package/contents/ui/main.qml index 6e2917c2..ddd3f223 100644 --- a/kcms/mobileshell/package/contents/ui/main.qml +++ b/kcms/mobileshell/package/contents/ui/main.qml @@ -117,6 +117,7 @@ KCM.SimpleKCM { Layout.topMargin: Kirigami.Units.largeSpacing contentItem: ColumnLayout { + id: parentCol spacing: 0 MobileForm.FormCardHeader { @@ -128,6 +129,93 @@ KCM.SimpleKCM { text: i18n("Quick Settings") onClicked: kcm.push("QuickSettingsForm.qml") } + + Kirigami.Separator { + Layout.leftMargin: Kirigami.Units.largeSpacing + Layout.rightMargin: Kirigami.Units.largeSpacing + Layout.fillWidth: true + opacity: (!quickSettingsButton.controlHovered && !topLeftActionDrawerModeDelegate.controlHovered) ? 0.5 : 0 + } + + property string pinnedString: i18nc("Pinned action drawer mode", "Pinned Mode") + property string expandedString: i18nc("Expanded action drawer mode", "Expanded Mode") + + MobileForm.FormComboBoxDelegate { + id: topLeftActionDrawerModeDelegate + text: i18n("Top Left Drawer Mode") + description: i18n("Mode when opening from the top left.") + + currentValue: { + let mode = MobileShell.MobileShellSettings.actionDrawerTopLeftMode; + if (mode === MobileShell.MobileShellSettings.Expanded) { + return parentCol.expandedString; + } else{ + return parentCol.pinnedString; + } + } + model: ListModel { + // we can't use i18n with ListElement + Component.onCompleted: { + append({"name": parentCol.pinnedString, "value": MobileShell.MobileShellSettings.Pinned}); + append({"name": parentCol.expandedString, "value": MobileShell.MobileShellSettings.Expanded}); + } + } + dialogDelegate: QQC2.RadioDelegate { + implicitWidth: Kirigami.Units.gridUnit * 16 + topPadding: Kirigami.Units.smallSpacing * 2 + bottomPadding: Kirigami.Units.smallSpacing * 2 + + text: name + checked: topLeftActionDrawerModeDelegate.currentValue === name + onCheckedChanged: { + if (checked) { + MobileShell.MobileShellSettings.actionDrawerTopLeftMode = value; + } + } + } + } + + Kirigami.Separator { + Layout.leftMargin: Kirigami.Units.largeSpacing + Layout.rightMargin: Kirigami.Units.largeSpacing + Layout.fillWidth: true + opacity: (!topLeftActionDrawerModeDelegate.controlHovered && !topRightActionDrawerModeDelegate.controlHovered) ? 0.5 : 0 + } + + MobileForm.FormComboBoxDelegate { + id: topRightActionDrawerModeDelegate + text: i18n("Top Right Drawer Mode") + description: i18n("Mode when opening from from the top right.") + + currentValue: { + let mode = MobileShell.MobileShellSettings.actionDrawerTopRightMode; + if (mode === MobileShell.MobileShellSettings.Expanded) { + return parentCol.expandedString; + } else { + return parentCol.pinnedString; + } + } + model: ListModel { + // we can't use i18n with ListElement + Component.onCompleted: { + append({"name": parentCol.pinnedString, "value": MobileShell.MobileShellSettings.Pinned}); + append({"name": parentCol.expandedString, "value": MobileShell.MobileShellSettings.Expanded}); + } + } + dialogDelegate: QQC2.RadioDelegate { + implicitWidth: Kirigami.Units.gridUnit * 16 + topPadding: Kirigami.Units.smallSpacing * 2 + bottomPadding: Kirigami.Units.smallSpacing * 2 + + text: name + checked: topRightActionDrawerModeDelegate.currentValue === name + onCheckedChanged: { + if (checked) { + MobileShell.MobileShellSettings.actionDrawerTopRightMode = value; + } + } + } + } } } }