~ubuntu-branches/ubuntu/breezy/kdemultimedia/breezy

« back to all changes in this revision

Viewing changes to juk/keydialog.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2005-03-24 04:48:58 UTC
  • mfrom: (1.2.1 upstream) (2.1.1 sarge)
  • Revision ID: james.westby@ubuntu.com-20050324044858-8ff88o9jxej6ii3d
Tags: 4:3.4.0-0ubuntu3
Add kubuntu_02_hide_arts_menu_entries.diff to hide artsbuilder and artscontrol k-menu entries

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
    begin                : Tue Mar 11 19:00:00 CET 2003
 
3
    copyright            : (C) 2003 by Stefan Asserhall
 
4
    email                : stefan.asserhall@telia.com
 
5
***************************************************************************/
 
6
 
 
7
/***************************************************************************
 
8
 *                                                                         *
 
9
 *   This program is free software; you can redistribute it and/or modify  *
 
10
 *   it under the terms of the GNU General Public License as published by  *
 
11
 *   the Free Software Foundation; either version 2 of the License, or     *
 
12
 *   (at your option) any later version.                                   *
 
13
 *                                                                         *
 
14
 ***************************************************************************/
 
15
 
 
16
#include "keydialog.h"
 
17
 
 
18
#include <kconfig.h>
 
19
#include <klocale.h>
 
20
 
 
21
#include <qradiobutton.h>
 
22
#include <qvbox.h>
 
23
#include <qwhatsthis.h>
 
24
 
 
25
 
 
26
// Table of shortcut keys for each action, key group and three or four button modifier
 
27
 
 
28
const KeyDialog::KeyInfo KeyDialog::keyInfo[] = {
 
29
    { "PlayPause",
 
30
      { { KShortcut::null(),                        KShortcut::null() },
 
31
        { Qt::CTRL+Qt::ALT+Qt::Key_P,               KKey::QtWIN+Qt::ALT+Qt::Key_P },
 
32
        { Qt::Key_MediaPlay,                        Qt::Key_MediaPlay } } },
 
33
    { "Stop",
 
34
      { { KShortcut::null(),                        KShortcut::null() },
 
35
        { Qt::CTRL+Qt::ALT+Qt::Key_S,               KKey::QtWIN+Qt::ALT+Qt::Key_S },
 
36
        { Qt::Key_MediaStop,                        Qt::Key_MediaStop } } },
 
37
    { "Back",
 
38
      { { KShortcut::null(),                        KShortcut::null() },
 
39
        { Qt::CTRL+Qt::ALT+Qt::Key_Left,            KKey::QtWIN+Qt::ALT+Qt::Key_Left },
 
40
        { Qt::Key_MediaPrev,                        Qt::Key_MediaPrev } } },
 
41
    { "Forward",
 
42
      { { KShortcut::null(),                        KShortcut::null() },
 
43
        { Qt::CTRL+Qt::ALT+Qt::Key_Right,           KKey::QtWIN+Qt::ALT+Qt::Key_Right },
 
44
        { Qt::Key_MediaNext,                        Qt::Key_MediaNext } } },
 
45
    { "ForwardAlbum",
 
46
      { { KShortcut::null(),                        KShortcut::null() },
 
47
        { Qt::CTRL+Qt::ALT+Qt::Key_Up,              KKey::QtWIN+Qt::ALT+Qt::Key_Up },
 
48
        { Qt::CTRL+Qt::Key_MediaNext,               Qt::CTRL+Qt::Key_MediaNext } } },
 
49
    { "SeekBack",
 
50
      { { KShortcut::null(),                        KShortcut::null() },
 
51
        { Qt::CTRL+Qt::SHIFT+Qt::ALT+Qt::Key_Left,  KKey::QtWIN+Qt::SHIFT+Qt::ALT+Qt::Key_Left },
 
52
        { Qt::SHIFT+Qt::Key_MediaPrev,              Qt::SHIFT+Qt::Key_MediaPrev } } },
 
53
    { "SeekForward",
 
54
      { { KShortcut::null(),                        KShortcut::null() },
 
55
        { Qt::CTRL+Qt::SHIFT+Qt::ALT+Qt::Key_Right, KKey::QtWIN+Qt::SHIFT+Qt::ALT+Qt::Key_Right },
 
56
        { Qt::SHIFT+Qt::Key_MediaNext,              Qt::SHIFT+Qt::Key_MediaNext } } },
 
57
    { "VolumeUp",
 
58
      { { KShortcut::null(),                        KShortcut::null() },
 
59
        { Qt::CTRL+Qt::ALT+Qt::SHIFT+Qt::Key_Up,    KKey::QtWIN+Qt::ALT+Qt::SHIFT+Qt::Key_Up },
 
60
        { Qt::Key_VolumeUp,                         Qt::Key_VolumeUp } } },
 
61
    { "VolumeDown",
 
62
      { { KShortcut::null(),                        KShortcut::null() },
 
63
        { Qt::CTRL+Qt::ALT+Qt::SHIFT+Qt::Key_Down,  KKey::QtWIN+Qt::ALT+Qt::SHIFT+Qt::Key_Down },
 
64
        { Qt::Key_VolumeDown,                       Qt::Key_VolumeDown } } },
 
65
    { "Mute",
 
66
      { { KShortcut::null(),                        KShortcut::null() },
 
67
        { Qt::CTRL+Qt::ALT+Qt::Key_M,               KKey::QtWIN+Qt::ALT+Qt::Key_M },
 
68
        { Qt::Key_VolumeMute,                       Qt::Key_VolumeMute } } },
 
69
    { "ShowHide",
 
70
      { { KShortcut::null(),                        KShortcut::null() },
 
71
        { KShortcut::null(),                        KShortcut::null() },
 
72
        { KShortcut::null(),                        KShortcut::null() } } }
 
73
};
 
74
 
 
75
const uint KeyDialog::keyInfoCount = sizeof(KeyDialog::keyInfo) / sizeof(KeyDialog::keyInfo[0]);
 
76
 
 
77
KeyDialog::KeyDialog(KGlobalAccel *keys, KActionCollection *actionCollection,
 
78
                     QWidget *parent, const char *name)
 
79
    : KDialogBase(parent, name, true, i18n("Configure Shortcuts"), Default | Ok | Cancel, Ok)
 
80
{
 
81
    // Read key group from configuration
 
82
 
 
83
    int selectedButton;
 
84
 
 
85
    KConfigGroup config(KGlobal::config(), "Shortcuts");
 
86
    selectedButton = config.readNumEntry("GlobalKeys", StandardKeys);
 
87
 
 
88
    // Create widgets for key chooser - widget stack used to replace key chooser
 
89
 
 
90
    QVBox *vbox = new QVBox(this);
 
91
    vbox->setSpacing(KDialog::spacingHint());
 
92
    m_widgetStack = new QWidgetStack(vbox);
 
93
 
 
94
    vbox->setStretchFactor(m_widgetStack, 1);
 
95
 
 
96
    // Create buttons to select key group
 
97
 
 
98
    m_group = new QHButtonGroup(i18n("Global Shortcuts"), vbox);
 
99
    new QRadioButton(i18n("&No keys"), m_group);
 
100
    new QRadioButton(i18n("&Standard keys"), m_group);
 
101
    new QRadioButton(i18n("&Multimedia keys"), m_group);
 
102
    connect(m_group, SIGNAL(clicked(int)), this, SLOT(slotKeys(int)));
 
103
    QWhatsThis::add(m_group,
 
104
      i18n("Here you can select the keys used as global shortcuts to control the player"));
 
105
 
 
106
    // Create the key chooser
 
107
 
 
108
    setMainWidget(vbox);
 
109
    newDialog(keys, actionCollection, selectedButton);
 
110
}
 
111
 
 
112
KeyDialog::~KeyDialog()
 
113
{
 
114
 
 
115
}
 
116
 
 
117
void KeyDialog::newDialog(KGlobalAccel *keys, KActionCollection *actionCollection,
 
118
                          int selectedButton)
 
119
{
 
120
    m_keys = keys;
 
121
    m_actionCollection = actionCollection;
 
122
 
 
123
    // Create key chooser and show it in the widget stack
 
124
    m_pKeyChooser = new KKeyChooser(keys, this);
 
125
    m_pKeyChooser->insert(actionCollection);
 
126
    m_widgetStack->addWidget(m_pKeyChooser);
 
127
    m_widgetStack->raiseWidget(m_pKeyChooser);
 
128
    m_group->setButton(selectedButton);
 
129
 
 
130
    connect(this, SIGNAL(defaultClicked()), this, SLOT(slotDefault()));
 
131
}
 
132
 
 
133
int KeyDialog::configure()
 
134
{
 
135
    // Show the dialog and save configuration if accepted
 
136
 
 
137
    int retcode = exec();
 
138
    if(retcode == Accepted) {
 
139
 
 
140
        KConfigGroup config(KGlobal::config(), "Shortcuts");
 
141
        config.writeEntry("GlobalKeys", m_group->id(m_group->selected()));
 
142
        KGlobal::config()->sync();
 
143
 
 
144
        m_pKeyChooser->save();
 
145
    }
 
146
    return retcode;
 
147
}
 
148
 
 
149
void KeyDialog::slotKeys(int group)
 
150
{
 
151
    bool fourModKeys = KGlobalAccel::useFourModifierKeys();
 
152
 
 
153
    // Set modifier keys according to key group and modifier keys
 
154
 
 
155
    for(uint i = 0; i < keyInfoCount; i++)
 
156
        m_keys->setShortcut(keyInfo[i].action, keyInfo[i].shortcut[group][fourModKeys]);
 
157
 
 
158
    // Create a new key chooser to show the keys, and delete the old one
 
159
 
 
160
    QWidget *w = m_widgetStack->visibleWidget();
 
161
    newDialog(m_keys, m_actionCollection, group);
 
162
    m_widgetStack->removeWidget(w);
 
163
    delete w;
 
164
}
 
165
 
 
166
void KeyDialog::slotDefault()
 
167
{
 
168
    // Select default keys - standard key group
 
169
 
 
170
    m_group->setButton(StandardKeys);
 
171
    m_pKeyChooser->allDefault();
 
172
}
 
173
 
 
174
int KeyDialog::configure(KGlobalAccel *keys, KActionCollection *actionCollection,
 
175
                         QWidget *parent)
 
176
{
 
177
    // Create and show dialog - update connections if accepted
 
178
 
 
179
    int retcode = KeyDialog(keys, actionCollection, parent).configure();
 
180
 
 
181
    if(retcode == Accepted)
 
182
        keys->updateConnections();
 
183
    return retcode;
 
184
}
 
185
 
 
186
void KeyDialog::insert(KGlobalAccel *keys, const QString &action, const QString &label,
 
187
                       const QObject *objSlot, const char *methodSlot)
 
188
{
 
189
    KShortcut def3 = KShortcut::null();
 
190
    KShortcut def4 = KShortcut::null();
 
191
 
 
192
    // Find and insert a standard key
 
193
 
 
194
    for(uint i = 0; i < keyInfoCount; i++) {
 
195
        if(keyInfo[i].action == action) {
 
196
            def3 = keyInfo[i].shortcut[StandardKeys][0];
 
197
            def4 = keyInfo[i].shortcut[StandardKeys][1];
 
198
            break;
 
199
        }
 
200
    }
 
201
    keys->insert(action, label, QString::null, def3, def4, objSlot, methodSlot);
 
202
}
 
203
 
 
204
#include "keydialog.moc"