X-Git-Url: http://shamusworld.gotdns.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fgui%2Fkeygrabber.cpp;h=b9b285c5248574f47355dfbfd14bbdb5942ddeb7;hb=62587015fb12ec54b1702bfa17077e4b8af44b19;hp=371c61991122a3d2a700a96b8ad8e90b37d89251;hpb=166019baeee39e3867ecf6c4eddd0855dc3507a4;p=virtualjaguar diff --git a/src/gui/keygrabber.cpp b/src/gui/keygrabber.cpp index 371c619..b9b285c 100644 --- a/src/gui/keygrabber.cpp +++ b/src/gui/keygrabber.cpp @@ -1,10 +1,10 @@ // // keygrabber.cpp - Widget to grab a key and dismiss itself // -// by James L. Hammons +// by James Hammons // (C) 2011 Underground Software // -// JLH = James L. Hammons +// JLH = James Hammons // // Who When What // --- ---------- ------------------------------------------------------------- @@ -12,29 +12,77 @@ // #include "keygrabber.h" +#include "gamepad.h" -KeyGrabber::KeyGrabber(QWidget * parent/*= 0*/): QDialog(parent) +KeyGrabber::KeyGrabber(QWidget * parent/*= 0*/): QDialog(parent), + label(new QLabel), timer(new QTimer), buttonDown(false) { - label = new QLabel(this); +// label = new QLabel(this); QVBoxLayout * mainLayout = new QVBoxLayout; mainLayout->addWidget(label); setLayout(mainLayout); setWindowTitle(tr("Grab")); + connect(timer, SIGNAL(timeout()), this, SLOT(CheckGamepad())); + timer->setInterval(100); + timer->start(); + + // Will this make Mac OSX work??? + setFocusPolicy(Qt::StrongFocus); } + KeyGrabber::~KeyGrabber() { + timer->stop(); } -void KeyGrabber::SetText(QString keyText) + +void KeyGrabber::SetKeyText(int keyNum) { - QString text = QString(tr("Press key for \"%1\"
(ESC to cancel)")).arg(keyText); + char jagButtonName[21][10] = { "Up", "Down", "Left", "Right", + "*", "7", "4", "1", "0", "8", "5", "2", "#", "9", "6", "3", + "A", "B", "C", "Option", "Pause" }; + + QString text = QString(tr("Press key for \"%1\"
(ESC to cancel)")) + .arg(QString(jagButtonName[keyNum])); label->setText(text); } + void KeyGrabber::keyPressEvent(QKeyEvent * e) { key = e->key(); - accept(); + + // Since this is problematic, we don't allow this key... + if (key != Qt::Key_Alt) + accept(); } + + +void KeyGrabber::CheckGamepad(void) +{ + // How do we determine which joystick it is, if more than one? + // Possibly by a combobox selecting the stick you want to configure... + Gamepad::Update(); + + if (!buttonDown) + { + button = Gamepad::CheckButtonPressed(); + + if (button == -1) + return; + + buttonDown = true; + } + else + { + if (Gamepad::CheckButtonPressed() == button) + return; + + key = button; + accept(); + buttonDown = false; + } +} +