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

tdecore

  • tdecore
tdeaccel.cpp
1 /*
2  Copyright (c) 2001,2002 Ellis Whitehead <ellis@kde.org>
3 
4  This library is free software; you can redistribute it and/or
5  modify it under the terms of the GNU Library General Public
6  License as published by the Free Software Foundation; either
7  version 2 of the License, or (at your option) any later version.
8 
9  This library 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 GNU
12  Library General Public License for more details.
13 
14  You should have received a copy of the GNU Library General Public License
15  along with this library; see the file COPYING.LIB. If not, write to
16  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  Boston, MA 02110-1301, USA.
18 */
19 
20 #include "tdeaccel.h"
21 
22 #include <tqaccel.h>
23 #include <tqguardedptr.h>
24 #include <tqpopupmenu.h>
25 #include <tqregexp.h>
26 #include <tqstring.h>
27 #include <tqtimer.h>
28 
29 #include "tdeaccelbase.h"
30 #include <tdeapplication.h>
31 #include <kdebug.h>
32 #include <tdelocale.h>
33 #include <tdeshortcut.h>
34 
35 #include "tdeaccelprivate.h"
36 
37 #ifdef TQ_WS_X11
38 # include <X11/Xlib.h>
39 # ifdef KeyPress // needed for --enable-final
40  // defined by X11 headers
41  const int XKeyPress = KeyPress;
42 # undef KeyPress
43 # endif
44 #endif
45 
46 // TODO: Put in tdeaccelbase.cpp
47 //---------------------------------------------------------------------
48 // TDEAccelEventHandler
49 //---------------------------------------------------------------------
50 //
51 // In TDEAccelEventHandler::x11Event we do our own X11 keyboard event handling
52 // This allows us to map the Win key to TQt::MetaButton, Qt does not know about
53 // the Win key.
54 //
55 // TDEAccelEventHandler::x11Event will generate an AccelOverride event. The
56 // AccelOverride event is abused a bit to ensure that TDEAccelPrivate::eventFilter
57 // (as an event filter on the toplevel widget) will get the key event first
58 // (in the form of AccelOverride) before any of the intermediate widgets are
59 // able to process it.
60 //
61 // Qt normally sends an AccelOverride, Accel and then a KeyPress event.
62 // A widget can accept the AccelOverride event in which case the Accel event will be
63 // skipped and the KeyPress is followed immediately.
64 // If the Accel event is accepted, no KeyPress event will follow.
65 //
66 // TDEAccelEventHandler::x11Event converts a X11 keyboard event into an AccelOverride
67 // event, there are now two possibilities:
68 //
69 // 1) If TDEAccel intercepts the AccelOverride we are done and can consider the X11
70 // keyboard event as handled.
71 // 2) If another widget accepts the AccelOverride, it will expect to get a normal
72 // Qt generated KeyPress event afterwards. So we let Qt handle the X11 keyboard event
73 // again. However, this will first generate an AccelOverride event, and we already
74 // had send that one. To compnesate for this, the global event filter in TDEApplication
75 // is instructed to eat the next AccelOveride event. Qt will then send a normal KeyPress
76 // event and from then on everything is normal again.
77 //
78 // kde_g_bKillAccelOverride is used to tell TDEApplication::notify to eat the next
79 // AccelOverride event.
80 
81 bool kde_g_bKillAccelOverride = false;
82 
83 class TDEAccelEventHandler : public TQWidget
84 {
85  public:
86  static TDEAccelEventHandler* self()
87  {
88  if( !g_pSelf )
89  g_pSelf = new TDEAccelEventHandler;
90  return g_pSelf;
91  }
92 
93  static void accelActivated( bool b ) { g_bAccelActivated = b; }
94 
95  private:
96  TDEAccelEventHandler();
97 
98 # ifdef TQ_WS_X11
99  bool x11Event( XEvent* pEvent );
100 # endif
101 
102  static TDEAccelEventHandler* g_pSelf;
103  static bool g_bAccelActivated;
104 };
105 
106 TDEAccelEventHandler* TDEAccelEventHandler::g_pSelf = 0;
107 bool TDEAccelEventHandler::g_bAccelActivated = false;
108 
109 TDEAccelEventHandler::TDEAccelEventHandler()
110  : TQWidget( 0, "TDEAccelEventHandler" )
111 {
112 # ifdef TQ_WS_X11
113  if ( kapp )
114  kapp->installX11EventFilter( this );
115 # endif
116 }
117 
118 #ifdef TQ_WS_X11
119 bool tqt_try_modal( TQWidget *, XEvent * );
120 
121 bool TDEAccelEventHandler::x11Event( XEvent* pEvent )
122 {
123  if( TQWidget::keyboardGrabber() || !kapp->focusWidget() )
124  return false;
125 
126  if ( !tqt_try_modal(kapp->focusWidget(), pEvent) )
127  return false;
128 
129  if( pEvent->type == XKeyPress ) {
130  unsigned int tmp = pEvent->xkey.state;
131  pEvent->xkey.state &= ~0x2000;
132  KKeyNative keyNative( pEvent );
133  pEvent->xkey.state = tmp;
134  KKey key( keyNative );
135  key.simplify();
136  int keyCodeQt = key.keyCodeQt();
137  int state = 0;
138  if( key.modFlags() & KKey::SHIFT ) state |= TQt::ShiftButton;
139  if( key.modFlags() & KKey::CTRL ) state |= TQt::ControlButton;
140  if( key.modFlags() & KKey::ALT ) state |= TQt::AltButton;
141  if( key.modFlags() & KKey::WIN ) state |= TQt::MetaButton;
142 
143  TQKeyEvent ke( TQEvent::AccelOverride, keyCodeQt, 0, state );
144  ke.ignore();
145 
146  g_bAccelActivated = false;
147  kapp->sendEvent( kapp->focusWidget(), &ke );
148 
149  // If the Override event was accepted from a non-TDEAccel widget,
150  // then kill the next AccelOverride in TDEApplication::notify.
151  if( ke.isAccepted() && !g_bAccelActivated )
152  kde_g_bKillAccelOverride = true;
153 
154  // Stop event processing if a KDE accelerator was activated.
155  return g_bAccelActivated;
156  }
157 
158  return false;
159 }
160 #endif // TQ_WS_X11
161 
162 //---------------------------------------------------------------------
163 // TDEAccelPrivate
164 //---------------------------------------------------------------------
165 
166 TDEAccelPrivate::TDEAccelPrivate( TDEAccel* pParent, TQWidget* pWatch )
167 : TDEAccelBase( TDEAccelBase::QT_KEYS )
168 {
169  //kdDebug(125) << "TDEAccelPrivate::TDEAccelPrivate( pParent = " << pParent << " ): this = " << this << endl;
170  m_pAccel = pParent;
171  m_pWatch = pWatch;
172  m_bAutoUpdate = true;
173  connect( (TQAccel*)m_pAccel, TQ_SIGNAL(activated(int)), this, TQ_SLOT(slotKeyPressed(int)) );
174 
175 #ifdef TQ_WS_X11 //only makes sense if TDEAccelEventHandler is working
176  if( m_pWatch )
177  m_pWatch->installEventFilter( this );
178 #endif
179  TDEAccelEventHandler::self();
180 }
181 
182 void TDEAccelPrivate::setEnabled( bool bEnabled )
183 {
184  m_bEnabled = bEnabled;
185  ((TQAccel*)m_pAccel)->setEnabled( bEnabled );
186 }
187 
188 bool TDEAccelPrivate::setEnabled( const TQString& sAction, bool bEnable )
189 {
190  kdDebug(125) << "TDEAccelPrivate::setEnabled( \"" << sAction << "\", " << bEnable << " ): this = " << this << endl;
191  TDEAccelAction* pAction = actionPtr( sAction );
192  if( !pAction )
193  return false;
194  if( pAction->isEnabled() == bEnable )
195  return true;
196 
197  pAction->setEnabled( bEnable );
198 
199  TQMap<int, TDEAccelAction*>::const_iterator it = m_mapIDToAction.begin();
200  for( ; it != m_mapIDToAction.end(); ++it ) {
201  if( *it == pAction )
202  ((TQAccel*)m_pAccel)->setItemEnabled( it.key(), bEnable );
203  }
204  return true;
205 }
206 
207 bool TDEAccelPrivate::removeAction( const TQString& sAction )
208 {
209  // FIXME: getID() doesn't contains any useful
210  // information! Use mapIDToAction. --ellis, 2/May/2002
211  // Or maybe TDEAccelBase::remove() takes care of TQAccel indirectly...
212  TDEAccelAction* pAction = actions().actionPtr( sAction );
213  if( pAction ) {
214  int nID = pAction->getID();
215  //bool b = actions().removeAction( sAction );
216  bool b = TDEAccelBase::remove( sAction );
217  ((TQAccel*)m_pAccel)->removeItem( nID );
218  return b;
219  } else
220  return false;
221 }
222 
223 bool TDEAccelPrivate::emitSignal( TDEAccelBase::Signal signal )
224 {
225  if( signal == TDEAccelBase::KEYCODE_CHANGED ) {
226  m_pAccel->emitKeycodeChanged();
227  return true;
228  }
229  return false;
230 }
231 
232 bool TDEAccelPrivate::connectKey( TDEAccelAction& action, const KKeyServer::Key& key )
233 {
234  uint keyQt = key.keyCodeQt();
235  int nID = ((TQAccel*)m_pAccel)->insertItem( keyQt );
236  m_mapIDToAction[nID] = &action;
237  m_mapIDToKey[nID] = keyQt;
238 
239  if( action.objSlotPtr() && action.methodSlotPtr() ) {
240 #ifdef TQ_WS_WIN
241  ((TQAccel*)m_pAccel)->connectItem( nID, action.objSlotPtr(), action.methodSlotPtr() );
242 #else
243  ((TQAccel*)m_pAccel)->connectItem( nID, this, TQ_SLOT(slotKeyPressed(int)));
244 #endif
245  if( !action.isEnabled() )
246  ((TQAccel*)m_pAccel)->setItemEnabled( nID, false );
247  }
248 
249  kdDebug(125) << "TDEAccelPrivate::connectKey( \"" << action.name() << "\", " << key.key().toStringInternal() << " = 0x" << TQString::number(keyQt,16) << " ): id = " << nID << " m_pObjSlot = " << action.objSlotPtr() << endl;
250  //kdDebug(125) << "m_pAccel = " << m_pAccel << endl;
251  return nID != 0;
252 }
253 
254 bool TDEAccelPrivate::connectKey( const KKeyServer::Key& key )
255 {
256  uint keyQt = key.keyCodeQt();
257  int nID = ((TQAccel*)m_pAccel)->insertItem( keyQt );
258 
259  m_mapIDToKey[nID] = keyQt;
260 
261  kdDebug(125) << "TDEAccelPrivate::connectKey( " << key.key().toStringInternal() << " = 0x" << TQString::number(keyQt,16) << " ): id = " << nID << endl;
262  return nID != 0;
263 }
264 
265 bool TDEAccelPrivate::disconnectKey( TDEAccelAction& action, const KKeyServer::Key& key )
266 {
267  int keyQt = key.keyCodeQt();
268  TQMap<int, int>::iterator it = m_mapIDToKey.begin();
269  for( ; it != m_mapIDToKey.end(); ++it ) {
270  //kdDebug(125) << "m_mapIDToKey[" << it.key() << "] = " << TQString::number(*it,16) << " == " << TQString::number(keyQt,16) << endl;
271  if( *it == keyQt ) {
272  int nID = it.key();
273  kdDebug(125) << "TDEAccelPrivate::disconnectKey( \"" << action.name() << "\", 0x" << TQString::number(keyQt,16) << " ) : id = " << nID << " m_pObjSlot = " << action.objSlotPtr() << endl;
274  ((TQAccel*)m_pAccel)->removeItem( nID );
275  m_mapIDToAction.remove( nID );
276  m_mapIDToKey.remove( it );
277  return true;
278  }
279  }
280  //kdWarning(125) << kdBacktrace() << endl;
281  kdWarning(125) << "Didn't find key in m_mapIDToKey." << endl;
282  return false;
283 }
284 
285 bool TDEAccelPrivate::disconnectKey( const KKeyServer::Key& key )
286 {
287  int keyQt = key.keyCodeQt();
288  kdDebug(125) << "TDEAccelPrivate::disconnectKey( 0x" << TQString::number(keyQt,16) << " )" << endl;
289  TQMap<int, int>::iterator it = m_mapIDToKey.begin();
290  for( ; it != m_mapIDToKey.end(); ++it ) {
291  if( *it == keyQt ) {
292  ((TQAccel*)m_pAccel)->removeItem( it.key() );
293  m_mapIDToKey.remove( it );
294  return true;
295  }
296  }
297  //kdWarning(125) << kdBacktrace() << endl;
298  kdWarning(125) << "Didn't find key in m_mapIDTokey." << endl;
299  return false;
300 }
301 
302 void TDEAccelPrivate::slotKeyPressed( int id )
303 {
304  kdDebug(125) << "TDEAccelPrivate::slotKeyPressed( " << id << " )" << endl;
305 
306  if( m_mapIDToKey.contains( id ) ) {
307  KKey key = m_mapIDToKey[id];
308  KKeySequence seq( key );
309  TQPopupMenu* pMenu = createPopupMenu( m_pWatch, seq );
310 
311  // If there was only one action mapped to this key,
312  // and that action is not a multi-key shortcut,
313  // then activated it without popping up the menu.
314  // This is needed for when there are multiple actions
315  // with the same shortcut where all but one is disabled.
316  // pMenu->count() also counts the menu title, so one shortcut will give count = 2.
317  if( pMenu->count() == 2 && pMenu->accel(1).isEmpty() ) {
318  int iAction = pMenu->idAt(1);
319  slotMenuActivated( iAction );
320  } else {
321  connect( pMenu, TQ_SIGNAL(activated(int)), this, TQ_SLOT(slotMenuActivated(int)) );
322  pMenu->exec( m_pWatch->mapToGlobal( TQPoint( 0, 0 ) ) );
323  disconnect( pMenu, TQ_SIGNAL(activated(int)), this, TQ_SLOT(slotMenuActivated(int)) );
324  }
325  delete pMenu;
326  }
327 }
328 
329 void TDEAccelPrivate::slotShowMenu()
330 {
331 }
332 
333 void TDEAccelPrivate::slotMenuActivated( int iAction )
334 {
335  kdDebug(125) << "TDEAccelPrivate::slotMenuActivated( " << iAction << " )" << endl;
336  TDEAccelAction* pAction = actions().actionPtr( iAction );
337 #ifdef TQ_WS_WIN
338  if( pAction ) {
339  connect( this, TQ_SIGNAL(menuItemActivated()), pAction->objSlotPtr(), pAction->methodSlotPtr() );
340  emit menuItemActivated();
341  disconnect( this, TQ_SIGNAL(menuItemActivated()), pAction->objSlotPtr(), pAction->methodSlotPtr() );
342  }
343 #else
344  emitActivatedSignal( pAction );
345 #endif
346 }
347 
348 bool TDEAccelPrivate::eventFilter( TQObject* /*pWatched*/, TQEvent* pEvent )
349 {
350  if( pEvent->type() == TQEvent::AccelOverride && m_bEnabled ) {
351  TQKeyEvent* pKeyEvent = (TQKeyEvent*) pEvent;
352  KKey key( pKeyEvent );
353  kdDebug(125) << "TDEAccelPrivate::eventFilter( AccelOverride ): this = " << this << ", key = " << key.toStringInternal() << endl;
354  int keyCodeQt = key.keyCodeQt();
355  TQMap<int, int>::iterator it = m_mapIDToKey.begin();
356  for( ; it != m_mapIDToKey.end(); ++it ) {
357  if( (*it) == keyCodeQt ) {
358  int nID = it.key();
359  kdDebug(125) << "shortcut found!" << endl;
360  if( m_mapIDToAction.contains( nID ) ) {
361  // TODO: reduce duplication between here and slotMenuActivated
362  TDEAccelAction* pAction = m_mapIDToAction[nID];
363  if( !pAction->isEnabled() )
364  continue;
365 #ifdef TQ_WS_WIN
366  TQGuardedPtr<TDEAccelPrivate> me = this;
367  connect( this, TQ_SIGNAL(menuItemActivated()), pAction->objSlotPtr(), pAction->methodSlotPtr() );
368  emit menuItemActivated();
369  if (me) {
370  disconnect( me, TQ_SIGNAL(menuItemActivated()), pAction->objSlotPtr(), pAction->methodSlotPtr() );
371  }
372 #else
373  emitActivatedSignal( pAction );
374 #endif
375  } else
376  slotKeyPressed( nID );
377 
378  pKeyEvent->accept();
379  TDEAccelEventHandler::accelActivated( true );
380  return true;
381  }
382  }
383  }
384  return false;
385 }
386 
387 #ifndef TQ_WS_WIN
388 void TDEAccelPrivate::emitActivatedSignal( TDEAccelAction* pAction )
389 {
390  if( pAction ) {
391  TQGuardedPtr<TDEAccelPrivate> me = this;
392  TQRegExp reg( "([ ]*TDEAccelAction.*)" );
393  if( reg.search( pAction->methodSlotPtr()) >= 0 ) {
394  connect( this, TQ_SIGNAL(menuItemActivated(TDEAccelAction*)),
395  pAction->objSlotPtr(), pAction->methodSlotPtr() );
396  emit menuItemActivated( pAction );
397  if (me)
398  disconnect( me, TQ_SIGNAL(menuItemActivated(TDEAccelAction*)),
399  pAction->objSlotPtr(), pAction->methodSlotPtr() );
400  } else {
401  connect( this, TQ_SIGNAL(menuItemActivated()),
402  pAction->objSlotPtr(), pAction->methodSlotPtr() );
403  emit menuItemActivated();
404  if (me)
405  disconnect( me, TQ_SIGNAL(menuItemActivated()),
406  pAction->objSlotPtr(), pAction->methodSlotPtr() );
407 
408  }
409  }
410 }
411 #endif
412 
413 //---------------------------------------------------------------------
414 // TDEAccel
415 //---------------------------------------------------------------------
416 
417 TDEAccel::TDEAccel( TQWidget* pParent, const char* psName )
418 : TQAccel( pParent, (psName) ? psName : "TDEAccel-TQAccel" )
419 {
420  kdDebug(125) << "TDEAccel( pParent = " << pParent << ", psName = " << psName << " ): this = " << this << endl;
421  d = new TDEAccelPrivate( this, pParent );
422 }
423 
424 TDEAccel::TDEAccel( TQWidget* watch, TQObject* pParent, const char* psName )
425 : TQAccel( watch, pParent, (psName) ? psName : "TDEAccel-TQAccel" )
426 {
427  kdDebug(125) << "TDEAccel( watch = " << watch << ", pParent = " << pParent << ", psName = " << psName << " ): this = " << this << endl;
428  if( !watch )
429  kdDebug(125) << kdBacktrace() << endl;
430  d = new TDEAccelPrivate( this, watch );
431 }
432 
433 TDEAccel::~TDEAccel()
434 {
435  kdDebug(125) << "~TDEAccel(): this = " << this << endl;
436  delete d;
437 }
438 
439 TDEAccelActions& TDEAccel::actions() { return d->actions(); }
440 const TDEAccelActions& TDEAccel::actions() const { return d->actions(); }
441 bool TDEAccel::isEnabled() { return d->isEnabled(); }
442 void TDEAccel::setEnabled( bool bEnabled ) { d->setEnabled( bEnabled ); }
443 bool TDEAccel::setAutoUpdate( bool bAuto ) { return d->setAutoUpdate( bAuto ); }
444 
445 TDEAccelAction* TDEAccel::insert( const TQString& sAction, const TQString& sLabel, const TQString& sWhatsThis,
446  const TDEShortcut& cutDef,
447  const TQObject* pObjSlot, const char* psMethodSlot,
448  bool bConfigurable, bool bEnabled )
449 {
450  return d->insert( sAction, sLabel, sWhatsThis,
451  cutDef, cutDef,
452  pObjSlot, psMethodSlot,
453  bConfigurable, bEnabled );
454 }
455 
456 TDEAccelAction* TDEAccel::insert( const TQString& sAction, const TQString& sLabel, const TQString& sWhatsThis,
457  const TDEShortcut& cutDef3, const TDEShortcut& cutDef4,
458  const TQObject* pObjSlot, const char* psMethodSlot,
459  bool bConfigurable, bool bEnabled )
460 {
461  return d->insert( sAction, sLabel, sWhatsThis,
462  cutDef3, cutDef4,
463  pObjSlot, psMethodSlot,
464  bConfigurable, bEnabled );
465 }
466 
467 TDEAccelAction* TDEAccel::insert( const char* psAction, const TDEShortcut& cutDef,
468  const TQObject* pObjSlot, const char* psMethodSlot,
469  bool bConfigurable, bool bEnabled )
470 {
471  return d->insert( psAction, i18n(psAction), TQString::null,
472  cutDef, cutDef,
473  pObjSlot, psMethodSlot,
474  bConfigurable, bEnabled );
475 }
476 
477 TDEAccelAction* TDEAccel::insert( TDEStdAccel::StdAccel id,
478  const TQObject* pObjSlot, const char* psMethodSlot,
479  bool bConfigurable, bool bEnabled )
480 {
481  TQString sAction = TDEStdAccel::name( id );
482  if( sAction.isEmpty() )
483  return 0;
484 
485  TDEAccelAction* pAction = d->insert( sAction, TDEStdAccel::label( id ), TDEStdAccel::whatsThis( id ),
486  TDEStdAccel::shortcutDefault3( id ), TDEStdAccel::shortcutDefault4( id ),
487  pObjSlot, psMethodSlot,
488  bConfigurable, bEnabled );
489  if( pAction )
490  pAction->setShortcut( TDEStdAccel::shortcut( id ) );
491 
492  return pAction;
493 }
494 
495 bool TDEAccel::remove( const TQString& sAction )
496  { return d->removeAction( sAction ); }
497 bool TDEAccel::updateConnections()
498  { return d->updateConnections(); }
499 
500 const TDEShortcut& TDEAccel::shortcut( const TQString& sAction ) const
501 {
502  const TDEAccelAction* pAction = actions().actionPtr( sAction );
503  return (pAction) ? pAction->shortcut() : TDEShortcut::null();
504 }
505 
506 bool TDEAccel::setSlot( const TQString& sAction, const TQObject* pObjSlot, const char* psMethodSlot )
507  { return d->setActionSlot( sAction, pObjSlot, psMethodSlot ); }
508 
509 bool TDEAccel::setEnabled( const TQString& sAction, bool bEnable )
510  { return d->setEnabled( sAction, bEnable ); }
511 
512 bool TDEAccel::setShortcut( const TQString& sAction, const TDEShortcut& cut )
513 {
514  kdDebug(125) << "TDEAccel::setShortcut( \"" << sAction << "\", " << cut.toStringInternal() << " )" << endl;
515  TDEAccelAction* pAction = actions().actionPtr( sAction );
516  if( pAction ) {
517  if( pAction->shortcut() != cut )
518  return d->setShortcut( sAction, cut );
519  return true;
520  }
521  return false;
522 }
523 
524 const TQString& TDEAccel::configGroup() const
525  { return d->configGroup(); }
526 // for tdegames/ksirtet
527 void TDEAccel::setConfigGroup( const TQString& s )
528  { d->setConfigGroup( s ); }
529 
530 bool TDEAccel::readSettings( TDEConfigBase* pConfig )
531 {
532  d->readSettings( pConfig );
533  return true;
534 }
535 
536 bool TDEAccel::writeSettings( TDEConfigBase* pConfig ) const
537  { d->writeSettings( pConfig ); return true; }
538 
539 void TDEAccel::emitKeycodeChanged()
540 {
541  kdDebug(125) << "TDEAccel::emitKeycodeChanged()" << endl;
542  emit keycodeChanged();
543 }
544 
545 #ifndef KDE_NO_COMPAT
546 //------------------------------------------------------------
547 // Obsolete methods -- for backward compatibility
548 //------------------------------------------------------------
549 
550 bool TDEAccel::insertItem( const TQString& sLabel, const TQString& sAction,
551  const char* cutsDef,
552  int /*nIDMenu*/, TQPopupMenu *, bool bConfigurable )
553 {
554  TDEShortcut cut( cutsDef );
555  bool b = d->insert( sAction, sLabel, TQString::null,
556  cut, cut,
557  0, 0,
558  bConfigurable ) != 0;
559  return b;
560 }
561 
562 bool TDEAccel::insertItem( const TQString& sLabel, const TQString& sAction,
563  int key,
564  int /*nIDMenu*/, TQPopupMenu*, bool bConfigurable )
565 {
566  TDEShortcut cut;
567  cut.init( TQKeySequence(key) );
568  TDEAccelAction* pAction = d->insert( sAction, sLabel, TQString::null,
569  cut, cut,
570  0, 0,
571  bConfigurable );
572  return pAction != 0;
573 }
574 
575 // Used in tdeutils/kjots
576 bool TDEAccel::insertStdItem( TDEStdAccel::StdAccel id, const TQString& sLabel )
577 {
578  TDEAccelAction* pAction = d->insert( TDEStdAccel::name( id ), sLabel, TQString::null,
579  TDEStdAccel::shortcutDefault3( id ), TDEStdAccel::shortcutDefault4( id ),
580  0, 0 );
581  if( pAction )
582  pAction->setShortcut( TDEStdAccel::shortcut( id ) );
583 
584  return true;
585 }
586 
587 bool TDEAccel::connectItem( const TQString& sAction, const TQObject* pObjSlot, const char* psMethodSlot, bool bActivate )
588 {
589  kdDebug(125) << "TDEAccel::connectItem( " << sAction << ", " << pObjSlot << ", " << psMethodSlot << " )" << endl;
590  if( bActivate == false )
591  d->setActionEnabled( sAction, false );
592  bool b = setSlot( sAction, pObjSlot, psMethodSlot );
593  if( bActivate == true )
594  d->setActionEnabled( sAction, true );
595  return b;
596 }
597 
598 bool TDEAccel::removeItem( const TQString& sAction )
599  { return d->removeAction( sAction ); }
600 
601 bool TDEAccel::setItemEnabled( const TQString& sAction, bool bEnable )
602  { return setEnabled( sAction, bEnable ); }
603 
604 void TDEAccel::changeMenuAccel( TQPopupMenu *menu, int id, const TQString& action )
605 {
606  TDEAccelAction* pAction = actions().actionPtr( action );
607  TQString s = menu->text( id );
608  if( !pAction || s.isEmpty() )
609  return;
610 
611  int i = s.find( '\t' );
612 
613  TQString k = pAction->shortcut().seq(0).toString();
614  if( k.isEmpty() )
615  return;
616 
617  if ( i >= 0 )
618  s.replace( i+1, s.length()-i, k );
619  else {
620  s += '\t';
621  s += k;
622  }
623 
624  TQPixmap *pp = menu->pixmap(id);
625  if( pp && !pp->isNull() )
626  menu->changeItem( *pp, s, id );
627  else
628  menu->changeItem( s, id );
629 }
630 
631 void TDEAccel::changeMenuAccel( TQPopupMenu *menu, int id, TDEStdAccel::StdAccel accel )
632 {
633  changeMenuAccel( menu, id, TDEStdAccel::name( accel ) );
634 }
635 
636 int TDEAccel::stringToKey( const TQString& sKey )
637 {
638  return KKey( sKey ).keyCodeQt();
639 }
640 
641 int TDEAccel::currentKey( const TQString& sAction ) const
642 {
643  TDEAccelAction* pAction = d->actionPtr( sAction );
644  if( pAction )
645  return pAction->shortcut().keyCodeQt();
646  return 0;
647 }
648 
649 TQString TDEAccel::findKey( int key ) const
650 {
651  TDEAccelAction* pAction = d->actionPtr( KKey(key) );
652  if( pAction )
653  return pAction->name();
654  else
655  return TQString::null;
656 }
657 #endif // !KDE_NO_COMPAT
658 
659 void TDEAccel::virtual_hook( int, void* )
660 { /*BASE::virtual_hook( id, data );*/ }
661 
662 #include "tdeaccel.moc"
663 #include "tdeaccelprivate.moc"
KKeyNative
Representation of a key in the format native of the windowing system (eg.
Definition: kkeynative.h:38
KKeySequence
A KKeySequence object holds a sequence of up to 4 keys.
Definition: tdeshortcut.h:289
KKey
A KKey object represents a single key with possible modifiers (Shift, Ctrl, Alt, Win).
Definition: tdeshortcut.h:41
KKey::keyCodeQt
int keyCodeQt() const
Returns the qt key code.
Definition: tdeshortcut.cpp:162
TDEAccel
Handle shortcuts.
Definition: tdeaccel.h:94
TDEAccel::keycodeChanged
void keycodeChanged()
Emitted when one of the key codes has changed.
TDEAccel::removeItem
bool removeItem(const TQString &sAction) TDE_DEPRECATED
Definition: tdeaccel.cpp:598
TDEAccel::configGroup
const TQString & configGroup() const
Returns the configuration group of the settings.
Definition: tdeaccel.cpp:524
TDEAccel::insertItem
bool insertItem(const TQString &sLabel, const TQString &sAction, const char *psKey, int nIDMenu=0, TQPopupMenu *pMenu=0, bool bConfigurable=true) TDE_DEPRECATED
Definition: tdeaccel.cpp:550
TDEAccel::connectItem
bool connectItem(const TQString &sAction, const TQObject *pObjSlot, const char *psMethodSlot, bool bActivate=true) TDE_DEPRECATED
Definition: tdeaccel.cpp:587
TDEAccel::insertStdItem
bool insertStdItem(TDEStdAccel::StdAccel id, const TQString &descr=TQString::null) TDE_DEPRECATED
Definition: tdeaccel.cpp:576
TDEAccel::readSettings
bool readSettings(TDEConfigBase *pConfig=0)
Read all shortcuts from pConfig, or (if pConfig is zero) from the application's configuration file TD...
Definition: tdeaccel.cpp:530
TDEAccel::emitKeycodeChanged
void emitKeycodeChanged()
Emits the keycodeChanged() signal.
Definition: tdeaccel.cpp:539
TDEAccel::updateConnections
bool updateConnections()
Updates the connections of the accelerations after changing them.
Definition: tdeaccel.cpp:497
TDEAccel::setAutoUpdate
bool setAutoUpdate(bool bAuto)
Enable auto-update of connections.
Definition: tdeaccel.cpp:443
TDEAccel::writeSettings
bool writeSettings(TDEConfigBase *pConfig=0) const
Write the current shortcuts to pConfig, or (if pConfig is zero) to the application's configuration fi...
Definition: tdeaccel.cpp:536
TDEAccel::setSlot
bool setSlot(const TQString &sAction, const TQObject *pObjSlot, const char *psMethodSlot)
Set the slot to be called when the shortcut of the action named by sAction is pressed.
Definition: tdeaccel.cpp:506
TDEAccel::setEnabled
void setEnabled(bool bEnabled)
Enables or disables the TDEAccel.
Definition: tdeaccel.cpp:442
TDEAccel::stringToKey
static int stringToKey(const TQString &) TDE_DEPRECATED
Definition: tdeaccel.cpp:636
TDEAccel::findKey
TQString findKey(int key) const TDE_DEPRECATED
Definition: tdeaccel.cpp:649
TDEAccel::remove
bool remove(const TQString &sAction)
Definition: tdeaccel.cpp:495
TDEAccel::setItemEnabled
bool setItemEnabled(const TQString &sAction, bool bEnable) TDE_DEPRECATED
Definition: tdeaccel.cpp:601
TDEAccel::shortcut
const TDEShortcut & shortcut(const TQString &sAction) const
Return the shortcut associated with the action named by sAction.
Definition: tdeaccel.cpp:500
TDEAccel::TDEAccel
TDEAccel(TQWidget *pParent, const char *psName=0)
Creates a new TDEAccel that watches pParent, which is also the TQObject's parent.
Definition: tdeaccel.cpp:417
TDEAccel::insert
TDEAccelAction * insert(const TQString &sAction, const TQString &sLabel, const TQString &sWhatsThis, const TDEShortcut &cutDef, const TQObject *pObjSlot, const char *psMethodSlot, bool bConfigurable=true, bool bEnabled=true)
Create an accelerator action.
Definition: tdeaccel.cpp:445
TDEAccel::setShortcut
bool setShortcut(const TQString &sAction, const TDEShortcut &shortcut)
Set the shortcut to be associated with the action named by sAction.
Definition: tdeaccel.cpp:512
TDEAccel::currentKey
int currentKey(const TQString &action) const TDE_DEPRECATED
Definition: tdeaccel.cpp:641
TDEAccel::isEnabled
bool isEnabled()
Checks whether the TDEAccel is active.
Definition: tdeaccel.cpp:441
TDEAccel::setConfigGroup
void setConfigGroup(const TQString &name)
Returns the configuration group of the settings.
Definition: tdeaccel.cpp:527
TDEAccel::changeMenuAccel
void changeMenuAccel(TQPopupMenu *menu, int id, const TQString &action) TDE_DEPRECATED
Definition: tdeaccel.cpp:604
TDEAction::isEnabled
virtual bool isEnabled() const
TDEConfigBase
KDE Configuration Management abstract base class.
Definition: tdeconfigbase.h:71
TDEShortcut
The TDEShortcut class is used to represent a keyboard shortcut to an action.
Definition: tdeshortcut.h:544
TDEShortcut::null
static TDEShortcut & null()
Returns a null shortcut.
Definition: tdeshortcut.cpp:667
endl
kndbgstream & endl(kndbgstream &s)
Does nothing.
Definition: kdebug.h:583
TDEGlobal::kdWarning
kdbgstream kdWarning(int area=0)
Returns a warning stream.
Definition: kdebug.cpp:376
TDEGlobal::kdDebug
kdbgstream kdDebug(int area=0)
Returns a debug stream.
Definition: kdebug.cpp:371
TDEGlobal::endl
kdbgstream & endl(kdbgstream &s)
Prints an "\n".
Definition: kdebug.h:430
KStdAction::action
TDEAction * action(StdAction act_enum, const TQObject *recvr, const char *slot, TDEActionCollection *parent, const char *name=0L)
TDEStdAccel::StdAccel
StdAccel
Defines the identifier of all standard accelerators.
Definition: tdestdaccel.h:47
TDEStdAccel::shortcutDefault3
TDEShortcut shortcutDefault3(StdAccel id)
Returns the hardcoded default 3 modifier shortcut for id.
Definition: tdestdaccel.cpp:208
TDEStdAccel::key
int key(StdAccel id)
Definition: tdestdaccel.cpp:383
TDEStdAccel::shortcutDefault4
TDEShortcut shortcutDefault4(StdAccel id)
Returns the hardcoded default 4 modifier shortcut for id.
Definition: tdestdaccel.cpp:225
TDEStdAccel::name
TQString name(StdAccel id)
Returns a unique name for the given accel.
Definition: tdestdaccel.cpp:148
TDEStdAccel::whatsThis
TQString whatsThis(StdAccel)
Returns an extended WhatsThis description for the given accelerator.
Definition: tdestdaccel.cpp:165
TDEStdAccel::label
TQString label(StdAccel id)
Returns a localized label for user-visible display.
Definition: tdestdaccel.cpp:156
TDEStdAccel::shortcut
const TDEShortcut & shortcut(StdAccel id)
Returns the keybinding for accel.
Definition: tdestdaccel.cpp:174
KKeyServer::Key
Represents a key press.
Definition: kkeyserver_x11.h:138
tdelocale.h

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
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdeioslave
  •   http
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdecore by doxygen 1.9.1
This website is maintained by Timothy Pearson.