KWindowSystem

kkeyserver.cpp
1 /*
2  SPDX-FileCopyrightText: 2001 Ellis Whitehead <[email protected]>
3 
4  Win32 port:
5  SPDX-FileCopyrightText: 2004 JarosÅ‚aw Staniek <[email protected]>
6 
7  SPDX-License-Identifier: LGPL-2.1-or-later
8 */
9 
10 #include "kkeyserver.h"
11 
12 #include <QCoreApplication>
13 
14 namespace KKeyServer
15 {
16 //---------------------------------------------------------------------
17 // Array Structures
18 //---------------------------------------------------------------------
19 
20 struct ModInfo {
21  int modQt;
22  const char *psName;
23  QString *sLabel; // this struct is used in static objects, so must use a pointer here.
24 };
25 
26 //---------------------------------------------------------------------
27 // Arrays
28 //---------------------------------------------------------------------
29 
30 // Key names with this context are extracted elsewhere,
31 // no need for I18N_NOOP2's here.
32 #define KEYCTXT "keyboard-key-name"
33 static ModInfo g_rgModInfo[4] = {
34  {Qt::SHIFT, "Shift", nullptr},
35  {Qt::CTRL, "Ctrl", nullptr},
36  {Qt::ALT, "Alt", nullptr},
37  {Qt::META, "Meta", nullptr},
38 };
39 
40 //---------------------------------------------------------------------
41 // Initialization
42 //---------------------------------------------------------------------
43 static bool g_bInitializedKKeyLabels;
44 static bool g_bMacLabels;
45 
46 static void intializeKKeyLabels()
47 {
48  g_rgModInfo[0].sLabel = new QString(QCoreApplication::translate("KKeyServer", (g_rgModInfo[0].psName), KEYCTXT));
49  g_rgModInfo[1].sLabel = new QString(QCoreApplication::translate("KKeyServer", (g_rgModInfo[1].psName), KEYCTXT));
50  g_rgModInfo[2].sLabel = new QString(QCoreApplication::translate("KKeyServer", (g_rgModInfo[2].psName), KEYCTXT));
51  g_rgModInfo[3].sLabel = new QString(QCoreApplication::translate("KKeyServer", (g_rgModInfo[3].psName), KEYCTXT));
52  g_bMacLabels = (*g_rgModInfo[2].sLabel == QLatin1String("Command"));
53  g_bInitializedKKeyLabels = true;
54 }
55 
56 //---------------------------------------------------------------------
57 // Public functions
58 //---------------------------------------------------------------------
59 
60 static QString modToString(uint mod, bool bUserSpace)
61 {
62  if (bUserSpace && !g_bInitializedKKeyLabels) {
63  intializeKKeyLabels();
64  }
65 
66  QString s;
67  for (int i = 3; i >= 0; i--) {
68  if (mod & g_rgModInfo[i].modQt) {
69  if (!s.isEmpty()) {
70  s += QLatin1Char('+');
71  }
72  s += (bUserSpace) ? *g_rgModInfo[i].sLabel : QLatin1String(g_rgModInfo[i].psName);
73  }
74  }
75  return s;
76 }
77 
79 {
80  return modToString(mod, true);
81 }
82 
83 uint stringUserToMod(const QString &mod)
84 {
85  for (int i = 3; i >= 0; i--) {
86  if (mod.toLower() == g_rgModInfo[i].sLabel->toLower()) {
87  return g_rgModInfo[i].modQt;
88  }
89  }
90  return 0;
91 }
92 
93 bool isShiftAsModifierAllowed(int keyQt)
94 {
95  // remove any modifiers
96  keyQt &= ~Qt::KeyboardModifierMask;
97 
98  // Shift only works as a modifier with certain keys. It's not possible
99  // to enter the SHIFT+5 key sequence for me because this is handled as
100  // '%' by qt on my keyboard.
101  // The working keys are all hardcoded here :-(
102  if (keyQt >= Qt::Key_F1 && keyQt <= Qt::Key_F35) {
103  return true;
104  }
105 
106  if (QChar(keyQt).isLetter()) {
107  return true;
108  }
109 
110  switch (keyQt) {
111  case Qt::Key_Return:
112  case Qt::Key_Space:
113  case Qt::Key_Backspace:
114  case Qt::Key_Tab:
115  case Qt::Key_Backtab:
116  case Qt::Key_Escape:
117  case Qt::Key_Print:
118  case Qt::Key_ScrollLock:
119  case Qt::Key_Pause:
120  case Qt::Key_PageUp:
121  case Qt::Key_PageDown:
122  case Qt::Key_Insert:
123  case Qt::Key_Delete:
124  case Qt::Key_Home:
125  case Qt::Key_End:
126  case Qt::Key_Up:
127  case Qt::Key_Down:
128  case Qt::Key_Left:
129  case Qt::Key_Right:
130  case Qt::Key_Enter:
131  case Qt::Key_SysReq:
132  case Qt::Key_CapsLock:
133  case Qt::Key_NumLock:
134  case Qt::Key_Help:
135  case Qt::Key_Back:
136  case Qt::Key_Forward:
137  case Qt::Key_Stop:
138  case Qt::Key_Refresh:
139  case Qt::Key_Favorites:
140  case Qt::Key_LaunchMedia:
141  case Qt::Key_OpenUrl:
142  case Qt::Key_HomePage:
143  case Qt::Key_Search:
144  case Qt::Key_VolumeDown:
145  case Qt::Key_VolumeMute:
146  case Qt::Key_VolumeUp:
147  case Qt::Key_BassBoost:
148  case Qt::Key_BassUp:
149  case Qt::Key_BassDown:
150  case Qt::Key_TrebleUp:
151  case Qt::Key_TrebleDown:
152  case Qt::Key_MediaPlay:
153  case Qt::Key_MediaStop:
155  case Qt::Key_MediaNext:
156  case Qt::Key_MediaRecord:
157  case Qt::Key_MediaPause:
159  case Qt::Key_LaunchMail:
160  case Qt::Key_Calculator:
161  case Qt::Key_Memo:
162  case Qt::Key_ToDoList:
163  case Qt::Key_Calendar:
164  case Qt::Key_PowerDown:
166  case Qt::Key_Standby:
172  case Qt::Key_PowerOff:
173  case Qt::Key_WakeUp:
174  case Qt::Key_Eject:
175  case Qt::Key_ScreenSaver:
176  case Qt::Key_WWW:
177  case Qt::Key_Sleep:
178  case Qt::Key_LightBulb:
179  case Qt::Key_Shop:
180  case Qt::Key_History:
181  case Qt::Key_AddFavorite:
182  case Qt::Key_HotLinks:
184  case Qt::Key_Finance:
185  case Qt::Key_Community:
186  case Qt::Key_AudioRewind:
187  case Qt::Key_BackForward:
190  case Qt::Key_Book:
191  case Qt::Key_CD:
192  case Qt::Key_Clear:
193  case Qt::Key_ClearGrab:
194  case Qt::Key_Close:
195  case Qt::Key_Copy:
196  case Qt::Key_Cut:
197  case Qt::Key_Display:
198  case Qt::Key_DOS:
199  case Qt::Key_Documents:
200  case Qt::Key_Excel:
201  case Qt::Key_Explorer:
202  case Qt::Key_Game:
203  case Qt::Key_Go:
204  case Qt::Key_iTouch:
205  case Qt::Key_LogOff:
206  case Qt::Key_Market:
207  case Qt::Key_Meeting:
208  case Qt::Key_MenuKB:
209  case Qt::Key_MenuPB:
210  case Qt::Key_MySites:
211  case Qt::Key_News:
212  case Qt::Key_OfficeHome:
213  case Qt::Key_Option:
214  case Qt::Key_Paste:
215  case Qt::Key_Phone:
216  case Qt::Key_Reply:
217  case Qt::Key_Reload:
219  case Qt::Key_RotationPB:
220  case Qt::Key_RotationKB:
221  case Qt::Key_Save:
222  case Qt::Key_Send:
223  case Qt::Key_Spell:
224  case Qt::Key_SplitScreen:
225  case Qt::Key_Support:
226  case Qt::Key_TaskPane:
227  case Qt::Key_Terminal:
228  case Qt::Key_Tools:
229  case Qt::Key_Travel:
230  case Qt::Key_Video:
231  case Qt::Key_Word:
232  case Qt::Key_Xfer:
233  case Qt::Key_ZoomIn:
234  case Qt::Key_ZoomOut:
235  case Qt::Key_Away:
236  case Qt::Key_Messenger:
237  case Qt::Key_WebCam:
238  case Qt::Key_MailForward:
239  case Qt::Key_Pictures:
240  case Qt::Key_Music:
241  case Qt::Key_Battery:
242  case Qt::Key_Bluetooth:
243  case Qt::Key_WLAN:
244  case Qt::Key_UWB:
246  case Qt::Key_AudioRepeat:
248  case Qt::Key_Subtitle:
250  case Qt::Key_Time:
251  case Qt::Key_Select:
252  case Qt::Key_View:
253  case Qt::Key_TopMenu:
254  case Qt::Key_Suspend:
255  case Qt::Key_Hibernate:
256  case Qt::Key_Launch0:
257  case Qt::Key_Launch1:
258  case Qt::Key_Launch2:
259  case Qt::Key_Launch3:
260  case Qt::Key_Launch4:
261  case Qt::Key_Launch5:
262  case Qt::Key_Launch6:
263  case Qt::Key_Launch7:
264  case Qt::Key_Launch8:
265  case Qt::Key_Launch9:
266  case Qt::Key_LaunchA:
267  case Qt::Key_LaunchB:
268  case Qt::Key_LaunchC:
269  case Qt::Key_LaunchD:
270  case Qt::Key_LaunchE:
271  case Qt::Key_LaunchF:
272  return true;
273 
274  default:
275  return false;
276  }
277 }
278 
279 }
QString modToStringUser(uint mod)
Converts the mask of ORed KKey::ModFlag modifiers to a user-readable string.
Definition: kkeyserver.cpp:78
QString translate(const char *context, const char *sourceText, const char *disambiguation, int n)
A collection of functions for the conversion of key presses and their modifiers from the window syste...
Definition: kkeyserver.cpp:14
bool isShiftAsModifierAllowed(int keyQt)
Test if the shift modifier should be recorded for a given key.
Definition: kkeyserver.cpp:93
uint stringUserToMod(const QString &mod)
Converts the modifier given as user-readable string (in English) to KKey::ModFlag modifier...
Definition: kkeyserver.cpp:83
bool isEmpty() const const
QString toLower() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Fri Oct 15 2021 22:41:49 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.