]> Shamusworld >> Repos - virtualjaguar/blob - src/gui/keygrabber.cpp
694be3cb5d20439e78edc2c7e5536d544b9d2998
[virtualjaguar] / src / gui / keygrabber.cpp
1 //
2 // keygrabber.cpp - Widget to grab a key and dismiss itself
3 //
4 // by James Hammons
5 // (C) 2011 Underground Software
6 //
7 // JLH = James Hammons <jlhamm@acm.org>
8 //
9 // Who  When        What
10 // ---  ----------  -------------------------------------------------------------
11 // JLH  07/18/2011  Created this file
12 //
13
14 #include "keygrabber.h"
15
16
17 KeyGrabber::KeyGrabber(QWidget * parent/*= 0*/): QDialog(parent)
18 {
19         label = new QLabel(this);
20         QVBoxLayout * mainLayout = new QVBoxLayout;
21         mainLayout->addWidget(label);
22         setLayout(mainLayout);
23         setWindowTitle(tr("Grab"));
24
25         // Will this make Mac OSX work???
26         setFocusPolicy(Qt::StrongFocus);
27 }
28
29 KeyGrabber::~KeyGrabber()
30 {
31 }
32
33 //void KeyGrabber::SetText(QString keyText)
34 void KeyGrabber::SetKeyText(int keyNum)
35 {
36         char jagButtonName[21][10] = { "Up", "Down", "Left", "Right",
37                 "*", "7", "4", "1", "0", "8", "5", "2", "#", "9", "6", "3",
38                 "A", "B", "C", "Option", "Pause" };
39
40         QString text = QString(tr("Press key for \"%1\"<br>(ESC to cancel)"))
41                 .arg(QString(jagButtonName[keyNum]));
42         label->setText(text);
43 }
44
45 void KeyGrabber::keyPressEvent(QKeyEvent * e)
46 {
47         key = e->key();
48
49         // Since this is problematic, we don't allow this key...
50         if (key != Qt::Key_Alt)
51                 accept();
52 }