Commit 4e15678f authored by Stefan Asserhäll's avatar Stefan Asserhäll

Added key configuration dialog with global shortcuts for player

svn path=/trunk/kdemultimedia/juk/; revision=213430
parent ad16dd2b
......@@ -7,7 +7,7 @@ juk_SOURCES = directorylistbase.ui genrelisteditorbase.ui \
playlistitem.cpp playlist.cpp playlistsplitter.cpp listboxpixmap.cpp \
playlistbox.cpp tageditor.cpp cache.cpp genrelistreader.cpp \
genrelistlist.cpp genrelist.cpp genre.cpp player.cpp tag.cpp customaction.cpp \
slideraction.cpp juk.cpp main.cpp
slideraction.cpp keydialog.cpp juk.cpp main.cpp
INCLUDES= $(all_includes) -I$(arts_includes)
......
......@@ -38,6 +38,7 @@
#include "splashscreen.h"
#include "genrelisteditor.h"
#include "systemtray.h"
#include "keydialog.h"
////////////////////////////////////////////////////////////////////////////////
// public members
......@@ -58,6 +59,7 @@ JuK::JuK(QWidget *parent, const char *name) : KMainWindow(parent, name, WDestruc
readConfig();
setupPlayer();
setupSystemTray();
setupGlobalAccels();
processArgs();
SplashScreen::finishedLoading();
......@@ -150,6 +152,7 @@ void JuK::setupActions()
new KAction(i18n("Genre List Editor..."), 0, this, SLOT(slotShowGenreListEditor()), actionCollection(), "showGenreListEditor");
KStdAction::keyBindings(this, SLOT(slotEditKeys()), actionCollection());
m_outputSelectAction = Player::playerSelectAction(actionCollection());
if(m_outputSelectAction) {
......@@ -202,6 +205,7 @@ void JuK::setupPlayer()
{
m_trackPositionDragging = false;
m_noSeek = false;
m_volmute = false;
m_pauseAction->setEnabled(false);
m_stopAction->setEnabled(false);
m_backAction->setEnabled(false);
......@@ -229,6 +233,21 @@ void JuK::setupPlayer()
}
void JuK::setupGlobalAccels()
{
m_accel = new KGlobalAccel(this);
KeyDialog::insert(m_accel, "PlayPause", i18n("Play/Pause"), this, SLOT(slotPlayPause()));
KeyDialog::insert(m_accel, "Stop", i18n("Stop Playing"), this, SLOT(slotStop()));
KeyDialog::insert(m_accel, "Back", i18n("Back"), this, SLOT(slotBack()));
KeyDialog::insert(m_accel, "Forward", i18n("Forward"), this, SLOT(slotForward()));
KeyDialog::insert(m_accel, "VolumeUp", i18n("Volume Up"), this, SLOT(slotVolumeUp()));
KeyDialog::insert(m_accel, "VolumeDown", i18n("Volume Down"), this, SLOT(slotVolumeDown()));
KeyDialog::insert(m_accel, "Mute", i18n("Mute"), this, SLOT(slotVolumeMute()));
m_accel->setConfigGroup("Shortcuts");
m_accel->readSettings();
m_accel->updateConnections();
}
void JuK::processArgs()
{
KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
......@@ -240,6 +259,13 @@ void JuK::processArgs()
m_splitter->open(files);
}
void JuK::keyPressEvent(QKeyEvent *e)
{
if (e->key() >= Qt::Key_Back && e->key() <= Qt::Key_MediaLast)
e->accept();
KMainWindow::keyPressEvent(e);
}
/**
* These are settings that need to be know before setting up the GUI.
*/
......@@ -571,6 +597,11 @@ void JuK::slotSetOutput(int output)
m_player = Player::createPlayer(output);
}
void JuK::slotEditKeys()
{
KeyDialog::configure(m_accel, actionCollection(), this);
}
////////////////////////////////////////////////////////////////////////////////
// additional player slots
////////////////////////////////////////////////////////////////////////////////
......@@ -598,6 +629,48 @@ void JuK::slotTrackPositionSliderUpdate(int position)
m_player->seekPosition(position);
}
void JuK::slotPlayPause()
{
if(!m_player)
return;
if(m_player->playing())
slotPause();
else
slotPlay();
}
void JuK::slotVolumeUp()
{
if(m_sliderAction && m_sliderAction->getVolumeSlider()) {
int volume = m_sliderAction->getVolumeSlider()->value() +
m_sliderAction->getVolumeSlider()->maxValue() / 25; // 4% up
slotSetVolume(volume);
m_sliderAction->getVolumeSlider()->setValue(volume);
}
}
void JuK::slotVolumeDown()
{
if(m_sliderAction && m_sliderAction->getVolumeSlider()) {
int volume = m_sliderAction->getVolumeSlider()->value() -
m_sliderAction->getVolumeSlider()->maxValue() / 25; // 4% down
slotSetVolume(volume);
m_sliderAction->getVolumeSlider()->setValue(volume);
}
}
void JuK::slotVolumeMute()
{
if(m_sliderAction && m_sliderAction->getVolumeSlider()) {
if(m_volmute)
slotSetVolume(m_sliderAction->getVolumeSlider()->value());
else
slotSetVolume(0);
m_volmute = !m_volmute;
}
}
// This method is called when the play timer has expired.
void JuK::slotPollPlay()
......
......@@ -23,6 +23,7 @@
#endif
#include <kaction.h>
#include <kglobalaccel.h>
#include <kstdaction.h>
#include <kmainwindow.h>
#include <kmenubar.h>
......@@ -57,9 +58,12 @@ private:
void setupActions();
void setupPlayer();
void setupSystemTray();
void setupGlobalAccels();
void processArgs();
void keyPressEvent(QKeyEvent *);
/**
* readSettings() is separate from readConfig() in that it contains settings
* that need to be read before the GUI is setup.
......@@ -105,11 +109,16 @@ private slots:
void slotShowGenreListEditor();
void slotToggleSystemTray(bool enabled);
void slotSetOutput(int output);
void slotEditKeys();
// additional player slots
void slotTrackPositionSliderClicked();
void slotTrackPositionSliderReleased();
void slotTrackPositionSliderUpdate(int position);
void slotPlayPause();
void slotVolumeUp();
void slotVolumeDown();
void slotVolumeMute();
/**
* This method is called to check our progress in the playing file. It uses
......@@ -156,11 +165,13 @@ private:
QTimer *m_playTimer;
Player *m_player;
KGlobalAccel *m_accel;
bool m_trackPositionDragging;
bool m_noSeek;
bool m_restore;
bool m_shuttingDown;
bool m_volmute;
static const int m_pollInterval = 800;
};
......
......@@ -53,6 +53,8 @@
<Action name="toggleSystemTray"/>
<Action name="dockOnClose"/>
<Action name="outputSelect"/>
<Separator />
<Action name="options_configure_keybinding"/>
</Menu>
</MenuBar>
......
/***************************************************************************
keydialog.cpp - description
-------------------
begin : Tue Mar 11 19:00:00 CET 2003
copyright : (C) 2003 by Stefan Asserhall
email : stefan.asserhall@telia.com
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#include "keydialog.h"
#include <kconfig.h>
#include <klocale.h>
#include <kshortcut.h>
#include <qlayout.h>
#include <qradiobutton.h>
#include <qvbox.h>
#include <qwhatsthis.h>
// Groups of keys that can be selected in the dialog
enum KeyGroup {NoKeys = 0, StandardKeys = 1, MultimediaKeys = 2};
// Table of shortcut keys for each action, key group and three or four button modifier
static const struct {
QString action;
KShortcut shortcut[3][2];
} keyInfo[] = {
{"PlayPause",
{{KShortcut::null(), KShortcut::null()},
{Qt::CTRL+Qt::ALT+Qt::Key_P, KKey::QtWIN+Qt::ALT+Qt::Key_P},
{Qt::Key_MediaPlay, Qt::Key_MediaPlay}}},
{"Stop",
{{KShortcut::null(), KShortcut::null()},
{Qt::CTRL+Qt::ALT+Qt::Key_S, KKey::QtWIN+Qt::ALT+Qt::Key_S},
{Qt::Key_MediaStop, Qt::Key_MediaStop}}},
{"Back",
{{KShortcut::null(), KShortcut::null()},
{Qt::CTRL+Qt::ALT+Qt::Key_Left, KKey::QtWIN+Qt::ALT+Qt::Key_Left},
{Qt::Key_MediaPrev, Qt::Key_MediaPrev}}},
{"Forward",
{{KShortcut::null(), KShortcut::null()},
{Qt::CTRL+Qt::ALT+Qt::Key_Right, KKey::QtWIN+Qt::ALT+Qt::Key_Right},
{Qt::Key_MediaNext, Qt::Key_MediaNext}}},
{"VolumeUp",
{{KShortcut::null(), KShortcut::null()},
{Qt::CTRL+Qt::ALT+Qt::SHIFT+Qt::Key_Up, KKey::QtWIN+Qt::ALT+Qt::SHIFT+Qt::Key_Up},
{Qt::Key_VolumeUp, Qt::Key_VolumeUp}}},
{"VolumeDown",
{{KShortcut::null(), KShortcut::null()},
{Qt::CTRL+Qt::ALT+Qt::SHIFT+Qt::Key_Down, KKey::QtWIN+Qt::ALT+Qt::SHIFT+Qt::Key_Down},
{Qt::Key_VolumeDown, Qt::Key_VolumeDown}}},
{"Mute",
{{KShortcut::null(), KShortcut::null()},
{Qt::CTRL+Qt::ALT+Qt::Key_M, KKey::QtWIN+Qt::ALT+Qt::Key_M},
{Qt::Key_VolumeMute, Qt::Key_VolumeMute}}}
};
#define KEYINFO_COUNT (sizeof(keyInfo) / sizeof(keyInfo[0]))
KeyDialog::KeyDialog(KGlobalAccel* keys, KActionCollection* coll, QWidget *parent, const char* name)
: KDialogBase( parent, name, true, i18n("Configure Shortcuts"), Default|Ok|Cancel, Ok )
{
// Read key group from configuration
int selectedButton;
KConfig *config = KGlobal::config();
{
KConfigGroupSaver saver(config, "Shortcuts");
selectedButton = config->readNumEntry("GlobalKeys", StandardKeys);
}
// Create widgets for key chooser - widget stack used to replace key chooser
QVBox *vbox = new QVBox(this);
vbox->setSpacing(KDialog::spacingHint());
m_widgetstack = new QWidgetStack(vbox);
// Create buttons to select key group
m_group = new QHButtonGroup(i18n("Global shortcuts"), vbox);
new QRadioButton(i18n("&No keys"), m_group);
new QRadioButton(i18n("&Standard keys"), m_group);
new QRadioButton(i18n("&Multimedia keys"), m_group);
connect(m_group, SIGNAL(clicked(int)), this, SLOT(slotKeys(int)));
QWhatsThis::add( m_group,
i18n("Here you can select the keys used as global shortcuts to control the player"));
// Create the key chooser
setMainWidget(vbox);
newDialog(keys, coll, selectedButton);
}
KeyDialog::~KeyDialog()
{
}
void KeyDialog::newDialog(KGlobalAccel* keys, KActionCollection* coll, int selectedButton)
{
m_keys = keys;
m_coll = coll;
// Create key chooser and show it in the widget stack
m_pKeyChooser = new KKeyChooser(keys, this);
m_pKeyChooser->insert(coll);
m_widgetstack->addWidget(m_pKeyChooser);
m_widgetstack->raiseWidget(m_pKeyChooser);
m_group->setButton(selectedButton);
connect(this, SIGNAL(defaultClicked()), this, SLOT(slotDefault()));
}
int KeyDialog::configure()
{
// Show the dialog and save configuration if accepted
int retcode = exec();
if(retcode == Accepted) {
KConfig *config = KGlobal::config();
{
KConfigGroupSaver saver(config, "Shortcuts");
config->writeEntry("GlobalKeys", m_group->id(m_group->selected()));
config->sync();
}
m_pKeyChooser->save();
}
return retcode;
}
void KeyDialog::slotKeys(int group)
{
bool fourModKeys = KGlobalAccel::useFourModifierKeys();
// Set modifier keys according to key group and modifier keys
for (unsigned int i = 0; i < KEYINFO_COUNT; i++)
m_keys->setShortcut(keyInfo[i].action, keyInfo[i].shortcut[group][fourModKeys]);
// Create a new key chooser to show the keys, and delete the old one
QWidget *w = m_widgetstack->visibleWidget();
newDialog(m_keys, m_coll, group);
m_widgetstack->removeWidget(w);
delete w;
}
void KeyDialog::slotDefault()
{
// Select default keys - standard key group
m_group->setButton(StandardKeys);
m_pKeyChooser->allDefault();
}
int KeyDialog::configure(KGlobalAccel* keys, KActionCollection* coll, QWidget* parent)
{
// Create and show dialog - update connections if accepted
KeyDialog dlg(keys, coll, parent);
int retcode = dlg.configure();
if (retcode == Accepted)
keys->updateConnections();
return retcode;
}
void KeyDialog::insert(KGlobalAccel* keys, const QString& action, const QString& label,
const QObject* objSlot, const char* methodSlot)
{
KShortcut def3 = KShortcut::null();
KShortcut def4 = KShortcut::null();
// Find and insert a standard key
for (unsigned int i = 0; i < KEYINFO_COUNT; i++)
if (keyInfo[i].action == action) {
def3 = keyInfo[i].shortcut[StandardKeys][0];
def4 = keyInfo[i].shortcut[StandardKeys][1];
break;
}
keys->insert(action, label, QString::null, def3, def4, objSlot, methodSlot);
}
/***************************************************************************
keydialog.h - description
-------------------
begin : Tue Mar 11 19:00:00 CET 2003
copyright : (C) 2003 by Stefan Asserhall
email : stefan.asserhall@telia.com
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#ifndef __KEYDIALOG_H__
#define __KEYDIALOG_H__
#include <kactioncollection.h>
#include <kdialogbase.h>
#include <kglobalaccel.h>
#include <kkeydialog.h>
#include <qhbuttongroup.h>
#include <qwidgetstack.h>
class KeyDialog : public KDialogBase
{
Q_OBJECT
public:
/**
* Constructs a KeyDialog called @p name as a child of @p parent.
*/
KeyDialog(KGlobalAccel* keys, KActionCollection* coll, QWidget *parent = 0, const char* name = 0);
/**
* Destructor. Deletes all resources used by a KeyDialog object.
*/
virtual ~KeyDialog();
/**
* This is a member function, provided to allow inserting both global
* accelerators and actions. It behaves essentially like the functions
* in KKeyDialog.
*/
static int configure(KGlobalAccel* keys, KActionCollection* coll, QWidget* parent = 0);
/**
* This is a member function, provided to create a global accelerator with
* standard keys. It behaves like the function in KGlobalAccel.
*/
static void insert(KGlobalAccel *keys, const QString& action, const QString& label,
const QObject* objSlot, const char* methodSlot);
private slots:
void slotKeys(int group);
void slotDefault();
private:
void newDialog(KGlobalAccel* keys, KActionCollection* coll, int selectedButton = 0);
int configure();
KActionCollection *m_coll;
KGlobalAccel *m_keys;
KKeyChooser *m_pKeyChooser;
QHButtonGroup *m_group;
QWidgetStack *m_widgetstack;
};
#endif // __KEYDIALOG_H__
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