Added layout change option to button GUI

This commit is contained in:
Robbi Blechdose
2023-03-10 18:34:48 +01:00
parent 0844b4a0c2
commit 84249daf5b
9 changed files with 70 additions and 7 deletions

View File

@ -6,6 +6,7 @@ Button::Button( int i, QObject *parent ) : QObject(parent) {
isButtonPressed = false; isButtonPressed = false;
isDown = false; isDown = false;
rapidfire = false; rapidfire = false;
hasLayout = false;
toDefault(); toDefault();
tick = 0; tick = 0;
} }
@ -49,6 +50,12 @@ bool Button::read( QTextStream &stream ) {
} }
else return false; 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") { else if (*it == "rapidfire") {
rapidfire = true; rapidfire = true;
} }
@ -63,7 +70,8 @@ void Button::write( QTextStream &stream ) {
stream << "\tButton " << (index+1) << ": "; stream << "\tButton " << (index+1) << ": ";
if (rapidfire) stream << "rapidfire, "; if (rapidfire) stream << "rapidfire, ";
if (sticky) stream << "sticky, "; if (sticky) stream << "sticky, ";
stream << (useMouse ? "mouse " : "key ") << keycode << "\n"; stream << (useMouse ? "mouse " : "key ") << keycode;
if (hasLayout) stream << "layout \"" << layout + "\"\n";
} }
void Button::release() { void Button::release() {
@ -74,6 +82,15 @@ void Button::release() {
} }
void Button::jsevent( int value ) { void Button::jsevent( int value ) {
if (hasLayout) {
if (value == 1 && !isButtonPressed) {
isButtonPressed = 1;
//Change layout
//TODO
}
return;
}
bool newval = (value == 1); bool newval = (value == 1);
if (sticky) { if (sticky) {
//the state of a sticky key only changes on button press, not button release. //the state of a sticky key only changes on button press, not button release.
@ -113,6 +130,7 @@ void Button::toDefault() {
sticky = false; sticky = false;
useMouse = false; useMouse = false;
keycode = 0; keycode = 0;
hasLayout = false;
timer.stop(); timer.stop();
} }
@ -120,7 +138,8 @@ bool Button::isDefault() {
return (rapidfire == false) && return (rapidfire == false) &&
(sticky == false) && (sticky == false) &&
(useMouse == false) && (useMouse == false) &&
(keycode == 0); (keycode == 0) &&
(hasLayout == false);
} }
QString Button::getName() { QString Button::getName() {
@ -128,7 +147,10 @@ QString Button::getName() {
} }
QString Button::status() { 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); return tr("%1 : Mouse %2").arg(getName()).arg(keycode);
} }
else { else {

View File

@ -53,6 +53,9 @@ class Button : public QObject {
bool useMouse; bool useMouse;
int keycode; int keycode;
QTimer timer; QTimer timer;
//Layout settings
bool hasLayout;
QString layout;
public slots: public slots:
void timerCalled(); void timerCalled();
}; };

View File

@ -4,7 +4,7 @@
#include <QHBoxLayout> #include <QHBoxLayout>
#include <QVBoxLayout> #include <QVBoxLayout>
ButtonEdit::ButtonEdit(Button* butt) ButtonEdit::ButtonEdit(Button* butt, const QStringList *layoutNames)
: QDialog(0) { : QDialog(0) {
setModal(true); setModal(true);
//build the dialog! //build the dialog!
@ -28,6 +28,21 @@ ButtonEdit::ButtonEdit(Button* butt)
h->addWidget(chkRapid); h->addWidget(chkRapid);
v->addLayout(h); 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); QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal, this);
connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept())); connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject())); connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
@ -52,6 +67,13 @@ void ButtonEdit::accept() {
//if the user chose a mouse button... //if the user chose a mouse button...
button->useMouse = btnKey->choseMouse(); button->useMouse = btnKey->choseMouse();
button->keycode = btnKey->getValue(); button->keycode = btnKey->getValue();
if (cmbLayout->currentIndex() != 0) {
button->hasLayout = true;
button->layout = cmbLayout->currentText();
}
else {
button->hasLayout = false;
}
QDialog::accept(); QDialog::accept();
} }

View File

@ -4,6 +4,7 @@
#include <QPushButton> #include <QPushButton>
#include <QCheckBox> #include <QCheckBox>
#include <QDialogButtonBox> #include <QDialogButtonBox>
#include <QComboBox>
//we need to edit a Button //we need to edit a Button
#include "button.h" #include "button.h"
@ -15,7 +16,7 @@
class ButtonEdit : public QDialog { class ButtonEdit : public QDialog {
Q_OBJECT Q_OBJECT
public: public:
ButtonEdit(Button* butt); ButtonEdit(Button* butt, const QStringList *layoutNames);
void show(); void show();
protected slots: protected slots:
void accept(); void accept();
@ -23,6 +24,7 @@ class ButtonEdit : public QDialog {
Button *button; Button *button;
KeyButton *btnKey; KeyButton *btnKey;
QCheckBox *chkSticky, *chkRapid; QCheckBox *chkSticky, *chkRapid;
QComboBox *cmbLayout;
}; };

View File

@ -19,7 +19,7 @@ void ButtonWidget::update() {
} }
void ButtonWidget::mouseReleaseEvent( QMouseEvent* e ) { void ButtonWidget::mouseReleaseEvent( QMouseEvent* e ) {
ButtonEdit* be = new ButtonEdit(button); ButtonEdit* be = new ButtonEdit(button, &layoutNames);
be->exec(); be->exec();
delete be; delete be;

View File

@ -17,10 +17,11 @@ class ButtonWidget : public FlashButton {
Q_OBJECT Q_OBJECT
public: public:
ButtonWidget( Button* b, QWidget* parent); ButtonWidget( Button* b, QWidget* parent );
void jsevent( int val ); void jsevent( int val );
//reset the label to match the respective Button's current state. //reset the label to match the respective Button's current state.
void update(); void update();
QStringList layoutNames;
private: private:
void mouseReleaseEvent( QMouseEvent* e ); void mouseReleaseEvent( QMouseEvent* e );
bool on; bool on;

View File

@ -103,3 +103,9 @@ void JoyPadWidget::jsevent( const js_event& msg ) {
quickset->jsevent(msg); quickset->jsevent(msg);
} }
} }
void JoyPadWidget::updateButtonLayoutLists(const QStringList layoutNames) {
foreach (ButtonWidget *bw, buttons) {
bw->layoutNames = layoutNames;
}
}

View File

@ -26,6 +26,8 @@ class JoyPadWidget : public QWidget {
~JoyPadWidget(); ~JoyPadWidget();
//takes in an event and decides whether or not to flash anything //takes in an event and decides whether or not to flash anything
void jsevent(const js_event &msg ); void jsevent(const js_event &msg );
//Propagate changes in layout list
void updateButtonLayoutLists(const QStringList layoutNames);
public slots: public slots:
//called whenever one of the subwidgets flashes... used to determine //called whenever one of the subwidgets flashes... used to determine
//when to emit the flashed() signal. //when to emit the flashed() signal.

View File

@ -168,6 +168,11 @@ void LayoutEdit::updateLayoutList() {
cmbLayouts->setCurrentIndex(cmbLayouts->count() - 1); 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() { void LayoutEdit::updateJoypadWidgets() {