Input: Add tooltips for button mapping

This commit is contained in:
Megamouse 2023-06-28 22:14:56 +02:00
parent b9dbda5ddc
commit e0e4fa3b3e
3 changed files with 13 additions and 9 deletions

View File

@ -6,9 +6,6 @@
#include <QApplication>
inline std::string sstr(const QString& _in) { return _in.toStdString(); }
constexpr auto qstr = QString::fromStdString;
bool keyboard_pad_handler::Init()
{
const steady_clock::time_point now = steady_clock::now();
@ -281,7 +278,7 @@ void keyboard_pad_handler::processKeyEvent(QKeyEvent* event, bool pressed)
if (is_num_key)
list.removeAll("Num");
const QString name = qstr(GetKeyName(event));
const QString name = QString::fromStdString(GetKeyName(event));
// TODO: Edge case: switching numlock keeps numpad keys pressed due to now different modifier
@ -642,7 +639,7 @@ QStringList keyboard_pad_handler::GetKeyNames(const QKeyEvent* keyEvent)
// Handle special cases
if (const std::string name = native_scan_code_to_string(keyEvent->nativeScanCode()); !name.empty())
{
list.append(qstr(name));
list.append(QString::fromStdString(name));
}
switch (keyEvent->key())
@ -692,7 +689,7 @@ std::string keyboard_pad_handler::GetKeyName(const QKeyEvent* keyEvent)
case Qt::Key_Meta:
return "Meta";
case Qt::Key_NumLock:
return sstr(QKeySequence(keyEvent->key()).toString(QKeySequence::NativeText));
return QKeySequence(keyEvent->key()).toString(QKeySequence::NativeText).toStdString();
#ifdef __APPLE__
// On macOS, the arrow keys are considered to be part of the keypad;
// since most Mac keyboards lack a keypad to begin with,
@ -709,12 +706,12 @@ std::string keyboard_pad_handler::GetKeyName(const QKeyEvent* keyEvent)
default:
break;
}
return sstr(QKeySequence(keyEvent->key() | keyEvent->modifiers()).toString(QKeySequence::NativeText));
return QKeySequence(keyEvent->key() | keyEvent->modifiers()).toString(QKeySequence::NativeText).toStdString();
}
std::string keyboard_pad_handler::GetKeyName(const u32& keyCode)
{
return sstr(QKeySequence(keyCode).toString(QKeySequence::NativeText));
return QKeySequence(keyCode).toString(QKeySequence::NativeText).toStdString();
}
std::set<u32> keyboard_pad_handler::GetKeyCodes(const cfg::string& cfg_string)
@ -734,7 +731,7 @@ u32 keyboard_pad_handler::GetKeyCode(const QString& keyName)
{
if (keyName.isEmpty())
return Qt::NoButton;
if (const int native_scan_code = native_scan_code_from_string(sstr(keyName)); native_scan_code >= 0)
if (const int native_scan_code = native_scan_code_from_string(keyName.toStdString()); native_scan_code >= 0)
return Qt::Key_unknown + native_scan_code; // Special cases that can't be expressed with Qt::Key
if (keyName == "Alt")
return Qt::Key_Alt;

View File

@ -1945,6 +1945,7 @@ void pad_settings_dialog::ResizeDialog()
void pad_settings_dialog::SubscribeTooltip(QObject* object, const QString& tooltip)
{
ensure(!!object);
m_descriptions[object] = tooltip;
object->installEventFilter(this);
}
@ -1967,6 +1968,11 @@ void pad_settings_dialog::SubscribeTooltips()
SubscribeTooltip(ui->gb_mouse_accel, tooltips.gamepad_settings.mouse_acceleration);
SubscribeTooltip(ui->gb_mouse_dz, tooltips.gamepad_settings.mouse_deadzones);
SubscribeTooltip(ui->gb_mouse_movement, tooltips.gamepad_settings.mouse_movement);
for (int i = button_ids::id_pad_begin + 1; i < button_ids::id_pad_end; i++)
{
SubscribeTooltip(m_pad_buttons->button(i), tooltips.gamepad_settings.button_assignment);
}
}
void pad_settings_dialog::start_input_thread()

View File

@ -280,6 +280,7 @@ public:
const QString mouse_deadzones = tr("The mouse deadzones represent the games' own deadzones on the x and y axes. Games usually enforce their own deadzones to filter out small unwanted stick movements. In consequence, mouse input feels unintuitive since it relies on immediate responsiveness. You can change these values temporarily during gameplay in order to find out the optimal values for your game (Alt+T and Alt+Y for x, Alt+U and Alt+I for y).");
const QString mouse_acceleration = tr("The mouse acceleration can be used to amplify your mouse movements on the x and y axes. Increase these values if your mouse movements feel too slow while playing a game. You can change these values temporarily during gameplay in order to find out the optimal values (Alt+G and Alt+H for x, Alt+J and Alt+K for y). Keep in mind that modern mice usually provide different modes and settings that can be used to change mouse movement speeds as well.");
const QString mouse_movement = tr("The mouse movement mode determines how the mouse movement is translated to pad input.<br>Use the relative mode for traditional mouse movement.<br>Use the absolute mode to use the mouse's distance to the center of the screen as input value.");
const QString button_assignment = tr("Left-click: remap this button.<br>Shift + Left-click: add an addition button mapping.<br>Right-click: clear this button mapping.");
} gamepad_settings;
};