From 3d60948da05a7f97b11c73e0aa77242502da8586 Mon Sep 17 00:00:00 2001 From: Arno Date: Tue, 7 Mar 2017 19:37:41 +0100 Subject: Add bindings for global KDE shortcuts Hell, this was much harder than it should be. The API documentation is crap and I didn't find a single decent example with my google foo! --- playerwidget.cpp | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) (limited to 'playerwidget.cpp') diff --git a/playerwidget.cpp b/playerwidget.cpp index 38e2eff..5e6e648 100644 --- a/playerwidget.cpp +++ b/playerwidget.cpp @@ -26,6 +26,7 @@ #include #include #include +#include #include "playerwidget.h" #include "beetview.h" @@ -218,10 +219,18 @@ void PlayerWidget::createActions(){ playAG->addAction(mStopA); mStopA->setChecked(true); connect(mStopA, SIGNAL(triggered()), this, SLOT(doStop())); + QAction *playOrPauseA = new QAction(tr("Play or Pause"), this); + playOrPauseA->setObjectName("beetPlayerDoPlayOrPause"); + connect(playOrPauseA, SIGNAL(triggered()), this, SLOT(doPlayOrPause())); + KGlobalAccel::self()->setShortcut(playOrPauseA, QList() << QKeySequence(Qt::Key_MediaPlay), KGlobalAccel::Autoloading); QAction *previousA = new QAction(QIcon(":/previous.png"), tr("Previous"), this); + previousA->setObjectName("beetPlayerPrevious"); connect(previousA, SIGNAL(triggered()), this, SLOT(previous())); + KGlobalAccel::self()->setShortcut(previousA, QList() << QKeySequence(Qt::Key_Launch2), KGlobalAccel::Autoloading); QAction *nextA = new QAction(QIcon(":/next.png"), tr("Next"), this); + nextA->setObjectName("beetPlayerNext"); connect(nextA, SIGNAL(triggered()), this, SLOT(next())); + KGlobalAccel::self()->setShortcut(nextA, QList() << QKeySequence(Qt::Key_Launch3), KGlobalAccel::Autoloading); QAction *addToPlayListA = new QAction(QIcon(":/belly_right.png"), tr("Add to playlist"), this); connect(addToPlayListA, SIGNAL(triggered()), this, SLOT(addToPlayList())); QAction *addToPlayListAndClearA = new QAction(QIcon(":/belly_right_and_clear.png"), tr("Clear and add"), this); @@ -241,8 +250,18 @@ void PlayerWidget::createActions(){ QAction *randomPlayA = new QAction(QIcon(":/dice.png"), tr("Play random"), this); connect(randomPlayA, SIGNAL(triggered()), this, SLOT(randomPlay())); QAction *muteA = new QAction(QIcon(":/mute.png"), tr("Mute"), this); + muteA->setObjectName("beetPlayerMute"); muteA->setCheckable(true); connect(muteA, SIGNAL(triggered(bool)), this, SLOT(mute(bool))); + KGlobalAccel::self()->setShortcut(muteA, QList() << QKeySequence(Qt::Key_VolumeMute), KGlobalAccel::Autoloading); + QAction *volumeUpA = new QAction(tr("Increase volume"), this); + volumeUpA->setObjectName("beetPlayerIncVolume"); + connect(volumeUpA, SIGNAL(triggered()), this, SLOT(volumeUp())); + KGlobalAccel::self()->setShortcut(volumeUpA, QList() << QKeySequence(Qt::Key_VolumeUp), KGlobalAccel::Autoloading); + QAction *volumeDownA = new QAction(tr("Decrease volume"), this); + volumeDownA->setObjectName("beetPlayerDecVolume"); + connect(volumeDownA, SIGNAL(triggered()), this, SLOT(volumeDown())); + KGlobalAccel::self()->setShortcut(volumeDownA, QList() << QKeySequence(Qt::Key_VolumeDown), KGlobalAccel::Autoloading); QAction *configA = Globals::instance()->action(Globals::ConfigAction); QAction *helpA = new QAction(Helper::iconFromQChar(QChar(0x00BF), 50), tr("Help"), this); QMenu *helpM = new QMenu; @@ -594,6 +613,34 @@ void PlayerWidget::doPause(){ emit setWinTitle(winTitle); } +void PlayerWidget::doPlayOrPause(){ + if(mPlayA->isChecked()){ + doPause(); + }else if(mPauseA->isChecked() || mStopA->isChecked()){ + doPlay(); + } +} + +void PlayerWidget::volumeUp(){ + adjustVolume(2); +} + +void PlayerWidget::volumeDown(){ + adjustVolume(-2); +} + +void PlayerWidget::adjustVolume(int by){ + int curVol = mVolumeSlider->value(); + int newVol = curVol + by; + if(newVol > 100){ + newVol = 100; + } + if(newVol < 0){ + newVol = 0; + } + mVolumeSlider->setValue(newVol); +} + void PlayerWidget::recurse(const QModelIndex &parent){ for(int i = 0; i < mCurrentModel->rowCount(parent); ++i){ QModelIndex cur = mCurrentModel->index(i, 0, parent); -- cgit v1.2.3-70-g09d2