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