2020-09-16 15:09:14 -04:00
|
|
|
#include "inputbindingmodel.h"
|
2017-05-23 16:08:53 +01:00
|
|
|
#include "ControllerInfo.h"
|
2020-09-14 19:43:25 -04:00
|
|
|
#include "../input/InputBindingManager.h"
|
2017-05-23 16:08:53 +01:00
|
|
|
|
2018-04-30 21:01:23 +01:00
|
|
|
#define CONFIG_PREFIX ("input")
|
|
|
|
#define CONFIG_BINDING_TYPE ("bindingtype")
|
2017-05-23 16:08:53 +01:00
|
|
|
|
2020-09-16 15:09:14 -04:00
|
|
|
CInputBindingModel::CInputBindingModel(QObject* parent, CInputBindingManager* inputManager, uint32 padIndex)
|
2018-04-30 21:01:23 +01:00
|
|
|
: QAbstractTableModel(parent)
|
2020-09-14 19:43:25 -04:00
|
|
|
, m_inputManager(inputManager)
|
|
|
|
, m_padIndex(padIndex)
|
2017-05-23 16:08:53 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2020-09-16 15:09:14 -04:00
|
|
|
int CInputBindingModel::rowCount(const QModelIndex& /*parent*/) const
|
2017-05-23 16:08:53 +01:00
|
|
|
{
|
|
|
|
return PS2::CControllerInfo::MAX_BUTTONS;
|
|
|
|
}
|
|
|
|
|
2020-09-16 15:09:14 -04:00
|
|
|
int CInputBindingModel::columnCount(const QModelIndex& /*parent*/) const
|
2017-05-23 16:08:53 +01:00
|
|
|
{
|
|
|
|
return 3;
|
|
|
|
}
|
|
|
|
|
2020-09-16 15:09:14 -04:00
|
|
|
QVariant CInputBindingModel::data(const QModelIndex& index, int role) const
|
2017-05-23 16:08:53 +01:00
|
|
|
{
|
2018-04-30 21:01:23 +01:00
|
|
|
if(role == Qt::DisplayRole)
|
2017-05-23 16:08:53 +01:00
|
|
|
{
|
2020-09-14 19:43:25 -04:00
|
|
|
auto binding = m_inputManager->GetBinding(m_padIndex, static_cast<PS2::CControllerInfo::BUTTON>(index.row()));
|
2023-04-19 13:13:27 -04:00
|
|
|
switch(index.column())
|
2017-05-23 16:08:53 +01:00
|
|
|
{
|
2023-04-19 13:13:27 -04:00
|
|
|
case 0:
|
|
|
|
{
|
|
|
|
std::string str(PS2::CControllerInfo::m_buttonName[index.row()]);
|
|
|
|
std::transform(str.begin(), str.end(), str.begin(), ::toupper);
|
|
|
|
return QVariant(str.c_str());
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
return binding ? QVariant(binding->GetBindingTypeName()) : QVariant();
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
return binding ? QVariant(binding->GetDescription(m_inputManager).c_str()) : QVariant();
|
2017-05-23 16:08:53 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return QVariant();
|
|
|
|
}
|
|
|
|
|
2020-09-16 15:09:14 -04:00
|
|
|
bool CInputBindingModel::setHeaderData(int section, Qt::Orientation orientation, const QVariant& value, int role)
|
2017-05-23 16:08:53 +01:00
|
|
|
{
|
2018-04-30 21:01:23 +01:00
|
|
|
if(orientation == Qt::Horizontal)
|
2017-05-23 16:08:53 +01:00
|
|
|
{
|
|
|
|
if(role == Qt::DisplayRole)
|
|
|
|
{
|
|
|
|
m_h_header.insert(section, value);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return QAbstractTableModel::setHeaderData(section, orientation, value, role);
|
|
|
|
}
|
|
|
|
|
2020-09-16 15:09:14 -04:00
|
|
|
QVariant CInputBindingModel::headerData(int section, Qt::Orientation orientation, int role) const
|
2017-05-23 16:08:53 +01:00
|
|
|
{
|
2018-04-30 21:01:23 +01:00
|
|
|
if(orientation == Qt::Horizontal)
|
2017-05-23 16:08:53 +01:00
|
|
|
{
|
|
|
|
if(role == Qt::DisplayRole)
|
|
|
|
{
|
2018-04-30 21:01:23 +01:00
|
|
|
if(section < m_h_header.size())
|
2017-05-23 16:08:53 +01:00
|
|
|
return m_h_header.at(section);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return QAbstractTableModel::headerData(section, orientation, role);
|
|
|
|
}
|
|
|
|
|
2020-09-16 15:09:14 -04:00
|
|
|
void CInputBindingModel::Refresh()
|
2017-05-23 16:08:53 +01:00
|
|
|
{
|
|
|
|
QAbstractTableModel::layoutChanged();
|
|
|
|
}
|