]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt2/qlkey.h
Some string(widget->text()) fixes. Weirdness
[lyx.git] / src / frontends / qt2 / qlkey.h
index 7f20c7def94b39f0da4a3aac9a1da8a9bcbc4dcf..43e34bce3c955739c4d125000a5c55a3310696e2 100644 (file)
@@ -1,20 +1,28 @@
+// -*- C++ -*-
 /**
  * \file qlkey.h
- * Copyright 2002 the LyX Team
- * Read the file COPYING
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
  *
- * \author John Levon <moz@compsoc.man.ac.uk>
+ * \author John Levon
+ *
+ * Full author contact details are available in file CREDITS
  */
 
 #ifndef QLKEY_H
 #define QLKEY_H
-#include <config.h>
-#include <qnamespace.h>
 
+#ifdef __GNUG__
+#pragma interface
+#endif
+
+#include <qnamespace.h>
 #include "LString.h"
-int q_is_modifier(int qkey)
+
+/**
+ * Return true if the key event is a modifier.
+ */
+bool q_is_modifier(int qkey)
 {
        switch (qkey) {
                case Qt::Key_Hyper_L:
@@ -26,21 +34,32 @@ int q_is_modifier(int qkey)
                case Qt::Key_Meta:
                case Qt::Key_Alt:
                        return true;
+
+               // AltGr becomes Key_unknown on at least one keyboard
+               case Qt::Key_unknown:
+                       return true;
        }
        return false;
 }
 
-// FIXME
+
+/**
+ * Return the numeric Qt Key corresponding to the
+ * given symbol name.
+ */
 int string_to_qkey(string const & str)
 {
+       // FIX! (Lgb)
+       
        if (str == "Escape") return Qt::Key_Escape;
        if (str == "Tab") return Qt::Key_Tab;
        if (str == "BackSpace") return Qt::Key_BackSpace;
        if (str == "Return") return Qt::Key_Return;
        if (str == "KP_Enter") return Qt::Key_Enter; // correct ?
        if (str == "Insert") return Qt::Key_Insert;
+       if (str == "KP_Insert") return Qt::Key_Insert;
        if (str == "Delete") return Qt::Key_Delete;
+       if (str == "KP_Delete") return Qt::Key_Delete;
        if (str == "Pause") return Qt::Key_Pause;
        if (str == "Print") return Qt::Key_Print;
        if (str == "Sys_Req") return Qt::Key_SysReq;
@@ -52,10 +71,18 @@ int string_to_qkey(string const & str)
        if (str == "Down") return Qt::Key_Down;
        if (str == "Prior") return Qt::Key_Prior;
        if (str == "Next") return Qt::Key_Next;
+       if (str == "KP_Home") return Qt::Key_Home;
+       if (str == "KP_End") return Qt::Key_End;
+       if (str == "KP_Left") return Qt::Key_Left;
+       if (str == "KP_Up") return Qt::Key_Up;
+       if (str == "KP_Right") return Qt::Key_Right;
+       if (str == "KP_Down") return Qt::Key_Down;
+       if (str == "KP_Prior") return Qt::Key_Prior;
+       if (str == "KP_Next") return Qt::Key_Next;
        if (str == "Shift_L") return Qt::Key_Shift;
        if (str == "Control_L") return Qt::Key_Control;
        if (str == "Alt_L") return Qt::Key_Meta; // correct ?
-       if (str == "Alt_L") return Qt::Key_Alt;
+       if (str == "Alt_R") return Qt::Key_Alt;
        if (str == "Caps_Lock") return Qt::Key_CapsLock;
        if (str == "Num_Lock") return Qt::Key_NumLock;
        if (str == "Scroll_Lock") return Qt::Key_ScrollLock;
@@ -111,6 +138,32 @@ int string_to_qkey(string const & str)
        if (str == "greater") return Qt::Key_Greater;
        if (str == "question") return Qt::Key_Question;
        if (str == "at") return Qt::Key_At;
+       if (str == "A") return Qt::Key_A;
+       if (str == "B") return Qt::Key_B;
+       if (str == "C") return Qt::Key_C;
+       if (str == "D") return Qt::Key_D;
+       if (str == "E") return Qt::Key_E;
+       if (str == "F") return Qt::Key_F;
+       if (str == "G") return Qt::Key_G;
+       if (str == "H") return Qt::Key_H;
+       if (str == "I") return Qt::Key_I;
+       if (str == "J") return Qt::Key_J;
+       if (str == "K") return Qt::Key_K;
+       if (str == "L") return Qt::Key_L;
+       if (str == "M") return Qt::Key_M;
+       if (str == "N") return Qt::Key_N;
+       if (str == "O") return Qt::Key_O;
+       if (str == "P") return Qt::Key_P;
+       if (str == "Q") return Qt::Key_Q;
+       if (str == "R") return Qt::Key_R;
+       if (str == "S") return Qt::Key_S;
+       if (str == "T") return Qt::Key_T;
+       if (str == "U") return Qt::Key_U;
+       if (str == "V") return Qt::Key_V;
+       if (str == "W") return Qt::Key_W;
+       if (str == "X") return Qt::Key_X;
+       if (str == "Y") return Qt::Key_Y;
+       if (str == "Z") return Qt::Key_Z;
        if (str == "a") return Qt::Key_A;
        if (str == "b") return Qt::Key_B;
        if (str == "c") return Qt::Key_C;
@@ -259,7 +312,7 @@ int string_to_qkey(string const & str)
        if (str == "thorn") return Qt::Key_thorn;
        if (str == "ydiaeresis") return Qt::Key_ydiaeresis;
 
-       // FIXME, correct for all these ? 
+       // FIXME, correct for all these ?
        if (str == "Super_L") return Qt::Key_Super_L;
        if (str == "Super_R") return Qt::Key_Super_R;
        if (str == "Menu") return Qt::Key_Menu;
@@ -268,25 +321,22 @@ int string_to_qkey(string const & str)
        if (str == "Help") return Qt::Key_Help;
        if (str == "Bar") return Qt::Key_Bar;
        if (str == "BackTab") return Qt::Key_Backtab;
+
        return Qt::Key_unknown;
 }
 
+
 /**
- * qkey_t_string - convert Qt keypress into LyX
+ * qkey_to_string - convert Qt keypress into LyX
  *
  * Convert the Qt keypress into a string understandable
- * by the LyX core (same as XKeysymToString)
+ * by the LyX core (same as XKeysymToString).
  */
-string const qkey_to_string(int lkey, bool shift) 
+string const qkey_to_string(int lkey)
 {
        switch (lkey) {
        case Qt::Key_Escape: return "Escape";
-       case Qt::Key_Tab: return "Tab";
        case Qt::Key_BackSpace: return "BackSpace";
-       case Qt::Key_Return: return "Return";
-       case Qt::Key_Enter: return "KP_Enter"; // correct ??
        case Qt::Key_Insert: return "Insert";
        case Qt::Key_Delete: return "Delete";
        case Qt::Key_Pause: return "Pause";
@@ -303,7 +353,7 @@ string const qkey_to_string(int lkey, bool shift)
        case Qt::Key_Shift: return "Shift_L";
        case Qt::Key_Control: return "Control_L";
        case Qt::Key_Meta: return "Alt_L"; // correct ?
-       case Qt::Key_Alt: return "Alt_L";
+       case Qt::Key_Alt: return "Alt_R";
        case Qt::Key_CapsLock: return "Caps_Lock";
        case Qt::Key_NumLock: return "Num_Lock";
        case Qt::Key_ScrollLock: return "Scroll_Lock";
@@ -342,16 +392,6 @@ string const qkey_to_string(int lkey, bool shift)
        case Qt::Key_F33: return "F33";
        case Qt::Key_F34: return "F34";
        case Qt::Key_F35: return "F35";
-       case Qt::Key_0: return "0";
-       case Qt::Key_1: return "1";
-       case Qt::Key_2: return "2";
-       case Qt::Key_3: return "3";
-       case Qt::Key_4: return "4";
-       case Qt::Key_5: return "5";
-       case Qt::Key_6: return "6";
-       case Qt::Key_7: return "7";
-       case Qt::Key_8: return "8";
-       case Qt::Key_9: return "9";
        case Qt::Key_Colon: return "colon";
        case Qt::Key_Semicolon: return "semicolon";
        case Qt::Key_Less: return "less";
@@ -359,32 +399,6 @@ string const qkey_to_string(int lkey, bool shift)
        case Qt::Key_Greater: return "greater";
        case Qt::Key_Question: return "question";
        case Qt::Key_At: return "at";
-       case Qt::Key_A: return shift ? "A" : "a";
-       case Qt::Key_B: return shift ? "B" : "b";
-       case Qt::Key_C: return shift ? "C" : "c";
-       case Qt::Key_D: return shift ? "D" : "d";
-       case Qt::Key_E: return shift ? "E" : "e";
-       case Qt::Key_F: return shift ? "F" : "f";
-       case Qt::Key_G: return shift ? "G" : "g";
-       case Qt::Key_H: return shift ? "H" : "h";
-       case Qt::Key_I: return shift ? "I" : "i";
-       case Qt::Key_J: return shift ? "J" : "j";
-       case Qt::Key_K: return shift ? "K" : "k";
-       case Qt::Key_L: return shift ? "L" : "l";
-       case Qt::Key_M: return shift ? "M" : "m";
-       case Qt::Key_N: return shift ? "N" : "n";
-       case Qt::Key_O: return shift ? "O" : "o";
-       case Qt::Key_P: return shift ? "P" : "p";
-       case Qt::Key_Q: return shift ? "Q" : "q";
-       case Qt::Key_R: return shift ? "R" : "r";
-       case Qt::Key_S: return shift ? "S" : "s";
-       case Qt::Key_T: return shift ? "T" : "t";
-       case Qt::Key_U: return shift ? "U" : "u";
-       case Qt::Key_V: return shift ? "V" : "v";
-       case Qt::Key_W: return shift ? "W" : "w";
-       case Qt::Key_X: return shift ? "X" : "x";
-       case Qt::Key_Y: return shift ? "Y" : "y";
-       case Qt::Key_Z: return shift ? "Z" : "z";
        case Qt::Key_BracketLeft: return "bracketleft";
        case Qt::Key_Backslash: return "backslash";
        case Qt::Key_BracketRight: return "bracketright";
@@ -519,60 +533,8 @@ string const qkey_to_string(int lkey, bool shift)
        case Qt::Key_Backtab: return "BackTab";
 
        default:
-       case Qt::Key_unknown: return "unknown";
-       }
-} 
-
-/**
- * qkey_to_char - convert keypress into char
- *
- * Convert the Qt keypress into a iso8859-1 char that
- * represents it.
- *
- * FIXME: this is where all the encoding stuff
- * sits, I suppose. I have shit all idea what
- * to do. Help ! 
- */
-char const qkey_to_char(int lkey, bool shift)
-{
-       // We are relying on Qt internals here, but it's
-       // not likely to change anyway.
-       if (lkey >= 0x1000) 
-               return 0;
-
-       switch (lkey) {
-       case Qt::Key_A: return shift ? 'A' : 'a';
-       case Qt::Key_B: return shift ? 'B' : 'b';
-       case Qt::Key_C: return shift ? 'C' : 'c';
-       case Qt::Key_D: return shift ? 'D' : 'd';
-       case Qt::Key_E: return shift ? 'E' : 'e';
-       case Qt::Key_F: return shift ? 'F' : 'f';
-       case Qt::Key_G: return shift ? 'G' : 'g';
-       case Qt::Key_H: return shift ? 'H' : 'h';
-       case Qt::Key_I: return shift ? 'I' : 'i';
-       case Qt::Key_J: return shift ? 'J' : 'j';
-       case Qt::Key_K: return shift ? 'K' : 'k';
-       case Qt::Key_L: return shift ? 'L' : 'l';
-       case Qt::Key_M: return shift ? 'M' : 'm';
-       case Qt::Key_N: return shift ? 'N' : 'n';
-       case Qt::Key_O: return shift ? 'O' : 'o';
-       case Qt::Key_P: return shift ? 'P' : 'p';
-       case Qt::Key_Q: return shift ? 'Q' : 'q';
-       case Qt::Key_R: return shift ? 'R' : 'r';
-       case Qt::Key_S: return shift ? 'S' : 's';
-       case Qt::Key_T: return shift ? 'T' : 't';
-       case Qt::Key_U: return shift ? 'U' : 'u';
-       case Qt::Key_V: return shift ? 'V' : 'v';
-       case Qt::Key_W: return shift ? 'W' : 'w';
-       case Qt::Key_X: return shift ? 'X' : 'x';
-       case Qt::Key_Y: return shift ? 'Y' : 'y';
-       case Qt::Key_Z: return shift ? 'Z' : 'z';
-       default:
-               return lkey;
+       case Qt::Key_unknown: return "";
        }
-
-       // FIXME: CapsLock ignored.
-       // FIXME: all things like é are screwed too. I LOVE Qt. I REALLY DO.
 }
 
 #endif // QLKEY_H