2016-09-06 00:23:31 +01:00
|
|
|
#include "controllerconfigdialog.h"
|
|
|
|
#include "ui_controllerconfigdialog.h"
|
|
|
|
|
|
|
|
#include <QRegularExpression>
|
|
|
|
#include <QLabel>
|
|
|
|
#include <QFile>
|
2017-05-23 16:08:53 +01:00
|
|
|
#include <QAbstractButton>
|
|
|
|
#include <QPushButton>
|
|
|
|
|
2017-06-13 04:51:38 +01:00
|
|
|
#include "bindingmodel.h"
|
|
|
|
#include "ControllerInfo.h"
|
|
|
|
#include "inputeventselectiondialog.h"
|
2016-09-06 00:23:31 +01:00
|
|
|
|
|
|
|
ControllerConfigDialog::ControllerConfigDialog(QWidget *parent) :
|
2017-06-13 04:51:38 +01:00
|
|
|
QDialog(parent),
|
|
|
|
ui(new Ui::ControllerConfigDialog),
|
|
|
|
m_inputDeviceManager(std::make_unique<CGamePadDeviceListener>(true))
|
2016-09-06 00:23:31 +01:00
|
|
|
{
|
2017-06-13 04:51:38 +01:00
|
|
|
ui->setupUi(this);
|
2017-06-13 04:53:18 +01:00
|
|
|
}
|
2016-09-06 00:23:31 +01:00
|
|
|
|
2017-06-13 04:53:18 +01:00
|
|
|
ControllerConfigDialog::~ControllerConfigDialog()
|
|
|
|
{
|
|
|
|
delete ui;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ControllerConfigDialog::SetInputBindingManager(CInputBindingManager *inputBindingManager)
|
|
|
|
{
|
|
|
|
m_inputManager = inputBindingManager;
|
2017-06-13 04:51:38 +01:00
|
|
|
CBindingModel* model= new CBindingModel(this);
|
|
|
|
model->Setup(m_inputManager);
|
|
|
|
model->setHeaderData(0, Qt::Orientation::Horizontal, QVariant("Button"), Qt::DisplayRole);
|
|
|
|
model->setHeaderData(1, Qt::Orientation::Horizontal, QVariant("Binding Type"), Qt::DisplayRole);
|
|
|
|
model->setHeaderData(2, Qt::Orientation::Horizontal, QVariant("Binding Value"), Qt::DisplayRole);
|
|
|
|
ui->tableView->setModel(model);
|
|
|
|
ui->tableView->horizontalHeader()->setStretchLastSection(true);
|
|
|
|
ui->tableView->resizeColumnsToContents();
|
2016-09-06 00:23:31 +01:00
|
|
|
}
|
|
|
|
|
2017-06-13 04:51:38 +01:00
|
|
|
void ControllerConfigDialog::on_buttonBox_clicked(QAbstractButton *button)
|
|
|
|
{
|
|
|
|
if(button == ui->buttonBox->button(QDialogButtonBox::Ok))
|
|
|
|
{
|
|
|
|
m_inputManager->Save();
|
|
|
|
}
|
|
|
|
else if (button == ui->buttonBox->button(QDialogButtonBox::Apply))
|
|
|
|
{
|
|
|
|
m_inputManager->Save();
|
|
|
|
}
|
|
|
|
else if (button == ui->buttonBox->button(QDialogButtonBox::RestoreDefaults))
|
|
|
|
{
|
|
|
|
switch (ui->tabWidget->currentIndex())
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
m_inputManager->AutoConfigureKeyboard();
|
|
|
|
static_cast<CBindingModel*>(ui->tableView->model())->Refresh();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2017-06-13 04:53:18 +01:00
|
|
|
else if (button == ui->buttonBox->button(QDialogButtonBox::Cancel))
|
|
|
|
{
|
|
|
|
m_inputManager->Load();
|
|
|
|
}
|
2016-09-06 00:23:31 +01:00
|
|
|
}
|
|
|
|
|
2017-05-23 16:08:53 +01:00
|
|
|
void ControllerConfigDialog::on_tableView_doubleClicked(const QModelIndex &index)
|
|
|
|
{
|
2017-06-13 04:51:38 +01:00
|
|
|
std::string button(PS2::CControllerInfo::m_buttonName[index.row()]);
|
|
|
|
std::transform(button.begin(), button.end(),button.begin(), ::toupper);
|
|
|
|
|
|
|
|
InputEventSelectionDialog IESD;
|
|
|
|
IESD.Setup(button.c_str(), m_inputManager,
|
|
|
|
static_cast<PS2::CControllerInfo::BUTTON>(index.row()), m_inputDeviceManager);
|
|
|
|
IESD.exec();
|
|
|
|
m_inputDeviceManager.get()->DisconnectInputEventCallback();
|
2017-05-23 16:08:53 +01:00
|
|
|
}
|
|
|
|
|
2017-06-13 04:51:38 +01:00
|
|
|
void ControllerConfigDialog::on_ConfigAllButton_clicked()
|
2016-09-06 00:23:31 +01:00
|
|
|
{
|
2017-06-13 04:51:38 +01:00
|
|
|
for(int i = 0; i < PS2::CControllerInfo::MAX_BUTTONS; ++i)
|
|
|
|
{
|
|
|
|
std::string button(PS2::CControllerInfo::m_buttonName[i]);
|
|
|
|
std::transform(button.begin(), button.end(),button.begin(), ::toupper);
|
|
|
|
|
|
|
|
InputEventSelectionDialog IESD;
|
|
|
|
IESD.Setup(button.c_str(), m_inputManager,
|
|
|
|
static_cast<PS2::CControllerInfo::BUTTON>(i), m_inputDeviceManager);
|
2018-01-10 16:24:42 +00:00
|
|
|
auto res = IESD.exec();
|
|
|
|
m_inputDeviceManager.get()->DisconnectInputEventCallback();
|
|
|
|
if(!res)
|
2017-06-13 04:51:38 +01:00
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2016-09-06 00:23:31 +01:00
|
|
|
}
|