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

tdecore

tdeaccel.cpp
00001 /*
00002     Copyright (c) 2001,2002 Ellis Whitehead <ellis@kde.org>
00003 
00004     This library is free software; you can redistribute it and/or
00005     modify it under the terms of the GNU Library General Public
00006     License as published by the Free Software Foundation; either
00007     version 2 of the License, or (at your option) any later version.
00008 
00009     This library is distributed in the hope that it will be useful,
00010     but WITHOUT ANY WARRANTY; without even the implied warranty of
00011     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012     Library General Public License for more details.
00013 
00014     You should have received a copy of the GNU Library General Public License
00015     along with this library; see the file COPYING.LIB.  If not, write to
00016     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00017     Boston, MA 02110-1301, USA.
00018 */
00019 
00020 #include "tdeaccel.h"
00021 
00022 #include <tqaccel.h>
00023 #include <tqguardedptr.h>
00024 #include <tqpopupmenu.h>
00025 #include <tqregexp.h>
00026 #include <tqstring.h>
00027 #include <tqtimer.h>
00028 
00029 #include "tdeaccelbase.h"
00030 #include <tdeapplication.h>
00031 #include <kdebug.h>
00032 #include <tdelocale.h>
00033 #include <tdeshortcut.h>
00034 
00035 #include "tdeaccelprivate.h"
00036 
00037 #ifdef Q_WS_X11
00038 #   include <X11/Xlib.h>
00039 #   ifdef KeyPress // needed for --enable-final
00040         // defined by X11 headers
00041         const int XKeyPress = KeyPress;
00042 #       undef KeyPress
00043 #   endif
00044 #endif
00045 
00046 // TODO: Put in tdeaccelbase.cpp
00047 //---------------------------------------------------------------------
00048 // TDEAccelEventHandler
00049 //---------------------------------------------------------------------
00050 //
00051 // In TDEAccelEventHandler::x11Event we do our own X11 keyboard event handling
00052 // This allows us to map the Win key to Qt::MetaButton, Qt does not know about
00053 // the Win key.
00054 //
00055 // TDEAccelEventHandler::x11Event will generate an AccelOverride event. The
00056 // AccelOverride event is abused a bit to ensure that TDEAccelPrivate::eventFilter
00057 // (as an event filter on the toplevel widget) will get the key event first
00058 // (in the form of AccelOverride) before any of the intermediate widgets are
00059 // able to process it.
00060 //
00061 // Qt normally sends an AccelOverride, Accel and then a KeyPress event.
00062 // A widget can accept the AccelOverride event in which case the Accel event will be
00063 // skipped and the KeyPress is followed immediately.
00064 // If the Accel event is accepted, no KeyPress event will follow.
00065 //
00066 // TDEAccelEventHandler::x11Event converts a X11 keyboard event into an AccelOverride
00067 // event, there are now two possibilities:
00068 //
00069 // 1) If TDEAccel intercepts the AccelOverride we are done and can consider the X11
00070 // keyboard event as handled.
00071 // 2) If another widget accepts the AccelOverride, it will expect to get a normal
00072 // Qt generated KeyPress event afterwards. So we let Qt handle the X11 keyboard event
00073 // again. However, this will first generate an AccelOverride event, and we already
00074 // had send that one. To compnesate for this, the global event filter in TDEApplication
00075 // is instructed to eat the next AccelOveride event. Qt will then send a normal KeyPress
00076 // event and from then on everything is normal again.
00077 //
00078 // kde_g_bKillAccelOverride is used to tell TDEApplication::notify to eat the next
00079 // AccelOverride event.
00080 
00081 bool kde_g_bKillAccelOverride = false;
00082 
00083 class TDEAccelEventHandler : public TQWidget
00084 {
00085  public:
00086     static TDEAccelEventHandler* self()
00087     {
00088         if( !g_pSelf )
00089             g_pSelf = new TDEAccelEventHandler;
00090         return g_pSelf;
00091     }
00092 
00093     static void accelActivated( bool b ) { g_bAccelActivated = b; }
00094 
00095  private:
00096     TDEAccelEventHandler();
00097 
00098 #   ifdef Q_WS_X11
00099     bool x11Event( XEvent* pEvent );
00100 #   endif
00101 
00102     static TDEAccelEventHandler* g_pSelf;
00103     static bool g_bAccelActivated;
00104 };
00105 
00106 TDEAccelEventHandler* TDEAccelEventHandler::g_pSelf = 0;
00107 bool TDEAccelEventHandler::g_bAccelActivated = false;
00108 
00109 TDEAccelEventHandler::TDEAccelEventHandler()
00110     : TQWidget( 0, "TDEAccelEventHandler" )
00111 {
00112 #   ifdef Q_WS_X11
00113     if ( kapp )
00114         kapp->installX11EventFilter( TQT_TQWIDGET(this) );
00115 #   endif
00116 }
00117 
00118 #ifdef Q_WS_X11
00119 bool    tqt_try_modal( TQWidget *, XEvent * );
00120 
00121 bool TDEAccelEventHandler::x11Event( XEvent* pEvent )
00122 {
00123     if( TQWidget::keyboardGrabber() || !kapp->focusWidget() )
00124         return false;
00125 
00126     if ( !tqt_try_modal(kapp->focusWidget(), pEvent) )
00127             return false;
00128 
00129     if( pEvent->type == XKeyPress ) {
00130         unsigned int tmp = pEvent->xkey.state;
00131         pEvent->xkey.state &= ~0x2000;
00132         KKeyNative keyNative( pEvent );
00133         pEvent->xkey.state = tmp;
00134         KKey key( keyNative );
00135         key.simplify();
00136         int keyCodeQt = key.keyCodeQt();
00137         int state = 0;
00138         if( key.modFlags() & KKey::SHIFT ) state |= TQt::ShiftButton;
00139         if( key.modFlags() & KKey::CTRL )  state |= TQt::ControlButton;
00140         if( key.modFlags() & KKey::ALT )   state |= TQt::AltButton;
00141         if( key.modFlags() & KKey::WIN )   state |= TQt::MetaButton;
00142 
00143         TQKeyEvent ke( TQEvent::AccelOverride, keyCodeQt, 0,  state );
00144         ke.ignore();
00145 
00146         g_bAccelActivated = false;
00147         kapp->sendEvent( kapp->focusWidget(), &ke );
00148 
00149         // If the Override event was accepted from a non-TDEAccel widget,
00150         //  then kill the next AccelOverride in TDEApplication::notify.
00151         if( ke.isAccepted() && !g_bAccelActivated )
00152             kde_g_bKillAccelOverride = true;
00153 
00154         // Stop event processing if a KDE accelerator was activated.
00155         return g_bAccelActivated;
00156     }
00157 
00158     return false;
00159 }
00160 #endif // Q_WS_X11
00161 
00162 //---------------------------------------------------------------------
00163 // TDEAccelPrivate
00164 //---------------------------------------------------------------------
00165 
00166 TDEAccelPrivate::TDEAccelPrivate( TDEAccel* pParent, TQWidget* pWatch )
00167 : TDEAccelBase( TDEAccelBase::QT_KEYS )
00168 {
00169     //kdDebug(125) << "TDEAccelPrivate::TDEAccelPrivate( pParent = " << pParent << " ): this = " << this << endl;
00170     m_pAccel = pParent;
00171     m_pWatch = pWatch;
00172     m_bAutoUpdate = true;
00173     connect( (TQAccel*)m_pAccel, TQT_SIGNAL(activated(int)), this, TQT_SLOT(slotKeyPressed(int)) );
00174 
00175 #ifdef Q_WS_X11 //only makes sense if TDEAccelEventHandler is working
00176     if( m_pWatch )
00177         m_pWatch->installEventFilter( this );
00178 #endif
00179     TDEAccelEventHandler::self();
00180 }
00181 
00182 void TDEAccelPrivate::setEnabled( bool bEnabled )
00183 {
00184     m_bEnabled = bEnabled;
00185     ((TQAccel*)m_pAccel)->setEnabled( bEnabled );
00186 }
00187 
00188 bool TDEAccelPrivate::setEnabled( const TQString& sAction, bool bEnable )
00189 {
00190     kdDebug(125) << "TDEAccelPrivate::setEnabled( \"" << sAction << "\", " << bEnable << " ): this = " << this << endl;
00191     TDEAccelAction* pAction = actionPtr( sAction );
00192     if( !pAction )
00193         return false;
00194     if( pAction->isEnabled() == bEnable )
00195         return true;
00196 
00197     pAction->setEnabled( bEnable );
00198 
00199     TQMap<int, TDEAccelAction*>::const_iterator it = m_mapIDToAction.begin();
00200     for( ; it != m_mapIDToAction.end(); ++it ) {
00201         if( *it == pAction )
00202             ((TQAccel*)m_pAccel)->setItemEnabled( it.key(), bEnable );
00203     }
00204     return true;
00205 }
00206 
00207 bool TDEAccelPrivate::removeAction( const TQString& sAction )
00208 {
00209     // FIXME: getID() doesn't contains any useful
00210     //  information!  Use mapIDToAction. --ellis, 2/May/2002
00211     //  Or maybe TDEAccelBase::remove() takes care of TQAccel indirectly...
00212     TDEAccelAction* pAction = actions().actionPtr( sAction );
00213     if( pAction ) {
00214         int nID = pAction->getID();
00215         //bool b = actions().removeAction( sAction );
00216         bool b = TDEAccelBase::remove( sAction );
00217         ((TQAccel*)m_pAccel)->removeItem( nID );
00218         return b;
00219     } else
00220         return false;
00221 }
00222 
00223 bool TDEAccelPrivate::emitSignal( TDEAccelBase::Signal signal )
00224 {
00225     if( signal == TDEAccelBase::KEYCODE_CHANGED ) {
00226         m_pAccel->emitKeycodeChanged();
00227         return true;
00228     }
00229     return false;
00230 }
00231 
00232 bool TDEAccelPrivate::connectKey( TDEAccelAction& action, const KKeyServer::Key& key )
00233 {
00234     uint keyQt = key.keyCodeQt();
00235     int nID = ((TQAccel*)m_pAccel)->insertItem( keyQt );
00236     m_mapIDToAction[nID] = &action;
00237     m_mapIDToKey[nID] = keyQt;
00238 
00239     if( action.objSlotPtr() && action.methodSlotPtr() ) {
00240 #ifdef Q_WS_WIN 
00241         ((TQAccel*)m_pAccel)->connectItem( nID, action.objSlotPtr(), action.methodSlotPtr() );
00242 #else
00243         ((TQAccel*)m_pAccel)->connectItem( nID, this, TQT_SLOT(slotKeyPressed(int)));
00244 #endif
00245         if( !action.isEnabled() )
00246             ((TQAccel*)m_pAccel)->setItemEnabled( nID, false );
00247     }
00248 
00249     kdDebug(125) << "TDEAccelPrivate::connectKey( \"" << action.name() << "\", " << key.key().toStringInternal() << " = 0x" << TQString::number(keyQt,16) << " ): id = " << nID << " m_pObjSlot = " << action.objSlotPtr() << endl;
00250     //kdDebug(125) << "m_pAccel = " << m_pAccel << endl;
00251     return nID != 0;
00252 }
00253 
00254 bool TDEAccelPrivate::connectKey( const KKeyServer::Key& key )
00255 {
00256     uint keyQt = key.keyCodeQt();
00257     int nID = ((TQAccel*)m_pAccel)->insertItem( keyQt );
00258 
00259     m_mapIDToKey[nID] = keyQt;
00260 
00261     kdDebug(125) << "TDEAccelPrivate::connectKey( " << key.key().toStringInternal() << " = 0x" << TQString::number(keyQt,16) << " ): id = " << nID << endl;
00262     return nID != 0;
00263 }
00264 
00265 bool TDEAccelPrivate::disconnectKey( TDEAccelAction& action, const KKeyServer::Key& key )
00266 {
00267     int keyQt = key.keyCodeQt();
00268     TQMap<int, int>::iterator it = m_mapIDToKey.begin();
00269     for( ; it != m_mapIDToKey.end(); ++it ) {
00270         //kdDebug(125) << "m_mapIDToKey[" << it.key() << "] = " << TQString::number(*it,16) << " == " << TQString::number(keyQt,16) << endl;
00271         if( *it == keyQt ) {
00272             int nID = it.key();
00273             kdDebug(125) << "TDEAccelPrivate::disconnectKey( \"" << action.name() << "\", 0x" << TQString::number(keyQt,16) << " ) : id = " << nID << " m_pObjSlot = " << action.objSlotPtr() << endl;
00274             ((TQAccel*)m_pAccel)->removeItem( nID );
00275             m_mapIDToAction.remove( nID );
00276             m_mapIDToKey.remove( it );
00277             return true;
00278         }
00279     }
00280     //kdWarning(125) << kdBacktrace() << endl;
00281     kdWarning(125) << "Didn't find key in m_mapIDToKey." << endl;
00282     return false;
00283 }
00284 
00285 bool TDEAccelPrivate::disconnectKey( const KKeyServer::Key& key )
00286 {
00287     int keyQt = key.keyCodeQt();
00288     kdDebug(125) << "TDEAccelPrivate::disconnectKey( 0x" << TQString::number(keyQt,16) << " )" << endl;
00289     TQMap<int, int>::iterator it = m_mapIDToKey.begin();
00290     for( ; it != m_mapIDToKey.end(); ++it ) {
00291         if( *it == keyQt ) {
00292             ((TQAccel*)m_pAccel)->removeItem( it.key() );
00293             m_mapIDToKey.remove( it );
00294             return true;
00295         }
00296     }
00297     //kdWarning(125) << kdBacktrace() << endl;
00298     kdWarning(125) << "Didn't find key in m_mapIDTokey." << endl;
00299     return false;
00300 }
00301 
00302 void TDEAccelPrivate::slotKeyPressed( int id )
00303 {
00304     kdDebug(125) << "TDEAccelPrivate::slotKeyPressed( " << id << " )" << endl;
00305 
00306     if( m_mapIDToKey.contains( id ) ) {
00307         KKey key = m_mapIDToKey[id];
00308         KKeySequence seq( key );
00309         TQPopupMenu* pMenu = createPopupMenu( m_pWatch, seq );
00310 
00311         // If there was only one action mapped to this key,
00312         //  and that action is not a multi-key shortcut,
00313         //  then activated it without popping up the menu.
00314         // This is needed for when there are multiple actions
00315         //  with the same shortcut where all but one is disabled.
00316         // pMenu->count() also counts the menu title, so one shortcut will give count = 2.
00317         if( pMenu->count() == 2 && pMenu->accel(1).isEmpty() ) {
00318             int iAction = pMenu->idAt(1);
00319             slotMenuActivated( iAction );
00320         } else {
00321             connect( pMenu, TQT_SIGNAL(activated(int)), this, TQT_SLOT(slotMenuActivated(int)) );
00322             pMenu->exec( m_pWatch->mapToGlobal( TQPoint( 0, 0 ) ) );
00323             disconnect( pMenu, TQT_SIGNAL(activated(int)), this, TQT_SLOT(slotMenuActivated(int)) );
00324         }
00325         delete pMenu;
00326     }
00327 }
00328 
00329 void TDEAccelPrivate::slotShowMenu()
00330 {
00331 }
00332 
00333 void TDEAccelPrivate::slotMenuActivated( int iAction )
00334 {
00335     kdDebug(125) << "TDEAccelPrivate::slotMenuActivated( " << iAction << " )" << endl;
00336     TDEAccelAction* pAction = actions().actionPtr( iAction );
00337 #ifdef Q_WS_WIN 
00338     if( pAction ) {
00339         connect( this, TQT_SIGNAL(menuItemActivated()), pAction->objSlotPtr(), pAction->methodSlotPtr() );
00340         emit menuItemActivated();
00341         disconnect( this, TQT_SIGNAL(menuItemActivated()), pAction->objSlotPtr(), pAction->methodSlotPtr() );
00342     }
00343 #else
00344     emitActivatedSignal( pAction );
00345 #endif
00346 }
00347 
00348 bool TDEAccelPrivate::eventFilter( TQObject* /*pWatched*/, TQEvent* pEvent )
00349 {
00350     if( pEvent->type() == TQEvent::AccelOverride && m_bEnabled ) {
00351         TQKeyEvent* pKeyEvent = (TQKeyEvent*) pEvent;
00352         KKey key( pKeyEvent );
00353         kdDebug(125) << "TDEAccelPrivate::eventFilter( AccelOverride ): this = " << this << ", key = " << key.toStringInternal() << endl;
00354         int keyCodeQt = key.keyCodeQt();
00355         TQMap<int, int>::iterator it = m_mapIDToKey.begin();
00356         for( ; it != m_mapIDToKey.end(); ++it ) {
00357             if( (*it) == keyCodeQt ) {
00358                 int nID = it.key();
00359                 kdDebug(125) << "shortcut found!" << endl;
00360                 if( m_mapIDToAction.contains( nID ) ) {
00361                     // TODO: reduce duplication between here and slotMenuActivated
00362                     TDEAccelAction* pAction = m_mapIDToAction[nID];
00363                     if( !pAction->isEnabled() )
00364                         continue;
00365 #ifdef Q_WS_WIN 
00366                     TQGuardedPtr<TDEAccelPrivate> me = this;
00367                     connect( this, TQT_SIGNAL(menuItemActivated()), pAction->objSlotPtr(), pAction->methodSlotPtr() );
00368                     emit menuItemActivated();
00369                     if (me) {
00370                         disconnect( me, TQT_SIGNAL(menuItemActivated()), pAction->objSlotPtr(), pAction->methodSlotPtr() );
00371                     }
00372 #else
00373                     emitActivatedSignal( pAction );
00374 #endif
00375                 } else
00376                     slotKeyPressed( nID );
00377 
00378                 pKeyEvent->accept();
00379                 TDEAccelEventHandler::accelActivated( true );
00380                 return true;
00381             }
00382         }
00383     }
00384     return false;
00385 }
00386 
00387 #ifndef Q_WS_WIN 
00388 void TDEAccelPrivate::emitActivatedSignal( TDEAccelAction* pAction )
00389 {
00390     if( pAction ) {
00391         TQGuardedPtr<TDEAccelPrivate> me = this;
00392         TQRegExp reg( "([ ]*TDEAccelAction.*)" );
00393         if( reg.search( pAction->methodSlotPtr()) >= 0 ) {
00394             connect( this, TQT_SIGNAL(menuItemActivated(TDEAccelAction*)),
00395                 pAction->objSlotPtr(), pAction->methodSlotPtr() );
00396             emit menuItemActivated( pAction );
00397             if (me)
00398                 disconnect( me, TQT_SIGNAL(menuItemActivated(TDEAccelAction*)),
00399                     pAction->objSlotPtr(), pAction->methodSlotPtr() );
00400         } else {
00401             connect( this, TQT_SIGNAL(menuItemActivated()),
00402                 pAction->objSlotPtr(), pAction->methodSlotPtr() );
00403             emit menuItemActivated();
00404             if (me)
00405                 disconnect( me, TQT_SIGNAL(menuItemActivated()),
00406                     pAction->objSlotPtr(), pAction->methodSlotPtr() );
00407 
00408         }
00409     }
00410 }
00411 #endif
00412 
00413 //---------------------------------------------------------------------
00414 // TDEAccel
00415 //---------------------------------------------------------------------
00416 
00417 TDEAccel::TDEAccel( TQWidget* pParent, const char* psName )
00418 : TQAccel( pParent, (psName) ? psName : "TDEAccel-TQAccel" )
00419 {
00420     kdDebug(125) << "TDEAccel( pParent = " << pParent << ", psName = " << psName << " ): this = " << this << endl;
00421     d = new TDEAccelPrivate( this, pParent );
00422 }
00423 
00424 TDEAccel::TDEAccel( TQWidget* watch, TQObject* pParent, const char* psName )
00425 : TQAccel( watch, pParent, (psName) ? psName : "TDEAccel-TQAccel" )
00426 {
00427     kdDebug(125) << "TDEAccel( watch = " << watch << ", pParent = " << pParent << ", psName = " << psName << " ): this = " << this << endl;
00428     if( !watch )
00429         kdDebug(125) << kdBacktrace() << endl;
00430     d = new TDEAccelPrivate( this, watch );
00431 }
00432 
00433 TDEAccel::~TDEAccel()
00434 {
00435     kdDebug(125) << "~TDEAccel(): this = " << this << endl;
00436     delete d;
00437 }
00438 
00439 TDEAccelActions& TDEAccel::actions()             { return d->actions(); }
00440 const TDEAccelActions& TDEAccel::actions() const { return d->actions(); }
00441 bool TDEAccel::isEnabled()                     { return d->isEnabled(); }
00442 void TDEAccel::setEnabled( bool bEnabled )     { d->setEnabled( bEnabled ); }
00443 bool TDEAccel::setAutoUpdate( bool bAuto )     { return d->setAutoUpdate( bAuto ); }
00444 
00445 TDEAccelAction* TDEAccel::insert( const TQString& sAction, const TQString& sLabel, const TQString& sWhatsThis,
00446         const TDEShortcut& cutDef,
00447         const TQObject* pObjSlot, const char* psMethodSlot,
00448         bool bConfigurable, bool bEnabled )
00449 {
00450     return d->insert( sAction, sLabel, sWhatsThis,
00451         cutDef, cutDef,
00452         pObjSlot, psMethodSlot,
00453         bConfigurable, bEnabled );
00454 }
00455 
00456 TDEAccelAction* TDEAccel::insert( const TQString& sAction, const TQString& sLabel, const TQString& sWhatsThis,
00457         const TDEShortcut& cutDef3, const TDEShortcut& cutDef4,
00458         const TQObject* pObjSlot, const char* psMethodSlot,
00459         bool bConfigurable, bool bEnabled )
00460 {
00461     return d->insert( sAction, sLabel, sWhatsThis,
00462         cutDef3, cutDef4,
00463         pObjSlot, psMethodSlot,
00464         bConfigurable, bEnabled );
00465 }
00466 
00467 TDEAccelAction* TDEAccel::insert( const char* psAction, const TDEShortcut& cutDef,
00468         const TQObject* pObjSlot, const char* psMethodSlot,
00469         bool bConfigurable, bool bEnabled )
00470 {
00471     return d->insert( psAction, i18n(psAction), TQString::null,
00472         cutDef, cutDef,
00473         pObjSlot, psMethodSlot,
00474         bConfigurable, bEnabled );
00475 }
00476 
00477 TDEAccelAction* TDEAccel::insert( TDEStdAccel::StdAccel id,
00478         const TQObject* pObjSlot, const char* psMethodSlot,
00479         bool bConfigurable, bool bEnabled )
00480 {
00481     TQString sAction = TDEStdAccel::name( id );
00482     if( sAction.isEmpty() )
00483         return 0;
00484 
00485     TDEAccelAction* pAction = d->insert( sAction, TDEStdAccel::label( id ), TDEStdAccel::whatsThis( id ),
00486         TDEStdAccel::shortcutDefault3( id ), TDEStdAccel::shortcutDefault4( id ),
00487         pObjSlot, psMethodSlot,
00488         bConfigurable, bEnabled );
00489     if( pAction )
00490         pAction->setShortcut( TDEStdAccel::shortcut( id ) );
00491 
00492     return pAction;
00493 }
00494 
00495 bool TDEAccel::remove( const TQString& sAction )
00496     { return d->removeAction( sAction ); }
00497 bool TDEAccel::updateConnections()
00498     { return d->updateConnections(); }
00499 
00500 const TDEShortcut& TDEAccel::shortcut( const TQString& sAction ) const
00501 {
00502     const TDEAccelAction* pAction = actions().actionPtr( sAction );
00503     return (pAction) ? pAction->shortcut() : TDEShortcut::null();
00504 }
00505 
00506 bool TDEAccel::setSlot( const TQString& sAction, const TQObject* pObjSlot, const char* psMethodSlot )
00507     { return d->setActionSlot( sAction, pObjSlot, psMethodSlot ); }
00508 
00509 bool TDEAccel::setEnabled( const TQString& sAction, bool bEnable )
00510     { return d->setEnabled( sAction, bEnable ); }
00511 
00512 bool TDEAccel::setShortcut( const TQString& sAction, const TDEShortcut& cut )
00513 {
00514     kdDebug(125) << "TDEAccel::setShortcut( \"" << sAction << "\", " << cut.toStringInternal() << " )" << endl;
00515     TDEAccelAction* pAction = actions().actionPtr( sAction );
00516     if( pAction ) {
00517         if( pAction->shortcut() != cut )
00518             return d->setShortcut( sAction, cut );
00519         return true;
00520     }
00521     return false;
00522 }
00523 
00524 const TQString& TDEAccel::configGroup() const
00525     { return d->configGroup(); }
00526 // for tdegames/ksirtet
00527 void TDEAccel::setConfigGroup( const TQString& s )
00528     { d->setConfigGroup( s ); }
00529 
00530 bool TDEAccel::readSettings( TDEConfigBase* pConfig )
00531 {
00532     d->readSettings( pConfig );
00533     return true;
00534 }
00535 
00536 bool TDEAccel::writeSettings( TDEConfigBase* pConfig ) const
00537     { d->writeSettings( pConfig ); return true; }
00538 
00539 void TDEAccel::emitKeycodeChanged()
00540 {
00541     kdDebug(125) << "TDEAccel::emitKeycodeChanged()" << endl;
00542     emit keycodeChanged();
00543 }
00544 
00545 #ifndef KDE_NO_COMPAT
00546 //------------------------------------------------------------
00547 // Obsolete methods -- for backward compatibility
00548 //------------------------------------------------------------
00549 
00550 bool TDEAccel::insertItem( const TQString& sLabel, const TQString& sAction,
00551         const char* cutsDef,
00552         int /*nIDMenu*/, TQPopupMenu *, bool bConfigurable )
00553 {
00554     TDEShortcut cut( cutsDef );
00555     bool b = d->insert( sAction, sLabel, TQString::null,
00556         cut, cut,
00557         0, 0,
00558         bConfigurable ) != 0;
00559     return b;
00560 }
00561 
00562 bool TDEAccel::insertItem( const TQString& sLabel, const TQString& sAction,
00563         int key,
00564         int /*nIDMenu*/, TQPopupMenu*, bool bConfigurable )
00565 {
00566     TDEShortcut cut;
00567     cut.init( TQKeySequence(key) );
00568     TDEAccelAction* pAction = d->insert( sAction, sLabel, TQString::null,
00569         cut, cut,
00570         0, 0,
00571         bConfigurable );
00572     return pAction != 0;
00573 }
00574 
00575 // Used in tdeutils/kjots
00576 bool TDEAccel::insertStdItem( TDEStdAccel::StdAccel id, const TQString& sLabel )
00577 {
00578     TDEAccelAction* pAction = d->insert( TDEStdAccel::name( id ), sLabel, TQString::null,
00579         TDEStdAccel::shortcutDefault3( id ), TDEStdAccel::shortcutDefault4( id ),
00580         0, 0 );
00581     if( pAction )
00582         pAction->setShortcut( TDEStdAccel::shortcut( id ) );
00583 
00584     return true;
00585 }
00586 
00587 bool TDEAccel::connectItem( const TQString& sAction, const TQObject* pObjSlot, const char* psMethodSlot, bool bActivate )
00588 {
00589     kdDebug(125) << "TDEAccel::connectItem( " << sAction << ", " << pObjSlot << ", " << psMethodSlot << " )" << endl;
00590     if( bActivate == false )
00591         d->setActionEnabled( sAction, false );
00592     bool b = setSlot( sAction, pObjSlot, psMethodSlot );
00593     if( bActivate == true )
00594         d->setActionEnabled( sAction, true );
00595     return b;
00596 }
00597 
00598 bool TDEAccel::removeItem( const TQString& sAction )
00599     { return d->removeAction( sAction ); }
00600 
00601 bool TDEAccel::setItemEnabled( const TQString& sAction, bool bEnable )
00602     { return setEnabled( sAction, bEnable ); }
00603 
00604 void TDEAccel::changeMenuAccel( TQPopupMenu *menu, int id, const TQString& action )
00605 {
00606     TDEAccelAction* pAction = actions().actionPtr( action );
00607     TQString s = menu->text( id );
00608     if( !pAction || s.isEmpty() )
00609         return;
00610 
00611     int i = s.find( '\t' );
00612 
00613     TQString k = pAction->shortcut().seq(0).toString();
00614     if( k.isEmpty() )
00615         return;
00616 
00617     if ( i >= 0 )
00618         s.replace( i+1, s.length()-i, k );
00619     else {
00620         s += '\t';
00621         s += k;
00622     }
00623 
00624     TQPixmap *pp = menu->pixmap(id);
00625     if( pp && !pp->isNull() )
00626         menu->changeItem( *pp, s, id );
00627     else
00628         menu->changeItem( s, id );
00629 }
00630 
00631 void TDEAccel::changeMenuAccel( TQPopupMenu *menu, int id, TDEStdAccel::StdAccel accel )
00632 {
00633     changeMenuAccel( menu, id, TDEStdAccel::name( accel ) );
00634 }
00635 
00636 int TDEAccel::stringToKey( const TQString& sKey )
00637 {
00638     return KKey( sKey ).keyCodeQt();
00639 }
00640 
00641 int TDEAccel::currentKey( const TQString& sAction ) const
00642 {
00643     TDEAccelAction* pAction = d->actionPtr( sAction );
00644     if( pAction )
00645         return pAction->shortcut().keyCodeQt();
00646     return 0;
00647 }
00648 
00649 TQString TDEAccel::findKey( int key ) const
00650 {
00651     TDEAccelAction* pAction = d->actionPtr( KKey(key) );
00652     if( pAction )
00653         return pAction->name();
00654     else
00655         return TQString::null;
00656 }
00657 #endif // !KDE_NO_COMPAT
00658 
00659 void TDEAccel::virtual_hook( int, void* )
00660 { /*BASE::virtual_hook( id, data );*/ }
00661 
00662 #include "tdeaccel.moc"
00663 #include "tdeaccelprivate.moc"

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.7.6.1
This website is maintained by Timothy Pearson.