From c5f9ec7e4c740eca51ff52feb25e6b8d8e977eae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mathias=20Panzenb=C3=B6ck?= Date: Fri, 21 Feb 2014 23:11:12 +0100 Subject: [PATCH] use QDilaogButtonBox for Ok/Cancel buttons --- src/axis_edit.cpp | 16 ++++++---------- src/axis_edit.h | 4 ++-- src/button_edit.cpp | 38 +++++++++++++++++--------------------- src/button_edit.h | 7 +++---- 4 files changed, 28 insertions(+), 37 deletions(-) diff --git a/src/axis_edit.cpp b/src/axis_edit.cpp index 40a0e45..8ca68e9 100644 --- a/src/axis_edit.cpp +++ b/src/axis_edit.cpp @@ -98,14 +98,10 @@ AxisEdit::AxisEdit( Axis* ax ) h->addWidget(btnPos); v->addWidget( keyBox ); - h = new QHBoxLayout(); - btnOkay = new QPushButton("&Okay", this); - connect(btnOkay, SIGNAL( clicked() ), this, SLOT( accept())); - h->addWidget(btnOkay); - btnCancel = new QPushButton("&Cancel", this); - connect(btnCancel, SIGNAL( clicked() ), this, SLOT( reject())); - h->addWidget(btnCancel); - v->addLayout(h); + QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal, this); + connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept())); + connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject())); + v->addWidget(buttonBox); modeChanged( axis->mode ); transferCurveChanged( axis->transferCurve ); @@ -131,8 +127,8 @@ void AxisEdit::gradientChanged( bool on ) { } } -void AxisEdit::modeChanged( int index ) { - if (index == Axis::Keyboard) { +void AxisEdit::modeChanged( Axis::Mode mode ) { + if (mode == Axis::Keyboard) { mouseBox->setEnabled(false); keyBox->setEnabled(true); } diff --git a/src/axis_edit.h b/src/axis_edit.h index 9bc94ca..687c300 100644 --- a/src/axis_edit.h +++ b/src/axis_edit.h @@ -8,6 +8,7 @@ #include #include #include +#include //for my home-brewed widgets #include "joyslider.h" #include "keycode.h" @@ -24,7 +25,7 @@ class AxisEdit : public QDialog { protected slots: //slots for GUI events void gradientChanged( bool on ); - void modeChanged( int index ); + void modeChanged( Axis::Mode mode ); void transferCurveChanged( int index ); void throttleChanged( int index ); void accept(); @@ -40,7 +41,6 @@ class AxisEdit : public QDialog { QDoubleSpinBox *spinSensitivity; KeyButton *btnNeg, *btnPos; JoySlider *slider; - QPushButton *btnOkay, *btnCancel; }; #endif diff --git a/src/button_edit.cpp b/src/button_edit.cpp index 47ed384..41cb664 100644 --- a/src/button_edit.cpp +++ b/src/button_edit.cpp @@ -5,7 +5,7 @@ #include ButtonEdit::ButtonEdit(Button* butt) - :QDialog(0) { + : QDialog(0) { setModal(true); //build the dialog! button = butt; @@ -16,26 +16,22 @@ ButtonEdit::ButtonEdit(Button* butt) v->setMargin(5); v->setSpacing(5); - BKKey = new KeyButton( button->getName(), button->keycode, this, true, button->useMouse); - v->addWidget(BKKey); + btnKey = new KeyButton( button->getName(), button->keycode, this, true, button->useMouse); + v->addWidget(btnKey); QHBoxLayout* h = new QHBoxLayout(); - CSticky = new QCheckBox("&Sticky", this); - CSticky->setChecked(button->sticky); - h->addWidget(CSticky); - CRapid = new QCheckBox("&Rapid Fire", this); - CRapid->setChecked(button->rapidfire); - h->addWidget(CRapid); + chkSticky = new QCheckBox("&Sticky", this); + chkSticky->setChecked(button->sticky); + h->addWidget(chkSticky); + chkRapid = new QCheckBox("&Rapid Fire", this); + chkRapid->setChecked(button->rapidfire); + h->addWidget(chkRapid); v->addLayout(h); - 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); + QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal, this); + connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept())); + connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject())); + v->addWidget(buttonBox); } void ButtonEdit::show() { @@ -51,11 +47,11 @@ void ButtonEdit::accept() { else { if (CRapid->isChecked()) takeTimer(button); }*/ - button->rapidfire = CRapid->isChecked(); - button->sticky = (CSticky->isChecked()); + button->rapidfire = chkRapid->isChecked(); + button->sticky = chkSticky->isChecked(); //if the user chose a mouse button... - button->useMouse = BKKey->choseMouse(); - button->keycode = BKKey->getValue(); + button->useMouse = btnKey->choseMouse(); + button->keycode = btnKey->getValue(); QDialog::accept(); } diff --git a/src/button_edit.h b/src/button_edit.h index 92ff3a8..b886a94 100644 --- a/src/button_edit.h +++ b/src/button_edit.h @@ -3,6 +3,7 @@ #include #include +#include //we need to edit a Button #include "button.h" @@ -20,10 +21,8 @@ class ButtonEdit : public QDialog { void accept(); protected: Button *button; - KeyButton *BKKey; - QPushButton *BKey, *BMouse, *BOkay, *BCancel; - QPushButton **BMKey; - QCheckBox *CSticky, *CRapid; + KeyButton *btnKey; + QCheckBox *chkSticky, *chkRapid; };