chore: ensure Consistent formatting of code across entire project

* Create basic config for clang-format

* Format source files using clang-format

* Add Github Action checking proper code formatting after every Pull request
This commit is contained in:
Paweł Kotiuk
2020-10-12 15:57:33 +02:00
committed by GitHub
parent 759d2e80c1
commit a0c7d84b8d
261 changed files with 13342 additions and 15466 deletions

14
.clang-format Normal file
View File

@@ -0,0 +1,14 @@
BasedOnStyle: LLVM
IndentWidth: 4
BreakBeforeBraces: Custom
ColumnLimit: 125
IndentPPDirectives: BeforeHash
BraceWrapping:
AfterEnum: true
AfterStruct: true
AfterClass: true
AfterControlStatement: true
AfterFunction: true
AfterUnion: true
BreakConstructorInitializersBeforeComma: true

20
.github/workflows/code_formatting.yml vendored Normal file
View File

@@ -0,0 +1,20 @@
name: Check code formatting
on: pull_request
jobs:
test:
# The type of runner that the job will run on
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Download tools
run: |
sudo apt-get update && sudo apt-get install clang-format-10
echo "Clang-format version"
clang-format --version
wget https://raw.githubusercontent.com/Sarcasm/run-clang-format/master/run-clang-format.py
chmod +x ./run-clang-format.py
- name: Test
run: ./run-clang-format.py -r src

View File

@@ -19,24 +19,24 @@
#include "aboutdialog.h" #include "aboutdialog.h"
#include "ui_aboutdialog.h" #include "ui_aboutdialog.h"
#include "messagehandler.h"
#include "common.h" #include "common.h"
#include "eventhandlerfactory.h" #include "eventhandlerfactory.h"
#include "messagehandler.h"
#include <SDL2/SDL_version.h>
#include <SDL2/SDL_gamecontroller.h> #include <SDL2/SDL_gamecontroller.h>
#include <SDL2/SDL_version.h>
#include <QtGlobal> #include <QDebug>
#include <QResource>
#include <QTextStream>
#include <QEvent> #include <QEvent>
#include <QFile> #include <QFile>
#include <QResource>
#include <QStringList> #include <QStringList>
#include <QDebug> #include <QTextStream>
#include <QtGlobal>
AboutDialog::AboutDialog(QWidget *parent) : AboutDialog::AboutDialog(QWidget *parent)
QDialog(parent), : QDialog(parent)
ui(new Ui::AboutDialog) , ui(new Ui::AboutDialog)
{ {
ui->setupUi(this); ui->setupUi(this);
@@ -107,7 +107,8 @@ void AboutDialog::changeEvent(QEvent *event)
{ {
qInstallMessageHandler(MessageHandler::myMessageOutput); qInstallMessageHandler(MessageHandler::myMessageOutput);
if (event->type() == QEvent::LanguageChange) retranslateUi(); if (event->type() == QEvent::LanguageChange)
retranslateUi();
QDialog::changeEvent(event); QDialog::changeEvent(event);
} }

View File

@@ -16,7 +16,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef ABOUTDIALOG_H #ifndef ABOUTDIALOG_H
#define ABOUTDIALOG_H #define ABOUTDIALOG_H
@@ -31,15 +30,15 @@ class AboutDialog;
class AboutDialog : public QDialog class AboutDialog : public QDialog
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit AboutDialog(QWidget *parent = nullptr); explicit AboutDialog(QWidget *parent = nullptr);
~AboutDialog(); ~AboutDialog();
private: private:
Ui::AboutDialog *ui; Ui::AboutDialog *ui;
protected: protected:
void fillInfoTextBrowser(); void fillInfoTextBrowser();
virtual void changeEvent(QEvent *event); virtual void changeEvent(QEvent *event);
void retranslateUi(); void retranslateUi();

View File

@@ -19,17 +19,17 @@
#include "addeditautoprofiledialog.h" #include "addeditautoprofiledialog.h"
#include "ui_addeditautoprofiledialog.h" #include "ui_addeditautoprofiledialog.h"
#include "messagehandler.h"
#include "autoprofileinfo.h"
#include "inputdevice.h"
#include "antimicrosettings.h" #include "antimicrosettings.h"
#include "autoprofileinfo.h"
#include "common.h" #include "common.h"
#include "inputdevice.h"
#include "messagehandler.h"
#ifdef WITH_X11 #ifdef WITH_X11
#include "unixcapturewindowutility.h" #include "capturedwindowinfodialog.h"
#include "capturedwindowinfodialog.h" #include "unixcapturewindowutility.h"
#include "x11extras.h" #include "x11extras.h"
#endif #endif
#include <QApplication> #include <QApplication>
#include <QDebug> #include <QDebug>
@@ -39,13 +39,11 @@
#include <QMessageBox> #include <QMessageBox>
#include <QThread> #include <QThread>
AddEditAutoProfileDialog::AddEditAutoProfileDialog(AutoProfileInfo *info, AntiMicroSettings *settings, AddEditAutoProfileDialog::AddEditAutoProfileDialog(AutoProfileInfo *info, AntiMicroSettings *settings,
QList<InputDevice*> *devices, QList<InputDevice *> *devices, QList<QString> &reservedUniques, bool edit,
QList<QString> &reservedUniques, bool edit, QWidget *parent) : QWidget *parent)
QDialog(parent), : QDialog(parent)
ui(new Ui::AddEditAutoProfileDialog) , ui(new Ui::AddEditAutoProfileDialog)
{ {
ui->setupUi(this); ui->setupUi(this);
@@ -61,8 +59,10 @@ AddEditAutoProfileDialog::AddEditAutoProfileDialog(AutoProfileInfo *info, AntiMi
this->originalWindowClass = info->getWindowClass(); this->originalWindowClass = info->getWindowClass();
this->originalWindowName = info->getWindowName(); this->originalWindowName = info->getWindowName();
if (info->isPartialState()) ui->setPartialCheckBox->setChecked(true); if (info->isPartialState())
else ui->setPartialCheckBox->setChecked(false); ui->setPartialCheckBox->setChecked(true);
else
ui->setPartialCheckBox->setChecked(false);
QListIterator<QString> iterUniques(reservedUniques); QListIterator<QString> iterUniques(reservedUniques);
@@ -70,36 +70,37 @@ AddEditAutoProfileDialog::AddEditAutoProfileDialog(AutoProfileInfo *info, AntiMi
{ {
QString uniqueID = iterUniques.next(); QString uniqueID = iterUniques.next();
if (!getReservedUniques().contains(uniqueID)) this->reservedUniques.append(uniqueID); if (!getReservedUniques().contains(uniqueID))
this->reservedUniques.append(uniqueID);
} }
ui->devicesComboBox->addItem("all"); ui->devicesComboBox->addItem("all");
QListIterator<InputDevice*> iter(*devices); QListIterator<InputDevice *> iter(*devices);
int found = -1; int found = -1;
int numItems = 1; int numItems = 1;
while (iter.hasNext()) while (iter.hasNext())
{
InputDevice *device = iter.next();
ui->devicesComboBox->addItem(device->getSDLName(), QVariant::fromValue<InputDevice *>(device));
if (device->getUniqueIDString() == info->getUniqueID())
found = numItems;
numItems++;
}
if (!info->getUniqueID().isEmpty() && (info->getUniqueID() != "all"))
{
if (found >= 0)
{ {
InputDevice *device = iter.next(); ui->devicesComboBox->setCurrentIndex(found);
ui->devicesComboBox->addItem(device->getSDLName(), QVariant::fromValue<InputDevice*>(device)); } else
if (device->getUniqueIDString() == info->getUniqueID()) found = numItems;
numItems++;
}
if (!info->getUniqueID().isEmpty() && (info->getUniqueID() != "all"))
{ {
if (found >= 0) ui->devicesComboBox->addItem(tr("Current (%1)").arg(info->getDeviceName()));
{ ui->devicesComboBox->setCurrentIndex(ui->devicesComboBox->count() - 1);
ui->devicesComboBox->setCurrentIndex(found);
}
else
{
ui->devicesComboBox->addItem(tr("Current (%1)").arg(info->getDeviceName()));
ui->devicesComboBox->setCurrentIndex(ui->devicesComboBox->count()-1);
}
} }
}
ui->profileLineEdit->setText(info->getProfileLocation()); ui->profileLineEdit->setText(info->getProfileLocation());
ui->applicationLineEdit->setText(info->getExe()); ui->applicationLineEdit->setText(info->getExe());
@@ -110,29 +111,29 @@ AddEditAutoProfileDialog::AddEditAutoProfileDialog(AutoProfileInfo *info, AntiMi
connect(ui->profileBrowsePushButton, &QPushButton::clicked, this, &AddEditAutoProfileDialog::openProfileBrowseDialog); connect(ui->profileBrowsePushButton, &QPushButton::clicked, this, &AddEditAutoProfileDialog::openProfileBrowseDialog);
connect(ui->applicationPushButton, &QPushButton::clicked, this, &AddEditAutoProfileDialog::openApplicationBrowseDialog); connect(ui->applicationPushButton, &QPushButton::clicked, this, &AddEditAutoProfileDialog::openApplicationBrowseDialog);
connect(ui->devicesComboBox, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this, &AddEditAutoProfileDialog::checkForReservedUniques); connect(ui->devicesComboBox, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this,
connect(ui->devicesComboBox, static_cast<void (QComboBox::*)(const QString&)>(&QComboBox::currentTextChanged), this, &AddEditAutoProfileDialog::checkDefaultCheckbox); &AddEditAutoProfileDialog::checkForReservedUniques);
connect(ui->devicesComboBox, static_cast<void (QComboBox::*)(const QString &)>(&QComboBox::currentTextChanged), this,
&AddEditAutoProfileDialog::checkDefaultCheckbox);
connect(ui->applicationLineEdit, &QLineEdit::textChanged, this, &AddEditAutoProfileDialog::checkForDefaultStatus); connect(ui->applicationLineEdit, &QLineEdit::textChanged, this, &AddEditAutoProfileDialog::checkForDefaultStatus);
connect(ui->winClassLineEdit, &QLineEdit::textChanged, this, &AddEditAutoProfileDialog::checkForDefaultStatus); connect(ui->winClassLineEdit, &QLineEdit::textChanged, this, &AddEditAutoProfileDialog::checkForDefaultStatus);
connect(ui->winNameLineEdit, &QLineEdit::textChanged, this, &AddEditAutoProfileDialog::checkForDefaultStatus); connect(ui->winNameLineEdit, &QLineEdit::textChanged, this, &AddEditAutoProfileDialog::checkForDefaultStatus);
connect(ui->detectWinPropsSelectWindowPushButton, &QPushButton::clicked, this, &AddEditAutoProfileDialog::showCaptureHelpWindow); connect(ui->detectWinPropsSelectWindowPushButton, &QPushButton::clicked, this,
&AddEditAutoProfileDialog::showCaptureHelpWindow);
connect(this, &AddEditAutoProfileDialog::accepted, this, &AddEditAutoProfileDialog::saveAutoProfileInformation); connect(this, &AddEditAutoProfileDialog::accepted, this, &AddEditAutoProfileDialog::saveAutoProfileInformation);
ui->asDefaultCheckBox->setChecked(info->isCurrentDefault()); ui->asDefaultCheckBox->setChecked(info->isCurrentDefault());
} }
// created for tests // created for tests
AddEditAutoProfileDialog::AddEditAutoProfileDialog(QWidget *parent) : AddEditAutoProfileDialog::AddEditAutoProfileDialog(QWidget *parent)
QDialog(parent), : QDialog(parent)
ui(new Ui::AddEditAutoProfileDialog) , ui(new Ui::AddEditAutoProfileDialog)
{ {
} }
AddEditAutoProfileDialog::~AddEditAutoProfileDialog() AddEditAutoProfileDialog::~AddEditAutoProfileDialog()
{ {
qInstallMessageHandler(MessageHandler::myMessageOutput); qInstallMessageHandler(MessageHandler::myMessageOutput);
@@ -140,18 +141,18 @@ AddEditAutoProfileDialog::~AddEditAutoProfileDialog()
delete ui; delete ui;
} }
void AddEditAutoProfileDialog::openProfileBrowseDialog() void AddEditAutoProfileDialog::openProfileBrowseDialog()
{ {
qInstallMessageHandler(MessageHandler::myMessageOutput); qInstallMessageHandler(MessageHandler::myMessageOutput);
QString lookupDir = PadderCommon::preferredProfileDir(settings); QString lookupDir = PadderCommon::preferredProfileDir(settings);
QString filename = QFileDialog::getOpenFileName(this, tr("Open Config"), lookupDir, QString("Config Files (*.amgp *.xml)")); QString filename =
QFileDialog::getOpenFileName(this, tr("Open Config"), lookupDir, QString("Config Files (*.amgp *.xml)"));
if (!filename.isNull() && !filename.isEmpty()) ui->profileLineEdit->setText(QDir::toNativeSeparators(filename)); if (!filename.isNull() && !filename.isEmpty())
ui->profileLineEdit->setText(QDir::toNativeSeparators(filename));
} }
void AddEditAutoProfileDialog::openApplicationBrowseDialog() void AddEditAutoProfileDialog::openApplicationBrowseDialog()
{ {
qInstallMessageHandler(MessageHandler::myMessageOutput); qInstallMessageHandler(MessageHandler::myMessageOutput);
@@ -162,19 +163,18 @@ void AddEditAutoProfileDialog::openApplicationBrowseDialog()
{ {
QFileInfo exe(filename); QFileInfo exe(filename);
if (exe.exists() && exe.isExecutable()) ui->applicationLineEdit->setText(filename); if (exe.exists() && exe.isExecutable())
ui->applicationLineEdit->setText(filename);
} }
} }
AutoProfileInfo *AddEditAutoProfileDialog::getAutoProfile() const
AutoProfileInfo* AddEditAutoProfileDialog::getAutoProfile() const
{ {
qInstallMessageHandler(MessageHandler::myMessageOutput); qInstallMessageHandler(MessageHandler::myMessageOutput);
return info; return info;
} }
void AddEditAutoProfileDialog::saveAutoProfileInformation() void AddEditAutoProfileDialog::saveAutoProfileInformation()
{ {
qInstallMessageHandler(MessageHandler::myMessageOutput); qInstallMessageHandler(MessageHandler::myMessageOutput);
@@ -182,7 +182,6 @@ void AddEditAutoProfileDialog::saveAutoProfileInformation()
info->setProfileLocation(ui->profileLineEdit->text()); info->setProfileLocation(ui->profileLineEdit->text());
int deviceIndex = ui->devicesComboBox->currentIndex(); int deviceIndex = ui->devicesComboBox->currentIndex();
if (deviceIndex > 0) if (deviceIndex > 0)
{ {
@@ -190,12 +189,11 @@ void AddEditAutoProfileDialog::saveAutoProfileInformation()
// not be changed. // not be changed.
if (!ui->devicesComboBox->itemData(deviceIndex, Qt::UserRole).isNull()) if (!ui->devicesComboBox->itemData(deviceIndex, Qt::UserRole).isNull())
{ {
InputDevice *device = ui->devicesComboBox->itemData(deviceIndex, Qt::UserRole).value<InputDevice*>(); InputDevice *device = ui->devicesComboBox->itemData(deviceIndex, Qt::UserRole).value<InputDevice *>();
info->setUniqueID(device->getUniqueIDString()); info->setUniqueID(device->getUniqueIDString());
info->setDeviceName(device->getSDLName()); info->setDeviceName(device->getSDLName());
} }
} } else
else
{ {
info->setUniqueID("all"); info->setUniqueID("all");
info->setDeviceName(""); info->setDeviceName("");
@@ -208,7 +206,6 @@ void AddEditAutoProfileDialog::saveAutoProfileInformation()
info->setPartialState(ui->setPartialCheckBox->isChecked()); info->setPartialState(ui->setPartialCheckBox->isChecked());
} }
void AddEditAutoProfileDialog::checkForReservedUniques(int index) void AddEditAutoProfileDialog::checkForReservedUniques(int index)
{ {
qInstallMessageHandler(MessageHandler::myMessageOutput); qInstallMessageHandler(MessageHandler::myMessageOutput);
@@ -220,21 +217,20 @@ void AddEditAutoProfileDialog::checkForReservedUniques(int index)
ui->asDefaultCheckBox->setChecked(false); ui->asDefaultCheckBox->setChecked(false);
ui->asDefaultCheckBox->setEnabled(false); ui->asDefaultCheckBox->setEnabled(false);
QMessageBox::warning(this, tr("Main Profile"), tr("Please use the main default profile selection.")); QMessageBox::warning(this, tr("Main Profile"), tr("Please use the main default profile selection."));
} } else if (!data.isNull() && getReservedUniques().contains(data.value<InputDevice *>()->getUniqueIDString()))
else if (!data.isNull() && getReservedUniques().contains(data.value<InputDevice*>()->getUniqueIDString()))
{ {
ui->asDefaultCheckBox->setChecked(false); ui->asDefaultCheckBox->setChecked(false);
ui->asDefaultCheckBox->setEnabled(false); ui->asDefaultCheckBox->setEnabled(false);
QMessageBox::warning(this, tr("Already selected"), tr("A different profile is already selected as the default for this device.")); QMessageBox::warning(this, tr("Already selected"),
} tr("A different profile is already selected as the default for this device."));
else } else
{ {
ui->asDefaultCheckBox->setEnabled(true); ui->asDefaultCheckBox->setEnabled(true);
QMessageBox::information(this, tr("Chosen Profile"), tr("The selection will be used instead\nof the all default profile option.")); QMessageBox::information(this, tr("Chosen Profile"),
tr("The selection will be used instead\nof the all default profile option."));
} }
} }
QString AddEditAutoProfileDialog::getOriginalUniqueID() const QString AddEditAutoProfileDialog::getOriginalUniqueID() const
{ {
qInstallMessageHandler(MessageHandler::myMessageOutput); qInstallMessageHandler(MessageHandler::myMessageOutput);
@@ -242,7 +238,6 @@ QString AddEditAutoProfileDialog::getOriginalUniqueID() const
return originalUniqueID; return originalUniqueID;
} }
QString AddEditAutoProfileDialog::getOriginalExe() const QString AddEditAutoProfileDialog::getOriginalExe() const
{ {
qInstallMessageHandler(MessageHandler::myMessageOutput); qInstallMessageHandler(MessageHandler::myMessageOutput);
@@ -264,14 +259,13 @@ QString AddEditAutoProfileDialog::getOriginalWindowName() const
return originalWindowName; return originalWindowName;
} }
/** /**
* @brief Display a simple message box and attempt to capture a window using the mouse * @brief Display a simple message box and attempt to capture a window using the mouse
*/ */
void AddEditAutoProfileDialog::showCaptureHelpWindow() void AddEditAutoProfileDialog::showCaptureHelpWindow()
{ {
qInstallMessageHandler(MessageHandler::myMessageOutput); qInstallMessageHandler(MessageHandler::myMessageOutput);
#ifdef WITH_X11 #ifdef WITH_X11
if (QApplication::platformName() == QStringLiteral("xcb")) if (QApplication::platformName() == QStringLiteral("xcb"))
{ {
@@ -289,27 +283,27 @@ void AddEditAutoProfileDialog::showCaptureHelpWindow()
connect(thread, &QThread::started, util, &UnixCaptureWindowUtility::attemptWindowCapture); connect(thread, &QThread::started, util, &UnixCaptureWindowUtility::attemptWindowCapture);
connect(util, &UnixCaptureWindowUtility::captureFinished, thread, &QThread::quit); connect(util, &UnixCaptureWindowUtility::captureFinished, thread, &QThread::quit);
connect(util, &UnixCaptureWindowUtility::captureFinished, box, &QMessageBox::hide); connect(util, &UnixCaptureWindowUtility::captureFinished, box, &QMessageBox::hide);
connect(util, &UnixCaptureWindowUtility::captureFinished, this, [this, util]() { connect(
checkForGrabbedWindow(util); util, &UnixCaptureWindowUtility::captureFinished, this, [this, util]() { checkForGrabbedWindow(util); },
}, Qt::QueuedConnection); Qt::QueuedConnection);
connect(thread, &QThread::finished, box, &QMessageBox::deleteLater); connect(thread, &QThread::finished, box, &QMessageBox::deleteLater);
connect(util, &UnixCaptureWindowUtility::destroyed, thread, &QThread::deleteLater); connect(util, &UnixCaptureWindowUtility::destroyed, thread, &QThread::deleteLater);
thread->start(); thread->start();
} }
#endif #endif
} }
/** /**
* @brief Check if there is a program path saved in an UnixCaptureWindowUtility * @brief Check if there is a program path saved in an UnixCaptureWindowUtility
* object * object
*/ */
void AddEditAutoProfileDialog::checkForGrabbedWindow(UnixCaptureWindowUtility* util) void AddEditAutoProfileDialog::checkForGrabbedWindow(UnixCaptureWindowUtility *util)
{ {
qInstallMessageHandler(MessageHandler::myMessageOutput); qInstallMessageHandler(MessageHandler::myMessageOutput);
#ifdef WITH_X11 #ifdef WITH_X11
if (QApplication::platformName() == QStringLiteral("xcb")) if (QApplication::platformName() == QStringLiteral("xcb"))
{ {
long targetWindow = util->getTargetWindow(); long targetWindow = util->getTargetWindow();
@@ -323,27 +317,22 @@ void AddEditAutoProfileDialog::checkForGrabbedWindow(UnixCaptureWindowUtility* u
qDebug() << "ORIGINAL: " << QString::number(targetWindow, 16); qDebug() << "ORIGINAL: " << QString::number(targetWindow, 16);
long tempWindow = X11Extras::getInstance()->findClientWindow(targetWindow); long tempWindow = X11Extras::getInstance()->findClientWindow(targetWindow);
if (tempWindow > 0) if (tempWindow > 0)
{ {
targetWindow = tempWindow; targetWindow = tempWindow;
} }
qDebug() << "ADJUSTED: " << QString::number(targetWindow, 16); qDebug() << "ADJUSTED: " << QString::number(targetWindow, 16);
} }
if (targetWindow != None) if (targetWindow != None)
{ {
CapturedWindowInfoDialog *dialog = new CapturedWindowInfoDialog(targetWindow, this); CapturedWindowInfoDialog *dialog = new CapturedWindowInfoDialog(targetWindow, this);
connect(dialog, &CapturedWindowInfoDialog::accepted, [this, dialog]() { connect(dialog, &CapturedWindowInfoDialog::accepted, [this, dialog]() { windowPropAssignment(dialog); });
windowPropAssignment(dialog);
});
dialog->show(); dialog->show();
} } else if (!escaped)
else if (!escaped)
{ {
failed = true; failed = true;
} }
@@ -362,10 +351,9 @@ void AddEditAutoProfileDialog::checkForGrabbedWindow(UnixCaptureWindowUtility* u
util->deleteLater(); util->deleteLater();
} }
#endif #endif
} }
void AddEditAutoProfileDialog::windowPropAssignment(CapturedWindowInfoDialog *dialog) void AddEditAutoProfileDialog::windowPropAssignment(CapturedWindowInfoDialog *dialog)
{ {
qInstallMessageHandler(MessageHandler::myMessageOutput); qInstallMessageHandler(MessageHandler::myMessageOutput);
@@ -374,16 +362,14 @@ void AddEditAutoProfileDialog::windowPropAssignment(CapturedWindowInfoDialog *di
disconnect(ui->winClassLineEdit, &QLineEdit::textChanged, this, &AddEditAutoProfileDialog::checkForDefaultStatus); disconnect(ui->winClassLineEdit, &QLineEdit::textChanged, this, &AddEditAutoProfileDialog::checkForDefaultStatus);
disconnect(ui->winNameLineEdit, &QLineEdit::textChanged, this, &AddEditAutoProfileDialog::checkForDefaultStatus); disconnect(ui->winNameLineEdit, &QLineEdit::textChanged, this, &AddEditAutoProfileDialog::checkForDefaultStatus);
#ifdef WITH_X11 #ifdef WITH_X11
if (dialog->useFullWindowPath() && dialog->getSelectedOptions() & CapturedWindowInfoDialog::WindowPath) if (dialog->useFullWindowPath() && dialog->getSelectedOptions() & CapturedWindowInfoDialog::WindowPath)
{ {
ui->applicationLineEdit->setText(dialog->getWindowPath()); ui->applicationLineEdit->setText(dialog->getWindowPath());
} } else if (!dialog->useFullWindowPath() && dialog->getSelectedOptions() & CapturedWindowInfoDialog::WindowPath)
else if (!dialog->useFullWindowPath() && dialog->getSelectedOptions() & CapturedWindowInfoDialog::WindowPath)
{ {
ui->applicationLineEdit->setText(QFileInfo(dialog->getWindowPath()).fileName()); ui->applicationLineEdit->setText(QFileInfo(dialog->getWindowPath()).fileName());
} } else
else
{ {
#endif #endif
ui->applicationLineEdit->clear(); ui->applicationLineEdit->clear();
@@ -391,27 +377,25 @@ void AddEditAutoProfileDialog::windowPropAssignment(CapturedWindowInfoDialog *di
} }
#endif #endif
#ifdef WITH_X11 #ifdef WITH_X11
if (dialog->getSelectedOptions() & CapturedWindowInfoDialog::WindowClass) if (dialog->getSelectedOptions() & CapturedWindowInfoDialog::WindowClass)
{ {
ui->winClassLineEdit->setText(dialog->getWindowClass()); ui->winClassLineEdit->setText(dialog->getWindowClass());
} } else
else
{ {
#endif #endif
ui->winClassLineEdit->clear(); ui->winClassLineEdit->clear();
#ifdef WITH_X11 #ifdef WITH_X11
} }
#endif #endif
#ifdef WITH_X11 #ifdef WITH_X11
if (dialog->getSelectedOptions() & CapturedWindowInfoDialog::WindowName) if (dialog->getSelectedOptions() & CapturedWindowInfoDialog::WindowName)
{ {
ui->winNameLineEdit->setText(dialog->getWindowName()); ui->winNameLineEdit->setText(dialog->getWindowName());
} } else
else
{ {
#endif #endif
ui->winNameLineEdit->clear(); ui->winNameLineEdit->clear();
#ifdef WITH_X11 #ifdef WITH_X11
} }
@@ -424,7 +408,6 @@ void AddEditAutoProfileDialog::windowPropAssignment(CapturedWindowInfoDialog *di
connect(ui->winNameLineEdit, &QLineEdit::textChanged, this, &AddEditAutoProfileDialog::checkForDefaultStatus); connect(ui->winNameLineEdit, &QLineEdit::textChanged, this, &AddEditAutoProfileDialog::checkForDefaultStatus);
} }
void AddEditAutoProfileDialog::checkForDefaultStatus() void AddEditAutoProfileDialog::checkForDefaultStatus()
{ {
qInstallMessageHandler(MessageHandler::myMessageOutput); qInstallMessageHandler(MessageHandler::myMessageOutput);
@@ -437,8 +420,7 @@ void AddEditAutoProfileDialog::checkForDefaultStatus()
{ {
ui->asDefaultCheckBox->setChecked(false); ui->asDefaultCheckBox->setChecked(false);
ui->asDefaultCheckBox->setEnabled(false); ui->asDefaultCheckBox->setEnabled(false);
} } else
else
{ {
ui->asDefaultCheckBox->setEnabled(true); ui->asDefaultCheckBox->setEnabled(true);
} }
@@ -466,15 +448,12 @@ void AddEditAutoProfileDialog::accept()
} }
} }
if (validForm && if (validForm && (ui->applicationLineEdit->text().isEmpty() && ui->winClassLineEdit->text().isEmpty() &&
(ui->applicationLineEdit->text().isEmpty() && ui->winNameLineEdit->text().isEmpty()))
ui->winClassLineEdit->text().isEmpty() &&
ui->winNameLineEdit->text().isEmpty()))
{ {
validForm = false; validForm = false;
errorString = tr("No window matching property was specified."); errorString = tr("No window matching property was specified.");
} } else
else
{ {
propertyFound = true; propertyFound = true;
} }
@@ -500,8 +479,7 @@ void AddEditAutoProfileDialog::accept()
if (validForm) if (validForm)
{ {
QDialog::accept(); QDialog::accept();
} } else
else
{ {
QMessageBox msgBox; QMessageBox msgBox;
msgBox.setText(errorString); msgBox.setText(errorString);
@@ -510,46 +488,31 @@ void AddEditAutoProfileDialog::accept()
} }
} }
QList<InputDevice *> *AddEditAutoProfileDialog::getDevices() const { return devices; }
QList<InputDevice*> *AddEditAutoProfileDialog::getDevices() const { AntiMicroSettings *AddEditAutoProfileDialog::getSettings() const { return settings; }
return devices; bool AddEditAutoProfileDialog::getEditForm() const { return editForm; }
}
AntiMicroSettings *AddEditAutoProfileDialog::getSettings() const { bool AddEditAutoProfileDialog::getDefaultInfo() const { return defaultInfo; }
return settings; QList<QString> const &AddEditAutoProfileDialog::getReservedUniques() { return reservedUniques; }
}
bool AddEditAutoProfileDialog::getEditForm() const {
return editForm;
}
bool AddEditAutoProfileDialog::getDefaultInfo() const {
return defaultInfo;
}
QList<QString> const& AddEditAutoProfileDialog::getReservedUniques() {
return reservedUniques;
}
void AddEditAutoProfileDialog::on_setPartialCheckBox_stateChanged(int arg1) void AddEditAutoProfileDialog::on_setPartialCheckBox_stateChanged(int arg1)
{ {
if (arg1 == 0) ui->winNameLineEdit->setEnabled(false); if (arg1 == 0)
else ui->winNameLineEdit->setEnabled(true); ui->winNameLineEdit->setEnabled(false);
else
ui->winNameLineEdit->setEnabled(true);
} }
void AddEditAutoProfileDialog::checkDefaultCheckbox(const QString& text) void AddEditAutoProfileDialog::checkDefaultCheckbox(const QString &text)
{ {
if (text == "all") if (text == "all")
{ {
ui->asDefaultCheckBox->setChecked(false); ui->asDefaultCheckBox->setChecked(false);
ui->asDefaultCheckBox->setDisabled(true); ui->asDefaultCheckBox->setDisabled(true);
} } else
else
{ {
ui->asDefaultCheckBox->setDisabled(false); ui->asDefaultCheckBox->setDisabled(false);
} }

View File

@@ -16,7 +16,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef ADDEDITAUTOPROFILEDIALOG_H #ifndef ADDEDITAUTOPROFILEDIALOG_H
#define ADDEDITAUTOPROFILEDIALOG_H #define ADDEDITAUTOPROFILEDIALOG_H
@@ -36,35 +35,33 @@ class AddEditAutoProfileDialog : public QDialog
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit AddEditAutoProfileDialog(AutoProfileInfo *info, AntiMicroSettings *settings, QList<InputDevice*> *devices, explicit AddEditAutoProfileDialog(AutoProfileInfo *info, AntiMicroSettings *settings, QList<InputDevice *> *devices,
QList<QString> &reservedUniques, QList<QString> &reservedUniques, bool edit = false, QWidget *parent = nullptr);
bool edit=false, QWidget *parent = nullptr);
AddEditAutoProfileDialog(QWidget *parent = nullptr); AddEditAutoProfileDialog(QWidget *parent = nullptr);
~AddEditAutoProfileDialog(); ~AddEditAutoProfileDialog();
AutoProfileInfo* getAutoProfile() const; AutoProfileInfo *getAutoProfile() const;
QString getOriginalUniqueID() const; QString getOriginalUniqueID() const;
QString getOriginalExe() const; QString getOriginalExe() const;
QString getOriginalWindowClass() const; QString getOriginalWindowClass() const;
QString getOriginalWindowName() const; QString getOriginalWindowName() const;
QList<InputDevice*> *getDevices() const; QList<InputDevice *> *getDevices() const;
AntiMicroSettings *getSettings() const; AntiMicroSettings *getSettings() const;
bool getEditForm() const; bool getEditForm() const;
bool getDefaultInfo() const; bool getDefaultInfo() const;
QList<QString> const& getReservedUniques(); QList<QString> const &getReservedUniques();
protected:
protected:
virtual void accept(); virtual void accept();
signals: signals:
void captureFinished(); void captureFinished();
private slots: private slots:
void openProfileBrowseDialog(); void openProfileBrowseDialog();
void openApplicationBrowseDialog(); void openApplicationBrowseDialog();
void saveAutoProfileInformation(); void saveAutoProfileInformation();
@@ -72,15 +69,15 @@ private slots:
void checkForDefaultStatus(); void checkForDefaultStatus();
void windowPropAssignment(CapturedWindowInfoDialog *dialog); void windowPropAssignment(CapturedWindowInfoDialog *dialog);
void showCaptureHelpWindow(); void showCaptureHelpWindow();
void checkForGrabbedWindow(UnixCaptureWindowUtility* util); void checkForGrabbedWindow(UnixCaptureWindowUtility *util);
void on_setPartialCheckBox_stateChanged(int arg1); void on_setPartialCheckBox_stateChanged(int arg1);
void checkDefaultCheckbox(const QString& text); void checkDefaultCheckbox(const QString &text);
private: private:
Ui::AddEditAutoProfileDialog *ui; Ui::AddEditAutoProfileDialog *ui;
AutoProfileInfo *info; AutoProfileInfo *info;
QList<InputDevice*> *devices; QList<InputDevice *> *devices;
AntiMicroSettings *settings; AntiMicroSettings *settings;
bool editForm; bool editForm;
bool defaultInfo; bool defaultInfo;
@@ -89,7 +86,6 @@ private:
QString originalExe; QString originalExe;
QString originalWindowClass; QString originalWindowClass;
QString originalWindowName; QString originalWindowName;
}; };
#endif // ADDEDITAUTOPROFILEDIALOG_H #endif // ADDEDITAUTOPROFILEDIALOG_H

View File

File diff suppressed because it is too large Load Diff

View File

@@ -16,11 +16,9 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef ADVANCEBUTTONDIALOG_H #ifndef ADVANCEBUTTONDIALOG_H
#define ADVANCEBUTTONDIALOG_H #define ADVANCEBUTTONDIALOG_H
#include "uihelpers/advancebuttondialoghelper.h" #include "uihelpers/advancebuttondialoghelper.h"
#include <QDialog> #include <QDialog>
@@ -37,90 +35,100 @@ class AdvanceButtonDialog;
class AdvanceButtonDialog : public QDialog class AdvanceButtonDialog : public QDialog
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit AdvanceButtonDialog(JoyButton *button, QWidget *parent=0); explicit AdvanceButtonDialog(JoyButton *button, QWidget *parent = 0);
AdvanceButtonDialog(QWidget *parent=0); AdvanceButtonDialog(QWidget *parent = 0);
~AdvanceButtonDialog(); ~AdvanceButtonDialog();
int getOldRow() const; int getOldRow() const;
JoyButton *getButton() const; JoyButton *getButton() const;
AdvanceButtonDialogHelper const& getHelper(); AdvanceButtonDialogHelper const &getHelper();
protected: protected:
void connectButtonEvents(SimpleKeyGrabberButton *button); // AdvanceBtnDlgAssign class void connectButtonEvents(SimpleKeyGrabberButton *button); // AdvanceBtnDlgAssign class
void appendBlankKeyGrabber(); // AdvanceBtnDlgAssign class void appendBlankKeyGrabber(); // AdvanceBtnDlgAssign class
int actionTimeConvert(); // AdvanceBtnDlgAssign class int actionTimeConvert(); // AdvanceBtnDlgAssign class
void changeTurboForSequences(); void changeTurboForSequences();
void fillTimeComboBoxes(); // AdvanceBtnDlgAssign class void fillTimeComboBoxes(); // AdvanceBtnDlgAssign class
void refreshTimeComboBoxes(JoyButtonSlot *slot); // AdvanceBtnDlgAssign class void refreshTimeComboBoxes(JoyButtonSlot *slot); // AdvanceBtnDlgAssign class
void updateWindowTitleButtonName(); // AdvanceBtnDlgAssign class void updateWindowTitleButtonName(); // AdvanceBtnDlgAssign class
void populateAutoResetInterval(); // AdvanceBtnDlgAssign class void populateAutoResetInterval(); // AdvanceBtnDlgAssign class
void disconnectTimeBoxesEvents(); // AdvanceBtnDlgAssign class void disconnectTimeBoxesEvents(); // AdvanceBtnDlgAssign class
void connectTimeBoxesEvents(); // AdvanceBtnDlgAssign class void connectTimeBoxesEvents(); // AdvanceBtnDlgAssign class
void resetTimeBoxes(); // AdvanceBtnDlgAssign class void resetTimeBoxes(); // AdvanceBtnDlgAssign class
void populateSetSelectionComboBox(); void populateSetSelectionComboBox();
void populateSlotSetSelectionComboBox(); void populateSlotSetSelectionComboBox();
void findTurboModeComboIndex(); void findTurboModeComboIndex();
void showSelectProfileWind(QListWidgetItem* item, QString& firstChoiceProfile); void showSelectProfileWind(QListWidgetItem *item, QString &firstChoiceProfile);
bool anySelectedNotKeybSlot(); bool anySelectedNotKeybSlot();
bool selectedNotMixSlot(); bool selectedNotMixSlot();
signals: signals:
void toggleChanged(bool state); void toggleChanged(bool state);
void turboChanged(bool state); void turboChanged(bool state);
void slotsChanged(); // AdvanceBtnDlgAssign class void slotsChanged(); // AdvanceBtnDlgAssign class
void turboButtonEnabledChange(bool state); void turboButtonEnabledChange(bool state);
public slots: public slots:
void placeNewSlot(JoyButtonSlot *slot); // AdvanceBtnDlgAssign class void placeNewSlot(JoyButtonSlot *slot); // AdvanceBtnDlgAssign class
void clearAllSlots(); // AdvanceBtnDlgAssign class void clearAllSlots(); // AdvanceBtnDlgAssign class
private slots: private slots:
void changeTurboText(int value); void changeTurboText(int value);
void updateTurboIntervalValue(int value); void updateTurboIntervalValue(int value);
void checkTurboSetting(bool state); void checkTurboSetting(bool state);
void updateSlotsScrollArea(int value); // AdvanceBtnDlgAssign class void updateSlotsScrollArea(int value); // AdvanceBtnDlgAssign class
void deleteSlot(bool showWarning = true); // AdvanceBtnDlgAssign class void deleteSlot(bool showWarning = true); // AdvanceBtnDlgAssign class
void insertSlot(); // AdvanceBtnDlgAssign class void insertSlot(); // AdvanceBtnDlgAssign class
void joinSlot(); // AdvanceBtnDlgAssign class void joinSlot(); // AdvanceBtnDlgAssign class
void splitSlot(); // AdvanceBtnDlgAssign class void splitSlot(); // AdvanceBtnDlgAssign class
void insertCycleSlot(QListWidgetItem* item); // AdvanceBtnDlgAssign class void insertCycleSlot(QListWidgetItem *item); // AdvanceBtnDlgAssign class
void insertTextEntrySlot(QListWidgetItem* item); // AdvanceBtnDlgAssign class void insertTextEntrySlot(QListWidgetItem *item); // AdvanceBtnDlgAssign class
void insertExecuteSlot(QListWidgetItem* item, QStringList& prevExecAndArgs); // AdvanceBtnDlgAssign class void insertExecuteSlot(QListWidgetItem *item, QStringList &prevExecAndArgs); // AdvanceBtnDlgAssign class
void updateActionTimeLabel(); void updateActionTimeLabel();
void updateSetSelection(); void updateSetSelection();
void checkTurboIntervalValue(int value); void checkTurboIntervalValue(int value);
void performStatsWidgetRefresh(QListWidgetItem *item); void performStatsWidgetRefresh(QListWidgetItem *item);
void checkSlotTimeUpdate(); // AdvanceBtnDlgAssign class void checkSlotTimeUpdate(); // AdvanceBtnDlgAssign class
void checkSlotMouseModUpdate(); // AdvanceBtnDlgAssign class void checkSlotMouseModUpdate(); // AdvanceBtnDlgAssign class
void checkSlotDistanceUpdate(); // AdvanceBtnDlgAssign class void checkSlotDistanceUpdate(); // AdvanceBtnDlgAssign class
void checkSlotSetChangeUpdate(); // AdvanceBtnDlgAssign class void checkSlotSetChangeUpdate(); // AdvanceBtnDlgAssign class
void checkCycleResetWidgetStatus(bool enabled); // AdvanceBtnDlgAssign class void checkCycleResetWidgetStatus(bool enabled); // AdvanceBtnDlgAssign class
void setButtonCycleResetInterval(double value); // AdvanceBtnDlgAssign class void setButtonCycleResetInterval(double value); // AdvanceBtnDlgAssign class
void setButtonCycleReset(bool enabled); // AdvanceBtnDlgAssign class void setButtonCycleReset(bool enabled); // AdvanceBtnDlgAssign class
void setButtonTurboMode(int value); void setButtonTurboMode(int value);
void showSelectProfileWindow(); void showSelectProfileWindow();
void showFindExecutableWindow(bool); // AdvanceBtnDlgAssign class void showFindExecutableWindow(bool); // AdvanceBtnDlgAssign class
void changeSlotTypeDisplay(int index); // AdvanceBtnDlgAssign class void changeSlotTypeDisplay(int index); // AdvanceBtnDlgAssign class
void changeSlotHelpText(int index); // AdvanceBtnDlgAssign class void changeSlotHelpText(int index); // AdvanceBtnDlgAssign class
private:
private:
Ui::AdvanceButtonDialog *ui; Ui::AdvanceButtonDialog *ui;
AdvanceButtonDialogHelper& getHelperLocal(); AdvanceButtonDialogHelper &getHelperLocal();
enum SlotTypeComboIndex { enum SlotTypeComboIndex
KBMouseSlot = 0, CycleSlot, DelaySlot, DistanceSlot, ExecuteSlot, {
HoldSlot, LoadSlot, MouseModSlot, PauseSlot, PressTimeSlot, KBMouseSlot = 0,
ReleaseSlot, SetChangeSlot, TextEntry CycleSlot,
DelaySlot,
DistanceSlot,
ExecuteSlot,
HoldSlot,
LoadSlot,
MouseModSlot,
PauseSlot,
PressTimeSlot,
ReleaseSlot,
SetChangeSlot,
TextEntry
}; };
int oldRow; int oldRow;
@@ -128,8 +136,8 @@ private:
AdvanceButtonDialogHelper helper; AdvanceButtonDialogHelper helper;
QReadWriteLock joinLock; QReadWriteLock joinLock;
void insertKindOfSlot(QListWidgetItem* item, int slotProperty, JoyButtonSlot::JoySlotInputAction inputAction); // AdvanceBtnDlgAssign class void insertKindOfSlot(QListWidgetItem *item, int slotProperty,
JoyButtonSlot::JoySlotInputAction inputAction); // AdvanceBtnDlgAssign class
}; };
#endif // ADVANCEBUTTONDIALOG_H #endif // ADVANCEBUTTONDIALOG_H

View File

File diff suppressed because it is too large Load Diff

View File

@@ -16,7 +16,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef ADVANCESTICKASSIGNMENTDIALOG_H #ifndef ADVANCESTICKASSIGNMENTDIALOG_H
#define ADVANCESTICKASSIGNMENTDIALOG_H #define ADVANCESTICKASSIGNMENTDIALOG_H
@@ -36,25 +35,24 @@ class AdvanceStickAssignmentDialog;
class AdvanceStickAssignmentDialog : public QDialog class AdvanceStickAssignmentDialog : public QDialog
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit AdvanceStickAssignmentDialog(Joystick *joystick, QWidget *parent = nullptr); explicit AdvanceStickAssignmentDialog(Joystick *joystick, QWidget *parent = nullptr);
AdvanceStickAssignmentDialog(QWidget *parent = nullptr); AdvanceStickAssignmentDialog(QWidget *parent = nullptr);
~AdvanceStickAssignmentDialog(); ~AdvanceStickAssignmentDialog();
Joystick *getJoystick() const; Joystick *getJoystick() const;
signals: signals:
void stickConfigurationChanged(); void stickConfigurationChanged();
void vdpadConfigurationChanged(); void vdpadConfigurationChanged();
private slots: private slots:
void refreshStickConfiguration(JoyControlStick *stick1, JoyControlStick *stick2); void refreshStickConfiguration(JoyControlStick *stick1, JoyControlStick *stick2);
void refreshVDPadsConfiguration(); void refreshVDPadsConfiguration();
void checkForAxisAssignmentStickOne(QWidget* comboBox); void checkForAxisAssignmentStickOne(QWidget *comboBox);
void checkForAxisAssignmentStickTwo(QWidget* comboBox); void checkForAxisAssignmentStickTwo(QWidget *comboBox);
void changeStateStickOneWidgets(bool enabled); void changeStateStickOneWidgets(bool enabled);
void changeStateStickTwoWidgets(bool enabled); void changeStateStickTwoWidgets(bool enabled);
@@ -78,25 +76,27 @@ private slots:
void openAssignVDPadLeft(); void openAssignVDPadLeft();
void openAssignVDPadRight(); void openAssignVDPadRight();
void quickAssignVDPadUp(JoyAxisButton* joyaxisbtn); void quickAssignVDPadUp(JoyAxisButton *joyaxisbtn);
void quickAssignVDPadUpBtn(JoyButton* joybtn); void quickAssignVDPadUpBtn(JoyButton *joybtn);
void quickAssignVDPadDown(JoyAxisButton* axbtn); void quickAssignVDPadDown(JoyAxisButton *axbtn);
void quickAssignVDPadDownJbtn(JoyButton* axbtn); void quickAssignVDPadDownJbtn(JoyButton *axbtn);
void quickAssignVDPadLeft(JoyAxisButton* joyaxisbtn); void quickAssignVDPadLeft(JoyAxisButton *joyaxisbtn);
void quickAssignVDPadLeftJbtn(JoyButton* joybtn); void quickAssignVDPadLeftJbtn(JoyButton *joybtn);
void quickAssignVDPadRight(JoyAxisButton* joyaxisbtn); void quickAssignVDPadRight(JoyAxisButton *joyaxisbtn);
void quickAssignVDPadRightJbtn(JoyButton* joybtn); void quickAssignVDPadRightJbtn(JoyButton *joybtn);
void reenableButtonEvents(); void reenableButtonEvents();
private: private:
Ui::AdvanceStickAssignmentDialog *ui; Ui::AdvanceStickAssignmentDialog *ui;
Joystick *joystick; Joystick *joystick;
void checkForAxisAssignmentSticks(QWidget* comboBox, QComboBox* xAxisComboBox, QComboBox* yAxisComboBox, int controlStickNumber); void checkForAxisAssignmentSticks(QWidget *comboBox, QComboBox *xAxisComboBox, QComboBox *yAxisComboBox,
void refreshSticksForAxes(bool axesExist, int xAxisComboBoxIndex, int yAxisComboBoxIndex, QComboBox* xAxisComboBox, QComboBox* yAxisComboBox, QCheckBox* enabledSticksCheckbox, QPushButton* quickAssignBtn); int controlStickNumber);
void refreshVDPadConf(JoyButton *vdpadButton, QComboBox* vpadComboBox); void refreshSticksForAxes(bool axesExist, int xAxisComboBoxIndex, int yAxisComboBoxIndex, QComboBox *xAxisComboBox,
QComboBox *yAxisComboBox, QCheckBox *enabledSticksCheckbox, QPushButton *quickAssignBtn);
void refreshVDPadConf(JoyButton *vdpadButton, QComboBox *vpadComboBox);
}; };
#endif // ADVANCESTICKASSIGNMENTDIALOG_H #endif // ADVANCESTICKASSIGNMENTDIALOG_H

View File

@@ -22,9 +22,8 @@
#include <QDebug> #include <QDebug>
AntiMicroSettings::AntiMicroSettings(const QString &fileName, Format format, QObject *parent)
AntiMicroSettings::AntiMicroSettings(const QString &fileName, Format format, QObject *parent) : : QSettings(fileName, format, parent)
QSettings(fileName, format, parent)
{ {
qInstallMessageHandler(MessageHandler::myMessageOutput); qInstallMessageHandler(MessageHandler::myMessageOutput);
} }
@@ -44,8 +43,10 @@ QVariant AntiMicroSettings::runtimeValue(const QString &key, const QVariant &def
QString inGroup = group(); QString inGroup = group();
QString fullKey = QString(inGroup).append("/").append(key); QString fullKey = QString(inGroup).append("/").append(key);
if (cmdSettings.contains(fullKey)) settingValue = cmdSettings.value(fullKey, defaultValue); if (cmdSettings.contains(fullKey))
else settingValue = value(key, defaultValue); settingValue = cmdSettings.value(fullKey, defaultValue);
else
settingValue = value(key, defaultValue);
return settingValue; return settingValue;
} }
@@ -73,14 +74,15 @@ void AntiMicroSettings::importFromCommandLine(CommandLineUtility &cmdutility)
} }
} }
QMutex* AntiMicroSettings::getLock() QMutex *AntiMicroSettings::getLock()
{ {
qInstallMessageHandler(MessageHandler::myMessageOutput); qInstallMessageHandler(MessageHandler::myMessageOutput);
return &lock; return &lock;
} }
QSettings& AntiMicroSettings::getCmdSettings() { QSettings &AntiMicroSettings::getCmdSettings()
{
qInstallMessageHandler(MessageHandler::myMessageOutput); qInstallMessageHandler(MessageHandler::myMessageOutput);

View File

@@ -16,32 +16,28 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef ANTIMICROSETTINGS_H #ifndef ANTIMICROSETTINGS_H
#define ANTIMICROSETTINGS_H #define ANTIMICROSETTINGS_H
#include "commandlineutility.h" #include "commandlineutility.h"
#include <QSettings> #include <QSettings>
class AntiMicroSettings : public QSettings class AntiMicroSettings : public QSettings
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit AntiMicroSettings(const QString &fileName, Format format, QObject *parent = nullptr); explicit AntiMicroSettings(const QString &fileName, Format format, QObject *parent = nullptr);
QVariant runtimeValue(const QString &key, const QVariant &defaultValue = QVariant()) const; QVariant runtimeValue(const QString &key, const QVariant &defaultValue = QVariant()) const;
void importFromCommandLine(CommandLineUtility &cmdutility); void importFromCommandLine(CommandLineUtility &cmdutility);
QMutex* getLock(); QMutex *getLock();
QSettings& getCmdSettings(); QSettings &getCmdSettings();
protected: protected:
QSettings cmdSettings; QSettings cmdSettings;
QMutex lock; QMutex lock;
}; };
#endif // ANTIMICROSETTINGS_H #endif // ANTIMICROSETTINGS_H

View File

@@ -18,15 +18,14 @@
#include "antkeymapper.h" #include "antkeymapper.h"
#include "messagehandler.h"
#include "eventhandlerfactory.h" #include "eventhandlerfactory.h"
#include "messagehandler.h"
#include <QDebug> #include <QDebug>
#include <QtGlobal>
#include <QStringList> #include <QStringList>
#include <QtGlobal>
AntKeyMapper *AntKeyMapper::_instance = nullptr;
AntKeyMapper* AntKeyMapper::_instance = nullptr;
static QStringList buildEventGeneratorList() static QStringList buildEventGeneratorList()
{ {
@@ -34,18 +33,18 @@ static QStringList buildEventGeneratorList()
QStringList temp = QStringList(); QStringList temp = QStringList();
#ifdef WITH_XTEST #ifdef WITH_XTEST
temp.append("xtest"); temp.append("xtest");
#endif #endif
#ifdef WITH_UINPUT #ifdef WITH_UINPUT
temp.append("uinput"); temp.append("uinput");
#endif #endif
return temp; return temp;
} }
AntKeyMapper::AntKeyMapper(QString handler, QObject *parent) : AntKeyMapper::AntKeyMapper(QString handler, QObject *parent)
QObject(parent) : QObject(parent)
{ {
qInstallMessageHandler(MessageHandler::myMessageOutput); qInstallMessageHandler(MessageHandler::myMessageOutput);
@@ -64,18 +63,18 @@ AntKeyMapper::AntKeyMapper(QString handler, QObject *parent) :
if (handler == "uinput") if (handler == "uinput")
{ {
internalMapper = &uinputMapper; internalMapper = &uinputMapper;
#ifdef WITH_XTEST #ifdef WITH_XTEST
nativeKeyMapper = &x11Mapper; nativeKeyMapper = &x11Mapper;
#else #else
nativeKeyMapper = nullptr; nativeKeyMapper = nullptr;
#endif #endif
} }
#endif #endif
#endif #endif
} }
AntKeyMapper* AntKeyMapper::getInstance(QString handler) AntKeyMapper *AntKeyMapper::getInstance(QString handler)
{ {
qInstallMessageHandler(MessageHandler::myMessageOutput); qInstallMessageHandler(MessageHandler::myMessageOutput);
@@ -122,14 +121,14 @@ bool AntKeyMapper::isModifierKey(int qkey)
return internalMapper->isModifier(qkey); return internalMapper->isModifier(qkey);
} }
QtKeyMapperBase* AntKeyMapper::getNativeKeyMapper() const QtKeyMapperBase *AntKeyMapper::getNativeKeyMapper() const
{ {
qInstallMessageHandler(MessageHandler::myMessageOutput); qInstallMessageHandler(MessageHandler::myMessageOutput);
return nativeKeyMapper; return nativeKeyMapper;
} }
QtKeyMapperBase* AntKeyMapper::getKeyMapper() const QtKeyMapperBase *AntKeyMapper::getKeyMapper() const
{ {
qInstallMessageHandler(MessageHandler::myMessageOutput); qInstallMessageHandler(MessageHandler::myMessageOutput);

View File

@@ -16,53 +16,50 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef ANTKEYMAPPER_H #ifndef ANTKEYMAPPER_H
#define ANTKEYMAPPER_H #define ANTKEYMAPPER_H
#include <QObject> #include <QObject>
#if defined(WITH_XTEST) #if defined(WITH_XTEST)
#include "qtx11keymapper.h" #include "qtx11keymapper.h"
#endif #endif
#if defined(WITH_UINPUT) #if defined(WITH_UINPUT)
#include "qtuinputkeymapper.h" #include "qtuinputkeymapper.h"
#endif #endif
class AntKeyMapper : public QObject class AntKeyMapper : public QObject
{ {
Q_OBJECT Q_OBJECT
public: public:
static AntKeyMapper* getInstance(QString handler = ""); static AntKeyMapper *getInstance(QString handler = "");
void deleteInstance(); void deleteInstance();
int returnVirtualKey(int qkey); int returnVirtualKey(int qkey);
int returnQtKey(int key, int scancode=0); int returnQtKey(int key, int scancode = 0);
bool isModifierKey(int qkey); bool isModifierKey(int qkey);
QtKeyMapperBase* getNativeKeyMapper() const; QtKeyMapperBase *getNativeKeyMapper() const;
QtKeyMapperBase* getKeyMapper() const; QtKeyMapperBase *getKeyMapper() const;
bool hasNativeKeyMapper(); bool hasNativeKeyMapper();
protected: protected:
static AntKeyMapper *_instance; static AntKeyMapper *_instance;
private: private:
explicit AntKeyMapper(QString handler = "", QObject *parent = nullptr); explicit AntKeyMapper(QString handler = "", QObject *parent = nullptr);
QtKeyMapperBase *internalMapper; QtKeyMapperBase *internalMapper;
QtKeyMapperBase *nativeKeyMapper; QtKeyMapperBase *nativeKeyMapper;
#if defined(WITH_XTEST) #if defined(WITH_XTEST)
QtX11KeyMapper x11Mapper; QtX11KeyMapper x11Mapper;
#endif #endif
#if defined(WITH_UINPUT) #if defined(WITH_UINPUT)
QtUInputKeyMapper uinputMapper; QtUInputKeyMapper uinputMapper;
#endif #endif
}; };
#endif // ANTKEYMAPPER_H #endif // ANTKEYMAPPER_H

View File

@@ -18,22 +18,20 @@
#include "applaunchhelper.h" #include "applaunchhelper.h"
#include "antimicrosettings.h"
#include "globalvariables.h" #include "globalvariables.h"
#include "messagehandler.h"
#include "inputdevice.h" #include "inputdevice.h"
#include "joybutton.h" #include "joybutton.h"
#include "antimicrosettings.h" #include "messagehandler.h"
#include <QTextStream>
#include <QMapIterator>
#include <QDesktopWidget>
#include <QThread>
#include <QDebug> #include <QDebug>
#include <QDesktopWidget>
#include <QMapIterator>
#include <QTextStream>
#include <QThread>
AppLaunchHelper::AppLaunchHelper(AntiMicroSettings *settings, bool graphical, QObject *parent)
AppLaunchHelper::AppLaunchHelper(AntiMicroSettings *settings, bool graphical, : QObject(parent)
QObject *parent) :
QObject(parent)
{ {
qInstallMessageHandler(MessageHandler::myMessageOutput); qInstallMessageHandler(MessageHandler::myMessageOutput);
@@ -67,14 +65,18 @@ void AppLaunchHelper::enablePossibleMouseSmoothing()
if (historySize > 0) if (historySize > 0)
{ {
JoyButton::setMouseHistorySize(historySize, GlobalVariables::JoyButton::MAXIMUMMOUSEHISTORYSIZE, GlobalVariables::JoyButton::mouseHistorySize, &GlobalVariables::JoyButton::mouseHistoryX, &GlobalVariables::JoyButton::mouseHistoryY); JoyButton::setMouseHistorySize(historySize, GlobalVariables::JoyButton::MAXIMUMMOUSEHISTORYSIZE,
GlobalVariables::JoyButton::mouseHistorySize,
&GlobalVariables::JoyButton::mouseHistoryX,
&GlobalVariables::JoyButton::mouseHistoryY);
} }
double weightModifier = settings->value("Mouse/WeightModifier", 0.0).toDouble(); double weightModifier = settings->value("Mouse/WeightModifier", 0.0).toDouble();
if (weightModifier > 0.0) if (weightModifier > 0.0)
{ {
JoyButton::setWeightModifier(weightModifier, GlobalVariables::JoyButton::MAXIMUMWEIGHTMODIFIER, GlobalVariables::JoyButton::weightModifier); JoyButton::setWeightModifier(weightModifier, GlobalVariables::JoyButton::MAXIMUMWEIGHTMODIFIER,
GlobalVariables::JoyButton::weightModifier);
} }
} }
} }
@@ -87,7 +89,11 @@ void AppLaunchHelper::changeMouseRefreshRate()
if (refreshRate > 0) if (refreshRate > 0)
{ {
JoyButton::setMouseRefreshRate(refreshRate, GlobalVariables::JoyButton::mouseRefreshRate, GlobalVariables::JoyButton::IDLEMOUSEREFRESHRATE, JoyButton::getMouseHelper(), &GlobalVariables::JoyButton::mouseHistoryX, &GlobalVariables::JoyButton::mouseHistoryY, JoyButton::getTestOldMouseTime(), JoyButton::getStaticMouseEventTimer()); JoyButton::setMouseRefreshRate(refreshRate, GlobalVariables::JoyButton::mouseRefreshRate,
GlobalVariables::JoyButton::IDLEMOUSEREFRESHRATE, JoyButton::getMouseHelper(),
&GlobalVariables::JoyButton::mouseHistoryX,
&GlobalVariables::JoyButton::mouseHistoryY, JoyButton::getTestOldMouseTime(),
JoyButton::getStaticMouseEventTimer());
} }
} }
@@ -95,11 +101,11 @@ void AppLaunchHelper::changeGamepadPollRate()
{ {
qInstallMessageHandler(MessageHandler::myMessageOutput); qInstallMessageHandler(MessageHandler::myMessageOutput);
int pollRate = settings->value("GamepadPollRate", int pollRate = settings->value("GamepadPollRate", GlobalVariables::AntimicroSettings::defaultSDLGamepadPollRate).toInt();
GlobalVariables::AntimicroSettings::defaultSDLGamepadPollRate).toInt();
if (pollRate > 0) if (pollRate > 0)
{ {
JoyButton::setGamepadRefreshRate(pollRate, GlobalVariables::JoyButton::gamepadRefreshRate, JoyButton::getMouseHelper()); JoyButton::setGamepadRefreshRate(pollRate, GlobalVariables::JoyButton::gamepadRefreshRate,
JoyButton::getMouseHelper());
} }
} }
@@ -113,7 +119,7 @@ void AppLaunchHelper::printControllerList(QMap<SDL_JoystickID, InputDevice *> *j
outstream << endl; outstream << endl;
outstream << QObject::tr("List Joysticks:") << endl; outstream << QObject::tr("List Joysticks:") << endl;
outstream << QObject::tr("---------------") << endl; outstream << QObject::tr("---------------") << endl;
QMapIterator<SDL_JoystickID, InputDevice*> iter(*joysticks); QMapIterator<SDL_JoystickID, InputDevice *> iter(*joysticks);
int indexNumber = 1; int indexNumber = 1;
while (iter.hasNext()) while (iter.hasNext())
@@ -121,15 +127,14 @@ void AppLaunchHelper::printControllerList(QMap<SDL_JoystickID, InputDevice *> *j
InputDevice *tempdevice = iter.next().value(); InputDevice *tempdevice = iter.next().value();
outstream << QObject::tr("Joystick %1:").arg(indexNumber) << endl; outstream << QObject::tr("Joystick %1:").arg(indexNumber) << endl;
outstream << " " << QObject::tr("Index: %1").arg(tempdevice->getRealJoyNumber()) << endl; outstream << " " << QObject::tr("Index: %1").arg(tempdevice->getRealJoyNumber()) << endl;
//outstream << " " << QObject::tr("GUID: %1").arg(tempdevice->getGUIDString()) << endl; // outstream << " " << QObject::tr("GUID: %1").arg(tempdevice->getGUIDString()) << endl;
outstream << " " << QObject::tr("UniqueID: %1").arg(tempdevice->getUniqueIDString()) << endl; outstream << " " << QObject::tr("UniqueID: %1").arg(tempdevice->getUniqueIDString()) << endl;
outstream << " " << QObject::tr("GUID: %1").arg(tempdevice->getGUIDString()) << endl; outstream << " " << QObject::tr("GUID: %1").arg(tempdevice->getGUIDString()) << endl;
outstream << " " << QObject::tr("VendorID: %1").arg(tempdevice->getVendorString()) << endl; outstream << " " << QObject::tr("VendorID: %1").arg(tempdevice->getVendorString()) << endl;
outstream << " " << QObject::tr("ProductID: %1").arg(tempdevice->getProductIDString()) << endl; outstream << " " << QObject::tr("ProductID: %1").arg(tempdevice->getProductIDString()) << endl;
outstream << " " << QObject::tr("Product Version: %1").arg(tempdevice->getProductVersion()) << endl; outstream << " " << QObject::tr("Product Version: %1").arg(tempdevice->getProductVersion()) << endl;
outstream << " " << QObject::tr("Name: %1").arg(tempdevice->getSDLName()) << endl; outstream << " " << QObject::tr("Name: %1").arg(tempdevice->getSDLName()) << endl;
QString gameControllerStatus = tempdevice->isGameController() ? QString gameControllerStatus = tempdevice->isGameController() ? QObject::tr("Yes") : QObject::tr("No");
QObject::tr("Yes") : QObject::tr("No");
outstream << " " << QObject::tr("Game Controller: %1").arg(gameControllerStatus) << endl; outstream << " " << QObject::tr("Game Controller: %1").arg(gameControllerStatus) << endl;
outstream << " " << QObject::tr("# of Axes: %1").arg(tempdevice->getNumberRawAxes()) << endl; outstream << " " << QObject::tr("# of Axes: %1").arg(tempdevice->getNumberRawAxes()) << endl;
@@ -149,33 +154,33 @@ void AppLaunchHelper::changeSpringModeScreen()
qInstallMessageHandler(MessageHandler::myMessageOutput); qInstallMessageHandler(MessageHandler::myMessageOutput);
QDesktopWidget deskWid; QDesktopWidget deskWid;
int springScreen = settings->value("Mouse/SpringScreen", int springScreen =
GlobalVariables::AntimicroSettings::defaultSpringScreen).toInt(); settings->value("Mouse/SpringScreen", GlobalVariables::AntimicroSettings::defaultSpringScreen).toInt();
if (springScreen >= deskWid.screenCount()) if (springScreen >= deskWid.screenCount())
{ {
springScreen = -1; springScreen = -1;
settings->setValue("Mouse/SpringScreen", settings->setValue("Mouse/SpringScreen", GlobalVariables::AntimicroSettings::defaultSpringScreen);
GlobalVariables::AntimicroSettings::defaultSpringScreen);
settings->sync(); settings->sync();
} }
JoyButton::setSpringModeScreen(springScreen, GlobalVariables::JoyButton::springModeScreen); JoyButton::setSpringModeScreen(springScreen, GlobalVariables::JoyButton::springModeScreen);
} }
void AppLaunchHelper::revertMouseThread() void AppLaunchHelper::revertMouseThread()
{ {
qInstallMessageHandler(MessageHandler::myMessageOutput); qInstallMessageHandler(MessageHandler::myMessageOutput);
JoyButton::indirectStaticMouseThread(QThread::currentThread(), JoyButton::getStaticMouseEventTimer(), JoyButton::getMouseHelper()); JoyButton::indirectStaticMouseThread(QThread::currentThread(), JoyButton::getStaticMouseEventTimer(),
JoyButton::getMouseHelper());
} }
void AppLaunchHelper::changeMouseThread(QThread *thread) void AppLaunchHelper::changeMouseThread(QThread *thread)
{ {
qInstallMessageHandler(MessageHandler::myMessageOutput); qInstallMessageHandler(MessageHandler::myMessageOutput);
JoyButton::setStaticMouseThread(thread, JoyButton::getStaticMouseEventTimer(), JoyButton::getTestOldMouseTime(), GlobalVariables::JoyButton::IDLEMOUSEREFRESHRATE, JoyButton::getMouseHelper()); JoyButton::setStaticMouseThread(thread, JoyButton::getStaticMouseEventTimer(), JoyButton::getTestOldMouseTime(),
GlobalVariables::JoyButton::IDLEMOUSEREFRESHRATE, JoyButton::getMouseHelper());
} }
void AppLaunchHelper::establishMouseTimerConnections() void AppLaunchHelper::establishMouseTimerConnections()
@@ -185,7 +190,4 @@ void AppLaunchHelper::establishMouseTimerConnections()
JoyButton::establishMouseTimerConnections(); JoyButton::establishMouseTimerConnections();
} }
AntiMicroSettings *AppLaunchHelper::getSettings() const { AntiMicroSettings *AppLaunchHelper::getSettings() const { return settings; }
return settings;
}

View File

@@ -16,7 +16,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef APPLAUNCHHELPER_H #ifndef APPLAUNCHHELPER_H
#define APPLAUNCHHELPER_H #define APPLAUNCHHELPER_H
@@ -32,31 +31,28 @@ class AppLaunchHelper : public QObject
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit AppLaunchHelper(AntiMicroSettings *settings, bool graphical=false, explicit AppLaunchHelper(AntiMicroSettings *settings, bool graphical = false, QObject *parent = 0);
QObject *parent=0);
void printControllerList(QMap<SDL_JoystickID, InputDevice *> *joysticks); void printControllerList(QMap<SDL_JoystickID, InputDevice *> *joysticks);
AntiMicroSettings *getSettings() const; AntiMicroSettings *getSettings() const;
protected:
protected:
void enablePossibleMouseSmoothing(); void enablePossibleMouseSmoothing();
void establishMouseTimerConnections(); void establishMouseTimerConnections();
void changeMouseRefreshRate(); void changeMouseRefreshRate();
void changeSpringModeScreen(); void changeSpringModeScreen();
void changeGamepadPollRate(); void changeGamepadPollRate();
public slots: public slots:
void initRunMethods(); void initRunMethods();
void revertMouseThread(); void revertMouseThread();
void changeMouseThread(QThread *thread); void changeMouseThread(QThread *thread);
private: private:
AntiMicroSettings *settings; AntiMicroSettings *settings;
bool graphical; bool graphical;
}; };
#endif // APPLAUNCHHELPER_H #endif // APPLAUNCHHELPER_H

View File

@@ -20,13 +20,12 @@
#include "messagehandler.h" #include "messagehandler.h"
#include <QFileInfo>
#include <QDebug> #include <QDebug>
#include <QFileInfo>
AutoProfileInfo::AutoProfileInfo(QString uniqueID, QString profileLocation, QString exe, bool active, bool partialTitle,
AutoProfileInfo::AutoProfileInfo(QString uniqueID, QString profileLocation, QObject *parent)
QString exe, bool active, bool partialTitle, QObject *parent) : : QObject(parent)
QObject(parent)
{ {
qInstallMessageHandler(MessageHandler::myMessageOutput); qInstallMessageHandler(MessageHandler::myMessageOutput);
@@ -38,9 +37,8 @@ AutoProfileInfo::AutoProfileInfo(QString uniqueID, QString profileLocation,
setPartialState(partialTitle); setPartialState(partialTitle);
} }
AutoProfileInfo::AutoProfileInfo(QString uniqueID, QString profileLocation, AutoProfileInfo::AutoProfileInfo(QString uniqueID, QString profileLocation, bool active, bool partialTitle, QObject *parent)
bool active, bool partialTitle, QObject *parent) : : QObject(parent)
QObject(parent)
{ {
qInstallMessageHandler(MessageHandler::myMessageOutput); qInstallMessageHandler(MessageHandler::myMessageOutput);
@@ -51,8 +49,8 @@ AutoProfileInfo::AutoProfileInfo(QString uniqueID, QString profileLocation,
setPartialState(partialTitle); setPartialState(partialTitle);
} }
AutoProfileInfo::AutoProfileInfo(QObject *parent) : AutoProfileInfo::AutoProfileInfo(QObject *parent)
QObject(parent) : QObject(parent)
{ {
qInstallMessageHandler(MessageHandler::myMessageOutput); qInstallMessageHandler(MessageHandler::myMessageOutput);
@@ -61,11 +59,7 @@ AutoProfileInfo::AutoProfileInfo(QObject *parent) :
setPartialState(false); setPartialState(false);
} }
AutoProfileInfo::~AutoProfileInfo() AutoProfileInfo::~AutoProfileInfo() { qInstallMessageHandler(MessageHandler::myMessageOutput); }
{
qInstallMessageHandler(MessageHandler::myMessageOutput);
}
void AutoProfileInfo::setUniqueID(QString uniqueID) void AutoProfileInfo::setUniqueID(QString uniqueID)
{ {
@@ -74,7 +68,6 @@ void AutoProfileInfo::setUniqueID(QString uniqueID)
this->uniqueID = uniqueID; this->uniqueID = uniqueID;
} }
QString AutoProfileInfo::getUniqueID() const QString AutoProfileInfo::getUniqueID() const
{ {
qInstallMessageHandler(MessageHandler::myMessageOutput); qInstallMessageHandler(MessageHandler::myMessageOutput);
@@ -82,19 +75,16 @@ QString AutoProfileInfo::getUniqueID() const
return uniqueID; return uniqueID;
} }
void AutoProfileInfo::setProfileLocation(QString profileLocation) void AutoProfileInfo::setProfileLocation(QString profileLocation)
{ {
qInstallMessageHandler(MessageHandler::myMessageOutput); qInstallMessageHandler(MessageHandler::myMessageOutput);
QFileInfo info(profileLocation); QFileInfo info(profileLocation);
if ((profileLocation != this->profileLocation) && if ((profileLocation != this->profileLocation) && info.exists() && info.isReadable())
info.exists() && info.isReadable())
{ {
this->profileLocation = profileLocation; this->profileLocation = profileLocation;
} } else if (profileLocation.isEmpty())
else if (profileLocation.isEmpty())
{ {
this->profileLocation = ""; this->profileLocation = "";
} }
@@ -119,8 +109,7 @@ void AutoProfileInfo::setExe(QString exe)
{ {
this->exe = exe; this->exe = exe;
} }
} } else
else
{ {
this->exe = exe; this->exe = exe;
} }
@@ -200,8 +189,10 @@ QString AutoProfileInfo::getDeviceName() const
{ {
qInstallMessageHandler(MessageHandler::myMessageOutput); qInstallMessageHandler(MessageHandler::myMessageOutput);
if (deviceName.isNull()) return ""; if (deviceName.isNull())
else return deviceName; return "";
else
return deviceName;
} }
void AutoProfileInfo::setPartialState(bool value) void AutoProfileInfo::setPartialState(bool value)

View File

@@ -16,7 +16,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef AUTOPROFILEINFO_H #ifndef AUTOPROFILEINFO_H
#define AUTOPROFILEINFO_H #define AUTOPROFILEINFO_H
@@ -27,16 +26,16 @@ class AutoProfileInfo : public QObject
Q_OBJECT Q_OBJECT
public: public:
explicit AutoProfileInfo(QString uniqueID, QString profileLocation, explicit AutoProfileInfo(QString uniqueID, QString profileLocation, bool active, bool partialTitle,
bool active, bool partialTitle, QObject *parent = nullptr); QObject *parent = nullptr);
explicit AutoProfileInfo(QString uniqueID, QString profileLocation, explicit AutoProfileInfo(QString uniqueID, QString profileLocation, QString exe, bool active, bool partialTitle,
QString exe, bool active, bool partialTitle, QObject *parent = nullptr); QObject *parent = nullptr);
explicit AutoProfileInfo(QObject *parent=0); explicit AutoProfileInfo(QObject *parent = 0);
~AutoProfileInfo(); ~AutoProfileInfo();
// void setGUID(QString guid); // void setGUID(QString guid);
// QString getGUID() const; // QString getGUID() const;
void setUniqueID(QString guid); void setUniqueID(QString guid);
QString getUniqueID() const; QString getUniqueID() const;
@@ -65,7 +64,7 @@ public:
void setPartialState(bool value); void setPartialState(bool value);
bool isPartialState(); bool isPartialState();
private: private:
QString guid; QString guid;
QString uniqueID; QString uniqueID;
QString profileLocation; QString profileLocation;
@@ -76,9 +75,8 @@ private:
bool active; bool active;
bool defaultState; bool defaultState;
bool partialState; bool partialState;
}; };
Q_DECLARE_METATYPE(AutoProfileInfo*) Q_DECLARE_METATYPE(AutoProfileInfo *)
#endif // AUTOPROFILEINFO_H #endif // AUTOPROFILEINFO_H

View File

@@ -18,30 +18,28 @@
#include "autoprofilewatcher.h" #include "autoprofilewatcher.h"
#include "messagehandler.h"
#include "autoprofileinfo.h"
#include "antimicrosettings.h" #include "antimicrosettings.h"
#include "autoprofileinfo.h"
#include "messagehandler.h"
#include <QApplication>
#include <QDebug> #include <QDebug>
#include <QListIterator> #include <QDir>
#include <QStringListIterator>
#include <QSetIterator>
#include <QFile> #include <QFile>
#include <QFileInfo> #include <QFileInfo>
#include <QDir> #include <QListIterator>
#include <QApplication> #include <QSetIterator>
#include <QStringListIterator>
#if defined(WITH_X11) #if defined(WITH_X11)
#include "x11extras.h" #include "x11extras.h"
#endif #endif
AutoProfileWatcher *AutoProfileWatcher::_instance = nullptr;
AutoProfileWatcher* AutoProfileWatcher::_instance = nullptr;
QTimer AutoProfileWatcher::checkWindowTimer; QTimer AutoProfileWatcher::checkWindowTimer;
AutoProfileWatcher::AutoProfileWatcher(AntiMicroSettings *settings, QObject *parent)
AutoProfileWatcher::AutoProfileWatcher(AntiMicroSettings *settings, QObject *parent) : : QObject(parent)
QObject(parent)
{ {
qInstallMessageHandler(MessageHandler::myMessageOutput); qInstallMessageHandler(MessageHandler::myMessageOutput);
@@ -57,7 +55,8 @@ AutoProfileWatcher::AutoProfileWatcher(AntiMicroSettings *settings, QObject *par
AutoProfileWatcher::~AutoProfileWatcher() AutoProfileWatcher::~AutoProfileWatcher()
{ {
if (checkWindowTimer.isActive()) { if (checkWindowTimer.isActive())
{
checkWindowTimer.stop(); checkWindowTimer.stop();
disconnect(&(checkWindowTimer), &QTimer::timeout, _instance, nullptr); disconnect(&(checkWindowTimer), &QTimer::timeout, _instance, nullptr);
@@ -66,10 +65,7 @@ AutoProfileWatcher::~AutoProfileWatcher()
_instance = nullptr; _instance = nullptr;
} }
AutoProfileWatcher* AutoProfileWatcher::getAutoProfileWatcherInstance() AutoProfileWatcher *AutoProfileWatcher::getAutoProfileWatcherInstance() { return _instance; }
{
return _instance;
}
void AutoProfileWatcher::disconnectWindowTimer() void AutoProfileWatcher::disconnectWindowTimer()
{ {
@@ -91,14 +87,11 @@ void AutoProfileWatcher::stopTimer()
checkWindowTimer.stop(); checkWindowTimer.stop();
} }
void AutoProfileWatcher::runAppCheck() void AutoProfileWatcher::runAppCheck()
{ {
qInstallMessageHandler(MessageHandler::myMessageOutput); qInstallMessageHandler(MessageHandler::myMessageOutput);
qDebug() << qApp->applicationFilePath();
qDebug() << qApp->applicationFilePath();
QString appLocation = QString(); QString appLocation = QString();
QString baseAppFileName = QString(); QString baseAppFileName = QString();
@@ -115,7 +108,8 @@ void AutoProfileWatcher::runAppCheck()
// More portable check for whether antimicrox is the current application // More portable check for whether antimicrox is the current application
// with focus. // with focus.
QWidget *focusedWidget = qApp->activeWindow(); QWidget *focusedWidget = qApp->activeWindow();
if (focusedWidget != nullptr) qDebug() << "get active window of app" << endl; if (focusedWidget != nullptr)
qDebug() << "get active window of app" << endl;
QString nowWindow = QString(); QString nowWindow = QString();
QString nowWindowClass = QString(); QString nowWindowClass = QString();
QString nowWindowName = QString(); QString nowWindowName = QString();
@@ -128,7 +122,8 @@ void AutoProfileWatcher::runAppCheck()
long tempWindow = X11Extras::getInstance()->findParentClient(currentWindow); long tempWindow = X11Extras::getInstance()->findParentClient(currentWindow);
qDebug() << "findParentClient: " << tempWindow << endl; qDebug() << "findParentClient: " << tempWindow << endl;
if (tempWindow > 0) currentWindow = tempWindow; if (tempWindow > 0)
currentWindow = tempWindow;
nowWindow = QString::number(currentWindow); nowWindow = QString::number(currentWindow);
qDebug() << "number of window now: " << nowWindow << endl; qDebug() << "number of window now: " << nowWindow << endl;
@@ -151,34 +146,33 @@ void AutoProfileWatcher::runAppCheck()
qDebug() << "checkForTitleChange: " << checkForTitleChange; qDebug() << "checkForTitleChange: " << checkForTitleChange;
if (!focusedWidget && ((!nowWindow.isEmpty() && (nowWindow != currentApplication)) || if (!focusedWidget && ((!nowWindow.isEmpty() && (nowWindow != currentApplication)) ||
(checkForTitleChange && (nowWindowName != currentAppWindowTitle)))) (checkForTitleChange && (nowWindowName != currentAppWindowTitle))))
{ {
currentApplication = nowWindow; currentApplication = nowWindow;
currentAppWindowTitle = nowWindowName; currentAppWindowTitle = nowWindowName;
Logger::LogDebug(QObject::tr("Active window changed to: Title = \"%1\", " Logger::LogDebug(QObject::tr("Active window changed to: Title = \"%1\", "
"Class = \"%2\", Program = \"%3\" or \"%4\"."). "Class = \"%2\", Program = \"%3\" or \"%4\".")
arg(nowWindowName, nowWindowClass, appLocation, baseAppFileName)); .arg(nowWindowName, nowWindowClass, appLocation, baseAppFileName));
QSet<AutoProfileInfo*> fullSet; QSet<AutoProfileInfo *> fullSet;
if (!appLocation.isEmpty() && getAppProfileAssignments().contains(appLocation)) if (!appLocation.isEmpty() && getAppProfileAssignments().contains(appLocation))
{ {
QSet<AutoProfileInfo*> tempSet; QSet<AutoProfileInfo *> tempSet;
tempSet = getAppProfileAssignments().value(appLocation).toSet(); tempSet = getAppProfileAssignments().value(appLocation).toSet();
fullSet.unite(tempSet); fullSet.unite(tempSet);
} } else if (!baseAppFileName.isEmpty() && getAppProfileAssignments().contains(baseAppFileName))
else if (!baseAppFileName.isEmpty() && getAppProfileAssignments().contains(baseAppFileName))
{ {
QSet<AutoProfileInfo*> tempSet; QSet<AutoProfileInfo *> tempSet;
tempSet = getAppProfileAssignments().value(baseAppFileName).toSet(); tempSet = getAppProfileAssignments().value(baseAppFileName).toSet();
fullSet.unite(tempSet); fullSet.unite(tempSet);
} }
if (!nowWindowClass.isEmpty() && getWindowClassProfileAssignments().contains(nowWindowClass)) if (!nowWindowClass.isEmpty() && getWindowClassProfileAssignments().contains(nowWindowClass))
{ {
QSet<AutoProfileInfo*> tempSet; QSet<AutoProfileInfo *> tempSet;
tempSet = getWindowClassProfileAssignments().value(nowWindowClass).toSet(); tempSet = getWindowClassProfileAssignments().value(nowWindowClass).toSet();
fullSet.unite(tempSet); fullSet.unite(tempSet);
} }
@@ -186,55 +180,63 @@ void AutoProfileWatcher::runAppCheck()
// part window title // part window title
if (!nowWindowName.isEmpty()) if (!nowWindowName.isEmpty())
{ {
QHashIterator< QString, QList< AutoProfileInfo *> > iter(getWindowNameProfileAssignments()); QHashIterator<QString, QList<AutoProfileInfo *>> iter(getWindowNameProfileAssignments());
while (iter.hasNext()) while (iter.hasNext())
{ {
iter.next(); iter.next();
bool hasOnePartName = false; bool hasOnePartName = false;
QListIterator< AutoProfileInfo* > iterList(iter.value()); QListIterator<AutoProfileInfo *> iterList(iter.value());
while (iterList.hasNext()) { while (iterList.hasNext())
{
AutoProfileInfo* autoInfo = iterList.next(); AutoProfileInfo *autoInfo = iterList.next();
if (autoInfo->isPartialState()) { if (autoInfo->isPartialState())
{
hasOnePartName = true; hasOnePartName = true;
break; break;
} }
} }
if (hasOnePartName) { if (hasOnePartName)
{
qDebug() << "IT HAS A PARTIAL TITLE NAME"; qDebug() << "IT HAS A PARTIAL TITLE NAME";
if (nowWindowName.contains(iter.key())) { if (nowWindowName.contains(iter.key()))
{
qDebug() << "WINDOW: \"" << nowWindowName << "\" includes \"" << iter.key() << "\""; qDebug() << "WINDOW: \"" << nowWindowName << "\" includes \"" << iter.key() << "\"";
QSet< AutoProfileInfo* > tempSet; QSet<AutoProfileInfo *> tempSet;
QList< AutoProfileInfo *> list = iter.value(); QList<AutoProfileInfo *> list = iter.value();
tempSet = list.toSet(); tempSet = list.toSet();
fullSet = fullSet.unite(tempSet); fullSet = fullSet.unite(tempSet);
} else { } else
{
qDebug() << "WINDOW: \"" << nowWindowName << "\" doesn't include \"" << iter.key() << "\""; qDebug() << "WINDOW: \"" << nowWindowName << "\" doesn't include \"" << iter.key() << "\"";
} }
} else { } else
{
qDebug() << "IT HAS A FULL TITLE NAME"; qDebug() << "IT HAS A FULL TITLE NAME";
if (iter.key() == nowWindowName) { if (iter.key() == nowWindowName)
{
qDebug() << "WINDOW: \"" << nowWindowName << "\" is equal to hash key: \"" << iter.key() << "\""; qDebug() << "WINDOW: \"" << nowWindowName << "\" is equal to hash key: \"" << iter.key() << "\"";
QSet<AutoProfileInfo*> tempSet; QSet<AutoProfileInfo *> tempSet;
tempSet = getWindowNameProfileAssignments().value(nowWindowName).toSet(); tempSet = getWindowNameProfileAssignments().value(nowWindowName).toSet();
fullSet = fullSet.unite(tempSet); fullSet = fullSet.unite(tempSet);
} else { } else
{
qDebug() << "WINDOW: \"" << nowWindowName << "\" is not equal to hash key: \"" << iter.key() << "\""; qDebug() << "WINDOW: \"" << nowWindowName << "\" is not equal to hash key: \"" << iter.key() << "\"";
} }
@@ -243,9 +245,9 @@ void AutoProfileWatcher::runAppCheck()
} }
QHash<QString, int> highestMatchCount; QHash<QString, int> highestMatchCount;
QHash<QString, AutoProfileInfo*> highestMatches; QHash<QString, AutoProfileInfo *> highestMatches;
QSetIterator<AutoProfileInfo*> fullSetIter(fullSet); QSetIterator<AutoProfileInfo *> fullSetIter(fullSet);
while (fullSetIter.hasNext()) while (fullSetIter.hasNext())
{ {
AutoProfileInfo *info = fullSetIter.next(); AutoProfileInfo *info = fullSetIter.next();
@@ -257,24 +259,22 @@ void AutoProfileWatcher::runAppCheck()
numProps += !info->getWindowName().isEmpty() ? 1 : 0; numProps += !info->getWindowName().isEmpty() ? 1 : 0;
int numMatched = 0; int numMatched = 0;
numMatched += (!info->getExe().isEmpty() && numMatched +=
(info->getExe() == appLocation || (!info->getExe().isEmpty() && (info->getExe() == appLocation || info->getExe() == baseAppFileName)) ? 1
info->getExe() == baseAppFileName)) ? 1 : 0; : 0;
numMatched += (!info->getWindowClass().isEmpty() && numMatched += (!info->getWindowClass().isEmpty() && info->getWindowClass() == nowWindowClass) ? 1 : 0;
info->getWindowClass() == nowWindowClass) ? 1 : 0;
if (info->isPartialState())
{
if (info->isPartialState()) { numMatched +=
(!info->getWindowName().isEmpty() && nowWindowName.contains(info->getWindowName())) ? 1 : 0;
} else
{
numMatched += (!info->getWindowName().isEmpty() && numMatched += (!info->getWindowName().isEmpty() && info->getWindowName() == nowWindowName) ? 1 : 0;
nowWindowName.contains(info->getWindowName())) ? 1 : 0;
} else {
numMatched += (!info->getWindowName().isEmpty() &&
info->getWindowName() == nowWindowName) ? 1 : 0;
} }
if (numProps == numMatched && highestMatchCount.contains(info->getUniqueID())) if (numProps == numMatched && highestMatchCount.contains(info->getUniqueID()))
{ {
int currentHigh = highestMatchCount.value(info->getUniqueID()); int currentHigh = highestMatchCount.value(info->getUniqueID());
@@ -283,8 +283,7 @@ void AutoProfileWatcher::runAppCheck()
highestMatchCount.insert(info->getUniqueID(), numMatched); highestMatchCount.insert(info->getUniqueID(), numMatched);
highestMatches.insert(info->getUniqueID(), info); highestMatches.insert(info->getUniqueID(), info);
} }
} } else if (numProps == numMatched && !highestMatchCount.contains(info->getUniqueID()))
else if (numProps == numMatched && !highestMatchCount.contains(info->getUniqueID()))
{ {
highestMatchCount.insert(info->getUniqueID(), numMatched); highestMatchCount.insert(info->getUniqueID(), numMatched);
highestMatches.insert(info->getUniqueID(), info); highestMatches.insert(info->getUniqueID(), info);
@@ -292,7 +291,7 @@ void AutoProfileWatcher::runAppCheck()
} }
} }
QHashIterator<QString, AutoProfileInfo*> highIter(highestMatches); QHashIterator<QString, AutoProfileInfo *> highIter(highestMatches);
while (highIter.hasNext()) while (highIter.hasNext())
{ {
@@ -305,10 +304,10 @@ void AutoProfileWatcher::runAppCheck()
{ {
if (allDefaultInfo != nullptr && allDefaultInfo->isActive() && !getUniqeIDSetLocal().contains("all")) if (allDefaultInfo != nullptr && allDefaultInfo->isActive() && !getUniqeIDSetLocal().contains("all"))
{ {
emit foundApplicableProfile(allDefaultInfo); emit foundApplicableProfile(allDefaultInfo);
} }
QHashIterator<QString, AutoProfileInfo*> iter(getDefaultProfileAssignments()); QHashIterator<QString, AutoProfileInfo *> iter(getDefaultProfileAssignments());
while (iter.hasNext()) while (iter.hasNext())
{ {
@@ -397,7 +396,8 @@ void AutoProfileWatcher::syncProfileAssignment()
exe = settings->value(QString("AutoProfile%1Exe").arg(i), "").toString(); exe = settings->value(QString("AutoProfile%1Exe").arg(i), "").toString();
exe = QDir::toNativeSeparators(exe); exe = QDir::toNativeSeparators(exe);
convToUniqueIDAutoProfGroupSett(settings, QString("AutoProfile%1GUID").arg(i), QString("AutoProfile%1UniqueID").arg(i)); convToUniqueIDAutoProfGroupSett(settings, QString("AutoProfile%1GUID").arg(i),
QString("AutoProfile%1UniqueID").arg(i));
uniqueID = settings->value(QString("AutoProfile%1UniqueID").arg(i), "").toString(); uniqueID = settings->value(QString("AutoProfile%1UniqueID").arg(i), "").toString();
profile = settings->value(QString("AutoProfile%1Profile").arg(i), "").toString(); profile = settings->value(QString("AutoProfile%1Profile").arg(i), "").toString();
@@ -406,7 +406,6 @@ void AutoProfileWatcher::syncProfileAssignment()
QString partialTitle = settings->value(QString("AutoProfile%1PartialTitle").arg(i), 0).toString(); QString partialTitle = settings->value(QString("AutoProfile%1PartialTitle").arg(i), 0).toString();
bool partialTitleBool = partialTitle == "1" ? true : false; bool partialTitleBool = partialTitle == "1" ? true : false;
#ifdef Q_OS_UNIX #ifdef Q_OS_UNIX
windowClass = settings->value(QString("AutoProfile%1WindowClass").arg(i), "").toString(); windowClass = settings->value(QString("AutoProfile%1WindowClass").arg(i), "").toString();
#else #else
@@ -415,8 +414,7 @@ void AutoProfileWatcher::syncProfileAssignment()
// Check if all required elements exist. If not, assume that the end of the // Check if all required elements exist. If not, assume that the end of the
// list has been reached. // list has been reached.
if ((!exe.isEmpty() || !windowClass.isEmpty() || !windowName.isEmpty()) && if ((!exe.isEmpty() || !windowClass.isEmpty() || !windowName.isEmpty()) && !uniqueID.isEmpty())
!uniqueID.isEmpty())
{ {
bool profileActive = active == "1" ? true : false; bool profileActive = active == "1" ? true : false;
@@ -428,7 +426,7 @@ void AutoProfileWatcher::syncProfileAssignment()
{ {
info->setWindowClass(windowClass); info->setWindowClass(windowClass);
QList<AutoProfileInfo*> templist; QList<AutoProfileInfo *> templist;
if (getWindowClassProfileAssignments().contains(windowClass)) if (getWindowClassProfileAssignments().contains(windowClass))
templist = getWindowClassProfileAssignments().value(windowClass); templist = getWindowClassProfileAssignments().value(windowClass);
@@ -443,13 +441,14 @@ void AutoProfileWatcher::syncProfileAssignment()
info->setWindowName(windowName); info->setWindowName(windowName);
qDebug() << "WINDOW NAME IN AUTOPROFILEWATCHER: " << windowName; qDebug() << "WINDOW NAME IN AUTOPROFILEWATCHER: " << windowName;
QList<AutoProfileInfo*> templist; QList<AutoProfileInfo *> templist;
QHashIterator<QString, QList<AutoProfileInfo*> > windows(getWindowNameProfileAssignments()); QHashIterator<QString, QList<AutoProfileInfo *>> windows(getWindowNameProfileAssignments());
qDebug() << "getWindowNameProfileAssignments contains such elements like: "; qDebug() << "getWindowNameProfileAssignments contains such elements like: ";
while(windows.hasNext()) { while (windows.hasNext())
{
windows.next(); windows.next();
qDebug() << windows.key(); qDebug() << windows.key();
@@ -460,7 +459,8 @@ void AutoProfileWatcher::syncProfileAssignment()
qDebug() << "getWindowNameProfileAssignments contains " << windowName; qDebug() << "getWindowNameProfileAssignments contains " << windowName;
templist = getWindowNameProfileAssignments().value(windowName); templist = getWindowNameProfileAssignments().value(windowName);
} else { } else
{
qDebug() << "getWindowNameProfileAssignments doesn't contain " << windowName; qDebug() << "getWindowNameProfileAssignments doesn't contain " << windowName;
} }
@@ -473,7 +473,7 @@ void AutoProfileWatcher::syncProfileAssignment()
{ {
info->setExe(exe); info->setExe(exe);
QList<AutoProfileInfo*> templist; QList<AutoProfileInfo *> templist;
if (getAppProfileAssignments().contains(exe)) if (getAppProfileAssignments().contains(exe))
templist = getAppProfileAssignments().value(exe); templist = getAppProfileAssignments().value(exe);
@@ -484,7 +484,7 @@ void AutoProfileWatcher::syncProfileAssignment()
if (!baseExe.isEmpty() && baseExe != exe) if (!baseExe.isEmpty() && baseExe != exe)
{ {
QList<AutoProfileInfo*> templist; QList<AutoProfileInfo *> templist;
if (getAppProfileAssignments().contains(baseExe)) if (getAppProfileAssignments().contains(baseExe))
templist = getAppProfileAssignments().value(baseExe); templist = getAppProfileAssignments().value(baseExe);
@@ -494,8 +494,7 @@ void AutoProfileWatcher::syncProfileAssignment()
} }
} }
} }
} } else
else
{ {
quitSearch = true; quitSearch = true;
} }
@@ -505,43 +504,42 @@ void AutoProfileWatcher::syncProfileAssignment()
settings->getLock()->unlock(); settings->getLock()->unlock();
} }
void AutoProfileWatcher::clearProfileAssignments() void AutoProfileWatcher::clearProfileAssignments()
{ {
qInstallMessageHandler(MessageHandler::myMessageOutput); qInstallMessageHandler(MessageHandler::myMessageOutput);
QSet<AutoProfileInfo*> terminateProfiles; QSet<AutoProfileInfo *> terminateProfiles;
QListIterator<QList<AutoProfileInfo*> > iterDelete(getAppProfileAssignments().values()); QListIterator<QList<AutoProfileInfo *>> iterDelete(getAppProfileAssignments().values());
while (iterDelete.hasNext()) while (iterDelete.hasNext())
{ {
QList<AutoProfileInfo*> templist = iterDelete.next(); QList<AutoProfileInfo *> templist = iterDelete.next();
terminateProfiles.unite(templist.toSet()); terminateProfiles.unite(templist.toSet());
} }
appProfileAssignments.clear(); appProfileAssignments.clear();
QListIterator<QList<AutoProfileInfo*> > iterClassDelete(getWindowClassProfileAssignments().values()); QListIterator<QList<AutoProfileInfo *>> iterClassDelete(getWindowClassProfileAssignments().values());
while (iterClassDelete.hasNext()) while (iterClassDelete.hasNext())
{ {
QList<AutoProfileInfo*> templist = iterClassDelete.next(); QList<AutoProfileInfo *> templist = iterClassDelete.next();
terminateProfiles.unite(templist.toSet()); terminateProfiles.unite(templist.toSet());
} }
windowClassProfileAssignments.clear(); windowClassProfileAssignments.clear();
QListIterator<QList<AutoProfileInfo*> > iterNameDelete(getWindowNameProfileAssignments().values()); QListIterator<QList<AutoProfileInfo *>> iterNameDelete(getWindowNameProfileAssignments().values());
while (iterNameDelete.hasNext()) while (iterNameDelete.hasNext())
{ {
QList<AutoProfileInfo*> templist = iterNameDelete.next(); QList<AutoProfileInfo *> templist = iterNameDelete.next();
terminateProfiles.unite(templist.toSet()); terminateProfiles.unite(templist.toSet());
} }
windowNameProfileAssignments.clear(); windowNameProfileAssignments.clear();
QSetIterator<AutoProfileInfo*> iterTerminate(terminateProfiles); QSetIterator<AutoProfileInfo *> iterTerminate(terminateProfiles);
while (iterTerminate.hasNext()) while (iterTerminate.hasNext())
{ {
@@ -553,7 +551,7 @@ void AutoProfileWatcher::clearProfileAssignments()
} }
} }
QListIterator<AutoProfileInfo*> iterDefaultsDelete(getDefaultProfileAssignments().values()); QListIterator<AutoProfileInfo *> iterDefaultsDelete(getDefaultProfileAssignments().values());
while (iterDefaultsDelete.hasNext()) while (iterDefaultsDelete.hasNext())
{ {
@@ -576,24 +574,26 @@ QString AutoProfileWatcher::findAppLocation()
QString exepath = QString(); QString exepath = QString();
#ifdef WITH_X11 #ifdef WITH_X11
Window currentWindow = 0; Window currentWindow = 0;
int pid = 0; int pid = 0;
currentWindow = X11Extras::getInstance()->getWindowInFocus(); currentWindow = X11Extras::getInstance()->getWindowInFocus();
if (currentWindow) pid = X11Extras::getInstance()->getApplicationPid(currentWindow); if (currentWindow)
if (pid > 0) exepath = X11Extras::getInstance()->getApplicationLocation(pid); pid = X11Extras::getInstance()->getApplicationPid(currentWindow);
#endif if (pid > 0)
exepath = X11Extras::getInstance()->getApplicationLocation(pid);
#endif
return exepath; return exepath;
} }
QList<AutoProfileInfo*>* AutoProfileWatcher::getCustomDefaults() QList<AutoProfileInfo *> *AutoProfileWatcher::getCustomDefaults()
{ {
qInstallMessageHandler(MessageHandler::myMessageOutput); qInstallMessageHandler(MessageHandler::myMessageOutput);
QList<AutoProfileInfo*> *temp = new QList<AutoProfileInfo*>(); QList<AutoProfileInfo *> *temp = new QList<AutoProfileInfo *>();
QHashIterator<QString, AutoProfileInfo*> iter(getDefaultProfileAssignments()); QHashIterator<QString, AutoProfileInfo *> iter(getDefaultProfileAssignments());
while (iter.hasNext()) while (iter.hasNext())
{ {
@@ -604,14 +604,13 @@ QList<AutoProfileInfo*>* AutoProfileWatcher::getCustomDefaults()
return temp; return temp;
} }
AutoProfileInfo* AutoProfileWatcher::getDefaultAllProfile() AutoProfileInfo *AutoProfileWatcher::getDefaultAllProfile()
{ {
qInstallMessageHandler(MessageHandler::myMessageOutput); qInstallMessageHandler(MessageHandler::myMessageOutput);
return allDefaultInfo; return allDefaultInfo;
} }
bool AutoProfileWatcher::isUniqueIDLocked(QString uniqueID) bool AutoProfileWatcher::isUniqueIDLocked(QString uniqueID)
{ {
qInstallMessageHandler(MessageHandler::myMessageOutput); qInstallMessageHandler(MessageHandler::myMessageOutput);
@@ -619,34 +618,34 @@ bool AutoProfileWatcher::isUniqueIDLocked(QString uniqueID)
return getUniqeIDSetLocal().contains(uniqueID); return getUniqeIDSetLocal().contains(uniqueID);
} }
QHash<QString, QList<AutoProfileInfo*> > const& AutoProfileWatcher::getAppProfileAssignments() { QHash<QString, QList<AutoProfileInfo *>> const &AutoProfileWatcher::getAppProfileAssignments()
{
return appProfileAssignments; return appProfileAssignments;
} }
QHash<QString, QList<AutoProfileInfo*> > const& AutoProfileWatcher::getWindowClassProfileAssignments() { QHash<QString, QList<AutoProfileInfo *>> const &AutoProfileWatcher::getWindowClassProfileAssignments()
{
return windowClassProfileAssignments; return windowClassProfileAssignments;
} }
QHash<QString, QList<AutoProfileInfo*> > const& AutoProfileWatcher::getWindowNameProfileAssignments() { QHash<QString, QList<AutoProfileInfo *>> const &AutoProfileWatcher::getWindowNameProfileAssignments()
{
return windowNameProfileAssignments; return windowNameProfileAssignments;
} }
QHash<QString, AutoProfileInfo*> const& AutoProfileWatcher::getDefaultProfileAssignments() { QHash<QString, AutoProfileInfo *> const &AutoProfileWatcher::getDefaultProfileAssignments()
{
return defaultProfileAssignments; return defaultProfileAssignments;
} }
QSet<QString> &AutoProfileWatcher::getUniqeIDSetLocal() { return uniqueIDSet; }
QSet<QString>& AutoProfileWatcher::getUniqeIDSetLocal() { void AutoProfileWatcher::convToUniqueIDAutoProfGroupSett(QSettings *sett, QString guidAutoProfSett,
QString uniqueAutoProfSett)
return uniqueIDSet;
}
void AutoProfileWatcher::convToUniqueIDAutoProfGroupSett(QSettings* sett, QString guidAutoProfSett, QString uniqueAutoProfSett)
{ {
if (sett->contains(guidAutoProfSett)) if (sett->contains(guidAutoProfSett))
{ {

View File

@@ -16,13 +16,12 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef AUTOPROFILEWATCHER_H #ifndef AUTOPROFILEWATCHER_H
#define AUTOPROFILEWATCHER_H #define AUTOPROFILEWATCHER_H
#include <QTimer>
#include <QHash> #include <QHash>
#include <QSet> #include <QSet>
#include <QTimer>
class AntiMicroSettings; class AntiMicroSettings;
class AutoProfileInfo; class AutoProfileInfo;
@@ -32,55 +31,54 @@ class AutoProfileWatcher : public QObject
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit AutoProfileWatcher(AntiMicroSettings *settings, QObject *parent = nullptr); explicit AutoProfileWatcher(AntiMicroSettings *settings, QObject *parent = nullptr);
~AutoProfileWatcher(); ~AutoProfileWatcher();
void startTimer(); void startTimer();
void stopTimer(); void stopTimer();
static void disconnectWindowTimer(); static void disconnectWindowTimer();
static AutoProfileWatcher* getAutoProfileWatcherInstance(); static AutoProfileWatcher *getAutoProfileWatcherInstance();
QList<AutoProfileInfo*>* getCustomDefaults(); QList<AutoProfileInfo *> *getCustomDefaults();
AutoProfileInfo* getDefaultAllProfile(); AutoProfileInfo *getDefaultAllProfile();
//bool isGUIDLocked(QString guid); // bool isGUIDLocked(QString guid);
bool isUniqueIDLocked(QString uniqueID); bool isUniqueIDLocked(QString uniqueID);
QHash<QString, QList<AutoProfileInfo*> > const& getAppProfileAssignments(); QHash<QString, QList<AutoProfileInfo *>> const &getAppProfileAssignments();
QHash<QString, QList<AutoProfileInfo*> > const& getWindowClassProfileAssignments(); QHash<QString, QList<AutoProfileInfo *>> const &getWindowClassProfileAssignments();
QHash<QString, QList<AutoProfileInfo*> > const& getWindowNameProfileAssignments(); QHash<QString, QList<AutoProfileInfo *>> const &getWindowNameProfileAssignments();
QHash<QString, AutoProfileInfo*> const& getDefaultProfileAssignments(); QHash<QString, AutoProfileInfo *> const &getDefaultProfileAssignments();
static const int CHECKTIME = 500; // time in ms static const int CHECKTIME = 500; // time in ms
protected:
protected:
QString findAppLocation(); QString findAppLocation();
void clearProfileAssignments(); void clearProfileAssignments();
void convToUniqueIDAutoProfGroupSett(QSettings* sett, QString guidAutoProfSett, QString uniqueAutoProfSett); void convToUniqueIDAutoProfGroupSett(QSettings *sett, QString guidAutoProfSett, QString uniqueAutoProfSett);
signals: signals:
void foundApplicableProfile(AutoProfileInfo *info); void foundApplicableProfile(AutoProfileInfo *info);
public slots: public slots:
void syncProfileAssignment(); void syncProfileAssignment();
private slots: private slots:
void runAppCheck(); void runAppCheck();
private: private:
//QSet<QString>& getGuidSetLocal(); // QSet<QString>& getGuidSetLocal();
QSet<QString>& getUniqeIDSetLocal(); QSet<QString> &getUniqeIDSetLocal();
static AutoProfileWatcher* _instance; static AutoProfileWatcher *_instance;
static QTimer checkWindowTimer; static QTimer checkWindowTimer;
AntiMicroSettings *settings; AntiMicroSettings *settings;
QHash<QString, QList<AutoProfileInfo*> > appProfileAssignments; QHash<QString, QList<AutoProfileInfo *>> appProfileAssignments;
QHash<QString, QList<AutoProfileInfo*> > windowClassProfileAssignments; QHash<QString, QList<AutoProfileInfo *>> windowClassProfileAssignments;
QHash<QString, QList<AutoProfileInfo*> > windowNameProfileAssignments; QHash<QString, QList<AutoProfileInfo *>> windowNameProfileAssignments;
QHash<QString, AutoProfileInfo*> defaultProfileAssignments; QHash<QString, AutoProfileInfo *> defaultProfileAssignments;
AutoProfileInfo *allDefaultInfo; AutoProfileInfo *allDefaultInfo;
QString currentApplication; QString currentApplication;
QString currentAppWindowTitle; QString currentAppWindowTitle;
//QSet<QString> guidSet; // QSet<QString> guidSet;
QSet<QString> uniqueIDSet; QSet<QString> uniqueIDSet;
}; };

View File

@@ -19,26 +19,25 @@
#include "axiseditdialog.h" #include "axiseditdialog.h"
#include "ui_axiseditdialog.h" #include "ui_axiseditdialog.h"
#include "messagehandler.h"
#include "buttoneditdialog.h"
#include "mousedialog/mouseaxissettingsdialog.h"
#include "event.h"
#include "antkeymapper.h" #include "antkeymapper.h"
#include "setjoystick.h"
#include "inputdevice.h"
#include "common.h"
#include "joyaxis.h"
#include "axisvaluebox.h" #include "axisvaluebox.h"
#include "setaxisthrottledialog.h" #include "buttoneditdialog.h"
#include "common.h"
#include "event.h"
#include "inputdevice.h"
#include "joyaxis.h"
#include "joycontrolstick.h" #include "joycontrolstick.h"
#include "messagehandler.h"
#include "mousedialog/mouseaxissettingsdialog.h"
#include "setaxisthrottledialog.h"
#include "setjoystick.h"
#include <QDebug> #include <QDebug>
#include <QList> #include <QList>
AxisEditDialog::AxisEditDialog(JoyAxis *axis, bool keypadUnlocked, QWidget *parent)
AxisEditDialog::AxisEditDialog(JoyAxis *axis, bool keypadUnlocked, QWidget *parent) : : QDialog(parent, Qt::Window)
QDialog(parent, Qt::Window), , ui(new Ui::AxisEditDialog)
ui(new Ui::AxisEditDialog)
{ {
ui->setupUi(this); ui->setupUi(this);
qInstallMessageHandler(MessageHandler::myMessageOutput); qInstallMessageHandler(MessageHandler::myMessageOutput);
@@ -59,7 +58,8 @@ AxisEditDialog::AxisEditDialog(JoyAxis *axis, bool keypadUnlocked, QWidget *pare
actAsTrigger = true; actAsTrigger = true;
} }
if (actAsTrigger) buildTriggerPresetsMenu(); if (actAsTrigger)
buildTriggerPresetsMenu();
ui->horizontalSlider->setValue(axis->getDeadZone()); ui->horizontalSlider->setValue(axis->getDeadZone());
ui->lineEdit->setText(QString::number(axis->getDeadZone())); ui->lineEdit->setText(QString::number(axis->getDeadZone()));
@@ -72,8 +72,7 @@ AxisEditDialog::AxisEditDialog(JoyAxis *axis, bool keypadUnlocked, QWidget *pare
if (!nButton->getActionName().isEmpty()) if (!nButton->getActionName().isEmpty())
{ {
ui->nPushButton->setText(nButton->getActionName()); ui->nPushButton->setText(nButton->getActionName());
} } else
else
{ {
ui->nPushButton->setText(nButton->getSlotsSummary()); ui->nPushButton->setText(nButton->getSlotsSummary());
} }
@@ -83,22 +82,22 @@ AxisEditDialog::AxisEditDialog(JoyAxis *axis, bool keypadUnlocked, QWidget *pare
if (!pButton->getActionName().isEmpty()) if (!pButton->getActionName().isEmpty())
{ {
ui->pPushButton->setText(pButton->getActionName()); ui->pPushButton->setText(pButton->getActionName());
} } else
else
{ {
ui->pPushButton->setText(pButton->getSlotsSummary()); ui->pPushButton->setText(pButton->getSlotsSummary());
} }
int currentThrottle = axis->getThrottle(); int currentThrottle = axis->getThrottle();
if ((currentThrottle == static_cast<int>(JoyAxis::NegativeThrottle)) || (currentThrottle == static_cast<int>(JoyAxis::NegativeHalfThrottle))) if ((currentThrottle == static_cast<int>(JoyAxis::NegativeThrottle)) ||
(currentThrottle == static_cast<int>(JoyAxis::NegativeHalfThrottle)))
{ {
int tempindex = (currentThrottle == static_cast<int>(JoyAxis::NegativeHalfThrottle)) ? 0 : 1; int tempindex = (currentThrottle == static_cast<int>(JoyAxis::NegativeHalfThrottle)) ? 0 : 1;
ui->comboBox_2->setCurrentIndex(tempindex); ui->comboBox_2->setCurrentIndex(tempindex);
ui->nPushButton->setEnabled(true); ui->nPushButton->setEnabled(true);
ui->pPushButton->setEnabled(false); ui->pPushButton->setEnabled(false);
} } else if ((currentThrottle == static_cast<int>(JoyAxis::PositiveThrottle)) ||
else if ((currentThrottle == static_cast<int>(JoyAxis::PositiveThrottle)) || (currentThrottle == static_cast<int>(JoyAxis::PositiveHalfThrottle))) (currentThrottle == static_cast<int>(JoyAxis::PositiveHalfThrottle)))
{ {
int tempindex = (currentThrottle == static_cast<int>(JoyAxis::PositiveThrottle)) ? 3 : 4; int tempindex = (currentThrottle == static_cast<int>(JoyAxis::PositiveThrottle)) ? 3 : 4;
ui->comboBox_2->setCurrentIndex(tempindex); ui->comboBox_2->setCurrentIndex(tempindex);
@@ -113,33 +112,34 @@ AxisEditDialog::AxisEditDialog(JoyAxis *axis, bool keypadUnlocked, QWidget *pare
ui->joyValueLabel->setText(QString::number(axis->getCurrentRawValue())); ui->joyValueLabel->setText(QString::number(axis->getCurrentRawValue()));
ui->axisstatusBox->setValue(axis->getCurrentRawValue()); ui->axisstatusBox->setValue(axis->getCurrentRawValue());
if (!actAsTrigger) selectAxisCurrentPreset(); if (!actAsTrigger)
else selectTriggerPreset(); selectAxisCurrentPreset();
else
selectTriggerPreset();
ui->axisNameLineEdit->setText(axis->getAxisName()); ui->axisNameLineEdit->setText(axis->getAxisName());
connect(ui->presetsComboBox, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this, &AxisEditDialog::implementPresets); connect(ui->presetsComboBox, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this,
&AxisEditDialog::implementPresets);
connect(ui->horizontalSlider, &QSlider::valueChanged, this, &AxisEditDialog::updateDeadZoneBox); connect(ui->horizontalSlider, &QSlider::valueChanged, this, &AxisEditDialog::updateDeadZoneBox);
connect(ui->horizontalSlider, &QSlider::valueChanged, this, [this, axis](int deadzone) { connect(ui->horizontalSlider, &QSlider::valueChanged, this,
ui->axisstatusBox->setDeadZone(axis, deadzone); [this, axis](int deadzone) { ui->axisstatusBox->setDeadZone(axis, deadzone); });
});
connect(ui->horizontalSlider, &QSlider::valueChanged, axis, &JoyAxis::setDeadZone); connect(ui->horizontalSlider, &QSlider::valueChanged, axis, &JoyAxis::setDeadZone);
connect(ui->horizontalSlider_2, &QSlider::valueChanged, this, &AxisEditDialog::updateMaxZoneBox); connect(ui->horizontalSlider_2, &QSlider::valueChanged, this, &AxisEditDialog::updateMaxZoneBox);
connect(ui->horizontalSlider_2, &QSlider::valueChanged, this, [this, axis](int deadzone) { connect(ui->horizontalSlider_2, &QSlider::valueChanged, this,
ui->axisstatusBox->setMaxZone(axis, deadzone); [this, axis](int deadzone) { ui->axisstatusBox->setMaxZone(axis, deadzone); });
});
connect(ui->horizontalSlider_2, &QSlider::valueChanged, axis, &JoyAxis::setMaxZoneValue); connect(ui->horizontalSlider_2, &QSlider::valueChanged, axis, &JoyAxis::setMaxZoneValue);
connect(ui->comboBox_2, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this, &AxisEditDialog::updateThrottleUi); connect(ui->comboBox_2, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this,
connect(ui->comboBox_2, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this, &AxisEditDialog::presetForThrottleChange); &AxisEditDialog::updateThrottleUi);
connect(ui->comboBox_2, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this,
&AxisEditDialog::presetForThrottleChange);
connect(axis, &JoyAxis::moved, this, [this, axis](int value) { connect(axis, &JoyAxis::moved, this, [this, axis](int value) { ui->axisstatusBox->setValue(axis, value); });
ui->axisstatusBox->setValue(axis, value);
});
connect(axis, &JoyAxis::moved, this, &AxisEditDialog::updateJoyValue); connect(axis, &JoyAxis::moved, this, &AxisEditDialog::updateJoyValue);
@@ -157,11 +157,10 @@ AxisEditDialog::AxisEditDialog(JoyAxis *axis, bool keypadUnlocked, QWidget *pare
} }
// for tests // for tests
AxisEditDialog::AxisEditDialog(QWidget *parent) : AxisEditDialog::AxisEditDialog(QWidget *parent)
QDialog(parent, Qt::Window), : QDialog(parent, Qt::Window)
ui(new Ui::AxisEditDialog) , ui(new Ui::AxisEditDialog)
{ {
} }
AxisEditDialog::~AxisEditDialog() AxisEditDialog::~AxisEditDialog()
@@ -184,8 +183,10 @@ void AxisEditDialog::implementPresets(int index)
actAsTrigger = true; actAsTrigger = true;
} }
if (actAsTrigger) implementTriggerPresets(index); if (actAsTrigger)
else implementAxisPresets(index); implementTriggerPresets(index);
else
implementAxisPresets(index);
} }
void AxisEditDialog::implementAxisPresets(int index) void AxisEditDialog::implementAxisPresets(int index)
@@ -199,85 +200,93 @@ void AxisEditDialog::implementAxisPresets(int index)
InputDevice *tempDevice = m_axis->getParentSet()->getInputDevice(); InputDevice *tempDevice = m_axis->getParentSet()->getInputDevice();
QMetaObject::invokeMethod(tempDevice, "haltServices", Qt::BlockingQueuedConnection); QMetaObject::invokeMethod(tempDevice, "haltServices", Qt::BlockingQueuedConnection);
switch(index) switch (index)
{ {
case 1: case 1:
nbuttonslot = new JoyButtonSlot(JoyButtonSlot::MouseLeft, JoyButtonSlot::JoyMouseMovement, this); nbuttonslot = new JoyButtonSlot(JoyButtonSlot::MouseLeft, JoyButtonSlot::JoyMouseMovement, this);
pbuttonslot = new JoyButtonSlot(JoyButtonSlot::MouseRight, JoyButtonSlot::JoyMouseMovement, this); pbuttonslot = new JoyButtonSlot(JoyButtonSlot::MouseRight, JoyButtonSlot::JoyMouseMovement, this);
break; break;
case 2: case 2:
nbuttonslot = new JoyButtonSlot(JoyButtonSlot::MouseRight, JoyButtonSlot::JoyMouseMovement, this); nbuttonslot = new JoyButtonSlot(JoyButtonSlot::MouseRight, JoyButtonSlot::JoyMouseMovement, this);
pbuttonslot = new JoyButtonSlot(JoyButtonSlot::MouseLeft, JoyButtonSlot::JoyMouseMovement, this); pbuttonslot = new JoyButtonSlot(JoyButtonSlot::MouseLeft, JoyButtonSlot::JoyMouseMovement, this);
break; break;
case 3: case 3:
nbuttonslot = new JoyButtonSlot(JoyButtonSlot::MouseUp, JoyButtonSlot::JoyMouseMovement, this); nbuttonslot = new JoyButtonSlot(JoyButtonSlot::MouseUp, JoyButtonSlot::JoyMouseMovement, this);
pbuttonslot = new JoyButtonSlot(JoyButtonSlot::MouseDown, JoyButtonSlot::JoyMouseMovement, this); pbuttonslot = new JoyButtonSlot(JoyButtonSlot::MouseDown, JoyButtonSlot::JoyMouseMovement, this);
break; break;
case 4: case 4:
nbuttonslot = new JoyButtonSlot(JoyButtonSlot::MouseDown, JoyButtonSlot::JoyMouseMovement, this); nbuttonslot = new JoyButtonSlot(JoyButtonSlot::MouseDown, JoyButtonSlot::JoyMouseMovement, this);
pbuttonslot = new JoyButtonSlot(JoyButtonSlot::MouseUp, JoyButtonSlot::JoyMouseMovement, this); pbuttonslot = new JoyButtonSlot(JoyButtonSlot::MouseUp, JoyButtonSlot::JoyMouseMovement, this);
break; break;
case 5: case 5:
nbuttonslot = new JoyButtonSlot(AntKeyMapper::getInstance()->returnVirtualKey(Qt::Key_Up), Qt::Key_Up, JoyButtonSlot::JoyKeyboard, this); nbuttonslot = new JoyButtonSlot(AntKeyMapper::getInstance()->returnVirtualKey(Qt::Key_Up), Qt::Key_Up,
pbuttonslot = new JoyButtonSlot(AntKeyMapper::getInstance()->returnVirtualKey(Qt::Key_Down), Qt::Key_Down, JoyButtonSlot::JoyKeyboard, this); JoyButtonSlot::JoyKeyboard, this);
pbuttonslot = new JoyButtonSlot(AntKeyMapper::getInstance()->returnVirtualKey(Qt::Key_Down), Qt::Key_Down,
JoyButtonSlot::JoyKeyboard, this);
break; break;
case 6: case 6:
nbuttonslot = new JoyButtonSlot(AntKeyMapper::getInstance()->returnVirtualKey(Qt::Key_Left), Qt::Key_Left, JoyButtonSlot::JoyKeyboard, this); nbuttonslot = new JoyButtonSlot(AntKeyMapper::getInstance()->returnVirtualKey(Qt::Key_Left), Qt::Key_Left,
pbuttonslot = new JoyButtonSlot(AntKeyMapper::getInstance()->returnVirtualKey(Qt::Key_Right), Qt::Key_Right, JoyButtonSlot::JoyKeyboard, this); JoyButtonSlot::JoyKeyboard, this);
pbuttonslot = new JoyButtonSlot(AntKeyMapper::getInstance()->returnVirtualKey(Qt::Key_Right), Qt::Key_Right,
JoyButtonSlot::JoyKeyboard, this);
break; break;
case 7: case 7:
nbuttonslot = new JoyButtonSlot(AntKeyMapper::getInstance()->returnVirtualKey(Qt::Key_W), Qt::Key_W, JoyButtonSlot::JoyKeyboard, this); nbuttonslot = new JoyButtonSlot(AntKeyMapper::getInstance()->returnVirtualKey(Qt::Key_W), Qt::Key_W,
pbuttonslot = new JoyButtonSlot(AntKeyMapper::getInstance()->returnVirtualKey(Qt::Key_S), Qt::Key_S, JoyButtonSlot::JoyKeyboard, this); JoyButtonSlot::JoyKeyboard, this);
pbuttonslot = new JoyButtonSlot(AntKeyMapper::getInstance()->returnVirtualKey(Qt::Key_S), Qt::Key_S,
JoyButtonSlot::JoyKeyboard, this);
break; break;
case 8: case 8:
nbuttonslot = new JoyButtonSlot(AntKeyMapper::getInstance()->returnVirtualKey(Qt::Key_A), Qt::Key_A, JoyButtonSlot::JoyKeyboard, this); nbuttonslot = new JoyButtonSlot(AntKeyMapper::getInstance()->returnVirtualKey(Qt::Key_A), Qt::Key_A,
pbuttonslot = new JoyButtonSlot(AntKeyMapper::getInstance()->returnVirtualKey(Qt::Key_D), Qt::Key_D, JoyButtonSlot::JoyKeyboard, this); JoyButtonSlot::JoyKeyboard, this);
pbuttonslot = new JoyButtonSlot(AntKeyMapper::getInstance()->returnVirtualKey(Qt::Key_D), Qt::Key_D,
JoyButtonSlot::JoyKeyboard, this);
break; break;
case 9: case 9:
nbuttonslot = new JoyButtonSlot(AntKeyMapper::getInstance()->returnVirtualKey(QtKeyMapperBase::AntKey_KP_8), QtKeyMapperBase::AntKey_KP_8, JoyButtonSlot::JoyKeyboard, this); nbuttonslot = new JoyButtonSlot(AntKeyMapper::getInstance()->returnVirtualKey(QtKeyMapperBase::AntKey_KP_8),
pbuttonslot = new JoyButtonSlot(AntKeyMapper::getInstance()->returnVirtualKey(QtKeyMapperBase::AntKey_KP_2), QtKeyMapperBase::AntKey_KP_2, JoyButtonSlot::JoyKeyboard, this); QtKeyMapperBase::AntKey_KP_8, JoyButtonSlot::JoyKeyboard, this);
pbuttonslot = new JoyButtonSlot(AntKeyMapper::getInstance()->returnVirtualKey(QtKeyMapperBase::AntKey_KP_2),
QtKeyMapperBase::AntKey_KP_2, JoyButtonSlot::JoyKeyboard, this);
break; break;
case 10: case 10:
nbuttonslot = new JoyButtonSlot(AntKeyMapper::getInstance()->returnVirtualKey(QtKeyMapperBase::AntKey_KP_4), QtKeyMapperBase::AntKey_KP_4, JoyButtonSlot::JoyKeyboard, this); nbuttonslot = new JoyButtonSlot(AntKeyMapper::getInstance()->returnVirtualKey(QtKeyMapperBase::AntKey_KP_4),
pbuttonslot = new JoyButtonSlot(AntKeyMapper::getInstance()->returnVirtualKey(QtKeyMapperBase::AntKey_KP_6), QtKeyMapperBase::AntKey_KP_6, JoyButtonSlot::JoyKeyboard, this); QtKeyMapperBase::AntKey_KP_4, JoyButtonSlot::JoyKeyboard, this);
pbuttonslot = new JoyButtonSlot(AntKeyMapper::getInstance()->returnVirtualKey(QtKeyMapperBase::AntKey_KP_6),
QtKeyMapperBase::AntKey_KP_6, JoyButtonSlot::JoyKeyboard, this);
break; break;
case 0: case 0:
case 11: case 11:
JoyAxisButton *nbutton = m_axis->getNAxisButton(); JoyAxisButton *nbutton = m_axis->getNAxisButton();
JoyAxisButton *pbutton = m_axis->getPAxisButton(); JoyAxisButton *pbutton = m_axis->getPAxisButton();
QMetaObject::invokeMethod(nbutton, "clearSlotsEventReset"); QMetaObject::invokeMethod(nbutton, "clearSlotsEventReset");
QMetaObject::invokeMethod(pbutton, "clearSlotsEventReset", Qt::BlockingQueuedConnection); QMetaObject::invokeMethod(pbutton, "clearSlotsEventReset", Qt::BlockingQueuedConnection);
refreshNButtonLabel(); refreshNButtonLabel();
refreshPButtonLabel(); refreshPButtonLabel();
nbutton->buildActiveZoneSummaryString(); nbutton->buildActiveZoneSummaryString();
pbutton->buildActiveZoneSummaryString(); pbutton->buildActiveZoneSummaryString();
break; break;
} }
if (nbuttonslot != nullptr) if (nbuttonslot != nullptr)
{ {
JoyAxisButton *button = m_axis->getNAxisButton(); JoyAxisButton *button = m_axis->getNAxisButton();
QMetaObject::invokeMethod(button, "clearSlotsEventReset", QMetaObject::invokeMethod(button, "clearSlotsEventReset", Q_ARG(bool, false));
Q_ARG(bool, false));
QMetaObject::invokeMethod(button, "setAssignedSlot", Qt::BlockingQueuedConnection, QMetaObject::invokeMethod(button, "setAssignedSlot", Qt::BlockingQueuedConnection,
Q_ARG(int, nbuttonslot->getSlotCode()), Q_ARG(int, nbuttonslot->getSlotCode()), Q_ARG(int, nbuttonslot->getSlotCodeAlias()),
Q_ARG(int, nbuttonslot->getSlotCodeAlias()),
Q_ARG(JoyButtonSlot::JoySlotInputAction, nbuttonslot->getSlotMode())); Q_ARG(JoyButtonSlot::JoySlotInputAction, nbuttonslot->getSlotMode()));
refreshNButtonLabel(); refreshNButtonLabel();
@@ -290,8 +299,7 @@ void AxisEditDialog::implementAxisPresets(int index)
QMetaObject::invokeMethod(button, "clearSlotsEventReset", Q_ARG(bool, false)); QMetaObject::invokeMethod(button, "clearSlotsEventReset", Q_ARG(bool, false));
QMetaObject::invokeMethod(button, "setAssignedSlot", Qt::BlockingQueuedConnection, QMetaObject::invokeMethod(button, "setAssignedSlot", Qt::BlockingQueuedConnection,
Q_ARG(int, pbuttonslot->getSlotCode()), Q_ARG(int, pbuttonslot->getSlotCode()), Q_ARG(int, pbuttonslot->getSlotCodeAlias()),
Q_ARG(int, pbuttonslot->getSlotCodeAlias()),
Q_ARG(JoyButtonSlot::JoySlotInputAction, pbuttonslot->getSlotMode())); Q_ARG(JoyButtonSlot::JoySlotInputAction, pbuttonslot->getSlotMode()));
refreshPButtonLabel(); refreshPButtonLabel();
@@ -325,19 +333,19 @@ void AxisEditDialog::updateThrottleUi(int index)
{ {
ui->nPushButton->setEnabled(true); ui->nPushButton->setEnabled(true);
ui->pPushButton->setEnabled(false); ui->pPushButton->setEnabled(false);
tempthrottle = (index == 0) ? static_cast<int>(JoyAxis::NegativeHalfThrottle) : static_cast<int>(JoyAxis::NegativeThrottle); tempthrottle =
} (index == 0) ? static_cast<int>(JoyAxis::NegativeHalfThrottle) : static_cast<int>(JoyAxis::NegativeThrottle);
else if (index == 2) } else if (index == 2)
{ {
ui->nPushButton->setEnabled(true); ui->nPushButton->setEnabled(true);
ui->pPushButton->setEnabled(true); ui->pPushButton->setEnabled(true);
tempthrottle = static_cast<int>(JoyAxis::NormalThrottle); tempthrottle = static_cast<int>(JoyAxis::NormalThrottle);
} } else if ((index == 3) || (index == 4))
else if ((index == 3) || (index == 4))
{ {
ui->pPushButton->setEnabled(true); ui->pPushButton->setEnabled(true);
ui->nPushButton->setEnabled(false); ui->nPushButton->setEnabled(false);
tempthrottle = (index == 3) ? static_cast<int>(JoyAxis::PositiveThrottle) : static_cast<int>(JoyAxis::PositiveHalfThrottle); tempthrottle =
(index == 3) ? static_cast<int>(JoyAxis::PositiveThrottle) : static_cast<int>(JoyAxis::PositiveHalfThrottle);
} }
m_axis->setThrottle(tempthrottle); m_axis->setThrottle(tempthrottle);
@@ -379,7 +387,8 @@ void AxisEditDialog::openAdvancedPDialog()
{ {
qInstallMessageHandler(MessageHandler::myMessageOutput); qInstallMessageHandler(MessageHandler::myMessageOutput);
ButtonEditDialog *dialog = new ButtonEditDialog(m_axis->getPAxisButton(), m_axis->getPAxisButton()->getParentSet()->getInputDevice(), keypadUnlocked, this); ButtonEditDialog *dialog = new ButtonEditDialog(
m_axis->getPAxisButton(), m_axis->getPAxisButton()->getParentSet()->getInputDevice(), keypadUnlocked, this);
dialog->show(); dialog->show();
connect(dialog, &ButtonEditDialog::finished, this, &AxisEditDialog::refreshPButtonLabel); connect(dialog, &ButtonEditDialog::finished, this, &AxisEditDialog::refreshPButtonLabel);
@@ -390,7 +399,8 @@ void AxisEditDialog::openAdvancedNDialog()
{ {
qInstallMessageHandler(MessageHandler::myMessageOutput); qInstallMessageHandler(MessageHandler::myMessageOutput);
ButtonEditDialog *dialog = new ButtonEditDialog(m_axis->getNAxisButton(), m_axis->getNAxisButton()->getParentSet()->getInputDevice(), keypadUnlocked, this); ButtonEditDialog *dialog = new ButtonEditDialog(
m_axis->getNAxisButton(), m_axis->getNAxisButton()->getParentSet()->getInputDevice(), keypadUnlocked, this);
dialog->show(); dialog->show();
connect(dialog, &ButtonEditDialog::finished, this, &AxisEditDialog::refreshNButtonLabel); connect(dialog, &ButtonEditDialog::finished, this, &AxisEditDialog::refreshNButtonLabel);
@@ -409,7 +419,6 @@ void AxisEditDialog::refreshPButtonLabel()
qInstallMessageHandler(MessageHandler::myMessageOutput); qInstallMessageHandler(MessageHandler::myMessageOutput);
ui->pPushButton->setText(m_axis->getPAxisButton()->getSlotsSummary()); ui->pPushButton->setText(m_axis->getPAxisButton()->getSlotsSummary());
} }
void AxisEditDialog::checkFinalSettings() void AxisEditDialog::checkFinalSettings()
@@ -425,75 +434,82 @@ void AxisEditDialog::selectAxisCurrentPreset()
qInstallMessageHandler(MessageHandler::myMessageOutput); qInstallMessageHandler(MessageHandler::myMessageOutput);
JoyAxisButton *naxisbutton = m_axis->getNAxisButton(); JoyAxisButton *naxisbutton = m_axis->getNAxisButton();
QList<JoyButtonSlot*> *naxisslots = naxisbutton->getAssignedSlots(); QList<JoyButtonSlot *> *naxisslots = naxisbutton->getAssignedSlots();
JoyAxisButton *paxisbutton = m_axis->getPAxisButton(); JoyAxisButton *paxisbutton = m_axis->getPAxisButton();
QList<JoyButtonSlot*> *paxisslots = paxisbutton->getAssignedSlots(); QList<JoyButtonSlot *> *paxisslots = paxisbutton->getAssignedSlots();
if ((naxisslots->length() == 1) && (paxisslots->length() == 1)) if ((naxisslots->length() == 1) && (paxisslots->length() == 1))
{ {
JoyButtonSlot *nslot = naxisslots->at(0); JoyButtonSlot *nslot = naxisslots->at(0);
JoyButtonSlot *pslot = paxisslots->at(0); JoyButtonSlot *pslot = paxisslots->at(0);
if ((nslot->getSlotMode() == JoyButtonSlot::JoyMouseMovement) && (nslot->getSlotCode() == JoyButtonSlot::MouseLeft) && if ((nslot->getSlotMode() == JoyButtonSlot::JoyMouseMovement) &&
(nslot->getSlotCode() == JoyButtonSlot::MouseLeft) &&
(pslot->getSlotMode() == JoyButtonSlot::JoyMouseMovement) && (pslot->getSlotCode() == JoyButtonSlot::MouseRight)) (pslot->getSlotMode() == JoyButtonSlot::JoyMouseMovement) && (pslot->getSlotCode() == JoyButtonSlot::MouseRight))
{ {
ui->presetsComboBox->setCurrentIndex(1); ui->presetsComboBox->setCurrentIndex(1);
} } else if ((nslot->getSlotMode() == JoyButtonSlot::JoyMouseMovement) &&
else if ((nslot->getSlotMode() == JoyButtonSlot::JoyMouseMovement) && (nslot->getSlotCode() == JoyButtonSlot::MouseRight) && (nslot->getSlotCode() == JoyButtonSlot::MouseRight) &&
(pslot->getSlotMode() == JoyButtonSlot::JoyMouseMovement) && (pslot->getSlotCode() == JoyButtonSlot::MouseLeft)) (pslot->getSlotMode() == JoyButtonSlot::JoyMouseMovement) &&
(pslot->getSlotCode() == JoyButtonSlot::MouseLeft))
{ {
ui->presetsComboBox->setCurrentIndex(2); ui->presetsComboBox->setCurrentIndex(2);
} } else if ((nslot->getSlotMode() == JoyButtonSlot::JoyMouseMovement) &&
else if ((nslot->getSlotMode() == JoyButtonSlot::JoyMouseMovement) && (nslot->getSlotCode() == JoyButtonSlot::MouseUp) && (nslot->getSlotCode() == JoyButtonSlot::MouseUp) &&
(pslot->getSlotMode() == JoyButtonSlot::JoyMouseMovement) && (pslot->getSlotCode() == JoyButtonSlot::MouseDown)) (pslot->getSlotMode() == JoyButtonSlot::JoyMouseMovement) &&
(pslot->getSlotCode() == JoyButtonSlot::MouseDown))
{ {
ui->presetsComboBox->setCurrentIndex(3); ui->presetsComboBox->setCurrentIndex(3);
} } else if ((nslot->getSlotMode() == JoyButtonSlot::JoyMouseMovement) &&
else if ((nslot->getSlotMode() == JoyButtonSlot::JoyMouseMovement) && (nslot->getSlotCode() == JoyButtonSlot::MouseDown) && (nslot->getSlotCode() == JoyButtonSlot::MouseDown) &&
(pslot->getSlotMode() == JoyButtonSlot::JoyMouseMovement) && (pslot->getSlotCode() == JoyButtonSlot::MouseUp)) (pslot->getSlotMode() == JoyButtonSlot::JoyMouseMovement) &&
(pslot->getSlotCode() == JoyButtonSlot::MouseUp))
{ {
ui->presetsComboBox->setCurrentIndex(4); ui->presetsComboBox->setCurrentIndex(4);
} } else if ((nslot->getSlotMode() == JoyButtonSlot::JoyKeyboard) &&
else if ((nslot->getSlotMode() == JoyButtonSlot::JoyKeyboard) && (nslot->getSlotCode() == AntKeyMapper::getInstance()->returnVirtualKey(Qt::Key_Up)) && (nslot->getSlotCode() == AntKeyMapper::getInstance()->returnVirtualKey(Qt::Key_Up)) &&
(pslot->getSlotMode() == JoyButtonSlot::JoyKeyboard) && (pslot->getSlotCode() == AntKeyMapper::getInstance()->returnVirtualKey(Qt::Key_Down))) (pslot->getSlotMode() == JoyButtonSlot::JoyKeyboard) &&
(pslot->getSlotCode() == AntKeyMapper::getInstance()->returnVirtualKey(Qt::Key_Down)))
{ {
ui->presetsComboBox->setCurrentIndex(5); ui->presetsComboBox->setCurrentIndex(5);
} } else if ((nslot->getSlotMode() == JoyButtonSlot::JoyKeyboard) &&
else if ((nslot->getSlotMode() == JoyButtonSlot::JoyKeyboard) && (nslot->getSlotCode() == AntKeyMapper::getInstance()->returnVirtualKey(Qt::Key_Left)) && (nslot->getSlotCode() == AntKeyMapper::getInstance()->returnVirtualKey(Qt::Key_Left)) &&
(pslot->getSlotMode() == JoyButtonSlot::JoyKeyboard) && (pslot->getSlotCode() == AntKeyMapper::getInstance()->returnVirtualKey(Qt::Key_Right))) (pslot->getSlotMode() == JoyButtonSlot::JoyKeyboard) &&
(pslot->getSlotCode() == AntKeyMapper::getInstance()->returnVirtualKey(Qt::Key_Right)))
{ {
ui->presetsComboBox->setCurrentIndex(6); ui->presetsComboBox->setCurrentIndex(6);
} } else if ((nslot->getSlotMode() == JoyButtonSlot::JoyKeyboard) &&
else if ((nslot->getSlotMode() == JoyButtonSlot::JoyKeyboard) && (nslot->getSlotCode() == AntKeyMapper::getInstance()->returnVirtualKey(Qt::Key_W)) && (nslot->getSlotCode() == AntKeyMapper::getInstance()->returnVirtualKey(Qt::Key_W)) &&
(pslot->getSlotMode() == JoyButtonSlot::JoyKeyboard) && (pslot->getSlotCode() == AntKeyMapper::getInstance()->returnVirtualKey(Qt::Key_S))) (pslot->getSlotMode() == JoyButtonSlot::JoyKeyboard) &&
(pslot->getSlotCode() == AntKeyMapper::getInstance()->returnVirtualKey(Qt::Key_S)))
{ {
ui->presetsComboBox->setCurrentIndex(7); ui->presetsComboBox->setCurrentIndex(7);
} } else if ((nslot->getSlotMode() == JoyButtonSlot::JoyKeyboard) &&
else if ((nslot->getSlotMode() == JoyButtonSlot::JoyKeyboard) && (nslot->getSlotCode() == AntKeyMapper::getInstance()->returnVirtualKey(Qt::Key_A)) && (nslot->getSlotCode() == AntKeyMapper::getInstance()->returnVirtualKey(Qt::Key_A)) &&
(pslot->getSlotMode() == JoyButtonSlot::JoyKeyboard) && (pslot->getSlotCode() == AntKeyMapper::getInstance()->returnVirtualKey(Qt::Key_D))) (pslot->getSlotMode() == JoyButtonSlot::JoyKeyboard) &&
(pslot->getSlotCode() == AntKeyMapper::getInstance()->returnVirtualKey(Qt::Key_D)))
{ {
ui->presetsComboBox->setCurrentIndex(8); ui->presetsComboBox->setCurrentIndex(8);
} } else if ((nslot->getSlotMode() == JoyButtonSlot::JoyKeyboard) &&
else if ((nslot->getSlotMode() == JoyButtonSlot::JoyKeyboard) && (nslot->getSlotCode() == AntKeyMapper::getInstance()->returnVirtualKey(QtKeyMapperBase::AntKey_KP_8)) && (nslot->getSlotCode() == AntKeyMapper::getInstance()->returnVirtualKey(QtKeyMapperBase::AntKey_KP_8)) &&
(pslot->getSlotMode() == JoyButtonSlot::JoyKeyboard) && (pslot->getSlotCode() == AntKeyMapper::getInstance()->returnVirtualKey(QtKeyMapperBase::AntKey_KP_2))) (pslot->getSlotMode() == JoyButtonSlot::JoyKeyboard) &&
(pslot->getSlotCode() == AntKeyMapper::getInstance()->returnVirtualKey(QtKeyMapperBase::AntKey_KP_2)))
{ {
ui->presetsComboBox->setCurrentIndex(9); ui->presetsComboBox->setCurrentIndex(9);
} } else if ((nslot->getSlotMode() == JoyButtonSlot::JoyKeyboard) &&
else if ((nslot->getSlotMode() == JoyButtonSlot::JoyKeyboard) && (nslot->getSlotCode() == AntKeyMapper::getInstance()->returnVirtualKey(QtKeyMapperBase::AntKey_KP_4)) && (nslot->getSlotCode() == AntKeyMapper::getInstance()->returnVirtualKey(QtKeyMapperBase::AntKey_KP_4)) &&
(pslot->getSlotMode() == JoyButtonSlot::JoyKeyboard) && (pslot->getSlotCode() == AntKeyMapper::getInstance()->returnVirtualKey(QtKeyMapperBase::AntKey_KP_6))) (pslot->getSlotMode() == JoyButtonSlot::JoyKeyboard) &&
(pslot->getSlotCode() == AntKeyMapper::getInstance()->returnVirtualKey(QtKeyMapperBase::AntKey_KP_6)))
{ {
ui->presetsComboBox->setCurrentIndex(10); ui->presetsComboBox->setCurrentIndex(10);
} } else
else
{ {
ui->presetsComboBox->setCurrentIndex(0); ui->presetsComboBox->setCurrentIndex(0);
} }
} } else if ((naxisslots->length() == 0) && (paxisslots->length() == 0))
else if ((naxisslots->length() == 0) && (paxisslots->length() == 0))
{ {
ui->presetsComboBox->setCurrentIndex(11); ui->presetsComboBox->setCurrentIndex(11);
} } else
else
{ {
ui->presetsComboBox->setCurrentIndex(0); ui->presetsComboBox->setCurrentIndex(0);
} }
@@ -504,7 +520,7 @@ void AxisEditDialog::selectTriggerPreset()
qInstallMessageHandler(MessageHandler::myMessageOutput); qInstallMessageHandler(MessageHandler::myMessageOutput);
JoyAxisButton *paxisbutton = m_axis->getPAxisButton(); JoyAxisButton *paxisbutton = m_axis->getPAxisButton();
QList<JoyButtonSlot*> *paxisslots = paxisbutton->getAssignedSlots(); QList<JoyButtonSlot *> *paxisslots = paxisbutton->getAssignedSlots();
if (paxisslots->length() == 1) if (paxisslots->length() == 1)
{ {
@@ -513,21 +529,18 @@ void AxisEditDialog::selectTriggerPreset()
if ((pslot->getSlotMode() == JoyButtonSlot::JoyMouseButton) && (pslot->getSlotCode() == JoyButtonSlot::MouseLB)) if ((pslot->getSlotMode() == JoyButtonSlot::JoyMouseButton) && (pslot->getSlotCode() == JoyButtonSlot::MouseLB))
{ {
ui->presetsComboBox->setCurrentIndex(1); ui->presetsComboBox->setCurrentIndex(1);
} } else if ((pslot->getSlotMode() == JoyButtonSlot::JoyMouseButton) &&
else if ((pslot->getSlotMode() == JoyButtonSlot::JoyMouseButton) && (pslot->getSlotCode() == JoyButtonSlot::MouseRB)) (pslot->getSlotCode() == JoyButtonSlot::MouseRB))
{ {
ui->presetsComboBox->setCurrentIndex(2); ui->presetsComboBox->setCurrentIndex(2);
} } else
else
{ {
ui->presetsComboBox->setCurrentIndex(0); ui->presetsComboBox->setCurrentIndex(0);
} }
} } else if (paxisslots->length() == 0)
else if (paxisslots->length() == 0)
{ {
ui->presetsComboBox->setCurrentIndex(3); ui->presetsComboBox->setCurrentIndex(3);
} } else
else
{ {
ui->presetsComboBox->setCurrentIndex(0); ui->presetsComboBox->setCurrentIndex(0);
} }
@@ -542,12 +555,10 @@ void AxisEditDialog::implementTriggerPresets(int index)
if (index == 1) if (index == 1)
{ {
pbuttonslot = new JoyButtonSlot(JoyButtonSlot::MouseLB, JoyButtonSlot::JoyMouseButton, this); pbuttonslot = new JoyButtonSlot(JoyButtonSlot::MouseLB, JoyButtonSlot::JoyMouseButton, this);
} } else if (index == 2)
else if (index == 2)
{ {
pbuttonslot = new JoyButtonSlot(JoyButtonSlot::MouseRB, JoyButtonSlot::JoyMouseButton, this); pbuttonslot = new JoyButtonSlot(JoyButtonSlot::MouseRB, JoyButtonSlot::JoyMouseButton, this);
} } else if (index == 3)
else if (index == 3)
{ {
JoyAxisButton *nbutton = m_axis->getNAxisButton(); JoyAxisButton *nbutton = m_axis->getNAxisButton();
JoyAxisButton *pbutton = m_axis->getPAxisButton(); JoyAxisButton *pbutton = m_axis->getPAxisButton();
@@ -566,17 +577,14 @@ void AxisEditDialog::implementTriggerPresets(int index)
if (nbutton->getAssignedSlots()->length() > 0) if (nbutton->getAssignedSlots()->length() > 0)
{ {
QMetaObject::invokeMethod(nbutton, "clearSlotsEventReset", Qt::BlockingQueuedConnection, QMetaObject::invokeMethod(nbutton, "clearSlotsEventReset", Qt::BlockingQueuedConnection, Q_ARG(bool, false));
Q_ARG(bool, false));
refreshNButtonLabel(); refreshNButtonLabel();
} }
QMetaObject::invokeMethod(pbutton, "clearSlotsEventReset", QMetaObject::invokeMethod(pbutton, "clearSlotsEventReset", Q_ARG(bool, false));
Q_ARG(bool, false));
QMetaObject::invokeMethod(pbutton, "setAssignedSlot", Qt::BlockingQueuedConnection, QMetaObject::invokeMethod(pbutton, "setAssignedSlot", Qt::BlockingQueuedConnection,
Q_ARG(int, pbuttonslot->getSlotCode()), Q_ARG(int, pbuttonslot->getSlotCode()), Q_ARG(int, pbuttonslot->getSlotCodeAlias()),
Q_ARG(int, pbuttonslot->getSlotCodeAlias()),
Q_ARG(JoyButtonSlot::JoySlotInputAction, pbuttonslot->getSlotMode())); Q_ARG(JoyButtonSlot::JoySlotInputAction, pbuttonslot->getSlotMode()));
refreshPButtonLabel(); refreshPButtonLabel();
@@ -590,10 +598,12 @@ void AxisEditDialog::refreshPreset()
// Disconnect event associated with presetsComboBox so a change in the index does not // Disconnect event associated with presetsComboBox so a change in the index does not
// alter the axis buttons // alter the axis buttons
disconnect(ui->presetsComboBox, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this, &AxisEditDialog::implementPresets); disconnect(ui->presetsComboBox, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this,
&AxisEditDialog::implementPresets);
selectAxisCurrentPreset(); selectAxisCurrentPreset();
// Reconnect the event // Reconnect the event
connect(ui->presetsComboBox, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this, &AxisEditDialog::implementPresets); connect(ui->presetsComboBox, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this,
&AxisEditDialog::implementPresets);
} }
void AxisEditDialog::openMouseSettingsDialog() void AxisEditDialog::openMouseSettingsDialog()
@@ -624,8 +634,7 @@ void AxisEditDialog::updateWindowTitleAxisName()
if (!m_axis->getAxisName().isEmpty()) if (!m_axis->getAxisName().isEmpty())
{ {
temp.append(m_axis->getPartialName(false, true)); temp.append(m_axis->getPartialName(false, true));
} } else
else
{ {
temp.append(m_axis->getPartialName()); temp.append(m_axis->getPartialName());
} }
@@ -636,7 +645,8 @@ void AxisEditDialog::updateWindowTitleAxisName()
temp.append(" [").append(tr("Set %1").arg(setIndex)); temp.append(" [").append(tr("Set %1").arg(setIndex));
QString setName = m_axis->getParentSet()->getName(); QString setName = m_axis->getParentSet()->getName();
if (!setName.isEmpty()) temp.append(": ").append(setName); if (!setName.isEmpty())
temp.append(": ").append(setName);
temp.append("]"); temp.append("]");
} }
@@ -689,18 +699,19 @@ void AxisEditDialog::presetForThrottleChange(int index)
actAsTrigger = true; actAsTrigger = true;
} }
disconnect(ui->presetsComboBox, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this, &AxisEditDialog::implementPresets); disconnect(ui->presetsComboBox, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this,
&AxisEditDialog::implementPresets);
if (actAsTrigger) if (actAsTrigger)
{ {
buildTriggerPresetsMenu(); buildTriggerPresetsMenu();
selectTriggerPreset(); selectTriggerPreset();
} } else
else
{ {
buildAxisPresetsMenu(); buildAxisPresetsMenu();
selectAxisCurrentPreset(); selectAxisCurrentPreset();
} }
connect(ui->presetsComboBox, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this, &AxisEditDialog::implementPresets); connect(ui->presetsComboBox, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this,
&AxisEditDialog::implementPresets);
} }

View File

@@ -16,13 +16,11 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef AXISEDITDIALOG_H #ifndef AXISEDITDIALOG_H
#define AXISEDITDIALOG_H #define AXISEDITDIALOG_H
#include <QDialog> #include <QDialog>
class JoyAxis; class JoyAxis;
class SetAxisThrottleDialog; class SetAxisThrottleDialog;
class QWidget; class QWidget;
@@ -34,20 +32,20 @@ class AxisEditDialog;
class AxisEditDialog : public QDialog class AxisEditDialog : public QDialog
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit AxisEditDialog(JoyAxis *axis, bool keypadUnlocked, QWidget *parent=0); explicit AxisEditDialog(JoyAxis *axis, bool keypadUnlocked, QWidget *parent = 0);
AxisEditDialog(QWidget *parent=0); AxisEditDialog(QWidget *parent = 0);
~AxisEditDialog(); ~AxisEditDialog();
protected: protected:
void selectAxisCurrentPreset(); void selectAxisCurrentPreset();
void selectTriggerPreset(); void selectTriggerPreset();
void buildTriggerPresetsMenu(); void buildTriggerPresetsMenu();
void buildAxisPresetsMenu(); void buildAxisPresetsMenu();
private: private:
Ui::AxisEditDialog *ui; Ui::AxisEditDialog *ui;
JoyAxis *m_axis; JoyAxis *m_axis;
@@ -55,7 +53,7 @@ private:
SetAxisThrottleDialog *setAxisThrottleConfirm; SetAxisThrottleDialog *setAxisThrottleConfirm;
int initialThrottleState; int initialThrottleState;
private slots: private slots:
void implementAxisPresets(int index); void implementAxisPresets(int index);
void implementTriggerPresets(int index); void implementTriggerPresets(int index);
void implementPresets(int index); void implementPresets(int index);

View File

@@ -19,19 +19,18 @@
#include "axisvaluebox.h" #include "axisvaluebox.h"
#include "globalvariables.h" #include "globalvariables.h"
#include "messagehandler.h"
#include "joyaxis.h" #include "joyaxis.h"
#include "messagehandler.h"
#include <qdrawutil.h> #include <qdrawutil.h>
#include <QPainter>
#include <QPaintEvent>
#include <QResizeEvent>
#include <QDebug> #include <QDebug>
#include <QPaintEvent>
#include <QPainter>
#include <QResizeEvent>
AxisValueBox::AxisValueBox(QWidget *parent)
AxisValueBox::AxisValueBox(QWidget *parent) : : QWidget(parent)
QWidget(parent)
{ {
qInstallMessageHandler(MessageHandler::myMessageOutput); qInstallMessageHandler(MessageHandler::myMessageOutput);
@@ -54,11 +53,10 @@ void AxisValueBox::setThrottle(int throttle)
{ {
qInstallMessageHandler(MessageHandler::myMessageOutput); qInstallMessageHandler(MessageHandler::myMessageOutput);
qDebug() << "throttle value at start of function setThrottle: " << throttle; qDebug() << "throttle value at start of function setThrottle: " << throttle;
if ((throttle <= static_cast<int>(JoyAxis::PositiveHalfThrottle)) &&
if ((throttle <= static_cast<int>(JoyAxis::PositiveHalfThrottle)) && (throttle >= static_cast<int>(JoyAxis::NegativeHalfThrottle))) (throttle >= static_cast<int>(JoyAxis::NegativeHalfThrottle)))
{ {
qDebug() << "throttle variable has been set in setThrottle with: " << throttle; qDebug() << "throttle variable has been set in setThrottle with: " << throttle;
@@ -74,83 +72,79 @@ void AxisValueBox::setValue(int value)
{ {
qInstallMessageHandler(MessageHandler::myMessageOutput); qInstallMessageHandler(MessageHandler::myMessageOutput);
qDebug() << "Value for axis from value box at start is: " << value; qDebug() << "Value for axis from value box at start is: " << value;
qDebug() << "throttle variable has value: " << m_throttle; qDebug() << "throttle variable has value: " << m_throttle;
if ((value >= GlobalVariables::JoyAxis::AXISMIN) && (value <= GlobalVariables::JoyAxis::AXISMAX)) if ((value >= GlobalVariables::JoyAxis::AXISMIN) && (value <= GlobalVariables::JoyAxis::AXISMAX))
{ {
qDebug() << "Value for axis from value box is between : " << GlobalVariables::JoyAxis::AXISMIN << " and " << GlobalVariables::JoyAxis::AXISMAX; qDebug() << "Value for axis from value box is between : " << GlobalVariables::JoyAxis::AXISMIN << " and "
<< GlobalVariables::JoyAxis::AXISMAX;
switch (m_throttle)
switch(m_throttle)
{ {
case -2: case -2:
this->joyValue = (value <= 0) ? value : (-value); this->joyValue = (value <= 0) ? value : (-value);
break; break;
case -1: case -1:
this->joyValue = ((value + GlobalVariables::JoyAxis::AXISMIN) / 2); this->joyValue = ((value + GlobalVariables::JoyAxis::AXISMIN) / 2);
break; break;
case 0: case 0:
this->joyValue = value; this->joyValue = value;
break; break;
case 1: case 1:
this->joyValue = (value + GlobalVariables::JoyAxis::AXISMAX) / 2; this->joyValue = (value + GlobalVariables::JoyAxis::AXISMAX) / 2;
break; break;
case 2: case 2:
this->joyValue = (value >= 0) ? value : (-value); this->joyValue = (value >= 0) ? value : (-value);
break; break;
} }
} }
update(); update();
} }
void AxisValueBox::setValue(JoyAxis* axis, int value) void AxisValueBox::setValue(JoyAxis *axis, int value)
{ {
qInstallMessageHandler(MessageHandler::myMessageOutput); qInstallMessageHandler(MessageHandler::myMessageOutput);
m_axis = axis; m_axis = axis;
qDebug() << "Value for axis from value box at start is: " << value; qDebug() << "Value for axis from value box at start is: " << value;
qDebug() << "throttle variable has value: " << m_throttle; qDebug() << "throttle variable has value: " << m_throttle;
if ((value >= axis->getAxisMinCal()) && (value <= axis->getAxisMaxCal())) if ((value >= axis->getAxisMinCal()) && (value <= axis->getAxisMaxCal()))
{ {
qDebug() << "Value for axis from value box is between : " << axis->getAxisMinCal() << " and " << axis->getAxisMaxCal(); qDebug() << "Value for axis from value box is between : " << axis->getAxisMinCal() << " and "
<< axis->getAxisMaxCal();
switch (m_throttle)
switch(m_throttle)
{ {
case -2: case -2:
this->joyValue = (value <= 0) ? value : (-value); this->joyValue = (value <= 0) ? value : (-value);
break; break;
case -1: case -1:
this->joyValue = ((value + axis->getAxisMinCal()) / 2); this->joyValue = ((value + axis->getAxisMinCal()) / 2);
break; break;
case 0: case 0:
this->joyValue = value; this->joyValue = value;
break; break;
case 1: case 1:
this->joyValue = (value + axis->getAxisMaxCal()) / 2; this->joyValue = (value + axis->getAxisMaxCal()) / 2;
break; break;
case 2: case 2:
this->joyValue = (value >= 0) ? value : (-value); this->joyValue = (value >= 0) ? value : (-value);
break; break;
} }
} }
@@ -169,7 +163,7 @@ void AxisValueBox::setDeadZone(int deadZone)
update(); update();
} }
void AxisValueBox::setDeadZone(JoyAxis* axis, int deadZone) void AxisValueBox::setDeadZone(JoyAxis *axis, int deadZone)
{ {
qInstallMessageHandler(MessageHandler::myMessageOutput); qInstallMessageHandler(MessageHandler::myMessageOutput);
@@ -202,7 +196,7 @@ void AxisValueBox::setMaxZone(int maxZone)
update(); update();
} }
void AxisValueBox::setMaxZone(JoyAxis* axis, int maxZone) void AxisValueBox::setMaxZone(JoyAxis *axis, int maxZone)
{ {
qInstallMessageHandler(MessageHandler::myMessageOutput); qInstallMessageHandler(MessageHandler::myMessageOutput);
@@ -262,7 +256,7 @@ void AxisValueBox::paintEvent(QPaintEvent *event)
Q_UNUSED(event); Q_UNUSED(event);
QPainter paint (this); QPainter paint(this);
paint.setPen(palette().base().color()); paint.setPen(palette().base().color());
paint.setBrush(palette().base().color()); paint.setBrush(palette().base().color());
@@ -272,8 +266,7 @@ void AxisValueBox::paintEvent(QPaintEvent *event)
{ {
qDrawShadeRect(&paint, lboxstart, 0, lboxend, height(), palette(), true, 2, 0, &brush); qDrawShadeRect(&paint, lboxstart, 0, lboxend, height(), palette(), true, 2, 0, &brush);
qDrawShadeRect(&paint, rboxstart, 0, rboxend, height(), palette(), true, 2, 0, &brush); qDrawShadeRect(&paint, rboxstart, 0, rboxend, height(), palette(), true, 2, 0, &brush);
} } else
else
{ {
qDrawShadeRect(&paint, lboxstart, 0, singlewidth, height(), palette(), true, 2, 0, &brush); qDrawShadeRect(&paint, lboxstart, 0, singlewidth, height(), palette(), true, 2, 0, &brush);
} }
@@ -282,12 +275,10 @@ void AxisValueBox::paintEvent(QPaintEvent *event)
if (abs(joyValue) <= m_deadZone) if (abs(joyValue) <= m_deadZone)
{ {
innerColor = Qt::gray; innerColor = Qt::gray;
} } else if (abs(joyValue) >= m_maxZone)
else if (abs(joyValue) >= m_maxZone)
{ {
innerColor = Qt::red; innerColor = Qt::red;
} } else
else
{ {
innerColor = Qt::blue; innerColor = Qt::blue;
} }
@@ -301,8 +292,7 @@ void AxisValueBox::paintEvent(QPaintEvent *event)
if (joyValue > 0) if (joyValue > 0)
{ {
paint.drawRect(((m_throttle == 0) ? rboxstart : lboxstart) + 2, 2, barlength, boxheight); paint.drawRect(((m_throttle == 0) ? rboxstart : lboxstart) + 2, 2, barlength, boxheight);
} } else if (joyValue < 0)
else if (joyValue < 0)
{ {
paint.drawRect(lboxstart + barwidth - 2 - barlength, 2, barlength, boxheight); paint.drawRect(lboxstart + barwidth - 2 - barlength, 2, barlength, boxheight);
} }
@@ -323,15 +313,16 @@ void AxisValueBox::paintEvent(QPaintEvent *event)
paint.setPen(Qt::red); paint.setPen(Qt::red);
qDrawPlainRect(&paint, rboxstart + 2 + maxLine, 2, 4, boxheight + 2, Qt::black, 1, &maxBrush); qDrawPlainRect(&paint, rboxstart + 2 + maxLine, 2, 4, boxheight + 2, Qt::black, 1, &maxBrush);
qDrawPlainRect(&paint, lboxend - maxLine - 2, 2, 4, boxheight + 2, Qt::black, 1, &maxBrush); qDrawPlainRect(&paint, lboxend - maxLine - 2, 2, 4, boxheight + 2, Qt::black, 1, &maxBrush);
} } else if ((m_throttle == static_cast<int>(JoyAxis::PositiveThrottle)) ||
else if ((m_throttle == static_cast<int>(JoyAxis::PositiveThrottle)) || (m_throttle == static_cast<int>(JoyAxis::PositiveHalfThrottle))) (m_throttle == static_cast<int>(JoyAxis::PositiveHalfThrottle)))
{ {
qDrawPlainRect(&paint, lboxstart + deadLine - 2, 2, 4, boxheight + 2, Qt::black, 1, &brush); qDrawPlainRect(&paint, lboxstart + deadLine - 2, 2, 4, boxheight + 2, Qt::black, 1, &brush);
paint.setPen(Qt::red); paint.setPen(Qt::red);
qDrawPlainRect(&paint, lboxstart + maxLine, 2, 4, boxheight + 2, Qt::black, 1, &maxBrush); qDrawPlainRect(&paint, lboxstart + maxLine, 2, 4, boxheight + 2, Qt::black, 1, &maxBrush);
} }
else if ((m_throttle == static_cast<int>(JoyAxis::NegativeThrottle)) || (m_throttle == static_cast<int>(JoyAxis::NegativeHalfThrottle))) else if ((m_throttle == static_cast<int>(JoyAxis::NegativeThrottle)) ||
(m_throttle == static_cast<int>(JoyAxis::NegativeHalfThrottle)))
{ {
qDrawPlainRect(&paint, singleend - deadLine - 2, 2, 4, boxheight + 2, Qt::black, 1, &brush); qDrawPlainRect(&paint, singleend - deadLine - 2, 2, 4, boxheight + 2, Qt::black, 1, &brush);
paint.setPen(Qt::red); paint.setPen(Qt::red);
@@ -339,21 +330,22 @@ void AxisValueBox::paintEvent(QPaintEvent *event)
} }
} }
int AxisValueBox::getMaxAxValue()
int AxisValueBox::getMaxAxValue() { {
bool axisDefined = false; bool axisDefined = false;
if (m_axis != nullptr) axisDefined = true; if (m_axis != nullptr)
axisDefined = true;
return (axisDefined && (m_axis->getAxisMaxCal() != -1)) ? m_axis->getAxisMaxCal() : GlobalVariables::JoyAxis::AXISMAX; return (axisDefined && (m_axis->getAxisMaxCal() != -1)) ? m_axis->getAxisMaxCal() : GlobalVariables::JoyAxis::AXISMAX;
} }
int AxisValueBox::getMinAxValue()
int AxisValueBox::getMinAxValue() { {
bool axisDefined = false; bool axisDefined = false;
if (m_axis != nullptr) axisDefined = true; if (m_axis != nullptr)
axisDefined = true;
return (axisDefined && (m_axis->getAxisMinCal() != -1)) ? m_axis->getAxisMinCal() : GlobalVariables::JoyAxis::AXISMIN; return (axisDefined && (m_axis->getAxisMinCal() != -1)) ? m_axis->getAxisMinCal() : GlobalVariables::JoyAxis::AXISMIN;
} }

View File

@@ -16,7 +16,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef AXISVALUEBOX_H #ifndef AXISVALUEBOX_H
#define AXISVALUEBOX_H #define AXISVALUEBOX_H
@@ -29,7 +28,7 @@ class JoyAxis;
class AxisValueBox : public QWidget class AxisValueBox : public QWidget
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit AxisValueBox(QWidget *parent = nullptr); explicit AxisValueBox(QWidget *parent = nullptr);
int getDeadZone(); int getDeadZone();
@@ -39,21 +38,21 @@ public:
int getMinAxValue(); int getMinAxValue();
int getMaxAxValue(); int getMaxAxValue();
protected: protected:
virtual void resizeEvent(QResizeEvent *event); virtual void resizeEvent(QResizeEvent *event);
virtual void paintEvent(QPaintEvent *event); virtual void paintEvent(QPaintEvent *event);
public slots: public slots:
void setThrottle(int throttle); void setThrottle(int throttle);
void setValue(int value); void setValue(int value);
void setValue(JoyAxis* axis, int value); void setValue(JoyAxis *axis, int value);
void setDeadZone(int deadZone); void setDeadZone(int deadZone);
void setDeadZone(JoyAxis* axis, int deadZone); void setDeadZone(JoyAxis *axis, int deadZone);
void setMaxZone(int maxZone); void setMaxZone(int maxZone);
void setMaxZone(JoyAxis* axis, int deadZone); void setMaxZone(JoyAxis *axis, int deadZone);
private: private:
JoyAxis* m_axis; JoyAxis *m_axis;
int m_deadZone; int m_deadZone;
int m_maxZone; int m_maxZone;
int joyValue; int joyValue;
@@ -66,7 +65,6 @@ private:
int rboxend; int rboxend;
int singlewidth; int singlewidth;
int singleend; int singleend;
}; };
#endif // AXISVALUEBOX_H #endif // AXISVALUEBOX_H

View File

@@ -19,36 +19,34 @@
#include "buttoneditdialog.h" #include "buttoneditdialog.h"
#include "ui_buttoneditdialog.h" #include "ui_buttoneditdialog.h"
#include "messagehandler.h"
#include "joybutton.h"
#include "keyboard/virtualkeyboardmousewidget.h"
#include "advancebuttondialog.h" #include "advancebuttondialog.h"
#include "inputdevice.h" #include "inputdevice.h"
#include "joybutton.h"
#include "keyboard/virtualkeyboardmousewidget.h"
#include "messagehandler.h"
#include "quicksetdialog.h" #include "quicksetdialog.h"
#include "event.h"
#include "antkeymapper.h" #include "antkeymapper.h"
#include "eventhandlerfactory.h"
#include "setjoystick.h"
#include "inputdevice.h"
#include "common.h" #include "common.h"
#include "event.h"
#include "eventhandlerfactory.h"
#include "inputdevice.h"
#include "setjoystick.h"
#include <QApplication> #include <QApplication>
#include <QDebug> #include <QDebug>
#include <QPointer>
#include <QtGlobal>
#include <QWidget>
#include <QKeyEvent> #include <QKeyEvent>
#include <QMessageBox> #include <QMessageBox>
#include <QPointer>
#include <QWidget>
#include <QtGlobal>
ButtonEditDialog *ButtonEditDialog::instance = nullptr;
ButtonEditDialog* ButtonEditDialog::instance = nullptr; ButtonEditDialog::ButtonEditDialog(InputDevice *joystick, bool isNumKeypad, QWidget *parent)
: QDialog(parent, Qt::Window)
, helper()
ButtonEditDialog::ButtonEditDialog(InputDevice* joystick, bool isNumKeypad, QWidget *parent) : , ui(new Ui::ButtonEditDialog)
QDialog(parent, Qt::Window),
helper(),
ui(new Ui::ButtonEditDialog)
{ {
ui->setupUi(this); ui->setupUi(this);
@@ -81,22 +79,22 @@ ButtonEditDialog::ButtonEditDialog(InputDevice* joystick, bool isNumKeypad, QWid
ignoreRelease = false; ignoreRelease = false;
qDebug() << "Thread in ButtonEditDialog"; qDebug() << "Thread in ButtonEditDialog";
PadderCommon::inputDaemonMutex.lock(); PadderCommon::inputDaemonMutex.lock();
ui->virtualKeyMouseTabWidget->hide(); ui->virtualKeyMouseTabWidget->hide();
ui->virtualKeyMouseTabWidget->deleteLater(); ui->virtualKeyMouseTabWidget->deleteLater();
ui->virtualKeyMouseTabWidget = new VirtualKeyboardMouseWidget(joystick , &helper, m_isNumKeypad, currentQuickDialog, nullptr, this); ui->virtualKeyMouseTabWidget =
new VirtualKeyboardMouseWidget(joystick, &helper, m_isNumKeypad, currentQuickDialog, nullptr, this);
ui->verticalLayout->insertWidget(1, ui->virtualKeyMouseTabWidget); ui->verticalLayout->insertWidget(1, ui->virtualKeyMouseTabWidget);
PadderCommon::inputDaemonMutex.unlock(); PadderCommon::inputDaemonMutex.unlock();
connect(qApp, &QApplication::focusChanged, this, &ButtonEditDialog::checkForKeyboardWidgetFocus); connect(qApp, &QApplication::focusChanged, this, &ButtonEditDialog::checkForKeyboardWidgetFocus);
connect(ui->virtualKeyMouseTabWidget, &VirtualKeyboardMouseWidget::selectionCleared, this, &ButtonEditDialog::refreshSlotSummaryLabel); connect(ui->virtualKeyMouseTabWidget, &VirtualKeyboardMouseWidget::selectionCleared, this,
&ButtonEditDialog::refreshSlotSummaryLabel);
connect(this, &ButtonEditDialog::keyGrabbed, this, &ButtonEditDialog::processSlotAssignment); connect(this, &ButtonEditDialog::keyGrabbed, this, &ButtonEditDialog::processSlotAssignment);
connect(this, &ButtonEditDialog::selectionCleared, this, &ButtonEditDialog::clearButtonSlots); connect(this, &ButtonEditDialog::selectionCleared, this, &ButtonEditDialog::clearButtonSlots);
@@ -104,17 +102,18 @@ ButtonEditDialog::ButtonEditDialog(InputDevice* joystick, bool isNumKeypad, QWid
connect(ui->toggleCheckBox, &QCheckBox::clicked, this, &ButtonEditDialog::changeToggleSetting); connect(ui->toggleCheckBox, &QCheckBox::clicked, this, &ButtonEditDialog::changeToggleSetting);
connect(ui->turboCheckBox, &QCheckBox::clicked, this, &ButtonEditDialog::changeTurboSetting); connect(ui->turboCheckBox, &QCheckBox::clicked, this, &ButtonEditDialog::changeTurboSetting);
connect(ui->advancedPushButton, &QPushButton::clicked, this, &ButtonEditDialog::openAdvancedDialog); connect(ui->advancedPushButton, &QPushButton::clicked, this, &ButtonEditDialog::openAdvancedDialog);
connect(this, &ButtonEditDialog::advancedDialogOpened, ui->virtualKeyMouseTabWidget, &VirtualKeyboardMouseWidget::establishVirtualKeyboardAdvancedSignalConnections); connect(this, &ButtonEditDialog::advancedDialogOpened, ui->virtualKeyMouseTabWidget,
connect(this, &ButtonEditDialog::advancedDialogOpened, ui->virtualKeyMouseTabWidget, &VirtualKeyboardMouseWidget::establishVirtualMouseAdvancedSignalConnections); &VirtualKeyboardMouseWidget::establishVirtualKeyboardAdvancedSignalConnections);
connect(this, &ButtonEditDialog::advancedDialogOpened, ui->virtualKeyMouseTabWidget,
&VirtualKeyboardMouseWidget::establishVirtualMouseAdvancedSignalConnections);
refreshForLastBtn(); refreshForLastBtn();
} }
ButtonEditDialog::ButtonEditDialog(JoyButton *button, InputDevice *joystick, bool isNumKeypad, QWidget *parent)
ButtonEditDialog::ButtonEditDialog(JoyButton* button, InputDevice* joystick, bool isNumKeypad, QWidget *parent) : : QDialog(parent, Qt::Window)
QDialog(parent, Qt::Window), , helper()
helper(), , ui(new Ui::ButtonEditDialog)
ui(new Ui::ButtonEditDialog)
{ {
ui->setupUi(this); ui->setupUi(this);
@@ -151,42 +150,41 @@ ButtonEditDialog::ButtonEditDialog(JoyButton* button, InputDevice* joystick, boo
ui->virtualKeyMouseTabWidget->hide(); ui->virtualKeyMouseTabWidget->hide();
ui->virtualKeyMouseTabWidget->deleteLater(); ui->virtualKeyMouseTabWidget->deleteLater();
ui->virtualKeyMouseTabWidget = new VirtualKeyboardMouseWidget(joystick, &helper, m_isNumKeypad, currentQuickDialog, button, this); ui->virtualKeyMouseTabWidget =
new VirtualKeyboardMouseWidget(joystick, &helper, m_isNumKeypad, currentQuickDialog, button, this);
ui->verticalLayout->insertWidget(1, ui->virtualKeyMouseTabWidget); ui->verticalLayout->insertWidget(1, ui->virtualKeyMouseTabWidget);
PadderCommon::inputDaemonMutex.unlock(); PadderCommon::inputDaemonMutex.unlock();
connect(qApp, &QApplication::focusChanged, this, &ButtonEditDialog::checkForKeyboardWidgetFocus); connect(qApp, &QApplication::focusChanged, this, &ButtonEditDialog::checkForKeyboardWidgetFocus);
connect(ui->virtualKeyMouseTabWidget, &VirtualKeyboardMouseWidget::selectionCleared, this, &ButtonEditDialog::refreshSlotSummaryLabel); connect(ui->virtualKeyMouseTabWidget, &VirtualKeyboardMouseWidget::selectionCleared, this,
&ButtonEditDialog::refreshSlotSummaryLabel);
connect(this, &ButtonEditDialog::keyGrabbed, this, &ButtonEditDialog::processSlotAssignment); connect(this, &ButtonEditDialog::keyGrabbed, this, &ButtonEditDialog::processSlotAssignment);
connect(this, &ButtonEditDialog::selectionCleared, this, &ButtonEditDialog::clearButtonSlots); // used to clear button sets connect(this, &ButtonEditDialog::selectionCleared, this,
&ButtonEditDialog::clearButtonSlots); // used to clear button sets
connect(ui->toggleCheckBox, &QCheckBox::clicked, this, &ButtonEditDialog::changeToggleSetting); connect(ui->toggleCheckBox, &QCheckBox::clicked, this, &ButtonEditDialog::changeToggleSetting);
connect(ui->turboCheckBox, &QCheckBox::clicked, this, &ButtonEditDialog::changeTurboSetting); connect(ui->turboCheckBox, &QCheckBox::clicked, this, &ButtonEditDialog::changeTurboSetting);
connect(ui->advancedPushButton, &QPushButton::clicked, this, &ButtonEditDialog::openAdvancedDialog); connect(ui->advancedPushButton, &QPushButton::clicked, this, &ButtonEditDialog::openAdvancedDialog);
connect(this, &ButtonEditDialog::advancedDialogOpened, ui->virtualKeyMouseTabWidget, &VirtualKeyboardMouseWidget::establishVirtualKeyboardAdvancedSignalConnections); connect(this, &ButtonEditDialog::advancedDialogOpened, ui->virtualKeyMouseTabWidget,
connect(this, &ButtonEditDialog::advancedDialogOpened, ui->virtualKeyMouseTabWidget, &VirtualKeyboardMouseWidget::establishVirtualMouseAdvancedSignalConnections); &VirtualKeyboardMouseWidget::establishVirtualKeyboardAdvancedSignalConnections);
connect(this, &ButtonEditDialog::advancedDialogOpened, ui->virtualKeyMouseTabWidget,
&VirtualKeyboardMouseWidget::establishVirtualMouseAdvancedSignalConnections);
refreshForLastBtn(); refreshForLastBtn();
} }
// for tests // for tests
ButtonEditDialog::ButtonEditDialog(QWidget *parent) : ButtonEditDialog::ButtonEditDialog(QWidget *parent)
QDialog(parent, Qt::Window), : QDialog(parent, Qt::Window)
helper(), , helper()
ui(new Ui::ButtonEditDialog) , ui(new Ui::ButtonEditDialog)
{ {
}
ButtonEditDialog* ButtonEditDialog::getInstance()
{
return instance;
} }
ButtonEditDialog *ButtonEditDialog::getInstance() { return instance; }
void ButtonEditDialog::checkForKeyboardWidgetFocus(QWidget *old, QWidget *now) void ButtonEditDialog::checkForKeyboardWidgetFocus(QWidget *old, QWidget *now)
{ {
@@ -195,12 +193,10 @@ void ButtonEditDialog::checkForKeyboardWidgetFocus(QWidget *old, QWidget *now)
Q_UNUSED(old); Q_UNUSED(old);
Q_UNUSED(now); Q_UNUSED(now);
if (ui->virtualKeyMouseTabWidget->hasFocus() && if (ui->virtualKeyMouseTabWidget->hasFocus() && ui->virtualKeyMouseTabWidget->isKeyboardTabVisible())
ui->virtualKeyMouseTabWidget->isKeyboardTabVisible())
{ {
grabKeyboard(); grabKeyboard();
} } else
else
{ {
releaseKeyboard(); releaseKeyboard();
} }
@@ -215,7 +211,6 @@ ButtonEditDialog::~ButtonEditDialog()
delete ui; delete ui;
} }
void ButtonEditDialog::keyPressEvent(QKeyEvent *event) void ButtonEditDialog::keyPressEvent(QKeyEvent *event)
{ {
qInstallMessageHandler(MessageHandler::myMessageOutput); qInstallMessageHandler(MessageHandler::myMessageOutput);
@@ -223,24 +218,24 @@ void ButtonEditDialog::keyPressEvent(QKeyEvent *event)
bool ignore = false; bool ignore = false;
// Ignore the following keys that might // Ignore the following keys that might
// trigger an event in QDialog::keyPressEvent // trigger an event in QDialog::keyPressEvent
switch(event->key()) switch (event->key())
{ {
case Qt::Key_Escape: case Qt::Key_Escape:
case Qt::Key_Right: case Qt::Key_Right:
case Qt::Key_Down: case Qt::Key_Down:
case Qt::Key_Up: case Qt::Key_Up:
case Qt::Key_Left: case Qt::Key_Left:
case Qt::Key_Enter: case Qt::Key_Enter:
case Qt::Key_Return: case Qt::Key_Return: {
{ ignore = true;
ignore = true; break;
break; }
}
default: default:
break; break;
} }
if (!ignore) QDialog::keyPressEvent(event); if (!ignore)
QDialog::keyPressEvent(event);
} }
void ButtonEditDialog::keyReleaseEvent(QKeyEvent *event) void ButtonEditDialog::keyReleaseEvent(QKeyEvent *event)
@@ -252,101 +247,92 @@ void ButtonEditDialog::keyReleaseEvent(QKeyEvent *event)
if (ui->actionNameLineEdit->hasFocus() || ui->buttonNameLineEdit->hasFocus()) if (ui->actionNameLineEdit->hasFocus() || ui->buttonNameLineEdit->hasFocus())
{ {
QDialog::keyReleaseEvent(event); QDialog::keyReleaseEvent(event);
} } else if (ui->virtualKeyMouseTabWidget->isKeyboardTabVisible())
else if (ui->virtualKeyMouseTabWidget->isKeyboardTabVisible())
{ {
int controlcode = event->nativeScanCode(); int controlcode = event->nativeScanCode();
int virtualactual = event->nativeVirtualKey(); int virtualactual = event->nativeVirtualKey();
BaseEventHandler *handler = EventHandlerFactory::getInstance()->handler(); BaseEventHandler *handler = EventHandlerFactory::getInstance()->handler();
#if defined(WITH_X11) #if defined(WITH_X11)
int finalvirtual = 0; int finalvirtual = 0;
int checkalias = 0; int checkalias = 0;
if (QApplication::platformName() == QStringLiteral("xcb")) if (QApplication::platformName() == QStringLiteral("xcb"))
{ {
// Obtain group 1 X11 keysym. Removes effects from modifiers. // Obtain group 1 X11 keysym. Removes effects from modifiers.
finalvirtual = X11KeyCodeToX11KeySym(controlcode); finalvirtual = X11KeyCodeToX11KeySym(controlcode);
#ifdef WITH_UINPUT
if (handler->getIdentifier() == "uinput")
{
// Find Qt Key corresponding to X11 KeySym.
Q_ASSERT(AntKeyMapper::getInstance()->hasNativeKeyMapper());
QtKeyMapperBase *x11KeyMapper = AntKeyMapper::getInstance()->getNativeKeyMapper();
Q_ASSERT(x11KeyMapper != nullptr);
checkalias = x11KeyMapper->returnQtKey(finalvirtual);
finalvirtual = AntKeyMapper::getInstance()->returnVirtualKey(checkalias); // Find corresponding Linux input key for the Qt key.
}
#endif
#ifdef WITH_XTEST
BACKEND_ELSE_IF (handler->getIdentifier() == "xtest")
{
// Check for alias against group 1 keysym.
checkalias = AntKeyMapper::getInstance()->returnQtKey(finalvirtual);
}
#endif
}
else
{
// Not running on xcb platform.
finalvirtual = controlcode;
checkalias = AntKeyMapper::getInstance()->returnQtKey(finalvirtual);
}
#else
int finalvirtual = 0;
int checkalias = 0;
if (QApplication::platformName() == QStringLiteral("xcb"))
{
finalvirtual = AntKeyMapper::getInstance()->returnVirtualKey(event->key());
checkalias = AntKeyMapper::getInstance()->returnQtKey(finalvirtual);
}
else
{
// Not running on xcb platform.
finalvirtual = controlcode;
checkalias = AntKeyMapper::getInstance()->returnQtKey(finalvirtual);
}
#ifdef WITH_UINPUT
if (handler->getIdentifier() == "uinput")
{
// Find Qt Key corresponding to X11 KeySym.
Q_ASSERT(AntKeyMapper::getInstance()->hasNativeKeyMapper());
QtKeyMapperBase *x11KeyMapper = AntKeyMapper::getInstance()->getNativeKeyMapper();
Q_ASSERT(x11KeyMapper != nullptr);
checkalias = x11KeyMapper->returnQtKey(finalvirtual);
finalvirtual = AntKeyMapper::getInstance()->returnVirtualKey(
checkalias); // Find corresponding Linux input key for the Qt key.
}
#endif #endif
#ifdef WITH_XTEST
BACKEND_ELSE_IF(handler->getIdentifier() == "xtest")
{
// Check for alias against group 1 keysym.
checkalias = AntKeyMapper::getInstance()->returnQtKey(finalvirtual);
}
#endif
} else
{
// Not running on xcb platform.
finalvirtual = controlcode;
checkalias = AntKeyMapper::getInstance()->returnQtKey(finalvirtual);
}
#else
int finalvirtual = 0;
int checkalias = 0;
if (QApplication::platformName() == QStringLiteral("xcb"))
{
finalvirtual = AntKeyMapper::getInstance()->returnVirtualKey(event->key());
checkalias = AntKeyMapper::getInstance()->returnQtKey(finalvirtual);
} else
{
// Not running on xcb platform.
finalvirtual = controlcode;
checkalias = AntKeyMapper::getInstance()->returnQtKey(finalvirtual);
}
#endif
if (!ignoreRelease && (event->modifiers() & Qt::ControlModifier) && (event->key() == Qt::Key_X)) if (!ignoreRelease && (event->modifiers() & Qt::ControlModifier) && (event->key() == Qt::Key_X))
{ {
controlcode = 0; controlcode = 0;
ignoreRelease = true; ignoreRelease = true;
emit selectionCleared(); emit selectionCleared();
} } else if (!ignoreRelease && (controlcode <= 0))
else if (!ignoreRelease && (controlcode <= 0))
{ {
controlcode = 0; controlcode = 0;
} } else if (ignoreRelease)
else if (ignoreRelease)
{ {
controlcode = 0; controlcode = 0;
ignoreRelease = false; ignoreRelease = false;
} }
if (controlcode > 0 && (checkalias > 0) && (finalvirtual > 0)) if (controlcode > 0 && (checkalias > 0) && (finalvirtual > 0))
{ {
JoyButtonSlot *tempslot = new JoyButtonSlot(finalvirtual, checkalias, JoyButtonSlot::JoyKeyboard, this); JoyButtonSlot *tempslot = new JoyButtonSlot(finalvirtual, checkalias, JoyButtonSlot::JoyKeyboard, this);
emit keyGrabbed(tempslot); emit keyGrabbed(tempslot);
} } else if ((controlcode > 0) && (virtualactual > 0))
else if ((controlcode > 0) && (virtualactual > 0))
{ {
JoyButtonSlot *tempslot = new JoyButtonSlot(virtualactual, JoyButtonSlot::JoyKeyboard, this); JoyButtonSlot *tempslot = new JoyButtonSlot(virtualactual, JoyButtonSlot::JoyKeyboard, this);
emit keyGrabbed(tempslot); emit keyGrabbed(tempslot);
} } else
else
{ {
QDialog::keyReleaseEvent(event); QDialog::keyReleaseEvent(event);
} }
} } else
else
{ {
QDialog::keyReleaseEvent(event); QDialog::keyReleaseEvent(event);
} }
@@ -356,25 +342,34 @@ void ButtonEditDialog::refreshSlotSummaryLabel()
{ {
qInstallMessageHandler(MessageHandler::myMessageOutput); qInstallMessageHandler(MessageHandler::myMessageOutput);
if (lastJoyButton != nullptr) ui->slotSummaryLabel->setText(lastJoyButton->getSlotsString().replace("&", "&&")); if (lastJoyButton != nullptr)
else ui->slotSummaryLabel->setText(tr("No button")); ui->slotSummaryLabel->setText(lastJoyButton->getSlotsString().replace("&", "&&"));
else
ui->slotSummaryLabel->setText(tr("No button"));
} }
void ButtonEditDialog::changeToggleSetting() void ButtonEditDialog::changeToggleSetting()
{ {
qInstallMessageHandler(MessageHandler::myMessageOutput); qInstallMessageHandler(MessageHandler::myMessageOutput);
if (lastJoyButton != nullptr) lastJoyButton->setToggle(ui->toggleCheckBox->isChecked()); if (lastJoyButton != nullptr)
else QMessageBox::information(this, tr("Last button"), tr("To change settings for last button, it must be at least one assignment from keyboard to gamepad")); lastJoyButton->setToggle(ui->toggleCheckBox->isChecked());
else
QMessageBox::information(
this, tr("Last button"),
tr("To change settings for last button, it must be at least one assignment from keyboard to gamepad"));
} }
void ButtonEditDialog::changeTurboSetting() void ButtonEditDialog::changeTurboSetting()
{ {
qInstallMessageHandler(MessageHandler::myMessageOutput); qInstallMessageHandler(MessageHandler::myMessageOutput);
if (lastJoyButton != nullptr) lastJoyButton->setUseTurbo(ui->turboCheckBox->isChecked()); if (lastJoyButton != nullptr)
else QMessageBox::information(this, tr("Last button"), tr("To change settings of turbo for last button, it must be at least one assignment from keyboard to gamepad")); lastJoyButton->setUseTurbo(ui->turboCheckBox->isChecked());
else
QMessageBox::information(
this, tr("Last button"),
tr("To change settings of turbo for last button, it must be at least one assignment from keyboard to gamepad"));
} }
void ButtonEditDialog::openAdvancedDialog() void ButtonEditDialog::openAdvancedDialog()
@@ -394,30 +389,41 @@ void ButtonEditDialog::openAdvancedDialog()
disconnect(this, &ButtonEditDialog::selectionCleared, nullptr, nullptr); disconnect(this, &ButtonEditDialog::selectionCleared, nullptr, nullptr);
disconnect(this, &ButtonEditDialog::selectionFinished, nullptr, nullptr); disconnect(this, &ButtonEditDialog::selectionFinished, nullptr, nullptr);
connect(dialog, &AdvanceButtonDialog::finished, ui->virtualKeyMouseTabWidget, &VirtualKeyboardMouseWidget::establishVirtualKeyboardSingleSignalConnections); connect(dialog, &AdvanceButtonDialog::finished, ui->virtualKeyMouseTabWidget,
connect(dialog, &AdvanceButtonDialog::finished, ui->virtualKeyMouseTabWidget, &VirtualKeyboardMouseWidget::establishVirtualMouseSignalConnections); &VirtualKeyboardMouseWidget::establishVirtualKeyboardSingleSignalConnections);
connect(dialog, &AdvanceButtonDialog::finished, ui->virtualKeyMouseTabWidget,
&VirtualKeyboardMouseWidget::establishVirtualMouseSignalConnections);
connect(dialog, &AdvanceButtonDialog::finished, this, &ButtonEditDialog::closedAdvancedDialog); connect(dialog, &AdvanceButtonDialog::finished, this, &ButtonEditDialog::closedAdvancedDialog);
connect(dialog, &AdvanceButtonDialog::turboButtonEnabledChange, this, &ButtonEditDialog::setTurboButtonEnabled); connect(dialog, &AdvanceButtonDialog::turboButtonEnabledChange, this, &ButtonEditDialog::setTurboButtonEnabled);
connect(this, &ButtonEditDialog::sendTempSlotToAdvanced, dialog, &AdvanceButtonDialog::placeNewSlot); connect(this, &ButtonEditDialog::sendTempSlotToAdvanced, dialog, &AdvanceButtonDialog::placeNewSlot);
connect(this, &ButtonEditDialog::keyGrabbed, dialog, &AdvanceButtonDialog::placeNewSlot); connect(this, &ButtonEditDialog::keyGrabbed, dialog, &AdvanceButtonDialog::placeNewSlot);
connect(this, &ButtonEditDialog::selectionCleared, dialog, &AdvanceButtonDialog::clearAllSlots); connect(this, &ButtonEditDialog::selectionCleared, dialog, &AdvanceButtonDialog::clearAllSlots);
connect(ui->virtualKeyMouseTabWidget, static_cast<void (VirtualKeyboardMouseWidget::*)(JoyButtonSlot*)>(&VirtualKeyboardMouseWidget::selectionMade), dialog, &AdvanceButtonDialog::placeNewSlot); connect(ui->virtualKeyMouseTabWidget,
connect(ui->virtualKeyMouseTabWidget, static_cast<void (VirtualKeyboardMouseWidget::*)(int,int)>(&VirtualKeyboardMouseWidget::selectionMade), this, &ButtonEditDialog::createTempSlot); static_cast<void (VirtualKeyboardMouseWidget::*)(JoyButtonSlot *)>(
connect(ui->virtualKeyMouseTabWidget, &VirtualKeyboardMouseWidget::selectionCleared, dialog, &AdvanceButtonDialog::clearAllSlots); &VirtualKeyboardMouseWidget::selectionMade),
dialog, &AdvanceButtonDialog::placeNewSlot);
connect(ui->virtualKeyMouseTabWidget,
static_cast<void (VirtualKeyboardMouseWidget::*)(int, int)>(&VirtualKeyboardMouseWidget::selectionMade),
this, &ButtonEditDialog::createTempSlot);
connect(ui->virtualKeyMouseTabWidget, &VirtualKeyboardMouseWidget::selectionCleared, dialog,
&AdvanceButtonDialog::clearAllSlots);
connect(this, &ButtonEditDialog::finished, dialog, &AdvanceButtonDialog::close); connect(this, &ButtonEditDialog::finished, dialog, &AdvanceButtonDialog::close);
emit advancedDialogOpened(); emit advancedDialogOpened();
} } else
else
{ {
QMessageBox::information(this, tr("No choice"), tr("Before you open window with advanced settins, you have to choice a key")); QMessageBox::information(this, tr("No choice"),
tr("Before you open window with advanced settins, you have to choice a key"));
} }
} else { } else
{
QMessageBox::information(this, tr("Last button"), tr("To open advanced dialog, it's needed to map at least one button from keyboard to gamepad")); QMessageBox::information(
this, tr("Last button"),
tr("To open advanced dialog, it's needed to map at least one button from keyboard to gamepad"));
} }
} }
@@ -425,8 +431,7 @@ void ButtonEditDialog::createTempSlot(int keycode, int alias)
{ {
qInstallMessageHandler(MessageHandler::myMessageOutput); qInstallMessageHandler(MessageHandler::myMessageOutput);
JoyButtonSlot *slot = new JoyButtonSlot(keycode, alias, JoyButtonSlot *slot = new JoyButtonSlot(keycode, alias, JoyButtonSlot::JoyKeyboard, this);
JoyButtonSlot::JoyKeyboard, this);
emit sendTempSlotToAdvanced(slot); emit sendTempSlotToAdvanced(slot);
} }
@@ -434,14 +439,14 @@ void ButtonEditDialog::checkTurboSetting(bool state)
{ {
qInstallMessageHandler(MessageHandler::myMessageOutput); qInstallMessageHandler(MessageHandler::myMessageOutput);
if (lastJoyButton != nullptr) { if (lastJoyButton != nullptr)
{
if (lastJoyButton->containsSequence()) if (lastJoyButton->containsSequence())
{ {
ui->turboCheckBox->setChecked(false); ui->turboCheckBox->setChecked(false);
ui->turboCheckBox->setEnabled(false); ui->turboCheckBox->setEnabled(false);
} } else
else
{ {
ui->turboCheckBox->setChecked(state); ui->turboCheckBox->setChecked(state);
ui->turboCheckBox->setEnabled(true); ui->turboCheckBox->setEnabled(true);
@@ -462,13 +467,14 @@ void ButtonEditDialog::closedAdvancedDialog()
refreshForLastBtn(); refreshForLastBtn();
disconnect(ui->virtualKeyMouseTabWidget, static_cast<void (VirtualKeyboardMouseWidget::*)(int,int)>(&VirtualKeyboardMouseWidget::selectionMade), this, nullptr); disconnect(ui->virtualKeyMouseTabWidget,
static_cast<void (VirtualKeyboardMouseWidget::*)(int, int)>(&VirtualKeyboardMouseWidget::selectionMade), this,
nullptr);
// Re-connect previously disconnected event // Re-connect previously disconnected event
connect(this, &ButtonEditDialog::keyGrabbed, this, &ButtonEditDialog::processSlotAssignment); connect(this, &ButtonEditDialog::keyGrabbed, this, &ButtonEditDialog::processSlotAssignment);
connect(this, &ButtonEditDialog::selectionCleared, this, &ButtonEditDialog::clearButtonSlots); connect(this, &ButtonEditDialog::selectionCleared, this, &ButtonEditDialog::clearButtonSlots);
connect(this, &ButtonEditDialog::selectionCleared, this, &ButtonEditDialog::sendSelectionFinished); connect(this, &ButtonEditDialog::selectionCleared, this, &ButtonEditDialog::sendSelectionFinished);
} }
void ButtonEditDialog::processSlotAssignment(JoyButtonSlot *tempslot) void ButtonEditDialog::processSlotAssignment(JoyButtonSlot *tempslot)
@@ -477,9 +483,10 @@ void ButtonEditDialog::processSlotAssignment(JoyButtonSlot *tempslot)
if (withoutQuickSetDialog) if (withoutQuickSetDialog)
{ {
invokeMethodLastBtn(lastJoyButton, &helper, "setAssignedSlot", tempslot->getSlotCode(), tempslot->getSlotCodeAlias(), -1, tempslot->getSlotMode(), false, false, Qt::QueuedConnection, Qt::QueuedConnection, Qt::QueuedConnection); invokeMethodLastBtn(lastJoyButton, &helper, "setAssignedSlot", tempslot->getSlotCode(), tempslot->getSlotCodeAlias(),
} -1, tempslot->getSlotMode(), false, false, Qt::QueuedConnection, Qt::QueuedConnection,
else Qt::QueuedConnection);
} else
{ {
if ((currentQuickDialog == nullptr) && (!buttonEventInterval.isValid() || (buttonEventInterval.elapsed() > 1000))) if ((currentQuickDialog == nullptr) && (!buttonEventInterval.isValid() || (buttonEventInterval.elapsed() > 1000)))
{ {
@@ -488,10 +495,14 @@ void ButtonEditDialog::processSlotAssignment(JoyButtonSlot *tempslot)
// it's good for oversensitive buttons and axes, which can // it's good for oversensitive buttons and axes, which can
// create QuickSetDialog windows many times for one key // create QuickSetDialog windows many times for one key
if (!buttonEventInterval.isValid()) buttonEventInterval.start(); if (!buttonEventInterval.isValid())
else buttonEventInterval.restart(); buttonEventInterval.start();
else
buttonEventInterval.restart();
currentQuickDialog = new QuickSetDialog(joystick, &helper, "setAssignedSlot", tempslot->getSlotCode(), tempslot->getSlotCodeAlias(), -1, tempslot->getSlotMode(), false, false, this); currentQuickDialog =
new QuickSetDialog(joystick, &helper, "setAssignedSlot", tempslot->getSlotCode(),
tempslot->getSlotCodeAlias(), -1, tempslot->getSlotMode(), false, false, this);
currentQuickDialog->show(); currentQuickDialog->show();
connect(currentQuickDialog, &QuickSetDialog::finished, this, &ButtonEditDialog::nullifyDialogPointer); connect(currentQuickDialog, &QuickSetDialog::finished, this, &ButtonEditDialog::nullifyDialogPointer);
} }
@@ -507,8 +518,9 @@ void ButtonEditDialog::clearButtonSlots()
if (lastJoyButton != nullptr) if (lastJoyButton != nullptr)
QMetaObject::invokeMethod(lastJoyButton, "clearSlotsEventReset", Q_ARG(bool, false)); QMetaObject::invokeMethod(lastJoyButton, "clearSlotsEventReset", Q_ARG(bool, false));
else else
QMessageBox::information(this, tr("Last button"), tr("Slots for button couldn't be cleared, because there was not any set button from keyboard for gamepad. Map at least one button from keyboard to gamepad")); QMessageBox::information(this, tr("Last button"),
tr("Slots for button couldn't be cleared, because there was not any set button from "
"keyboard for gamepad. Map at least one button from keyboard to gamepad"));
} }
void ButtonEditDialog::sendSelectionFinished() void ButtonEditDialog::sendSelectionFinished()
@@ -522,9 +534,13 @@ void ButtonEditDialog::updateWindowTitleButtonName()
{ {
qInstallMessageHandler(MessageHandler::myMessageOutput); qInstallMessageHandler(MessageHandler::myMessageOutput);
if (lastJoyButton != nullptr) { if (lastJoyButton != nullptr)
{
QString temp = QString(tr("As last gamepad button has been set")).append(" \"").append(lastJoyButton->getPartialName(false, true)).append("\" "); QString temp = QString(tr("As last gamepad button has been set"))
.append(" \"")
.append(lastJoyButton->getPartialName(false, true))
.append("\" ");
if (lastJoyButton->getParentSet()->getIndex() != 0) if (lastJoyButton->getParentSet()->getIndex() != 0)
{ {
@@ -532,20 +548,21 @@ void ButtonEditDialog::updateWindowTitleButtonName()
temp.append(" [").append(tr("Index %1").arg(setIndex)); temp.append(" [").append(tr("Index %1").arg(setIndex));
QString setName = lastJoyButton->getParentSet()->getName(); QString setName = lastJoyButton->getParentSet()->getName();
if (!setName.isEmpty()) temp.append(": ").append(setName); if (!setName.isEmpty())
temp.append(": ").append(setName);
temp.append("]"); temp.append("]");
} }
setWindowTitle(temp); setWindowTitle(temp);
} else { } else
{
setWindowTitle(tr("Choose your keyboard key")); setWindowTitle(tr("Choose your keyboard key"));
} }
} }
void ButtonEditDialog::nullifyDialogPointer() void ButtonEditDialog::nullifyDialogPointer()
{ {
qInstallMessageHandler(MessageHandler::myMessageOutput); qInstallMessageHandler(MessageHandler::myMessageOutput);
@@ -560,10 +577,11 @@ void ButtonEditDialog::nullifyDialogPointer()
refreshForLastBtn(); refreshForLastBtn();
} }
void ButtonEditDialog::refreshForLastBtn()
{
void ButtonEditDialog::refreshForLastBtn() { if (lastJoyButton != nullptr)
{
if (lastJoyButton != nullptr) {
ui->slotSummaryLabel->setText(lastJoyButton->getSlotsString()); ui->slotSummaryLabel->setText(lastJoyButton->getSlotsString());
@@ -578,9 +596,10 @@ void ButtonEditDialog::refreshForLastBtn() {
if (!lastJoyButton->getButtonName().isEmpty()) if (!lastJoyButton->getButtonName().isEmpty())
ui->buttonNameLineEdit->setText(lastJoyButton->getButtonName()); ui->buttonNameLineEdit->setText(lastJoyButton->getButtonName());
if (lastJoyButton != nullptr) { if (lastJoyButton != nullptr)
{
QListIterator<JoyButtonSlot*> iter(*(lastJoyButton->getAssignedSlots())); QListIterator<JoyButtonSlot *> iter(*(lastJoyButton->getAssignedSlots()));
ui->virtualKeyMouseTabWidget->disableMouseSettingButton(); ui->virtualKeyMouseTabWidget->disableMouseSettingButton();
@@ -588,17 +607,16 @@ void ButtonEditDialog::refreshForLastBtn() {
{ {
JoyButtonSlot *buttonslot = iter.next(); JoyButtonSlot *buttonslot = iter.next();
switch(buttonslot->getSlotMode()) switch (buttonslot->getSlotMode())
{ {
case JoyButtonSlot::JoyMouseMovement: case JoyButtonSlot::JoyMouseMovement:
case JoyButtonSlot::JoyMouseButton: case JoyButtonSlot::JoyMouseButton:
ui->virtualKeyMouseTabWidget->enableMouseSettingButton(); ui->virtualKeyMouseTabWidget->enableMouseSettingButton();
break; break;
default: default:
break; break;
} }
} }
} }
@@ -612,13 +630,16 @@ void ButtonEditDialog::refreshForLastBtn() {
} }
update(); update();
} }
void ButtonEditDialog::invokeMethodLastBtn(JoyButton* lastJoyBtn, ButtonEditDialogHelper* helper, const char* invokeString, int code, int alias, int index, JoyButtonSlot::JoySlotInputAction mode, bool withClear, bool withTrue, Qt::ConnectionType connTypeForAlias, Qt::ConnectionType connTypeForNothing, Qt::ConnectionType connTypeForAll) void ButtonEditDialog::invokeMethodLastBtn(JoyButton *lastJoyBtn, ButtonEditDialogHelper *helper, const char *invokeString,
int code, int alias, int index, JoyButtonSlot::JoySlotInputAction mode,
bool withClear, bool withTrue, Qt::ConnectionType connTypeForAlias,
Qt::ConnectionType connTypeForNothing, Qt::ConnectionType connTypeForAll)
{ {
QPointer<JoyButton> lastBtn = lastJoyBtn; QPointer<JoyButton> lastBtn = lastJoyBtn;
if (helper != nullptr) helper = new ButtonEditDialogHelper(); if (helper != nullptr)
helper = new ButtonEditDialogHelper();
QPointer<ButtonEditDialogHelper> btnEditDHelper = helper; QPointer<ButtonEditDialogHelper> btnEditDHelper = helper;
@@ -627,56 +648,45 @@ void ButtonEditDialog::invokeMethodLastBtn(JoyButton* lastJoyBtn, ButtonEditDial
helper->setThisButton(lastJoyBtn); helper->setThisButton(lastJoyBtn);
helper->moveToThread(lastJoyBtn->thread()); helper->moveToThread(lastJoyBtn->thread());
qDebug() << "Thread in QuickSetDialog";
qDebug() << "Thread in QuickSetDialog"; if (withClear)
QMetaObject::invokeMethod(lastJoyBtn, "clearSlotsEventReset", Q_ARG(bool, withTrue));
if (withClear) QMetaObject::invokeMethod(lastJoyBtn, "clearSlotsEventReset", Q_ARG(bool, withTrue));
// when alias exists but not index // when alias exists but not index
if ((alias != -1) && (index == -1)) { if ((alias != -1) && (index == -1))
{
QMetaObject::invokeMethod(helper, invokeString, connTypeForAlias, QMetaObject::invokeMethod(helper, invokeString, connTypeForAlias, Q_ARG(int, code), Q_ARG(int, alias),
Q_ARG(int, code),
Q_ARG(int, alias),
Q_ARG(JoyButtonSlot::JoySlotInputAction, mode)); Q_ARG(JoyButtonSlot::JoySlotInputAction, mode));
// when alias doesn't exists and index too // when alias doesn't exists and index too
} else if ((alias == -1) && (index == -1)) { } else if ((alias == -1) && (index == -1))
{
QMetaObject::invokeMethod(helper, invokeString, connTypeForNothing, QMetaObject::invokeMethod(helper, invokeString, connTypeForNothing, Q_ARG(int, code),
Q_ARG(int, code),
Q_ARG(JoyButtonSlot::JoySlotInputAction, mode)); Q_ARG(JoyButtonSlot::JoySlotInputAction, mode));
// when all exist (code, alias, index) // when all exist (code, alias, index)
} else { } else
{
if (lastJoyBtn->isPartVDPad()) connTypeForAll = Qt::BlockingQueuedConnection; if (lastJoyBtn->isPartVDPad())
connTypeForAll = Qt::BlockingQueuedConnection;
QMetaObject::invokeMethod(helper, invokeString, connTypeForAll, QMetaObject::invokeMethod(helper, invokeString, connTypeForAll, Q_ARG(int, code), Q_ARG(int, alias),
Q_ARG(int, code), Q_ARG(int, index), Q_ARG(JoyButtonSlot::JoySlotInputAction, mode));
Q_ARG(int, alias),
Q_ARG(int, index),
Q_ARG(JoyButtonSlot::JoySlotInputAction, mode));
} }
} }
if (lastBtn.isNull()) lastBtn.clear(); if (lastBtn.isNull())
if (btnEditDHelper.isNull()) btnEditDHelper.clear(); lastBtn.clear();
if (btnEditDHelper.isNull())
btnEditDHelper.clear();
} }
JoyButton *ButtonEditDialog::getLastJoyButton() { return lastJoyButton; }
JoyButton* ButtonEditDialog::getLastJoyButton() { void ButtonEditDialog::setUpLastJoyButton(JoyButton *newButton) { lastJoyButton = newButton; }
return lastJoyButton; ButtonEditDialogHelper &ButtonEditDialog::getHelperLocal() { return helper; }
}
void ButtonEditDialog::setUpLastJoyButton(JoyButton * newButton) {
lastJoyButton = newButton;
}
ButtonEditDialogHelper& ButtonEditDialog::getHelperLocal() {
return helper;
}

View File

@@ -16,7 +16,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef BUTTONEDITDIALOGTWO_H #ifndef BUTTONEDITDIALOGTWO_H
#define BUTTONEDITDIALOGTWO_H #define BUTTONEDITDIALOGTWO_H
@@ -38,28 +37,32 @@ class ButtonEditDialog;
class ButtonEditDialog : public QDialog class ButtonEditDialog : public QDialog
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit ButtonEditDialog(JoyButton* button, InputDevice* joystick, bool isNumKeypad, QWidget *parent = nullptr); // called for chosen button explicit ButtonEditDialog(JoyButton *button, InputDevice *joystick, bool isNumKeypad,
explicit ButtonEditDialog(InputDevice* joystick, bool isNumKeypad, QWidget *parent = nullptr); // Accessed by pressing the "Quick Set" button QWidget *parent = nullptr); // called for chosen button
explicit ButtonEditDialog(InputDevice *joystick, bool isNumKeypad,
QWidget *parent = nullptr); // Accessed by pressing the "Quick Set" button
ButtonEditDialog(QWidget *parent = 0); ButtonEditDialog(QWidget *parent = 0);
~ButtonEditDialog(); ~ButtonEditDialog();
static ButtonEditDialog* getInstance(); static ButtonEditDialog *getInstance();
JoyButton* getLastJoyButton(); JoyButton *getLastJoyButton();
void setUpLastJoyButton(JoyButton*); void setUpLastJoyButton(JoyButton *);
void refreshForLastBtn(); void refreshForLastBtn();
void invokeMethodLastBtn(JoyButton* lastJoyBtn, ButtonEditDialogHelper* helper, const char* invokeString, int code, int alias, int index, JoyButtonSlot::JoySlotInputAction mode, bool withClear, bool withTrue, Qt::ConnectionType connTypeForAlias, Qt::ConnectionType connTypeForNothing, Qt::ConnectionType connTypeForAll); void invokeMethodLastBtn(JoyButton *lastJoyBtn, ButtonEditDialogHelper *helper, const char *invokeString, int code,
int alias, int index, JoyButtonSlot::JoySlotInputAction mode, bool withClear, bool withTrue,
protected: Qt::ConnectionType connTypeForAlias, Qt::ConnectionType connTypeForNothing,
Qt::ConnectionType connTypeForAll);
protected:
virtual void keyReleaseEvent(QKeyEvent *event); virtual void keyReleaseEvent(QKeyEvent *event);
virtual void keyPressEvent(QKeyEvent *event); virtual void keyPressEvent(QKeyEvent *event);
private:
private:
ButtonEditDialogHelper helper; ButtonEditDialogHelper helper;
Ui::ButtonEditDialog *ui; Ui::ButtonEditDialog *ui;
ButtonEditDialogHelper& getHelperLocal(); ButtonEditDialogHelper &getHelperLocal();
QElapsedTimer buttonEventInterval; QElapsedTimer buttonEventInterval;
InputDevice *joystick; InputDevice *joystick;
@@ -67,11 +70,11 @@ private:
bool ignoreRelease; bool ignoreRelease;
bool withoutQuickSetDialog; bool withoutQuickSetDialog;
bool m_isNumKeypad; bool m_isNumKeypad;
JoyButton* lastJoyButton; JoyButton *lastJoyButton;
static ButtonEditDialog *instance; static ButtonEditDialog *instance;
signals: signals:
void advancedDialogOpened(); void advancedDialogOpened();
void sendTempSlotToAdvanced(JoyButtonSlot *tempslot); void sendTempSlotToAdvanced(JoyButtonSlot *tempslot);
void keyGrabbed(JoyButtonSlot *tempslot); void keyGrabbed(JoyButtonSlot *tempslot);
@@ -79,7 +82,7 @@ signals:
void selectionFinished(); void selectionFinished();
void buttonDialogClosed(); void buttonDialogClosed();
private slots: private slots:
void nullifyDialogPointer(); void nullifyDialogPointer();
void refreshSlotSummaryLabel(); void refreshSlotSummaryLabel();
void changeToggleSetting(); void changeToggleSetting();

View File

@@ -19,36 +19,34 @@
#include "ui_calibration.h" #include "ui_calibration.h"
#include "globalvariables.h" #include "globalvariables.h"
#include "inputdevice.h"
#include "joybuttontypes/joycontrolstickmodifierbutton.h"
#include "joycontrolstick.h" #include "joycontrolstick.h"
#include "joytabwidget.h" #include "joytabwidget.h"
#include "inputdevice.h"
#include "messagehandler.h" #include "messagehandler.h"
#include "joybuttontypes/joycontrolstickmodifierbutton.h"
#include <SDL2/SDL_joystick.h> #include <SDL2/SDL_joystick.h>
#include <QtConcurrent>
#include <QFuture>
#include <QTabWidget>
#include <QProgressBar>
#include <QMessageBox>
#include <QLayoutItem>
#include <QPointer>
#include <QDebug> #include <QDebug>
#include <QFuture>
#include <QLayoutItem>
#include <QMessageBox>
#include <QPointer>
#include <QProgressBar>
#include <QTabWidget>
#include <QtConcurrent>
Calibration::Calibration(InputDevice *joystick, QWidget *parent)
: QWidget(parent)
Calibration::Calibration(InputDevice* joystick, QWidget *parent) : , ui(new Ui::Calibration)
QWidget(parent), , currentJoystick(joystick)
ui(new Ui::Calibration), , helper(currentJoystick->getActiveSetJoystick()->getJoyStick(0))
currentJoystick(joystick),
helper(currentJoystick->getActiveSetJoystick()->getJoyStick(0))
{ {
ui->setupUi(this); ui->setupUi(this);
qInstallMessageHandler(MessageHandler::myMessageOutput); qInstallMessageHandler(MessageHandler::myMessageOutput);
setAttribute( Qt::WA_DeleteOnClose, true ); setAttribute(Qt::WA_DeleteOnClose, true);
setWindowTitle(tr("Calibration")); setWindowTitle(tr("Calibration"));
sumX = 0; sumX = 0;
@@ -87,8 +85,8 @@ Calibration::Calibration(InputDevice* joystick, QWidget *parent) :
if (controlstick.isNull()) if (controlstick.isNull())
controlstick.clear(); controlstick.clear();
QList<JoyControlStick*> sticksList = currentJoystick->getActiveSetJoystick()->getSticks().values(); QList<JoyControlStick *> sticksList = currentJoystick->getActiveSetJoystick()->getSticks().values();
QListIterator<JoyControlStick*> currStick(sticksList); QListIterator<JoyControlStick *> currStick(sticksList);
while (currStick.hasNext()) while (currStick.hasNext())
{ {
@@ -98,17 +96,14 @@ Calibration::Calibration(InputDevice* joystick, QWidget *parent) :
connect(currentJoystick, &InputDevice::destroyed, this, &Calibration::close); connect(currentJoystick, &InputDevice::destroyed, this, &Calibration::close);
connect(ui->saveBtn, &QPushButton::clicked, this, &Calibration::saveSettings); connect(ui->saveBtn, &QPushButton::clicked, this, &Calibration::saveSettings);
connect(ui->cancelBtn, &QPushButton::clicked, this, &Calibration::close); connect(ui->cancelBtn, &QPushButton::clicked, this, &Calibration::close);
connect(ui->axesBox, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this, &Calibration::createAxesConnection); connect(ui->axesBox, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this,
&Calibration::createAxesConnection);
connect(ui->startButton, &QPushButton::clicked, this, &Calibration::startCalibration); connect(ui->startButton, &QPushButton::clicked, this, &Calibration::startCalibration);
connect(ui->resetBtn, &QPushButton::clicked, [this](bool clicked) connect(ui->resetBtn, &QPushButton::clicked, [this](bool clicked) { resetSettings(false, clicked); });
{
resetSettings(false, clicked);
});
update(); update();
} }
Calibration::~Calibration() Calibration::~Calibration()
{ {
qInstallMessageHandler(MessageHandler::myMessageOutput); qInstallMessageHandler(MessageHandler::myMessageOutput);
@@ -122,27 +117,27 @@ Calibration::~Calibration()
*/ */
void Calibration::resetSettings(bool silentReset, bool) void Calibration::resetSettings(bool silentReset, bool)
{ {
if (!silentReset) { if (!silentReset)
{
QMessageBox msgBox; QMessageBox msgBox;
msgBox.setText(tr("Do you really want to reset settings of current axis?")); msgBox.setText(tr("Do you really want to reset settings of current axis?"));
msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No); msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
switch(msgBox.exec()) switch (msgBox.exec())
{ {
case QMessageBox::Yes: case QMessageBox::Yes:
restoreCalValues(); restoreCalValues();
ui->steps->clear(); ui->steps->clear();
break; break;
case QMessageBox::No: case QMessageBox::No:
break; break;
default: default:
break; break;
} }
} } else
else
{ {
restoreCalValues(); restoreCalValues();
ui->steps->clear(); ui->steps->clear();
@@ -205,46 +200,41 @@ void Calibration::restoreCalValues()
* @param min value for Y - negative value * @param min value for Y - negative value
* @return Nothing * @return Nothing
*/ */
void Calibration::setQuadraticZoneCalibrated(int &max_axis_val_x, int &min_axis_val_x, int &max_axis_val_y, int &min_axis_val_y) { void Calibration::setQuadraticZoneCalibrated(int &max_axis_val_x, int &min_axis_val_x, int &max_axis_val_y,
int &min_axis_val_y)
{
if (max_axis_val_x > abs(min_axis_val_x)) max_axis_val_x = abs(min_axis_val_x); if (max_axis_val_x > abs(min_axis_val_x))
else min_axis_val_x = -(max_axis_val_x); max_axis_val_x = abs(min_axis_val_x);
else
min_axis_val_x = -(max_axis_val_x);
if (max_axis_val_y > abs(min_axis_val_y)) max_axis_val_y = abs(min_axis_val_y); if (max_axis_val_y > abs(min_axis_val_y))
else min_axis_val_y = -(max_axis_val_y); max_axis_val_y = abs(min_axis_val_y);
else
min_axis_val_y = -(max_axis_val_y);
} }
/** /**
* @brief Moves deadzone position after changing center position of axes * @brief Moves deadzone position after changing center position of axes
* @return Moved deadzone position * @return Moved deadzone position
*/ */
int Calibration::calibratedDeadZone(int center, int deadzone) int Calibration::calibratedDeadZone(int center, int deadzone) { return (center + deadzone); }
{
return (center + deadzone);
}
int Calibration::fakeMapFunc(const int &x) { return x; }
int Calibration::fakeMapFunc(const int &x) void Calibration::summarizeValues(int &numbFromList, const int &mappednumb) { numbFromList += mappednumb; }
{
return x;
}
void Calibration::summarizeValues(int &numbFromList, const int &mappednumb)
{
numbFromList += mappednumb;
}
void Calibration::getMinVal(int &numbFromList, const int &mappednumb) void Calibration::getMinVal(int &numbFromList, const int &mappednumb)
{ {
if (numbFromList > mappednumb) numbFromList = mappednumb; if (numbFromList > mappednumb)
numbFromList = mappednumb;
} }
void Calibration::getMaxVal(int &numbFromList, const int &mappednumb) void Calibration::getMaxVal(int &numbFromList, const int &mappednumb)
{ {
if (numbFromList < mappednumb) numbFromList = mappednumb; if (numbFromList < mappednumb)
numbFromList = mappednumb;
} }
/** /**
@@ -257,29 +247,29 @@ void Calibration::startCalibration()
bool confirmed = true; bool confirmed = true;
if (stick->wasCalibrated()) { if (stick->wasCalibrated())
{
QMessageBox msgBox; QMessageBox msgBox;
msgBox.setText(tr("Calibration was saved for the preset. Do you really want to reset settings?")); msgBox.setText(tr("Calibration was saved for the preset. Do you really want to reset settings?"));
msgBox.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel); msgBox.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel);
switch(msgBox.exec()) switch (msgBox.exec())
{ {
case QMessageBox::Ok: case QMessageBox::Ok:
confirmed = true; confirmed = true;
ui->resetBtn->setEnabled(false); ui->resetBtn->setEnabled(false);
break; break;
case QMessageBox::Cancel: case QMessageBox::Cancel:
confirmed = false; confirmed = false;
break; break;
default: default:
confirmed = true; confirmed = true;
break; break;
} }
} } else
else
{ {
center_calibrated_x = 0; center_calibrated_x = 0;
center_calibrated_y = 0; center_calibrated_y = 0;
@@ -295,8 +285,8 @@ void Calibration::startCalibration()
y_es_val.clear(); y_es_val.clear();
} }
if ((joyAxisX != nullptr) && (joyAxisY != nullptr) && confirmed)
if ((joyAxisX != nullptr) && (joyAxisY != nullptr) && confirmed) { {
center_calibrated_x = 0; center_calibrated_x = 0;
center_calibrated_y = 0; center_calibrated_y = 0;
@@ -314,7 +304,8 @@ void Calibration::startCalibration()
stick->setCalibrationFlag(false); stick->setCalibrationFlag(false);
calibrated = false; calibrated = false;
ui->steps->setText(tr("Place the joystick in the center position.\n\nIt's the part, where often you don't have to move. Just skip it in such situation.")); ui->steps->setText(tr("Place the joystick in the center position.\n\nIt's the part, where often you don't have to "
"move. Just skip it in such situation."));
this->setWindowTitle(tr("Calibrating center")); this->setWindowTitle(tr("Calibrating center"));
ui->startButton->setText(tr("Start second step")); ui->startButton->setText(tr("Start second step"));
update(); update();
@@ -327,13 +318,14 @@ void Calibration::startCalibration()
QFuture<int> resY = QtConcurrent::mappedReduced(yValues, &Calibration::fakeMapFunc, &Calibration::summarizeValues); QFuture<int> resY = QtConcurrent::mappedReduced(yValues, &Calibration::fakeMapFunc, &Calibration::summarizeValues);
sumY = resY.result(); sumY = resY.result();
if ((sumX != 0) && (sumY != 0))
if ((sumX != 0) && (sumY != 0)) { {
center_calibrated_x = sumX / x_es_val.count(); center_calibrated_x = sumX / x_es_val.count();
center_calibrated_y = sumY / y_es_val.count(); center_calibrated_y = sumY / y_es_val.count();
} else { } else
{
center_calibrated_x = 0; center_calibrated_x = 0;
center_calibrated_y = 0; center_calibrated_y = 0;
@@ -364,48 +356,48 @@ void Calibration::startSecondStep()
{ {
qInstallMessageHandler(MessageHandler::myMessageOutput); qInstallMessageHandler(MessageHandler::myMessageOutput);
if ((joyAxisX != nullptr) && (joyAxisY != nullptr)) { if ((joyAxisX != nullptr) && (joyAxisY != nullptr))
{
ui->steps->setText(tr("\nPlace the joystick in the top-left corner many times"));
this->setWindowTitle(tr("Calibrating position"));
update();
qDebug() << "X_ES_VAL: " << x_es_val.count(QString("-"));
qDebug() << "Y_ES_VAL: " << y_es_val.count(QString("-"));
if (enoughProb(x_es_val.count(QString("-")), y_es_val.count(QString("-")), QString("-")))
{
int min_x = 0;
int min_y = 0;
QList<int> xValues = x_es_val.values(QString("-"));
QFuture<int> resX = QtConcurrent::mappedReduced(xValues, &Calibration::fakeMapFunc, &Calibration::getMinVal);
min_x = resX.result();
QList<int> yValues = y_es_val.values(QString("-"));
QFuture<int> resY = QtConcurrent::mappedReduced(yValues, &Calibration::fakeMapFunc, &Calibration::getMinVal);
min_y = resY.result();
min_axis_val_x = min_x;
min_axis_val_y = min_y;
QString text = ui->Informations->text();
text.append(tr("\n\nX: %1").arg(min_axis_val_x));
text.append(tr("\nY: %1").arg(min_axis_val_y));
ui->Informations->setText(text);
this->text = text;
x_es_val.clear();
y_es_val.clear();
sumX = 0;
sumY = 0;
ui->steps->setText(tr("\nPlace the joystick in the top-left corner many times"));
this->setWindowTitle(tr("Calibrating position"));
update(); update();
disconnect(ui->startButton, &QPushButton::clicked, this, nullptr);
qDebug() << "X_ES_VAL: " << x_es_val.count(QString("-")); connect(ui->startButton, &QPushButton::clicked, this, &Calibration::startLastStep);
qDebug() << "Y_ES_VAL: " << y_es_val.count(QString("-")); }
if (enoughProb(x_es_val.count(QString("-")), y_es_val.count(QString("-")), QString("-"))) {
int min_x = 0;
int min_y = 0;
QList<int> xValues = x_es_val.values(QString("-"));
QFuture<int> resX = QtConcurrent::mappedReduced(xValues, &Calibration::fakeMapFunc, &Calibration::getMinVal);
min_x = resX.result();
QList<int> yValues = y_es_val.values(QString("-"));
QFuture<int> resY = QtConcurrent::mappedReduced(yValues, &Calibration::fakeMapFunc, &Calibration::getMinVal);
min_y = resY.result();
min_axis_val_x = min_x;
min_axis_val_y = min_y;
QString text = ui->Informations->text();
text.append(tr("\n\nX: %1").arg(min_axis_val_x));
text.append(tr("\nY: %1").arg(min_axis_val_y));
ui->Informations->setText(text);
this->text = text;
x_es_val.clear();
y_es_val.clear();
sumX = 0;
sumY = 0;
update();
disconnect(ui->startButton, &QPushButton::clicked, this, nullptr);
connect(ui->startButton, &QPushButton::clicked, this, &Calibration::startLastStep);
}
} }
} }
@@ -417,69 +409,70 @@ void Calibration::startLastStep()
{ {
qInstallMessageHandler(MessageHandler::myMessageOutput); qInstallMessageHandler(MessageHandler::myMessageOutput);
if ((joyAxisX != nullptr) && (joyAxisY != nullptr)) { if ((joyAxisX != nullptr) && (joyAxisY != nullptr))
{
ui->steps->setText(tr("\nPlace the joystick in the bottom-right corner")); ui->steps->setText(tr("\nPlace the joystick in the bottom-right corner"));
this->setWindowTitle(tr("Calibrating position")); this->setWindowTitle(tr("Calibrating position"));
ui->startButton->setText(tr("Start final step")); ui->startButton->setText(tr("Start final step"));
update();
if (enoughProb(x_es_val.count(QString("+")), y_es_val.count(QString("+")), QString("+")))
{
int max_x = 0;
int max_y = 0;
QList<int> xValues = x_es_val.values(QString("+"));
QFuture<int> resX = QtConcurrent::mappedReduced(xValues, &Calibration::fakeMapFunc, &Calibration::getMaxVal);
max_x = resX.result();
QList<int> yValues = y_es_val.values(QString("+"));
QFuture<int> resY = QtConcurrent::mappedReduced(yValues, &Calibration::fakeMapFunc, &Calibration::getMaxVal);
max_y = resY.result();
max_axis_val_x = max_x;
max_axis_val_y = max_y;
QString text2 = ui->Informations->text();
text2.append(tr("\n\nX: %1").arg(max_axis_val_x));
text2.append(tr("\nY: %1").arg(max_axis_val_y));
ui->Informations->setText(text2);
this->text = text2;
update(); update();
if (enoughProb(x_es_val.count(QString("+")), y_es_val.count(QString("+")), QString("+"))) { setQuadraticZoneCalibrated(max_axis_val_x, min_axis_val_x, max_axis_val_y, min_axis_val_y);
int max_x = 0; deadzone_calibrated_x = (max_axis_val_y + max_axis_val_x) / 4;
int max_y = 0; deadzone_calibrated_y = (max_axis_val_y + max_axis_val_x) / 4;
QList<int> xValues = x_es_val.values(QString("+")); QString text3 = ui->Informations->text();
QFuture<int> resX = QtConcurrent::mappedReduced(xValues, &Calibration::fakeMapFunc, &Calibration::getMaxVal); text3.append(tr("\n\nrange X: %1 - %2").arg(min_axis_val_x).arg(max_axis_val_x));
max_x = resX.result(); text3.append(tr("\nrange Y: %1 - %2").arg(min_axis_val_y).arg(max_axis_val_y));
text3.append(tr("\n\ndeadzone X: %1").arg(deadzone_calibrated_x));
QList<int> yValues = y_es_val.values(QString("+")); text3.append(tr("\ndeadzone Y: %1").arg(deadzone_calibrated_y));
QFuture<int> resY = QtConcurrent::mappedReduced(yValues, &Calibration::fakeMapFunc, &Calibration::getMaxVal); ui->Informations->setText(text3);
max_y = resY.result(); this->text = text3;
max_axis_val_x = max_x;
max_axis_val_y = max_y;
QString text2 = ui->Informations->text();
text2.append(tr("\n\nX: %1").arg(max_axis_val_x));
text2.append(tr("\nY: %1").arg(max_axis_val_y));
ui->Informations->setText(text2);
this->text = text2;
update();
setQuadraticZoneCalibrated(max_axis_val_x, min_axis_val_x, max_axis_val_y, min_axis_val_y);
deadzone_calibrated_x = (max_axis_val_y + max_axis_val_x)/4;
deadzone_calibrated_y = (max_axis_val_y + max_axis_val_x)/4;
QString text3 = ui->Informations->text();
text3.append(tr("\n\nrange X: %1 - %2").arg(min_axis_val_x).arg(max_axis_val_x));
text3.append(tr("\nrange Y: %1 - %2").arg(min_axis_val_y).arg(max_axis_val_y));
text3.append(tr("\n\ndeadzone X: %1").arg(deadzone_calibrated_x));
text3.append(tr("\ndeadzone Y: %1").arg(deadzone_calibrated_y));
ui->Informations->setText(text3);
this->text = text3;
if (stick != nullptr)
{
ui->saveBtn->setEnabled(true);
}
ui->steps->setText(tr("\n---Calibration done!---\n"));
ui->startButton->setText(tr("Start calibration"));
this->setWindowTitle(tr("Calibration"));
update();
x_es_val.clear();
y_es_val.clear();
sumX = 0;
sumY = 0;
disconnect(ui->startButton, &QPushButton::clicked, this, nullptr);
connect(ui->startButton, &QPushButton::clicked, this, &Calibration::startCalibration);
if (stick != nullptr)
{
ui->saveBtn->setEnabled(true);
} }
}
ui->steps->setText(tr("\n---Calibration done!---\n"));
ui->startButton->setText(tr("Start calibration"));
this->setWindowTitle(tr("Calibration"));
update();
x_es_val.clear();
y_es_val.clear();
sumX = 0;
sumY = 0;
disconnect(ui->startButton, &QPushButton::clicked, this, nullptr);
connect(ui->startButton, &QPushButton::clicked, this, &Calibration::startCalibration);
}
}
} }
/** /**
@@ -490,38 +483,39 @@ void Calibration::saveSettings()
{ {
qInstallMessageHandler(MessageHandler::myMessageOutput); qInstallMessageHandler(MessageHandler::myMessageOutput);
if ((joyAxisX != nullptr) && (joyAxisY != nullptr)) { if ((joyAxisX != nullptr) && (joyAxisY != nullptr))
{
joyAxisX->setAxisCenterCal(center_calibrated_x); joyAxisX->setAxisCenterCal(center_calibrated_x);
joyAxisY->setAxisCenterCal(center_calibrated_y); joyAxisY->setAxisCenterCal(center_calibrated_y);
joyAxisX->setDeadZone(deadzone_calibrated_x); joyAxisX->setDeadZone(deadzone_calibrated_x);
joyAxisY->setDeadZone(deadzone_calibrated_y); joyAxisY->setDeadZone(deadzone_calibrated_y);
stick->setDeadZone(deadzone_calibrated_x); stick->setDeadZone(deadzone_calibrated_x);
joyAxisX->setAxisMinCal(min_axis_val_x); joyAxisX->setAxisMinCal(min_axis_val_x);
joyAxisY->setAxisMinCal(min_axis_val_y); joyAxisY->setAxisMinCal(min_axis_val_y);
joyAxisX->setAxisMaxCal(max_axis_val_x); joyAxisX->setAxisMaxCal(max_axis_val_x);
joyAxisY->setAxisMaxCal(max_axis_val_y); joyAxisY->setAxisMaxCal(max_axis_val_y);
joyAxisX->setMaxZoneValue(max_axis_val_x); joyAxisX->setMaxZoneValue(max_axis_val_x);
joyAxisY->setMaxZoneValue(max_axis_val_y); joyAxisY->setMaxZoneValue(max_axis_val_y);
stick->setMaxZone(max_axis_val_x); stick->setMaxZone(max_axis_val_x);
calibrated = true; calibrated = true;
stick->setCalibrationFlag(true); stick->setCalibrationFlag(true);
stick->setCalibrationSummary(this->text); stick->setCalibrationSummary(this->text);
ui->resetBtn->setEnabled(true); ui->resetBtn->setEnabled(true);
ui->saveBtn->setEnabled(false); ui->saveBtn->setEnabled(false);
ui->stickStatusBoxWidget->update(); ui->stickStatusBoxWidget->update();
update(); update();
QMessageBox::information(this, tr("Save"), tr("Calibration values have been saved")); QMessageBox::information(this, tr("Save"), tr("Calibration values have been saved"));
} }
} }
/** /**
@@ -536,16 +530,18 @@ bool Calibration::enoughProb(int x_count, int y_count, QString character)
bool enough = true; bool enough = true;
if ((x_count < 5) || (y_count < 5)) { if ((x_count < 5) || (y_count < 5))
{
if (character == QString("-")) if (character == QString("-"))
{ {
enough = false; enough = false;
QMessageBox::information(this, tr("Dead zone calibration"), tr("You have to move axes to the top-left corner at least five times.")); QMessageBox::information(this, tr("Dead zone calibration"),
} tr("You have to move axes to the top-left corner at least five times."));
else if (character == QString("+")) } else if (character == QString("+"))
{ {
enough = false; enough = false;
QMessageBox::information(this, tr("Dead zone calibration"), tr("You have to move axes to the bottom-right corner at least five times.")); QMessageBox::information(this, tr("Dead zone calibration"),
tr("You have to move axes to the bottom-right corner at least five times."));
} }
} }
@@ -564,15 +560,16 @@ int Calibration::chooseMinMax(QString min_max_sign, QList<int> ax_values)
int min_max = 0; int min_max = 0;
foreach(int val, ax_values) foreach (int val, ax_values)
{ {
if (min_max_sign == QString("+")) if (min_max_sign == QString("+"))
{ {
if (min_max < val) min_max = val; if (min_max < val)
} min_max = val;
else } else
{ {
if (min_max > val) min_max = val; if (min_max > val)
min_max = val;
} }
} }
@@ -588,10 +585,14 @@ void Calibration::checkX(int value)
{ {
qInstallMessageHandler(MessageHandler::myMessageOutput); qInstallMessageHandler(MessageHandler::myMessageOutput);
if (value > 0) { if (value > 0)
if (x_es_val.count(QString("+")) <= 100) x_es_val.insert(QString("+"), value); {
} else if (value < 0) { if (x_es_val.count(QString("+")) <= 100)
if (x_es_val.count(QString("-")) <= 100) x_es_val.insert(QString("-"), value); x_es_val.insert(QString("+"), value);
} else if (value < 0)
{
if (x_es_val.count(QString("-")) <= 100)
x_es_val.insert(QString("-"), value);
} }
axisBarX->setValue(value); axisBarX->setValue(value);
@@ -607,12 +608,14 @@ void Calibration::checkY(int value)
{ {
qInstallMessageHandler(MessageHandler::myMessageOutput); qInstallMessageHandler(MessageHandler::myMessageOutput);
if (value > 0) { if (value > 0)
{
if (y_es_val.count(QString("+")) <= 100) if (y_es_val.count(QString("+")) <= 100)
y_es_val.insert(QString("+"), value); y_es_val.insert(QString("+"), value);
} else if (value < 0) { } else if (value < 0)
{
if (y_es_val.count(QString("-")) <= 100) if (y_es_val.count(QString("-")) <= 100)
y_es_val.insert(QString("-"), value); y_es_val.insert(QString("-"), value);
@@ -631,8 +634,8 @@ void Calibration::updateAxesBox()
qInstallMessageHandler(MessageHandler::myMessageOutput); qInstallMessageHandler(MessageHandler::myMessageOutput);
ui->axesBox->clear(); ui->axesBox->clear();
QList<JoyControlStick*> sticksList = currentJoystick->getActiveSetJoystick()->getSticks().values(); QList<JoyControlStick *> sticksList = currentJoystick->getActiveSetJoystick()->getSticks().values();
QListIterator<JoyControlStick*> currStick(sticksList); QListIterator<JoyControlStick *> currStick(sticksList);
while (currStick.hasNext()) while (currStick.hasNext())
{ {
@@ -650,32 +653,34 @@ void Calibration::createAxesConnection()
{ {
qInstallMessageHandler(MessageHandler::myMessageOutput); qInstallMessageHandler(MessageHandler::myMessageOutput);
if (ui->saveBtn->isEnabled()) { if (ui->saveBtn->isEnabled())
{
QMessageBox msgBox; QMessageBox msgBox;
msgBox.setText(tr("Do you want to save calibration of current axis?")); msgBox.setText(tr("Do you want to save calibration of current axis?"));
msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No); msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
switch(msgBox.exec()) switch (msgBox.exec())
{ {
case QMessageBox::Yes: case QMessageBox::Yes:
saveSettings(); saveSettings();
break; break;
case QMessageBox::No: case QMessageBox::No:
break; break;
default: default:
break; break;
} }
} }
while(!ui->progressBarsLayout->isEmpty()) { while (!ui->progressBarsLayout->isEmpty())
{
QLayout *hb = ui->progressBarsLayout->takeAt(0)->layout(); QLayout *hb = ui->progressBarsLayout->takeAt(0)->layout();
while(!hb->isEmpty()) { while (!hb->isEmpty())
{
QWidget *w = hb->takeAt(0)->widget(); QWidget *w = hb->takeAt(0)->widget();
delete w; delete w;
@@ -686,7 +691,8 @@ void Calibration::createAxesConnection()
update(); update();
QPointer<JoyControlStick> controlstick = currentJoystick->getActiveSetJoystick()->getJoyStick(ui->axesBox->currentIndex()); QPointer<JoyControlStick> controlstick =
currentJoystick->getActiveSetJoystick()->getJoyStick(ui->axesBox->currentIndex());
this->stick = controlstick.data(); this->stick = controlstick.data();
center_calibrated_x = controlstick->getAxisX()->getAxisCenterCal(); center_calibrated_x = controlstick->getAxisX()->getAxisCenterCal();
@@ -704,8 +710,10 @@ void Calibration::createAxesConnection()
calibrated = controlstick->wasCalibrated(); calibrated = controlstick->wasCalibrated();
text = controlstick->getCalibrationSummary(); text = controlstick->getCalibrationSummary();
if (calibrated) ui->resetBtn->setEnabled(true); if (calibrated)
else ui->resetBtn->setEnabled(false); ui->resetBtn->setEnabled(true);
else
ui->resetBtn->setEnabled(false);
controlstick.data()->getModifierButton()->establishPropertyUpdatedConnections(); controlstick.data()->getModifierButton()->establishPropertyUpdatedConnections();
helper.moveToThread(controlstick.data()->thread()); helper.moveToThread(controlstick.data()->thread());
@@ -715,7 +723,8 @@ void Calibration::createAxesConnection()
update(); update();
if (controlstick.isNull()) controlstick.clear(); if (controlstick.isNull())
controlstick.clear();
} }
/** /**
@@ -723,57 +732,56 @@ void Calibration::createAxesConnection()
* @param pointer to stick * @param pointer to stick
* @return nothing * @return nothing
*/ */
void Calibration::setProgressBars(JoyControlStick* controlstick) void Calibration::setProgressBars(JoyControlStick *controlstick)
{ {
qInstallMessageHandler(MessageHandler::myMessageOutput); qInstallMessageHandler(MessageHandler::myMessageOutput);
joyAxisX = controlstick->getAxisX(); joyAxisX = controlstick->getAxisX();
joyAxisY = controlstick->getAxisY(); joyAxisY = controlstick->getAxisY();
calibrated = controlstick->wasCalibrated(); calibrated = controlstick->wasCalibrated();
ui->Informations->setText(controlstick->getCalibrationSummary()); ui->Informations->setText(controlstick->getCalibrationSummary());
if ((joyAxisX != nullptr) && (joyAxisY != nullptr)) if ((joyAxisX != nullptr) && (joyAxisY != nullptr))
{ {
QHBoxLayout *hbox = new QHBoxLayout(); QHBoxLayout *hbox = new QHBoxLayout();
QHBoxLayout *hbox2 = new QHBoxLayout(); QHBoxLayout *hbox2 = new QHBoxLayout();
QLabel *axisLabel = new QLabel(); QLabel *axisLabel = new QLabel();
QLabel *axisLabel2 = new QLabel(); QLabel *axisLabel2 = new QLabel();
axisLabel->setText(tr("Axis %1").arg(joyAxisX->getRealJoyIndex())); axisLabel->setText(tr("Axis %1").arg(joyAxisX->getRealJoyIndex()));
axisLabel2->setText(tr("Axis %1").arg(joyAxisY->getRealJoyIndex())); axisLabel2->setText(tr("Axis %1").arg(joyAxisY->getRealJoyIndex()));
axisBarX = new QProgressBar(); axisBarX = new QProgressBar();
axisBarY = new QProgressBar(); axisBarY = new QProgressBar();
axisBarX->setMinimum(GlobalVariables::JoyAxis::AXISMIN); axisBarX->setMinimum(GlobalVariables::JoyAxis::AXISMIN);
axisBarX->setMaximum(GlobalVariables::JoyAxis::AXISMAX); axisBarX->setMaximum(GlobalVariables::JoyAxis::AXISMAX);
axisBarX->setFormat("%v"); axisBarX->setFormat("%v");
axisBarX->setValue(joyAxisX->getCurrentRawValue()); axisBarX->setValue(joyAxisX->getCurrentRawValue());
axisBarY->setMinimum(GlobalVariables::JoyAxis::AXISMIN); axisBarY->setMinimum(GlobalVariables::JoyAxis::AXISMIN);
axisBarY->setMaximum(GlobalVariables::JoyAxis::AXISMAX); axisBarY->setMaximum(GlobalVariables::JoyAxis::AXISMAX);
axisBarY->setFormat("%v"); axisBarY->setFormat("%v");
axisBarY->setValue(joyAxisY->getCurrentRawValue()); axisBarY->setValue(joyAxisY->getCurrentRawValue());
hbox->addWidget(axisLabel); hbox->addWidget(axisLabel);
hbox->addWidget(axisBarX); hbox->addWidget(axisBarX);
hbox->addSpacing(10); hbox->addSpacing(10);
hbox2->addWidget(axisLabel2); hbox2->addWidget(axisLabel2);
hbox2->addWidget(axisBarY); hbox2->addWidget(axisBarY);
hbox2->addSpacing(10); hbox2->addSpacing(10);
ui->progressBarsLayout->addLayout(hbox); ui->progressBarsLayout->addLayout(hbox);
ui->progressBarsLayout->addLayout(hbox2); ui->progressBarsLayout->addLayout(hbox2);
connect(joyAxisX, &JoyAxis::moved, this, &Calibration::checkX); connect(joyAxisX, &JoyAxis::moved, this, &Calibration::checkX);
connect(joyAxisY, &JoyAxis::moved, this, &Calibration::checkY); connect(joyAxisY, &JoyAxis::moved, this, &Calibration::checkY);
}
} update();
update();
} }
/** /**
@@ -787,54 +795,53 @@ void Calibration::setProgressBars(int setJoyNr, int stickNr)
{ {
qInstallMessageHandler(MessageHandler::myMessageOutput); qInstallMessageHandler(MessageHandler::myMessageOutput);
JoyControlStick* controlstick = currentJoystick->getActiveSetJoystick()->getJoyStick(stickNr); JoyControlStick *controlstick = currentJoystick->getActiveSetJoystick()->getJoyStick(stickNr);
//helper.moveToThread(controlstick->thread()); // helper.moveToThread(controlstick->thread());
joyAxisX = controlstick->getAxisX(); joyAxisX = controlstick->getAxisX();
joyAxisY = controlstick->getAxisY(); joyAxisY = controlstick->getAxisY();
calibrated = controlstick->wasCalibrated(); calibrated = controlstick->wasCalibrated();
ui->Informations->setText(controlstick->getCalibrationSummary()); ui->Informations->setText(controlstick->getCalibrationSummary());
if ((joyAxisX != nullptr) && (joyAxisY != nullptr)) if ((joyAxisX != nullptr) && (joyAxisY != nullptr))
{ {
QHBoxLayout *hbox = new QHBoxLayout(); QHBoxLayout *hbox = new QHBoxLayout();
QHBoxLayout *hbox2 = new QHBoxLayout(); QHBoxLayout *hbox2 = new QHBoxLayout();
QLabel *axisLabel = new QLabel(); QLabel *axisLabel = new QLabel();
QLabel *axisLabel2 = new QLabel(); QLabel *axisLabel2 = new QLabel();
axisLabel->setText(tr("Axis %1").arg(joyAxisX->getRealJoyIndex())); axisLabel->setText(tr("Axis %1").arg(joyAxisX->getRealJoyIndex()));
axisLabel2->setText(tr("Axis %1").arg(joyAxisY->getRealJoyIndex())); axisLabel2->setText(tr("Axis %1").arg(joyAxisY->getRealJoyIndex()));
axisBarX = new QProgressBar(); axisBarX = new QProgressBar();
axisBarY = new QProgressBar(); axisBarY = new QProgressBar();
axisBarX->setMinimum(GlobalVariables::JoyAxis::AXISMIN); axisBarX->setMinimum(GlobalVariables::JoyAxis::AXISMIN);
axisBarX->setMaximum(GlobalVariables::JoyAxis::AXISMAX); axisBarX->setMaximum(GlobalVariables::JoyAxis::AXISMAX);
axisBarX->setFormat("%v"); axisBarX->setFormat("%v");
axisBarX->setValue(joyAxisX->getCurrentRawValue()); axisBarX->setValue(joyAxisX->getCurrentRawValue());
axisBarY->setMinimum(GlobalVariables::JoyAxis::AXISMIN); axisBarY->setMinimum(GlobalVariables::JoyAxis::AXISMIN);
axisBarY->setMaximum(GlobalVariables::JoyAxis::AXISMAX); axisBarY->setMaximum(GlobalVariables::JoyAxis::AXISMAX);
axisBarY->setFormat("%v"); axisBarY->setFormat("%v");
axisBarY->setValue(joyAxisY->getCurrentRawValue()); axisBarY->setValue(joyAxisY->getCurrentRawValue());
hbox->addWidget(axisLabel); hbox->addWidget(axisLabel);
hbox->addWidget(axisBarX); hbox->addWidget(axisBarX);
hbox->addSpacing(10); hbox->addSpacing(10);
hbox2->addWidget(axisLabel2); hbox2->addWidget(axisLabel2);
hbox2->addWidget(axisBarY); hbox2->addWidget(axisBarY);
hbox2->addSpacing(10); hbox2->addSpacing(10);
ui->progressBarsLayout->addLayout(hbox); ui->progressBarsLayout->addLayout(hbox);
ui->progressBarsLayout->addLayout(hbox2); ui->progressBarsLayout->addLayout(hbox2);
connect(joyAxisX, &JoyAxis::moved, this, &Calibration::checkX); connect(joyAxisX, &JoyAxis::moved, this, &Calibration::checkX);
connect(joyAxisY, &JoyAxis::moved, this, &Calibration::checkY); connect(joyAxisY, &JoyAxis::moved, this, &Calibration::checkY);
}
} update();
update();
} }

View File

@@ -15,7 +15,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef CALIBRATION_H #ifndef CALIBRATION_H
#define CALIBRATION_H #define CALIBRATION_H
@@ -25,7 +24,6 @@
#include <QProgressBar> #include <QProgressBar>
class JoyControlStick; class JoyControlStick;
class InputDevice; class InputDevice;
@@ -37,23 +35,22 @@ class Calibration : public QWidget
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit Calibration(InputDevice* joystick, QWidget *parent = 0); explicit Calibration(InputDevice *joystick, QWidget *parent = 0);
~Calibration(); ~Calibration();
int chooseMinMax(QString min_max_sign, QList<int> ax_values); int chooseMinMax(QString min_max_sign, QList<int> ax_values);
void setQuadraticZoneCalibrated(int &max_axis_val_x, int &min_axis_val_x, int &max_axis_val_y, int &min_axis_val_y); void setQuadraticZoneCalibrated(int &max_axis_val_x, int &min_axis_val_x, int &max_axis_val_y, int &min_axis_val_y);
protected: protected:
void setProgressBars(int setJoyNr, int stickNr); void setProgressBars(int setJoyNr, int stickNr);
void setProgressBars(JoyControlStick* controlstick); void setProgressBars(JoyControlStick *controlstick);
void updateAxesBox(); void updateAxesBox();
void restoreCalValues(); void restoreCalValues();
bool enoughProb(int x_count, int y_count, QString character); bool enoughProb(int x_count, int y_count, QString character);
int calibratedDeadZone(int center, int deadzone); int calibratedDeadZone(int center, int deadzone);
private:
private:
static int fakeMapFunc(const int &x); static int fakeMapFunc(const int &x);
static void summarizeValues(int &numbFromList, const int &mappednumb); static void summarizeValues(int &numbFromList, const int &mappednumb);
static void getMinVal(int &numbFromList, const int &mappednumb); static void getMinVal(int &numbFromList, const int &mappednumb);
@@ -61,14 +58,14 @@ private:
Ui::Calibration *ui; Ui::Calibration *ui;
JoyControlStick *stick; JoyControlStick *stick;
InputDevice* currentJoystick; InputDevice *currentJoystick;
JoyControlStickEditDialogHelper helper; JoyControlStickEditDialogHelper helper;
JoyAxis* joyAxisX; JoyAxis *joyAxisX;
JoyAxis* joyAxisY; JoyAxis *joyAxisY;
QProgressBar *axisBarX; QProgressBar *axisBarX;
QProgressBar *axisBarY; QProgressBar *axisBarY;
QMultiHash<QString,int> x_es_val; QMultiHash<QString, int> x_es_val;
QMultiHash<QString,int> y_es_val; QMultiHash<QString, int> y_es_val;
int center_calibrated_x; int center_calibrated_x;
int center_calibrated_y; int center_calibrated_y;
int max_axis_val_x; int max_axis_val_x;
@@ -82,7 +79,7 @@ private:
bool calibrated; bool calibrated;
QString text; QString text;
public slots: public slots:
void saveSettings(); void saveSettings();
void checkX(int value); void checkX(int value);
void checkY(int value); void checkY(int value);
@@ -91,13 +88,12 @@ public slots:
void startSecondStep(); void startSecondStep();
void startLastStep(); void startLastStep();
protected slots: protected slots:
void resetSettings(bool silentReset, bool clicked = false); void resetSettings(bool silentReset, bool clicked = false);
signals: signals:
void deadZoneChanged(int value); void deadZoneChanged(int value);
void propertyUpdated(); void propertyUpdated();
}; };
#endif // CALIBRATION_H #endif // CALIBRATION_H

View File

@@ -21,17 +21,15 @@
#include "messagehandler.h" #include "messagehandler.h"
#include <QDebug>
#include <QPushButton> #include <QPushButton>
#include <QWidget> #include <QWidget>
#include <QDebug>
#include "x11extras.h" #include "x11extras.h"
CapturedWindowInfoDialog::CapturedWindowInfoDialog(long window, QWidget *parent)
: QDialog(parent)
CapturedWindowInfoDialog::CapturedWindowInfoDialog(long window, QWidget *parent) : , ui(new Ui::CapturedWindowInfoDialog)
QDialog(parent),
ui(new Ui::CapturedWindowInfoDialog)
{ {
ui->setupUi(this); ui->setupUi(this);
@@ -53,8 +51,7 @@ CapturedWindowInfoDialog::CapturedWindowInfoDialog(long window, QWidget *parent)
{ {
ui->winClassCheckBox->setEnabled(false); ui->winClassCheckBox->setEnabled(false);
ui->winClassCheckBox->setChecked(false); ui->winClassCheckBox->setChecked(false);
} } else
else
{ {
ui->winClassCheckBox->setChecked(true); ui->winClassCheckBox->setChecked(true);
setRadioDefault = true; setRadioDefault = true;
@@ -70,8 +67,7 @@ CapturedWindowInfoDialog::CapturedWindowInfoDialog(long window, QWidget *parent)
{ {
ui->winTitleCheckBox->setEnabled(false); ui->winTitleCheckBox->setEnabled(false);
ui->winTitleCheckBox->setChecked(false); ui->winTitleCheckBox->setChecked(false);
} } else if (!setRadioDefault)
else if (!setRadioDefault)
{ {
ui->winTitleCheckBox->setChecked(true); ui->winTitleCheckBox->setChecked(true);
setRadioDefault = true; setRadioDefault = true;
@@ -90,24 +86,21 @@ CapturedWindowInfoDialog::CapturedWindowInfoDialog(long window, QWidget *parent)
ui->winPathLabel->setText(exepath); ui->winPathLabel->setText(exepath);
winPath = exepath; winPath = exepath;
if (!setRadioDefault) ui->winTitleCheckBox->setChecked(true); if (!setRadioDefault)
ui->winTitleCheckBox->setChecked(true);
} } else
else
{ {
ui->winPathCheckBox->setEnabled(false); ui->winPathCheckBox->setEnabled(false);
ui->winPathCheckBox->setChecked(false); ui->winPathCheckBox->setChecked(false);
} }
} } else
else
{ {
ui->winPathCheckBox->setEnabled(false); ui->winPathCheckBox->setEnabled(false);
ui->winPathCheckBox->setChecked(false); ui->winPathCheckBox->setChecked(false);
} }
if (winClass.isEmpty() && winName.isEmpty() && winPath.isEmpty())
if (winClass.isEmpty() && winName.isEmpty() &&
winPath.isEmpty())
{ {
QPushButton *button = ui->buttonBox->button(QDialogButtonBox::Ok); QPushButton *button = ui->buttonBox->button(QDialogButtonBox::Ok);
button->setEnabled(false); button->setEnabled(false);
@@ -137,8 +130,10 @@ void CapturedWindowInfoDialog::populateOption()
{ {
selectedMatch = selectedMatch | WindowPath; selectedMatch = selectedMatch | WindowPath;
if (ui->winPathChoiceComboBox->currentIndex() == 0) fullWinPath = true; if (ui->winPathChoiceComboBox->currentIndex() == 0)
else fullWinPath = false; fullWinPath = true;
else
fullWinPath = false;
} }
} }

View File

@@ -16,7 +16,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef UNIXWINDOWINFODIALOG_H #ifndef UNIXWINDOWINFODIALOG_H
#define UNIXWINDOWINFODIALOG_H #define UNIXWINDOWINFODIALOG_H
@@ -32,12 +31,12 @@ class CapturedWindowInfoDialog : public QDialog
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit CapturedWindowInfoDialog(long window, QWidget *parent = nullptr); explicit CapturedWindowInfoDialog(long window, QWidget *parent = nullptr);
~CapturedWindowInfoDialog(); ~CapturedWindowInfoDialog();
enum { enum
{
WindowNone = 0, WindowNone = 0,
WindowClass = (1 << 0), WindowClass = (1 << 0),
WindowName = (1 << 1), WindowName = (1 << 1),
@@ -51,7 +50,7 @@ public:
bool useFullWindowPath(); bool useFullWindowPath();
CapturedWindowOption getSelectedOptions(); CapturedWindowOption getSelectedOptions();
private: private:
Ui::CapturedWindowInfoDialog *ui; Ui::CapturedWindowInfoDialog *ui;
CapturedWindowOption selectedMatch; CapturedWindowOption selectedMatch;
@@ -61,8 +60,7 @@ private:
QString winPath; QString winPath;
bool fullWinPath; bool fullWinPath;
private slots:
private slots:
void populateOption(); void populateOption();
}; };

View File

@@ -18,19 +18,19 @@
#include "commandlineutility.h" #include "commandlineutility.h"
#include "messagehandler.h"
#include "common.h" #include "common.h"
#include "eventhandlerfactory.h" #include "eventhandlerfactory.h"
#include "messagehandler.h"
#include <QApplication>
#include <QCommandLineParser>
#include <QDebug> #include <QDebug>
#include <QFileInfo> #include <QFileInfo>
#include <QCommandLineParser>
#include <QApplication>
QStringList CommandLineUtility::eventGeneratorsList = EventHandlerFactory::buildEventGeneratorList(); QStringList CommandLineUtility::eventGeneratorsList = EventHandlerFactory::buildEventGeneratorList();
CommandLineUtility::CommandLineUtility(QObject *parent) : CommandLineUtility::CommandLineUtility(QObject *parent)
QObject(parent) : QObject(parent)
{ {
qInstallMessageHandler(MessageHandler::myMessageOutput); qInstallMessageHandler(MessageHandler::myMessageOutput);
@@ -55,8 +55,8 @@ CommandLineUtility::CommandLineUtility(QObject *parent) :
eventGenerator = EventHandlerFactory::fallBackIdentifier(); eventGenerator = EventHandlerFactory::fallBackIdentifier();
} }
void CommandLineUtility::parseArguments(QCommandLineParser *parser)
void CommandLineUtility::parseArguments(QCommandLineParser* parser) { {
qInstallMessageHandler(MessageHandler::myMessageOutput); qInstallMessageHandler(MessageHandler::myMessageOutput);
@@ -69,16 +69,13 @@ void CommandLineUtility::parseArguments(QCommandLineParser* parser) {
qDebug() << "tray is set"; qDebug() << "tray is set";
launchInTray = true; launchInTray = true;
hideTrayIcon = false; hideTrayIcon = false;
} } else if (parser->isSet("no-tray"))
else if (parser->isSet("no-tray"))
{ {
qDebug() << "no-tray is set"; qDebug() << "no-tray is set";
hideTrayIcon = true; hideTrayIcon = true;
launchInTray = false; launchInTray = false;
} }
@@ -129,50 +126,51 @@ void CommandLineUtility::parseArguments(QCommandLineParser* parser) {
{ {
daemonMode = true; daemonMode = true;
} }
#ifdef WITH_X11 #ifdef WITH_X11
if (parser->isSet("display")) if (parser->isSet("display"))
{ {
if (!parser->value("display").isEmpty()) if (!parser->value("display").isEmpty())
{ {
displayString = parser->value("display"); displayString = parser->value("display");
} } else
else
{ {
setErrorMessage(QObject::tr("No display string was specified.")); setErrorMessage(QObject::tr("No display string was specified."));
} }
} }
#endif #endif
#if (defined(WITH_UINPUT) && defined(WITH_XTEST)) #if (defined(WITH_UINPUT) && defined(WITH_XTEST))
if (parser->isSet("eventgen")) if (parser->isSet("eventgen"))
{ {
QString eventGenText = parser->value("eventgen"); QString eventGenText = parser->value("eventgen");
if (!eventGenText.isEmpty() && !eventGeneratorsList.contains(eventGenText)) if (!eventGenText.isEmpty() && !eventGeneratorsList.contains(eventGenText))
{ {
eventGenerator = ""; eventGenerator = "";
setErrorMessage(QObject::tr("An invalid event generator was specified.")); setErrorMessage(QObject::tr("An invalid event generator was specified."));
} } else if (!eventGenText.isEmpty() && eventGeneratorsList.contains(eventGenText))
else if (!eventGenText.isEmpty() && eventGeneratorsList.contains(eventGenText))
{ {
eventGenerator = eventGenText; eventGenerator = eventGenText;
} } else
else
{ {
setErrorMessage(QObject::tr("No event generator string was specified.")); setErrorMessage(QObject::tr("No event generator string was specified."));
} }
} }
#endif #endif
if (parser->isSet("log-level")) if (parser->isSet("log-level"))
{ {
QString logLevelText = parser->value("log-level"); QString logLevelText = parser->value("log-level");
if (logLevelText == "debug") currentLogLevel = Logger::LOG_DEBUG; if (logLevelText == "debug")
else if (logLevelText == "info") currentLogLevel = Logger::LOG_INFO; currentLogLevel = Logger::LOG_DEBUG;
else if (logLevelText == "warn") currentLogLevel = Logger::LOG_WARNING; else if (logLevelText == "info")
else if (logLevelText == "error") currentLogLevel = Logger::LOG_ERROR; currentLogLevel = Logger::LOG_INFO;
else if (logLevelText == "warn")
currentLogLevel = Logger::LOG_WARNING;
else if (logLevelText == "error")
currentLogLevel = Logger::LOG_ERROR;
} }
if (parser->isSet("log-file")) if (parser->isSet("log-file"))
@@ -180,8 +178,7 @@ void CommandLineUtility::parseArguments(QCommandLineParser* parser) {
if (!parser->value("log-file").isEmpty()) if (!parser->value("log-file").isEmpty())
{ {
currentLogFile = parser->value("log-file"); currentLogFile = parser->value("log-file");
} } else
else
{ {
setErrorMessage(QObject::tr("No log file specified.")); setErrorMessage(QObject::tr("No log file specified."));
} }
@@ -191,55 +188,53 @@ void CommandLineUtility::parseArguments(QCommandLineParser* parser) {
} }
} }
void CommandLineUtility::parseArgsProfile(QCommandLineParser* parser) void CommandLineUtility::parseArgsProfile(QCommandLineParser *parser)
{ {
QFileInfo profileFileInfo(parser->value("profile")); QFileInfo profileFileInfo(parser->value("profile"));
if (profileFileInfo.exists() && (profileFileInfo.suffix() != "amgp") && (profileFileInfo.suffix() != "xml")) if (profileFileInfo.exists() && (profileFileInfo.suffix() != "amgp") && (profileFileInfo.suffix() != "xml"))
{ {
setErrorMessage(QObject::tr("Profile location %1 is not an XML file.").arg(parser->value("profile"))); setErrorMessage(QObject::tr("Profile location %1 is not an XML file.").arg(parser->value("profile")));
} } else if (profileFileInfo.exists() && ((profileFileInfo.suffix() == "amgp") || (profileFileInfo.suffix() == "xml")))
else if (profileFileInfo.exists() && ((profileFileInfo.suffix() == "amgp") || (profileFileInfo.suffix() == "xml")))
{ {
QString tempProfileLocation = profileFileInfo.absoluteFilePath(); QString tempProfileLocation = profileFileInfo.absoluteFilePath();
ControllerOptionsInfo tempInfo = getControllerOptionsList().at(currentListsIndex); ControllerOptionsInfo tempInfo = getControllerOptionsList().at(currentListsIndex);
tempInfo.setProfileLocation(tempProfileLocation); tempInfo.setProfileLocation(tempProfileLocation);
controllerOptionsList.replace(currentListsIndex, tempInfo); controllerOptionsList.replace(currentListsIndex, tempInfo);
} } else
else
{ {
setErrorMessage(QObject::tr("Profile location %1 does not exist.").arg(parser->value("profile"))); setErrorMessage(QObject::tr("Profile location %1 does not exist.").arg(parser->value("profile")));
} }
} }
void CommandLineUtility::parseArgsPrControle(QCommandLineParser* parser) void CommandLineUtility::parseArgsPrControle(QCommandLineParser *parser)
{ {
bool validNumber = false; bool validNumber = false;
int tempNumber = parser->value("profile-controller").toInt(&validNumber); int tempNumber = parser->value("profile-controller").toInt(&validNumber);
if (validNumber) if (validNumber)
{ {
if (controllerNumber == 0) controllerNumber = tempNumber; if (controllerNumber == 0)
controllerNumber = tempNumber;
ControllerOptionsInfo tempInfo = getControllerOptionsList().at(currentListsIndex); ControllerOptionsInfo tempInfo = getControllerOptionsList().at(currentListsIndex);
tempInfo.setControllerNumber(tempNumber); tempInfo.setControllerNumber(tempNumber);
controllerOptionsList.replace(currentListsIndex, tempInfo); controllerOptionsList.replace(currentListsIndex, tempInfo);
} } else if (!parser->value("profile-controller").isEmpty())
else if (!parser->value("profile-controller").isEmpty())
{ {
if (controllerIDString.isEmpty()) controllerIDString = parser->value("profile-controller"); if (controllerIDString.isEmpty())
controllerIDString = parser->value("profile-controller");
ControllerOptionsInfo tempInfo = getControllerOptionsList().at(currentListsIndex); ControllerOptionsInfo tempInfo = getControllerOptionsList().at(currentListsIndex);
tempInfo.setControllerID(parser->value("profile-controller")); tempInfo.setControllerID(parser->value("profile-controller"));
controllerOptionsList.replace(currentListsIndex, tempInfo); controllerOptionsList.replace(currentListsIndex, tempInfo);
} } else
else
{ {
setErrorMessage(QObject::tr("Controller identifier is not a valid value.")); setErrorMessage(QObject::tr("Controller identifier is not a valid value."));
} }
} }
void CommandLineUtility::parseArgsUnload(QCommandLineParser* parser) void CommandLineUtility::parseArgsUnload(QCommandLineParser *parser)
{ {
ControllerOptionsInfo gameControllerOptionInfo = getControllerOptionsList().at(currentListsIndex); ControllerOptionsInfo gameControllerOptionInfo = getControllerOptionsList().at(currentListsIndex);
gameControllerOptionInfo.setProfileLocation(""); gameControllerOptionInfo.setProfileLocation("");
@@ -266,27 +261,24 @@ void CommandLineUtility::parseArgsUnload(QCommandLineParser* parser)
gameControllerOptionInfo = getControllerOptionsList().at(currentListsIndex); gameControllerOptionInfo = getControllerOptionsList().at(currentListsIndex);
gameControllerOptionInfo.setControllerNumber(controllerNumber); gameControllerOptionInfo.setControllerNumber(controllerNumber);
controllerOptionsList.replace(currentListsIndex, gameControllerOptionInfo); controllerOptionsList.replace(currentListsIndex, gameControllerOptionInfo);
} } else if (!unloadedProfText.isEmpty())
else if (!unloadedProfText.isEmpty())
{ {
controllerIDString = unloadedProfText; controllerIDString = unloadedProfText;
gameControllerOptionInfo = getControllerOptionsList().at(currentListsIndex); gameControllerOptionInfo = getControllerOptionsList().at(currentListsIndex);
gameControllerOptionInfo.setControllerID(controllerIDString); gameControllerOptionInfo.setControllerID(controllerIDString);
controllerOptionsList.replace(currentListsIndex, gameControllerOptionInfo); controllerOptionsList.replace(currentListsIndex, gameControllerOptionInfo);
} } else
else
{ {
setErrorMessage(QObject::tr("Controller identifier is not a valid value.")); setErrorMessage(QObject::tr("Controller identifier is not a valid value."));
} }
} } else
else
{ {
unloadProfile = true; unloadProfile = true;
profileLocation = ""; profileLocation = "";
} }
} }
void CommandLineUtility::parseArgsStartSet(QCommandLineParser* parser) void CommandLineUtility::parseArgsStartSet(QCommandLineParser *parser)
{ {
QStringList parserValues = QStringList() << parser->values("startSet"); QStringList parserValues = QStringList() << parser->values("startSet");
QListIterator<QString> profileForStartset(parserValues); QListIterator<QString> profileForStartset(parserValues);
@@ -305,8 +297,7 @@ void CommandLineUtility::parseArgsStartSet(QCommandLineParser* parser)
ControllerOptionsInfo tempInfo = getControllerOptionsList().at(currentListsIndex); ControllerOptionsInfo tempInfo = getControllerOptionsList().at(currentListsIndex);
tempInfo.setStartSetNumber(startSetNumber); tempInfo.setStartSetNumber(startSetNumber);
controllerOptionsList.replace(currentListsIndex, tempInfo); controllerOptionsList.replace(currentListsIndex, tempInfo);
} } else if (validNumber)
else if (validNumber)
{ {
setErrorMessage(QObject::tr("An invalid set number '%1' was specified.").arg(tempNumber)); setErrorMessage(QObject::tr("An invalid set number '%1' was specified.").arg(tempNumber));
} }
@@ -321,31 +312,29 @@ void CommandLineUtility::parseArgsStartSet(QCommandLineParser* parser)
ControllerOptionsInfo tempInfo = getControllerOptionsList().at(currentListsIndex); ControllerOptionsInfo tempInfo = getControllerOptionsList().at(currentListsIndex);
tempInfo.setControllerNumber(controllerNumber); tempInfo.setControllerNumber(controllerNumber);
controllerOptionsList.replace(currentListsIndex, tempInfo); controllerOptionsList.replace(currentListsIndex, tempInfo);
} } else if (!startSetText.isEmpty())
else if (!startSetText.isEmpty())
{ {
controllerIDString = startSetText; controllerIDString = startSetText;
ControllerOptionsInfo tempInfo = getControllerOptionsList().at(currentListsIndex); ControllerOptionsInfo tempInfo = getControllerOptionsList().at(currentListsIndex);
tempInfo.setControllerID(controllerIDString); tempInfo.setControllerID(controllerIDString);
controllerOptionsList.replace(currentListsIndex, tempInfo); controllerOptionsList.replace(currentListsIndex, tempInfo);
} } else
else
{ {
setErrorMessage(QObject::tr("Controller identifier '%s'' is not a valid value.").arg(startSetText)); setErrorMessage(QObject::tr("Controller identifier '%s'' is not a valid value.").arg(startSetText));
} }
} }
} } else
else
{ {
setErrorMessage(QObject::tr("No set number was specified.")); setErrorMessage(QObject::tr("No set number was specified."));
} }
} }
void CommandLineUtility::parseArgsMap(QCommandLineParser* parser) void CommandLineUtility::parseArgsMap(QCommandLineParser *parser)
{ {
QString mapOptionText = parser->value("map"); QString mapOptionText = parser->value("map");
if (!mapOptionText.isEmpty()) { if (!mapOptionText.isEmpty())
{
bool validNumber = false; bool validNumber = false;
int tempNumber = mapOptionText.toInt(&validNumber); int tempNumber = mapOptionText.toInt(&validNumber);
@@ -354,18 +343,15 @@ void CommandLineUtility::parseArgsMap(QCommandLineParser* parser)
{ {
controllerNumber = tempNumber; controllerNumber = tempNumber;
mappingController = true; mappingController = true;
} } else if (!mapOptionText.isEmpty())
else if (!mapOptionText.isEmpty())
{ {
controllerIDString = mapOptionText; controllerIDString = mapOptionText;
mappingController = true; mappingController = true;
} } else
else
{ {
setErrorMessage(QObject::tr("Controller identifier is not a valid value.")); setErrorMessage(QObject::tr("Controller identifier is not a valid value."));
} }
} } else
else
{ {
setErrorMessage(QObject::tr("No controller was specified.")); setErrorMessage(QObject::tr("No controller was specified."));
} }
@@ -483,7 +469,6 @@ QString CommandLineUtility::getEventGenerator()
return eventGenerator; return eventGenerator;
} }
bool CommandLineUtility::launchAsDaemon() bool CommandLineUtility::launchAsDaemon()
{ {
qInstallMessageHandler(MessageHandler::myMessageOutput); qInstallMessageHandler(MessageHandler::myMessageOutput);
@@ -498,7 +483,6 @@ QString CommandLineUtility::getDisplayString()
return displayString; return displayString;
} }
Logger::LogLevel CommandLineUtility::getCurrentLogLevel() Logger::LogLevel CommandLineUtility::getCurrentLogLevel()
{ {
qInstallMessageHandler(MessageHandler::myMessageOutput); qInstallMessageHandler(MessageHandler::myMessageOutput);
@@ -506,14 +490,16 @@ Logger::LogLevel CommandLineUtility::getCurrentLogLevel()
return currentLogLevel; return currentLogLevel;
} }
QString CommandLineUtility::getCurrentLogFile() { QString CommandLineUtility::getCurrentLogFile()
{
qInstallMessageHandler(MessageHandler::myMessageOutput); qInstallMessageHandler(MessageHandler::myMessageOutput);
return currentLogFile; return currentLogFile;
} }
QString CommandLineUtility::getErrorText() { QString CommandLineUtility::getErrorText()
{
qInstallMessageHandler(MessageHandler::myMessageOutput); qInstallMessageHandler(MessageHandler::myMessageOutput);
@@ -528,7 +514,7 @@ void CommandLineUtility::setErrorMessage(QString temp)
encounteredError = true; encounteredError = true;
} }
QList<ControllerOptionsInfo> const& CommandLineUtility::getControllerOptionsList() QList<ControllerOptionsInfo> const &CommandLineUtility::getControllerOptionsList()
{ {
qInstallMessageHandler(MessageHandler::myMessageOutput); qInstallMessageHandler(MessageHandler::myMessageOutput);

View File

@@ -16,7 +16,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef COMMANDLINEPARSER_H #ifndef COMMANDLINEPARSER_H
#define COMMANDLINEPARSER_H #define COMMANDLINEPARSER_H
@@ -24,11 +23,10 @@ class QCommandLineParser;
#include "logger.h" #include "logger.h"
class ControllerOptionsInfo
{
class ControllerOptionsInfo { public:
public:
ControllerOptionsInfo() ControllerOptionsInfo()
{ {
controllerNumber = 0; controllerNumber = 0;
@@ -36,70 +34,31 @@ public:
unloadProfile = false; unloadProfile = false;
} }
bool hasProfile() bool hasProfile() { return !profileLocation.isEmpty(); }
{
return !profileLocation.isEmpty();
}
QString getProfileLocation() QString getProfileLocation() { return profileLocation; }
{
return profileLocation;
}
void setProfileLocation(QString location) void setProfileLocation(QString location) { profileLocation = location; }
{
profileLocation = location;
}
bool hasControllerNumber() bool hasControllerNumber() { return (controllerNumber > 0); }
{
return (controllerNumber > 0);
}
int getControllerNumber() int getControllerNumber() { return controllerNumber; }
{
return controllerNumber;
}
void setControllerNumber(int temp) void setControllerNumber(int temp) { controllerNumber = temp; }
{
controllerNumber = temp;
}
bool hasControllerID() bool hasControllerID() { return !controllerIDString.isEmpty(); }
{
return !controllerIDString.isEmpty();
}
QString getControllerID() QString getControllerID() { return controllerIDString; }
{
return controllerIDString;
}
void setControllerID(QString temp) void setControllerID(QString temp) { controllerIDString = temp; }
{
controllerIDString = temp;
}
bool isUnloadRequested() bool isUnloadRequested() { return unloadProfile; }
{
return unloadProfile;
}
void setUnloadRequest(bool status) void setUnloadRequest(bool status) { unloadProfile = status; }
{
unloadProfile = status;
}
int getStartSetNumber() int getStartSetNumber() { return startSetNumber; }
{
return startSetNumber;
}
int getJoyStartSetNumber() int getJoyStartSetNumber() { return startSetNumber - 1; }
{
return startSetNumber - 1;
}
void setStartSetNumber(int temp) void setStartSetNumber(int temp)
{ {
@@ -109,7 +68,7 @@ public:
} }
} }
private: private:
QString profileLocation; QString profileLocation;
int controllerNumber; int controllerNumber;
QString controllerIDString; QString controllerIDString;
@@ -121,10 +80,10 @@ class CommandLineUtility : public QObject
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit CommandLineUtility(QObject *parent = nullptr); explicit CommandLineUtility(QObject *parent = nullptr);
void parseArguments(QCommandLineParser* parser); void parseArguments(QCommandLineParser *parser);
bool isLaunchInTrayEnabled(); bool isLaunchInTrayEnabled();
bool isTrayHidden(); bool isTrayHidden();
@@ -148,18 +107,18 @@ public:
QString getCurrentLogFile(); QString getCurrentLogFile();
QString getErrorText(); QString getErrorText();
QList<int>* getJoyStartSetNumberList(); QList<int> *getJoyStartSetNumberList();
QList<ControllerOptionsInfo> const& getControllerOptionsList(); QList<ControllerOptionsInfo> const &getControllerOptionsList();
bool launchAsDaemon(); bool launchAsDaemon();
QString getDisplayString(); QString getDisplayString();
Logger::LogLevel getCurrentLogLevel(); Logger::LogLevel getCurrentLogLevel();
protected: protected:
void setErrorMessage(QString temp); void setErrorMessage(QString temp);
private: private:
bool launchInTray; bool launchInTray;
bool hideTrayIcon; bool hideTrayIcon;
bool encounteredError; bool encounteredError;
@@ -186,12 +145,11 @@ private:
static QStringList eventGeneratorsList; static QStringList eventGeneratorsList;
void parseArgsProfile(QCommandLineParser* parser); void parseArgsProfile(QCommandLineParser *parser);
void parseArgsPrControle(QCommandLineParser* parser); void parseArgsPrControle(QCommandLineParser *parser);
void parseArgsUnload(QCommandLineParser* parser); void parseArgsUnload(QCommandLineParser *parser);
void parseArgsStartSet(QCommandLineParser* parser); void parseArgsStartSet(QCommandLineParser *parser);
void parseArgsMap(QCommandLineParser* parser); void parseArgsMap(QCommandLineParser *parser);
}; };
#endif // COMMANDLINEPARSER_H #endif // COMMANDLINEPARSER_H

View File

@@ -20,125 +20,126 @@
#include "messagehandler.h" #include "messagehandler.h"
#include <QDebug>
#include <QReadWriteLock>
#include <QApplication> #include <QApplication>
#include <QDebug>
#include <QLibraryInfo> #include <QLibraryInfo>
#include <QReadWriteLock>
namespace PadderCommon {
namespace PadderCommon QString preferredProfileDir(AntiMicroSettings *settings)
{ {
QString preferredProfileDir(AntiMicroSettings *settings) qInstallMessageHandler(MessageHandler::myMessageOutput);
QString lastProfileDir = settings->value("LastProfileDir", "").toString();
QString defaultProfileDir = settings->value("DefaultProfileDir", "").toString();
QString lookupDir = QString();
if (!defaultProfileDir.isEmpty())
{ {
qInstallMessageHandler(MessageHandler::myMessageOutput); QFileInfo dirinfo(defaultProfileDir);
QString lastProfileDir = settings->value("LastProfileDir", "").toString(); if (dirinfo.isDir() && dirinfo.isReadable())
QString defaultProfileDir = settings->value("DefaultProfileDir", "").toString(); lookupDir = defaultProfileDir;
QString lookupDir = QString();
if (!defaultProfileDir.isEmpty())
{
QFileInfo dirinfo(defaultProfileDir);
if (dirinfo.isDir() && dirinfo.isReadable()) lookupDir = defaultProfileDir;
}
if (lookupDir.isEmpty() && !lastProfileDir.isEmpty())
{
QFileInfo dirinfo(lastProfileDir);
if (dirinfo.isDir() && dirinfo.isReadable()) lookupDir = lastProfileDir;
}
if (lookupDir.isEmpty())
{
lookupDir = QDir::homePath();
}
return lookupDir;
} }
QStringList arguments(const int &argc, char **argv) if (lookupDir.isEmpty() && !lastProfileDir.isEmpty())
{ {
qInstallMessageHandler(MessageHandler::myMessageOutput); QFileInfo dirinfo(lastProfileDir);
QStringList list = QStringList(); if (dirinfo.isDir() && dirinfo.isReadable())
lookupDir = lastProfileDir;
for (int a = 0; a < argc; ++a)
list << QString::fromLocal8Bit(argv[a]);
return list;
} }
QStringList parseArgumentsString(QString tempString) if (lookupDir.isEmpty())
{ {
qInstallMessageHandler(MessageHandler::myMessageOutput); lookupDir = QDir::homePath();
bool inside = (!tempString.isEmpty() && tempString.at(0) == QChar('"'));
QStringList tempList = tempString.split(QRegExp("\""), QString::SkipEmptyParts);
QStringList finalList = QStringList();
QStringListIterator iter(tempList);
while (iter.hasNext())
{
QString temp = iter.next();
if (inside) finalList.append(temp);
else finalList.append(temp.split(QRegExp("\\s+"), QString::SkipEmptyParts));
inside = !inside;
}
return finalList;
} }
/** return lookupDir;
* @brief Reload main application and base Qt translation files.
* @param Based Qt translator
* @param Application translator
* @param Language code
*/
void reloadTranslations(QTranslator *translator,
QTranslator *appTranslator,
QString language)
{
qInstallMessageHandler(MessageHandler::myMessageOutput);
// Remove application specific translation strings
qApp->removeTranslator(translator);
// Remove old Qt translation strings
qApp->removeTranslator(appTranslator);
// Load new Qt translation strings
translator->load(QString("qt_").append(language), QLibraryInfo::location(QLibraryInfo::TranslationsPath));
qApp->installTranslator(appTranslator);
// Load application specific translation strings
translator->load("antimicrox_" + language, QApplication::applicationDirPath().append("/../share/antimicrox/translations"));
qApp->installTranslator(translator);
}
void lockInputDevices()
{
qInstallMessageHandler(MessageHandler::myMessageOutput);
sdlWaitMutex.lock();
}
void unlockInputDevices()
{
qInstallMessageHandler(MessageHandler::myMessageOutput);
sdlWaitMutex.unlock();
}
QWaitCondition waitThisOut;
QMutex sdlWaitMutex;
QMutex inputDaemonMutex;
QReadWriteLock editingLock;
bool editingBindings = false;
MouseHelper mouseHelperObj;
} }
QStringList arguments(const int &argc, char **argv)
{
qInstallMessageHandler(MessageHandler::myMessageOutput);
QStringList list = QStringList();
for (int a = 0; a < argc; ++a)
list << QString::fromLocal8Bit(argv[a]);
return list;
}
QStringList parseArgumentsString(QString tempString)
{
qInstallMessageHandler(MessageHandler::myMessageOutput);
bool inside = (!tempString.isEmpty() && tempString.at(0) == QChar('"'));
QStringList tempList = tempString.split(QRegExp("\""), QString::SkipEmptyParts);
QStringList finalList = QStringList();
QStringListIterator iter(tempList);
while (iter.hasNext())
{
QString temp = iter.next();
if (inside)
finalList.append(temp);
else
finalList.append(temp.split(QRegExp("\\s+"), QString::SkipEmptyParts));
inside = !inside;
}
return finalList;
}
/**
* @brief Reload main application and base Qt translation files.
* @param Based Qt translator
* @param Application translator
* @param Language code
*/
void reloadTranslations(QTranslator *translator, QTranslator *appTranslator, QString language)
{
qInstallMessageHandler(MessageHandler::myMessageOutput);
// Remove application specific translation strings
qApp->removeTranslator(translator);
// Remove old Qt translation strings
qApp->removeTranslator(appTranslator);
// Load new Qt translation strings
translator->load(QString("qt_").append(language), QLibraryInfo::location(QLibraryInfo::TranslationsPath));
qApp->installTranslator(appTranslator);
// Load application specific translation strings
translator->load("antimicrox_" + language,
QApplication::applicationDirPath().append("/../share/antimicrox/translations"));
qApp->installTranslator(translator);
}
void lockInputDevices()
{
qInstallMessageHandler(MessageHandler::myMessageOutput);
sdlWaitMutex.lock();
}
void unlockInputDevices()
{
qInstallMessageHandler(MessageHandler::myMessageOutput);
sdlWaitMutex.unlock();
}
QWaitCondition waitThisOut;
QMutex sdlWaitMutex;
QMutex inputDaemonMutex;
QReadWriteLock editingLock;
bool editingBindings = false;
MouseHelper mouseHelperObj;
} // namespace PadderCommon

View File

@@ -16,12 +16,11 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef COMMON_H #ifndef COMMON_H
#define COMMON_H #define COMMON_H
#include "config.h"
#include "antimicrosettings.h" #include "antimicrosettings.h"
#include "config.h"
#include "mousehelper.h" #include "mousehelper.h"
#include <QDir> #include <QDir>
@@ -29,81 +28,73 @@
#include <QTranslator> #include <QTranslator>
#include <QWaitCondition> #include <QWaitCondition>
namespace PadderCommon {
inline QString configPath()
namespace PadderCommon
{ {
inline QString configPath() {
return (!qgetenv("XDG_CONFIG_HOME").isEmpty()) ? return (!qgetenv("XDG_CONFIG_HOME").isEmpty()) ? QString::fromUtf8(qgetenv("XDG_CONFIG_HOME")) + "/antimicrox"
QString::fromUtf8(qgetenv("XDG_CONFIG_HOME")) + "/antimicrox" : : QDir::homePath() + "/.config/antimicrox";
QDir::homePath() + "/.config/antimicrox";
}
const QString configFileName = "antimicrox_settings.ini";
inline QString configFilePath() {
return QString(configPath()).append("/").append(configFileName);
}
inline QString configLegacyFilePath() {
QString configPath = (!qgetenv("XDG_CONFIG_HOME").isEmpty()) ?
QString::fromUtf8(qgetenv("XDG_CONFIG_HOME")) + "/antimicroX" :
QDir::homePath() + "/.config/antimicroX";
return QString(configPath).append("/").append("antimicroX_settings.ini");
}
const int LATESTCONFIGFILEVERSION = 19;
// Specify the last known profile version that requires a migration
// to be performed in order to be compatible with the latest version.
const int LATESTCONFIGMIGRATIONVERSION = 5;
const QString localSocketKey = "antimicroxSignalListener";
const QString githubProjectPage = "https://github.com/AntiMicroX/antimicrox/";
const QString githubIssuesPage = "https://github.com/AntiMicroX/antimicrox/issues";
const QString wikiPage = QString("%1/wiki").arg(githubProjectPage);
const QString mouseDeviceName("antimicrox Mouse Emulation");
const QString keyboardDeviceName("antimicrox Keyboard Emulation");
const QString springMouseDeviceName("antimicrox Abs Mouse Emulation");
const int ANTIMICROX_MAJOR_VERSION = PROJECT_MAJOR_VERSION;
const int ANTIMICROX_MINOR_VERSION = PROJECT_MINOR_VERSION;
const int ANTIMICROX_PATCH_VERSION = PROJECT_PATCH_VERSION;
const QString programVersion = (ANTIMICROX_PATCH_VERSION > 0) ?
QString("%1.%2.%3").arg(ANTIMICROX_MAJOR_VERSION)
.arg(ANTIMICROX_MINOR_VERSION).arg(ANTIMICROX_PATCH_VERSION) :
QString("%1.%2").arg(ANTIMICROX_MAJOR_VERSION)
.arg(ANTIMICROX_MINOR_VERSION);
extern QWaitCondition waitThisOut;
extern QMutex sdlWaitMutex;
extern QMutex inputDaemonMutex;
extern bool editingBindings;
extern QReadWriteLock editingLock;
extern MouseHelper mouseHelperObj;
QString preferredProfileDir(AntiMicroSettings *settings);
QStringList arguments(const int &argc, char **argv);
QStringList parseArgumentsString(QString tempString);
void reloadTranslations(QTranslator *translator,
QTranslator *appTranslator,
QString language);
void lockInputDevices();
void unlockInputDevices();
/*!
* \brief Returns the "human-readable" name of the given profile.
*/
inline QString getProfileName(QFileInfo& profile) {
QString retVal = profile.completeBaseName();
return retVal;
}
} }
Q_DECLARE_METATYPE(QThread*) const QString configFileName = "antimicrox_settings.ini";
inline QString configFilePath() { return QString(configPath()).append("/").append(configFileName); }
inline QString configLegacyFilePath()
{
QString configPath = (!qgetenv("XDG_CONFIG_HOME").isEmpty())
? QString::fromUtf8(qgetenv("XDG_CONFIG_HOME")) + "/antimicroX"
: QDir::homePath() + "/.config/antimicroX";
return QString(configPath).append("/").append("antimicroX_settings.ini");
}
const int LATESTCONFIGFILEVERSION = 19;
// Specify the last known profile version that requires a migration
// to be performed in order to be compatible with the latest version.
const int LATESTCONFIGMIGRATIONVERSION = 5;
const QString localSocketKey = "antimicroxSignalListener";
const QString githubProjectPage = "https://github.com/AntiMicroX/antimicrox/";
const QString githubIssuesPage = "https://github.com/AntiMicroX/antimicrox/issues";
const QString wikiPage = QString("%1/wiki").arg(githubProjectPage);
const QString mouseDeviceName("antimicrox Mouse Emulation");
const QString keyboardDeviceName("antimicrox Keyboard Emulation");
const QString springMouseDeviceName("antimicrox Abs Mouse Emulation");
const int ANTIMICROX_MAJOR_VERSION = PROJECT_MAJOR_VERSION;
const int ANTIMICROX_MINOR_VERSION = PROJECT_MINOR_VERSION;
const int ANTIMICROX_PATCH_VERSION = PROJECT_PATCH_VERSION;
const QString programVersion =
(ANTIMICROX_PATCH_VERSION > 0)
? QString("%1.%2.%3").arg(ANTIMICROX_MAJOR_VERSION).arg(ANTIMICROX_MINOR_VERSION).arg(ANTIMICROX_PATCH_VERSION)
: QString("%1.%2").arg(ANTIMICROX_MAJOR_VERSION).arg(ANTIMICROX_MINOR_VERSION);
extern QWaitCondition waitThisOut;
extern QMutex sdlWaitMutex;
extern QMutex inputDaemonMutex;
extern bool editingBindings;
extern QReadWriteLock editingLock;
extern MouseHelper mouseHelperObj;
QString preferredProfileDir(AntiMicroSettings *settings);
QStringList arguments(const int &argc, char **argv);
QStringList parseArgumentsString(QString tempString);
void reloadTranslations(QTranslator *translator, QTranslator *appTranslator, QString language);
void lockInputDevices();
void unlockInputDevices();
/*!
* \brief Returns the "human-readable" name of the given profile.
*/
inline QString getProfileName(QFileInfo &profile)
{
QString retVal = profile.completeBaseName();
return retVal;
}
} // namespace PadderCommon
Q_DECLARE_METATYPE(QThread *)
#endif // COMMON_H #endif // COMMON_H

View File

@@ -18,20 +18,19 @@
#include "dpadcontextmenu.h" #include "dpadcontextmenu.h"
#include "messagehandler.h"
#include "joydpad.h"
#include "mousedialog/mousedpadsettingsdialog.h"
#include "antkeymapper.h" #include "antkeymapper.h"
#include "inputdevice.h"
#include "common.h" #include "common.h"
#include "inputdevice.h"
#include "joydpad.h"
#include "messagehandler.h"
#include "mousedialog/mousedpadsettingsdialog.h"
#include <QHash>
#include <QDebug> #include <QDebug>
#include <QHash>
DPadContextMenu::DPadContextMenu(JoyDPad *dpad, QWidget *parent)
DPadContextMenu::DPadContextMenu(JoyDPad *dpad, QWidget *parent) : : QMenu(parent)
QMenu(parent), , helper(dpad)
helper(dpad)
{ {
this->dpad = dpad; this->dpad = dpad;
@@ -50,7 +49,7 @@ void DPadContextMenu::buildMenu()
qInstallMessageHandler(MessageHandler::myMessageOutput); qInstallMessageHandler(MessageHandler::myMessageOutput);
QActionGroup *presetGroup = new QActionGroup(this); QActionGroup *presetGroup = new QActionGroup(this);
QAction* action = nullptr; QAction *action = nullptr;
int presetMode = 0; int presetMode = 0;
int currentPreset = getPresetIndex(); int currentPreset = getPresetIndex();
@@ -67,10 +66,14 @@ void DPadContextMenu::buildMenu()
QActionGroup *modesGroup = new QActionGroup(this); QActionGroup *modesGroup = new QActionGroup(this);
generateActionMode(modesGroup, action, tr("Standard"), static_cast<int>(dpad->getJoyMode()), static_cast<int>(JoyDPad::StandardMode)); generateActionMode(modesGroup, action, tr("Standard"), static_cast<int>(dpad->getJoyMode()),
generateActionMode(modesGroup, action, tr("Eight Way"), static_cast<int>(dpad->getJoyMode()), static_cast<int>(JoyDPad::EightWayMode)); static_cast<int>(JoyDPad::StandardMode));
generateActionMode(modesGroup, action, tr("4 Way Cardinal"), static_cast<int>(dpad->getJoyMode()), static_cast<int>(JoyDPad::FourWayCardinal)); generateActionMode(modesGroup, action, tr("Eight Way"), static_cast<int>(dpad->getJoyMode()),
generateActionMode(modesGroup, action, tr("4 Way Diagonal"), static_cast<int>(dpad->getJoyMode()), static_cast<int>(JoyDPad::FourWayDiagonal)); static_cast<int>(JoyDPad::EightWayMode));
generateActionMode(modesGroup, action, tr("4 Way Cardinal"), static_cast<int>(dpad->getJoyMode()),
static_cast<int>(JoyDPad::FourWayCardinal));
generateActionMode(modesGroup, action, tr("4 Way Diagonal"), static_cast<int>(dpad->getJoyMode()),
static_cast<int>(JoyDPad::FourWayDiagonal));
this->addSeparator(); this->addSeparator();
@@ -80,31 +83,29 @@ void DPadContextMenu::buildMenu()
connect(action, &QAction::triggered, this, &DPadContextMenu::openMouseSettingsDialog); connect(action, &QAction::triggered, this, &DPadContextMenu::openMouseSettingsDialog);
} }
void DPadContextMenu::generateActionPreset(QAction* action, QString actionText, int currentPreset, int& presetMode, QActionGroup* presetGroup) void DPadContextMenu::generateActionPreset(QAction *action, QString actionText, int currentPreset, int &presetMode,
QActionGroup *presetGroup)
{ {
action = this->addAction(actionText); action = this->addAction(actionText);
action->setCheckable(true); action->setCheckable(true);
action->setChecked(currentPreset == presetMode + 1); action->setChecked(currentPreset == presetMode + 1);
action->setData(QVariant(presetMode)); action->setData(QVariant(presetMode));
connect(action, &QAction::triggered, this, [this, action] { connect(action, &QAction::triggered, this, [this, action] { setDPadPreset(action); });
setDPadPreset(action);
});
presetGroup->addAction(action); presetGroup->addAction(action);
presetMode++; presetMode++;
} }
void DPadContextMenu::generateActionMode(QActionGroup *modesGroup, QAction* action, QString actionText, int currentPreset, int presetMode) void DPadContextMenu::generateActionMode(QActionGroup *modesGroup, QAction *action, QString actionText, int currentPreset,
int presetMode)
{ {
action = this->addAction(actionText); action = this->addAction(actionText);
action->setCheckable(true); action->setCheckable(true);
action->setChecked(currentPreset == presetMode); action->setChecked(currentPreset == presetMode);
action->setData(QVariant(presetMode)); action->setData(QVariant(presetMode));
connect(action, &QAction::triggered, this, [this, action] { connect(action, &QAction::triggered, this, [this, action] { setDPadMode(action); });
setDPadMode(action);
});
modesGroup->addAction(action); modesGroup->addAction(action);
} }
@@ -112,7 +113,7 @@ void DPadContextMenu::generateActionMode(QActionGroup *modesGroup, QAction* acti
/** /**
* @brief Set the appropriate mode for a DPad based on the item chosen. * @brief Set the appropriate mode for a DPad based on the item chosen.
*/ */
void DPadContextMenu::setDPadMode(QAction* action) void DPadContextMenu::setDPadMode(QAction *action)
{ {
qInstallMessageHandler(MessageHandler::myMessageOutput); qInstallMessageHandler(MessageHandler::myMessageOutput);
@@ -124,7 +125,7 @@ void DPadContextMenu::setDPadMode(QAction* action)
* @brief Assign the appropriate slots to DPad buttons based on the preset item * @brief Assign the appropriate slots to DPad buttons based on the preset item
* that was chosen. * that was chosen.
*/ */
void DPadContextMenu::setDPadPreset(QAction* action) void DPadContextMenu::setDPadPreset(QAction *action)
{ {
qInstallMessageHandler(MessageHandler::myMessageOutput); qInstallMessageHandler(MessageHandler::myMessageOutput);
@@ -139,137 +140,163 @@ void DPadContextMenu::setDPadPreset(QAction* action)
JoyButtonSlot *downLeftButtonSlot = nullptr; JoyButtonSlot *downLeftButtonSlot = nullptr;
JoyButtonSlot *downRightButtonSlot = nullptr; JoyButtonSlot *downRightButtonSlot = nullptr;
switch (item)
switch(item)
{ {
case 0: case 0:
PadderCommon::inputDaemonMutex.lock(); PadderCommon::inputDaemonMutex.lock();
upButtonSlot = new JoyButtonSlot(JoyButtonSlot::MouseUp, JoyButtonSlot::JoyMouseMovement, this); upButtonSlot = new JoyButtonSlot(JoyButtonSlot::MouseUp, JoyButtonSlot::JoyMouseMovement, this);
downButtonSlot = new JoyButtonSlot(JoyButtonSlot::MouseDown, JoyButtonSlot::JoyMouseMovement, this); downButtonSlot = new JoyButtonSlot(JoyButtonSlot::MouseDown, JoyButtonSlot::JoyMouseMovement, this);
leftButtonSlot = new JoyButtonSlot(JoyButtonSlot::MouseLeft, JoyButtonSlot::JoyMouseMovement, this); leftButtonSlot = new JoyButtonSlot(JoyButtonSlot::MouseLeft, JoyButtonSlot::JoyMouseMovement, this);
rightButtonSlot = new JoyButtonSlot(JoyButtonSlot::MouseRight, JoyButtonSlot::JoyMouseMovement, this); rightButtonSlot = new JoyButtonSlot(JoyButtonSlot::MouseRight, JoyButtonSlot::JoyMouseMovement, this);
dpad->setJoyMode(JoyDPad::StandardMode); dpad->setJoyMode(JoyDPad::StandardMode);
PadderCommon::inputDaemonMutex.unlock(); PadderCommon::inputDaemonMutex.unlock();
break; break;
case 1: case 1:
PadderCommon::inputDaemonMutex.lock(); PadderCommon::inputDaemonMutex.lock();
upButtonSlot = new JoyButtonSlot(JoyButtonSlot::MouseUp, JoyButtonSlot::JoyMouseMovement, this); upButtonSlot = new JoyButtonSlot(JoyButtonSlot::MouseUp, JoyButtonSlot::JoyMouseMovement, this);
downButtonSlot = new JoyButtonSlot(JoyButtonSlot::MouseDown, JoyButtonSlot::JoyMouseMovement, this); downButtonSlot = new JoyButtonSlot(JoyButtonSlot::MouseDown, JoyButtonSlot::JoyMouseMovement, this);
leftButtonSlot = new JoyButtonSlot(JoyButtonSlot::MouseRight, JoyButtonSlot::JoyMouseMovement, this); leftButtonSlot = new JoyButtonSlot(JoyButtonSlot::MouseRight, JoyButtonSlot::JoyMouseMovement, this);
rightButtonSlot = new JoyButtonSlot(JoyButtonSlot::MouseLeft, JoyButtonSlot::JoyMouseMovement, this); rightButtonSlot = new JoyButtonSlot(JoyButtonSlot::MouseLeft, JoyButtonSlot::JoyMouseMovement, this);
dpad->setJoyMode(JoyDPad::StandardMode); dpad->setJoyMode(JoyDPad::StandardMode);
PadderCommon::inputDaemonMutex.unlock(); PadderCommon::inputDaemonMutex.unlock();
break; break;
case 2: case 2:
PadderCommon::inputDaemonMutex.lock(); PadderCommon::inputDaemonMutex.lock();
upButtonSlot = new JoyButtonSlot(JoyButtonSlot::MouseDown, JoyButtonSlot::JoyMouseMovement, this); upButtonSlot = new JoyButtonSlot(JoyButtonSlot::MouseDown, JoyButtonSlot::JoyMouseMovement, this);
downButtonSlot = new JoyButtonSlot(JoyButtonSlot::MouseUp, JoyButtonSlot::JoyMouseMovement, this); downButtonSlot = new JoyButtonSlot(JoyButtonSlot::MouseUp, JoyButtonSlot::JoyMouseMovement, this);
leftButtonSlot = new JoyButtonSlot(JoyButtonSlot::MouseLeft, JoyButtonSlot::JoyMouseMovement, this); leftButtonSlot = new JoyButtonSlot(JoyButtonSlot::MouseLeft, JoyButtonSlot::JoyMouseMovement, this);
rightButtonSlot = new JoyButtonSlot(JoyButtonSlot::MouseRight, JoyButtonSlot::JoyMouseMovement, this); rightButtonSlot = new JoyButtonSlot(JoyButtonSlot::MouseRight, JoyButtonSlot::JoyMouseMovement, this);
dpad->setJoyMode(JoyDPad::StandardMode); dpad->setJoyMode(JoyDPad::StandardMode);
PadderCommon::inputDaemonMutex.unlock(); PadderCommon::inputDaemonMutex.unlock();
break; break;
case 3: case 3:
PadderCommon::inputDaemonMutex.lock(); PadderCommon::inputDaemonMutex.lock();
upButtonSlot = new JoyButtonSlot(JoyButtonSlot::MouseDown, JoyButtonSlot::JoyMouseMovement, this); upButtonSlot = new JoyButtonSlot(JoyButtonSlot::MouseDown, JoyButtonSlot::JoyMouseMovement, this);
downButtonSlot = new JoyButtonSlot(JoyButtonSlot::MouseUp, JoyButtonSlot::JoyMouseMovement, this); downButtonSlot = new JoyButtonSlot(JoyButtonSlot::MouseUp, JoyButtonSlot::JoyMouseMovement, this);
leftButtonSlot = new JoyButtonSlot(JoyButtonSlot::MouseRight, JoyButtonSlot::JoyMouseMovement, this); leftButtonSlot = new JoyButtonSlot(JoyButtonSlot::MouseRight, JoyButtonSlot::JoyMouseMovement, this);
rightButtonSlot = new JoyButtonSlot(JoyButtonSlot::MouseLeft, JoyButtonSlot::JoyMouseMovement, this); rightButtonSlot = new JoyButtonSlot(JoyButtonSlot::MouseLeft, JoyButtonSlot::JoyMouseMovement, this);
dpad->setJoyMode(JoyDPad::StandardMode); dpad->setJoyMode(JoyDPad::StandardMode);
PadderCommon::inputDaemonMutex.unlock(); PadderCommon::inputDaemonMutex.unlock();
break; break;
case 4: case 4:
PadderCommon::inputDaemonMutex.lock(); PadderCommon::inputDaemonMutex.lock();
upButtonSlot = new JoyButtonSlot(AntKeyMapper::getInstance()->returnVirtualKey(Qt::Key_Up), Qt::Key_Up, JoyButtonSlot::JoyKeyboard, this); upButtonSlot = new JoyButtonSlot(AntKeyMapper::getInstance()->returnVirtualKey(Qt::Key_Up), Qt::Key_Up,
downButtonSlot = new JoyButtonSlot(AntKeyMapper::getInstance()->returnVirtualKey(Qt::Key_Down), Qt::Key_Down, JoyButtonSlot::JoyKeyboard, this); JoyButtonSlot::JoyKeyboard, this);
leftButtonSlot = new JoyButtonSlot(AntKeyMapper::getInstance()->returnVirtualKey(Qt::Key_Left), Qt::Key_Left, JoyButtonSlot::JoyKeyboard, this); downButtonSlot = new JoyButtonSlot(AntKeyMapper::getInstance()->returnVirtualKey(Qt::Key_Down), Qt::Key_Down,
rightButtonSlot = new JoyButtonSlot(AntKeyMapper::getInstance()->returnVirtualKey(Qt::Key_Right), Qt::Key_Right, JoyButtonSlot::JoyKeyboard, this); JoyButtonSlot::JoyKeyboard, this);
dpad->setJoyMode(JoyDPad::StandardMode); leftButtonSlot = new JoyButtonSlot(AntKeyMapper::getInstance()->returnVirtualKey(Qt::Key_Left), Qt::Key_Left,
JoyButtonSlot::JoyKeyboard, this);
rightButtonSlot = new JoyButtonSlot(AntKeyMapper::getInstance()->returnVirtualKey(Qt::Key_Right), Qt::Key_Right,
JoyButtonSlot::JoyKeyboard, this);
dpad->setJoyMode(JoyDPad::StandardMode);
PadderCommon::inputDaemonMutex.unlock(); PadderCommon::inputDaemonMutex.unlock();
break; break;
case 5: case 5:
PadderCommon::inputDaemonMutex.lock(); PadderCommon::inputDaemonMutex.lock();
upButtonSlot = new JoyButtonSlot(AntKeyMapper::getInstance()->returnVirtualKey(Qt::Key_W), Qt::Key_W, JoyButtonSlot::JoyKeyboard, this); upButtonSlot = new JoyButtonSlot(AntKeyMapper::getInstance()->returnVirtualKey(Qt::Key_W), Qt::Key_W,
downButtonSlot = new JoyButtonSlot(AntKeyMapper::getInstance()->returnVirtualKey(Qt::Key_S), Qt::Key_S, JoyButtonSlot::JoyKeyboard, this); JoyButtonSlot::JoyKeyboard, this);
leftButtonSlot = new JoyButtonSlot(AntKeyMapper::getInstance()->returnVirtualKey(Qt::Key_A), Qt::Key_A, JoyButtonSlot::JoyKeyboard, this); downButtonSlot = new JoyButtonSlot(AntKeyMapper::getInstance()->returnVirtualKey(Qt::Key_S), Qt::Key_S,
rightButtonSlot = new JoyButtonSlot(AntKeyMapper::getInstance()->returnVirtualKey(Qt::Key_D), Qt::Key_D, JoyButtonSlot::JoyKeyboard, this); JoyButtonSlot::JoyKeyboard, this);
dpad->setJoyMode(JoyDPad::StandardMode); leftButtonSlot = new JoyButtonSlot(AntKeyMapper::getInstance()->returnVirtualKey(Qt::Key_A), Qt::Key_A,
JoyButtonSlot::JoyKeyboard, this);
rightButtonSlot = new JoyButtonSlot(AntKeyMapper::getInstance()->returnVirtualKey(Qt::Key_D), Qt::Key_D,
JoyButtonSlot::JoyKeyboard, this);
dpad->setJoyMode(JoyDPad::StandardMode);
PadderCommon::inputDaemonMutex.unlock(); PadderCommon::inputDaemonMutex.unlock();
break; break;
case 6: case 6:
PadderCommon::inputDaemonMutex.lock(); PadderCommon::inputDaemonMutex.lock();
if ((dpad->getJoyMode() == JoyDPad::StandardMode) || if ((dpad->getJoyMode() == JoyDPad::StandardMode) || (dpad->getJoyMode() == JoyDPad::FourWayCardinal))
(dpad->getJoyMode() == JoyDPad::FourWayCardinal)) {
{ upButtonSlot = new JoyButtonSlot(AntKeyMapper::getInstance()->returnVirtualKey(QtKeyMapperBase::AntKey_KP_8),
upButtonSlot = new JoyButtonSlot(AntKeyMapper::getInstance()->returnVirtualKey(QtKeyMapperBase::AntKey_KP_8), QtKeyMapperBase::AntKey_KP_8, JoyButtonSlot::JoyKeyboard, this); QtKeyMapperBase::AntKey_KP_8, JoyButtonSlot::JoyKeyboard, this);
downButtonSlot = new JoyButtonSlot(AntKeyMapper::getInstance()->returnVirtualKey(QtKeyMapperBase::AntKey_KP_2), QtKeyMapperBase::AntKey_KP_2, JoyButtonSlot::JoyKeyboard, this); downButtonSlot = new JoyButtonSlot(AntKeyMapper::getInstance()->returnVirtualKey(QtKeyMapperBase::AntKey_KP_2),
leftButtonSlot = new JoyButtonSlot(AntKeyMapper::getInstance()->returnVirtualKey(QtKeyMapperBase::AntKey_KP_4), QtKeyMapperBase::AntKey_KP_4, JoyButtonSlot::JoyKeyboard, this); QtKeyMapperBase::AntKey_KP_2, JoyButtonSlot::JoyKeyboard, this);
rightButtonSlot = new JoyButtonSlot(AntKeyMapper::getInstance()->returnVirtualKey(QtKeyMapperBase::AntKey_KP_6), QtKeyMapperBase::AntKey_KP_6, JoyButtonSlot::JoyKeyboard, this); leftButtonSlot = new JoyButtonSlot(AntKeyMapper::getInstance()->returnVirtualKey(QtKeyMapperBase::AntKey_KP_4),
} QtKeyMapperBase::AntKey_KP_4, JoyButtonSlot::JoyKeyboard, this);
else if (dpad->getJoyMode() == JoyDPad::EightWayMode) rightButtonSlot = new JoyButtonSlot(AntKeyMapper::getInstance()->returnVirtualKey(QtKeyMapperBase::AntKey_KP_6),
{ QtKeyMapperBase::AntKey_KP_6, JoyButtonSlot::JoyKeyboard, this);
upButtonSlot = new JoyButtonSlot(AntKeyMapper::getInstance()->returnVirtualKey(QtKeyMapperBase::AntKey_KP_8), QtKeyMapperBase::AntKey_KP_8, JoyButtonSlot::JoyKeyboard, this); } else if (dpad->getJoyMode() == JoyDPad::EightWayMode)
downButtonSlot = new JoyButtonSlot(AntKeyMapper::getInstance()->returnVirtualKey(QtKeyMapperBase::AntKey_KP_2), QtKeyMapperBase::AntKey_KP_2, JoyButtonSlot::JoyKeyboard, this); {
leftButtonSlot = new JoyButtonSlot(AntKeyMapper::getInstance()->returnVirtualKey(QtKeyMapperBase::AntKey_KP_4), QtKeyMapperBase::AntKey_KP_4, JoyButtonSlot::JoyKeyboard, this); upButtonSlot = new JoyButtonSlot(AntKeyMapper::getInstance()->returnVirtualKey(QtKeyMapperBase::AntKey_KP_8),
rightButtonSlot = new JoyButtonSlot(AntKeyMapper::getInstance()->returnVirtualKey(QtKeyMapperBase::AntKey_KP_6), QtKeyMapperBase::AntKey_KP_6, JoyButtonSlot::JoyKeyboard, this); QtKeyMapperBase::AntKey_KP_8, JoyButtonSlot::JoyKeyboard, this);
downButtonSlot = new JoyButtonSlot(AntKeyMapper::getInstance()->returnVirtualKey(QtKeyMapperBase::AntKey_KP_2),
QtKeyMapperBase::AntKey_KP_2, JoyButtonSlot::JoyKeyboard, this);
leftButtonSlot = new JoyButtonSlot(AntKeyMapper::getInstance()->returnVirtualKey(QtKeyMapperBase::AntKey_KP_4),
QtKeyMapperBase::AntKey_KP_4, JoyButtonSlot::JoyKeyboard, this);
rightButtonSlot = new JoyButtonSlot(AntKeyMapper::getInstance()->returnVirtualKey(QtKeyMapperBase::AntKey_KP_6),
QtKeyMapperBase::AntKey_KP_6, JoyButtonSlot::JoyKeyboard, this);
upLeftButtonSlot = new JoyButtonSlot(AntKeyMapper::getInstance()->returnVirtualKey(QtKeyMapperBase::AntKey_KP_7), QtKeyMapperBase::AntKey_KP_7, JoyButtonSlot::JoyKeyboard, this); upLeftButtonSlot = new JoyButtonSlot(AntKeyMapper::getInstance()->returnVirtualKey(QtKeyMapperBase::AntKey_KP_7),
upRightButtonSlot = new JoyButtonSlot(AntKeyMapper::getInstance()->returnVirtualKey(QtKeyMapperBase::AntKey_KP_9), QtKeyMapperBase::AntKey_KP_9, JoyButtonSlot::JoyKeyboard, this); QtKeyMapperBase::AntKey_KP_7, JoyButtonSlot::JoyKeyboard, this);
downLeftButtonSlot = new JoyButtonSlot(AntKeyMapper::getInstance()->returnVirtualKey(QtKeyMapperBase::AntKey_KP_1), QtKeyMapperBase::AntKey_KP_1, JoyButtonSlot::JoyKeyboard, this); upRightButtonSlot =
downRightButtonSlot = new JoyButtonSlot(AntKeyMapper::getInstance()->returnVirtualKey(QtKeyMapperBase::AntKey_KP_3), QtKeyMapperBase::AntKey_KP_3, JoyButtonSlot::JoyKeyboard, this); new JoyButtonSlot(AntKeyMapper::getInstance()->returnVirtualKey(QtKeyMapperBase::AntKey_KP_9),
} QtKeyMapperBase::AntKey_KP_9, JoyButtonSlot::JoyKeyboard, this);
else if (dpad->getJoyMode() == JoyDPad::FourWayDiagonal) downLeftButtonSlot =
{ new JoyButtonSlot(AntKeyMapper::getInstance()->returnVirtualKey(QtKeyMapperBase::AntKey_KP_1),
upLeftButtonSlot = new JoyButtonSlot(AntKeyMapper::getInstance()->returnVirtualKey(QtKeyMapperBase::AntKey_KP_7), QtKeyMapperBase::AntKey_KP_7, JoyButtonSlot::JoyKeyboard, this); QtKeyMapperBase::AntKey_KP_1, JoyButtonSlot::JoyKeyboard, this);
upRightButtonSlot = new JoyButtonSlot(AntKeyMapper::getInstance()->returnVirtualKey(QtKeyMapperBase::AntKey_KP_9), QtKeyMapperBase::AntKey_KP_9, JoyButtonSlot::JoyKeyboard, this); downRightButtonSlot =
downLeftButtonSlot = new JoyButtonSlot(AntKeyMapper::getInstance()->returnVirtualKey(QtKeyMapperBase::AntKey_KP_1), QtKeyMapperBase::AntKey_KP_1, JoyButtonSlot::JoyKeyboard, this); new JoyButtonSlot(AntKeyMapper::getInstance()->returnVirtualKey(QtKeyMapperBase::AntKey_KP_3),
downRightButtonSlot = new JoyButtonSlot(AntKeyMapper::getInstance()->returnVirtualKey(QtKeyMapperBase::AntKey_KP_3), QtKeyMapperBase::AntKey_KP_3, JoyButtonSlot::JoyKeyboard, this); QtKeyMapperBase::AntKey_KP_3, JoyButtonSlot::JoyKeyboard, this);
} } else if (dpad->getJoyMode() == JoyDPad::FourWayDiagonal)
{
upLeftButtonSlot = new JoyButtonSlot(AntKeyMapper::getInstance()->returnVirtualKey(QtKeyMapperBase::AntKey_KP_7),
QtKeyMapperBase::AntKey_KP_7, JoyButtonSlot::JoyKeyboard, this);
upRightButtonSlot =
new JoyButtonSlot(AntKeyMapper::getInstance()->returnVirtualKey(QtKeyMapperBase::AntKey_KP_9),
QtKeyMapperBase::AntKey_KP_9, JoyButtonSlot::JoyKeyboard, this);
downLeftButtonSlot =
new JoyButtonSlot(AntKeyMapper::getInstance()->returnVirtualKey(QtKeyMapperBase::AntKey_KP_1),
QtKeyMapperBase::AntKey_KP_1, JoyButtonSlot::JoyKeyboard, this);
downRightButtonSlot =
new JoyButtonSlot(AntKeyMapper::getInstance()->returnVirtualKey(QtKeyMapperBase::AntKey_KP_3),
QtKeyMapperBase::AntKey_KP_3, JoyButtonSlot::JoyKeyboard, this);
}
PadderCommon::inputDaemonMutex.unlock(); PadderCommon::inputDaemonMutex.unlock();
break; break;
case 7: case 7:
QMetaObject::invokeMethod(&helper, "clearButtonsSlotsEventReset", Qt::BlockingQueuedConnection); QMetaObject::invokeMethod(&helper, "clearButtonsSlotsEventReset", Qt::BlockingQueuedConnection);
break; break;
} }
QHash<JoyDPadButton::JoyDPadDirections, JoyButtonSlot*> tempHash; QHash<JoyDPadButton::JoyDPadDirections, JoyButtonSlot *> tempHash;
tempHash.insert(JoyDPadButton::DpadUp, upButtonSlot); tempHash.insert(JoyDPadButton::DpadUp, upButtonSlot);
tempHash.insert(JoyDPadButton::DpadDown, downButtonSlot); tempHash.insert(JoyDPadButton::DpadDown, downButtonSlot);
tempHash.insert(JoyDPadButton::DpadLeft, leftButtonSlot); tempHash.insert(JoyDPadButton::DpadLeft, leftButtonSlot);
@@ -298,16 +325,16 @@ int DPadContextMenu::getPresetIndex()
PadderCommon::inputDaemonMutex.lock(); PadderCommon::inputDaemonMutex.lock();
JoyDPadButton *upButton = dpad->getJoyButton(JoyDPadButton::DpadUp); JoyDPadButton *upButton = dpad->getJoyButton(JoyDPadButton::DpadUp);
QList<JoyButtonSlot*> *upslots = upButton->getAssignedSlots(); QList<JoyButtonSlot *> *upslots = upButton->getAssignedSlots();
JoyDPadButton *downButton = dpad->getJoyButton(JoyDPadButton::DpadDown); JoyDPadButton *downButton = dpad->getJoyButton(JoyDPadButton::DpadDown);
QList<JoyButtonSlot*> *downslots = downButton->getAssignedSlots(); QList<JoyButtonSlot *> *downslots = downButton->getAssignedSlots();
JoyDPadButton *leftButton = dpad->getJoyButton(JoyDPadButton::DpadLeft); JoyDPadButton *leftButton = dpad->getJoyButton(JoyDPadButton::DpadLeft);
QList<JoyButtonSlot*> *leftslots = leftButton->getAssignedSlots(); QList<JoyButtonSlot *> *leftslots = leftButton->getAssignedSlots();
JoyDPadButton *rightButton = dpad->getJoyButton(JoyDPadButton::DpadRight); JoyDPadButton *rightButton = dpad->getJoyButton(JoyDPadButton::DpadRight);
QList<JoyButtonSlot*> *rightslots = rightButton->getAssignedSlots(); QList<JoyButtonSlot *> *rightslots = rightButton->getAssignedSlots();
if ((upslots->length() == 1) && (downslots->length() == 1) && (leftslots->length() == 1) && (rightslots->length() == 1)) if ((upslots->length() == 1) && (downslots->length() == 1) && (leftslots->length() == 1) && (rightslots->length() == 1))
{ {
@@ -316,57 +343,81 @@ int DPadContextMenu::getPresetIndex()
JoyButtonSlot *leftslot = leftslots->at(0); JoyButtonSlot *leftslot = leftslots->at(0);
JoyButtonSlot *rightslot = rightslots->at(0); JoyButtonSlot *rightslot = rightslots->at(0);
if ((upslot->getSlotMode() == JoyButtonSlot::JoyMouseMovement) && (upslot->getSlotCode() == JoyButtonSlot::MouseUp) && if ((upslot->getSlotMode() == JoyButtonSlot::JoyMouseMovement) &&
(downslot->getSlotMode() == JoyButtonSlot::JoyMouseMovement) && (downslot->getSlotCode() == JoyButtonSlot::MouseDown) && (upslot->getSlotCode() == JoyButtonSlot::MouseUp) &&
(leftslot->getSlotMode() == JoyButtonSlot::JoyMouseMovement) && (leftslot->getSlotCode() == JoyButtonSlot::MouseLeft) && (downslot->getSlotMode() == JoyButtonSlot::JoyMouseMovement) &&
(rightslot->getSlotMode() == JoyButtonSlot::JoyMouseMovement) && (rightslot->getSlotCode() == JoyButtonSlot::MouseRight)) (downslot->getSlotCode() == JoyButtonSlot::MouseDown) &&
(leftslot->getSlotMode() == JoyButtonSlot::JoyMouseMovement) &&
(leftslot->getSlotCode() == JoyButtonSlot::MouseLeft) &&
(rightslot->getSlotMode() == JoyButtonSlot::JoyMouseMovement) &&
(rightslot->getSlotCode() == JoyButtonSlot::MouseRight))
{ {
result = 1; result = 1;
} } else if ((upslot->getSlotMode() == JoyButtonSlot::JoyMouseMovement) &&
else if ((upslot->getSlotMode() == JoyButtonSlot::JoyMouseMovement) && (upslot->getSlotCode() == JoyButtonSlot::MouseUp) && (upslot->getSlotCode() == JoyButtonSlot::MouseUp) &&
(downslot->getSlotMode() == JoyButtonSlot::JoyMouseMovement) && (downslot->getSlotCode() == JoyButtonSlot::MouseDown) && (downslot->getSlotMode() == JoyButtonSlot::JoyMouseMovement) &&
(leftslot->getSlotMode() == JoyButtonSlot::JoyMouseMovement) && (leftslot->getSlotCode() == JoyButtonSlot::MouseRight) && (downslot->getSlotCode() == JoyButtonSlot::MouseDown) &&
(rightslot->getSlotMode() == JoyButtonSlot::JoyMouseMovement) && (rightslot->getSlotCode() == JoyButtonSlot::MouseLeft)) (leftslot->getSlotMode() == JoyButtonSlot::JoyMouseMovement) &&
(leftslot->getSlotCode() == JoyButtonSlot::MouseRight) &&
(rightslot->getSlotMode() == JoyButtonSlot::JoyMouseMovement) &&
(rightslot->getSlotCode() == JoyButtonSlot::MouseLeft))
{ {
result = 2; result = 2;
} } else if ((upslot->getSlotMode() == JoyButtonSlot::JoyMouseMovement) &&
else if ((upslot->getSlotMode() == JoyButtonSlot::JoyMouseMovement) && (upslot->getSlotCode() == JoyButtonSlot::MouseDown) && (upslot->getSlotCode() == JoyButtonSlot::MouseDown) &&
(downslot->getSlotMode() == JoyButtonSlot::JoyMouseMovement) && (downslot->getSlotCode() == JoyButtonSlot::MouseUp) && (downslot->getSlotMode() == JoyButtonSlot::JoyMouseMovement) &&
(leftslot->getSlotMode() == JoyButtonSlot::JoyMouseMovement) && (leftslot->getSlotCode() == JoyButtonSlot::MouseLeft) && (downslot->getSlotCode() == JoyButtonSlot::MouseUp) &&
(rightslot->getSlotMode() == JoyButtonSlot::JoyMouseMovement) && (rightslot->getSlotCode() == JoyButtonSlot::MouseRight)) (leftslot->getSlotMode() == JoyButtonSlot::JoyMouseMovement) &&
(leftslot->getSlotCode() == JoyButtonSlot::MouseLeft) &&
(rightslot->getSlotMode() == JoyButtonSlot::JoyMouseMovement) &&
(rightslot->getSlotCode() == JoyButtonSlot::MouseRight))
{ {
result = 3; result = 3;
} } else if ((upslot->getSlotMode() == JoyButtonSlot::JoyMouseMovement) &&
else if ((upslot->getSlotMode() == JoyButtonSlot::JoyMouseMovement) && (upslot->getSlotCode() == JoyButtonSlot::MouseDown) && (upslot->getSlotCode() == JoyButtonSlot::MouseDown) &&
(downslot->getSlotMode() == JoyButtonSlot::JoyMouseMovement) && (downslot->getSlotCode() == JoyButtonSlot::MouseUp) && (downslot->getSlotMode() == JoyButtonSlot::JoyMouseMovement) &&
(leftslot->getSlotMode() == JoyButtonSlot::JoyMouseMovement) && (leftslot->getSlotCode() == JoyButtonSlot::MouseRight) && (downslot->getSlotCode() == JoyButtonSlot::MouseUp) &&
(rightslot->getSlotMode() == JoyButtonSlot::JoyMouseMovement) && (rightslot->getSlotCode() == JoyButtonSlot::MouseLeft)) (leftslot->getSlotMode() == JoyButtonSlot::JoyMouseMovement) &&
(leftslot->getSlotCode() == JoyButtonSlot::MouseRight) &&
(rightslot->getSlotMode() == JoyButtonSlot::JoyMouseMovement) &&
(rightslot->getSlotCode() == JoyButtonSlot::MouseLeft))
{ {
result = 4; result = 4;
} } else if ((upslot->getSlotMode() == JoyButtonSlot::JoyKeyboard) &&
else if ((upslot->getSlotMode() == JoyButtonSlot::JoyKeyboard) && (upslot->getSlotCode() == AntKeyMapper::getInstance()->returnVirtualKey(Qt::Key_Up)) && (upslot->getSlotCode() == AntKeyMapper::getInstance()->returnVirtualKey(Qt::Key_Up)) &&
(downslot->getSlotMode() == JoyButtonSlot::JoyKeyboard) && (downslot->getSlotCode() == AntKeyMapper::getInstance()->returnVirtualKey(Qt::Key_Down)) && (downslot->getSlotMode() == JoyButtonSlot::JoyKeyboard) &&
(leftslot->getSlotMode() == JoyButtonSlot::JoyKeyboard) && (leftslot->getSlotCode() == AntKeyMapper::getInstance()->returnVirtualKey(Qt::Key_Left)) && (downslot->getSlotCode() == AntKeyMapper::getInstance()->returnVirtualKey(Qt::Key_Down)) &&
(rightslot->getSlotMode() == JoyButtonSlot::JoyKeyboard) && (rightslot->getSlotCode() == AntKeyMapper::getInstance()->returnVirtualKey(Qt::Key_Right))) (leftslot->getSlotMode() == JoyButtonSlot::JoyKeyboard) &&
(leftslot->getSlotCode() == AntKeyMapper::getInstance()->returnVirtualKey(Qt::Key_Left)) &&
(rightslot->getSlotMode() == JoyButtonSlot::JoyKeyboard) &&
(rightslot->getSlotCode() == AntKeyMapper::getInstance()->returnVirtualKey(Qt::Key_Right)))
{ {
result = 5; result = 5;
} } else if ((upslot->getSlotMode() == JoyButtonSlot::JoyKeyboard) &&
else if ((upslot->getSlotMode() == JoyButtonSlot::JoyKeyboard) && (upslot->getSlotCode() == AntKeyMapper::getInstance()->returnVirtualKey(Qt::Key_W)) && (upslot->getSlotCode() == AntKeyMapper::getInstance()->returnVirtualKey(Qt::Key_W)) &&
(downslot->getSlotMode() == JoyButtonSlot::JoyKeyboard) && (downslot->getSlotCode() == AntKeyMapper::getInstance()->returnVirtualKey(Qt::Key_S)) && (downslot->getSlotMode() == JoyButtonSlot::JoyKeyboard) &&
(leftslot->getSlotMode() == JoyButtonSlot::JoyKeyboard) && (leftslot->getSlotCode() == AntKeyMapper::getInstance()->returnVirtualKey(Qt::Key_A)) && (downslot->getSlotCode() == AntKeyMapper::getInstance()->returnVirtualKey(Qt::Key_S)) &&
(rightslot->getSlotMode() == JoyButtonSlot::JoyKeyboard) && (rightslot->getSlotCode() == AntKeyMapper::getInstance()->returnVirtualKey(Qt::Key_D))) (leftslot->getSlotMode() == JoyButtonSlot::JoyKeyboard) &&
(leftslot->getSlotCode() == AntKeyMapper::getInstance()->returnVirtualKey(Qt::Key_A)) &&
(rightslot->getSlotMode() == JoyButtonSlot::JoyKeyboard) &&
(rightslot->getSlotCode() == AntKeyMapper::getInstance()->returnVirtualKey(Qt::Key_D)))
{ {
result = 6; result = 6;
} } else if ((upslot->getSlotMode() == JoyButtonSlot::JoyKeyboard) &&
else if ((upslot->getSlotMode() == JoyButtonSlot::JoyKeyboard) && (upslot->getSlotCode() == AntKeyMapper::getInstance()->returnVirtualKey(QtKeyMapperBase::AntKey_KP_8)) && (upslot->getSlotCode() == AntKeyMapper::getInstance()->returnVirtualKey(QtKeyMapperBase::AntKey_KP_8)) &&
(downslot->getSlotMode() == JoyButtonSlot::JoyKeyboard) && (downslot->getSlotCode() == AntKeyMapper::getInstance()->returnVirtualKey(QtKeyMapperBase::AntKey_KP_2)) && (downslot->getSlotMode() == JoyButtonSlot::JoyKeyboard) &&
(leftslot->getSlotMode() == JoyButtonSlot::JoyKeyboard) && (leftslot->getSlotCode() == AntKeyMapper::getInstance()->returnVirtualKey(QtKeyMapperBase::AntKey_KP_4)) && (downslot->getSlotCode() ==
(rightslot->getSlotMode() == JoyButtonSlot::JoyKeyboard) && (rightslot->getSlotCode() == AntKeyMapper::getInstance()->returnVirtualKey(QtKeyMapperBase::AntKey_KP_6))) AntKeyMapper::getInstance()->returnVirtualKey(QtKeyMapperBase::AntKey_KP_2)) &&
(leftslot->getSlotMode() == JoyButtonSlot::JoyKeyboard) &&
(leftslot->getSlotCode() ==
AntKeyMapper::getInstance()->returnVirtualKey(QtKeyMapperBase::AntKey_KP_4)) &&
(rightslot->getSlotMode() == JoyButtonSlot::JoyKeyboard) &&
(rightslot->getSlotCode() == AntKeyMapper::getInstance()->returnVirtualKey(QtKeyMapperBase::AntKey_KP_6)))
{ {
result = 7; result = 7;
} }
} } else if ((upslots->length() == 0) && (downslots->length() == 0) && (leftslots->length() == 0) &&
else if ((upslots->length() == 0) && (downslots->length() == 0) && (leftslots->length() == 0) && (rightslots->length() == 0)) (rightslots->length() == 0))
{ {
result = 8; result = 8;
} }
@@ -388,7 +439,4 @@ void DPadContextMenu::openMouseSettingsDialog()
dialog->show(); dialog->show();
} }
DPadContextMenuHelper& DPadContextMenu::getHelper() { DPadContextMenuHelper &DPadContextMenu::getHelper() { return helper; }
return helper;
}

View File

@@ -16,7 +16,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef DPADCONTEXTMENU_H #ifndef DPADCONTEXTMENU_H
#define DPADCONTEXTMENU_H #define DPADCONTEXTMENU_H
@@ -31,26 +30,28 @@ class DPadContextMenu : public QMenu
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit DPadContextMenu(JoyDPad *dpad, QWidget *parent = nullptr); explicit DPadContextMenu(JoyDPad *dpad, QWidget *parent = nullptr);
void buildMenu(); void buildMenu();
protected: protected:
int getPresetIndex(); int getPresetIndex();
private slots: private slots:
void setDPadPreset(QAction* action); void setDPadPreset(QAction *action);
void setDPadMode(QAction* action); void setDPadMode(QAction *action);
void openMouseSettingsDialog(); void openMouseSettingsDialog();
private: private:
DPadContextMenuHelper& getHelper(); DPadContextMenuHelper &getHelper();
JoyDPad *dpad; JoyDPad *dpad;
DPadContextMenuHelper helper; DPadContextMenuHelper helper;
void generateActionPreset(QAction* action, QString actionText, int currentPreset, int& presetMode, QActionGroup* presetGroup); void generateActionPreset(QAction *action, QString actionText, int currentPreset, int &presetMode,
void generateActionMode(QActionGroup *modesGroup, QAction* action, QString actionText, int currentPreset, int presetMode); QActionGroup *presetGroup);
void generateActionMode(QActionGroup *modesGroup, QAction *action, QString actionText, int currentPreset,
int presetMode);
}; };
#endif // DPADCONTEXTMENU_H #endif // DPADCONTEXTMENU_H

View File

@@ -19,25 +19,23 @@
#include "dpadeditdialog.h" #include "dpadeditdialog.h"
#include "ui_dpadeditdialog.h" #include "ui_dpadeditdialog.h"
#include "messagehandler.h"
#include "joydpad.h"
#include "mousedialog/mousedpadsettingsdialog.h"
#include "event.h"
#include "antkeymapper.h" #include "antkeymapper.h"
#include "setjoystick.h"
#include "inputdevice.h"
#include "common.h" #include "common.h"
#include "event.h"
#include "inputdevice.h"
#include "joydpad.h"
#include "messagehandler.h"
#include "mousedialog/mousedpadsettingsdialog.h"
#include "setjoystick.h"
#include <QDebug> #include <QDebug>
#include <QHashIterator> #include <QHashIterator>
#include <QList> #include <QList>
DPadEditDialog::DPadEditDialog(JoyDPad *dpad, QWidget *parent)
: QDialog(parent, Qt::Window)
DPadEditDialog::DPadEditDialog(JoyDPad *dpad, QWidget *parent) : , ui(new Ui::DPadEditDialog)
QDialog(parent, Qt::Window), , helper(dpad)
ui(new Ui::DPadEditDialog),
helper(dpad)
{ {
ui->setupUi(this); ui->setupUi(this);
@@ -51,25 +49,23 @@ DPadEditDialog::DPadEditDialog(JoyDPad *dpad, QWidget *parent) :
updateWindowTitleDPadName(); updateWindowTitleDPadName();
switch (dpad->getJoyMode())
switch(dpad->getJoyMode())
{ {
case JoyDPad::StandardMode: case JoyDPad::StandardMode:
ui->joyModeComboBox->setCurrentIndex(0); ui->joyModeComboBox->setCurrentIndex(0);
break; break;
case JoyDPad::EightWayMode: case JoyDPad::EightWayMode:
ui->joyModeComboBox->setCurrentIndex(1); ui->joyModeComboBox->setCurrentIndex(1);
break; break;
case JoyDPad::FourWayCardinal: case JoyDPad::FourWayCardinal:
ui->joyModeComboBox->setCurrentIndex(2); ui->joyModeComboBox->setCurrentIndex(2);
break; break;
case JoyDPad::FourWayDiagonal: case JoyDPad::FourWayDiagonal:
ui->joyModeComboBox->setCurrentIndex(3); ui->joyModeComboBox->setCurrentIndex(3);
break; break;
} }
selectCurrentPreset(); selectCurrentPreset();
@@ -82,14 +78,18 @@ DPadEditDialog::DPadEditDialog(JoyDPad *dpad, QWidget *parent) :
PadderCommon::inputDaemonMutex.unlock(); PadderCommon::inputDaemonMutex.unlock();
connect(ui->presetsComboBox, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this, &DPadEditDialog::implementPresets); connect(ui->presetsComboBox, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this,
connect(ui->joyModeComboBox, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this, &DPadEditDialog::implementModes); &DPadEditDialog::implementPresets);
connect(ui->joyModeComboBox, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this,
&DPadEditDialog::implementModes);
connect(ui->mouseSettingsPushButton, &QPushButton::clicked, this, &DPadEditDialog::openMouseSettingsDialog); connect(ui->mouseSettingsPushButton, &QPushButton::clicked, this, &DPadEditDialog::openMouseSettingsDialog);
connect(ui->dpadNameLineEdit, &QLineEdit::textEdited, dpad, &JoyDPad::setDPadName); connect(ui->dpadNameLineEdit, &QLineEdit::textEdited, dpad, &JoyDPad::setDPadName);
connect(ui->dpadDelaySlider, static_cast<void (QSlider::*)(int)>(&QSlider::valueChanged), &helper, &DPadEditDialogHelper::updateJoyDPadDelay); connect(ui->dpadDelaySlider, static_cast<void (QSlider::*)(int)>(&QSlider::valueChanged), &helper,
&DPadEditDialogHelper::updateJoyDPadDelay);
connect(dpad, &JoyDPad::dpadDelayChanged, this, &DPadEditDialog::updateDPadDelaySpinBox); connect(dpad, &JoyDPad::dpadDelayChanged, this, &DPadEditDialog::updateDPadDelaySpinBox);
connect(ui->dpadDelayDoubleSpinBox, static_cast<void (QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged), this, &DPadEditDialog::updateDPadDelaySlider); connect(ui->dpadDelayDoubleSpinBox, static_cast<void (QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged), this,
&DPadEditDialog::updateDPadDelaySlider);
connect(dpad, &JoyDPad::dpadNameChanged, this, &DPadEditDialog::updateWindowTitleDPadName); connect(dpad, &JoyDPad::dpadNameChanged, this, &DPadEditDialog::updateWindowTitleDPadName);
} }
@@ -114,146 +114,173 @@ void DPadEditDialog::implementPresets(int index)
JoyButtonSlot *downLeftButtonSlot = nullptr; JoyButtonSlot *downLeftButtonSlot = nullptr;
JoyButtonSlot *downRightButtonSlot = nullptr; JoyButtonSlot *downRightButtonSlot = nullptr;
switch(index) switch (index)
{ {
case 1: case 1:
PadderCommon::inputDaemonMutex.lock(); PadderCommon::inputDaemonMutex.lock();
upButtonSlot = new JoyButtonSlot(JoyButtonSlot::MouseUp, JoyButtonSlot::JoyMouseMovement, this); upButtonSlot = new JoyButtonSlot(JoyButtonSlot::MouseUp, JoyButtonSlot::JoyMouseMovement, this);
downButtonSlot = new JoyButtonSlot(JoyButtonSlot::MouseDown, JoyButtonSlot::JoyMouseMovement, this); downButtonSlot = new JoyButtonSlot(JoyButtonSlot::MouseDown, JoyButtonSlot::JoyMouseMovement, this);
leftButtonSlot = new JoyButtonSlot(JoyButtonSlot::MouseLeft, JoyButtonSlot::JoyMouseMovement, this); leftButtonSlot = new JoyButtonSlot(JoyButtonSlot::MouseLeft, JoyButtonSlot::JoyMouseMovement, this);
rightButtonSlot = new JoyButtonSlot(JoyButtonSlot::MouseRight, JoyButtonSlot::JoyMouseMovement, this); rightButtonSlot = new JoyButtonSlot(JoyButtonSlot::MouseRight, JoyButtonSlot::JoyMouseMovement, this);
PadderCommon::inputDaemonMutex.unlock(); PadderCommon::inputDaemonMutex.unlock();
ui->joyModeComboBox->setCurrentIndex(0); ui->joyModeComboBox->setCurrentIndex(0);
break; break;
case 2: case 2:
PadderCommon::inputDaemonMutex.lock(); PadderCommon::inputDaemonMutex.lock();
upButtonSlot = new JoyButtonSlot(JoyButtonSlot::MouseUp, JoyButtonSlot::JoyMouseMovement, this); upButtonSlot = new JoyButtonSlot(JoyButtonSlot::MouseUp, JoyButtonSlot::JoyMouseMovement, this);
downButtonSlot = new JoyButtonSlot(JoyButtonSlot::MouseDown, JoyButtonSlot::JoyMouseMovement, this); downButtonSlot = new JoyButtonSlot(JoyButtonSlot::MouseDown, JoyButtonSlot::JoyMouseMovement, this);
leftButtonSlot = new JoyButtonSlot(JoyButtonSlot::MouseRight, JoyButtonSlot::JoyMouseMovement, this); leftButtonSlot = new JoyButtonSlot(JoyButtonSlot::MouseRight, JoyButtonSlot::JoyMouseMovement, this);
rightButtonSlot = new JoyButtonSlot(JoyButtonSlot::MouseLeft, JoyButtonSlot::JoyMouseMovement, this); rightButtonSlot = new JoyButtonSlot(JoyButtonSlot::MouseLeft, JoyButtonSlot::JoyMouseMovement, this);
PadderCommon::inputDaemonMutex.unlock(); PadderCommon::inputDaemonMutex.unlock();
ui->joyModeComboBox->setCurrentIndex(0); ui->joyModeComboBox->setCurrentIndex(0);
break; break;
case 3: case 3:
PadderCommon::inputDaemonMutex.lock(); PadderCommon::inputDaemonMutex.lock();
upButtonSlot = new JoyButtonSlot(JoyButtonSlot::MouseDown, JoyButtonSlot::JoyMouseMovement, this); upButtonSlot = new JoyButtonSlot(JoyButtonSlot::MouseDown, JoyButtonSlot::JoyMouseMovement, this);
downButtonSlot = new JoyButtonSlot(JoyButtonSlot::MouseUp, JoyButtonSlot::JoyMouseMovement, this); downButtonSlot = new JoyButtonSlot(JoyButtonSlot::MouseUp, JoyButtonSlot::JoyMouseMovement, this);
leftButtonSlot = new JoyButtonSlot(JoyButtonSlot::MouseLeft, JoyButtonSlot::JoyMouseMovement, this); leftButtonSlot = new JoyButtonSlot(JoyButtonSlot::MouseLeft, JoyButtonSlot::JoyMouseMovement, this);
rightButtonSlot = new JoyButtonSlot(JoyButtonSlot::MouseRight, JoyButtonSlot::JoyMouseMovement, this); rightButtonSlot = new JoyButtonSlot(JoyButtonSlot::MouseRight, JoyButtonSlot::JoyMouseMovement, this);
PadderCommon::inputDaemonMutex.unlock(); PadderCommon::inputDaemonMutex.unlock();
ui->joyModeComboBox->setCurrentIndex(0); ui->joyModeComboBox->setCurrentIndex(0);
break; break;
case 4: case 4:
PadderCommon::inputDaemonMutex.lock(); PadderCommon::inputDaemonMutex.lock();
upButtonSlot = new JoyButtonSlot(JoyButtonSlot::MouseDown, JoyButtonSlot::JoyMouseMovement, this); upButtonSlot = new JoyButtonSlot(JoyButtonSlot::MouseDown, JoyButtonSlot::JoyMouseMovement, this);
downButtonSlot = new JoyButtonSlot(JoyButtonSlot::MouseUp, JoyButtonSlot::JoyMouseMovement, this); downButtonSlot = new JoyButtonSlot(JoyButtonSlot::MouseUp, JoyButtonSlot::JoyMouseMovement, this);
leftButtonSlot = new JoyButtonSlot(JoyButtonSlot::MouseRight, JoyButtonSlot::JoyMouseMovement, this); leftButtonSlot = new JoyButtonSlot(JoyButtonSlot::MouseRight, JoyButtonSlot::JoyMouseMovement, this);
rightButtonSlot = new JoyButtonSlot(JoyButtonSlot::MouseLeft, JoyButtonSlot::JoyMouseMovement, this); rightButtonSlot = new JoyButtonSlot(JoyButtonSlot::MouseLeft, JoyButtonSlot::JoyMouseMovement, this);
PadderCommon::inputDaemonMutex.unlock(); PadderCommon::inputDaemonMutex.unlock();
ui->joyModeComboBox->setCurrentIndex(0); ui->joyModeComboBox->setCurrentIndex(0);
break; break;
case 5: case 5:
PadderCommon::inputDaemonMutex.lock(); PadderCommon::inputDaemonMutex.lock();
upButtonSlot = new JoyButtonSlot(AntKeyMapper::getInstance()->returnVirtualKey(Qt::Key_Up), Qt::Key_Up, JoyButtonSlot::JoyKeyboard, this); upButtonSlot = new JoyButtonSlot(AntKeyMapper::getInstance()->returnVirtualKey(Qt::Key_Up), Qt::Key_Up,
downButtonSlot = new JoyButtonSlot(AntKeyMapper::getInstance()->returnVirtualKey(Qt::Key_Down), Qt::Key_Down, JoyButtonSlot::JoyKeyboard, this); JoyButtonSlot::JoyKeyboard, this);
leftButtonSlot = new JoyButtonSlot(AntKeyMapper::getInstance()->returnVirtualKey(Qt::Key_Left), Qt::Key_Left, JoyButtonSlot::JoyKeyboard, this); downButtonSlot = new JoyButtonSlot(AntKeyMapper::getInstance()->returnVirtualKey(Qt::Key_Down), Qt::Key_Down,
rightButtonSlot = new JoyButtonSlot(AntKeyMapper::getInstance()->returnVirtualKey(Qt::Key_Right), Qt::Key_Right, JoyButtonSlot::JoyKeyboard, this); JoyButtonSlot::JoyKeyboard, this);
leftButtonSlot = new JoyButtonSlot(AntKeyMapper::getInstance()->returnVirtualKey(Qt::Key_Left), Qt::Key_Left,
JoyButtonSlot::JoyKeyboard, this);
rightButtonSlot = new JoyButtonSlot(AntKeyMapper::getInstance()->returnVirtualKey(Qt::Key_Right), Qt::Key_Right,
JoyButtonSlot::JoyKeyboard, this);
PadderCommon::inputDaemonMutex.unlock(); PadderCommon::inputDaemonMutex.unlock();
ui->joyModeComboBox->setCurrentIndex(0); ui->joyModeComboBox->setCurrentIndex(0);
break; break;
case 6: case 6:
PadderCommon::inputDaemonMutex.lock(); PadderCommon::inputDaemonMutex.lock();
upButtonSlot = new JoyButtonSlot(AntKeyMapper::getInstance()->returnVirtualKey(Qt::Key_W), Qt::Key_W, JoyButtonSlot::JoyKeyboard, this); upButtonSlot = new JoyButtonSlot(AntKeyMapper::getInstance()->returnVirtualKey(Qt::Key_W), Qt::Key_W,
downButtonSlot = new JoyButtonSlot(AntKeyMapper::getInstance()->returnVirtualKey(Qt::Key_S), Qt::Key_S, JoyButtonSlot::JoyKeyboard, this); JoyButtonSlot::JoyKeyboard, this);
leftButtonSlot = new JoyButtonSlot(AntKeyMapper::getInstance()->returnVirtualKey(Qt::Key_A), Qt::Key_A, JoyButtonSlot::JoyKeyboard, this); downButtonSlot = new JoyButtonSlot(AntKeyMapper::getInstance()->returnVirtualKey(Qt::Key_S), Qt::Key_S,
rightButtonSlot = new JoyButtonSlot(AntKeyMapper::getInstance()->returnVirtualKey(Qt::Key_D), Qt::Key_D, JoyButtonSlot::JoyKeyboard, this); JoyButtonSlot::JoyKeyboard, this);
leftButtonSlot = new JoyButtonSlot(AntKeyMapper::getInstance()->returnVirtualKey(Qt::Key_A), Qt::Key_A,
JoyButtonSlot::JoyKeyboard, this);
rightButtonSlot = new JoyButtonSlot(AntKeyMapper::getInstance()->returnVirtualKey(Qt::Key_D), Qt::Key_D,
JoyButtonSlot::JoyKeyboard, this);
PadderCommon::inputDaemonMutex.unlock(); PadderCommon::inputDaemonMutex.unlock();
ui->joyModeComboBox->setCurrentIndex(0); ui->joyModeComboBox->setCurrentIndex(0);
break; break;
case 7: case 7:
PadderCommon::inputDaemonMutex.lock(); PadderCommon::inputDaemonMutex.lock();
if ((ui->joyModeComboBox->currentIndex() == 0) || if ((ui->joyModeComboBox->currentIndex() == 0) || (ui->joyModeComboBox->currentIndex() == 2))
(ui->joyModeComboBox->currentIndex() == 2)) {
{ upButtonSlot = new JoyButtonSlot(AntKeyMapper::getInstance()->returnVirtualKey(QtKeyMapperBase::AntKey_KP_8),
upButtonSlot = new JoyButtonSlot(AntKeyMapper::getInstance()->returnVirtualKey(QtKeyMapperBase::AntKey_KP_8), QtKeyMapperBase::AntKey_KP_8, JoyButtonSlot::JoyKeyboard, this); QtKeyMapperBase::AntKey_KP_8, JoyButtonSlot::JoyKeyboard, this);
downButtonSlot = new JoyButtonSlot(AntKeyMapper::getInstance()->returnVirtualKey(QtKeyMapperBase::AntKey_KP_2), QtKeyMapperBase::AntKey_KP_2, JoyButtonSlot::JoyKeyboard, this); downButtonSlot = new JoyButtonSlot(AntKeyMapper::getInstance()->returnVirtualKey(QtKeyMapperBase::AntKey_KP_2),
leftButtonSlot = new JoyButtonSlot(AntKeyMapper::getInstance()->returnVirtualKey(QtKeyMapperBase::AntKey_KP_4), QtKeyMapperBase::AntKey_KP_4, JoyButtonSlot::JoyKeyboard, this); QtKeyMapperBase::AntKey_KP_2, JoyButtonSlot::JoyKeyboard, this);
rightButtonSlot = new JoyButtonSlot(AntKeyMapper::getInstance()->returnVirtualKey(QtKeyMapperBase::AntKey_KP_6), QtKeyMapperBase::AntKey_KP_6, JoyButtonSlot::JoyKeyboard, this); leftButtonSlot = new JoyButtonSlot(AntKeyMapper::getInstance()->returnVirtualKey(QtKeyMapperBase::AntKey_KP_4),
} QtKeyMapperBase::AntKey_KP_4, JoyButtonSlot::JoyKeyboard, this);
else if (ui->joyModeComboBox->currentIndex() == 1) rightButtonSlot = new JoyButtonSlot(AntKeyMapper::getInstance()->returnVirtualKey(QtKeyMapperBase::AntKey_KP_6),
{ QtKeyMapperBase::AntKey_KP_6, JoyButtonSlot::JoyKeyboard, this);
upButtonSlot = new JoyButtonSlot(AntKeyMapper::getInstance()->returnVirtualKey(QtKeyMapperBase::AntKey_KP_8), QtKeyMapperBase::AntKey_KP_8, JoyButtonSlot::JoyKeyboard, this); } else if (ui->joyModeComboBox->currentIndex() == 1)
downButtonSlot = new JoyButtonSlot(AntKeyMapper::getInstance()->returnVirtualKey(QtKeyMapperBase::AntKey_KP_2), QtKeyMapperBase::AntKey_KP_2, JoyButtonSlot::JoyKeyboard, this); {
leftButtonSlot = new JoyButtonSlot(AntKeyMapper::getInstance()->returnVirtualKey(QtKeyMapperBase::AntKey_KP_4), QtKeyMapperBase::AntKey_KP_4, JoyButtonSlot::JoyKeyboard, this); upButtonSlot = new JoyButtonSlot(AntKeyMapper::getInstance()->returnVirtualKey(QtKeyMapperBase::AntKey_KP_8),
rightButtonSlot = new JoyButtonSlot(AntKeyMapper::getInstance()->returnVirtualKey(QtKeyMapperBase::AntKey_KP_6), QtKeyMapperBase::AntKey_KP_6, JoyButtonSlot::JoyKeyboard, this); QtKeyMapperBase::AntKey_KP_8, JoyButtonSlot::JoyKeyboard, this);
downButtonSlot = new JoyButtonSlot(AntKeyMapper::getInstance()->returnVirtualKey(QtKeyMapperBase::AntKey_KP_2),
QtKeyMapperBase::AntKey_KP_2, JoyButtonSlot::JoyKeyboard, this);
leftButtonSlot = new JoyButtonSlot(AntKeyMapper::getInstance()->returnVirtualKey(QtKeyMapperBase::AntKey_KP_4),
QtKeyMapperBase::AntKey_KP_4, JoyButtonSlot::JoyKeyboard, this);
rightButtonSlot = new JoyButtonSlot(AntKeyMapper::getInstance()->returnVirtualKey(QtKeyMapperBase::AntKey_KP_6),
QtKeyMapperBase::AntKey_KP_6, JoyButtonSlot::JoyKeyboard, this);
upLeftButtonSlot = new JoyButtonSlot(AntKeyMapper::getInstance()->returnVirtualKey(QtKeyMapperBase::AntKey_KP_7), QtKeyMapperBase::AntKey_KP_7, JoyButtonSlot::JoyKeyboard, this); upLeftButtonSlot = new JoyButtonSlot(AntKeyMapper::getInstance()->returnVirtualKey(QtKeyMapperBase::AntKey_KP_7),
upRightButtonSlot = new JoyButtonSlot(AntKeyMapper::getInstance()->returnVirtualKey(QtKeyMapperBase::AntKey_KP_9), QtKeyMapperBase::AntKey_KP_9, JoyButtonSlot::JoyKeyboard, this); QtKeyMapperBase::AntKey_KP_7, JoyButtonSlot::JoyKeyboard, this);
downLeftButtonSlot = new JoyButtonSlot(AntKeyMapper::getInstance()->returnVirtualKey(QtKeyMapperBase::AntKey_KP_1), QtKeyMapperBase::AntKey_KP_1, JoyButtonSlot::JoyKeyboard, this); upRightButtonSlot =
downRightButtonSlot = new JoyButtonSlot(AntKeyMapper::getInstance()->returnVirtualKey(QtKeyMapperBase::AntKey_KP_3), QtKeyMapperBase::AntKey_KP_3, JoyButtonSlot::JoyKeyboard, this); new JoyButtonSlot(AntKeyMapper::getInstance()->returnVirtualKey(QtKeyMapperBase::AntKey_KP_9),
} QtKeyMapperBase::AntKey_KP_9, JoyButtonSlot::JoyKeyboard, this);
else if (ui->joyModeComboBox->currentIndex() == 3) downLeftButtonSlot =
{ new JoyButtonSlot(AntKeyMapper::getInstance()->returnVirtualKey(QtKeyMapperBase::AntKey_KP_1),
upLeftButtonSlot = new JoyButtonSlot(AntKeyMapper::getInstance()->returnVirtualKey(QtKeyMapperBase::AntKey_KP_7), QtKeyMapperBase::AntKey_KP_7, JoyButtonSlot::JoyKeyboard, this); QtKeyMapperBase::AntKey_KP_1, JoyButtonSlot::JoyKeyboard, this);
upRightButtonSlot = new JoyButtonSlot(AntKeyMapper::getInstance()->returnVirtualKey(QtKeyMapperBase::AntKey_KP_9), QtKeyMapperBase::AntKey_KP_9, JoyButtonSlot::JoyKeyboard, this); downRightButtonSlot =
downLeftButtonSlot = new JoyButtonSlot(AntKeyMapper::getInstance()->returnVirtualKey(QtKeyMapperBase::AntKey_KP_1), QtKeyMapperBase::AntKey_KP_1, JoyButtonSlot::JoyKeyboard, this); new JoyButtonSlot(AntKeyMapper::getInstance()->returnVirtualKey(QtKeyMapperBase::AntKey_KP_3),
downRightButtonSlot = new JoyButtonSlot(AntKeyMapper::getInstance()->returnVirtualKey(QtKeyMapperBase::AntKey_KP_3), QtKeyMapperBase::AntKey_KP_3, JoyButtonSlot::JoyKeyboard, this); QtKeyMapperBase::AntKey_KP_3, JoyButtonSlot::JoyKeyboard, this);
} } else if (ui->joyModeComboBox->currentIndex() == 3)
{
upLeftButtonSlot = new JoyButtonSlot(AntKeyMapper::getInstance()->returnVirtualKey(QtKeyMapperBase::AntKey_KP_7),
QtKeyMapperBase::AntKey_KP_7, JoyButtonSlot::JoyKeyboard, this);
upRightButtonSlot =
new JoyButtonSlot(AntKeyMapper::getInstance()->returnVirtualKey(QtKeyMapperBase::AntKey_KP_9),
QtKeyMapperBase::AntKey_KP_9, JoyButtonSlot::JoyKeyboard, this);
downLeftButtonSlot =
new JoyButtonSlot(AntKeyMapper::getInstance()->returnVirtualKey(QtKeyMapperBase::AntKey_KP_1),
QtKeyMapperBase::AntKey_KP_1, JoyButtonSlot::JoyKeyboard, this);
downRightButtonSlot =
new JoyButtonSlot(AntKeyMapper::getInstance()->returnVirtualKey(QtKeyMapperBase::AntKey_KP_3),
QtKeyMapperBase::AntKey_KP_3, JoyButtonSlot::JoyKeyboard, this);
}
PadderCommon::inputDaemonMutex.unlock(); PadderCommon::inputDaemonMutex.unlock();
break; break;
case 0: case 0:
case 8: case 8:
QMetaObject::invokeMethod(&helper, "clearButtonsSlotsEventReset", Qt::BlockingQueuedConnection); QMetaObject::invokeMethod(&helper, "clearButtonsSlotsEventReset", Qt::BlockingQueuedConnection);
dpad->getJoyButton(JoyDPadButton::DpadUp)->buildActiveZoneSummaryString(); dpad->getJoyButton(JoyDPadButton::DpadUp)->buildActiveZoneSummaryString();
dpad->getJoyButton(JoyDPadButton::DpadDown)->buildActiveZoneSummaryString(); dpad->getJoyButton(JoyDPadButton::DpadDown)->buildActiveZoneSummaryString();
dpad->getJoyButton(JoyDPadButton::DpadLeft)->buildActiveZoneSummaryString(); dpad->getJoyButton(JoyDPadButton::DpadLeft)->buildActiveZoneSummaryString();
dpad->getJoyButton(JoyDPadButton::DpadRight)->buildActiveZoneSummaryString(); dpad->getJoyButton(JoyDPadButton::DpadRight)->buildActiveZoneSummaryString();
break; break;
} }
QHash<JoyDPadButton::JoyDPadDirections, JoyButtonSlot*> tempHash; QHash<JoyDPadButton::JoyDPadDirections, JoyButtonSlot *> tempHash;
tempHash.insert(JoyDPadButton::DpadUp, upButtonSlot); tempHash.insert(JoyDPadButton::DpadUp, upButtonSlot);
tempHash.insert(JoyDPadButton::DpadDown, downButtonSlot); tempHash.insert(JoyDPadButton::DpadDown, downButtonSlot);
tempHash.insert(JoyDPadButton::DpadLeft, leftButtonSlot); tempHash.insert(JoyDPadButton::DpadLeft, leftButtonSlot);
@@ -267,7 +294,6 @@ void DPadEditDialog::implementPresets(int index)
QMetaObject::invokeMethod(&helper, "setFromPendingSlots", Qt::BlockingQueuedConnection); QMetaObject::invokeMethod(&helper, "setFromPendingSlots", Qt::BlockingQueuedConnection);
} }
void DPadEditDialog::implementModes(int index) void DPadEditDialog::implementModes(int index)
{ {
qInstallMessageHandler(MessageHandler::myMessageOutput); qInstallMessageHandler(MessageHandler::myMessageOutput);
@@ -276,23 +302,23 @@ void DPadEditDialog::implementModes(int index)
dpad->releaseButtonEvents(); dpad->releaseButtonEvents();
switch(index) switch (index)
{ {
case 0: case 0:
dpad->setJoyMode(JoyDPad::StandardMode); dpad->setJoyMode(JoyDPad::StandardMode);
break; break;
case 1: case 1:
dpad->setJoyMode(JoyDPad::EightWayMode); dpad->setJoyMode(JoyDPad::EightWayMode);
break; break;
case 2: case 2:
dpad->setJoyMode(JoyDPad::FourWayCardinal); dpad->setJoyMode(JoyDPad::FourWayCardinal);
break; break;
case 3: case 3:
dpad->setJoyMode(JoyDPad::FourWayDiagonal); dpad->setJoyMode(JoyDPad::FourWayDiagonal);
break; break;
} }
PadderCommon::inputDaemonMutex.unlock(); PadderCommon::inputDaemonMutex.unlock();
@@ -303,16 +329,16 @@ void DPadEditDialog::selectCurrentPreset()
qInstallMessageHandler(MessageHandler::myMessageOutput); qInstallMessageHandler(MessageHandler::myMessageOutput);
JoyDPadButton *upButton = dpad->getJoyButton(JoyDPadButton::DpadUp); JoyDPadButton *upButton = dpad->getJoyButton(JoyDPadButton::DpadUp);
QList<JoyButtonSlot*> *upslots = upButton->getAssignedSlots(); QList<JoyButtonSlot *> *upslots = upButton->getAssignedSlots();
JoyDPadButton *downButton = dpad->getJoyButton(JoyDPadButton::DpadDown); JoyDPadButton *downButton = dpad->getJoyButton(JoyDPadButton::DpadDown);
QList<JoyButtonSlot*> *downslots = downButton->getAssignedSlots(); QList<JoyButtonSlot *> *downslots = downButton->getAssignedSlots();
JoyDPadButton *leftButton = dpad->getJoyButton(JoyDPadButton::DpadLeft); JoyDPadButton *leftButton = dpad->getJoyButton(JoyDPadButton::DpadLeft);
QList<JoyButtonSlot*> *leftslots = leftButton->getAssignedSlots(); QList<JoyButtonSlot *> *leftslots = leftButton->getAssignedSlots();
JoyDPadButton *rightButton = dpad->getJoyButton(JoyDPadButton::DpadRight); JoyDPadButton *rightButton = dpad->getJoyButton(JoyDPadButton::DpadRight);
QList<JoyButtonSlot*> *rightslots = rightButton->getAssignedSlots(); QList<JoyButtonSlot *> *rightslots = rightButton->getAssignedSlots();
if ((upslots->length() == 1) && (downslots->length() == 1) && (leftslots->length() == 1) && (rightslots->length() == 1)) if ((upslots->length() == 1) && (downslots->length() == 1) && (leftslots->length() == 1) && (rightslots->length() == 1))
{ {
@@ -321,58 +347,81 @@ void DPadEditDialog::selectCurrentPreset()
JoyButtonSlot *leftslot = leftslots->at(0); JoyButtonSlot *leftslot = leftslots->at(0);
JoyButtonSlot *rightslot = rightslots->at(0); JoyButtonSlot *rightslot = rightslots->at(0);
if ((upslot->getSlotMode() == JoyButtonSlot::JoyMouseMovement) && (upslot->getSlotCode() == JoyButtonSlot::MouseUp) && if ((upslot->getSlotMode() == JoyButtonSlot::JoyMouseMovement) &&
(downslot->getSlotMode() == JoyButtonSlot::JoyMouseMovement) && (downslot->getSlotCode() == JoyButtonSlot::MouseDown) && (upslot->getSlotCode() == JoyButtonSlot::MouseUp) &&
(leftslot->getSlotMode() == JoyButtonSlot::JoyMouseMovement) && (leftslot->getSlotCode() == JoyButtonSlot::MouseLeft) && (downslot->getSlotMode() == JoyButtonSlot::JoyMouseMovement) &&
(rightslot->getSlotMode() == JoyButtonSlot::JoyMouseMovement) && (rightslot->getSlotCode() == JoyButtonSlot::MouseRight)) (downslot->getSlotCode() == JoyButtonSlot::MouseDown) &&
(leftslot->getSlotMode() == JoyButtonSlot::JoyMouseMovement) &&
(leftslot->getSlotCode() == JoyButtonSlot::MouseLeft) &&
(rightslot->getSlotMode() == JoyButtonSlot::JoyMouseMovement) &&
(rightslot->getSlotCode() == JoyButtonSlot::MouseRight))
{ {
ui->presetsComboBox->setCurrentIndex(1); ui->presetsComboBox->setCurrentIndex(1);
} } else if ((upslot->getSlotMode() == JoyButtonSlot::JoyMouseMovement) &&
else if ((upslot->getSlotMode() == JoyButtonSlot::JoyMouseMovement) && (upslot->getSlotCode() == JoyButtonSlot::MouseUp) && (upslot->getSlotCode() == JoyButtonSlot::MouseUp) &&
(downslot->getSlotMode() == JoyButtonSlot::JoyMouseMovement) && (downslot->getSlotCode() == JoyButtonSlot::MouseDown) && (downslot->getSlotMode() == JoyButtonSlot::JoyMouseMovement) &&
(leftslot->getSlotMode() == JoyButtonSlot::JoyMouseMovement) && (leftslot->getSlotCode() == JoyButtonSlot::MouseRight) && (downslot->getSlotCode() == JoyButtonSlot::MouseDown) &&
(rightslot->getSlotMode() == JoyButtonSlot::JoyMouseMovement) && (rightslot->getSlotCode() == JoyButtonSlot::MouseLeft)) (leftslot->getSlotMode() == JoyButtonSlot::JoyMouseMovement) &&
(leftslot->getSlotCode() == JoyButtonSlot::MouseRight) &&
(rightslot->getSlotMode() == JoyButtonSlot::JoyMouseMovement) &&
(rightslot->getSlotCode() == JoyButtonSlot::MouseLeft))
{ {
ui->presetsComboBox->setCurrentIndex(2); ui->presetsComboBox->setCurrentIndex(2);
} } else if ((upslot->getSlotMode() == JoyButtonSlot::JoyMouseMovement) &&
else if ((upslot->getSlotMode() == JoyButtonSlot::JoyMouseMovement) && (upslot->getSlotCode() == JoyButtonSlot::MouseDown) && (upslot->getSlotCode() == JoyButtonSlot::MouseDown) &&
(downslot->getSlotMode() == JoyButtonSlot::JoyMouseMovement) && (downslot->getSlotCode() == JoyButtonSlot::MouseUp) && (downslot->getSlotMode() == JoyButtonSlot::JoyMouseMovement) &&
(leftslot->getSlotMode() == JoyButtonSlot::JoyMouseMovement) && (leftslot->getSlotCode() == JoyButtonSlot::MouseLeft) && (downslot->getSlotCode() == JoyButtonSlot::MouseUp) &&
(rightslot->getSlotMode() == JoyButtonSlot::JoyMouseMovement) && (rightslot->getSlotCode() == JoyButtonSlot::MouseRight)) (leftslot->getSlotMode() == JoyButtonSlot::JoyMouseMovement) &&
(leftslot->getSlotCode() == JoyButtonSlot::MouseLeft) &&
(rightslot->getSlotMode() == JoyButtonSlot::JoyMouseMovement) &&
(rightslot->getSlotCode() == JoyButtonSlot::MouseRight))
{ {
ui->presetsComboBox->setCurrentIndex(3); ui->presetsComboBox->setCurrentIndex(3);
} } else if ((upslot->getSlotMode() == JoyButtonSlot::JoyMouseMovement) &&
else if ((upslot->getSlotMode() == JoyButtonSlot::JoyMouseMovement) && (upslot->getSlotCode() == JoyButtonSlot::MouseDown) && (upslot->getSlotCode() == JoyButtonSlot::MouseDown) &&
(downslot->getSlotMode() == JoyButtonSlot::JoyMouseMovement) && (downslot->getSlotCode() == JoyButtonSlot::MouseUp) && (downslot->getSlotMode() == JoyButtonSlot::JoyMouseMovement) &&
(leftslot->getSlotMode() == JoyButtonSlot::JoyMouseMovement) && (leftslot->getSlotCode() == JoyButtonSlot::MouseRight) && (downslot->getSlotCode() == JoyButtonSlot::MouseUp) &&
(rightslot->getSlotMode() == JoyButtonSlot::JoyMouseMovement) && (rightslot->getSlotCode() == JoyButtonSlot::MouseLeft)) (leftslot->getSlotMode() == JoyButtonSlot::JoyMouseMovement) &&
(leftslot->getSlotCode() == JoyButtonSlot::MouseRight) &&
(rightslot->getSlotMode() == JoyButtonSlot::JoyMouseMovement) &&
(rightslot->getSlotCode() == JoyButtonSlot::MouseLeft))
{ {
ui->presetsComboBox->setCurrentIndex(4); ui->presetsComboBox->setCurrentIndex(4);
} } else if ((upslot->getSlotMode() == JoyButtonSlot::JoyKeyboard) &&
else if ((upslot->getSlotMode() == JoyButtonSlot::JoyKeyboard) && (upslot->getSlotCode() == AntKeyMapper::getInstance()->returnVirtualKey(Qt::Key_Up)) && (upslot->getSlotCode() == AntKeyMapper::getInstance()->returnVirtualKey(Qt::Key_Up)) &&
(downslot->getSlotMode() == JoyButtonSlot::JoyKeyboard) && (downslot->getSlotCode() == AntKeyMapper::getInstance()->returnVirtualKey(Qt::Key_Down)) && (downslot->getSlotMode() == JoyButtonSlot::JoyKeyboard) &&
(leftslot->getSlotMode() == JoyButtonSlot::JoyKeyboard) && (leftslot->getSlotCode() == AntKeyMapper::getInstance()->returnVirtualKey(Qt::Key_Left)) && (downslot->getSlotCode() == AntKeyMapper::getInstance()->returnVirtualKey(Qt::Key_Down)) &&
(rightslot->getSlotMode() == JoyButtonSlot::JoyKeyboard) && (rightslot->getSlotCode() == AntKeyMapper::getInstance()->returnVirtualKey(Qt::Key_Right))) (leftslot->getSlotMode() == JoyButtonSlot::JoyKeyboard) &&
(leftslot->getSlotCode() == AntKeyMapper::getInstance()->returnVirtualKey(Qt::Key_Left)) &&
(rightslot->getSlotMode() == JoyButtonSlot::JoyKeyboard) &&
(rightslot->getSlotCode() == AntKeyMapper::getInstance()->returnVirtualKey(Qt::Key_Right)))
{ {
ui->presetsComboBox->setCurrentIndex(5); ui->presetsComboBox->setCurrentIndex(5);
} } else if ((upslot->getSlotMode() == JoyButtonSlot::JoyKeyboard) &&
else if ((upslot->getSlotMode() == JoyButtonSlot::JoyKeyboard) && (upslot->getSlotCode() == AntKeyMapper::getInstance()->returnVirtualKey(Qt::Key_W)) && (upslot->getSlotCode() == AntKeyMapper::getInstance()->returnVirtualKey(Qt::Key_W)) &&
(downslot->getSlotMode() == JoyButtonSlot::JoyKeyboard) && (downslot->getSlotCode() == AntKeyMapper::getInstance()->returnVirtualKey(Qt::Key_S)) && (downslot->getSlotMode() == JoyButtonSlot::JoyKeyboard) &&
(leftslot->getSlotMode() == JoyButtonSlot::JoyKeyboard) && (leftslot->getSlotCode() == AntKeyMapper::getInstance()->returnVirtualKey(Qt::Key_A)) && (downslot->getSlotCode() == AntKeyMapper::getInstance()->returnVirtualKey(Qt::Key_S)) &&
(rightslot->getSlotMode() == JoyButtonSlot::JoyKeyboard) && (rightslot->getSlotCode() == AntKeyMapper::getInstance()->returnVirtualKey(Qt::Key_D))) (leftslot->getSlotMode() == JoyButtonSlot::JoyKeyboard) &&
(leftslot->getSlotCode() == AntKeyMapper::getInstance()->returnVirtualKey(Qt::Key_A)) &&
(rightslot->getSlotMode() == JoyButtonSlot::JoyKeyboard) &&
(rightslot->getSlotCode() == AntKeyMapper::getInstance()->returnVirtualKey(Qt::Key_D)))
{ {
ui->presetsComboBox->setCurrentIndex(6); ui->presetsComboBox->setCurrentIndex(6);
} } else if ((upslot->getSlotMode() == JoyButtonSlot::JoyKeyboard) &&
else if ((upslot->getSlotMode() == JoyButtonSlot::JoyKeyboard) && (upslot->getSlotCode() == AntKeyMapper::getInstance()->returnVirtualKey(QtKeyMapperBase::AntKey_KP_8)) && (upslot->getSlotCode() == AntKeyMapper::getInstance()->returnVirtualKey(QtKeyMapperBase::AntKey_KP_8)) &&
(downslot->getSlotMode() == JoyButtonSlot::JoyKeyboard) && (downslot->getSlotCode() == AntKeyMapper::getInstance()->returnVirtualKey(QtKeyMapperBase::AntKey_KP_2)) && (downslot->getSlotMode() == JoyButtonSlot::JoyKeyboard) &&
(leftslot->getSlotMode() == JoyButtonSlot::JoyKeyboard) && (leftslot->getSlotCode() == AntKeyMapper::getInstance()->returnVirtualKey(QtKeyMapperBase::AntKey_KP_4)) && (downslot->getSlotCode() ==
(rightslot->getSlotMode() == JoyButtonSlot::JoyKeyboard) && (rightslot->getSlotCode() == AntKeyMapper::getInstance()->returnVirtualKey(QtKeyMapperBase::AntKey_KP_6))) AntKeyMapper::getInstance()->returnVirtualKey(QtKeyMapperBase::AntKey_KP_2)) &&
(leftslot->getSlotMode() == JoyButtonSlot::JoyKeyboard) &&
(leftslot->getSlotCode() ==
AntKeyMapper::getInstance()->returnVirtualKey(QtKeyMapperBase::AntKey_KP_4)) &&
(rightslot->getSlotMode() == JoyButtonSlot::JoyKeyboard) &&
(rightslot->getSlotCode() == AntKeyMapper::getInstance()->returnVirtualKey(QtKeyMapperBase::AntKey_KP_6)))
{ {
ui->presetsComboBox->setCurrentIndex(7); ui->presetsComboBox->setCurrentIndex(7);
} }
} } else if ((upslots->length() == 0) && (downslots->length() == 0) && (leftslots->length() == 0) &&
else if ((upslots->length() == 0) && (downslots->length() == 0) && (rightslots->length() == 0))
(leftslots->length() == 0) && (rightslots->length() == 0))
{ {
ui->presetsComboBox->setCurrentIndex(8); ui->presetsComboBox->setCurrentIndex(8);
} }
@@ -431,8 +480,10 @@ void DPadEditDialog::updateWindowTitleDPadName()
QString temp = QString(tr("Set")).append(" "); QString temp = QString(tr("Set")).append(" ");
if (!dpad->getDpadName().isEmpty()) temp.append(dpad->getName(false, true)); if (!dpad->getDpadName().isEmpty())
else temp.append(dpad->getName()); temp.append(dpad->getName(false, true));
else
temp.append(dpad->getName());
if (dpad->getParentSet()->getIndex() != 0) if (dpad->getParentSet()->getIndex() != 0)
{ {
@@ -451,17 +502,8 @@ void DPadEditDialog::updateWindowTitleDPadName()
setWindowTitle(temp); setWindowTitle(temp);
} }
JoyDPad* DPadEditDialog::getDPad() const { JoyDPad *DPadEditDialog::getDPad() const { return dpad; }
return dpad; DPadEditDialogHelper const &DPadEditDialog::getHelper() { return helper; }
}
DPadEditDialogHelper const& DPadEditDialog::getHelper() { DPadEditDialogHelper &DPadEditDialog::getHelperLocal() { return helper; }
return helper;
}
DPadEditDialogHelper& DPadEditDialog::getHelperLocal() {
return helper;
}

View File

@@ -19,7 +19,6 @@
#ifndef DPADEDITDIALOG_H #ifndef DPADEDITDIALOG_H
#define DPADEDITDIALOG_H #define DPADEDITDIALOG_H
#include "uihelpers/dpadeditdialoghelper.h" #include "uihelpers/dpadeditdialoghelper.h"
#include <QDialog> #include <QDialog>
@@ -34,18 +33,18 @@ class DPadEditDialog;
class DPadEditDialog : public QDialog class DPadEditDialog : public QDialog
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit DPadEditDialog(JoyDPad *dpad, QWidget *parent = nullptr); explicit DPadEditDialog(JoyDPad *dpad, QWidget *parent = nullptr);
~DPadEditDialog(); ~DPadEditDialog();
JoyDPad* getDPad() const; JoyDPad *getDPad() const;
DPadEditDialogHelper const& getHelper(); DPadEditDialogHelper const &getHelper();
protected: protected:
void selectCurrentPreset(); void selectCurrentPreset();
private slots: private slots:
void implementPresets(int index); void implementPresets(int index);
void implementModes(int index); void implementModes(int index);
void openMouseSettingsDialog(); void openMouseSettingsDialog();
@@ -54,13 +53,12 @@ private slots:
void updateDPadDelaySpinBox(int value); void updateDPadDelaySpinBox(int value);
void updateDPadDelaySlider(double value); void updateDPadDelaySlider(double value);
private: private:
Ui::DPadEditDialog *ui; Ui::DPadEditDialog *ui;
DPadEditDialogHelper& getHelperLocal(); DPadEditDialogHelper &getHelperLocal();
JoyDPad *dpad; JoyDPad *dpad;
DPadEditDialogHelper helper; DPadEditDialogHelper helper;
}; };
#endif // DPADEDITDIALOG_H #endif // DPADEDITDIALOG_H

View File

@@ -18,14 +18,14 @@
#include "dpadpushbutton.h" #include "dpadpushbutton.h"
#include "messagehandler.h"
#include "joydpad.h"
#include "dpadcontextmenu.h" #include "dpadcontextmenu.h"
#include "joydpad.h"
#include "messagehandler.h"
#include <QDebug> #include <QDebug>
DPadPushButton::DPadPushButton(JoyDPad *dpad, bool displayNames, QWidget *parent) : DPadPushButton::DPadPushButton(JoyDPad *dpad, bool displayNames, QWidget *parent)
FlashButtonWidget(displayNames, parent) : FlashButtonWidget(displayNames, parent)
{ {
qInstallMessageHandler(MessageHandler::myMessageOutput); qInstallMessageHandler(MessageHandler::myMessageOutput);
@@ -42,7 +42,7 @@ DPadPushButton::DPadPushButton(JoyDPad *dpad, bool displayNames, QWidget *parent
connect(dpad, &JoyDPad::dpadNameChanged, this, &DPadPushButton::refreshLabel); connect(dpad, &JoyDPad::dpadNameChanged, this, &DPadPushButton::refreshLabel);
} }
JoyDPad* DPadPushButton::getDPad() const JoyDPad *DPadPushButton::getDPad() const
{ {
qInstallMessageHandler(MessageHandler::myMessageOutput); qInstallMessageHandler(MessageHandler::myMessageOutput);
@@ -55,13 +55,13 @@ QString DPadPushButton::generateLabel()
QString temp = QString(); QString temp = QString();
if (!dpad->getDpadName().isEmpty()) temp.append(dpad->getName(false, ifDisplayNames())); if (!dpad->getDpadName().isEmpty())
else temp.append(dpad->getName()); temp.append(dpad->getName(false, ifDisplayNames()));
else
temp.append(dpad->getName());
qDebug() << "Dpad button name is: " << temp; qDebug() << "Dpad button name is: " << temp;
return temp; return temp;
} }

View File

@@ -16,14 +16,11 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef DPADPUSHBUTTON_H #ifndef DPADPUSHBUTTON_H
#define DPADPUSHBUTTON_H #define DPADPUSHBUTTON_H
#include "flashbuttonwidget.h" #include "flashbuttonwidget.h"
class JoyDPad; class JoyDPad;
class QWidget; class QWidget;
@@ -31,25 +28,24 @@ class DPadPushButton : public FlashButtonWidget
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit DPadPushButton(JoyDPad *dpad, bool displayNames, QWidget *parent = nullptr); explicit DPadPushButton(JoyDPad *dpad, bool displayNames, QWidget *parent = nullptr);
JoyDPad* getDPad() const; JoyDPad *getDPad() const;
void tryFlash(); void tryFlash();
protected: protected:
QString generateLabel() override; QString generateLabel() override;
public slots: public slots:
void disableFlashes() override; void disableFlashes() override;
void enableFlashes() override; void enableFlashes() override;
private slots: private slots:
void showContextMenu(const QPoint &point); void showContextMenu(const QPoint &point);
private: private:
JoyDPad *dpad; JoyDPad *dpad;
}; };
#endif // DPADPUSHBUTTON_H #endif // DPADPUSHBUTTON_H

View File

@@ -18,20 +18,20 @@
#include "dpadpushbuttongroup.h" #include "dpadpushbuttongroup.h"
#include "messagehandler.h"
#include "joydpad.h"
#include "joydpadbuttonwidget.h"
#include "dpadpushbutton.h"
#include "buttoneditdialog.h" #include "buttoneditdialog.h"
#include "dpadeditdialog.h" #include "dpadeditdialog.h"
#include "dpadpushbutton.h"
#include "inputdevice.h" #include "inputdevice.h"
#include "joydpad.h"
#include "joydpadbuttonwidget.h"
#include "messagehandler.h"
#include <QDebug>
#include <QHash> #include <QHash>
#include <QWidget> #include <QWidget>
#include <QDebug>
DPadPushButtonGroup::DPadPushButtonGroup(JoyDPad *dpad, bool keypadUnlocked, bool displayNames, QWidget *parent) : DPadPushButtonGroup::DPadPushButtonGroup(JoyDPad *dpad, bool keypadUnlocked, bool displayNames, QWidget *parent)
QGridLayout(parent) : QGridLayout(parent)
{ {
qInstallMessageHandler(MessageHandler::myMessageOutput); qInstallMessageHandler(MessageHandler::myMessageOutput);
@@ -49,7 +49,7 @@ void DPadPushButtonGroup::generateButtons()
{ {
qInstallMessageHandler(MessageHandler::myMessageOutput); qInstallMessageHandler(MessageHandler::myMessageOutput);
QHash<int, JoyDPadButton*> *buttons = dpad->getJoyButtons(); QHash<int, JoyDPadButton *> *buttons = dpad->getJoyButtons();
upLeftButton = generateBtnForGrid(buttons, 9, 0, 0); upLeftButton = generateBtnForGrid(buttons, 9, 0, 0);
upButton = generateBtnForGrid(buttons, 1, 0, 1); upButton = generateBtnForGrid(buttons, 1, 0, 1);
@@ -68,14 +68,13 @@ void DPadPushButtonGroup::generateButtons()
downRightButton = generateBtnForGrid(buttons, 6, 2, 2); downRightButton = generateBtnForGrid(buttons, 6, 2, 2);
} }
JoyDPadButtonWidget* DPadPushButtonGroup::generateBtnForGrid(QHash<int, JoyDPadButton*> *buttons, int dpadDirection, int cellRow, int cellCol) JoyDPadButtonWidget *DPadPushButtonGroup::generateBtnForGrid(QHash<int, JoyDPadButton *> *buttons, int dpadDirection,
int cellRow, int cellCol)
{ {
JoyDPadButton *button = buttons->value(static_cast<JoyDPadButton::JoyDPadDirections>(dpadDirection)); JoyDPadButton *button = buttons->value(static_cast<JoyDPadButton::JoyDPadDirections>(dpadDirection));
JoyDPadButtonWidget *pushbutton = new JoyDPadButtonWidget(button, displayNames, parentWidget()); JoyDPadButtonWidget *pushbutton = new JoyDPadButtonWidget(button, displayNames, parentWidget());
connect(pushbutton, &JoyDPadButtonWidget::clicked, this, [this, pushbutton] { connect(pushbutton, &JoyDPadButtonWidget::clicked, this, [this, pushbutton] { openDPadButtonDialog(pushbutton); });
openDPadButtonDialog(pushbutton);
});
button->establishPropertyUpdatedConnections(); button->establishPropertyUpdatedConnections();
connect(button, &JoyDPadButton::slotsChanged, this, &DPadPushButtonGroup::propogateSlotsChanged); connect(button, &JoyDPadButton::slotsChanged, this, &DPadPushButtonGroup::propogateSlotsChanged);
@@ -88,16 +87,14 @@ void DPadPushButtonGroup::changeButtonLayout()
{ {
qInstallMessageHandler(MessageHandler::myMessageOutput); qInstallMessageHandler(MessageHandler::myMessageOutput);
if ((dpad->getJoyMode() == JoyDPad::StandardMode) || if ((dpad->getJoyMode() == JoyDPad::StandardMode) || (dpad->getJoyMode() == JoyDPad::EightWayMode) ||
(dpad->getJoyMode() == JoyDPad::EightWayMode) ||
(dpad->getJoyMode() == JoyDPad::FourWayCardinal)) (dpad->getJoyMode() == JoyDPad::FourWayCardinal))
{ {
upButton->setVisible(true); upButton->setVisible(true);
downButton->setVisible(true); downButton->setVisible(true);
leftButton->setVisible(true); leftButton->setVisible(true);
rightButton->setVisible(true); rightButton->setVisible(true);
} } else
else
{ {
upButton->setVisible(false); upButton->setVisible(false);
downButton->setVisible(false); downButton->setVisible(false);
@@ -105,15 +102,13 @@ void DPadPushButtonGroup::changeButtonLayout()
rightButton->setVisible(false); rightButton->setVisible(false);
} }
if ((dpad->getJoyMode() == JoyDPad::EightWayMode) || if ((dpad->getJoyMode() == JoyDPad::EightWayMode) || (dpad->getJoyMode() == JoyDPad::FourWayDiagonal))
(dpad->getJoyMode() == JoyDPad::FourWayDiagonal))
{ {
upLeftButton->setVisible(true); upLeftButton->setVisible(true);
upRightButton->setVisible(true); upRightButton->setVisible(true);
downLeftButton->setVisible(true); downLeftButton->setVisible(true);
downRightButton->setVisible(true); downRightButton->setVisible(true);
} } else
else
{ {
upLeftButton->setVisible(false); upLeftButton->setVisible(false);
upRightButton->setVisible(false); upRightButton->setVisible(false);
@@ -129,20 +124,21 @@ void DPadPushButtonGroup::propogateSlotsChanged()
emit buttonSlotChanged(); emit buttonSlotChanged();
} }
JoyDPad* DPadPushButtonGroup::getDPad() const JoyDPad *DPadPushButtonGroup::getDPad() const
{ {
qInstallMessageHandler(MessageHandler::myMessageOutput); qInstallMessageHandler(MessageHandler::myMessageOutput);
return dpad; return dpad;
} }
void DPadPushButtonGroup::openDPadButtonDialog(JoyButtonWidget* buttonWidget) void DPadPushButtonGroup::openDPadButtonDialog(JoyButtonWidget *buttonWidget)
{ {
qInstallMessageHandler(MessageHandler::myMessageOutput); qInstallMessageHandler(MessageHandler::myMessageOutput);
JoyButton *button = buttonWidget->getJoyButton(); JoyButton *button = buttonWidget->getJoyButton();
ButtonEditDialog *dialog = new ButtonEditDialog(button, dpad->getParentSet()->getInputDevice(), keypadUnlocked, parentWidget()); ButtonEditDialog *dialog =
new ButtonEditDialog(button, dpad->getParentSet()->getInputDevice(), keypadUnlocked, parentWidget());
dialog->show(); dialog->show();
} }

View File

@@ -16,7 +16,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef DPADPUSHBUTTONGROUP_H #ifndef DPADPUSHBUTTONGROUP_H
#define DPADPUSHBUTTONGROUP_H #define DPADPUSHBUTTONGROUP_H
@@ -33,27 +32,27 @@ class DPadPushButtonGroup : public QGridLayout
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit DPadPushButtonGroup(JoyDPad *dpad, bool keypadUnlocked, bool displayNames = false, QWidget *parent = nullptr); explicit DPadPushButtonGroup(JoyDPad *dpad, bool keypadUnlocked, bool displayNames = false, QWidget *parent = nullptr);
JoyDPad *getDPad() const; JoyDPad *getDPad() const;
protected: protected:
void generateButtons(); void generateButtons();
signals: signals:
void buttonSlotChanged(); void buttonSlotChanged();
public slots: public slots:
void changeButtonLayout(); void changeButtonLayout();
void toggleNameDisplay(); void toggleNameDisplay();
private slots: private slots:
void propogateSlotsChanged(); void propogateSlotsChanged();
void openDPadButtonDialog(JoyButtonWidget* buttonWidget); void openDPadButtonDialog(JoyButtonWidget *buttonWidget);
void showDPadDialog(); void showDPadDialog();
private: private:
JoyDPad *dpad; JoyDPad *dpad;
bool keypadUnlocked; bool keypadUnlocked;
bool displayNames; bool displayNames;
@@ -70,7 +69,8 @@ private:
DPadPushButton *dpadWidget; DPadPushButton *dpadWidget;
JoyDPadButtonWidget * generateBtnForGrid(QHash<int, JoyDPadButton*> *buttons, int dpadDirection , int cellRow, int cellCol); JoyDPadButtonWidget *generateBtnForGrid(QHash<int, JoyDPadButton *> *buttons, int dpadDirection, int cellRow,
int cellCol);
}; };
#endif // DPADPUSHBUTTONGROUP_H #endif // DPADPUSHBUTTONGROUP_H

View File

@@ -19,22 +19,21 @@
#include "editalldefaultautoprofiledialog.h" #include "editalldefaultautoprofiledialog.h"
#include "ui_editalldefaultautoprofiledialog.h" #include "ui_editalldefaultautoprofiledialog.h"
#include "messagehandler.h"
#include "autoprofileinfo.h"
#include "antimicrosettings.h" #include "antimicrosettings.h"
#include "autoprofileinfo.h"
#include "common.h" #include "common.h"
#include "messagehandler.h"
#include <QFileInfo> #include <QDebug>
#include <QFileDialog> #include <QFileDialog>
#include <QFileInfo>
#include <QMessageBox> #include <QMessageBox>
#include <QWidget> #include <QWidget>
#include <QDebug>
EditAllDefaultAutoProfileDialog::EditAllDefaultAutoProfileDialog(AutoProfileInfo *info, AntiMicroSettings *settings, EditAllDefaultAutoProfileDialog::EditAllDefaultAutoProfileDialog(AutoProfileInfo *info, AntiMicroSettings *settings,
QWidget *parent) : QWidget *parent)
QDialog(parent), : QDialog(parent)
ui(new Ui::EditAllDefaultAutoProfileDialog) , ui(new Ui::EditAllDefaultAutoProfileDialog)
{ {
ui->setupUi(this); ui->setupUi(this);
@@ -48,8 +47,10 @@ EditAllDefaultAutoProfileDialog::EditAllDefaultAutoProfileDialog(AutoProfileInfo
if (!info->getProfileLocation().isEmpty()) if (!info->getProfileLocation().isEmpty())
ui->profileLineEdit->setText(info->getProfileLocation()); ui->profileLineEdit->setText(info->getProfileLocation());
connect(ui->profileBrowsePushButton, &QPushButton::clicked, this, &EditAllDefaultAutoProfileDialog::openProfileBrowseDialog); connect(ui->profileBrowsePushButton, &QPushButton::clicked, this,
connect(this, &EditAllDefaultAutoProfileDialog::accepted, this, &EditAllDefaultAutoProfileDialog::saveAutoProfileInformation); &EditAllDefaultAutoProfileDialog::openProfileBrowseDialog);
connect(this, &EditAllDefaultAutoProfileDialog::accepted, this,
&EditAllDefaultAutoProfileDialog::saveAutoProfileInformation);
} }
EditAllDefaultAutoProfileDialog::~EditAllDefaultAutoProfileDialog() EditAllDefaultAutoProfileDialog::~EditAllDefaultAutoProfileDialog()
@@ -64,22 +65,24 @@ void EditAllDefaultAutoProfileDialog::openProfileBrowseDialog()
qInstallMessageHandler(MessageHandler::myMessageOutput); qInstallMessageHandler(MessageHandler::myMessageOutput);
QString preferredProfileDir = PadderCommon::preferredProfileDir(settings); QString preferredProfileDir = PadderCommon::preferredProfileDir(settings);
QString profileFilename = QFileDialog::getOpenFileName(this, tr("Open Config"), preferredProfileDir, QString("Config Files (*.amgp *.xml)")); QString profileFilename =
QFileDialog::getOpenFileName(this, tr("Open Config"), preferredProfileDir, QString("Config Files (*.amgp *.xml)"));
if (!profileFilename.isNull() && !profileFilename.isEmpty()) ui->profileLineEdit->setText(profileFilename); if (!profileFilename.isNull() && !profileFilename.isEmpty())
ui->profileLineEdit->setText(profileFilename);
} }
void EditAllDefaultAutoProfileDialog::saveAutoProfileInformation() void EditAllDefaultAutoProfileDialog::saveAutoProfileInformation()
{ {
qInstallMessageHandler(MessageHandler::myMessageOutput); qInstallMessageHandler(MessageHandler::myMessageOutput);
//info->setGUID("all"); // info->setGUID("all");
info->setUniqueID("all"); info->setUniqueID("all");
info->setProfileLocation(ui->profileLineEdit->text()); info->setProfileLocation(ui->profileLineEdit->text());
info->setActive(true); info->setActive(true);
} }
AutoProfileInfo* EditAllDefaultAutoProfileDialog::getAutoProfile() const AutoProfileInfo *EditAllDefaultAutoProfileDialog::getAutoProfile() const
{ {
qInstallMessageHandler(MessageHandler::myMessageOutput); qInstallMessageHandler(MessageHandler::myMessageOutput);
@@ -107,8 +110,7 @@ void EditAllDefaultAutoProfileDialog::accept()
if (validForm) if (validForm)
{ {
QDialog::accept(); QDialog::accept();
} } else
else
{ {
QMessageBox msgBox; QMessageBox msgBox;
msgBox.setText(errorString); msgBox.setText(errorString);
@@ -117,7 +119,4 @@ void EditAllDefaultAutoProfileDialog::accept()
} }
} }
AntiMicroSettings* EditAllDefaultAutoProfileDialog::getSettings() const { AntiMicroSettings *EditAllDefaultAutoProfileDialog::getSettings() const { return settings; }
return settings;
}

View File

@@ -16,7 +16,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef EDITALLDEFAULTAUTOPROFILEDIALOG_H #ifndef EDITALLDEFAULTAUTOPROFILEDIALOG_H
#define EDITALLDEFAULTAUTOPROFILEDIALOG_H #define EDITALLDEFAULTAUTOPROFILEDIALOG_H
@@ -34,26 +33,23 @@ class EditAllDefaultAutoProfileDialog : public QDialog
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit EditAllDefaultAutoProfileDialog(AutoProfileInfo *info, AntiMicroSettings *settings, explicit EditAllDefaultAutoProfileDialog(AutoProfileInfo *info, AntiMicroSettings *settings, QWidget *parent = nullptr);
QWidget *parent = nullptr);
~EditAllDefaultAutoProfileDialog(); ~EditAllDefaultAutoProfileDialog();
AutoProfileInfo* getAutoProfile() const; AutoProfileInfo *getAutoProfile() const;
AntiMicroSettings* getSettings() const; AntiMicroSettings *getSettings() const;
protected:
protected:
virtual void accept(); virtual void accept();
private:
private:
Ui::EditAllDefaultAutoProfileDialog *ui; Ui::EditAllDefaultAutoProfileDialog *ui;
AutoProfileInfo *info; AutoProfileInfo *info;
AntiMicroSettings *settings; AntiMicroSettings *settings;
private slots: private slots:
void openProfileBrowseDialog(); void openProfileBrowseDialog();
void saveAutoProfileInformation(); void saveAutoProfileInformation();
}; };

View File

@@ -16,48 +16,42 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <QVariant>
#include <QApplication> #include <QApplication>
#include <cmath>
#include <QFileInfo>
#include <QStringList>
#include <QCursor> #include <QCursor>
#include <QDesktopWidget>
#include <QProcess>
#include <QDebug> #include <QDebug>
#include <QDesktopWidget>
#include <QFileInfo>
#include <QMessageBox> #include <QMessageBox>
#include <QProcess>
#include <QStringList>
#include <QVariant>
#include <cmath>
#include "event.h" #include "event.h"
#include "globalvariables.h"
#include "messagehandler.h"
#include "eventhandlerfactory.h" #include "eventhandlerfactory.h"
#include "globalvariables.h"
#include "joybutton.h" #include "joybutton.h"
#include "messagehandler.h"
#if defined(WITH_X11) #if defined(WITH_X11)
#include <X11/Xlib.h> #include "x11extras.h"
#include <X11/Xutil.h> #include <X11/XKBlib.h>
#include <X11/XKBlib.h> #include <X11/Xlib.h>
#include "x11extras.h" #include <X11/Xutil.h>
#ifdef WITH_XTEST #ifdef WITH_XTEST
#include <X11/extensions/XTest.h> #include <X11/extensions/XTest.h>
#endif #endif
#endif #endif
#if defined(WITH_UINPUT) #if defined(WITH_UINPUT)
#include "uinputhelper.h" #include "uinputhelper.h"
#endif #endif
// TODO: Implement function for determining final mouse pointer position // TODO: Implement function for determining final mouse pointer position
// based around a fixed bounding box resolution. // based around a fixed bounding box resolution.
void fakeAbsMouseCoordinates(double springX, double springY, void fakeAbsMouseCoordinates(double springX, double springY, int width, int height, int &finalx, int &finaly, int screen)
int width, int height,
int &finalx, int &finaly, int screen)
{ {
qInstallMessageHandler(MessageHandler::myMessageOutput); qInstallMessageHandler(MessageHandler::myMessageOutput);
@@ -72,8 +66,7 @@ void fakeAbsMouseCoordinates(double springX, double springY,
int destMidWidth = 0; int destMidWidth = 0;
int destMidHeight = 0; int destMidHeight = 0;
QRect deskRect = PadderCommon::mouseHelperObj.getDesktopWidget() QRect deskRect = PadderCommon::mouseHelperObj.getDesktopWidget()->screenGeometry(screen);
->screenGeometry(screen);
screenWidth = deskRect.width(); screenWidth = deskRect.width();
screenHeight = deskRect.height(); screenHeight = deskRect.height();
@@ -85,8 +78,7 @@ void fakeAbsMouseCoordinates(double springX, double springY,
{ {
destSpringWidth = qMin(width, screenWidth); destSpringWidth = qMin(width, screenWidth);
destSpringHeight = qMin(height, screenHeight); destSpringHeight = qMin(height, screenHeight);
} } else
else
{ {
destSpringWidth = screenWidth; destSpringWidth = screenWidth;
destSpringHeight = screenHeight; destSpringHeight = screenHeight;
@@ -109,34 +101,34 @@ void sendevent(JoyButtonSlot *slot, bool pressed)
if (device == JoyButtonSlot::JoyKeyboard) if (device == JoyButtonSlot::JoyKeyboard)
{ {
EventHandlerFactory::getInstance()->handler()->sendKeyboardEvent(slot, pressed); EventHandlerFactory::getInstance()->handler()->sendKeyboardEvent(slot, pressed);
} } else if (device == JoyButtonSlot::JoyMouseButton)
else if (device == JoyButtonSlot::JoyMouseButton)
{ {
EventHandlerFactory::getInstance()->handler()->sendMouseButtonEvent(slot, pressed); EventHandlerFactory::getInstance()->handler()->sendMouseButtonEvent(slot, pressed);
} } else if ((device == JoyButtonSlot::JoyTextEntry) && pressed && !slot->getTextData().isEmpty())
else if ((device == JoyButtonSlot::JoyTextEntry) && pressed && !slot->getTextData().isEmpty())
{ {
EventHandlerFactory::getInstance()->handler()->sendTextEntryEvent(slot->getTextData()); EventHandlerFactory::getInstance()->handler()->sendTextEntryEvent(slot->getTextData());
} } else if ((device == JoyButtonSlot::JoyExecute) && pressed && !slot->getTextData().isEmpty())
else if ((device == JoyButtonSlot::JoyExecute) && pressed && !slot->getTextData().isEmpty())
{ {
if (slot->getExtraData().canConvert<QString>()) if (slot->getExtraData().canConvert<QString>())
{ {
QString argumentsString = slot->getExtraData().toString(); QString argumentsString = slot->getExtraData().toString();
//QStringList argumentsTempList(PadderCommon::parseArgumentsString(argumentsString)); // QStringList argumentsTempList(PadderCommon::parseArgumentsString(argumentsString));
bool success = QProcess::startDetached(QString("%1 %2 %3").arg(detectedScriptExt(slot->getTextData())).arg(slot->getTextData()).arg(argumentsString)); bool success = QProcess::startDetached(QString("%1 %2 %3")
if (!success) qDebug() << "Script cannot be executed"; .arg(detectedScriptExt(slot->getTextData()))
} .arg(slot->getTextData())
else .arg(argumentsString));
if (!success)
qDebug() << "Script cannot be executed";
} else
{ {
bool success = QProcess::startDetached(QString("%1 %2").arg(detectedScriptExt(slot->getTextData())).arg(slot->getTextData())); bool success = QProcess::startDetached(
if (!success) qDebug() << "Script cannot be executed"; QString("%1 %2").arg(detectedScriptExt(slot->getTextData())).arg(slot->getTextData()));
if (!success)
qDebug() << "Script cannot be executed";
} }
} }
} }
QString detectedScriptExt(QString file) QString detectedScriptExt(QString file)
{ {
QFileInfo fileinfo(file); QFileInfo fileinfo(file);
@@ -146,9 +138,9 @@ QString detectedScriptExt(QString file)
if (inputFile.open(QIODevice::ReadOnly)) if (inputFile.open(QIODevice::ReadOnly))
{ {
QTextStream in(&inputFile); QTextStream in(&inputFile);
firstLine = in.readLine(); firstLine = in.readLine();
inputFile.close(); inputFile.close();
} }
/* /*
@@ -158,12 +150,18 @@ QString detectedScriptExt(QString file)
* need to find another way * need to find another way
*/ */
if (fileinfo.completeSuffix() == "sh" || firstLine.contains("bin/bash")) return "/bin/sh"; if (fileinfo.completeSuffix() == "sh" || firstLine.contains("bin/bash"))
else if (fileinfo.completeSuffix() == "py" && firstLine.contains("python3")) return "python3"; return "/bin/sh";
else if (fileinfo.completeSuffix() == "py" && firstLine.contains("python")) return "python"; else if (fileinfo.completeSuffix() == "py" && firstLine.contains("python3"))
else if (fileinfo.completeSuffix() == "pl" || firstLine.contains("usr/bin/perl")) return "perl"; return "python3";
else if (fileinfo.completeSuffix() == "php" || firstLine.contains("/php")) return "php"; else if (fileinfo.completeSuffix() == "py" && firstLine.contains("python"))
else if (fileinfo.completeSuffix() == "rb" || firstLine.contains("ruby")) return "ruby"; return "python";
else if (fileinfo.completeSuffix() == "pl" || firstLine.contains("usr/bin/perl"))
return "perl";
else if (fileinfo.completeSuffix() == "php" || firstLine.contains("/php"))
return "php";
else if (fileinfo.completeSuffix() == "rb" || firstLine.contains("ruby"))
return "ruby";
// when run "chmod +x file_name" // when run "chmod +x file_name"
return ""; return "";
@@ -180,9 +178,8 @@ void sendevent(int code1, int code2)
// TODO: Re-implement spring event generation to simplify the process // TODO: Re-implement spring event generation to simplify the process
// and reduce overhead. Refactor old function to only be used when an absmouse // and reduce overhead. Refactor old function to only be used when an absmouse
// position must be faked. // position must be faked.
void sendSpringEventRefactor(PadderCommon::springModeInfo *fullSpring, void sendSpringEventRefactor(PadderCommon::springModeInfo *fullSpring, PadderCommon::springModeInfo *relativeSpring,
PadderCommon::springModeInfo *relativeSpring, int *const mousePosX, int *const mousePosY)
int* const mousePosX, int* const mousePosY)
{ {
Q_UNUSED(relativeSpring) Q_UNUSED(relativeSpring)
Q_UNUSED(mousePosX) Q_UNUSED(mousePosX)
@@ -216,8 +213,7 @@ void sendSpringEventRefactor(PadderCommon::springModeInfo *fullSpring,
{ {
displacementX = fullSpring->displacementX; displacementX = fullSpring->displacementX;
displacementY = fullSpring->displacementY; displacementY = fullSpring->displacementY;
} } else
else
{ {
displacementX = fullSpring->displacementX; displacementX = fullSpring->displacementX;
displacementY = fullSpring->displacementY; displacementY = fullSpring->displacementY;
@@ -256,18 +252,14 @@ void sendSpringEventRefactor(PadderCommon::springModeInfo *fullSpring,
if (handler->getIdentifier() == "xtest") if (handler->getIdentifier() == "xtest")
{ {
fakeAbsMouseCoordinates(displacementX, displacementY, fakeAbsMouseCoordinates(displacementX, displacementY, springWidth, springHeight, xmovecoor, ymovecoor,
springWidth, springHeight, xmovecoor, ymovecoor,
fullSpring->screen); fullSpring->screen);
} } else if (handler->getIdentifier() == "uinput")
else if (handler->getIdentifier() == "uinput")
{ {
fakeAbsMouseCoordinates(displacementX, displacementY, fakeAbsMouseCoordinates(displacementX, displacementY, springWidth, springHeight, xmovecoor, ymovecoor,
springWidth, springHeight, xmovecoor, ymovecoor,
fullSpring->screen); fullSpring->screen);
} }
} } else
else
{ {
PadderCommon::mouseHelperObj.springMouseMoving = false; PadderCommon::mouseHelperObj.springMouseMoving = false;
PadderCommon::mouseHelperObj.pivotPoint[0] = -1; PadderCommon::mouseHelperObj.pivotPoint[0] = -1;
@@ -279,19 +271,18 @@ void sendSpringEventRefactor(PadderCommon::springModeInfo *fullSpring,
// pointer to fake absolute mouse moves. Otherwise, don't worry about // pointer to fake absolute mouse moves. Otherwise, don't worry about
// current position of the mouse and just send an absolute mouse pointer // current position of the mouse and just send an absolute mouse pointer
// event. // event.
void sendSpringEvent(PadderCommon::springModeInfo *fullSpring, void sendSpringEvent(PadderCommon::springModeInfo *fullSpring, PadderCommon::springModeInfo *relativeSpring,
PadderCommon::springModeInfo *relativeSpring, int *const mousePosX, int *const mousePosY)
int* const mousePosX, int* const mousePosY)
{ {
qInstallMessageHandler(MessageHandler::myMessageOutput); qInstallMessageHandler(MessageHandler::myMessageOutput);
PadderCommon::mouseHelperObj.mouseTimer.stop(); PadderCommon::mouseHelperObj.mouseTimer.stop();
if (((fullSpring->displacementX >= -2.0) && (fullSpring->displacementX <= 1.0) && if (((fullSpring->displacementX >= -2.0) && (fullSpring->displacementX <= 1.0) && (fullSpring->displacementY >= -2.0) &&
(fullSpring->displacementY >= -2.0) && (fullSpring->displacementY <= 1.0)) || (fullSpring->displacementY <= 1.0)) ||
(relativeSpring && ((relativeSpring->displacementX >= -2.0) && (relativeSpring->displacementX <= 1.0) && (relativeSpring && ((relativeSpring->displacementX >= -2.0) && (relativeSpring->displacementX <= 1.0) &&
(relativeSpring->displacementY >= -2.0) && (relativeSpring->displacementY <= 1.0)))) (relativeSpring->displacementY >= -2.0) && (relativeSpring->displacementY <= 1.0))))
{ {
int xmovecoor = 0; int xmovecoor = 0;
int ymovecoor = 0; int ymovecoor = 0;
@@ -315,8 +306,7 @@ void sendSpringEvent(PadderCommon::springModeInfo *fullSpring,
fullSpring->screen = -1; fullSpring->screen = -1;
} }
QRect deskRect = PadderCommon::mouseHelperObj.getDesktopWidget() QRect deskRect = PadderCommon::mouseHelperObj.getDesktopWidget()->screenGeometry(fullSpring->screen);
->screenGeometry(fullSpring->screen);
width = deskRect.width(); width = deskRect.width();
height = deskRect.height(); height = deskRect.height();
@@ -326,8 +316,7 @@ void sendSpringEvent(PadderCommon::springModeInfo *fullSpring,
if (QApplication::platformName() == QStringLiteral("xcb")) if (QApplication::platformName() == QStringLiteral("xcb"))
{ {
currentPoint = X11Extras::getInstance()->getPos(); currentPoint = X11Extras::getInstance()->getPos();
} } else
else
{ {
currentPoint = QCursor::pos(); currentPoint = QCursor::pos();
} }
@@ -346,8 +335,7 @@ void sendSpringEvent(PadderCommon::springModeInfo *fullSpring,
{ {
destSpringWidth = qMin(springWidth, width); destSpringWidth = qMin(springWidth, width);
destSpringHeight = qMin(springHeight, height); destSpringHeight = qMin(springHeight, height);
} } else
else
{ {
destSpringWidth = width; destSpringWidth = width;
destSpringHeight = height; destSpringHeight = height;
@@ -364,8 +352,7 @@ void sendSpringEvent(PadderCommon::springModeInfo *fullSpring,
if (PadderCommon::mouseHelperObj.pivotPoint[0] != -1) if (PadderCommon::mouseHelperObj.pivotPoint[0] != -1)
{ {
pivotX = PadderCommon::mouseHelperObj.pivotPoint[0]; pivotX = PadderCommon::mouseHelperObj.pivotPoint[0];
} } else
else
{ {
pivotX = currentMouseX; pivotX = currentMouseX;
} }
@@ -373,15 +360,18 @@ void sendSpringEvent(PadderCommon::springModeInfo *fullSpring,
if (PadderCommon::mouseHelperObj.pivotPoint[1] != -1) if (PadderCommon::mouseHelperObj.pivotPoint[1] != -1)
{ {
pivotY = PadderCommon::mouseHelperObj.pivotPoint[1]; pivotY = PadderCommon::mouseHelperObj.pivotPoint[1];
} } else
else
{ {
pivotY = currentMouseY; pivotY = currentMouseY;
} }
} }
xmovecoor = (fullSpring->displacementX >= -1.0) ? (midwidth + (fullSpring->displacementX * destMidWidth) + deskRect.x()): pivotX; xmovecoor = (fullSpring->displacementX >= -1.0)
ymovecoor = (fullSpring->displacementY >= -1.0) ? (midheight + (fullSpring->displacementY * destMidHeight) + deskRect.y()) : pivotY; ? (midwidth + (fullSpring->displacementX * destMidWidth) + deskRect.x())
: pivotX;
ymovecoor = (fullSpring->displacementY >= -1.0)
? (midheight + (fullSpring->displacementY * destMidHeight) + deskRect.y())
: pivotY;
int fullSpringDestX = xmovecoor; int fullSpringDestX = xmovecoor;
int fullSpringDestY = ymovecoor; int fullSpringDestY = ymovecoor;
@@ -407,9 +397,11 @@ void sendSpringEvent(PadderCommon::springModeInfo *fullSpring,
ymovecoor += yRelativeMoovCoor; ymovecoor += yRelativeMoovCoor;
} }
if (mousePosX) *mousePosX = xmovecoor; if (mousePosX)
*mousePosX = xmovecoor;
if (mousePosY) *mousePosY = ymovecoor; if (mousePosY)
*mousePosY = ymovecoor;
if ((xmovecoor != currentMouseX) || (ymovecoor != currentMouseY)) if ((xmovecoor != currentMouseX) || (ymovecoor != currentMouseY))
{ {
@@ -425,26 +417,20 @@ void sendSpringEvent(PadderCommon::springModeInfo *fullSpring,
{ {
if (handler->getIdentifier() == "xtest") if (handler->getIdentifier() == "xtest")
{ {
EventHandlerFactory::getInstance()->handler()->sendMouseAbsEvent(xmovecoor, EventHandlerFactory::getInstance()->handler()->sendMouseAbsEvent(xmovecoor, ymovecoor, -1);
ymovecoor, } else if (handler->getIdentifier() == "uinput")
-1);
}
else if (handler->getIdentifier() == "uinput")
{ {
EventHandlerFactory::getInstance()->handler() EventHandlerFactory::getInstance()->handler()->sendMouseSpringEvent(
->sendMouseSpringEvent(xmovecoor, ymovecoor, xmovecoor, ymovecoor, width + deskRect.x(), height + deskRect.y());
width + deskRect.x(), height + deskRect.y());
} }
} } else
else
{ {
EventHandlerFactory::getInstance()->handler()->sendMouseEvent(xmovecoor - currentMouseX, EventHandlerFactory::getInstance()->handler()->sendMouseEvent(xmovecoor - currentMouseX,
ymovecoor - currentMouseY); ymovecoor - currentMouseY);
} }
} } else if (!PadderCommon::mouseHelperObj.springMouseMoving && relativeSpring &&
else if (!PadderCommon::mouseHelperObj.springMouseMoving && relativeSpring && ((relativeSpring->displacementX >= -1.0) || (relativeSpring->displacementY >= -1.0)) &&
((relativeSpring->displacementX >= -1.0) || (relativeSpring->displacementY >= -1.0)) && ((diffx >= (destRelativeWidth * .013)) || (diffy >= (destRelativeHeight * .013))))
((diffx >= (destRelativeWidth * .013)) || (diffy >= (destRelativeHeight * .013))))
{ {
PadderCommon::mouseHelperObj.springMouseMoving = true; PadderCommon::mouseHelperObj.springMouseMoving = true;
BaseEventHandler *handler = EventHandlerFactory::getInstance()->handler(); BaseEventHandler *handler = EventHandlerFactory::getInstance()->handler();
@@ -453,29 +439,22 @@ void sendSpringEvent(PadderCommon::springModeInfo *fullSpring,
{ {
if (handler->getIdentifier() == "xtest") if (handler->getIdentifier() == "xtest")
{ {
EventHandlerFactory::getInstance()->handler()->sendMouseAbsEvent(xmovecoor, EventHandlerFactory::getInstance()->handler()->sendMouseAbsEvent(xmovecoor, ymovecoor, -1);
ymovecoor, } else if (handler->getIdentifier() == "uinput")
-1);
}
else if (handler->getIdentifier() == "uinput")
{ {
EventHandlerFactory::getInstance()->handler() EventHandlerFactory::getInstance()->handler()->sendMouseSpringEvent(
->sendMouseSpringEvent(xmovecoor, ymovecoor, xmovecoor, ymovecoor, width + deskRect.x(), height + deskRect.y());
width + deskRect.x(), height + deskRect.y());
} }
} } else
else
{ {
EventHandlerFactory::getInstance()->handler() EventHandlerFactory::getInstance()->handler()->sendMouseEvent(xmovecoor - currentMouseX,
->sendMouseEvent(xmovecoor - currentMouseX, ymovecoor - currentMouseY); ymovecoor - currentMouseY);
} }
PadderCommon::mouseHelperObj.mouseTimer.start( PadderCommon::mouseHelperObj.mouseTimer.start(
qMax(GlobalVariables::JoyButton::mouseRefreshRate, qMax(GlobalVariables::JoyButton::mouseRefreshRate, GlobalVariables::JoyButton::gamepadRefreshRate) + 1);
GlobalVariables::JoyButton::gamepadRefreshRate) + 1); } else if (!PadderCommon::mouseHelperObj.springMouseMoving &&
} ((diffx >= (destSpringWidth * .013)) || (diffy >= (destSpringHeight * .013))))
else if (!PadderCommon::mouseHelperObj.springMouseMoving &&
((diffx >= (destSpringWidth * .013)) || (diffy >= (destSpringHeight * .013))))
{ {
PadderCommon::mouseHelperObj.springMouseMoving = true; PadderCommon::mouseHelperObj.springMouseMoving = true;
BaseEventHandler *handler = EventHandlerFactory::getInstance()->handler(); BaseEventHandler *handler = EventHandlerFactory::getInstance()->handler();
@@ -484,28 +463,20 @@ void sendSpringEvent(PadderCommon::springModeInfo *fullSpring,
{ {
if (handler->getIdentifier() == "xtest") if (handler->getIdentifier() == "xtest")
{ {
EventHandlerFactory::getInstance()->handler()->sendMouseAbsEvent(xmovecoor, EventHandlerFactory::getInstance()->handler()->sendMouseAbsEvent(xmovecoor, ymovecoor, -1);
ymovecoor, } else if (handler->getIdentifier() == "uinput")
-1);
}
else if (handler->getIdentifier() == "uinput")
{ {
EventHandlerFactory::getInstance()->handler() EventHandlerFactory::getInstance()->handler()->sendMouseSpringEvent(
->sendMouseSpringEvent(xmovecoor, ymovecoor, xmovecoor, ymovecoor, width + deskRect.x(), height + deskRect.y());
width + deskRect.x(), height + deskRect.y());
} }
} } else
else
{ {
EventHandlerFactory::getInstance()->handler() EventHandlerFactory::getInstance()->handler()->sendMouseEvent(xmovecoor - currentMouseX,
->sendMouseEvent(xmovecoor - currentMouseX, ymovecoor - currentMouseY);
ymovecoor - currentMouseY);
} }
PadderCommon::mouseHelperObj.mouseTimer.start( PadderCommon::mouseHelperObj.mouseTimer.start(
qMax(GlobalVariables::JoyButton::mouseRefreshRate, qMax(GlobalVariables::JoyButton::mouseRefreshRate, GlobalVariables::JoyButton::gamepadRefreshRate) + 1);
GlobalVariables::JoyButton::gamepadRefreshRate) + 1);
} }
else if (PadderCommon::mouseHelperObj.springMouseMoving && ((diffx < 2) && (diffy < 2))) else if (PadderCommon::mouseHelperObj.springMouseMoving && ((diffx < 2) && (diffy < 2)))
@@ -521,41 +492,31 @@ void sendSpringEvent(PadderCommon::springModeInfo *fullSpring,
{ {
if (handler->getIdentifier() == "xtest") if (handler->getIdentifier() == "xtest")
{ {
EventHandlerFactory::getInstance()->handler()->sendMouseAbsEvent(xmovecoor, EventHandlerFactory::getInstance()->handler()->sendMouseAbsEvent(xmovecoor, ymovecoor, -1);
ymovecoor, } else if (handler->getIdentifier() == "uinput")
-1);
}
else if (handler->getIdentifier() == "uinput")
{ {
EventHandlerFactory::getInstance()->handler() EventHandlerFactory::getInstance()->handler()->sendMouseSpringEvent(
->sendMouseSpringEvent(xmovecoor, ymovecoor, xmovecoor, ymovecoor, width + deskRect.x(), height + deskRect.y());
width + deskRect.x(), height + deskRect.y());
} }
} } else
else
{ {
EventHandlerFactory::getInstance()->handler() EventHandlerFactory::getInstance()->handler()->sendMouseEvent(xmovecoor - currentMouseX,
->sendMouseEvent(xmovecoor - currentMouseX, ymovecoor - currentMouseY);
ymovecoor - currentMouseY);
} }
PadderCommon::mouseHelperObj.mouseTimer.start( PadderCommon::mouseHelperObj.mouseTimer.start(
qMax(GlobalVariables::JoyButton::mouseRefreshRate, qMax(GlobalVariables::JoyButton::mouseRefreshRate, GlobalVariables::JoyButton::gamepadRefreshRate) + 1);
GlobalVariables::JoyButton::gamepadRefreshRate) + 1);
} }
PadderCommon::mouseHelperObj.previousCursorLocation[0] = currentMouseX; PadderCommon::mouseHelperObj.previousCursorLocation[0] = currentMouseX;
PadderCommon::mouseHelperObj.previousCursorLocation[1] = currentMouseY; PadderCommon::mouseHelperObj.previousCursorLocation[1] = currentMouseY;
PadderCommon::mouseHelperObj.pivotPoint[0] = fullSpringDestX; PadderCommon::mouseHelperObj.pivotPoint[0] = fullSpringDestX;
PadderCommon::mouseHelperObj.pivotPoint[1] = fullSpringDestY; PadderCommon::mouseHelperObj.pivotPoint[1] = fullSpringDestY;
} } else if ((PadderCommon::mouseHelperObj.previousCursorLocation[0] == xmovecoor) &&
else if ((PadderCommon::mouseHelperObj.previousCursorLocation[0] == xmovecoor) && (PadderCommon::mouseHelperObj.previousCursorLocation[1] == ymovecoor))
(PadderCommon::mouseHelperObj.previousCursorLocation[1] == ymovecoor))
{ {
PadderCommon::mouseHelperObj.springMouseMoving = false; PadderCommon::mouseHelperObj.springMouseMoving = false;
} } else
else
{ {
PadderCommon::mouseHelperObj.previousCursorLocation[0] = currentMouseX; PadderCommon::mouseHelperObj.previousCursorLocation[0] = currentMouseX;
PadderCommon::mouseHelperObj.previousCursorLocation[1] = currentMouseY; PadderCommon::mouseHelperObj.previousCursorLocation[1] = currentMouseY;
@@ -563,11 +524,9 @@ void sendSpringEvent(PadderCommon::springModeInfo *fullSpring,
PadderCommon::mouseHelperObj.pivotPoint[1] = fullSpringDestY; PadderCommon::mouseHelperObj.pivotPoint[1] = fullSpringDestY;
PadderCommon::mouseHelperObj.mouseTimer.start( PadderCommon::mouseHelperObj.mouseTimer.start(
qMax(GlobalVariables::JoyButton::mouseRefreshRate, qMax(GlobalVariables::JoyButton::mouseRefreshRate, GlobalVariables::JoyButton::gamepadRefreshRate) + 1);
GlobalVariables::JoyButton::gamepadRefreshRate) + 1);
} }
} } else
else
{ {
PadderCommon::mouseHelperObj.springMouseMoving = false; PadderCommon::mouseHelperObj.springMouseMoving = false;
PadderCommon::mouseHelperObj.pivotPoint[0] = -1; PadderCommon::mouseHelperObj.pivotPoint[0] = -1;
@@ -588,7 +547,7 @@ int X11KeySymToKeycode(QString key)
#ifdef WITH_XTEST #ifdef WITH_XTEST
if (handler->getIdentifier() == "xtest") if (handler->getIdentifier() == "xtest")
{ {
Display* display = X11Extras::getInstance()->display(); Display *display = X11Extras::getInstance()->display();
tempcode = XKeysymToKeycode(display, XStringToKeysym(key.toUtf8().data())); tempcode = XKeysymToKeycode(display, XStringToKeysym(key.toUtf8().data()));
} }
#endif #endif
@@ -604,7 +563,6 @@ int X11KeySymToKeycode(QString key)
return tempcode; return tempcode;
} }
QString keycodeToKeyString(int keycode, int alias) QString keycodeToKeyString(int keycode, int alias)
{ {
qInstallMessageHandler(MessageHandler::myMessageOutput); qInstallMessageHandler(MessageHandler::myMessageOutput);
@@ -618,15 +576,14 @@ QString keycodeToKeyString(int keycode, int alias)
if (keycode <= 0) if (keycode <= 0)
{ {
newkey = "[NO KEY]"; newkey = "[NO KEY]";
} } else
else
{ {
BaseEventHandler *handler = EventHandlerFactory::getInstance()->handler(); BaseEventHandler *handler = EventHandlerFactory::getInstance()->handler();
#ifdef WITH_XTEST #ifdef WITH_XTEST
if (handler->getIdentifier() == "xtest") if (handler->getIdentifier() == "xtest")
{ {
Display* display = X11Extras::getInstance()->display(); Display *display = X11Extras::getInstance()->display();
newkey = QString("0x%1").arg(keycode, 0, 16); newkey = QString("0x%1").arg(keycode, 0, 16);
QString tempkey = XKeysymToString(XkbKeycodeToKeysym(display, static_cast<KeyCode>(keycode), 0, 0)); QString tempkey = XKeysymToString(XkbKeycodeToKeysym(display, static_cast<KeyCode>(keycode), 0, 0));
QString tempalias = X11Extras::getInstance()->getDisplayString(tempkey); QString tempalias = X11Extras::getInstance()->getDisplayString(tempkey);
@@ -634,8 +591,7 @@ QString keycodeToKeyString(int keycode, int alias)
if (!tempalias.isEmpty()) if (!tempalias.isEmpty())
{ {
newkey = tempalias; newkey = tempalias;
} } else
else
{ {
XKeyPressedEvent tempevent; XKeyPressedEvent tempevent;
tempevent.keycode = keycode; tempevent.keycode = keycode;
@@ -655,8 +611,7 @@ QString keycodeToKeyString(int keycode, int alias)
qDebug() << "NEWKEY:" << newkey << endl; qDebug() << "NEWKEY:" << newkey << endl;
qDebug() << "NEWKEY LEGNTH:" << numchars << endl; qDebug() << "NEWKEY LEGNTH:" << numchars << endl;
} } else
else
{ {
newkey = tempkey; newkey = tempkey;
} }
@@ -669,8 +624,10 @@ QString keycodeToKeyString(int keycode, int alias)
{ {
QString tempalias = UInputHelper::getInstance()->getDisplayString(keycode); QString tempalias = UInputHelper::getInstance()->getDisplayString(keycode);
if (!tempalias.isEmpty()) newkey = tempalias; if (!tempalias.isEmpty())
else newkey = QString("0x%1").arg(keycode, 0, 16); newkey = tempalias;
else
newkey = QString("0x%1").arg(keycode, 0, 16);
} }
#endif #endif
} }
@@ -682,17 +639,17 @@ int X11KeyCodeToX11KeySym(int keycode)
{ {
qInstallMessageHandler(MessageHandler::myMessageOutput); qInstallMessageHandler(MessageHandler::myMessageOutput);
#ifdef WITH_X11 #ifdef WITH_X11
Display* display = X11Extras::getInstance()->display(); Display *display = X11Extras::getInstance()->display();
return XkbKeycodeToKeysym(display, static_cast<KeyCode>(keycode), 0, 0); return XkbKeycodeToKeysym(display, static_cast<KeyCode>(keycode), 0, 0);
#else #else
Q_UNUSED(keycode) Q_UNUSED(keycode)
return 0; return 0;
#endif #endif
} }
QString keysymToKeyString(int keysym, int alias) QString keysymToKeyString(int keysym, int alias)
@@ -701,28 +658,27 @@ QString keysymToKeyString(int keysym, int alias)
QString newkey = QString(); QString newkey = QString();
#ifdef WITH_X11 #ifdef WITH_X11
Q_UNUSED(alias) Q_UNUSED(alias)
BaseEventHandler *handler = EventHandlerFactory::getInstance()->handler(); BaseEventHandler *handler = EventHandlerFactory::getInstance()->handler();
if (handler->getIdentifier() == "xtest") if (handler->getIdentifier() == "xtest")
{ {
Display* display = X11Extras::getInstance()->display(); Display *display = X11Extras::getInstance()->display();
int keycode = 0; int keycode = 0;
if (keysym > 0) if (keysym > 0)
keycode = XKeysymToKeycode(display, static_cast<KeySym>(keysym)); keycode = XKeysymToKeycode(display, static_cast<KeySym>(keysym));
newkey = keycodeToKeyString(keycode); newkey = keycodeToKeyString(keycode);
} } else if (handler->getIdentifier() == "uinput")
else if (handler->getIdentifier() == "uinput")
{ {
newkey = keycodeToKeyString(keysym); newkey = keycodeToKeyString(keysym);
} }
#else #else
newkey = keycodeToKeyString(keysym, alias); newkey = keycodeToKeyString(keysym, alias);
#endif #endif
return newkey; return newkey;
} }

View File

@@ -16,35 +16,29 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef EVENT_H #ifndef EVENT_H
#define EVENT_H #define EVENT_H
#include "common.h"
#include "joybuttonslot.h" #include "joybuttonslot.h"
#include "springmousemoveinfo.h" #include "springmousemoveinfo.h"
#include "common.h"
void sendevent(JoyButtonSlot *slot, bool pressed = true);
void sendevent (JoyButtonSlot *slot, bool pressed=true);
void sendevent(int code1, int code2); void sendevent(int code1, int code2);
void sendKeybEvent(JoyButtonSlot *slot, bool pressed=true); void sendKeybEvent(JoyButtonSlot *slot, bool pressed = true);
void sendSpringEventRefactor(PadderCommon::springModeInfo *fullSpring, void sendSpringEventRefactor(PadderCommon::springModeInfo *fullSpring, PadderCommon::springModeInfo *relativeSpring = 0,
PadderCommon::springModeInfo *relativeSpring=0, int *const mousePosX = 0, int *const mousePos = 0);
int* const mousePosX=0, int* const mousePos=0);
void sendSpringEvent(PadderCommon::springModeInfo *fullSpring, void sendSpringEvent(PadderCommon::springModeInfo *fullSpring, PadderCommon::springModeInfo *relativeSpring = 0,
PadderCommon::springModeInfo *relativeSpring=0, int *const mousePosX = 0, int *const mousePos = 0);
int* const mousePosX=0, int* const mousePos=0);
void fakeAbsMouseCoordinates(double springX, double springY, void fakeAbsMouseCoordinates(double springX, double springY, int width, int height, int &finalx, int &finaly,
int width, int height, int screen = -1);
int &finalx, int &finaly, int screen=-1);
QString detectedScriptExt(QString file); QString detectedScriptExt(QString file);
int X11KeySymToKeycode(QString key); int X11KeySymToKeycode(QString key);
QString keycodeToKeyString(int keycode, int alias=0); QString keycodeToKeyString(int keycode, int alias = 0);
int X11KeyCodeToX11KeySym(int keycode); int X11KeyCodeToX11KeySym(int keycode);
QString keysymToKeyString(int keysym, int alias=0); QString keysymToKeyString(int keysym, int alias = 0);
#endif // EVENT_H #endif // EVENT_H

View File

@@ -18,12 +18,11 @@
#include "eventhandlerfactory.h" #include "eventhandlerfactory.h"
#include "messagehandler.h"
#include "eventhandlers/baseeventhandler.h" #include "eventhandlers/baseeventhandler.h"
#include "messagehandler.h"
#include <QHash>
#include <QDebug> #include <QDebug>
#include <QHash>
static QHash<QString, QString> buildDisplayNames() static QHash<QString, QString> buildDisplayNames()
{ {
@@ -39,29 +38,26 @@ static QHash<QString, QString> buildDisplayNames()
QHash<QString, QString> handlerDisplayNames = buildDisplayNames(); QHash<QString, QString> handlerDisplayNames = buildDisplayNames();
EventHandlerFactory* EventHandlerFactory::instance = nullptr; EventHandlerFactory *EventHandlerFactory::instance = nullptr;
EventHandlerFactory::EventHandlerFactory(QString handler, QObject *parent)
: QObject(parent)
EventHandlerFactory::EventHandlerFactory(QString handler, QObject *parent) :
QObject(parent)
{ {
qInstallMessageHandler(MessageHandler::myMessageOutput); qInstallMessageHandler(MessageHandler::myMessageOutput);
#ifdef WITH_UINPUT #ifdef WITH_UINPUT
if (handler == "uinput") if (handler == "uinput")
eventHandler = new UInputEventHandler(this); eventHandler = new UInputEventHandler(this);
#endif #endif
#ifdef WITH_XTEST #ifdef WITH_XTEST
if (handler == "xtest") if (handler == "xtest")
eventHandler = new XTestEventHandler(this); eventHandler = new XTestEventHandler(this);
#endif #endif
} }
EventHandlerFactory::~EventHandlerFactory() EventHandlerFactory::~EventHandlerFactory()
@@ -75,7 +71,7 @@ EventHandlerFactory::~EventHandlerFactory()
} }
} }
EventHandlerFactory* EventHandlerFactory::getInstance(QString handler) EventHandlerFactory *EventHandlerFactory::getInstance(QString handler)
{ {
qInstallMessageHandler(MessageHandler::myMessageOutput); qInstallMessageHandler(MessageHandler::myMessageOutput);
@@ -83,8 +79,10 @@ EventHandlerFactory* EventHandlerFactory::getInstance(QString handler)
{ {
QStringList temp = buildEventGeneratorList(); QStringList temp = buildEventGeneratorList();
if (!handler.isEmpty() && temp.contains(handler)) instance = new EventHandlerFactory(handler); if (!handler.isEmpty() && temp.contains(handler))
else instance = new EventHandlerFactory(fallBackIdentifier()); instance = new EventHandlerFactory(handler);
else
instance = new EventHandlerFactory(fallBackIdentifier());
} }
return instance; return instance;
@@ -101,7 +99,7 @@ void EventHandlerFactory::deleteInstance()
} }
} }
BaseEventHandler* EventHandlerFactory::handler() BaseEventHandler *EventHandlerFactory::handler()
{ {
qInstallMessageHandler(MessageHandler::myMessageOutput); qInstallMessageHandler(MessageHandler::myMessageOutput);
@@ -114,13 +112,13 @@ QString EventHandlerFactory::fallBackIdentifier()
QString temp = QString(); QString temp = QString();
#if defined(WITH_XTEST) #if defined(WITH_XTEST)
temp = "xtest"; temp = "xtest";
#elif defined(WITH_UINPUT) #elif defined(WITH_UINPUT)
temp = "uinput"; temp = "uinput";
#else #else
temp = "xtest"; temp = "xtest";
#endif #endif
return temp; return temp;
} }

View File

@@ -16,66 +16,60 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef EVENTHANDLERFACTORY_H #ifndef EVENTHANDLERFACTORY_H
#define EVENTHANDLERFACTORY_H #define EVENTHANDLERFACTORY_H
#include <QObject> #include <QObject>
#include <QStringList> #include <QStringList>
#ifdef WITH_UINPUT
#ifdef WITH_UINPUT
#include "eventhandlers/uinputeventhandler.h" #include "eventhandlers/uinputeventhandler.h"
#endif #endif
#ifdef WITH_XTEST #ifdef WITH_XTEST
#include "eventhandlers/xtesteventhandler.h" #include "eventhandlers/xtesteventhandler.h"
#endif #endif
#ifdef WITH_XTEST
#ifdef WITH_XTEST
#define ADD_XTEST 1 #define ADD_XTEST 1
#else #else
#define ADD_XTEST 0 #define ADD_XTEST 0
#endif #endif
#ifdef WITH_UINPUT #ifdef WITH_UINPUT
#define ADD_UINPUT 1 #define ADD_UINPUT 1
#else #else
#define ADD_UINPUT 0 #define ADD_UINPUT 0
#endif #endif
#define NUM_BACKENDS (ADD_XTEST + ADD_UINPUT)
#define NUM_BACKENDS (ADD_XTEST + ADD_UINPUT)
#if (NUM_BACKENDS > 1) #if (NUM_BACKENDS > 1)
#define BACKEND_ELSE_IF else if #define BACKEND_ELSE_IF else if
#else #else
#define BACKEND_ELSE_IF if #define BACKEND_ELSE_IF if
#endif #endif
class BaseEventHandler; class BaseEventHandler;
class EventHandlerFactory : public QObject class EventHandlerFactory : public QObject
{ {
Q_OBJECT Q_OBJECT
public: public:
static EventHandlerFactory* getInstance(QString handler = ""); static EventHandlerFactory *getInstance(QString handler = "");
void deleteInstance(); void deleteInstance();
BaseEventHandler* handler(); BaseEventHandler *handler();
static QString fallBackIdentifier(); static QString fallBackIdentifier();
static QStringList buildEventGeneratorList(); static QStringList buildEventGeneratorList();
static QString handlerDisplayName(QString handler); static QString handlerDisplayName(QString handler);
protected: protected:
explicit EventHandlerFactory(QString handler, QObject *parent = nullptr); explicit EventHandlerFactory(QString handler, QObject *parent = nullptr);
~EventHandlerFactory(); ~EventHandlerFactory();
BaseEventHandler *eventHandler; BaseEventHandler *eventHandler;
static EventHandlerFactory *instance; static EventHandlerFactory *instance;
}; };
#endif // EVENTHANDLERFACTORY_H #endif // EVENTHANDLERFACTORY_H

View File

@@ -23,19 +23,13 @@
#include <QDebug> #include <QDebug>
BaseEventHandler::BaseEventHandler(QObject *parent)
BaseEventHandler::BaseEventHandler(QObject *parent) : : QObject(parent)
QObject(parent)
{
qInstallMessageHandler(MessageHandler::myMessageOutput);
}
BaseEventHandler::~BaseEventHandler()
{ {
qInstallMessageHandler(MessageHandler::myMessageOutput); qInstallMessageHandler(MessageHandler::myMessageOutput);
} }
BaseEventHandler::~BaseEventHandler() { qInstallMessageHandler(MessageHandler::myMessageOutput); }
QString BaseEventHandler::getErrorString() QString BaseEventHandler::getErrorString()
{ {
@@ -48,10 +42,7 @@ QString BaseEventHandler::getErrorString()
* @brief Do nothing by default. Allow child classes to specify text to output * @brief Do nothing by default. Allow child classes to specify text to output
* to a text stream. * to a text stream.
*/ */
void BaseEventHandler::printPostMessages() void BaseEventHandler::printPostMessages() { qInstallMessageHandler(MessageHandler::myMessageOutput); }
{
qInstallMessageHandler(MessageHandler::myMessageOutput);
}
/** /**
* @brief Do nothing by default. Useful for child classes to define behavior. * @brief Do nothing by default. Useful for child classes to define behavior.
@@ -75,8 +66,7 @@ void BaseEventHandler::sendMouseAbsEvent(int xDis, int yDis, int screen)
* @param Bounding box width * @param Bounding box width
* @param Bounding box height * @param Bounding box height
*/ */
void BaseEventHandler::sendMouseSpringEvent(int xDis, int yDis, void BaseEventHandler::sendMouseSpringEvent(int xDis, int yDis, int width, int height)
int width, int height)
{ {
qInstallMessageHandler(MessageHandler::myMessageOutput); qInstallMessageHandler(MessageHandler::myMessageOutput);

View File

@@ -16,7 +16,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef BASEEVENTHANDLER_H #ifndef BASEEVENTHANDLER_H
#define BASEEVENTHANDLER_H #define BASEEVENTHANDLER_H
@@ -24,12 +23,11 @@
class JoyButtonSlot; class JoyButtonSlot;
class BaseEventHandler : public QObject class BaseEventHandler : public QObject
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit BaseEventHandler(QObject *parent = nullptr); explicit BaseEventHandler(QObject *parent = nullptr);
virtual ~BaseEventHandler(); virtual ~BaseEventHandler();
@@ -41,8 +39,7 @@ public:
virtual void sendMouseEvent(int xDis, int yDis) = 0; virtual void sendMouseEvent(int xDis, int yDis) = 0;
virtual void sendMouseAbsEvent(int xDis, int yDis, int screen); virtual void sendMouseAbsEvent(int xDis, int yDis, int screen);
virtual void sendMouseSpringEvent(int xDis, int yDis, virtual void sendMouseSpringEvent(int xDis, int yDis, int width, int height);
int width, int height);
virtual void sendMouseSpringEvent(int xDis, int yDis); virtual void sendMouseSpringEvent(int xDis, int yDis);
virtual void sendTextEntryEvent(QString maintext); virtual void sendTextEntryEvent(QString maintext);
@@ -52,10 +49,8 @@ public:
virtual void printPostMessages(); virtual void printPostMessages();
QString getErrorString(); QString getErrorString();
protected:
protected:
QString lastErrorString; QString lastErrorString;
}; };
#endif // BASEEVENTHANDLER_H #endif // BASEEVENTHANDLER_H

View File

@@ -16,55 +16,47 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <unistd.h> #include <cmath>
#include <fcntl.h> #include <fcntl.h>
#include <linux/input.h> #include <linux/input.h>
#include <linux/uinput.h> #include <linux/uinput.h>
#include <cmath> #include <unistd.h>
#include <QDebug> #include <QDebug>
#include <QFileInfo>
#include <QStringList> #include <QStringList>
#include <QStringListIterator> #include <QStringListIterator>
#include <QFileInfo>
#include <QTimer> #include <QTimer>
#include <antkeymapper.h> #include <antkeymapper.h>
#include <common.h>
#include <joybuttonslot.h> #include <joybuttonslot.h>
#include <logger.h> #include <logger.h>
#include <common.h>
static const QString mouseDeviceName = PadderCommon::mouseDeviceName; static const QString mouseDeviceName = PadderCommon::mouseDeviceName;
static const QString keyboardDeviceName = PadderCommon::keyboardDeviceName; static const QString keyboardDeviceName = PadderCommon::keyboardDeviceName;
static const QString springMouseDeviceName = PadderCommon::springMouseDeviceName; static const QString springMouseDeviceName = PadderCommon::springMouseDeviceName;
#ifdef WITH_X11 #ifdef WITH_X11
#if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)) #if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
#include <QApplication> #include <QApplication>
#endif #endif
#include <x11extras.h> #include <x11extras.h>
#endif #endif
#include "uinputeventhandler.h"
#include "messagehandler.h" #include "messagehandler.h"
#include "uinputeventhandler.h"
UInputEventHandler::UInputEventHandler(QObject *parent)
UInputEventHandler::UInputEventHandler(QObject *parent) : : BaseEventHandler(parent)
BaseEventHandler(parent)
{ {
keyboardFileHandler = 0; keyboardFileHandler = 0;
mouseFileHandler = 0; mouseFileHandler = 0;
springMouseFileHandler = 0; springMouseFileHandler = 0;
} }
UInputEventHandler::~UInputEventHandler() { cleanupUinputEvHand(); }
UInputEventHandler::~UInputEventHandler()
{
cleanupUinputEvHand();
}
/** /**
* @brief Initialize keyboard and mouse virtual devices. Each device will * @brief Initialize keyboard and mouse virtual devices. Each device will
@@ -97,22 +89,21 @@ bool UInputEventHandler::init()
if (result) if (result)
{ {
#if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)) #if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
if (QApplication::platformName() == QStringLiteral("xcb")) if (QApplication::platformName() == QStringLiteral("xcb"))
{ {
#endif #endif
// Some time needs to elapse after device creation before changing // Some time needs to elapse after device creation before changing
// pointer settings. Otherwise, settings will not take effect. // pointer settings. Otherwise, settings will not take effect.
QTimer::singleShot(2000, this, SLOT(x11ResetMouseAccelerationChange())); QTimer::singleShot(2000, this, SLOT(x11ResetMouseAccelerationChange()));
#if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
#if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
} }
#endif #endif
} }
#endif #endif
@@ -120,8 +111,7 @@ bool UInputEventHandler::init()
return result; return result;
} }
void UInputEventHandler::initDevice(int &device, QString name, bool &result)
void UInputEventHandler::initDevice(int& device, QString name, bool& result)
{ {
device = openUInputHandle(); device = openUInputHandle();
@@ -131,26 +121,22 @@ void UInputEventHandler::initDevice(int& device, QString name, bool& result)
{ {
setSpringMouseEvents(device); setSpringMouseEvents(device);
createUInputSpringMouseDevice(device); createUInputSpringMouseDevice(device);
} } else if (name == "mouseFileHandler")
else if (name == "mouseFileHandler")
{ {
setRelMouseEvents(device); setRelMouseEvents(device);
createUInputMouseDevice(device); createUInputMouseDevice(device);
} } else if (name == "keyboardFileHandler")
else if (name == "keyboardFileHandler")
{ {
setKeyboardEvents(device); setKeyboardEvents(device);
populateKeyCodes(device); populateKeyCodes(device);
createUInputKeyboardDevice(device); createUInputKeyboardDevice(device);
} }
} } else
else
{ {
result = false; result = false;
} }
} }
#ifdef WITH_X11 #ifdef WITH_X11
void UInputEventHandler::x11ResetMouseAccelerationChange() void UInputEventHandler::x11ResetMouseAccelerationChange()
{ {
@@ -161,12 +147,7 @@ void UInputEventHandler::x11ResetMouseAccelerationChange()
} }
#endif #endif
bool UInputEventHandler::cleanup() { return cleanupUinputEvHand(); }
bool UInputEventHandler::cleanup()
{
return cleanupUinputEvHand();
}
bool UInputEventHandler::cleanupUinputEvHand() bool UInputEventHandler::cleanupUinputEvHand()
{ {
@@ -191,7 +172,6 @@ bool UInputEventHandler::cleanupUinputEvHand()
return true; return true;
} }
void UInputEventHandler::sendKeyboardEvent(JoyButtonSlot *slot, bool pressed) void UInputEventHandler::sendKeyboardEvent(JoyButtonSlot *slot, bool pressed)
{ {
JoyButtonSlot::JoySlotInputAction device = slot->getSlotMode(); JoyButtonSlot::JoySlotInputAction device = slot->getSlotMode();
@@ -203,7 +183,6 @@ void UInputEventHandler::sendKeyboardEvent(JoyButtonSlot *slot, bool pressed)
} }
} }
void UInputEventHandler::sendMouseButtonEvent(JoyButtonSlot *slot, bool pressed) void UInputEventHandler::sendMouseButtonEvent(JoyButtonSlot *slot, bool pressed)
{ {
JoyButtonSlot::JoySlotInputAction device = slot->getSlotMode(); JoyButtonSlot::JoySlotInputAction device = slot->getSlotMode();
@@ -216,73 +195,62 @@ void UInputEventHandler::sendMouseButtonEvent(JoyButtonSlot *slot, bool pressed)
unsigned int tempcode = BTN_LEFT; unsigned int tempcode = BTN_LEFT;
switch (code) switch (code)
{ {
case 3: case 3: {
{ tempcode = BTN_RIGHT;
tempcode = BTN_RIGHT; break;
break; }
} case 2: {
case 2: tempcode = BTN_MIDDLE;
{ break;
tempcode = BTN_MIDDLE; }
break; case 1:
} default: {
case 1: tempcode = BTN_LEFT;
default: }
{
tempcode = BTN_LEFT;
}
} }
write_uinput_event(mouseFileHandler, EV_KEY, tempcode, pressed ? 1 : 0); write_uinput_event(mouseFileHandler, EV_KEY, tempcode, pressed ? 1 : 0);
} } else if (code == 4)
else if (code == 4)
{ {
if (pressed) if (pressed)
{ {
write_uinput_event(mouseFileHandler, EV_REL, REL_WHEEL, 1); write_uinput_event(mouseFileHandler, EV_REL, REL_WHEEL, 1);
} }
} } else if (code == 5)
else if (code == 5)
{ {
if (pressed) if (pressed)
{ {
write_uinput_event(mouseFileHandler, EV_REL, REL_WHEEL, -1); write_uinput_event(mouseFileHandler, EV_REL, REL_WHEEL, -1);
} }
} } else if (code == 6)
else if (code == 6)
{ {
if (pressed) if (pressed)
{ {
write_uinput_event(mouseFileHandler, EV_REL, REL_HWHEEL, 1); write_uinput_event(mouseFileHandler, EV_REL, REL_HWHEEL, 1);
} }
} } else if (code == 7)
else if (code == 7)
{ {
if (pressed) if (pressed)
{ {
write_uinput_event(mouseFileHandler, EV_REL, REL_HWHEEL, -1); write_uinput_event(mouseFileHandler, EV_REL, REL_HWHEEL, -1);
} }
} } else if (code == 8)
else if (code == 8)
{ {
write_uinput_event(mouseFileHandler, EV_KEY, BTN_SIDE, pressed ? 1 : 0); write_uinput_event(mouseFileHandler, EV_KEY, BTN_SIDE, pressed ? 1 : 0);
} } else if (code == 9)
else if (code == 9)
{ {
write_uinput_event(mouseFileHandler, EV_KEY, BTN_EXTRA, pressed ? 1 : 0); write_uinput_event(mouseFileHandler, EV_KEY, BTN_EXTRA, pressed ? 1 : 0);
} }
} }
} }
void UInputEventHandler::sendMouseEvent(int xDis, int yDis) void UInputEventHandler::sendMouseEvent(int xDis, int yDis)
{ {
write_uinput_event(mouseFileHandler, EV_REL, REL_X, xDis, false); write_uinput_event(mouseFileHandler, EV_REL, REL_X, xDis, false);
write_uinput_event(mouseFileHandler, EV_REL, REL_Y, yDis); write_uinput_event(mouseFileHandler, EV_REL, REL_Y, yDis);
} }
void UInputEventHandler::sendMouseAbsEvent(int xDis, int yDis, int screen) void UInputEventHandler::sendMouseAbsEvent(int xDis, int yDis, int screen)
{ {
Q_UNUSED(screen); Q_UNUSED(screen);
@@ -291,9 +259,7 @@ void UInputEventHandler::sendMouseAbsEvent(int xDis, int yDis, int screen)
write_uinput_event(springMouseFileHandler, EV_ABS, ABS_Y, yDis); write_uinput_event(springMouseFileHandler, EV_ABS, ABS_Y, yDis);
} }
void UInputEventHandler::sendMouseSpringEvent(int xDis, int yDis, int width, int height)
void UInputEventHandler::sendMouseSpringEvent(int xDis, int yDis,
int width, int height)
{ {
if ((width > 0) && (height > 0)) if ((width > 0) && (height > 0))
{ {
@@ -306,11 +272,9 @@ void UInputEventHandler::sendMouseSpringEvent(int xDis, int yDis,
} }
} }
void UInputEventHandler::sendMouseSpringEvent(int xDis, int yDis) void UInputEventHandler::sendMouseSpringEvent(int xDis, int yDis)
{ {
if ((xDis >= -1.0) && (xDis <= 1.0) && if ((xDis >= -1.0) && (xDis <= 1.0) && (yDis >= -1.0) && (yDis <= 1.0))
(yDis >= -1.0) && (yDis <= 1.0))
{ {
int fx = ceil(32767 * xDis); int fx = ceil(32767 * xDis);
int fy = ceil(32767 * yDis); int fy = ceil(32767 * yDis);
@@ -318,7 +282,6 @@ void UInputEventHandler::sendMouseSpringEvent(int xDis, int yDis)
} }
} }
int UInputEventHandler::openUInputHandle() int UInputEventHandler::openUInputHandle()
{ {
int filehandle = -1; int filehandle = -1;
@@ -348,8 +311,7 @@ int UInputEventHandler::openUInputHandle()
lastErrorString = tr("Could not find a valid uinput device file.\n" lastErrorString = tr("Could not find a valid uinput device file.\n"
"Please check that you have the uinput module loaded.\n" "Please check that you have the uinput module loaded.\n"
"lsmod | grep uinput"); "lsmod | grep uinput");
} } else
else
{ {
QByteArray tempArray = possibleLocation.toUtf8(); QByteArray tempArray = possibleLocation.toUtf8();
filehandle = open(tempArray.constData(), O_WRONLY | O_NONBLOCK); filehandle = open(tempArray.constData(), O_WRONLY | O_NONBLOCK);
@@ -359,8 +321,7 @@ int UInputEventHandler::openUInputHandle()
lastErrorString = tr("Could not open uinput device file\n" lastErrorString = tr("Could not open uinput device file\n"
"Please check that you have permission to write to the device"); "Please check that you have permission to write to the device");
lastErrorString.append("\n").append(possibleLocation); lastErrorString.append("\n").append(possibleLocation);
} } else
else
{ {
uinputDeviceLocation = possibleLocation; uinputDeviceLocation = possibleLocation;
} }
@@ -369,14 +330,12 @@ int UInputEventHandler::openUInputHandle()
return filehandle; return filehandle;
} }
void UInputEventHandler::setKeyboardEvents(int filehandle) void UInputEventHandler::setKeyboardEvents(int filehandle)
{ {
ioctl(filehandle, UI_SET_EVBIT, EV_KEY); ioctl(filehandle, UI_SET_EVBIT, EV_KEY);
ioctl(filehandle, UI_SET_EVBIT, EV_SYN); ioctl(filehandle, UI_SET_EVBIT, EV_SYN);
} }
void UInputEventHandler::setRelMouseEvents(int filehandle) void UInputEventHandler::setRelMouseEvents(int filehandle)
{ {
ioctl(filehandle, UI_SET_EVBIT, EV_KEY); ioctl(filehandle, UI_SET_EVBIT, EV_KEY);
@@ -395,7 +354,6 @@ void UInputEventHandler::setRelMouseEvents(int filehandle)
ioctl(filehandle, UI_SET_KEYBIT, BTN_EXTRA); ioctl(filehandle, UI_SET_KEYBIT, BTN_EXTRA);
} }
void UInputEventHandler::setSpringMouseEvents(int filehandle) void UInputEventHandler::setSpringMouseEvents(int filehandle)
{ {
ioctl(filehandle, UI_SET_EVBIT, EV_KEY); ioctl(filehandle, UI_SET_EVBIT, EV_KEY);
@@ -417,7 +375,6 @@ void UInputEventHandler::setSpringMouseEvents(int filehandle)
ioctl(filehandle, UI_SET_KEYBIT, BTN_TOOL_PEN); ioctl(filehandle, UI_SET_KEYBIT, BTN_TOOL_PEN);
} }
void UInputEventHandler::populateKeyCodes(int filehandle) void UInputEventHandler::populateKeyCodes(int filehandle)
{ {
for (unsigned int i = KEY_ESC; i <= KEY_MICMUTE; i++) for (unsigned int i = KEY_ESC; i <= KEY_MICMUTE; i++)
@@ -426,7 +383,6 @@ void UInputEventHandler::populateKeyCodes(int filehandle)
} }
} }
void UInputEventHandler::createUInputKeyboardDevice(int filehandle) void UInputEventHandler::createUInputKeyboardDevice(int filehandle)
{ {
struct uinput_user_dev uidev; struct uinput_user_dev uidev;
@@ -435,7 +391,7 @@ void UInputEventHandler::createUInputKeyboardDevice(int filehandle)
QByteArray temp = keyboardDeviceName.toUtf8(); QByteArray temp = keyboardDeviceName.toUtf8();
strncpy(uidev.name, temp.constData(), UINPUT_MAX_NAME_SIZE); strncpy(uidev.name, temp.constData(), UINPUT_MAX_NAME_SIZE);
uidev.id.bustype = BUS_USB; uidev.id.bustype = BUS_USB;
uidev.id.vendor = 0x0; uidev.id.vendor = 0x0;
uidev.id.product = 0x0; uidev.id.product = 0x0;
uidev.id.version = 1; uidev.id.version = 1;
@@ -443,7 +399,6 @@ void UInputEventHandler::createUInputKeyboardDevice(int filehandle)
ioctl(filehandle, UI_DEV_CREATE); ioctl(filehandle, UI_DEV_CREATE);
} }
void UInputEventHandler::createUInputMouseDevice(int filehandle) void UInputEventHandler::createUInputMouseDevice(int filehandle)
{ {
struct uinput_user_dev uidev; struct uinput_user_dev uidev;
@@ -452,7 +407,7 @@ void UInputEventHandler::createUInputMouseDevice(int filehandle)
QByteArray temp = mouseDeviceName.toUtf8(); QByteArray temp = mouseDeviceName.toUtf8();
strncpy(uidev.name, temp.constData(), UINPUT_MAX_NAME_SIZE); strncpy(uidev.name, temp.constData(), UINPUT_MAX_NAME_SIZE);
uidev.id.bustype = BUS_USB; uidev.id.bustype = BUS_USB;
uidev.id.vendor = 0x0; uidev.id.vendor = 0x0;
uidev.id.product = 0x0; uidev.id.product = 0x0;
uidev.id.version = 1; uidev.id.version = 1;
@@ -460,7 +415,6 @@ void UInputEventHandler::createUInputMouseDevice(int filehandle)
ioctl(filehandle, UI_DEV_CREATE); ioctl(filehandle, UI_DEV_CREATE);
} }
void UInputEventHandler::createUInputSpringMouseDevice(int filehandle) void UInputEventHandler::createUInputSpringMouseDevice(int filehandle)
{ {
struct uinput_user_dev uidev; struct uinput_user_dev uidev;
@@ -469,7 +423,7 @@ void UInputEventHandler::createUInputSpringMouseDevice(int filehandle)
QByteArray temp = springMouseDeviceName.toUtf8(); QByteArray temp = springMouseDeviceName.toUtf8();
strncpy(uidev.name, temp.constData(), UINPUT_MAX_NAME_SIZE); strncpy(uidev.name, temp.constData(), UINPUT_MAX_NAME_SIZE);
uidev.id.bustype = BUS_USB; uidev.id.bustype = BUS_USB;
uidev.id.vendor = 0x0; uidev.id.vendor = 0x0;
uidev.id.product = 0x0; uidev.id.product = 0x0;
uidev.id.version = 1; uidev.id.version = 1;
@@ -485,16 +439,13 @@ void UInputEventHandler::createUInputSpringMouseDevice(int filehandle)
ioctl(filehandle, UI_DEV_CREATE); ioctl(filehandle, UI_DEV_CREATE);
} }
void UInputEventHandler::closeUInputDevice(int filehandle) void UInputEventHandler::closeUInputDevice(int filehandle)
{ {
ioctl(filehandle, UI_DEV_DESTROY); ioctl(filehandle, UI_DEV_DESTROY);
close(filehandle); close(filehandle);
} }
void UInputEventHandler::write_uinput_event(int filehandle, int type, int code, int value, bool syn)
void UInputEventHandler::write_uinput_event(int filehandle, int type,
int code, int value, bool syn)
{ {
struct input_event ev; struct input_event ev;
struct input_event ev2; struct input_event ev2;
@@ -519,17 +470,9 @@ void UInputEventHandler::write_uinput_event(int filehandle, int type,
} }
} }
QString UInputEventHandler::getName() { return QString("uinput"); }
QString UInputEventHandler::getName() QString UInputEventHandler::getIdentifier() { return getName(); }
{
return QString("uinput");
}
QString UInputEventHandler::getIdentifier()
{
return getName();
}
/** /**
* @brief Print extra help messages to stdout. * @brief Print extra help messages to stdout.
@@ -547,22 +490,21 @@ void UInputEventHandler::printPostMessages()
} }
} }
void UInputEventHandler::sendTextEntryEvent(QString maintext) void UInputEventHandler::sendTextEntryEvent(QString maintext)
{ {
AntKeyMapper *mapper = AntKeyMapper::getInstance(); AntKeyMapper *mapper = AntKeyMapper::getInstance();
if ((mapper != nullptr) && mapper->getKeyMapper()) if ((mapper != nullptr) && mapper->getKeyMapper())
{ {
QtUInputKeyMapper *keymapper = qobject_cast<QtUInputKeyMapper*>(mapper->getKeyMapper()); QtUInputKeyMapper *keymapper = qobject_cast<QtUInputKeyMapper *>(mapper->getKeyMapper());
#ifdef WITH_X11 #ifdef WITH_X11
QtX11KeyMapper *nativeWinKeyMapper = nullptr; QtX11KeyMapper *nativeWinKeyMapper = nullptr;
if (mapper->getNativeKeyMapper()) if (mapper->getNativeKeyMapper())
{ {
nativeWinKeyMapper = qobject_cast<QtX11KeyMapper*>(mapper->getNativeKeyMapper()); nativeWinKeyMapper = qobject_cast<QtX11KeyMapper *>(mapper->getNativeKeyMapper());
} }
#endif #endif
QList<unsigned int> tempList; QList<unsigned int> tempList;
@@ -574,7 +516,7 @@ void UInputEventHandler::sendTextEntryEvent(QString maintext)
temp.virtualkey = 0; temp.virtualkey = 0;
temp.modifiers = Qt::NoModifier; temp.modifiers = Qt::NoModifier;
#ifdef WITH_X11 #ifdef WITH_X11
if (nativeWinKeyMapper != nullptr) if (nativeWinKeyMapper != nullptr)
{ {
QtX11KeyMapper::charKeyInformation tempX11 = nativeWinKeyMapper->getCharKeyInformation(maintext.at(i)); QtX11KeyMapper::charKeyInformation tempX11 = nativeWinKeyMapper->getCharKeyInformation(maintext.at(i));
@@ -585,19 +527,17 @@ void UInputEventHandler::sendTextEntryEvent(QString maintext)
{ {
temp.virtualkey = keymapper->returnVirtualKey(tempQtKey); temp.virtualkey = keymapper->returnVirtualKey(tempQtKey);
temp.modifiers = tempX11.modifiers; temp.modifiers = tempX11.modifiers;
} } else
else
{ {
temp = keymapper->getCharKeyInformation(maintext.at(i)); temp = keymapper->getCharKeyInformation(maintext.at(i));
} }
} } else
else
{ {
#endif #endif
temp = keymapper->getCharKeyInformation(maintext.at(i)); temp = keymapper->getCharKeyInformation(maintext.at(i));
#ifdef WITH_X11 #ifdef WITH_X11
} }
#endif #endif
if (temp.virtualkey > KEY_RESERVED) if (temp.virtualkey > KEY_RESERVED)
{ {
@@ -629,8 +569,7 @@ void UInputEventHandler::sendTextEntryEvent(QString maintext)
} }
} }
void UInputEventHandler::testAndAppend(bool tested, QList<unsigned int> &tempList, unsigned int key)
void UInputEventHandler::testAndAppend(bool tested, QList<unsigned int>& tempList, unsigned int key)
{ {
if (tested) if (tested)
{ {
@@ -639,26 +578,10 @@ void UInputEventHandler::testAndAppend(bool tested, QList<unsigned int>& tempLis
} }
} }
int UInputEventHandler::getKeyboardFileHandler() { return keyboardFileHandler; }
int UInputEventHandler::getKeyboardFileHandler() { int UInputEventHandler::getMouseFileHandler() { return mouseFileHandler; }
return keyboardFileHandler; int UInputEventHandler::getSpringMouseFileHandler() { return springMouseFileHandler; }
}
const QString UInputEventHandler::getUinputDeviceLocation() { return uinputDeviceLocation; }
int UInputEventHandler::getMouseFileHandler() {
return mouseFileHandler;
}
int UInputEventHandler::getSpringMouseFileHandler() {
return springMouseFileHandler;
}
const QString UInputEventHandler::getUinputDeviceLocation() {
return uinputDeviceLocation;
}

View File

@@ -25,7 +25,7 @@ class UInputEventHandler : public BaseEventHandler
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit UInputEventHandler(QObject *parent = nullptr); explicit UInputEventHandler(QObject *parent = nullptr);
~UInputEventHandler(); ~UInputEventHandler();
@@ -36,8 +36,7 @@ public:
virtual void sendMouseEvent(int xDis, int yDis) override; virtual void sendMouseEvent(int xDis, int yDis) override;
virtual void sendMouseAbsEvent(int xDis, int yDis, int screen) override; virtual void sendMouseAbsEvent(int xDis, int yDis, int screen) override;
virtual void sendMouseSpringEvent(int xDis, int yDis, virtual void sendMouseSpringEvent(int xDis, int yDis, int width, int height) override;
int width, int height) override;
virtual void sendMouseSpringEvent(int xDis, int yDis) override; virtual void sendMouseSpringEvent(int xDis, int yDis) override;
virtual QString getName() override; virtual QString getName() override;
@@ -51,7 +50,7 @@ public:
int getSpringMouseFileHandler(); int getSpringMouseFileHandler();
const QString getUinputDeviceLocation(); const QString getUinputDeviceLocation();
protected: protected:
int openUInputHandle(); int openUInputHandle();
void setKeyboardEvents(int filehandle); void setKeyboardEvents(int filehandle);
void setRelMouseEvents(int filehandle); void setRelMouseEvents(int filehandle);
@@ -61,24 +60,22 @@ protected:
void createUInputMouseDevice(int filehandle); void createUInputMouseDevice(int filehandle);
void createUInputSpringMouseDevice(int filehandle); void createUInputSpringMouseDevice(int filehandle);
void closeUInputDevice(int filehandle); void closeUInputDevice(int filehandle);
void write_uinput_event(int filehandle, int type, void write_uinput_event(int filehandle, int type, int code, int value, bool syn = true);
int code, int value, bool syn=true);
private slots: private slots:
#ifdef WITH_X11 #ifdef WITH_X11
void x11ResetMouseAccelerationChange(); void x11ResetMouseAccelerationChange();
#endif #endif
private: private:
int keyboardFileHandler; int keyboardFileHandler;
int mouseFileHandler; int mouseFileHandler;
int springMouseFileHandler; int springMouseFileHandler;
QString uinputDeviceLocation; QString uinputDeviceLocation;
bool cleanupUinputEvHand(); bool cleanupUinputEvHand();
void testAndAppend(bool tested, QList<unsigned int>& tempList, unsigned int key); void testAndAppend(bool tested, QList<unsigned int> &tempList, unsigned int key);
void initDevice(int& device, QString name, bool& result); void initDevice(int &device, QString name, bool &result);
}; };
#endif // UINPUTEVENTHANDLER_H #endif // UINPUTEVENTHANDLER_H

View File

@@ -18,9 +18,9 @@
#include "xtesteventhandler.h" #include "xtesteventhandler.h"
#include "antkeymapper.h"
#include "globalvariables.h" #include "globalvariables.h"
#include "joybuttonslot.h" #include "joybuttonslot.h"
#include "antkeymapper.h"
#include "messagehandler.h" #include "messagehandler.h"
#include <X11/Xlib.h> #include <X11/Xlib.h>
@@ -29,19 +29,13 @@
#include "x11extras.h" #include "x11extras.h"
XTestEventHandler::XTestEventHandler(QObject *parent)
XTestEventHandler::XTestEventHandler(QObject *parent) : : BaseEventHandler(parent)
BaseEventHandler(parent)
{
qInstallMessageHandler(MessageHandler::myMessageOutput);
}
XTestEventHandler::~XTestEventHandler()
{ {
qInstallMessageHandler(MessageHandler::myMessageOutput); qInstallMessageHandler(MessageHandler::myMessageOutput);
} }
XTestEventHandler::~XTestEventHandler() { qInstallMessageHandler(MessageHandler::myMessageOutput); }
bool XTestEventHandler::init() bool XTestEventHandler::init()
{ {
@@ -57,7 +51,6 @@ bool XTestEventHandler::init()
return true; return true;
} }
bool XTestEventHandler::cleanup() bool XTestEventHandler::cleanup()
{ {
qInstallMessageHandler(MessageHandler::myMessageOutput); qInstallMessageHandler(MessageHandler::myMessageOutput);
@@ -65,12 +58,11 @@ bool XTestEventHandler::cleanup()
return true; return true;
} }
void XTestEventHandler::sendKeyboardEvent(JoyButtonSlot *slot, bool pressed) void XTestEventHandler::sendKeyboardEvent(JoyButtonSlot *slot, bool pressed)
{ {
qInstallMessageHandler(MessageHandler::myMessageOutput); qInstallMessageHandler(MessageHandler::myMessageOutput);
Display* display = X11Extras::getInstance()->display(); Display *display = X11Extras::getInstance()->display();
JoyButtonSlot::JoySlotInputAction device = slot->getSlotMode(); JoyButtonSlot::JoySlotInputAction device = slot->getSlotMode();
@@ -88,12 +80,11 @@ void XTestEventHandler::sendKeyboardEvent(JoyButtonSlot *slot, bool pressed)
} }
} }
void XTestEventHandler::sendMouseButtonEvent(JoyButtonSlot *slot, bool pressed) void XTestEventHandler::sendMouseButtonEvent(JoyButtonSlot *slot, bool pressed)
{ {
qInstallMessageHandler(MessageHandler::myMessageOutput); qInstallMessageHandler(MessageHandler::myMessageOutput);
Display* display = X11Extras::getInstance()->display(); Display *display = X11Extras::getInstance()->display();
JoyButtonSlot::JoySlotInputAction device = slot->getSlotMode(); JoyButtonSlot::JoySlotInputAction device = slot->getSlotMode();
int code = slot->getSlotCode(); int code = slot->getSlotCode();
@@ -105,27 +96,24 @@ void XTestEventHandler::sendMouseButtonEvent(JoyButtonSlot *slot, bool pressed)
} }
} }
void XTestEventHandler::sendMouseEvent(int xDis, int yDis) void XTestEventHandler::sendMouseEvent(int xDis, int yDis)
{ {
qInstallMessageHandler(MessageHandler::myMessageOutput); qInstallMessageHandler(MessageHandler::myMessageOutput);
Display* display = X11Extras::getInstance()->display(); Display *display = X11Extras::getInstance()->display();
XTestFakeRelativeMotionEvent(display, xDis, yDis, 0); XTestFakeRelativeMotionEvent(display, xDis, yDis, 0);
XFlush(display); XFlush(display);
} }
void XTestEventHandler::sendMouseAbsEvent(int xDis, int yDis, int screen) void XTestEventHandler::sendMouseAbsEvent(int xDis, int yDis, int screen)
{ {
qInstallMessageHandler(MessageHandler::myMessageOutput); qInstallMessageHandler(MessageHandler::myMessageOutput);
Display* display = X11Extras::getInstance()->display(); Display *display = X11Extras::getInstance()->display();
XTestFakeMotionEvent(display, screen, xDis, yDis, 0); XTestFakeMotionEvent(display, screen, xDis, yDis, 0);
XFlush(display); XFlush(display);
} }
QString XTestEventHandler::getName() QString XTestEventHandler::getName()
{ {
qInstallMessageHandler(MessageHandler::myMessageOutput); qInstallMessageHandler(MessageHandler::myMessageOutput);
@@ -133,7 +121,6 @@ QString XTestEventHandler::getName()
return QString("XTest"); return QString("XTest");
} }
QString XTestEventHandler::getIdentifier() QString XTestEventHandler::getIdentifier()
{ {
qInstallMessageHandler(MessageHandler::myMessageOutput); qInstallMessageHandler(MessageHandler::myMessageOutput);
@@ -141,7 +128,6 @@ QString XTestEventHandler::getIdentifier()
return QString("xtest"); return QString("xtest");
} }
void XTestEventHandler::sendTextEntryEvent(QString maintext) void XTestEventHandler::sendTextEntryEvent(QString maintext)
{ {
qInstallMessageHandler(MessageHandler::myMessageOutput); qInstallMessageHandler(MessageHandler::myMessageOutput);
@@ -150,8 +136,8 @@ void XTestEventHandler::sendTextEntryEvent(QString maintext)
if ((mapper != nullptr) && mapper->getKeyMapper()) if ((mapper != nullptr) && mapper->getKeyMapper())
{ {
Display* display = X11Extras::getInstance()->display(); Display *display = X11Extras::getInstance()->display();
QtX11KeyMapper *keymapper = qobject_cast<QtX11KeyMapper*>(mapper->getKeyMapper()); QtX11KeyMapper *keymapper = qobject_cast<QtX11KeyMapper *>(mapper->getKeyMapper());
for (int i = 0; i < maintext.size(); i++) for (int i = 0; i < maintext.size(); i++)
{ {
@@ -164,34 +150,34 @@ void XTestEventHandler::sendTextEntryEvent(QString maintext)
if ((temp.modifiers != Qt::NoModifier) && temp.modifiers.testFlag(Qt::ShiftModifier)) if ((temp.modifiers != Qt::NoModifier) && temp.modifiers.testFlag(Qt::ShiftModifier))
{ {
int shiftcode = XKeysymToKeycode(display, XK_Shift_L); int shiftcode = XKeysymToKeycode(display, XK_Shift_L);
int modifiercode = shiftcode; int modifiercode = shiftcode;
XTestFakeKeyEvent(display, modifiercode, 1, 0); XTestFakeKeyEvent(display, modifiercode, 1, 0);
tempList.append(modifiercode); tempList.append(modifiercode);
} }
if ((temp.modifiers != Qt::NoModifier) && temp.modifiers.testFlag(Qt::ControlModifier)) if ((temp.modifiers != Qt::NoModifier) && temp.modifiers.testFlag(Qt::ControlModifier))
{ {
int controlcode = XKeysymToKeycode(display, XK_Control_L); int controlcode = XKeysymToKeycode(display, XK_Control_L);
int modifiercode = controlcode; int modifiercode = controlcode;
XTestFakeKeyEvent(display, modifiercode, 1, 0); XTestFakeKeyEvent(display, modifiercode, 1, 0);
tempList.append(modifiercode); tempList.append(modifiercode);
} }
if ((temp.modifiers != Qt::NoModifier) && temp.modifiers.testFlag(Qt::AltModifier)) if ((temp.modifiers != Qt::NoModifier) && temp.modifiers.testFlag(Qt::AltModifier))
{ {
int altcode = XKeysymToKeycode(display, XK_Alt_L); int altcode = XKeysymToKeycode(display, XK_Alt_L);
int modifiercode = altcode; int modifiercode = altcode;
XTestFakeKeyEvent(display, modifiercode, 1, 0); XTestFakeKeyEvent(display, modifiercode, 1, 0);
tempList.append(modifiercode); tempList.append(modifiercode);
} }
if ((temp.modifiers != Qt::NoModifier) && temp.modifiers.testFlag(Qt::MetaModifier)) if ((temp.modifiers != Qt::NoModifier) && temp.modifiers.testFlag(Qt::MetaModifier))
{ {
int metacode = XKeysymToKeycode(display, XK_Meta_L); int metacode = XKeysymToKeycode(display, XK_Meta_L);
int modifiercode = metacode; int modifiercode = metacode;
XTestFakeKeyEvent(display, modifiercode, 1, 0); XTestFakeKeyEvent(display, modifiercode, 1, 0);
tempList.append(modifiercode); tempList.append(modifiercode);
} }
XTestFakeKeyEvent(display, tempcode, 1, 0); XTestFakeKeyEvent(display, tempcode, 1, 0);
@@ -217,8 +203,8 @@ void XTestEventHandler::sendTextEntryEvent(QString maintext)
} }
} }
void XTestEventHandler::sendMouseSpringEvent(int xDis, int yDis, int width, int height)
void XTestEventHandler::sendMouseSpringEvent(int xDis, int yDis, int width, int height) { {
qInstallMessageHandler(MessageHandler::myMessageOutput); qInstallMessageHandler(MessageHandler::myMessageOutput);
@@ -228,14 +214,6 @@ void XTestEventHandler::sendMouseSpringEvent(int xDis, int yDis, int width, int
Q_UNUSED(height); Q_UNUSED(height);
} }
void XTestEventHandler::sendMouseSpringEvent(int, int) { qInstallMessageHandler(MessageHandler::myMessageOutput); }
void XTestEventHandler::sendMouseSpringEvent(int, int) void XTestEventHandler::printPostMessages() { qInstallMessageHandler(MessageHandler::myMessageOutput); }
{
qInstallMessageHandler(MessageHandler::myMessageOutput);
}
void XTestEventHandler::printPostMessages()
{
qInstallMessageHandler(MessageHandler::myMessageOutput);
}

View File

@@ -16,21 +16,18 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef XTESTEVENTHANDLER_H #ifndef XTESTEVENTHANDLER_H
#define XTESTEVENTHANDLER_H #define XTESTEVENTHANDLER_H
#include "baseeventhandler.h" #include "baseeventhandler.h"
class JoyButtonSlot; class JoyButtonSlot;
class XTestEventHandler : public BaseEventHandler class XTestEventHandler : public BaseEventHandler
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit XTestEventHandler(QObject *parent = nullptr); explicit XTestEventHandler(QObject *parent = nullptr);
virtual ~XTestEventHandler(); virtual ~XTestEventHandler();
@@ -42,8 +39,7 @@ public:
void sendMouseEvent(int xDis, int yDis) override; void sendMouseEvent(int xDis, int yDis) override;
void sendMouseAbsEvent(int xDis, int yDis, int screen) override; void sendMouseAbsEvent(int xDis, int yDis, int screen) override;
void sendMouseSpringEvent(int xDis, int yDis, void sendMouseSpringEvent(int xDis, int yDis, int width, int height) override;
int width, int height) override;
void sendMouseSpringEvent(int xDis, int yDis) override; void sendMouseSpringEvent(int xDis, int yDis) override;
void sendTextEntryEvent(QString maintext) override; void sendTextEntryEvent(QString maintext) override;
@@ -51,7 +47,6 @@ public:
QString getName() override; QString getName() override;
QString getIdentifier() override; QString getIdentifier() override;
void printPostMessages() override; void printPostMessages() override;
}; };
#endif // XTESTEVENTHANDLER_H #endif // XTESTEVENTHANDLER_H

View File

@@ -19,15 +19,14 @@
#include "extraprofilesettingsdialog.h" #include "extraprofilesettingsdialog.h"
#include "ui_extraprofilesettingsdialog.h" #include "ui_extraprofilesettingsdialog.h"
#include "messagehandler.h"
#include "inputdevice.h" #include "inputdevice.h"
#include "messagehandler.h"
#include <QDebug> #include <QDebug>
ExtraProfileSettingsDialog::ExtraProfileSettingsDialog(InputDevice *device, QWidget *parent)
ExtraProfileSettingsDialog::ExtraProfileSettingsDialog(InputDevice *device, QWidget *parent) : : QDialog(parent)
QDialog(parent), , ui(new Ui::ExtraProfileSettingsDialog)
ui(new Ui::ExtraProfileSettingsDialog)
{ {
ui->setupUi(this); ui->setupUi(this);
@@ -67,7 +66,4 @@ void ExtraProfileSettingsDialog::changeDeviceKeyPress(int value)
ui->pressValueLabel->setText(QString::number(temppress / 1000.0, 'g', 3).append("").append(tr("s"))); ui->pressValueLabel->setText(QString::number(temppress / 1000.0, 'g', 3).append("").append(tr("s")));
} }
InputDevice* ExtraProfileSettingsDialog::getDevice() const { InputDevice *ExtraProfileSettingsDialog::getDevice() const { return device; }
return device;
}

View File

@@ -16,7 +16,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef KEYDELAYDIALOG_H #ifndef KEYDELAYDIALOG_H
#define KEYDELAYDIALOG_H #define KEYDELAYDIALOG_H
@@ -33,18 +32,18 @@ class ExtraProfileSettingsDialog : public QDialog
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit ExtraProfileSettingsDialog(InputDevice *device, QWidget *parent = nullptr); explicit ExtraProfileSettingsDialog(InputDevice *device, QWidget *parent = nullptr);
~ExtraProfileSettingsDialog(); ~ExtraProfileSettingsDialog();
InputDevice* getDevice() const; InputDevice *getDevice() const;
private: private:
Ui::ExtraProfileSettingsDialog *ui; Ui::ExtraProfileSettingsDialog *ui;
InputDevice *device; InputDevice *device;
private slots: private slots:
void changeDeviceKeyPress(int value); void changeDeviceKeyPress(int value);
}; };

View File

@@ -1,11 +1,8 @@
#define MAKE_CONTROLLER_ID( nVID, nPID ) (unsigned int)( nVID << 16 | nPID ) #define MAKE_CONTROLLER_ID(nVID, nPID) (unsigned int)(nVID << 16 | nPID)
#include "xbox360wireless.h" #include "xbox360wireless.h"
//#include "SDL-mirror/src/joystick/SDL_sysjoystick.h" //#include "SDL-mirror/src/joystick/SDL_sysjoystick.h"
Xbox360Wireless::Xbox360Wireless() Xbox360Wireless::Xbox360Wireless()
{ {
SDL_Joystick Xbox360; SDL_Joystick Xbox360;
@@ -17,19 +14,22 @@ Xbox360Wireless::Xbox360Wireless()
Xbox360.naxes = 6; Xbox360.naxes = 6;
Xbox360.nhats = 0; Xbox360.nhats = 0;
Xbox360.nbuttons = 15; Xbox360.nbuttons = 15;
// Xbox360.nballs = 0; // Xbox360.nballs = 0;
if (Xbox360.naxes > 0) { if (Xbox360.naxes > 0)
Xbox360.axes = (SDL_JoystickAxisInfo *) SDL_calloc(Xbox360.naxes, sizeof(SDL_JoystickAxisInfo)); {
Xbox360.axes = (SDL_JoystickAxisInfo *)SDL_calloc(Xbox360.naxes, sizeof(SDL_JoystickAxisInfo));
} }
if (Xbox360.nhats > 0) { if (Xbox360.nhats > 0)
Xbox360.hats = (Uint8 *) SDL_calloc(Xbox360.nhats, sizeof(Uint8)); {
Xbox360.hats = (Uint8 *)SDL_calloc(Xbox360.nhats, sizeof(Uint8));
} }
//if (Xbox360.nballs > 0) { // if (Xbox360.nballs > 0) {
// Xbox360.balls = (struct balldelta *) SDL_calloc(Xbox360.balls, sizeof(*Xbox360.balls)); // Xbox360.balls = (struct balldelta *) SDL_calloc(Xbox360.balls, sizeof(*Xbox360.balls));
// } // }
if (Xbox360.nbuttons > 0) { if (Xbox360.nbuttons > 0)
Xbox360.buttons = (Uint8 *) SDL_calloc(Xbox360.nbuttons, sizeof(Uint8)); {
Xbox360.buttons = (Uint8 *)SDL_calloc(Xbox360.nbuttons, sizeof(Uint8));
} }
Xbox360.attached = SDL_TRUE; Xbox360.attached = SDL_TRUE;
@@ -41,10 +41,8 @@ Xbox360Wireless::Xbox360Wireless()
// _SDL_JoystickDriver - it's faked class so there is no need to use detection from system level // _SDL_JoystickDriver - it's faked class so there is no need to use detection from system level
result = &Xbox360; result = &Xbox360;
} }
Xbox360Wireless::~Xbox360Wireless() Xbox360Wireless::~Xbox360Wireless()
{ {
SDL_free(result->name); SDL_free(result->name);
@@ -57,39 +55,19 @@ Xbox360Wireless::~Xbox360Wireless()
SDL_free(result); SDL_free(result);
} }
char *Xbox360Wireless::GUID() char *Xbox360Wireless::GUID() { return "030000005e040000e002000000000000"; }
{
return "030000005e040000e002000000000000";
}
char *Xbox360Wireless::name() char *Xbox360Wireless::name() { return "Xbox Wireless Controller"; }
{
return "Xbox Wireless Controller";
}
unsigned int Xbox360Wireless::deviceId() unsigned int Xbox360Wireless::deviceId() { return MAKE_CONTROLLER_ID(0x045e, 0x0291); }
{
return MAKE_CONTROLLER_ID( 0x045e, 0x0291 );
}
int Xbox360Wireless::controllerType() int Xbox360Wireless::controllerType()
{ {
return 31; // k_eControllerType_XBox360Controller return 31; // k_eControllerType_XBox360Controller
} }
SDL_JoystickType Xbox360Wireless::joystickType() SDL_JoystickType Xbox360Wireless::joystickType() { return SDL_JoystickType::SDL_JOYSTICK_TYPE_GAMECONTROLLER; }
{
return SDL_JoystickType::SDL_JOYSTICK_TYPE_GAMECONTROLLER;
}
SDL_JoystickGUID Xbox360Wireless::joyGUID()
{
return SDL_JoystickGetGUIDFromString(GUID());
}
SDL_Joystick* Xbox360Wireless::getResult()
{
return result;
}
SDL_JoystickGUID Xbox360Wireless::joyGUID() { return SDL_JoystickGetGUIDFromString(GUID()); }
SDL_Joystick *Xbox360Wireless::getResult() { return result; }

View File

@@ -3,13 +3,12 @@
#include <SDL2/SDL_joystick.h> #include <SDL2/SDL_joystick.h>
typedef struct _SDL_JoystickAxisInfo typedef struct _SDL_JoystickAxisInfo
{ {
Sint16 initial_value; /* Initial axis state */ Sint16 initial_value; /* Initial axis state */
Sint16 value; /* Current axis state */ Sint16 value; /* Current axis state */
Sint16 zero; /* Zero point on the axis (-32768 for triggers) */ Sint16 zero; /* Zero point on the axis (-32768 for triggers) */
SDL_bool has_initial_value; /* Whether we've seen a value on the axis yet */ SDL_bool has_initial_value; /* Whether we've seen a value on the axis yet */
SDL_bool sent_initial_value; /* Whether we've sent the initial axis value */ SDL_bool sent_initial_value; /* Whether we've sent the initial axis value */
} SDL_JoystickAxisInfo; } SDL_JoystickAxisInfo;
@@ -20,54 +19,53 @@ struct _SDL_Joystick
int player_index; /* Joystick player index, or -1 if unavailable */ int player_index; /* Joystick player index, or -1 if unavailable */
SDL_JoystickGUID guid; /* Joystick guid */ SDL_JoystickGUID guid; /* Joystick guid */
int naxes; /* Number of axis controls on the joystick */ int naxes; /* Number of axis controls on the joystick */
SDL_JoystickAxisInfo *axes; SDL_JoystickAxisInfo *axes;
int nhats; /* Number of hats on the joystick */ int nhats; /* Number of hats on the joystick */
Uint8 *hats; /* Current hat states */ Uint8 *hats; /* Current hat states */
int nballs; /* Number of trackballs on the joystick */ int nballs; /* Number of trackballs on the joystick */
struct balldelta { struct balldelta
{
int dx; int dx;
int dy; int dy;
} *balls; /* Current ball motion deltas */ } * balls; /* Current ball motion deltas */
int nbuttons; /* Number of buttons on the joystick */ int nbuttons; /* Number of buttons on the joystick */
Uint8 *buttons; /* Current button states */ Uint8 *buttons; /* Current button states */
SDL_bool attached; SDL_bool attached;
SDL_bool is_game_controller; SDL_bool is_game_controller;
SDL_bool delayed_guide_button; /* SDL_TRUE if this device has the guide button event delayed */ SDL_bool delayed_guide_button; /* SDL_TRUE if this device has the guide button event delayed */
SDL_bool force_recentering; /* SDL_TRUE if this device needs to have its state reset to 0 */ SDL_bool force_recentering; /* SDL_TRUE if this device needs to have its state reset to 0 */
SDL_JoystickPowerLevel epowerlevel; /* power level of this joystick, SDL_JOYSTICK_POWER_UNKNOWN if not supported */ SDL_JoystickPowerLevel epowerlevel; /* power level of this joystick, SDL_JOYSTICK_POWER_UNKNOWN if not supported */
struct _SDL_JoystickDriver *driver; struct _SDL_JoystickDriver *driver;
struct joystick_hwdata *hwdata; /* Driver dependent information */ struct joystick_hwdata *hwdata; /* Driver dependent information */
int ref_count; /* Reference count for multiple opens */ int ref_count; /* Reference count for multiple opens */
struct _SDL_Joystick *next; /* pointer to next joystick we have allocated */ struct _SDL_Joystick *next; /* pointer to next joystick we have allocated */
}; };
class Xbox360Wireless class Xbox360Wireless
{ {
public: public:
Xbox360Wireless(); Xbox360Wireless();
~Xbox360Wireless(); ~Xbox360Wireless();
char* GUID(); char *GUID();
char* name(); char *name();
unsigned int deviceId(); unsigned int deviceId();
int controllerType(); int controllerType();
SDL_JoystickType joystickType(); SDL_JoystickType joystickType();
SDL_JoystickGUID joyGUID(); SDL_JoystickGUID joyGUID();
SDL_Joystick* getResult(); SDL_Joystick *getResult();
private:
SDL_Joystick* result;
private:
SDL_Joystick *result;
}; };
#endif #endif

View File

@@ -21,15 +21,14 @@
#include "messagehandler.h" #include "messagehandler.h"
#include <QDebug> #include <QDebug>
#include <QStyle>
#include <QFontMetrics> #include <QFontMetrics>
#include <QPainter>
#include <QPaintEvent> #include <QPaintEvent>
#include <QPainter>
#include <QStyle>
#include <QWidget> #include <QWidget>
FlashButtonWidget::FlashButtonWidget(QWidget *parent)
FlashButtonWidget::FlashButtonWidget(QWidget *parent) : : QPushButton(parent)
QPushButton(parent)
{ {
qInstallMessageHandler(MessageHandler::myMessageOutput); qInstallMessageHandler(MessageHandler::myMessageOutput);
@@ -38,8 +37,8 @@ FlashButtonWidget::FlashButtonWidget(QWidget *parent) :
leftAlignText = false; leftAlignText = false;
} }
FlashButtonWidget::FlashButtonWidget(bool displayNames, QWidget *parent) : FlashButtonWidget::FlashButtonWidget(bool displayNames, QWidget *parent)
QPushButton(parent) : QPushButton(parent)
{ {
qInstallMessageHandler(MessageHandler::myMessageOutput); qInstallMessageHandler(MessageHandler::myMessageOutput);
@@ -78,9 +77,7 @@ void FlashButtonWidget::refreshLabel()
setText(generateLabel()); setText(generateLabel());
qDebug() << "label has been set: " << generateLabel();
qDebug() << "label has been set: " << generateLabel();
} }
bool FlashButtonWidget::isButtonFlashing() bool FlashButtonWidget::isButtonFlashing()
@@ -114,7 +111,7 @@ bool FlashButtonWidget::isDisplayingNames()
void FlashButtonWidget::paintEvent(QPaintEvent *event) void FlashButtonWidget::paintEvent(QPaintEvent *event)
{ {
// qInstallMessageHandler(MessageHandler::myMessageOutput); // qInstallMessageHandler(MessageHandler::myMessageOutput);
QPainter painter(this); QPainter painter(this);
@@ -127,7 +124,7 @@ void FlashButtonWidget::paintEvent(QPaintEvent *event)
while ((this->width() < fm.width(text())) && (tempScaledFont.pointSize() >= 7)) while ((this->width() < fm.width(text())) && (tempScaledFont.pointSize() >= 7))
{ {
tempScaledFont.setPointSize(tempScaledFont.pointSize()-1); tempScaledFont.setPointSize(tempScaledFont.pointSize() - 1);
painter.setFont(tempScaledFont); painter.setFont(tempScaledFont);
fm = painter.fontMetrics(); fm = painter.fontMetrics();
reduce = true; reduce = true;
@@ -143,8 +140,7 @@ void FlashButtonWidget::paintEvent(QPaintEvent *event)
setStyleSheet("text-align: left;"); setStyleSheet("text-align: left;");
this->style()->unpolish(this); this->style()->unpolish(this);
this->style()->polish(this); this->style()->polish(this);
} } else if (!reduce && leftAlignText)
else if (!reduce && leftAlignText)
{ {
leftAlignText = !leftAlignText; leftAlignText = !leftAlignText;
setStyleSheet("text-align: center;"); setStyleSheet("text-align: center;");
@@ -165,7 +161,4 @@ void FlashButtonWidget::retranslateUi()
refreshLabel(); refreshLabel();
} }
bool FlashButtonWidget::ifDisplayNames() { bool FlashButtonWidget::ifDisplayNames() { return m_displayNames; }
return m_displayNames;
}

View File

@@ -16,7 +16,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef FLASHBUTTONWIDGET_H #ifndef FLASHBUTTONWIDGET_H
#define FLASHBUTTONWIDGET_H #define FLASHBUTTONWIDGET_H
@@ -25,13 +24,12 @@
class QWidget; class QWidget;
class QPaintEvent; class QPaintEvent;
class FlashButtonWidget : public QPushButton class FlashButtonWidget : public QPushButton
{ {
Q_OBJECT Q_OBJECT
Q_PROPERTY(bool isflashing READ isButtonFlashing) Q_PROPERTY(bool isflashing READ isButtonFlashing)
public: public:
explicit FlashButtonWidget(QWidget *parent = nullptr); explicit FlashButtonWidget(QWidget *parent = nullptr);
explicit FlashButtonWidget(bool displayNames, QWidget *parent = nullptr); explicit FlashButtonWidget(bool displayNames, QWidget *parent = nullptr);
@@ -39,30 +37,29 @@ public:
void setDisplayNames(bool display); void setDisplayNames(bool display);
bool isDisplayingNames(); bool isDisplayingNames();
protected: protected:
virtual void paintEvent(QPaintEvent *event); virtual void paintEvent(QPaintEvent *event);
virtual QString generateLabel() = 0; virtual QString generateLabel() = 0;
virtual void retranslateUi(); virtual void retranslateUi();
bool ifDisplayNames(); bool ifDisplayNames();
signals: signals:
void flashed(bool flashing); void flashed(bool flashing);
public slots: public slots:
void refreshLabel(); void refreshLabel();
void toggleNameDisplay(); void toggleNameDisplay();
virtual void disableFlashes() = 0; virtual void disableFlashes() = 0;
virtual void enableFlashes() = 0; virtual void enableFlashes() = 0;
protected slots: protected slots:
void flash(); void flash();
void unflash(); void unflash();
private: private:
bool isflashing; bool isflashing;
bool m_displayNames; bool m_displayNames;
bool leftAlignText; bool leftAlignText;
}; };
#endif // FLASHBUTTONWIDGET_H #endif // FLASHBUTTONWIDGET_H

View File

@@ -18,26 +18,25 @@
#include "gamecontroller.h" #include "gamecontroller.h"
#include "globalvariables.h" #include "antimicrosettings.h"
#include "common.h"
#include "gamecontrollerdpad.h" #include "gamecontrollerdpad.h"
#include "gamecontrollerset.h" #include "gamecontrollerset.h"
#include "antimicrosettings.h" #include "globalvariables.h"
#include "joycontrolstick.h"
#include "joybuttontypes/joycontrolstickbutton.h" #include "joybuttontypes/joycontrolstickbutton.h"
#include "common.h" #include "joycontrolstick.h"
#include "messagehandler.h" #include "messagehandler.h"
//#include "logger.h" //#include "logger.h"
#include <cmath> #include <cmath>
#include <QDebug>
#include <QXmlStreamReader> #include <QXmlStreamReader>
#include <QXmlStreamWriter> #include <QXmlStreamWriter>
#include <QDebug>
GameController::GameController(SDL_GameController *controller, int deviceIndex, AntiMicroSettings *settings,
GameController::GameController(SDL_GameController *controller, int deviceIndex, int counterUniques, QObject *parent)
AntiMicroSettings *settings, int counterUniques, QObject *parent) : : InputDevice(SDL_GameControllerGetJoystick(controller), deviceIndex, settings, parent)
InputDevice(SDL_GameControllerGetJoystick(controller), deviceIndex, settings, parent)
{ {
qInstallMessageHandler(MessageHandler::myMessageOutput); qInstallMessageHandler(MessageHandler::myMessageOutput);
@@ -56,7 +55,6 @@ GameController::GameController(SDL_GameController *controller, int deviceIndex,
} }
} }
QString GameController::getName() QString GameController::getName()
{ {
qInstallMessageHandler(MessageHandler::myMessageOutput); qInstallMessageHandler(MessageHandler::myMessageOutput);
@@ -64,7 +62,6 @@ QString GameController::getName()
return QString(tr("Game Controller")).append(" ").append(QString::number(getRealJoyNumber())); return QString(tr("Game Controller")).append(" ").append(QString::number(getRealJoyNumber()));
} }
QString GameController::getSDLName() QString GameController::getSDLName()
{ {
qInstallMessageHandler(MessageHandler::myMessageOutput); qInstallMessageHandler(MessageHandler::myMessageOutput);
@@ -86,7 +83,6 @@ QString GameController::getXmlName()
return GlobalVariables::GameController::xmlName; return GlobalVariables::GameController::xmlName;
} }
QString GameController::getGUIDString() QString GameController::getGUIDString()
{ {
qInstallMessageHandler(MessageHandler::myMessageOutput); qInstallMessageHandler(MessageHandler::myMessageOutput);
@@ -94,7 +90,6 @@ QString GameController::getGUIDString()
return getRawGUIDString(); return getRawGUIDString();
} }
QString GameController::getVendorString() QString GameController::getVendorString()
{ {
qInstallMessageHandler(MessageHandler::myMessageOutput); qInstallMessageHandler(MessageHandler::myMessageOutput);
@@ -102,7 +97,6 @@ QString GameController::getVendorString()
return getRawVendorString(); return getRawVendorString();
} }
QString GameController::getProductIDString() QString GameController::getProductIDString()
{ {
qInstallMessageHandler(MessageHandler::myMessageOutput); qInstallMessageHandler(MessageHandler::myMessageOutput);
@@ -110,7 +104,6 @@ QString GameController::getProductIDString()
return getRawProductIDString(); return getRawProductIDString();
} }
QString GameController::getUniqueIDString() QString GameController::getUniqueIDString()
{ {
qInstallMessageHandler(MessageHandler::myMessageOutput); qInstallMessageHandler(MessageHandler::myMessageOutput);
@@ -118,11 +111,7 @@ QString GameController::getUniqueIDString()
return getRawUniqueIDString(); return getRawUniqueIDString();
} }
QString GameController::getProductVersion() QString GameController::getProductVersion() { return getRawProductVersion(); }
{
return getRawProductVersion();
}
QString GameController::getRawGUIDString() QString GameController::getRawGUIDString()
{ {
@@ -146,7 +135,6 @@ QString GameController::getRawGUIDString()
return temp; return temp;
} }
QString GameController::getRawVendorString() QString GameController::getRawVendorString()
{ {
qInstallMessageHandler(MessageHandler::myMessageOutput); qInstallMessageHandler(MessageHandler::myMessageOutput);
@@ -155,17 +143,16 @@ QString GameController::getRawVendorString()
if (controller != nullptr) if (controller != nullptr)
{ {
Uint16 tempVendor = SDL_GameControllerGetVendor(controller); Uint16 tempVendor = SDL_GameControllerGetVendor(controller);
char buffer [50]; char buffer[50];
sprintf (buffer, "%u", tempVendor); sprintf(buffer, "%u", tempVendor);
temp = QString(buffer); temp = QString(buffer);
} }
return temp; return temp;
} }
QString GameController::getRawProductIDString() QString GameController::getRawProductIDString()
{ {
qInstallMessageHandler(MessageHandler::myMessageOutput); qInstallMessageHandler(MessageHandler::myMessageOutput);
@@ -174,11 +161,11 @@ QString GameController::getRawProductIDString()
if (controller != nullptr) if (controller != nullptr)
{ {
Uint16 tempProduct = SDL_GameControllerGetProduct(controller) + counterUniques; Uint16 tempProduct = SDL_GameControllerGetProduct(controller) + counterUniques;
char buffer [50]; char buffer[50];
sprintf (buffer, "%u", tempProduct); sprintf(buffer, "%u", tempProduct);
temp = QString(buffer); temp = QString(buffer);
} }
return temp; return temp;
@@ -192,23 +179,21 @@ QString GameController::getRawProductVersion()
if (controller != nullptr) if (controller != nullptr)
{ {
Uint16 tempProductVersion = SDL_GameControllerGetProductVersion(controller); Uint16 tempProductVersion = SDL_GameControllerGetProductVersion(controller);
char buffer [50]; char buffer[50];
sprintf (buffer, "%u", tempProductVersion); sprintf(buffer, "%u", tempProductVersion);
temp = QString(buffer); temp = QString(buffer);
} }
return temp; return temp;
} }
QString GameController::getRawUniqueIDString() QString GameController::getRawUniqueIDString()
{ {
return (getRawGUIDString() + getRawVendorString() + getRawProductIDString()); return (getRawGUIDString() + getRawVendorString() + getRawProductIDString());
} }
void GameController::closeSDLDevice() void GameController::closeSDLDevice()
{ {
qInstallMessageHandler(MessageHandler::myMessageOutput); qInstallMessageHandler(MessageHandler::myMessageOutput);
@@ -220,7 +205,6 @@ void GameController::closeSDLDevice()
} }
} }
int GameController::getNumberRawButtons() int GameController::getNumberRawButtons()
{ {
qInstallMessageHandler(MessageHandler::myMessageOutput); qInstallMessageHandler(MessageHandler::myMessageOutput);
@@ -228,19 +212,15 @@ int GameController::getNumberRawButtons()
return SDL_CONTROLLER_BUTTON_MAX; return SDL_CONTROLLER_BUTTON_MAX;
} }
int GameController::getNumberRawAxes() int GameController::getNumberRawAxes()
{ {
qInstallMessageHandler(MessageHandler::myMessageOutput); qInstallMessageHandler(MessageHandler::myMessageOutput);
qDebug() << "Controller has " << SDL_CONTROLLER_AXIS_MAX << " raw axes"; qDebug() << "Controller has " << SDL_CONTROLLER_AXIS_MAX << " raw axes";
return SDL_CONTROLLER_AXIS_MAX; return SDL_CONTROLLER_AXIS_MAX;
} }
int GameController::getNumberRawHats() int GameController::getNumberRawHats()
{ {
qInstallMessageHandler(MessageHandler::myMessageOutput); qInstallMessageHandler(MessageHandler::myMessageOutput);
@@ -248,13 +228,10 @@ int GameController::getNumberRawHats()
return 0; return 0;
} }
void GameController::setCounterUniques(int counter) void GameController::setCounterUniques(int counter) { counterUniques = counter; }
{
counterUniques = counter;
}
void GameController::fillContainers(QHash<int, SDL_GameControllerButton> &buttons, QHash<int, SDL_GameControllerAxis> &axes,
void GameController::fillContainers(QHash<int, SDL_GameControllerButton> &buttons, QHash<int, SDL_GameControllerAxis> &axes, QList<SDL_GameControllerButtonBind> &hatButtons) QList<SDL_GameControllerButtonBind> &hatButtons)
{ {
for (int i = 0; i < SDL_JoystickNumHats(getJoyHandle()); i++) for (int i = 0; i < SDL_JoystickNumHats(getJoyHandle()); i++)
@@ -262,10 +239,8 @@ void GameController::fillContainers(QHash<int, SDL_GameControllerButton> &button
SDL_GameControllerButton currentButton = static_cast<SDL_GameControllerButton>(i); SDL_GameControllerButton currentButton = static_cast<SDL_GameControllerButton>(i);
SDL_GameControllerButtonBind bound = SDL_GameControllerGetBindForButton(this->controller, currentButton); SDL_GameControllerButtonBind bound = SDL_GameControllerGetBindForButton(this->controller, currentButton);
qDebug() << "Hat " << (i + 1); qDebug() << "Hat " << (i + 1);
if (bound.bindType == SDL_CONTROLLER_BINDTYPE_HAT) if (bound.bindType == SDL_CONTROLLER_BINDTYPE_HAT)
{ {
hatButtons.append(bound); hatButtons.append(bound);
@@ -277,7 +252,6 @@ void GameController::fillContainers(QHash<int, SDL_GameControllerButton> &button
qDebug() << "Button " << (i + 1); qDebug() << "Button " << (i + 1);
SDL_GameControllerButton currentButton = static_cast<SDL_GameControllerButton>(i); SDL_GameControllerButton currentButton = static_cast<SDL_GameControllerButton>(i);
SDL_GameControllerButtonBind bound = SDL_GameControllerGetBindForButton(this->controller, currentButton); SDL_GameControllerButtonBind bound = SDL_GameControllerGetBindForButton(this->controller, currentButton);
@@ -292,7 +266,6 @@ void GameController::fillContainers(QHash<int, SDL_GameControllerButton> &button
qDebug() << "Axis " << (i + 1); qDebug() << "Axis " << (i + 1);
SDL_GameControllerAxis currentAxis = static_cast<SDL_GameControllerAxis>(i); SDL_GameControllerAxis currentAxis = static_cast<SDL_GameControllerAxis>(i);
SDL_GameControllerButtonBind bound = SDL_GameControllerGetBindForAxis(this->controller, currentAxis); SDL_GameControllerButtonBind bound = SDL_GameControllerGetBindForAxis(this->controller, currentAxis);
@@ -303,7 +276,6 @@ void GameController::fillContainers(QHash<int, SDL_GameControllerButton> &button
} }
} }
QString GameController::getBindStringForAxis(int index, bool) QString GameController::getBindStringForAxis(int index, bool)
{ {
qInstallMessageHandler(MessageHandler::myMessageOutput); qInstallMessageHandler(MessageHandler::myMessageOutput);
@@ -311,15 +283,12 @@ QString GameController::getBindStringForAxis(int index, bool)
QString temp = QString(); QString temp = QString();
SDL_GameControllerButtonBind bind = SDL_GameControllerButtonBind bind =
SDL_GameControllerGetBindForAxis(controller, SDL_GameControllerGetBindForAxis(controller, static_cast<SDL_GameControllerAxis>(index));
static_cast<SDL_GameControllerAxis>(index));
if (bind.bindType == SDL_CONTROLLER_BINDTYPE_BUTTON) if (bind.bindType == SDL_CONTROLLER_BINDTYPE_BUTTON)
{ {
temp.append(QString("Button %1").arg(bind.value.button)); temp.append(QString("Button %1").arg(bind.value.button));
} } else if (bind.bindType == SDL_CONTROLLER_BINDTYPE_AXIS)
else if (bind.bindType == SDL_CONTROLLER_BINDTYPE_AXIS)
{ {
temp.append(QString("Axis %1").arg(bind.value.axis + 1)); temp.append(QString("Axis %1").arg(bind.value.axis + 1));
} }
@@ -327,7 +296,6 @@ QString GameController::getBindStringForAxis(int index, bool)
return temp; return temp;
} }
QString GameController::getBindStringForButton(int index, bool trueIndex) QString GameController::getBindStringForButton(int index, bool trueIndex)
{ {
qInstallMessageHandler(MessageHandler::myMessageOutput); qInstallMessageHandler(MessageHandler::myMessageOutput);
@@ -335,35 +303,30 @@ QString GameController::getBindStringForButton(int index, bool trueIndex)
QString temp = QString(); QString temp = QString();
SDL_GameControllerButtonBind bind = SDL_GameControllerButtonBind bind =
SDL_GameControllerGetBindForButton(controller, SDL_GameControllerGetBindForButton(controller, static_cast<SDL_GameControllerButton>(index));
static_cast<SDL_GameControllerButton>(index));
int offset = trueIndex ? 0 : 1; int offset = trueIndex ? 0 : 1;
int bindInt = static_cast<int>(bind.bindType); int bindInt = static_cast<int>(bind.bindType);
switch(bindInt) { switch (bindInt)
{
case SDL_CONTROLLER_BINDTYPE_BUTTON: case SDL_CONTROLLER_BINDTYPE_BUTTON:
temp.append(QString("Button %1").arg(bind.value.button + offset)); temp.append(QString("Button %1").arg(bind.value.button + offset));
break; break;
case SDL_CONTROLLER_BINDTYPE_AXIS:
temp.append(QString("Axis %1").arg(bind.value.axis + offset));
break;
case SDL_CONTROLLER_BINDTYPE_AXIS: case SDL_CONTROLLER_BINDTYPE_HAT:
temp.append(QString("Axis %1").arg(bind.value.axis + offset)); temp.append(QString("Hat %1.%2").arg(bind.value.hat.hat + offset).arg(bind.value.hat.hat_mask));
break; break;
case SDL_CONTROLLER_BINDTYPE_HAT:
temp.append(QString("Hat %1.%2").arg(bind.value.hat.hat + offset)
.arg(bind.value.hat.hat_mask));
break;
} }
return temp; return temp;
} }
SDL_GameControllerButtonBind GameController::getBindForAxis(int index) SDL_GameControllerButtonBind GameController::getBindForAxis(int index)
{ {
qInstallMessageHandler(MessageHandler::myMessageOutput); qInstallMessageHandler(MessageHandler::myMessageOutput);
@@ -371,7 +334,6 @@ SDL_GameControllerButtonBind GameController::getBindForAxis(int index)
return SDL_GameControllerGetBindForAxis(controller, static_cast<SDL_GameControllerAxis>(index)); return SDL_GameControllerGetBindForAxis(controller, static_cast<SDL_GameControllerAxis>(index));
} }
SDL_GameControllerButtonBind GameController::getBindForButton(int index) SDL_GameControllerButtonBind GameController::getBindForButton(int index)
{ {
qInstallMessageHandler(MessageHandler::myMessageOutput); qInstallMessageHandler(MessageHandler::myMessageOutput);
@@ -379,24 +341,11 @@ SDL_GameControllerButtonBind GameController::getBindForButton(int index)
return SDL_GameControllerGetBindForButton(controller, static_cast<SDL_GameControllerButton>(index)); return SDL_GameControllerGetBindForButton(controller, static_cast<SDL_GameControllerButton>(index));
} }
void GameController::buttonClickEvent(int) { qInstallMessageHandler(MessageHandler::myMessageOutput); }
void GameController::buttonClickEvent(int) void GameController::buttonReleaseEvent(int) { qInstallMessageHandler(MessageHandler::myMessageOutput); }
{
qInstallMessageHandler(MessageHandler::myMessageOutput);
}
void GameController::buttonReleaseEvent(int)
{
qInstallMessageHandler(MessageHandler::myMessageOutput);
}
void GameController::axisActivatedEvent(int, int, int)
{
qInstallMessageHandler(MessageHandler::myMessageOutput);
}
void GameController::axisActivatedEvent(int, int, int) { qInstallMessageHandler(MessageHandler::myMessageOutput); }
SDL_JoystickID GameController::getSDLJoystickID() SDL_JoystickID GameController::getSDLJoystickID()
{ {
@@ -416,21 +365,19 @@ bool GameController::isGameController()
return true; return true;
} }
/** /**
* @brief Check if GUID passed matches the expected GUID for a device. * @brief Check if GUID passed matches the expected GUID for a device.
* Needed for xinput GUID abstraction. * Needed for xinput GUID abstraction.
* @param GUID string * @param GUID string
* @return if GUID is considered a match. * @return if GUID is considered a match.
*/ */
//bool GameController::isRelevantGUID(QString tempGUID) // bool GameController::isRelevantGUID(QString tempGUID)
//{ //{
// qInstallMessageHandler(MessageHandler::myMessageOutput); // qInstallMessageHandler(MessageHandler::myMessageOutput);
// return InputDevice::isRelevantGUID(tempGUID); // return InputDevice::isRelevantGUID(tempGUID);
//} //}
bool GameController::isRelevantUniqueID(QString tempUniqueID) bool GameController::isRelevantUniqueID(QString tempUniqueID)
{ {
qInstallMessageHandler(MessageHandler::myMessageOutput); qInstallMessageHandler(MessageHandler::myMessageOutput);
@@ -438,7 +385,6 @@ bool GameController::isRelevantUniqueID(QString tempUniqueID)
return InputDevice::isRelevantUniqueID(tempUniqueID); return InputDevice::isRelevantUniqueID(tempUniqueID);
} }
void GameController::rawButtonEvent(int index, bool pressed) void GameController::rawButtonEvent(int index, bool pressed)
{ {
qInstallMessageHandler(MessageHandler::myMessageOutput); qInstallMessageHandler(MessageHandler::myMessageOutput);
@@ -449,15 +395,13 @@ void GameController::rawButtonEvent(int index, bool pressed)
{ {
rawbuttons.insert(index, pressed); rawbuttons.insert(index, pressed);
emit rawButtonClick(index); emit rawButtonClick(index);
} } else if (knownbutton && !pressed)
else if (knownbutton && !pressed)
{ {
rawbuttons.remove(index); rawbuttons.remove(index);
emit rawButtonRelease(index); emit rawButtonRelease(index);
} }
} }
void GameController::rawAxisEvent(int index, int value) void GameController::rawAxisEvent(int index, int value)
{ {
qInstallMessageHandler(MessageHandler::myMessageOutput); qInstallMessageHandler(MessageHandler::myMessageOutput);
@@ -468,8 +412,7 @@ void GameController::rawAxisEvent(int index, int value)
{ {
axisvalues.insert(index, value); axisvalues.insert(index, value);
emit rawAxisActivated(index, value); emit rawAxisActivated(index, value);
} } else if (knownaxis && (fabs(value) < rawAxisDeadZone))
else if (knownaxis && (fabs(value) < rawAxisDeadZone))
{ {
axisvalues.remove(index); axisvalues.remove(index);
emit rawAxisReleased(index, value); emit rawAxisReleased(index, value);
@@ -478,7 +421,6 @@ void GameController::rawAxisEvent(int index, int value)
emit rawAxisMoved(index, value); emit rawAxisMoved(index, value);
} }
void GameController::rawDPadEvent(int index, int value) void GameController::rawDPadEvent(int index, int value)
{ {
qInstallMessageHandler(MessageHandler::myMessageOutput); qInstallMessageHandler(MessageHandler::myMessageOutput);
@@ -489,34 +431,17 @@ void GameController::rawDPadEvent(int index, int value)
{ {
dpadvalues.insert(index, value); dpadvalues.insert(index, value);
emit rawDPadButtonClick(index, value); emit rawDPadButtonClick(index, value);
} } else if (knowndpad && (value == 0))
else if (knowndpad && (value == 0))
{ {
dpadvalues.remove(index); dpadvalues.remove(index);
emit rawDPadButtonRelease(index, value); emit rawDPadButtonRelease(index, value);
} }
} }
QHash<int, bool> const &GameController::getRawbuttons() { return rawbuttons; }
QHash<int, bool> const& GameController::getRawbuttons() { QHash<int, int> const &GameController::getAxisvalues() { return axisvalues; }
return rawbuttons; QHash<int, int> const &GameController::getDpadvalues() { return dpadvalues; }
}
SDL_GameController *GameController::getController() const { return controller; }
QHash<int, int> const& GameController::getAxisvalues() {
return axisvalues;
}
QHash<int, int> const& GameController::getDpadvalues() {
return dpadvalues;
}
SDL_GameController* GameController::getController() const {
return controller;
}

View File

@@ -16,7 +16,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef GAMECONTROLLER_H #ifndef GAMECONTROLLER_H
#define GAMECONTROLLER_H #define GAMECONTROLLER_H
@@ -33,8 +32,9 @@ class GameController : public InputDevice
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit GameController(SDL_GameController *controller, int deviceIndex, AntiMicroSettings *settings, int counterUniques, QObject *parent = nullptr); explicit GameController(SDL_GameController *controller, int deviceIndex, AntiMicroSettings *settings, int counterUniques,
QObject *parent = nullptr);
virtual QString getName() override; virtual QString getName() override;
virtual QString getSDLName() override; virtual QString getSDLName() override;
@@ -61,32 +61,33 @@ public:
virtual int getNumberRawHats() override; virtual int getNumberRawHats() override;
void setCounterUniques(int counter) override; void setCounterUniques(int counter) override;
QString getBindStringForAxis(int index, bool trueIndex=true); QString getBindStringForAxis(int index, bool trueIndex = true);
QString getBindStringForButton(int index, bool trueIndex=true); QString getBindStringForButton(int index, bool trueIndex = true);
SDL_GameControllerButtonBind getBindForAxis(int index); SDL_GameControllerButtonBind getBindForAxis(int index);
SDL_GameControllerButtonBind getBindForButton(int index); SDL_GameControllerButtonBind getBindForButton(int index);
//bool isRelevantGUID(QString tempGUID); // bool isRelevantGUID(QString tempGUID);
bool isRelevantUniqueID(QString tempUniqueID); bool isRelevantUniqueID(QString tempUniqueID);
void rawButtonEvent(int index, bool pressed); void rawButtonEvent(int index, bool pressed);
void rawAxisEvent(int index, int value); void rawAxisEvent(int index, int value);
void rawDPadEvent(int index, int value); void rawDPadEvent(int index, int value);
QHash<int, bool> const& getRawbuttons(); QHash<int, bool> const &getRawbuttons();
QHash<int, int> const& getAxisvalues(); QHash<int, int> const &getAxisvalues();
QHash<int, int> const& getDpadvalues(); QHash<int, int> const &getDpadvalues();
SDL_GameController *getController() const; SDL_GameController *getController() const;
void fillContainers(QHash<int, SDL_GameControllerButton> &buttons, QHash<int, SDL_GameControllerAxis> &axes, QList<SDL_GameControllerButtonBind> &hatButtons); void fillContainers(QHash<int, SDL_GameControllerButton> &buttons, QHash<int, SDL_GameControllerAxis> &axes,
QList<SDL_GameControllerButtonBind> &hatButtons);
protected slots: protected slots:
virtual void axisActivatedEvent(int setindex, int axisindex, int value) override; virtual void axisActivatedEvent(int setindex, int axisindex, int value) override;
virtual void buttonClickEvent(int buttonindex) override; virtual void buttonClickEvent(int buttonindex) override;
virtual void buttonReleaseEvent(int buttonindex) override; virtual void buttonReleaseEvent(int buttonindex) override;
private: private:
QHash<int, bool> rawbuttons; QHash<int, bool> rawbuttons;
QHash<int, int> axisvalues; QHash<int, int> axisvalues;
QHash<int, int> dpadvalues; QHash<int, int> dpadvalues;
@@ -94,7 +95,6 @@ private:
SDL_JoystickID joystickID; SDL_JoystickID joystickID;
SDL_GameController *controller; SDL_GameController *controller;
}; };
#endif // GAMECONTROLLER_H #endif // GAMECONTROLLER_H

View File

@@ -19,22 +19,21 @@
#include "gamecontrollerdpad.h" #include "gamecontrollerdpad.h"
#include "globalvariables.h" #include "globalvariables.h"
#include "joybutton.h"
#include "messagehandler.h" #include "messagehandler.h"
#include "setjoystick.h" #include "setjoystick.h"
#include "joybutton.h"
#include "xml/joydpadxml.h" #include "xml/joydpadxml.h"
#include <QDebug> #include <QDebug>
GameControllerDPad::GameControllerDPad(JoyButton *upButton, JoyButton *downButton, JoyButton *leftButton,
GameControllerDPad::GameControllerDPad(JoyButton *upButton, JoyButton *downButton, JoyButton *leftButton, JoyButton *rightButton, JoyButton *rightButton, int index, int originset, SetJoystick *parentSet,
int index, int originset, SetJoystick *parentSet, QObject *parent) : QObject *parent)
VDPad(upButton, downButton, leftButton, rightButton, index, originset, parentSet, parent) : VDPad(upButton, downButton, leftButton, rightButton, index, originset, parentSet, parent)
{ {
qInstallMessageHandler(MessageHandler::myMessageOutput); qInstallMessageHandler(MessageHandler::myMessageOutput);
} }
QString GameControllerDPad::getName(bool forceFullFormat, bool displayName) QString GameControllerDPad::getName(bool forceFullFormat, bool displayName)
{ {
qInstallMessageHandler(MessageHandler::myMessageOutput); qInstallMessageHandler(MessageHandler::myMessageOutput);
@@ -49,8 +48,7 @@ QString GameControllerDPad::getName(bool forceFullFormat, bool displayName)
} }
label.append(getDpadName()); label.append(getDpadName());
} } else if (!getDefaultDpadName().isEmpty())
else if (!getDefaultDpadName().isEmpty())
{ {
if (forceFullFormat) if (forceFullFormat)
{ {
@@ -58,8 +56,7 @@ QString GameControllerDPad::getName(bool forceFullFormat, bool displayName)
} }
label.append(getDefaultDpadName()); label.append(getDefaultDpadName());
} } else
else
{ {
label.append(tr("DPad")).append(" "); label.append(tr("DPad")).append(" ");
label.append(QString::number(getRealJoyNumber())); label.append(QString::number(getRealJoyNumber()));
@@ -68,7 +65,6 @@ QString GameControllerDPad::getName(bool forceFullFormat, bool displayName)
return label; return label;
} }
QString GameControllerDPad::getXmlName() QString GameControllerDPad::getXmlName()
{ {
qInstallMessageHandler(MessageHandler::myMessageOutput); qInstallMessageHandler(MessageHandler::myMessageOutput);

View File

@@ -16,7 +16,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef GAMECONTROLLERDPAD_H #ifndef GAMECONTROLLERDPAD_H
#define GAMECONTROLLERDPAD_H #define GAMECONTROLLERDPAD_H
@@ -33,7 +32,7 @@ class GameControllerDPad : public VDPad
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit GameControllerDPad(JoyButton *upButton, JoyButton *downButton, JoyButton *leftButton, JoyButton *rightButton, explicit GameControllerDPad(JoyButton *upButton, JoyButton *downButton, JoyButton *leftButton, JoyButton *rightButton,
int index, int originset, SetJoystick *parentSet, QObject *parent = nullptr); int index, int originset, SetJoystick *parentSet, QObject *parent = nullptr);

View File

@@ -18,29 +18,27 @@
#include "gamecontrollerset.h" #include "gamecontrollerset.h"
#include "messagehandler.h" #include "gamecontroller/xml/gamecontrollertriggerxml.h"
#include "gamecontrollerdpad.h" #include "gamecontrollerdpad.h"
#include "gamecontrollertrigger.h" #include "gamecontrollertrigger.h"
#include "inputdevice.h" #include "inputdevice.h"
#include "joycontrolstick.h" #include "joycontrolstick.h"
#include "xml/joydpadxml.h" #include "messagehandler.h"
#include "xml/joyaxisxml.h" #include "xml/joyaxisxml.h"
#include "gamecontroller/xml/gamecontrollertriggerxml.h"
#include "xml/joybuttonxml.h" #include "xml/joybuttonxml.h"
#include "xml/joydpadxml.h"
#include <QXmlStreamReader>
#include <QDebug> #include <QDebug>
#include <QXmlStreamReader>
GameControllerSet::GameControllerSet(InputDevice *device, int index, QObject *parent)
GameControllerSet::GameControllerSet(InputDevice *device, int index, QObject *parent) : : SetJoystick(device, index, false, parent)
SetJoystick(device, index, false, parent)
{ {
qInstallMessageHandler(MessageHandler::myMessageOutput); qInstallMessageHandler(MessageHandler::myMessageOutput);
resetSticks(); resetSticks();
} }
void GameControllerSet::reset() void GameControllerSet::reset()
{ {
qInstallMessageHandler(MessageHandler::myMessageOutput); qInstallMessageHandler(MessageHandler::myMessageOutput);
@@ -78,7 +76,8 @@ void GameControllerSet::populateSticksDPad()
JoyButton *buttonDown = getJoyButton(SDL_CONTROLLER_BUTTON_DPAD_DOWN); JoyButton *buttonDown = getJoyButton(SDL_CONTROLLER_BUTTON_DPAD_DOWN);
JoyButton *buttonLeft = getJoyButton(SDL_CONTROLLER_BUTTON_DPAD_LEFT); JoyButton *buttonLeft = getJoyButton(SDL_CONTROLLER_BUTTON_DPAD_LEFT);
JoyButton *buttonRight = getJoyButton(SDL_CONTROLLER_BUTTON_DPAD_RIGHT); JoyButton *buttonRight = getJoyButton(SDL_CONTROLLER_BUTTON_DPAD_RIGHT);
GameControllerDPad *controllerDPad = new GameControllerDPad(buttonUp, buttonDown, buttonLeft, buttonRight, 0, getIndex(), this, this); GameControllerDPad *controllerDPad =
new GameControllerDPad(buttonUp, buttonDown, buttonLeft, buttonRight, 0, getIndex(), this, this);
controllerDPad->setDefaultDPadName("DPad"); controllerDPad->setDefaultDPadName("DPad");
addVDPad(0, controllerDPad); addVDPad(0, controllerDPad);
@@ -100,22 +99,19 @@ void GameControllerSet::populateSticksDPad()
getJoyAxis(SDL_CONTROLLER_AXIS_TRIGGERRIGHT)->setDefaultAxisName(tr("R Trigger")); getJoyAxis(SDL_CONTROLLER_AXIS_TRIGGERRIGHT)->setDefaultAxisName(tr("R Trigger"));
} }
template <typename T> void readConf(T *x, QXmlStreamReader *xml)
template <typename T>
void readConf(T* x, QXmlStreamReader *xml)
{ {
if (x != nullptr) if (x != nullptr)
{ {
x->readConfig(xml); x->readConfig(xml);
} } else
else
{ {
xml->skipCurrentElement(); xml->skipCurrentElement();
} }
} }
void GameControllerSet::readConfDpad(QXmlStreamReader *xml, QList<SDL_GameControllerButtonBind> &hatButtons,
void GameControllerSet::readConfDpad(QXmlStreamReader *xml, QList<SDL_GameControllerButtonBind> &hatButtons, bool vdpadExists, bool dpadExists) bool vdpadExists, bool dpadExists)
{ {
int index = xml->attributes().value("index").toString().toInt(); int index = xml->attributes().value("index").toString().toInt();
index = index - 1; index = index - 1;
@@ -132,7 +128,7 @@ void GameControllerSet::readConfDpad(QXmlStreamReader *xml, QList<SDL_GameContro
} }
VDPad *dpad = nullptr; VDPad *dpad = nullptr;
JoyDPadXml<VDPad>* dpadXml = nullptr; JoyDPadXml<VDPad> *dpadXml = nullptr;
if (found) if (found)
{ {
@@ -143,16 +139,13 @@ void GameControllerSet::readConfDpad(QXmlStreamReader *xml, QList<SDL_GameContro
if ((dpad != nullptr) && !vdpadExists) if ((dpad != nullptr) && !vdpadExists)
{ {
dpadXml->readConfig(xml); dpadXml->readConfig(xml);
} } else
else
{ {
xml->skipCurrentElement(); xml->skipCurrentElement();
} }
} }
void GameControllerSet::readJoystickConfig(QXmlStreamReader *xml, QHash<int, SDL_GameControllerButton> &buttons,
void GameControllerSet::readJoystickConfig(QXmlStreamReader *xml,
QHash<int, SDL_GameControllerButton> &buttons,
QHash<int, SDL_GameControllerAxis> &axes, QHash<int, SDL_GameControllerAxis> &axes,
QList<SDL_GameControllerButtonBind> &hatButtons) QList<SDL_GameControllerButtonBind> &hatButtons)
{ {
@@ -172,28 +165,27 @@ void GameControllerSet::readJoystickConfig(QXmlStreamReader *xml,
{ {
int index = xml->attributes().value("index").toString().toInt(); int index = xml->attributes().value("index").toString().toInt();
JoyButton *button = nullptr; JoyButton *button = nullptr;
JoyButtonXml* joyButtonXml = nullptr; JoyButtonXml *joyButtonXml = nullptr;
if (buttons.contains(index-1)) if (buttons.contains(index - 1))
{ {
SDL_GameControllerButton current = buttons.value(index-1); SDL_GameControllerButton current = buttons.value(index - 1);
button = getJoyButton(current); button = getJoyButton(current);
joyButtonXml = new JoyButtonXml(button); joyButtonXml = new JoyButtonXml(button);
} }
readConf(joyButtonXml, xml); readConf(joyButtonXml, xml);
} } else if ((xml->name() == "axis") && xml->isStartElement())
else if ((xml->name() == "axis") && xml->isStartElement())
{ {
int index = xml->attributes().value("index").toString().toInt(); int index = xml->attributes().value("index").toString().toInt();
GameControllerTrigger *trigger = nullptr; GameControllerTrigger *trigger = nullptr;
GameControllerTriggerXml* gameContrTriggerXml = nullptr; GameControllerTriggerXml *gameContrTriggerXml = nullptr;
if (axes.contains(index-1)) if (axes.contains(index - 1))
{ {
SDL_GameControllerAxis current = axes.value(index-1); SDL_GameControllerAxis current = axes.value(index - 1);
trigger = qobject_cast<GameControllerTrigger*>(getJoyAxis(static_cast<int>(current))); trigger = qobject_cast<GameControllerTrigger *>(getJoyAxis(static_cast<int>(current)));
gameContrTriggerXml = new GameControllerTriggerXml(trigger); gameContrTriggerXml = new GameControllerTriggerXml(trigger);
} }
@@ -201,25 +193,20 @@ void GameControllerSet::readJoystickConfig(QXmlStreamReader *xml,
{ {
gameContrTriggerXml->readJoystickConfig(xml); gameContrTriggerXml->readJoystickConfig(xml);
delete gameContrTriggerXml; delete gameContrTriggerXml;
} } else
else
{ {
xml->skipCurrentElement(); xml->skipCurrentElement();
} }
} } else if ((xml->name() == "dpad") && xml->isStartElement())
else if ((xml->name() == "dpad") && xml->isStartElement())
{ {
readConfDpad(xml, hatButtons, vdpadExists, dpadExists); readConfDpad(xml, hatButtons, vdpadExists, dpadExists);
} } else if ((xml->name() == "stick") && xml->isStartElement())
else if ((xml->name() == "stick") && xml->isStartElement())
{ {
getElemFromXml("stick", xml); getElemFromXml("stick", xml);
} } else if ((xml->name() == "vdpad") && xml->isStartElement())
else if ((xml->name() == "vdpad") && xml->isStartElement())
{ {
readConfDpad(xml, hatButtons, vdpadExists, dpadExists); readConfDpad(xml, hatButtons, vdpadExists, dpadExists);
} } else if ((xml->name() == "name") && xml->isStartElement())
else if ((xml->name() == "name") && xml->isStartElement())
{ {
QString temptext = xml->readElementText(); QString temptext = xml->readElementText();
@@ -227,8 +214,7 @@ void GameControllerSet::readJoystickConfig(QXmlStreamReader *xml,
{ {
setName(temptext); setName(temptext);
} }
} } else
else
{ {
// If none of the above, skip the element // If none of the above, skip the element
xml->skipCurrentElement(); xml->skipCurrentElement();
@@ -239,7 +225,6 @@ void GameControllerSet::readJoystickConfig(QXmlStreamReader *xml,
} }
} }
void GameControllerSet::readConfig(QXmlStreamReader *xml) void GameControllerSet::readConfig(QXmlStreamReader *xml)
{ {
qInstallMessageHandler(MessageHandler::myMessageOutput); qInstallMessageHandler(MessageHandler::myMessageOutput);
@@ -253,20 +238,16 @@ void GameControllerSet::readConfig(QXmlStreamReader *xml)
if ((xml->name() == "button") && xml->isStartElement()) if ((xml->name() == "button") && xml->isStartElement())
{ {
getElemFromXml("button", xml); getElemFromXml("button", xml);
} } else if ((xml->name() == "trigger") && xml->isStartElement())
else if ((xml->name() == "trigger") && xml->isStartElement())
{ {
getElemFromXml("trigger", xml); getElemFromXml("trigger", xml);
} } else if ((xml->name() == "stick") && xml->isStartElement())
else if ((xml->name() == "stick") && xml->isStartElement())
{ {
getElemFromXml("stick", xml); getElemFromXml("stick", xml);
} } else if ((xml->name() == "dpad") && xml->isStartElement())
else if ((xml->name() == "dpad") && xml->isStartElement())
{ {
getElemFromXml("dpad", xml); getElemFromXml("dpad", xml);
} } else if ((xml->name() == "name") && xml->isStartElement())
else if ((xml->name() == "name") && xml->isStartElement())
{ {
QString temptext = xml->readElementText(); QString temptext = xml->readElementText();
@@ -274,8 +255,7 @@ void GameControllerSet::readConfig(QXmlStreamReader *xml)
{ {
setName(temptext); setName(temptext);
} }
} } else
else
{ {
// If none of the above, skip the element // If none of the above, skip the element
xml->skipCurrentElement(); xml->skipCurrentElement();
@@ -286,79 +266,75 @@ void GameControllerSet::readConfig(QXmlStreamReader *xml)
} }
} }
void GameControllerSet::getElemFromXml(QString elemName, QXmlStreamReader *xml) void GameControllerSet::getElemFromXml(QString elemName, QXmlStreamReader *xml)
{ {
int index = xml->attributes().value("index").toString().toInt(); int index = xml->attributes().value("index").toString().toInt();
if (elemName == "button") { if (elemName == "button")
JoyButton *button = getJoyButton(index-1); {
JoyButtonXml* joyButtonXml = new JoyButtonXml(button, this); JoyButton *button = getJoyButton(index - 1);
JoyButtonXml *joyButtonXml = new JoyButtonXml(button, this);
readConf(joyButtonXml, xml); readConf(joyButtonXml, xml);
} } else if (elemName == "dpad")
else if (elemName == "dpad") { {
GameControllerDPad *vdpad = qobject_cast<GameControllerDPad*>(getVDPad(index-1)); GameControllerDPad *vdpad = qobject_cast<GameControllerDPad *>(getVDPad(index - 1));
JoyDPadXml<GameControllerDPad>* dpadXml = new JoyDPadXml<GameControllerDPad>(vdpad); JoyDPadXml<GameControllerDPad> *dpadXml = new JoyDPadXml<GameControllerDPad>(vdpad);
readConf(dpadXml, xml); readConf(dpadXml, xml);
// if (!dpadXml.isNull()) delete dpadXml; // if (!dpadXml.isNull()) delete dpadXml;
} } else if (elemName == "trigger")
else if (elemName == "trigger")
{ {
GameControllerTrigger *axis = nullptr; GameControllerTrigger *axis = nullptr;
GameControllerTriggerXml* triggerAxisXml = nullptr; GameControllerTriggerXml *triggerAxisXml = nullptr;
switch(index - 1) switch (index - 1)
{ {
// for older profiles // for older profiles
case 0: case 0:
axis = qobject_cast<GameControllerTrigger*>(getJoyAxis(SDL_CONTROLLER_AXIS_TRIGGERLEFT)); axis = qobject_cast<GameControllerTrigger *>(getJoyAxis(SDL_CONTROLLER_AXIS_TRIGGERLEFT));
triggerAxisXml = new GameControllerTriggerXml(axis, this); triggerAxisXml = new GameControllerTriggerXml(axis, this);
readConf(triggerAxisXml, xml); readConf(triggerAxisXml, xml);
break; break;
// for older profiles // for older profiles
case 1: case 1:
axis = qobject_cast<GameControllerTrigger*>(getJoyAxis(SDL_CONTROLLER_AXIS_TRIGGERRIGHT)); axis = qobject_cast<GameControllerTrigger *>(getJoyAxis(SDL_CONTROLLER_AXIS_TRIGGERRIGHT));
triggerAxisXml = new GameControllerTriggerXml(axis, this); triggerAxisXml = new GameControllerTriggerXml(axis, this);
readConf(triggerAxisXml, xml); readConf(triggerAxisXml, xml);
break; break;
case 4: case 4:
axis = qobject_cast<GameControllerTrigger*>(getJoyAxis(SDL_CONTROLLER_AXIS_TRIGGERLEFT)); axis = qobject_cast<GameControllerTrigger *>(getJoyAxis(SDL_CONTROLLER_AXIS_TRIGGERLEFT));
triggerAxisXml = new GameControllerTriggerXml(axis, this); triggerAxisXml = new GameControllerTriggerXml(axis, this);
readConf(triggerAxisXml, xml); readConf(triggerAxisXml, xml);
break; break;
case 5: case 5:
axis = qobject_cast<GameControllerTrigger*>(getJoyAxis(SDL_CONTROLLER_AXIS_TRIGGERRIGHT)); axis = qobject_cast<GameControllerTrigger *>(getJoyAxis(SDL_CONTROLLER_AXIS_TRIGGERRIGHT));
triggerAxisXml = new GameControllerTriggerXml(axis, this); triggerAxisXml = new GameControllerTriggerXml(axis, this);
readConf(triggerAxisXml, xml); readConf(triggerAxisXml, xml);
break; break;
} }
} } else if (elemName == "stick")
else if (elemName == "stick") { {
if (index > 0) if (index > 0)
{ {
index -= 1; index -= 1;
JoyControlStick *stick = getJoyStick(index); JoyControlStick *stick = getJoyStick(index);
readConf(stick, xml); readConf(stick, xml);
} } else
else
{ {
xml->skipCurrentElement(); xml->skipCurrentElement();
} }
} }
} }
void GameControllerSet::refreshAxes() void GameControllerSet::refreshAxes()
{ {
qInstallMessageHandler(MessageHandler::myMessageOutput); qInstallMessageHandler(MessageHandler::myMessageOutput);
deleteAxes(); deleteAxes();
for (int i = 0; i < getInputDevice()->getNumberRawAxes(); i++) for (int i = 0; i < getInputDevice()->getNumberRawAxes(); i++)
{ {
if ((i == static_cast<int>(SDL_CONTROLLER_AXIS_TRIGGERLEFT)) || if ((i == static_cast<int>(SDL_CONTROLLER_AXIS_TRIGGERLEFT)) ||
@@ -367,8 +343,7 @@ void GameControllerSet::refreshAxes()
GameControllerTrigger *trigger = new GameControllerTrigger(i, getIndex(), this, this); GameControllerTrigger *trigger = new GameControllerTrigger(i, getIndex(), this, this);
getAxes()->insert(i, trigger); getAxes()->insert(i, trigger);
enableAxisConnections(trigger); enableAxisConnections(trigger);
} } else
else
{ {
JoyAxis *axis = new JoyAxis(i, getIndex(), this, this); JoyAxis *axis = new JoyAxis(i, getIndex(), this, this);
getAxes()->insert(i, axis); getAxes()->insert(i, axis);

View File

@@ -16,7 +16,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef GAMECONTROLLERSET_H #ifndef GAMECONTROLLERSET_H
#define GAMECONTROLLERSET_H #define GAMECONTROLLERSET_H
@@ -27,31 +26,30 @@
class QXmlStreamReader; class QXmlStreamReader;
class InputDevice; class InputDevice;
class GameControllerSet : public SetJoystick class GameControllerSet : public SetJoystick
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit GameControllerSet(InputDevice *device, int index, QObject *parent = nullptr); explicit GameControllerSet(InputDevice *device, int index, QObject *parent = nullptr);
virtual void refreshAxes(); virtual void refreshAxes();
virtual void readConfig(QXmlStreamReader *xml); // GameControllerSetXml virtual void readConfig(QXmlStreamReader *xml); // GameControllerSetXml
virtual void readJoystickConfig(QXmlStreamReader *xml, virtual void readJoystickConfig(QXmlStreamReader *xml, QHash<int, SDL_GameControllerButton> &buttons,
QHash<int, SDL_GameControllerButton> &buttons, QHash<int, SDL_GameControllerAxis> &axes,
QHash<int, SDL_GameControllerAxis> &axes, QList<SDL_GameControllerButtonBind> &hatButtons); // GameControllerSetXml class
QList<SDL_GameControllerButtonBind> &hatButtons); // GameControllerSetXml class
protected: protected:
void populateSticksDPad(); void populateSticksDPad();
public slots: public slots:
virtual void reset(); virtual void reset();
private: private:
void getElemFromXml(QString elemName, QXmlStreamReader *xml); // GameControllerSetXml class void getElemFromXml(QString elemName, QXmlStreamReader *xml); // GameControllerSetXml class
void readConfDpad(QXmlStreamReader *xml, QList<SDL_GameControllerButtonBind> &hatButtons, bool vdpadExists, bool dpadExists); // GameControllerSetXml class void readConfDpad(QXmlStreamReader *xml, QList<SDL_GameControllerButtonBind> &hatButtons, bool vdpadExists,
bool dpadExists); // GameControllerSetXml class
void resetSticks(); void resetSticks();
}; };

View File

@@ -20,22 +20,22 @@
#include "gamecontrollertrigger.h" #include "gamecontrollertrigger.h"
#include "gamecontrollertriggerbutton.h"
#include "globalvariables.h" #include "globalvariables.h"
#include "messagehandler.h" #include "messagehandler.h"
#include "gamecontrollertriggerbutton.h"
#include "xml/joyaxisxml.h" #include "xml/joyaxisxml.h"
#include <SDL2/SDL_gamecontroller.h> #include <SDL2/SDL_gamecontroller.h>
#include <QDebug>
#include <QXmlStreamReader> #include <QXmlStreamReader>
#include <QXmlStreamWriter> #include <QXmlStreamWriter>
#include <QDebug>
const GameControllerTrigger::ThrottleTypes GameControllerTrigger::DEFAULTTHROTTLE =
GameControllerTrigger::PositiveHalfThrottle;
const GameControllerTrigger::ThrottleTypes GameControllerTrigger::DEFAULTTHROTTLE = GameControllerTrigger::PositiveHalfThrottle; GameControllerTrigger::GameControllerTrigger(int index, int originset, SetJoystick *parentSet, QObject *parent)
: JoyAxis(index, originset, parentSet, parent)
GameControllerTrigger::GameControllerTrigger(int index, int originset, SetJoystick *parentSet, QObject *parent) :
JoyAxis(index, originset, parentSet, parent)
{ {
qInstallMessageHandler(MessageHandler::myMessageOutput); qInstallMessageHandler(MessageHandler::myMessageOutput);
@@ -44,7 +44,6 @@ GameControllerTrigger::GameControllerTrigger(int index, int originset, SetJoysti
reset(index); reset(index);
} }
void GameControllerTrigger::reset(int index) void GameControllerTrigger::reset(int index)
{ {
qInstallMessageHandler(MessageHandler::myMessageOutput); qInstallMessageHandler(MessageHandler::myMessageOutput);
@@ -53,7 +52,6 @@ void GameControllerTrigger::reset(int index)
m_index = index; m_index = index;
} }
void GameControllerTrigger::reset() void GameControllerTrigger::reset()
{ {
qInstallMessageHandler(MessageHandler::myMessageOutput); qInstallMessageHandler(MessageHandler::myMessageOutput);
@@ -81,7 +79,6 @@ void GameControllerTrigger::reset()
pendingIgnoreSets = false; pendingIgnoreSets = false;
} }
QString GameControllerTrigger::getXmlName() QString GameControllerTrigger::getXmlName()
{ {
qInstallMessageHandler(MessageHandler::myMessageOutput); qInstallMessageHandler(MessageHandler::myMessageOutput);
@@ -89,7 +86,6 @@ QString GameControllerTrigger::getXmlName()
return GlobalVariables::GameControllerTrigger::xmlName; return GlobalVariables::GameControllerTrigger::xmlName;
} }
QString GameControllerTrigger::getPartialName(bool forceFullFormat, bool displayNames) QString GameControllerTrigger::getPartialName(bool forceFullFormat, bool displayNames)
{ {
qInstallMessageHandler(MessageHandler::myMessageOutput); qInstallMessageHandler(MessageHandler::myMessageOutput);
@@ -104,8 +100,7 @@ QString GameControllerTrigger::getPartialName(bool forceFullFormat, bool display
{ {
label.append(" ").append(tr("Trigger")); label.append(" ").append(tr("Trigger"));
} }
} } else if (!defaultAxisName.isEmpty())
else if (!defaultAxisName.isEmpty())
{ {
label.append(defaultAxisName); label.append(defaultAxisName);
@@ -113,8 +108,7 @@ QString GameControllerTrigger::getPartialName(bool forceFullFormat, bool display
{ {
label.append(" ").append(tr("Trigger")); label.append(" ").append(tr("Trigger"));
} }
} } else
else
{ {
label.append(tr("Trigger")).append(" "); label.append(tr("Trigger")).append(" ");
label.append(QString::number(getRealJoyIndex() - SDL_CONTROLLER_AXIS_TRIGGERLEFT)); label.append(QString::number(getRealJoyIndex() - SDL_CONTROLLER_AXIS_TRIGGERLEFT));
@@ -136,7 +130,6 @@ void GameControllerTrigger::correctJoystickThrottle()
} }
} }
int GameControllerTrigger::getDefaultDeadZone() int GameControllerTrigger::getDefaultDeadZone()
{ {
qInstallMessageHandler(MessageHandler::myMessageOutput); qInstallMessageHandler(MessageHandler::myMessageOutput);
@@ -144,7 +137,6 @@ int GameControllerTrigger::getDefaultDeadZone()
return GlobalVariables::GameControllerTrigger::AXISDEADZONE; return GlobalVariables::GameControllerTrigger::AXISDEADZONE;
} }
int GameControllerTrigger::getDefaultMaxZone() int GameControllerTrigger::getDefaultMaxZone()
{ {
qInstallMessageHandler(MessageHandler::myMessageOutput); qInstallMessageHandler(MessageHandler::myMessageOutput);
@@ -152,7 +144,6 @@ int GameControllerTrigger::getDefaultMaxZone()
return GlobalVariables::GameControllerTrigger::AXISMAXZONE; return GlobalVariables::GameControllerTrigger::AXISMAXZONE;
} }
JoyAxis::ThrottleTypes GameControllerTrigger::getDefaultThrottle() JoyAxis::ThrottleTypes GameControllerTrigger::getDefaultThrottle()
{ {
qInstallMessageHandler(MessageHandler::myMessageOutput); qInstallMessageHandler(MessageHandler::myMessageOutput);

View File

@@ -16,7 +16,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef GAMECONTROLLERTRIGGER_H #ifndef GAMECONTROLLERTRIGGER_H
#define GAMECONTROLLERTRIGGER_H #define GAMECONTROLLERTRIGGER_H
@@ -30,7 +29,7 @@ class GameControllerTrigger : public JoyAxis
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit GameControllerTrigger(int index, int originset, SetJoystick *parentSet, QObject *parent = nullptr); explicit GameControllerTrigger(int index, int originset, SetJoystick *parentSet, QObject *parent = nullptr);
virtual QString getXmlName(); // GameControllerTriggerXml class virtual QString getXmlName(); // GameControllerTriggerXml class
@@ -42,13 +41,12 @@ public:
static const ThrottleTypes DEFAULTTHROTTLE; static const ThrottleTypes DEFAULTTHROTTLE;
public slots: public slots:
virtual void reset(); virtual void reset();
virtual void reset(int index); virtual void reset(int index);
protected: protected:
void correctJoystickThrottle(); void correctJoystickThrottle();
}; };
#endif // GAMECONTROLLERTRIGGER_H #endif // GAMECONTROLLERTRIGGER_H

View File

@@ -19,23 +19,22 @@
#include "gamecontrollertriggerbutton.h" #include "gamecontrollertriggerbutton.h"
#include "globalvariables.h" #include "globalvariables.h"
#include "inputdevice.h"
#include "joyaxis.h"
#include "messagehandler.h" #include "messagehandler.h"
#include "setjoystick.h" #include "setjoystick.h"
#include "joyaxis.h"
#include "inputdevice.h"
#include "xml/joybuttonxml.h" #include "xml/joybuttonxml.h"
#include <QXmlStreamReader>
#include <QDebug> #include <QDebug>
#include <QXmlStreamReader>
GameControllerTriggerButton::GameControllerTriggerButton(JoyAxis *axis, int index, int originset, SetJoystick *parentSet,
GameControllerTriggerButton::GameControllerTriggerButton(JoyAxis *axis, int index, int originset, SetJoystick *parentSet, QObject *parent) : QObject *parent)
JoyAxisButton(axis, index, originset, parentSet, parent) : JoyAxisButton(axis, index, originset, parentSet, parent)
{ {
qInstallMessageHandler(MessageHandler::myMessageOutput); qInstallMessageHandler(MessageHandler::myMessageOutput);
} }
QString GameControllerTriggerButton::getXmlName() QString GameControllerTriggerButton::getXmlName()
{ {
qInstallMessageHandler(MessageHandler::myMessageOutput); qInstallMessageHandler(MessageHandler::myMessageOutput);
@@ -43,22 +42,20 @@ QString GameControllerTriggerButton::getXmlName()
return GlobalVariables::GameControllerTriggerButton::xmlName; return GlobalVariables::GameControllerTriggerButton::xmlName;
} }
void GameControllerTriggerButton::readJoystickConfig(QXmlStreamReader *xml) void GameControllerTriggerButton::readJoystickConfig(QXmlStreamReader *xml)
{ {
qInstallMessageHandler(MessageHandler::myMessageOutput); qInstallMessageHandler(MessageHandler::myMessageOutput);
if (xml->isStartElement() && (xml->name() == GlobalVariables::JoyAxisButton::xmlName)) if (xml->isStartElement() && (xml->name() == GlobalVariables::JoyAxisButton::xmlName))
{ {
disconnect(this, &GameControllerTriggerButton::slotsChanged, m_parentSet->getInputDevice(), &InputDevice::profileEdited); disconnect(this, &GameControllerTriggerButton::slotsChanged, m_parentSet->getInputDevice(),
&InputDevice::profileEdited);
xml->readNextStartElement(); xml->readNextStartElement();
while (!xml->atEnd() && (!xml->isEndElement() && (xml->name() != GlobalVariables::JoyAxisButton::xmlName))) while (!xml->atEnd() && (!xml->isEndElement() && (xml->name() != GlobalVariables::JoyAxisButton::xmlName)))
{ {
JoyButtonXml* joyButtonXml = new JoyButtonXml(this); JoyButtonXml *joyButtonXml = new JoyButtonXml(this);
bool found = joyButtonXml->readButtonConfig(xml); bool found = joyButtonXml->readButtonConfig(xml);
if (!found) if (!found)
@@ -69,6 +66,7 @@ void GameControllerTriggerButton::readJoystickConfig(QXmlStreamReader *xml)
xml->readNextStartElement(); xml->readNextStartElement();
} }
connect(this, &GameControllerTriggerButton::slotsChanged, m_parentSet->getInputDevice(), &InputDevice::profileEdited); connect(this, &GameControllerTriggerButton::slotsChanged, m_parentSet->getInputDevice(),
&InputDevice::profileEdited);
} }
} }

View File

@@ -16,7 +16,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef GAMECONTROLLERBUTTON_H #ifndef GAMECONTROLLERBUTTON_H
#define GAMECONTROLLERBUTTON_H #define GAMECONTROLLERBUTTON_H
@@ -26,17 +25,16 @@ class QXmlStreamReader;
class SetJoystick; class SetJoystick;
class JoyAxis; class JoyAxis;
class GameControllerTriggerButton : public JoyAxisButton class GameControllerTriggerButton : public JoyAxisButton
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit GameControllerTriggerButton(JoyAxis *axis, int index, int originset, SetJoystick *parentSet, QObject *parent = nullptr); explicit GameControllerTriggerButton(JoyAxis *axis, int index, int originset, SetJoystick *parentSet,
QObject *parent = nullptr);
virtual QString getXmlName(); // GameContrTriggerBtnXml class virtual QString getXmlName(); // GameContrTriggerBtnXml class
void readJoystickConfig(QXmlStreamReader *xml); // GameContrTriggerBtnXml class void readJoystickConfig(QXmlStreamReader *xml); // GameContrTriggerBtnXml class
}; };
#endif // GAMECONTROLLERBUTTON_H #endif // GAMECONTROLLERBUTTON_H

View File

@@ -20,11 +20,11 @@
#include "gamecontroller/gamecontrollerdpad.h" #include "gamecontroller/gamecontrollerdpad.h"
#include <QXmlStreamReader>
#include <QDebug> #include <QDebug>
#include <QXmlStreamReader>
GameControllerDPadXml::GameControllerDPadXml(GameControllerDPad *gameContrDpad, QObject *parent)
GameControllerDPadXml::GameControllerDPadXml(GameControllerDPad* gameContrDpad, QObject* parent) : JoyDPadXml<VDPad>(gameContrDpad, parent) : JoyDPadXml<VDPad>(gameContrDpad, parent)
{ {
dpadXml = new JoyDPadXml<GameControllerDPad>(gameContrDpad, this); dpadXml = new JoyDPadXml<GameControllerDPad>(gameContrDpad, this);
} }

View File

@@ -15,7 +15,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef GAMECONTROLLERDPADXML_H #ifndef GAMECONTROLLERDPADXML_H
#define GAMECONTROLLERDPADXML_H #define GAMECONTROLLERDPADXML_H
@@ -24,18 +23,17 @@
class GameControllerDPad; class GameControllerDPad;
class QXmlStreamReader; class QXmlStreamReader;
class GameControllerDPadXml : public JoyDPadXml<VDPad> class GameControllerDPadXml : public JoyDPadXml<VDPad>
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit GameControllerDPadXml(GameControllerDPad* gameContrDpad, QObject* parent = nullptr); explicit GameControllerDPadXml(GameControllerDPad *gameContrDpad, QObject *parent = nullptr);
void readJoystickConfig(QXmlStreamReader *xml); void readJoystickConfig(QXmlStreamReader *xml);
private: private:
JoyDPadXml<GameControllerDPad>* dpadXml; JoyDPadXml<GameControllerDPad> *dpadXml;
}; };
#endif // GAMECONTROLLERDPADXML_H #endif // GAMECONTROLLERDPADXML_H

View File

@@ -25,12 +25,12 @@
#include <SDL2/SDL_gamecontroller.h> #include <SDL2/SDL_gamecontroller.h>
#include <QXmlStreamWriter>
#include <QXmlStreamReader>
#include <QDebug> #include <QDebug>
#include <QXmlStreamReader>
#include <QXmlStreamWriter>
GameControllerTriggerXml::GameControllerTriggerXml(GameControllerTrigger *gameContrTrigger, QObject *parent)
GameControllerTriggerXml::GameControllerTriggerXml(GameControllerTrigger* gameContrTrigger, QObject *parent) : JoyAxisXml(gameContrTrigger, parent) : JoyAxisXml(gameContrTrigger, parent)
{ {
m_gameContrTrigger = gameContrTrigger; m_gameContrTrigger = gameContrTrigger;
joyButtonXmlNAxis = new JoyButtonXml(gameContrTrigger->getNAxisButton(), this); joyButtonXmlNAxis = new JoyButtonXml(gameContrTrigger->getNAxisButton(), this);
@@ -56,20 +56,19 @@ void GameControllerTriggerXml::readJoystickConfig(QXmlStreamReader *xml)
qDebug() << "Index for axis in readJoystickConfig is: " << index; qDebug() << "Index for axis in readJoystickConfig is: " << index;
switch (index) { switch (index)
{
case 1: case 1:
found = true; found = true;
triggerButton = triggerButton = qobject_cast<GameControllerTriggerButton *>(m_gameContrTrigger->getNAxisButton());
qobject_cast<GameControllerTriggerButton*>(m_gameContrTrigger->getNAxisButton()); triggerButton->readJoystickConfig(xml);
triggerButton->readJoystickConfig(xml);
break; break;
case 2: case 2:
found = true; found = true;
triggerButton = triggerButton = qobject_cast<GameControllerTriggerButton *>(m_gameContrTrigger->getPAxisButton());
qobject_cast<GameControllerTriggerButton*>(m_gameContrTrigger->getPAxisButton()); triggerButton->readJoystickConfig(xml);
triggerButton->readJoystickConfig(xml);
break; break;
} }
} }
@@ -87,7 +86,8 @@ void GameControllerTriggerXml::readJoystickConfig(QXmlStreamReader *xml)
{ {
m_gameContrTrigger->setThrottle(static_cast<int>(JoyAxis::PositiveHalfThrottle)); m_gameContrTrigger->setThrottle(static_cast<int>(JoyAxis::PositiveHalfThrottle));
m_gameContrTrigger->setCurrentRawValue(m_gameContrTrigger->getCurrentThrottledDeadValue()); m_gameContrTrigger->setCurrentRawValue(m_gameContrTrigger->getCurrentThrottledDeadValue());
m_gameContrTrigger->updateCurrentThrottledValue(m_gameContrTrigger->calculateThrottledValue(m_gameContrTrigger->getCurrentRawValue())); m_gameContrTrigger->updateCurrentThrottledValue(
m_gameContrTrigger->calculateThrottledValue(m_gameContrTrigger->getCurrentRawValue()));
} }
} }
@@ -112,30 +112,30 @@ void GameControllerTriggerXml::writeConfig(QXmlStreamWriter *xml)
xml->writeStartElement("throttle"); xml->writeStartElement("throttle");
switch(m_gameContrTrigger->getThrottle()) switch (m_gameContrTrigger->getThrottle())
{ {
case -2: case -2:
xml->writeCharacters("negativehalf"); xml->writeCharacters("negativehalf");
break; break;
case -1: case -1:
xml->writeCharacters("negative"); xml->writeCharacters("negative");
break; break;
case 0: case 0:
xml->writeCharacters("normal"); xml->writeCharacters("normal");
break; break;
case 1: case 1:
xml->writeCharacters("positive"); xml->writeCharacters("positive");
break; break;
case 2: case 2:
xml->writeCharacters("positivehalf"); xml->writeCharacters("positivehalf");
break; break;
} }
xml->writeEndElement(); xml->writeEndElement();
if (!currentlyDefault) if (!currentlyDefault)
{ {

View File

@@ -15,7 +15,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef GAMECONTROLLERTRIGGERXML_H #ifndef GAMECONTROLLERTRIGGERXML_H
#define GAMECONTROLLERTRIGGERXML_H #define GAMECONTROLLERTRIGGERXML_H
@@ -23,20 +22,19 @@
class GameControllerTrigger; class GameControllerTrigger;
class GameControllerTriggerXml : public JoyAxisXml class GameControllerTriggerXml : public JoyAxisXml
{ {
public: public:
explicit GameControllerTriggerXml(GameControllerTrigger* gameContrTrigger, QObject *parent = 0); explicit GameControllerTriggerXml(GameControllerTrigger *gameContrTrigger, QObject *parent = 0);
void readJoystickConfig(QXmlStreamReader *xml); void readJoystickConfig(QXmlStreamReader *xml);
virtual void writeConfig(QXmlStreamWriter *xml); virtual void writeConfig(QXmlStreamWriter *xml);
private: private:
GameControllerTrigger* m_gameContrTrigger; GameControllerTrigger *m_gameContrTrigger;
JoyButtonXml* joyButtonXmlNAxis; JoyButtonXml *joyButtonXmlNAxis;
JoyButtonXml* joyButtonXmlPAxis; JoyButtonXml *joyButtonXmlPAxis;
}; };
#endif // GAMECONTROLLERTRIGGERXML_H #endif // GAMECONTROLLERTRIGGERXML_H

View File

@@ -19,8 +19,8 @@
#include "gamecontroller/gamecontroller.h" #include "gamecontroller/gamecontroller.h"
#include "globalvariables.h"
#include "common.h" #include "common.h"
#include "globalvariables.h"
#include "messagehandler.h" #include "messagehandler.h"
//#include "logger.h" //#include "logger.h"
#include "gamecontroller/gamecontrollerdpad.h" #include "gamecontroller/gamecontrollerdpad.h"
@@ -30,11 +30,12 @@
#include <cmath> #include <cmath>
#include <QDebug>
#include <QXmlStreamReader> #include <QXmlStreamReader>
#include <QXmlStreamWriter> #include <QXmlStreamWriter>
#include <QDebug>
GameControllerXml::GameControllerXml(GameController* gameController, QObject *parent) : InputDeviceXml(gameController, parent) GameControllerXml::GameControllerXml(GameController *gameController, QObject *parent)
: InputDeviceXml(gameController, parent)
{ {
m_gameController = gameController; m_gameController = gameController;
} }
@@ -59,7 +60,6 @@ void GameControllerXml::readJoystickConfig(QXmlStreamReader *xml)
xml->readNextStartElement(); xml->readNextStartElement();
while (!xml->atEnd() && (!xml->isEndElement() && (xml->name() != "joystick"))) while (!xml->atEnd() && (!xml->isEndElement() && (xml->name() != "joystick")))
{ {
if ((xml->name() == "sets") && xml->isStartElement()) if ((xml->name() == "sets") && xml->isStartElement())
@@ -75,11 +75,11 @@ void GameControllerXml::readJoystickConfig(QXmlStreamReader *xml)
if ((index >= 0) && (index < m_gameController->getJoystick_sets().size())) if ((index >= 0) && (index < m_gameController->getJoystick_sets().size()))
{ {
GameControllerSet *currentSet = qobject_cast<GameControllerSet*>(m_gameController->getJoystick_sets().value(index)); // static_cast GameControllerSet *currentSet = qobject_cast<GameControllerSet *>(
m_gameController->getJoystick_sets().value(index)); // static_cast
currentSet->readJoystickConfig(xml, buttons, axes, hatButtons); currentSet->readJoystickConfig(xml, buttons, axes, hatButtons);
} }
} } else
else
{ {
// If none of the above, skip the element // If none of the above, skip the element
xml->skipCurrentElement(); xml->skipCurrentElement();
@@ -87,8 +87,7 @@ void GameControllerXml::readJoystickConfig(QXmlStreamReader *xml)
xml->readNextStartElement(); xml->readNextStartElement();
} }
} } else if ((xml->name() == "names") && xml->isStartElement())
else if ((xml->name() == "names") && xml->isStartElement())
{ {
bool dpadNameExists = false; bool dpadNameExists = false;
bool vdpadNameExists = false; bool vdpadNameExists = false;
@@ -101,7 +100,6 @@ void GameControllerXml::readJoystickConfig(QXmlStreamReader *xml)
{ {
assignVariablesShort(xml, index, temp); assignVariablesShort(xml, index, temp);
if ((index >= 0) && !temp.isEmpty()) if ((index >= 0) && !temp.isEmpty())
{ {
SDL_GameControllerButton current = buttons.value(index); SDL_GameControllerButton current = buttons.value(index);
@@ -111,12 +109,10 @@ void GameControllerXml::readJoystickConfig(QXmlStreamReader *xml)
m_gameController->setButtonName(current, temp); m_gameController->setButtonName(current, temp);
} }
} }
} } else if ((xml->name() == "axisbuttonname") && xml->isStartElement())
else if ((xml->name() == "axisbuttonname") && xml->isStartElement())
{ {
assignVariables(xml, index, buttonIndex, temp, true); assignVariables(xml, index, buttonIndex, temp, true);
if ((index >= 0) && !temp.isEmpty()) if ((index >= 0) && !temp.isEmpty())
{ {
SDL_GameControllerAxis current = axes.value(index); SDL_GameControllerAxis current = axes.value(index);
@@ -124,41 +120,34 @@ void GameControllerXml::readJoystickConfig(QXmlStreamReader *xml)
switch (currentInt) switch (currentInt)
{ {
case SDL_CONTROLLER_AXIS_LEFTX: case SDL_CONTROLLER_AXIS_LEFTX:
case SDL_CONTROLLER_AXIS_LEFTY: case SDL_CONTROLLER_AXIS_LEFTY: {
{ m_gameController->setStickButtonName(0, buttonIndex, temp);
m_gameController->setStickButtonName(0, buttonIndex, temp); break;
break; }
} case SDL_CONTROLLER_AXIS_RIGHTX:
case SDL_CONTROLLER_AXIS_RIGHTX: case SDL_CONTROLLER_AXIS_RIGHTY: {
case SDL_CONTROLLER_AXIS_RIGHTY: m_gameController->setStickButtonName(1, buttonIndex, temp);
{ break;
m_gameController->setStickButtonName(1, buttonIndex, temp); }
break; case SDL_CONTROLLER_AXIS_TRIGGERLEFT:
} case SDL_CONTROLLER_AXIS_TRIGGERRIGHT: {
case SDL_CONTROLLER_AXIS_TRIGGERLEFT: m_gameController->setAxisName(current, temp);
case SDL_CONTROLLER_AXIS_TRIGGERRIGHT: }
{
m_gameController->setAxisName(current, temp);
}
} }
} }
} } else if ((xml->name() == "controlstickbuttonname") && xml->isStartElement())
else if ((xml->name() == "controlstickbuttonname") && xml->isStartElement())
{ {
assignVariables(xml, index, buttonIndex, temp, false); assignVariables(xml, index, buttonIndex, temp, false);
if ((index >= 0) && !temp.isEmpty()) if ((index >= 0) && !temp.isEmpty())
{ {
m_gameController->setStickButtonName(index, buttonIndex, temp); m_gameController->setStickButtonName(index, buttonIndex, temp);
} }
} } else if ((xml->name() == "dpadbuttonname") && xml->isStartElement())
else if ((xml->name() == "dpadbuttonname") && xml->isStartElement())
{ {
assignVariables(xml, index, buttonIndex, temp, false); assignVariables(xml, index, buttonIndex, temp, false);
if ((index >= 0) && !temp.isEmpty()) if ((index >= 0) && !temp.isEmpty())
{ {
bool found = false; bool found = false;
@@ -184,19 +173,18 @@ void GameControllerXml::readJoystickConfig(QXmlStreamReader *xml)
{ {
JoyDPadButton *dpadbutton = dpad->getJoyButton(buttonIndex); JoyDPadButton *dpadbutton = dpad->getJoyButton(buttonIndex);
if ((dpad != nullptr) && (dpadbutton != nullptr) && dpadbutton->getActionName().isEmpty()) if ((dpad != nullptr) && (dpadbutton != nullptr) &&
dpadbutton->getActionName().isEmpty())
{ {
m_gameController->setVDPadButtonName(index, buttonIndex, temp); m_gameController->setVDPadButtonName(index, buttonIndex, temp);
} }
} }
} }
} }
} } else if ((xml->name() == "vdpadbuttonname") && xml->isStartElement())
else if ((xml->name() == "vdpadbuttonname") && xml->isStartElement())
{ {
assignVariables(xml, index, buttonIndex, temp, false); assignVariables(xml, index, buttonIndex, temp, false);
if ((index >= 0) && !temp.isEmpty()) if ((index >= 0) && !temp.isEmpty())
{ {
bool found = false; bool found = false;
@@ -221,19 +209,18 @@ void GameControllerXml::readJoystickConfig(QXmlStreamReader *xml)
{ {
JoyDPadButton *dpadbutton = dpad->getJoyButton(buttonIndex); JoyDPadButton *dpadbutton = dpad->getJoyButton(buttonIndex);
if ((dpad != nullptr) && (dpadbutton != nullptr) && dpadbutton->getActionName().isEmpty()) if ((dpad != nullptr) && (dpadbutton != nullptr) &&
dpadbutton->getActionName().isEmpty())
{ {
m_gameController->setVDPadButtonName(index, buttonIndex, temp); m_gameController->setVDPadButtonName(index, buttonIndex, temp);
} }
} }
} }
} }
} } else if ((xml->name() == "axisname") && xml->isStartElement())
else if ((xml->name() == "axisname") && xml->isStartElement())
{ {
assignVariablesShort(xml, index, temp); assignVariablesShort(xml, index, temp);
if ((index >= 0) && !temp.isEmpty()) if ((index >= 0) && !temp.isEmpty())
{ {
if (axes.contains(index)) if (axes.contains(index))
@@ -242,26 +229,21 @@ void GameControllerXml::readJoystickConfig(QXmlStreamReader *xml)
m_gameController->setAxisName(static_cast<int>(current), temp); m_gameController->setAxisName(static_cast<int>(current), temp);
} }
} }
} } else if ((xml->name() == "controlstickname") && xml->isStartElement())
else if ((xml->name() == "controlstickname") && xml->isStartElement())
{ {
assignVariablesShort(xml, index, temp); assignVariablesShort(xml, index, temp);
if ((index >= 0) && !temp.isEmpty()) if ((index >= 0) && !temp.isEmpty())
{ {
m_gameController->setStickName(index, temp); m_gameController->setStickName(index, temp);
} }
} } else if ((xml->name() == "dpadname") && xml->isStartElement())
else if ((xml->name() == "dpadname") && xml->isStartElement())
{ {
readJoystickConfigXmlLong(hatButtons, dpadNameExists, vdpadNameExists, xml); readJoystickConfigXmlLong(hatButtons, dpadNameExists, vdpadNameExists, xml);
} } else if ((xml->name() == "vdpadname") && xml->isStartElement())
else if ((xml->name() == "vdpadname") && xml->isStartElement())
{ {
readJoystickConfigXmlLong(hatButtons, dpadNameExists, vdpadNameExists, xml); readJoystickConfigXmlLong(hatButtons, dpadNameExists, vdpadNameExists, xml);
} } else
else
{ {
// If none of the above, skip the element // If none of the above, skip the element
xml->skipCurrentElement(); xml->skipCurrentElement();
@@ -269,21 +251,19 @@ void GameControllerXml::readJoystickConfig(QXmlStreamReader *xml)
xml->readNextStartElement(); xml->readNextStartElement();
} }
} } else if ((xml->name() == "keyPressTime") && xml->isStartElement())
else if ((xml->name() == "keyPressTime") && xml->isStartElement())
{ {
QString temptext = xml->readElementText(); QString temptext = xml->readElementText();
int tempchoice = temptext.toInt(); int tempchoice = temptext.toInt();
if (tempchoice >= 10) m_gameController->setDeviceKeyPressTime(tempchoice); if (tempchoice >= 10)
m_gameController->setDeviceKeyPressTime(tempchoice);
} } else if ((xml->name() == "profilename") && xml->isStartElement())
else if ((xml->name() == "profilename") && xml->isStartElement())
{ {
QString temptext = xml->readElementText(); QString temptext = xml->readElementText();
m_gameController->setProfileName(temptext); m_gameController->setProfileName(temptext);
} } else
else
{ {
// If none of the above, skip the element // If none of the above, skip the element
xml->skipCurrentElement(); xml->skipCurrentElement();
@@ -300,7 +280,6 @@ void GameControllerXml::readConfig(QXmlStreamReader *xml)
{ {
qInstallMessageHandler(MessageHandler::myMessageOutput); qInstallMessageHandler(MessageHandler::myMessageOutput);
if (xml->isStartElement() && (xml->name() == m_gameController->getXmlName())) if (xml->isStartElement() && (xml->name() == m_gameController->getXmlName()))
{ {
m_gameController->transferReset(); m_gameController->transferReset();
@@ -324,8 +303,7 @@ void GameControllerXml::readConfig(QXmlStreamReader *xml)
{ {
m_gameController->getJoystick_sets().value(index)->readConfig(xml); m_gameController->getJoystick_sets().value(index)->readConfig(xml);
} }
} } else
else
{ {
// If none of the above, skip the element // If none of the above, skip the element
xml->skipCurrentElement(); xml->skipCurrentElement();
@@ -333,8 +311,7 @@ void GameControllerXml::readConfig(QXmlStreamReader *xml)
xml->readNextStartElement(); xml->readNextStartElement();
} }
} } else if ((xml->name() == "names") && xml->isStartElement())
else if ((xml->name() == "names") && xml->isStartElement())
{ {
xml->readNextStartElement(); xml->readNextStartElement();
@@ -343,32 +320,25 @@ void GameControllerXml::readConfig(QXmlStreamReader *xml)
if ((xml->name() == "buttonname") && xml->isStartElement()) if ((xml->name() == "buttonname") && xml->isStartElement())
{ {
readXmlNamesShort("buttonname", xml); readXmlNamesShort("buttonname", xml);
} } else if ((xml->name() == "triggerbuttonname") && xml->isStartElement())
else if ((xml->name() == "triggerbuttonname") && xml->isStartElement())
{ {
readXmlNamesLong("triggerbuttonname", xml); readXmlNamesLong("triggerbuttonname", xml);
} } else if ((xml->name() == "controlstickbuttonname") && xml->isStartElement())
else if ((xml->name() == "controlstickbuttonname") && xml->isStartElement())
{ {
readXmlNamesMiddle("controlstickbuttonname", xml); readXmlNamesMiddle("controlstickbuttonname", xml);
} } else if ((xml->name() == "dpadbuttonname") && xml->isStartElement())
else if ((xml->name() == "dpadbuttonname") && xml->isStartElement())
{ {
readXmlNamesMiddle("dpadbuttonname", xml); readXmlNamesMiddle("dpadbuttonname", xml);
} } else if ((xml->name() == "triggername") && xml->isStartElement())
else if ((xml->name() == "triggername") && xml->isStartElement())
{ {
readXmlNamesLong("triggername", xml); readXmlNamesLong("triggername", xml);
} } else if ((xml->name() == "controlstickname") && xml->isStartElement())
else if ((xml->name() == "controlstickname") && xml->isStartElement())
{ {
readXmlNamesShort("controlstickname", xml); readXmlNamesShort("controlstickname", xml);
} } else if ((xml->name() == "dpadname") && xml->isStartElement())
else if ((xml->name() == "dpadname") && xml->isStartElement())
{ {
readXmlNamesShort("dpadname", xml); readXmlNamesShort("dpadname", xml);
} } else
else
{ {
// If none of the above, skip the element // If none of the above, skip the element
xml->skipCurrentElement(); xml->skipCurrentElement();
@@ -376,8 +346,7 @@ void GameControllerXml::readConfig(QXmlStreamReader *xml)
xml->readNextStartElement(); xml->readNextStartElement();
} }
} } else if ((xml->name() == "keyPressTime") && xml->isStartElement())
else if ((xml->name() == "keyPressTime") && xml->isStartElement())
{ {
QString temptext = xml->readElementText(); QString temptext = xml->readElementText();
int tempchoice = temptext.toInt(); int tempchoice = temptext.toInt();
@@ -386,13 +355,11 @@ void GameControllerXml::readConfig(QXmlStreamReader *xml)
{ {
m_gameController->setDeviceKeyPressTime(tempchoice); m_gameController->setDeviceKeyPressTime(tempchoice);
} }
} } else if ((xml->name() == "profilename") && xml->isStartElement())
else if ((xml->name() == "profilename") && xml->isStartElement())
{ {
QString temptext = xml->readElementText(); QString temptext = xml->readElementText();
m_gameController->setProfileName(temptext); m_gameController->setProfileName(temptext);
} } else
else
{ {
// If none of the above, skip the element // If none of the above, skip the element
xml->skipCurrentElement(); xml->skipCurrentElement();
@@ -403,8 +370,7 @@ void GameControllerXml::readConfig(QXmlStreamReader *xml)
m_gameController->reInitButtons(); m_gameController->reInitButtons();
} } else if (xml->isStartElement() && (xml->name() == "joystick"))
else if (xml->isStartElement() && (xml->name() == "joystick"))
{ {
this->readJoystickConfig(xml); this->readJoystickConfig(xml);
} }
@@ -422,8 +388,8 @@ void GameControllerXml::writeConfig(QXmlStreamWriter *xml)
xml->writeTextElement("sdlname", m_gameController->getSDLName()); xml->writeTextElement("sdlname", m_gameController->getSDLName());
xml->writeComment("The Unique ID for a joystick is included for informational purposes only."); xml->writeComment("The Unique ID for a joystick is included for informational purposes only.");
xml->writeTextElement("uniqueID", m_gameController->getUniqueIDString()); xml->writeTextElement("uniqueID", m_gameController->getUniqueIDString());
// xml->writeComment("The GUID for a joystick is included for informational purposes only."); // xml->writeComment("The GUID for a joystick is included for informational purposes only.");
// xml->writeTextElement("guid", m_gameController->getGUIDString()); // xml->writeTextElement("guid", m_gameController->getGUIDString());
if (!m_gameController->getProfileName().isEmpty()) if (!m_gameController->getProfileName().isEmpty())
{ {
@@ -441,20 +407,21 @@ void GameControllerXml::writeConfig(QXmlStreamWriter *xml)
xml->writeEndElement(); // </names> xml->writeEndElement(); // </names>
if ((m_gameController->getDeviceKeyPressTime() > 0) && (m_gameController->getDeviceKeyPressTime() != GlobalVariables::InputDevice::DEFAULTKEYPRESSTIME)) if ((m_gameController->getDeviceKeyPressTime() > 0) &&
(m_gameController->getDeviceKeyPressTime() != GlobalVariables::InputDevice::DEFAULTKEYPRESSTIME))
{ {
xml->writeTextElement("keyPressTime", QString::number(m_gameController->getDeviceKeyPressTime())); xml->writeTextElement("keyPressTime", QString::number(m_gameController->getDeviceKeyPressTime()));
} }
xml->writeStartElement("sets"); xml->writeStartElement("sets");
QHashIterator<int, SetJoystick*> currHash(m_gameController->getJoystick_sets()); QHashIterator<int, SetJoystick *> currHash(m_gameController->getJoystick_sets());
while (currHash.hasNext()) { while (currHash.hasNext())
{
currHash.next(); currHash.next();
currHash.value()->writeConfig(xml); currHash.value()->writeConfig(xml);
} }
xml->writeEndElement(); xml->writeEndElement();
xml->writeEndElement(); xml->writeEndElement();
@@ -462,9 +429,10 @@ void GameControllerXml::writeConfig(QXmlStreamWriter *xml)
void GameControllerXml::writeXmlForButtons(SetJoystick *tempSet, QXmlStreamWriter *xml) void GameControllerXml::writeXmlForButtons(SetJoystick *tempSet, QXmlStreamWriter *xml)
{ {
QHashIterator<int, JoyButton*> currBtn(tempSet->getButtons()); QHashIterator<int, JoyButton *> currBtn(tempSet->getButtons());
while (currBtn.hasNext()) { while (currBtn.hasNext())
{
currBtn.next(); currBtn.next();
if ((currBtn.value() != nullptr) && !currBtn.value()->getButtonName().isEmpty()) if ((currBtn.value() != nullptr) && !currBtn.value()->getButtonName().isEmpty())
@@ -477,12 +445,12 @@ void GameControllerXml::writeXmlForButtons(SetJoystick *tempSet, QXmlStreamWrite
} }
} }
void GameControllerXml::writeXmlForAxes(SetJoystick *tempSet, QXmlStreamWriter *xml) void GameControllerXml::writeXmlForAxes(SetJoystick *tempSet, QXmlStreamWriter *xml)
{ {
QHashIterator<int, JoyAxis*> currAxis(*tempSet->getAxes()); QHashIterator<int, JoyAxis *> currAxis(*tempSet->getAxes());
while (currAxis.hasNext()) { while (currAxis.hasNext())
{
currAxis.next(); currAxis.next();
if (currAxis.value() != nullptr) if (currAxis.value() != nullptr)
@@ -497,12 +465,10 @@ void GameControllerXml::writeXmlForAxes(SetJoystick *tempSet, QXmlStreamWriter *
writeXmlAxBtn(currAxis.value(), currAxis.value()->getNAxisButton(), xml); writeXmlAxBtn(currAxis.value(), currAxis.value()->getNAxisButton(), xml);
writeXmlAxBtn(currAxis.value(), currAxis.value()->getPAxisButton(), xml); writeXmlAxBtn(currAxis.value(), currAxis.value()->getPAxisButton(), xml);
} }
} }
} }
void GameControllerXml::writeXmlAxBtn(JoyAxis *axis, JoyAxisButton *axisbutton, QXmlStreamWriter *xml) void GameControllerXml::writeXmlAxBtn(JoyAxis *axis, JoyAxisButton *axisbutton, QXmlStreamWriter *xml)
{ {
if (!axisbutton->getButtonName().isEmpty()) if (!axisbutton->getButtonName().isEmpty())
@@ -515,12 +481,12 @@ void GameControllerXml::writeXmlAxBtn(JoyAxis *axis, JoyAxisButton *axisbutton,
} }
} }
void GameControllerXml::writeXmlForSticks(SetJoystick *tempSet, QXmlStreamWriter *xml) void GameControllerXml::writeXmlForSticks(SetJoystick *tempSet, QXmlStreamWriter *xml)
{ {
QHashIterator<int, JoyControlStick*> currStick(tempSet->getSticks()); QHashIterator<int, JoyControlStick *> currStick(tempSet->getSticks());
while (currStick.hasNext()) { while (currStick.hasNext())
{
currStick.next(); currStick.next();
if (currStick.value() != nullptr) if (currStick.value() != nullptr)
@@ -533,8 +499,8 @@ void GameControllerXml::writeXmlForSticks(SetJoystick *tempSet, QXmlStreamWriter
xml->writeEndElement(); xml->writeEndElement();
} }
QHash<JoyControlStick::JoyStickDirections, JoyControlStickButton*> *buttons = currStick.value()->getButtons(); QHash<JoyControlStick::JoyStickDirections, JoyControlStickButton *> *buttons = currStick.value()->getButtons();
QHashIterator<JoyControlStick::JoyStickDirections, JoyControlStickButton*> iter(*buttons); QHashIterator<JoyControlStick::JoyStickDirections, JoyControlStickButton *> iter(*buttons);
while (iter.hasNext()) while (iter.hasNext())
{ {
@@ -553,12 +519,12 @@ void GameControllerXml::writeXmlForSticks(SetJoystick *tempSet, QXmlStreamWriter
} }
} }
void GameControllerXml::writeXmlForVDpad(QXmlStreamWriter *xml) void GameControllerXml::writeXmlForVDpad(QXmlStreamWriter *xml)
{ {
QHashIterator<int, VDPad*> currVDPad(m_gameController->getActiveSetJoystick()->getVdpads()); QHashIterator<int, VDPad *> currVDPad(m_gameController->getActiveSetJoystick()->getVdpads());
while (currVDPad.hasNext()) { while (currVDPad.hasNext())
{
currVDPad.next(); currVDPad.next();
if (currVDPad.value() != nullptr) if (currVDPad.value() != nullptr)
@@ -571,8 +537,8 @@ void GameControllerXml::writeXmlForVDpad(QXmlStreamWriter *xml)
xml->writeEndElement(); xml->writeEndElement();
} }
QHash<int, JoyDPadButton*> *temp = currVDPad.value()->getButtons(); QHash<int, JoyDPadButton *> *temp = currVDPad.value()->getButtons();
QHashIterator<int, JoyDPadButton*> iter(*temp); QHashIterator<int, JoyDPadButton *> iter(*temp);
while (iter.hasNext()) while (iter.hasNext())
{ {
@@ -600,13 +566,15 @@ void GameControllerXml::readXmlNamesShort(QString name, QXmlStreamReader *xml)
if ((index >= 0) && !temp.isEmpty()) if ((index >= 0) && !temp.isEmpty())
{ {
if (name == "buttonname") m_gameController->setButtonName(index, temp); if (name == "buttonname")
else if (name == "controlstickname") m_gameController->setStickName(index, temp); m_gameController->setButtonName(index, temp);
else if (name == "dpadname") m_gameController->setVDPadName(index, temp); else if (name == "controlstickname")
m_gameController->setStickName(index, temp);
else if (name == "dpadname")
m_gameController->setVDPadName(index, temp);
} }
} }
void GameControllerXml::readXmlNamesMiddle(QString name, QXmlStreamReader *xml) void GameControllerXml::readXmlNamesMiddle(QString name, QXmlStreamReader *xml)
{ {
int index = -1; int index = -1;
@@ -615,25 +583,24 @@ void GameControllerXml::readXmlNamesMiddle(QString name, QXmlStreamReader *xml)
assignVariables(xml, index, buttonIndex, temp, false); assignVariables(xml, index, buttonIndex, temp, false);
if ((name == "dpadbuttonname") && (index >= 0) && !temp.isEmpty()) m_gameController->setVDPadButtonName(index, buttonIndex, temp); if ((name == "dpadbuttonname") && (index >= 0) && !temp.isEmpty())
else if ((name == "controlstickbuttonname") && (index >= 0) && !temp.isEmpty()) m_gameController->setStickButtonName(index, buttonIndex, temp); m_gameController->setVDPadButtonName(index, buttonIndex, temp);
else if ((name == "controlstickbuttonname") && (index >= 0) && !temp.isEmpty())
m_gameController->setStickButtonName(index, buttonIndex, temp);
} }
void GameControllerXml::readXmlNamesLong(QString name, QXmlStreamReader *xml) void GameControllerXml::readXmlNamesLong(QString name, QXmlStreamReader *xml)
{ {
int index = xml->attributes().value("index").toString().toInt(); int index = xml->attributes().value("index").toString().toInt();
QString temp = xml->readElementText(); QString temp = xml->readElementText();
index = (index - 1) + SDL_CONTROLLER_AXIS_TRIGGERLEFT; index = (index - 1) + SDL_CONTROLLER_AXIS_TRIGGERLEFT;
if ((index == SDL_CONTROLLER_AXIS_TRIGGERLEFT || if ((index == SDL_CONTROLLER_AXIS_TRIGGERLEFT || index == SDL_CONTROLLER_AXIS_TRIGGERRIGHT) && !temp.isEmpty())
index == SDL_CONTROLLER_AXIS_TRIGGERRIGHT) && !temp.isEmpty())
{ {
if (name == "triggername") if (name == "triggername")
{ {
m_gameController->setAxisName(index, temp); m_gameController->setAxisName(index, temp);
} } else if (name == "triggerbuttonname")
else if (name == "triggerbuttonname")
{ {
int buttonIndex = xml->attributes().value("button").toString().toInt(); int buttonIndex = xml->attributes().value("button").toString().toInt();
buttonIndex = buttonIndex - 1; buttonIndex = buttonIndex - 1;
@@ -642,7 +609,8 @@ void GameControllerXml::readXmlNamesLong(QString name, QXmlStreamReader *xml)
} }
} }
void GameControllerXml::readJoystickConfigXmlLong(QList<SDL_GameControllerButtonBind>& hatButtons, bool& dpadNameExists, bool& vdpadNameExists, QXmlStreamReader *xml) void GameControllerXml::readJoystickConfigXmlLong(QList<SDL_GameControllerButtonBind> &hatButtons, bool &dpadNameExists,
bool &vdpadNameExists, QXmlStreamReader *xml)
{ {
int index = -1; int index = -1;
bool first = false; bool first = false;
@@ -651,13 +619,11 @@ void GameControllerXml::readJoystickConfigXmlLong(QList<SDL_GameControllerButton
assignVariablesShort(xml, index, temp); assignVariablesShort(xml, index, temp);
if (xml->name() == "vdpadname") if (xml->name() == "vdpadname")
{ {
first = dpadNameExists; first = dpadNameExists;
second = vdpadNameExists; second = vdpadNameExists;
} } else if (xml->name() == "dpadname")
else if (xml->name() == "dpadname")
{ {
first = vdpadNameExists; first = vdpadNameExists;
second = dpadNameExists; second = dpadNameExists;
@@ -694,18 +660,19 @@ void GameControllerXml::readJoystickConfigXmlLong(QList<SDL_GameControllerButton
} }
} }
inline void GameControllerXml::assignVariables(QXmlStreamReader *xml, int& index, int& buttonIndex, QString& temp, bool buttonDecreased) inline void GameControllerXml::assignVariables(QXmlStreamReader *xml, int &index, int &buttonIndex, QString &temp,
bool buttonDecreased)
{ {
index = xml->attributes().value("index").toString().toInt(); index = xml->attributes().value("index").toString().toInt();
buttonIndex = xml->attributes().value("button").toString().toInt(); buttonIndex = xml->attributes().value("button").toString().toInt();
temp = xml->readElementText(); temp = xml->readElementText();
index = index - 1; index = index - 1;
if (buttonDecreased) buttonIndex = buttonIndex - 1; if (buttonDecreased)
buttonIndex = buttonIndex - 1;
} }
inline void GameControllerXml::assignVariablesShort(QXmlStreamReader *xml, int &index, QString &temp)
inline void GameControllerXml::assignVariablesShort(QXmlStreamReader *xml, int& index, QString& temp)
{ {
index = xml->attributes().value("index").toString().toInt(); index = xml->attributes().value("index").toString().toInt();
temp = xml->readElementText(); temp = xml->readElementText();

View File

@@ -15,7 +15,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef GAMECONTROLLERXML_H #ifndef GAMECONTROLLERXML_H
#define GAMECONTROLLERXML_H #define GAMECONTROLLERXML_H
@@ -28,38 +27,37 @@ class QXmlStreamWriter;
class JoyAxisButton; class JoyAxisButton;
class JoyAxis; class JoyAxis;
class GameControllerXml : public InputDeviceXml class GameControllerXml : public InputDeviceXml
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit GameControllerXml(GameController* gameController, QObject *parent = nullptr); explicit GameControllerXml(GameController *gameController, QObject *parent = nullptr);
protected: protected:
void readJoystickConfig(QXmlStreamReader *xml); // GameControllerXml class void readJoystickConfig(QXmlStreamReader *xml); // GameControllerXml class
public slots: public slots:
virtual void readConfig(QXmlStreamReader *xml) override; // GameControllerXml class virtual void readConfig(QXmlStreamReader *xml) override; // GameControllerXml class
virtual void writeConfig(QXmlStreamWriter *xml) override; // GameControllerXml class virtual void writeConfig(QXmlStreamWriter *xml) override; // GameControllerXml class
private: private:
GameController *m_gameController;
GameController* m_gameController; void writeXmlForButtons(SetJoystick *tempSet, QXmlStreamWriter *xml); // GameControllerXml class
void writeXmlForAxes(SetJoystick *tempSet, QXmlStreamWriter *xml); // GameControllerXml class
void writeXmlForButtons(SetJoystick *tempSet, QXmlStreamWriter *xml); // GameControllerXml class
void writeXmlForAxes(SetJoystick *tempSet, QXmlStreamWriter *xml); // GameControllerXml class
void writeXmlAxBtn(JoyAxis *axis, JoyAxisButton *naxisbutton, QXmlStreamWriter *xml); // GameControllerXml class void writeXmlAxBtn(JoyAxis *axis, JoyAxisButton *naxisbutton, QXmlStreamWriter *xml); // GameControllerXml class
void writeXmlForSticks(SetJoystick *tempSet, QXmlStreamWriter *xml); // GameControllerXml class void writeXmlForSticks(SetJoystick *tempSet, QXmlStreamWriter *xml); // GameControllerXml class
void writeXmlForVDpad(QXmlStreamWriter *xml); // GameControllerXml class void writeXmlForVDpad(QXmlStreamWriter *xml); // GameControllerXml class
void readXmlNamesShort(QString name, QXmlStreamReader *xml); // GameControllerXml class void readXmlNamesShort(QString name, QXmlStreamReader *xml); // GameControllerXml class
void readXmlNamesMiddle(QString name, QXmlStreamReader *xml); // GameControllerXml class void readXmlNamesMiddle(QString name, QXmlStreamReader *xml); // GameControllerXml class
void readXmlNamesLong(QString name, QXmlStreamReader *xml); // GameControllerXml class void readXmlNamesLong(QString name, QXmlStreamReader *xml); // GameControllerXml class
void readJoystickConfigXmlLong(QList<SDL_GameControllerButtonBind>& hatButtons, bool& dpadNameExists, bool& vdpadNameExists, QXmlStreamReader *xml); // GameControllerXml class void readJoystickConfigXmlLong(QList<SDL_GameControllerButtonBind> &hatButtons, bool &dpadNameExists,
bool &vdpadNameExists, QXmlStreamReader *xml); // GameControllerXml class
inline void assignVariables(QXmlStreamReader *xml, int& index, int& buttonIndex, QString& temp, bool buttonDecreased); // GameControllerXml class
inline void assignVariablesShort(QXmlStreamReader *xml, int& index, QString& temp); // GameControllerXml class
inline void assignVariables(QXmlStreamReader *xml, int &index, int &buttonIndex, QString &temp,
bool buttonDecreased); // GameControllerXml class
inline void assignVariablesShort(QXmlStreamReader *xml, int &index, QString &temp); // GameControllerXml class
}; };
#endif // GAMECONTROLLERXML_H #endif // GAMECONTROLLERXML_H

View File

@@ -20,48 +20,48 @@
#include "messagehandler.h" #include "messagehandler.h"
#include <QDebug>
#include <QPaintEvent>
#include <QPainter> #include <QPainter>
#include <QPixmap> #include <QPixmap>
#include <QTransform> #include <QTransform>
#include <QPaintEvent>
#include <QDebug>
struct ButtonImagePlacement
struct ButtonImagePlacement { {
int x; int x;
int y; int y;
GameControllerExample::ButtonType buttontype; GameControllerExample::ButtonType buttontype;
}; };
static ButtonImagePlacement buttonLocations[] = { static ButtonImagePlacement buttonLocations[] = {
{225, 98, GameControllerExample::Button}, // SDL_CONTROLLER_BUTTON_A {225, 98, GameControllerExample::Button}, // SDL_CONTROLLER_BUTTON_A
{252, 77, GameControllerExample::Button}, // SDL_CONTROLLER_BUTTON_B {252, 77, GameControllerExample::Button}, // SDL_CONTROLLER_BUTTON_B
{200, 77, GameControllerExample::Button}, // SDL_CONTROLLER_BUTTON_X {200, 77, GameControllerExample::Button}, // SDL_CONTROLLER_BUTTON_X
{227, 59, GameControllerExample::Button}, // SDL_CONTROLLER_BUTTON_Y {227, 59, GameControllerExample::Button}, // SDL_CONTROLLER_BUTTON_Y
{102, 77, GameControllerExample::Button}, // SDL_CONTROLLER_BUTTON_BACK {102, 77, GameControllerExample::Button}, // SDL_CONTROLLER_BUTTON_BACK
{169, 77, GameControllerExample::Button}, // SDL_CONTROLLER_BUTTON_START {169, 77, GameControllerExample::Button}, // SDL_CONTROLLER_BUTTON_START
{137, 77, GameControllerExample::Button}, // SDL_CONTROLLER_BUTTON_GUIDE {137, 77, GameControllerExample::Button}, // SDL_CONTROLLER_BUTTON_GUIDE
{45, 23, GameControllerExample::Button}, // SDL_CONTROLLER_BUTTON_LEFTSHOULDER {45, 23, GameControllerExample::Button}, // SDL_CONTROLLER_BUTTON_LEFTSHOULDER
{232, 21, GameControllerExample::Button}, // SDL_CONTROLLER_BUTTON_RIGHTSHOULDER {232, 21, GameControllerExample::Button}, // SDL_CONTROLLER_BUTTON_RIGHTSHOULDER
{44, 90, GameControllerExample::Button}, // SDL_CONTROLLER_BUTTON_LEFTSTICK {44, 90, GameControllerExample::Button}, // SDL_CONTROLLER_BUTTON_LEFTSTICK
{179, 135, GameControllerExample::Button}, // SDL_CONTROLLER_BUTTON_RIGHTSTICK {179, 135, GameControllerExample::Button}, // SDL_CONTROLLER_BUTTON_RIGHTSTICK
{44, 90, GameControllerExample::AxisX}, // SDL_CONTROLLER_AXIS_LEFTX {44, 90, GameControllerExample::AxisX}, // SDL_CONTROLLER_AXIS_LEFTX
{44, 90, GameControllerExample::AxisY}, // SDL_CONTROLLER_AXIS_LEFTY {44, 90, GameControllerExample::AxisY}, // SDL_CONTROLLER_AXIS_LEFTY
{179, 135, GameControllerExample::AxisX}, // SDL_CONTROLLER_AXIS_RIGHTX {179, 135, GameControllerExample::AxisX}, // SDL_CONTROLLER_AXIS_RIGHTX
{179, 135, GameControllerExample::AxisY}, // SDL_CONTROLLER_AXIS_RIGHTY {179, 135, GameControllerExample::AxisY}, // SDL_CONTROLLER_AXIS_RIGHTY
{53, 0, GameControllerExample::Button}, // SDL_CONTROLLER_AXIS_TRIGGERLEFT {53, 0, GameControllerExample::Button}, // SDL_CONTROLLER_AXIS_TRIGGERLEFT
{220, 0, GameControllerExample::Button}, // SDL_CONTROLLER_AXIS_TRIGGERRIGHT {220, 0, GameControllerExample::Button}, // SDL_CONTROLLER_AXIS_TRIGGERRIGHT
{90, 110, GameControllerExample::Button}, // SDL_CONTROLLER_BUTTON_DPAD_UP {90, 110, GameControllerExample::Button}, // SDL_CONTROLLER_BUTTON_DPAD_UP
{68, 127, GameControllerExample::Button}, // SDL_CONTROLLER_BUTTON_DPAD_DOWN {68, 127, GameControllerExample::Button}, // SDL_CONTROLLER_BUTTON_DPAD_DOWN
{90, 146, GameControllerExample::Button}, // SDL_CONTROLLER_BUTTON_DPAD_LEFT {90, 146, GameControllerExample::Button}, // SDL_CONTROLLER_BUTTON_DPAD_LEFT
{109, 127, GameControllerExample::Button}, // SDL_CONTROLLER_BUTTON_DPAD_RIGHT {109, 127, GameControllerExample::Button}, // SDL_CONTROLLER_BUTTON_DPAD_RIGHT
}; };
GameControllerExample::GameControllerExample(QWidget *parent) : GameControllerExample::GameControllerExample(QWidget *parent)
QWidget(parent) : QWidget(parent)
{ {
qInstallMessageHandler(MessageHandler::myMessageOutput); qInstallMessageHandler(MessageHandler::myMessageOutput);
@@ -89,7 +89,7 @@ void GameControllerExample::paintEvent(QPaintEvent *event)
paint.setOpacity(0.85); paint.setOpacity(0.85);
switch(current.buttontype) switch (current.buttontype)
{ {
case Button: case Button:
@@ -103,7 +103,6 @@ void GameControllerExample::paintEvent(QPaintEvent *event)
case AxisY: case AxisY:
paint.drawImage(QRect(current.x, current.y, rotatedaxisimage.width(), rotatedaxisimage.height()), rotatedaxisimage); paint.drawImage(QRect(current.x, current.y, rotatedaxisimage.width(), rotatedaxisimage.height()), rotatedaxisimage);
break; break;
} }
paint.setOpacity(1.0); paint.setOpacity(1.0);

View File

@@ -16,39 +16,40 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef GAMECONTROLLEREXAMPLE_H #ifndef GAMECONTROLLEREXAMPLE_H
#define GAMECONTROLLEREXAMPLE_H #define GAMECONTROLLEREXAMPLE_H
#include <QWidget>
#include <QImage> #include <QImage>
#include <QWidget>
class QPaintEvent; class QPaintEvent;
class GameControllerExample : public QWidget class GameControllerExample : public QWidget
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit GameControllerExample(QWidget *parent = nullptr); explicit GameControllerExample(QWidget *parent = nullptr);
enum ButtonType { enum ButtonType
Button, AxisX, AxisY, {
Button,
AxisX,
AxisY,
}; };
static const int MAXBUTTONINDEX = 20; static const int MAXBUTTONINDEX = 20;
protected: protected:
virtual void paintEvent(QPaintEvent *event); virtual void paintEvent(QPaintEvent *event);
signals: signals:
void indexUpdated(int index); void indexUpdated(int index);
public slots: public slots:
void setActiveButton(int button); void setActiveButton(int button);
private: private:
QImage controllerimage; QImage controllerimage;
QImage buttonimage; QImage buttonimage;
QImage axisimage; QImage axisimage;

View File

@@ -19,25 +19,24 @@
#include "gamecontrollermappingdialog.h" #include "gamecontrollermappingdialog.h"
#include "ui_gamecontrollermappingdialog.h" #include "ui_gamecontrollermappingdialog.h"
#include "messagehandler.h"
#include "inputdevice.h"
#include "antimicrosettings.h" #include "antimicrosettings.h"
#include "common.h" #include "common.h"
#include "inputdevice.h"
#include "messagehandler.h"
#include <QAbstractButton>
#include <QAbstractItemModel>
#include <QDebug> #include <QDebug>
#include <QList> #include <QList>
#include <QListIterator> #include <QListIterator>
#include <QTableWidgetItem>
#include <QAbstractItemModel>
#include <QModelIndexList>
#include <QVariant>
#include <QStringList>
#include <QMessageBox> #include <QMessageBox>
#include <QModelIndexList>
#include <QStringList>
#include <QTableWidgetItem>
#include <QTextStream> #include <QTextStream>
#include <QAbstractButton> #include <QVariant>
#include <QWidget> #include <QWidget>
static QHash<int, QString> initAliases() static QHash<int, QString> initAliases()
{ {
qInstallMessageHandler(MessageHandler::myMessageOutput); qInstallMessageHandler(MessageHandler::myMessageOutput);
@@ -109,12 +108,10 @@ QHash<int, QString> GameControllerMappingDialog::tempaliases = initAliases();
QHash<SDL_GameControllerButton, int> GameControllerMappingDialog::buttonPlacement = initButtonPlacement(); QHash<SDL_GameControllerButton, int> GameControllerMappingDialog::buttonPlacement = initButtonPlacement();
QHash<SDL_GameControllerAxis, int> GameControllerMappingDialog::axisPlacement = initAxisPlacement(); QHash<SDL_GameControllerAxis, int> GameControllerMappingDialog::axisPlacement = initAxisPlacement();
GameControllerMappingDialog::GameControllerMappingDialog(InputDevice *device, GameControllerMappingDialog::GameControllerMappingDialog(InputDevice *device, AntiMicroSettings *settings, QWidget *parent)
AntiMicroSettings *settings, : QDialog(parent)
QWidget *parent) : , ui(new Ui::GameControllerMappingDialog)
QDialog(parent), , helper(device)
ui(new Ui::GameControllerMappingDialog),
helper(device)
{ {
ui->setupUi(this); ui->setupUi(this);
@@ -134,7 +131,7 @@ GameControllerMappingDialog::GameControllerMappingDialog(InputDevice *device,
QMetaObject::invokeMethod(device, "haltServices"); QMetaObject::invokeMethod(device, "haltServices");
QMetaObject::invokeMethod(&helper, "setupDeadZones", Qt::BlockingQueuedConnection); QMetaObject::invokeMethod(&helper, "setupDeadZones", Qt::BlockingQueuedConnection);
GameController *controller = qobject_cast<GameController*>(device); GameController *controller = qobject_cast<GameController *>(device);
if (controller != nullptr) if (controller != nullptr)
{ {
@@ -143,8 +140,8 @@ GameControllerMappingDialog::GameControllerMappingDialog(InputDevice *device,
ui->mappingStringPlainTextEdit->document()->setPlainText(generateSDLMappingString()); ui->mappingStringPlainTextEdit->document()->setPlainText(generateSDLMappingString());
} }
QString tempWindowTitle = QString(tr("Game Controller Mapping (%1) (#%2)")).arg(device->getSDLName()) QString tempWindowTitle =
.arg(device->getRealJoyNumber()); QString(tr("Game Controller Mapping (%1) (#%2)")).arg(device->getSDLName()).arg(device->getRealJoyNumber());
setWindowTitle(tempWindowTitle); setWindowTitle(tempWindowTitle);
enableDeviceConnections(); enableDeviceConnections();
@@ -156,13 +153,16 @@ GameControllerMappingDialog::GameControllerMappingDialog(InputDevice *device,
currentDeadZoneValue = 20000; currentDeadZoneValue = 20000;
int index = ui->axisDeadZoneComboBox->findData(currentDeadZoneValue); int index = ui->axisDeadZoneComboBox->findData(currentDeadZoneValue);
if (index != -1) ui->axisDeadZoneComboBox->setCurrentIndex(index); if (index != -1)
ui->axisDeadZoneComboBox->setCurrentIndex(index);
connect(device, &InputDevice::destroyed, this, &GameControllerMappingDialog::obliterate); connect(device, &InputDevice::destroyed, this, &GameControllerMappingDialog::obliterate);
connect(ui->buttonBox, &QDialogButtonBox::accepted, this, &GameControllerMappingDialog::saveChanges); connect(ui->buttonBox, &QDialogButtonBox::accepted, this, &GameControllerMappingDialog::saveChanges);
connect(ui->buttonBox, &QDialogButtonBox::clicked, this, &GameControllerMappingDialog::discardMapping); connect(ui->buttonBox, &QDialogButtonBox::clicked, this, &GameControllerMappingDialog::discardMapping);
connect(ui->buttonMappingTableWidget, &QTableWidget::itemSelectionChanged, this, &GameControllerMappingDialog::changeButtonDisplay); connect(ui->buttonMappingTableWidget, &QTableWidget::itemSelectionChanged, this,
connect(ui->axisDeadZoneComboBox, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this, &GameControllerMappingDialog::changeAxisDeadZone); &GameControllerMappingDialog::changeButtonDisplay);
connect(ui->axisDeadZoneComboBox, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this,
&GameControllerMappingDialog::changeAxisDeadZone);
connect(this, &GameControllerMappingDialog::finished, this, &GameControllerMappingDialog::enableButtonEvents); connect(this, &GameControllerMappingDialog::finished, this, &GameControllerMappingDialog::enableButtonEvents);
PadderCommon::unlockInputDevices(); PadderCommon::unlockInputDevices();
@@ -183,13 +183,13 @@ void GameControllerMappingDialog::buttonAssign(int buttonindex)
if (ui->buttonMappingTableWidget->currentRow() > -1) if (ui->buttonMappingTableWidget->currentRow() > -1)
{ {
QTableWidgetItem* item = ui->buttonMappingTableWidget->currentItem(); QTableWidgetItem *item = ui->buttonMappingTableWidget->currentItem();
int column = ui->buttonMappingTableWidget->currentColumn(); int column = ui->buttonMappingTableWidget->currentColumn();
int row = ui->buttonMappingTableWidget->currentRow(); int row = ui->buttonMappingTableWidget->currentRow();
if (item == nullptr) if (item == nullptr)
{ {
item = new QTableWidgetItem(QString("Button %1").arg(buttonindex+1)); item = new QTableWidgetItem(QString("Button %1").arg(buttonindex + 1));
ui->buttonMappingTableWidget->setItem(row, column, item); ui->buttonMappingTableWidget->setItem(row, column, item);
} }
@@ -197,9 +197,10 @@ void GameControllerMappingDialog::buttonAssign(int buttonindex)
templist.append(QVariant(0)); templist.append(QVariant(0));
templist.append(QVariant(buttonindex)); templist.append(QVariant(buttonindex));
QAbstractItemModel *model = ui->buttonMappingTableWidget->model(); QAbstractItemModel *model = ui->buttonMappingTableWidget->model();
QModelIndexList matchlist = model->match(model->index(0,0), Qt::UserRole, templist, 1, Qt::MatchExactly); QModelIndexList matchlist = model->match(model->index(0, 0), Qt::UserRole, templist, 1, Qt::MatchExactly);
foreach (const QModelIndex &index, matchlist) { foreach (const QModelIndex &index, matchlist)
{
QTableWidgetItem *existingItem = ui->buttonMappingTableWidget->item(index.row(), index.column()); QTableWidgetItem *existingItem = ui->buttonMappingTableWidget->item(index.row(), index.column());
if (existingItem != nullptr) if (existingItem != nullptr)
@@ -214,7 +215,7 @@ void GameControllerMappingDialog::buttonAssign(int buttonindex)
tempvalue.append(QVariant(buttonindex)); tempvalue.append(QVariant(buttonindex));
item->setData(Qt::UserRole, tempvalue); item->setData(Qt::UserRole, tempvalue);
item->setText(QString("Button %1").arg(buttonindex+1)); item->setText(QString("Button %1").arg(buttonindex + 1));
if (row < (ui->buttonMappingTableWidget->rowCount() - 1)) if (row < (ui->buttonMappingTableWidget->rowCount() - 1))
ui->buttonMappingTableWidget->setCurrentCell(row + 1, column); ui->buttonMappingTableWidget->setCurrentCell(row + 1, column);
@@ -237,54 +238,54 @@ void GameControllerMappingDialog::axisAssign(int axis, int value)
if (!skip && (ui->buttonMappingTableWidget->currentRow() > -1)) if (!skip && (ui->buttonMappingTableWidget->currentRow() > -1))
{ {
QTableWidgetItem* item = ui->buttonMappingTableWidget->currentItem(); QTableWidgetItem *item = ui->buttonMappingTableWidget->currentItem();
int column = ui->buttonMappingTableWidget->currentColumn(); int column = ui->buttonMappingTableWidget->currentColumn();
int row = ui->buttonMappingTableWidget->currentRow(); int row = ui->buttonMappingTableWidget->currentRow();
if (usingGameController && (value > currentDeadZoneValue) && !getEventTriggerAxesLocal().contains(axis)) if (usingGameController && (value > currentDeadZoneValue) && !getEventTriggerAxesLocal().contains(axis))
{ {
getEventTriggerAxesLocal().append(axis); getEventTriggerAxesLocal().append(axis);
} } else if (usingGameController && (value < currentDeadZoneValue))
else if (usingGameController && (value < currentDeadZoneValue))
{ {
skip = true; skip = true;
} }
if (!skip) if (!skip)
{ {
if (item == nullptr) if (item == nullptr)
{
item = new QTableWidgetItem(QString("Axis %1").arg(axis + 1));
ui->buttonMappingTableWidget->setItem(row, column, item);
}
QList<QVariant> templist;
templist.append(QVariant(axis + 1));
templist.append(QVariant(0));
QAbstractItemModel *model = ui->buttonMappingTableWidget->model();
QModelIndexList matchlist = model->match(model->index(0, 0), Qt::UserRole, templist, 1, Qt::MatchExactly);
foreach (const QModelIndex &index, matchlist)
{
QTableWidgetItem *existingItem = ui->buttonMappingTableWidget->item(index.row(), index.column());
if (existingItem != nullptr)
{ {
item = new QTableWidgetItem(QString("Axis %1").arg(axis+1)); existingItem->setText("");
ui->buttonMappingTableWidget->setItem(row, column, item); existingItem->setData(Qt::UserRole, QVariant());
} }
}
QList<QVariant> templist; QList<QVariant> tempvalue;
templist.append(QVariant(axis+1)); tempvalue.append(QVariant(axis + 1));
templist.append(QVariant(0)); tempvalue.append(QVariant(0));
QAbstractItemModel *model = ui->buttonMappingTableWidget->model();
QModelIndexList matchlist = model->match(model->index(0,0), Qt::UserRole, templist, 1, Qt::MatchExactly);
foreach (const QModelIndex &index, matchlist) { item->setData(Qt::UserRole, tempvalue);
QTableWidgetItem *existingItem = ui->buttonMappingTableWidget->item(index.row(), index.column()); item->setText(QString("Axis %1").arg(axis + 1));
if (existingItem != nullptr) if (row < (ui->buttonMappingTableWidget->rowCount() - 1))
{ ui->buttonMappingTableWidget->setCurrentCell(row + 1, column);
existingItem->setText("");
existingItem->setData(Qt::UserRole, QVariant());
}
}
QList<QVariant> tempvalue; ui->mappingStringPlainTextEdit->document()->setPlainText(generateSDLMappingString());
tempvalue.append(QVariant(axis+1));
tempvalue.append(QVariant(0));
item->setData(Qt::UserRole, tempvalue);
item->setText(QString("Axis %1").arg(axis+1));
if (row < (ui->buttonMappingTableWidget->rowCount()-1))
ui->buttonMappingTableWidget->setCurrentCell(row+1, column);
ui->mappingStringPlainTextEdit->document()->setPlainText(generateSDLMappingString());
} }
} }
} }
@@ -295,43 +296,44 @@ void GameControllerMappingDialog::dpadAssign(int dpad, int buttonindex)
if (ui->buttonMappingTableWidget->currentRow() > -1) if (ui->buttonMappingTableWidget->currentRow() > -1)
{ {
QTableWidgetItem* item = ui->buttonMappingTableWidget->currentItem(); QTableWidgetItem *item = ui->buttonMappingTableWidget->currentItem();
int column = ui->buttonMappingTableWidget->currentColumn(); int column = ui->buttonMappingTableWidget->currentColumn();
int row = ui->buttonMappingTableWidget->currentRow(); int row = ui->buttonMappingTableWidget->currentRow();
if (item == nullptr) if (item == nullptr)
{ {
item = new QTableWidgetItem(QString("Hat %1.%2").arg(dpad+1).arg(buttonindex)); item = new QTableWidgetItem(QString("Hat %1.%2").arg(dpad + 1).arg(buttonindex));
ui->buttonMappingTableWidget->setItem(row, column, item); ui->buttonMappingTableWidget->setItem(row, column, item);
} }
QList<QVariant> templist; QList<QVariant> templist;
templist.append(QVariant(-dpad-1)); templist.append(QVariant(-dpad - 1));
templist.append(QVariant(buttonindex)); templist.append(QVariant(buttonindex));
QAbstractItemModel *model = ui->buttonMappingTableWidget->model(); QAbstractItemModel *model = ui->buttonMappingTableWidget->model();
QModelIndexList matchlist = model->match(model->index(0,0), Qt::UserRole, templist, 1, Qt::MatchExactly); QModelIndexList matchlist = model->match(model->index(0, 0), Qt::UserRole, templist, 1, Qt::MatchExactly);
foreach (const QModelIndex &index, matchlist) { foreach (const QModelIndex &index, matchlist)
QTableWidgetItem *existingItem = ui->buttonMappingTableWidget->item(index.row(), index.column()); {
QTableWidgetItem *existingItem = ui->buttonMappingTableWidget->item(index.row(), index.column());
if (existingItem != nullptr) if (existingItem != nullptr)
{ {
existingItem->setText(""); existingItem->setText("");
existingItem->setData(Qt::UserRole, QVariant()); existingItem->setData(Qt::UserRole, QVariant());
} }
} }
QList<QVariant> tempvalue; QList<QVariant> tempvalue;
tempvalue.append(QVariant(-dpad-1)); tempvalue.append(QVariant(-dpad - 1));
tempvalue.append(QVariant(buttonindex)); tempvalue.append(QVariant(buttonindex));
item->setData(Qt::UserRole, tempvalue); item->setData(Qt::UserRole, tempvalue);
item->setText(QString("Hat %1.%2").arg(dpad+1).arg(buttonindex)); item->setText(QString("Hat %1.%2").arg(dpad + 1).arg(buttonindex));
if (row < (ui->buttonMappingTableWidget->rowCount() - 1)) if (row < (ui->buttonMappingTableWidget->rowCount() - 1))
ui->buttonMappingTableWidget->setCurrentCell(row + 1, column); ui->buttonMappingTableWidget->setCurrentCell(row + 1, column);
ui->mappingStringPlainTextEdit->document()->setPlainText(generateSDLMappingString()); ui->mappingStringPlainTextEdit->document()->setPlainText(generateSDLMappingString());
} }
} }
@@ -342,11 +344,13 @@ void GameControllerMappingDialog::saveChanges()
QString mappingString = generateSDLMappingString(); QString mappingString = generateSDLMappingString();
settings->getLock()->lock(); settings->getLock()->lock();
// settings->setValue(QString("Mappings/").append(device->getGUIDString()), mappingString); // settings->setValue(QString("Mappings/").append(device->getGUIDString()), mappingString);
// settings->setValue(QString("Mappings/%1%2").arg(device->getGUIDString()).arg("Disable"), "0"); // settings->setValue(QString("Mappings/%1%2").arg(device->getGUIDString()).arg("Disable"), "0");
device->convertToUniqueMappSett(settings, QString("Mappings/").append(device->getGUIDString()), QString("Mappings/").append(device->getUniqueIDString())); device->convertToUniqueMappSett(settings, QString("Mappings/").append(device->getGUIDString()),
device->convertToUniqueMappSett(settings, QString("Mappings/%1%2").arg(device->getGUIDString()).arg("Disable"), QString("Mappings/%1%2").arg(device->getUniqueIDString()).arg("Disable")); QString("Mappings/").append(device->getUniqueIDString()));
device->convertToUniqueMappSett(settings, QString("Mappings/%1%2").arg(device->getGUIDString()).arg("Disable"),
QString("Mappings/%1%2").arg(device->getUniqueIDString()).arg("Disable"));
settings->setValue(QString("Mappings/").append(device->getUniqueIDString()), mappingString); settings->setValue(QString("Mappings/").append(device->getUniqueIDString()), mappingString);
settings->setValue(QString("Mappings/%1%2").arg(device->getUniqueIDString()).arg("Disable"), "0"); settings->setValue(QString("Mappings/%1%2").arg(device->getUniqueIDString()).arg("Disable"), "0");
@@ -383,17 +387,15 @@ void GameControllerMappingDialog::populateGameControllerBindings(GameController
if (!temptext.isEmpty()) if (!temptext.isEmpty())
{ {
QList<QVariant> tempvariant = bindingValues(bind); QList<QVariant> tempvariant = bindingValues(bind);
QTableWidgetItem* item = new QTableWidgetItem(); QTableWidgetItem *item = new QTableWidgetItem();
ui->buttonMappingTableWidget->setItem(associatedRow, 0, item); ui->buttonMappingTableWidget->setItem(associatedRow, 0, item);
item->setText(temptext); item->setText(temptext);
item->setData(Qt::UserRole, tempvariant); item->setData(Qt::UserRole, tempvariant);
} }
} }
qDebug() << "Controller has " << controller->getNumberAxes() << " axes"; qDebug() << "Controller has " << controller->getNumberAxes() << " axes";
for (int i = 0; i < controller->getNumberAxes(); i++) for (int i = 0; i < controller->getNumberAxes(); i++)
{ {
int associatedRow = axisPlacement.value(static_cast<SDL_GameControllerAxis>(i)); int associatedRow = axisPlacement.value(static_cast<SDL_GameControllerAxis>(i));
@@ -405,7 +407,7 @@ void GameControllerMappingDialog::populateGameControllerBindings(GameController
if (!temptext.isEmpty()) if (!temptext.isEmpty())
{ {
QList<QVariant> tempvariant = bindingValues(bind); QList<QVariant> tempvariant = bindingValues(bind);
QTableWidgetItem* item = new QTableWidgetItem(); QTableWidgetItem *item = new QTableWidgetItem();
ui->buttonMappingTableWidget->setItem(associatedRow, 0, item); ui->buttonMappingTableWidget->setItem(associatedRow, 0, item);
item->setText(temptext); item->setText(temptext);
item->setData(Qt::UserRole, tempvariant); item->setData(Qt::UserRole, tempvariant);
@@ -420,26 +422,24 @@ QString GameControllerMappingDialog::bindingString(SDL_GameControllerButtonBind
QString temp = QString(); QString temp = QString();
switch(bind.bindType) switch (bind.bindType)
{ {
case SDL_CONTROLLER_BINDTYPE_BUTTON: case SDL_CONTROLLER_BINDTYPE_BUTTON:
temp.append(QString("Button %1").arg(bind.value.button+1)); temp.append(QString("Button %1").arg(bind.value.button + 1));
break; break;
case SDL_CONTROLLER_BINDTYPE_AXIS: case SDL_CONTROLLER_BINDTYPE_AXIS:
temp.append(QString("Axis %1").arg(bind.value.axis+1)); temp.append(QString("Axis %1").arg(bind.value.axis + 1));
break; break;
case SDL_CONTROLLER_BINDTYPE_HAT: case SDL_CONTROLLER_BINDTYPE_HAT:
temp.append(QString("Hat %1.%2").arg(bind.value.hat.hat+1) temp.append(QString("Hat %1.%2").arg(bind.value.hat.hat + 1).arg(bind.value.hat.hat_mask));
.arg(bind.value.hat.hat_mask)); break;
break;
default: default:
break; break;
}
}
return temp; return temp;
} }
@@ -450,26 +450,25 @@ QList<QVariant> GameControllerMappingDialog::bindingValues(SDL_GameControllerBut
QList<QVariant> temp; QList<QVariant> temp;
switch(bind.bindType) switch (bind.bindType)
{ {
case SDL_CONTROLLER_BINDTYPE_BUTTON: case SDL_CONTROLLER_BINDTYPE_BUTTON:
temp.append(QVariant(0)); temp.append(QVariant(0));
temp.append(QVariant(bind.value.button)); temp.append(QVariant(bind.value.button));
break; break;
case SDL_CONTROLLER_BINDTYPE_AXIS: case SDL_CONTROLLER_BINDTYPE_AXIS:
temp.append(QVariant(bind.value.axis+1)); temp.append(QVariant(bind.value.axis + 1));
temp.append(QVariant(0)); temp.append(QVariant(0));
break; break;
case SDL_CONTROLLER_BINDTYPE_HAT:
temp.append(QVariant(-bind.value.hat.hat-1));
temp.append(QVariant(bind.value.hat.hat_mask));
break;
default:
break;
}
case SDL_CONTROLLER_BINDTYPE_HAT:
temp.append(QVariant(-bind.value.hat.hat - 1));
temp.append(QVariant(bind.value.hat.hat_mask));
break;
default:
break;
}
return temp; return temp;
} }
@@ -485,7 +484,8 @@ void GameControllerMappingDialog::discardMapping(QAbstractButton *button)
{ {
QMessageBox msgBox; QMessageBox msgBox;
msgBox.setWindowTitle(tr("Discard Controller Mapping?")); msgBox.setWindowTitle(tr("Discard Controller Mapping?"));
msgBox.setText(tr("Discard mapping for this controller?\n\nIf discarded, the controller will be reverted to a joystick once you refresh all joysticks.")); msgBox.setText(tr("Discard mapping for this controller?\n\nIf discarded, the controller will be reverted to a "
"joystick once you refresh all joysticks."));
msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::Cancel); msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::Cancel);
int status = msgBox.exec(); int status = msgBox.exec();
@@ -494,8 +494,7 @@ void GameControllerMappingDialog::discardMapping(QAbstractButton *button)
{ {
removeControllerMapping(); removeControllerMapping();
close(); close();
} } else
else
{ {
enableDeviceConnections(); enableDeviceConnections();
} }
@@ -509,9 +508,9 @@ void GameControllerMappingDialog::removeControllerMapping()
settings->getLock()->lock(); settings->getLock()->lock();
settings->beginGroup("Mappings"); settings->beginGroup("Mappings");
//settings->remove(device->getGUIDString()); // settings->remove(device->getGUIDString());
settings->remove(device->getUniqueIDString()); settings->remove(device->getUniqueIDString());
//settings->remove(QString("%1Disable").arg(device->getGUIDString())); // settings->remove(QString("%1Disable").arg(device->getGUIDString()));
settings->remove(QString("%1Disable").arg(device->getUniqueIDString())); settings->remove(QString("%1Disable").arg(device->getUniqueIDString()));
settings->endGroup(); settings->endGroup();
settings->sync(); settings->sync();
@@ -551,14 +550,13 @@ void GameControllerMappingDialog::enableButtonEvents(int code)
Q_UNUSED(code); Q_UNUSED(code);
bool invoked = QMetaObject::invokeMethod(&helper, "restoreDeviceDeadZones", Qt::BlockingQueuedConnection);
if (invoked)
qDebug() << "the member restoreDeviceDeadZones could be invoked";
else
qDebug() << "the member restoreDeviceDeadZones could not be invoked";
bool invoked = QMetaObject::invokeMethod(&helper, "restoreDeviceDeadZones", Qt::BlockingQueuedConnection); // QMetaObject::invokeMethod(&helper, "restoreDeviceDeadZones", Qt::BlockingQueuedConnection);
if (invoked) qDebug() << "the member restoreDeviceDeadZones could be invoked";
else qDebug() << "the member restoreDeviceDeadZones could not be invoked";
// QMetaObject::invokeMethod(&helper, "restoreDeviceDeadZones", Qt::BlockingQueuedConnection);
} }
QString GameControllerMappingDialog::generateSDLMappingString() QString GameControllerMappingDialog::generateSDLMappingString()
@@ -566,7 +564,7 @@ QString GameControllerMappingDialog::generateSDLMappingString()
qInstallMessageHandler(MessageHandler::myMessageOutput); qInstallMessageHandler(MessageHandler::myMessageOutput);
QStringList templist = QStringList(); QStringList templist = QStringList();
//templist.append(device->getGUIDString()); // templist.append(device->getGUIDString());
templist.append(device->getUniqueIDString()); templist.append(device->getUniqueIDString());
templist.append(device->getSDLName()); templist.append(device->getSDLName());
templist.append(QString("platform:").append(device->getSDLPlatform())); templist.append(QString("platform:").append(device->getSDLPlatform()));
@@ -588,16 +586,14 @@ QString GameControllerMappingDialog::generateSDLMappingString()
{ {
mapNative.append("b"); mapNative.append("b");
mapNative.append(QString::number(tempassociation.value(1).toInt())); mapNative.append(QString::number(tempassociation.value(1).toInt()));
} } else if (bindingType > 0)
else if (bindingType > 0)
{ {
mapNative.append("a"); mapNative.append("a");
mapNative.append(QString::number(tempassociation.value(0).toInt()-1)); mapNative.append(QString::number(tempassociation.value(0).toInt() - 1));
} } else if (bindingType < 0)
else if (bindingType < 0)
{ {
mapNative.append("h"); mapNative.append("h");
mapNative.append(QString::number(tempassociation.value(0).toInt()+1)); mapNative.append(QString::number(tempassociation.value(0).toInt() + 1));
mapNative.append(".").append(QString::number(tempassociation.value(1).toInt())); mapNative.append(".").append(QString::number(tempassociation.value(1).toInt()));
} }
} }
@@ -688,8 +684,7 @@ void GameControllerMappingDialog::changeAxisDeadZone(int index)
if ((value >= 5000) && (value <= 32000)) if ((value >= 5000) && (value <= 32000))
{ {
QMetaObject::invokeMethod(&helper, "raiseDeadZones", Qt::BlockingQueuedConnection, QMetaObject::invokeMethod(&helper, "raiseDeadZones", Qt::BlockingQueuedConnection, Q_ARG(int, value));
Q_ARG(int, value));
currentDeadZoneValue = value; currentDeadZoneValue = value;
} }
} }
@@ -704,14 +699,11 @@ void GameControllerMappingDialog::updateLastAxisLineEdit(JoyAxis *tempAxis, int
if (device->isGameController()) if (device->isGameController())
{ {
GameController *controller = qobject_cast<GameController*>(device); GameController *controller = qobject_cast<GameController *>(device);
axisText = QString("%1: %2").arg(controller->getBindStringForAxis(tempAxis->getIndex(), true)) axisText = QString("%1: %2").arg(controller->getBindStringForAxis(tempAxis->getIndex(), true)).arg(value);
.arg(value); } else
}
else
{ {
axisText = QString("Axis %1: %2").arg(tempAxis->getRealJoyIndex()) axisText = QString("Axis %1: %2").arg(tempAxis->getRealJoyIndex()).arg(value);
.arg(value);
} }
ui->lastAxisEventLineEdit->setText(axisText); ui->lastAxisEventLineEdit->setText(axisText);
@@ -724,19 +716,12 @@ void GameControllerMappingDialog::updateLastAxisLineEditRaw(int index, int value
if (abs(value) >= 2000) if (abs(value) >= 2000)
{ {
QString axisText = QString("Axis %1: %2").arg(index+1) QString axisText = QString("Axis %1: %2").arg(index + 1).arg(value);
.arg(value);
ui->lastAxisEventLineEdit->setText(axisText); ui->lastAxisEventLineEdit->setText(axisText);
} }
} }
GameControllerMappingDialogHelper& GameControllerMappingDialog::getHelperLocal() { GameControllerMappingDialogHelper &GameControllerMappingDialog::getHelperLocal() { return helper; }
return helper; QList<int> &GameControllerMappingDialog::getEventTriggerAxesLocal() { return eventTriggerAxes; }
}
QList<int>& GameControllerMappingDialog::getEventTriggerAxesLocal() {
return eventTriggerAxes;
}

View File

@@ -16,17 +16,14 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef GAMECONTROLLERMAPPINGDIALOG_H #ifndef GAMECONTROLLERMAPPINGDIALOG_H
#define GAMECONTROLLERMAPPINGDIALOG_H #define GAMECONTROLLERMAPPINGDIALOG_H
#include "uihelpers/gamecontrollermappingdialoghelper.h"
#include "gamecontroller/gamecontroller.h" #include "gamecontroller/gamecontroller.h"
#include "uihelpers/gamecontrollermappingdialoghelper.h"
#include <QDialog> #include <QDialog>
class InputDevice; class InputDevice;
class AntiMicroSettings; class AntiMicroSettings;
class QWidget; class QWidget;
@@ -40,7 +37,7 @@ class GameControllerMappingDialog : public QDialog
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit GameControllerMappingDialog(InputDevice *device, AntiMicroSettings *settings, QWidget *parent = nullptr); explicit GameControllerMappingDialog(InputDevice *device, AntiMicroSettings *settings, QWidget *parent = nullptr);
~GameControllerMappingDialog(); ~GameControllerMappingDialog();
@@ -48,7 +45,7 @@ public:
static QHash<SDL_GameControllerButton, int> buttonPlacement; static QHash<SDL_GameControllerButton, int> buttonPlacement;
static QHash<SDL_GameControllerAxis, int> axisPlacement; static QHash<SDL_GameControllerAxis, int> axisPlacement;
protected: protected:
void populateGameControllerBindings(GameController *controller); void populateGameControllerBindings(GameController *controller);
void removeControllerMapping(); void removeControllerMapping();
void enableDeviceConnections(); void enableDeviceConnections();
@@ -59,13 +56,13 @@ protected:
QString bindingString(SDL_GameControllerButtonBind bind); QString bindingString(SDL_GameControllerButtonBind bind);
QList<QVariant> bindingValues(SDL_GameControllerButtonBind bind); QList<QVariant> bindingValues(SDL_GameControllerButtonBind bind);
private: private:
Ui::GameControllerMappingDialog *ui; Ui::GameControllerMappingDialog *ui;
signals: signals:
void mappingUpdate(QString mapping, InputDevice *device); void mappingUpdate(QString mapping, InputDevice *device);
private slots: private slots:
void buttonAssign(int buttonindex); void buttonAssign(int buttonindex);
void axisAssign(int axis, int value); void axisAssign(int axis, int value);
void dpadAssign(int dpad, int buttonindex); void dpadAssign(int dpad, int buttonindex);
@@ -81,9 +78,9 @@ private slots:
void updateLastAxisLineEdit(JoyAxis *tempAxis, int value); void updateLastAxisLineEdit(JoyAxis *tempAxis, int value);
void updateLastAxisLineEditRaw(int index, int value); void updateLastAxisLineEditRaw(int index, int value);
private: private:
GameControllerMappingDialogHelper& getHelperLocal(); GameControllerMappingDialogHelper &getHelperLocal();
QList<int>& getEventTriggerAxesLocal(); QList<int> &getEventTriggerAxesLocal();
InputDevice *device; InputDevice *device;
AntiMicroSettings *settings; AntiMicroSettings *settings;

View File

@@ -21,8 +21,6 @@
#include <cmath> #include <cmath>
// ---- JOYBUTTON --- // // ---- JOYBUTTON --- //
const QString GlobalVariables::JoyButton::xmlName = "button"; const QString GlobalVariables::JoyButton::xmlName = "button";
@@ -32,7 +30,7 @@ const int GlobalVariables::JoyButton::ENABLEDTURBODEFAULT = 100;
const double GlobalVariables::JoyButton::DEFAULTMOUSESPEEDMOD = 1.0; const double GlobalVariables::JoyButton::DEFAULTMOUSESPEEDMOD = 1.0;
double GlobalVariables::JoyButton::mouseSpeedModifier = GlobalVariables::JoyButton::DEFAULTMOUSESPEEDMOD; double GlobalVariables::JoyButton::mouseSpeedModifier = GlobalVariables::JoyButton::DEFAULTMOUSESPEEDMOD;
const int GlobalVariables::JoyButton::DEFAULTKEYREPEATDELAY = 600; // 600 ms const int GlobalVariables::JoyButton::DEFAULTKEYREPEATDELAY = 600; // 600 ms
const int GlobalVariables::JoyButton::DEFAULTKEYREPEATRATE = 40; // 40 ms. 25 times per second const int GlobalVariables::JoyButton::DEFAULTKEYREPEATRATE = 40; // 40 ms. 25 times per second
const bool GlobalVariables::JoyButton::DEFAULTTOGGLE = false; const bool GlobalVariables::JoyButton::DEFAULTTOGGLE = false;
const int GlobalVariables::JoyButton::DEFAULTTURBOINTERVAL = 0; const int GlobalVariables::JoyButton::DEFAULTTURBOINTERVAL = 0;
const bool GlobalVariables::JoyButton::DEFAULTUSETURBO = false; const bool GlobalVariables::JoyButton::DEFAULTUSETURBO = false;
@@ -87,7 +85,6 @@ int GlobalVariables::JoyButton::mouseRefreshRate = 5;
int GlobalVariables::JoyButton::springModeScreen = -1; int GlobalVariables::JoyButton::springModeScreen = -1;
int GlobalVariables::JoyButton::gamepadRefreshRate = 10; int GlobalVariables::JoyButton::gamepadRefreshRate = 10;
// ---- ANTIMICROSETTINGS --- // // ---- ANTIMICROSETTINGS --- //
const bool GlobalVariables::AntimicroSettings::defaultDisabledWinEnhanced = false; const bool GlobalVariables::AntimicroSettings::defaultDisabledWinEnhanced = false;
@@ -101,9 +98,9 @@ const int GlobalVariables::InputDevice::NUMBER_JOYSETS = 8;
const int GlobalVariables::InputDevice::DEFAULTKEYPRESSTIME = 100; const int GlobalVariables::InputDevice::DEFAULTKEYPRESSTIME = 100;
const int GlobalVariables::InputDevice::RAISEDDEADZONE = 20000; const int GlobalVariables::InputDevice::RAISEDDEADZONE = 20000;
const int GlobalVariables::InputDevice::DEFAULTKEYREPEATDELAY = 660; // 660 ms const int GlobalVariables::InputDevice::DEFAULTKEYREPEATDELAY = 660; // 660 ms
const int GlobalVariables::InputDevice::DEFAULTKEYREPEATRATE = 40; // 40 ms. 25 times per second const int GlobalVariables::InputDevice::DEFAULTKEYREPEATRATE = 40; // 40 ms. 25 times per second
//QRegExp GlobalVariables::InputDevice::emptyGUID("^[0]+$"); // QRegExp GlobalVariables::InputDevice::emptyGUID("^[0]+$");
QRegExp GlobalVariables::InputDevice::emptyUniqueID("^[0]+$"); QRegExp GlobalVariables::InputDevice::emptyUniqueID("^[0]+$");
// ---- JOYAXIS ---- // // ---- JOYAXIS ---- //
@@ -119,8 +116,7 @@ const float GlobalVariables::JoyAxis::JOYSPEED = 20.0;
const QString GlobalVariables::JoyAxis::xmlName = "axis"; const QString GlobalVariables::JoyAxis::xmlName = "axis";
#ifdef WITH_X11
#ifdef WITH_X11
// ---- X11EXTRAS ---- // // ---- X11EXTRAS ---- //
@@ -130,19 +126,16 @@ const QString GlobalVariables::X11Extras::xtestMouseDeviceName = QString("Virtua
QString GlobalVariables::X11Extras::_customDisplayString = QString(""); QString GlobalVariables::X11Extras::_customDisplayString = QString("");
#endif #endif
// ---- GameController ---- // // ---- GameController ---- //
const QString GlobalVariables::GameController::xmlName = "gamecontroller"; const QString GlobalVariables::GameController::xmlName = "gamecontroller";
// ---- GameControllerDPad ---- // // ---- GameControllerDPad ---- //
const QString GlobalVariables::GameControllerDPad::xmlName = "dpad"; const QString GlobalVariables::GameControllerDPad::xmlName = "dpad";
// ---- GameControllerTrigger ---- // // ---- GameControllerTrigger ---- //
const int GlobalVariables::GameControllerTrigger::AXISDEADZONE = 2000; const int GlobalVariables::GameControllerTrigger::AXISDEADZONE = 2000;
@@ -150,39 +143,32 @@ const int GlobalVariables::GameControllerTrigger::AXISMAXZONE = 32000;
const QString GlobalVariables::GameControllerTrigger::xmlName = "trigger"; const QString GlobalVariables::GameControllerTrigger::xmlName = "trigger";
// ---- GameControllerTriggerButton ---- // // ---- GameControllerTriggerButton ---- //
const QString GlobalVariables::GameControllerTriggerButton::xmlName = "triggerbutton"; const QString GlobalVariables::GameControllerTriggerButton::xmlName = "triggerbutton";
// ---- InputDaemon ---- // // ---- InputDaemon ---- //
const int GlobalVariables::InputDaemon::GAMECONTROLLERTRIGGERRELEASE = 16384; const int GlobalVariables::InputDaemon::GAMECONTROLLERTRIGGERRELEASE = 16384;
// ---- VDPad ---- // // ---- VDPad ---- //
const QString GlobalVariables::VDPad::xmlName = "vdpad"; const QString GlobalVariables::VDPad::xmlName = "vdpad";
// ---- SetJoystick ---- // // ---- SetJoystick ---- //
const int GlobalVariables::SetJoystick::MAXNAMELENGTH = 30; const int GlobalVariables::SetJoystick::MAXNAMELENGTH = 30;
const int GlobalVariables::SetJoystick::RAISEDDEADZONE = 20000; const int GlobalVariables::SetJoystick::RAISEDDEADZONE = 20000;
// ---- Joystick ---- // // ---- Joystick ---- //
const QString GlobalVariables::Joystick::xmlName = "joystick"; const QString GlobalVariables::Joystick::xmlName = "joystick";
// ---- JoyDPad ---- // // ---- JoyDPad ---- //
const QString GlobalVariables::JoyDPad::xmlName = "dpad"; const QString GlobalVariables::JoyDPad::xmlName = "dpad";
const int GlobalVariables::JoyDPad::DEFAULTDPADDELAY = 0; const int GlobalVariables::JoyDPad::DEFAULTDPADDELAY = 0;
// ---- JoyControlStick ---- // // ---- JoyControlStick ---- //
// Define Pi here. // Define Pi here.
@@ -195,35 +181,28 @@ const int GlobalVariables::JoyControlStick::DEFAULTDIAGONALRANGE = 45;
const double GlobalVariables::JoyControlStick::DEFAULTCIRCLE = 0.0; const double GlobalVariables::JoyControlStick::DEFAULTCIRCLE = 0.0;
const int GlobalVariables::JoyControlStick::DEFAULTSTICKDELAY = 0; const int GlobalVariables::JoyControlStick::DEFAULTSTICKDELAY = 0;
// ---- JoyButtonSlot ---- // // ---- JoyButtonSlot ---- //
const int GlobalVariables::JoyButtonSlot::JOYSPEED = 20; const int GlobalVariables::JoyButtonSlot::JOYSPEED = 20;
const QString GlobalVariables::JoyButtonSlot::xmlName = "slot"; const QString GlobalVariables::JoyButtonSlot::xmlName = "slot";
const int GlobalVariables::JoyButtonSlot::MAXTEXTENTRYDISPLAYLENGTH = 40; const int GlobalVariables::JoyButtonSlot::MAXTEXTENTRYDISPLAYLENGTH = 40;
// ---- AdvanceButtonDialog ---- // // ---- AdvanceButtonDialog ---- //
const int GlobalVariables::AdvanceButtonDialog::MINIMUMTURBO = 2; const int GlobalVariables::AdvanceButtonDialog::MINIMUMTURBO = 2;
// ---- JoyAxisButton ---- // // ---- JoyAxisButton ---- //
const QString GlobalVariables::JoyAxisButton::xmlName = "axisbutton"; const QString GlobalVariables::JoyAxisButton::xmlName = "axisbutton";
// ---- JoyControlStickButton ---- // // ---- JoyControlStickButton ---- //
const QString GlobalVariables::JoyControlStickButton::xmlName = "stickbutton"; const QString GlobalVariables::JoyControlStickButton::xmlName = "stickbutton";
// ---- JoyControlStickModifierButton ---- // // ---- JoyControlStickModifierButton ---- //
const QString GlobalVariables::JoyControlStickModifierButton::xmlName = "stickmodifierbutton"; const QString GlobalVariables::JoyControlStickModifierButton::xmlName = "stickmodifierbutton";
// ---- JoyDPadButton ---- // // ---- JoyDPadButton ---- //
const QString GlobalVariables::JoyDPadButton::xmlName = "dpadbutton"; const QString GlobalVariables::JoyDPadButton::xmlName = "dpadbutton";

View File

@@ -16,262 +16,236 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef GLOBALVARIABLES_H #ifndef GLOBALVARIABLES_H
#define GLOBALVARIABLES_H #define GLOBALVARIABLES_H
#include <QObject>
#include <QList> #include <QList>
#include <QObject>
namespace GlobalVariables {
namespace GlobalVariables class JoyButton
{ {
class JoyButton public:
{ static const QString xmlName;
public:
static const QString xmlName; static int IDLEMOUSEREFRESHRATE;
static int mouseHistorySize;
// Get active mouse movement refresh rate
static int mouseRefreshRate;
static int springModeScreen;
// gamepad poll rate used by the application in ms
static int gamepadRefreshRate;
static int IDLEMOUSEREFRESHRATE; static double cursorRemainderX;
static int mouseHistorySize; static double cursorRemainderY;
// Get active mouse movement refresh rate static double mouseSpeedModifier;
static int mouseRefreshRate; // Weight modifier in the range of 0.0 - 1.0
static int springModeScreen; static double weightModifier;
// gamepad poll rate used by the application in ms
static int gamepadRefreshRate;
static double cursorRemainderX; static const bool DEFAULTTOGGLE;
static double cursorRemainderY; static const bool DEFAULTUSETURBO;
static double mouseSpeedModifier; static const bool DEFAULTCYCLERESETACTIVE;
// Weight modifier in the range of 0.0 - 1.0 static const bool DEFAULTRELATIVESPRING;
static double weightModifier;
static const bool DEFAULTTOGGLE; static const double DEFAULTMOUSESPEEDMOD;
static const bool DEFAULTUSETURBO; static const double DEFAULTSENSITIVITY;
static const bool DEFAULTCYCLERESETACTIVE; static const double DEFAULTEASINGDURATION;
static const bool DEFAULTRELATIVESPRING; static const double MINIMUMEASINGDURATION;
static const double MAXIMUMEASINGDURATION;
static const double DEFAULTWEIGHTMODIFIER;
static const double MAXIMUMWEIGHTMODIFIER;
static const double DEFAULTEXTRACCELVALUE;
static const double DEFAULTMINACCELTHRESHOLD;
static const double DEFAULTMAXACCELTHRESHOLD;
static const double DEFAULTSTARTACCELMULTIPLIER;
static const double DEFAULTACCELEASINGDURATION;
static const double DEFAULTMOUSESPEEDMOD; // Define default values for many properties.
static const double DEFAULTSENSITIVITY; static const int ENABLEDTURBODEFAULT;
static const double DEFAULTEASINGDURATION; static const int DEFAULTKEYREPEATDELAY; // unsigned
static const double MINIMUMEASINGDURATION; static const int DEFAULTKEYREPEATRATE; // unsigned
static const double MAXIMUMEASINGDURATION; static const int DEFAULTTURBOINTERVAL;
static const double DEFAULTWEIGHTMODIFIER; static const int DEFAULTMOUSESPEEDX;
static const double MAXIMUMWEIGHTMODIFIER; static const int DEFAULTMOUSESPEEDY;
static const double DEFAULTEXTRACCELVALUE; static const int DEFAULTSETSELECTION;
static const double DEFAULTMINACCELTHRESHOLD; static const int DEFAULTSPRINGWIDTH;
static const double DEFAULTMAXACCELTHRESHOLD; static const int DEFAULTSPRINGHEIGHT;
static const double DEFAULTSTARTACCELMULTIPLIER; static const int DEFAULTWHEELX;
static const double DEFAULTACCELEASINGDURATION; static const int DEFAULTWHEELY;
static const int DEFAULTCYCLERESET;
static const int DEFAULTMOUSEHISTORYSIZE;
static const int MAXIMUMMOUSEHISTORYSIZE;
static const int MAXIMUMMOUSEREFRESHRATE;
static const int DEFAULTIDLEMOUSEREFRESHRATE;
static const int MINCYCLERESETTIME;
static const int MAXCYCLERESETTIME;
static const int DEFAULTSPRINGRELEASERADIUS;
// Define default values for many properties. static QHash<int, int> activeKeys;
static const int ENABLEDTURBODEFAULT; static QHash<int, int> activeMouseButtons;
static const int DEFAULTKEYREPEATDELAY; // unsigned static QList<double> mouseHistoryX;
static const int DEFAULTKEYREPEATRATE; // unsigned static QList<double> mouseHistoryY;
static const int DEFAULTTURBOINTERVAL; };
static const int DEFAULTMOUSESPEEDX;
static const int DEFAULTMOUSESPEEDY;
static const int DEFAULTSETSELECTION;
static const int DEFAULTSPRINGWIDTH;
static const int DEFAULTSPRINGHEIGHT;
static const int DEFAULTWHEELX;
static const int DEFAULTWHEELY;
static const int DEFAULTCYCLERESET;
static const int DEFAULTMOUSEHISTORYSIZE;
static const int MAXIMUMMOUSEHISTORYSIZE;
static const int MAXIMUMMOUSEREFRESHRATE;
static const int DEFAULTIDLEMOUSEREFRESHRATE;
static const int MINCYCLERESETTIME;
static const int MAXCYCLERESETTIME;
static const int DEFAULTSPRINGRELEASERADIUS;
static QHash<int, int> activeKeys; class AntimicroSettings
static QHash<int, int> activeMouseButtons; {
static QList<double> mouseHistoryX; public:
static QList<double> mouseHistoryY; static const bool defaultDisabledWinEnhanced;
}; static const bool defaultAssociateProfiles;
static const int defaultSpringScreen;
static const int defaultSDLGamepadPollRate;
};
class AntimicroSettings class InputDevice
{ {
public: public:
static const int NUMBER_JOYSETS;
static const int DEFAULTKEYPRESSTIME;
static const int RAISEDDEADZONE;
static const int DEFAULTKEYREPEATDELAY;
static const int DEFAULTKEYREPEATRATE;
static const bool defaultDisabledWinEnhanced; // static QRegExp emptyGUID;
static const bool defaultAssociateProfiles; static QRegExp emptyUniqueID;
static const int defaultSpringScreen; };
static const int defaultSDLGamepadPollRate;
};
class InputDevice class JoyAxis
{ {
public: public:
static const int AXISMIN;
static const int AXISMAX;
static const int AXISDEADZONE;
static const int AXISMAXZONE;
static const int NUMBER_JOYSETS; static const float JOYSPEED;
static const int DEFAULTKEYPRESSTIME;
static const int RAISEDDEADZONE;
static const int DEFAULTKEYREPEATDELAY;
static const int DEFAULTKEYREPEATRATE;
//static QRegExp emptyGUID; static const QString xmlName;
static QRegExp emptyUniqueID; };
};
class JoyAxis #ifdef WITH_X11
{
public:
static const int AXISMIN; class X11Extras
static const int AXISMAX; {
static const int AXISDEADZONE; public:
static const int AXISMAXZONE; static const QString mouseDeviceName;
static const QString keyboardDeviceName;
static const QString xtestMouseDeviceName;
static const float JOYSPEED; static QString _customDisplayString;
};
static const QString xmlName; #endif
};
class GameController
{
public:
static const QString xmlName;
};
#ifdef WITH_X11 class GameControllerDPad
{
public:
static const QString xmlName;
};
class X11Extras class GameControllerTrigger
{ {
public: public:
static const int AXISDEADZONE;
static const int AXISMAXZONE;
static const QString mouseDeviceName; static const QString xmlName;
static const QString keyboardDeviceName; };
static const QString xtestMouseDeviceName;
static QString _customDisplayString; class GameControllerTriggerButton
}; {
public:
static const QString xmlName;
};
#endif class InputDaemon
{
public:
static const int GAMECONTROLLERTRIGGERRELEASE;
};
class VDPad
{
public:
static const QString xmlName;
};
class GameController class SetJoystick
{ {
public: public:
static const int MAXNAMELENGTH;
static const int RAISEDDEADZONE;
};
static const QString xmlName; class Joystick
}; {
public:
static const QString xmlName;
};
class GameControllerDPad class JoyDPad
{ {
public: public:
static const QString xmlName;
static const int DEFAULTDPADDELAY; // unsigned
};
static const QString xmlName; class JoyControlStick
}; {
public:
static const double PI;
class GameControllerTrigger // Define default values for stick properties.
{ static const int DEFAULTDEADZONE;
public: static const int DEFAULTMAXZONE;
static const int DEFAULTDIAGONALRANGE;
static const double DEFAULTCIRCLE;
static const int DEFAULTSTICKDELAY;
};
static const int AXISDEADZONE; class JoyButtonSlot
static const int AXISMAXZONE; {
public:
static const int JOYSPEED;
static const QString xmlName;
static const int MAXTEXTENTRYDISPLAYLENGTH;
};
static const QString xmlName; class AdvanceButtonDialog
}; {
public:
static const int MINIMUMTURBO;
};
class GameControllerTriggerButton class JoyAxisButton
{ {
public: public:
static const QString xmlName;
};
static const QString xmlName; class JoyControlStickButton
}; {
public:
static const QString xmlName;
};
class InputDaemon class JoyControlStickModifierButton
{ {
public: public:
static const QString xmlName;
};
static const int GAMECONTROLLERTRIGGERRELEASE; class JoyDPadButton
}; {
public:
static const QString xmlName;
};
class VDPad } // namespace GlobalVariables
{
public:
static const QString xmlName;
};
class SetJoystick
{
public:
static const int MAXNAMELENGTH;
static const int RAISEDDEADZONE;
};
class Joystick
{
public:
static const QString xmlName;
};
class JoyDPad
{
public:
static const QString xmlName;
static const int DEFAULTDPADDELAY; // unsigned
};
class JoyControlStick
{
public:
static const double PI;
// Define default values for stick properties.
static const int DEFAULTDEADZONE;
static const int DEFAULTMAXZONE;
static const int DEFAULTDIAGONALRANGE;
static const double DEFAULTCIRCLE;
static const int DEFAULTSTICKDELAY;
};
class JoyButtonSlot
{
public:
static const int JOYSPEED;
static const QString xmlName;
static const int MAXTEXTENTRYDISPLAYLENGTH;
};
class AdvanceButtonDialog
{
public:
static const int MINIMUMTURBO;
};
class JoyAxisButton
{
public:
static const QString xmlName;
};
class JoyControlStickButton
{
public:
static const QString xmlName;
};
class JoyControlStickModifierButton
{
public:
static const QString xmlName;
};
class JoyDPadButton
{
public:
static const QString xmlName;
};
}
#endif // GLOBALVARIABLES_H #endif // GLOBALVARIABLES_H

View File

File diff suppressed because it is too large Load Diff

View File

@@ -16,7 +16,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef INPUTDAEMONTHREAD_H #ifndef INPUTDAEMONTHREAD_H
#define INPUTDAEMONTHREAD_H #define INPUTDAEMONTHREAD_H
@@ -24,7 +23,6 @@
//#include "fakeclasses/xbox360wireless.h" //#include "fakeclasses/xbox360wireless.h"
#include <SDL2/SDL_events.h> #include <SDL2/SDL_events.h>
class InputDevice; class InputDevice;
class AntiMicroSettings; class AntiMicroSettings;
class InputDeviceBitArrayStatus; class InputDeviceBitArrayStatus;
@@ -37,17 +35,14 @@ class InputDaemon : public QObject
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit InputDaemon (QMap<SDL_JoystickID, InputDevice*> *joysticks, explicit InputDaemon(QMap<SDL_JoystickID, InputDevice *> *joysticks, AntiMicroSettings *settings, bool graphical = true,
AntiMicroSettings *settings, bool graphical=true, QObject *parent = 0);
QObject *parent=0);
~InputDaemon(); ~InputDaemon();
protected:
protected: InputDeviceBitArrayStatus *createOrGrabBitStatusEntry(QHash<InputDevice *, InputDeviceBitArrayStatus *> *statusHash,
InputDeviceBitArrayStatus* createOrGrabBitStatusEntry( InputDevice *device, bool readCurrent = true);
QHash<InputDevice*, InputDeviceBitArrayStatus*> *statusHash,
InputDevice *device, bool readCurrent=true);
QString getJoyInfo(SDL_JoystickGUID sdlvalue); QString getJoyInfo(SDL_JoystickGUID sdlvalue);
QString getJoyInfo(Uint16 sdlvalue); QString getJoyInfo(Uint16 sdlvalue);
@@ -56,14 +51,14 @@ protected:
void secondInputPass(QQueue<SDL_Event> *sdlEventQueue); void secondInputPass(QQueue<SDL_Event> *sdlEventQueue);
void modifyUnplugEvents(QQueue<SDL_Event> *sdlEventQueue); void modifyUnplugEvents(QQueue<SDL_Event> *sdlEventQueue);
QBitArray createUnplugEventBitArray(InputDevice *device); QBitArray createUnplugEventBitArray(InputDevice *device);
Joystick* openJoystickDevice(int index); Joystick *openJoystickDevice(int index);
void clearBitArrayStatusInstances(); void clearBitArrayStatusInstances();
void convertMappingsToUnique(QSettings* sett, QString guidString, QString uniqueIdString); void convertMappingsToUnique(QSettings *sett, QString guidString, QString uniqueIdString);
signals: signals:
void joystickRefreshed (InputDevice *joystick); void joystickRefreshed(InputDevice *joystick);
void joysticksRefreshed(QMap<SDL_JoystickID, InputDevice*> *joysticks); void joysticksRefreshed(QMap<SDL_JoystickID, InputDevice *> *joysticks);
void complete(InputDevice *joystick); void complete(InputDevice *joystick);
void complete(); void complete();
@@ -71,8 +66,7 @@ signals:
void deviceRemoved(SDL_JoystickID deviceID); void deviceRemoved(SDL_JoystickID deviceID);
void deviceAdded(InputDevice *device); void deviceAdded(InputDevice *device);
public slots:
public slots:
void run(); void run();
void quit(); void quit();
void refresh(); void refresh();
@@ -82,25 +76,25 @@ public slots:
void startWorker(); void startWorker();
void refreshMapping(QString mapping, InputDevice *device); void refreshMapping(QString mapping, InputDevice *device);
void removeDevice(InputDevice *device); void removeDevice(InputDevice *device);
void addInputDevice(int index, QMap<QString,int>& uniques, int &counterUniques, bool &duplicatedGamepad); void addInputDevice(int index, QMap<QString, int> &uniques, int &counterUniques, bool &duplicatedGamepad);
void refreshIndexes(); void refreshIndexes();
private slots: private slots:
void stop(); void stop();
void resetActiveButtonMouseDistances(); void resetActiveButtonMouseDistances();
void updatePollResetRate(int tempPollRate); void updatePollResetRate(int tempPollRate);
private: private:
QHash<SDL_JoystickID, Joystick*>& getTrackjoysticksLocal(); QHash<SDL_JoystickID, Joystick *> &getTrackjoysticksLocal();
QHash<InputDevice*, InputDeviceBitArrayStatus*>& getReleaseEventsGeneratedLocal(); QHash<InputDevice *, InputDeviceBitArrayStatus *> &getReleaseEventsGeneratedLocal();
QHash<InputDevice*, InputDeviceBitArrayStatus*>& getPendingEventValuesLocal(); QHash<InputDevice *, InputDeviceBitArrayStatus *> &getPendingEventValuesLocal();
QMap<SDL_JoystickID, InputDevice*> *m_joysticks; QMap<SDL_JoystickID, InputDevice *> *m_joysticks;
QHash<SDL_JoystickID, Joystick*> trackjoysticks; QHash<SDL_JoystickID, Joystick *> trackjoysticks;
QHash<SDL_JoystickID, GameController*> trackcontrollers; QHash<SDL_JoystickID, GameController *> trackcontrollers;
QHash<InputDevice*, InputDeviceBitArrayStatus*> releaseEventsGenerated; QHash<InputDevice *, InputDeviceBitArrayStatus *> releaseEventsGenerated;
QHash<InputDevice*, InputDeviceBitArrayStatus*> pendingEventValues; QHash<InputDevice *, InputDeviceBitArrayStatus *> pendingEventValues;
bool stopped; bool stopped;
bool m_graphical; bool m_graphical;
@@ -109,7 +103,7 @@ private:
QThread *sdlWorkerThread; QThread *sdlWorkerThread;
AntiMicroSettings *m_settings; AntiMicroSettings *m_settings;
QTimer pollResetTimer; QTimer pollResetTimer;
//SDL_Joystick* xbox360; // SDL_Joystick* xbox360;
}; };
#endif // INPUTDAEMONTHREAD_H #endif // INPUTDAEMONTHREAD_H

View File

File diff suppressed because it is too large Load Diff

View File

@@ -16,7 +16,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef INPUTDEVICE_H #ifndef INPUTDEVICE_H
#define INPUTDEVICE_H #define INPUTDEVICE_H
@@ -24,7 +23,6 @@
#include <SDL2/SDL_joystick.h> #include <SDL2/SDL_joystick.h>
class AntiMicroSettings; class AntiMicroSettings;
class SetJoystick; class SetJoystick;
class QXmlStreamReader; class QXmlStreamReader;
@@ -35,8 +33,8 @@ class InputDevice : public QObject
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit InputDevice(SDL_Joystick* joystick, int deviceIndex, AntiMicroSettings *settings, QObject *parent = nullptr); explicit InputDevice(SDL_Joystick *joystick, int deviceIndex, AntiMicroSettings *settings, QObject *parent = nullptr);
virtual ~InputDevice(); virtual ~InputDevice();
virtual int getNumberButtons(); virtual int getNumberButtons();
@@ -48,8 +46,8 @@ public:
int getJoyNumber(); int getJoyNumber();
int getRealJoyNumber(); int getRealJoyNumber();
int getActiveSetNumber(); int getActiveSetNumber();
SetJoystick* getActiveSetJoystick(); SetJoystick *getActiveSetJoystick();
SetJoystick* getSetJoystick(int index); SetJoystick *getSetJoystick(int index);
void removeControlStick(int index); void removeControlStick(int index);
bool isActive(); bool isActive();
int getButtonDownCount(); int getButtonDownCount();
@@ -78,15 +76,15 @@ public:
virtual bool isGameController(); virtual bool isGameController();
virtual bool isKnownController(); virtual bool isKnownController();
void setButtonName(int index, QString tempName); // InputDeviceXml class void setButtonName(int index, QString tempName); // InputDeviceXml class
void setAxisButtonName(int axisIndex, int buttonIndex, QString tempName); // InputDeviceXml class void setAxisButtonName(int axisIndex, int buttonIndex, QString tempName); // InputDeviceXml class
void setStickButtonName(int stickIndex, int buttonIndex, QString tempName); // InputDeviceXml class void setStickButtonName(int stickIndex, int buttonIndex, QString tempName); // InputDeviceXml class
void setDPadButtonName(int dpadIndex, int buttonIndex, QString tempName); // InputDeviceXml class void setDPadButtonName(int dpadIndex, int buttonIndex, QString tempName); // InputDeviceXml class
void setVDPadButtonName(int vdpadIndex, int buttonIndex, QString tempName); // InputDeviceXml class void setVDPadButtonName(int vdpadIndex, int buttonIndex, QString tempName); // InputDeviceXml class
void setAxisName(int axisIndex, QString tempName); // InputDeviceAxis class void setAxisName(int axisIndex, QString tempName); // InputDeviceAxis class
void setStickName(int stickIndex, QString tempName); // InputDeviceStick class void setStickName(int stickIndex, QString tempName); // InputDeviceStick class
void setDPadName(int dpadIndex, QString tempName); // InputDeviceHat class void setDPadName(int dpadIndex, QString tempName); // InputDeviceHat class
void setVDPadName(int vdpadIndex, QString tempName); // InputDeviceVDPad class void setVDPadName(int vdpadIndex, QString tempName); // InputDeviceVDPad class
virtual int getNumberRawButtons() = 0; virtual int getNumberRawButtons() = 0;
@@ -119,114 +117,117 @@ public:
void activatePossiblePendingEvents(); void activatePossiblePendingEvents();
void activatePossibleControlStickEvents(); // InputDeviceStick class void activatePossibleControlStickEvents(); // InputDeviceStick class
void activatePossibleAxisEvents(); // InputDeviceAxis class void activatePossibleAxisEvents(); // InputDeviceAxis class
void activatePossibleDPadEvents(); // InputDeviceHat class void activatePossibleDPadEvents(); // InputDeviceHat class
void activatePossibleVDPadEvents(); // InputDeviceVDPad class void activatePossibleVDPadEvents(); // InputDeviceVDPad class
void activatePossibleButtonEvents(); // InputDeviceButton class void activatePossibleButtonEvents(); // InputDeviceButton class
void convertToUniqueMappSett(QSettings* sett, QString gUIDmappGroupSett, QString uniqueIDGroupSett); void convertToUniqueMappSett(QSettings *sett, QString gUIDmappGroupSett, QString uniqueIDGroupSett);
//bool isEmptyGUID(QString tempGUID); // bool isEmptyGUID(QString tempGUID);
bool isEmptyUniqueID(QString tempUniqueID); bool isEmptyUniqueID(QString tempUniqueID);
//bool isRelevantGUID(QString tempGUID); // bool isRelevantGUID(QString tempGUID);
bool isRelevantUniqueID(QString tempUniqueID); bool isRelevantUniqueID(QString tempUniqueID);
void setRawAxisDeadZone(int deadZone); // InputDeviceAxis class void setRawAxisDeadZone(int deadZone); // InputDeviceAxis class
int getRawAxisDeadZone(); // InputDeviceAxis class int getRawAxisDeadZone(); // InputDeviceAxis class
void rawAxisEvent(int index, int value); // InputDeviceAxis class void rawAxisEvent(int index, int value); // InputDeviceAxis class
bool elementsHaveNames(); bool elementsHaveNames();
QHash<int, SetJoystick*>& getJoystick_sets(); QHash<int, SetJoystick *> &getJoystick_sets();
SDL_Joystick* getJoyHandle() const; SDL_Joystick *getJoyHandle() const;
protected: protected:
void enableSetConnections(SetJoystick *setstick); void enableSetConnections(SetJoystick *setstick);
QHash<int, JoyAxis::ThrottleTypes>& getCali(); QHash<int, JoyAxis::ThrottleTypes> &getCali();
SDL_JoystickID* getJoystickID(); SDL_JoystickID *getJoystickID();
int rawAxisDeadZone; int rawAxisDeadZone;
int keyPressTime; // unsigned int keyPressTime; // unsigned
QString profileName; QString profileName;
signals:
signals:
void setChangeActivated(int index); void setChangeActivated(int index);
void setAxisThrottleActivated(int index); // InputDeviceAxis class void setAxisThrottleActivated(int index); // InputDeviceAxis class
void clicked(int index); void clicked(int index);
void released(int index); void released(int index);
void rawButtonClick(int index); // InputDeviceButton class void rawButtonClick(int index); // InputDeviceButton class
void rawButtonRelease(int index); // InputDeviceButton class void rawButtonRelease(int index); // InputDeviceButton class
void rawAxisButtonClick(int axis, int buttonindex); // InputDeviceAxisBtn class void rawAxisButtonClick(int axis, int buttonindex); // InputDeviceAxisBtn class
void rawAxisButtonRelease(int axis, int buttonindex); // InputDeviceAxisBtn class void rawAxisButtonRelease(int axis, int buttonindex); // InputDeviceAxisBtn class
void rawDPadButtonClick(int dpad, int buttonindex); // InputDeviceHat class void rawDPadButtonClick(int dpad, int buttonindex); // InputDeviceHat class
void rawDPadButtonRelease(int dpad, int buttonindex); // InputDeviceHat class void rawDPadButtonRelease(int dpad, int buttonindex); // InputDeviceHat class
void rawAxisActivated(int axis, int value); // InputDeviceAxis class void rawAxisActivated(int axis, int value); // InputDeviceAxis class
void rawAxisReleased(int axis, int value); // InputDeviceAxis class void rawAxisReleased(int axis, int value); // InputDeviceAxis class
void rawAxisMoved(int axis, int value); // InputDeviceAxis class void rawAxisMoved(int axis, int value); // InputDeviceAxis class
void profileUpdated(); void profileUpdated();
void propertyUpdated(); void propertyUpdated();
void profileNameEdited(QString text); void profileNameEdited(QString text);
void requestProfileLoad(QString location); void requestProfileLoad(QString location);
void requestWait(); void requestWait();
public slots: public slots:
void reset(); void reset();
void transferReset(); void transferReset();
void reInitButtons(); void reInitButtons();
void resetButtonDownCount(); void resetButtonDownCount();
void setActiveSetNumber(int index); void setActiveSetNumber(int index);
void changeSetButtonAssociation(int button_index, int originset, int newset, int mode); // InputDeviceButton class void changeSetButtonAssociation(int button_index, int originset, int newset, int mode); // InputDeviceButton class
void changeSetAxisButtonAssociation(int button_index, int axis_index, int originset, int newset, int mode); // InputDeviceAxisBtn class void changeSetAxisButtonAssociation(int button_index, int axis_index, int originset, int newset,
void changeSetStickButtonAssociation(int button_index, int stick_index, int originset, int newset, int mode); // InputDeviceStick class int mode); // InputDeviceAxisBtn class
void changeSetDPadButtonAssociation(int button_index, int dpad_index, int originset, int newset, int mode); // InputDeviceHat class void changeSetStickButtonAssociation(int button_index, int stick_index, int originset, int newset,
void changeSetVDPadButtonAssociation(int button_index, int dpad_index, int originset, int newset, int mode); // InputDeviceVDPad class int mode); // InputDeviceStick class
void setDeviceKeyPressTime(int newPressTime); // .., unsigned void changeSetDPadButtonAssociation(int button_index, int dpad_index, int originset, int newset,
int mode); // InputDeviceHat class
void changeSetVDPadButtonAssociation(int button_index, int dpad_index, int originset, int newset,
int mode); // InputDeviceVDPad class
void setDeviceKeyPressTime(int newPressTime); // .., unsigned
void profileEdited(); void profileEdited();
void setProfileName(QString value); void setProfileName(QString value);
void haltServices(); void haltServices();
void finalRemoval(); void finalRemoval();
virtual void buttonClickEvent(int buttonindex); // InputDeviceButton class virtual void buttonClickEvent(int buttonindex); // InputDeviceButton class
virtual void buttonReleaseEvent(int buttonindex); // InputDeviceButton class virtual void buttonReleaseEvent(int buttonindex); // InputDeviceButton class
virtual void dpadButtonClickEvent(int buttonindex); // InputDeviceHat class virtual void dpadButtonClickEvent(int buttonindex); // InputDeviceHat class
virtual void dpadButtonReleaseEvent(int buttonindex); // InputDeviceHat class virtual void dpadButtonReleaseEvent(int buttonindex); // InputDeviceHat class
void establishPropertyUpdatedConnection(); void establishPropertyUpdatedConnection();
void disconnectPropertyUpdatedConnection(); void disconnectPropertyUpdatedConnection();
protected slots: protected slots:
void propogateSetChange(int index); void propogateSetChange(int index);
void propogateSetAxisThrottleChange(int index, int originset); void propogateSetAxisThrottleChange(int index, int originset);
void buttonDownEvent(int setindex, int buttonindex); // InputDeviceButton class void buttonDownEvent(int setindex, int buttonindex); // InputDeviceButton class
void buttonUpEvent(int setindex, int buttonindex); // InputDeviceButton class void buttonUpEvent(int setindex, int buttonindex); // InputDeviceButton class
virtual void axisActivatedEvent(int setindex, int axisindex, int value); // InputDeviceAxis class virtual void axisActivatedEvent(int setindex, int axisindex, int value); // InputDeviceAxis class
virtual void axisReleasedEvent(int setindex, int axisindex, int value); // InputDeviceAxis class virtual void axisReleasedEvent(int setindex, int axisindex, int value); // InputDeviceAxis class
virtual void axisButtonDownEvent(int setindex, int axisindex, int buttonindex); // InputDeviceAxisBtn class virtual void axisButtonDownEvent(int setindex, int axisindex, int buttonindex); // InputDeviceAxisBtn class
virtual void axisButtonUpEvent(int setindex, int axisindex, int buttonindex); // InputDeviceAxisBtn class virtual void axisButtonUpEvent(int setindex, int axisindex, int buttonindex); // InputDeviceAxisBtn class
virtual void dpadButtonDownEvent(int setindex, int dpadindex, int buttonindex); // InputDeviceHat class virtual void dpadButtonDownEvent(int setindex, int dpadindex, int buttonindex); // InputDeviceHat class
virtual void dpadButtonUpEvent(int setindex, int dpadindex, int buttonindex); // InputDeviceHat class virtual void dpadButtonUpEvent(int setindex, int dpadindex, int buttonindex); // InputDeviceHat class
virtual void stickButtonDownEvent(int setindex, int stickindex, int buttonindex); // InputDeviceStick class virtual void stickButtonDownEvent(int setindex, int stickindex, int buttonindex); // InputDeviceStick class
virtual void stickButtonUpEvent(int setindex, int stickindex, int buttonindex); // InputDeviceStick class virtual void stickButtonUpEvent(int setindex, int stickindex, int buttonindex); // InputDeviceStick class
void updateSetButtonNames(int index); // InputDeviceButton class void updateSetButtonNames(int index); // InputDeviceButton class
void updateSetAxisButtonNames(int axisIndex, int buttonIndex); // InputDeviceAxis class void updateSetAxisButtonNames(int axisIndex, int buttonIndex); // InputDeviceAxis class
void updateSetStickButtonNames(int stickIndex, int buttonIndex); // InputDeviceStick class void updateSetStickButtonNames(int stickIndex, int buttonIndex); // InputDeviceStick class
void updateSetDPadButtonNames(int dpadIndex, int buttonIndex); // InputDeviceHat class void updateSetDPadButtonNames(int dpadIndex, int buttonIndex); // InputDeviceHat class
void updateSetVDPadButtonNames(int vdpadIndex, int buttonIndex); // InputDeviceVDPad class void updateSetVDPadButtonNames(int vdpadIndex, int buttonIndex); // InputDeviceVDPad class
void updateSetAxisNames(int axisIndex); // InputDeviceAxis class void updateSetAxisNames(int axisIndex); // InputDeviceAxis class
void updateSetStickNames(int stickIndex); // InputDeviceStick class void updateSetStickNames(int stickIndex); // InputDeviceStick class
void updateSetDPadNames(int dpadIndex); // InputDeviceHat class void updateSetDPadNames(int dpadIndex); // InputDeviceHat class
void updateSetVDPadNames(int vdpadIndex); // InputDeviceVDPad class void updateSetVDPadNames(int vdpadIndex); // InputDeviceVDPad class
private: private:
QList<bool>& getButtonstatesLocal(); QList<bool> &getButtonstatesLocal();
QList<int>& getAxesstatesLocal(); QList<int> &getAxesstatesLocal();
QList<int>& getDpadstatesLocal(); QList<int> &getDpadstatesLocal();
SDL_Joystick* m_joyhandle; SDL_Joystick *m_joyhandle;
QHash<int, SetJoystick*> joystick_sets; QHash<int, SetJoystick *> joystick_sets;
QHash<int, JoyAxis::ThrottleTypes> cali; QHash<int, JoyAxis::ThrottleTypes> cali;
AntiMicroSettings *m_settings; AntiMicroSettings *m_settings;
int active_set; int active_set;
@@ -244,7 +245,7 @@ private:
QList<int> dpadstates; QList<int> dpadstates;
}; };
Q_DECLARE_METATYPE(InputDevice*) Q_DECLARE_METATYPE(InputDevice *)
Q_DECLARE_METATYPE(SDL_JoystickID) Q_DECLARE_METATYPE(SDL_JoystickID)
#endif // INPUTDEVICE_H #endif // INPUTDEVICE_H

View File

@@ -18,17 +18,17 @@
#include "inputdevicebitarraystatus.h" #include "inputdevicebitarraystatus.h"
#include "messagehandler.h"
#include "inputdevice.h" #include "inputdevice.h"
#include "setjoystick.h"
#include "joystick.h"
#include "joydpad.h"
#include "joybutton.h" #include "joybutton.h"
#include "joydpad.h"
#include "joystick.h"
#include "messagehandler.h"
#include "setjoystick.h"
#include <QDebug> #include <QDebug>
InputDeviceBitArrayStatus::InputDeviceBitArrayStatus(InputDevice *device, bool readCurrent, QObject *parent) : InputDeviceBitArrayStatus::InputDeviceBitArrayStatus(InputDevice *device, bool readCurrent, QObject *parent)
QObject(parent) : QObject(parent)
{ {
qInstallMessageHandler(MessageHandler::myMessageOutput); qInstallMessageHandler(MessageHandler::myMessageOutput);
@@ -40,8 +40,7 @@ InputDeviceBitArrayStatus::InputDeviceBitArrayStatus(InputDevice *device, bool r
if ((axis != nullptr) && readCurrent) if ((axis != nullptr) && readCurrent)
{ {
axesStatus.append(!axis->inDeadZone(axis->getCurrentRawValue()) ? true : false); axesStatus.append(!axis->inDeadZone(axis->getCurrentRawValue()) ? true : false);
} } else
else
{ {
axesStatus.append(false); axesStatus.append(false);
} }
@@ -55,8 +54,7 @@ InputDeviceBitArrayStatus::InputDeviceBitArrayStatus(InputDevice *device, bool r
if ((dpad != nullptr) && readCurrent) if ((dpad != nullptr) && readCurrent)
{ {
hatButtonStatus.append(dpad->getCurrentDirection() != JoyDPadButton::DpadCentered ? true : false); hatButtonStatus.append(dpad->getCurrentDirection() != JoyDPadButton::DpadCentered ? true : false);
} } else
else
{ {
hatButtonStatus.append(false); hatButtonStatus.append(false);
} }
@@ -150,7 +148,4 @@ void InputDeviceBitArrayStatus::clearStatusValues()
getButtonStatusLocal().fill(false); getButtonStatusLocal().fill(false);
} }
QBitArray& InputDeviceBitArrayStatus::getButtonStatusLocal() { QBitArray &InputDeviceBitArrayStatus::getButtonStatusLocal() { return buttonStatus; }
return buttonStatus;
}

View File

@@ -16,14 +16,12 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef INPUTDEVICESTATUSEVENT_H #ifndef INPUTDEVICESTATUSEVENT_H
#define INPUTDEVICESTATUSEVENT_H #define INPUTDEVICESTATUSEVENT_H
#include <QObject>
#include <QList>
#include <QBitArray> #include <QBitArray>
#include <QList>
#include <QObject>
class InputDevice; class InputDevice;
@@ -31,7 +29,7 @@ class InputDeviceBitArrayStatus : public QObject
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit InputDeviceBitArrayStatus(InputDevice *device, bool readCurrent = true, QObject *parent = nullptr); explicit InputDeviceBitArrayStatus(InputDevice *device, bool readCurrent = true, QObject *parent = nullptr);
void changeAxesStatus(int axisIndex, bool value); void changeAxesStatus(int axisIndex, bool value);
@@ -41,13 +39,12 @@ public:
QBitArray generateFinalBitArray(); QBitArray generateFinalBitArray();
void clearStatusValues(); void clearStatusValues();
private: private:
QBitArray& getButtonStatusLocal(); QBitArray &getButtonStatusLocal();
QList<bool> axesStatus; QList<bool> axesStatus;
QList<bool> hatButtonStatus; QList<bool> hatButtonStatus;
QBitArray buttonStatus; QBitArray buttonStatus;
}; };
#endif // INPUTDEVICESTATUSEVENT_H #endif // INPUTDEVICESTATUSEVENT_H

View File

@@ -18,26 +18,25 @@
#include "joyaxis.h" #include "joyaxis.h"
#include "event.h"
#include "globalvariables.h" #include "globalvariables.h"
#include "messagehandler.h"
#include "joycontrolstick.h"
#include "setjoystick.h"
#include "inputdevice.h" #include "inputdevice.h"
#include "joyaxis.h" #include "joyaxis.h"
#include "event.h" #include "joycontrolstick.h"
#include "messagehandler.h"
#include "setjoystick.h"
#include <cmath> #include <cmath>
#include <QDebug>
#include <QXmlStreamReader> #include <QXmlStreamReader>
#include <QXmlStreamWriter> #include <QXmlStreamWriter>
#include <QtGlobal> #include <QtGlobal>
#include <QDebug>
const JoyAxis::ThrottleTypes JoyAxis::DEFAULTTHROTTLE = JoyAxis::NormalThrottle; const JoyAxis::ThrottleTypes JoyAxis::DEFAULTTHROTTLE = JoyAxis::NormalThrottle;
JoyAxis::JoyAxis(int index, int originset, SetJoystick *parentSet, JoyAxis::JoyAxis(int index, int originset, SetJoystick *parentSet, QObject *parent)
QObject *parent) : : QObject(parent)
QObject(parent)
{ {
qInstallMessageHandler(MessageHandler::myMessageOutput); qInstallMessageHandler(MessageHandler::myMessageOutput);
@@ -75,8 +74,7 @@ void JoyAxis::queuePendingEvent(int value, bool ignoresets, bool updateLastValue
if (m_stick != nullptr) if (m_stick != nullptr)
{ {
stickPassEvent(value, ignoresets, updateLastValues); stickPassEvent(value, ignoresets, updateLastValues);
} } else
else
{ {
pendingEvent = true; pendingEvent = true;
pendingValue = value; pendingValue = value;
@@ -135,15 +133,16 @@ void JoyAxis::stickPassEvent(int value, bool ignoresets, bool updateLastValues)
{ {
isActive = eventActive = true; isActive = eventActive = true;
emit active(value); emit active(value);
} } else if (!safezone && isActive)
else if (!safezone && isActive)
{ {
isActive = eventActive = false; isActive = eventActive = false;
emit released(value); emit released(value);
} }
if (!ignoresets) m_stick->queueJoyEvent(ignoresets); if (!ignoresets)
else m_stick->joyEvent(ignoresets); m_stick->queueJoyEvent(ignoresets);
else
m_stick->joyEvent(ignoresets);
emit moved(currentRawValue); emit moved(currentRawValue);
} }
@@ -156,8 +155,7 @@ void JoyAxis::joyEvent(int value, bool ignoresets, bool updateLastValues)
if ((m_stick != nullptr) && !pendingEvent) if ((m_stick != nullptr) && !pendingEvent)
{ {
stickPassEvent(value, ignoresets, updateLastValues); stickPassEvent(value, ignoresets, updateLastValues);
} } else
else
{ {
if (updateLastValues) if (updateLastValues)
{ {
@@ -187,14 +185,12 @@ void JoyAxis::joyEvent(int value, bool ignoresets, bool updateLastValues)
isActive = eventActive = true; isActive = eventActive = true;
emit active(value); emit active(value);
createDeskEvent(ignoresets); createDeskEvent(ignoresets);
} } else if (!safezone && isActive)
else if (!safezone && isActive)
{ {
isActive = eventActive = false; isActive = eventActive = false;
emit released(value); emit released(value);
createDeskEvent(ignoresets); createDeskEvent(ignoresets);
} } else if (isActive)
else if (isActive)
{ {
createDeskEvent(ignoresets); createDeskEvent(ignoresets);
} }
@@ -212,13 +208,14 @@ bool JoyAxis::inDeadZone(int value)
if (abs(temp) <= deadZone) if (abs(temp) <= deadZone)
{ {
qDebug() << "Value of throttle is in (less than) dead zone: " << abs(temp) << " <= " << deadZone; qDebug() << "Value of throttle is in (less than) dead zone: " << abs(temp) << " <= " << deadZone;
result = true; result = true;
} else { } else
{
qDebug() << "Value of throttle is not in (greater than) dead zone: " << abs(temp) << " > " << deadZone; qDebug() << "Value of throttle is not in (greater than) dead zone: " << abs(temp) << " > " << deadZone;
} }
return result; return result;
@@ -238,8 +235,7 @@ QString JoyAxis::getName(bool forceFullFormat, bool displayNames)
if (!naxisbutton->getActionName().isEmpty() && displayNames) if (!naxisbutton->getActionName().isEmpty() && displayNames)
{ {
label.append(naxisbutton->getActionName()); label.append(naxisbutton->getActionName());
} } else
else
{ {
label.append(naxisbutton->getCalculatedActiveZoneSummary()); label.append(naxisbutton->getCalculatedActiveZoneSummary());
} }
@@ -249,34 +245,29 @@ QString JoyAxis::getName(bool forceFullFormat, bool displayNames)
if (!paxisbutton->getActionName().isEmpty() && displayNames) if (!paxisbutton->getActionName().isEmpty() && displayNames)
{ {
label.append(paxisbutton->getActionName()); label.append(paxisbutton->getActionName());
} } else
else
{ {
label.append(paxisbutton->getCalculatedActiveZoneSummary()); label.append(paxisbutton->getCalculatedActiveZoneSummary());
} }
} } else if ((throttle == static_cast<int>(PositiveThrottle)) || (throttle == static_cast<int>(PositiveHalfThrottle)))
else if ((throttle == static_cast<int>(PositiveThrottle)) || (throttle == static_cast<int>(PositiveHalfThrottle)))
{ {
label.append("+"); label.append("+");
if (!paxisbutton->getActionName().isEmpty() && displayNames) if (!paxisbutton->getActionName().isEmpty() && displayNames)
{ {
label.append(paxisbutton->getActionName()); label.append(paxisbutton->getActionName());
} } else
else
{ {
label.append(paxisbutton->getCalculatedActiveZoneSummary()); label.append(paxisbutton->getCalculatedActiveZoneSummary());
} }
} } else if ((throttle == static_cast<int>(NegativeThrottle)) || (throttle == static_cast<int>(NegativeHalfThrottle)))
else if ((throttle == static_cast<int>(NegativeThrottle)) || (throttle == static_cast<int>(NegativeHalfThrottle)))
{ {
label.append("-"); label.append("-");
if (!naxisbutton->getActionName().isEmpty() && displayNames) if (!naxisbutton->getActionName().isEmpty() && displayNames)
{ {
label.append(naxisbutton->getActionName()); label.append(naxisbutton->getActionName());
} } else
else
{ {
label.append(naxisbutton->getCalculatedActiveZoneSummary()); label.append(naxisbutton->getCalculatedActiveZoneSummary());
} }
@@ -299,52 +290,47 @@ int JoyAxis::getCurrentThrottledValue()
return currentThrottledValue; return currentThrottledValue;
} }
void JoyAxis::updateCurrentThrottledValue(int newValue) void JoyAxis::updateCurrentThrottledValue(int newValue) { currentThrottledValue = newValue; }
{
currentThrottledValue = newValue;
}
int JoyAxis::calculateThrottledValue(int value) int JoyAxis::calculateThrottledValue(int value)
{ {
qInstallMessageHandler(MessageHandler::myMessageOutput); qInstallMessageHandler(MessageHandler::myMessageOutput);
qDebug() << "Throtted value at start of function is: " << value; qDebug() << "Throtted value at start of function is: " << value;
int temp = value; int temp = value;
switch(throttle) switch (throttle)
{ {
case -2: case -2:
qDebug() << "It's a negative half throttle"; qDebug() << "It's a negative half throttle";
value = (value <= 0) ? value : -value; value = (value <= 0) ? value : -value;
temp = value; temp = value;
break; break;
case -1: case -1:
qDebug() << "It's a negative throttle"; qDebug() << "It's a negative throttle";
temp = (value + getAxisMinCal()) / 2; temp = (value + getAxisMinCal()) / 2;
break; break;
case 1: case 1:
qDebug() << "It's a positive throttle"; qDebug() << "It's a positive throttle";
temp = (value + getAxisMaxCal()) / 2; temp = (value + getAxisMaxCal()) / 2;
break; break;
case 2: case 2:
qDebug() << "It's a positive half throttle"; qDebug() << "It's a positive half throttle";
value = (value >= 0) ? value : -value; value = (value >= 0) ? value : -value;
temp = value; temp = value;
break; break;
} }
qDebug() << "Calculated value of throttle is: " << temp;
qDebug() << "Calculated value of throttle is: " << temp;
return temp; return temp;
} }
@@ -363,15 +349,16 @@ int JoyAxis::getIndex()
return m_index; return m_index;
} }
void JoyAxis::createDeskEvent(bool ignoresets) void JoyAxis::createDeskEvent(bool ignoresets)
{ {
qInstallMessageHandler(MessageHandler::myMessageOutput); qInstallMessageHandler(MessageHandler::myMessageOutput);
JoyAxisButton *eventbutton = nullptr; JoyAxisButton *eventbutton = nullptr;
if (currentThrottledValue > deadZone) eventbutton = paxisbutton; if (currentThrottledValue > deadZone)
else if (currentThrottledValue < -deadZone) eventbutton = naxisbutton; eventbutton = paxisbutton;
else if (currentThrottledValue < -deadZone)
eventbutton = naxisbutton;
if ((eventbutton != nullptr) && !activeButton) if ((eventbutton != nullptr) && !activeButton)
{ {
@@ -379,19 +366,16 @@ void JoyAxis::createDeskEvent(bool ignoresets)
// button as active button // button as active button
eventbutton->joyEvent(eventActive, ignoresets); eventbutton->joyEvent(eventActive, ignoresets);
activeButton = eventbutton; activeButton = eventbutton;
} } else if ((eventbutton == nullptr) && (activeButton != nullptr))
else if ((eventbutton == nullptr) && (activeButton != nullptr))
{ {
// Currently in deadzone. Disable currently active button. // Currently in deadzone. Disable currently active button.
activeButton->joyEvent(eventActive, ignoresets); activeButton->joyEvent(eventActive, ignoresets);
activeButton = nullptr; activeButton = nullptr;
} } else if ((eventbutton != nullptr) && (activeButton != nullptr) && (eventbutton == activeButton))
else if ((eventbutton != nullptr) && (activeButton != nullptr) && (eventbutton == activeButton))
{ {
//Button is currently active. Just pass current value // Button is currently active. Just pass current value
eventbutton->joyEvent(eventActive, ignoresets); eventbutton->joyEvent(eventActive, ignoresets);
} } else if ((eventbutton != nullptr) && (activeButton != nullptr) && (eventbutton != activeButton))
else if ((eventbutton != nullptr) && (activeButton != nullptr) && (eventbutton != activeButton))
{ {
// Deadzone skipped. Button for new event is not the currently // Deadzone skipped. Button for new event is not the currently
// active button. Disable the active button before enabling // active button. Disable the active button before enabling
@@ -423,12 +407,11 @@ void JoyAxis::setMaxZoneValue(int value)
value = abs(value); value = abs(value);
if (value >=getAxisMaxCal()) if (value >= getAxisMaxCal())
{ {
maxZoneValue = getAxisMaxCal(); maxZoneValue = getAxisMaxCal();
emit propertyUpdated(); emit propertyUpdated();
} } else
else
{ {
maxZoneValue = value; maxZoneValue = value;
emit propertyUpdated(); emit propertyUpdated();
@@ -450,13 +433,14 @@ void JoyAxis::setThrottle(int value)
{ {
qInstallMessageHandler(MessageHandler::myMessageOutput); qInstallMessageHandler(MessageHandler::myMessageOutput);
qDebug() << "Value of throttle for axis in setThrottle is: " << value; qDebug() << "Value of throttle for axis in setThrottle is: " << value;
if ((value >= static_cast<int>(JoyAxis::NegativeHalfThrottle)) && (value <= static_cast<int>(JoyAxis::PositiveHalfThrottle))) if ((value >= static_cast<int>(JoyAxis::NegativeHalfThrottle)) &&
(value <= static_cast<int>(JoyAxis::PositiveHalfThrottle)))
{ {
if (value != throttle) if (value != throttle)
{ {
qDebug() << "Throttle value for variable \"throttle\" has been set: " << value; qDebug() << "Throttle value for variable \"throttle\" has been set: " << value;
throttle = value; throttle = value;
adjustRange(); adjustRange();
@@ -475,8 +459,8 @@ void JoyAxis::setInitialThrottle(int value)
{ {
qInstallMessageHandler(MessageHandler::myMessageOutput); qInstallMessageHandler(MessageHandler::myMessageOutput);
if ((value >= static_cast<int>(JoyAxis::NegativeHalfThrottle)) && (value <= static_cast<int>(JoyAxis::PositiveHalfThrottle)) if ((value >= static_cast<int>(JoyAxis::NegativeHalfThrottle)) &&
&& (value != throttle)) (value <= static_cast<int>(JoyAxis::PositiveHalfThrottle)) && (value != throttle))
{ {
throttle = value; throttle = value;
adjustRange(); adjustRange();
@@ -530,14 +514,14 @@ void JoyAxis::reset(int index)
m_index = index; m_index = index;
} }
JoyAxisButton* JoyAxis::getPAxisButton() JoyAxisButton *JoyAxis::getPAxisButton()
{ {
qInstallMessageHandler(MessageHandler::myMessageOutput); qInstallMessageHandler(MessageHandler::myMessageOutput);
return paxisbutton; return paxisbutton;
} }
JoyAxisButton* JoyAxis::getNAxisButton() JoyAxisButton *JoyAxis::getNAxisButton()
{ {
qInstallMessageHandler(MessageHandler::myMessageOutput); qInstallMessageHandler(MessageHandler::myMessageOutput);
@@ -558,14 +542,12 @@ void JoyAxis::adjustRange()
if (throttle == static_cast<int>(JoyAxis::NegativeThrottle)) if (throttle == static_cast<int>(JoyAxis::NegativeThrottle))
{ {
currentThrottledDeadValue = getAxisMaxCal(); currentThrottledDeadValue = getAxisMaxCal();
} } else if ((throttle == static_cast<int>(JoyAxis::NormalThrottle)) ||
else if ((throttle == static_cast<int>(JoyAxis::NormalThrottle)) || (throttle == static_cast<int>(JoyAxis::PositiveHalfThrottle)) ||
(throttle == static_cast<int>(JoyAxis::PositiveHalfThrottle)) || (throttle == static_cast<int>(JoyAxis::NegativeHalfThrottle)))
(throttle == static_cast<int>(JoyAxis::NegativeHalfThrottle)))
{ {
currentThrottledDeadValue = 0; currentThrottledDeadValue = 0;
} } else if (throttle == static_cast<int>(JoyAxis::PositiveThrottle))
else if (throttle == static_cast<int>(JoyAxis::PositiveThrottle))
{ {
currentThrottledDeadValue = getAxisMinCal(); currentThrottledDeadValue = getAxisMinCal();
} }
@@ -595,11 +577,10 @@ double JoyAxis::getDistanceFromDeadZone(int value)
if (value >= deadZone) if (value >= deadZone)
{ {
distance = static_cast<double>(value - deadZone)/(maxZoneValue - deadZone); distance = static_cast<double>(value - deadZone) / (maxZoneValue - deadZone);
} } else if (value <= -deadZone)
else if (value <= -deadZone)
{ {
distance = static_cast<double>(value + deadZone)/( (-maxZoneValue) + deadZone); distance = static_cast<double>(value + deadZone) / ((-maxZoneValue) + deadZone);
} }
return qBound(0.0, distance, 1.0); return qBound(0.0, distance, 1.0);
@@ -649,7 +630,7 @@ bool JoyAxis::isPartControlStick()
return (m_stick != nullptr); return (m_stick != nullptr);
} }
JoyControlStick* JoyAxis::getControlStick() JoyControlStick *JoyAxis::getControlStick()
{ {
qInstallMessageHandler(MessageHandler::myMessageOutput); qInstallMessageHandler(MessageHandler::myMessageOutput);
@@ -666,11 +647,10 @@ void JoyAxis::removeControlStick(bool performRelease)
m_stick->releaseButtonEvents(); m_stick->releaseButtonEvents();
m_stick = nullptr; m_stick = nullptr;
//emit propertyUpdated(); // emit propertyUpdated();
} }
} }
bool JoyAxis::hasControlOfButtons() bool JoyAxis::hasControlOfButtons()
{ {
qInstallMessageHandler(MessageHandler::myMessageOutput); qInstallMessageHandler(MessageHandler::myMessageOutput);
@@ -726,24 +706,22 @@ void JoyAxis::setCurrentRawValue(int value)
if ((value >= getAxisMinCal()) && (value <= getAxisMaxCal())) if ((value >= getAxisMinCal()) && (value <= getAxisMaxCal()))
{ {
qDebug() << "Raw value is less than " << getAxisMaxCal() << " and greather than " << getAxisMinCal(); qDebug() << "Raw value is less than " << getAxisMaxCal() << " and greather than " << getAxisMinCal();
currentRawValue = value; currentRawValue = value;
} } else if (value > getAxisMaxCal())
else if (value > getAxisMaxCal())
{ {
qDebug() << "Raw value is greather than " << getAxisMaxCal(); qDebug() << "Raw value is greather than " << getAxisMaxCal();
currentRawValue = getAxisMaxCal(); currentRawValue = getAxisMaxCal();
} } else if (value < getAxisMinCal())
else if (value < getAxisMinCal())
{ {
qDebug() << "Raw value is less than " << getAxisMinCal(); qDebug() << "Raw value is less than " << getAxisMinCal();
currentRawValue = getAxisMinCal(); currentRawValue = getAxisMinCal();
} }
qDebug() << "Raw value for axis is: " << currentRawValue; qDebug() << "Raw value for axis is: " << currentRawValue;
} }
void JoyAxis::setButtonsMouseMode(JoyButton::JoyMouseMovementMode mode) void JoyAxis::setButtonsMouseMode(JoyButton::JoyMouseMovementMode mode)
@@ -874,22 +852,21 @@ double JoyAxis::getButtonsPresetSensitivity()
return presetSensitivity; return presetSensitivity;
} }
JoyAxisButton* JoyAxis::getAxisButtonByValue(int value) JoyAxisButton *JoyAxis::getAxisButtonByValue(int value)
{ {
qInstallMessageHandler(MessageHandler::myMessageOutput); qInstallMessageHandler(MessageHandler::myMessageOutput);
JoyAxisButton *eventbutton = nullptr; JoyAxisButton *eventbutton = nullptr;
int throttledValue = calculateThrottledValue(value); int throttledValue = calculateThrottledValue(value);
qDebug() << "throttledValue in getAxisButtonByValue is: " << throttledValue; qDebug() << "throttledValue in getAxisButtonByValue is: " << throttledValue;
if (throttledValue > deadZone) if (throttledValue > deadZone)
{ {
qDebug() << "throtted value is positive"; qDebug() << "throtted value is positive";
eventbutton = paxisbutton; eventbutton = paxisbutton;
} } else if (throttledValue < (-deadZone))
else if (throttledValue < (-deadZone))
{ {
qDebug() << "throtted value is negative"; qDebug() << "throtted value is negative";
@@ -962,8 +939,7 @@ QString JoyAxis::getPartialName(bool forceFullFormat, bool displayNames)
} }
label.append(axisName); label.append(axisName);
} } else if (!defaultAxisName.isEmpty())
else if (!defaultAxisName.isEmpty())
{ {
if (forceFullFormat) if (forceFullFormat)
{ {
@@ -971,8 +947,7 @@ QString JoyAxis::getPartialName(bool forceFullFormat, bool displayNames)
} }
label.append(defaultAxisName); label.append(defaultAxisName);
} } else
else
{ {
label.append(tr("Axis")).append(" "); label.append(tr("Axis")).append(" ");
label.append(QString::number(getRealJoyIndex())); label.append(QString::number(getRealJoyIndex()));
@@ -1009,7 +984,7 @@ JoyAxis::ThrottleTypes JoyAxis::getDefaultThrottle()
return this->DEFAULTTHROTTLE; return this->DEFAULTTHROTTLE;
} }
SetJoystick* JoyAxis::getParentSet() SetJoystick *JoyAxis::getParentSet()
{ {
qInstallMessageHandler(MessageHandler::myMessageOutput); qInstallMessageHandler(MessageHandler::myMessageOutput);
@@ -1060,12 +1035,10 @@ void JoyAxis::performCalibration(int value)
{ {
// Assume axis is a trigger. Set default throttle to Positive. // Assume axis is a trigger. Set default throttle to Positive.
device->setCalibrationThrottle(m_index, PositiveThrottle); device->setCalibrationThrottle(m_index, PositiveThrottle);
} } else
else
{ {
// Ensure that default throttle is used when a device is reset. // Ensure that default throttle is used when a device is reset.
device->setCalibrationThrottle(m_index, device->setCalibrationThrottle(m_index, static_cast<JoyAxis::ThrottleTypes>(throttle));
static_cast<JoyAxis::ThrottleTypes>(throttle));
} }
} }
@@ -1135,16 +1108,13 @@ int JoyAxis::getProperReleaseValue()
if (throttle == static_cast<int>(NegativeHalfThrottle)) if (throttle == static_cast<int>(NegativeHalfThrottle))
{ {
value = 0; value = 0;
} } else if (throttle == static_cast<int>(NegativeThrottle))
else if (throttle == static_cast<int>(NegativeThrottle))
{ {
value = getAxisMaxCal(); value = getAxisMaxCal();
} } else if (throttle == static_cast<int>(PositiveThrottle))
else if (throttle == static_cast<int>(PositiveThrottle))
{ {
value = getAxisMinCal(); value = getAxisMinCal();
} } else if (throttle == static_cast<int>(PositiveHalfThrottle))
else if (throttle == static_cast<int>(PositiveHalfThrottle))
{ {
value = 0; value = 0;
} }
@@ -1198,32 +1168,14 @@ void JoyAxis::eventReset()
paxisbutton->eventReset(); paxisbutton->eventReset();
} }
void JoyAxis::setAxisMinCal(int value) { void JoyAxis::setAxisMinCal(int value) { axis_min_cal = value; }
axis_min_cal = value; int JoyAxis::getAxisMinCal() { return ((axis_min_cal != -1) ? axis_min_cal : GlobalVariables::JoyAxis::AXISMIN); }
}
int JoyAxis::getAxisMinCal() { void JoyAxis::setAxisMaxCal(int value) { axis_max_cal = value; }
return ((axis_min_cal != -1) ? axis_min_cal : GlobalVariables::JoyAxis::AXISMIN); int JoyAxis::getAxisMaxCal() { return ((axis_max_cal != -1) ? axis_max_cal : GlobalVariables::JoyAxis::AXISMAX); }
}
void JoyAxis::setAxisMaxCal(int value) { void JoyAxis::setAxisCenterCal(int value) { axis_center_cal = value; }
axis_max_cal = value; int JoyAxis::getAxisCenterCal() { return ((axis_center_cal != -1) ? axis_center_cal : 0); }
}
int JoyAxis::getAxisMaxCal() {
return ((axis_max_cal != -1) ? axis_max_cal : GlobalVariables::JoyAxis::AXISMAX);
}
void JoyAxis::setAxisCenterCal(int value) {
axis_center_cal = value;
}
int JoyAxis::getAxisCenterCal() {
return((axis_center_cal != -1) ? axis_center_cal : 0);
}

View File

@@ -16,12 +16,11 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef JOYAXIS_H #ifndef JOYAXIS_H
#define JOYAXIS_H #define JOYAXIS_H
#include <QObject>
#include <QList> #include <QList>
#include <QObject>
#include "joybuttontypes/joyaxisbutton.h" #include "joybuttontypes/joyaxisbutton.h"
@@ -32,16 +31,16 @@ class QXmlStreamReader;
class QXmlStreamWriter; class QXmlStreamWriter;
class JoyAxis; class JoyAxis;
class JoyAxis : public QObject class JoyAxis : public QObject
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit JoyAxis(int index, int originset, SetJoystick *parentSet, QObject *parent=0); explicit JoyAxis(int index, int originset, SetJoystick *parentSet, QObject *parent = 0);
~JoyAxis(); ~JoyAxis();
enum ThrottleTypes { enum ThrottleTypes
{
NegativeHalfThrottle = -2, NegativeHalfThrottle = -2,
NegativeThrottle = -1, NegativeThrottle = -1,
NormalThrottle = 0, NormalThrottle = 0,
@@ -49,15 +48,15 @@ public:
PositiveHalfThrottle = 2 PositiveHalfThrottle = 2
}; };
void joyEvent(int value, bool ignoresets=false, bool updateLastValues=true); // JoyAxisEvent class void joyEvent(int value, bool ignoresets = false, bool updateLastValues = true); // JoyAxisEvent class
void queuePendingEvent(int value, bool ignoresets=false, bool updateLastValues=true); // JoyAxisEvent class void queuePendingEvent(int value, bool ignoresets = false, bool updateLastValues = true); // JoyAxisEvent class
void activatePendingEvent(); // JoyAxisEvent class void activatePendingEvent(); // JoyAxisEvent class
bool hasPendingEvent(); // JoyAxisEvent class bool hasPendingEvent(); // JoyAxisEvent class
void clearPendingEvent(); // JoyAxisEvent class void clearPendingEvent(); // JoyAxisEvent class
bool inDeadZone(int value); bool inDeadZone(int value);
virtual QString getName(bool forceFullFormat=false, bool displayNames=false); virtual QString getName(bool forceFullFormat = false, bool displayNames = false);
virtual QString getPartialName(bool forceFullFormat=false, bool displayNames=false); virtual QString getPartialName(bool forceFullFormat = false, bool displayNames = false);
virtual QString getXmlName(); // JoyAxisXml class virtual QString getXmlName(); // JoyAxisXml class
void setIndex(int index); void setIndex(int index);
@@ -78,7 +77,7 @@ public:
int getCurrentRawValue(); int getCurrentRawValue();
int getCurrentThrottledDeadValue(); int getCurrentThrottledDeadValue();
int getCurrentlyAssignedSet(); int getCurrentlyAssignedSet();
JoyAxisButton* getAxisButtonByValue(int value); JoyAxisButton *getAxisButtonByValue(int value);
double getDistanceFromDeadZone(); double getDistanceFromDeadZone();
double getDistanceFromDeadZone(int value); double getDistanceFromDeadZone(int value);
@@ -87,7 +86,7 @@ public:
void setControlStick(JoyControlStick *stick); void setControlStick(JoyControlStick *stick);
void removeControlStick(bool performRelease = true); void removeControlStick(bool performRelease = true);
bool isPartControlStick(); bool isPartControlStick();
JoyControlStick* getControlStick(); JoyControlStick *getControlStick();
bool hasControlOfButtons(); bool hasControlOfButtons();
void removeVDPads(); void removeVDPads();
@@ -130,7 +129,7 @@ public:
virtual void setDefaultAxisName(QString tempname); virtual void setDefaultAxisName(QString tempname);
virtual QString getDefaultAxisName(); virtual QString getDefaultAxisName();
SetJoystick* getParentSet(); SetJoystick *getParentSet();
virtual bool isDefault(); virtual bool isDefault();
@@ -154,12 +153,12 @@ public:
static const ThrottleTypes DEFAULTTHROTTLE; static const ThrottleTypes DEFAULTTHROTTLE;
int calculateThrottledValue(int value); int calculateThrottledValue(int value);
protected: protected:
void createDeskEvent(bool ignoresets = false); // JoyAxisEvent class void createDeskEvent(bool ignoresets = false); // JoyAxisEvent class
void adjustRange(); void adjustRange();
void performCalibration(int value); void performCalibration(int value);
void stickPassEvent(int value, bool ignoresets=false, bool updateLastValues=true); // JoyAxisEvent class void stickPassEvent(int value, bool ignoresets = false, bool updateLastValues = true); // JoyAxisEvent class
JoyAxisButton *paxisbutton; JoyAxisButton *paxisbutton;
JoyAxisButton *naxisbutton; JoyAxisButton *naxisbutton;
@@ -189,9 +188,9 @@ protected:
JoyAxisButton *activeButton; JoyAxisButton *activeButton;
// TODO: CHECK IF PROPERTY IS NEEDED. // TODO: CHECK IF PROPERTY IS NEEDED.
//bool pendingUpdateLastValues; // bool pendingUpdateLastValues;
signals: signals:
void active(int value); void active(int value);
void released(int value); void released(int value);
void moved(int value); void moved(int value);
@@ -200,10 +199,10 @@ signals:
void axisNameChanged(); void axisNameChanged();
void propertyUpdated(); void propertyUpdated();
public slots: public slots:
virtual void reset(); virtual void reset();
virtual void reset(int index); virtual void reset(int index);
void propogateThrottleChange(); void propogateThrottleChange();
void setDeadZone(int value); void setDeadZone(int value);
void setMaxZoneValue(int value); void setMaxZoneValue(int value);
@@ -214,15 +213,13 @@ public slots:
void establishPropertyUpdatedConnection(); void establishPropertyUpdatedConnection();
void disconnectPropertyUpdatedConnection(); void disconnectPropertyUpdatedConnection();
private: private:
int m_originset; int m_originset;
JoyControlStick *m_stick; JoyControlStick *m_stick;
SetJoystick *m_parentSet; SetJoystick *m_parentSet;
void resetPrivateVars(); void resetPrivateVars();
}; };

View File

@@ -18,19 +18,19 @@
#include "joyaxiscontextmenu.h" #include "joyaxiscontextmenu.h"
#include "antkeymapper.h"
#include "common.h"
#include "inputdevice.h"
#include "joyaxis.h"
#include "messagehandler.h" #include "messagehandler.h"
#include "mousedialog/mouseaxissettingsdialog.h" #include "mousedialog/mouseaxissettingsdialog.h"
#include "antkeymapper.h"
#include "inputdevice.h"
#include "common.h"
#include "joyaxis.h"
#include <QWidget>
#include <QDebug> #include <QDebug>
#include <QWidget>
JoyAxisContextMenu::JoyAxisContextMenu(JoyAxis *axis, QWidget *parent) : JoyAxisContextMenu::JoyAxisContextMenu(JoyAxis *axis, QWidget *parent)
QMenu(parent), : QMenu(parent)
helper(axis) , helper(axis)
{ {
qInstallMessageHandler(MessageHandler::myMessageOutput); qInstallMessageHandler(MessageHandler::myMessageOutput);
@@ -56,8 +56,10 @@ void JoyAxisContextMenu::buildMenu()
PadderCommon::inputDaemonMutex.unlock(); PadderCommon::inputDaemonMutex.unlock();
if (actAsTrigger)buildTriggerMenu(); if (actAsTrigger)
else buildAxisMenu(); buildTriggerMenu();
else
buildAxisMenu();
} }
void JoyAxisContextMenu::buildAxisMenu() void JoyAxisContextMenu::buildAxisMenu()
@@ -70,131 +72,109 @@ void JoyAxisContextMenu::buildAxisMenu()
QAction *action = this->addAction(tr("Mouse (Horizontal)")); QAction *action = this->addAction(tr("Mouse (Horizontal)"));
action->setCheckable(true); action->setCheckable(true);
action->setChecked(currentPreset == presetMode+1); action->setChecked(currentPreset == presetMode + 1);
action->setData(QVariant(presetMode)); action->setData(QVariant(presetMode));
connect(action, &QAction::triggered, this, [this, action]() { connect(action, &QAction::triggered, this, [this, action]() { setAxisPreset(action); });
setAxisPreset(action);
});
presetGroup->addAction(action); presetGroup->addAction(action);
presetMode++; presetMode++;
action = this->addAction(tr("Mouse (Inverted Horizontal)")); action = this->addAction(tr("Mouse (Inverted Horizontal)"));
action->setCheckable(true); action->setCheckable(true);
action->setChecked(currentPreset == presetMode+1); action->setChecked(currentPreset == presetMode + 1);
action->setData(QVariant(presetMode)); action->setData(QVariant(presetMode));
connect(action, &QAction::triggered, this, [this, action]() { connect(action, &QAction::triggered, this, [this, action]() { setAxisPreset(action); });
setAxisPreset(action);
});
presetGroup->addAction(action); presetGroup->addAction(action);
presetMode++; presetMode++;
action = this->addAction(tr("Mouse (Vertical)")); action = this->addAction(tr("Mouse (Vertical)"));
action->setCheckable(true); action->setCheckable(true);
action->setChecked(currentPreset == presetMode+1); action->setChecked(currentPreset == presetMode + 1);
action->setData(QVariant(presetMode)); action->setData(QVariant(presetMode));
connect(action, &QAction::triggered, this, [this, action]() { connect(action, &QAction::triggered, this, [this, action]() { setAxisPreset(action); });
setAxisPreset(action);
});
presetGroup->addAction(action); presetGroup->addAction(action);
presetMode++; presetMode++;
action = this->addAction(tr("Mouse (Inverted Vertical)")); action = this->addAction(tr("Mouse (Inverted Vertical)"));
action->setCheckable(true); action->setCheckable(true);
action->setChecked(currentPreset == presetMode+1); action->setChecked(currentPreset == presetMode + 1);
action->setData(QVariant(presetMode)); action->setData(QVariant(presetMode));
connect(action, &QAction::triggered, this, [this, action]() { connect(action, &QAction::triggered, this, [this, action]() { setAxisPreset(action); });
setAxisPreset(action);
});
presetGroup->addAction(action); presetGroup->addAction(action);
presetMode++; presetMode++;
action = this->addAction(tr("Arrows: Up | Down")); action = this->addAction(tr("Arrows: Up | Down"));
action->setCheckable(true); action->setCheckable(true);
action->setChecked(currentPreset == presetMode+1); action->setChecked(currentPreset == presetMode + 1);
action->setData(QVariant(presetMode)); action->setData(QVariant(presetMode));
connect(action, &QAction::triggered, this, [this, action]() { connect(action, &QAction::triggered, this, [this, action]() { setAxisPreset(action); });
setAxisPreset(action);
});
presetGroup->addAction(action); presetGroup->addAction(action);
presetMode++; presetMode++;
action = this->addAction(tr("Arrows: Left | Right")); action = this->addAction(tr("Arrows: Left | Right"));
action->setCheckable(true); action->setCheckable(true);
action->setChecked(currentPreset == presetMode+1); action->setChecked(currentPreset == presetMode + 1);
action->setData(QVariant(presetMode)); action->setData(QVariant(presetMode));
connect(action, &QAction::triggered, this, [this, action]() { connect(action, &QAction::triggered, this, [this, action]() { setAxisPreset(action); });
setAxisPreset(action);
});
presetGroup->addAction(action); presetGroup->addAction(action);
presetMode++; presetMode++;
action = this->addAction(tr("Keys: W | S")); action = this->addAction(tr("Keys: W | S"));
action->setCheckable(true); action->setCheckable(true);
action->setChecked(currentPreset == presetMode+1); action->setChecked(currentPreset == presetMode + 1);
action->setData(QVariant(presetMode)); action->setData(QVariant(presetMode));
connect(action, &QAction::triggered, this, [this, action]() { connect(action, &QAction::triggered, this, [this, action]() { setAxisPreset(action); });
setAxisPreset(action);
});
presetGroup->addAction(action); presetGroup->addAction(action);
presetMode++; presetMode++;
action = this->addAction(tr("Keys: A | D")); action = this->addAction(tr("Keys: A | D"));
action->setCheckable(true); action->setCheckable(true);
action->setChecked(currentPreset == presetMode+1); action->setChecked(currentPreset == presetMode + 1);
action->setData(QVariant(presetMode)); action->setData(QVariant(presetMode));
connect(action, &QAction::triggered, this, [this, action]() { connect(action, &QAction::triggered, this, [this, action]() { setAxisPreset(action); });
setAxisPreset(action);
});
presetGroup->addAction(action); presetGroup->addAction(action);
presetMode++; presetMode++;
action = this->addAction(tr("NumPad: KP_8 | KP_2")); action = this->addAction(tr("NumPad: KP_8 | KP_2"));
action->setCheckable(true); action->setCheckable(true);
action->setChecked(currentPreset == presetMode+1); action->setChecked(currentPreset == presetMode + 1);
action->setData(QVariant(presetMode)); action->setData(QVariant(presetMode));
connect(action, &QAction::triggered, this, [this, action]() { connect(action, &QAction::triggered, this, [this, action]() { setAxisPreset(action); });
setAxisPreset(action);
});
presetGroup->addAction(action); presetGroup->addAction(action);
presetMode++; presetMode++;
action = this->addAction(tr("NumPad: KP_4 | KP_6")); action = this->addAction(tr("NumPad: KP_4 | KP_6"));
action->setCheckable(true); action->setCheckable(true);
action->setChecked(currentPreset == presetMode+1); action->setChecked(currentPreset == presetMode + 1);
action->setData(QVariant(presetMode)); action->setData(QVariant(presetMode));
connect(action, &QAction::triggered, this, [this, action]() { connect(action, &QAction::triggered, this, [this, action]() { setAxisPreset(action); });
setAxisPreset(action);
});
presetGroup->addAction(action); presetGroup->addAction(action);
presetMode++; presetMode++;
action = this->addAction(tr("None")); action = this->addAction(tr("None"));
action->setCheckable(true); action->setCheckable(true);
action->setChecked(currentPreset == presetMode+1); action->setChecked(currentPreset == presetMode + 1);
action->setData(QVariant(presetMode)); action->setData(QVariant(presetMode));
connect(action, &QAction::triggered, this, [this, action]() { connect(action, &QAction::triggered, this, [this, action]() { setAxisPreset(action); });
setAxisPreset(action);
});
presetGroup->addAction(action); presetGroup->addAction(action);
@@ -212,67 +192,76 @@ int JoyAxisContextMenu::getPresetIndex()
int result = 0; int result = 0;
JoyAxisButton *naxisbutton = axis->getNAxisButton(); JoyAxisButton *naxisbutton = axis->getNAxisButton();
QList<JoyButtonSlot*> *naxisslots = naxisbutton->getAssignedSlots(); QList<JoyButtonSlot *> *naxisslots = naxisbutton->getAssignedSlots();
JoyAxisButton *paxisbutton = axis->getPAxisButton(); JoyAxisButton *paxisbutton = axis->getPAxisButton();
QList<JoyButtonSlot*> *paxisslots = paxisbutton->getAssignedSlots(); QList<JoyButtonSlot *> *paxisslots = paxisbutton->getAssignedSlots();
if ((naxisslots->length() == 1) && (paxisslots->length() == 1)) if ((naxisslots->length() == 1) && (paxisslots->length() == 1))
{ {
JoyButtonSlot *nslot = naxisslots->at(0); JoyButtonSlot *nslot = naxisslots->at(0);
JoyButtonSlot *pslot = paxisslots->at(0); JoyButtonSlot *pslot = paxisslots->at(0);
if ((nslot->getSlotMode() == JoyButtonSlot::JoyMouseMovement) && (nslot->getSlotCode() == JoyButtonSlot::MouseLeft) && if ((nslot->getSlotMode() == JoyButtonSlot::JoyMouseMovement) &&
(nslot->getSlotCode() == JoyButtonSlot::MouseLeft) &&
(pslot->getSlotMode() == JoyButtonSlot::JoyMouseMovement) && (pslot->getSlotCode() == JoyButtonSlot::MouseRight)) (pslot->getSlotMode() == JoyButtonSlot::JoyMouseMovement) && (pslot->getSlotCode() == JoyButtonSlot::MouseRight))
{ {
result = 1; result = 1;
} } else if ((nslot->getSlotMode() == JoyButtonSlot::JoyMouseMovement) &&
else if ((nslot->getSlotMode() == JoyButtonSlot::JoyMouseMovement) && (nslot->getSlotCode() == JoyButtonSlot::MouseRight) && (nslot->getSlotCode() == JoyButtonSlot::MouseRight) &&
(pslot->getSlotMode() == JoyButtonSlot::JoyMouseMovement) && (pslot->getSlotCode() == JoyButtonSlot::MouseLeft)) (pslot->getSlotMode() == JoyButtonSlot::JoyMouseMovement) &&
(pslot->getSlotCode() == JoyButtonSlot::MouseLeft))
{ {
result = 2; result = 2;
} } else if ((nslot->getSlotMode() == JoyButtonSlot::JoyMouseMovement) &&
else if ((nslot->getSlotMode() == JoyButtonSlot::JoyMouseMovement) && (nslot->getSlotCode() == JoyButtonSlot::MouseUp) && (nslot->getSlotCode() == JoyButtonSlot::MouseUp) &&
(pslot->getSlotMode() == JoyButtonSlot::JoyMouseMovement) && (pslot->getSlotCode() == JoyButtonSlot::MouseDown)) (pslot->getSlotMode() == JoyButtonSlot::JoyMouseMovement) &&
(pslot->getSlotCode() == JoyButtonSlot::MouseDown))
{ {
result = 3; result = 3;
} } else if ((nslot->getSlotMode() == JoyButtonSlot::JoyMouseMovement) &&
else if ((nslot->getSlotMode() == JoyButtonSlot::JoyMouseMovement) && (nslot->getSlotCode() == JoyButtonSlot::MouseDown) && (nslot->getSlotCode() == JoyButtonSlot::MouseDown) &&
(pslot->getSlotMode() == JoyButtonSlot::JoyMouseMovement) && (pslot->getSlotCode() == JoyButtonSlot::MouseUp)) (pslot->getSlotMode() == JoyButtonSlot::JoyMouseMovement) &&
(pslot->getSlotCode() == JoyButtonSlot::MouseUp))
{ {
result = 4; result = 4;
} } else if ((nslot->getSlotMode() == JoyButtonSlot::JoyKeyboard) &&
else if ((nslot->getSlotMode() == JoyButtonSlot::JoyKeyboard) && (nslot->getSlotCode() == AntKeyMapper::getInstance()->returnVirtualKey(Qt::Key_Up)) && (nslot->getSlotCode() == AntKeyMapper::getInstance()->returnVirtualKey(Qt::Key_Up)) &&
(pslot->getSlotMode() == JoyButtonSlot::JoyKeyboard) && (pslot->getSlotCode() == AntKeyMapper::getInstance()->returnVirtualKey(Qt::Key_Down))) (pslot->getSlotMode() == JoyButtonSlot::JoyKeyboard) &&
(pslot->getSlotCode() == AntKeyMapper::getInstance()->returnVirtualKey(Qt::Key_Down)))
{ {
result = 5; result = 5;
} } else if ((nslot->getSlotMode() == JoyButtonSlot::JoyKeyboard) &&
else if ((nslot->getSlotMode() == JoyButtonSlot::JoyKeyboard) && (nslot->getSlotCode() == AntKeyMapper::getInstance()->returnVirtualKey(Qt::Key_Left)) && (nslot->getSlotCode() == AntKeyMapper::getInstance()->returnVirtualKey(Qt::Key_Left)) &&
(pslot->getSlotMode() == JoyButtonSlot::JoyKeyboard) && (pslot->getSlotCode() == AntKeyMapper::getInstance()->returnVirtualKey(Qt::Key_Right))) (pslot->getSlotMode() == JoyButtonSlot::JoyKeyboard) &&
(pslot->getSlotCode() == AntKeyMapper::getInstance()->returnVirtualKey(Qt::Key_Right)))
{ {
result = 6; result = 6;
} } else if ((nslot->getSlotMode() == JoyButtonSlot::JoyKeyboard) &&
else if ((nslot->getSlotMode() == JoyButtonSlot::JoyKeyboard) && (nslot->getSlotCode() == AntKeyMapper::getInstance()->returnVirtualKey(Qt::Key_W)) && (nslot->getSlotCode() == AntKeyMapper::getInstance()->returnVirtualKey(Qt::Key_W)) &&
(pslot->getSlotMode() == JoyButtonSlot::JoyKeyboard) && (pslot->getSlotCode() == AntKeyMapper::getInstance()->returnVirtualKey(Qt::Key_S))) (pslot->getSlotMode() == JoyButtonSlot::JoyKeyboard) &&
(pslot->getSlotCode() == AntKeyMapper::getInstance()->returnVirtualKey(Qt::Key_S)))
{ {
result = 7; result = 7;
} } else if ((nslot->getSlotMode() == JoyButtonSlot::JoyKeyboard) &&
else if ((nslot->getSlotMode() == JoyButtonSlot::JoyKeyboard) && (nslot->getSlotCode() == AntKeyMapper::getInstance()->returnVirtualKey(Qt::Key_A)) && (nslot->getSlotCode() == AntKeyMapper::getInstance()->returnVirtualKey(Qt::Key_A)) &&
(pslot->getSlotMode() == JoyButtonSlot::JoyKeyboard) && (pslot->getSlotCode() == AntKeyMapper::getInstance()->returnVirtualKey(Qt::Key_D))) (pslot->getSlotMode() == JoyButtonSlot::JoyKeyboard) &&
(pslot->getSlotCode() == AntKeyMapper::getInstance()->returnVirtualKey(Qt::Key_D)))
{ {
result = 8; result = 8;
} } else if ((nslot->getSlotMode() == JoyButtonSlot::JoyKeyboard) &&
else if ((nslot->getSlotMode() == JoyButtonSlot::JoyKeyboard) && (nslot->getSlotCode() == AntKeyMapper::getInstance()->returnVirtualKey(QtKeyMapperBase::AntKey_KP_8)) && (nslot->getSlotCode() == AntKeyMapper::getInstance()->returnVirtualKey(QtKeyMapperBase::AntKey_KP_8)) &&
(pslot->getSlotMode() == JoyButtonSlot::JoyKeyboard) && (pslot->getSlotCode() == AntKeyMapper::getInstance()->returnVirtualKey(QtKeyMapperBase::AntKey_KP_2))) (pslot->getSlotMode() == JoyButtonSlot::JoyKeyboard) &&
(pslot->getSlotCode() == AntKeyMapper::getInstance()->returnVirtualKey(QtKeyMapperBase::AntKey_KP_2)))
{ {
result = 9; result = 9;
} } else if ((nslot->getSlotMode() == JoyButtonSlot::JoyKeyboard) &&
else if ((nslot->getSlotMode() == JoyButtonSlot::JoyKeyboard) && (nslot->getSlotCode() == AntKeyMapper::getInstance()->returnVirtualKey(QtKeyMapperBase::AntKey_KP_4)) && (nslot->getSlotCode() == AntKeyMapper::getInstance()->returnVirtualKey(QtKeyMapperBase::AntKey_KP_4)) &&
(pslot->getSlotMode() == JoyButtonSlot::JoyKeyboard) && (pslot->getSlotCode() == AntKeyMapper::getInstance()->returnVirtualKey(QtKeyMapperBase::AntKey_KP_6))) (pslot->getSlotMode() == JoyButtonSlot::JoyKeyboard) &&
(pslot->getSlotCode() == AntKeyMapper::getInstance()->returnVirtualKey(QtKeyMapperBase::AntKey_KP_6)))
{ {
result = 10; result = 10;
} }
} } else if ((naxisslots->length() == 0) && (paxisslots->length() == 0))
else if ((naxisslots->length() == 0) && (paxisslots->length() == 0))
{ {
result = 11; result = 11;
} }
@@ -282,7 +271,7 @@ int JoyAxisContextMenu::getPresetIndex()
return result; return result;
} }
void JoyAxisContextMenu::setAxisPreset(QAction* action) void JoyAxisContextMenu::setAxisPreset(QAction *action)
{ {
qInstallMessageHandler(MessageHandler::myMessageOutput); qInstallMessageHandler(MessageHandler::myMessageOutput);
@@ -291,68 +280,79 @@ void JoyAxisContextMenu::setAxisPreset(QAction* action)
JoyButtonSlot *nbuttonslot = nullptr; JoyButtonSlot *nbuttonslot = nullptr;
JoyButtonSlot *pbuttonslot = nullptr; JoyButtonSlot *pbuttonslot = nullptr;
switch(item) switch (item)
{ {
case 0: case 0:
nbuttonslot = new JoyButtonSlot(JoyButtonSlot::MouseLeft, JoyButtonSlot::JoyMouseMovement, this); nbuttonslot = new JoyButtonSlot(JoyButtonSlot::MouseLeft, JoyButtonSlot::JoyMouseMovement, this);
pbuttonslot = new JoyButtonSlot(JoyButtonSlot::MouseRight, JoyButtonSlot::JoyMouseMovement, this); pbuttonslot = new JoyButtonSlot(JoyButtonSlot::MouseRight, JoyButtonSlot::JoyMouseMovement, this);
break; break;
case 1: case 1:
nbuttonslot = new JoyButtonSlot(JoyButtonSlot::MouseRight, JoyButtonSlot::JoyMouseMovement, this); nbuttonslot = new JoyButtonSlot(JoyButtonSlot::MouseRight, JoyButtonSlot::JoyMouseMovement, this);
pbuttonslot = new JoyButtonSlot(JoyButtonSlot::MouseLeft, JoyButtonSlot::JoyMouseMovement, this); pbuttonslot = new JoyButtonSlot(JoyButtonSlot::MouseLeft, JoyButtonSlot::JoyMouseMovement, this);
break; break;
case 2: case 2:
nbuttonslot = new JoyButtonSlot(JoyButtonSlot::MouseUp, JoyButtonSlot::JoyMouseMovement, this); nbuttonslot = new JoyButtonSlot(JoyButtonSlot::MouseUp, JoyButtonSlot::JoyMouseMovement, this);
pbuttonslot = new JoyButtonSlot(JoyButtonSlot::MouseDown, JoyButtonSlot::JoyMouseMovement, this); pbuttonslot = new JoyButtonSlot(JoyButtonSlot::MouseDown, JoyButtonSlot::JoyMouseMovement, this);
break; break;
case 3: case 3:
nbuttonslot = new JoyButtonSlot(JoyButtonSlot::MouseDown, JoyButtonSlot::JoyMouseMovement, this); nbuttonslot = new JoyButtonSlot(JoyButtonSlot::MouseDown, JoyButtonSlot::JoyMouseMovement, this);
pbuttonslot = new JoyButtonSlot(JoyButtonSlot::MouseUp, JoyButtonSlot::JoyMouseMovement, this); pbuttonslot = new JoyButtonSlot(JoyButtonSlot::MouseUp, JoyButtonSlot::JoyMouseMovement, this);
break; break;
case 4: case 4:
nbuttonslot = new JoyButtonSlot(AntKeyMapper::getInstance()->returnVirtualKey(Qt::Key_Up), Qt::Key_Up, JoyButtonSlot::JoyKeyboard, this); nbuttonslot = new JoyButtonSlot(AntKeyMapper::getInstance()->returnVirtualKey(Qt::Key_Up), Qt::Key_Up,
pbuttonslot = new JoyButtonSlot(AntKeyMapper::getInstance()->returnVirtualKey(Qt::Key_Down), Qt::Key_Down, JoyButtonSlot::JoyKeyboard, this); JoyButtonSlot::JoyKeyboard, this);
pbuttonslot = new JoyButtonSlot(AntKeyMapper::getInstance()->returnVirtualKey(Qt::Key_Down), Qt::Key_Down,
JoyButtonSlot::JoyKeyboard, this);
break; break;
case 5: case 5:
nbuttonslot = new JoyButtonSlot(AntKeyMapper::getInstance()->returnVirtualKey(Qt::Key_Left), Qt::Key_Left, JoyButtonSlot::JoyKeyboard, this); nbuttonslot = new JoyButtonSlot(AntKeyMapper::getInstance()->returnVirtualKey(Qt::Key_Left), Qt::Key_Left,
pbuttonslot = new JoyButtonSlot(AntKeyMapper::getInstance()->returnVirtualKey(Qt::Key_Right), Qt::Key_Right, JoyButtonSlot::JoyKeyboard, this); JoyButtonSlot::JoyKeyboard, this);
pbuttonslot = new JoyButtonSlot(AntKeyMapper::getInstance()->returnVirtualKey(Qt::Key_Right), Qt::Key_Right,
JoyButtonSlot::JoyKeyboard, this);
break; break;
case 6: case 6:
nbuttonslot = new JoyButtonSlot(AntKeyMapper::getInstance()->returnVirtualKey(Qt::Key_W), Qt::Key_W, JoyButtonSlot::JoyKeyboard, this); nbuttonslot = new JoyButtonSlot(AntKeyMapper::getInstance()->returnVirtualKey(Qt::Key_W), Qt::Key_W,
pbuttonslot = new JoyButtonSlot(AntKeyMapper::getInstance()->returnVirtualKey(Qt::Key_S), Qt::Key_S, JoyButtonSlot::JoyKeyboard, this); JoyButtonSlot::JoyKeyboard, this);
pbuttonslot = new JoyButtonSlot(AntKeyMapper::getInstance()->returnVirtualKey(Qt::Key_S), Qt::Key_S,
JoyButtonSlot::JoyKeyboard, this);
break; break;
case 7: case 7:
nbuttonslot = new JoyButtonSlot(AntKeyMapper::getInstance()->returnVirtualKey(Qt::Key_A), Qt::Key_A, JoyButtonSlot::JoyKeyboard, this); nbuttonslot = new JoyButtonSlot(AntKeyMapper::getInstance()->returnVirtualKey(Qt::Key_A), Qt::Key_A,
pbuttonslot = new JoyButtonSlot(AntKeyMapper::getInstance()->returnVirtualKey(Qt::Key_D), Qt::Key_D, JoyButtonSlot::JoyKeyboard, this); JoyButtonSlot::JoyKeyboard, this);
pbuttonslot = new JoyButtonSlot(AntKeyMapper::getInstance()->returnVirtualKey(Qt::Key_D), Qt::Key_D,
JoyButtonSlot::JoyKeyboard, this);
break; break;
case 8: case 8:
nbuttonslot = new JoyButtonSlot(AntKeyMapper::getInstance()->returnVirtualKey(QtKeyMapperBase::AntKey_KP_8), QtKeyMapperBase::AntKey_KP_8, JoyButtonSlot::JoyKeyboard, this); nbuttonslot = new JoyButtonSlot(AntKeyMapper::getInstance()->returnVirtualKey(QtKeyMapperBase::AntKey_KP_8),
pbuttonslot = new JoyButtonSlot(AntKeyMapper::getInstance()->returnVirtualKey(QtKeyMapperBase::AntKey_KP_2), QtKeyMapperBase::AntKey_KP_2, JoyButtonSlot::JoyKeyboard, this); QtKeyMapperBase::AntKey_KP_8, JoyButtonSlot::JoyKeyboard, this);
pbuttonslot = new JoyButtonSlot(AntKeyMapper::getInstance()->returnVirtualKey(QtKeyMapperBase::AntKey_KP_2),
QtKeyMapperBase::AntKey_KP_2, JoyButtonSlot::JoyKeyboard, this);
break; break;
case 9: case 9:
nbuttonslot = new JoyButtonSlot(AntKeyMapper::getInstance()->returnVirtualKey(QtKeyMapperBase::AntKey_KP_4), QtKeyMapperBase::AntKey_KP_4, JoyButtonSlot::JoyKeyboard, this); nbuttonslot = new JoyButtonSlot(AntKeyMapper::getInstance()->returnVirtualKey(QtKeyMapperBase::AntKey_KP_4),
pbuttonslot = new JoyButtonSlot(AntKeyMapper::getInstance()->returnVirtualKey(QtKeyMapperBase::AntKey_KP_6), QtKeyMapperBase::AntKey_KP_6, JoyButtonSlot::JoyKeyboard, this); QtKeyMapperBase::AntKey_KP_4, JoyButtonSlot::JoyKeyboard, this);
pbuttonslot = new JoyButtonSlot(AntKeyMapper::getInstance()->returnVirtualKey(QtKeyMapperBase::AntKey_KP_6),
QtKeyMapperBase::AntKey_KP_6, JoyButtonSlot::JoyKeyboard, this);
break; break;
case 10: case 10:
QMetaObject::invokeMethod(&helper, "clearAndResetAxisButtons", Qt::BlockingQueuedConnection); QMetaObject::invokeMethod(&helper, "clearAndResetAxisButtons", Qt::BlockingQueuedConnection);
break; break;
} }
if (nbuttonslot != nullptr) if (nbuttonslot != nullptr)
{ {
QMetaObject::invokeMethod(&helper, "setNAssignedSlot", Qt::BlockingQueuedConnection, QMetaObject::invokeMethod(&helper, "setNAssignedSlot", Qt::BlockingQueuedConnection,
Q_ARG(int, nbuttonslot->getSlotCode()), Q_ARG(int, nbuttonslot->getSlotCode()), Q_ARG(int, nbuttonslot->getSlotCodeAlias()),
Q_ARG(int, nbuttonslot->getSlotCodeAlias()),
Q_ARG(JoyButtonSlot::JoySlotInputAction, nbuttonslot->getSlotMode())); Q_ARG(JoyButtonSlot::JoySlotInputAction, nbuttonslot->getSlotMode()));
nbuttonslot->deleteLater(); nbuttonslot->deleteLater();
@@ -361,8 +361,7 @@ void JoyAxisContextMenu::setAxisPreset(QAction* action)
if (pbuttonslot != nullptr) if (pbuttonslot != nullptr)
{ {
QMetaObject::invokeMethod(&helper, "setPAssignedSlot", Qt::BlockingQueuedConnection, QMetaObject::invokeMethod(&helper, "setPAssignedSlot", Qt::BlockingQueuedConnection,
Q_ARG(int, nbuttonslot->getSlotCode()), Q_ARG(int, nbuttonslot->getSlotCode()), Q_ARG(int, nbuttonslot->getSlotCodeAlias()),
Q_ARG(int, nbuttonslot->getSlotCodeAlias()),
Q_ARG(JoyButtonSlot::JoySlotInputAction, nbuttonslot->getSlotMode())); Q_ARG(JoyButtonSlot::JoySlotInputAction, nbuttonslot->getSlotMode()));
pbuttonslot->deleteLater(); pbuttonslot->deleteLater();
@@ -387,36 +386,30 @@ void JoyAxisContextMenu::buildTriggerMenu()
QAction *action = this->addAction(tr("Left Mouse Button")); QAction *action = this->addAction(tr("Left Mouse Button"));
action->setCheckable(true); action->setCheckable(true);
action->setChecked(currentPreset == presetMode+1); action->setChecked(currentPreset == presetMode + 1);
action->setData(QVariant(presetMode)); action->setData(QVariant(presetMode));
connect(action, &QAction::triggered, this, [this, action]() { connect(action, &QAction::triggered, this, [this, action]() { setTriggerPreset(action); });
setTriggerPreset(action);
});
presetGroup->addAction(action); presetGroup->addAction(action);
presetMode++; presetMode++;
action = this->addAction(tr("Right Mouse Button")); action = this->addAction(tr("Right Mouse Button"));
action->setCheckable(true); action->setCheckable(true);
action->setChecked(currentPreset == presetMode+1); action->setChecked(currentPreset == presetMode + 1);
action->setData(QVariant(presetMode)); action->setData(QVariant(presetMode));
connect(action, &QAction::triggered, this, [this, action]() { connect(action, &QAction::triggered, this, [this, action]() { setTriggerPreset(action); });
setTriggerPreset(action);
});
presetGroup->addAction(action); presetGroup->addAction(action);
presetMode++; presetMode++;
action = this->addAction(tr("None")); action = this->addAction(tr("None"));
action->setCheckable(true); action->setCheckable(true);
action->setChecked(currentPreset == presetMode+1); action->setChecked(currentPreset == presetMode + 1);
action->setData(QVariant(presetMode)); action->setData(QVariant(presetMode));
connect(action, &QAction::triggered, this, [this, action]() { connect(action, &QAction::triggered, this, [this, action]() { setTriggerPreset(action); });
setTriggerPreset(action);
});
presetGroup->addAction(action); presetGroup->addAction(action);
@@ -436,24 +429,21 @@ int JoyAxisContextMenu::getTriggerPresetIndex()
PadderCommon::inputDaemonMutex.lock(); PadderCommon::inputDaemonMutex.lock();
JoyAxisButton *paxisbutton = axis->getPAxisButton(); JoyAxisButton *paxisbutton = axis->getPAxisButton();
QList<JoyButtonSlot*> *paxisslots = paxisbutton->getAssignedSlots(); QList<JoyButtonSlot *> *paxisslots = paxisbutton->getAssignedSlots();
if (paxisslots->length() == 1) if (paxisslots->length() == 1)
{ {
JoyButtonSlot *pslot = paxisslots->at(0); JoyButtonSlot *pslot = paxisslots->at(0);
if ((pslot->getSlotMode() == JoyButtonSlot::JoyMouseButton) && if ((pslot->getSlotMode() == JoyButtonSlot::JoyMouseButton) && (pslot->getSlotCode() == JoyButtonSlot::MouseLB))
(pslot->getSlotCode() == JoyButtonSlot::MouseLB))
{ {
result = 1; result = 1;
} } else if ((pslot->getSlotMode() == JoyButtonSlot::JoyMouseButton) &&
else if ((pslot->getSlotMode() == JoyButtonSlot::JoyMouseButton) && (pslot->getSlotCode() == JoyButtonSlot::MouseRB))
(pslot->getSlotCode() == JoyButtonSlot::MouseRB))
{ {
result = 2; result = 2;
} }
} } else if (paxisslots->length() == 0)
else if (paxisslots->length() == 0)
{ {
result = 3; result = 3;
} }
@@ -463,7 +453,7 @@ int JoyAxisContextMenu::getTriggerPresetIndex()
return result; return result;
} }
void JoyAxisContextMenu::setTriggerPreset(QAction* action) void JoyAxisContextMenu::setTriggerPreset(QAction *action)
{ {
qInstallMessageHandler(MessageHandler::myMessageOutput); qInstallMessageHandler(MessageHandler::myMessageOutput);
@@ -471,35 +461,30 @@ void JoyAxisContextMenu::setTriggerPreset(QAction* action)
JoyButtonSlot *pbuttonslot = nullptr; JoyButtonSlot *pbuttonslot = nullptr;
switch(item) switch (item)
{ {
case 0: case 0:
pbuttonslot = new JoyButtonSlot(JoyButtonSlot::MouseLB, JoyButtonSlot::JoyMouseButton, this); pbuttonslot = new JoyButtonSlot(JoyButtonSlot::MouseLB, JoyButtonSlot::JoyMouseButton, this);
break; break;
case 1: case 1:
pbuttonslot = new JoyButtonSlot(JoyButtonSlot::MouseRB, JoyButtonSlot::JoyMouseButton, this); pbuttonslot = new JoyButtonSlot(JoyButtonSlot::MouseRB, JoyButtonSlot::JoyMouseButton, this);
break; break;
case 2: case 2:
JoyAxisButton *pbutton = axis->getPAxisButton(); JoyAxisButton *pbutton = axis->getPAxisButton();
QMetaObject::invokeMethod(pbutton, "clearSlotsEventReset", Qt::BlockingQueuedConnection); QMetaObject::invokeMethod(pbutton, "clearSlotsEventReset", Qt::BlockingQueuedConnection);
break; break;
} }
if (pbuttonslot != nullptr) if (pbuttonslot != nullptr)
{ {
QMetaObject::invokeMethod(&helper, "setPAssignedSlot", Qt::BlockingQueuedConnection, QMetaObject::invokeMethod(&helper, "setPAssignedSlot", Qt::BlockingQueuedConnection,
Q_ARG(int, pbuttonslot->getSlotCode()), Q_ARG(int, pbuttonslot->getSlotCode()), Q_ARG(int, pbuttonslot->getSlotCodeAlias()),
Q_ARG(int, pbuttonslot->getSlotCodeAlias()),
Q_ARG(JoyButtonSlot::JoySlotInputAction, pbuttonslot->getSlotMode())); Q_ARG(JoyButtonSlot::JoySlotInputAction, pbuttonslot->getSlotMode()));
pbuttonslot->deleteLater(); pbuttonslot->deleteLater();
} }
} }
JoyAxisContextMenuHelper& JoyAxisContextMenu::getHelperLocal() { JoyAxisContextMenuHelper &JoyAxisContextMenu::getHelperLocal() { return helper; }
return helper;
}

View File

@@ -16,12 +16,9 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef JOYAXISCONTEXTMENU_H #ifndef JOYAXISCONTEXTMENU_H
#define JOYAXISCONTEXTMENU_H #define JOYAXISCONTEXTMENU_H
#include "uihelpers/joyaxiscontextmenuhelper.h" #include "uihelpers/joyaxiscontextmenuhelper.h"
#include <QMenu> #include <QMenu>
@@ -33,23 +30,23 @@ class JoyAxisContextMenu : public QMenu
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit JoyAxisContextMenu(JoyAxis *axis, QWidget *parent = nullptr); explicit JoyAxisContextMenu(JoyAxis *axis, QWidget *parent = nullptr);
void buildMenu(); void buildMenu();
void buildAxisMenu(); void buildAxisMenu();
void buildTriggerMenu(); void buildTriggerMenu();
protected: protected:
int getPresetIndex(); int getPresetIndex();
int getTriggerPresetIndex(); int getTriggerPresetIndex();
private slots: private slots:
void setAxisPreset(QAction* action); void setAxisPreset(QAction *action);
void setTriggerPreset(QAction* action); void setTriggerPreset(QAction *action);
void openMouseSettingsDialog(); void openMouseSettingsDialog();
private: private:
JoyAxisContextMenuHelper& getHelperLocal(); JoyAxisContextMenuHelper &getHelperLocal();
JoyAxis *axis; JoyAxis *axis;
JoyAxisContextMenuHelper helper; JoyAxisContextMenuHelper helper;

View File

@@ -18,14 +18,14 @@
#include "joyaxiswidget.h" #include "joyaxiswidget.h"
#include "messagehandler.h"
#include "joyaxiscontextmenu.h"
#include "joyaxis.h" #include "joyaxis.h"
#include "joyaxiscontextmenu.h"
#include "messagehandler.h"
#include <QDebug> #include <QDebug>
JoyAxisWidget::JoyAxisWidget(JoyAxis *axis, bool displayNames, QWidget *parent) : JoyAxisWidget::JoyAxisWidget(JoyAxis *axis, bool displayNames, QWidget *parent)
FlashButtonWidget(displayNames, parent) : FlashButtonWidget(displayNames, parent)
{ {
qInstallMessageHandler(MessageHandler::myMessageOutput); qInstallMessageHandler(MessageHandler::myMessageOutput);
@@ -54,7 +54,7 @@ JoyAxisWidget::JoyAxisWidget(JoyAxis *axis, bool displayNames, QWidget *parent)
pAxisButton->establishPropertyUpdatedConnections(); pAxisButton->establishPropertyUpdatedConnections();
} }
JoyAxis* JoyAxisWidget::getAxis() const JoyAxis *JoyAxisWidget::getAxis() const
{ {
qInstallMessageHandler(MessageHandler::myMessageOutput); qInstallMessageHandler(MessageHandler::myMessageOutput);
@@ -88,7 +88,7 @@ QString JoyAxisWidget::generateLabel()
QString temp = m_axis->getName(false, ifDisplayNames()).replace("&", "&&"); QString temp = m_axis->getName(false, ifDisplayNames()).replace("&", "&&");
qDebug() << "Name of joy axis is: " << temp; qDebug() << "Name of joy axis is: " << temp;
return temp; return temp;
} }

View File

@@ -16,7 +16,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef JOYAXISWIDGET_H #ifndef JOYAXISWIDGET_H
#define JOYAXISWIDGET_H #define JOYAXISWIDGET_H
@@ -25,28 +24,27 @@
class JoyAxis; class JoyAxis;
class QWidget; class QWidget;
class JoyAxisWidget : public FlashButtonWidget class JoyAxisWidget : public FlashButtonWidget
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit JoyAxisWidget(JoyAxis *axis, bool displayNames, QWidget *parent=0); explicit JoyAxisWidget(JoyAxis *axis, bool displayNames, QWidget *parent = 0);
JoyAxis* getAxis() const; JoyAxis *getAxis() const;
void tryFlash(); void tryFlash();
protected: protected:
virtual QString generateLabel() override; virtual QString generateLabel() override;
public slots: public slots:
void disableFlashes() override; void disableFlashes() override;
void enableFlashes() override; void enableFlashes() override;
private slots: private slots:
void showContextMenu(const QPoint &point); void showContextMenu(const QPoint &point);
private: private:
JoyAxis *m_axis; JoyAxis *m_axis;
}; };

View File

File diff suppressed because it is too large Load Diff

View File

@@ -16,51 +16,73 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef JOYBUTTON_H #ifndef JOYBUTTON_H
#define JOYBUTTON_H #define JOYBUTTON_H
#include "joybuttonslot.h"
#include "globalvariables.h" #include "globalvariables.h"
#include "springmousemoveinfo.h"
#include "joybuttonmousehelper.h" #include "joybuttonmousehelper.h"
#include "joybuttonslot.h"
#include "springmousemoveinfo.h"
#include <QThread> #include <QDeadlineTimer>
#include <QTimer>
#include <QQueue> #include <QQueue>
#include <QReadWriteLock> #include <QReadWriteLock>
#include <QRunnable> #include <QRunnable>
#include <QDeadlineTimer> #include <QThread>
#include <QTimer>
class VDPad; class VDPad;
class SetJoystick; class SetJoystick;
class QXmlStreamReader; class QXmlStreamReader;
class QXmlStreamWriter; class QXmlStreamWriter;
//class QThread; // class QThread;
class QThreadPool; class QThreadPool;
class JoyButton : public QObject class JoyButton : public QObject
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit JoyButton(int index, int originset, SetJoystick *parentSet, QObject *parent=0); explicit JoyButton(int index, int originset, SetJoystick *parentSet, QObject *parent = 0);
~JoyButton(); ~JoyButton();
enum SetChangeCondition {SetChangeDisabled=0, SetChangeOneWay, enum SetChangeCondition
SetChangeTwoWay, SetChangeWhileHeld}; {
SetChangeDisabled = 0,
SetChangeOneWay,
SetChangeTwoWay,
SetChangeWhileHeld
};
enum JoyMouseMovementMode {MouseCursor=0, MouseSpring}; enum JoyMouseMovementMode
enum JoyMouseCurve {EnhancedPrecisionCurve=0, LinearCurve, QuadraticCurve, {
CubicCurve, QuadraticExtremeCurve, PowerCurve, MouseCursor = 0,
EasingQuadraticCurve, EasingCubicCurve}; MouseSpring
enum JoyExtraAccelerationCurve {LinearAccelCurve, EaseOutSineCurve, };
EaseOutQuadAccelCurve, EaseOutCubicAccelCurve}; enum JoyMouseCurve
enum TurboMode {NormalTurbo=0, GradientTurbo, PulseTurbo}; {
EnhancedPrecisionCurve = 0,
LinearCurve,
QuadraticCurve,
CubicCurve,
QuadraticExtremeCurve,
PowerCurve,
EasingQuadraticCurve,
EasingCubicCurve
};
enum JoyExtraAccelerationCurve
{
LinearAccelCurve,
EaseOutSineCurve,
EaseOutQuadAccelCurve,
EaseOutCubicAccelCurve
};
enum TurboMode
{
NormalTurbo = 0,
GradientTurbo,
PulseTurbo
};
typedef struct _mouseCursorInfo typedef struct _mouseCursorInfo
{ {
@@ -68,9 +90,9 @@ public:
double code; double code;
} mouseCursorInfo; } mouseCursorInfo;
void joyEvent(bool pressed, bool ignoresets=false); // JoyButtonEvents class void joyEvent(bool pressed, bool ignoresets = false); // JoyButtonEvents class
void queuePendingEvent(bool pressed, bool ignoresets=false); // JoyButtonEvents class void queuePendingEvent(bool pressed, bool ignoresets = false); // JoyButtonEvents class
void activatePendingEvent(); // JoyButtonEvents class void activatePendingEvent(); // JoyButtonEvents class
void setJoyNumber(int index); void setJoyNumber(int index);
void clearPendingEvent(); // JoyButtonEvents class void clearPendingEvent(); // JoyButtonEvents class
void setCustomName(QString name); void setCustomName(QString name);
@@ -93,8 +115,8 @@ public:
void setAccelExtraDuration(double value); void setAccelExtraDuration(double value);
void setStartAccelMultiplier(double value); void setStartAccelMultiplier(double value);
void setMaxAccelThreshold(double value); void setMaxAccelThreshold(double value);
void setChangeSetSelection(int index, bool updateActiveString=true); void setChangeSetSelection(int index, bool updateActiveString = true);
void activateMiniSlots(JoyButtonSlot* slot, JoyButtonSlot* mix); void activateMiniSlots(JoyButtonSlot *slot, JoyButtonSlot *mix);
bool hasPendingEvent(); // JoyButtonEvents class bool hasPendingEvent(); // JoyButtonEvents class
bool getToggleState(); bool getToggleState();
@@ -102,8 +124,8 @@ public:
bool getButtonState(); bool getButtonState();
bool containsSequence(); bool containsSequence();
bool containsDistanceSlots(); // JoyButtonSlots class bool containsDistanceSlots(); // JoyButtonSlots class
bool containsReleaseSlots(); // JoyButtonSlots class bool containsReleaseSlots(); // JoyButtonSlots class
bool getIgnoreEventState(); // JoyButtonEvents class bool getIgnoreEventState(); // JoyButtonEvents class
bool getWhileHeldStatus(); bool getWhileHeldStatus();
bool hasActiveSlots(); // JoyButtonSlots class bool hasActiveSlots(); // JoyButtonSlots class
bool isCycleResetActive(); bool isCycleResetActive();
@@ -136,8 +158,8 @@ public:
QString getActionName(); QString getActionName();
QString getButtonName(); QString getButtonName();
QList<JoyButtonSlot*>* getAssignedSlots(); // JoyButtonSlots class QList<JoyButtonSlot *> *getAssignedSlots(); // JoyButtonSlots class
QList<JoyButtonSlot*> const& getActiveSlots(); // JoyButtonSlots class QList<JoyButtonSlot *> const &getActiveSlots(); // JoyButtonSlots class
virtual bool isPartRealAxis(); virtual bool isPartRealAxis();
virtual bool isModifierButton(); virtual bool isModifierButton();
@@ -154,63 +176,77 @@ public:
virtual void initializeDistanceValues(); virtual void initializeDistanceValues();
virtual void setTurboMode(TurboMode mode); virtual void setTurboMode(TurboMode mode);
virtual void setDefaultButtonName(QString tempname); virtual void setDefaultButtonName(QString tempname);
virtual void copyLastMouseDistanceFromDeadZone(JoyButton *srcButton); // Don't use direct assignment but copying from a current button. virtual void copyLastMouseDistanceFromDeadZone(
JoyButton *srcButton); // Don't use direct assignment but copying from a current button.
virtual void copyLastAccelerationDistance(JoyButton *srcButton); virtual void copyLastAccelerationDistance(JoyButton *srcButton);
virtual void setVDPad(VDPad *vdpad); virtual void setVDPad(VDPad *vdpad);
virtual void setChangeSetCondition(SetChangeCondition condition, virtual void setChangeSetCondition(SetChangeCondition condition, bool passive = false, bool updateActiveString = true);
bool passive=false, bool updateActiveString=true);
virtual QString getPartialName(bool forceFullFormat=false, bool displayNames=false) const; virtual QString getPartialName(bool forceFullFormat = false, bool displayNames = false) const;
virtual QString getSlotsSummary(); // JoyButtonSlots class virtual QString getSlotsSummary(); // JoyButtonSlots class
virtual QString getSlotsString(); // JoyButtonSlots class virtual QString getSlotsString(); // JoyButtonSlots class
virtual QString getActiveZoneSummary(); virtual QString getActiveZoneSummary();
virtual QString getCalculatedActiveZoneSummary(); virtual QString getCalculatedActiveZoneSummary();
virtual QString getName(bool forceFullFormat=false, bool displayNames=false); virtual QString getName(bool forceFullFormat = false, bool displayNames = false);
virtual QString getXmlName(); // JoyButtonXml class virtual QString getXmlName(); // JoyButtonXml class
virtual QString getDefaultButtonName(); virtual QString getDefaultButtonName();
virtual QList<JoyButtonSlot*> getActiveZoneList(); virtual QList<JoyButtonSlot *> getActiveZoneList();
SetChangeCondition getChangeSetCondition(); SetChangeCondition getChangeSetCondition();
VDPad* getVDPad(); VDPad *getVDPad();
JoyMouseMovementMode getMouseMode(); JoyMouseMovementMode getMouseMode();
JoyMouseCurve getMouseCurve(); JoyMouseCurve getMouseCurve();
SetJoystick* getParentSet(); SetJoystick *getParentSet();
TurboMode getTurboMode(); TurboMode getTurboMode();
static int calculateFinalMouseSpeed(JoyMouseCurve curve, int value, const float joyspeed); static int calculateFinalMouseSpeed(JoyMouseCurve curve, int value, const float joyspeed);
static bool hasCursorEvents(QList<JoyButton::mouseCursorInfo>* cursorXSpeedsList, QList<JoyButton::mouseCursorInfo>* cursorYSpeedsList); // JoyButtonEvents class static bool hasCursorEvents(QList<JoyButton::mouseCursorInfo> *cursorXSpeedsList,
static bool hasSpringEvents(QList<PadderCommon::springModeInfo>* springXSpeedsList, QList<PadderCommon::springModeInfo>* springYSpeedsList); // JoyButtonEvents class QList<JoyButton::mouseCursorInfo> *cursorYSpeedsList); // JoyButtonEvents class
static bool shouldInvokeMouseEvents(QList<JoyButton*>* pendingMouseButtons, QTimer* staticMouseEventTimer, QTime* testOldMouseTime); // JoyButtonEvents class static bool hasSpringEvents(QList<PadderCommon::springModeInfo> *springXSpeedsList,
QList<PadderCommon::springModeInfo> *springYSpeedsList); // JoyButtonEvents class
static bool shouldInvokeMouseEvents(QList<JoyButton *> *pendingMouseButtons, QTimer *staticMouseEventTimer,
QTime *testOldMouseTime); // JoyButtonEvents class
static void setWeightModifier(double modifier, double maxWeightModifier, double& weightModifier); static void setWeightModifier(double modifier, double maxWeightModifier, double &weightModifier);
static void moveMouseCursor(int &movedX, int &movedY, int &movedElapsed, QList<double>* mouseHistoryX, QList<double>* mouseHistoryY, QTime* testOldMouseTime, QTimer* staticMouseEventTimer, int mouseRefreshRate, int mouseHistorySize, QList<JoyButton::mouseCursorInfo>* cursorXSpeeds, QList<JoyButton::mouseCursorInfo>* cursorYSpeeds, double& cursorRemainderX, double& cursorRemainderY, double weightModifier, int idleMouseRefrRate, QList<JoyButton*>* pendingMouseButtonse); static void moveMouseCursor(int &movedX, int &movedY, int &movedElapsed, QList<double> *mouseHistoryX,
static void moveSpringMouse(int &movedX, int &movedY, bool &hasMoved, int springModeScreen, QList<PadderCommon::springModeInfo>* springXSpeeds, QList<PadderCommon::springModeInfo>* springYSpeeds, QList<JoyButton*>* pendingMouseButtons, int mouseRefreshRate, int idleMouseRefrRate, QTimer* staticMouseEventTimer); QList<double> *mouseHistoryY, QTime *testOldMouseTime, QTimer *staticMouseEventTimer,
static void setMouseHistorySize(int size, int maxMouseHistSize, int& mouseHistSize, QList<double>* mouseHistoryX, QList<double>* mouseHistoryY); int mouseRefreshRate, int mouseHistorySize, QList<JoyButton::mouseCursorInfo> *cursorXSpeeds,
static void setMouseRefreshRate(int refresh, int& mouseRefreshRate, int idleMouseRefrRate, JoyButtonMouseHelper* mouseHelper, QList<double>* mouseHistoryX, QList<double>* mouseHistoryY, QTime* testOldMouseTime, QTimer* staticMouseEventTimer); QList<JoyButton::mouseCursorInfo> *cursorYSpeeds, double &cursorRemainderX,
static void setSpringModeScreen(int screen, int& springModeScreen); double &cursorRemainderY, double weightModifier, int idleMouseRefrRate,
static void resetActiveButtonMouseDistances(JoyButtonMouseHelper* mouseHelper); QList<JoyButton *> *pendingMouseButtonse);
static void setGamepadRefreshRate(int refresh, int& gamepadRefreshRate, JoyButtonMouseHelper* mouseHelper); static void moveSpringMouse(int &movedX, int &movedY, bool &hasMoved, int springModeScreen,
static void restartLastMouseTime(QTime* testOldMouseTime); QList<PadderCommon::springModeInfo> *springXSpeeds,
static void setStaticMouseThread(QThread *thread, QTimer* staticMouseEventTimer, QTime* testOldMouseTime, int idleMouseRefrRate, JoyButtonMouseHelper* mouseHelper); QList<PadderCommon::springModeInfo> *springYSpeeds, QList<JoyButton *> *pendingMouseButtons,
static void indirectStaticMouseThread(QThread *thread, QTimer* staticMouseEventTimer, JoyButtonMouseHelper* mouseHelper); int mouseRefreshRate, int idleMouseRefrRate, QTimer *staticMouseEventTimer);
static void invokeMouseEvents(JoyButtonMouseHelper* mouseHelper); // JoyButtonEvents class static void setMouseHistorySize(int size, int maxMouseHistSize, int &mouseHistSize, QList<double> *mouseHistoryX,
QList<double> *mouseHistoryY);
static void setMouseRefreshRate(int refresh, int &mouseRefreshRate, int idleMouseRefrRate,
JoyButtonMouseHelper *mouseHelper, QList<double> *mouseHistoryX,
QList<double> *mouseHistoryY, QTime *testOldMouseTime, QTimer *staticMouseEventTimer);
static void setSpringModeScreen(int screen, int &springModeScreen);
static void resetActiveButtonMouseDistances(JoyButtonMouseHelper *mouseHelper);
static void setGamepadRefreshRate(int refresh, int &gamepadRefreshRate, JoyButtonMouseHelper *mouseHelper);
static void restartLastMouseTime(QTime *testOldMouseTime);
static void setStaticMouseThread(QThread *thread, QTimer *staticMouseEventTimer, QTime *testOldMouseTime,
int idleMouseRefrRate, JoyButtonMouseHelper *mouseHelper);
static void indirectStaticMouseThread(QThread *thread, QTimer *staticMouseEventTimer, JoyButtonMouseHelper *mouseHelper);
static void invokeMouseEvents(JoyButtonMouseHelper *mouseHelper); // JoyButtonEvents class
static JoyButtonMouseHelper* getMouseHelper(); static JoyButtonMouseHelper *getMouseHelper();
static QList<JoyButton*>* getPendingMouseButtons(); static QList<JoyButton *> *getPendingMouseButtons();
static QList<JoyButton::mouseCursorInfo>* getCursorXSpeeds(); static QList<JoyButton::mouseCursorInfo> *getCursorXSpeeds();
static QList<JoyButton::mouseCursorInfo>* getCursorYSpeeds(); static QList<JoyButton::mouseCursorInfo> *getCursorYSpeeds();
static QList<PadderCommon::springModeInfo>* getSpringXSpeeds(); static QList<PadderCommon::springModeInfo> *getSpringXSpeeds();
static QList<PadderCommon::springModeInfo>* getSpringYSpeeds(); static QList<PadderCommon::springModeInfo> *getSpringYSpeeds();
static QTimer* getStaticMouseEventTimer(); // JoyButtonEvents class static QTimer *getStaticMouseEventTimer(); // JoyButtonEvents class
static QTime* getTestOldMouseTime(); static QTime *getTestOldMouseTime();
JoyExtraAccelerationCurve getExtraAccelerationCurve(); JoyExtraAccelerationCurve getExtraAccelerationCurve();
@@ -220,25 +256,25 @@ public:
static const TurboMode DEFAULTTURBOMODE; static const TurboMode DEFAULTTURBOMODE;
static const JoyExtraAccelerationCurve DEFAULTEXTRAACCELCURVE; static const JoyExtraAccelerationCurve DEFAULTEXTRAACCELCURVE;
bool insertAssignedSlot(JoyButtonSlot *slot, bool updateActiveString=true); // JoyButtonSlots class bool insertAssignedSlot(JoyButtonSlot *slot, bool updateActiveString = true); // JoyButtonSlots class
bool insertAssignedSlot(JoyButtonSlot *newSlot, int index, bool updateActiveString=true); bool insertAssignedSlot(JoyButtonSlot *newSlot, int index, bool updateActiveString = true);
bool containsJoyMixSlot(); bool containsJoyMixSlot();
protected: protected:
int getPreferredKeyPressTime(); // unsigned int getPreferredKeyPressTime(); // unsigned
double getTotalSlotDistance(JoyButtonSlot *slot); double getTotalSlotDistance(JoyButtonSlot *slot);
bool distanceEvent(); // JoyButtonEvents class bool distanceEvent(); // JoyButtonEvents class
bool checkForDelaySequence(); bool checkForDelaySequence();
void clearAssignedSlots(bool signalEmit=true); // JoyButtonSlots class void clearAssignedSlots(bool signalEmit = true); // JoyButtonSlots class
void releaseSlotEvent(); // JoyButtonEvents class void releaseSlotEvent(); // JoyButtonEvents class
void checkForPressedSetChange(); void checkForPressedSetChange();
void checkTurboCondition(JoyButtonSlot *slot); void checkTurboCondition(JoyButtonSlot *slot);
void vdpadPassEvent(bool pressed, bool ignoresets=false); // JoyButtonEvents class void vdpadPassEvent(bool pressed, bool ignoresets = false); // JoyButtonEvents class
void localBuildActiveZoneSummaryString(); void localBuildActiveZoneSummaryString();
static bool hasFutureSpringEvents(QList<JoyButton*>* pendingMouseButtons); static bool hasFutureSpringEvents(QList<JoyButton *> *pendingMouseButtons);
static int timeBetweenMiniSlots; static int timeBetweenMiniSlots;
static int allSlotTimeBetweenSlots; static int allSlotTimeBetweenSlots;
@@ -246,14 +282,14 @@ protected:
TurboMode currentTurboMode; TurboMode currentTurboMode;
QString buildActiveZoneSummary(QList<JoyButtonSlot*> &tempList); QString buildActiveZoneSummary(QList<JoyButtonSlot *> &tempList);
static QList<JoyButtonSlot*> mouseSpeedModList; // JoyButtonSlots class static QList<JoyButtonSlot *> mouseSpeedModList; // JoyButtonSlots class
static QList<mouseCursorInfo> cursorXSpeeds; static QList<mouseCursorInfo> cursorXSpeeds;
static QList<mouseCursorInfo> cursorYSpeeds; static QList<mouseCursorInfo> cursorYSpeeds;
static QList<PadderCommon::springModeInfo> springXSpeeds; static QList<PadderCommon::springModeInfo> springXSpeeds;
static QList<PadderCommon::springModeInfo> springYSpeeds; static QList<PadderCommon::springModeInfo> springYSpeeds;
static QList<JoyButton*> pendingMouseButtons; static QList<JoyButton *> pendingMouseButtons;
static JoyButtonSlot *lastActiveKey; // JoyButtonSlots class static JoyButtonSlot *lastActiveKey; // JoyButtonSlots class
static JoyButtonMouseHelper mouseHelper; static JoyButtonMouseHelper mouseHelper;
@@ -266,7 +302,7 @@ protected:
int springDeadCircleMultiplier; int springDeadCircleMultiplier;
bool isButtonPressed; // Used to denote whether the actual joypad button is pressed bool isButtonPressed; // Used to denote whether the actual joypad button is pressed
bool isKeyPressed; // Used to denote whether the virtual key is pressed bool isKeyPressed; // Used to denote whether the virtual key is pressed
double lastDistance; double lastDistance;
double lastWheelVerticalDistance; double lastWheelVerticalDistance;
@@ -282,20 +318,20 @@ protected:
SetJoystick *m_parentSet; // Pointer to set that button is assigned to. SetJoystick *m_parentSet; // Pointer to set that button is assigned to.
SetChangeCondition setSelectionCondition; SetChangeCondition setSelectionCondition;
JoyButtonSlot *currentWheelVerticalEvent; // JoyButtonEvents class JoyButtonSlot *currentWheelVerticalEvent; // JoyButtonEvents class
JoyButtonSlot *currentWheelHorizontalEvent; // JoyButtonEvents class JoyButtonSlot *currentWheelHorizontalEvent; // JoyButtonEvents class
QQueue<bool> ignoreSetQueue; QQueue<bool> ignoreSetQueue;
QQueue<bool> isButtonPressedQueue; QQueue<bool> isButtonPressedQueue;
QQueue<JoyButtonSlot*> mouseWheelVerticalEventQueue; // JoyButtonEvents class QQueue<JoyButtonSlot *> mouseWheelVerticalEventQueue; // JoyButtonEvents class
QQueue<JoyButtonSlot*> mouseWheelHorizontalEventQueue; // JoyButtonEvents class QQueue<JoyButtonSlot *> mouseWheelHorizontalEventQueue; // JoyButtonEvents class
QString buttonName; // User specified button name QString buttonName; // User specified button name
QString defaultButtonName; // Name used by the system QString defaultButtonName; // Name used by the system
signals: signals:
void clicked (int index); void clicked(int index);
void released (int index); void released(int index);
void keyChanged(int keycode); void keyChanged(int keycode);
void mouseChanged(int mousecode); void mouseChanged(int mousecode);
void setChangeActivated(int index); void setChangeActivated(int index);
@@ -310,9 +346,9 @@ signals:
void propertyUpdated(); void propertyUpdated();
void activeZoneChanged(); void activeZoneChanged();
public slots: public slots:
void setTurboInterval (int interval); void setTurboInterval(int interval);
void setToggle (bool toggle); void setToggle(bool toggle);
void setUseTurbo(bool useTurbo); void setUseTurbo(bool useTurbo);
void setMouseSpeedX(int speed); void setMouseSpeedX(int speed);
void setMouseSpeedY(int speed); void setMouseSpeedY(int speed);
@@ -331,51 +367,49 @@ public slots:
virtual void reset(); virtual void reset();
virtual void reset(int index); virtual void reset(int index);
virtual void resetProperties(); virtual void resetProperties();
virtual void clearSlotsEventReset(bool clearSignalEmit=true); // JoyButtonEvents class virtual void clearSlotsEventReset(bool clearSignalEmit = true); // JoyButtonEvents class
virtual void eventReset(); // JoyButtonEvents class virtual void eventReset(); // JoyButtonEvents class
virtual void mouseEvent(); // JoyButtonEvents class virtual void mouseEvent(); // JoyButtonEvents class
static void establishMouseTimerConnections(); static void establishMouseTimerConnections();
bool setAssignedSlot(int code, int alias, int index, 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, bool setAssignedSlot(int code,
JoyButtonSlot::JoySlotInputAction mode=JoyButtonSlot::JoyKeyboard); // JoyButtonSlots class JoyButtonSlot::JoySlotInputAction mode = JoyButtonSlot::JoyKeyboard); // JoyButtonSlots class
bool setAssignedSlot(int code, int alias, 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, bool insertAssignedSlot(int code, int alias, int index,
JoyButtonSlot::JoySlotInputAction mode=JoyButtonSlot::JoyKeyboard); // JoyButtonSlots class JoyButtonSlot::JoySlotInputAction mode = JoyButtonSlot::JoyKeyboard); // JoyButtonSlots class
void buildActiveZoneSummaryString(); void buildActiveZoneSummaryString();
protected slots: protected slots:
virtual void turboEvent(); // JoyButtonEvents class virtual void turboEvent(); // JoyButtonEvents class
virtual void wheelEventVertical(); // JoyButtonEvents class virtual void wheelEventVertical(); // JoyButtonEvents class
virtual void wheelEventHorizontal(); // JoyButtonEvents class virtual void wheelEventHorizontal(); // JoyButtonEvents class
void createDeskEvent(); // JoyButtonEvents class void createDeskEvent(); // JoyButtonEvents class
void releaseDeskEvent(bool skipsetchange=false); // JoyButtonEvents class void releaseDeskEvent(bool skipsetchange = false); // JoyButtonEvents class
private slots:
private slots: void releaseActiveSlots(); // JoyButtonSlots class
void releaseActiveSlots(); // JoyButtonSlots class void activateSlots(); // JoyButtonSlots class
void activateSlots(); // JoyButtonSlots class void waitForDeskEvent(); // JoyButtonEvents class
void waitForDeskEvent(); // JoyButtonEvents class
void waitForReleaseDeskEvent(); // JoyButtonEvents class void waitForReleaseDeskEvent(); // JoyButtonEvents class
void holdEvent(); // JoyButtonEvents class void holdEvent(); // JoyButtonEvents class
void delayEvent(); // JoyButtonEvents class void delayEvent(); // JoyButtonEvents class
void pauseWaitEvent(); // JoyButtonEvents class void pauseWaitEvent(); // JoyButtonEvents class
void checkForSetChange(); void checkForSetChange();
void keyPressEvent(); // JoyButtonEvents class void keyPressEvent(); // JoyButtonEvents class
void slotSetChange(); void slotSetChange();
private: private:
inline void updatePendingParams(bool isEvent, bool isPressed, bool areIgnoredSets) inline void updatePendingParams(bool isEvent, bool isPressed, bool areIgnoredSets)
{ {
pendingEvent = isEvent; pendingEvent = isEvent;
@@ -404,7 +438,8 @@ private:
currentWheelHorizontalEvent = nullptr; currentWheelHorizontalEvent = nullptr;
currentKeyPress = nullptr; currentKeyPress = nullptr;
currentDelay = nullptr; currentDelay = nullptr;
if (currentChangedSlot) currentSetChangeSlot = nullptr; if (currentChangedSlot)
currentSetChangeSlot = nullptr;
isKeyPressed = isButtonPressed = false; isKeyPressed = isButtonPressed = false;
quitEvent = true; quitEvent = true;
@@ -412,7 +447,8 @@ private:
inline void stopTimers(bool restartedActiveZoneTimer, bool stoppedActiveZoneTimer, bool stoppedSlotSetTimer) inline void stopTimers(bool restartedActiveZoneTimer, bool stoppedActiveZoneTimer, bool stoppedSlotSetTimer)
{ {
if (restartedActiveZoneTimer) activeZoneTimer.start(); if (restartedActiveZoneTimer)
activeZoneTimer.start();
turboTimer.stop(); turboTimer.stop();
pauseWaitTimer.stop(); pauseWaitTimer.stop();
@@ -425,15 +461,17 @@ private:
keyPressTimer.stop(); keyPressTimer.stop();
delayTimer.stop(); delayTimer.stop();
if (stoppedActiveZoneTimer) activeZoneTimer.stop(); if (stoppedActiveZoneTimer)
activeZoneTimer.stop();
if (stoppedSlotSetTimer) slotSetChangeTimer.stop(); if (stoppedSlotSetTimer)
slotSetChangeTimer.stop();
if (slotiter != nullptr) if (slotiter != nullptr)
{ {
delete slotiter; delete slotiter;
slotiter = nullptr; slotiter = nullptr;
} }
} }
inline void clearQueues() inline void clearQueues()
@@ -452,11 +490,14 @@ private:
currentAccelerationDistance = 0.0; currentAccelerationDistance = 0.0;
startingAccelerationDistance = 0.0; startingAccelerationDistance = 0.0;
if (updatedOldAccel) oldAccelMulti = updateOldAccelMulti = 0.0; if (updatedOldAccel)
else oldAccelMulti = 0.0; oldAccelMulti = updateOldAccelMulti = 0.0;
else
oldAccelMulti = 0.0;
accelTravel = 0.0; accelTravel = 0.0;
if (restartedAccelDurTimer) accelExtraDurationTime.restart(); if (restartedAccelDurTimer)
accelExtraDurationTime.restart();
if (restartedRestParams) if (restartedRestParams)
{ {
@@ -471,35 +512,45 @@ private:
} }
} }
inline void lockForWritedString(QString& param, QString value) inline void lockForWritedString(QString &param, QString value)
{ {
activeZoneStringLock.lockForWrite(); activeZoneStringLock.lockForWrite();
param = value; param = value;
activeZoneStringLock.unlock(); activeZoneStringLock.unlock();
} }
void releaseEachSlot(bool &changeRepeatState, int &references, int tempcode, JoyButtonSlot::JoySlotInputAction mode, JoyButtonSlot *slot); void releaseEachSlot(bool &changeRepeatState, int &references, int tempcode, JoyButtonSlot::JoySlotInputAction mode,
JoyButtonSlot *slot);
void resetAllProperties(); void resetAllProperties();
void resetPrivVars(); void resetPrivVars();
void restartAllForSetChange(); void restartAllForSetChange();
void startTimerOverrun(int slotCode, QElapsedTimer* currSlotTime, QTimer* currSlotTimer, bool releasedDeskTimer = false); void startTimerOverrun(int slotCode, QElapsedTimer *currSlotTime, QTimer *currSlotTimer, bool releasedDeskTimer = false);
void findJoySlotsEnd(QListIterator<JoyButtonSlot*> *slotiter); void findJoySlotsEnd(QListIterator<JoyButtonSlot *> *slotiter);
void changeStatesQueue(bool currentReleased); void changeStatesQueue(bool currentReleased);
void countActiveSlots(int tempcode, int& references, JoyButtonSlot* slot, QHash<int, int>& activeSlotsHash, bool& changeRepeatState, bool activeSlotHashWindows = false); // JoyButtonSlots class void countActiveSlots(int tempcode, int &references, JoyButtonSlot *slot, QHash<int, int> &activeSlotsHash,
void releaseMoveSlots(QList<JoyButton::mouseCursorInfo>& cursorSpeeds, JoyButtonSlot *slot, QList<int>& indexesToRemove); // JoyButtonSlots class bool &changeRepeatState, bool activeSlotHashWindows = false); // JoyButtonSlots class
void setSpringDeadCircle(double& springDeadCircle, int mouseDirection); void releaseMoveSlots(QList<JoyButton::mouseCursorInfo> &cursorSpeeds, JoyButtonSlot *slot,
void checkSpringDeadCircle(int tempcode, double& springDeadCircle, int mouseSlot1, int mouseSlot2); QList<int> &indexesToRemove); // JoyButtonSlots class
static void distanceForMovingAx(double& finalAx, mouseCursorInfo infoAx); void setSpringDeadCircle(double &springDeadCircle, int mouseDirection);
static void adjustAxForCursor(QList<double>* mouseHistoryList, double& adjustedAx, double& cursorRemainder, double weightModifier); void checkSpringDeadCircle(int tempcode, double &springDeadCircle, int mouseSlot1, int mouseSlot2);
void setDistanceForSpring(JoyButtonMouseHelper& mouseHelper, double& mouseFirstAx, double& mouseSecondAx, double distanceFromDeadZone); static void distanceForMovingAx(double &finalAx, mouseCursorInfo infoAx);
static void adjustAxForCursor(QList<double> *mouseHistoryList, double &adjustedAx, double &cursorRemainder,
double weightModifier);
void setDistanceForSpring(JoyButtonMouseHelper &mouseHelper, double &mouseFirstAx, double &mouseSecondAx,
double distanceFromDeadZone);
void changeTurboParams(bool _isKeyPressed, bool isButtonPressed); void changeTurboParams(bool _isKeyPressed, bool isButtonPressed);
void updateParamsAfterDistEvent(); // JoyButtonEvents class void updateParamsAfterDistEvent(); // JoyButtonEvents class
void startSequenceOfPressActive(bool isTurbo, QString debugText); void startSequenceOfPressActive(bool isTurbo, QString debugText);
QList<JoyButtonSlot*>& getAssignmentsLocal(); QList<JoyButtonSlot *> &getAssignmentsLocal();
QList<JoyButtonSlot*>& getActiveSlotsLocal(); // JoyButtonSlots class QList<JoyButtonSlot *> &getActiveSlotsLocal(); // JoyButtonSlots class
void updateMouseProperties(double newAxisValue, double newSpringDead, int newSpringWidth, int newSpringHeight, bool relatived, int modeScreen, QList<PadderCommon::springModeInfo>& springSpeeds, QChar axis, double newAxisValueY = 0, double newSpringDeadY = 0); void updateMouseProperties(double newAxisValue, double newSpringDead, int newSpringWidth, int newSpringHeight,
//void getActiveZoneWithAppend(JoyButtonSlot::JoySlotInputAction mode, QList<JoyButtonSlot *>& tempSlotList, QListIterator<JoyButtonSlot *> *iter, JoyButtonSlot *slot); bool relatived, int modeScreen, QList<PadderCommon::springModeInfo> &springSpeeds, QChar axis,
void buildActiveZoneSummarySwitchSlots(JoyButtonSlot::JoySlotInputAction mode, JoyButtonSlot *slot, bool& behindHold, QStringList* stringlist, int& i, QListIterator<JoyButtonSlot*>* iter, bool slotsActive); double newAxisValueY = 0, double newSpringDeadY = 0);
// void getActiveZoneWithAppend(JoyButtonSlot::JoySlotInputAction mode, QList<JoyButtonSlot *>& tempSlotList,
// QListIterator<JoyButtonSlot *> *iter, JoyButtonSlot *slot);
void buildActiveZoneSummarySwitchSlots(JoyButtonSlot::JoySlotInputAction mode, JoyButtonSlot *slot, bool &behindHold,
QStringList *stringlist, int &i, QListIterator<JoyButtonSlot *> *iter,
bool slotsActive);
bool m_toggle; bool m_toggle;
bool quitEvent; // JoyButtonEvents class bool quitEvent; // JoyButtonEvents class
@@ -510,8 +561,9 @@ private:
bool m_ignoresets; bool m_ignoresets;
bool ignoreEvents; // JoyButtonEvents class bool ignoreEvents; // JoyButtonEvents class
bool whileHeldStatus; bool whileHeldStatus;
bool updateLastMouseDistance; // Should lastMouseDistance be updated. Set after mouse event. bool updateLastMouseDistance; // Should lastMouseDistance be updated. Set after mouse event.
bool updateStartingMouseDistance; // Should startingMouseDistance be updated. Set after acceleration has finally been applied. bool updateStartingMouseDistance; // Should startingMouseDistance be updated. Set after acceleration has finally been
// applied.
bool relativeSpring; bool relativeSpring;
bool pendingPress; bool pendingPress;
bool pendingEvent; // JoyButtonEvents class bool pendingEvent; // JoyButtonEvents class
@@ -529,15 +581,17 @@ private:
int cycleResetInterval; // unsigned int cycleResetInterval; // unsigned
double sensitivity; double sensitivity;
double lastMouseDistance; // Keep track of the previous mouse distance from the previous gamepad poll. double lastMouseDistance; // Keep track of the previous mouse distance from the previous gamepad poll.
double lastAccelerationDistance; // Keep track of the previous full distance from the previous gamepad poll double lastAccelerationDistance; // Keep track of the previous full distance from the previous gamepad poll
double currentAccelMulti; // Multiplier and time used for acceleration easing. double currentAccelMulti; // Multiplier and time used for acceleration easing.
double accelDuration; double accelDuration;
double oldAccelMulti; double oldAccelMulti;
double accelTravel; // Track travel when accel started double accelTravel; // Track travel when accel started
double updateOldAccelMulti; double updateOldAccelMulti;
double currentMouseDistance; // Keep track of the current mouse distance after a poll. Used to update lastMouseDistance later. double currentMouseDistance; // Keep track of the current mouse distance after a poll. Used to update lastMouseDistance
double currentAccelerationDistance; // Keep track of the current mouse distance after a poll. Used to update lastMouseDistance later. // later.
double currentAccelerationDistance; // Keep track of the current mouse distance after a poll. Used to update
// lastMouseDistance later.
double startingAccelerationDistance; // Take into account when mouse acceleration started double startingAccelerationDistance; // Take into account when mouse acceleration started
double minMouseDistanceAccelThreshold; double minMouseDistanceAccelThreshold;
double maxMouseDistanceAccelThreshold; double maxMouseDistanceAccelThreshold;
@@ -561,10 +615,10 @@ private:
QString actionName; QString actionName;
QString activeZoneString; QString activeZoneString;
QList<JoyButtonSlot*> assignments; QList<JoyButtonSlot *> assignments;
QList<JoyButtonSlot*> activeSlots; QList<JoyButtonSlot *> activeSlots;
QListIterator<JoyButtonSlot*> *slotiter; QListIterator<JoyButtonSlot *> *slotiter;
QQueue<JoyButtonSlot*> mouseEventQueue; // JoyButtonEvents class QQueue<JoyButtonSlot *> mouseEventQueue; // JoyButtonEvents class
JoyButtonSlot *currentPause; JoyButtonSlot *currentPause;
JoyButtonSlot *currentHold; JoyButtonSlot *currentHold;
JoyButtonSlot *currentCycle; JoyButtonSlot *currentCycle;
@@ -586,7 +640,6 @@ private:
QElapsedTimer cycleResetHold; QElapsedTimer cycleResetHold;
static QTime testOldMouseTime; static QTime testOldMouseTime;
VDPad *m_vdpad; VDPad *m_vdpad;
JoyMouseMovementMode mouseMode; JoyMouseMovementMode mouseMode;
JoyMouseCurve mouseCurve; JoyMouseCurve mouseCurve;
@@ -597,29 +650,25 @@ private:
QReadWriteLock activeZoneStringLock; QReadWriteLock activeZoneStringLock;
QThreadPool *threadPool; QThreadPool *threadPool;
void addEachSlotToActives(JoyButtonSlot *slot, int &i, bool &delaySequence, bool &exit,
void addEachSlotToActives(JoyButtonSlot *slot, int &i, bool &delaySequence, bool &exit, QListIterator<JoyButtonSlot *> *slotiter); QListIterator<JoyButtonSlot *> *slotiter);
}; };
class MiniSlotRun : public QRunnable, public QObject class MiniSlotRun : public QRunnable, public QObject
{ {
public: public:
MiniSlotRun(JoyButtonSlot *slot, JoyButtonSlot* slotmini, JoyButton* btn, int milisec) : MiniSlotRun(JoyButtonSlot *slot, JoyButtonSlot *slotmini, JoyButton *btn, int milisec)
QObject(btn), : QObject(btn)
m_slot(slot), , m_slot(slot)
m_slotmini(slotmini), , m_slotmini(slotmini)
m_btn(btn), , m_btn(btn)
m_miliseconds(milisec) , m_miliseconds(milisec)
{
}
~MiniSlotRun()
{ {
} }
~MiniSlotRun() {}
void run() void run()
{ {
this->thread()->wait(m_miliseconds); this->thread()->wait(m_miliseconds);
@@ -627,12 +676,11 @@ public:
m_btn->activateMiniSlots(m_slotmini, m_slot); m_btn->activateMiniSlots(m_slotmini, m_slot);
} }
private: private:
JoyButtonSlot* m_slot; JoyButtonSlot *m_slot;
JoyButtonSlot* m_slotmini; JoyButtonSlot *m_slotmini;
JoyButton* m_btn; JoyButton *m_btn;
int m_miliseconds; int m_miliseconds;
}; };
#endif // JOYBUTTON_H #endif // JOYBUTTON_H

View File

@@ -18,19 +18,18 @@
#include "joybuttoncontextmenu.h" #include "joybuttoncontextmenu.h"
#include "globalvariables.h"
#include "messagehandler.h"
#include "inputdevice.h"
#include "common.h" #include "common.h"
#include "globalvariables.h"
#include "inputdevice.h"
#include "joybutton.h" #include "joybutton.h"
#include "messagehandler.h"
#include <QDebug>
#include <QActionGroup> #include <QActionGroup>
#include <QDebug>
#include <QWidget> #include <QWidget>
JoyButtonContextMenu::JoyButtonContextMenu(JoyButton *button, QWidget *parent)
JoyButtonContextMenu::JoyButtonContextMenu(JoyButton *button, QWidget *parent) : : QMenu(parent)
QMenu(parent)
{ {
qInstallMessageHandler(MessageHandler::myMessageOutput); qInstallMessageHandler(MessageHandler::myMessageOutput);
@@ -77,7 +76,7 @@ void JoyButtonContextMenu::buildMenu()
for (int i = 0; i < GlobalVariables::InputDevice::NUMBER_JOYSETS; i++) for (int i = 0; i < GlobalVariables::InputDevice::NUMBER_JOYSETS; i++)
{ {
QMenu *tempSetMenu = setSectionMenu->addMenu(tr("Set %1").arg(i+1)); QMenu *tempSetMenu = setSectionMenu->addMenu(tr("Set %1").arg(i + 1));
int setSelection = i * 3; int setSelection = i * 3;
if (i == button->getSetSelection()) if (i == button->getSetSelection())
@@ -99,8 +98,9 @@ void JoyButtonContextMenu::buildMenu()
PadderCommon::inputDaemonMutex.unlock(); PadderCommon::inputDaemonMutex.unlock();
} }
void JoyButtonContextMenu::createActionForGroup(QActionGroup *tempGroup, QString actionText, QAction *action,
void JoyButtonContextMenu::createActionForGroup(QActionGroup *tempGroup, QString actionText, QAction *action, QMenu *tempSetMenu, int setSelection, int currentSelection, int setDataInc, int setCondition) QMenu *tempSetMenu, int setSelection, int currentSelection, int setDataInc,
int setCondition)
{ {
action = tempSetMenu->addAction(actionText.arg(currentSelection + 1)); action = tempSetMenu->addAction(actionText.arg(currentSelection + 1));
action->setData(QVariant(setSelection + setDataInc)); action->setData(QVariant(setSelection + setDataInc));
@@ -112,14 +112,11 @@ void JoyButtonContextMenu::createActionForGroup(QActionGroup *tempGroup, QString
action->setChecked(true); action->setChecked(true);
} }
connect(action, &QAction::triggered, this, [this, action]() { connect(action, &QAction::triggered, this, [this, action]() { switchSetMode(action); });
switchSetMode(action);
});
tempGroup->addAction(action); tempGroup->addAction(action);
} }
void JoyButtonContextMenu::switchToggle() void JoyButtonContextMenu::switchToggle()
{ {
qInstallMessageHandler(MessageHandler::myMessageOutput); qInstallMessageHandler(MessageHandler::myMessageOutput);
@@ -138,7 +135,7 @@ void JoyButtonContextMenu::switchTurbo()
PadderCommon::inputDaemonMutex.unlock(); PadderCommon::inputDaemonMutex.unlock();
} }
void JoyButtonContextMenu::switchSetMode(QAction* action) void JoyButtonContextMenu::switchSetMode(QAction *action)
{ {
qInstallMessageHandler(MessageHandler::myMessageOutput); qInstallMessageHandler(MessageHandler::myMessageOutput);
@@ -147,22 +144,21 @@ void JoyButtonContextMenu::switchSetMode(QAction* action)
int setChangeCondition = item % 3; int setChangeCondition = item % 3;
JoyButton::SetChangeCondition temp = JoyButton::SetChangeOneWay; JoyButton::SetChangeCondition temp = JoyButton::SetChangeOneWay;
switch(setChangeCondition) switch (setChangeCondition)
{ {
case 0: case 0:
temp = JoyButton::SetChangeOneWay; temp = JoyButton::SetChangeOneWay;
break; break;
case 1: case 1:
temp = JoyButton::SetChangeTwoWay; temp = JoyButton::SetChangeTwoWay;
break; break;
case 2: case 2:
temp = JoyButton::SetChangeWhileHeld; temp = JoyButton::SetChangeWhileHeld;
break; break;
} }
PadderCommon::inputDaemonMutex.lock(); PadderCommon::inputDaemonMutex.lock();
// First, remove old condition for the button in both sets. // First, remove old condition for the button in both sets.

View File

@@ -21,7 +21,6 @@
#include <QMenu> #include <QMenu>
class JoyButton; class JoyButton;
class QWidget; class QWidget;
@@ -29,20 +28,21 @@ class JoyButtonContextMenu : public QMenu
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit JoyButtonContextMenu(JoyButton *button, QWidget *parent = nullptr); explicit JoyButtonContextMenu(JoyButton *button, QWidget *parent = nullptr);
void buildMenu(); void buildMenu();
protected: protected:
JoyButton *button; JoyButton *button;
private slots: private slots:
void switchToggle(); void switchToggle();
void switchTurbo(); void switchTurbo();
void switchSetMode(QAction* action); void switchSetMode(QAction *action);
void disableSetMode(); void disableSetMode();
void clearButton(); void clearButton();
void createActionForGroup(QActionGroup *tempGroup, QString actionText, QAction *action, QMenu *tempSetMenu, int setSelection, int currentSelection, int setDataInc, int setCondition); void createActionForGroup(QActionGroup *tempGroup, QString actionText, QAction *action, QMenu *tempSetMenu,
int setSelection, int currentSelection, int setDataInc, int setCondition);
}; };
#endif // JOYBUTTONCONTEXTMENU_H #endif // JOYBUTTONCONTEXTMENU_H

View File

@@ -19,15 +19,15 @@
#include "joybuttonmousehelper.h" #include "joybuttonmousehelper.h"
#include "globalvariables.h" #include "globalvariables.h"
#include "messagehandler.h"
#include "joybutton.h" #include "joybutton.h"
#include "messagehandler.h"
#include <QDebug> #include <QDebug>
#include <QList> #include <QList>
#include <QThread> #include <QThread>
JoyButtonMouseHelper::JoyButtonMouseHelper(QObject *parent) : JoyButtonMouseHelper::JoyButtonMouseHelper(QObject *parent)
QObject(parent) : QObject(parent)
{ {
qInstallMessageHandler(MessageHandler::myMessageOutput); qInstallMessageHandler(MessageHandler::myMessageOutput);
@@ -39,12 +39,18 @@ JoyButtonMouseHelper::JoyButtonMouseHelper(QObject *parent) :
*/ */
void JoyButtonMouseHelper::moveMouseCursor() void JoyButtonMouseHelper::moveMouseCursor()
{ {
// qInstallMessageHandler(MessageHandler::myMessageOutput); // qInstallMessageHandler(MessageHandler::myMessageOutput);
int finalx = 0; int finalx = 0;
int finaly = 0; int finaly = 0;
int elapsedTime = 5; int elapsedTime = 5;
JoyButton::moveMouseCursor(finalx, finaly, elapsedTime, &GlobalVariables::JoyButton::mouseHistoryX, &GlobalVariables::JoyButton::mouseHistoryY, JoyButton::getTestOldMouseTime(), JoyButton::getStaticMouseEventTimer(), GlobalVariables::JoyButton::mouseRefreshRate, GlobalVariables::JoyButton::mouseHistorySize, JoyButton::getCursorXSpeeds(), JoyButton::getCursorYSpeeds(), GlobalVariables::JoyButton::cursorRemainderX, GlobalVariables::JoyButton::cursorRemainderY, GlobalVariables::JoyButton::weightModifier, GlobalVariables::JoyButton::IDLEMOUSEREFRESHRATE, JoyButton::getPendingMouseButtons()); JoyButton::moveMouseCursor(finalx, finaly, elapsedTime, &GlobalVariables::JoyButton::mouseHistoryX,
&GlobalVariables::JoyButton::mouseHistoryY, JoyButton::getTestOldMouseTime(),
JoyButton::getStaticMouseEventTimer(), GlobalVariables::JoyButton::mouseRefreshRate,
GlobalVariables::JoyButton::mouseHistorySize, JoyButton::getCursorXSpeeds(),
JoyButton::getCursorYSpeeds(), GlobalVariables::JoyButton::cursorRemainderX,
GlobalVariables::JoyButton::cursorRemainderY, GlobalVariables::JoyButton::weightModifier,
GlobalVariables::JoyButton::IDLEMOUSEREFRESHRATE, JoyButton::getPendingMouseButtons());
if ((finalx != 0) || (finaly != 0)) if ((finalx != 0) || (finaly != 0))
emit mouseCursorMoved(finalx, finaly, elapsedTime); emit mouseCursorMoved(finalx, finaly, elapsedTime);
@@ -60,7 +66,10 @@ void JoyButtonMouseHelper::moveSpringMouse()
int finalx = 0; int finalx = 0;
int finaly = 0; int finaly = 0;
bool hasMoved = false; bool hasMoved = false;
JoyButton::moveSpringMouse(finalx, finaly, hasMoved, GlobalVariables::JoyButton::springModeScreen, JoyButton::getSpringXSpeeds(), JoyButton::getSpringYSpeeds(), JoyButton::getPendingMouseButtons(), GlobalVariables::JoyButton::mouseRefreshRate, GlobalVariables::JoyButton::IDLEMOUSEREFRESHRATE, JoyButton::getStaticMouseEventTimer()); JoyButton::moveSpringMouse(finalx, finaly, hasMoved, GlobalVariables::JoyButton::springModeScreen,
JoyButton::getSpringXSpeeds(), JoyButton::getSpringYSpeeds(),
JoyButton::getPendingMouseButtons(), GlobalVariables::JoyButton::mouseRefreshRate,
GlobalVariables::JoyButton::IDLEMOUSEREFRESHRATE, JoyButton::getStaticMouseEventTimer());
if (hasMoved) if (hasMoved)
emit mouseSpringMoved(finalx, finaly); emit mouseSpringMoved(finalx, finaly);
@@ -71,12 +80,13 @@ void JoyButtonMouseHelper::moveSpringMouse()
*/ */
void JoyButtonMouseHelper::mouseEvent() void JoyButtonMouseHelper::mouseEvent()
{ {
// qInstallMessageHandler(MessageHandler::myMessageOutput); // qInstallMessageHandler(MessageHandler::myMessageOutput);
if (!JoyButton::hasCursorEvents(JoyButton::getCursorXSpeeds(), JoyButton::getCursorYSpeeds()) && !JoyButton::hasSpringEvents(JoyButton::getSpringXSpeeds(), JoyButton::getSpringYSpeeds())) if (!JoyButton::hasCursorEvents(JoyButton::getCursorXSpeeds(), JoyButton::getCursorYSpeeds()) &&
!JoyButton::hasSpringEvents(JoyButton::getSpringXSpeeds(), JoyButton::getSpringYSpeeds()))
{ {
QList<JoyButton*> *buttonList = JoyButton::getPendingMouseButtons(); QList<JoyButton *> *buttonList = JoyButton::getPendingMouseButtons();
QListIterator<JoyButton*> iter(*buttonList); QListIterator<JoyButton *> iter(*buttonList);
while (iter.hasNext()) while (iter.hasNext())
{ {
@@ -100,8 +110,8 @@ void JoyButtonMouseHelper::resetButtonMouseDistances()
{ {
qInstallMessageHandler(MessageHandler::myMessageOutput); qInstallMessageHandler(MessageHandler::myMessageOutput);
QList<JoyButton*> *buttonList = JoyButton::getPendingMouseButtons(); QList<JoyButton *> *buttonList = JoyButton::getPendingMouseButtons();
QListIterator<JoyButton*> iter(*buttonList); QListIterator<JoyButton *> iter(*buttonList);
while (iter.hasNext()) while (iter.hasNext())
{ {
@@ -142,5 +152,6 @@ void JoyButtonMouseHelper::changeThread(QThread *thread)
{ {
qInstallMessageHandler(MessageHandler::myMessageOutput); qInstallMessageHandler(MessageHandler::myMessageOutput);
JoyButton::setStaticMouseThread(thread, JoyButton::getStaticMouseEventTimer(), JoyButton::getTestOldMouseTime(), GlobalVariables::JoyButton::IDLEMOUSEREFRESHRATE, JoyButton::getMouseHelper()); JoyButton::setStaticMouseThread(thread, JoyButton::getStaticMouseEventTimer(), JoyButton::getTestOldMouseTime(),
GlobalVariables::JoyButton::IDLEMOUSEREFRESHRATE, JoyButton::getMouseHelper());
} }

View File

@@ -16,20 +16,18 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef JOYBUTTONMOUSEHELPER_H #ifndef JOYBUTTONMOUSEHELPER_H
#define JOYBUTTONMOUSEHELPER_H #define JOYBUTTONMOUSEHELPER_H
#include <QObject> #include <QObject>
class QThread; class QThread;
class JoyButtonMouseHelper : public QObject class JoyButtonMouseHelper : public QObject
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit JoyButtonMouseHelper(QObject *parent = nullptr); explicit JoyButtonMouseHelper(QObject *parent = nullptr);
void resetButtonMouseDistances(); void resetButtonMouseDistances();
void setFirstSpringStatus(bool status); void setFirstSpringStatus(bool status);
@@ -37,19 +35,19 @@ public:
void carryGamePollRateUpdate(int pollRate); void carryGamePollRateUpdate(int pollRate);
void carryMouseRefreshRateUpdate(int refreshRate); void carryMouseRefreshRateUpdate(int refreshRate);
signals: signals:
void mouseCursorMoved(int mouseX, int mouseY, int elapsed); void mouseCursorMoved(int mouseX, int mouseY, int elapsed);
void mouseSpringMoved(int mouseX, int mouseY); void mouseSpringMoved(int mouseX, int mouseY);
void gamepadRefreshRateUpdated(int pollRate); void gamepadRefreshRateUpdated(int pollRate);
void mouseRefreshRateUpdated(int refreshRate); void mouseRefreshRateUpdated(int refreshRate);
public slots: public slots:
void moveMouseCursor(); void moveMouseCursor();
void moveSpringMouse(); void moveSpringMouse();
void mouseEvent(); void mouseEvent();
void changeThread(QThread *thread); void changeThread(QThread *thread);
private: private:
bool firstSpringEvent; bool firstSpringEvent;
}; };

Some files were not shown because too many files have changed in this diff Show More