Swap Qt::ControlModifier and Qt::MetaModifier on Mac
This is because their meaning is different there. See https://doc.qt.io/qt-5/qt.html#KeyboardModifier-enum
This commit is contained in:
committed by
Chih-Hsuan Yen
parent
9ee754ad0f
commit
5ce909cbc2
@@ -50,6 +50,13 @@ const QByteArray KeyboardTranslatorManager::defaultTranslatorText(
|
||||
"key Tab : \"\\t\""
|
||||
);
|
||||
|
||||
#ifdef Q_OS_MAC
|
||||
// On Mac, Qt::ControlModifier means Cmd, and MetaModifier means Ctrl
|
||||
const Qt::KeyboardModifier KeyboardTranslator::CTRL_MOD = Qt::MetaModifier;
|
||||
#else
|
||||
const Qt::KeyboardModifier KeyboardTranslator::CTRL_MOD = Qt::ControlModifier;
|
||||
#endif
|
||||
|
||||
KeyboardTranslatorManager::KeyboardTranslatorManager()
|
||||
: _haveLoadedAll(false)
|
||||
{
|
||||
@@ -613,6 +620,11 @@ bool KeyboardTranslator::Entry::matches(int keyCode ,
|
||||
Qt::KeyboardModifiers modifiers,
|
||||
States testState) const
|
||||
{
|
||||
#ifdef Q_OS_MAC
|
||||
// On Mac, arrow keys are considered part of keypad. Ignore that.
|
||||
modifiers &= ~Qt::KeypadModifier;
|
||||
#endif
|
||||
|
||||
if ( _keyCode != keyCode )
|
||||
return false;
|
||||
|
||||
|
||||
@@ -314,6 +314,9 @@ public:
|
||||
/** Returns a list of all entries in the translator. */
|
||||
QList<Entry> entries() const;
|
||||
|
||||
/** The modifier code for the actual Ctrl key on this OS. */
|
||||
static const Qt::KeyboardModifier CTRL_MOD;
|
||||
|
||||
private:
|
||||
|
||||
QMultiHash<int,Entry> _entries; // entries in this keyboard translation,
|
||||
@@ -558,8 +561,8 @@ inline QByteArray KeyboardTranslator::Entry::text(bool expandWildCards,Qt::Keybo
|
||||
{
|
||||
int modifierValue = 1;
|
||||
modifierValue += oneOrZero(modifiers & Qt::ShiftModifier);
|
||||
modifierValue += oneOrZero(modifiers & Qt::AltModifier) << 1;
|
||||
modifierValue += oneOrZero(modifiers & Qt::ControlModifier) << 2;
|
||||
modifierValue += oneOrZero(modifiers & Qt::AltModifier) << 1;
|
||||
modifierValue += oneOrZero(modifiers & KeyboardTranslator::CTRL_MOD) << 2;
|
||||
|
||||
for (int i=0;i<_text.length();i++)
|
||||
{
|
||||
|
||||
@@ -1025,7 +1025,7 @@ void Vt102Emulation::sendKeyEvent( QKeyEvent* event )
|
||||
states |= KeyboardTranslator::ApplicationKeypadState;
|
||||
|
||||
// check flow control state
|
||||
if (modifiers & Qt::ControlModifier)
|
||||
if (modifiers & KeyboardTranslator::CTRL_MOD)
|
||||
{
|
||||
switch (event->key()) {
|
||||
case Qt::Key_S:
|
||||
@@ -1080,7 +1080,7 @@ void Vt102Emulation::sendKeyEvent( QKeyEvent* event )
|
||||
{
|
||||
textToSend += _codec->fromUnicode(QString::fromUtf8(entry.text(true,modifiers)));
|
||||
}
|
||||
else if((modifiers & Qt::ControlModifier) && event->key() >= 0x40 && event->key() < 0x5f) {
|
||||
else if((modifiers & KeyboardTranslator::CTRL_MOD) && event->key() >= 0x40 && event->key() < 0x5f) {
|
||||
textToSend += (event->key() & 0x1f);
|
||||
}
|
||||
else if(event->key() == Qt::Key_Tab) {
|
||||
|
||||
Reference in New Issue
Block a user