]> Shamusworld >> Repos - virtualjaguar/blob - src/gui/controllertab.cpp
ce09270ff86b53fd2e186b42260d9ec95b9d389d
[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
37 ControllerTab::~ControllerTab()
38 {
39 }
40
41
42 void ControllerTab::DefineAllKeys(void)
43 {
44 //      char jagButtonName[21][10] = { "Up", "Down", "Left", "Right",
45 //              "*", "7", "4", "1", "0", "8", "5", "2", "#", "9", "6", "3",
46 //              "A", "B", "C", "Option", "Pause" };
47         int orderToDefine[21] = { 0, 1, 2, 3, 18, 17, 16, 20, 19, 7, 11, 15, 6, 10, 14, 5, 9, 13, 8, 4, 12 };
48         KeyGrabber keyGrab(this);
49
50         for(int i=BUTTON_FIRST; i<=BUTTON_LAST; i++)
51         {
52 //              keyGrab.SetText(jagButtonName[orderToDefine[i]]);
53                 keyGrab.SetKeyText(orderToDefine[i]);
54                 keyGrab.exec();
55                 int key = keyGrab.key;
56
57                 if (key == Qt::Key_Escape)
58                         break;
59
60                 // Otherwise, populate the appropriate spot in the settings & update screen...
61                 controllerWidget->keys[orderToDefine[i]] = key;
62                 controllerWidget->update();
63         }
64 }
65