void SetJoystick::propogateSetVDPadNameChange() { VDPad *vdpad = static_cast<VDPad*>(sender()); disconnect(vdpad, SIGNAL(dpadNameChanged()), this, SLOT(propogateSetVDPadNameChange())); emit setVDPadNameChange(vdpad->getIndex()); connect(vdpad, SIGNAL(dpadNameChanged()), this, SLOT(propogateSetVDPadNameChange())); }
void InputDevice::updateSetVDPadNames(int vdpadIndex) { VDPad *vdpad = getActiveSetJoystick()->getVDPad(vdpadIndex); if (vdpad) { setVDPadName(vdpadIndex, vdpad->getDpadName()); } }
void SetJoystick::copyAssignments(SetJoystick *destSet) { for (int i=0; i < device->getNumberAxes(); i++) { JoyAxis *sourceAxis = axes.value(i); JoyAxis *destAxis = destSet->axes.value(i); if (sourceAxis && destAxis) { sourceAxis->copyAssignments(destAxis); } } QHashIterator<int, JoyControlStick*> stickIter(sticks); while (stickIter.hasNext()) { stickIter.next(); int index = stickIter.key(); JoyControlStick *sourceStick = stickIter.value(); JoyControlStick *destStick = destSet->sticks.value(index); if (sourceStick && destStick) { sourceStick->copyAssignments(destStick); } } for (int i=0; i < device->getNumberHats(); i++) { JoyDPad *sourceDPad = hats.value(i); JoyDPad *destDPad = destSet->hats.value(i); if (sourceDPad && destDPad) { sourceDPad->copyAssignments(destDPad); } } QHashIterator<int, VDPad*> vdpadIter(vdpads); while (vdpadIter.hasNext()) { vdpadIter.next(); int index = vdpadIter.key(); VDPad *sourceVDpad = vdpadIter.value(); VDPad *destVDPad = destSet->vdpads.value(index); if (sourceVDpad && destVDPad) { sourceVDpad->copyAssignments(destVDPad); } } for (int i=0; i < device->getNumberButtons(); i++) { JoyButton *sourceButton = buttons.value(i); JoyButton *destButton = destSet->buttons.value(i); if (sourceButton && destButton) { sourceButton->copyAssignments(destButton); } } }
bool SetJoystick::isSetEmpty() { bool result = true; QHashIterator<int, JoyButton*> iter(buttons); while (iter.hasNext() && result) { JoyButton *button = iter.next().value(); if (!button->isDefault()) { result = false; } } QHashIterator<int, JoyAxis*> iter2(axes); while (iter2.hasNext() && result) { JoyAxis *axis = iter2.next().value(); if (!axis->isDefault()) { result = false; } } QHashIterator<int, JoyDPad*> iter3(hats); while (iter3.hasNext() && result) { JoyDPad *dpad = iter3.next().value(); if (!dpad->isDefault()) { result = false; } } QHashIterator<int, JoyControlStick*> iter4(sticks); while (iter4.hasNext() && result) { JoyControlStick *stick = iter4.next().value(); if (!stick->isDefault()) { result = false; } } QHashIterator<int, VDPad*> iter5(vdpads); while (iter5.hasNext() && result) { VDPad *vdpad = iter5.next().value(); if (!vdpad->isDefault()) { result = false; } } return result; }
void SetJoystick::writeConfig(QXmlStreamWriter *xml) { if (!isSetEmpty()) { xml->writeStartElement("set"); xml->writeAttribute("index", QString::number(index+1)); if (!name.isEmpty()) { xml->writeTextElement("name", 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); if (vdpad) { vdpad->writeConfig(xml); } } for (int i=0; i < getNumberAxes(); i++) { JoyAxis *axis = getJoyAxis(i); if (!axis->isPartControlStick() && axis->hasControlOfButtons()) { axis->writeConfig(xml); } } for (int i=0; i < getNumberHats(); i++) { JoyDPad *dpad = getJoyDPad(i); dpad->writeConfig(xml); } for (int i=0; i < getNumberButtons(); i++) { JoyButton *button = getJoyButton(i); if (button && !button->isPartVDPad()) { button->writeConfig(xml); } } xml->writeEndElement(); } }
void InputDevice::updateSetVDPadButtonNames(int vdpadIndex, int buttonIndex) { VDPad *vdpad = getActiveSetJoystick()->getVDPad(vdpadIndex); if (vdpad) { JoyDPadButton *button = vdpad->getJoyButton(buttonIndex); if (button) { setVDPadButtonName(vdpadIndex, buttonIndex, button->getButtonName()); } } }
void InputDevice::setVDPadName(int vdpadIndex, QString tempName) { QHashIterator<int, SetJoystick*> iter(joystick_sets); while (iter.hasNext()) { SetJoystick *tempSet = iter.next().value(); disconnect(tempSet, SIGNAL(setVDPadNameChange(int)), this, SLOT(updateSetVDPadNames(int))); VDPad *vdpad = tempSet->getVDPad(vdpadIndex); if (vdpad) { vdpad->setDPadName(tempName); } connect(tempSet, SIGNAL(setVDPadNameChange(int)), this, SLOT(updateSetVDPadNames(int))); } }
void SetJoystick::setIgnoreEventState(bool ignore) { QHashIterator<int, JoyButton*> iter(buttons); while (iter.hasNext()) { JoyButton *button = iter.next().value(); if (button) { button->setIgnoreEventState(ignore); } } QHashIterator<int, JoyAxis*> iter2(axes); while (iter2.hasNext()) { JoyAxis *axis = iter2.next().value(); if (axis) { JoyAxisButton *naxisbutton = axis->getNAxisButton(); naxisbutton->setIgnoreEventState(ignore); JoyAxisButton *paxisbutton = axis->getPAxisButton(); paxisbutton->setIgnoreEventState(ignore); } } QHashIterator<int, JoyDPad*> iter3(hats); while (iter3.hasNext()) { JoyDPad *dpad = iter3.next().value(); if (dpad) { QHash<int, JoyDPadButton*>* dpadbuttons = dpad->getButtons(); QHashIterator<int, JoyDPadButton*> iterdpadbuttons(*dpadbuttons); while (iterdpadbuttons.hasNext()) { JoyDPadButton *dpadbutton = iterdpadbuttons.next().value(); if (dpadbutton) { dpadbutton->setIgnoreEventState(ignore); } } } } QHashIterator<int, JoyControlStick*> iter4(sticks); while (iter4.hasNext()) { JoyControlStick *stick = iter4.next().value(); if (stick) { QHash<JoyControlStick::JoyStickDirections, JoyControlStickButton*> *stickButtons = stick->getButtons(); QHashIterator<JoyControlStick::JoyStickDirections, JoyControlStickButton*> iterstickbuttons(*stickButtons); while (iterstickbuttons.hasNext()) { JoyControlStickButton *stickbutton = iterstickbuttons.next().value(); stickbutton->setIgnoreEventState(ignore); } } } QHashIterator<int, VDPad*> iter5(vdpads); while (iter5.hasNext()) { VDPad *vdpad = iter5.next().value(); if (vdpad) { QHash<int, JoyDPadButton*>* dpadbuttons = vdpad->getButtons(); QHashIterator<int, JoyDPadButton*> itervdpadbuttons(*dpadbuttons); while (itervdpadbuttons.hasNext()) { JoyDPadButton *dpadbutton = itervdpadbuttons.next().value(); dpadbutton->setIgnoreEventState(ignore); } } } }
void SetJoystick::readConfig(QXmlStreamReader *xml) { if (xml->isStartElement() && xml->name() == "set") { //reset(); xml->readNextStartElement(); while (!xml->atEnd() && (!xml->isEndElement() && xml->name() != "set")) { if (xml->name() == "button" && xml->isStartElement()) { int index = xml->attributes().value("index").toString().toInt(); JoyButton *button = getJoyButton(index-1); if (button) { button->readConfig(xml); } else { xml->skipCurrentElement(); } } else if (xml->name() == "axis" && xml->isStartElement()) { int index = xml->attributes().value("index").toString().toInt(); JoyAxis *axis = getJoyAxis(index-1); if (axis) { axis->readConfig(xml); } else { xml->skipCurrentElement(); } } else if (xml->name() == "dpad" && xml->isStartElement()) { int index = xml->attributes().value("index").toString().toInt(); JoyDPad *dpad = getJoyDPad(index-1); if (dpad) { dpad->readConfig(xml); } else { xml->skipCurrentElement(); } } else if (xml->name() == "stick" && xml->isStartElement()) { int stickIndex = xml->attributes().value("index").toString().toInt(); if (stickIndex > 0) { stickIndex -= 1; JoyControlStick *stick = getJoyStick(stickIndex); if (stick) { 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); if (vdpad) { vdpad->readConfig(xml); } else { xml->skipCurrentElement(); } } else { // If none of the above, skip the element xml->skipCurrentElement(); } xml->readNextStartElement(); } } }
void InputDevice::writeConfig(QXmlStreamWriter *xml) { xml->writeStartElement(getXmlName()); xml->writeAttribute("configversion", QString::number(PadderCommon::LATESTCONFIGFILEVERSION)); xml->writeAttribute("appversion", PadderCommon::programVersion); xml->writeComment("The SDL name for a joystick is included for informational purposes only."); xml->writeTextElement("sdlname", getSDLName()); for (int i=0; i < getNumberSticks(); i++) { JoyControlStick *stick = getActiveSetJoystick()->getJoyStick(i); xml->writeStartElement("stickAxisAssociation"); xml->writeAttribute("index", QString::number(stick->getRealJoyIndex())); xml->writeAttribute("xAxis", QString::number(stick->getAxisX()->getRealJoyIndex())); xml->writeAttribute("yAxis", QString::number(stick->getAxisY()->getRealJoyIndex())); xml->writeEndElement(); } for (int i=0; i < getNumberVDPads(); i++) { VDPad *vdpad = getActiveSetJoystick()->getVDPad(i); xml->writeStartElement("vdpadButtonAssociations"); xml->writeAttribute("index", QString::number(vdpad->getRealJoyNumber())); JoyButton *button = vdpad->getVButton(JoyDPadButton::DpadUp); if (button) { xml->writeStartElement("vdpadButtonAssociation"); if (typeid(*button) == typeid(JoyAxisButton)) { JoyAxisButton *axisbutton = static_cast<JoyAxisButton*>(button); xml->writeAttribute("axis", QString::number(axisbutton->getAxis()->getRealJoyIndex())); xml->writeAttribute("button", QString::number(button->getJoyNumber())); } else { xml->writeAttribute("axis", QString::number(0)); xml->writeAttribute("button", QString::number(button->getRealJoyNumber())); } xml->writeAttribute("direction", QString::number(JoyDPadButton::DpadUp)); xml->writeEndElement(); } button = vdpad->getVButton(JoyDPadButton::DpadDown); if (button) { xml->writeStartElement("vdpadButtonAssociation"); if (typeid(*button) == typeid(JoyAxisButton)) { JoyAxisButton *axisbutton = static_cast<JoyAxisButton*>(button); xml->writeAttribute("axis", QString::number(axisbutton->getAxis()->getRealJoyIndex())); xml->writeAttribute("button", QString::number(button->getJoyNumber())); } else { xml->writeAttribute("axis", QString::number(0)); xml->writeAttribute("button", QString::number(button->getRealJoyNumber())); } xml->writeAttribute("direction", QString::number(JoyDPadButton::DpadDown)); xml->writeEndElement(); } button = vdpad->getVButton(JoyDPadButton::DpadLeft); if (button) { xml->writeStartElement("vdpadButtonAssociation"); if (typeid(*button) == typeid(JoyAxisButton)) { JoyAxisButton *axisbutton = static_cast<JoyAxisButton*>(button); xml->writeAttribute("axis", QString::number(axisbutton->getAxis()->getRealJoyIndex())); xml->writeAttribute("button", QString::number(button->getJoyNumber())); } else { xml->writeAttribute("axis", QString::number(0)); xml->writeAttribute("button", QString::number(button->getRealJoyNumber())); } xml->writeAttribute("direction", QString::number(JoyDPadButton::DpadLeft)); xml->writeEndElement(); } button = vdpad->getVButton(JoyDPadButton::DpadRight); if (button) { xml->writeStartElement("vdpadButtonAssociation"); if (typeid(*button) == typeid(JoyAxisButton)) { JoyAxisButton *axisbutton = static_cast<JoyAxisButton*>(button); xml->writeAttribute("axis", QString::number(axisbutton->getAxis()->getRealJoyIndex())); xml->writeAttribute("button", QString::number(button->getJoyNumber())); } else { xml->writeAttribute("axis", QString::number(0)); xml->writeAttribute("button", QString::number(button->getRealJoyNumber())); } xml->writeAttribute("direction", QString::number(JoyDPadButton::DpadRight)); xml->writeEndElement(); } xml->writeEndElement(); } xml->writeStartElement("names"); // <name> SetJoystick *tempSet = getActiveSetJoystick(); for (int i=0; i < getNumberButtons(); i++) { JoyButton *button = tempSet->getJoyButton(i); if (button && !button->getButtonName().isEmpty()) { xml->writeStartElement("buttonname"); xml->writeAttribute("index", QString::number(button->getRealJoyNumber())); xml->writeCharacters(button->getButtonName()); xml->writeEndElement(); } } for (int i=0; i < getNumberAxes(); i++) { JoyAxis *axis = tempSet->getJoyAxis(i); if (axis) { if (!axis->getAxisName().isEmpty()) { xml->writeStartElement("axisname"); xml->writeAttribute("index", QString::number(axis->getRealJoyIndex())); xml->writeCharacters(axis->getAxisName()); xml->writeEndElement(); } JoyAxisButton *naxisbutton = axis->getNAxisButton(); if (!naxisbutton->getButtonName().isEmpty()) { xml->writeStartElement("axisbuttonname"); xml->writeAttribute("index", QString::number(axis->getRealJoyIndex())); xml->writeAttribute("button", QString::number(naxisbutton->getRealJoyNumber())); xml->writeCharacters(naxisbutton->getButtonName()); xml->writeEndElement(); } JoyAxisButton *paxisbutton = axis->getPAxisButton(); if (!paxisbutton->getButtonName().isEmpty()) { xml->writeStartElement("axisbuttonname"); xml->writeAttribute("index", QString::number(axis->getRealJoyIndex())); xml->writeAttribute("button", QString::number(paxisbutton->getRealJoyNumber())); xml->writeCharacters(paxisbutton->getButtonName()); xml->writeEndElement(); } } } for (int i=0; i < getNumberSticks(); i++) { JoyControlStick *stick = tempSet->getJoyStick(i); if (stick) { if (!stick->getStickName().isEmpty()) { xml->writeStartElement("controlstickname"); xml->writeAttribute("index", QString::number(stick->getRealJoyIndex())); xml->writeCharacters(stick->getStickName()); xml->writeEndElement(); } QHash<JoyControlStick::JoyStickDirections, JoyControlStickButton*> *buttons = stick->getButtons(); QHashIterator<JoyControlStick::JoyStickDirections, JoyControlStickButton*> iter(*buttons); while (iter.hasNext()) { JoyControlStickButton *button = iter.next().value(); if (button && !button->getButtonName().isEmpty()) { xml->writeStartElement("controlstickbuttonname"); xml->writeAttribute("index", QString::number(stick->getRealJoyIndex())); xml->writeAttribute("button", QString::number(button->getRealJoyNumber())); xml->writeCharacters(button->getButtonName()); xml->writeEndElement(); } } } } for (int i=0; i < getNumberHats(); i++) { JoyDPad *dpad = tempSet->getJoyDPad(i); if (dpad) { if (!dpad->getDpadName().isEmpty()) { xml->writeStartElement("dpadname"); xml->writeAttribute("index", QString::number(dpad->getRealJoyNumber())); xml->writeCharacters(dpad->getDpadName()); xml->writeEndElement(); } QHash<int, JoyDPadButton*> *temp = dpad->getButtons(); QHashIterator<int, JoyDPadButton*> iter(*temp); while (iter.hasNext()) { JoyDPadButton *button = iter.next().value(); if (button && !button->getButtonName().isEmpty()) { xml->writeStartElement("dpadbuttonname"); xml->writeAttribute("index", QString::number(dpad->getRealJoyNumber())); xml->writeAttribute("button", QString::number(button->getRealJoyNumber())); xml->writeCharacters(button->getButtonName()); xml->writeEndElement(); } } } } for (int i=0; i < getNumberVDPads(); i++) { VDPad *vdpad = getActiveSetJoystick()->getVDPad(i); if (vdpad) { if (!vdpad->getDpadName().isEmpty()) { xml->writeStartElement("vdpadname"); xml->writeAttribute("index", QString::number(vdpad->getRealJoyNumber())); xml->writeCharacters(vdpad->getDpadName()); xml->writeEndElement(); } QHash<int, JoyDPadButton*> *temp = vdpad->getButtons(); QHashIterator<int, JoyDPadButton*> iter(*temp); while (iter.hasNext()) { JoyDPadButton *button = iter.next().value(); if (button && !button->getButtonName().isEmpty()) { xml->writeStartElement("vdpadbutton"); xml->writeAttribute("index", QString::number(vdpad->getRealJoyNumber())); xml->writeAttribute("button", QString::number(button->getRealJoyNumber())); xml->writeCharacters(button->getButtonName()); xml->writeEndElement(); } } } } xml->writeEndElement(); // </names> if (keyDelay > 0) { xml->writeTextElement("keyPressTime", QString::number(keyDelay)); } xml->writeStartElement("sets"); for (int i=0; i < joystick_sets.size(); i++) { joystick_sets.value(i)->writeConfig(xml); } xml->writeEndElement(); xml->writeEndElement(); }
void InputDevice::readConfig(QXmlStreamReader *xml) { if (xml->isStartElement() && xml->name() == getXmlName()) { reset(); xml->readNextStartElement(); while (!xml->atEnd() && (!xml->isEndElement() && xml->name() != getXmlName())) { if (xml->name() == "sets" && xml->isStartElement()) { xml->readNextStartElement(); while (!xml->atEnd() && (!xml->isEndElement() && xml->name() != "sets")) { if (xml->name() == "set" && xml->isStartElement()) { int index = xml->attributes().value("index").toString().toInt(); index = index - 1; if (index >= 0 && index < joystick_sets.size()) { joystick_sets.value(index)->readConfig(xml); } } else { // If none of the above, skip the element xml->skipCurrentElement(); } xml->readNextStartElement(); } } else if (xml->name() == "stickAxisAssociation" && xml->isStartElement()) { int stickIndex = xml->attributes().value("index").toString().toInt(); int xAxis = xml->attributes().value("xAxis").toString().toInt(); int yAxis = xml->attributes().value("yAxis").toString().toInt(); if (stickIndex > 0 && xAxis > 0 && yAxis > 0) { xAxis -= 1; yAxis -= 1; stickIndex -= 1; for (int i=0; i <joystick_sets.size(); i++) { SetJoystick *currentset = joystick_sets.value(i); JoyAxis *axis1 = currentset->getJoyAxis(xAxis); JoyAxis *axis2 = currentset->getJoyAxis(yAxis); if (axis1 && axis2) { JoyControlStick *stick = new JoyControlStick(axis1, axis2, stickIndex, i, this); currentset->addControlStick(stickIndex, stick); } } xml->readNext(); } else { xml->skipCurrentElement(); } } else if (xml->name() == "vdpadButtonAssociations" && xml->isStartElement()) { int vdpadIndex = xml->attributes().value("index").toString().toInt(); if (vdpadIndex > 0) { for (int i=0; i <joystick_sets.size(); i++) { SetJoystick *currentset = joystick_sets.value(i); VDPad *vdpad = currentset->getVDPad(vdpadIndex-1); if (!vdpad) { vdpad = new VDPad(vdpadIndex-1, i, currentset); currentset->addVDPad(vdpadIndex-1, vdpad); } } xml->readNextStartElement(); while (!xml->atEnd() && (!xml->isEndElement() && xml->name() != "vdpadButtonAssociations")) { if (xml->name() == "vdpadButtonAssociation" && xml->isStartElement()) { int vdpadAxisIndex = xml->attributes().value("axis").toString().toInt(); int vdpadButtonIndex = xml->attributes().value("button").toString().toInt(); int vdpadDirection = xml->attributes().value("direction").toString().toInt(); if (vdpadAxisIndex > 0 && vdpadDirection > 0) { vdpadAxisIndex -= 1; for (int i=0; i < joystick_sets.size(); i++) { SetJoystick *currentset = joystick_sets.value(i); VDPad *vdpad = currentset->getVDPad(vdpadIndex-1); if (vdpad) { JoyAxis *axis = currentset->getJoyAxis(vdpadAxisIndex); if (axis) { JoyButton *button = 0; if (vdpadButtonIndex == 0) { button = axis->getNAxisButton(); } else if (vdpadButtonIndex == 1) { button = axis->getPAxisButton(); } if (button) { vdpad->addVButton((JoyDPadButton::JoyDPadDirections)vdpadDirection, button); } } } } } else if (vdpadButtonIndex > 0 && vdpadDirection > 0) { vdpadButtonIndex -= 1; for (int i=0; i < joystick_sets.size(); i++) { SetJoystick *currentset = joystick_sets.value(i); VDPad *vdpad = currentset->getVDPad(vdpadIndex-1); if (vdpad) { JoyButton *button = currentset->getJoyButton(vdpadButtonIndex); if (button) { vdpad->addVButton((JoyDPadButton::JoyDPadDirections)vdpadDirection, button); } } } } xml->readNext(); } else { xml->skipCurrentElement(); } xml->readNextStartElement(); } } for (int i=0; i < joystick_sets.size(); i++) { SetJoystick *currentset = joystick_sets.value(i); for (int j=0; j < currentset->getNumberVDPads(); j++) { VDPad *vdpad = currentset->getVDPad(j); if (vdpad && vdpad->isEmpty()) { currentset->removeVDPad(j); } } } } else if (xml->name() == "names" && xml->isStartElement()) { xml->readNextStartElement(); while (!xml->atEnd() && (!xml->isEndElement() && xml->name() != "names")) { if (xml->name() == "buttonname" && xml->isStartElement()) { int index = xml->attributes().value("index").toString().toInt(); QString temp = xml->readElementText(); index = index - 1; if (index >= 0 && !temp.isEmpty()) { setButtonName(index, temp); } } else if (xml->name() == "axisbuttonname" && xml->isStartElement()) { int index = xml->attributes().value("index").toString().toInt(); int buttonIndex = xml->attributes().value("button").toString().toInt(); QString temp = xml->readElementText(); index = index - 1; buttonIndex = buttonIndex - 1; if (index >= 0 && !temp.isEmpty()) { setAxisButtonName(index, buttonIndex, temp); } } else if (xml->name() == "controlstickbuttonname" && xml->isStartElement()) { int index = xml->attributes().value("index").toString().toInt(); int buttonIndex = xml->attributes().value("button").toString().toInt(); QString temp = xml->readElementText(); index = index - 1; if (index >= 0 && !temp.isEmpty()) { setStickButtonName(index, buttonIndex, temp); } } else if (xml->name() == "dpadbuttonname" && xml->isStartElement()) { int index = xml->attributes().value("index").toString().toInt(); int buttonIndex = xml->attributes().value("button").toString().toInt(); QString temp = xml->readElementText(); index = index - 1; if (index >= 0 && !temp.isEmpty()) { setDPadButtonName(index, buttonIndex, temp); } } else if (xml->name() == "vdpadbuttonname" && xml->isStartElement()) { int index = xml->attributes().value("index").toString().toInt(); int buttonIndex = xml->attributes().value("button").toString().toInt(); QString temp = xml->readElementText(); index = index - 1; if (index >= 0 && !temp.isEmpty()) { setVDPadButtonName(index, buttonIndex, temp); } } else if (xml->name() == "axisname" && xml->isStartElement()) { int index = xml->attributes().value("index").toString().toInt(); QString temp = xml->readElementText(); index = index - 1; if (index >= 0 && !temp.isEmpty()) { setAxisName(index, temp); } } else if (xml->name() == "controlstickname" && xml->isStartElement()) { int index = xml->attributes().value("index").toString().toInt(); QString temp = xml->readElementText(); index = index - 1; if (index >= 0 && !temp.isEmpty()) { setStickName(index, temp); } } else if (xml->name() == "dpadname" && xml->isStartElement()) { int index = xml->attributes().value("index").toString().toInt(); QString temp = xml->readElementText(); index = index - 1; if (index >= 0 && !temp.isEmpty()) { setDPadName(index, temp); } } else if (xml->name() == "vdpadname" && xml->isStartElement()) { int index = xml->attributes().value("index").toString().toInt(); QString temp = xml->readElementText(); index = index - 1; if (index >= 0 && !temp.isEmpty()) { setVDPadName(index, temp); } } else { // If none of the above, skip the element xml->skipCurrentElement(); } xml->readNextStartElement(); } } else if (xml->name() == "keyPressTime" && xml->isStartElement()) { QString temptext = xml->readElementText(); int tempchoice = temptext.toInt(); if (tempchoice >= 10) { this->setDeviceKeyDelay(tempchoice); } } else { // If none of the above, skip the element xml->skipCurrentElement(); } xml->readNextStartElement(); } } }
void GameController::writeConfig(QXmlStreamWriter *xml) { xml->writeStartElement(getXmlName()); xml->writeAttribute("configversion", QString::number(PadderCommon::LATESTCONFIGFILEVERSION)); xml->writeAttribute("appversion", PadderCommon::programVersion); xml->writeComment("The SDL name for a joystick is included for informational purposes only."); xml->writeTextElement("sdlname", getSDLName()); #ifdef USE_SDL_2 xml->writeComment("The GUID for a joystick is included for informational purposes only."); xml->writeTextElement("guid", getGUIDString()); #endif if (!profileName.isEmpty()) { xml->writeTextElement("profilename", profileName); } xml->writeStartElement("names"); // <names> SetJoystick *tempSet = getActiveSetJoystick(); for (int i=0; i < getNumberButtons(); i++) { JoyButton *button = tempSet->getJoyButton(i); if (button && !button->getButtonName().isEmpty()) { xml->writeStartElement("buttonname"); xml->writeAttribute("index", QString::number(button->getRealJoyNumber())); xml->writeCharacters(button->getButtonName()); xml->writeEndElement(); } } for (int i=0; i < getNumberAxes(); i++) { JoyAxis *axis = tempSet->getJoyAxis(i); if (axis) { if (!axis->getAxisName().isEmpty()) { xml->writeStartElement("axisname"); xml->writeAttribute("index", QString::number(axis->getRealJoyIndex())); xml->writeCharacters(axis->getAxisName()); xml->writeEndElement(); } JoyAxisButton *naxisbutton = axis->getNAxisButton(); if (!naxisbutton->getButtonName().isEmpty()) { xml->writeStartElement("axisbuttonname"); xml->writeAttribute("index", QString::number(axis->getRealJoyIndex())); xml->writeAttribute("button", QString::number(naxisbutton->getRealJoyNumber())); xml->writeCharacters(naxisbutton->getButtonName()); xml->writeEndElement(); } JoyAxisButton *paxisbutton = axis->getPAxisButton(); if (!paxisbutton->getButtonName().isEmpty()) { xml->writeStartElement("axisbuttonname"); xml->writeAttribute("index", QString::number(axis->getRealJoyIndex())); xml->writeAttribute("button", QString::number(paxisbutton->getRealJoyNumber())); xml->writeCharacters(paxisbutton->getButtonName()); xml->writeEndElement(); } } } for (int i=0; i < getNumberSticks(); i++) { JoyControlStick *stick = tempSet->getJoyStick(i); if (stick) { if (!stick->getStickName().isEmpty()) { xml->writeStartElement("controlstickname"); xml->writeAttribute("index", QString::number(stick->getRealJoyIndex())); xml->writeCharacters(stick->getStickName()); xml->writeEndElement(); } QHash<JoyControlStick::JoyStickDirections, JoyControlStickButton*> *buttons = stick->getButtons(); QHashIterator<JoyControlStick::JoyStickDirections, JoyControlStickButton*> iter(*buttons); while (iter.hasNext()) { JoyControlStickButton *button = iter.next().value(); if (button && !button->getButtonName().isEmpty()) { xml->writeStartElement("controlstickbuttonname"); xml->writeAttribute("index", QString::number(stick->getRealJoyIndex())); xml->writeAttribute("button", QString::number(button->getRealJoyNumber())); xml->writeCharacters(button->getButtonName()); xml->writeEndElement(); } } } } for (int i=0; i < getNumberVDPads(); i++) { VDPad *vdpad = getActiveSetJoystick()->getVDPad(i); if (vdpad) { if (!vdpad->getDpadName().isEmpty()) { xml->writeStartElement("dpadname"); xml->writeAttribute("index", QString::number(vdpad->getRealJoyNumber())); xml->writeCharacters(vdpad->getDpadName()); xml->writeEndElement(); } QHash<int, JoyDPadButton*> *temp = vdpad->getButtons(); QHashIterator<int, JoyDPadButton*> iter(*temp); while (iter.hasNext()) { JoyDPadButton *button = iter.next().value(); if (button && !button->getButtonName().isEmpty()) { xml->writeStartElement("dpadbutton"); xml->writeAttribute("index", QString::number(vdpad->getRealJoyNumber())); xml->writeAttribute("button", QString::number(button->getRealJoyNumber())); xml->writeCharacters(button->getButtonName()); xml->writeEndElement(); } } } } xml->writeEndElement(); // </names> if (keyPressTime > 0 && keyPressTime != DEFAULTKEYPRESSTIME) { xml->writeTextElement("keyPressTime", QString::number(keyPressTime)); } xml->writeStartElement("sets"); for (int i=0; i < joystick_sets.size(); i++) { joystick_sets.value(i)->writeConfig(xml); } xml->writeEndElement(); xml->writeEndElement(); }
void GameController::readJoystickConfig(QXmlStreamReader *xml) { if (xml->isStartElement() && xml->name() == "joystick") { //reset(); transferReset(); QHash<unsigned int, SDL_GameControllerButton> buttons; QHash<unsigned int, SDL_GameControllerAxis> axes; QList<SDL_GameControllerButtonBind> hatButtons; for (int i=(int)SDL_CONTROLLER_BUTTON_A; i < (int)SDL_CONTROLLER_BUTTON_MAX; i++) { SDL_GameControllerButton currentButton = (SDL_GameControllerButton)i; SDL_GameControllerButtonBind bound = SDL_GameControllerGetBindForButton(this->controller, currentButton); if (bound.bindType == SDL_CONTROLLER_BINDTYPE_BUTTON) { buttons.insert(bound.value.button, currentButton); } else if (bound.bindType == SDL_CONTROLLER_BINDTYPE_HAT) { hatButtons.append(bound); } } for (int i=(int)SDL_CONTROLLER_AXIS_LEFTX; i < (int)SDL_CONTROLLER_AXIS_MAX; i++) { SDL_GameControllerAxis currentAxis = (SDL_GameControllerAxis)i; SDL_GameControllerButtonBind bound = SDL_GameControllerGetBindForAxis(this->controller, currentAxis); if (bound.bindType == SDL_CONTROLLER_BINDTYPE_AXIS) { axes.insert(bound.value.axis, currentAxis); } } xml->readNextStartElement(); while (!xml->atEnd() && (!xml->isEndElement() && xml->name() != "joystick")) { if (xml->name() == "sets" && xml->isStartElement()) { xml->readNextStartElement(); while (!xml->atEnd() && (!xml->isEndElement() && xml->name() != "sets")) { if (xml->name() == "set" && xml->isStartElement()) { int index = xml->attributes().value("index").toString().toInt(); index = index - 1; if (index >= 0 && index < joystick_sets.size()) { GameControllerSet *currentSet = static_cast<GameControllerSet*>(joystick_sets.value(index)); currentSet->readJoystickConfig(xml, buttons, axes, hatButtons); } } else { // If none of the above, skip the element xml->skipCurrentElement(); } xml->readNextStartElement(); } } else if (xml->name() == "names" && xml->isStartElement()) { bool dpadNameExists = false; bool vdpadNameExists = false; xml->readNextStartElement(); while (!xml->atEnd() && (!xml->isEndElement() && xml->name() != "names")) { if (xml->name() == "buttonname" && xml->isStartElement()) { int index = xml->attributes().value("index").toString().toInt(); QString temp = xml->readElementText(); index = index - 1; if (index >= 0 && !temp.isEmpty()) { SDL_GameControllerButton current = buttons.value(index); if (current) { setButtonName(current, temp); } } } else if (xml->name() == "axisbuttonname" && xml->isStartElement()) { int index = xml->attributes().value("index").toString().toInt(); int buttonIndex = xml->attributes().value("button").toString().toInt(); QString temp = xml->readElementText(); index = index - 1; buttonIndex = buttonIndex - 1; if (index >= 0 && !temp.isEmpty()) { SDL_GameControllerAxis current = axes.value(index); if (current) { if (current == SDL_CONTROLLER_AXIS_LEFTX) { setStickButtonName(0, buttonIndex, temp); } else if (current == SDL_CONTROLLER_AXIS_LEFTY) { setStickButtonName(0, buttonIndex, temp); } else if (current == SDL_CONTROLLER_AXIS_RIGHTX) { setStickButtonName(1, buttonIndex, temp); } else if (current == SDL_CONTROLLER_AXIS_RIGHTY) { setStickButtonName(1, buttonIndex, temp); } else if (current == SDL_CONTROLLER_AXIS_TRIGGERLEFT) { setAxisName(current, temp); } else if (current == SDL_CONTROLLER_AXIS_TRIGGERRIGHT) { setAxisName(current, temp); } } } } else if (xml->name() == "controlstickbuttonname" && xml->isStartElement()) { int index = xml->attributes().value("index").toString().toInt(); int buttonIndex = xml->attributes().value("button").toString().toInt(); QString temp = xml->readElementText(); index = index - 1; if (index >= 0 && !temp.isEmpty()) { setStickButtonName(index, buttonIndex, temp); } } else if (xml->name() == "dpadbuttonname" && xml->isStartElement()) { int index = xml->attributes().value("index").toString().toInt(); int buttonIndex = xml->attributes().value("button").toString().toInt(); QString temp = xml->readElementText(); index = index - 1; if (index >= 0 && !temp.isEmpty()) { bool found = false; QListIterator<SDL_GameControllerButtonBind> iter(hatButtons); SDL_GameControllerButtonBind current; while (iter.hasNext()) { current = iter.next(); if (current.value.hat.hat == index) { found = true; iter.toBack(); } } if (found) { VDPad *dpad = getActiveSetJoystick()->getVDPad(0); if (dpad) { JoyDPadButton *dpadbutton = dpad->getJoyButton(buttonIndex); if (dpad && dpadbutton->getActionName().isEmpty()) { setVDPadButtonName(index, buttonIndex, temp); } } } } } else if (xml->name() == "vdpadbuttonname" && xml->isStartElement()) { int index = xml->attributes().value("index").toString().toInt(); int buttonIndex = xml->attributes().value("button").toString().toInt(); QString temp = xml->readElementText(); index = index - 1; if (index >= 0 && !temp.isEmpty()) { bool found = false; QListIterator<SDL_GameControllerButtonBind> iter(hatButtons); SDL_GameControllerButtonBind current; while (iter.hasNext()) { current = iter.next(); if (current.value.hat.hat == index) { found = true; iter.toBack(); } } if (found) { VDPad *dpad = getActiveSetJoystick()->getVDPad(0); if (dpad) { JoyDPadButton *dpadbutton = dpad->getJoyButton(buttonIndex); if (dpad && dpadbutton->getActionName().isEmpty()) { setVDPadButtonName(index, buttonIndex, temp); } } } } } else if (xml->name() == "axisname" && xml->isStartElement()) { int index = xml->attributes().value("index").toString().toInt(); QString temp = xml->readElementText(); index = index - 1; if (index >= 0 && !temp.isEmpty()) { if (axes.contains(index)) { SDL_GameControllerAxis current = axes.value(index); setAxisName((int)current, temp); } } } else if (xml->name() == "controlstickname" && xml->isStartElement()) { int index = xml->attributes().value("index").toString().toInt(); QString temp = xml->readElementText(); index = index - 1; if (index >= 0 && !temp.isEmpty()) { setStickName(index, temp); } } else if (xml->name() == "dpadname" && xml->isStartElement()) { int index = xml->attributes().value("index").toString().toInt(); QString temp = xml->readElementText(); index = index - 1; if (index >= 0 && !temp.isEmpty() && !vdpadNameExists) { bool found = false; QListIterator<SDL_GameControllerButtonBind> iter(hatButtons); SDL_GameControllerButtonBind current; while (iter.hasNext()) { current = iter.next(); if (current.value.hat.hat == index) { found = true; iter.toBack(); } } if (found) { dpadNameExists = true; VDPad *dpad = getActiveSetJoystick()->getVDPad(0); if (dpad) { if (dpad->getDpadName().isEmpty()) { setVDPadName(index, temp); } } } } } else if (xml->name() == "vdpadname" && xml->isStartElement()) { int index = xml->attributes().value("index").toString().toInt(); QString temp = xml->readElementText(); index = index - 1; if (index >= 0 && !temp.isEmpty() && !dpadNameExists) { bool found = false; QListIterator<SDL_GameControllerButtonBind> iter(hatButtons); SDL_GameControllerButtonBind current; while (iter.hasNext()) { current = iter.next(); if (current.value.hat.hat == index) { found = true; iter.toBack(); } } if (found) { vdpadNameExists = true; VDPad *dpad = getActiveSetJoystick()->getVDPad(0); if (dpad) { if (dpad->getDpadName().isEmpty()) { setVDPadName(index, temp); } } } } } else { // If none of the above, skip the element xml->skipCurrentElement(); } xml->readNextStartElement(); } } else if (xml->name() == "keyPressTime" && xml->isStartElement()) { QString temptext = xml->readElementText(); int tempchoice = temptext.toInt(); if (tempchoice >= 10) { this->setDeviceKeyPressTime(tempchoice); } } else if (xml->name() == "profilename" && xml->isStartElement()) { QString temptext = xml->readElementText(); this->setProfileName(temptext); } else { // If none of the above, skip the element xml->skipCurrentElement(); } xml->readNextStartElement(); } reInitButtons(); } }