2 // controllertab.cpp: "Controller" tab on the config dialog
4 // Part of the Virtual Jaguar Project
5 // (C) 2011 Underground Software
6 // See the README and GPLv3 files for licensing and warranty information
8 // JLH = James Hammons <jlhamm@acm.org>
11 // --- ---------- ------------------------------------------------------------
12 // JLH 06/23/2011 Created this file
13 // JLH 07/20/2011 Fixed a bunch of stuff
16 #include "controllertab.h"
18 #include "controllerwidget.h"
21 #include "keygrabber.h"
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))
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());
45 setFixedWidth(sizeHint().width());
47 connect(redefineAll, SIGNAL(clicked()), this, SLOT(DefineAllKeys()));
49 //this is the default. :-/ need to set it somewhere else i guess...
50 // profile->setSizeAdjustPolicy(QComboBox::AdjustToContentsOnFirstShow);
51 profile->addItem(tr("Keyboard"));
53 for(int i=0; i<Gamepad::numJoysticks; i++)
54 profile->addItem(Gamepad::GetJoystickName(i));
58 ControllerTab::~ControllerTab()
63 //QSize ControllerTab::sizeHint(void) const
69 void ControllerTab::DefineAllKeys(void)
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);
77 for(int i=BUTTON_FIRST; i<=BUTTON_LAST; i++)
79 // keyGrab.SetText(jagButtonName[orderToDefine[i]]);
80 keyGrab.SetKeyText(orderToDefine[i]);
82 int key = keyGrab.key;
84 if (key == Qt::Key_Escape)
87 // Otherwise, populate the appropriate spot in the settings & update screen...
88 controllerWidget->keys[orderToDefine[i]] = key;
89 controllerWidget->update();