mirror of
https://github.com/RPCS3/rpcs3
synced 2024-09-05 07:56:33 +00:00
Qt: use mouse input to map basic mouse buttons
This commit is contained in:
parent
eb8ab8ef15
commit
7ffb61f650
|
@ -9,14 +9,14 @@ struct mouse_config final : cfg::node
|
||||||
|
|
||||||
const std::string cfg_name;
|
const std::string cfg_name;
|
||||||
|
|
||||||
cfg::string mouse_button_1{this, "Button 1", "LeftButton"};
|
cfg::string mouse_button_1{this, "Button 1", "Mouse Left"};
|
||||||
cfg::string mouse_button_2{this, "Button 2", "RightButton"};
|
cfg::string mouse_button_2{this, "Button 2", "Mouse Right"};
|
||||||
cfg::string mouse_button_3{this, "Button 3", "MiddleButton"};
|
cfg::string mouse_button_3{this, "Button 3", "Mouse Middle"};
|
||||||
cfg::string mouse_button_4{this, "Button 4", "NoButton"};
|
cfg::string mouse_button_4{this, "Button 4", ""};
|
||||||
cfg::string mouse_button_5{this, "Button 5", "NoButton"};
|
cfg::string mouse_button_5{this, "Button 5", ""};
|
||||||
cfg::string mouse_button_6{this, "Button 6", "NoButton"};
|
cfg::string mouse_button_6{this, "Button 6", ""};
|
||||||
cfg::string mouse_button_7{this, "Button 7", "NoButton"};
|
cfg::string mouse_button_7{this, "Button 7", ""};
|
||||||
cfg::string mouse_button_8{this, "Button 8", "NoButton"};
|
cfg::string mouse_button_8{this, "Button 8", ""};
|
||||||
|
|
||||||
bool exist() const;
|
bool exist() const;
|
||||||
bool load();
|
bool load();
|
||||||
|
|
|
@ -5,12 +5,11 @@
|
||||||
#include "util/logs.hpp"
|
#include "util/logs.hpp"
|
||||||
|
|
||||||
#include "basic_mouse_handler.h"
|
#include "basic_mouse_handler.h"
|
||||||
|
#include "keyboard_pad_handler.h"
|
||||||
#include "rpcs3qt/gs_frame.h"
|
#include "rpcs3qt/gs_frame.h"
|
||||||
#include "Emu/Io/interception.h"
|
#include "Emu/Io/interception.h"
|
||||||
#include "Emu/Io/mouse_config.h"
|
#include "Emu/Io/mouse_config.h"
|
||||||
|
|
||||||
LOG_CHANNEL(input_log, "Input");
|
|
||||||
|
|
||||||
mouse_config g_cfg_mouse;
|
mouse_config g_cfg_mouse;
|
||||||
|
|
||||||
void basic_mouse_handler::Init(const u32 max_connect)
|
void basic_mouse_handler::Init(const u32 max_connect)
|
||||||
|
@ -104,7 +103,8 @@ bool basic_mouse_handler::eventFilter(QObject* target, QEvent* ev)
|
||||||
|
|
||||||
void basic_mouse_handler::MouseButtonDown(QMouseEvent* event)
|
void basic_mouse_handler::MouseButtonDown(QMouseEvent* event)
|
||||||
{
|
{
|
||||||
if (const auto it = std::find_if(m_buttons.cbegin(), m_buttons.cend(), [event](const auto& entry){ return entry.second == event->button(); });
|
const int button = event->button();
|
||||||
|
if (const auto it = std::find_if(m_buttons.cbegin(), m_buttons.cend(), [button](const auto& entry){ return entry.second == button; });
|
||||||
it != m_buttons.cend())
|
it != m_buttons.cend())
|
||||||
{
|
{
|
||||||
MouseHandlerBase::Button(0, it->first, true);
|
MouseHandlerBase::Button(0, it->first, true);
|
||||||
|
@ -113,7 +113,8 @@ void basic_mouse_handler::MouseButtonDown(QMouseEvent* event)
|
||||||
|
|
||||||
void basic_mouse_handler::MouseButtonUp(QMouseEvent* event)
|
void basic_mouse_handler::MouseButtonUp(QMouseEvent* event)
|
||||||
{
|
{
|
||||||
if (const auto it = std::find_if(m_buttons.cbegin(), m_buttons.cend(), [event](const auto& entry){ return entry.second == event->button(); });
|
const int button = event->button();
|
||||||
|
if (const auto it = std::find_if(m_buttons.cbegin(), m_buttons.cend(), [button](const auto& entry){ return entry.second == button; });
|
||||||
it != m_buttons.cend())
|
it != m_buttons.cend())
|
||||||
{
|
{
|
||||||
MouseHandlerBase::Button(0, it->first, false);
|
MouseHandlerBase::Button(0, it->first, false);
|
||||||
|
@ -132,13 +133,14 @@ bool basic_mouse_handler::get_mouse_lock_state() const
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
Qt::MouseButton basic_mouse_handler::get_mouse_button(const cfg::string& button)
|
int basic_mouse_handler::get_mouse_button(const cfg::string& button)
|
||||||
{
|
{
|
||||||
const std::string value = button.to_string();
|
const std::string name = button.to_string();
|
||||||
|
const auto it = std::find_if(mouse_list.cbegin(), mouse_list.cend(), [&name](const auto& entry){ return entry.second == name; });
|
||||||
|
|
||||||
if (const auto it = qt_mouse_button_map.find(value); it != qt_mouse_button_map.cend())
|
if (it != mouse_list.cend())
|
||||||
{
|
{
|
||||||
return it->second;
|
return it->first;
|
||||||
}
|
}
|
||||||
|
|
||||||
return Qt::MouseButton::NoButton;
|
return Qt::MouseButton::NoButton;
|
||||||
|
|
|
@ -12,38 +12,6 @@ namespace cfg
|
||||||
class string;
|
class string;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const std::map<std::string, Qt::MouseButton> qt_mouse_button_map
|
|
||||||
{
|
|
||||||
{ "NoButton", Qt::MouseButton::NoButton },
|
|
||||||
{ "LeftButton", Qt::MouseButton::LeftButton },
|
|
||||||
{ "RightButton", Qt::MouseButton::RightButton },
|
|
||||||
{ "MiddleButton", Qt::MouseButton::MiddleButton },
|
|
||||||
{ "BackButton", Qt::MouseButton::BackButton },
|
|
||||||
{ "ForwardButton", Qt::MouseButton::ForwardButton },
|
|
||||||
{ "TaskButton", Qt::MouseButton::TaskButton },
|
|
||||||
{ "ExtraButton4", Qt::MouseButton::ExtraButton4 },
|
|
||||||
{ "ExtraButton5", Qt::MouseButton::ExtraButton5 },
|
|
||||||
{ "ExtraButton6", Qt::MouseButton::ExtraButton6 },
|
|
||||||
{ "ExtraButton7", Qt::MouseButton::ExtraButton7 },
|
|
||||||
{ "ExtraButton8", Qt::MouseButton::ExtraButton8 },
|
|
||||||
{ "ExtraButton9", Qt::MouseButton::ExtraButton9 },
|
|
||||||
{ "ExtraButton10", Qt::MouseButton::ExtraButton10 },
|
|
||||||
{ "ExtraButton11", Qt::MouseButton::ExtraButton11 },
|
|
||||||
{ "ExtraButton12", Qt::MouseButton::ExtraButton12 },
|
|
||||||
{ "ExtraButton13", Qt::MouseButton::ExtraButton13 },
|
|
||||||
{ "ExtraButton14", Qt::MouseButton::ExtraButton14 },
|
|
||||||
{ "ExtraButton15", Qt::MouseButton::ExtraButton15 },
|
|
||||||
{ "ExtraButton16", Qt::MouseButton::ExtraButton16 },
|
|
||||||
{ "ExtraButton17", Qt::MouseButton::ExtraButton17 },
|
|
||||||
{ "ExtraButton18", Qt::MouseButton::ExtraButton18 },
|
|
||||||
{ "ExtraButton19", Qt::MouseButton::ExtraButton19 },
|
|
||||||
{ "ExtraButton20", Qt::MouseButton::ExtraButton20 },
|
|
||||||
{ "ExtraButton21", Qt::MouseButton::ExtraButton21 },
|
|
||||||
{ "ExtraButton22", Qt::MouseButton::ExtraButton22 },
|
|
||||||
{ "ExtraButton23", Qt::MouseButton::ExtraButton23 },
|
|
||||||
{ "ExtraButton24", Qt::MouseButton::ExtraButton24 }
|
|
||||||
};
|
|
||||||
|
|
||||||
class basic_mouse_handler final : public MouseHandlerBase, public QObject
|
class basic_mouse_handler final : public MouseHandlerBase, public QObject
|
||||||
{
|
{
|
||||||
using MouseHandlerBase::MouseHandlerBase;
|
using MouseHandlerBase::MouseHandlerBase;
|
||||||
|
@ -61,7 +29,7 @@ public:
|
||||||
private:
|
private:
|
||||||
QWindow* m_target = nullptr;
|
QWindow* m_target = nullptr;
|
||||||
bool get_mouse_lock_state() const;
|
bool get_mouse_lock_state() const;
|
||||||
static Qt::MouseButton get_mouse_button(const cfg::string& button);
|
static int get_mouse_button(const cfg::string& button);
|
||||||
|
|
||||||
std::map<u8, Qt::MouseButton> m_buttons;
|
std::map<u8, int> m_buttons;
|
||||||
};
|
};
|
||||||
|
|
|
@ -658,12 +658,12 @@ std::vector<pad_list_entry> keyboard_pad_handler::list_devices()
|
||||||
return list_devices;
|
return list_devices;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string keyboard_pad_handler::GetMouseName(const QMouseEvent* event) const
|
std::string keyboard_pad_handler::GetMouseName(const QMouseEvent* event)
|
||||||
{
|
{
|
||||||
return GetMouseName(event->button());
|
return GetMouseName(event->button());
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string keyboard_pad_handler::GetMouseName(u32 button) const
|
std::string keyboard_pad_handler::GetMouseName(u32 button)
|
||||||
{
|
{
|
||||||
if (const auto it = mouse_list.find(button); it != mouse_list.cend())
|
if (const auto it = mouse_list.find(button); it != mouse_list.cend())
|
||||||
return it->second;
|
return it->second;
|
||||||
|
|
|
@ -21,51 +21,51 @@ enum mouse
|
||||||
wheel_right = 0x05555557
|
wheel_right = 0x05555557
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Unique button names for the config files and our pad settings dialog
|
||||||
|
const std::unordered_map<u32, std::string> mouse_list =
|
||||||
|
{
|
||||||
|
{ Qt::NoButton , "" },
|
||||||
|
{ Qt::LeftButton , "Mouse Left" },
|
||||||
|
{ Qt::RightButton , "Mouse Right" },
|
||||||
|
{ Qt::MiddleButton , "Mouse Middle" },
|
||||||
|
{ Qt::BackButton , "Mouse Back" },
|
||||||
|
{ Qt::ForwardButton , "Mouse Fwd" },
|
||||||
|
{ Qt::TaskButton , "Mouse Task" },
|
||||||
|
{ Qt::ExtraButton4 , "Mouse 4" },
|
||||||
|
{ Qt::ExtraButton5 , "Mouse 5" },
|
||||||
|
{ Qt::ExtraButton6 , "Mouse 6" },
|
||||||
|
{ Qt::ExtraButton7 , "Mouse 7" },
|
||||||
|
{ Qt::ExtraButton8 , "Mouse 8" },
|
||||||
|
{ Qt::ExtraButton9 , "Mouse 9" },
|
||||||
|
{ Qt::ExtraButton10 , "Mouse 10" },
|
||||||
|
{ Qt::ExtraButton11 , "Mouse 11" },
|
||||||
|
{ Qt::ExtraButton12 , "Mouse 12" },
|
||||||
|
{ Qt::ExtraButton13 , "Mouse 13" },
|
||||||
|
{ Qt::ExtraButton14 , "Mouse 14" },
|
||||||
|
{ Qt::ExtraButton15 , "Mouse 15" },
|
||||||
|
{ Qt::ExtraButton16 , "Mouse 16" },
|
||||||
|
{ Qt::ExtraButton17 , "Mouse 17" },
|
||||||
|
{ Qt::ExtraButton18 , "Mouse 18" },
|
||||||
|
{ Qt::ExtraButton19 , "Mouse 19" },
|
||||||
|
{ Qt::ExtraButton20 , "Mouse 20" },
|
||||||
|
{ Qt::ExtraButton21 , "Mouse 21" },
|
||||||
|
{ Qt::ExtraButton22 , "Mouse 22" },
|
||||||
|
{ Qt::ExtraButton23 , "Mouse 23" },
|
||||||
|
{ Qt::ExtraButton24 , "Mouse 24" },
|
||||||
|
|
||||||
|
{ mouse::move_left , "Mouse MLeft" },
|
||||||
|
{ mouse::move_right , "Mouse MRight" },
|
||||||
|
{ mouse::move_up , "Mouse MUp" },
|
||||||
|
{ mouse::move_down , "Mouse MDown" },
|
||||||
|
|
||||||
|
{ mouse::wheel_up , "Wheel Up" },
|
||||||
|
{ mouse::wheel_down , "Wheel Down" },
|
||||||
|
{ mouse::wheel_left , "Wheel Left" },
|
||||||
|
{ mouse::wheel_right , "Wheel Right" },
|
||||||
|
};
|
||||||
|
|
||||||
class keyboard_pad_handler final : public QObject, public PadHandlerBase
|
class keyboard_pad_handler final : public QObject, public PadHandlerBase
|
||||||
{
|
{
|
||||||
// Unique button names for the config files and our pad settings dialog
|
|
||||||
const std::unordered_map<u32, std::string> mouse_list =
|
|
||||||
{
|
|
||||||
{ Qt::NoButton , "" },
|
|
||||||
{ Qt::LeftButton , "Mouse Left" },
|
|
||||||
{ Qt::RightButton , "Mouse Right" },
|
|
||||||
{ Qt::MiddleButton , "Mouse Middle" },
|
|
||||||
{ Qt::BackButton , "Mouse Back" },
|
|
||||||
{ Qt::ForwardButton , "Mouse Fwd" },
|
|
||||||
{ Qt::TaskButton , "Mouse Task" },
|
|
||||||
{ Qt::ExtraButton4 , "Mouse 4" },
|
|
||||||
{ Qt::ExtraButton5 , "Mouse 5" },
|
|
||||||
{ Qt::ExtraButton6 , "Mouse 6" },
|
|
||||||
{ Qt::ExtraButton7 , "Mouse 7" },
|
|
||||||
{ Qt::ExtraButton8 , "Mouse 8" },
|
|
||||||
{ Qt::ExtraButton9 , "Mouse 9" },
|
|
||||||
{ Qt::ExtraButton10 , "Mouse 10" },
|
|
||||||
{ Qt::ExtraButton11 , "Mouse 11" },
|
|
||||||
{ Qt::ExtraButton12 , "Mouse 12" },
|
|
||||||
{ Qt::ExtraButton13 , "Mouse 13" },
|
|
||||||
{ Qt::ExtraButton14 , "Mouse 14" },
|
|
||||||
{ Qt::ExtraButton15 , "Mouse 15" },
|
|
||||||
{ Qt::ExtraButton16 , "Mouse 16" },
|
|
||||||
{ Qt::ExtraButton17 , "Mouse 17" },
|
|
||||||
{ Qt::ExtraButton18 , "Mouse 18" },
|
|
||||||
{ Qt::ExtraButton19 , "Mouse 19" },
|
|
||||||
{ Qt::ExtraButton20 , "Mouse 20" },
|
|
||||||
{ Qt::ExtraButton21 , "Mouse 21" },
|
|
||||||
{ Qt::ExtraButton22 , "Mouse 22" },
|
|
||||||
{ Qt::ExtraButton23 , "Mouse 23" },
|
|
||||||
{ Qt::ExtraButton24 , "Mouse 24" },
|
|
||||||
|
|
||||||
{ mouse::move_left , "Mouse MLeft" },
|
|
||||||
{ mouse::move_right , "Mouse MRight" },
|
|
||||||
{ mouse::move_up , "Mouse MUp" },
|
|
||||||
{ mouse::move_down , "Mouse MDown" },
|
|
||||||
|
|
||||||
{ mouse::wheel_up , "Wheel Up" },
|
|
||||||
{ mouse::wheel_down , "Wheel Down" },
|
|
||||||
{ mouse::wheel_left , "Wheel Left" },
|
|
||||||
{ mouse::wheel_right , "Wheel Right" },
|
|
||||||
};
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
bool Init() override;
|
bool Init() override;
|
||||||
|
|
||||||
|
@ -88,8 +88,8 @@ public:
|
||||||
bool bindPadToDevice(std::shared_ptr<Pad> pad, u8 player_id) override;
|
bool bindPadToDevice(std::shared_ptr<Pad> pad, u8 player_id) override;
|
||||||
void process() override;
|
void process() override;
|
||||||
|
|
||||||
std::string GetMouseName(const QMouseEvent* event) const;
|
static std::string GetMouseName(const QMouseEvent* event);
|
||||||
std::string GetMouseName(u32 button) const;
|
static std::string GetMouseName(u32 button);
|
||||||
static QStringList GetKeyNames(const QKeyEvent* keyEvent);
|
static QStringList GetKeyNames(const QKeyEvent* keyEvent);
|
||||||
static std::string GetKeyName(const QKeyEvent* keyEvent);
|
static std::string GetKeyName(const QKeyEvent* keyEvent);
|
||||||
static std::string GetKeyName(const u32& keyCode);
|
static std::string GetKeyName(const u32& keyCode);
|
||||||
|
|
|
@ -2,14 +2,12 @@
|
||||||
#include "basic_mouse_settings_dialog.h"
|
#include "basic_mouse_settings_dialog.h"
|
||||||
#include "localized_emu.h"
|
#include "localized_emu.h"
|
||||||
#include "Input/basic_mouse_handler.h"
|
#include "Input/basic_mouse_handler.h"
|
||||||
|
#include "Input/keyboard_pad_handler.h"
|
||||||
#include "Emu/Io/mouse_config.h"
|
#include "Emu/Io/mouse_config.h"
|
||||||
#include "Emu/Io/MouseHandler.h"
|
|
||||||
#include "util/asm.hpp"
|
#include "util/asm.hpp"
|
||||||
|
|
||||||
#include <QDialogButtonBox>
|
|
||||||
#include <QGroupBox>
|
#include <QGroupBox>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
#include <QPushButton>
|
|
||||||
#include <QVBoxLayout>
|
#include <QVBoxLayout>
|
||||||
|
|
||||||
LOG_CHANNEL(cfg_log, "CFG");
|
LOG_CHANNEL(cfg_log, "CFG");
|
||||||
|
@ -31,28 +29,33 @@ basic_mouse_settings_dialog::basic_mouse_settings_dialog(QWidget* parent)
|
||||||
|
|
||||||
QVBoxLayout* v_layout = new QVBoxLayout(this);
|
QVBoxLayout* v_layout = new QVBoxLayout(this);
|
||||||
|
|
||||||
QDialogButtonBox* buttons = new QDialogButtonBox(this);
|
m_button_box = new QDialogButtonBox(this);
|
||||||
buttons->setStandardButtons(QDialogButtonBox::Apply | QDialogButtonBox::Cancel | QDialogButtonBox::Save | QDialogButtonBox::RestoreDefaults);
|
m_button_box->setStandardButtons(QDialogButtonBox::Apply | QDialogButtonBox::Cancel | QDialogButtonBox::Save | QDialogButtonBox::RestoreDefaults);
|
||||||
|
|
||||||
connect(buttons, &QDialogButtonBox::clicked, this, [this, buttons](QAbstractButton* button)
|
connect(m_button_box, &QDialogButtonBox::clicked, this, [this](QAbstractButton* button)
|
||||||
{
|
{
|
||||||
if (button == buttons->button(QDialogButtonBox::Apply))
|
if (button == m_button_box->button(QDialogButtonBox::Apply))
|
||||||
{
|
{
|
||||||
g_cfg_mouse.save();
|
g_cfg_mouse.save();
|
||||||
}
|
}
|
||||||
else if (button == buttons->button(QDialogButtonBox::Save))
|
else if (button == m_button_box->button(QDialogButtonBox::Save))
|
||||||
{
|
{
|
||||||
g_cfg_mouse.save();
|
g_cfg_mouse.save();
|
||||||
accept();
|
accept();
|
||||||
}
|
}
|
||||||
else if (button == buttons->button(QDialogButtonBox::RestoreDefaults))
|
else if (button == m_button_box->button(QDialogButtonBox::RestoreDefaults))
|
||||||
{
|
{
|
||||||
if (QMessageBox::question(this, tr("Confirm Reset"), tr("Reset all settings?")) != QMessageBox::Yes)
|
if (QMessageBox::question(this, tr("Confirm Reset"), tr("Reset all settings?")) != QMessageBox::Yes)
|
||||||
return;
|
return;
|
||||||
reset_config();
|
reset_config();
|
||||||
}
|
}
|
||||||
else if (button == buttons->button(QDialogButtonBox::Cancel))
|
else if (button == m_button_box->button(QDialogButtonBox::Cancel))
|
||||||
{
|
{
|
||||||
|
// Restore config
|
||||||
|
if (!g_cfg_mouse.load())
|
||||||
|
{
|
||||||
|
cfg_log.notice("Could not restore mouse config. Using defaults.");
|
||||||
|
}
|
||||||
reject();
|
reject();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -62,6 +65,39 @@ basic_mouse_settings_dialog::basic_mouse_settings_dialog(QWidget* parent)
|
||||||
cfg_log.notice("Could not load basic mouse config. Using defaults.");
|
cfg_log.notice("Could not load basic mouse config. Using defaults.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
m_buttons = new QButtonGroup(this);
|
||||||
|
|
||||||
|
connect(m_buttons, &QButtonGroup::idClicked, this, &basic_mouse_settings_dialog::on_button_click);
|
||||||
|
|
||||||
|
connect(&m_remap_timer, &QTimer::timeout, this, [this]()
|
||||||
|
{
|
||||||
|
auto button = m_buttons->button(m_button_id);
|
||||||
|
|
||||||
|
if (--m_seconds <= 0)
|
||||||
|
{
|
||||||
|
if (button)
|
||||||
|
{
|
||||||
|
if (const int button_id = m_buttons->id(button))
|
||||||
|
{
|
||||||
|
const std::string name = g_cfg_mouse.get_button(button_id).to_string();
|
||||||
|
button->setText(name.empty() ? QStringLiteral("-") : QString::fromStdString(name));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
reactivate_buttons();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (button)
|
||||||
|
{
|
||||||
|
button->setText(tr("[ Waiting %1 ]").arg(m_seconds));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
const auto insert_button = [this](int id, QPushButton* button)
|
||||||
|
{
|
||||||
|
m_buttons->addButton(button, id);
|
||||||
|
button->installEventFilter(this);
|
||||||
|
};
|
||||||
|
|
||||||
constexpr u32 button_count = 8;
|
constexpr u32 button_count = 8;
|
||||||
constexpr u32 max_items_per_column = 4;
|
constexpr u32 max_items_per_column = 4;
|
||||||
int rows = button_count;
|
int rows = button_count;
|
||||||
|
@ -81,33 +117,13 @@ basic_mouse_settings_dialog::basic_mouse_settings_dialog(QWidget* parent)
|
||||||
|
|
||||||
QHBoxLayout* h_layout = new QHBoxLayout(this);
|
QHBoxLayout* h_layout = new QHBoxLayout(this);
|
||||||
QGroupBox* gb = new QGroupBox(translated_cell_button, this);
|
QGroupBox* gb = new QGroupBox(translated_cell_button, this);
|
||||||
QComboBox* combo = new QComboBox;
|
QPushButton* pb = new QPushButton(this);
|
||||||
|
|
||||||
for (const auto& [name, btn] : qt_mouse_button_map)
|
insert_button(cell_code, pb);
|
||||||
{
|
|
||||||
const QString id = QString::fromStdString(name);
|
|
||||||
const QString translated_id = id; // We could localize the id, but I am too lazy at the moment
|
|
||||||
combo->addItem(translated_id);
|
|
||||||
const int index = combo->findText(translated_id);
|
|
||||||
combo->setItemData(index, id, button_role::button_name);
|
|
||||||
combo->setItemData(index, cell_code, button_role::button_code);
|
|
||||||
}
|
|
||||||
|
|
||||||
const std::string saved_btn = g_cfg_mouse.get_button(cell_code);
|
const std::string saved_btn = g_cfg_mouse.get_button(cell_code);
|
||||||
|
|
||||||
combo->setCurrentIndex(combo->findData(QString::fromStdString(saved_btn), button_role::button_name));
|
pb->setText(saved_btn.empty() ? QStringLiteral("-") : QString::fromStdString(saved_btn));
|
||||||
|
|
||||||
connect(combo, QOverload<int>::of(&QComboBox::currentIndexChanged), this, [this, cell_code, combo](int index)
|
|
||||||
{
|
|
||||||
if (index < 0 || !combo)
|
|
||||||
return;
|
|
||||||
|
|
||||||
const QVariant data = combo->itemData(index, button_role::button_name);
|
|
||||||
if (!data.isValid() || !data.canConvert<QString>())
|
|
||||||
return;
|
|
||||||
|
|
||||||
g_cfg_mouse.get_button(cell_code).from_string(data.toString().toStdString());
|
|
||||||
});
|
|
||||||
|
|
||||||
if (row >= rows)
|
if (row >= rows)
|
||||||
{
|
{
|
||||||
|
@ -115,8 +131,8 @@ basic_mouse_settings_dialog::basic_mouse_settings_dialog(QWidget* parent)
|
||||||
col++;
|
col++;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_combos.push_back(combo);
|
m_push_buttons[cell_code] = pb;
|
||||||
h_layout->addWidget(combo);
|
h_layout->addWidget(pb);
|
||||||
gb->setLayout(h_layout);
|
gb->setLayout(h_layout);
|
||||||
grid_layout->addWidget(gb, row, col);
|
grid_layout->addWidget(gb, row, col);
|
||||||
}
|
}
|
||||||
|
@ -124,26 +140,144 @@ basic_mouse_settings_dialog::basic_mouse_settings_dialog(QWidget* parent)
|
||||||
widget->setLayout(grid_layout);
|
widget->setLayout(grid_layout);
|
||||||
|
|
||||||
v_layout->addWidget(widget);
|
v_layout->addWidget(widget);
|
||||||
v_layout->addWidget(buttons);
|
v_layout->addWidget(m_button_box);
|
||||||
setLayout(v_layout);
|
setLayout(v_layout);
|
||||||
|
|
||||||
|
m_palette = m_push_buttons[CELL_MOUSE_BUTTON_1]->palette(); // save normal palette
|
||||||
}
|
}
|
||||||
|
|
||||||
void basic_mouse_settings_dialog::reset_config()
|
void basic_mouse_settings_dialog::reset_config()
|
||||||
{
|
{
|
||||||
g_cfg_mouse.from_default();
|
g_cfg_mouse.from_default();
|
||||||
|
|
||||||
for (QComboBox* combo : m_combos)
|
for (auto& [cell_code, pb] : m_push_buttons)
|
||||||
{
|
{
|
||||||
if (!combo)
|
if (!pb)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
const QVariant data = combo->itemData(0, button_role::button_code);
|
const QString text = QString::fromStdString(g_cfg_mouse.get_button(cell_code).def);
|
||||||
if (!data.isValid() || !data.canConvert<int>())
|
pb->setText(text.isEmpty() ? QStringLiteral("-") : text);
|
||||||
continue;
|
}
|
||||||
|
}
|
||||||
const int cell_code = data.toInt();
|
|
||||||
const QString def_btn_id = QString::fromStdString(g_cfg_mouse.get_button(cell_code).def);
|
void basic_mouse_settings_dialog::on_button_click(int id)
|
||||||
|
{
|
||||||
combo->setCurrentIndex(combo->findData(def_btn_id, button_role::button_name));
|
if (id <= 0)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (auto but : m_buttons->buttons())
|
||||||
|
{
|
||||||
|
but->setFocusPolicy(Qt::ClickFocus);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (auto but : m_button_box->buttons())
|
||||||
|
{
|
||||||
|
but->setFocusPolicy(Qt::ClickFocus);
|
||||||
|
}
|
||||||
|
|
||||||
|
m_button_id = id;
|
||||||
|
if (auto button = m_buttons->button(m_button_id))
|
||||||
|
{
|
||||||
|
button->setText(tr("[ Waiting %1 ]").arg(MAX_SECONDS));
|
||||||
|
button->setPalette(QPalette(Qt::blue));
|
||||||
|
button->grabMouse();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Disable all buttons
|
||||||
|
m_button_box->setEnabled(false);
|
||||||
|
for (auto button : m_buttons->buttons())
|
||||||
|
{
|
||||||
|
button->setEnabled(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
m_remap_timer.start(1000);
|
||||||
|
}
|
||||||
|
|
||||||
|
void basic_mouse_settings_dialog::mouseReleaseEvent(QMouseEvent* event)
|
||||||
|
{
|
||||||
|
if (m_button_id <= 0)
|
||||||
|
{
|
||||||
|
// We are not remapping a button, so pass the event to the base class.
|
||||||
|
QDialog::mouseReleaseEvent(event);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const std::string name = keyboard_pad_handler::GetMouseName(event);
|
||||||
|
g_cfg_mouse.get_button(m_button_id).from_string(name);
|
||||||
|
|
||||||
|
if (auto button = m_buttons->button(m_button_id))
|
||||||
|
{
|
||||||
|
button->setText(QString::fromStdString(name));
|
||||||
|
}
|
||||||
|
|
||||||
|
reactivate_buttons();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool basic_mouse_settings_dialog::eventFilter(QObject* object, QEvent* event)
|
||||||
|
{
|
||||||
|
switch (event->type())
|
||||||
|
{
|
||||||
|
case QEvent::MouseButtonRelease:
|
||||||
|
{
|
||||||
|
// On right click clear binding if we are not remapping pad button
|
||||||
|
if (m_button_id <= 0)
|
||||||
|
{
|
||||||
|
QMouseEvent* mouse_event = static_cast<QMouseEvent*>(event);
|
||||||
|
if (const auto button = qobject_cast<QPushButton*>(object); button && mouse_event->button() == Qt::RightButton)
|
||||||
|
{
|
||||||
|
if (const int button_id = m_buttons->id(button))
|
||||||
|
{
|
||||||
|
button->setText(QStringLiteral("-"));
|
||||||
|
g_cfg_mouse.get_button(button_id).from_string("");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Disabled buttons should not absorb mouseclicks
|
||||||
|
event->ignore();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return QDialog::eventFilter(object, event);
|
||||||
|
}
|
||||||
|
|
||||||
|
void basic_mouse_settings_dialog::reactivate_buttons()
|
||||||
|
{
|
||||||
|
m_remap_timer.stop();
|
||||||
|
m_seconds = MAX_SECONDS;
|
||||||
|
|
||||||
|
if (m_button_id <= 0)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (auto button = m_buttons->button(m_button_id))
|
||||||
|
{
|
||||||
|
button->setPalette(m_palette);
|
||||||
|
button->releaseMouse();
|
||||||
|
}
|
||||||
|
|
||||||
|
m_button_id = 0;
|
||||||
|
|
||||||
|
// Enable all buttons
|
||||||
|
m_button_box->setEnabled(true);
|
||||||
|
|
||||||
|
for (auto but : m_buttons->buttons())
|
||||||
|
{
|
||||||
|
but->setEnabled(true);
|
||||||
|
but->setFocusPolicy(Qt::StrongFocus);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (auto but : m_button_box->buttons())
|
||||||
|
{
|
||||||
|
but->setFocusPolicy(Qt::StrongFocus);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,15 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <QComboBox>
|
#include "Emu/Io/MouseHandler.h"
|
||||||
#include <QDialog>
|
|
||||||
|
|
||||||
#include <vector>
|
#include <QButtonGroup>
|
||||||
|
#include <QPushButton>
|
||||||
|
#include <QDialog>
|
||||||
|
#include <QDialogButtonBox>
|
||||||
|
#include <QMouseEvent>
|
||||||
|
#include <QTimer>
|
||||||
|
|
||||||
|
#include <unordered_map>
|
||||||
|
|
||||||
class basic_mouse_settings_dialog : public QDialog
|
class basic_mouse_settings_dialog : public QDialog
|
||||||
{
|
{
|
||||||
|
@ -15,5 +21,24 @@ public:
|
||||||
private:
|
private:
|
||||||
void reset_config();
|
void reset_config();
|
||||||
|
|
||||||
std::vector<QComboBox*> m_combos;
|
void on_button_click(int id);
|
||||||
|
void reactivate_buttons();
|
||||||
|
|
||||||
|
// Buttons
|
||||||
|
QDialogButtonBox* m_button_box = nullptr;
|
||||||
|
QButtonGroup* m_buttons = nullptr;
|
||||||
|
std::unordered_map<int, QPushButton*> m_push_buttons;
|
||||||
|
u32 m_button_id = 0;
|
||||||
|
|
||||||
|
// Backup for standard button palette
|
||||||
|
QPalette m_palette;
|
||||||
|
|
||||||
|
// Remap Timer
|
||||||
|
static constexpr int MAX_SECONDS = 5;
|
||||||
|
int m_seconds = MAX_SECONDS;
|
||||||
|
QTimer m_remap_timer;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void mouseReleaseEvent(QMouseEvent* event) override;
|
||||||
|
bool eventFilter(QObject* object, QEvent* event) override;
|
||||||
};
|
};
|
||||||
|
|
|
@ -56,6 +56,8 @@ emulated_pad_settings_dialog::emulated_pad_settings_dialog(pad_type type, QWidge
|
||||||
}
|
}
|
||||||
else if (button == buttons->button(QDialogButtonBox::Cancel))
|
else if (button == buttons->button(QDialogButtonBox::Cancel))
|
||||||
{
|
{
|
||||||
|
// Restore config
|
||||||
|
load_config();
|
||||||
reject();
|
reject();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -54,6 +54,11 @@ raw_mouse_settings_dialog::raw_mouse_settings_dialog(QWidget* parent)
|
||||||
}
|
}
|
||||||
else if (button == buttons->button(QDialogButtonBox::Cancel))
|
else if (button == buttons->button(QDialogButtonBox::Cancel))
|
||||||
{
|
{
|
||||||
|
// Restore config
|
||||||
|
if (!g_cfg_raw_mouse.load())
|
||||||
|
{
|
||||||
|
cfg_log.notice("Could not restore raw mouse config. Using defaults.");
|
||||||
|
}
|
||||||
reject();
|
reject();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue