Code: Select all
QString KeyUnit::getKeyName(int keyCode, int modifierCode)
{
QString name;
/*
Qt::NoModifier 0x00000000 No modifier key is pressed.
Qt::ShiftModifier 0x02000000 A Shift key on the keyboard is pressed.
Qt::ControlModifier 0x04000000 A Ctrl key on the keyboard is pressed.
Qt::AltModifier 0x08000000 An Alt key on the keyboard is pressed.
Qt::MetaModifier 0x10000000 A Meta key on the keyboard is pressed.
Qt::KeypadModifier 0x20000000 A keypad button is pressed.
Qt::GroupSwitchModifier 0x40000000 X11 only. A Mode_switch key on the keyboard is pressed.
*/
- if (modifierCode == 0x00000000) {
- name += "no modifiers + ";
- }
- if (modifierCode & 0x02000000) {
- name += "shift + ";
- }
- if (modifierCode & 0x04000000) {
- name += "control + ";
- }
- if (modifierCode & 0x08000000) {
- name += "alt + ";
- }
- if (modifierCode & 0x10000000) {
- name += "meta + ";
- }
- if (modifierCode & 0x20000000) {
- name += "keypad + ";
+ if (!modifierCode) {
+ name += tr("no modifiers + ");
+ } else {
+ if (modifierCode & Qt::ShiftModifier) {
+#if defined(Q_OS_MAC)
+ name += tr("⇧ shift + ");
+#else
+ name += tr("shift + ");
+#endif
+ }
+ if (modifierCode & Qt::ControlModifier) {
+ // Control is the:
+ // "⌘ Command" on macOs (symbol is U+2318 PLACE OF INTEREST
+ // a.k.a. "Cloverleaf"
+ // "Ctrl" on other platforms
+#if defined(Q_OS_MAC)
+ name += tr("⌘ command + ");
+#else
+ name += tr("ctrl + ");
+#endif
+ }
+ if (modifierCode & Qt::AltModifier) {
+ // Alt is the:
+ // "Option" on macOs
+ // "Alt" on other platform
+#if defined(Q_OS_MAC)
+ name += tr("⌥ option + ");
+#else
+ name += tr("alt + ");
+#endif
+ }
+ if (modifierCode & Qt::MetaModifier) {
+ // Meta is the:
+ // "Windows" keys on Wintel machines and
+ // "Control" on macOs
+ // "Meta" on other platforms
+#if defined(Q_OS_MAC)
+ name += tr("control + ");
+#elif defined(Q_OS_WIN)
+ name += tr("win + ");
+#else
+ name += tr("meta + ");
+#endif
+ }
+ if (modifierCode & Qt::KeypadModifier) {
+ name += tr("keypad + ");
+ }
+ if (modifierCode & Qt::GroupSwitchModifier) {
+ name += tr("groupswitch + ");
}
- if (modifierCode & 0x40000000) {
- name += "groupswitch + ";
}
+
if (mKeys.contains(keyCode)) {
name += mKeys[keyCode];
return name;
} else {
- return QString("undefined key");
+ return tr("%1undefined key {code: 0x%2}").arg(name).arg(keyCode, 8, 16, QLatin1Char('0'));
}
}