Skip to content

Commit

Permalink
Connect JoySensorButtons sensor GUI buttons
Browse files Browse the repository at this point in the history
The buttons from the last commit were just dummies. The move forward
with adding functionality, add a new JobButton type JoySensorButton
which connects the GUI button with the JoySensor object.
Add more boilerplate for the scaffold and connect QT signals/slots.
The buttons still do nothing yet.
  • Loading branch information
mmmaisel committed Apr 14, 2022
1 parent 69c3890 commit be7185e
Show file tree
Hide file tree
Showing 12 changed files with 438 additions and 44 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ set(antimicrox_SOURCES
src/joybuttontypes/joycontrolstickmodifierbutton.cpp
src/joybuttontypes/joydpadbutton.cpp
src/joybuttontypes/joygradientbutton.cpp
src/joybuttontypes/joysensorbutton.cpp
src/joycontrolstick.cpp
src/joycontrolstickbuttonpushbutton.cpp
src/joycontrolstickcontextmenu.cpp
Expand Down Expand Up @@ -297,6 +298,7 @@ set(antimicrox_HEADERS
src/joybuttontypes/joycontrolstickmodifierbutton.h
src/joybuttontypes/joydpadbutton.h
src/joybuttontypes/joygradientbutton.h
src/joybuttontypes/joysensorbutton.h
src/joycontrolstick.h
src/joycontrolstickbuttonpushbutton.h
src/joycontrolstickcontextmenu.h
Expand Down
40 changes: 28 additions & 12 deletions src/gui/joytabwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1822,6 +1822,18 @@ void JoyTabWidget::checkStickEmptyDisplay()
}
}

void JoyTabWidget::checkSensorEmptyDisplay()
{
SensorPushButtonGroup *group = qobject_cast<SensorPushButtonGroup *>(sender()); // static_cast
JoySensor *sensor = group->getSensor();
if ((sensor != nullptr) && !sensor->hasSlotsAssigned())
{
SetJoystick *currentSet = m_joystick->getActiveSetJoystick();
removeSetButtons(currentSet);
fillSetButtons(currentSet);
}
}

void JoyTabWidget::checkDPadButtonEmptyDisplay()
{
DPadPushButtonGroup *group = qobject_cast<DPadPushButtonGroup *>(sender()); // static_cast
Expand Down Expand Up @@ -2008,15 +2020,17 @@ void JoyTabWidget::fillSetButtons(SetJoystick *set)
}

QWidget *groupContainer = new QWidget(sensorGroup);
SensorPushButtonGroup *sensorButtonGroup =
new SensorPushButtonGroup(sensor, isKeypadUnlocked(), displayingNames, groupContainer);
/*if (hideEmptyButtons)
SensorPushButtonGroup *sensorButtonGroup = new SensorPushButtonGroup(
sensor, isKeypadUnlocked(), displayingNames, groupContainer);
if (hideEmptyButtons)
{
connect(stickButtonGroup, &StickPushButtonGroup::buttonSlotChanged, this,
&JoyTabWidget::checkStickEmptyDisplay);
connect(sensorButtonGroup,
&SensorPushButtonGroup::buttonSlotChanged, this,
&JoyTabWidget::checkStickEmptyDisplay);
}

connect(namesPushButton, &QPushButton::clicked, stickButtonGroup, &StickPushButtonGroup::toggleNameDisplay);*/
connect(namesPushButton, &QPushButton::clicked, sensorButtonGroup,
&SensorPushButtonGroup::toggleNameDisplay);

if (sensorGridColumn > 1)
{
Expand Down Expand Up @@ -2049,15 +2063,17 @@ void JoyTabWidget::fillSetButtons(SetJoystick *set)
}

QWidget *groupContainer = new QWidget(sensorGroup);
SensorPushButtonGroup *sensorButtonGroup =
new SensorPushButtonGroup(sensor, isKeypadUnlocked(), displayingNames, groupContainer);
/*if (hideEmptyButtons)
SensorPushButtonGroup *sensorButtonGroup = new SensorPushButtonGroup(
sensor, isKeypadUnlocked(), displayingNames, groupContainer);
if (hideEmptyButtons)
{
connect(stickButtonGroup, &StickPushButtonGroup::buttonSlotChanged, this,
&JoyTabWidget::checkStickEmptyDisplay);
connect(sensorButtonGroup,
&SensorPushButtonGroup::buttonSlotChanged, this,
&JoyTabWidget::checkSensorEmptyDisplay);
}

connect(namesPushButton, &QPushButton::clicked, stickButtonGroup, &StickPushButtonGroup::toggleNameDisplay);*/
connect(namesPushButton, &QPushButton::clicked, sensorButtonGroup,
&SensorPushButtonGroup::toggleNameDisplay);

if (sensorGridColumn > 1)
{
Expand Down
1 change: 1 addition & 0 deletions src/gui/joytabwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ class JoyTabWidget : public QWidget
void checkButtonDisplay();

void checkStickEmptyDisplay();
void checkSensorEmptyDisplay();
void checkDPadButtonEmptyDisplay();
void checkAxisButtonEmptyDisplay();
void checkButtonEmptyDisplay();
Expand Down
173 changes: 173 additions & 0 deletions src/joybuttontypes/joysensorbutton.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
/* antimicrox Gamepad to KB+M event mapper
* Copyright (C) 2022 Max Maisel <max.maisel@posteo.de>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#include "joysensorbutton.h"

#include "event.h"
#include "globalvariables.h"
#include "joysensor.h"
#include "joybutton.h"
#include "setjoystick.h"
#include "vdpad.h"

#include <cmath>

#include <QDebug>

JoySensorButton::JoySensorButton(JoySensor *sensor,
int index, int originset, SetJoystick *parentSet, QObject *parent)
: JoyGradientButton(index, originset, parentSet, parent),
m_sensor(sensor)
{
}

QString JoySensorButton::getPartialName(bool forceFullFormat, bool displayNames) const
{
QString temp = QString(m_sensor->getPartialName(forceFullFormat, displayNames));
temp.append(": ");

/* if (!buttonName.isEmpty() && displayNames)
{
if (forceFullFormat)
{
temp.append(tr("Button")).append(" ");
}
temp.append(buttonName);
} else if (!defaultButtonName.isEmpty() && displayNames)
{
if (forceFullFormat)
{
temp.append(tr("Button")).append(" ");
}
temp.append(defaultButtonName);
} else
{
QString buttontype = QString();
switch (m_index)
{
case 0:
buttontype = tr("Negative");
break;
case 1:
buttontype = tr("Positive");
break;
default:
buttontype = tr("Unknown");
break;
}
temp.append(tr("Button")).append(" ").append(buttontype);
}*/

return temp;
}

//QString JoyAxisButton::getXmlName() { return GlobalVariables::JoyAxisButton::xmlName; }

/*void JoyAxisButton::setChangeSetCondition(SetChangeCondition condition, bool passive, bool updateActiveString)
{
SetChangeCondition oldCondition = setSelectionCondition;
if ((condition != setSelectionCondition) && !passive)
{
if ((condition == SetChangeWhileHeld) || (condition == SetChangeTwoWay))
{
// Set new condition
emit setAssignmentChanged(m_index, m_axis->getIndex(), setSelection, condition);
} else if ((setSelectionCondition == SetChangeWhileHeld) || (setSelectionCondition == SetChangeTwoWay))
{
// Remove old condition
emit setAssignmentChanged(m_index, m_axis->getIndex(), setSelection, SetChangeDisabled);
}
setSelectionCondition = condition;
} else if (passive)
{
setSelectionCondition = condition;
}
if (setSelectionCondition == SetChangeDisabled)
{
setChangeSetSelection(-1);
}
if (setSelectionCondition != oldCondition)
{
if (updateActiveString)
{
buildActiveZoneSummaryString();
}
emit propertyUpdated();
}
}*/

/**
* @brief Get the distance that an element is away from its assigned
* dead zone
* @return Normalized distance away from dead zone
*/
//double JoyAxisButton::getDistanceFromDeadZone() { return m_axis->getDistanceFromDeadZone(); }

/**
* @brief Get the distance factor that should be used for mouse movement
* @return Distance factor that should be used for mouse movement
*/
//double JoyAxisButton::getMouseDistanceFromDeadZone() { return this->getDistanceFromDeadZone(); }

/**
* @brief Set the turbo mode that the button should use
* @param Mode that should be used
*/
/*void JoyAxisButton::setTurboMode(TurboMode mode)
{
if (isPartRealAxis())
{
currentTurboMode = mode;
}
}*/

/**
* @brief Check if button should be considered a part of a real controller
* axis. Needed for some dialogs so the program won't have to resort to
* type checking.
* @return Status of being part of a real controller axis
*/
bool JoySensorButton::isPartRealAxis() { return false; }

/*double JoyAxisButton::getAccelerationDistance() { return m_axis->getRawDistance(m_axis->getCurrentThrottledValue()); }
double JoyAxisButton::getLastAccelerationDistance() { return m_axis->getRawDistance(m_axis->getLastKnownThrottleValue()); }
double JoyAxisButton::getLastMouseDistanceFromDeadZone()
{
double distance = 0.0;
if (m_axis->getAxisButtonByValue(m_axis->getLastKnownThrottleValue()) == this)
{
distance = m_axis->getDistanceFromDeadZone(m_axis->getLastKnownThrottleValue());
}
return distance;
}*/

JoySensor *JoySensorButton::getSensor() const { return m_sensor; }
55 changes: 55 additions & 0 deletions src/joybuttontypes/joysensorbutton.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/* antimicrox Gamepad to KB+M event mapper
* Copyright (C) 2022 Max Maisel <max.maisel@posteo.de>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once

#include "joybuttontypes/joygradientbutton.h"
#include "logger.h"

class VDPad;
class SetJoystick;
class JoySensor;

class JoySensorButton : public JoyGradientButton
{
Q_OBJECT

public:
explicit JoySensorButton(JoySensor *sensor, int index, int originset, SetJoystick *parentSet, QObject *parent);

virtual QString getPartialName(bool forceFullFormat = false, bool displayNames = false) const;
/*virtual QString getXmlName();
virtual double getDistanceFromDeadZone();
virtual double getMouseDistanceFromDeadZone();
virtual double getLastMouseDistanceFromDeadZone();
virtual void setChangeSetCondition(SetChangeCondition condition, bool passive = false, bool updateActiveString = true);
virtual void setVDPad(VDPad *vdpad);
virtual void setTurboMode(TurboMode mode);*/
virtual bool isPartRealAxis();

/*virtual double getAccelerationDistance();
virtual double getLastAccelerationDistance();*/

JoySensor *getSensor() const;

signals:
void setAssignmentChanged(int current_button, int axis_index, int associated_set, int mode);

private:
JoySensor *m_sensor;
};
Loading

0 comments on commit be7185e

Please sign in to comment.