• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • tdecore
 

tdecore

  • tdecore
tdestdaccel.cpp
1 /* This file is part of the KDE libraries
2  Copyright (C) 1997 Stefan Taferner (taferner@alpin.or.at)
3  Copyright (C) 2000 Nicolas Hadacek (haadcek@kde.org)
4  Copyright (C) 2001,2002 Ellis Whitehead (ellis@kde.org)
5 
6  This library is free software; you can redistribute it and/or
7  modify it under the terms of the GNU Library General Public
8  License version 2 as published by the Free Software Foundation.
9 
10  This library is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Library General Public License for more details.
14 
15  You should have received a copy of the GNU Library General Public License
16  along with this library; see the file COPYING.LIB. If not, write to
17  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18  Boston, MA 02110-1301, USA.
19 */
20 #define __KSTDACCEL_CPP_ 1
21 
22 #include "tdestdaccel.h"
23 
24 #include "tdeaccelaction.h"
25 #include "tdeaccelbase.h"
26 #include <tdeconfig.h>
27 #include <kdebug.h>
28 #include <tdeglobal.h>
29 #include <tdelocale.h>
30 #include <tdeshortcut.h>
31 #include <tdeshortcutlist.h>
32 
33 namespace TDEStdAccel
34 {
35 
36 struct TDEStdAccelInfo
37 {
38  StdAccel id;
39  const char* psName;
40  const char* psDesc;
41  int cutDefault, cutDefault4, cutDefault3B, cutDefault4B;
42  TDEShortcut cut;
43  bool bInitialized;
44 };
45 
50 static TDEStdAccelInfo g_infoStdAccel[] =
51 {
52  {AccelNone, "Group:File", I18N_NOOP("File"), 0, 0, 0, 0, TDEShortcut(), false },
53  { Open, I18N_NOOP("Open"), 0, Qt::CTRL+Qt::Key_O, 0, 0, 0, TDEShortcut(), false },
54  { New, I18N_NOOP("New"), 0, Qt::CTRL+Qt::Key_N, 0, 0, 0, TDEShortcut(), false },
55  { Close, I18N_NOOP("Close"), 0, Qt::CTRL+Qt::Key_W, Qt::CTRL+Qt::Key_Escape, 0, Qt::CTRL+Qt::Key_W, TDEShortcut(), false },
56  { Save, I18N_NOOP("Save"), 0, Qt::CTRL+Qt::Key_S, 0, 0, 0, TDEShortcut(), false },
57  { Print, I18N_NOOP("Print"), 0, Qt::CTRL+Qt::Key_P, 0, 0, 0, TDEShortcut(), false },
58  { Quit, I18N_NOOP("Quit"), 0, Qt::CTRL+Qt::Key_Q, 0, 0, 0, TDEShortcut(), false },
59  {AccelNone, "Group:Edit", I18N_NOOP("Edit"), 0, 0, 0, 0, TDEShortcut(), false },
60  { Undo, I18N_NOOP("Undo"), 0, Qt::CTRL+Qt::Key_Z, 0, 0, 0, TDEShortcut(), false },
61  { Redo, I18N_NOOP("Redo"), 0, Qt::CTRL+Qt::SHIFT+Qt::Key_Z, 0, 0, 0, TDEShortcut(), false },
62  { Cut, I18N_NOOP("Cut"), 0, Qt::CTRL+Qt::Key_X, 0, Qt::SHIFT+Qt::Key_Delete, 0, TDEShortcut(), false },
63  { Copy, I18N_NOOP("Copy"), 0, Qt::CTRL+Qt::Key_C, 0, Qt::CTRL+Qt::Key_Insert, 0, TDEShortcut(), false },
64  { Paste, I18N_NOOP("Paste"), 0, Qt::CTRL+Qt::Key_V, 0, Qt::SHIFT+Qt::Key_Insert, 0, TDEShortcut(), false },
65  { PasteSelection, I18N_NOOP("Paste Selection"), 0, 0, 0, Qt::CTRL+Qt::SHIFT+Qt::Key_Insert, 0, TDEShortcut(), false },
66  { SelectAll, "SelectAll", I18N_NOOP("Select All"), Qt::CTRL+Qt::Key_A, 0, 0, 0, TDEShortcut(), false },
67  { Deselect, I18N_NOOP("Deselect"), 0, Qt::CTRL+Qt::SHIFT+Qt::Key_A, 0, 0, 0, TDEShortcut(), false },
68  { DeleteWordBack, "DeleteWordBack", I18N_NOOP("Delete Word Backwards"), Qt::CTRL+Qt::Key_Backspace, 0, 0, 0, TDEShortcut(), false },
69  { DeleteWordForward, "DeleteWordForward", I18N_NOOP("Delete Word Forward"), Qt::CTRL+Qt::Key_Delete, 0, 0, 0, TDEShortcut(), false },
70  { Find, I18N_NOOP("Find"), 0, Qt::CTRL+Qt::Key_F, 0, 0, 0, TDEShortcut(), false },
71  { FindNext, "FindNext", I18N_NOOP("Find Next"), Qt::Key_F3, 0, 0, 0, TDEShortcut(), false },
72  { FindPrev, "FindPrev", I18N_NOOP("Find Prev"), Qt::SHIFT+Qt::Key_F3, 0, 0, 0, TDEShortcut(), false },
73  { Replace, I18N_NOOP("Replace"), 0, Qt::CTRL+Qt::Key_R, 0, 0, 0, TDEShortcut(), false },
74  {AccelNone, "Group:Navigation", I18N_NOOP("Navigation"), 0, 0, 0, 0, TDEShortcut(), false },
75  { Home, I18N_NOOP2("Opposite to End","Home"), 0, Qt::CTRL+Qt::Key_Home, 0, Qt::Key_HomePage, 0, TDEShortcut(), false },
76  { End, I18N_NOOP("End"), 0, Qt::CTRL+Qt::Key_End, 0, 0, 0, TDEShortcut(), false },
77  { BeginningOfLine, "BeginningOfLine", I18N_NOOP("Beginning of Line"), Qt::Key_Home, 0, 0, 0, TDEShortcut(), false},
78  { EndOfLine, "EndOfLine", I18N_NOOP("End of Line"), Qt::Key_End, 0, 0, 0, TDEShortcut(), false},
79  { Prior, I18N_NOOP("Prior"), 0, TQt::Key_Prior, 0, 0, 0, TDEShortcut(), false },
80  { Next, I18N_NOOP2("Opposite to Prior","Next"), 0, TQt::Key_Next, 0, 0, 0, TDEShortcut(), false },
81  { GotoLine, "GotoLine", I18N_NOOP("Go to Line"), Qt::CTRL+Qt::Key_G, 0, 0, 0, TDEShortcut(), false },
82  { AddBookmark, "AddBookmark", I18N_NOOP("Add Bookmark"), Qt::CTRL+Qt::Key_B, 0, 0, 0, TDEShortcut(), false },
83  { ZoomIn, "ZoomIn", I18N_NOOP("Zoom In"), Qt::CTRL+Qt::Key_Plus, 0, 0, 0, TDEShortcut(), false },
84  { ZoomOut, "ZoomOut", I18N_NOOP("Zoom Out"), Qt::CTRL+Qt::Key_Minus, 0, 0, 0, TDEShortcut(), false },
85  { Up, I18N_NOOP("Up"), 0, Qt::ALT+Qt::Key_Up, 0, 0, 0, TDEShortcut(), false },
86  { Back, I18N_NOOP("Back"), 0, Qt::ALT+Qt::Key_Left, 0, Qt::Key_Back, 0, TDEShortcut(), false },
87  { Forward, I18N_NOOP("Forward"), 0, Qt::ALT+Qt::Key_Right, 0, Qt::Key_Forward, 0, TDEShortcut(), false },
88  { Reload, I18N_NOOP("Reload"), 0, Qt::Key_F5, 0, Qt::Key_Refresh, 0, TDEShortcut(), false },
89  { PopupMenuContext, "PopupMenuContext", I18N_NOOP("Popup Menu Context"), Qt::Key_Menu, 0, 0, 0, TDEShortcut(), false },
90  { ShowMenubar, "ShowMenubar", I18N_NOOP("Show Menu Bar"), Qt::CTRL+Qt::Key_M, 0, 0, 0, TDEShortcut(), false },
91  { BackwardWord, "BackwardWord", I18N_NOOP("Backward Word"), Qt::CTRL+Qt::Key_Left, 0, 0, 0, TDEShortcut(), false },
92  { ForwardWord, "ForwardWord", I18N_NOOP("Forward Word"), Qt::CTRL+Qt::Key_Right, 0, 0, 0, TDEShortcut(), false },
93  { TabNext, I18N_NOOP("Activate Next Tab"), 0, Qt::CTRL+Qt::Key_Period, 0, Qt::CTRL+Qt::Key_BracketRight, 0, TDEShortcut(), false },
94  { TabPrev, I18N_NOOP("Activate Previous Tab"), 0, Qt::CTRL+Qt::Key_Comma, 0, Qt::CTRL+Qt::Key_BracketLeft, 0, TDEShortcut(), false },
95  { FullScreen, "FullScreen", I18N_NOOP("Full Screen Mode"), Qt::CTRL+Qt::SHIFT+Qt::Key_F, 0, 0, 0, TDEShortcut(), false },
96  {AccelNone, "Group:Help", I18N_NOOP("Help"), 0, 0, 0, 0, TDEShortcut(), false },
97  { Help, I18N_NOOP("Help"), 0, Qt::Key_F1, 0, 0, 0, TDEShortcut(), false },
98  { WhatsThis, "WhatsThis", I18N_NOOP("What's This"), Qt::SHIFT+Qt::Key_F1, 0, 0, 0, TDEShortcut(), false },
99  {AccelNone, "Group:TextCompletion", I18N_NOOP("Text Completion"), 0, 0, 0, 0, TDEShortcut(), false },
100  { TextCompletion, "TextCompletion", I18N_NOOP("Text Completion"), Qt::CTRL+Qt::Key_E, 0, 0, 0, TDEShortcut(), false },
101  { PrevCompletion, "PrevCompletion", I18N_NOOP("Previous Completion Match"), Qt::CTRL+Qt::Key_Up, 0, 0, 0, TDEShortcut(), false },
102  { NextCompletion, "NextCompletion", I18N_NOOP("Next Completion Match"), Qt::CTRL+Qt::Key_Down, 0, 0, 0, TDEShortcut(), false },
103  { SubstringCompletion, "SubstringCompletion", I18N_NOOP("Substring Completion"), Qt::CTRL+Qt::Key_T, 0, 0, 0, TDEShortcut(), false },
104  { RotateUp, "RotateUp", I18N_NOOP("Previous Item in List"), Qt::Key_Up, 0, 0, 0, TDEShortcut(), false },
105  { RotateDown, "RotateDown", I18N_NOOP("Next Item in List"), Qt::Key_Down, 0, 0, 0, TDEShortcut(), false },
106  { AccelNone, 0, 0, 0, 0, 0, 0, TDEShortcut(), false }
107 };
108 
110 static TDEStdAccelInfo* infoPtr( StdAccel id )
111 {
112  if( id != AccelNone ) {
113  // Linear search. Changing the data structure doesn't seem possible
114  // (since we need groups for the config stuff), but maybe a little
115  // additional hashtable wouldn't hurt.
116  for( uint i = 0; g_infoStdAccel[i].psName != 0; i++ ) {
117  if( g_infoStdAccel[i].id == id )
118  return &g_infoStdAccel[i];
119  }
120  }
121  return 0;
122 }
123 
127 static void initialize( StdAccel id )
128 {
129  TDEConfigGroupSaver saver( TDEGlobal::config(), "Shortcuts" );
130  TDEStdAccelInfo* pInfo = infoPtr( id );
131 
132  if( !pInfo ) {
133  kdWarning(125) << "TDEStdAccel: id not found!" << endl; // -- ellis
134  return;
135  }
136 
137  if( saver.config()->hasKey( pInfo->psName ) ) {
138  TQString s = saver.config()->readEntry( pInfo->psName );
139  if( s != "none" )
140  pInfo->cut.init( s );
141  else
142  pInfo->cut.clear();
143  } else
144  pInfo->cut = shortcutDefault( id );
145  pInfo->bInitialized = true;
146 }
147 
148 TQString name( StdAccel id )
149 {
150  TDEStdAccelInfo* pInfo = infoPtr( id );
151  if( !pInfo )
152  return TQString::null;
153  return pInfo->psName;
154 }
155 
156 TQString label( StdAccel id )
157 {
158  TDEStdAccelInfo* pInfo = infoPtr( id );
159  if( !pInfo )
160  return TQString::null;
161  return i18n((pInfo->psDesc) ? pInfo->psDesc : pInfo->psName);
162 }
163 
164 // TODO: Add psWhatsThis entry to TDEStdAccelInfo
165 TQString whatsThis( StdAccel /*id*/ )
166 {
167 // TDEStdAccelInfo* pInfo = infoPtr( id );
168 // if( pInfo && pInfo->psWhatsThis )
169 // return i18n(pInfo->psWhatsThis);
170 // else
171  return TQString::null;
172 }
173 
174 const TDEShortcut& shortcut( StdAccel id )
175 {
176  TDEStdAccelInfo* pInfo = infoPtr( id );
177  if( !pInfo )
178  return TDEShortcut::null();
179 
180  if( !pInfo->bInitialized )
181  initialize( id );
182 
183  return pInfo->cut;
184 }
185 
186 StdAccel findStdAccel( const KKeySequence& seq )
187 {
188  if( !seq.isNull() ) {
189  for( uint i = 0; g_infoStdAccel[i].psName != 0; i++ ) {
190  StdAccel id = g_infoStdAccel[i].id;
191  if( id != AccelNone ) {
192  if( !g_infoStdAccel[i].bInitialized )
193  initialize( id );
194  if( g_infoStdAccel[i].cut.contains( seq ) )
195  return id;
196  }
197  }
198  }
199  return AccelNone;
200 }
201 
202 TDEShortcut shortcutDefault( StdAccel id )
203 {
204  return (TDEAccelAction::useFourModifierKeys())
205  ? shortcutDefault4(id) : shortcutDefault3(id);
206 }
207 
208 TDEShortcut shortcutDefault3( StdAccel id )
209 {
210  TDEShortcut cut;
211 
212  TDEStdAccelInfo* pInfo = infoPtr( id );
213  if( pInfo ) {
214  if( pInfo->cutDefault )
215  cut.init( pInfo->cutDefault );
216  // FIXME: if there is no cutDefault, then this we be made the primary
217  // instead of alternate shortcut.
218  if( pInfo->cutDefault3B )
219  cut.append( KKey(pInfo->cutDefault3B) );
220  }
221 
222  return cut;
223 }
224 
225 TDEShortcut shortcutDefault4( StdAccel id )
226 {
227  TDEShortcut cut;
228 
229  TDEStdAccelInfo* pInfo = infoPtr( id );
230  if( pInfo ) {
231  TDEStdAccelInfo& info = *pInfo;
232  KKeySequence key2;
233 
234  cut.init( (info.cutDefault4) ?
235  TQKeySequence(info.cutDefault) : TQKeySequence(info.cutDefault4) );
236 
237  if( info.cutDefault4B )
238  key2.init( TQKeySequence(info.cutDefault4B) );
239  else if( info.cutDefault3B )
240  key2.init( TQKeySequence(info.cutDefault3B) );
241 
242  if( key2.count() )
243  cut.append( key2 );
244  }
245 
246  return cut;
247 }
248 
249 #if 0 // unused
250 void createAccelActions( TDEAccelActions& actions )
251 {
252  actions.clear();
253 
254  for( uint i = 0; g_infoStdAccel[i].psName != 0; i++ ) {
255  StdAccel id = g_infoStdAccel[i].id;
256  TDEStdAccelInfo* pInfo = &g_infoStdAccel[i];
257 
258  if( id != AccelNone ) {
259  actions.insert( pInfo->psName,
260  i18n((pInfo->psDesc) ? pInfo->psDesc : pInfo->psName),
261  TQString::null, // pInfo->psWhatsThis,
262  shortcutDefault3(id),
263  shortcutDefault4(id) );
264  } else
265  actions.insert( pInfo->psName, i18n(pInfo->psDesc) );
266  }
267 }
268 #endif
269 
270 const TDEShortcut& open() { return shortcut( Open ); }
271 const TDEShortcut& openNew() { return shortcut( New ); }
272 const TDEShortcut& close() { return shortcut( Close ); }
273 const TDEShortcut& save() { return shortcut( Save ); }
274 const TDEShortcut& print() { return shortcut( Print ); }
275 const TDEShortcut& quit() { return shortcut( Quit ); }
276 const TDEShortcut& cut() { return shortcut( Cut ); }
277 const TDEShortcut& copy() { return shortcut( Copy ); }
278 const TDEShortcut& paste() { return shortcut( Paste ); }
279 const TDEShortcut& pasteSelection() { return shortcut( PasteSelection ); }
280 const TDEShortcut& deleteWordBack() { return shortcut( DeleteWordBack ); }
281 const TDEShortcut& deleteWordForward() { return shortcut( DeleteWordForward ); }
282 const TDEShortcut& undo() { return shortcut( Undo ); }
283 const TDEShortcut& redo() { return shortcut( Redo ); }
284 const TDEShortcut& find() { return shortcut( Find ); }
285 const TDEShortcut& findNext() { return shortcut( FindNext ); }
286 const TDEShortcut& findPrev() { return shortcut( FindPrev ); }
287 const TDEShortcut& replace() { return shortcut( Replace ); }
288 const TDEShortcut& home() { return shortcut( Home ); }
289 const TDEShortcut& end() { return shortcut( End ); }
290 const TDEShortcut& beginningOfLine() { return shortcut( BeginningOfLine ); }
291 const TDEShortcut& endOfLine() { return shortcut( EndOfLine ); }
292 const TDEShortcut& prior() { return shortcut( Prior ); }
293 const TDEShortcut& next() { return shortcut( Next ); }
294 const TDEShortcut& backwardWord() { return shortcut( BackwardWord ); }
295 const TDEShortcut& forwardWord() { return shortcut( ForwardWord ); }
296 const TDEShortcut& gotoLine() { return shortcut( GotoLine ); }
297 const TDEShortcut& addBookmark() { return shortcut( AddBookmark ); }
298 const TDEShortcut& tabNext() { return shortcut( TabNext ); }
299 const TDEShortcut& tabPrev() { return shortcut( TabPrev ); }
300 const TDEShortcut& fullScreen() { return shortcut( FullScreen ); }
301 const TDEShortcut& zoomIn() { return shortcut( ZoomIn ); }
302 const TDEShortcut& zoomOut() { return shortcut( ZoomOut ); }
303 const TDEShortcut& help() { return shortcut( Help ); }
304 const TDEShortcut& completion() { return shortcut( TextCompletion ); }
305 const TDEShortcut& prevCompletion() { return shortcut( PrevCompletion ); }
306 const TDEShortcut& nextCompletion() { return shortcut( NextCompletion ); }
307 const TDEShortcut& rotateUp() { return shortcut( RotateUp ); }
308 const TDEShortcut& rotateDown() { return shortcut( RotateDown ); }
309 const TDEShortcut& substringCompletion() { return shortcut( SubstringCompletion ); }
310 const TDEShortcut& popupMenuContext() { return shortcut( PopupMenuContext ); }
311 const TDEShortcut& whatsThis() { return shortcut( WhatsThis ); }
312 const TDEShortcut& reload() { return shortcut( Reload ); }
313 const TDEShortcut& selectAll() { return shortcut( SelectAll ); }
314 const TDEShortcut& up() { return shortcut( Up ); }
315 const TDEShortcut& back() { return shortcut( Back ); }
316 const TDEShortcut& forward() { return shortcut( Forward ); }
317 const TDEShortcut& showMenubar() { return shortcut( ShowMenubar ); }
318 
319 //---------------------------------------------------------------------
320 // ShortcutList
321 //---------------------------------------------------------------------
322 
323 ShortcutList::ShortcutList()
324  { }
325 
326 ShortcutList::~ShortcutList()
327  { }
328 
329 uint ShortcutList::count() const
330 {
331  static uint g_nAccels = 0;
332  if( g_nAccels == 0 ) {
333  for( ; g_infoStdAccel[g_nAccels].psName != 0; g_nAccels++ )
334  ;
335  }
336  return g_nAccels;
337 }
338 
339 TQString ShortcutList::name( uint i ) const
340  { return g_infoStdAccel[i].psName; }
341 
342 TQString ShortcutList::label( uint i ) const
343  { return i18n((g_infoStdAccel[i].psDesc) ? g_infoStdAccel[i].psDesc : g_infoStdAccel[i].psName); }
344 
345 TQString ShortcutList::whatsThis( uint ) const
346  { return TQString::null; }
347 
348 const TDEShortcut& ShortcutList::shortcut( uint i ) const
349 {
350  if( !g_infoStdAccel[i].bInitialized )
351  initialize( g_infoStdAccel[i].id );
352  return g_infoStdAccel[i].cut;
353 }
354 
355 const TDEShortcut& ShortcutList::shortcutDefault( uint i ) const
356 {
357  static TDEShortcut cut;
358  cut = TDEStdAccel::shortcutDefault( g_infoStdAccel[i].id );
359  return cut;
360 }
361 
362 bool ShortcutList::isConfigurable( uint i ) const
363  { return (g_infoStdAccel[i].id != AccelNone); }
364 
365 bool ShortcutList::setShortcut( uint i, const TDEShortcut& cut )
366  { g_infoStdAccel[i].cut = cut; return true; }
367 
368 TQVariant ShortcutList::getOther( Other, uint ) const
369  { return TQVariant(); }
370 
371 bool ShortcutList::setOther( Other, uint, TQVariant )
372  { return false; }
373 
374 bool ShortcutList::save() const
375 {
376  return writeSettings( TQString::null, 0, false, true );
377 }
378 
379 TDECORE_EXPORT TQString action(StdAccel id)
380  { return name(id); }
381 TDECORE_EXPORT TQString description(StdAccel id)
382  { return label(id); }
383 TDECORE_EXPORT int key(StdAccel id)
384  { return shortcut(id).keyCodeQt(); }
385 TDECORE_EXPORT int defaultKey(StdAccel id)
386  { return shortcutDefault(id).keyCodeQt(); }
387 
388 TDECORE_EXPORT bool isEqual(const TQKeyEvent* ev, int keyQt)
389 {
390  KKey key1( ev ), key2( keyQt );
391  return key1 == key2;
392 }
393 
394 }
395 
396 #undef __KSTDACCEL_CPP_

tdecore

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

tdecore

Skip menu "tdecore"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  •     tdecore
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  • tdeioslave
  •   http
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdecore by doxygen 1.8.1.2
This website is maintained by Timothy Pearson.