Address review comments and fix code compilation

This commit is contained in:
FearlessTobi 2020-08-29 20:56:51 +02:00
parent e6bd1fd1b8
commit d176feffad
13 changed files with 218 additions and 155 deletions

View file

@ -175,9 +175,11 @@ const GCButtonFactory* InputSubsystem::GetGCButtons() const {
return impl->gcbuttons.get();
}
void ReloadInputDevices() {
if (udp)
udp->ReloadUDPClient();
void InputSubsystem::ReloadInputDevices() {
if (!impl->udp) {
return;
}
impl->udp->ReloadUDPClient();
}
std::vector<std::unique_ptr<Polling::DevicePoller>> InputSubsystem::GetPollers(

View file

@ -118,6 +118,8 @@ public:
/// Retrieves the underlying GameCube button handler.
[[nodiscard]] const GCButtonFactory* GetGCButtons() const;
void ReloadInputDevices();
/// Get all DevicePoller from all backends for a specific device type
[[nodiscard]] std::vector<std::unique_ptr<Polling::DevicePoller>> GetPollers(
Polling::DeviceType type) const;

View file

@ -30,14 +30,15 @@ public:
static_cast<int>(Layout::ScreenUndocked::Width);
const float y = static_cast<float>(std::get<2>(m)) /
static_cast<int>(Layout::ScreenUndocked::Height);
return std::make_tuple(x, y, true);
return {x, y, true};
}
}
return std::make_tuple(0.0f, 0.0f, false);
return {};
}
private:
std::vector<std::tuple<std::unique_ptr<Input::ButtonDevice>, int, int>> map; // button, x, y
// A vector of the mapped button, its x and its y-coordinate
std::vector<std::tuple<std::unique_ptr<Input::ButtonDevice>, int, int>> map;
};
std::unique_ptr<Input::TouchDevice> TouchFromButtonFactory::Create(

View file

@ -420,10 +420,17 @@ void Config::ReadControlValues() {
ReadKeyboardValues();
ReadMouseValues();
ReadTouchscreenValues();
ReadMotionTouchValues();
Settings::values.vibration_enabled =
ReadSetting(QStringLiteral("vibration_enabled"), true).toBool();
Settings::values.use_docked_mode =
ReadSetting(QStringLiteral("use_docked_mode"), false).toBool();
qt_config->endGroup();
}
void Config::ReadMotionTouchValues() {
int num_touch_from_button_maps =
qt_config->beginReadArray(QStringLiteral("touch_from_button_maps"));
@ -481,10 +488,6 @@ void Config::ReadControlValues() {
.toInt());
Settings::values.udp_pad_index =
static_cast<u8>(ReadSetting(QStringLiteral("udp_pad_index"), 0).toUInt());
Settings::values.use_docked_mode =
ReadSetting(QStringLiteral("use_docked_mode"), false).toBool();
qt_config->endGroup();
}
void Config::ReadCoreValues() {
@ -977,6 +980,43 @@ void Config::SaveTouchscreenValues() {
WriteSetting(QStringLiteral("touchscreen_diameter_y"), touchscreen.diameter_y, 15);
}
void Config::SaveMotionTouchValues() {
WriteSetting(QStringLiteral("motion_device"),
QString::fromStdString(Settings::values.motion_device),
QStringLiteral("engine:motion_emu,update_period:100,sensitivity:0.01"));
WriteSetting(QStringLiteral("touch_device"),
QString::fromStdString(Settings::values.touch_device),
QStringLiteral("engine:emu_window"));
WriteSetting(QStringLiteral("use_touch_from_button"), Settings::values.use_touch_from_button,
false);
WriteSetting(QStringLiteral("touch_from_button_map"),
Settings::values.touch_from_button_map_index, 0);
WriteSetting(QStringLiteral("udp_input_address"),
QString::fromStdString(Settings::values.udp_input_address),
QString::fromUtf8(InputCommon::CemuhookUDP::DEFAULT_ADDR));
WriteSetting(QStringLiteral("udp_input_port"), Settings::values.udp_input_port,
InputCommon::CemuhookUDP::DEFAULT_PORT);
WriteSetting(QStringLiteral("udp_pad_index"), Settings::values.udp_pad_index, 0);
qt_config->beginWriteArray(QStringLiteral("touch_from_button_maps"));
for (std::size_t p = 0; p < Settings::values.touch_from_button_maps.size(); ++p) {
qt_config->setArrayIndex(static_cast<int>(p));
WriteSetting(QStringLiteral("name"),
QString::fromStdString(Settings::values.touch_from_button_maps[p].name),
QStringLiteral("default"));
qt_config->beginWriteArray(QStringLiteral("entries"));
for (std::size_t q = 0; q < Settings::values.touch_from_button_maps[p].buttons.size();
++q) {
qt_config->setArrayIndex(static_cast<int>(q));
WriteSetting(
QStringLiteral("bind"),
QString::fromStdString(Settings::values.touch_from_button_maps[p].buttons[q]));
}
qt_config->endArray();
}
qt_config->endArray();
}
void Config::SaveValues() {
if (global) {
SaveControlValues();
@ -1019,6 +1059,7 @@ void Config::SaveControlValues() {
SaveDebugValues();
SaveMouseValues();
SaveTouchscreenValues();
SaveMotionTouchValues();
WriteSetting(QStringLiteral("vibration_enabled"), Settings::values.vibration_enabled, true);
WriteSetting(QStringLiteral("motion_device"),
@ -1028,36 +1069,8 @@ void Config::SaveControlValues() {
QString::fromStdString(Settings::values.touch_device),
QStringLiteral("engine:emu_window"));
WriteSetting(QStringLiteral("keyboard_enabled"), Settings::values.keyboard_enabled, false);
WriteSetting(QStringLiteral("use_touch_from_button"), Settings::values.use_touch_from_button,
false);
WriteSetting(QStringLiteral("touch_from_button_map"),
Settings::values.touch_from_button_map_index, 0);
WriteSetting(QStringLiteral("udp_input_address"),
QString::fromStdString(Settings::values.udp_input_address),
QString::fromUtf8(InputCommon::CemuhookUDP::DEFAULT_ADDR));
WriteSetting(QStringLiteral("udp_input_port"), Settings::values.udp_input_port,
InputCommon::CemuhookUDP::DEFAULT_PORT);
WriteSetting(QStringLiteral("udp_pad_index"), Settings::values.udp_pad_index, 0);
WriteSetting(QStringLiteral("use_docked_mode"), Settings::values.use_docked_mode, false);
qt_config->beginWriteArray(QStringLiteral("touch_from_button_maps"));
for (std::size_t p = 0; p < Settings::values.touch_from_button_maps.size(); ++p) {
qt_config->setArrayIndex(static_cast<int>(p));
WriteSetting(QStringLiteral("name"),
QString::fromStdString(Settings::values.touch_from_button_maps[p].name),
QStringLiteral("default"));
qt_config->beginWriteArray(QStringLiteral("entries"));
for (std::size_t q = 0; q < Settings::values.touch_from_button_maps[p].buttons.size();
++q) {
qt_config->setArrayIndex(static_cast<int>(q));
WriteSetting(
QStringLiteral("bind"),
QString::fromStdString(Settings::values.touch_from_button_maps[p].buttons[q]));
}
qt_config->endArray();
}
qt_config->endArray();
qt_config->endGroup();
}

View file

@ -38,6 +38,7 @@ private:
void ReadKeyboardValues();
void ReadMouseValues();
void ReadTouchscreenValues();
void ReadMotionTouchValues();
// Read functions bases off the respective config section names.
void ReadAudioValues();
@ -64,6 +65,7 @@ private:
void SaveDebugValues();
void SaveMouseValues();
void SaveTouchscreenValues();
void SaveMotionTouchValues();
// Save functions based off the respective config section names.
void SaveAudioValues();

View file

@ -128,15 +128,14 @@ void ConfigureInput::Initialize(InputCommon::InputSubsystem* input_subsystem) {
});
connect(advanced, &ConfigureInputAdvanced::CallTouchscreenConfigDialog,
[this] { CallConfigureDialog<ConfigureTouchscreenAdvanced>(*this); });
connect(advanced, &ConfigureInputAdvanced::CallMotionTouchConfigDialog,
[this, input_subsystem] {
CallConfigureDialog<ConfigureMotionTouch>(*this, input_subsystem);
});
connect(ui->buttonClearAll, &QPushButton::clicked, [this] { ClearAll(); });
connect(ui->buttonRestoreDefaults, &QPushButton::clicked, [this] { RestoreDefaults(); });
connect(ui->buttonMotionTouch, &QPushButton::clicked, [this] {
QDialog* motion_touch_dialog = new ConfigureMotionTouch(this);
return motion_touch_dialog->exec();
});
RetranslateUI();
LoadConfiguration();
}

View file

@ -86,6 +86,8 @@ ConfigureInputAdvanced::ConfigureInputAdvanced(QWidget* parent)
connect(ui->mouse_advanced, &QPushButton::clicked, this, [this] { CallMouseConfigDialog(); });
connect(ui->touchscreen_advanced, &QPushButton::clicked, this,
[this] { CallTouchscreenConfigDialog(); });
connect(ui->buttonMotionTouch, &QPushButton::clicked, this,
[this] { CallMotionTouchConfigDialog(); });
LoadConfiguration();
}

View file

@ -28,6 +28,7 @@ signals:
void CallDebugControllerDialog();
void CallMouseConfigDialog();
void CallTouchscreenConfigDialog();
void CallMotionTouchConfigDialog();
private:
void changeEvent(QEvent* event) override;

View file

@ -8,7 +8,11 @@
#include <QMessageBox>
#include <QPushButton>
#include <QVBoxLayout>
#include "common/logging/log.h"
#include "core/settings.h"
#include "input_common/main.h"
#include "input_common/udp/client.h"
#include "input_common/udp/udp.h"
#include "ui_configure_motion_touch.h"
#include "yuzu/configuration/configure_motion_touch.h"
#include "yuzu/configuration/configure_touch_from_button.h"
@ -21,8 +25,9 @@ CalibrationConfigurationDialog::CalibrationConfigurationDialog(QWidget* parent,
status_label = new QLabel(tr("Communicating with the server..."));
cancel_button = new QPushButton(tr("Cancel"));
connect(cancel_button, &QPushButton::clicked, this, [this] {
if (!completed)
if (!completed) {
job->Stop();
}
accept();
});
layout->addWidget(status_label);
@ -61,36 +66,40 @@ CalibrationConfigurationDialog::CalibrationConfigurationDialog(QWidget* parent,
CalibrationConfigurationDialog::~CalibrationConfigurationDialog() = default;
void CalibrationConfigurationDialog::UpdateLabelText(QString text) {
void CalibrationConfigurationDialog::UpdateLabelText(const QString& text) {
status_label->setText(text);
}
void CalibrationConfigurationDialog::UpdateButtonText(QString text) {
void CalibrationConfigurationDialog::UpdateButtonText(const QString& text) {
cancel_button->setText(text);
}
const std::array<std::pair<const char*, const char*>, 2> MotionProviders = {
{{"motion_emu", QT_TRANSLATE_NOOP("ConfigureMotionTouch", "Mouse (Right Click)")},
{"cemuhookudp", QT_TRANSLATE_NOOP("ConfigureMotionTouch", "CemuhookUDP")}}};
constexpr std::array<std::pair<const char*, const char*>, 2> MotionProviders = {{
{"motion_emu", QT_TRANSLATE_NOOP("ConfigureMotionTouch", "Mouse (Right Click)")},
{"cemuhookudp", QT_TRANSLATE_NOOP("ConfigureMotionTouch", "CemuhookUDP")},
}};
const std::array<std::pair<const char*, const char*>, 2> TouchProviders = {
{{"emu_window", QT_TRANSLATE_NOOP("ConfigureMotionTouch", "Emulator Window")},
{"cemuhookudp", QT_TRANSLATE_NOOP("ConfigureMotionTouch", "CemuhookUDP")}}};
constexpr std::array<std::pair<const char*, const char*>, 2> TouchProviders = {{
{"emu_window", QT_TRANSLATE_NOOP("ConfigureMotionTouch", "Emulator Window")},
{"cemuhookudp", QT_TRANSLATE_NOOP("ConfigureMotionTouch", "CemuhookUDP")},
}};
ConfigureMotionTouch::ConfigureMotionTouch(QWidget* parent)
: QDialog(parent), ui(std::make_unique<Ui::ConfigureMotionTouch>()) {
ConfigureMotionTouch::ConfigureMotionTouch(QWidget* parent,
InputCommon::InputSubsystem* input_subsystem_)
: QDialog(parent), input_subsystem{input_subsystem_},
ui(std::make_unique<Ui::ConfigureMotionTouch>()) {
ui->setupUi(this);
for (auto [provider, name] : MotionProviders) {
for (const auto [provider, name] : MotionProviders) {
ui->motion_provider->addItem(tr(name), QString::fromUtf8(provider));
}
for (auto [provider, name] : TouchProviders) {
for (const auto [provider, name] : TouchProviders) {
ui->touch_provider->addItem(tr(name), QString::fromUtf8(provider));
}
ui->udp_learn_more->setOpenExternalLinks(true);
ui->udp_learn_more->setText(
tr("<a "
"href='https://citra-emu.org/wiki/"
"href='https://yuzu-emu.org/wiki/"
"using-a-controller-or-android-phone-for-motion-or-touch-input'><span "
"style=\"text-decoration: underline; color:#039be5;\">Learn More</span></a>"));
@ -130,10 +139,11 @@ void ConfigureMotionTouch::SetConfiguration() {
}
void ConfigureMotionTouch::UpdateUiDisplay() {
std::string motion_engine = ui->motion_provider->currentData().toString().toStdString();
std::string touch_engine = ui->touch_provider->currentData().toString().toStdString();
const QString motion_engine = ui->motion_provider->currentData().toString();
const QString touch_engine = ui->touch_provider->currentData().toString();
QString cemuhook_udp = QStringLiteral("cemuhookudp");
if (motion_engine == "motion_emu") {
if (motion_engine == QStringLiteral("motion_emu")) {
ui->motion_sensitivity_label->setVisible(true);
ui->motion_sensitivity->setVisible(true);
} else {
@ -141,20 +151,19 @@ void ConfigureMotionTouch::UpdateUiDisplay() {
ui->motion_sensitivity->setVisible(false);
}
if (touch_engine == "cemuhookudp") {
if (touch_engine == cemuhook_udp) {
ui->touch_calibration->setVisible(true);
ui->touch_calibration_config->setVisible(true);
ui->touch_calibration_label->setVisible(true);
ui->touch_calibration->setText(QStringLiteral("(%1, %2) - (%3, %4)")
.arg(QString::number(min_x), QString::number(min_y),
QString::number(max_x), QString::number(max_y)));
ui->touch_calibration->setText(
QStringLiteral("(%1, %2) - (%3, %4)").arg(min_x).arg(min_y).arg(max_x).arg(max_y));
} else {
ui->touch_calibration->setVisible(false);
ui->touch_calibration_config->setVisible(false);
ui->touch_calibration_label->setVisible(false);
}
if (motion_engine == "cemuhookudp" || touch_engine == "cemuhookudp") {
if (motion_engine == cemuhook_udp || touch_engine == cemuhook_udp) {
ui->udp_config_group_box->setVisible(true);
} else {
ui->udp_config_group_box->setVisible(false);
@ -162,11 +171,9 @@ void ConfigureMotionTouch::UpdateUiDisplay() {
}
void ConfigureMotionTouch::ConnectEvents() {
connect(ui->motion_provider,
static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this,
connect(ui->motion_provider, qOverload<int>(&QComboBox::currentIndexChanged), this,
[this](int index) { UpdateUiDisplay(); });
connect(ui->touch_provider,
static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this,
connect(ui->touch_provider, qOverload<int>(&QComboBox::currentIndexChanged), this,
[this](int index) { UpdateUiDisplay(); });
connect(ui->udp_test, &QPushButton::clicked, this, &ConfigureMotionTouch::OnCemuhookUDPTest);
connect(ui->touch_calibration_config, &QPushButton::clicked, this,
@ -174,8 +181,9 @@ void ConfigureMotionTouch::ConnectEvents() {
connect(ui->touch_from_button_config_btn, &QPushButton::clicked, this,
&ConfigureMotionTouch::OnConfigureTouchFromButton);
connect(ui->buttonBox, &QDialogButtonBox::rejected, this, [this] {
if (CanCloseDialog())
if (CanCloseDialog()) {
reject();
}
});
}
@ -199,15 +207,15 @@ void ConfigureMotionTouch::OnCemuhookUDPTest() {
void ConfigureMotionTouch::OnConfigureTouchCalibration() {
ui->touch_calibration_config->setEnabled(false);
ui->touch_calibration_config->setText(tr("Configuring"));
CalibrationConfigurationDialog* dialog = new CalibrationConfigurationDialog(
CalibrationConfigurationDialog dialog(
this, ui->udp_server->text().toStdString(), static_cast<u16>(ui->udp_port->text().toUInt()),
static_cast<u8>(ui->udp_pad_index->currentIndex()), 24872);
dialog->exec();
if (dialog->completed) {
min_x = dialog->min_x;
min_y = dialog->min_y;
max_x = dialog->max_x;
max_y = dialog->max_y;
dialog.exec();
if (dialog.completed) {
min_x = dialog.min_x;
min_y = dialog.min_y;
max_x = dialog.max_x;
max_y = dialog.max_y;
LOG_INFO(Frontend,
"UDP touchpad calibration config success: min_x={}, min_y={}, max_x={}, max_y={}",
min_x, min_y, max_x, max_y);
@ -220,10 +228,11 @@ void ConfigureMotionTouch::OnConfigureTouchCalibration() {
}
void ConfigureMotionTouch::closeEvent(QCloseEvent* event) {
if (CanCloseDialog())
if (CanCloseDialog()) {
event->accept();
else
} else {
event->ignore();
}
}
void ConfigureMotionTouch::ShowUDPTestResult(bool result) {
@ -242,7 +251,7 @@ void ConfigureMotionTouch::ShowUDPTestResult(bool result) {
}
void ConfigureMotionTouch::OnConfigureTouchFromButton() {
ConfigureTouchFromButton dialog{this, touch_from_button_maps,
ConfigureTouchFromButton dialog{this, touch_from_button_maps, input_subsystem,
ui->touch_from_button_map->currentIndex()};
if (dialog.exec() != QDialog::Accepted) {
return;
@ -269,8 +278,9 @@ bool ConfigureMotionTouch::CanCloseDialog() {
}
void ConfigureMotionTouch::ApplyConfiguration() {
if (!CanCloseDialog())
if (!CanCloseDialog()) {
return;
}
std::string motion_engine = ui->motion_provider->currentData().toString().toStdString();
std::string touch_engine = ui->touch_provider->currentData().toString().toStdString();
@ -298,7 +308,7 @@ void ConfigureMotionTouch::ApplyConfiguration() {
Settings::values.udp_input_address = ui->udp_server->text().toStdString();
Settings::values.udp_input_port = static_cast<u16>(ui->udp_port->text().toInt());
Settings::values.udp_pad_index = static_cast<u8>(ui->udp_pad_index->currentIndex());
InputCommon::ReloadInputDevices();
input_subsystem->ReloadInputDevices();
accept();
}

View file

@ -7,29 +7,30 @@
#include <memory>
#include <QDialog>
#include "common/param_package.h"
#include "core/settings.h"
#include "input_common/udp/client.h"
#include "input_common/udp/udp.h"
class QVBoxLayout;
class QLabel;
class QPushButton;
class QVBoxLayout;
namespace Ui {
class ConfigureMotionTouch;
}
namespace InputCommon::CemuhookUDP {
class CalibrationConfigurationJob;
}
/// A dialog for touchpad calibration configuration.
class CalibrationConfigurationDialog : public QDialog {
Q_OBJECT
public:
explicit CalibrationConfigurationDialog(QWidget* parent, const std::string& host, u16 port,
u8 pad_index, u16 client_id);
~CalibrationConfigurationDialog();
~CalibrationConfigurationDialog() override;
private:
Q_INVOKABLE void UpdateLabelText(QString text);
Q_INVOKABLE void UpdateButtonText(QString text);
Q_INVOKABLE void UpdateLabelText(const QString& text);
Q_INVOKABLE void UpdateButtonText(const QString& text);
QVBoxLayout* layout;
QLabel* status_label;
@ -38,7 +39,10 @@ private:
// Configuration results
bool completed{};
u16 min_x, min_y, max_x, max_y;
u16 min_x{};
u16 min_y{};
u16 max_x{};
u16 max_y{};
friend class ConfigureMotionTouch;
};
@ -47,7 +51,7 @@ class ConfigureMotionTouch : public QDialog {
Q_OBJECT
public:
explicit ConfigureMotionTouch(QWidget* parent = nullptr);
explicit ConfigureMotionTouch(QWidget* parent, InputCommon::InputSubsystem* input_subsystem_);
~ConfigureMotionTouch() override;
public slots:
@ -69,9 +73,14 @@ private:
std::unique_ptr<Ui::ConfigureMotionTouch> ui;
// Coordinate system of the CemuhookUDP touch provider
int min_x, min_y, max_x, max_y;
int min_x{};
int min_y{};
int max_x{};
int max_y{};
bool udp_test_in_progress{};
InputCommon::InputSubsystem* input_subsystem;
std::vector<Settings::TouchFromButtonMap> touch_from_button_maps;
};

View file

@ -10,6 +10,8 @@
#include <QStandardItemModel>
#include <QTimer>
#include "common/param_package.h"
#include "core/frontend/framebuffer_layout.h"
#include "core/settings.h"
#include "input_common/main.h"
#include "ui_configure_touch_from_button.h"
#include "yuzu/configuration/configure_touch_from_button.h"
@ -68,15 +70,16 @@ static QString ButtonToText(const Common::ParamPackage& param) {
ConfigureTouchFromButton::ConfigureTouchFromButton(
QWidget* parent, const std::vector<Settings::TouchFromButtonMap>& touch_maps,
const int default_index)
: QDialog(parent), ui(std::make_unique<Ui::ConfigureTouchFromButton>()), touch_maps(touch_maps),
selected_index(default_index), timeout_timer(std::make_unique<QTimer>()),
poll_timer(std::make_unique<QTimer>()) {
InputCommon::InputSubsystem* input_subsystem_, const int default_index)
: QDialog(parent), ui(std::make_unique<Ui::ConfigureTouchFromButton>()),
touch_maps(touch_maps), input_subsystem{input_subsystem_}, selected_index(default_index),
timeout_timer(std::make_unique<QTimer>()), poll_timer(std::make_unique<QTimer>()) {
ui->setupUi(this);
binding_list_model = std::make_unique<QStandardItemModel>(0, 3, this);
binding_list_model->setHorizontalHeaderLabels({tr("Button"), tr("X"), tr("Y")});
ui->binding_list->setModel(binding_list_model.get());
binding_list_model = new QStandardItemModel(0, 3, this);
binding_list_model->setHorizontalHeaderLabels(
{tr("Button"), tr("X", "X axis"), tr("Y", "Y axis")});
ui->binding_list->setModel(binding_list_model);
ui->bottom_screen->SetCoordLabel(ui->coord_label);
SetConfiguration();
@ -92,11 +95,12 @@ void ConfigureTouchFromButton::showEvent(QShowEvent* ev) {
// width values are not valid in the constructor
const int w =
ui->binding_list->viewport()->contentsRect().width() / binding_list_model->columnCount();
if (w > 0) {
if (w <= 0) {
return;
}
ui->binding_list->setColumnWidth(0, w);
ui->binding_list->setColumnWidth(1, w);
ui->binding_list->setColumnWidth(2, w);
}
}
void ConfigureTouchFromButton::SetConfiguration() {
@ -122,7 +126,7 @@ void ConfigureTouchFromButton::UpdateUiDisplay() {
QStandardItem* ycoord = new QStandardItem(QString::number(package.Get("y", 0)));
binding_list_model->appendRow({button, xcoord, ycoord});
int dot = ui->bottom_screen->AddDot(package.Get("x", 0), package.Get("y", 0));
const int dot = ui->bottom_screen->AddDot(package.Get("x", 0), package.Get("y", 0));
button->setData(dot, DataRoleDot);
}
}
@ -144,7 +148,7 @@ void ConfigureTouchFromButton::ConnectEvents() {
&ConfigureTouchFromButton::EditBinding);
connect(ui->binding_list->selectionModel(), &QItemSelectionModel::selectionChanged, this,
&ConfigureTouchFromButton::OnBindingSelection);
connect(binding_list_model.get(), &QStandardItemModel::itemChanged, this,
connect(binding_list_model, &QStandardItemModel::itemChanged, this,
&ConfigureTouchFromButton::OnBindingChanged);
connect(ui->binding_list->model(), &QStandardItemModel::rowsAboutToBeRemoved, this,
&ConfigureTouchFromButton::OnBindingDeleted);
@ -231,7 +235,7 @@ void ConfigureTouchFromButton::GetButtonInput(const int row_index, const bool is
input_setter = [this, row_index, is_new](const Common::ParamPackage& params,
const bool cancel) {
auto cell = binding_list_model->item(row_index, 0);
auto* cell = binding_list_model->item(row_index, 0);
if (cancel) {
if (is_new) {
binding_list_model->removeRow(row_index);
@ -245,7 +249,7 @@ void ConfigureTouchFromButton::GetButtonInput(const int row_index, const bool is
}
};
device_pollers = InputCommon::Polling::GetPollers(InputCommon::Polling::DeviceType::Button);
device_pollers = input_subsystem->GetPollers(InputCommon::Polling::DeviceType::Button);
for (auto& poller : device_pollers) {
poller->Start();
@ -259,15 +263,15 @@ void ConfigureTouchFromButton::GetButtonInput(const int row_index, const bool is
}
void ConfigureTouchFromButton::NewBinding(const QPoint& pos) {
QStandardItem* button = new QStandardItem();
auto* button = new QStandardItem();
button->setEditable(false);
QStandardItem* xcoord = new QStandardItem(QString::number(pos.x()));
QStandardItem* ycoord = new QStandardItem(QString::number(pos.y()));
auto* x_coord = new QStandardItem(QString::number(pos.x()));
auto* y_coord = new QStandardItem(QString::number(pos.y()));
const int dot_id = ui->bottom_screen->AddDot(pos.x(), pos.y());
button->setData(dot_id, DataRoleDot);
binding_list_model->appendRow({button, xcoord, ycoord});
binding_list_model->appendRow({button, x_coord, y_coord});
ui->binding_list->setFocus();
ui->binding_list->setCurrentIndex(button->index());
@ -282,11 +286,11 @@ void ConfigureTouchFromButton::EditBinding(const QModelIndex& qi) {
void ConfigureTouchFromButton::DeleteBinding() {
const int row_index = ui->binding_list->currentIndex().row();
if (row_index >= 0) {
ui->bottom_screen->RemoveDot(
binding_list_model->index(row_index, 0).data(DataRoleDot).toInt());
binding_list_model->removeRow(row_index);
if (row_index < 0) {
return;
}
ui->bottom_screen->RemoveDot(binding_list_model->index(row_index, 0).data(DataRoleDot).toInt());
binding_list_model->removeRow(row_index);
}
void ConfigureTouchFromButton::OnBindingSelection(const QItemSelection& selected,
@ -329,7 +333,7 @@ void ConfigureTouchFromButton::OnBindingChanged(QStandardItem* item) {
void ConfigureTouchFromButton::OnBindingDeleted(const QModelIndex& parent, int first, int last) {
for (int i = first; i <= last; ++i) {
auto ix = binding_list_model->index(i, 0);
const auto ix = binding_list_model->index(i, 0);
if (!ix.isValid()) {
return;
}
@ -422,7 +426,7 @@ int TouchScreenPreview::AddDot(const int device_x, const int device_y) {
dot_font.setStyleHint(QFont::Monospace);
dot_font.setPointSize(20);
QLabel* dot = new QLabel(this);
auto* dot = new QLabel(this);
dot->setAttribute(Qt::WA_TranslucentBackground);
dot->setFont(dot_font);
dot->setText(QChar(0xD7)); // U+00D7 Multiplication Sign
@ -440,13 +444,14 @@ int TouchScreenPreview::AddDot(const int device_x, const int device_y) {
}
void TouchScreenPreview::RemoveDot(const int id) {
for (auto dot_it = dots.begin(); dot_it != dots.end(); ++dot_it) {
if (dot_it->first == id) {
dot_it->second->deleteLater();
dots.erase(dot_it);
const auto iter = std::find_if(dots.begin(), dots.end(),
[id](const auto& entry) { return entry.first == id; });
if (iter == dots.cend()) {
return;
}
}
iter->second->deleteLater();
dots.erase(iter);
}
void TouchScreenPreview::HighlightDot(const int id, const bool active) const {
@ -470,14 +475,15 @@ void TouchScreenPreview::HighlightDot(const int id, const bool active) const {
}
void TouchScreenPreview::MoveDot(const int id, const int device_x, const int device_y) const {
for (const auto& dot : dots) {
if (dot.first == id) {
dot.second->setProperty(PropX, device_x);
dot.second->setProperty(PropY, device_y);
PositionDot(dot.second, device_x, device_y);
const auto iter = std::find_if(dots.begin(), dots.end(),
[id](const auto& entry) { return entry.first == id; });
if (iter == dots.cend()) {
return;
}
}
iter->second->setProperty(PropX, device_x);
iter->second->setProperty(PropY, device_y);
PositionDot(iter->second, device_x, device_y);
}
void TouchScreenPreview::resizeEvent(QResizeEvent* event) {
@ -521,12 +527,13 @@ void TouchScreenPreview::leaveEvent(QEvent* event) {
}
void TouchScreenPreview::mousePressEvent(QMouseEvent* event) {
if (event->button() == Qt::MouseButton::LeftButton) {
if (event->button() != Qt::MouseButton::LeftButton) {
return;
}
const auto pos = MapToDeviceCoords(event->x(), event->y());
if (pos) {
emit DotAdded(*pos);
}
}
}
bool TouchScreenPreview::eventFilter(QObject* obj, QEvent* event) {
@ -601,12 +608,17 @@ std::optional<QPoint> TouchScreenPreview::MapToDeviceCoords(const int screen_x,
void TouchScreenPreview::PositionDot(QLabel* const dot, const int device_x,
const int device_y) const {
dot->move(static_cast<int>(
static_cast<float>(device_x >= 0 ? device_x : dot->property(PropX).toInt()) *
(contentsRect().width() - 1) / (Layout::ScreenUndocked::Width - 1) +
contentsMargins().left() - static_cast<float>(dot->width()) / 2 + 0.5f),
static_cast<int>(
static_cast<float>(device_y >= 0 ? device_y : dot->property(PropY).toInt()) *
(contentsRect().height() - 1) / (Layout::ScreenUndocked::Height - 1) +
contentsMargins().top() - static_cast<float>(dot->height()) / 2 + 0.5f));
const float device_coord_x =
static_cast<float>(device_x >= 0 ? device_x : dot->property(PropX).toInt());
int x_coord = static_cast<int>(
device_coord_x * (contentsRect().width() - 1) / (Layout::ScreenUndocked::Width - 1) +
contentsMargins().left() - static_cast<float>(dot->width()) / 2 + 0.5f);
const float device_coord_y =
static_cast<float>(device_y >= 0 ? device_y : dot->property(PropY).toInt());
const int y_coord = static_cast<int>(
device_coord_y * (contentsRect().height() - 1) / (Layout::ScreenUndocked::Height - 1) +
contentsMargins().top() - static_cast<float>(dot->height()) / 2 + 0.5f);
dot->move(x_coord, y_coord);
}

View file

@ -9,8 +9,6 @@
#include <optional>
#include <vector>
#include <QDialog>
#include "core/frontend/framebuffer_layout.h"
#include "core/settings.h"
class QItemSelection;
class QModelIndex;
@ -18,6 +16,10 @@ class QStandardItemModel;
class QStandardItem;
class QTimer;
namespace InputCommon {
class InputSubsystem;
}
namespace Common {
class ParamPackage;
}
@ -32,12 +34,17 @@ namespace Ui {
class ConfigureTouchFromButton;
}
namespace Settings {
struct TouchFromButtonMap;
}
class ConfigureTouchFromButton : public QDialog {
Q_OBJECT
public:
explicit ConfigureTouchFromButton(QWidget* parent,
const std::vector<Settings::TouchFromButtonMap>& touch_maps,
InputCommon::InputSubsystem* input_subsystem_,
int default_index = 0);
~ConfigureTouchFromButton() override;
@ -51,8 +58,8 @@ public slots:
void SetCoordinates(int dot_id, const QPoint& pos);
protected:
virtual void showEvent(QShowEvent* ev) override;
virtual void keyPressEvent(QKeyEvent* event) override;
void showEvent(QShowEvent* ev) override;
void keyPressEvent(QKeyEvent* event) override;
private slots:
void NewMapping();
@ -73,10 +80,12 @@ private:
void SaveCurrentMapping();
std::unique_ptr<Ui::ConfigureTouchFromButton> ui;
std::unique_ptr<QStandardItemModel> binding_list_model;
std::vector<Settings::TouchFromButtonMap> touch_maps;
QStandardItemModel* binding_list_model;
int selected_index;
InputCommon::InputSubsystem* input_subsystem;
std::unique_ptr<QTimer> timeout_timer;
std::unique_ptr<QTimer> poll_timer;
std::vector<std::unique_ptr<InputCommon::Polling::DevicePoller>> device_pollers;

View file

@ -33,11 +33,11 @@ signals:
void DotMoved(int dot_id, const QPoint& pos);
protected:
virtual void resizeEvent(QResizeEvent*) override;
virtual void mouseMoveEvent(QMouseEvent*) override;
virtual void leaveEvent(QEvent*) override;
virtual void mousePressEvent(QMouseEvent*) override;
virtual bool eventFilter(QObject*, QEvent*) override;
void resizeEvent(QResizeEvent*) override;
void mouseMoveEvent(QMouseEvent*) override;
void leaveEvent(QEvent*) override;
void mousePressEvent(QMouseEvent*) override;
bool eventFilter(QObject*, QEvent*) override;
private:
std::optional<QPoint> MapToDeviceCoords(int screen_x, int screen_y) const;
@ -53,9 +53,10 @@ private:
static constexpr char PropX[] = "device_x";
static constexpr char PropY[] = "device_y";
struct {
struct DragState {
bool active = false;
QPointer<QLabel> dot;
QPoint start_pos;
} drag_state;
};
DragState drag_state;
};