Added layout change option to button GUI
This commit is contained in:
@ -6,6 +6,7 @@ Button::Button( int i, QObject *parent ) : QObject(parent) {
|
||||
isButtonPressed = false;
|
||||
isDown = false;
|
||||
rapidfire = false;
|
||||
hasLayout = false;
|
||||
toDefault();
|
||||
tick = 0;
|
||||
}
|
||||
@ -49,6 +50,12 @@ bool Button::read( QTextStream &stream ) {
|
||||
}
|
||||
else return false;
|
||||
}
|
||||
else if (*it == "layout") {
|
||||
//TODO: handle spaces in filenames
|
||||
++it;
|
||||
if (it == words.end()) return false;
|
||||
layout = *it;
|
||||
}
|
||||
else if (*it == "rapidfire") {
|
||||
rapidfire = true;
|
||||
}
|
||||
@ -63,7 +70,8 @@ void Button::write( QTextStream &stream ) {
|
||||
stream << "\tButton " << (index+1) << ": ";
|
||||
if (rapidfire) stream << "rapidfire, ";
|
||||
if (sticky) stream << "sticky, ";
|
||||
stream << (useMouse ? "mouse " : "key ") << keycode << "\n";
|
||||
stream << (useMouse ? "mouse " : "key ") << keycode;
|
||||
if (hasLayout) stream << "layout \"" << layout + "\"\n";
|
||||
}
|
||||
|
||||
void Button::release() {
|
||||
@ -74,6 +82,15 @@ void Button::release() {
|
||||
}
|
||||
|
||||
void Button::jsevent( int value ) {
|
||||
if (hasLayout) {
|
||||
if (value == 1 && !isButtonPressed) {
|
||||
isButtonPressed = 1;
|
||||
//Change layout
|
||||
//TODO
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
bool newval = (value == 1);
|
||||
if (sticky) {
|
||||
//the state of a sticky key only changes on button press, not button release.
|
||||
@ -113,6 +130,7 @@ void Button::toDefault() {
|
||||
sticky = false;
|
||||
useMouse = false;
|
||||
keycode = 0;
|
||||
hasLayout = false;
|
||||
timer.stop();
|
||||
}
|
||||
|
||||
@ -120,7 +138,8 @@ bool Button::isDefault() {
|
||||
return (rapidfire == false) &&
|
||||
(sticky == false) &&
|
||||
(useMouse == false) &&
|
||||
(keycode == 0);
|
||||
(keycode == 0) &&
|
||||
(hasLayout == false);
|
||||
}
|
||||
|
||||
QString Button::getName() {
|
||||
@ -128,7 +147,10 @@ QString Button::getName() {
|
||||
}
|
||||
|
||||
QString Button::status() {
|
||||
if (useMouse) {
|
||||
if (hasLayout) {
|
||||
return tr("%1 : %2").arg(getName(), layout);
|
||||
}
|
||||
else if (useMouse) {
|
||||
return tr("%1 : Mouse %2").arg(getName()).arg(keycode);
|
||||
}
|
||||
else {
|
||||
|
@ -53,6 +53,9 @@ class Button : public QObject {
|
||||
bool useMouse;
|
||||
int keycode;
|
||||
QTimer timer;
|
||||
//Layout settings
|
||||
bool hasLayout;
|
||||
QString layout;
|
||||
public slots:
|
||||
void timerCalled();
|
||||
};
|
||||
|
@ -4,7 +4,7 @@
|
||||
#include <QHBoxLayout>
|
||||
#include <QVBoxLayout>
|
||||
|
||||
ButtonEdit::ButtonEdit(Button* butt)
|
||||
ButtonEdit::ButtonEdit(Button* butt, const QStringList *layoutNames)
|
||||
: QDialog(0) {
|
||||
setModal(true);
|
||||
//build the dialog!
|
||||
@ -28,6 +28,21 @@ ButtonEdit::ButtonEdit(Button* butt)
|
||||
h->addWidget(chkRapid);
|
||||
v->addLayout(h);
|
||||
|
||||
cmbLayout = new QComboBox(this);
|
||||
cmbLayout->addItem(tr("[UNSET]"), QVariant(QString()));
|
||||
cmbLayout->addItem(tr("[NO LAYOUT]"), QVariant(QString()));
|
||||
foreach (const QString& layout, *layoutNames) {
|
||||
cmbLayout->addItem(layout, layout);
|
||||
}
|
||||
//Keep selected layout (if any)
|
||||
if (button->hasLayout) {
|
||||
cmbLayout->setCurrentIndex(layoutNames->indexOf(button->layout) + 2);
|
||||
}
|
||||
else {
|
||||
cmbLayout->setCurrentIndex(0);
|
||||
}
|
||||
v->addWidget(cmbLayout);
|
||||
|
||||
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()));
|
||||
@ -52,6 +67,13 @@ void ButtonEdit::accept() {
|
||||
//if the user chose a mouse button...
|
||||
button->useMouse = btnKey->choseMouse();
|
||||
button->keycode = btnKey->getValue();
|
||||
if (cmbLayout->currentIndex() != 0) {
|
||||
button->hasLayout = true;
|
||||
button->layout = cmbLayout->currentText();
|
||||
}
|
||||
else {
|
||||
button->hasLayout = false;
|
||||
}
|
||||
|
||||
QDialog::accept();
|
||||
}
|
||||
|
@ -4,6 +4,7 @@
|
||||
#include <QPushButton>
|
||||
#include <QCheckBox>
|
||||
#include <QDialogButtonBox>
|
||||
#include <QComboBox>
|
||||
|
||||
//we need to edit a Button
|
||||
#include "button.h"
|
||||
@ -15,7 +16,7 @@
|
||||
class ButtonEdit : public QDialog {
|
||||
Q_OBJECT
|
||||
public:
|
||||
ButtonEdit(Button* butt);
|
||||
ButtonEdit(Button* butt, const QStringList *layoutNames);
|
||||
void show();
|
||||
protected slots:
|
||||
void accept();
|
||||
@ -23,6 +24,7 @@ class ButtonEdit : public QDialog {
|
||||
Button *button;
|
||||
KeyButton *btnKey;
|
||||
QCheckBox *chkSticky, *chkRapid;
|
||||
QComboBox *cmbLayout;
|
||||
};
|
||||
|
||||
|
||||
|
@ -19,7 +19,7 @@ void ButtonWidget::update() {
|
||||
}
|
||||
|
||||
void ButtonWidget::mouseReleaseEvent( QMouseEvent* e ) {
|
||||
ButtonEdit* be = new ButtonEdit(button);
|
||||
ButtonEdit* be = new ButtonEdit(button, &layoutNames);
|
||||
be->exec();
|
||||
delete be;
|
||||
|
||||
|
@ -17,10 +17,11 @@ class ButtonWidget : public FlashButton {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
ButtonWidget( Button* b, QWidget* parent);
|
||||
ButtonWidget( Button* b, QWidget* parent );
|
||||
void jsevent( int val );
|
||||
//reset the label to match the respective Button's current state.
|
||||
void update();
|
||||
QStringList layoutNames;
|
||||
private:
|
||||
void mouseReleaseEvent( QMouseEvent* e );
|
||||
bool on;
|
||||
|
@ -103,3 +103,9 @@ void JoyPadWidget::jsevent( const js_event& msg ) {
|
||||
quickset->jsevent(msg);
|
||||
}
|
||||
}
|
||||
|
||||
void JoyPadWidget::updateButtonLayoutLists(const QStringList layoutNames) {
|
||||
foreach (ButtonWidget *bw, buttons) {
|
||||
bw->layoutNames = layoutNames;
|
||||
}
|
||||
}
|
@ -26,6 +26,8 @@ class JoyPadWidget : public QWidget {
|
||||
~JoyPadWidget();
|
||||
//takes in an event and decides whether or not to flash anything
|
||||
void jsevent(const js_event &msg );
|
||||
//Propagate changes in layout list
|
||||
void updateButtonLayoutLists(const QStringList layoutNames);
|
||||
public slots:
|
||||
//called whenever one of the subwidgets flashes... used to determine
|
||||
//when to emit the flashed() signal.
|
||||
|
@ -168,6 +168,11 @@ void LayoutEdit::updateLayoutList() {
|
||||
cmbLayouts->setCurrentIndex(cmbLayouts->count() - 1);
|
||||
}
|
||||
}
|
||||
//Update layout list for all button edit widgets
|
||||
for (int i = 0, n = lm->available.count(); i < n; i++) {
|
||||
const QStringList layoutNames = lm->getLayoutNames();
|
||||
((JoyPadWidget*)padStack->widget(i))->updateButtonLayoutLists(layoutNames);
|
||||
}
|
||||
}
|
||||
|
||||
void LayoutEdit::updateJoypadWidgets() {
|
||||
|
Reference in New Issue
Block a user