From 9fe2bec93893adb6aa444d5c618f1ef60e424017 Mon Sep 17 00:00:00 2001 From: juliagoda Date: Mon, 10 Dec 2018 01:36:58 +0100 Subject: [PATCH] Created xml classes from the old ones --- CMakeLists.txt | 18 +- src/gamecontroller/gamecontroller.cpp | 5 - src/gamecontroller/gamecontroller.h | 4 - src/gamecontroller/gamecontrollerdpad.cpp | 26 -- src/gamecontroller/gamecontrollerdpad.h | 10 +- src/gamecontroller/gamecontrollerset.cpp | 243 -------------- src/gamecontroller/gamecontrollerset.h | 11 - src/gamecontroller/gamecontrollertrigger.cpp | 5 - src/gamecontroller/gamecontrollertrigger.h | 3 - .../gamecontrollertriggerbutton.cpp | 33 -- .../gamecontrollertriggerbutton.h | 5 +- .../xml/gamecontrollerdpadxml.cpp | 36 ++ .../xml/gamecontrollerdpadxml.h | 22 ++ .../xml/gamecontrollersetxml.cpp | 259 ++++++++++++++ src/gamecontroller/xml/gamecontrollersetxml.h | 43 +++ .../xml/gamecontrollertriggerxml.cpp | 27 +- .../xml/gamecontrollertriggerxml.h | 7 +- src/gamecontroller/xml/gamecontrollerxml.cpp | 22 +- src/gamecontroller/xml/gamecontrollerxml.h | 8 +- .../xml/gamecontrtriggbtnxml.cpp | 45 +++ src/gamecontroller/xml/gamecontrtriggbtnxml.h | 27 ++ src/inputdevice.cpp | 3 - src/inputdevice.h | 2 - src/joyaxis.cpp | 2 - src/joyaxis.h | 2 - src/joybutton.cpp | 2 - src/joybutton.h | 56 ++-- src/joybuttonslot.cpp | 298 ----------------- src/joybuttonslot.h | 5 - src/joybuttonslotslist.cpp | 6 + src/joybuttonslotslist.h | 113 +++++++ src/joycontrolstick.cpp | 170 ---------- src/joycontrolstick.h | 4 - src/joydpad.cpp | 2 - src/joydpad.h | 3 - src/setjoystick.cpp | 142 -------- src/setjoystick.h | 14 +- src/xml/inputdevicexml.cpp | 16 +- src/xml/inputdevicexml.h | 5 +- src/xml/joyaxisxml.cpp | 12 +- src/xml/joyaxisxml.h | 6 +- src/xml/joybuttonslotxml.cpp | 315 ++++++++++++++++++ src/xml/joybuttonslotxml.h | 27 ++ src/xml/joybuttonxml.cpp | 12 +- src/xml/joybuttonxml.h | 4 + src/xml/joycontrolstickxml.cpp | 183 ++++++++++ src/xml/joycontrolstickxml.h | 28 ++ src/xml/setjoystickxml.cpp | 183 ++++++++++ src/xml/setjoystickxml.h | 33 ++ 49 files changed, 1453 insertions(+), 1054 deletions(-) create mode 100644 src/gamecontroller/xml/gamecontrollerdpadxml.cpp create mode 100644 src/gamecontroller/xml/gamecontrollerdpadxml.h create mode 100644 src/gamecontroller/xml/gamecontrollersetxml.cpp create mode 100644 src/gamecontroller/xml/gamecontrollersetxml.h create mode 100644 src/gamecontroller/xml/gamecontrtriggbtnxml.cpp create mode 100644 src/gamecontroller/xml/gamecontrtriggbtnxml.h create mode 100644 src/joybuttonslotslist.cpp create mode 100644 src/joybuttonslotslist.h create mode 100644 src/xml/joybuttonslotxml.cpp create mode 100644 src/xml/joybuttonslotxml.h create mode 100644 src/xml/joycontrolstickxml.cpp create mode 100644 src/xml/joycontrolstickxml.h create mode 100644 src/xml/setjoystickxml.cpp create mode 100644 src/xml/setjoystickxml.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 8a3bda69..47e8d5dd 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -161,6 +161,7 @@ set(antimicro_SOURCES src/joybuttonwidget.cpp src/joystick.cpp src/joybutton.cpp + #src/joybuttonslotslist.cpp src/xml/joybuttonxml.cpp src/joybuttontypes/joygradientbutton.cpp src/event.cpp @@ -179,9 +180,11 @@ set(antimicro_SOURCES src/advancebuttondialog.cpp src/simplekeygrabberbutton.cpp src/joybuttonslot.cpp + src/xml/joybuttonslotxml.cpp src/joybuttontypes/joyaxisbutton.cpp src/aboutdialog.cpp src/setjoystick.cpp + src/xml/setjoystickxml.cpp src/sdleventreader.cpp src/setaxisthrottledialog.cpp src/keyboard/virtualkeypushbutton.cpp @@ -190,6 +193,7 @@ set(antimicro_SOURCES src/buttoneditdialog.cpp src/commandlineutility.cpp src/joycontrolstick.cpp + src/xml/joycontrolstickxml.cpp src/joybuttontypes/joycontrolstickbutton.cpp src/joybuttontypes/joycontrolstickmodifierbutton.cpp src/joycontrolstickeditdialog.cpp @@ -220,7 +224,6 @@ set(antimicro_SOURCES src/inputdevice.cpp src/xml/inputdevicexml.cpp src/mainsettingsdialog.cpp - src/gamecontroller/gamecontrollertriggerbutton.cpp src/setnamesdialog.cpp src/autoprofileinfo.cpp src/addeditautoprofiledialog.cpp @@ -265,6 +268,7 @@ set(antimicro_HEADERS src/joybuttonwidget.h src/joystick.h src/joybutton.h + #src/joybuttonslotslist.h src/xml/joybuttonxml.h src/joybuttontypes/joygradientbutton.h src/inputdaemon.h @@ -282,9 +286,11 @@ set(antimicro_HEADERS src/advancebuttondialog.h src/simplekeygrabberbutton.h src/joybuttonslot.h + src/xml/joybuttonslotxml.h src/joybuttontypes/joyaxisbutton.h src/aboutdialog.h src/setjoystick.h + src/xml/setjoystickxml.h src/sdleventreader.h src/setaxisthrottledialog.h src/keyboard/virtualkeypushbutton.h @@ -293,6 +299,7 @@ set(antimicro_HEADERS src/buttoneditdialog.h src/commandlineutility.h src/joycontrolstick.h + src/xml/joycontrolstickxml.h src/joybuttontypes/joycontrolstickbutton.h src/joybuttontypes/joycontrolstickmodifierbutton.h src/joycontrolstickeditdialog.h @@ -323,7 +330,6 @@ set(antimicro_HEADERS src/inputdevice.h src/xml/inputdevicexml.h src/mainsettingsdialog.h - src/gamecontroller/gamecontrollertriggerbutton.h src/setnamesdialog.h src/autoprofileinfo.h src/addeditautoprofiledialog.h @@ -395,8 +401,12 @@ if(USE_SDL_2) src/gamecontroller/gamecontrollertrigger.cpp src/gamecontrollermappingdialog.cpp src/gamecontrollerexample.cpp + src/gamecontroller/gamecontrollertriggerbutton.cpp + src/gamecontroller/xml/gamecontrtriggbtnxml.cpp src/gamecontroller/xml/gamecontrollerxml.cpp src/gamecontroller/xml/gamecontrollertriggerxml.cpp + src/gamecontroller/xml/gamecontrollerdpadxml.cpp + src/gamecontroller/xml/gamecontrollersetxml.cpp ) LIST(APPEND antimicro_HEADERS src/gamecontroller/gamecontroller.h src/gamecontroller/gamecontrollerdpad.h @@ -404,8 +414,12 @@ if(USE_SDL_2) src/gamecontroller/gamecontrollertrigger.h src/gamecontrollermappingdialog.h src/gamecontrollerexample.h + src/gamecontroller/gamecontrollertriggerbutton.h + src/gamecontroller/xml/gamecontrtriggbtnxml.h src/gamecontroller/xml/gamecontrollerxml.h src/gamecontroller/xml/gamecontrollertriggerxml.h + src/gamecontroller/xml/gamecontrollerdpadxml.h + src/gamecontroller/xml/gamecontrollersetxml.h ) endif(USE_SDL_2) diff --git a/src/gamecontroller/gamecontroller.cpp b/src/gamecontroller/gamecontroller.cpp index c00d4650..5f21ceeb 100755 --- a/src/gamecontroller/gamecontroller.cpp +++ b/src/gamecontroller/gamecontroller.cpp @@ -25,12 +25,7 @@ #include "joybuttontypes/joycontrolstickbutton.h" #include "common.h" #include "messagehandler.h" -//#include "logger.h" -#include - -#include -#include #include diff --git a/src/gamecontroller/gamecontroller.h b/src/gamecontroller/gamecontroller.h index 21ce6984..6bf9cbaf 100755 --- a/src/gamecontroller/gamecontroller.h +++ b/src/gamecontroller/gamecontroller.h @@ -20,11 +20,7 @@ #include #include -#include - -class QXmlStreamReader; -class QXmlStreamWriter; class AntiMicroSettings; // holds information about gamecontrollers diff --git a/src/gamecontroller/gamecontrollerdpad.cpp b/src/gamecontroller/gamecontrollerdpad.cpp index bd16aa97..5b7dca79 100755 --- a/src/gamecontroller/gamecontrollerdpad.cpp +++ b/src/gamecontroller/gamecontrollerdpad.cpp @@ -21,9 +21,7 @@ #include "messagehandler.h" #include "setjoystick.h" #include "joybutton.h" -#include "xml/joydpadxml.h" -#include #include @@ -32,7 +30,6 @@ GameControllerDPad::GameControllerDPad(JoyButton *upButton, JoyButton *downButto VDPad(upButton, downButton, leftButton, rightButton, index, originset, parentSet, parent) { qInstallMessageHandler(MessageHandler::myMessageOutput); - dpadXml = new JoyDPadXml(getDPad()); } @@ -83,26 +80,3 @@ QString GameControllerDPad::getXmlName() return GlobalVariables::GameControllerDPad::xmlName; } - - -void GameControllerDPad::readJoystickConfig(QXmlStreamReader *xml) -{ - qInstallMessageHandler(MessageHandler::myMessageOutput); - - if (xml->isStartElement() && (xml->name() == GlobalVariables::VDPad::xmlName)) - { - xml->readNextStartElement(); - - while (!xml->atEnd() && (!xml->isEndElement() && (xml->name() != GlobalVariables::VDPad::xmlName))) - { - bool found = dpadXml->readMainConfig(xml); - - if (!found) - { - xml->skipCurrentElement(); - } - - xml->readNextStartElement(); - } - } -} diff --git a/src/gamecontroller/gamecontrollerdpad.h b/src/gamecontroller/gamecontrollerdpad.h index 0b491a9f..41bdec03 100755 --- a/src/gamecontroller/gamecontrollerdpad.h +++ b/src/gamecontroller/gamecontrollerdpad.h @@ -22,10 +22,8 @@ #include "vdpad.h" -class QXmlStreamReader; class JoyButton; class SetJoystick; -class JoyDPadXml; class DPad; // holds information about gamecontroller dpad @@ -39,15 +37,9 @@ class GameControllerDPad : public VDPad int index, int originset, SetJoystick *parentSet, QObject *parent = nullptr); virtual QString getName(bool forceFullFormat, bool displayName); - virtual QString getXmlName(); // GameControllerDPadXml class - - void readJoystickConfig(QXmlStreamReader *xml); // GameControllerDPadXml class + virtual QString getXmlName(); VDPad* getDPad(); - -private: - JoyDPadXml* dpadXml; - }; #endif // GAMECONTROLLERDPAD_H diff --git a/src/gamecontroller/gamecontrollerset.cpp b/src/gamecontroller/gamecontrollerset.cpp index 15e2e2a2..8b397863 100755 --- a/src/gamecontroller/gamecontrollerset.cpp +++ b/src/gamecontroller/gamecontrollerset.cpp @@ -22,12 +22,7 @@ #include "gamecontrollertrigger.h" #include "inputdevice.h" #include "joycontrolstick.h" -#include "xml/joydpadxml.h" -#include "xml/joyaxisxml.h" -#include "gamecontroller/xml/gamecontrollertriggerxml.h" -#include "xml/joybuttonxml.h" -#include #include @@ -100,244 +95,6 @@ void GameControllerSet::populateSticksDPad() } -template -void readConf(T* x, QXmlStreamReader *xml) -{ - if (x != nullptr) - { - x->readConfig(xml); - } - else - { - xml->skipCurrentElement(); - } -} - - -void GameControllerSet::readConfDpad(QXmlStreamReader *xml, QList &hatButtons, bool vdpadExists, bool dpadExists) -{ - int index = xml->attributes().value("index").toString().toInt(); - index = index - 1; - bool found = false; - QListIterator iter(hatButtons); - SDL_GameControllerButtonBind current; - - while (iter.hasNext()) - { - current = iter.next(); - - if (current.value.hat.hat == index) - { - found = true; - iter.toBack(); - } - } - - VDPad *dpad = nullptr; - - if (found) - { - if (dpadXml != nullptr) delete dpadXml; - - dpad = getVDPad(0); - dpadXml = new JoyDPadXml(dpad); - } - - if ((dpad != nullptr) && !vdpadExists) - { - dpadExists = true; - dpadXml->readConfig(xml); - } - else - { - xml->skipCurrentElement(); - } -} - - -void GameControllerSet::readJoystickConfig(QXmlStreamReader *xml, - QHash &buttons, - QHash &axes, - QList &hatButtons) -{ - - qInstallMessageHandler(MessageHandler::myMessageOutput); - - if (xml->isStartElement() && (xml->name() == "set")) - { - xml->readNextStartElement(); - - while (!xml->atEnd() && (!xml->isEndElement() && (xml->name() != "set"))) - { - bool dpadExists = false; - bool vdpadExists = false; - - if ((xml->name() == "button") && xml->isStartElement()) - { - int index = xml->attributes().value("index").toString().toInt(); - JoyButton *button = nullptr; - JoyButtonXml* joyButtonXml = nullptr; - - if (buttons.contains(index-1)) - { - SDL_GameControllerButton current = buttons.value(index-1); - button = getJoyButton(current); - joyButtonXml = new JoyButtonXml(button); - } - - readConf(joyButtonXml, xml); - - } - else if ((xml->name() == "axis") && xml->isStartElement()) - { - int index = xml->attributes().value("index").toString().toInt(); - GameControllerTrigger *trigger = nullptr; - GameControllerTriggerXml* gameContrTriggerXml = nullptr; - - if (axes.contains(index-1)) - { - SDL_GameControllerAxis current = axes.value(index-1); - trigger = qobject_cast(getJoyAxis(static_cast(current))); - gameContrTriggerXml = new GameControllerTriggerXml(trigger, getJoyAxis(static_cast(current))); - } - - if (trigger != nullptr) - { - gameContrTriggerXml->readJoystickConfig(xml); - delete gameContrTriggerXml; - } - else - { - xml->skipCurrentElement(); - } - } - else if ((xml->name() == "dpad") && xml->isStartElement()) - { - readConfDpad(xml, hatButtons, vdpadExists, dpadExists); - } - else if ((xml->name() == "stick") && xml->isStartElement()) - { - getElemFromXml("stick", xml); - } - else if ((xml->name() == "vdpad") && xml->isStartElement()) - { - readConfDpad(xml, hatButtons, vdpadExists, dpadExists); - } - else if ((xml->name() == "name") && xml->isStartElement()) - { - QString temptext = xml->readElementText(); - - if (!temptext.isEmpty()) - { - setName(temptext); - } - } - else - { - // If none of the above, skip the element - xml->skipCurrentElement(); - } - - xml->readNextStartElement(); - } - } -} - - -void GameControllerSet::readConfig(QXmlStreamReader *xml) -{ - qInstallMessageHandler(MessageHandler::myMessageOutput); - - if (xml->isStartElement() && (xml->name() == "set")) - { - xml->readNextStartElement(); - - while (!xml->atEnd() && (!xml->isEndElement() && xml->name() != "set")) - { - if ((xml->name() == "button") && xml->isStartElement()) - { - getElemFromXml("button", xml); - } - else if ((xml->name() == "trigger") && xml->isStartElement()) - { - getElemFromXml("trigger", xml); - } - else if ((xml->name() == "stick") && xml->isStartElement()) - { - getElemFromXml("stick", xml); - } - else if ((xml->name() == "dpad") && xml->isStartElement()) - { - getElemFromXml("dpad", xml); - } - else if ((xml->name() == "name") && xml->isStartElement()) - { - QString temptext = xml->readElementText(); - - if (!temptext.isEmpty()) - { - setName(temptext); - } - } - else - { - // If none of the above, skip the element - xml->skipCurrentElement(); - } - - xml->readNextStartElement(); - } - } -} - - -void GameControllerSet::getElemFromXml(QString elemName, QXmlStreamReader *xml) -{ - int index = xml->attributes().value("index").toString().toInt(); - - if (elemName == "button") { - JoyButton *button = getJoyButton(index-1); - JoyButtonXml* joyButtonXml = new JoyButtonXml(button); - readConf(joyButtonXml, xml); - } - else if (elemName == "dpad") { - GameControllerDPad *vdpad = qobject_cast(getVDPad(index-1)); - readConf(new JoyDPadXml(vdpad), xml); - } - else if (elemName == "trigger") - { - GameControllerTrigger *axis = nullptr; - GameControllerTriggerXml* triggerAxisXml = nullptr; - - switch(index-1) - { - case 4: - axis = qobject_cast(getJoyAxis(SDL_CONTROLLER_AXIS_TRIGGERLEFT)); - triggerAxisXml = new GameControllerTriggerXml(axis, getJoyAxis(SDL_CONTROLLER_AXIS_TRIGGERLEFT)); - readConf(triggerAxisXml, xml); - break; - case 5: - axis = qobject_cast(getJoyAxis(SDL_CONTROLLER_AXIS_TRIGGERRIGHT)); - triggerAxisXml = new GameControllerTriggerXml(axis, getJoyAxis(SDL_CONTROLLER_AXIS_TRIGGERRIGHT)); - readConf(triggerAxisXml, xml); - break; - } - } - else if (elemName == "stick") { - if (index > 0) - { - index -= 1; - JoyControlStick *stick = getJoyStick(index); - readConf(stick, xml); - } - else - { - xml->skipCurrentElement(); - } - } -} - - void GameControllerSet::refreshAxes() { qInstallMessageHandler(MessageHandler::myMessageOutput); diff --git a/src/gamecontroller/gamecontrollerset.h b/src/gamecontroller/gamecontrollerset.h index 42d1e1b7..72398a8b 100755 --- a/src/gamecontroller/gamecontrollerset.h +++ b/src/gamecontroller/gamecontrollerset.h @@ -23,11 +23,8 @@ #include #include -#include -class QXmlStreamReader; class InputDevice; -class JoyDPadXml; class GameControllerSet : public SetJoystick @@ -39,11 +36,6 @@ class GameControllerSet : public SetJoystick virtual void refreshAxes(); - virtual void readConfig(QXmlStreamReader *xml); // GameControllerSetXml - virtual void readJoystickConfig(QXmlStreamReader *xml, - QHash &buttons, - QHash &axes, - QList &hatButtons); // GameControllerSetXml class protected: void populateSticksDPad(); @@ -52,11 +44,8 @@ public slots: virtual void reset(); private: - void getElemFromXml(QString elemName, QXmlStreamReader *xml); // GameControllerSetXml class - void readConfDpad(QXmlStreamReader *xml, QList &hatButtons, bool vdpadExists, bool dpadExists); // GameControllerSetXml class void resetSticks(); - JoyDPadXml* dpadXml; }; #endif // GAMECONTROLLERSET_H diff --git a/src/gamecontroller/gamecontrollertrigger.cpp b/src/gamecontroller/gamecontrollertrigger.cpp index 86d65a0b..9dacd178 100755 --- a/src/gamecontroller/gamecontrollertrigger.cpp +++ b/src/gamecontroller/gamecontrollertrigger.cpp @@ -15,19 +15,14 @@ * along with this program. If not, see . */ -//#include - #include "gamecontrollertrigger.h" #include "globalvariables.h" #include "messagehandler.h" #include "gamecontrollertriggerbutton.h" -#include "xml/joyaxisxml.h" #include -#include -#include #include diff --git a/src/gamecontroller/gamecontrollertrigger.h b/src/gamecontroller/gamecontrollertrigger.h index 47905d88..f21e4550 100755 --- a/src/gamecontroller/gamecontrollertrigger.h +++ b/src/gamecontroller/gamecontrollertrigger.h @@ -23,9 +23,6 @@ #include #include - -class QXmlStreamReader; -class QXmlStreamWriter; class SetJoystick; class GameControllerTrigger : public JoyAxis diff --git a/src/gamecontroller/gamecontrollertriggerbutton.cpp b/src/gamecontroller/gamecontrollertriggerbutton.cpp index b53af3f6..a8d34d3d 100755 --- a/src/gamecontroller/gamecontrollertriggerbutton.cpp +++ b/src/gamecontroller/gamecontrollertriggerbutton.cpp @@ -21,10 +21,7 @@ #include "messagehandler.h" #include "setjoystick.h" #include "joyaxis.h" -#include "inputdevice.h" -#include "xml/joybuttonxml.h" -#include #include @@ -41,33 +38,3 @@ QString GameControllerTriggerButton::getXmlName() return GlobalVariables::GameControllerTriggerButton::xmlName; } - - -void GameControllerTriggerButton::readJoystickConfig(QXmlStreamReader *xml) -{ - qInstallMessageHandler(MessageHandler::myMessageOutput); - - - if (xml->isStartElement() && (xml->name() == GlobalVariables::JoyAxisButton::xmlName)) - { - disconnect(this, &GameControllerTriggerButton::slotsChanged, m_parentSet->getInputDevice(), &InputDevice::profileEdited); - - xml->readNextStartElement(); - - - while (!xml->atEnd() && (!xml->isEndElement() && (xml->name() != GlobalVariables::JoyAxisButton::xmlName))) - { - JoyButtonXml* joyButtonXml = new JoyButtonXml(this); - bool found = joyButtonXml->readButtonConfig(xml); - - if (!found) - { - xml->skipCurrentElement(); - } - - xml->readNextStartElement(); - } - - connect(this, &GameControllerTriggerButton::slotsChanged, m_parentSet->getInputDevice(), &InputDevice::profileEdited); - } -} diff --git a/src/gamecontroller/gamecontrollertriggerbutton.h b/src/gamecontroller/gamecontrollertriggerbutton.h index 45ad49e6..76b0a5f5 100755 --- a/src/gamecontroller/gamecontrollertriggerbutton.h +++ b/src/gamecontroller/gamecontrollertriggerbutton.h @@ -26,6 +26,7 @@ class QXmlStreamReader; class SetJoystick; class JoyAxis; + class GameControllerTriggerButton : public JoyAxisButton { Q_OBJECT @@ -33,9 +34,7 @@ class GameControllerTriggerButton : public JoyAxisButton public: explicit GameControllerTriggerButton(JoyAxis *axis, int index, int originset, SetJoystick *parentSet, QObject *parent = nullptr); - virtual QString getXmlName(); // GameContrTriggerBtnXml class - void readJoystickConfig(QXmlStreamReader *xml); // GameContrTriggerBtnXml class - + virtual QString getXmlName(); }; #endif // GAMECONTROLLERBUTTON_H diff --git a/src/gamecontroller/xml/gamecontrollerdpadxml.cpp b/src/gamecontroller/xml/gamecontrollerdpadxml.cpp new file mode 100644 index 00000000..ac09c417 --- /dev/null +++ b/src/gamecontroller/xml/gamecontrollerdpadxml.cpp @@ -0,0 +1,36 @@ +#include "gamecontrollerdpadxml.h" +#include "gamecontroller/gamecontrollerdpad.h" +#include "vdpad.h" + +#include "messagehandler.h" + +#include +#include + +GameControllerDPadXml::GameControllerDPadXml(GameControllerDPad* gameContrDPad, VDPad* vdpad, QObject* parent) : JoyDPadXml(vdpad, parent) +{ + m_gameContrDPad = gameContrDPad; +} + + +void GameControllerDPadXml::readJoystickConfig(QXmlStreamReader *xml) +{ + qInstallMessageHandler(MessageHandler::myMessageOutput); + + if (xml->isStartElement() && (xml->name() == GlobalVariables::VDPad::xmlName)) + { + xml->readNextStartElement(); + + while (!xml->atEnd() && (!xml->isEndElement() && (xml->name() != GlobalVariables::VDPad::xmlName))) + { + bool found = readMainConfig(xml); + + if (!found) + { + xml->skipCurrentElement(); + } + + xml->readNextStartElement(); + } + } +} diff --git a/src/gamecontroller/xml/gamecontrollerdpadxml.h b/src/gamecontroller/xml/gamecontrollerdpadxml.h new file mode 100644 index 00000000..3a47e1ac --- /dev/null +++ b/src/gamecontroller/xml/gamecontrollerdpadxml.h @@ -0,0 +1,22 @@ +#ifndef GAMECONTROLLERDPADXML_H +#define GAMECONTROLLERDPADXML_H + +#include "xml/joydpadxml.h" + +#include + +class GameControllerDPad; +class VDPad; + +class GameControllerDPadXml : public JoyDPadXml +{ +public: + GameControllerDPadXml(GameControllerDPad* gameContrDPad, VDPad* vdpad, QObject* parent = nullptr); + + void readJoystickConfig(QXmlStreamReader *xml); // GameControllerDPadXml class + +private: + GameControllerDPad* m_gameContrDPad; +}; + +#endif // GAMECONTROLLERDPADXML_H diff --git a/src/gamecontroller/xml/gamecontrollersetxml.cpp b/src/gamecontroller/xml/gamecontrollersetxml.cpp new file mode 100644 index 00000000..4c7aab08 --- /dev/null +++ b/src/gamecontroller/xml/gamecontrollersetxml.cpp @@ -0,0 +1,259 @@ +#include "gamecontrollersetxml.h" +#include "gamecontroller/gamecontrollerset.h" +#include "gamecontroller/gamecontrollertrigger.h" +#include "gamecontroller/gamecontrollerdpad.h" +#include "xml/joycontrolstickxml.h" +#include "xml/joydpadxml.h" +#include "xml/joybuttonxml.h" +#include "gamecontroller/xml/gamecontrollertriggerxml.h" + +#include "messagehandler.h" + +#include +#include +#include + + +GameControllerSetXml::GameControllerSetXml(GameControllerSet* gameContrSet, SetJoystick* setJoystick, QObject* parent) : SetJoystickXml(setJoystick, parent) +{ + m_gameContrSet = gameContrSet; +} + + +template +void readConf(T* x, QXmlStreamReader *xml) +{ + if (x != nullptr) + { + x->readConfig(xml); + } + else + { + xml->skipCurrentElement(); + } +} + + +void GameControllerSetXml::readConfig(QXmlStreamReader *xml) +{ + qInstallMessageHandler(MessageHandler::myMessageOutput); + + if (xml->isStartElement() && (xml->name() == "set")) + { + xml->readNextStartElement(); + + while (!xml->atEnd() && (!xml->isEndElement() && xml->name() != "set")) + { + if ((xml->name() == "button") && xml->isStartElement()) + { + getElemFromXml("button", xml); + } + else if ((xml->name() == "trigger") && xml->isStartElement()) + { + getElemFromXml("trigger", xml); + } + else if ((xml->name() == "stick") && xml->isStartElement()) + { + getElemFromXml("stick", xml); + } + else if ((xml->name() == "dpad") && xml->isStartElement()) + { + getElemFromXml("dpad", xml); + } + else if ((xml->name() == "name") && xml->isStartElement()) + { + QString temptext = xml->readElementText(); + + if (!temptext.isEmpty()) + { + m_gameContrSet->setName(temptext); + } + } + else + { + // If none of the above, skip the element + xml->skipCurrentElement(); + } + + xml->readNextStartElement(); + } + } +} + +void GameControllerSetXml::readJoystickConfig(QXmlStreamReader *xml, + QHash &buttons, + QHash &axes, + QList &hatButtons) +{ + + qInstallMessageHandler(MessageHandler::myMessageOutput); + + if (xml->isStartElement() && (xml->name() == "set")) + { + xml->readNextStartElement(); + + while (!xml->atEnd() && (!xml->isEndElement() && (xml->name() != "set"))) + { + bool dpadExists = false; + bool vdpadExists = false; + + if ((xml->name() == "button") && xml->isStartElement()) + { + int index = xml->attributes().value("index").toString().toInt(); + JoyButton *button = nullptr; + JoyButtonXml* joyButtonXml = nullptr; + + if (buttons.contains(index-1)) + { + SDL_GameControllerButton current = buttons.value(index-1); + button = m_gameContrSet->getJoyButton(current); + joyButtonXml = new JoyButtonXml(button); + } + + readConf(joyButtonXml, xml); + + } + else if ((xml->name() == "axis") && xml->isStartElement()) + { + int index = xml->attributes().value("index").toString().toInt(); + GameControllerTrigger *trigger = nullptr; + GameControllerTriggerXml* gameContrTriggerXml = nullptr; + + if (axes.contains(index-1)) + { + SDL_GameControllerAxis current = axes.value(index-1); + trigger = qobject_cast(m_gameContrSet->getJoyAxis(static_cast(current))); + gameContrTriggerXml = new GameControllerTriggerXml(trigger, m_gameContrSet->getJoyAxis(static_cast(current))); + } + + if (trigger != nullptr) + { + gameContrTriggerXml->readJoystickConfig(xml); + delete gameContrTriggerXml; + } + else + { + xml->skipCurrentElement(); + } + } + else if ((xml->name() == "dpad") && xml->isStartElement()) + { + readConfDpad(xml, hatButtons, vdpadExists, dpadExists); + } + else if ((xml->name() == "stick") && xml->isStartElement()) + { + getElemFromXml("stick", xml); + } + else if ((xml->name() == "vdpad") && xml->isStartElement()) + { + readConfDpad(xml, hatButtons, vdpadExists, dpadExists); + } + else if ((xml->name() == "name") && xml->isStartElement()) + { + QString temptext = xml->readElementText(); + + if (!temptext.isEmpty()) + { + m_gameContrSet->setName(temptext); + } + } + else + { + // If none of the above, skip the element + xml->skipCurrentElement(); + } + + xml->readNextStartElement(); + } + } +} + +void GameControllerSetXml::getElemFromXml(QString elemName, QXmlStreamReader *xml) +{ + int index = xml->attributes().value("index").toString().toInt(); + + if (elemName == "button") + { + JoyButtonXml* joyButtonXml = new JoyButtonXml(m_gameContrSet->getJoyButton(index-1)); + readConf(joyButtonXml, xml); + } + else if (elemName == "dpad") + { + GameControllerDPad *vdpad = qobject_cast(m_gameContrSet->getVDPad(index-1)); + readConf(new JoyDPadXml(vdpad), xml); + } + else if (elemName == "trigger") + { + GameControllerTrigger *axis = nullptr; + GameControllerTriggerXml* triggerAxisXml = nullptr; + + switch(index-1) + { + case 4: + axis = qobject_cast(m_gameContrSet->getJoyAxis(SDL_CONTROLLER_AXIS_TRIGGERLEFT)); + triggerAxisXml = new GameControllerTriggerXml(axis, m_gameContrSet->getJoyAxis(SDL_CONTROLLER_AXIS_TRIGGERLEFT)); + readConf(triggerAxisXml, xml); + break; + case 5: + axis = qobject_cast(m_gameContrSet->getJoyAxis(SDL_CONTROLLER_AXIS_TRIGGERRIGHT)); + triggerAxisXml = new GameControllerTriggerXml(axis, m_gameContrSet->getJoyAxis(SDL_CONTROLLER_AXIS_TRIGGERRIGHT)); + readConf(triggerAxisXml, xml); + break; + } + } + else if (elemName == "stick") { + if (index > 0) + { + index -= 1; + + if (!joyContrStickXml.isNull()) joyContrStickXml.clear(); + joyContrStickXml = new JoyControlStickXml(m_gameContrSet->getJoyStick(index)); + readConf(joyContrStickXml.data(), xml); + } + else + { + xml->skipCurrentElement(); + } + } +} + +void GameControllerSetXml::readConfDpad(QXmlStreamReader *xml, QList &hatButtons, bool vdpadExists, bool dpadExists) +{ + int index = xml->attributes().value("index").toString().toInt(); + index = index - 1; + bool found = false; + QListIterator iter(hatButtons); + SDL_GameControllerButtonBind current; + + while (iter.hasNext()) + { + current = iter.next(); + + if (current.value.hat.hat == index) + { + found = true; + iter.toBack(); + } + } + + VDPad *dpad = nullptr; + + if (found) + { + if (!dpadXml.isNull()) dpadXml.clear(); + + dpad = m_gameContrSet->getVDPad(0); + dpadXml = new JoyDPadXml(dpad); + } + + if ((dpad != nullptr && !dpadXml.isNull()) && !vdpadExists) + { + dpadExists = true; + dpadXml->readConfig(xml); + } + else + { + xml->skipCurrentElement(); + } +} + diff --git a/src/gamecontroller/xml/gamecontrollersetxml.h b/src/gamecontroller/xml/gamecontrollersetxml.h new file mode 100644 index 00000000..ca1eb5f1 --- /dev/null +++ b/src/gamecontroller/xml/gamecontrollersetxml.h @@ -0,0 +1,43 @@ +#ifndef GAMECONTROLLERSETXML_H +#define GAMECONTROLLERSETXML_H + +#include "xml/setjoystickxml.h" +#include + +#include +#include +#include +#include + +class GameControllerSet; +class SetJoystick; +class JoyDPadXml; +class JoyControlStickXml; + +class QXmlStreamReader; + + +class GameControllerSetXml : public SetJoystickXml +{ + +public: + GameControllerSetXml(GameControllerSet* gameContrSet, SetJoystick* setJoystick, QObject* parent = nullptr); + + virtual void readConfig(QXmlStreamReader *xml); // GameControllerSetXml + virtual void readJoystickConfig(QXmlStreamReader *xml, + QHash &buttons, + QHash &axes, + QList &hatButtons); + +private: + GameControllerSet* m_gameContrSet; + QPointer dpadXml; + QPointer joyContrStickXml; + + void getElemFromXml(QString elemName, QXmlStreamReader *xml); // GameControllerSetXml class + void readConfDpad(QXmlStreamReader *xml, QList &hatButtons, bool vdpadExists, bool dpadExists); // GameControllerSetXml class + + +}; + +#endif // GAMECONTROLLERSETXML_H diff --git a/src/gamecontroller/xml/gamecontrollertriggerxml.cpp b/src/gamecontroller/xml/gamecontrollertriggerxml.cpp index 8417a3f0..7791c43c 100644 --- a/src/gamecontroller/xml/gamecontrollertriggerxml.cpp +++ b/src/gamecontroller/xml/gamecontrollertriggerxml.cpp @@ -1,6 +1,8 @@ #include "gamecontrollertriggerxml.h" #include "gamecontroller/gamecontrollertrigger.h" #include "gamecontroller/gamecontrollertriggerbutton.h" +#include "gamecontroller/xml/gamecontrtriggbtnxml.h" + #include "xml/joyaxisxml.h" #include "xml/joybuttonxml.h" @@ -16,8 +18,8 @@ GameControllerTriggerXml::GameControllerTriggerXml(GameControllerTrigger* gameContrTrigger, JoyAxis* joyAxis, QObject *parent) : JoyAxisXml(joyAxis, parent) { m_gameContrTrigger = gameContrTrigger; - joyButtonXmlNAxis = new JoyButtonXml(gameContrTrigger->getNAxisButton()); - joyButtonXmlPAxis = new JoyButtonXml(gameContrTrigger->getPAxisButton()); + m_joyButtonXmlNAxis = new JoyButtonXml(gameContrTrigger->getNAxisButton()); + m_joyButtonXmlPAxis = new JoyButtonXml(gameContrTrigger->getPAxisButton()); } void GameControllerTriggerXml::readJoystickConfig(QXmlStreamReader *xml) @@ -35,7 +37,6 @@ void GameControllerTriggerXml::readJoystickConfig(QXmlStreamReader *xml) if (!found && (xml->name() == GlobalVariables::JoyAxisButton::xmlName) && xml->isStartElement()) { int index = xml->attributes().value("index").toString().toInt(); - GameControllerTriggerButton *triggerButton = nullptr; #ifndef QT_DEBUG_NO_OUTPUT qDebug() << "Index for axis in readJoystickConfig is: " << index; @@ -45,16 +46,20 @@ void GameControllerTriggerXml::readJoystickConfig(QXmlStreamReader *xml) case 1: found = true; - triggerButton = - qobject_cast(m_gameContrTrigger->getNAxisButton()); - triggerButton->readJoystickConfig(xml); + + if (!m_gameContrTriggBtnXml.isNull()) m_gameContrTriggBtnXml.clear(); + m_gameContrTriggBtnXml = new GameContrTriggBtnXml(qobject_cast(m_gameContrTrigger->getNAxisButton()), m_gameContrTrigger->getNAxisButton()); + m_gameContrTriggBtnXml->readJoystickConfig(xml); break; case 2: found = true; - triggerButton = - qobject_cast(m_gameContrTrigger->getPAxisButton()); - triggerButton->readJoystickConfig(xml); + + if (!m_gameContrTriggBtnXml.isNull()) m_gameContrTriggBtnXml.clear(); + + if (!m_gameContrTriggBtnXml.isNull()) m_gameContrTriggBtnXml.clear(); + m_gameContrTriggBtnXml = new GameContrTriggBtnXml(qobject_cast(m_gameContrTrigger->getPAxisButton()), m_gameContrTrigger->getPAxisButton()); + m_gameContrTriggBtnXml->readJoystickConfig(xml); break; } } @@ -124,8 +129,8 @@ void GameControllerTriggerXml::writeConfig(QXmlStreamWriter *xml) if (!currentlyDefault) { - joyButtonXmlNAxis->writeConfig(xml); - joyButtonXmlPAxis->writeConfig(xml); + m_joyButtonXmlNAxis.data()->writeConfig(xml); + m_joyButtonXmlPAxis.data()->writeConfig(xml); } xml->writeEndElement(); diff --git a/src/gamecontroller/xml/gamecontrollertriggerxml.h b/src/gamecontroller/xml/gamecontrollertriggerxml.h index 2c003175..ef266441 100644 --- a/src/gamecontroller/xml/gamecontrollertriggerxml.h +++ b/src/gamecontroller/xml/gamecontrollertriggerxml.h @@ -4,8 +4,10 @@ #include "xml/joyaxisxml.h" #include +#include class GameControllerTrigger; +class GameContrTriggBtnXml; class GameControllerTriggerXml : public JoyAxisXml @@ -19,8 +21,9 @@ class GameControllerTriggerXml : public JoyAxisXml private: GameControllerTrigger* m_gameContrTrigger; - JoyButtonXml* joyButtonXmlNAxis; - JoyButtonXml* joyButtonXmlPAxis; + QPointer m_gameContrTriggBtnXml; + QPointer m_joyButtonXmlNAxis; + QPointer m_joyButtonXmlPAxis; }; #endif // GAMECONTROLLERTRIGGERXML_H diff --git a/src/gamecontroller/xml/gamecontrollerxml.cpp b/src/gamecontroller/xml/gamecontrollerxml.cpp index 6e4121ff..1c2f4b88 100644 --- a/src/gamecontroller/xml/gamecontrollerxml.cpp +++ b/src/gamecontroller/xml/gamecontrollerxml.cpp @@ -10,6 +10,8 @@ #include "gamecontroller/gamecontrollerset.h" #include "joybuttontypes/joycontrolstickbutton.h" #include "joycontrolstick.h" +#include "xml/setjoystickxml.h" +#include "gamecontroller/xml/gamecontrollersetxml.h" #include @@ -17,11 +19,13 @@ #include #include + GameControllerXml::GameControllerXml(GameController* gameController, InputDevice* inputDevice, QObject *parent) : InputDeviceXml(inputDevice, parent) { m_gameController = gameController; } + void GameControllerXml::readJoystickConfig(QXmlStreamReader *xml) { qInstallMessageHandler(MessageHandler::myMessageOutput); @@ -59,7 +63,10 @@ void GameControllerXml::readJoystickConfig(QXmlStreamReader *xml) if ((index >= 0) && (index < m_gameController->getJoystick_sets().size())) { GameControllerSet *currentSet = qobject_cast(m_gameController->getJoystick_sets().value(index)); // static_cast - currentSet->readJoystickConfig(xml, buttons, axes, hatButtons); + + if (!m_gameContrSetXml.isNull()) m_gameContrSetXml.clear(); + m_gameContrSetXml = new GameControllerSetXml(currentSet, const_cast(m_gameController->getJoystick_sets().value(index))); + m_gameContrSetXml->readJoystickConfig(xml, buttons, axes, hatButtons); } } else @@ -305,7 +312,9 @@ void GameControllerXml::readConfig(QXmlStreamReader *xml) if ((index >= 0) && (index < m_gameController->getJoystick_sets().size())) { - m_gameController->getJoystick_sets().value(index)->readConfig(xml); + if (!m_setJoystickXml.isNull()) m_setJoystickXml.clear(); + m_setJoystickXml = new SetJoystickXml(const_cast(m_gameController->getJoystick_sets().value(index))); + m_setJoystickXml.data()->readConfig(xml); } } else @@ -427,15 +436,16 @@ void GameControllerXml::writeConfig(QXmlStreamWriter *xml) xml->writeTextElement("keyPressTime", QString::number(m_gameController->getDeviceKeyPressTime())); } - xml->writeStartElement("sets"); + xml->writeStartElement("sets"); for (int i = 0; i < m_gameController->getJoystick_sets().size(); i++) { - m_gameController->getJoystick_sets().value(i)->writeConfig(xml); + if (!m_setJoystickXml.isNull()) m_setJoystickXml.clear(); + m_setJoystickXml = new SetJoystickXml(m_gameController->getJoystick_sets().value(i)); + m_setJoystickXml->writeConfig(xml); } - xml->writeEndElement(); - + xml->writeEndElement(); xml->writeEndElement(); } diff --git a/src/gamecontroller/xml/gamecontrollerxml.h b/src/gamecontroller/xml/gamecontrollerxml.h index 78cc4a88..559ca7c7 100644 --- a/src/gamecontroller/xml/gamecontrollerxml.h +++ b/src/gamecontroller/xml/gamecontrollerxml.h @@ -1,12 +1,16 @@ #ifndef GAMECONTROLLERXML_H #define GAMECONTROLLERXML_H - #include +#include + +#include "xml/inputdevicexml.h" #include "gamecontroller/gamecontroller.h" #include class SetJoystick; +class SetJoystickXml; +class GameControllerSetXml; class QXmlStreamReader; class QXmlStreamWriter; class JoyAxisButton; @@ -29,6 +33,8 @@ public slots: private: GameController* m_gameController; + QPointer m_setJoystickXml; + QPointer m_gameContrSetXml; void writeXmlForButtons(SetJoystick *tempSet, QXmlStreamWriter *xml); // GameControllerXml class void writeXmlForAxes(SetJoystick *tempSet, QXmlStreamWriter *xml); // GameControllerXml class diff --git a/src/gamecontroller/xml/gamecontrtriggbtnxml.cpp b/src/gamecontroller/xml/gamecontrtriggbtnxml.cpp new file mode 100644 index 00000000..1e7e816a --- /dev/null +++ b/src/gamecontroller/xml/gamecontrtriggbtnxml.cpp @@ -0,0 +1,45 @@ +#include "gamecontrtriggbtnxml.h" +#include "gamecontroller/gamecontrollertriggerbutton.h" +#include "xml/joybuttonxml.h" +#include "inputdevice.h" + +#include "messagehandler.h" + +#include +#include + + +GameContrTriggBtnXml::GameContrTriggBtnXml(GameControllerTriggerButton* gameContrTriggBtn, JoyButton* joyBtn, QObject* parent) : JoyButtonXml(joyBtn, parent) +{ + m_gameContrTriggBtn = gameContrTriggBtn; +} + +void GameContrTriggBtnXml::readJoystickConfig(QXmlStreamReader *xml) +{ + qInstallMessageHandler(MessageHandler::myMessageOutput); + + + if (xml->isStartElement() && (xml->name() == GlobalVariables::JoyAxisButton::xmlName)) + { + disconnect(m_gameContrTriggBtn, &GameControllerTriggerButton::slotsChanged, m_gameContrTriggBtn->getParentSet()->getInputDevice(), &InputDevice::profileEdited); + + xml->readNextStartElement(); + + + while (!xml->atEnd() && (!xml->isEndElement() && (xml->name() != GlobalVariables::JoyAxisButton::xmlName))) + { + if (!m_joyButtonXml.isNull()) m_joyButtonXml.clear(); + m_joyButtonXml = new JoyButtonXml(m_gameContrTriggBtn); + bool found = m_joyButtonXml->readButtonConfig(xml); + + if (!found) + { + xml->skipCurrentElement(); + } + + xml->readNextStartElement(); + } + + connect(m_gameContrTriggBtn, &GameControllerTriggerButton::slotsChanged, m_gameContrTriggBtn->getParentSet()->getInputDevice(), &InputDevice::profileEdited); + } +} diff --git a/src/gamecontroller/xml/gamecontrtriggbtnxml.h b/src/gamecontroller/xml/gamecontrtriggbtnxml.h new file mode 100644 index 00000000..3d4a8238 --- /dev/null +++ b/src/gamecontroller/xml/gamecontrtriggbtnxml.h @@ -0,0 +1,27 @@ +#ifndef GAMECONTRTRIGGBTNXML_H +#define GAMECONTRTRIGGBTNXML_H + +#include + +#include "xml/joybuttonxml.h" + +class GameControllerTriggerButton; +class QXmlStreamReader; +class JoyButtonXml; + + +class GameContrTriggBtnXml : public JoyButtonXml +{ + +public: + GameContrTriggBtnXml(GameControllerTriggerButton* gameContrTriggBtn, JoyButton* joyBtn, QObject* parent = nullptr); + + void readJoystickConfig(QXmlStreamReader *xml); + +private: + GameControllerTriggerButton* m_gameContrTriggBtn; + QPointer m_joyButtonXml; + +}; + +#endif // GAMECONTRTRIGGBTNXML_H diff --git a/src/inputdevice.cpp b/src/inputdevice.cpp index 0f59faa2..3ee93756 100755 --- a/src/inputdevice.cpp +++ b/src/inputdevice.cpp @@ -28,9 +28,6 @@ #include "joybuttontypes/joycontrolstickbutton.h" #include - -#include -#include #include diff --git a/src/inputdevice.h b/src/inputdevice.h index 35781378..f0acc236 100755 --- a/src/inputdevice.h +++ b/src/inputdevice.h @@ -29,8 +29,6 @@ class AntiMicroSettings; class SetJoystick; -class QXmlStreamReader; -class QXmlStreamWriter; class InputDevice : public QObject diff --git a/src/joyaxis.cpp b/src/joyaxis.cpp index 97c57335..60384bcc 100755 --- a/src/joyaxis.cpp +++ b/src/joyaxis.cpp @@ -27,8 +27,6 @@ #include -#include -#include #include #include diff --git a/src/joyaxis.h b/src/joyaxis.h index bf25337c..debdc102 100755 --- a/src/joyaxis.h +++ b/src/joyaxis.h @@ -28,8 +28,6 @@ class JoyControlStick; class SetJoystick; class JoyAxisButton; -class QXmlStreamReader; -class QXmlStreamWriter; class JoyAxis; diff --git a/src/joybutton.cpp b/src/joybutton.cpp index 329730a7..18b36567 100755 --- a/src/joybutton.cpp +++ b/src/joybutton.cpp @@ -32,8 +32,6 @@ #include #include #include -#include -#include #include const JoyButton::JoyMouseCurve JoyButton::DEFAULTMOUSECURVE = JoyButton::EnhancedPrecisionCurve; diff --git a/src/joybutton.h b/src/joybutton.h index a561a612..01e31d2d 100755 --- a/src/joybutton.h +++ b/src/joybutton.h @@ -40,8 +40,6 @@ class VDPad; class SetJoystick; -class QXmlStreamReader; -class QXmlStreamWriter; class QThread; class JoyButton : public QObject @@ -100,12 +98,12 @@ class JoyButton : public QObject bool getToggleState(); bool isUsingTurbo(); bool getButtonState(); - bool containsSequence(); - bool containsDistanceSlots(); // JoyButtonSlots class - bool containsReleaseSlots(); // JoyButtonSlots class + bool containsSequence(); // JoyButtonSlots class * + bool containsDistanceSlots(); // JoyButtonSlots class * + bool containsReleaseSlots(); // JoyButtonSlots class * bool getIgnoreEventState(); // JoyButtonEvents class bool getWhileHeldStatus(); - bool hasActiveSlots(); // JoyButtonSlots class + bool hasActiveSlots(); // JoyButtonSlots class * bool isCycleResetActive(); bool isRelativeSpring(); bool isPartVDPad(); @@ -136,8 +134,8 @@ class JoyButton : public QObject QString getActionName(); QString getButtonName(); - QList* getAssignedSlots(); // JoyButtonSlots class - QList const& getActiveSlots(); // JoyButtonSlots class + QList* getAssignedSlots(); // JoyButtonSlots class * + QList const& getActiveSlots(); // JoyButtonSlots class * virtual bool isPartRealAxis(); virtual bool isModifierButton(); @@ -161,8 +159,8 @@ class JoyButton : public QObject bool passive=false, bool updateActiveString=true); virtual QString getPartialName(bool forceFullFormat=false, bool displayNames=false) const; - virtual QString getSlotsSummary(); // JoyButtonSlots class - virtual QString getSlotsString(); // JoyButtonSlots class + virtual QString getSlotsSummary(); // JoyButtonSlots class * + virtual QString getSlotsString(); // JoyButtonSlots class * virtual QString getActiveZoneSummary(); virtual QString getCalculatedActiveZoneSummary(); virtual QString getName(bool forceFullFormat=false, bool displayNames=false); @@ -220,7 +218,7 @@ class JoyButton : public QObject static const TurboMode DEFAULTTURBOMODE; static const JoyExtraAccelerationCurve DEFAULTEXTRAACCELCURVE; - bool insertAssignedSlot(JoyButtonSlot *newSlot, bool updateActiveString=true); // JoyButtonSlots class + bool insertAssignedSlot(JoyButtonSlot *newSlot, bool updateActiveString=true); // JoyButtonSlots class * @@ -231,10 +229,10 @@ class JoyButton : public QObject bool distanceEvent(); // JoyButtonEvents class bool checkForDelaySequence(); - void clearAssignedSlots(bool signalEmit=true); // JoyButtonSlots class + void clearAssignedSlots(bool signalEmit=true); // JoyButtonSlots class * void releaseSlotEvent(); // JoyButtonEvents class void checkForPressedSetChange(); - void checkTurboCondition(JoyButtonSlot *slot); + void checkTurboCondition(JoyButtonSlot *slot); // JoyButtonSlots class * void vdpadPassEvent(bool pressed, bool ignoresets=false); // JoyButtonEvents class void localBuildActiveZoneSummaryString(); @@ -257,7 +255,7 @@ class JoyButton : public QObject static JoyKeyRepeatHelper repeatHelper; #endif - static JoyButtonSlot *lastActiveKey; // JoyButtonSlots class + static JoyButtonSlot *lastActiveKey; // JoyButtonSlots class* static JoyButtonMouseHelper mouseHelper; int m_index; // Used to denote the SDL index of the actual joypad button @@ -307,7 +305,7 @@ class JoyButton : public QObject void turboChanged(bool state); void toggleChanged(bool state); void turboIntervalChanged(int interval); - void slotsChanged(); // JoyButtonSlots class + void slotsChanged(); // JoyButtonSlots class * void actionNameChanged(); void buttonNameChanged(); void propertyUpdated(); @@ -329,7 +327,7 @@ public slots: void setEasingDuration(double value); void establishPropertyUpdatedConnections(); void disconnectPropertyUpdatedConnections(); - void removeAssignedSlot(int index); + void removeAssignedSlot(int index); // JoyButtonSlots class * virtual void reset(); virtual void reset(int index); @@ -341,18 +339,18 @@ public slots: static void establishMouseTimerConnections(); bool setAssignedSlot(int code, int alias, int index, - JoyButtonSlot::JoySlotInputAction mode=JoyButtonSlot::JoyKeyboard); // JoyButtonSlots class + JoyButtonSlot::JoySlotInputAction mode=JoyButtonSlot::JoyKeyboard); // JoyButtonSlots class * bool setAssignedSlot(int code, - JoyButtonSlot::JoySlotInputAction mode=JoyButtonSlot::JoyKeyboard); // JoyButtonSlots class + JoyButtonSlot::JoySlotInputAction mode=JoyButtonSlot::JoyKeyboard); // JoyButtonSlots class * bool setAssignedSlot(int code, int alias, - JoyButtonSlot::JoySlotInputAction mode=JoyButtonSlot::JoyKeyboard); // JoyButtonSlots class + JoyButtonSlot::JoySlotInputAction mode=JoyButtonSlot::JoyKeyboard); // JoyButtonSlots class * - bool setAssignedSlot(JoyButtonSlot *otherSlot, int index); // JoyButtonSlots class + bool setAssignedSlot(JoyButtonSlot *otherSlot, int index); // JoyButtonSlots class * bool insertAssignedSlot(int code, int alias, int index, - JoyButtonSlot::JoySlotInputAction mode=JoyButtonSlot::JoyKeyboard); // JoyButtonSlots class + JoyButtonSlot::JoySlotInputAction mode=JoyButtonSlot::JoyKeyboard); // JoyButtonSlots class * void buildActiveZoneSummaryString(); @@ -366,7 +364,7 @@ protected slots: private slots: - void releaseActiveSlots(); // JoyButtonSlots class + void releaseActiveSlots(); // JoyButtonSlots class * void activateSlots(); // JoyButtonSlots class void waitForDeskEvent(); // JoyButtonEvents class void waitForReleaseDeskEvent(); // JoyButtonEvents class @@ -393,7 +391,7 @@ private slots: updateOldAccelMulti = oldAccelMultiVal; } - inline void resetSlotsProp(bool currentChangedSlot = false) // JoyButtonSlots class + inline void resetSlotsProp(bool currentChangedSlot = false) // JoyButtonSlots class * { currentCycle = nullptr; previousCycle = nullptr; @@ -488,10 +486,10 @@ private slots: void resetPrivVars(); void restartAllForSetChange(); void startTimerOverrun(int slotCode, QTime* currSlotTime, QTimer* currSlotTimer, bool releasedDeskTimer = false); - void findJoySlotsEnd(QListIterator *slotiter); + void findJoySlotsEnd(QListIterator *slotiter); // JoyButtonSlots class * void changeStatesQueue(bool currentReleased); - void countActiveSlots(int tempcode, int& references, JoyButtonSlot* slot, QHash& activeSlotsHash, bool& changeRepeatState, bool activeSlotHashWindows = false); // JoyButtonSlots class - void releaseMoveSlots(QList& cursorSpeeds, JoyButtonSlot *slot, QList& indexesToRemove); // JoyButtonSlots class + void countActiveSlots(int tempcode, int& references, JoyButtonSlot* slot, QHash& activeSlotsHash, bool& changeRepeatState, bool activeSlotHashWindows = false); // JoyButtonSlots class * + void releaseMoveSlots(QList& cursorSpeeds, JoyButtonSlot *slot, QList& indexesToRemove); // JoyButtonSlots class * void setSpringDeadCircle(double& springDeadCircle, int mouseDirection); void checkSpringDeadCircle(int tempcode, double& springDeadCircle, int mouseSlot1, int mouseSlot2); static void distanceForMovingAx(double& finalAx, mouseCursorInfo infoAx); @@ -500,8 +498,8 @@ private slots: void changeTurboParams(bool _isKeyPressed, bool isButtonPressed); void updateParamsAfterDistEvent(); // JoyButtonEvents class void startSequenceOfPressActive(bool isTurbo, QString debugText); - QList& getAssignmentsLocal(); - QList& getActiveSlotsLocal(); // JoyButtonSlots class + QList& getAssignmentsLocal(); // JoyButtonSlots class * + QList& getActiveSlotsLocal(); // JoyButtonSlots class * void updateMouseProperties(double newAxisValue, double newSpringDead, int newSpringWidth, int newSpringHeight, bool relatived, int modeScreen, QList& springSpeeds, QChar axis, double newAxisValueY = 0, double newSpringDeadY = 0); bool m_toggle; @@ -564,6 +562,7 @@ private slots: QString actionName; QString activeZoneString; + // copied QList assignments; QList activeSlots; QListIterator *slotiter; @@ -578,6 +577,7 @@ private slots: JoyButtonSlot *currentKeyPress; JoyButtonSlot *currentDelay; JoyButtonSlot *currentSetChangeSlot; + // QTime buttonHold; QTime pauseHold; diff --git a/src/joybuttonslot.cpp b/src/joybuttonslot.cpp index eb85de92..7e177d08 100755 --- a/src/joybuttonslot.cpp +++ b/src/joybuttonslot.cpp @@ -25,8 +25,6 @@ #include #include -#include -#include JoyButtonSlot::JoyButtonSlot(QObject *parent) : @@ -228,302 +226,6 @@ void JoyButtonSlot::restartMouseInterval() mouseInterval.restart(); } -void JoyButtonSlot::readConfig(QXmlStreamReader *xml) -{ - qInstallMessageHandler(MessageHandler::myMessageOutput); - - if (xml->isStartElement() && (xml->name() == "slot")) - { - QString profile = QString(); - QString tempStringData = QString(); - QString extraStringData = QString(); - - xml->readNextStartElement(); - - while (!xml->atEnd() && (!xml->isEndElement() && (xml->name() != "slot"))) - { - if ((xml->name() == "code") && xml->isStartElement()) - { - QString temptext = xml->readElementText(); - bool ok = false; - int tempchoice = temptext.toInt(&ok, 0); - - if (ok) this->setSlotCode(tempchoice); - } - else if ((xml->name() == "profile") && xml->isStartElement()) - { - QString temptext = xml->readElementText(); - profile = temptext; - } - else if ((xml->name() == "text") && xml->isStartElement()) - { - QString temptext = xml->readElementText(); - tempStringData = temptext; - } - else if ((xml->name() == "path") && xml->isStartElement()) - { - QString temptext = xml->readElementText(); - tempStringData = temptext; - } - else if ((xml->name() == "arguments") && xml->isStartElement()) - { - QString temptext = xml->readElementText(); - extraStringData = temptext; - } - else if ((xml->name() == "mode") && xml->isStartElement()) - { - QString temptext = xml->readElementText(); - - if (temptext == "keyboard") - { - this->setSlotMode(JoyKeyboard); - } - else if (temptext == "mousebutton") - { - this->setSlotMode(JoyMouseButton); - } - else if (temptext == "mousemovement") - { - this->setSlotMode(JoyMouseMovement); - } - else if (temptext == "pause") - { - this->setSlotMode(JoyPause); - } - else if (temptext == "hold") - { - this->setSlotMode(JoyHold); - } - else if (temptext == "cycle") - { - this->setSlotMode(JoyCycle); - } - else if (temptext == "distance") - { - this->setSlotMode(JoyDistance); - } - else if (temptext == "release") - { - this->setSlotMode(JoyRelease); - } - else if (temptext == "mousespeedmod") - { - this->setSlotMode(JoyMouseSpeedMod); - } - else if (temptext == "keypress") - { - this->setSlotMode(JoyKeyPress); - } - else if (temptext == "delay") - { - this->setSlotMode(JoyDelay); - } - else if (temptext == "loadprofile") - { - this->setSlotMode(JoyLoadProfile); - } - else if (temptext == "setchange") - { - this->setSlotMode(JoySetChange); - } - else if (temptext == "textentry") - { - this->setSlotMode(JoyTextEntry); - } - else if (temptext == "execute") - { - this->setSlotMode(JoyExecute); - } - } - else - { - xml->skipCurrentElement(); - } - - xml->readNextStartElement(); - } - - if (this->getSlotMode() == JoyButtonSlot::JoyKeyboard) - { - int virtualkey = AntKeyMapper::getInstance()->returnVirtualKey(this->getSlotCode()); - int tempkey = this->getSlotCode(); - - if (virtualkey) - { - // Mapping found a valid native keysym. - this->setSlotCode(virtualkey, tempkey); - } - else if (this->getSlotCode() > QtKeyMapperBase::nativeKeyPrefix) - { - // Value is in the native key range. Remove prefix and use - // new value as a native keysym. - int temp = this->getSlotCode() - QtKeyMapperBase::nativeKeyPrefix; - this->setSlotCode(temp); - } - } - else if ((this->getSlotMode() == JoyButtonSlot::JoyLoadProfile) && !profile.isEmpty()) - { - QFileInfo profileInfo(profile); - - if (!profileInfo.exists() || !((profileInfo.suffix() == "amgp") || (profileInfo.suffix() == "xml"))) - { - this->setTextData(""); - } - else - { - this->setTextData(profile); - } - } - else if (this->getSlotMode() == JoySetChange && !(this->getSlotCode() >= 0) && !(this->getSlotCode() < GlobalVariables::InputDevice::NUMBER_JOYSETS)) - { - this->setSlotCode(-1); - } - else if ((this->getSlotMode() == JoyTextEntry) && !tempStringData.isEmpty()) - { - this->setTextData(tempStringData); - } - else if ((this->getSlotMode() == JoyExecute) && !tempStringData.isEmpty()) - { - QFileInfo tempFile(tempStringData); - - if (tempFile.exists() && tempFile.isExecutable()) - { - this->setTextData(tempStringData); - - if (!extraStringData.isEmpty()) - this->setExtraData(QVariant(extraStringData)); - } - } - } -} - -void JoyButtonSlot::writeConfig(QXmlStreamWriter *xml) -{ - qInstallMessageHandler(MessageHandler::myMessageOutput); - - xml->writeStartElement(getXmlName()); - - if (m_mode == JoyKeyboard) - { - int basekey = AntKeyMapper::getInstance()->returnQtKey(deviceCode); - int qtkey = this->getSlotCodeAlias(); - - if ((qtkey > 0) || (basekey > 0)) - { - // Did not add an alias to slot. If a possible Qt key value - // was found, use it. - if ((qtkey == 0) && (basekey > 0)) qtkey = basekey; - - // Found a valid abstract keysym. - #ifndef QT_DEBUG_NO_OUTPUT - qDebug() << "ANT KEY: " << QString::number(qtkey, 16); - #endif - - xml->writeTextElement("code", QString("0x%1").arg(qtkey, 0, 16)); - } - else if (deviceCode > 0) - { - // No abstraction provided for key. Add prefix to native keysym. - int tempkey = deviceCode | QtKeyMapperBase::nativeKeyPrefix; - - #ifndef QT_DEBUG_NO_OUTPUT - qDebug() << "ANT KEY: " << QString::number(tempkey, 16); - #endif - - xml->writeTextElement("code", QString("0x%1").arg(tempkey, 0, 16)); - } - } - else if ((m_mode == JoyLoadProfile) && !m_textData.isEmpty()) - { - xml->writeTextElement("profile", m_textData); - } - else if ((m_mode == JoyTextEntry) && !m_textData.isEmpty()) - { - xml->writeTextElement("text", m_textData); - } - else if ((m_mode == JoyExecute) && !m_textData.isEmpty()) - { - xml->writeTextElement("path", m_textData); - - if (!extraData.isNull() && extraData.canConvert()) - { - xml->writeTextElement("arguments", extraData.toString()); - } - } - else - { - xml->writeTextElement("code", QString::number(deviceCode)); - } - - xml->writeStartElement("mode"); - - switch(m_mode) - { - case JoyKeyboard: - xml->writeCharacters("keyboard"); - break; - - case JoyMouseButton: - xml->writeCharacters("mousebutton"); - break; - - case JoyMouseMovement: - xml->writeCharacters("mousemovement"); - break; - - case JoyPause: - xml->writeCharacters("pause"); - break; - - case JoyHold: - xml->writeCharacters("hold"); - break; - - case JoyCycle: - xml->writeCharacters("cycle"); - break; - - case JoyDistance: - xml->writeCharacters("distance"); - break; - - case JoyRelease: - xml->writeCharacters("release"); - break; - - case JoyMouseSpeedMod: - xml->writeCharacters("mousespeedmod"); - break; - - case JoyKeyPress: - xml->writeCharacters("keypress"); - break; - - case JoyDelay: - xml->writeCharacters("delay"); - break; - - case JoyLoadProfile: - xml->writeCharacters("loadprofile"); - break; - - case JoySetChange: - xml->writeCharacters("setchange"); - break; - - case JoyTextEntry: - xml->writeCharacters("textentry"); - break; - - case JoyExecute: - xml->writeCharacters("execute"); - break; - } - - xml->writeEndElement(); - xml->writeEndElement(); -} - QString JoyButtonSlot::getXmlName() { qInstallMessageHandler(MessageHandler::myMessageOutput); diff --git a/src/joybuttonslot.h b/src/joybuttonslot.h index 9d87f013..e554cf8d 100755 --- a/src/joybuttonslot.h +++ b/src/joybuttonslot.h @@ -24,8 +24,6 @@ #include #include -class QXmlStreamReader; -class QXmlStreamWriter; class JoyButtonSlot : public QObject { @@ -77,9 +75,6 @@ class JoyButtonSlot : public QObject QVariant getExtraData(); bool isValidSlot(); - - virtual void readConfig(QXmlStreamReader *xml); - virtual void writeConfig(QXmlStreamWriter *xml); private: int deviceCode; diff --git a/src/joybuttonslotslist.cpp b/src/joybuttonslotslist.cpp new file mode 100644 index 00000000..e2aa42bf --- /dev/null +++ b/src/joybuttonslotslist.cpp @@ -0,0 +1,6 @@ +#include "joybuttonslotslist.h" + +JoyButtonSlotsList::JoyButtonSlotsList(QObject *parent) : QObject(parent) +{ + +} diff --git a/src/joybuttonslotslist.h b/src/joybuttonslotslist.h new file mode 100644 index 00000000..bfe6ff24 --- /dev/null +++ b/src/joybuttonslotslist.h @@ -0,0 +1,113 @@ +#ifndef JOYBUTTONSLOTSLIST_H +#define JOYBUTTONSLOTSLIST_H + +#include "joybuttonslot.h" + +#include + + + +class JoyButtonSlotsList : public QObject +{ + Q_OBJECT + +public: + explicit JoyButtonSlotsList(QObject *parent = nullptr); + + bool containsSequence(); + bool containsDistanceSlots(); // JoyButtonSlots class * + bool containsReleaseSlots(); // JoyButtonSlots class * + bool hasActiveSlots(); // JoyButtonSlots class * + + QList* getAssignedSlots(); // JoyButtonSlots class * + QList const& getActiveSlots(); // JoyButtonSlots class * + + virtual QString getSlotsSummary(); // JoyButtonSlots class * + virtual QString getSlotsString(); // JoyButtonSlots class * + + bool insertAssignedSlot(JoyButtonSlot *newSlot, bool updateActiveString=true); // JoyButtonSlots class + + +signals: + void slotsChanged(); // JoyButtonSlots class * + + +public slots: + void removeAssignedSlot(int index); // JoyButtonSlots class * + + bool setAssignedSlot(int code, int alias, int index, + JoyButtonSlot::JoySlotInputAction mode=JoyButtonSlot::JoyKeyboard); // JoyButtonSlots class + + bool setAssignedSlot(int code, + JoyButtonSlot::JoySlotInputAction mode=JoyButtonSlot::JoyKeyboard); // JoyButtonSlots class + + bool setAssignedSlot(int code, int alias, + JoyButtonSlot::JoySlotInputAction mode=JoyButtonSlot::JoyKeyboard); // JoyButtonSlots class + + bool setAssignedSlot(JoyButtonSlot *otherSlot, int index); // JoyButtonSlots class + + bool insertAssignedSlot(int code, int alias, int index, + JoyButtonSlot::JoySlotInputAction mode=JoyButtonSlot::JoyKeyboard); // JoyButtonSlots class + + +protected: + void clearAssignedSlots(bool signalEmit=true); // JoyButtonSlots class * + void checkTurboCondition(JoyButtonSlot *slot); // JoyButtonSlots class * + + static JoyButtonSlot *lastActiveKey; // JoyButtonSlots class* + + +protected slots: + + +private slots: + void releaseActiveSlots(); // JoyButtonSlots class * + + +private: + + void findJoySlotsEnd(QListIterator *slotiter); // JoyButtonSlots class * + void countActiveSlots(int tempcode, int& references, JoyButtonSlot* slot, QHash& activeSlotsHash, bool& changeRepeatState, bool activeSlotHashWindows = false); // JoyButtonSlots class * + void releaseMoveSlots(QList& cursorSpeeds, JoyButtonSlot *slot, QList& indexesToRemove); // JoyButtonSlots class * + + QList& getAssignmentsLocal(); // JoyButtonSlots class * + QList& getActiveSlotsLocal(); // JoyButtonSlots class * + + inline void resetSlotsProp(bool currentChangedSlot = false) // JoyButtonSlots class + { + currentCycle = nullptr; + previousCycle = nullptr; + currentPause = nullptr; + currentHold = nullptr; + m_currentDistance = nullptr; + currentRawValue = 0; + currentMouseEvent = nullptr; + currentRelease = nullptr; + currentWheelVerticalEvent = nullptr; + currentWheelHorizontalEvent = nullptr; + currentKeyPress = nullptr; + currentDelay = nullptr; + if (currentChangedSlot) currentSetChangeSlot = nullptr; + + isKeyPressed = isButtonPressed = false; + quitEvent = true; + } + + QList assignments; + QList activeSlots; + QListIterator *slotiter; + JoyButtonSlot *currentPause; + JoyButtonSlot *currentHold; + JoyButtonSlot *currentCycle; + JoyButtonSlot *previousCycle; + JoyButtonSlot *m_currentDistance; + JoyButtonSlot *currentMouseEvent; // JoyButtonEvents class + JoyButtonSlot *currentRelease; + JoyButtonSlot *currentKeyPress; + JoyButtonSlot *currentDelay; + JoyButtonSlot *currentSetChangeSlot; + + +}; + +#endif // JOYBUTTONSLOTSLIST_H diff --git a/src/joycontrolstick.cpp b/src/joycontrolstick.cpp index af2e9742..4207fad7 100755 --- a/src/joycontrolstick.cpp +++ b/src/joycontrolstick.cpp @@ -22,14 +22,11 @@ #include "inputdevice.h" #include "joybuttontypes/joycontrolstickbutton.h" #include "joybuttontypes/joycontrolstickmodifierbutton.h" -#include "xml/joybuttonxml.h" #include "joyaxis.h" #include #include #include -#include -#include #include #include @@ -1090,173 +1087,6 @@ void JoyControlStick::deleteButtons() } } -/** - * @brief Take a XML stream and set the stick and direction button properties - * according to the values contained within the stream. - * @param QXmlStreamReader instance that will be used to read property values. - */ -void JoyControlStick::readConfig(QXmlStreamReader *xml) -{ - qInstallMessageHandler(MessageHandler::myMessageOutput); - - if (xml->isStartElement() && (xml->name() == "stick")) - { - xml->readNextStartElement(); - - while (!xml->atEnd() && (!xml->isEndElement() && (xml->name() != "stick"))) - { - if ((xml->name() == "deadZone") && xml->isStartElement()) - { - QString temptext = xml->readElementText(); - int tempchoice = temptext.toInt(); - this->setDeadZone(tempchoice); - } - else if ((xml->name() == "maxZone") && xml->isStartElement()) - { - QString temptext = xml->readElementText(); - int tempchoice = temptext.toInt(); - this->setMaxZone(tempchoice); - } - else if ((xml->name() == "calibrated") && xml->isStartElement()) - { - QString temptext = xml->readElementText(); - bool tempchoice = (temptext == "true") ? true : false; - this->setCalibrationFlag(tempchoice); - } - else if ((xml->name() == "summary") && xml->isStartElement()) - { - QString temptext = xml->readElementText(); - this->setCalibrationSummary(temptext); - } - else if ((xml->name() == "diagonalRange") && xml->isStartElement()) - { - QString temptext = xml->readElementText(); - int tempchoice = temptext.toInt(); - this->setDiagonalRange(tempchoice); - } - else if ((xml->name() == "mode") && xml->isStartElement()) - { - QString temptext = xml->readElementText(); - - if (temptext == "eight-way") - { - this->setJoyMode(EightWayMode); - } - else if (temptext == "four-way") - { - this->setJoyMode(FourWayCardinal); - } - else if (temptext == "diagonal") - { - this->setJoyMode(FourWayDiagonal); - } - } - else if ((xml->name() == "squareStick") && xml->isStartElement()) - { - int tempchoice = xml->readElementText().toInt(); - - if ((tempchoice > 0) && (tempchoice <= 100)) - this->setCircleAdjust(tempchoice / 100.0); - } - else if ((xml->name() == GlobalVariables::JoyControlStickButton::xmlName) && xml->isStartElement()) - { - int index = xml->attributes().value("index").toString().toInt(); - JoyControlStickButton *button = buttons.value(static_cast(index)); - JoyButtonXml* joyButtonXml = new JoyButtonXml(button); - - if (button != nullptr) joyButtonXml->readConfig(xml); - else xml->skipCurrentElement(); - } - else if ((xml->name() == GlobalVariables::JoyControlStickModifierButton::xmlName) && xml->isStartElement()) - { - JoyButtonXml* joyButtonXml = new JoyButtonXml(modifierButton); - joyButtonXml->readConfig(xml); - } - else if ((xml->name() == "stickDelay") && xml->isStartElement()) - { - QString temptext = xml->readElementText(); - int tempchoice = temptext.toInt(); - this->setStickDelay(tempchoice); - } - else - { - xml->skipCurrentElement(); - } - - xml->readNextStartElement(); - } - } -} - -/** - * @brief Write the status of the properties of a stick and direction buttons - * to an XML stream. - * @param QXmlStreamWriter instance that will be used to write a profile. - */ -void JoyControlStick::writeConfig(QXmlStreamWriter *xml) -{ - qInstallMessageHandler(MessageHandler::myMessageOutput); - - if (!isDefault()) - { - xml->writeStartElement("stick"); - xml->writeAttribute("index", QString::number(index+1)); - - if (deadZone != GlobalVariables::JoyControlStick::DEFAULTDEADZONE) - xml->writeTextElement("deadZone", QString::number(deadZone)); - - if (maxZone != GlobalVariables::JoyControlStick::DEFAULTMAXZONE) - xml->writeTextElement("maxZone", QString::number(maxZone)); - - xml->writeTextElement("calibrated", (calibrated ? "true" : "false")); - xml->writeTextElement("summary", (getCalibrationSummary().isEmpty() ? "" : calibrationSummary)); - - - if ((currentMode == StandardMode || currentMode == EightWayMode) && (diagonalRange != GlobalVariables::JoyControlStick::DEFAULTDIAGONALRANGE)) - { - xml->writeTextElement("diagonalRange", QString::number(diagonalRange)); - } - - switch(currentMode) - { - case EightWayMode: - xml->writeTextElement("mode", "eight-way"); - break; - - case FourWayCardinal: - xml->writeTextElement("mode", "four-way"); - break; - - case FourWayDiagonal: - xml->writeTextElement("mode", "diagonal"); - break; - } - - if (circle > GlobalVariables::JoyControlStick::DEFAULTCIRCLE) - xml->writeTextElement("squareStick", QString::number(circle * 100)); - - if (stickDelay > GlobalVariables::JoyControlStick::DEFAULTSTICKDELAY) - xml->writeTextElement("stickDelay", QString::number(stickDelay)); - - QHashIterator iter(buttons); - - while (iter.hasNext()) - { - JoyControlStickButton *button = iter.next().value(); - JoyButtonXml* joyButtonXml = new JoyButtonXml(button); - joyButtonXml->writeConfig(xml); - } - - if (!modifierButton->isDefault()) - { - JoyButtonXml* joyButtonXmlModif = new JoyButtonXml(modifierButton); - joyButtonXmlModif->writeConfig(xml); - } - - xml->writeEndElement(); - } -} - /** * @brief Reset all the properties of the stick direction buttons and the * stick modifier button. diff --git a/src/joycontrolstick.h b/src/joycontrolstick.h index 837d09be..5bfb41fc 100755 --- a/src/joycontrolstick.h +++ b/src/joycontrolstick.h @@ -30,8 +30,6 @@ class JoyAxis; class JoyControlStickButton; class JoyControlStickModifierButton; -class QXmlStreamReader; -class QXmlStreamWriter; class JoyControlStick : public QObject, public JoyStickDirectionsType @@ -174,8 +172,6 @@ class JoyControlStick : public QObject, public JoyStickDirectionsType virtual bool isDefault(); virtual void setDefaultStickName(QString tempname); virtual QString getDefaultStickName(); - virtual void readConfig(QXmlStreamReader *xml); // JoyControlStickXml class - virtual void writeConfig(QXmlStreamWriter *xml); // JoyControlStickXml class static const JoyMode DEFAULTMODE; diff --git a/src/joydpad.cpp b/src/joydpad.cpp index e7e02c01..6e85f140 100755 --- a/src/joydpad.cpp +++ b/src/joydpad.cpp @@ -23,8 +23,6 @@ #include #include -#include -#include JoyDPad::JoyDPad(int index, int originset, SetJoystick *parentSet, QObject *parent) : diff --git a/src/joydpad.h b/src/joydpad.h index 51f7caa1..48321f42 100755 --- a/src/joydpad.h +++ b/src/joydpad.h @@ -18,7 +18,6 @@ #ifndef JOYDPAD_H #define JOYDPAD_H - #include "joybuttontypes/joydpadbutton.h" #include @@ -26,8 +25,6 @@ #include #include -class QXmlStreamReader; -class QXmlStreamWriter; class JoyDPad : public QObject { diff --git a/src/setjoystick.cpp b/src/setjoystick.cpp index a1824044..c3b6bc53 100755 --- a/src/setjoystick.cpp +++ b/src/setjoystick.cpp @@ -25,14 +25,9 @@ #include "joybutton.h" #include "vdpad.h" #include "joybuttontypes/joycontrolstickbutton.h" -#include "xml/joydpadxml.h" -#include "xml/joyaxisxml.h" -#include "xml/joybuttonxml.h" #include #include -#include -#include #include @@ -392,143 +387,6 @@ void SetJoystick::release() } } -void SetJoystick::readConfig(QXmlStreamReader *xml) -{ - qInstallMessageHandler(MessageHandler::myMessageOutput); - - if (xml->isStartElement() && (xml->name() == "set")) - { - 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); - joyButtonXml = new JoyButtonXml(button); - - if (button != nullptr) joyButtonXml->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); - joyAxisXml = new JoyAxisXml(axis); - - if (axis != nullptr) joyAxisXml->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); - joydpadXml = new JoyDPadXml(dpad); - - if (dpad != nullptr && joydpadXml != nullptr) joydpadXml->readConfig(xml); - else xml->skipCurrentElement(); - } - else if ((xml->name() == "stick") && xml->isStartElement()) - { - int stickIndex = xml->attributes().value("index").toString().toInt(); - - if (stickIndex > 0) - { - stickIndex -= 1; - JoyControlStick *stick = getJoyStick(stickIndex); - - if (stick != nullptr) stick->readConfig(xml); - else xml->skipCurrentElement(); - } - else - { - xml->skipCurrentElement(); - } - } - else if ((xml->name() == "vdpad") && xml->isStartElement()) - { - int index = xml->attributes().value("index").toString().toInt(); - VDPad *vdpad = getVDPad(index - 1); - joydpadXml = new JoyDPadXml(vdpad); - - if (joydpadXml != nullptr) joydpadXml->readConfig(xml); - else xml->skipCurrentElement(); - } - else if ((xml->name() == "name") && xml->isStartElement()) - { - QString temptext = xml->readElementText(); - - if (!temptext.isEmpty()) setName(temptext); - } - else - { - xml->skipCurrentElement(); // If none of the above, skip the element - } - - xml->readNextStartElement(); - } - } -} - -void SetJoystick::writeConfig(QXmlStreamWriter *xml) -{ - qInstallMessageHandler(MessageHandler::myMessageOutput); - - if (!isSetEmpty()) - { - xml->writeStartElement("set"); - xml->writeAttribute("index", QString::number(m_index+1)); - - if (!m_name.isEmpty()) - xml->writeTextElement("name", m_name); - - for (int i = 0; i < getNumberSticks(); i++) - { - JoyControlStick *stick = getJoyStick(i); - stick->writeConfig(xml); - } - - for (int i = 0; i < getNumberVDPads(); i++) - { - VDPad *vdpad = getVDPad(i); - - joydpadXml = new JoyDPadXml(vdpad); - if (joydpadXml != nullptr) joydpadXml->writeConfig(xml); - } - - for (int i = 0; i < getNumberAxes(); i++) - { - JoyAxis *axis = getJoyAxis(i); - joyAxisXml = new JoyAxisXml(axis); - - if (!axis->isPartControlStick() && axis->hasControlOfButtons()) - { - joyAxisXml->writeConfig(xml); - } - } - - for (int i = 0; i < getNumberHats(); i++) - { - JoyDPad *dpad = getJoyDPad(i); - joydpadXml = new JoyDPadXml(dpad); - joydpadXml->writeConfig(xml); - } - - for (int i = 0 ; i < getNumberButtons(); i++) - { - JoyButton *button = getJoyButton(i); - - if ((button != nullptr) && !button->isPartVDPad()) - { - joyButtonXml = new JoyButtonXml(button); - joyButtonXml->writeConfig(xml); - } - } - - xml->writeEndElement(); - } -} bool SetJoystick::isSetEmpty() { diff --git a/src/setjoystick.h b/src/setjoystick.h index 26434d93..c192368f 100755 --- a/src/setjoystick.h +++ b/src/setjoystick.h @@ -24,17 +24,14 @@ #include #include #include +#include class InputDevice; class JoyButton; class JoyDPad; class JoyControlStick; class VDPad; -class QXmlStreamReader; -class QXmlStreamWriter; -class JoyDPadXml; -class JoyAxisXml; -class JoyButtonXml; + class SetJoystick : public QObject { @@ -88,11 +85,9 @@ class SetJoystick : public QObject void removeAllBtnFromQueue(); int getCountBtnInList(QString partialName); - virtual void readConfig(QXmlStreamReader *xml); - virtual void writeConfig(QXmlStreamWriter *xml); + bool isSetEmpty(); protected: - bool isSetEmpty(); void deleteButtons(); // SetButton class void deleteAxes(); // SetAxis class void deleteHats(); // SetHat class @@ -185,9 +180,6 @@ protected slots: InputDevice *m_device; QString m_name; - JoyDPadXml* joydpadXml; - JoyAxisXml* joyAxisXml; - JoyButtonXml* joyButtonXml; }; Q_DECLARE_METATYPE(SetJoystick*) diff --git a/src/xml/inputdevicexml.cpp b/src/xml/inputdevicexml.cpp index 6d707ed5..cb390576 100644 --- a/src/xml/inputdevicexml.cpp +++ b/src/xml/inputdevicexml.cpp @@ -3,6 +3,7 @@ #include "vdpad.h" #include "joycontrolstick.h" #include "joybuttontypes/joycontrolstickbutton.h" +#include "xml/setjoystickxml.h" #include "globalvariables.h" #include "messagehandler.h" @@ -48,7 +49,10 @@ void InputDeviceXml::readConfig(QXmlStreamReader *xml) index = index - 1; if ((index >= 0) && (index < m_inputDevice->getJoystick_sets().size())) - m_inputDevice->getJoystick_sets().value(index)->readConfig(xml); + + if (!m_setJoystickXml.isNull()) m_setJoystickXml.clear(); + m_setJoystickXml = new SetJoystickXml(const_cast(m_inputDevice->getJoystick_sets().value(index))); + m_setJoystickXml.data()->readConfig(xml); } else { @@ -617,12 +621,16 @@ void InputDeviceXml::writeConfig(QXmlStreamWriter *xml) if ((m_inputDevice->getDeviceKeyPressTime() > 0) && (m_inputDevice->getDeviceKeyPressTime() != GlobalVariables::InputDevice::DEFAULTKEYPRESSTIME)) xml->writeTextElement("keyPressTime", QString::number(m_inputDevice->getDeviceKeyPressTime())); - xml->writeStartElement("sets"); + xml->writeStartElement("sets"); for (int i = 0; i < m_inputDevice->getJoystick_sets().size(); i++) - m_inputDevice->getJoystick_sets().value(i)->writeConfig(xml); + { + if (!m_setJoystickXml.isNull()) m_setJoystickXml.clear(); + m_setJoystickXml = new SetJoystickXml(m_inputDevice->getJoystick_sets().value(i)); + m_setJoystickXml->writeConfig(xml); + } - xml->writeEndElement(); + xml->writeEndElement(); xml->writeEndElement(); } diff --git a/src/xml/inputdevicexml.h b/src/xml/inputdevicexml.h index fdf55ff9..94f1de96 100644 --- a/src/xml/inputdevicexml.h +++ b/src/xml/inputdevicexml.h @@ -2,9 +2,12 @@ #define INPUTDEVICEXML_H #include +#include class QXmlStreamReader; class QXmlStreamWriter; +class SetJoystickXml; +class InputDeviceXml; class InputDevice; class AntiMicroSettings; @@ -21,8 +24,8 @@ public slots: virtual void writeConfig(QXmlStreamWriter *xml); // InputDeviceXml class private: - InputDevice* m_inputDevice; + QPointer m_setJoystickXml; }; diff --git a/src/xml/joyaxisxml.cpp b/src/xml/joyaxisxml.cpp index 419d9f79..24cebe73 100644 --- a/src/xml/joyaxisxml.cpp +++ b/src/xml/joyaxisxml.cpp @@ -13,8 +13,8 @@ JoyAxisXml::JoyAxisXml(JoyAxis* axis, QObject *parent) : QObject(parent) { m_joyAxis = axis; - joyButtonXmlNAxis = new JoyButtonXml(axis->getNAxisButton()); - joyButtonXmlPAxis = new JoyButtonXml(axis->getPAxisButton()); + m_joyButtonXmlNAxis = new JoyButtonXml(axis->getNAxisButton()); + m_joyButtonXmlPAxis = new JoyButtonXml(axis->getPAxisButton()); } @@ -93,8 +93,8 @@ void JoyAxisXml::writeConfig(QXmlStreamWriter *xml) if (!currentlyDefault) { - joyButtonXmlNAxis->writeConfig(xml); - joyButtonXmlPAxis->writeConfig(xml); + m_joyButtonXmlNAxis->writeConfig(xml); + m_joyButtonXmlPAxis->writeConfig(xml); } xml->writeEndElement(); @@ -224,12 +224,12 @@ bool JoyAxisXml::readButtonConfig(QXmlStreamReader *xml) if (index_local == 1) { found = true; - joyButtonXmlNAxis->readConfig(xml); + m_joyButtonXmlNAxis->readConfig(xml); } else if (index_local == 2) { found = true; - joyButtonXmlPAxis->readConfig(xml); + m_joyButtonXmlPAxis->readConfig(xml); } return found; diff --git a/src/xml/joyaxisxml.h b/src/xml/joyaxisxml.h index 82d3da82..d953cb50 100644 --- a/src/xml/joyaxisxml.h +++ b/src/xml/joyaxisxml.h @@ -1,7 +1,7 @@ #ifndef JOYAXISXML_H #define JOYAXISXML_H - +#include #include class JoyAxis; @@ -24,8 +24,8 @@ class JoyAxisXml : public QObject private: JoyAxis* m_joyAxis; - JoyButtonXml* joyButtonXmlNAxis; - JoyButtonXml* joyButtonXmlPAxis; + QPointer m_joyButtonXmlNAxis; + QPointer m_joyButtonXmlPAxis; }; #endif // JOYAXISXML_H diff --git a/src/xml/joybuttonslotxml.cpp b/src/xml/joybuttonslotxml.cpp new file mode 100644 index 00000000..c8211b9d --- /dev/null +++ b/src/xml/joybuttonslotxml.cpp @@ -0,0 +1,315 @@ +#include "joybuttonslotxml.h" +#include "joybuttonslot.h" + +#include "antkeymapper.h" +#include "messagehandler.h" +#include "globalvariables.h" + +#include +#include +#include +#include + + +JoyButtonSlotXml::JoyButtonSlotXml(JoyButtonSlot* btnSlot, QObject *parent) : QObject(parent) +{ + m_btnSlot = btnSlot; +} + + +void JoyButtonSlotXml::readConfig(QXmlStreamReader *xml) +{ + qInstallMessageHandler(MessageHandler::myMessageOutput); + + if (xml->isStartElement() && (xml->name() == "slot")) + { + QString profile = QString(); + QString tempStringData = QString(); + QString extraStringData = QString(); + + xml->readNextStartElement(); + + while (!xml->atEnd() && (!xml->isEndElement() && (xml->name() != "slot"))) + { + if ((xml->name() == "code") && xml->isStartElement()) + { + QString temptext = xml->readElementText(); + bool ok = false; + int tempchoice = temptext.toInt(&ok, 0); + + if (ok) m_btnSlot->setSlotCode(tempchoice); + } + else if ((xml->name() == "profile") && xml->isStartElement()) + { + QString temptext = xml->readElementText(); + profile = temptext; + } + else if ((xml->name() == "text") && xml->isStartElement()) + { + QString temptext = xml->readElementText(); + tempStringData = temptext; + } + else if ((xml->name() == "path") && xml->isStartElement()) + { + QString temptext = xml->readElementText(); + tempStringData = temptext; + } + else if ((xml->name() == "arguments") && xml->isStartElement()) + { + QString temptext = xml->readElementText(); + extraStringData = temptext; + } + else if ((xml->name() == "mode") && xml->isStartElement()) + { + QString temptext = xml->readElementText(); + + if (temptext == "keyboard") + { + m_btnSlot->setSlotMode(JoyButtonSlot::JoyKeyboard); + } + else if (temptext == "mousebutton") + { + m_btnSlot->setSlotMode(JoyButtonSlot::JoyMouseButton); + } + else if (temptext == "mousemovement") + { + m_btnSlot->setSlotMode(JoyButtonSlot::JoyMouseMovement); + } + else if (temptext == "pause") + { + m_btnSlot->setSlotMode(JoyButtonSlot::JoyPause); + } + else if (temptext == "hold") + { + m_btnSlot->setSlotMode(JoyButtonSlot::JoyHold); + } + else if (temptext == "cycle") + { + m_btnSlot->setSlotMode(JoyButtonSlot::JoyCycle); + } + else if (temptext == "distance") + { + m_btnSlot->setSlotMode(JoyButtonSlot::JoyDistance); + } + else if (temptext == "release") + { + m_btnSlot->setSlotMode(JoyButtonSlot::JoyRelease); + } + else if (temptext == "mousespeedmod") + { + m_btnSlot->setSlotMode(JoyButtonSlot::JoyMouseSpeedMod); + } + else if (temptext == "keypress") + { + m_btnSlot->setSlotMode(JoyButtonSlot::JoyKeyPress); + } + else if (temptext == "delay") + { + m_btnSlot->setSlotMode(JoyButtonSlot::JoyDelay); + } + else if (temptext == "loadprofile") + { + m_btnSlot->setSlotMode(JoyButtonSlot::JoyLoadProfile); + } + else if (temptext == "setchange") + { + m_btnSlot->setSlotMode(JoyButtonSlot::JoySetChange); + } + else if (temptext == "textentry") + { + m_btnSlot->setSlotMode(JoyButtonSlot::JoyTextEntry); + } + else if (temptext == "execute") + { + m_btnSlot->setSlotMode(JoyButtonSlot::JoyExecute); + } + } + else + { + xml->skipCurrentElement(); + } + + xml->readNextStartElement(); + } + + if (m_btnSlot->getSlotMode() == JoyButtonSlot::JoyKeyboard) + { + int virtualkey = AntKeyMapper::getInstance()->returnVirtualKey(m_btnSlot->getSlotCode()); + int tempkey = m_btnSlot->getSlotCode(); + + if (virtualkey) + { + // Mapping found a valid native keysym. + m_btnSlot->setSlotCode(virtualkey, tempkey); + } + else if (m_btnSlot->getSlotCode() > QtKeyMapperBase::nativeKeyPrefix) + { + // Value is in the native key range. Remove prefix and use + // new value as a native keysym. + int temp = m_btnSlot->getSlotCode() - QtKeyMapperBase::nativeKeyPrefix; + m_btnSlot->setSlotCode(temp); + } + } + else if ((m_btnSlot->getSlotMode() == JoyButtonSlot::JoyLoadProfile) && !profile.isEmpty()) + { + QFileInfo profileInfo(profile); + + if (!profileInfo.exists() || !((profileInfo.suffix() == "amgp") || (profileInfo.suffix() == "xml"))) + { + m_btnSlot->setTextData(""); + } + else + { + m_btnSlot->setTextData(profile); + } + } + else if (m_btnSlot->getSlotMode() == JoyButtonSlot::JoySetChange && !(m_btnSlot->getSlotCode() >= 0) && !(m_btnSlot->getSlotCode() < GlobalVariables::InputDevice::NUMBER_JOYSETS)) + { + m_btnSlot->setSlotCode(-1); + } + else if ((m_btnSlot->getSlotMode() == JoyButtonSlot::JoyTextEntry) && !tempStringData.isEmpty()) + { + m_btnSlot->setTextData(tempStringData); + } + else if ((m_btnSlot->getSlotMode() == JoyButtonSlot::JoyExecute) && !tempStringData.isEmpty()) + { + QFileInfo tempFile(tempStringData); + + if (tempFile.exists() && tempFile.isExecutable()) + { + m_btnSlot->setTextData(tempStringData); + + if (!extraStringData.isEmpty()) + m_btnSlot->setExtraData(QVariant(extraStringData)); + } + } + } +} + +void JoyButtonSlotXml::writeConfig(QXmlStreamWriter *xml) +{ + qInstallMessageHandler(MessageHandler::myMessageOutput); + + xml->writeStartElement(m_btnSlot->getXmlName()); + + if (m_btnSlot->getSlotMode() == JoyButtonSlot::JoyKeyboard) + { + int basekey = AntKeyMapper::getInstance()->returnQtKey(m_btnSlot->getSlotCode()); + int qtkey = m_btnSlot->getSlotCodeAlias(); + + if ((qtkey > 0) || (basekey > 0)) + { + // Did not add an alias to slot. If a possible Qt key value + // was found, use it. + if ((qtkey == 0) && (basekey > 0)) qtkey = basekey; + + // Found a valid abstract keysym. + #ifndef QT_DEBUG_NO_OUTPUT + qDebug() << "ANT KEY: " << QString::number(qtkey, 16); + #endif + + xml->writeTextElement("code", QString("0x%1").arg(qtkey, 0, 16)); + } + else if (m_btnSlot->getSlotCode() > 0) + { + // No abstraction provided for key. Add prefix to native keysym. + int tempkey = m_btnSlot->getSlotCode() | QtKeyMapperBase::nativeKeyPrefix; + + #ifndef QT_DEBUG_NO_OUTPUT + qDebug() << "ANT KEY: " << QString::number(tempkey, 16); + #endif + + xml->writeTextElement("code", QString("0x%1").arg(tempkey, 0, 16)); + } + } + else if ((m_btnSlot->getSlotMode() == JoyButtonSlot::JoyLoadProfile) && !m_btnSlot->getTextData().isEmpty()) + { + xml->writeTextElement("profile", m_btnSlot->getTextData()); + } + else if ((m_btnSlot->getSlotMode() == JoyButtonSlot::JoyTextEntry) && !m_btnSlot->getTextData().isEmpty()) + { + xml->writeTextElement("text", m_btnSlot->getTextData()); + } + else if ((m_btnSlot->getSlotMode() == JoyButtonSlot::JoyExecute) && !m_btnSlot->getTextData().isEmpty()) + { + xml->writeTextElement("path", m_btnSlot->getTextData()); + + if (!m_btnSlot->getExtraData().isNull() && m_btnSlot->getExtraData().canConvert()) + { + xml->writeTextElement("arguments", m_btnSlot->getExtraData().toString()); + } + } + else + { + xml->writeTextElement("code", QString::number(m_btnSlot->getSlotCode())); + } + + xml->writeStartElement("mode"); + + switch(m_btnSlot->getSlotMode()) + { + case JoyButtonSlot::JoyKeyboard: + xml->writeCharacters("keyboard"); + break; + + case JoyButtonSlot::JoyMouseButton: + xml->writeCharacters("mousebutton"); + break; + + case JoyButtonSlot::JoyMouseMovement: + xml->writeCharacters("mousemovement"); + break; + + case JoyButtonSlot::JoyPause: + xml->writeCharacters("pause"); + break; + + case JoyButtonSlot::JoyHold: + xml->writeCharacters("hold"); + break; + + case JoyButtonSlot::JoyCycle: + xml->writeCharacters("cycle"); + break; + + case JoyButtonSlot::JoyDistance: + xml->writeCharacters("distance"); + break; + + case JoyButtonSlot::JoyRelease: + xml->writeCharacters("release"); + break; + + case JoyButtonSlot::JoyMouseSpeedMod: + xml->writeCharacters("mousespeedmod"); + break; + + case JoyButtonSlot::JoyKeyPress: + xml->writeCharacters("keypress"); + break; + + case JoyButtonSlot::JoyDelay: + xml->writeCharacters("delay"); + break; + + case JoyButtonSlot::JoyLoadProfile: + xml->writeCharacters("loadprofile"); + break; + + case JoyButtonSlot::JoySetChange: + xml->writeCharacters("setchange"); + break; + + case JoyButtonSlot::JoyTextEntry: + xml->writeCharacters("textentry"); + break; + + case JoyButtonSlot::JoyExecute: + xml->writeCharacters("execute"); + break; + } + + xml->writeEndElement(); + xml->writeEndElement(); +} + diff --git a/src/xml/joybuttonslotxml.h b/src/xml/joybuttonslotxml.h new file mode 100644 index 00000000..32d19d25 --- /dev/null +++ b/src/xml/joybuttonslotxml.h @@ -0,0 +1,27 @@ +#ifndef JOYBUTTONSLOTXML_H +#define JOYBUTTONSLOTXML_H + +class JoyButtonSlot; +class QXmlStreamReader; +class QXmlStreamWriter; + +#include + +class JoyButtonSlotXml : public QObject +{ + Q_OBJECT +public: + explicit JoyButtonSlotXml(JoyButtonSlot* btnSlot, QObject *parent = nullptr); + + virtual void readConfig(QXmlStreamReader *xml); + virtual void writeConfig(QXmlStreamWriter *xml); + +signals: + +public slots: + +private: + JoyButtonSlot* m_btnSlot; +}; + +#endif // JOYBUTTONSLOTXML_H diff --git a/src/xml/joybuttonxml.cpp b/src/xml/joybuttonxml.cpp index 57f3514f..407141ae 100644 --- a/src/xml/joybuttonxml.cpp +++ b/src/xml/joybuttonxml.cpp @@ -1,5 +1,6 @@ #include "joybuttonxml.h" #include "joybutton.h" +#include "xml/joybuttonslotxml.h" #include "messagehandler.h" @@ -7,6 +8,7 @@ #include #include + JoyButtonXml::JoyButtonXml(JoyButton* joyButton, QObject *parent) : QObject(parent) { m_joyButton = joyButton; @@ -88,8 +90,11 @@ bool JoyButtonXml::readButtonConfig(QXmlStreamReader *xml) { if ((xml->name() == "slot") && xml->isStartElement()) { + if (!m_btnSlotXml.isNull()) m_btnSlotXml.clear(); + JoyButtonSlot *buttonslot = new JoyButtonSlot(this); - buttonslot->readConfig(xml); + m_btnSlotXml = new JoyButtonSlotXml(buttonslot); + m_btnSlotXml->readConfig(xml); if (buttonslot->isValidSlot()) { @@ -489,8 +494,11 @@ void JoyButtonXml::writeConfig(QXmlStreamWriter *xml) while (iter.hasNext()) { + if (!m_btnSlotXml.isNull()) m_btnSlotXml.clear(); + JoyButtonSlot *buttonslot = iter.next(); - buttonslot->writeConfig(xml); + m_btnSlotXml = new JoyButtonSlotXml(buttonslot); + m_btnSlotXml->writeConfig(xml); } xml->writeEndElement(); diff --git a/src/xml/joybuttonxml.h b/src/xml/joybuttonxml.h index 8444b819..e6d93886 100644 --- a/src/xml/joybuttonxml.h +++ b/src/xml/joybuttonxml.h @@ -2,7 +2,10 @@ #define JOYBUTTONXML_H #include +#include + class JoyButton; +class JoyButtonSlotXml; class QXmlStreamReader; class QXmlStreamWriter; @@ -19,6 +22,7 @@ class JoyButtonXml : public QObject private: JoyButton* m_joyButton; + QPointer m_btnSlotXml; }; diff --git a/src/xml/joycontrolstickxml.cpp b/src/xml/joycontrolstickxml.cpp new file mode 100644 index 00000000..20bf9b9c --- /dev/null +++ b/src/xml/joycontrolstickxml.cpp @@ -0,0 +1,183 @@ +#include "joycontrolstickxml.h" +#include "joycontrolstick.h" +#include "joybuttontypes/joycontrolstickbutton.h" +#include "joybuttontypes/joycontrolstickmodifierbutton.h" +#include "xml/joybuttonxml.h" + +#include "messagehandler.h" +#include "QDebug" + +#include +#include + +JoyControlStickXml::JoyControlStickXml(JoyControlStick* stick, QObject *parent) : QObject(parent) +{ + m_stick = stick; +} + +/** + * @brief Take a XML stream and set the stick and direction button properties + * according to the values contained within the stream. + * @param QXmlStreamReader instance that will be used to read property values. + */ +void JoyControlStickXml::readConfig(QXmlStreamReader *xml) +{ + qInstallMessageHandler(MessageHandler::myMessageOutput); + + if (xml->isStartElement() && (xml->name() == "stick")) + { + xml->readNextStartElement(); + + while (!xml->atEnd() && (!xml->isEndElement() && (xml->name() != "stick"))) + { + if ((xml->name() == "deadZone") && xml->isStartElement()) + { + QString temptext = xml->readElementText(); + int tempchoice = temptext.toInt(); + m_stick->setDeadZone(tempchoice); + } + else if ((xml->name() == "maxZone") && xml->isStartElement()) + { + QString temptext = xml->readElementText(); + int tempchoice = temptext.toInt(); + m_stick->setMaxZone(tempchoice); + } + else if ((xml->name() == "calibrated") && xml->isStartElement()) + { + QString temptext = xml->readElementText(); + bool tempchoice = (temptext == "true") ? true : false; + m_stick->setCalibrationFlag(tempchoice); + } + else if ((xml->name() == "summary") && xml->isStartElement()) + { + QString temptext = xml->readElementText(); + m_stick->setCalibrationSummary(temptext); + } + else if ((xml->name() == "diagonalRange") && xml->isStartElement()) + { + QString temptext = xml->readElementText(); + int tempchoice = temptext.toInt(); + m_stick->setDiagonalRange(tempchoice); + } + else if ((xml->name() == "mode") && xml->isStartElement()) + { + QString temptext = xml->readElementText(); + + if (temptext == "eight-way") + { + m_stick->setJoyMode(JoyControlStick::EightWayMode); + } + else if (temptext == "four-way") + { + m_stick->setJoyMode(JoyControlStick::FourWayCardinal); + } + else if (temptext == "diagonal") + { + m_stick->setJoyMode(JoyControlStick::FourWayDiagonal); + } + } + else if ((xml->name() == "squareStick") && xml->isStartElement()) + { + int tempchoice = xml->readElementText().toInt(); + + if ((tempchoice > 0) && (tempchoice <= 100)) + m_stick->setCircleAdjust(tempchoice / 100.0); + } + else if ((xml->name() == GlobalVariables::JoyControlStickButton::xmlName) && xml->isStartElement()) + { + int index = xml->attributes().value("index").toString().toInt(); + JoyControlStickButton *button = m_stick->getButtons()->value(static_cast(index)); + JoyButtonXml* joyButtonXml = new JoyButtonXml(button); + + if (button != nullptr) joyButtonXml->readConfig(xml); + else xml->skipCurrentElement(); + } + else if ((xml->name() == GlobalVariables::JoyControlStickModifierButton::xmlName) && xml->isStartElement()) + { + JoyButtonXml* joyButtonXml = new JoyButtonXml(m_stick->getModifierButton()); + joyButtonXml->readConfig(xml); + } + else if ((xml->name() == "stickDelay") && xml->isStartElement()) + { + QString temptext = xml->readElementText(); + int tempchoice = temptext.toInt(); + m_stick->setStickDelay(tempchoice); + } + else + { + xml->skipCurrentElement(); + } + + xml->readNextStartElement(); + } + } +} + +/** + * @brief Write the status of the properties of a stick and direction buttons + * to an XML stream. + * @param QXmlStreamWriter instance that will be used to write a profile. + */ +void JoyControlStickXml::writeConfig(QXmlStreamWriter *xml) +{ + qInstallMessageHandler(MessageHandler::myMessageOutput); + + if (!m_stick->isDefault()) + { + xml->writeStartElement("stick"); + xml->writeAttribute("index", QString::number(m_stick->getRealJoyIndex())); + + if (m_stick->getDeadZone() != GlobalVariables::JoyControlStick::DEFAULTDEADZONE) + xml->writeTextElement("deadZone", QString::number(m_stick->getDeadZone())); + + if (m_stick->getMaxZone() != GlobalVariables::JoyControlStick::DEFAULTMAXZONE) + xml->writeTextElement("maxZone", QString::number(m_stick->getMaxZone())); + + xml->writeTextElement("calibrated", (m_stick->wasCalibrated() ? "true" : "false")); + xml->writeTextElement("summary", (m_stick->getCalibrationSummary().isEmpty() ? "" : m_stick->getCalibrationSummary())); + + + if ((m_stick->getJoyMode() == JoyControlStick::StandardMode || m_stick->getJoyMode() == JoyControlStick::EightWayMode) && (m_stick->getDiagonalRange() != GlobalVariables::JoyControlStick::DEFAULTDIAGONALRANGE)) + { + xml->writeTextElement("diagonalRange", QString::number(m_stick->getDiagonalRange())); + } + + switch(m_stick->getJoyMode()) + { + case JoyControlStick::EightWayMode: + xml->writeTextElement("mode", "eight-way"); + break; + + case JoyControlStick::FourWayCardinal: + xml->writeTextElement("mode", "four-way"); + break; + + case JoyControlStick::FourWayDiagonal: + xml->writeTextElement("mode", "diagonal"); + break; + } + + if (m_stick->getCircleAdjust() > GlobalVariables::JoyControlStick::DEFAULTCIRCLE) + xml->writeTextElement("squareStick", QString::number(m_stick->getCircleAdjust() * 100)); + + if (m_stick->getStickDelay() > GlobalVariables::JoyControlStick::DEFAULTSTICKDELAY) + xml->writeTextElement("stickDelay", QString::number(m_stick->getStickDelay())); + + QHashIterator iter(*m_stick->getButtons()); + + while (iter.hasNext()) + { + JoyControlStickButton *button = iter.next().value(); + JoyButtonXml* joyButtonXml = new JoyButtonXml(button); + joyButtonXml->writeConfig(xml); + } + + if (!m_stick->getModifierButton()->isDefault()) + { + JoyButtonXml* joyButtonXmlModif = new JoyButtonXml(m_stick->getModifierButton()); + joyButtonXmlModif->writeConfig(xml); + } + + xml->writeEndElement(); + } +} diff --git a/src/xml/joycontrolstickxml.h b/src/xml/joycontrolstickxml.h new file mode 100644 index 00000000..40e1e1b9 --- /dev/null +++ b/src/xml/joycontrolstickxml.h @@ -0,0 +1,28 @@ +#ifndef JOYCONTROLSTICKXML_H +#define JOYCONTROLSTICKXML_H + +#include "joycontrolstickdirectionstype.h" +#include + +class JoyControlStick; +class QXmlStreamReader; +class QXmlStreamWriter; + +class JoyControlStickXml : public QObject, public JoyStickDirectionsType +{ + Q_OBJECT +public: + explicit JoyControlStickXml(JoyControlStick* stick, QObject *parent = nullptr); + + virtual void readConfig(QXmlStreamReader *xml); // JoyControlStickXml class + virtual void writeConfig(QXmlStreamWriter *xml); // JoyControlStickXml class + +signals: + +public slots: + +private: + JoyControlStick* m_stick; +}; + +#endif // JOYCONTROLSTICKXML_H diff --git a/src/xml/setjoystickxml.cpp b/src/xml/setjoystickxml.cpp new file mode 100644 index 00000000..58c3bab4 --- /dev/null +++ b/src/xml/setjoystickxml.cpp @@ -0,0 +1,183 @@ +#include "setjoystickxml.h" +#include "setjoystick.h" +#include "vdpad.h" +#include "xml/joydpadxml.h" +#include "xml/joyaxisxml.h" +#include "xml/joybuttonxml.h" +#include "xml/joycontrolstickxml.h" + +#include "messagehandler.h" + +#include +#include +#include + + +SetJoystickXml::SetJoystickXml(SetJoystick* setJoystick, QObject* parent) : QObject(parent) +{ + m_setJoystick = setJoystick; +} + + +void SetJoystickXml::readConfig(QXmlStreamReader *xml) +{ + qInstallMessageHandler(MessageHandler::myMessageOutput); + + if (xml->isStartElement() && (xml->name() == "set")) + { + 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 = m_setJoystick->getJoyButton(index - 1); + + if(!joyButtonXml.isNull()) joyButtonXml.clear(); + joyButtonXml = new JoyButtonXml(button); + + if (button != nullptr && !joyButtonXml.isNull()) joyButtonXml->readConfig(xml); + else xml->skipCurrentElement(); + } + else if ((xml->name() == "axis") && xml->isStartElement()) + { + int index = xml->attributes().value("index").toString().toInt(); + JoyAxis *axis = m_setJoystick->getJoyAxis(index - 1); + + if (!joyAxisXml.isNull()) joyAxisXml.clear(); + joyAxisXml = new JoyAxisXml(axis); + + if (axis != nullptr && !joyAxisXml.isNull()) joyAxisXml->readConfig(xml); + else xml->skipCurrentElement(); + } + else if ((xml->name() == "dpad") && xml->isStartElement()) + { + int index = xml->attributes().value("index").toString().toInt(); + JoyDPad *dpad = m_setJoystick->getJoyDPad(index - 1); + + if (!joydpadXml.isNull()) joydpadXml.clear(); + joydpadXml = new JoyDPadXml(dpad); + + if (dpad != nullptr && !joydpadXml.isNull()) joydpadXml->readConfig(xml); + else xml->skipCurrentElement(); + } + else if ((xml->name() == "stick") && xml->isStartElement()) + { + int stickIndex = xml->attributes().value("index").toString().toInt(); + + if (stickIndex > 0) + { + stickIndex -= 1; + JoyControlStick *stick = m_setJoystick->getJoyStick(stickIndex); + + if (!joyControlStickXml.isNull()) joyControlStickXml.clear(); + joyControlStickXml = new JoyControlStickXml(stick); + + if (stick != nullptr && !joyControlStickXml.isNull()) joyControlStickXml->readConfig(xml); + else xml->skipCurrentElement(); + } + else + { + xml->skipCurrentElement(); + } + } + else if ((xml->name() == "vdpad") && xml->isStartElement()) + { + int index = xml->attributes().value("index").toString().toInt(); + VDPad *vdpad = m_setJoystick->getVDPad(index - 1); + + if (!joydpadXml.isNull()) joydpadXml.clear(); + joydpadXml = new JoyDPadXml(vdpad); + + if (vdpad != nullptr && !joydpadXml.isNull()) joydpadXml->readConfig(xml); + else xml->skipCurrentElement(); + } + else if ((xml->name() == "name") && xml->isStartElement()) + { + QString temptext = xml->readElementText(); + + if (!temptext.isEmpty()) m_setJoystick->setName(temptext); + } + else + { + xml->skipCurrentElement(); // If none of the above, skip the element + } + + xml->readNextStartElement(); + } + } +} + +void SetJoystickXml::writeConfig(QXmlStreamWriter *xml) +{ + qInstallMessageHandler(MessageHandler::myMessageOutput); + + if (!m_setJoystick->isSetEmpty()) + { + xml->writeStartElement("set"); + xml->writeAttribute("index", QString::number(m_setJoystick->getRealIndex())); + + if (!m_setJoystick->getName().isEmpty()) + xml->writeTextElement("name", m_setJoystick->getName()); + + for (int i = 0; i < m_setJoystick->getNumberSticks(); i++) + { + JoyControlStick *stick = m_setJoystick->getJoyStick(i); + + if (!joyControlStickXml.isNull()) joyControlStickXml.clear(); + joyControlStickXml = new JoyControlStickXml(stick); + + if (stick != nullptr && !joyControlStickXml.isNull()) joyControlStickXml->writeConfig(xml); + } + + for (int i = 0; i < m_setJoystick->getNumberVDPads(); i++) + { + VDPad *vdpad = m_setJoystick->getVDPad(i); + + if (!joydpadXml.isNull()) joydpadXml.clear(); + joydpadXml = new JoyDPadXml(vdpad); + + if (vdpad != nullptr && !joydpadXml.isNull()) joydpadXml->writeConfig(xml); + } + + for (int i = 0; i < m_setJoystick->getNumberAxes(); i++) + { + JoyAxis *axis = m_setJoystick->getJoyAxis(i); + + if (!joyAxisXml.isNull()) joyAxisXml.clear(); + joyAxisXml = new JoyAxisXml(axis); + + if (!axis->isPartControlStick() && axis->hasControlOfButtons() + && (axis != nullptr && !joyAxisXml.isNull())) + { + joyAxisXml->writeConfig(xml); + } + } + + for (int i = 0; i < m_setJoystick->getNumberHats(); i++) + { + JoyDPad *dpad = m_setJoystick->getJoyDPad(i); + + if (!joydpadXml.isNull()) joydpadXml.clear(); + joydpadXml = new JoyDPadXml(dpad); + + if (dpad != nullptr && !joydpadXml.isNull()) joydpadXml->writeConfig(xml); + } + + for (int i = 0 ; i < m_setJoystick->getNumberButtons(); i++) + { + JoyButton *button = m_setJoystick->getJoyButton(i); + + if (!joyButtonXml.isNull()) joyButtonXml.clear(); + joyButtonXml = new JoyButtonXml(button); + + if ((button != nullptr && !joyButtonXml.isNull()) && !button->isPartVDPad()) + { + joyButtonXml->writeConfig(xml); + } + } + + xml->writeEndElement(); + } +} diff --git a/src/xml/setjoystickxml.h b/src/xml/setjoystickxml.h new file mode 100644 index 00000000..d88c4d4f --- /dev/null +++ b/src/xml/setjoystickxml.h @@ -0,0 +1,33 @@ +#ifndef SETJOYSTICKXML_H +#define SETJOYSTICKXML_H + +#include +#include + +class SetJoystick; +class JoyDPadXml; +class JoyAxisXml; +class JoyButtonXml; +class JoyControlStickXml; + +class QXmlStreamReader; +class QXmlStreamWriter; + +class SetJoystickXml : public QObject +{ +public: + SetJoystickXml(SetJoystick* setJoystick, QObject* parent = nullptr); + + virtual void readConfig(QXmlStreamReader *xml); + virtual void writeConfig(QXmlStreamWriter *xml); + +private: + SetJoystick* m_setJoystick; + + QPointer joydpadXml; + QPointer joyAxisXml; + QPointer joyButtonXml; + QPointer joyControlStickXml; +}; + +#endif // SETJOYSTICKXML_H