]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt4/GuiKeySymbol.cpp
Disable CheckTeX while buffer is processed
[lyx.git] / src / frontends / qt4 / GuiKeySymbol.cpp
index 045bcaccaad37f796664af606067d3d348e95555..a01682cae2ed36d1f191cf0a3b52fc574558eb4c 100644 (file)
@@ -3,7 +3,7 @@
  * This file is part of LyX, the document processor.
  * Licence details can be found in the file COPYING.
  *
- * \author Asger & Jürgen
+ * \author Asger & Jürgen
  *
  * Full author contact details are available in file CREDITS.
  */
 #include <config.h>
 
 #include "KeySymbol.h"
+#include "GuiApplication.h"
 
 #include "qt_helpers.h"
 
-#include "support/assert.h"
+#include "support/lassert.h"
 #include "support/debug.h"
 
 #include "Encoding.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;
@@ -402,7 +404,9 @@ static std::string const qkey_to_string(int lkey)
        case Qt::Key_Y: return "y";
        case Qt::Key_Z: return "z";
 
+       case Qt::Key_Return: return "Return";
        case Qt::Key_Escape: return "Escape";
+       case Qt::Key_Tab: return "Tab";
        case Qt::Key_Backspace: return "BackSpace";
        case Qt::Key_Insert: return "Insert";
        case Qt::Key_Delete: return "Delete";
@@ -556,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 ...
@@ -565,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:
@@ -607,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()) {
@@ -618,7 +623,7 @@ void setKeySymbol(KeySymbol * sym, QKeyEvent * ev)
        LYXERR(Debug::KEY, "Getting key " << ev->key() << ", with text '"
                << ev->text() << "'");
        // This is unsafe because ev->text() is the unicode representation of the
-       // key, not the name of the key. For example, Ctrl-x and Alt-x produce 
+       // key, not the name of the key. For example, Ctrl-x and Alt-x produce
        // different texts.
        sym->setText(qstring_to_ucs4(ev->text()));
        LYXERR(Debug::KEY, "Setting key to " << sym->key() << ", "
@@ -636,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;
 }
@@ -668,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.
@@ -685,17 +690,35 @@ 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_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);
+               str.replace(QChar(0x21E7), qt_("Shift-"));
+               str.replace(QChar(0x2303), qt_("Control-"));
+               str.replace(QChar(0x2325), qt_("Option-"));
+               str.replace(QChar(0x2318), qt_("Command-"));
+#else
+               str = seq.toString(QKeySequence::PortableText);
+#endif
+       }
 
-       return qstring_to_ucs4(seq.toString(forgui ? QKeySequence::NativeText
-                                           : QKeySequence::PortableText));
+       return qstring_to_ucs4(str);
 }
 
 
@@ -722,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;
 }