From a301d1db33fdecb0e66495b51019922a9b040c1f Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Fri, 6 Apr 2018 16:45:04 +0200 Subject: Conversation view keyboard navigation --- framework/qml/ConversationListView.qml | 16 +++++++-------- framework/qml/ConversationView.qml | 36 ++++++++++++++++++--------------- framework/qml/FolderListView.qml | 10 +++++++++ framework/qml/ListView.qml | 8 ++++++++ framework/qml/MailListView.qml | 37 ++++++++++++++-------------------- framework/qml/Messages.qml | 8 ++++++-- framework/qml/TreeView.qml | 12 +++++++++++ views/conversation/qml/View.qml | 33 +++++++++++++++++++++++++++++- 8 files changed, 111 insertions(+), 49 deletions(-) diff --git a/framework/qml/ConversationListView.qml b/framework/qml/ConversationListView.qml index a7dc1f7d..1d408edc 100644 --- a/framework/qml/ConversationListView.qml +++ b/framework/qml/ConversationListView.qml @@ -68,14 +68,6 @@ FocusScope { flickable.decrementCurrentIndex() } - function scrollDown() { - scrollHelper.scrollDown() - } - - function scrollUp() { - scrollHelper.scrollUp() - } - Flickable { id: flickable anchors.fill: parent @@ -145,6 +137,14 @@ FocusScope { scrollToIndex(currentIndex) } + Keys.onPressed: { + if (event.matches(StandardKey.MoveToNextLine)) { + scrollHelper.scrollDown() + } else if (event.matches(StandardKey.MoveToPreviousLine)) { + scrollHelper.scrollUp() + } + } + Kube.ScrollHelper { id: scrollHelper flickable: flickable diff --git a/framework/qml/ConversationView.qml b/framework/qml/ConversationView.qml index 8331e581..1109ad8e 100644 --- a/framework/qml/ConversationView.qml +++ b/framework/qml/ConversationView.qml @@ -17,7 +17,7 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -import QtQuick 2.7 +import QtQuick 2.9 import QtQuick.Controls 2 import QtQuick.Layouts 1.1 import org.kube.framework 1.0 as Kube @@ -38,6 +38,22 @@ FocusScope { onMessageReceived: root.searchString = message.searchString } + Kube.Listener { + filter: Kube.Messages.selectNextMessage + onMessageReceived: { + listView.incrementCurrentIndex() + listView.forceActiveFocus() + } + } + + Kube.Listener { + filter: Kube.Messages.selectPreviousMessage + onMessageReceived: { + listView.decrementCurrentIndex() + listView.forceActiveFocus() + } + } + Rectangle { anchors.fill: parent color: Kube.Colors.backgroundColor @@ -61,21 +77,9 @@ FocusScope { } Keys.onPressed: { - if (event.text == "j" || event.matches(StandardKey.MoveToNextLine)) { - listView.scrollDown() - } else if (event.text == "J" || event.matches(StandardKey.MoveToNextPage)) { - listView.incrementCurrentIndex() - } else if (event.text == "k" || event.matches(StandardKey.MoveToPreviousLine)) { - listView.scrollUp() - } else if (event.text == "K" || event.matches(StandardKey.MoveToPreviousPage)) { - listView.decrementCurrentIndex() - } else if (event.text == "n") { - Kube.Fabric.postMessage(Kube.Messages.nextConversation, {}) - } else if (event.text == "p") { - Kube.Fabric.postMessage(Kube.Messages.previousConversation, {}) - } else if (event.text == "d") { - //Not implemented as a shortcut because we want it only to apply if we have the focus - Kube.Fabric.postMessage(Kube.Messages.moveToTrash, {"mail": listView.currentItem.currentData.mail}) + if (event.text == "d") { + //Not implemented as a shortcut because we want it only to apply if we have the focus + Kube.Fabric.postMessage(Kube.Messages.moveToTrash, {"mail": listView.currentItem.currentData.mail}) } } diff --git a/framework/qml/FolderListView.qml b/framework/qml/FolderListView.qml index 3a203083..221ec31c 100644 --- a/framework/qml/FolderListView.qml +++ b/framework/qml/FolderListView.qml @@ -27,6 +27,16 @@ Kube.TreeView { id: root property variant accountId + Kube.Listener { + filter: Kube.Messages.selectNextFolder + onMessageReceived: root.selectNext() + } + + Kube.Listener { + filter: Kube.Messages.selectPreviousFolder + onMessageReceived: root.selectPrevious() + } + Controls1.TableViewColumn { title: "Name" role: "name" diff --git a/framework/qml/ListView.qml b/framework/qml/ListView.qml index 52942b65..3017e377 100644 --- a/framework/qml/ListView.qml +++ b/framework/qml/ListView.qml @@ -29,6 +29,14 @@ ListView { clip: true ScrollBar.vertical: Kube.ScrollBar { id: scrollBar } + Keys.onPressed: { + if (event.matches(StandardKey.MoveToNextLine)) { + incrementCurrentIndex() + } else if (event.matches(StandardKey.MoveToPreviousLine)) { + decrementCurrentIndex() + } + } + Kube.ScrollHelper { id: scrollHelper flickable: root diff --git a/framework/qml/MailListView.qml b/framework/qml/MailListView.qml index f5806d82..a8322f15 100644 --- a/framework/qml/MailListView.qml +++ b/framework/qml/MailListView.qml @@ -46,10 +46,20 @@ FocusScope { find.forceActiveFocus() } - Shortcut { - sequences: [StandardKey.Delete] - enabled: !isTrash - onActivated: Kube.Fabric.postMessage(Kube.Messages.moveToTrash, {"mail":currentMail}) + Kube.Listener { + filter: Kube.Messages.selectNextConversation + onMessageReceived: { + listView.incrementCurrentIndex() + listView.forceActiveFocus() + } + } + + Kube.Listener { + filter: Kube.Messages.selectPreviousConversation + onMessageReceived: { + listView.decrementCurrentIndex() + listView.forceActiveFocus() + } } Kube.Label { @@ -59,16 +69,6 @@ FocusScope { text: qsTr("Nothing here...") } - Kube.Listener { - filter: Kube.Messages.nextConversation - onMessageReceived: listView.incrementCurrentIndex() - } - - Kube.Listener { - filter: Kube.Messages.previousConversation - onMessageReceived: listView.decrementCurrentIndex() - } - ColumnLayout { anchors.fill: parent @@ -123,7 +123,6 @@ FocusScope { clip: true focus: true - //BEGIN keyboard nav onActiveFocusChanged: { if (activeFocus && currentIndex < 0) { currentIndex = 0 @@ -131,18 +130,12 @@ FocusScope { } Keys.onPressed: { - if (event.text == "j" || event.matches(StandardKey.MoveToNextLine)) { - incrementCurrentIndex() - } else if (event.text == "k" || event.matches(StandardKey.MoveToPreviousLine)) { - decrementCurrentIndex() - } else if (event.text == "d") { + if (event.text == "d") { //Not implemented as a shortcut because we want it only to apply if we have the focus Kube.Fabric.postMessage(Kube.Messages.moveToTrash, {"mail": root.currentMail}) } } - //END keyboard nav - onCurrentItemChanged: { if (currentItem) { var currentData = currentItem.currentData; diff --git a/framework/qml/Messages.qml b/framework/qml/Messages.qml index a3f6ef00..630d05ab 100644 --- a/framework/qml/Messages.qml +++ b/framework/qml/Messages.qml @@ -52,7 +52,11 @@ Item { property string componentDone: "done" - property string nextConversation: "nextConversation" - property string previousConversation: "previousConversation" + property string selectNextConversation: "selectNextConversation" + property string selectPreviousConversation: "selectPreviousConversation" + property string selectNextMessage: "selectNextMessage" + property string selectPreviousMessage: "selectPreviousMessage" + property string selectNextFolder: "selectNextFolder" + property string selectPreviousFolder: "selectPreviousFolder" } diff --git a/framework/qml/TreeView.qml b/framework/qml/TreeView.qml index 21345fb0..d7fed711 100644 --- a/framework/qml/TreeView.qml +++ b/framework/qml/TreeView.qml @@ -46,6 +46,18 @@ FocusScope { return treeView.__model.mapRowToModelIndex(row) } + function selectNext() { + treeView.__listView.incrementCurrentIndexBlocking() + treeView.__mouseArea.keySelect(Qt.NoModifier) + activated(treeView.selection.currentIndex) + } + + function selectPrevious() { + treeView.__listView.decrementCurrentIndexBlocking() + treeView.__mouseArea.keySelect(Qt.NoModifier) + activated(treeView.selection.currentIndex) + } + Flickable { id: flickableItem diff --git a/views/conversation/qml/View.qml b/views/conversation/qml/View.qml index c1f3625b..c965b4c7 100644 --- a/views/conversation/qml/View.qml +++ b/views/conversation/qml/View.qml @@ -18,7 +18,7 @@ */ -import QtQuick 2.7 +import QtQuick 2.9 import QtQuick.Controls 1.3 as Controls1 import QtQuick.Controls 2.0 as Controls2 import QtQuick.Layouts 1.1 @@ -27,6 +27,37 @@ import org.kube.framework 1.0 as Kube FocusScope { property alias currentAccount: accountFolderview.currentAccount + + Shortcut { + sequences: ['j'] + onActivated: Kube.Fabric.postMessage(Kube.Messages.selectNextConversation, {}) + } + Shortcut { + sequences: ['k'] + onActivated: Kube.Fabric.postMessage(Kube.Messages.selectPreviousConversation, {}) + } + Shortcut { + sequences: ['n'] + onActivated: Kube.Fabric.postMessage(Kube.Messages.selectNextMessage, {}) + } + Shortcut { + sequences: ['p'] + onActivated: Kube.Fabric.postMessage(Kube.Messages.selectPreviousMessage, {}) + } + Shortcut { + sequences: ['f,n'] + onActivated: Kube.Fabric.postMessage(Kube.Messages.selectNextFolder, {}) + } + Shortcut { + sequences: ['f,p'] + onActivated: Kube.Fabric.postMessage(Kube.Messages.selectPreviousFolder, {}) + } + Shortcut { + sequences: ['c'] + onActivated: Kube.Fabric.postMessage(Kube.Messages.compose, {}) + } + + Controls1.SplitView { anchors.fill: parent Rectangle { -- cgit v1.2.3