• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdelibs API Reference
  • KDE Home
  • Contact Us
 

KDEUI

  • sources
  • kde-4.14
  • kdelibs
  • kdeui
  • util
kkeyserver.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2001 Ellis Whitehead <ellis@kde.org>
3 
4  Win32 port:
5  Copyright (C) 2004 JarosÅ‚aw Staniek <staniek@kde.org>
6 
7  This library is free software; you can redistribute it and/or
8  modify it under the terms of the GNU Library General Public
9  License as published by the Free Software Foundation; either
10  version 2 of the License, or (at your option) any later version.
11 
12  This library is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  Library General Public License for more details.
16 
17  You should have received a copy of the GNU Library General Public License
18  along with this library; see the file COPYING.LIB. If not, write to
19  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20  Boston, MA 02110-1301, USA.
21  */
22 
23 #include "kkeyserver.h"
24 
25 #include <config.h>
26 #include <klocale.h>
27 #include <kglobal.h>
28 #include <kconfig.h>
29 #include <kconfiggroup.h>
30 
31 namespace KKeyServer {
32 //---------------------------------------------------------------------
33 // Array Structures
34 //---------------------------------------------------------------------
35 
36 struct ModInfo
37 {
38  int modQt;
39  const char* psName;
40  QString* sLabel; // this struct is used in static objects, so must use a pointer here.
41 };
42 
43 //---------------------------------------------------------------------
44 // Arrays
45 //---------------------------------------------------------------------
46 
47 // Key names with this context are extracted elsewhere,
48 // no need for I18N_NOOP2's here.
49 #define KEYCTXT "keyboard-key-name"
50 static ModInfo g_rgModInfo[4] =
51 {
52  { Qt::SHIFT, "Shift", 0 },
53  { Qt::CTRL, "Ctrl", 0 },
54  { Qt::ALT, "Alt", 0 },
55  { Qt::META, "Meta", 0 }
56 };
57 
58 //---------------------------------------------------------------------
59 // Initialization
60 //---------------------------------------------------------------------
61 static bool g_bInitializedKKeyLabels;
62 static bool g_bMacLabels;
63 
64 static void intializeKKeyLabels()
65 {
66  KConfigGroup cg( KGlobal::config(), "Keyboard" );
67  g_rgModInfo[0].sLabel = new QString( cg.readEntry( "Label Shift", i18nc(KEYCTXT, g_rgModInfo[0].psName) ) );
68  g_rgModInfo[1].sLabel = new QString( cg.readEntry( "Label Ctrl", i18nc(KEYCTXT, g_rgModInfo[1].psName) ) );
69  g_rgModInfo[2].sLabel = new QString( cg.readEntry( "Label Alt", i18nc(KEYCTXT, g_rgModInfo[2].psName) ) );
70  g_rgModInfo[3].sLabel = new QString( cg.readEntry( "Label Win", i18nc(KEYCTXT, g_rgModInfo[3].psName) ) );
71  g_bMacLabels = (*g_rgModInfo[2].sLabel == "Command");
72  g_bInitializedKKeyLabels = true;
73 
74 }
75 
76 //---------------------------------------------------------------------
77 // Public functions
78 //---------------------------------------------------------------------
79 
80 static QString modToString( uint mod, bool bUserSpace )
81 {
82  if( bUserSpace && !g_bInitializedKKeyLabels )
83  intializeKKeyLabels();
84 
85  QString s;
86  for( int i = 3; i >= 0; i-- ) {
87  if( mod & g_rgModInfo[i].modQt ) {
88  if( !s.isEmpty() )
89  s += '+';
90  s += (bUserSpace)
91  ? *g_rgModInfo[i].sLabel
92  : QString(g_rgModInfo[i].psName);
93  }
94  }
95  return s;
96 }
97 
98 QString modToStringUser( uint mod )
99 {
100  return modToString( mod, true );
101 }
102 
103 uint stringUserToMod( const QString& mod )
104 {
105  QString s;
106  for( int i = 3; i >= 0; i-- ) {
107  if( mod.toLower() == g_rgModInfo[i].sLabel->toLower())
108  return g_rgModInfo[i].modQt;
109  }
110  return 0;
111 }
112 
113 bool isShiftAsModifierAllowed( int keyQt )
114 {
115  // remove any modifiers
116  keyQt &= ~Qt::KeyboardModifierMask;
117 
118  // Shift only works as a modifier with certain keys. It's not possible
119  // to enter the SHIFT+5 key sequence for me because this is handled as
120  // '%' by qt on my keyboard.
121  // The working keys are all hardcoded here :-(
122  if (keyQt >= Qt::Key_F1 && keyQt <= Qt::Key_F35)
123  return true;
124 
125  if (QChar(keyQt).isLetter())
126  return true;
127 
128  switch (keyQt) {
129  case Qt::Key_Return:
130  case Qt::Key_Space:
131  case Qt::Key_Backspace:
132  case Qt::Key_Backtab:
133  case Qt::Key_Escape:
134  case Qt::Key_Print:
135  case Qt::Key_ScrollLock:
136  case Qt::Key_Pause:
137  case Qt::Key_PageUp:
138  case Qt::Key_PageDown:
139  case Qt::Key_Insert:
140  case Qt::Key_Delete:
141  case Qt::Key_Home:
142  case Qt::Key_End:
143  case Qt::Key_Up:
144  case Qt::Key_Down:
145  case Qt::Key_Left:
146  case Qt::Key_Right:
147  case Qt::Key_Enter:
148  case Qt::Key_SysReq:
149  case Qt::Key_CapsLock:
150  case Qt::Key_NumLock:
151  case Qt::Key_Help:
152  case Qt::Key_Back:
153  case Qt::Key_Forward:
154  case Qt::Key_Stop:
155  case Qt::Key_Refresh:
156  case Qt::Key_Favorites:
157  case Qt::Key_LaunchMedia:
158  case Qt::Key_OpenUrl:
159  case Qt::Key_HomePage:
160  case Qt::Key_Search:
161  case Qt::Key_VolumeDown:
162  case Qt::Key_VolumeMute:
163  case Qt::Key_VolumeUp:
164  case Qt::Key_BassBoost:
165  case Qt::Key_BassUp:
166  case Qt::Key_BassDown:
167  case Qt::Key_TrebleUp:
168  case Qt::Key_TrebleDown:
169  case Qt::Key_MediaPlay:
170  case Qt::Key_MediaStop:
171  case Qt::Key_MediaPrevious:
172  case Qt::Key_MediaNext:
173  case Qt::Key_MediaRecord:
174  case Qt::Key_MediaPause:
175  case Qt::Key_MediaTogglePlayPause:
176  case Qt::Key_LaunchMail:
177  case Qt::Key_Calculator:
178  case Qt::Key_Memo:
179  case Qt::Key_ToDoList:
180  case Qt::Key_Calendar:
181  case Qt::Key_PowerDown:
182  case Qt::Key_ContrastAdjust:
183  case Qt::Key_Standby:
184  case Qt::Key_MonBrightnessUp:
185  case Qt::Key_MonBrightnessDown:
186  case Qt::Key_KeyboardLightOnOff:
187  case Qt::Key_KeyboardBrightnessUp:
188  case Qt::Key_KeyboardBrightnessDown:
189  case Qt::Key_PowerOff:
190  case Qt::Key_WakeUp:
191  case Qt::Key_Eject:
192  case Qt::Key_ScreenSaver:
193  case Qt::Key_WWW:
194  case Qt::Key_Sleep:
195  case Qt::Key_LightBulb:
196  case Qt::Key_Shop:
197  case Qt::Key_History:
198  case Qt::Key_AddFavorite:
199  case Qt::Key_HotLinks:
200  case Qt::Key_BrightnessAdjust:
201  case Qt::Key_Finance:
202  case Qt::Key_Community:
203  case Qt::Key_AudioRewind:
204  case Qt::Key_BackForward:
205  case Qt::Key_ApplicationLeft:
206  case Qt::Key_ApplicationRight:
207  case Qt::Key_Book:
208  case Qt::Key_CD:
209  case Qt::Key_Clear:
210  case Qt::Key_ClearGrab:
211  case Qt::Key_Close:
212  case Qt::Key_Copy:
213  case Qt::Key_Cut:
214  case Qt::Key_Display:
215  case Qt::Key_DOS:
216  case Qt::Key_Documents:
217  case Qt::Key_Excel:
218  case Qt::Key_Explorer:
219  case Qt::Key_Game:
220  case Qt::Key_Go:
221  case Qt::Key_iTouch:
222  case Qt::Key_LogOff:
223  case Qt::Key_Market:
224  case Qt::Key_Meeting:
225  case Qt::Key_MenuKB:
226  case Qt::Key_MenuPB:
227  case Qt::Key_MySites:
228  case Qt::Key_News:
229  case Qt::Key_OfficeHome:
230  case Qt::Key_Option:
231  case Qt::Key_Paste:
232  case Qt::Key_Phone:
233  case Qt::Key_Reply:
234  case Qt::Key_Reload:
235  case Qt::Key_RotateWindows:
236  case Qt::Key_RotationPB:
237  case Qt::Key_RotationKB:
238  case Qt::Key_Save:
239  case Qt::Key_Send:
240  case Qt::Key_Spell:
241  case Qt::Key_SplitScreen:
242  case Qt::Key_Support:
243  case Qt::Key_TaskPane:
244  case Qt::Key_Terminal:
245  case Qt::Key_Tools:
246  case Qt::Key_Travel:
247  case Qt::Key_Video:
248  case Qt::Key_Word:
249  case Qt::Key_Xfer:
250  case Qt::Key_ZoomIn:
251  case Qt::Key_ZoomOut:
252  case Qt::Key_Away:
253  case Qt::Key_Messenger:
254  case Qt::Key_WebCam:
255  case Qt::Key_MailForward:
256  case Qt::Key_Pictures:
257  case Qt::Key_Music:
258  case Qt::Key_Battery:
259  case Qt::Key_Bluetooth:
260  case Qt::Key_WLAN:
261  case Qt::Key_UWB:
262  case Qt::Key_AudioForward:
263  case Qt::Key_AudioRepeat:
264  case Qt::Key_AudioRandomPlay:
265  case Qt::Key_Subtitle:
266  case Qt::Key_AudioCycleTrack:
267  case Qt::Key_Time:
268  case Qt::Key_Select:
269  case Qt::Key_View:
270  case Qt::Key_TopMenu:
271  case Qt::Key_Suspend:
272  case Qt::Key_Hibernate:
273  case Qt::Key_Launch0:
274  case Qt::Key_Launch1:
275  case Qt::Key_Launch2:
276  case Qt::Key_Launch3:
277  case Qt::Key_Launch4:
278  case Qt::Key_Launch5:
279  case Qt::Key_Launch6:
280  case Qt::Key_Launch7:
281  case Qt::Key_Launch8:
282  case Qt::Key_Launch9:
283  case Qt::Key_LaunchA:
284  case Qt::Key_LaunchB:
285  case Qt::Key_LaunchC:
286  case Qt::Key_LaunchD:
287  case Qt::Key_LaunchE:
288  case Qt::Key_LaunchF:
289  return true;
290 
291  default:
292  return false;
293  }
294 }
295 
296 }
KKeyServer::isShiftAsModifierAllowed
bool isShiftAsModifierAllowed(int keyQt)
Test if the shift modifier should be recorded for a given key.
Definition: kkeyserver.cpp:113
QChar
kconfig.h
klocale.h
i18nc
QString i18nc(const char *ctxt, const char *text)
KGlobal::config
KSharedConfigPtr config()
kglobal.h
kkeyserver.h
SHIFT
#define SHIFT(x)
Definition: kstandardshortcut.cpp:71
KKeyServer::g_rgModInfo
static ModInfo g_rgModInfo[4]
Definition: kkeyserver.cpp:50
CTRL
#define CTRL(x)
Definition: kstandardshortcut.cpp:70
QString::isEmpty
bool isEmpty() const
KKeyServer::g_bMacLabels
static bool g_bMacLabels
Definition: kkeyserver.cpp:62
KKeyServer::intializeKKeyLabels
static void intializeKKeyLabels()
Definition: kkeyserver.cpp:64
ALT
#define ALT(x)
Definition: kstandardshortcut.cpp:73
QString
KEYCTXT
#define KEYCTXT
Definition: kkeyserver.cpp:49
QString::toLower
QString toLower() const
KConfigGroup
KKeyServer::stringUserToMod
uint stringUserToMod(const QString &mod)
Converts the modifier given as user-readable string to KKey::ModFlag modifier, or 0...
Definition: kkeyserver.cpp:103
KKeyServer::modToString
static QString modToString(uint mod, bool bUserSpace)
Definition: kkeyserver.cpp:80
KConfigGroup::readEntry
T readEntry(const QString &key, const T &aDefault) const
KKeyServer::g_bInitializedKKeyLabels
static bool g_bInitializedKKeyLabels
Definition: kkeyserver.cpp:61
kconfiggroup.h
KKeyServer::modToStringUser
QString modToStringUser(uint mod)
Converts the mask of ORed KKey::ModFlag modifiers to a user-readable string.
Definition: kkeyserver.cpp:98
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:23:59 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KDEUI

Skip menu "KDEUI"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Modules
  • Related Pages

kdelibs API Reference

Skip menu "kdelibs API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal