use QDilaogButtonBox for Ok/Cancel buttons

This commit is contained in:
Mathias Panzenböck
2014-02-21 23:11:12 +01:00
parent c93aa1df37
commit c5f9ec7e4c
4 changed files with 28 additions and 37 deletions

View File

@ -98,14 +98,10 @@ AxisEdit::AxisEdit( Axis* ax )
h->addWidget(btnPos); h->addWidget(btnPos);
v->addWidget( keyBox ); v->addWidget( keyBox );
h = new QHBoxLayout(); QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal, this);
btnOkay = new QPushButton("&Okay", this); connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
connect(btnOkay, SIGNAL( clicked() ), this, SLOT( accept())); connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
h->addWidget(btnOkay); v->addWidget(buttonBox);
btnCancel = new QPushButton("&Cancel", this);
connect(btnCancel, SIGNAL( clicked() ), this, SLOT( reject()));
h->addWidget(btnCancel);
v->addLayout(h);
modeChanged( axis->mode ); modeChanged( axis->mode );
transferCurveChanged( axis->transferCurve ); transferCurveChanged( axis->transferCurve );
@ -131,8 +127,8 @@ void AxisEdit::gradientChanged( bool on ) {
} }
} }
void AxisEdit::modeChanged( int index ) { void AxisEdit::modeChanged( Axis::Mode mode ) {
if (index == Axis::Keyboard) { if (mode == Axis::Keyboard) {
mouseBox->setEnabled(false); mouseBox->setEnabled(false);
keyBox->setEnabled(true); keyBox->setEnabled(true);
} }

View File

@ -8,6 +8,7 @@
#include <QCheckBox> #include <QCheckBox>
#include <QDoubleSpinBox> #include <QDoubleSpinBox>
#include <QLabel> #include <QLabel>
#include <QDialogButtonBox>
//for my home-brewed widgets //for my home-brewed widgets
#include "joyslider.h" #include "joyslider.h"
#include "keycode.h" #include "keycode.h"
@ -24,7 +25,7 @@ class AxisEdit : public QDialog {
protected slots: protected slots:
//slots for GUI events //slots for GUI events
void gradientChanged( bool on ); void gradientChanged( bool on );
void modeChanged( int index ); void modeChanged( Axis::Mode mode );
void transferCurveChanged( int index ); void transferCurveChanged( int index );
void throttleChanged( int index ); void throttleChanged( int index );
void accept(); void accept();
@ -40,7 +41,6 @@ class AxisEdit : public QDialog {
QDoubleSpinBox *spinSensitivity; QDoubleSpinBox *spinSensitivity;
KeyButton *btnNeg, *btnPos; KeyButton *btnNeg, *btnPos;
JoySlider *slider; JoySlider *slider;
QPushButton *btnOkay, *btnCancel;
}; };
#endif #endif

View File

@ -5,7 +5,7 @@
#include <QVBoxLayout> #include <QVBoxLayout>
ButtonEdit::ButtonEdit(Button* butt) ButtonEdit::ButtonEdit(Button* butt)
:QDialog(0) { : QDialog(0) {
setModal(true); setModal(true);
//build the dialog! //build the dialog!
button = butt; button = butt;
@ -16,26 +16,22 @@ ButtonEdit::ButtonEdit(Button* butt)
v->setMargin(5); v->setMargin(5);
v->setSpacing(5); v->setSpacing(5);
BKKey = new KeyButton( button->getName(), button->keycode, this, true, button->useMouse); btnKey = new KeyButton( button->getName(), button->keycode, this, true, button->useMouse);
v->addWidget(BKKey); v->addWidget(btnKey);
QHBoxLayout* h = new QHBoxLayout(); QHBoxLayout* h = new QHBoxLayout();
CSticky = new QCheckBox("&Sticky", this); chkSticky = new QCheckBox("&Sticky", this);
CSticky->setChecked(button->sticky); chkSticky->setChecked(button->sticky);
h->addWidget(CSticky); h->addWidget(chkSticky);
CRapid = new QCheckBox("&Rapid Fire", this); chkRapid = new QCheckBox("&Rapid Fire", this);
CRapid->setChecked(button->rapidfire); chkRapid->setChecked(button->rapidfire);
h->addWidget(CRapid); h->addWidget(chkRapid);
v->addLayout(h); v->addLayout(h);
h = new QHBoxLayout(); QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal, this);
BOkay = new QPushButton("&Okay", this); connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
connect(BOkay, SIGNAL( clicked() ), this, SLOT( accept())); connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
h->addWidget(BOkay); v->addWidget(buttonBox);
BCancel = new QPushButton("&Cancel", this);
connect(BCancel, SIGNAL( clicked() ), this, SLOT( reject()));
h->addWidget(BCancel);
v->addLayout(h);
} }
void ButtonEdit::show() { void ButtonEdit::show() {
@ -51,11 +47,11 @@ void ButtonEdit::accept() {
else { else {
if (CRapid->isChecked()) takeTimer(button); if (CRapid->isChecked()) takeTimer(button);
}*/ }*/
button->rapidfire = CRapid->isChecked(); button->rapidfire = chkRapid->isChecked();
button->sticky = (CSticky->isChecked()); button->sticky = chkSticky->isChecked();
//if the user chose a mouse button... //if the user chose a mouse button...
button->useMouse = BKKey->choseMouse(); button->useMouse = btnKey->choseMouse();
button->keycode = BKKey->getValue(); button->keycode = btnKey->getValue();
QDialog::accept(); QDialog::accept();
} }

View File

@ -3,6 +3,7 @@
#include <QPushButton> #include <QPushButton>
#include <QCheckBox> #include <QCheckBox>
#include <QDialogButtonBox>
//we need to edit a Button //we need to edit a Button
#include "button.h" #include "button.h"
@ -20,10 +21,8 @@ class ButtonEdit : public QDialog {
void accept(); void accept();
protected: protected:
Button *button; Button *button;
KeyButton *BKKey; KeyButton *btnKey;
QPushButton *BKey, *BMouse, *BOkay, *BCancel; QCheckBox *chkSticky, *chkRapid;
QPushButton **BMKey;
QCheckBox *CSticky, *CRapid;
}; };