Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

KeyNames.cpp

Go to the documentation of this file.
00001 #include "KeyNames.h"
00002 
00003 QMap<QString, int> KeyNames::codemap;
00004 QMap<int, QString> KeyNames::namemap;
00005 QString KeyNames::tmpname;
00006 
00007 static struct {
00008         int code;
00009         char* name;
00010 } stKeyNames[] = {
00011 {Qt::Key_Escape, "Escape"},
00012 {Qt::Key_Tab, "Tab"},
00013 {Qt::Key_Backtab, "Backtab"},
00014 {Qt::Key_BackTab, "BackTab"},
00015 {Qt::Key_Backtab, "Backtab"},
00016 {Qt::Key_Backspace, "Backspace"},
00017 {Qt::Key_BackSpace, "BackSpace"},
00018 {Qt::Key_Backspace, "Backspace"},
00019 {Qt::Key_Return, "Return"},
00020 {Qt::Key_Enter, "Enter"},
00021 {Qt::Key_Insert, "Insert"},
00022 {Qt::Key_Delete, "Delete"},
00023 {Qt::Key_Pause, "Pause"},
00024 {Qt::Key_Print, "Print"},
00025 {Qt::Key_SysReq, "SysReq"},
00026 {Qt::Key_Home, "Home"},
00027 {Qt::Key_End, "End"},
00028 {Qt::Key_Left, "Left"},
00029 {Qt::Key_Up, "Up"},
00030 {Qt::Key_Right, "Right"},
00031 {Qt::Key_Down, "Down"},
00032 {Qt::Key_Prior, "Prior"},
00033 {Qt::Key_PageUp, "PageUp"},
00034 {Qt::Key_Prior, "Prior"},
00035 {Qt::Key_Next, "Next"},
00036 {Qt::Key_PageDown, "PageDown"},
00037 {Qt::Key_Next, "Next"},
00038 {Qt::Key_Shift, "Shift"},
00039 {Qt::Key_Control, "Control"},
00040 {Qt::Key_Meta, "Meta"},
00041 {Qt::Key_Alt, "Alt"},
00042 {Qt::Key_CapsLock, "CapsLock"},
00043 {Qt::Key_NumLock, "NumLock"},
00044 {Qt::Key_ScrollLock, "ScrollLock"},
00045 {Qt::Key_F1, "F1"},
00046 {Qt::Key_F2, "F2"},
00047 {Qt::Key_F3, "F3"},
00048 {Qt::Key_F4, "F4"},
00049 {Qt::Key_F5, "F5"},
00050 {Qt::Key_F6, "F6"},
00051 {Qt::Key_F7, "F7"},
00052 {Qt::Key_F8, "F8"},
00053 {Qt::Key_F9, "F9"},
00054 {Qt::Key_F10, "F10"},
00055 {Qt::Key_F11, "F11"},
00056 {Qt::Key_F12, "F12"},
00057 {Qt::Key_F13, "F13"},
00058 {Qt::Key_F14, "F14"},
00059 {Qt::Key_F15, "F15"},
00060 {Qt::Key_F16, "F16"},
00061 {Qt::Key_F17, "F17"},
00062 {Qt::Key_F18, "F18"},
00063 {Qt::Key_F19, "F19"},
00064 {Qt::Key_F20, "F20"},
00065 {Qt::Key_F21, "F21"},
00066 {Qt::Key_F22, "F22"},
00067 {Qt::Key_F23, "F23"},
00068 {Qt::Key_F24, "F24"},
00069 {Qt::Key_F25, "F25"},
00070 {Qt::Key_F26, "F26"},
00071 {Qt::Key_F27, "F27"},
00072 {Qt::Key_F28, "F28"},
00073 {Qt::Key_F29, "F29"},
00074 {Qt::Key_F30, "F30"},
00075 {Qt::Key_F31, "F31"},
00076 {Qt::Key_F32, "F32"},
00077 {Qt::Key_F33, "F33"},
00078 {Qt::Key_F34, "F34"},
00079 {Qt::Key_F35, "F35"},
00080 {Qt::Key_Super_L, "Super_L"},
00081 {Qt::Key_Super_R, "Super_R"},
00082 {Qt::Key_Menu, "Menu"},
00083 {Qt::Key_Hyper_L, "Hyper_L"},
00084 {Qt::Key_Hyper_R, "Hyper_R"},
00085 {Qt::Key_Help, "Help"},
00086 {Qt::Key_Space, "Space"},
00087 {Qt::Key_Any, "Any"},
00088 {Qt::Key_Space, "Space"},
00089 {Qt::Key_Exclam, "Exclam"},
00090 {Qt::Key_QuoteDbl, "QuoteDbl"},
00091 {Qt::Key_NumberSign, "NumberSign"},
00092 {Qt::Key_Dollar, "Dollar"},
00093 {Qt::Key_Percent, "Percent"},
00094 {Qt::Key_Ampersand, "Ampersand"},
00095 {Qt::Key_Apostrophe, "Apostrophe"},
00096 {Qt::Key_ParenLeft, "ParenLeft"},
00097 {Qt::Key_ParenRight, "ParenRight"},
00098 {Qt::Key_Asterisk, "Asterisk"},
00099 {Qt::Key_Plus, "Plus"},
00100 {Qt::Key_Comma, "Comma"},
00101 {Qt::Key_Minus, "Minus"},
00102 {Qt::Key_Period, "Period"},
00103 {Qt::Key_Slash, "Slash"},
00104 {Qt::Key_0, "0"},
00105 {Qt::Key_1, "1"},
00106 {Qt::Key_2, "2"},
00107 {Qt::Key_3, "3"},
00108 {Qt::Key_4, "4"},
00109 {Qt::Key_5, "5"},
00110 {Qt::Key_6, "6"},
00111 {Qt::Key_7, "7"},
00112 {Qt::Key_8, "8"},
00113 {Qt::Key_9, "9"},
00114 {Qt::Key_Colon, "Colon"},
00115 {Qt::Key_Semicolon, "Semicolon"},
00116 {Qt::Key_Less, "Less"},
00117 {Qt::Key_Equal, "Equal"},
00118 {Qt::Key_Greater, "Greater"},
00119 {Qt::Key_Question, "Question"},
00120 {Qt::Key_At, "At"},
00121 {Qt::Key_A, "A"},
00122 {Qt::Key_B, "B"},
00123 {Qt::Key_C, "C"},
00124 {Qt::Key_D, "D"},
00125 {Qt::Key_E, "E"},
00126 {Qt::Key_F, "F"},
00127 {Qt::Key_G, "G"},
00128 {Qt::Key_H, "H"},
00129 {Qt::Key_I, "I"},
00130 {Qt::Key_J, "J"},
00131 {Qt::Key_K, "K"},
00132 {Qt::Key_L, "L"},
00133 {Qt::Key_M, "M"},
00134 {Qt::Key_N, "N"},
00135 {Qt::Key_O, "O"},
00136 {Qt::Key_P, "P"},
00137 {Qt::Key_Q, "Q"},
00138 {Qt::Key_R, "R"},
00139 {Qt::Key_S, "S"},
00140 {Qt::Key_T, "T"},
00141 {Qt::Key_U, "U"},
00142 {Qt::Key_V, "V"},
00143 {Qt::Key_W, "W"},
00144 {Qt::Key_X, "X"},
00145 {Qt::Key_Y, "Y"},
00146 {Qt::Key_Z, "Z"},
00147 {Qt::Key_BracketLeft, "BracketLeft"},
00148 {Qt::Key_Backslash, "Backslash"},
00149 {Qt::Key_BracketRight, "BracketRight"},
00150 {Qt::Key_AsciiCircum, "AsciiCircum"},
00151 {Qt::Key_Underscore, "Underscore"},
00152 {Qt::Key_QuoteLeft, "QuoteLeft"},
00153 {Qt::Key_BraceLeft, "BraceLeft"},
00154 {Qt::Key_Bar, "Bar"},
00155 {Qt::Key_BraceRight, "BraceRight"},
00156 {Qt::Key_AsciiTilde, "AsciiTilde"},
00157 {Qt::Key_nobreakspace, "nobreakspace"},
00158 {Qt::Key_exclamdown, "exclamdown"},
00159 {Qt::Key_cent, "cent"},
00160 {Qt::Key_sterling, "sterling"},
00161 {Qt::Key_currency, "currency"},
00162 {Qt::Key_yen, "yen"},
00163 {Qt::Key_brokenbar, "brokenbar"},
00164 {Qt::Key_section, "section"},
00165 {Qt::Key_diaeresis, "diaeresis"},
00166 {Qt::Key_copyright, "copyright"},
00167 {Qt::Key_ordfeminine, "ordfeminine"},
00168 {Qt::Key_guillemotleft, "guillemotleft"},
00169 {Qt::Key_notsign, "notsign"},
00170 {Qt::Key_hyphen, "hyphen"},
00171 {Qt::Key_registered, "registered"},
00172 {Qt::Key_macron, "macron"},
00173 {Qt::Key_degree, "degree"},
00174 {Qt::Key_plusminus, "plusminus"},
00175 {Qt::Key_twosuperior, "twosuperior"},
00176 {Qt::Key_threesuperior, "threesuperior"},
00177 {Qt::Key_acute, "acute"},
00178 {Qt::Key_mu, "mu"},
00179 {Qt::Key_paragraph, "paragraph"},
00180 {Qt::Key_periodcentered, "periodcentered"},
00181 {Qt::Key_cedilla, "cedilla"},
00182 {Qt::Key_onesuperior, "onesuperior"},
00183 {Qt::Key_masculine, "masculine"},
00184 {Qt::Key_guillemotright, "guillemotright"},
00185 {Qt::Key_onequarter, "onequarter"},
00186 {Qt::Key_onehalf, "onehalf"},
00187 {Qt::Key_threequarters, "threequarters"},
00188 {Qt::Key_questiondown, "questiondown"},
00189 {Qt::Key_Agrave, "Agrave"},
00190 {Qt::Key_Aacute, "Aacute"},
00191 {Qt::Key_Acircumflex, "Acircumflex"},
00192 {Qt::Key_Atilde, "Atilde"},
00193 {Qt::Key_Adiaeresis, "Adiaeresis"},
00194 {Qt::Key_Aring, "Aring"},
00195 {Qt::Key_AE, "AE"},
00196 {Qt::Key_Ccedilla, "Ccedilla"},
00197 {Qt::Key_Egrave, "Egrave"},
00198 {Qt::Key_Eacute, "Eacute"},
00199 {Qt::Key_Ecircumflex, "Ecircumflex"},
00200 {Qt::Key_Ediaeresis, "Ediaeresis"},
00201 {Qt::Key_Igrave, "Igrave"},
00202 {Qt::Key_Iacute, "Iacute"},
00203 {Qt::Key_Icircumflex, "Icircumflex"},
00204 {Qt::Key_Idiaeresis, "Idiaeresis"},
00205 {Qt::Key_ETH, "ETH"},
00206 {Qt::Key_Ntilde, "Ntilde"},
00207 {Qt::Key_Ograve, "Ograve"},
00208 {Qt::Key_Oacute, "Oacute"},
00209 {Qt::Key_Ocircumflex, "Ocircumflex"},
00210 {Qt::Key_Otilde, "Otilde"},
00211 {Qt::Key_Odiaeresis, "Odiaeresis"},
00212 {Qt::Key_multiply, "multiply"},
00213 {Qt::Key_Ooblique, "Ooblique"},
00214 {Qt::Key_Ugrave, "Ugrave"},
00215 {Qt::Key_Uacute, "Uacute"},
00216 {Qt::Key_Ucircumflex, "Ucircumflex"},
00217 {Qt::Key_Udiaeresis, "Udiaeresis"},
00218 {Qt::Key_Yacute, "Yacute"},
00219 {Qt::Key_THORN, "THORN"},
00220 {Qt::Key_ssharp, "ssharp"},
00221 {Qt::Key_agrave, "agrave"},
00222 {Qt::Key_aacute, "aacute"},
00223 {Qt::Key_acircumflex, "acircumflex"},
00224 {Qt::Key_atilde, "atilde"},
00225 {Qt::Key_adiaeresis, "adiaeresis"},
00226 {Qt::Key_aring, "aring"},
00227 {Qt::Key_ae, "ae"},
00228 {Qt::Key_ccedilla, "ccedilla"},
00229 {Qt::Key_egrave, "egrave"},
00230 {Qt::Key_eacute, "eacute"},
00231 {Qt::Key_ecircumflex, "ecircumflex"},
00232 {Qt::Key_ediaeresis, "ediaeresis"},
00233 {Qt::Key_igrave, "igrave"},
00234 {Qt::Key_iacute, "iacute"},
00235 {Qt::Key_icircumflex, "icircumflex"},
00236 {Qt::Key_idiaeresis, "idiaeresis"},
00237 {Qt::Key_eth, "eth"},
00238 {Qt::Key_ntilde, "ntilde"},
00239 {Qt::Key_ograve, "ograve"},
00240 {Qt::Key_oacute, "oacute"},
00241 {Qt::Key_ocircumflex, "ocircumflex"},
00242 {Qt::Key_otilde, "otilde"},
00243 {Qt::Key_odiaeresis, "odiaeresis"},
00244 {Qt::Key_division, "division"},
00245 {Qt::Key_oslash, "oslash"},
00246 {Qt::Key_ugrave, "ugrave"},
00247 {Qt::Key_uacute, "uacute"},
00248 {Qt::Key_ucircumflex, "ucircumflex"},
00249 {Qt::Key_udiaeresis, "udiaeresis"},
00250 {Qt::Key_yacute, "yacute"},
00251 {Qt::Key_thorn, "thorn"},
00252 {Qt::Key_ydiaeresis, "ydiaeresis"},
00253 {Qt::Key_unknown, "unknown"},
00254 {0,0},
00255 };
00256 
00257 void KeyNames::setCodeMap()
00258 {
00259         int i;
00260 
00261         codemap.clear();
00262         for(i=0; stKeyNames[i].code != 0; i++){
00263                 codemap.insert(stKeyNames[i].name, stKeyNames[i].code);
00264         }
00265 }
00266 
00267 void KeyNames::setNameMap()
00268 {
00269         int i;
00270 
00271         namemap.clear();
00272         for(i=0; stKeyNames[i].code != 0; i++){
00273                 namemap.insert(stKeyNames[i].code, stKeyNames[i].name);
00274         }
00275 }
00276 
00277 
00278 int KeyNames::getCode(const QString& s){
00279         if(codemap.isEmpty()) setCodeMap();
00280         if(codemap.contains(s)){
00281                 return(codemap[s]);
00282         } else {
00283                 if(s.find("0x") == 0){
00284                         bool success;
00285                         int val = s.mid(2).toInt(&success, 16);
00286                         if(success){
00287                                 return(val);
00288                         }
00289                 }
00290                 return(0);
00291         }
00292 }
00293 
00294 const QString& KeyNames::getName(int code){
00295         if(namemap.isEmpty()) setNameMap();
00296         if(namemap.contains(code)){
00297                 return(namemap[code]);
00298         } else {
00299                 tmpname.sprintf("0x%x", code);
00300                 return(tmpname);
00301                 //return(QString::null);
00302         }
00303 }

Generated on Sat Nov 5 16:16:43 2005 for OPIE by  doxygen 1.4.2