]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt/GuiKeySymbol.cpp
Make code a bit easier to read
[lyx.git] / src / frontends / qt / GuiKeySymbol.cpp
index 2cd2f61054ae8dfa4279dacd62ac5e8a457b0918..083bc5f8848cda5f3031e3ff614154c772ef77b7 100644 (file)
@@ -11,7 +11,7 @@
 #include <config.h>
 
 #include "GuiKeySymbol.h"
-#if defined(Q_OS_MAC) && QT_VERSION > 0x050000
+#if defined(Q_OS_MAC)
 #include "GuiApplication.h"
 #endif
 #include "qt_helpers.h"
@@ -25,7 +25,6 @@
 #include <QKeyEvent>
 #include <QKeySequence>
 #include <QEvent>
-#include <QTextCodec>
 
 #include <map>
 #include <string>
@@ -354,6 +353,80 @@ static int string_to_qkey(std::string const & str)
        if (str == "Help") return Qt::Key_Help;
        if (str == "BackTab") return Qt::Key_Backtab;
 
+       // Keyboard codes for Cyrillic letters
+       if (str == "А") return 1040;
+       if (str == "Б") return 1041;
+       if (str == "В") return 1042;
+       if (str == "Г") return 1043;
+       if (str == "Д") return 1044;
+       if (str == "Е") return 1045;
+       if (str == "Є") return 1028;
+       if (str == "Ё") return 1025;
+       if (str == "Ж") return 1046;
+       if (str == "З") return 1047;
+       if (str == "И") return 1048;
+       if (str == "І") return 1030;
+       if (str == "Ї") return 1031;
+       if (str == "Й") return 1049;
+       if (str == "К") return 1050;
+       if (str == "Л") return 1051;
+       if (str == "М") return 1052;
+       if (str == "Н") return 1053;
+       if (str == "О") return 1054;
+       if (str == "П") return 1055;
+       if (str == "Р") return 1056;
+       if (str == "С") return 1057;
+       if (str == "Т") return 1058;
+       if (str == "У") return 1059;
+       if (str == "Ф") return 1060;
+       if (str == "Х") return 1061;
+       if (str == "Ц") return 1062;
+       if (str == "Ч") return 1063;
+       if (str == "Ш") return 1064;
+       if (str == "Щ") return 1065;
+       if (str == "Ъ") return 1066;
+       if (str == "Ы") return 1067;
+       if (str == "Ь") return 1068;
+       if (str == "Э") return 1069;
+       if (str == "Ю") return 1070;
+       if (str == "Я") return 1071;
+       if (str == "а") return 1040;
+       if (str == "б") return 1041;
+       if (str == "в") return 1042;
+       if (str == "г") return 1043;
+       if (str == "д") return 1044;
+       if (str == "е") return 1045;
+       if (str == "є") return 1028;
+       if (str == "ё") return 1025;
+       if (str == "ж") return 1046;
+       if (str == "з") return 1047;
+       if (str == "и") return 1048;
+       if (str == "і") return 1030;
+       if (str == "ї") return 1031;
+       if (str == "й") return 1049;
+       if (str == "к") return 1050;
+       if (str == "л") return 1051;
+       if (str == "м") return 1052;
+       if (str == "н") return 1053;
+       if (str == "о") return 1054;
+       if (str == "п") return 1055;
+       if (str == "р") return 1056;
+       if (str == "с") return 1057;
+       if (str == "т") return 1058;
+       if (str == "у") return 1059;
+       if (str == "ф") return 1060;
+       if (str == "х") return 1061;
+       if (str == "ц") return 1062;
+       if (str == "ч") return 1063;
+       if (str == "ш") return 1064;
+       if (str == "щ") return 1065;
+       if (str == "ъ") return 1066;
+       if (str == "ы") return 1067;
+       if (str == "ь") return 1068;
+       if (str == "э") return 1069;
+       if (str == "ю") return 1070;
+       if (str == "я") return 1071;
+
        return Qt::Key_unknown;
 }
 
@@ -574,45 +647,50 @@ static std::string const qkey_to_string(int lkey)
        case Qt::Key_Help: return "Help";
        case Qt::Key_Backtab: return "BackTab";
 
+       // Cyrillic
+       case 1040: return "а";
+       case 1041: return "б";
+       case 1042: return "в";
+       case 1043: return "г";
+       case 1044: return "д";
+       case 1045: return "е";
+       case 1028: return "є";
+       case 1025: return "ё";
+       case 1046: return "ж";
+       case 1047: return "з";
+       case 1048: return "и";
+       case 1030: return "і";
+       case 1031: return "ї";
+       case 1049: return "й";
+       case 1050: return "к";
+       case 1051: return "л";
+       case 1052: return "м";
+       case 1053: return "н";
+       case 1054: return "о";
+       case 1055: return "п";
+       case 1056: return "р";
+       case 1057: return "с";
+       case 1058: return "т";
+       case 1059: return "у";
+       case 1060: return "ф";
+       case 1061: return "х";
+       case 1062: return "ц";
+       case 1063: return "ч";
+       case 1064: return "ш";
+       case 1065: return "щ";
+       case 1066: return "ъ";
+       case 1067: return "ы";
+       case 1068: return "ь";
+       case 1069: return "э";
+       case 1070: return "ю";
+       case 1071: return "я";
+
        default:
        case Qt::Key_unknown: return "";
        }
 }
 
 
-#if 0
-static char encode(string const & encoding, QString const & str)
-{
-       typedef map<string, QTextCodec *> EncodingMap;
-       EncodingMap encoding_map;
-
-       QTextCodec * codec = 0;
-
-       EncodingMap::const_iterator cit = encoding_map.find(encoding);
-       if (cit == encoding_map.end()) {
-               LYXERR(Debug::KEY, "Unrecognised encoding '" << encoding << "'.");
-               codec = encoding_map.find("")->second;
-       } else {
-               codec = cit->second;
-       }
-
-       if (!codec) {
-               LYXERR(Debug::KEY, "No codec for encoding '" << encoding << "' found.");
-               return 0;
-       }
-
-       LYXERR(Debug::KEY, "Using codec " << codec->name());
-
-       if (!codec->canEncode(str)) {
-               LYXERR(Debug::KEY, "Oof. Can't encode the text !");
-               return 0;
-       }
-
-       return codec->fromUnicode(str).data()[0];
-}
-#endif
-
-
 void setKeySymbol(KeySymbol * sym, QKeyEvent const * ev)
 {
        sym->setKey(ev->key());
@@ -640,6 +718,14 @@ void KeySymbol::init(string const & symbolname)
 }
 
 
+void KeySymbol::init(int key)
+{
+       key_ = key;
+       text_ = from_utf8(qkey_to_string(key));
+       LYXERR(Debug::KEY, "Init key to " << key_ << ", " << to_utf8(text_));
+}
+
+
 bool KeySymbol::isOK() const
 {
        bool const ok = !(text_.empty() && qkey_to_string(key_).empty());
@@ -747,10 +833,11 @@ bool KeySymbol::operator==(KeySymbol const & ks) const
 KeyModifier q_key_state(Qt::KeyboardModifiers state)
 {
        KeyModifier k = NoModifier;
-#if defined(Q_OS_MAC) && QT_VERSION > 0x050000
+#if defined(Q_OS_MAC) && (QT_VERSION < QT_VERSION_CHECK(5, 12, 0))
        /// 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.
+       /// AFAIK it is fixed at least with Qt 5.12.0
        const bool dontSwapCtrlAndMeta =
                frontend::theGuiApp()->testAttribute(Qt::AA_MacDontSwapCtrlAndMeta);
 #else