1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
//
// C++ Implementation: shortcutcapturedialog
//
// Description:
// Dialog window for capturing keyboard shortcuts
//
// Author: Mathias Lundgren <lunar_shuttle@users.sourceforge.net>, (C) 2003
//
// Copyright: Mathias Lundgren (lunar_shuttle@users.sourceforge.net) (C) 2003
//
//
#include "shortcutcapturedialog.h"
#include "shortcuts.h"
#include <qkeysequence.h>
#include <qlabel.h>
#include <qevent.h>
#include <qpushbutton.h>
ShortcutCaptureDialog::ShortcutCaptureDialog(QWidget* parent, const char* name, int index)
: ShortcutCaptureDialogBase(parent, name, true)
{
QKeySequence q = QKeySequence(shortcuts[index].key);
oshrtLabel->setText(q);
connect(okButton, SIGNAL( clicked() ), this, SLOT( apply() ) );
connect(cancelButton, SIGNAL(pressed()), this, SLOT(cancel()));
shortcutindex = index;
grabKeyboard();
okButton->setText(tr("Ok"));
cancelButton->setText(tr("Cancel"));
}
ShortcutCaptureDialog::~ShortcutCaptureDialog()
{
releaseKeyboard();
}
void ShortcutCaptureDialog::keyPressEvent(QKeyEvent* e)
{
bool shift, alt, ctrl, conflict = false, realkey = false;
QString msgString = "";
int temp_key;
shift = e->state() & ShiftButton;
ctrl = e->state() & ControlButton;
alt = e->state() & AltButton;
//printf("Key total: %d, alt: %d, ctrl: %d shift: %d\n",e->key(), alt, ctrl, shift);
temp_key = e->key();
temp_key += (shift ? Qt::SHIFT : 0);
temp_key += (ctrl ? Qt::CTRL : 0);
temp_key += (alt ? Qt::ALT : 0);
//printf("Final key assembled: %d\n",temp_key);
// Check if this is a "real" key that completes a valid shortcut:
int k = e->key();
if (k < 256 || k == Key_Enter || k == Key_Return || (k >= Key_F1 && k <= Key_F12) || k == Key_Home || k == Key_PageUp
|| k == Key_PageDown || k == Key_End || k == Key_Insert || k == Key_Delete) {
key = temp_key;
realkey = true;
QKeySequence q = QKeySequence(key);
QString keyString = q;
if (keyString != QString::null)
nshrtLabel->setText(q);
// Check against conflicting shortcuts
for (int i=0; i < SHRT_NUM_OF_ELEMENTS; i++) {
if (shortcuts[i].key == key && (shortcuts[i].type & (shortcuts[shortcutindex].type | GLOBAL_SHRT | INVIS_SHRT))) {
msgString = tr("Shortcut conflicts with ") + QString(shortcuts[i].descr);
conflict = true;
break;
}
}
}
messageLabel->setText(msgString);
okButton->setEnabled(conflict == false && realkey);
if (!realkey)
nshrtLabel->setText(tr("Undefined"));
}
void ShortcutCaptureDialog::apply()
{
//return the shortcut to configurator widget:
done(key);
}
|