Commit da771c8b authored by Michael Pyne's avatar Michael Pyne
Browse files

Fix bug 157028 (JuK shortcuts dialog has extra unlayouted widgets) in KDE trunk.

BUG:157028

svn path=/trunk/KDE/kdemultimedia/juk/; revision=807913
parent ccaa86fb
......@@ -2,7 +2,7 @@
begin : Tue Mar 11 19:00:00 CET 2003
copyright : (C) 2003 by Stefan Asserhall
email : stefan.asserhall@telia.com
copyright : (c) 2007 by Michael Pyne
copyright : (c) 2007, 2008 by Michael Pyne
email : michael.pyne@kdemail.net
***************************************************************************/
......@@ -25,14 +25,22 @@
#include <kaction.h>
#include <kvbox.h>
#include <kconfiggroup.h>
#include <KShortcut>
#include <QHBoxLayout>
#include <QTimer>
#include <QButtonGroup>
#include <QRadioButton>
#include <QGroupBox>
#include <Q3WidgetStack>
#include <QString>
// Table of shortcut keys for each action, key group and three or four button modifier
struct KeyDialog::KeyInfo {
QString action;
KShortcut shortcut[3];
};
const KeyDialog::KeyInfo KeyDialog::keyInfo[] = {
{ "playPause",
{ KShortcut(),
......@@ -83,7 +91,7 @@ const KeyDialog::KeyInfo KeyDialog::keyInfo[] = {
const uint KeyDialog::keyInfoCount = sizeof(KeyDialog::keyInfo) / sizeof(KeyDialog::keyInfo[0]);
KeyDialog::KeyDialog(KActionCollection *actionCollection, QWidget *parent)
: KDialog(parent)
: KDialog(parent), m_actionCollection(actionCollection)
{
setCaption(i18n("Configure Shortcuts"));
setButtons(Default | Ok | Cancel);
......@@ -93,50 +101,45 @@ KeyDialog::KeyDialog(KActionCollection *actionCollection, QWidget *parent)
KConfigGroup config(KGlobal::config(), "Shortcuts");
int selectedButton = config.readEntry("GlobalKeys", int(StandardKeys));
// Create widgets for key chooser - widget stack used to replace key chooser
// Create widgets for key chooser
KVBox *vbox = new KVBox(this);
vbox->setSpacing(KDialog::spacingHint());
m_widgetStack = new Q3WidgetStack(vbox);
vbox->setStretchFactor(m_widgetStack, 1);
m_pKeyChooser = new KShortcutsEditor(actionCollection, vbox);
// Create buttons to select key group
m_group = new QButtonGroup(vbox);
QGroupBox *buttonBox = new QGroupBox(i18n("Global Shortcuts"), vbox);
m_group = new QButtonGroup(buttonBox);
QHBoxLayout *buttonLayout = new QHBoxLayout;
buttonBox->setLayout(buttonLayout);
QRadioButton *radioButton = new QRadioButton(i18n("&No keys"), buttonBox);
m_group->addButton(radioButton, NoKeys);
buttonLayout->addWidget(radioButton);
m_group->addButton(new QRadioButton(i18n("&No keys"), buttonBox), NoKeys);
m_group->addButton(new QRadioButton(i18n("&Standard keys"), buttonBox), StandardKeys);
m_group->addButton(new QRadioButton(i18n("&Multimedia keys"), buttonBox), MultimediaKeys);
radioButton = new QRadioButton(i18n("&Standard keys"), buttonBox);
m_group->addButton(radioButton, StandardKeys);
buttonLayout->addWidget(radioButton);
radioButton = new QRadioButton(i18n("&Multimedia keys"), buttonBox);
m_group->addButton(radioButton, MultimediaKeys);
buttonLayout->addWidget(radioButton);
connect(m_group, SIGNAL(buttonClicked(int)), this, SLOT(slotKeys(int)));
buttonBox->setWhatsThis(
i18n("Here you can select the keys used as global shortcuts to control the player"));
// Create the key chooser
m_group->button(selectedButton)->setChecked(true);
connect(this, SIGNAL(defaultClicked()), this, SLOT(slotDefault()));
setMainWidget(vbox);
newDialog(actionCollection, selectedButton);
resize(400, 500); // Make it bigger!
}
KeyDialog::~KeyDialog()
{
}
void KeyDialog::newDialog(KActionCollection *actionCollection, int selectedButton)
{
m_actionCollection = actionCollection;
// Create key chooser and show it in the widget stack
m_pKeyChooser = new KShortcutsEditor(actionCollection, this);
m_widgetStack->addWidget(m_pKeyChooser);
m_widgetStack->raiseWidget(m_pKeyChooser);
m_group->button(selectedButton)->setChecked(true);
connect(this, SIGNAL(defaultClicked()), this, SLOT(slotDefault()));
}
int KeyDialog::configure()
......@@ -152,6 +155,7 @@ int KeyDialog::configure()
m_pKeyChooser->save();
}
return retcode;
}
......@@ -160,17 +164,21 @@ void KeyDialog::slotKeys(int group)
// Set modifier keys according to key group and modifier keys
for(uint i = 0; i < keyInfoCount; i++) {
KAction *a = dynamic_cast<KAction*>(ActionCollection::action(keyInfo[i].action));
if(a)
a->setGlobalShortcut(keyInfo[i].shortcut[group]);
KAction *a = ActionCollection::action<KAction>(keyInfo[i].action);
if(a) {
KShortcut shortcut(keyInfo[i].shortcut[group]);
a->setGlobalShortcut(shortcut, KAction::ActiveShortcut, KAction::NoAutoloading);
}
}
// Create a new key chooser to show the keys, and delete the old one
// Update the key chooser widget.
// TODO: When widget is fixed to note the update remove this bit so that
// we don't drop user changes for no reason.
QWidget *w = m_widgetStack->visibleWidget();
newDialog(m_actionCollection, group);
m_widgetStack->removeWidget(w);
delete w;
m_pKeyChooser->clearCollections();
m_pKeyChooser->addCollection(m_actionCollection);
}
void KeyDialog::slotDefault()
......@@ -178,6 +186,7 @@ void KeyDialog::slotDefault()
// Select default keys - standard key group
m_group->button(StandardKeys)->setChecked(true);
slotKeys(StandardKeys);
m_pKeyChooser->allDefault();
}
......@@ -193,9 +202,13 @@ void KeyDialog::setupActionShortcut(const QString &actionName)
// Find and insert a standard key
KShortcut shortcut = KShortcut();
// Find out what type is selected so we know what keys to setup.
KConfigGroup config(KGlobal::config(), "Shortcuts");
int selectedKeys = config.readEntry("GlobalKeys", int(StandardKeys));
for(uint i = 0; i < keyInfoCount; i++) {
if(keyInfo[i].action == actionName) {
shortcut = keyInfo[i].shortcut[StandardKeys];
shortcut = keyInfo[i].shortcut[selectedKeys];
break;
}
}
......@@ -203,7 +216,7 @@ void KeyDialog::setupActionShortcut(const QString &actionName)
if(shortcut.isEmpty())
return; // We have no shortcut to set.
KAction *a = dynamic_cast<KAction*>(ActionCollection::action(actionName));
KAction *a = ActionCollection::action<KAction>(actionName);
if(a)
a->setGlobalShortcut(shortcut);
}
......
......@@ -2,7 +2,7 @@
begin : Tue Mar 11 19:00:00 CET 2003
copyright : (C) 2003 by Stefan Asserhall
email : stefan.asserhall@telia.com
copyright : (c) 2007 by Michael Pyne
copyright : (c) 2007, 2008 by Michael Pyne
email : michael.pyne@kdemail.net
***************************************************************************/
......@@ -18,13 +18,9 @@
#ifndef KEYDIALOG_H
#define KEYDIALOG_H
#include <kshortcut.h>
#include <kdialog.h>
#include <QString>
#include <KDialog>
class QButtonGroup;
class Q3WidgetStack;
class KActionCollection;
class KShortcutsEditor;
......@@ -59,16 +55,12 @@ public:
private:
/**
* Groups of keys that can be selected in the dialog.
* Groups of keys that can be selected in the dialog. If you add or remove
* a group you must also adjust struct KeyInfo::shortcut to have enough
* entries for all groups, and then adjust the keyInfo[] array.
*/
enum KeyGroup { NoKeys = 0, StandardKeys = 1, MultimediaKeys = 2 };
struct KeyInfo {
QString action;
KShortcut shortcut[3];
};
void newDialog(KActionCollection *actionCollection, int selectedButton = 0);
int configure();
private slots:
......@@ -77,9 +69,10 @@ private slots:
private:
KActionCollection *m_actionCollection;
KShortcutsEditor *m_pKeyChooser;
KShortcutsEditor *m_pKeyChooser;
QButtonGroup *m_group;
Q3WidgetStack *m_widgetStack;
struct KeyInfo;
static const KeyInfo keyInfo[];
static const uint keyInfoCount;
......
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