Commit 5847d0e0 authored by Ashwin  Dhakaita's avatar Ashwin Dhakaita Committed by Matthieu Gallien
Browse files

Global shortcut for play/pause action using spacebar key

Summary:
Assign SpaceBar key as the global shortcut for play/pause action.  Most of the media player out there already use spacebar as the global shortcut for play/pause action.  So,  it would be good to do the same for Elisa.
Modified ElisaMainWindow.qml to add the shortcut component.
Modified MediaPlayerControl.qml to prevent elements from getting focus as it causes interference with the shortcut keypressed events.

BUG:    392989
FIXED-IN:    elisa  0.3.80

Reviewers: #elisa, ngraham, mgallien

Reviewed By: #elisa, ngraham, mgallien

Subscribers: shubham, mgallien, ngraham

Tags: #elisa

Differential Revision: https://phabricator.kde.org/D17994
parent a3577b30
......@@ -56,6 +56,7 @@
#include <QUrl>
#include <QFileInfo>
#include <QDir>
#include <QKeyEvent>
#include <QDebug>
#include <memory>
......@@ -159,6 +160,11 @@ void ElisaApplication::setupActions(const QString &actionName)
d->mCollection.setDefaultShortcut(scrubAction, QKeySequence(tr("Shift+Left")));
}
if (actionName == QStringLiteral("Play-Pause") && KAuthorized::authorizeAction(actionName)) {
auto playPauseAction = d->mCollection.addAction(actionName, this, &ElisaApplication::playPause);
d->mCollection.setDefaultShortcut(playPauseAction, QKeySequence(tr("Space")));
}
if (actionName == QStringLiteral("edit_find") && KAuthorized::authorizeAction(actionName)) {
auto findAction = KStandardAction::find(this, &ElisaApplication::find, this);
d->mCollection.addAction(findAction->objectName(), findAction);
......@@ -277,6 +283,8 @@ void ElisaApplication::seek() {}
void ElisaApplication::scrub() {}
void ElisaApplication::playPause() {}
ElisaUtils::EntryDataList ElisaApplication::checkFileListAndMakeAbsolute(const ElisaUtils::EntryDataList &filesList,
const QString &workingDirectory) const
{
......@@ -409,6 +417,28 @@ QString ElisaApplication::iconName(const QIcon& icon)
return icon.name();
}
void ElisaApplication::installKeyEventFilter(QObject *object)
{
if(!object) {
return;
}
object->installEventFilter(this);
}
bool ElisaApplication::eventFilter(QObject *object, QEvent *event)
{
Q_UNUSED(object);
QKeyEvent *keyEvent = static_cast<QKeyEvent*>(event);
auto playPauseAction = d->mCollection.action(tr("Play-Pause"));
if (keyEvent->key() == Qt::Key_Space && playPauseAction->shortcut()[0] == Qt::Key_Space) {
return true;
}
return false;
}
const ElisaUtils::EntryDataList &ElisaApplication::arguments() const
{
return d->mArguments;
......
......@@ -82,6 +82,10 @@ public:
Q_INVOKABLE QString iconName(const QIcon& icon);
Q_INVOKABLE void installKeyEventFilter(QObject *object);
bool eventFilter(QObject *object, QEvent *event) override;
const ElisaUtils::EntryDataList &arguments() const;
MusicListenersManager *musicManager() const;
......@@ -153,6 +157,8 @@ private Q_SLOTS:
void scrub();
void playPause();
private:
void initializeModels();
......
......@@ -43,6 +43,7 @@ ApplicationWindow {
property var goBackAction: elisa.action("go_back")
property var seekAction: elisa.action("Seek")
property var scrubAction: elisa.action("Scrub")
property var playPauseAction: elisa.action("Play-Pause")
Action {
shortcut: goBackAction.shortcut
......@@ -59,6 +60,11 @@ ApplicationWindow {
onTriggered: elisa.audioControl.seek(headerBar.playerControl.position - 10000)
}
Action {
shortcut: playPauseAction.shortcut
onTriggered: elisa.audioControl.playPause()
}
ApplicationMenu {
id: applicationMenu
}
......
......@@ -26,6 +26,10 @@ import org.kde.elisa 1.0
Button {
id: flatButtonWithToolTip
activeFocusOnTab: true
Keys.onReturnPressed: action.trigger()
contentItem: Image {
anchors.fill: parent
......
......@@ -137,10 +137,25 @@ FocusScope {
Item { Layout.fillWidth: true }
Controls1.ToolButton { action: showCurrentTrack }
Controls1.ToolButton { action: savePlaylist }
Controls1.ToolButton { action: loadPlaylist }
Controls1.ToolButton { action: clearPlayList }
Controls1.ToolButton {
action: showCurrentTrack
Keys.onReturnPressed: action.trigger()
}
Controls1.ToolButton {
action: savePlaylist
Keys.onReturnPressed: action.trigger()
}
Controls1.ToolButton {
action: loadPlaylist
Keys.onReturnPressed: action.trigger()
}
Controls1.ToolButton {
action: clearPlayList
Keys.onReturnPressed: action.trigger()
}
}
ColumnLayout {
......
......@@ -128,7 +128,7 @@ FocusScope {
spacing: 5
FlatButtonWithToolTip {
id: minimzeMaximizeAction
id: minimizeMaximizeButton
action: minimizeMaximizeAction
Layout.preferredWidth: elisaTheme.smallControlButtonSize
......@@ -423,5 +423,17 @@ FocusScope {
musicWidget.minimize()
}
}
Component.onCompleted: {
var elementList = [menuButton, repeatButton, shuffleButton, muteButton, skipForwardButton, skipBackwardButton, playPauseButton, minimizeMaximizeButton]
for (var i=0; i<elementList.length; i++)
installFilter(elementList[i])
function installFilter(element) {
elisa.installKeyEventFilter(element)
}
}
}
......@@ -90,6 +90,9 @@ FocusScope {
Controls1.ToolButton {
action: goPreviousAction
objectName: 'goPreviousButton'
Keys.onReturnPressed: action.trigger()
Layout.leftMargin: !LayoutMirroring.enabled ? elisaTheme.layoutHorizontalMargin : 0
Layout.rightMargin: LayoutMirroring.enabled ? elisaTheme.layoutHorizontalMargin : 0
visible: enableGoBack
......@@ -196,6 +199,7 @@ FocusScope {
iconName: "media-track-add-amarok"
onClicked: enqueue()
Keys.onReturnPressed: enqueue()
Layout.leftMargin: 0
Layout.rightMargin: 0
......@@ -208,6 +212,7 @@ FocusScope {
iconName: "media-playback-start"
onClicked: replaceAndPlay()
Keys.onReturnPressed: replaceAndPlay()
Layout.leftMargin: !LayoutMirroring.enabled ? elisaTheme.layoutHorizontalMargin : 0
Layout.rightMargin: LayoutMirroring.enabled ? elisaTheme.layoutHorizontalMargin : 0
......@@ -222,6 +227,7 @@ FocusScope {
iconName: "view-media-artist"
onClicked: showArtist()
Keys.onReturnPressed: showArtist()
Layout.leftMargin: !LayoutMirroring.enabled ? elisaTheme.layoutHorizontalMargin : 0
Layout.rightMargin: LayoutMirroring.enabled ? elisaTheme.layoutHorizontalMargin : 0
......@@ -235,6 +241,8 @@ FocusScope {
action: showFilterAction
objectName: 'showFilterButton'
Keys.onReturnPressed: action.trigger()
Layout.alignment: Qt.AlignRight
Layout.leftMargin: !LayoutMirroring.enabled ? elisaTheme.layoutHorizontalMargin : 0
Layout.rightMargin: LayoutMirroring.enabled ? elisaTheme.layoutHorizontalMargin : 0
......@@ -356,6 +364,8 @@ FocusScope {
action: sortAction
objectName: 'sortAscendingButton'
Keys.onReturnPressed: action.trigger()
Layout.alignment: Qt.AlignRight
Layout.leftMargin: !LayoutMirroring.enabled ? elisaTheme.layoutHorizontalMargin : 0
Layout.rightMargin: LayoutMirroring.enabled ? elisaTheme.layoutHorizontalMargin : 0
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment