From c696c386edf928377b65f85a8ce963b846bc670f Mon Sep 17 00:00:00 2001 From: Bharadwaj Raju Date: Wed, 6 Oct 2021 09:19:33 +0530 Subject: [PATCH 1/6] Keyboard navigation for applet Add ability to navigate the applet using the keyboard. --- applet/contents/ui/ConnectionItem.qml | 31 +++++++++++++++++++++++++++ applet/contents/ui/PopupDialog.qml | 26 ++++++++++++++++++++++ applet/contents/ui/Toolbar.qml | 2 ++ 3 files changed, 59 insertions(+) diff --git a/applet/contents/ui/ConnectionItem.qml b/applet/contents/ui/ConnectionItem.qml index f644cd56..2e6631b9 100644 --- a/applet/contents/ui/ConnectionItem.qml +++ b/applet/contents/ui/ConnectionItem.qml @@ -48,6 +48,32 @@ PlasmaExtras.ExpandableListItem { onTriggered: changeState() } showDefaultActionButtonWhenBusy: true + + property bool expanded: false + + Keys.onPressed: { + event.accepted = true; + if (event.key == Qt.Key_Return) { + console.log(index); + changeState(); + console.log(index); + ListView.view.currentIndex = index; + } else if (event.key == Qt.Key_Escape) { + if (expanded) { + connectionItem.collapse() + } else { + event.accepted = false; + } + } else if (event.key == Qt.Key_Menu) { + contextMenu.visualParent = connectionItem; + contextMenu.prepare(); + contextMenu.open(0, 0); + } + else { + event.accepted = false; + } + } + customExpandedViewContent: detailsComponent contextMenu: PlasmaComponents.Menu { id: contextMenu @@ -291,10 +317,15 @@ PlasmaExtras.ExpandableListItem { // Re-activate the default button if the password field is hidden without // sending a password onItemCollapsed: { + expanded = false; stateChangeButton.enabled = true; full.connectionModel.delayModelUpdates = false; } + onItemExpanded: { + expanded = true; + } + Component.onDestruction: { if ( full != null && full.connectionModel != null) { full.connectionModel.delayModelUpdates = false; diff --git a/applet/contents/ui/PopupDialog.qml b/applet/contents/ui/PopupDialog.qml index 7f5c78b5..0b6fe14b 100644 --- a/applet/contents/ui/PopupDialog.qml +++ b/applet/contents/ui/PopupDialog.qml @@ -41,6 +41,32 @@ PlasmaComponents3.Page { } } + Keys.onPressed: { + event.accepted = true; + if (event.modifiers & Qt.ControlModifier && event.key == Qt.Key_F) { + toolbar.searchTextField.forceActiveFocus(); + } else if (event.key == Qt.Key_Down) { + connectionView.incrementCurrentIndex(); + connectionView.positionViewAtIndex(connectionView.currentIndex, ListView.Contain); + if (connectionView.currentIndex != -1) { + connectionView.currentItem.forceActiveFocus(); + } + } else if (event.key == Qt.Key_Up) { + connectionView.decrementCurrentIndex(); + connectionView.positionViewAtIndex(connectionView.currentIndex, ListView.Contain); + if (connectionView.currentIndex != -1) { + connectionView.currentItem.forceActiveFocus(); + if (connectionView.currentItem.expanded) { + console.log("dfdf"); + connectionView.currentItem.passwordDialogComponent.passwordField.forceActiveFocus(); + } + } + } + else { + event.accepted = false; + } + } + FocusScope { anchors.fill: parent diff --git a/applet/contents/ui/Toolbar.qml b/applet/contents/ui/Toolbar.qml index e001b7ff..a91c626e 100644 --- a/applet/contents/ui/Toolbar.qml +++ b/applet/contents/ui/Toolbar.qml @@ -19,6 +19,8 @@ ColumnLayout { readonly property var displayWwanMessage: !wwanSwitchButton.checked && wwanSwitchButton.visible readonly property var displayplaneModeMessage: planeModeSwitchButton.checked && planeModeSwitchButton.visible + property alias searchTextField: searchTextField + PlasmaCore.Svg { id: lineSvg imagePath: "widgets/line" -- GitLab From bd6569995e4f3b4fd3656eb4905fdd6d889a0703 Mon Sep 17 00:00:00 2001 From: Bharadwaj Raju Date: Wed, 6 Oct 2021 12:30:08 +0530 Subject: [PATCH 2/6] Make Ctrl+F select all text in search field and remove a stray console.log, plus extract duplicated code --- applet/contents/ui/PopupDialog.qml | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/applet/contents/ui/PopupDialog.qml b/applet/contents/ui/PopupDialog.qml index 0b6fe14b..841c993e 100644 --- a/applet/contents/ui/PopupDialog.qml +++ b/applet/contents/ui/PopupDialog.qml @@ -43,24 +43,21 @@ PlasmaComponents3.Page { Keys.onPressed: { event.accepted = true; - if (event.modifiers & Qt.ControlModifier && event.key == Qt.Key_F) { - toolbar.searchTextField.forceActiveFocus(); - } else if (event.key == Qt.Key_Down) { - connectionView.incrementCurrentIndex(); + function goToCurrent() { connectionView.positionViewAtIndex(connectionView.currentIndex, ListView.Contain); if (connectionView.currentIndex != -1) { connectionView.currentItem.forceActiveFocus(); } + } + if (event.modifiers & Qt.ControlModifier && event.key == Qt.Key_F) { + toolbar.searchTextField.forceActiveFocus(); + toolbar.searchTextField.selectAll(); + } else if (event.key == Qt.Key_Down) { + connectionView.incrementCurrentIndex(); + goToCurrent() } else if (event.key == Qt.Key_Up) { connectionView.decrementCurrentIndex(); - connectionView.positionViewAtIndex(connectionView.currentIndex, ListView.Contain); - if (connectionView.currentIndex != -1) { - connectionView.currentItem.forceActiveFocus(); - if (connectionView.currentItem.expanded) { - console.log("dfdf"); - connectionView.currentItem.passwordDialogComponent.passwordField.forceActiveFocus(); - } - } + goToCurrent(); } else { event.accepted = false; -- GitLab From 6a5e12381613edf1aa33d69d90bb5880f5b92165 Mon Sep 17 00:00:00 2001 From: Bharadwaj Raju Date: Thu, 7 Oct 2021 00:19:37 +0530 Subject: [PATCH 3/6] Remove keyboard handler from ConnectionItem as they're being added to ExpandableListItem itself --- applet/contents/ui/ConnectionItem.qml | 25 ------------------------- 1 file changed, 25 deletions(-) diff --git a/applet/contents/ui/ConnectionItem.qml b/applet/contents/ui/ConnectionItem.qml index 2e6631b9..5beb45d4 100644 --- a/applet/contents/ui/ConnectionItem.qml +++ b/applet/contents/ui/ConnectionItem.qml @@ -49,31 +49,6 @@ PlasmaExtras.ExpandableListItem { } showDefaultActionButtonWhenBusy: true - property bool expanded: false - - Keys.onPressed: { - event.accepted = true; - if (event.key == Qt.Key_Return) { - console.log(index); - changeState(); - console.log(index); - ListView.view.currentIndex = index; - } else if (event.key == Qt.Key_Escape) { - if (expanded) { - connectionItem.collapse() - } else { - event.accepted = false; - } - } else if (event.key == Qt.Key_Menu) { - contextMenu.visualParent = connectionItem; - contextMenu.prepare(); - contextMenu.open(0, 0); - } - else { - event.accepted = false; - } - } - customExpandedViewContent: detailsComponent contextMenu: PlasmaComponents.Menu { id: contextMenu -- GitLab From bf41068189400280d9e12e20c4676444921582cb Mon Sep 17 00:00:00 2001 From: Bharadwaj Raju Date: Thu, 7 Oct 2021 00:53:49 +0530 Subject: [PATCH 4/6] Move to search field when pressing Up on first item --- applet/contents/ui/PopupDialog.qml | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/applet/contents/ui/PopupDialog.qml b/applet/contents/ui/PopupDialog.qml index 841c993e..34ea7e1c 100644 --- a/applet/contents/ui/PopupDialog.qml +++ b/applet/contents/ui/PopupDialog.qml @@ -42,7 +42,6 @@ PlasmaComponents3.Page { } Keys.onPressed: { - event.accepted = true; function goToCurrent() { connectionView.positionViewAtIndex(connectionView.currentIndex, ListView.Contain); if (connectionView.currentIndex != -1) { @@ -52,15 +51,21 @@ PlasmaComponents3.Page { if (event.modifiers & Qt.ControlModifier && event.key == Qt.Key_F) { toolbar.searchTextField.forceActiveFocus(); toolbar.searchTextField.selectAll(); + event.accepted = true; } else if (event.key == Qt.Key_Down) { connectionView.incrementCurrentIndex(); goToCurrent() + event.accepted = true; } else if (event.key == Qt.Key_Up) { - connectionView.decrementCurrentIndex(); - goToCurrent(); - } - else { - event.accepted = false; + if (connectionView.currentIndex == 0) { + connectionView.currentIndex = -1; + toolbar.searchTextField.forceActiveFocus(); + toolbar.searchTextField.selectAll(); + } else { + connectionView.decrementCurrentIndex(); + goToCurrent(); + } + event.accepted = true; } } -- GitLab From 0933a07755287086802b22a6666696c7dd3e1900 Mon Sep 17 00:00:00 2001 From: Bharadwaj Raju Date: Thu, 7 Oct 2021 00:54:31 +0530 Subject: [PATCH 5/6] Remove references to unused property --- applet/contents/ui/ConnectionItem.qml | 5 ----- 1 file changed, 5 deletions(-) diff --git a/applet/contents/ui/ConnectionItem.qml b/applet/contents/ui/ConnectionItem.qml index 5beb45d4..54ee92ce 100644 --- a/applet/contents/ui/ConnectionItem.qml +++ b/applet/contents/ui/ConnectionItem.qml @@ -292,15 +292,10 @@ PlasmaExtras.ExpandableListItem { // Re-activate the default button if the password field is hidden without // sending a password onItemCollapsed: { - expanded = false; stateChangeButton.enabled = true; full.connectionModel.delayModelUpdates = false; } - onItemExpanded: { - expanded = true; - } - Component.onDestruction: { if ( full != null && full.connectionModel != null) { full.connectionModel.delayModelUpdates = false; -- GitLab From e6ab51e75e2b390b1439e2026eb6fbc1b9927655 Mon Sep 17 00:00:00 2001 From: Bharadwaj Raju Date: Thu, 7 Oct 2021 19:21:39 +0530 Subject: [PATCH 6/6] Make left/right switch between Speed/Details in expanded connection, and port TabBar/TabButton to PC3 equivalents --- applet/contents/ui/ConnectionItem.qml | 30 ++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/applet/contents/ui/ConnectionItem.qml b/applet/contents/ui/ConnectionItem.qml index 54ee92ce..67c54411 100644 --- a/applet/contents/ui/ConnectionItem.qml +++ b/applet/contents/ui/ConnectionItem.qml @@ -13,7 +13,8 @@ import org.kde.kcoreaddons 1.0 as KCoreAddons import org.kde.kquickcontrolsaddons 2.0 import org.kde.plasma.core 2.0 as PlasmaCore -import org.kde.plasma.components 2.0 as PlasmaComponents // for ContextMenu+MenuItem/TabBar+TabButton +import org.kde.plasma.components 2.0 as PlasmaComponents // for ContextMenu+MenuItem +import org.kde.plasma.components 3.0 as PlasmaComponents3 // for TabBar+TabButton import org.kde.plasma.extras 2.0 as PlasmaExtras import org.kde.plasma.networkmanagement 0.2 as PlasmaNM @@ -49,6 +50,18 @@ PlasmaExtras.ExpandableListItem { } showDefaultActionButtonWhenBusy: true + Keys.onPressed: { + if ((customExpandedViewContent == detailsComponent) && showSpeed) { + if (event.key == Qt.Key_Right) { + customExpandedViewContentItem.detailsTabBar.currentIndex = 1; + event.accepted = true; + } else if (event.key == Qt.Key_Left) { + customExpandedViewContentItem.detailsTabBar.currentIndex = 0; + event.accepted = true; + } + } + } + customExpandedViewContent: detailsComponent contextMenu: PlasmaComponents.Menu { id: contextMenu @@ -103,8 +116,9 @@ PlasmaExtras.ExpandableListItem { Column { spacing: PlasmaCore.Units.smallSpacing + property Item detailsTabBar: detailsTabBar - PlasmaComponents.TabBar { + PlasmaComponents3.TabBar { id: detailsTabBar anchors { @@ -112,21 +126,23 @@ PlasmaExtras.ExpandableListItem { right: parent.right } height: visible ? implicitHeight : 0 + implicitHeight: contentHeight + position: PlasmaComponents3.TabBar.Header visible: showSpeed - PlasmaComponents.TabButton { + PlasmaComponents3.TabButton { id: speedTabButton text: i18n("Speed") } - PlasmaComponents.TabButton { + PlasmaComponents3.TabButton { id: detailsTabButton text: i18n("Details") } Component.onCompleted: { if (!showSpeed) { - currentTab = detailsTabButton + currentIndex = 1; } } } @@ -138,7 +154,7 @@ PlasmaExtras.ExpandableListItem { right: parent.right } details: ConnectionDetails - visible: detailsTabBar.currentTab == detailsTabButton + visible: detailsTabBar.currentIndex == 1 } TrafficMonitor { @@ -148,7 +164,7 @@ PlasmaExtras.ExpandableListItem { } downloadSpeed: rxBytes uploadSpeed: txBytes - visible: detailsTabBar.currentTab == speedTabButton + visible: detailsTabBar.currentIndex == 0 } } } -- GitLab