]> Shamusworld >> Repos - virtualjaguar/blob - src/gui/controllertab.cpp
Fixes for fullscreen mode, initial stab at multiple controller configs
[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 "gamepad.h"
20 #include "joystick.h"
21 #include "keygrabber.h"
22
23
24 ControllerTab::ControllerTab(QWidget * parent/*= 0*/): QWidget(parent),
25         label(new QLabel(tr("Controller:"))),
26         profile(new QComboBox(this)),
27         redefineAll(new QPushButton(tr("Define All Inputs"))),
28         controllerWidget(new ControllerWidget(this))
29 {
30         QVBoxLayout * layout = new QVBoxLayout;
31         QHBoxLayout * top = new QHBoxLayout;
32         layout->addLayout(top);
33         top->addWidget(label);
34         top->addWidget(profile, 0, Qt::AlignLeft);
35         layout->addWidget(controllerWidget);
36         layout->addWidget(redefineAll, 0, Qt::AlignHCenter);
37 //      layout->setFixedWidth(label->width());
38 //      layout->setSizeConstraint(QLayout::SetFixedSize);
39 //      top->setSizeConstraint(QLayout::SetFixedSize);
40 //printf("cw width = %i, label width = %i (min=%i, sizehint=%i)\n", controllerWidget->width(), label->width(), label->minimumWidth(), label->sizeHint().width());
41         // This is ugly, ugly, ugly. But it works. :-P It's a shame that Qt's
42         // layout system doesn't seem to allow for a nicer way to handle this.
43 //      profile->setFixedWidth(controllerWidget->sizeHint().width() - label->sizeHint().width());
44         setLayout(layout);
45         setFixedWidth(sizeHint().width());
46
47         connect(redefineAll, SIGNAL(clicked()), this, SLOT(DefineAllKeys()));
48
49 //this is the default. :-/ need to set it somewhere else i guess...
50 //      profile->setSizeAdjustPolicy(QComboBox::AdjustToContentsOnFirstShow);
51         profile->addItem(tr("Keyboard"));
52
53         for(int i=0; i<Gamepad::numJoysticks; i++)
54                 profile->addItem(Gamepad::GetJoystickName(i));
55 }
56
57
58 ControllerTab::~ControllerTab()
59 {
60 }
61
62
63 //QSize ControllerTab::sizeHint(void) const
64 //{
65 //      return 
66 //}
67
68
69 void ControllerTab::DefineAllKeys(void)
70 {
71 //      char jagButtonName[21][10] = { "Up", "Down", "Left", "Right",
72 //              "*", "7", "4", "1", "0", "8", "5", "2", "#", "9", "6", "3",
73 //              "A", "B", "C", "Option", "Pause" };
74         int orderToDefine[21] = { 0, 1, 2, 3, 18, 17, 16, 20, 19, 7, 11, 15, 6, 10, 14, 5, 9, 13, 8, 4, 12 };
75         KeyGrabber keyGrab(this);
76
77         for(int i=BUTTON_FIRST; i<=BUTTON_LAST; i++)
78         {
79 //              keyGrab.SetText(jagButtonName[orderToDefine[i]]);
80                 keyGrab.SetKeyText(orderToDefine[i]);
81                 keyGrab.exec();
82                 int key = keyGrab.key;
83
84                 if (key == Qt::Key_Escape)
85                         break;
86
87                 // Otherwise, populate the appropriate spot in the settings & update screen...
88                 controllerWidget->keys[orderToDefine[i]] = key;
89                 controllerWidget->update();
90         }
91 }
92