Files
thunderpad/src/axis_edit.cpp
John Toman 17ed926cdf reverting trunk back to stable 3.4.1 version
git-svn-id: svn://svn.code.sf.net/p/qjoypad/code/trunk@82 c05e91a0-76c8-4ec0-b377-ef19ce7cc080
2009-05-26 00:57:02 +00:00

132 lines
3.8 KiB
C++

#include "axis_edit.h"
AxisEdit::AxisEdit( Axis* ax )
:QDialog() {
//build the dialog, display current axis settings :)
axis = ax;
setCaption("Set " + axis->getName());
setIcon(QPixmap(ICON24));
//h, v, and v2 are all references to layouts. They are used to refer to
//various layouts as the dialog is built and are not pointing to the same
//thing throughout. This is just because I don't care about the layouts
//after I have placed the widgets within them and there's no reasno to
//keep track of them.
QVBoxLayout* v = new QVBoxLayout(this, 5, 5);
QHBoxLayout* h = new QHBoxLayout();
QVBoxLayout* v2 = new QVBoxLayout(0,5,5);
CGradient = new QCheckBox("Gradient", this);
CGradient->setChecked(axis->gradient);
v2->addWidget(CGradient);
CMode = new QComboBox(this);
CMode->insertItem("Keyboard",keybd);
CMode->insertItem("Mouse (Vert.)",mousepv);
CMode->insertItem("Mouse (Vert. Rev.)", mousenv);
CMode->insertItem("Mouse (Hor.)", mouseph);
CMode->insertItem("Mouse (Hor. Rev.)", mousenh);
CMode->setCurrentItem( axis->mode );
connect(CMode, SIGNAL(activated(int)), this, SLOT( CModeChanged( int )));
v2->addWidget(CMode);
h->addLayout(v2);
MouseBox = new QFrame(this);
MouseBox->setFrameStyle( QFrame::Box | QFrame::Sunken );
v2 = new QVBoxLayout(MouseBox,5,5);
v2->setAutoAdd(true);
new QLabel("Mouse Speed", MouseBox);
SSpeed = new QSpinBox(0,MAXMOUSESPEED,1,MouseBox);
SSpeed->setValue(axis->maxSpeed);
h->addWidget(MouseBox);
v->addLayout(h);
Slider = new JoySlider(axis->dZone, axis->xZone, axis->state, this);
v->addWidget(Slider);
KeyBox = new QFrame(this);
KeyBox->setFrameStyle( QFrame::Box | QFrame::Sunken );
h = new QHBoxLayout(KeyBox, 5, 5);
h->setAutoAdd(true);
BNeg = new KeyButton(axis->getName(),axis->nkeycode,KeyBox);
CThrottle = new QComboBox(KeyBox);
CThrottle->insertItem("Neg. Throttle",0);
CThrottle->insertItem("No Throttle",1);
CThrottle->insertItem("Pos. Throttle",2);
CThrottle->setCurrentItem(axis->throttle + 1);
connect( CThrottle, SIGNAL( activated( int )), this, SLOT( CThrottleChanged( int )));
BPos = new KeyButton(axis->getName(),axis->pkeycode,KeyBox);
v->addWidget( KeyBox );
h = new QHBoxLayout();
BOkay = new QPushButton("Okay", this);
connect(BOkay, SIGNAL( clicked() ), this, SLOT( accept()));
h->addWidget(BOkay);
BCancel = new QPushButton("Cancel", this);
connect(BCancel, SIGNAL( clicked() ), this, SLOT( reject()));
h->addWidget(BCancel);
v->addLayout(h);
CModeChanged( axis->mode );
CThrottleChanged( axis->throttle + 1 );
}
void AxisEdit::show() {
QDialog::show();
setFixedSize(size());
}
void AxisEdit::setState( int val ) {
Slider->setValue( val );
}
void AxisEdit::CModeChanged( int index ) {
if (index == keybd) {
MouseBox->setEnabled(false);
KeyBox->setEnabled(true);
}
else {
MouseBox->setEnabled(true);
KeyBox->setEnabled(false);
}
}
void AxisEdit::CThrottleChanged( int index ) {
switch (index) {
case 0: BNeg->setEnabled(true);
BPos->setEnabled(false);
break;
case 1: BNeg->setEnabled(true);
BPos->setEnabled(true);
break;
case 2: BNeg->setEnabled(false);
BPos->setEnabled(true);
break;
}
Slider->setThrottle( index - 1 );
}
void AxisEdit::accept() {
//if the gradient status has changed, either request a timer or turn it down.
if (axis->gradient) {
if (!CGradient->isChecked()) tossTimer(axis);
}
else {
if (CGradient->isChecked()) takeTimer(axis);
}
axis->gradient = CGradient->isChecked();
axis->maxSpeed = SSpeed->value();
axis->throttle = CThrottle->currentItem() - 1;
axis->dZone = Slider->dZone();
axis->xZone = Slider->xZone();
axis->mode = (AxisMode) CMode->currentItem();
axis->pkeycode = BPos->getValue();
axis->nkeycode = BNeg->getValue();
axis->adjustGradient();
QDialog::accept();
}