/** * Convert Qt key input into Neovim key-notation * * see QKeyEvent */ QString InputConv::convertKey(const QString& text, int k, Qt::KeyboardModifiers mod) { if (specialKeys.contains(k)) { return QString("<%1%2>").arg(modPrefix(mod)).arg(specialKeys.value(k)); } else if (text.isEmpty()) { // This is a special key we can't handle return QString(); } // Escape < and backslash if (text == "<") { return QString("<%1%2>").arg(modPrefix(mod)).arg("lt"); } if (text == "\\") { return QString("<%1%2>").arg(modPrefix(mod)).arg("Bslash"); } QChar c = text.at(0); // Remove SHIFT if (c.unicode() < 0x100 && !c.isLetterOrNumber() && c.isPrint()) { mod &= ~Qt::ShiftModifier; } // Remove CTRL empty characters at the start of the ASCII range if (c.unicode() < 0x20) { mod &= ~Qt::ControlModifier; } // Format with prefix if necessary QString prefix = modPrefix(mod); if (!prefix.isEmpty()) { return QString("<%1%2>").arg(prefix).arg(text); } return text; }
/** * Convert mouse event information into Neovim key notation * * @type is one of the Qt mouse event types * @pos is in Neovim Coordinates * @clickCount is the number of consecutive mouse clicks * 1 for a single click, 2 for a double click, up to 4. * This value is only used for LeftMouse events. * * see QMouseEvent * * If the event is not valid for Neovim, returns an empty string */ QString InputConv::convertMouse(Qt::MouseButton bt, QEvent::Type type, Qt::KeyboardModifiers mod, QPoint pos, short clickCount) { QString buttonName; switch(bt) { case Qt::LeftButton: // In practice Neovim only supports the clickcount for Left // mouse presses, even if our shell can support other buttons if (clickCount > 1 && clickCount <= 4) { buttonName = QString("%1-Left").arg(clickCount); } else { buttonName += "Left"; } break; case Qt::RightButton: buttonName += "Right"; break; case Qt::MidButton: buttonName += "Middle"; break; case Qt::NoButton: break; default: return ""; } QString evType; switch(type) { case QEvent::MouseButtonDblClick: // Treat this as a regular MouseButtonPress. Repeated // clicks are handled above. case QEvent::MouseButtonPress: evType += "Mouse"; break; case QEvent::MouseButtonRelease: evType += "Release"; break; case QEvent::MouseMove: evType += "Drag"; break; default: return ""; } QString inp = QString("<%1%2%3><%4,%5>").arg(modPrefix(mod)).arg(buttonName).arg(evType).arg(pos.x()).arg(pos.y()); return inp; }
/** * Convert Qt key input into Neovim key-notation * * see QKeyEvent */ QString InputConv::convertKey(const QString& text, int k, Qt::KeyboardModifiers mod) { if ( mod & Qt::KeypadModifier ) { switch (k) { case Qt::Key_Home: return QString("<%1kHome>").arg(modPrefix(mod)); case Qt::Key_End: return QString("<%1kEnd>").arg(modPrefix(mod)); case Qt::Key_PageUp: return QString("<%1kPageUp>").arg(modPrefix(mod)); case Qt::Key_PageDown: return QString("<%1kPageDown>").arg(modPrefix(mod)); case Qt::Key_Plus: return QString("<%1kPlus>").arg(modPrefix(mod)); case Qt::Key_Minus: return QString("<%1kMinus>").arg(modPrefix(mod)); case Qt::Key_multiply: return QString("<%1kMultiply>").arg(modPrefix(mod)); case Qt::Key_division: return QString("<%1kDivide>").arg(modPrefix(mod)); case Qt::Key_Enter: return QString("<%1kEnter>").arg(modPrefix(mod)); case Qt::Key_Period: return QString("<%1kPoint>").arg(modPrefix(mod)); case Qt::Key_0: return QString("<%1k0>").arg(modPrefix(mod)); case Qt::Key_1: return QString("<%1k1>").arg(modPrefix(mod)); case Qt::Key_2: return QString("<%1k2>").arg(modPrefix(mod)); case Qt::Key_3: return QString("<%1k3>").arg(modPrefix(mod)); case Qt::Key_4: return QString("<%1k4>").arg(modPrefix(mod)); case Qt::Key_5: return QString("<%1k5>").arg(modPrefix(mod)); case Qt::Key_6: return QString("<%1k6>").arg(modPrefix(mod)); case Qt::Key_7: return QString("<%1k7>").arg(modPrefix(mod)); case Qt::Key_8: return QString("<%1k8>").arg(modPrefix(mod)); case Qt::Key_9: return QString("<%1k9>").arg(modPrefix(mod)); } } if (specialKeys.contains(k)) { return QString("<%1%2>").arg(modPrefix(mod)).arg(specialKeys.value(k)); } QChar c; // Escape < and backslash if (text == "<") { return QString("<%1%2>").arg(modPrefix(mod)).arg("lt"); } else if (text == "\\") { return QString("<%1%2>").arg(modPrefix(mod)).arg("Bslash"); } else if (text.isEmpty()) { // on macs, text is empty for ctrl+key and cmd+key combos (with or without alt) if (mod & ControlModifier || mod & CmdModifier) { // ignore ctrl, alt and cmd key combos by themselves QList<Qt::Key> keys = { Key_Control, Key_Alt, Key_Cmd }; if (keys.contains((Qt::Key)k)) { return QString(); } else if (mod & ShiftModifier) { // Ignore event for Ctrl-Shift // Fixes issue #344, C-S- being treated as C-Space return QString(); } else { // key code will be the value of the char (hopefully) c = QChar(k); } } else { // This is a special key we can't handle return QString(); } } else { // Key event compression is disabled, text has one char c = text.at(0); } // Remove SHIFT if (c.unicode() >= 0x80 || (!c.isLetterOrNumber() && c.isPrint())) { mod &= ~ShiftModifier; } // Remove CTRL empty characters at the start of the ASCII range if (c.unicode() < 0x20) { mod &= ~ControlModifier; } // Format with prefix if necessary QString prefix = modPrefix(mod); if (!prefix.isEmpty()) { return QString("<%1%2>").arg(prefix).arg(c); } return QString(c); }