diff --git a/src/button.cpp b/src/button.cpp index aeebade..c4a0a6f 100644 --- a/src/button.cpp +++ b/src/button.cpp @@ -19,7 +19,7 @@ bool Button::read( QTextStream &stream ) { // at this point, toDefault() has just been called. //read in a line of text and break it into words - QString input = stream.readLine().toLower(); + QString input = stream.readLine(); QRegExp regex("[\\s,]+"); QStringList words = input.split(regex); @@ -30,7 +30,7 @@ bool Button::read( QTextStream &stream ) { //go through every word on the line describing this button. for ( QStringList::Iterator it = words.begin(); it != words.end(); ++it ) { - if (*it == "mouse") { + if ((*it).toLower() == "mouse") { ++it; if (it == words.end()) return false; val = (*it).toInt(&ok); @@ -40,7 +40,7 @@ bool Button::read( QTextStream &stream ) { } else return false; } - else if (*it == "key") { + else if ((*it).toLower() == "key") { ++it; if (it == words.end()) return false; val = (*it).toInt(&ok); @@ -51,15 +51,15 @@ 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; + layout = (*it).replace("\\s", " "); + hasLayout = true; } - else if (*it == "rapidfire") { + else if ((*it).toLower() == "rapidfire") { rapidfire = true; } - else if (*it == "sticky") { + else if ((*it).toLower() == "sticky") { sticky = true; } } @@ -71,7 +71,8 @@ void Button::write( QTextStream &stream ) { if (rapidfire) stream << "rapidfire, "; if (sticky) stream << "sticky, "; stream << (useMouse ? "mouse " : "key ") << keycode; - if (hasLayout) stream << "layout \"" << layout + "\"\n"; + if (hasLayout) stream << " layout " << layout.replace(" ", "\\s"); + stream << "\n"; } void Button::release() { @@ -86,7 +87,10 @@ void Button::jsevent( int value ) { if (value == 1 && !isButtonPressed) { isButtonPressed = 1; //Change layout - //TODO + emit loadLayout(layout); + } + else if (value == 0) { + isButtonPressed = 0; } return; } diff --git a/src/button.h b/src/button.h index 0820fab..ef597e1 100644 --- a/src/button.h +++ b/src/button.h @@ -58,6 +58,8 @@ class Button : public QObject { QString layout; public slots: void timerCalled(); + signals: + void loadLayout(QString name); }; #endif diff --git a/src/button_edit.cpp b/src/button_edit.cpp index 80a6969..6fa53c0 100644 --- a/src/button_edit.cpp +++ b/src/button_edit.cpp @@ -30,13 +30,12 @@ ButtonEdit::ButtonEdit(Button* butt, const QStringList *layoutNames) 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); + cmbLayout->setCurrentIndex(layoutNames->indexOf(button->layout) + 1); } else { cmbLayout->setCurrentIndex(0); diff --git a/src/joypad.h b/src/joypad.h index 4a28aea..731bbf8 100644 --- a/src/joypad.h +++ b/src/joypad.h @@ -58,13 +58,14 @@ class JoyPad : public QObject { JoyPadWidget* widget(QWidget* parent, int i); //called when the joypad is no longer being edited. void releaseWidget(); - protected: + //lookup axes and buttons. These are dictionaries to support //layouts with different numbers of axes/buttons than the current //devices. Note that with the current layout settings, the defined //buttons that don't actually exist on the device may not be contiguous. - QList axes; QList buttons; + protected: + QList axes; //the index of this device (devicenum) int index; diff --git a/src/layout.cpp b/src/layout.cpp index b7111ca..f705c9d 100644 --- a/src/layout.cpp +++ b/src/layout.cpp @@ -161,6 +161,10 @@ QString LayoutManager::getFileName(const QString& layoutname ) { return QString("%1%2.lyt").arg(settingsDir, layoutname); } +void LayoutManager::loadLayoutFromButton(QString name) { + load(name); +} + bool LayoutManager::load(const QString& name) { //it's VERY easy to load NL :) if (name.isNull()) { @@ -707,6 +711,9 @@ void LayoutManager::addJoyPad(int index, const QString& devpath) { //if we've never seen this device before, make a new one! if (joypad == 0) { joypad = new JoyPad( index, joydev, this ); + foreach (Button *button, joypad->buttons) { + connect(button, &Button::loadLayout, this, &LayoutManager::loadLayoutFromButton); + } joypads.insert(index,joypad); } else { diff --git a/src/layout.h b/src/layout.h index e17fa6a..f1cc0f5 100644 --- a/src/layout.h +++ b/src/layout.h @@ -43,6 +43,8 @@ class LayoutManager : public QObject { //produces a list of the names of all the available layout. QStringList getLayoutNames() const; public slots: + //This is necessary to prevent issues with the overloaded load() function + void loadLayoutFromButton(QString name); //load a layout with a given name bool load(const QString& name); //look for the last loaded layout and try to load that.