]> Shamusworld >> Repos - virtualjaguar/blob - src/gui/controllertab.cpp
957e568b1d7a32144ae219ce19fbc5283ed6c3d0
[virtualjaguar] / src / gui / controllertab.cpp
1 //
2 // controllertab.cpp: "Controller" tab on the config dialog
3 //
4 // Part of the Virtual Jaguar Project
5 // (C) 2011 Underground Software
6 // See the README and GPLv3 files for licensing and warranty information
7 //
8 // JLH = James Hammons <jlhamm@acm.org>
9 //
10 // WHO  WHEN        WHAT
11 // ---  ----------  ------------------------------------------------------------
12 // JLH  06/23/2011  Created this file
13 // JLH  07/20/2011  Fixed a bunch of stuff
14 //
15
16 #include "controllertab.h"
17
18 #include "controllerwidget.h"
19 #include "joystick.h"
20 #include "keygrabber.h"
21
22
23 ControllerTab::ControllerTab(QWidget * parent/*= 0*/): QWidget(parent)
24 {
25         controllerWidget = new ControllerWidget(this);
26         redefineAll = new QPushButton(tr("Define All Keys"));
27
28         QVBoxLayout * layout = new QVBoxLayout;
29         layout->addWidget(controllerWidget);
30         layout->addWidget(redefineAll);
31         setLayout(layout);
32
33         connect(redefineAll, SIGNAL(clicked()), this, SLOT(DefineAllKeys()));
34 }
35
36 ControllerTab::~ControllerTab()
37 {
38 }
39
40 void ControllerTab::DefineAllKeys(void)
41 {
42 //      char jagButtonName[21][10] = { "Up", "Down", "Left", "Right",
43 //              "*", "7", "4", "1", "0", "8", "5", "2", "#", "9", "6", "3",
44 //              "A", "B", "C", "Option", "Pause" };
45         int orderToDefine[21] = { 0, 1, 2, 3, 18, 17, 16, 20, 19, 7, 11, 15, 6, 10, 14, 5, 9, 13, 8, 4, 12 };
46         KeyGrabber keyGrab(this);
47
48         for(int i=BUTTON_FIRST; i<=BUTTON_LAST; i++)
49         {
50 //              keyGrab.SetText(jagButtonName[orderToDefine[i]]);
51                 keyGrab.SetKeyText(orderToDefine[i]);
52                 keyGrab.exec();
53                 int key = keyGrab.key;
54
55                 if (key == Qt::Key_Escape)
56                         break;
57
58                 // Otherwise, populate the appropriate spot in the settings & update screen...
59                 controllerWidget->keys[orderToDefine[i]] = key;
60                 controllerWidget->update();
61         }
62 }