Large diffs are not rendered by default.

@@ -42,7 +42,8 @@ SOURCES += main.cpp\
joybuttonslot.cpp \
joyaxisbutton.cpp \
aboutdialog.cpp \
xmlconfigmigration.cpp
xmlconfigmigration.cpp \
setjoystick.cpp

HEADERS += mainwindow.h \
joybuttonwidget.h \
@@ -69,7 +70,8 @@ HEADERS += mainwindow.h \
joybuttonslot.h \
joyaxisbutton.h \
aboutdialog.h \
xmlconfigmigration.h
xmlconfigmigration.h \
setjoystick.h

FORMS += mainwindow.ui \
buttoneditdialog.ui \
@@ -85,3 +87,6 @@ RESOURCES += \
resources.qrc

INSTALLS += target

OTHER_FILES += \
gpl.txt
@@ -74,7 +74,7 @@ AxisEditDialog::AxisEditDialog(JoyAxis *axis, QWidget *parent) :
ui->axisstatusBox->setThrottle(axis->getThrottle());

QString currentJoyValueText ("Current Value: ");
currentJoyValueText = currentJoyValueText.append(QString::number(axis->getCurrentValue()));
currentJoyValueText = currentJoyValueText.append(QString::number(axis->getCurrentRawValue()));
ui->joyValueLabel->setText(currentJoyValueText);

if (tempPConfig->mouseSpeedX == tempNConfig->mouseSpeedX)
@@ -175,6 +175,7 @@ void AxisEditDialog::saveAxisChanges()
currentThrottle = ui->comboBox_2->currentIndex() - 1;
}
axis->setThrottle(currentThrottle);
//axis->joyEvent(axis->getCurrentThrottledDeadValue(), true);
}

void AxisEditDialog::implementPresets(int index)
@@ -214,7 +214,7 @@
<number>1</number>
</property>
<property name="maximum">
<number>200</number>
<number>300</number>
</property>
</widget>
</item>
@@ -288,7 +288,7 @@
<number>1</number>
</property>
<property name="maximum">
<number>200</number>
<number>300</number>
</property>
</widget>
</item>
@@ -46,6 +46,10 @@ ButtonEditDialog::ButtonEditDialog(JoyButton *button, QWidget *parent) :
tempconfig->assignments->append(tempbuttonslot);
}

tempconfig->originset = button->getOriginSet();
tempconfig->setSelection = button->getSetSelection();
tempconfig->setSelectionCondition = button->getChangeSetCondition();

updateFromTempConfig();

connect (ui->buttonBox, SIGNAL(accepted()), this, SLOT(saveButtonChanges()));
@@ -67,6 +71,13 @@ ButtonEditDialog::~ButtonEditDialog()

void ButtonEditDialog::saveButtonChanges()
{
bool pressed = button->getButtonState();
if (pressed)
{
button->joyEvent(false);
}
JoyButton::SetChangeCondition oldCondition = button->getChangeSetCondition();

button->reset ();

updateTempConfigState();
@@ -93,7 +104,26 @@ void ButtonEditDialog::saveButtonChanges()
button->setMouseSpeedX(tempconfig->mouseSpeedX);
button->setMouseSpeedY(tempconfig->mouseSpeedY);

//button->joyEvent(false);
if (tempconfig->setSelection > -1 && tempconfig->setSelectionCondition != JoyButton::SetChangeDisabled)
{
// Revert old set condition before entering new set condition.
// Also, do not emit signals on first change
button->setChangeSetCondition(oldCondition, true);

button->setChangeSetSelection(tempconfig->setSelection);
button->setChangeSetCondition(tempconfig->setSelectionCondition);
}
else
{
button->setChangeSetSelection(-1);
button->setChangeSetCondition(JoyButton::SetChangeDisabled);
}

if (pressed)
{
button->joyEvent(pressed);
}

this->close();
}

@@ -154,6 +184,15 @@ void ButtonEditDialog::updateFromTempConfig()
{
ui->pushButton->setValue(0);
}

if (tempconfig->containsSequence())
{
ui->checkBox->setEnabled(false);
}
else
{
ui->checkBox->setEnabled(true);
}
}

void ButtonEditDialog::updateTempConfigState()
@@ -170,5 +209,6 @@ void ButtonEditDialog::singleAssignmentForTempConfig(bool edited)
JoyButtonSlot *newbuttonslot = new JoyButtonSlot(buttonslot->getSlotCode(), buttonslot->getSlotMode());
tempconfig->assignments->clear();
tempconfig->assignments->append(newbuttonslot);
ui->checkBox->setEnabled(true);
}
}
@@ -1,3 +1,5 @@
#include <QListIterator>

#include "buttontempconfig.h"
#include "event.h"

@@ -8,8 +10,11 @@ ButtonTempConfig::ButtonTempConfig(QObject *parent) :
toggle = false;
turboInterval = 100;
assignments = new QList<JoyButtonSlot*> ();
mouseSpeedX = 20;
mouseSpeedY = 20;
mouseSpeedX = 50;
mouseSpeedY = 50;
setSelection = -1;
originset = 0;
setSelectionCondition = JoyButton::SetChangeDisabled;
}

ButtonTempConfig::ButtonTempConfig(JoyButton *button, QObject *parent) :
@@ -28,11 +33,18 @@ ButtonTempConfig::ButtonTempConfig(JoyButton *button, QObject *parent) :
assignments = new QList<JoyButtonSlot*> ();
mouseSpeedX = button->getMouseSpeedX();
mouseSpeedY = button->getMouseSpeedY();

setSelection = -1;
setSelectionCondition = JoyButton::SetChangeDisabled;
}

ButtonTempConfig::~ButtonTempConfig()
{
delete assignments;
if (assignments)
{
delete assignments;
assignments = 0;
}
}

QString ButtonTempConfig::getSlotsSummary()
@@ -56,6 +68,14 @@ QString ButtonTempConfig::getSlotsSummary()
{
newlabel.append(slot->movementString());
}
else if (slot->getSlotMode() == JoyButtonSlot::JoyPause)
{
newlabel.append("Pause ").append(QString::number(slot->getSlotCode() / 1000.0, 'g', 3));
}
else if (slot->getSlotMode() == JoyButtonSlot::JoyHold)
{
newlabel.append("Hold ").append(QString::number(slot->getSlotCode() / 1000.0, 'g', 3));
}

if (slotCount > 1)
{
@@ -69,3 +89,21 @@ QString ButtonTempConfig::getSlotsSummary()

return newlabel;
}

bool ButtonTempConfig::containsSequence()
{
bool result = false;

QListIterator<JoyButtonSlot*> tempiter(*assignments);
while (tempiter.hasNext() && !result)
{
JoyButtonSlot *slot = tempiter.next();
JoyButtonSlot::JoySlotInputAction mode = slot->getSlotMode();
if (mode == JoyButtonSlot::JoyPause || mode == JoyButtonSlot::JoyHold)
{
result = true;
}
}

return result;
}
@@ -20,9 +20,13 @@ class ButtonTempConfig : public QObject
bool toggle;
int mouseSpeedX;
int mouseSpeedY;
int setSelection;
int originset;
QList<JoyButtonSlot*> *assignments;
JoyButton::SetChangeCondition setSelectionCondition;

QString getSlotsSummary();
bool containsSequence();

signals:

@@ -10,7 +10,8 @@ namespace PadderCommon
const QString configPath = QDir::homePath() + "/.antimicro";
const QString configFileName = "antimicro_settings.ini";
const QString configFilePath = configPath + "/" + configFileName;
const int LATESTCONFIGFILEVERSION = 1;
const int LATESTCONFIGFILEVERSION = 2;
const QString programVersion = "0.3";
}

#endif // COMMON_H
674 gpl.txt

Large diffs are not rendered by default.

@@ -55,31 +55,52 @@ void InputDaemon::run ()
{
case SDL_JOYBUTTONDOWN: {
Joystick *joy = joysticks->value(event.button.which);
JoyButton *button = joy->getJoyButton(event.button.button);
button->joyEvent(true);
SetJoystick* set = joy->getActiveSetJoystick();
//JoyButton *button = joy->getJoyButton(event.button.button);
JoyButton *button = set->getJoyButton(event.button.button);

if (button)
{
button->joyEvent(true);
}
break;
}

case SDL_JOYBUTTONUP:
{
Joystick *joy = joysticks->value(event.button.which);
JoyButton *button = joy->getJoyButton(event.button.button);
button->joyEvent(false);
SetJoystick* set = joy->getActiveSetJoystick();
//JoyButton *button = joy->getJoyButton(event.button.button);
JoyButton *button = set->getJoyButton(event.button.button);

if (button)
{
button->joyEvent(false);
}
break;
}

case SDL_JOYAXISMOTION: {
Joystick *joy = joysticks->value(event.jaxis.which);
JoyAxis *axis = joy->getJoyAxis(event.jaxis.axis);
axis->joyEvent(event.jaxis.value);
SetJoystick* set = joy->getActiveSetJoystick();
//JoyAxis *axis = joy->getJoyAxis(event.jaxis.axis);
JoyAxis *axis = set->getJoyAxis(event.jaxis.axis);
if (axis)
{
axis->joyEvent(event.jaxis.value);
}
break;
}

case SDL_JOYHATMOTION: {
Joystick *joy = joysticks->value(event.jhat.which);
JoyDPad *dpad = joy->getJoyDPad(event.jhat.hat);
dpad->joyEvent(event.jhat.value);

SetJoystick* set = joy->getActiveSetJoystick();
//JoyDPad *dpad = joy->getJoyDPad(event.jhat.hat);
JoyDPad *dpad = set->getJoyDPad(event.jhat.hat);
if (dpad)
{
dpad->joyEvent(event.jhat.value);
}
break;
}

@@ -111,9 +132,10 @@ void InputDaemon::refreshJoysticks()
{
SDL_Joystick* joystick = SDL_JoystickOpen (i);
Joystick *curJoystick = new Joystick (joystick, this);
curJoystick->refreshAxes();
curJoystick->refreshHats();
curJoystick->refreshButtons();
//curJoystick->refreshAxes();
//curJoystick->refreshHats();
//curJoystick->refreshButtons();
curJoystick->reset();

joysticks->insert(i, curJoystick);
}
@@ -143,9 +165,12 @@ bool InputDaemon::isRunning()

void InputDaemon::refreshJoystick(Joystick *joystick)
{
/*
joystick->refreshAxes();
joystick->refreshHats();
joystick->refreshButtons();
*/
joystick->reset();

emit joystickRefreshed(joystick);
}
@@ -22,22 +22,23 @@ JoyAxis::JoyAxis(QObject *parent) :
QObject(parent)
{
timer = new QTimer ();
naxisbutton = new JoyAxisButton(this, 0);
paxisbutton = new JoyAxisButton(this, 1);
originset = 0;
naxisbutton = new JoyAxisButton(this, 0, originset);
paxisbutton = new JoyAxisButton(this, 1, originset);

reset();
index = 0;
}

JoyAxis::JoyAxis(int index, QObject *parent) :
JoyAxis::JoyAxis(int index, int originset, QObject *parent) :
QObject(parent)
{
timer = new QTimer ();
naxisbutton = new JoyAxisButton(this, 0);
paxisbutton = new JoyAxisButton(this, 1);
this->originset = originset;
naxisbutton = new JoyAxisButton(this, 0, originset);
paxisbutton = new JoyAxisButton(this, 1, originset);

reset();

this->index = index;
}

@@ -48,9 +49,10 @@ JoyAxis::~JoyAxis()
delete naxisbutton;
}

void JoyAxis::joyEvent(int value)
void JoyAxis::joyEvent(int value, bool ignoresets)
{
int temp = value;
currentRawValue = value;

if (throttle == -1)
{
value = (value + AXISMIN) / 2;
@@ -60,25 +62,41 @@ void JoyAxis::joyEvent(int value)
value = (value + AXISMAX) / 2;
}

bool safezone = !inDeadZone(temp);
currentValue = value;
bool safezone = !inDeadZone(currentRawValue);
currentThrottledValue = value;

if (safezone && !isActive)
{
isActive = eventActive = true;
emit active(value);
createDeskEvent();
createDeskEvent(ignoresets);
}
else if (!safezone && isActive)
{
isActive = eventActive = false;
emit released(value);

createDeskEvent();
createDeskEvent(ignoresets);
lastkey = 0;
}

emit moved(temp);
/*if (!ignoresets)
{
if (!isActive && setSelectionCondition == SetChangeOneWay && setSelection > -1)
{
emit setChangeActivated(setSelection);
}
else if (!isActive && setSelectionCondition == SetChangeTwoWay && setSelection > -1)
{
emit setChangeActivated(setSelection);
}
else if (setSelectionCondition == SetChangeWhileHeld && setSelection > -1)
{
emit setChangeActivated(setSelection);
}
}*/

emit moved(currentRawValue);
}

bool JoyAxis::inDeadZone(int value)
@@ -128,9 +146,9 @@ int JoyAxis::getRealJoyIndex()
return index + 1;
}

int JoyAxis::getCurrentValue()
int JoyAxis::getCurrentThrottledValue()
{
return currentValue;
return currentThrottledValue;
}

void JoyAxis::setIndex(int index)
@@ -144,21 +162,21 @@ int JoyAxis::getIndex()
}


void JoyAxis::createDeskEvent()
void JoyAxis::createDeskEvent(bool ignoresets)
{
if (currentValue > deadZone)
if (currentThrottledValue > deadZone)
{
paxisbutton->joyEvent(eventActive);
paxisbutton->joyEvent(eventActive, ignoresets);
activeButton = paxisbutton;
}
else if (currentValue < -deadZone)
else if (currentThrottledValue < -deadZone)
{
naxisbutton->joyEvent(eventActive);
naxisbutton->joyEvent(eventActive, ignoresets);
activeButton = naxisbutton;
}
else if (activeButton)
{
activeButton->joyEvent(eventActive);
activeButton->joyEvent(eventActive, ignoresets);
activeButton = 0;
}
}
@@ -196,6 +214,7 @@ void JoyAxis::setThrottle(int value)
if (value >= -1 && value <= 1)
{
throttle = value;
adjustRange();
}
}

@@ -300,7 +319,8 @@ void JoyAxis::reset()
timer->stop();
interval = QTime ();
eventActive = false;
currentValue = 0;
currentThrottledValue = 0;
currentRawValue = 0;
maxZoneValue = 30000;
throttle = 0;
sumDist = 0.0;
@@ -310,6 +330,8 @@ void JoyAxis::reset()
paxisbutton->reset();
naxisbutton->reset();
activeButton = 0;

adjustRange();
}

void JoyAxis::reset(int index)
@@ -320,7 +342,7 @@ void JoyAxis::reset(int index)

double JoyAxis::calculateNormalizedAxisPlacement()
{
double difference = (abs(currentValue) - deadZone)/(double)(maxZoneValue - deadZone);
double difference = (abs(currentThrottledValue) - deadZone)/(double)(maxZoneValue - deadZone);
if (difference > 1.0)
{
difference = 1.0;
@@ -338,3 +360,48 @@ JoyAxisButton* JoyAxis::getNAxisButton()
{
return naxisbutton;
}

int JoyAxis::getCurrentRawValue()
{
return currentRawValue;
}

void JoyAxis::adjustRange()
{
if (throttle == -1)
{
currentThrottledDeadValue = AXISMAX;
//currentThrottledMin = AXISMAX;
//currentThrottledMax = 0;
//value = (value + AXISMIN) / 2;
}
else if (throttle == 0)
{
currentThrottledDeadValue = 0;
//currentThrottledMin = AXISMIN;
//currentThrottleCenter = 0;
//currentThrottledMax = AXISMAX;
}
else if (throttle == 1)
{
currentThrottledDeadValue = AXISMIN;
//currentThrottledMin = 0;
//currentThrottledMax = AXISMAX;
//value = (value + AXISMAX) / 2;
}
}

int JoyAxis::getCurrentThrottledMin()
{
return currentThrottledMin;
}

int JoyAxis::getCurrentThrottledMax()
{
return currentThrottledMax;
}

int JoyAxis::getCurrentThrottledDeadValue()
{
return currentThrottledDeadValue;
}
@@ -15,10 +15,10 @@ class JoyAxis : public QObject
Q_OBJECT
public:
explicit JoyAxis(QObject *parent = 0);
explicit JoyAxis(int index, QObject *parent=0);
explicit JoyAxis(int index, int originset, QObject *parent=0);
~JoyAxis();

void joyEvent(int value);
void joyEvent(int value, bool ignoresets=false);
bool inDeadZone(int value);
QString getName();
void setIndex(int index);
@@ -35,7 +35,12 @@ class JoyAxis : public QObject
int getMaxZoneValue();
void setThrottle(int value);
int getThrottle();
int getCurrentValue();
int getCurrentThrottledValue();
int getCurrentRawValue();
int getCurrentThrottledMin();
int getCurrentThrottledMax();
int getCurrentThrottledDeadValue();

double calculateNormalizedAxisPlacement();

void readConfig(QXmlStreamReader *xml);
@@ -49,7 +54,8 @@ class JoyAxis : public QObject
static const float JOYSPEED;

protected:
void createDeskEvent();
void createDeskEvent(bool ignoresets = false);
void adjustRange();

int index;
int deadZone;
@@ -60,14 +66,21 @@ class JoyAxis : public QObject
JoyAxisButton *naxisbutton;

bool eventActive;
int currentValue;
int currentThrottledValue;
int currentRawValue;
QTimer *timer;
QTime interval;
int throttle;
float sumDist;
int mouseOffset;
int lastkey;
JoyAxisButton *activeButton;
int originset;

int currentThrottledMin;
int currentThrottledMax;
int currentThrottleCenter;
int currentThrottledDeadValue;

signals:
void active(int value);
@@ -12,11 +12,10 @@ JoyAxisButton::JoyAxisButton(JoyAxis *axis, QObject *parent) :
this->axis = axis;
}

JoyAxisButton::JoyAxisButton(JoyAxis *axis, int index, QObject *parent) :
JoyButton(parent)
JoyAxisButton::JoyAxisButton(JoyAxis *axis, int index, int originset, QObject *parent) :
JoyButton(index, originset, parent)
{
this->axis = axis;
this->index = index;
}

QString JoyAxisButton::getXmlName()
@@ -49,7 +48,8 @@ void JoyAxisButton::mouseEvent(JoyButtonSlot *buttonslot)
mousespeed = mouseSpeedY;
}

if (isButtonPressed && timeElapsed >= 1)
bool isActive = activeSlots.contains(buttonslot);
if (isActive && timeElapsed >= 1)
{
double difference = axis->calculateNormalizedAxisPlacement();
int mouse1 = 0;
@@ -96,7 +96,7 @@ void JoyAxisButton::mouseEvent(JoyButtonSlot *buttonslot)
mouseInterval->restart();
}

if (isButtonPressed)
if (isActive)
{
QMetaObject::invokeMethod(this, "mouseEvent", Qt::QueuedConnection, Q_ARG(JoyButtonSlot*, buttonslot));
}
@@ -10,7 +10,7 @@ class JoyAxisButton : public JoyButton
Q_OBJECT
public:
explicit JoyAxisButton(JoyAxis *axis, QObject *parent = 0);
explicit JoyAxisButton(JoyAxis *axis, int index, QObject *parent=0);
explicit JoyAxisButton(JoyAxis *axis, int index, int originset, QObject *parent=0);

virtual QString getXmlName();

Large diffs are not rendered by default.

@@ -5,6 +5,10 @@
#include <QTimer>
#include <QTime>
#include <QList>
#include <QListIterator>
#include <QHash>
#include <QMutex>
#include <QQueue>
#include <QXmlStreamReader>
#include <QXmlStreamWriter>

@@ -15,10 +19,11 @@ class JoyButton : public QObject
Q_OBJECT
public:
explicit JoyButton(QObject *parent = 0);
explicit JoyButton(int index, QObject *parent=0);
explicit JoyButton(int index, int originset, QObject *parent=0);
~JoyButton();

void joyEvent (bool pressed);
enum SetChangeCondition {SetChangeDisabled=0, SetChangeOneWay, SetChangeTwoWay, SetChangeWhileHeld};
void joyEvent (bool pressed, bool ignoresets=false);
int getJoyNumber ();
virtual int getRealJoyNumber ();
void setJoyNumber (int index);
@@ -46,32 +51,63 @@ class JoyButton : public QObject
void setMouseSpeedY(int speed);
int getMouseSpeedY();

void setChangeSetSelection(int index);
int getSetSelection();

void setChangeSetCondition(SetChangeCondition condition, bool passive=false);
SetChangeCondition getChangeSetCondition();

bool getButtonState();
int getOriginSet();

void release();
bool containsSequence();

static const QString xmlName;

protected:
void createDeskEvent();

// Used to denote whether the actual joypad button is pressed
bool isButtonPressed;
// Used to denote whether the virtual key is pressed
bool isKeyPressed;
bool toggle;

bool eventReset;
bool quitEvent;
// Used to denote the SDL index of the actual joypad button
int index;
int turboInterval;
QTimer timer;
bool isDown;
bool useTurbo;
QList<JoyButtonSlot*> assignments;
QList<JoyButtonSlot*> activeSlots;
QString customName;
int mouseSpeedX;
int mouseSpeedY;

int setSelection;
SetChangeCondition setSelectionCondition;
int originset;
QListIterator<JoyButtonSlot*> *slotiter;
JoyButtonSlot *currentPause;
JoyButtonSlot *currentHold;
bool ignoresets;
QMutex buttonMutex;
QTime buttonHold;
QTime pauseHold;
QTime inpauseHold;
QQueue<bool> ignoreSetQueue;
QQueue<bool> isButtonPressedQueue;

signals:
void clicked (int index);
void released (int index);
void keyChanged(int keycode);
void mouseChanged(int mousecode);
void setChangeActivated(int index);
void setAssignmentChanged(int current_button, int associated_set, int mode);
void finishedPause();

public slots:
void setTurboInterval (int interval);
@@ -82,6 +118,14 @@ public slots:
private slots:
void turboEvent();
virtual void mouseEvent(JoyButtonSlot *buttonslot);
void createDeskEvent();
void releaseDeskEvent();
void waitForDeskEvent();
void waitForReleaseDeskEvent();
void pauseEvent();
void holdEvent();
void pauseWaitEvent();
void checkForSetChange();
};


@@ -132,6 +132,14 @@ void JoyButtonSlot::readConfig(QXmlStreamReader *xml)
{
this->setSlotMode(JoyMouseMovement);
}
else if (temptext == "pause")
{
this->setSlotMode(JoyPause);
}
else if (temptext == "hold")
{
this->setSlotMode(JoyHold);
}
}
else
{
@@ -162,6 +170,14 @@ void JoyButtonSlot::writeConfig(QXmlStreamWriter *xml)
{
xml->writeCharacters("mousemovement");
}
else if (mode == JoyPause)
{
xml->writeCharacters("pause");
}
else if (mode == JoyHold)
{
xml->writeCharacters("hold");
}
xml->writeEndElement();

xml->writeEndElement();
@@ -11,7 +11,7 @@ class JoyButtonSlot : public QObject
{
Q_OBJECT
public:
enum JoySlotInputAction {JoyKeyboard=0, JoyMouseButton, JoyMouseMovement};
enum JoySlotInputAction {JoyKeyboard=0, JoyMouseButton, JoyMouseMovement, JoyPause, JoyHold};
enum JoySlotMouseDirection {MouseUp=1, MouseDown, MouseLeft, MouseRight};

explicit JoyButtonSlot(QObject *parent = 0);
@@ -7,18 +7,18 @@ JoyDPad::JoyDPad(QObject *parent) :
{
buttons = QHash<int, JoyDPadButton*> ();
prevDirection = JoyDPadButton::DpadCentered;
previousValue = JoyDPadButton::DpadCentered;
populateButtons();
originset = 0;
}

JoyDPad::JoyDPad(int index, QObject *parent) :
JoyDPad::JoyDPad(int index, int originset, QObject *parent) :
QObject(parent)
{
this->index = index;
buttons = QHash<int, JoyDPadButton*> ();
prevDirection = JoyDPadButton::DpadCentered;
previousValue = JoyDPadButton::DpadCentered;
populateButtons();
this->originset = originset;
}

JoyDPadButton *JoyDPad::getJoyButton(int index)
@@ -28,16 +28,16 @@ JoyDPadButton *JoyDPad::getJoyButton(int index)

void JoyDPad::populateButtons()
{
JoyDPadButton* button = new JoyDPadButton (JoyDPadButton::DpadUp, this, this);
JoyDPadButton* button = new JoyDPadButton (JoyDPadButton::DpadUp, originset, this, this);
buttons.insert(JoyDPadButton::DpadUp, button);

button = new JoyDPadButton (JoyDPadButton::DpadDown, this, this);
button = new JoyDPadButton (JoyDPadButton::DpadDown, originset, this, this);
buttons.insert(JoyDPadButton::DpadDown, button);

button = new JoyDPadButton(JoyDPadButton::DpadRight, this, this);
button = new JoyDPadButton(JoyDPadButton::DpadRight, originset, this, this);
buttons.insert(JoyDPadButton::DpadRight, button);

button = new JoyDPadButton(JoyDPadButton::DpadLeft, this, this);
button = new JoyDPadButton(JoyDPadButton::DpadLeft, originset, this, this);
buttons.insert(JoyDPadButton::DpadLeft, button);
}

@@ -103,7 +103,7 @@ void JoyDPad::writeConfig(QXmlStreamWriter *xml)
xml->writeEndElement();
}

void JoyDPad::joyEvent(int value)
void JoyDPad::joyEvent(int value, bool ignoresets)
{
JoyDPadButton *curButton;
JoyDPadButton *prevButton;
@@ -112,23 +112,23 @@ void JoyDPad::joyEvent(int value)
if (prevDirection & JoyDPadButton::DpadUp)
{
prevButton = buttons.value(JoyDPadButton::DpadUp);
prevButton->joyEvent(false);
prevButton->joyEvent(false, ignoresets);
}
if (prevDirection & JoyDPadButton::DpadRight)
{
prevButton = buttons.value(JoyDPadButton::DpadRight);
prevButton->joyEvent(false);
prevButton->joyEvent(false, ignoresets);
}
if (prevDirection & JoyDPadButton::DpadDown)
{
prevButton = buttons.value(JoyDPadButton::DpadDown);
prevButton->joyEvent(false);
prevButton->joyEvent(false, ignoresets);
}

if (prevDirection & JoyDPadButton::DpadLeft)
{
prevButton = buttons.value(JoyDPadButton::DpadLeft);
prevButton->joyEvent(false);
prevButton->joyEvent(false, ignoresets);
}

/*if (prevDirection & JoyDPadButton::DpadRightUp)
@@ -155,22 +155,22 @@ void JoyDPad::joyEvent(int value)
if (value & JoyDPadButton::DpadUp)
{
curButton = buttons.value(JoyDPadButton::DpadUp);
curButton->joyEvent(true);
curButton->joyEvent(true, ignoresets);
}
if (value & JoyDPadButton::DpadRight)
{
curButton = buttons.value(JoyDPadButton::DpadRight);
curButton->joyEvent(true);
curButton->joyEvent(true, ignoresets);
}
if (value & JoyDPadButton::DpadDown)
{
curButton = buttons.value(JoyDPadButton::DpadDown);
curButton->joyEvent(true);
curButton->joyEvent(true, ignoresets);
}
if (value & JoyDPadButton::DpadLeft)
{
curButton = buttons.value(JoyDPadButton::DpadLeft);
curButton->joyEvent(true);
curButton->joyEvent(true, ignoresets);
}
/*if (value & JoyDPadButton::DpadRightUp)
{
@@ -222,3 +222,8 @@ QHash<int, JoyDPadButton*>* JoyDPad::getJoyButtons()
{
return &buttons;
}

int JoyDPad::getCurrentDirection()
{
return prevDirection;
}
@@ -13,15 +13,16 @@ class JoyDPad : public QObject
Q_OBJECT
public:
explicit JoyDPad(QObject *parent = 0);
explicit JoyDPad(int index, QObject *parent=0);
explicit JoyDPad(int index, int originset, QObject *parent=0);

JoyDPadButton* getJoyButton(int index);
QHash<int, JoyDPadButton*>* getJoyButtons();

int getCurrentDirection();
int getJoyNumber();
int getRealJoyNumber();
QString getName();
void joyEvent(int value);
void joyEvent(int value, bool ignoresets=false);
void readConfig(QXmlStreamReader *xml);
void writeConfig(QXmlStreamWriter *xml);

@@ -31,7 +32,7 @@ class JoyDPad : public QObject
QHash<int, JoyDPadButton*> buttons;
int index;
int prevDirection;
int previousValue;
int originset;

signals:

@@ -5,8 +5,8 @@
const QString JoyDPadButton::xmlName = "dpadbutton";

// Initially, qualify direction as the button's index
JoyDPadButton::JoyDPadButton(int direction, JoyDPad* dpad, QObject *parent) :
JoyButton(direction, parent)
JoyDPadButton::JoyDPadButton(int direction, int originset, JoyDPad* dpad, QObject *parent) :
JoyButton(direction, originset, parent)
{
this->direction = direction;
this->dpad = dpad;
@@ -9,7 +9,7 @@ class JoyDPadButton : public JoyButton
{
Q_OBJECT
public:
JoyDPadButton(int direction, JoyDPad* dpad, QObject *parent=0);
JoyDPadButton(int direction, int originset, JoyDPad* dpad, QObject *parent=0);

QString getDirectionName();
virtual int getRealJoyNumber();
@@ -1,111 +1,252 @@
#include <QDebug>
#include <QListIterator>

#include "joystick.h"

Joystick::Joystick(QObject *parent) :
QObject(parent)
{
joyhandle = 0;
buttons = QHash<int, JoyButton*> ();
axes = QHash<int, JoyAxis*> ();
}
const int Joystick::NUMBER_JOYSETS = 8;

Joystick::Joystick(SDL_Joystick *joyhandle, QObject *parent) :
QObject(parent)
{
this->joyhandle = joyhandle;
buttons = QHash<int, JoyButton*> ();
axes = QHash<int, JoyAxis*> ();
joystick_sets = QHash<int, SetJoystick*> ();
for (int i=0; i < NUMBER_JOYSETS; i++)
{
SetJoystick *setstick = new SetJoystick(joyhandle, i);
joystick_sets.insert(i, setstick);
connect(setstick, SIGNAL(setChangeActivated(int)), this, SLOT(setActiveSetNumber(int)));
connect(setstick, SIGNAL(setChangeActivated(int)), this, SLOT(propogateSetChange(int)));
connect(setstick, SIGNAL(setAssignmentChanged(int,int,int,int)), this, SLOT(changeSetButtonAssociation(int,int,int,int)));
}

active_set = 0;
}

int Joystick::getNumberButtons()
SDL_Joystick* Joystick::getSDLHandle()
{
return buttons.count();
return joyhandle;
}

int Joystick::getNumberAxes()
int Joystick::getJoyNumber()
{
return axes.count();
int joynumber = SDL_JoystickIndex(joyhandle);
return joynumber;
}

int Joystick::getNumberHats()
int Joystick::getRealJoyNumber()
{
return hats.count();
int joynumber = getJoyNumber();
return joynumber + 1;
}

SDL_Joystick* Joystick::getSDLHandle()
QString Joystick::getName()
{
return joyhandle;
return QString("Joystick ").append(QString::number(getRealJoyNumber()));
}

int Joystick::getJoyNumber()
void Joystick::reset()
{
int joynumber = SDL_JoystickIndex(joyhandle);
return joynumber;
for (int i=0; i < NUMBER_JOYSETS; i++)
{
SetJoystick* set = joystick_sets.value(i);
set->reset();
}
/*refreshAxes();
refreshButtons();
refreshHats();*/
}

void Joystick::refreshButtons()
void Joystick::setActiveSetNumber(int index)
{
buttons.clear();

for (int i=0; i < SDL_JoystickNumButtons(joyhandle); i++)
if ((index >= 0 && index < NUMBER_JOYSETS) && (index != active_set))
{
JoyButton *button = new JoyButton (i, this);
buttons.insert(i, button);
QList<bool> buttonstates;
QList<int> axesstates;
QList<int> dpadstates;

SetJoystick *current_set = joystick_sets.value(active_set);
for (int i = 0; i < current_set->getNumberButtons(); i++)
{
JoyButton *button = current_set->getJoyButton(i);
buttonstates.append(button->getButtonState());
}

for (int i = 0; i < current_set->getNumberAxes(); i++)
{
JoyAxis *axis = current_set->getJoyAxis(i);
axesstates.append(axis->getCurrentRawValue());
}

for (int i = 0; i < current_set->getNumberHats(); i++)
{
JoyDPad *dpad = current_set->getJoyDPad(i);
dpadstates.append(dpad->getCurrentDirection());
}

joystick_sets.value(active_set)->release();
active_set = index;

current_set = joystick_sets.value(active_set);
for (int i = 0; i < current_set->getNumberButtons(); i++)
{
bool value = buttonstates.at(i);
JoyButton *button = current_set->getJoyButton(i);
button->joyEvent(value, true);
}

for (int i = 0; i < current_set->getNumberAxes(); i++)
{
int value = axesstates.at(i);
JoyAxis *axis = current_set->getJoyAxis(i);
axis->joyEvent(value, true);
}

for (int i = 0; i < current_set->getNumberHats(); i++)
{
int value = dpadstates.at(i);
JoyDPad *dpad = current_set->getJoyDPad(i);
dpad->joyEvent(value, true);
}
}
}

void Joystick::refreshAxes()
int Joystick::getActiveSetNumber()
{
axes.clear();
return active_set;
}

for (int i=0; i < SDL_JoystickNumAxes(joyhandle); i++)
{
JoyAxis *axis = new JoyAxis(i, this);
axes.insert(i, axis);
}
SetJoystick* Joystick::getActiveSetJoystick()
{
return joystick_sets.value(active_set);
}

void Joystick::refreshHats()
int Joystick::getNumberButtons()
{
hats.clear();
return getActiveSetJoystick()->getNumberButtons();
}

for (int i=0; i < SDL_JoystickNumHats(joyhandle); i++)
{
JoyDPad *dpad = new JoyDPad(i, this);
hats.insert(i, dpad);
}
int Joystick::getNumberAxes()
{
return getActiveSetJoystick()->getNumberAxes();
}

int Joystick::getRealJoyNumber()
int Joystick::getNumberHats()
{
int joynumber = getJoyNumber();
return joynumber + 1;
return getActiveSetJoystick()->getNumberHats();
}

JoyButton* Joystick::getJoyButton(int index)
SetJoystick* Joystick::getSetJoystick(int index)
{
return buttons.value(index);
return joystick_sets.value(index);
}

JoyAxis* Joystick::getJoyAxis(int index)
void Joystick::propogateSetChange(int index)
{
return axes.value(index);
emit setChangeActivated(index);
}

JoyDPad* Joystick::getJoyDPad(int index)
void Joystick::changeSetButtonAssociation(int button_index, int originset, int newset, int mode)
{
return hats.value(index);
JoyButton *button = joystick_sets.value(newset)->getJoyButton(button_index);
JoyButton::SetChangeCondition tempmode = (JoyButton::SetChangeCondition)mode;
button->setChangeSetSelection(originset);
button->setChangeSetCondition(tempmode, true);
}

QString Joystick::getName()
void Joystick::readConfig(QXmlStreamReader *xml)
{
return QString("Joystick ").append(QString::number(getRealJoyNumber()));
if (xml->isStartElement() && xml->name() == "joystick")
{
//reset();

xml->readNextStartElement();
while (!xml->atEnd() && (!xml->isEndElement() && xml->name() != "joystick"))
{
if (xml->name() == "sets" && xml->isStartElement())
{
xml->readNextStartElement();

while (!xml->atEnd() && (!xml->isEndElement() && xml->name() != "sets"))
{
if (xml->name() == "set" && xml->isStartElement())
{
int index = xml->attributes().value("index").toString().toInt();
index = index - 1;
if (index >= 0 && index < joystick_sets.size())
{
joystick_sets.value(index)->readConfig(xml);
}
}
else
{
// If none of the above, skip the element
xml->skipCurrentElement();
}

xml->readNextStartElement();
}
}
else if (xml->name() == "button" && xml->isStartElement())
{
int index = xml->attributes().value("index").toString().toInt();
JoyButton *button = joystick_sets.value(0)->getJoyButton(index-1);
if (button)
{
button->readConfig(xml);
}
else
{
xml->skipCurrentElement();
}
}
else if (xml->name() == "axis" && xml->isStartElement())
{
int index = xml->attributes().value("index").toString().toInt();
JoyAxis *axis = joystick_sets.value(0)->getJoyAxis(index-1);
if (axis)
{
axis->readConfig(xml);
}
else
{
xml->skipCurrentElement();
}
}
else if (xml->name() == "dpad" && xml->isStartElement())
{
int index = xml->attributes().value("index").toString().toInt();
JoyDPad *dpad = joystick_sets.value(0)->getJoyDPad(index-1);
if (dpad)
{
dpad->readConfig(xml);
}
else
{
xml->skipCurrentElement();
}
}
else
{
// If none of the above, skip the element
xml->skipCurrentElement();
}

xml->readNextStartElement();
}
}
}

void Joystick::reset()
void Joystick::writeConfig(QXmlStreamWriter *xml)
{
refreshAxes();
refreshButtons();
refreshHats();
xml->writeStartElement("joystick");
xml->writeAttribute("configversion", QString::number(PadderCommon::LATESTCONFIGFILEVERSION));

xml->writeStartElement("sets");
for (int i=0; i < joystick_sets.size(); i++)
{
joystick_sets.value(i)->writeConfig(xml);
}
xml->writeEndElement();

xml->writeEndElement();
}
@@ -3,17 +3,20 @@

#include <QObject>
#include <QHash>
#include <QXmlStreamReader>
#include <QXmlStreamWriter>
#include <SDL/SDL.h>

#include "joyaxis.h"
#include "joydpad.h"
#include "joybutton.h"
#include "setjoystick.h"
#include "common.h"

class Joystick : public QObject
{
Q_OBJECT
public:
explicit Joystick(QObject *parent = 0);
explicit Joystick(SDL_Joystick *joyhandle, QObject *parent=0);

int getNumberButtons ();
@@ -22,24 +25,42 @@ class Joystick : public QObject
SDL_Joystick* getSDLHandle ();
int getJoyNumber ();
int getRealJoyNumber ();
void refreshButtons ();
void refreshAxes();
void refreshHats();
JoyAxis* getJoyAxis(int index);
//void refreshButtons ();
//void refreshAxes();
//void refreshHats();
/*JoyAxis* getJoyAxis(int index);
JoyButton* getJoyButton(int index);
JoyDPad* getJoyDPad(int index);
JoyDPad* getJoyDPad(int index);*/
QString getName();
int getActiveSetNumber();
SetJoystick* getActiveSetJoystick();
SetJoystick* getSetJoystick(int index);

virtual void readConfig(QXmlStreamReader *xml);
virtual void writeConfig(QXmlStreamWriter *xml);

static const int NUMBER_JOYSETS;

protected:
QHash<int, JoyButton*> buttons;
QHash<int, JoyAxis*> axes;
QHash<int, JoyDPad*> hats;

SDL_Joystick* joyhandle;
QHash<int, SetJoystick*> joystick_sets;
int active_set;

signals:

void setChangeActivated(int index);

public slots:
void reset();
void setActiveSetNumber(int index);
void changeSetButtonAssociation(int button_index, int originset, int newset, int mode);

private slots:
void propogateSetChange(int index);

};

#endif // JOYSTICK_H

Large diffs are not rendered by default.

@@ -11,6 +11,7 @@
#include <QFileDialog>
#include <QSettings>
#include <QHash>
#include <QStackedWidget>

#include "joystick.h"
#include "axiseditdialog.h"
@@ -37,12 +38,41 @@ class JoyTabWidget : public QWidget
QPushButton *saveAsButton;
QComboBox *configBox;
QGridLayout *gridLayout;
QGridLayout *gridLayout2;
QGridLayout *gridLayout3;
QGridLayout *gridLayout4;
QGridLayout *gridLayout5;
QGridLayout *gridLayout6;
QGridLayout *gridLayout7;
QGridLayout *gridLayout8;

QSpacerItem *spacer1;
QSpacerItem *spacer2;
QSpacerItem *spacer3;
QFileDialog *fileDialog;
ButtonEditDialog *buttonDialog;
AxisEditDialog *axisDialog;
QPushButton *setPushButton1;
QPushButton *setPushButton2;
QPushButton *setPushButton3;
QPushButton *setPushButton4;
QPushButton *setPushButton5;
QPushButton *setPushButton6;
QPushButton *setPushButton7;
QPushButton *setPushButton8;
QHBoxLayout *horizontalLayout_2;
QSpacerItem *verticalSpacer_2;
QStackedWidget *stackedWidget_2;
QWidget *page;
QWidget *page_2;
QWidget *page_3;
QWidget *page_4;
QWidget *page_5;
QWidget *page_6;
QWidget *page_7;
QWidget *page_8;
QPushButton *pushButton;
QSpacerItem *verticalSpacer_3;

Joystick *joystick;

@@ -62,6 +92,16 @@ private slots:
void changeJoyConfig(int index);
void showAxisDialog();
void showButtonDialog();

void changeSetOne();
void changeSetTwo();
void changeSetThree();
void changeSetFour();
void changeSetFive();
void changeSetSix();
void changeSetSeven();
void changeSetEight();
void changeCurrentSet(int index);
};

#endif // JOYTABWIDGET_H
@@ -20,10 +20,23 @@
<string notr="true">JoyButtonWidget[isflashing=&quot;true&quot;],
JoyAxisWidget[isflashing=&quot;true&quot;] {
background-color: rgb(0, 0, 255);
}</string>
color: rgb(205, 197, 191);
}

QPushButton#setPushButton1[setActive=&quot;false&quot;],
QPushButton#setPushButton2[setActive=&quot;false&quot;],
QPushButton#setPushButton3[setActive=&quot;false&quot;],
QPushButton#setPushButton4[setActive=&quot;false&quot;],
QPushButton#setPushButton5[setActive=&quot;false&quot;],
QPushButton#setPushButton6[setActive=&quot;false&quot;],
QPushButton#setPushButton7[setActive=&quot;false&quot;],
QPushButton#setPushButton8[setActive=&quot;false&quot;] {
background-color: rgb(190, 190, 190);
}
</string>
</property>
<widget class="QWidget" name="centralWidget">
<layout class="QVBoxLayout" name="verticalLayout">
<layout class="QGridLayout" name="gridLayout_2">
<property name="leftMargin">
<number>4</number>
</property>
@@ -33,7 +46,7 @@ JoyAxisWidget[isflashing=&quot;true&quot;] {
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<item row="0" column="0">
<widget class="QStackedWidget" name="stackedWidget">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="MinimumExpanding">
@@ -124,7 +137,7 @@ JoyAxisWidget[isflashing=&quot;true&quot;] {
<attribute name="title">
<string>Tab 1</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_6">
<layout class="QVBoxLayout" name="verticalLayout_5">
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
@@ -243,26 +256,140 @@ JoyAxisWidget[isflashing=&quot;true&quot;] {
</spacer>
</item>
<item>
<layout class="QGridLayout" name="gridLayout">
<property name="sizeConstraint">
<enum>QLayout::SetDefaultConstraint</enum>
<widget class="QStackedWidget" name="stackedWidget_2">
<property name="currentIndex">
<number>0</number>
</property>
<item row="0" column="0">
<widget class="QPushButton" name="pushButton">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="MinimumExpanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
<widget class="QWidget" name="page">
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QPushButton" name="pushButton">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="MinimumExpanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="text">
<string>PushButton</string>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="page_2"/>
<widget class="QWidget" name="page_3"/>
<widget class="QWidget" name="page_4"/>
<widget class="QWidget" name="page_5"/>
<widget class="QWidget" name="page_6"/>
<widget class="QWidget" name="page_7"/>
<widget class="QWidget" name="page_8"/>
</widget>
</item>
<item>
<spacer name="verticalSpacer_3">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QPushButton" name="setPushButton1">
<property name="styleSheet">
<string notr="true"/>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>0</height>
</size>
<property name="text">
<string>1</string>
</property>
<property name="setActive" stdset="0">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="setPushButton2">
<property name="text">
<string>2</string>
</property>
<property name="setActive" stdset="0">
<bool>false</bool>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="setPushButton3">
<property name="text">
<string>3</string>
</property>
<property name="setActive" stdset="0">
<bool>false</bool>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="setPushButton4">
<property name="text">
<string>4</string>
</property>
<property name="setActive" stdset="0">
<bool>false</bool>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="setPushButton5">
<property name="text">
<string>5</string>
</property>
<property name="setActive" stdset="0">
<bool>false</bool>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="setPushButton6">
<property name="text">
<string>6</string>
</property>
<property name="setActive" stdset="0">
<bool>false</bool>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="setPushButton7">
<property name="text">
<string>7</string>
</property>
<property name="setActive" stdset="0">
<bool>false</bool>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="setPushButton8">
<property name="text">
<string>PushButton</string>
<string>8</string>
</property>
<property name="setActive" stdset="0">
<bool>false</bool>
</property>
</widget>
</item>
@@ -284,26 +411,45 @@ JoyAxisWidget[isflashing=&quot;true&quot;] {
</property>
</spacer>
</item>
<item alignment="Qt::AlignRight">
<widget class="QPushButton" name="pushButton_9">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>75</width>
<height>0</height>
</size>
</property>
<property name="text">
<string>Reset</string>
</property>
</widget>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="pushButton_9">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>75</width>
<height>0</height>
</size>
</property>
<property name="text">
<string>Reset</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
<zorder>verticalSpacer_3</zorder>
<zorder>stackedWidget_2</zorder>
</widget>
<widget class="QWidget" name="tab_2">
<attribute name="title">
@@ -0,0 +1,289 @@
#include <QHashIterator>

#include "setjoystick.h"

/*
SetJoystick::SetJoystick(QObject *parent) :
QObject(parent)
{
joyhandle = 0;
}
*/

SetJoystick::SetJoystick(SDL_Joystick *joyhandle, int index, QObject *parent) :
QObject(parent)
{
this->joyhandle = joyhandle;
this->index = index;
this->reset();
}

JoyButton* SetJoystick::getJoyButton(int index)
{
return buttons.value(index);
}

JoyAxis* SetJoystick::getJoyAxis(int index)
{
return axes.value(index);
}

JoyDPad* SetJoystick::getJoyDPad(int index)
{
return hats.value(index);
}

void SetJoystick::refreshButtons()
{
buttons.clear();

for (int i=0; i < SDL_JoystickNumButtons(joyhandle); i++)
{
JoyButton *button = new JoyButton (i, index, this);
buttons.insert(i, button);
connect(button, SIGNAL(setChangeActivated(int)), this, SLOT(propogateSetChange(int)));
connect(button, SIGNAL(setAssignmentChanged(int,int,int)), this, SLOT(propogateSetButtonAssociation(int,int,int)));
}
}

void SetJoystick::refreshAxes()
{
axes.clear();

for (int i=0; i < SDL_JoystickNumAxes(joyhandle); i++)
{
JoyAxis *axis = new JoyAxis(i, index, this);
axes.insert(i, axis);
JoyButton *button = axis->getNAxisButton();
connect(button, SIGNAL(setChangeActivated(int)), this, SLOT(propogateSetChange(int)));
button = axis->getPAxisButton();
connect(button, SIGNAL(setChangeActivated(int)), this, SLOT(propogateSetChange(int)));
}
}

void SetJoystick::refreshHats()
{
hats.clear();

for (int i=0; i < SDL_JoystickNumHats(joyhandle); i++)
{
JoyDPad *dpad = new JoyDPad(i, index, this);
hats.insert(i, dpad);
QHash<int, JoyDPadButton*> *buttons = dpad->getJoyButtons();
QHashIterator<int, JoyDPadButton*> iter(*buttons);
while (iter.hasNext())
{
JoyDPadButton *button = iter.next().value();
connect(button, SIGNAL(setChangeActivated(int)), this, SLOT(propogateSetChange(int)));
}
}
}

int SetJoystick::getNumberButtons()
{
return buttons.count();
}

int SetJoystick::getNumberAxes()
{
return axes.count();
}

int SetJoystick::getNumberHats()
{
return hats.count();
}

void SetJoystick::reset()
{
refreshAxes();
refreshButtons();
refreshHats();
}

SDL_Joystick* SetJoystick::getSDLHandle()
{
return joyhandle;
}

void SetJoystick::propogateSetChange(int index)
{
emit setChangeActivated(index);
}

void SetJoystick::propogateSetButtonAssociation(int button, int newset, int mode)
{
if (newset != index)
{
emit setAssignmentChanged(button, index, newset, mode);
}
}

void SetJoystick::release()
{
QHashIterator<int, JoyButton*> iter(buttons);
while (iter.hasNext())
{
JoyButton *button = iter.next().value();
button->joyEvent(false, true);
}

QHashIterator<int, JoyAxis*> iter2(axes);
while (iter2.hasNext())
{
JoyAxis *axis = iter2.next().value();
axis->joyEvent(axis->getCurrentThrottledDeadValue(), true);
}

QHashIterator<int, JoyDPad*> iter3(hats);
while (iter3.hasNext())
{
JoyDPad *dpad = iter3.next().value();
dpad->joyEvent(0, true);
}

/*for (int i=0; i < SDL_JoystickNumAxes(joyhandle); i++)
{
JoyAxis *axis = new JoyAxis(i, this);
axes.insert(i, axis);
JoyButton *button = axis->getNAxisButton();
connect(button, SIGNAL(setChangeActivated(int)), this, SLOT(propogateSetChange(int)));
button = axis->getPAxisButton();
connect(button, SIGNAL(setChangeActivated(int)), this, SLOT(propogateSetChange(int)));
}*/
}

void SetJoystick::readConfig(QXmlStreamReader *xml)
{
if (xml->isStartElement() && xml->name() == "set")
{
//reset();

xml->readNextStartElement();
while (!xml->atEnd() && (!xml->isEndElement() && xml->name() != "set"))
{
if (xml->name() == "button" && xml->isStartElement())
{
int index = xml->attributes().value("index").toString().toInt();
JoyButton *button = getJoyButton(index-1);
if (button)
{
button->readConfig(xml);
}
else
{
xml->skipCurrentElement();
}
}
else if (xml->name() == "axis" && xml->isStartElement())
{
int index = xml->attributes().value("index").toString().toInt();
JoyAxis *axis = getJoyAxis(index-1);
if (axis)
{
axis->readConfig(xml);
}
else
{
xml->skipCurrentElement();
}
}
else if (xml->name() == "dpad" && xml->isStartElement())
{
int index = xml->attributes().value("index").toString().toInt();
JoyDPad *dpad = getJoyDPad(index-1);
if (dpad)
{
dpad->readConfig(xml);
}
else
{
xml->skipCurrentElement();
}
}
else
{
// If none of the above, skip the element
xml->skipCurrentElement();
}

xml->readNextStartElement();
}
}
}

void SetJoystick::writeConfig(QXmlStreamWriter *xml)
{
if (!isSetEmpty())
{
xml->writeStartElement("set");

xml->writeAttribute("index", QString::number(index+1));

for (int i=0; i < getNumberAxes(); i++)
{
JoyAxis *axis = getJoyAxis(i);
axis->writeConfig(xml);
}

for (int i=0; i < getNumberHats(); i++)
{
JoyDPad *dpad = getJoyDPad(i);
dpad->writeConfig(xml);
}

for (int i=0; i < getNumberButtons(); i++)
{
JoyButton *button = getJoyButton(i);
button->writeConfig(xml);
}

xml->writeEndElement();
}
}

bool SetJoystick::isSetEmpty()
{
bool result = true;
QHashIterator<int, JoyButton*> iter(buttons);
while (iter.hasNext() && result)
{
JoyButton *button = iter.next().value();
if (button->getAssignedSlots()->size() > 0)
{
result = false;
}
}

QHashIterator<int, JoyAxis*> iter2(axes);
while (iter2.hasNext() && result)
{
JoyAxis *axis = iter2.next().value();
if (axis->getPAxisButton()->getAssignedSlots()->size() > 0)
{
result = false;
}
else if (axis->getNAxisButton()->getAssignedSlots()->size() > 0)
{
result = false;
}
}

QHashIterator<int, JoyDPad*> iter3(hats);
while (iter3.hasNext() && result)
{
JoyDPad *dpad = iter3.next().value();
QHash<int, JoyDPadButton*> *dpadButtons = dpad->getJoyButtons();
QHashIterator<int, JoyDPadButton*> dpaditer(*dpadButtons);
while (dpaditer.hasNext() && result)
{
JoyDPadButton *button = dpaditer.next().value();
if (button->getAssignedSlots()->size() > 0)
{
result = false;
}
}
}

return result;
}
@@ -0,0 +1,56 @@
#ifndef SETJOYSTICK_H
#define SETJOYSTICK_H

#include <QObject>
#include <QHash>
#include <QXmlStreamReader>
#include <QXmlStreamWriter>
#include <SDL/SDL.h>

#include "joyaxis.h"
#include "joydpad.h"
#include "joybutton.h"

class SetJoystick : public QObject
{
Q_OBJECT
public:
//explicit SetJoystick(QObject *parent = 0);
explicit SetJoystick(SDL_Joystick *joyhandle, int index, QObject *parent=0);

SDL_Joystick* getSDLHandle ();
JoyAxis* getJoyAxis(int index);
JoyButton* getJoyButton(int index);
JoyDPad* getJoyDPad(int index);
int getNumberButtons ();
int getNumberAxes();
int getNumberHats();
void refreshButtons ();
void refreshAxes();
void refreshHats();
void release();

virtual void readConfig(QXmlStreamReader *xml);
virtual void writeConfig(QXmlStreamWriter *xml);

protected:
bool isSetEmpty();

QHash<int, JoyButton*> buttons;
QHash<int, JoyAxis*> axes;
QHash<int, JoyDPad*> hats;
int index;
SDL_Joystick* joyhandle;

signals:
void setChangeActivated(int index);
void setAssignmentChanged(int button, int originset, int newset, int mode);

public slots:
void reset();
void propogateSetChange(int index);
void propogateSetButtonAssociation(int button, int newset, int mode);

};

#endif // SETJOYSTICK_H
@@ -152,6 +152,18 @@ void SimpleKeyGrabberButton::setValue(int value, JoyButtonSlot::JoySlotInputActi
{
setText(buttonslot.movementString());
}
else if (buttonslot.getSlotMode() == JoyButtonSlot::JoyPause)
{
QString temp("Pause ");
temp.append(QString::number((buttonslot.getSlotCode() / 1000.0), 'g', 3));
setText(temp);
}
else if (buttonslot.getSlotMode() == JoyButtonSlot::JoyHold)
{
QString temp("Hold ");
temp.append(QString::number((buttonslot.getSlotCode() / 1000.0), 'g', 3));
setText(temp);
}
}

JoyButtonSlot* SimpleKeyGrabberButton::getValue()
@@ -94,49 +94,14 @@ bool XMLConfigReader::read()
requiredMigration = true;
}
}*/
xml->readNextStartElement();
//xml->readNextStartElement();
}

while (!xml->atEnd())
{
if (xml->name() == "button" && xml->isStartElement())
if (xml->name() == "joystick" && xml->isStartElement())
{
int index = xml->attributes().value("index").toString().toInt();
JoyButton *button = joystick->getJoyButton(index-1);
if (button)
{
button->readConfig(xml);
}
else
{
xml->skipCurrentElement();
}
}
else if (xml->name() == "axis" && xml->isStartElement())
{
int index = xml->attributes().value("index").toString().toInt();
JoyAxis *axis = joystick->getJoyAxis(index-1);
if (axis)
{
axis->readConfig(xml);
}
else
{
xml->skipCurrentElement();
}
}
else if (xml->name() == "dpad" && xml->isStartElement())
{
int index = xml->attributes().value("index").toString().toInt();
JoyDPad *dpad = joystick->getJoyDPad(index-1);
if (dpad)
{
dpad->readConfig(xml);
}
else
{
xml->skipCurrentElement();
}
joystick->readConfig(xml);
}
else
{
@@ -43,28 +43,9 @@ void XMLConfigWriter::write(Joystick *joystick)
}

xml->writeStartDocument();
xml->writeStartElement("joystick");
xml->writeAttribute("configversion", QString::number(PadderCommon::LATESTCONFIGFILEVERSION));

for (int i=0; i < joystick->getNumberAxes(); i++)
{
JoyAxis *axis = joystick->getJoyAxis(i);
axis->writeConfig(xml);
}

for (int i=0; i < joystick->getNumberHats(); i++)
{
JoyDPad *dpad = joystick->getJoyDPad(i);
dpad->writeConfig(xml);
}

for (int i=0; i < joystick->getNumberButtons(); i++)
{
JoyButton *button = joystick->getJoyButton(i);
button->writeConfig(xml);
}
joystick->writeConfig(xml);

xml->writeEndElement();
xml->writeEndDocument();

configFile->close();