From cb4aa06901b5a5637aea81158fe88d3d958d970f Mon Sep 17 00:00:00 2001 From: Thomas Perl Date: Tue, 28 Oct 2014 11:37:26 +0100 Subject: [PATCH] Add keyboard navigation for media playback --- common/GPodderPlayback.qml | 8 ++++++++ touch/Main.qml | 35 ++++++++++++++++++++++++++++++++++- touch/PTextField.qml | 6 ++++++ 3 files changed, 48 insertions(+), 1 deletion(-) diff --git a/common/GPodderPlayback.qml b/common/GPodderPlayback.qml index 0a43a1d..57da463 100644 --- a/common/GPodderPlayback.qml +++ b/common/GPodderPlayback.qml @@ -40,6 +40,14 @@ MediaPlayer { property int lastDuration: 0 property int playedFrom: 0 + function togglePause() { + if (playbackState === MediaPlayer.PlayingState) { + pause(); + } else if (playbackState === MediaPlayer.PausedState) { + play(); + } + } + function playbackEpisode(episode_id) { if (episode == episode_id) { // If the episode is already loaded, just start playing diff --git a/touch/Main.qml b/touch/Main.qml index c31cd89..13b78b7 100644 --- a/touch/Main.qml +++ b/touch/Main.qml @@ -34,6 +34,35 @@ Item { GPodderPodcastListModel { id: podcastListModel } GPodderPodcastListModelConnections {} + Keys.onPressed: { + switch (event.key) { + case Qt.Key_Space: + player.togglePause(); + break; + case Qt.Key_Q: + player.seekAndSync(player.position - 60 * 1000); + break; + case Qt.Key_W: + player.seekAndSync(player.position - 10 * 1000); + break; + case Qt.Key_O: + player.seekAndSync(player.position + 10 * 1000); + break; + case Qt.Key_P: + player.seekAndSync(player.position + 60 * 1000); + break; + case Qt.Key_Escape: + case Qt.Key_Backspace: + backButton.clicked(); + break; + default: + break; + } + } + + // Initial focus + focus: true + property real scalef: (width < height) ? (width / 480) : (height / 480) property int shorterSide: (width < height) ? width : height property int dialogsVisible: 0 @@ -169,7 +198,11 @@ Item { icon: Icons.arrow_left enabled: pgst.hasBackButton - onClicked: pgst.children[pgst.children.length-1].closePage(); + onClicked: { + if (enabled) { + pgst.children[pgst.children.length-1].closePage(); + } + } } } diff --git a/touch/PTextField.qml b/touch/PTextField.qml index dca2936..a046d39 100644 --- a/touch/PTextField.qml +++ b/touch/PTextField.qml @@ -38,6 +38,12 @@ Item { TextInput { id: textInput + + Component.onDestruction: { + // Return keyboard focus to pgst + pgst.focus = true; + } + anchors { verticalCenter: parent.verticalCenter left: parent.left