1 /************************************************************************** 2 ** ** 3 ** Copyright (C) 2018 Lukas Spies ** 4 ** Contact: http://photoqt.org ** 5 ** ** 6 ** This file is part of PhotoQt. ** 7 ** ** 8 ** PhotoQt is free software: you can redistribute it and/or modify ** 9 ** it under the terms of the GNU General Public License as published by ** 10 ** the Free Software Foundation, either version 2 of the License, or ** 11 ** (at your option) any later version. ** 12 ** ** 13 ** PhotoQt is distributed in the hope that it will be useful, ** 14 ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** 15 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** 16 ** GNU General Public License for more details. ** 17 ** ** 18 ** You should have received a copy of the GNU General Public License ** 19 ** along with PhotoQt. If not, see <http://www.gnu.org/licenses/>. ** 20 ** ** 21 **************************************************************************/ 22 23 #ifndef COMPOSESTRING_H 24 #define COMPOSESTRING_H 25 26 #include <QKeyEvent> 27 #include "../logger.h" 28 29 class ComposeString { 30 31 public: compose(QKeyEvent * e)32 static QString compose(QKeyEvent *e) { 33 34 QString combostring = getModifiers(e); 35 36 switch(e->key()) { 37 case Qt::Key_Escape: 38 combostring += "Escape"; 39 break; 40 case Qt::Key_Right: 41 combostring += "Right"; 42 break; 43 case Qt::Key_Left: 44 combostring += "Left"; 45 break; 46 case Qt::Key_Up: 47 combostring += "Up"; 48 break; 49 case Qt::Key_Down: 50 combostring += "Down"; 51 break; 52 case Qt::Key_Space: 53 combostring += "Space"; 54 break; 55 case Qt::Key_Delete: 56 combostring += "Delete"; 57 break; 58 case Qt::Key_Home: 59 combostring += "Home"; 60 break; 61 case Qt::Key_End: 62 combostring += "End"; 63 break; 64 case Qt::Key_PageUp: 65 combostring += "Page Up"; 66 break; 67 case Qt::Key_PageDown: 68 combostring += "Page Down"; 69 break; 70 case Qt::Key_Insert: 71 combostring += "Insert"; 72 break; 73 case Qt::Key_Tab: 74 combostring += "Tab"; 75 break; 76 case Qt::Key_Backtab: 77 combostring += "Tab"; 78 break; 79 case Qt::Key_Return: 80 combostring += "Return"; 81 break; 82 case Qt::Key_Enter: 83 combostring += "Enter"; 84 break; 85 case Qt::Key_Pause: 86 combostring += "Pause"; 87 break; 88 case Qt::Key_Print: 89 combostring += "Print"; 90 break; 91 case Qt::Key_SysReq: 92 combostring += "SysReq"; 93 break; 94 case Qt::Key_Clear: 95 combostring += "Clear"; 96 break; 97 case Qt::Key_CapsLock: 98 combostring += "CapsLock"; 99 break; 100 case Qt::Key_NumLock: 101 combostring += "NumLock"; 102 break; 103 case Qt::Key_ScrollLock: 104 combostring += "ScrollLock"; 105 break; 106 case Qt::Key_Super_L: 107 combostring += "Super L"; 108 break; 109 case Qt::Key_Super_R: 110 combostring += "Super R"; 111 break; 112 case Qt::Key_Menu: 113 combostring += "Menu"; 114 break; 115 case Qt::Key_Hyper_L: 116 combostring += "Hyper L"; 117 break; 118 case Qt::Key_Hyper_R: 119 combostring += "Hyper R"; 120 break; 121 case Qt::Key_Help: 122 combostring += "Help"; 123 break; 124 case Qt::Key_Direction_L: 125 combostring += "Direction L"; 126 break; 127 case Qt::Key_Direction_R: 128 combostring += "Direction R"; 129 break; 130 case Qt::Key_F1: 131 combostring += "F1"; 132 break; 133 case Qt::Key_F2: 134 combostring += "F2"; 135 break; 136 case Qt::Key_F3: 137 combostring += "F3"; 138 break; 139 case Qt::Key_F4: 140 combostring += "F4"; 141 break; 142 case Qt::Key_F5: 143 combostring += "F5"; 144 break; 145 case Qt::Key_F6: 146 combostring += "F6"; 147 break; 148 case Qt::Key_F7: 149 combostring += "F7"; 150 break; 151 case Qt::Key_F8: 152 combostring += "F8"; 153 break; 154 case Qt::Key_F9: 155 combostring += "F9"; 156 break; 157 case Qt::Key_F10: 158 combostring += "F10"; 159 break; 160 case Qt::Key_F11: 161 combostring += "F11"; 162 break; 163 case Qt::Key_F12: 164 combostring += "F12"; 165 break; 166 case Qt::Key_F13: 167 combostring += "F13"; 168 break; 169 case Qt::Key_F14: 170 combostring += "F14"; 171 break; 172 case Qt::Key_F15: 173 combostring += "F15"; 174 break; 175 case Qt::Key_F16: 176 combostring += "F16"; 177 break; 178 case Qt::Key_F17: 179 combostring += "F17"; 180 break; 181 case Qt::Key_F18: 182 combostring += "F18"; 183 break; 184 case Qt::Key_F19: 185 combostring += "F19"; 186 break; 187 case Qt::Key_F20: 188 combostring += "F20"; 189 break; 190 case Qt::Key_F21: 191 combostring += "F21"; 192 break; 193 case Qt::Key_F22: 194 combostring += "F22"; 195 break; 196 case Qt::Key_F23: 197 combostring += "F23"; 198 break; 199 case Qt::Key_F24: 200 combostring += "F24"; 201 break; 202 case Qt::Key_F25: 203 combostring += "F25"; 204 break; 205 case Qt::Key_F26: 206 combostring += "F26"; 207 break; 208 case Qt::Key_F27: 209 combostring += "F27"; 210 break; 211 case Qt::Key_F28: 212 combostring += "F28"; 213 break; 214 case Qt::Key_F29: 215 combostring += "F29"; 216 break; 217 case Qt::Key_F30: 218 combostring += "F30"; 219 break; 220 case Qt::Key_F31: 221 combostring += "F31"; 222 break; 223 case Qt::Key_F32: 224 combostring += "F32"; 225 break; 226 case Qt::Key_F33: 227 combostring += "F33"; 228 break; 229 case Qt::Key_F34: 230 combostring += "F34"; 231 break; 232 case Qt::Key_F35: 233 combostring += "F35"; 234 break; 235 default: 236 if(e->text() != "") 237 combostring += QKeySequence(e->key()).toString(); 238 239 } 240 241 if(qgetenv("PHOTOQT_DEBUG") == "yes") 242 LOG << CURDATE << "ComposeString::compose() - combostring = " << combostring.toStdString() << NL; 243 244 return combostring; 245 246 } 247 getModifiers(QKeyEvent * e)248 static QString getModifiers(QKeyEvent *e) { 249 250 QString modstring = ""; 251 252 if(e->modifiers() & Qt::ControlModifier) 253 modstring += "Ctrl+"; 254 if(e->modifiers() & Qt::AltModifier) 255 modstring += "Alt+"; 256 if(e->modifiers() & Qt::ShiftModifier) 257 modstring += "Shift+"; 258 if(e->modifiers() & Qt::MetaModifier) 259 modstring += "Meta+"; 260 if(e->modifiers() & Qt::KeypadModifier) 261 modstring += "Keypad+"; 262 263 return modstring; 264 265 } 266 267 }; 268 269 270 #endif // COMPOSESTRING_H 271