2 // keygrabber.cpp - Widget to grab a key and dismiss itself
5 // (C) 2011 Underground Software
7 // JLH = James Hammons <jlhamm@acm.org>
10 // --- ---------- -------------------------------------------------------------
11 // JLH 07/18/2011 Created this file
14 #include "keygrabber.h"
18 KeyGrabber::KeyGrabber(QWidget * parent/*= 0*/): QDialog(parent),
19 label(new QLabel), timer(new QTimer), buttonDown(false)
21 // label = new QLabel(this);
22 QVBoxLayout * mainLayout = new QVBoxLayout;
23 mainLayout->addWidget(label);
24 setLayout(mainLayout);
25 setWindowTitle(tr("Grab"));
26 connect(timer, SIGNAL(timeout()), this, SLOT(CheckGamepad()));
27 timer->setInterval(100);
30 // Will this make Mac OSX work???
31 setFocusPolicy(Qt::StrongFocus);
35 KeyGrabber::~KeyGrabber()
41 void KeyGrabber::SetKeyText(int keyNum)
43 char jagButtonName[21][10] = { "Up", "Down", "Left", "Right",
44 "*", "7", "4", "1", "0", "8", "5", "2", "#", "9", "6", "3",
45 "A", "B", "C", "Option", "Pause" };
47 QString text = QString(tr("Press key for \"%1\"<br>(ESC to cancel)"))
48 .arg(QString(jagButtonName[keyNum]));
53 void KeyGrabber::keyPressEvent(QKeyEvent * e)
57 // Since this is problematic, we don't allow this key...
58 if (key != Qt::Key_Alt)
63 void KeyGrabber::CheckGamepad(void)
65 // How do we determine which joystick it is, if more than one?
66 // Possibly by a combobox selecting the stick you want to configure...
71 button = Gamepad::CheckButtonPressed();
80 if (Gamepad::CheckButtonPressed() == button)