1
0
Fork 0
forked from suyu/suyu

Merge pull request #4647 from Morph1984/readd-context-menu

configure_input_player: Re-add "Clear" context menu option
This commit is contained in:
bunnei 2020-09-17 22:59:13 -07:00 committed by GitHub
commit 8568f44ffa
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 66 additions and 31 deletions

View file

@ -256,6 +256,11 @@ ConfigureInputPlayer::ConfigureInputPlayer(QWidget* parent, std::size_t player_i
ui->buttonSL, ui->buttonSR, ui->buttonHome, ui->buttonScreenshot, ui->buttonSL, ui->buttonSR, ui->buttonHome, ui->buttonScreenshot,
}; };
mod_buttons = {
ui->buttonLStickMod,
ui->buttonRStickMod,
};
analog_map_buttons = {{ analog_map_buttons = {{
{ {
ui->buttonLStickUp, ui->buttonLStickUp,
@ -311,11 +316,25 @@ ConfigureInputPlayer::ConfigureInputPlayer(QWidget* parent, std::size_t player_i
for (int button_id = 0; button_id < Settings::NativeButton::NumButtons; ++button_id) { for (int button_id = 0; button_id < Settings::NativeButton::NumButtons; ++button_id) {
auto* const button = button_map[button_id]; auto* const button = button_map[button_id];
if (button == nullptr) { if (button == nullptr) {
continue; continue;
} }
ConfigureButtonClick(button_map[button_id], &buttons_param[button_id], ConfigureButtonClick(button_map[button_id], &buttons_param[button_id],
Config::default_buttons[button_id]); Config::default_buttons[button_id]);
button->setContextMenuPolicy(Qt::CustomContextMenu);
connect(button, &QPushButton::customContextMenuRequested,
[=, this](const QPoint& menu_location) {
QMenu context_menu;
context_menu.addAction(tr("Clear"), [&] {
buttons_param[button_id].Clear();
button_map[button_id]->setText(tr("[not set]"));
});
context_menu.exec(button_map[button_id]->mapToGlobal(menu_location));
});
} }
for (int motion_id = 0; motion_id < Settings::NativeMotion::NumMotions; ++motion_id) { for (int motion_id = 0; motion_id < Settings::NativeMotion::NumMotions; ++motion_id) {
@ -324,15 +343,11 @@ ConfigureInputPlayer::ConfigureInputPlayer(QWidget* parent, std::size_t player_i
continue; continue;
} }
ConfigureButtonClick(motion_map[motion_id], &motions_param[motion_id],
Config::default_motions[motion_id]);
button->setContextMenuPolicy(Qt::CustomContextMenu); button->setContextMenuPolicy(Qt::CustomContextMenu);
connect(button, &QPushButton::clicked, [=, this] {
HandleClick(
motion_map[motion_id],
[=, this](Common::ParamPackage params) {
motions_param[motion_id] = std::move(params);
},
InputCommon::Polling::DeviceType::Motion);
});
connect(button, &QPushButton::customContextMenuRequested, connect(button, &QPushButton::customContextMenuRequested,
[=, this](const QPoint& menu_location) { [=, this](const QPoint& menu_location) {
QMenu context_menu; QMenu context_menu;
@ -344,10 +359,6 @@ ConfigureInputPlayer::ConfigureInputPlayer(QWidget* parent, std::size_t player_i
}); });
} }
// Handle clicks for the modifier buttons as well.
ConfigureButtonClick(ui->buttonLStickMod, &lstick_mod, Config::default_stick_mod[0]);
ConfigureButtonClick(ui->buttonRStickMod, &rstick_mod, Config::default_stick_mod[1]);
for (int analog_id = 0; analog_id < Settings::NativeAnalog::NumAnalogs; ++analog_id) { for (int analog_id = 0; analog_id < Settings::NativeAnalog::NumAnalogs; ++analog_id) {
for (int sub_button_id = 0; sub_button_id < ANALOG_SUB_BUTTONS_NUM; ++sub_button_id) { for (int sub_button_id = 0; sub_button_id < ANALOG_SUB_BUTTONS_NUM; ++sub_button_id) {
auto* const analog_button = analog_map_buttons[analog_id][sub_button_id]; auto* const analog_button = analog_map_buttons[analog_id][sub_button_id];
@ -365,8 +376,37 @@ ConfigureInputPlayer::ConfigureInputPlayer(QWidget* parent, std::size_t player_i
}, },
InputCommon::Polling::DeviceType::AnalogPreferred); InputCommon::Polling::DeviceType::AnalogPreferred);
}); });
analog_button->setContextMenuPolicy(Qt::CustomContextMenu);
connect(analog_button, &QPushButton::customContextMenuRequested,
[=, this](const QPoint& menu_location) {
QMenu context_menu;
context_menu.addAction(tr("Clear"), [&] {
analogs_param[analog_id].Clear();
analog_map_buttons[analog_id][sub_button_id]->setText(tr("[not set]"));
});
context_menu.exec(analog_map_buttons[analog_id][sub_button_id]->mapToGlobal(
menu_location));
});
} }
// Handle clicks for the modifier buttons as well.
ConfigureButtonClick(mod_buttons[analog_id], &stick_mod_param[analog_id],
Config::default_stick_mod[analog_id]);
mod_buttons[analog_id]->setContextMenuPolicy(Qt::CustomContextMenu);
connect(mod_buttons[analog_id], &QPushButton::customContextMenuRequested,
[=, this](const QPoint& menu_location) {
QMenu context_menu;
context_menu.addAction(tr("Clear"), [&] {
stick_mod_param[analog_id].Clear();
mod_buttons[analog_id]->setText(tr("[not set]"));
});
context_menu.exec(mod_buttons[analog_id]->mapToGlobal(menu_location));
});
connect(analog_map_range_spinbox[analog_id], qOverload<int>(&QSpinBox::valueChanged), connect(analog_map_range_spinbox[analog_id], qOverload<int>(&QSpinBox::valueChanged),
[=, this] { [=, this] {
const auto spinbox_value = analog_map_range_spinbox[analog_id]->value(); const auto spinbox_value = analog_map_range_spinbox[analog_id]->value();
@ -585,19 +625,16 @@ void ConfigureInputPlayer::RestoreDefaults() {
InputCommon::GenerateKeyboardParam(Config::default_buttons[button_id])}; InputCommon::GenerateKeyboardParam(Config::default_buttons[button_id])};
} }
// Reset Modifier Buttons // Reset Analogs and Modifier Buttons
lstick_mod =
Common::ParamPackage(InputCommon::GenerateKeyboardParam(Config::default_stick_mod[0]));
rstick_mod =
Common::ParamPackage(InputCommon::GenerateKeyboardParam(Config::default_stick_mod[1]));
// Reset Analogs
for (int analog_id = 0; analog_id < Settings::NativeAnalog::NumAnalogs; ++analog_id) { for (int analog_id = 0; analog_id < Settings::NativeAnalog::NumAnalogs; ++analog_id) {
for (int sub_button_id = 0; sub_button_id < ANALOG_SUB_BUTTONS_NUM; ++sub_button_id) { for (int sub_button_id = 0; sub_button_id < ANALOG_SUB_BUTTONS_NUM; ++sub_button_id) {
Common::ParamPackage params{InputCommon::GenerateKeyboardParam( Common::ParamPackage params{InputCommon::GenerateKeyboardParam(
Config::default_analogs[analog_id][sub_button_id])}; Config::default_analogs[analog_id][sub_button_id])};
SetAnalogParam(params, analogs_param[analog_id], analog_sub_buttons[sub_button_id]); SetAnalogParam(params, analogs_param[analog_id], analog_sub_buttons[sub_button_id]);
} }
stick_mod_param[analog_id] = Common::ParamPackage(
InputCommon::GenerateKeyboardParam(Config::default_stick_mod[analog_id]));
} }
for (int motion_id = 0; motion_id < Settings::NativeMotion::NumMotions; ++motion_id) { for (int motion_id = 0; motion_id < Settings::NativeMotion::NumMotions; ++motion_id) {
@ -613,30 +650,29 @@ void ConfigureInputPlayer::RestoreDefaults() {
void ConfigureInputPlayer::ClearAll() { void ConfigureInputPlayer::ClearAll() {
for (int button_id = 0; button_id < Settings::NativeButton::NumButtons; ++button_id) { for (int button_id = 0; button_id < Settings::NativeButton::NumButtons; ++button_id) {
const auto* const button = button_map[button_id]; const auto* const button = button_map[button_id];
if (button == nullptr || !button->isEnabled()) { if (button == nullptr) {
continue; continue;
} }
buttons_param[button_id].Clear(); buttons_param[button_id].Clear();
} }
lstick_mod.Clear();
rstick_mod.Clear();
for (int analog_id = 0; analog_id < Settings::NativeAnalog::NumAnalogs; ++analog_id) { for (int analog_id = 0; analog_id < Settings::NativeAnalog::NumAnalogs; ++analog_id) {
for (int sub_button_id = 0; sub_button_id < ANALOG_SUB_BUTTONS_NUM; ++sub_button_id) { for (int sub_button_id = 0; sub_button_id < ANALOG_SUB_BUTTONS_NUM; ++sub_button_id) {
const auto* const analog_button = analog_map_buttons[analog_id][sub_button_id]; const auto* const analog_button = analog_map_buttons[analog_id][sub_button_id];
if (analog_button == nullptr || !analog_button->isEnabled()) { if (analog_button == nullptr) {
continue; continue;
} }
analogs_param[analog_id].Clear(); analogs_param[analog_id].Clear();
} }
stick_mod_param[analog_id].Clear();
} }
for (int motion_id = 0; motion_id < Settings::NativeMotion::NumMotions; ++motion_id) { for (int motion_id = 0; motion_id < Settings::NativeMotion::NumMotions; ++motion_id) {
const auto* const button = motion_map[motion_id]; const auto* const motion_button = motion_map[motion_id];
if (button == nullptr || !button->isEnabled()) { if (motion_button == nullptr) {
continue; continue;
} }
@ -656,9 +692,6 @@ void ConfigureInputPlayer::UpdateUI() {
motion_map[motion_id]->setText(ButtonToText(motions_param[motion_id])); motion_map[motion_id]->setText(ButtonToText(motions_param[motion_id]));
} }
ui->buttonLStickMod->setText(ButtonToText(lstick_mod));
ui->buttonRStickMod->setText(ButtonToText(rstick_mod));
for (int analog_id = 0; analog_id < Settings::NativeAnalog::NumAnalogs; ++analog_id) { for (int analog_id = 0; analog_id < Settings::NativeAnalog::NumAnalogs; ++analog_id) {
for (int sub_button_id = 0; sub_button_id < ANALOG_SUB_BUTTONS_NUM; ++sub_button_id) { for (int sub_button_id = 0; sub_button_id < ANALOG_SUB_BUTTONS_NUM; ++sub_button_id) {
auto* const analog_button = analog_map_buttons[analog_id][sub_button_id]; auto* const analog_button = analog_map_buttons[analog_id][sub_button_id];
@ -671,6 +704,8 @@ void ConfigureInputPlayer::UpdateUI() {
AnalogToText(analogs_param[analog_id], analog_sub_buttons[sub_button_id])); AnalogToText(analogs_param[analog_id], analog_sub_buttons[sub_button_id]));
} }
mod_buttons[analog_id]->setText(ButtonToText(stick_mod_param[analog_id]));
const auto deadzone_label = analog_map_deadzone_label[analog_id]; const auto deadzone_label = analog_map_deadzone_label[analog_id];
const auto deadzone_slider = analog_map_deadzone_slider[analog_id]; const auto deadzone_slider = analog_map_deadzone_slider[analog_id];
const auto modifier_groupbox = analog_map_modifier_groupbox[analog_id]; const auto modifier_groupbox = analog_map_modifier_groupbox[analog_id];

View file

@ -131,6 +131,7 @@ private:
std::array<Common::ParamPackage, Settings::NativeButton::NumButtons> buttons_param; std::array<Common::ParamPackage, Settings::NativeButton::NumButtons> buttons_param;
std::array<Common::ParamPackage, Settings::NativeAnalog::NumAnalogs> analogs_param; std::array<Common::ParamPackage, Settings::NativeAnalog::NumAnalogs> analogs_param;
std::array<Common::ParamPackage, Settings::NativeAnalog::NumAnalogs> stick_mod_param;
std::array<Common::ParamPackage, Settings::NativeMotion::NumMotions> motions_param; std::array<Common::ParamPackage, Settings::NativeMotion::NumMotions> motions_param;
static constexpr int ANALOG_SUB_BUTTONS_NUM = 4; static constexpr int ANALOG_SUB_BUTTONS_NUM = 4;
@ -140,8 +141,7 @@ private:
/// Each motion input is represented by a QPushButton. /// Each motion input is represented by a QPushButton.
std::array<QPushButton*, Settings::NativeMotion::NumMotions> motion_map; std::array<QPushButton*, Settings::NativeMotion::NumMotions> motion_map;
/// Extra buttons for the modifiers. /// Extra buttons for the modifiers.
Common::ParamPackage lstick_mod; std::array<QPushButton*, Settings::NativeAnalog::NumAnalogs> mod_buttons;
Common::ParamPackage rstick_mod;
/// A group of four QPushButtons represent one analog input. The buttons each represent up, /// A group of four QPushButtons represent one analog input. The buttons each represent up,
/// down, left, right, respectively. /// down, left, right, respectively.