Added actual layout switch
This commit is contained in:
@ -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;
|
||||
}
|
||||
|
@ -58,6 +58,8 @@ class Button : public QObject {
|
||||
QString layout;
|
||||
public slots:
|
||||
void timerCalled();
|
||||
signals:
|
||||
void loadLayout(QString name);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -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);
|
||||
|
@ -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<Axis*> axes;
|
||||
QList<Button*> buttons;
|
||||
protected:
|
||||
QList<Axis*> axes;
|
||||
//the index of this device (devicenum)
|
||||
int index;
|
||||
|
||||
|
@ -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 {
|
||||
|
@ -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.
|
||||
|
Reference in New Issue
Block a user