Debian Codegraph @

src/gui/globalHotKeys/KeySequenceToWinKeyCodeTranslator.cpp

raw symbols SCIP
1 /*
2 * Copyright (C) 2019 Damir Porobic <[email protected]>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18 */
19
20 #include "KeySequenceToWinKeyCodeTranslator.h"
21
22 KeySequenceToWinKeyCodeTranslator::KeySequenceToWinKeyCodeTranslator()
23 {
24 mHotKeyMap = HotKeyMap::instance();
25 }
26
27 KeyCodeCombo KeySequenceToWinKeyCodeTranslator::map(const QKeySequence &keySequence) const
28 {
29 auto sequenceString = keySequence.toString().toUpper();
30 auto modifierString = sequenceString.section(QLatin1String("+"), 0, -2);
31 auto keyString = sequenceString.section(QLatin1String("+"), -1, -1);
32
33 auto modifier = getModifier(modifierString);
34 auto key = getKey(keyString);
35
36 return KeyCodeCombo(modifier, key);
37 }
38
39 unsigned int KeySequenceToWinKeyCodeTranslator::getModifier(const QString &modifierString) const
40 {
41 unsigned int modifier = MOD_NOREPEAT;
42 if (modifierString.contains(QLatin1String("SHIFT"))) {
43 modifier |= MOD_SHIFT;
44 }
45 if (modifierString.contains(QLatin1String("ALT"))) {
46 modifier |= MOD_ALT;
47 }
48 if (modifierString.contains(QLatin1String("CTRL"))) {
49 modifier |= MOD_CONTROL;
50 }
51
52 return modifier;
53 }
54
55 unsigned int KeySequenceToWinKeyCodeTranslator::getKey(const QString &keyString) const
56 {
57 auto key = mHotKeyMap->getKeyForString(keyString);
58 switch (key) {
59 case Qt::Key_F1:
60 return VK_F1;
61 case Qt::Key_F2:
62 return VK_F2;
63 case Qt::Key_F3:
64 return VK_F3;
65 case Qt::Key_F4:
66 return VK_F4;
67 case Qt::Key_F5:
68 return VK_F5;
69 case Qt::Key_F6:
70 return VK_F6;
71 case Qt::Key_F7:
72 return VK_F7;
73 case Qt::Key_F8:
74 return VK_F8;
75 case Qt::Key_F9:
76 return VK_F9;
77 case Qt::Key_F10:
78 return VK_F10;
79 case Qt::Key_F11:
80 return VK_F11;
81 case Qt::Key_F12:
82 return VK_F12;
83 case Qt::Key_Escape:
84 return VK_ESCAPE;
85 case Qt::Key_Backspace:
86 return VK_BACK;
87 case Qt::Key_Return:
88 case Qt::Key_Enter:
89 return VK_RETURN;
90 case Qt::Key_Insert:
91 return VK_INSERT;
92 case Qt::Key_Delete:
93 return VK_DELETE;
94 case Qt::Key_Pause:
95 return VK_PAUSE;
96 case Qt::Key_Print:
97 return VK_SNAPSHOT;
98 case Qt::Key_Home:
99 return VK_HOME;
100 case Qt::Key_End:
101 return VK_END;
102 case Qt::Key_Left:
103 return VK_LEFT;
104 case Qt::Key_Up:
105 return VK_UP;
106 case Qt::Key_Right:
107 return VK_RIGHT;
108 case Qt::Key_Down:
109 return VK_DOWN;
110 case Qt::Key_PageUp:
111 return VK_PRIOR;
112 case Qt::Key_PageDown:
113 return VK_NEXT;
114 case Qt::Key_Comma:
115 case Qt::Key_Semicolon:
116 return VK_OEM_COMMA;
117 case Qt::Key_Minus:
118 case Qt::Key_Underscore:
119 return VK_OEM_MINUS;
120 case Qt::Key_Period:
121 case Qt::Key_Colon:
122 return VK_OEM_PERIOD;
123 default:
124 return key;
125 }
126 }