X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Ffrontends%2Fqt4%2FGuiKeySymbol.cpp;h=ef9425deb1c72bcf0a7098b08804c35393f3dab5;hb=1f10969bb5c5f36017bf5ba8671381b09945cf57;hp=0770010f165d0a39735fc75fc348d70d5d2a227e;hpb=c1ca2b89fb5553cc18321124d607b78d2212c4a0;p=lyx.git diff --git a/src/frontends/qt4/GuiKeySymbol.cpp b/src/frontends/qt4/GuiKeySymbol.cpp index 0770010f16..ef9425deb1 100644 --- a/src/frontends/qt4/GuiKeySymbol.cpp +++ b/src/frontends/qt4/GuiKeySymbol.cpp @@ -11,6 +11,7 @@ #include #include "KeySymbol.h" +#include "GuiApplication.h" #include "qt_helpers.h" @@ -64,7 +65,7 @@ static int string_to_qkey(std::string const & str) if (str == "Escape") return Qt::Key_Escape; if (str == "Tab") return Qt::Key_Tab; - if (str == "ISO_Left_Tab") return Qt::Key_Tab; + if (str == "ISO_Left_Tab") return Qt::Key_Backtab; if (str == "BackSpace") return Qt::Key_Backspace; if (str == "Return") return Qt::Key_Return; if (str == "KP_Enter") return Qt::Key_Enter; // correct ? @@ -341,6 +342,7 @@ static int string_to_qkey(std::string const & str) if (str == "yacute") return Qt::Key_Yacute; if (str == "thorn") return Qt::Key_THORN; if (str == "ydiaeresis") return Qt::Key_ydiaeresis; + if (str == "Dead_Caron") return Qt::Key_Dead_Caron; // FIXME, correct for all these ? if (str == "Super_L") return Qt::Key_Super_L; @@ -558,6 +560,8 @@ static std::string const qkey_to_string(int lkey) case Qt::Key_THORN: return "THORN"; case Qt::Key_ssharp: return "ssharp"; case Qt::Key_ydiaeresis: return "ydiaeresis"; + case Qt::Key_Bar: return "bar"; + case Qt::Key_Dead_Caron: return "Dead_Caron"; // FIXME: these ones I don't know the names of ... help ! // what's here is basically guesses ... @@ -567,7 +571,6 @@ static std::string const qkey_to_string(int lkey) case Qt::Key_Hyper_L: return "Hyper_L"; case Qt::Key_Hyper_R: return "Hyper_R"; case Qt::Key_Help: return "Help"; - case Qt::Key_Bar: return "Bar"; case Qt::Key_Backtab: return "BackTab"; default: @@ -609,7 +612,7 @@ static char encode(string const & encoding, QString const & str) #endif -void setKeySymbol(KeySymbol * sym, QKeyEvent * ev) +void setKeySymbol(KeySymbol * sym, QKeyEvent const * ev) { sym->setKey(ev->key()); if (ev->text().isNull()) { @@ -638,7 +641,7 @@ void KeySymbol::init(string const & symbolname) bool KeySymbol::isOK() const { - bool const ok = !(text_.empty() && key_ == Qt::Key_unknown); + bool const ok = !(text_.empty() && qkey_to_string(key_).empty()); LYXERR(Debug::KEY, "isOK is " << ok); return ok; } @@ -670,7 +673,7 @@ char_type KeySymbol::getUCSEncoded() const return 0; // UTF16 has a maximum of two characters. - LASSERT(text_.size() <= 2, /**/); + LASSERT(text_.size() <= 2, return 0); if (lyxerr.debugging() && text_.size() > 1) { // We don't know yet how well support the full ucs4 range. @@ -687,20 +690,22 @@ docstring const KeySymbol::print(KeyModifier mod, bool forgui) const { int tmpkey = key_; - if (mod & ShiftModifier) + if (mod & ShiftModifier && !(tmpkey == Qt::Key_Shift)) tmpkey += Qt::ShiftModifier; - if (mod & ControlModifier) + if (mod & ControlModifier && !(tmpkey == Qt::Key_Control)) tmpkey += Qt::ControlModifier; - if (mod & AltModifier) + if (mod & AltModifier && !(tmpkey == Qt::Key_Alt)) tmpkey += Qt::AltModifier; + if (mod & MetaModifier && !(tmpkey == Qt::Key_Meta)) + tmpkey += Qt::MetaModifier; QKeySequence seq(tmpkey); QString str; - + if (forgui) str = seq.toString(QKeySequence::NativeText); else { -#ifdef Q_WS_MACX +#ifdef Q_OS_MAC // Qt/Mac does not use Command and friends in the // portable case, but the windows-like Control+x (bug 5421). str = seq.toString(QKeySequence::NativeText); @@ -740,12 +745,29 @@ bool KeySymbol::operator==(KeySymbol const & ks) const KeyModifier q_key_state(Qt::KeyboardModifiers state) { KeyModifier k = NoModifier; - if (state & Qt::ControlModifier) +#if defined(Q_OS_MAC) && QT_VERSION > 0x050000 + /// Additional check for Control and Meta modifier swap state. + /// Starting with Qt 5 the modifiers aren't reported correctly. + /// Until this is fixed a correction is required. + const bool dontSwapCtrlAndMeta = + frontend::theGuiApp()->testAttribute(Qt::AA_MacDontSwapCtrlAndMeta); +#else + const bool dontSwapCtrlAndMeta = false; +#endif + + if (state & (dontSwapCtrlAndMeta ? Qt::MetaModifier : Qt::ControlModifier)) k |= ControlModifier; if (state & Qt::ShiftModifier) k |= ShiftModifier; - if (state & Qt::AltModifier || state & Qt::MetaModifier) + if (state & Qt::AltModifier) k |= AltModifier; +#if defined(USE_MACOSX_PACKAGING) || defined(USE_META_KEYBINDING) + if (state & (dontSwapCtrlAndMeta ? Qt::ControlModifier : Qt::MetaModifier)) + k |= MetaModifier; +#else + if (state & Qt::MetaModifier) + k |= AltModifier; +#endif return k; }