Merge pull request #916 from dustinlieu/fix/hotkey-special-chars

Added special hotkey config rules for comma and semicolon
This commit is contained in:
Povilas Kanapickas 2021-01-10 15:50:43 +02:00 committed by GitHub
commit 8fe1df8c28
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 13 deletions

View File

@ -55,6 +55,8 @@ static const struct
{ Qt::Key_Help, "Help" }, { Qt::Key_Help, "Help" },
{ Qt::Key_Enter, "KP_Enter" }, { Qt::Key_Enter, "KP_Enter" },
{ Qt::Key_Clear, "Clear" }, { Qt::Key_Clear, "Clear" },
{ Qt::Key_Comma, "Comma" },
{ Qt::Key_Semicolon, "Semicolon" },
{ Qt::Key_Back, "WWWBack" }, { Qt::Key_Back, "WWWBack" },
{ Qt::Key_Forward, "WWWForward" }, { Qt::Key_Forward, "WWWForward" },
@ -211,23 +213,22 @@ QString KeySequence::keyToString(int key)
// treat key pad like normal keys (FIXME: we should have another lookup table for keypad keys instead) // treat key pad like normal keys (FIXME: we should have another lookup table for keypad keys instead)
key &= ~Qt::KeypadModifier; key &= ~Qt::KeypadModifier;
// a special key?
int i = 0;
while (keyname[i].name) {
if (key == keyname[i].key)
return QString::fromUtf8(keyname[i].name);
i++;
}
// a printable 7 bit character? // a printable 7 bit character?
if (key < 0x80 && key != Qt::Key_Space) if (key < 0x80)
return QChar(key & 0x7f).toLower(); return QChar(key & 0x7f).toLower();
// a function key? // a function key?
if (key >= Qt::Key_F1 && key <= Qt::Key_F35) if (key >= Qt::Key_F1 && key <= Qt::Key_F35)
return QString::fromUtf8("F%1").arg(key - Qt::Key_F1 + 1); return QString::fromUtf8("F%1").arg(key - Qt::Key_F1 + 1);
// a special key?
int i=0;
while (keyname[i].name)
{
if (key == keyname[i].key)
return QString::fromUtf8(keyname[i].name);
i++;
}
// representable in ucs2? // representable in ucs2?
if (key < 0x10000) if (key < 0x10000)
return QString("\\u%1").arg(QChar(key).toLower().unicode(), 4, 16, QChar('0')); return QString("\\u%1").arg(QChar(key).toLower().unicode(), 4, 16, QChar('0'));

View File

@ -300,7 +300,7 @@ TEST(HotkeyToTexStreamTests, KeysCommaSingleAction)
} }
}; };
ASSERT_EQ(hotkeyToStringViaTextStream(createHotkey(hotkey)), ASSERT_EQ(hotkeyToStringViaTextStream(createHotkey(hotkey)),
"\tkeystroke(a+,+b) = keyDown(z,*)\n"); "\tkeystroke(a+Comma+b) = keyDown(z,*)\n");
} }
TEST(HotkeyToTexStreamTests, KeysMultipleAction) TEST(HotkeyToTexStreamTests, KeysMultipleAction)

View File

@ -133,9 +133,9 @@ TEST(KeySequenceTests, ToString)
ASSERT_EQ(keySequenceToString({{Qt::Key_A, 0}, {Qt::Key_B, 0}}), ASSERT_EQ(keySequenceToString({{Qt::Key_A, 0}, {Qt::Key_B, 0}}),
"a+b"); "a+b");
ASSERT_EQ(keySequenceToString({{Qt::Key_A, 0}, {Qt::Key_Comma, 0}, {Qt::Key_B, 0}}), ASSERT_EQ(keySequenceToString({{Qt::Key_A, 0}, {Qt::Key_Comma, 0}, {Qt::Key_B, 0}}),
"a+,+b"); "a+Comma+b");
ASSERT_EQ(keySequenceToString({{Qt::Key_A, 0}, {Qt::Key_Semicolon, 0}, {Qt::Key_B, 0}}), ASSERT_EQ(keySequenceToString({{Qt::Key_A, 0}, {Qt::Key_Semicolon, 0}, {Qt::Key_B, 0}}),
"a+;+b"); "a+Semicolon+b");
ASSERT_EQ(keySequenceToString({{Qt::Key_A, 0}, {Qt::Key_Shift, Qt::ShiftModifier}, ASSERT_EQ(keySequenceToString({{Qt::Key_A, 0}, {Qt::Key_Shift, Qt::ShiftModifier},
{Qt::Key_0, Qt::ShiftModifier}}), {Qt::Key_0, Qt::ShiftModifier}}),
"a+Shift+0"); "a+Shift+0");