kdeui Library API Documentation

kactioncollection.cpp

00001 /* This file is part of the KDE libraries 00002 Copyright (C) 1999 Reginald Stadlbauer <reggie@kde.org> 00003 (C) 1999 Simon Hausmann <hausmann@kde.org> 00004 (C) 2000 Nicolas Hadacek <haadcek@kde.org> 00005 (C) 2000 Kurt Granroth <granroth@kde.org> 00006 (C) 2000 Michael Koch <koch@kde.org> 00007 (C) 2001 Holger Freyther <freyther@kde.org> 00008 (C) 2002 Ellis Whitehead <ellis@kde.org> 00009 (C) 2002 Joseph Wenninger <jowenn@kde.org> 00010 00011 This library is free software; you can redistribute it and/or 00012 modify it under the terms of the GNU Library General Public 00013 License version 2 as published by the Free Software Foundation. 00014 00015 This library is distributed in the hope that it will be useful, 00016 but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00018 Library General Public License for more details. 00019 00020 You should have received a copy of the GNU Library General Public License 00021 along with this library; see the file COPYING.LIB. If not, write to 00022 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 00023 Boston, MA 02111-1307, USA. 00024 */ 00025 00026 #include "kactioncollection.h" 00027 #include "kactionshortcutlist.h" 00028 #include "ktoolbar.h" 00029 #include "kxmlguifactory.h" 00030 #include "kxmlguiclient.h" 00031 00032 #include <kaccel.h> 00033 #include <kaccelbase.h> 00034 #include <kapplication.h> 00035 #include <kdebug.h> 00036 00037 #include <qpopupmenu.h> 00038 #include <qptrdict.h> 00039 #include <qvariant.h> 00040 00041 class KActionCollection::KActionCollectionPrivate 00042 { 00043 public: 00044 KActionCollectionPrivate() 00045 { 00046 m_instance = 0; 00047 //m_bOneKAccelOnly = false; 00048 //m_iWidgetCurrent = 0; 00049 m_bAutoConnectShortcuts = true; 00050 m_widget = 0; 00051 m_kaccel = m_builderKAccel = 0; 00052 m_dctHighlightContainers.setAutoDelete( true ); 00053 m_highlight = false; 00054 m_currentHighlightAction = 0; 00055 m_statusCleared = true; 00056 m_parentGUIClient = 0L; 00057 } 00058 00059 KInstance *m_instance; 00060 QString m_sXMLFile; 00061 bool m_bAutoConnectShortcuts; 00062 //bool m_bOneKAccelOnly; 00063 //int m_iWidgetCurrent; 00064 //QValueList<QWidget*> m_widgetList; 00065 //QValueList<KAccel*> m_kaccelList; 00066 QValueList<KActionCollection*> m_docList; 00067 QWidget *m_widget; 00068 KAccel *m_kaccel; 00069 KAccel *m_builderKAccel; 00070 00071 QAsciiDict<KAction> m_actionDict; 00072 QPtrDict< QPtrList<KAction> > m_dctHighlightContainers; 00073 bool m_highlight; 00074 KAction *m_currentHighlightAction; 00075 bool m_statusCleared; 00076 const KXMLGUIClient *m_parentGUIClient; 00077 }; 00078 00079 KActionCollection::KActionCollection( QWidget *parent, const char *name, 00080 KInstance *instance ) 00081 : QObject( parent, name ) 00082 { 00083 kdDebug(129) << "KActionCollection::KActionCollection( " << parent << ", " << name << " ): this = " << this << endl; // ellis 00084 d = new KActionCollectionPrivate; 00085 if( parent ) 00086 setWidget( parent ); 00087 //d->m_bOneKAccelOnly = (d->m_kaccelList.count() > 0); 00088 setInstance( instance ); 00089 } 00090 00091 00092 KActionCollection::KActionCollection( QWidget *watch, QObject* parent, const char *name, 00093 KInstance *instance ) 00094 : QObject( parent, name ) 00095 { 00096 kdDebug(129) << "KActionCollection::KActionCollection( " << watch << ", " << parent << ", " << name << " ): this = " << this << endl; //ellis 00097 d = new KActionCollectionPrivate; 00098 if( watch ) 00099 setWidget( watch ); 00100 //d->m_bOneKAccelOnly = (d->m_kaccelList.count() > 0); 00101 setInstance( instance ); 00102 } 00103 00104 #ifndef KDE_NO_COMPAT 00105 // KDE 4: remove 00106 KActionCollection::KActionCollection( QObject *parent, const char *name, 00107 KInstance *instance ) 00108 : QObject( parent, name ) 00109 { 00110 kdWarning(129) << "KActionCollection::KActionCollection( QObject *parent, const char *name, KInstance *instance )" << endl; //ellis 00111 kdDebug(129) << kdBacktrace() << endl; 00112 d = new KActionCollectionPrivate; 00113 QWidget* w = dynamic_cast<QWidget*>( parent ); 00114 if( w ) 00115 setWidget( w ); 00116 //d->m_bOneKAccelOnly = (d->m_kaccelList.count() > 0); 00117 setInstance( instance ); 00118 } 00119 00120 KActionCollection::KActionCollection( const KActionCollection &copy ) 00121 : QObject() 00122 { 00123 kdWarning(129) << "KActionCollection::KActionCollection( const KActionCollection & ): function is severely deprecated." << endl; 00124 d = new KActionCollectionPrivate; 00125 *this = copy; 00126 } 00127 #endif // KDE 4: remove end 00128 00129 KActionCollection::KActionCollection( const char *name, const KXMLGUIClient *parent ) 00130 : QObject( 0L, name ) 00131 { 00132 d = new KActionCollectionPrivate; 00133 d->m_parentGUIClient=parent; 00134 d->m_instance=parent->instance(); 00135 } 00136 00137 00138 KActionCollection::~KActionCollection() 00139 { 00140 kdDebug(129) << "KActionCollection::~KActionCollection(): this = " << this << endl; 00141 for ( QAsciiDictIterator<KAction> it( d->m_actionDict ); it.current(); ++it ) { 00142 KAction* pAction = it.current(); 00143 if ( pAction->m_parentCollection == this ) 00144 pAction->m_parentCollection = 0L; 00145 } 00146 00147 delete d->m_kaccel; 00148 delete d->m_builderKAccel; 00149 delete d; d = 0; 00150 } 00151 00152 void KActionCollection::setWidget( QWidget* w ) 00153 { 00154 //if ( d->m_actionDict.count() > 0 ) { 00155 // kdError(129) << "KActionCollection::setWidget(): must be called before any actions are added to collection!" << endl; 00156 // kdDebug(129) << kdBacktrace() << endl; 00157 //} 00158 //else 00159 if ( !d->m_widget ) { 00160 d->m_widget = w; 00161 d->m_kaccel = new KAccel( w, this, "KActionCollection-KAccel" ); 00162 } 00163 else if ( d->m_widget != w ) 00164 kdWarning(129) << "KActionCollection::setWidget(): tried to change widget from " << d->m_widget << " to " << w << endl; 00165 } 00166 00167 void KActionCollection::setAutoConnectShortcuts( bool b ) 00168 { 00169 d->m_bAutoConnectShortcuts = b; 00170 } 00171 00172 bool KActionCollection::isAutoConnectShortcuts() 00173 { 00174 return d->m_bAutoConnectShortcuts; 00175 } 00176 00177 bool KActionCollection::addDocCollection( KActionCollection* pDoc ) 00178 { 00179 d->m_docList.append( pDoc ); 00180 return true; 00181 } 00182 00183 void KActionCollection::beginXMLPlug( QWidget *widget ) 00184 { 00185 kdDebug(129) << "KActionCollection::beginXMLPlug( buildWidget = " << widget << " ): this = " << this << " d->m_builderKAccel = " << d->m_builderKAccel << endl; 00186 00187 if( widget && !d->m_builderKAccel ) { 00188 d->m_builderKAccel = new KAccel( widget, this, "KActionCollection-BuilderKAccel" ); 00189 } 00190 } 00191 00192 void KActionCollection::endXMLPlug() 00193 { 00194 kdDebug(129) << "KActionCollection::endXMLPlug(): this = " << this << endl; 00195 //s_kaccelXML = 0; 00196 } 00197 00198 void KActionCollection::prepareXMLUnplug() 00199 { 00200 kdDebug(129) << "KActionCollection::prepareXMLUnplug(): this = " << this << endl; 00201 unplugShortcuts( d->m_kaccel ); 00202 00203 if( d->m_builderKAccel ) { 00204 unplugShortcuts( d->m_builderKAccel ); 00205 delete d->m_builderKAccel; 00206 d->m_builderKAccel = 0; 00207 } 00208 } 00209 00210 void KActionCollection::unplugShortcuts( KAccel* kaccel ) 00211 { 00212 for ( QAsciiDictIterator<KAction> it( d->m_actionDict ); it.current(); ++it ) { 00213 KAction* pAction = it.current(); 00214 pAction->removeKAccel( kaccel ); 00215 } 00216 00217 for( uint i = 0; i < d->m_docList.count(); i++ ) 00218 d->m_docList[i]->unplugShortcuts( kaccel ); 00219 } 00220 00221 /*void KActionCollection::addWidget( QWidget* w ) 00222 { 00223 if( !d->m_bOneKAccelOnly ) { 00224 kdDebug(129) << "KActionCollection::addWidget( " << w << " ): this = " << this << endl; 00225 for( uint i = 0; i < d->m_widgetList.count(); i++ ) { 00226 if( d->m_widgetList[i] == w ) { 00227 d->m_iWidgetCurrent = i; 00228 return; 00229 } 00230 } 00231 d->m_iWidgetCurrent = d->m_widgetList.count(); 00232 d->m_widgetList.append( w ); 00233 d->m_kaccelList.append( new KAccel( w, this, "KActionCollection-KAccel" ) ); 00234 } 00235 } 00236 00237 void KActionCollection::removeWidget( QWidget* w ) 00238 { 00239 if( !d->m_bOneKAccelOnly ) { 00240 kdDebug(129) << "KActionCollection::removeWidget( " << w << " ): this = " << this << endl; 00241 for( uint i = 0; i < d->m_widgetList.count(); i++ ) { 00242 if( d->m_widgetList[i] == w ) { 00243 // Remove KAccel object from children. 00244 KAccel* pKAccel = d->m_kaccelList[i]; 00245 for ( QAsciiDictIterator<KAction> it( d->m_actionDict ); it.current(); ++it ) { 00246 KAction* pAction = it.current(); 00247 if ( pAction->m_parentCollection == this ) { 00248 pAction->removeKAccel( pKAccel ); 00249 } 00250 } 00251 delete pKAccel; 00252 00253 d->m_widgetList.remove( d->m_widgetList.at( i ) ); 00254 d->m_kaccelList.remove( d->m_kaccelList.at( i ) ); 00255 00256 if( d->m_iWidgetCurrent == (int)i ) 00257 d->m_iWidgetCurrent = -1; 00258 else if( d->m_iWidgetCurrent > (int)i ) 00259 d->m_iWidgetCurrent--; 00260 return; 00261 } 00262 } 00263 kdWarning(129) << "KActionCollection::removeWidget( " << w << " ): widget not in list." << endl; 00264 } 00265 } 00266 00267 bool KActionCollection::ownsKAccel() const 00268 { 00269 return d->m_bOneKAccelOnly; 00270 } 00271 00272 uint KActionCollection::widgetCount() const 00273 { 00274 return d->m_widgetList.count(); 00275 } 00276 00277 const KAccel* KActionCollection::widgetKAccel( uint i ) const 00278 { 00279 return d->m_kaccelList[i]; 00280 }*/ 00281 00282 KAccel* KActionCollection::kaccel() 00283 { 00284 //if( d->m_kaccelList.count() > 0 ) 00285 // return d->m_kaccelList[d->m_iWidgetCurrent]; 00286 //else 00287 // return 0; 00288 return d->m_kaccel; 00289 } 00290 00291 const KAccel* KActionCollection::kaccel() const 00292 { 00293 //if( d->m_kaccelList.count() > 0 ) 00294 // return d->m_kaccelList[d->m_iWidgetCurrent]; 00295 //else 00296 // return 0; 00297 return d->m_kaccel; 00298 } 00299 00300 /*void KActionCollection::findMainWindow( QWidget *w ) 00301 { 00302 // Note: topLevelWidget() stops too early, we can't use it. 00303 QWidget * tl = w; 00304 while ( tl->parentWidget() ) // lookup parent and store 00305 tl = tl->parentWidget(); 00306 00307 KMainWindow * mw = dynamic_cast<KMainWindow *>(tl); // try to see if it's a kmainwindow 00308 if (mw) 00309 d->m_mainwindow = mw; 00310 else 00311 kdDebug(129) << "KAction::plugMainWindowAccel: Toplevel widget isn't a KMainWindow, can't plug accel. " << tl << endl; 00312 }*/ 00313 00314 void KActionCollection::_insert( KAction* action ) 00315 { 00316 char unnamed_name[100]; 00317 const char *name = action->name(); 00318 if( !qstrcmp( name, "unnamed" ) ) 00319 { 00320 sprintf(unnamed_name, "unnamed-%p", (void *)action); 00321 name = unnamed_name; 00322 } 00323 KAction *a = d->m_actionDict[ name ]; 00324 if ( a == action ) 00325 return; 00326 00327 d->m_actionDict.insert( name, action ); 00328 00329 emit inserted( action ); 00330 } 00331 00332 void KActionCollection::_remove( KAction* action ) 00333 { 00334 delete _take( action ); 00335 } 00336 00337 KAction* KActionCollection::_take( KAction* action ) 00338 { 00339 char unnamed_name[100]; 00340 const char *name = action->name(); 00341 if( !qstrcmp( name, "unnamed" ) ) 00342 { 00343 sprintf(unnamed_name, "unnamed-%p", (void *) action); 00344 name = unnamed_name; 00345 } 00346 00347 KAction *a = d->m_actionDict.take( name ); 00348 if ( !a || a != action ) 00349 return 0; 00350 00351 if ( a->m_parentCollection == this ) 00352 a->m_parentCollection = 0; 00353 00354 emit removed( action ); 00355 return a; 00356 } 00357 00358 void KActionCollection::_clear() 00359 { 00360 QAsciiDictIterator<KAction> it( d->m_actionDict ); 00361 while ( it.current() ) 00362 _remove( it.current() ); 00363 } 00364 00365 void KActionCollection::insert( KAction* action ) { _insert( action ); } 00366 void KActionCollection::remove( KAction* action ) { _remove( action ); } 00367 KAction* KActionCollection::take( KAction* action ) { return _take( action ); } 00368 void KActionCollection::clear() { _clear(); } 00369 KAccel* KActionCollection::accel() { return kaccel(); } 00370 const KAccel* KActionCollection::accel() const { return kaccel(); } 00371 KAccel* KActionCollection::builderKAccel() const { return d->m_builderKAccel; } 00372 00373 KAction* KActionCollection::action( const char* name, const char* classname ) const 00374 { 00375 KAction* pAction = 0; 00376 00377 if ( !classname && name ) 00378 pAction = d->m_actionDict[ name ]; 00379 00380 else { 00381 QAsciiDictIterator<KAction> it( d->m_actionDict ); 00382 for( ; it.current(); ++it ) 00383 { 00384 if ( ( !name || !strcmp( it.current()->name(), name ) ) && 00385 ( !classname || !strcmp( it.current()->className(), classname ) ) ) { 00386 pAction = it.current(); 00387 break; 00388 } 00389 } 00390 } 00391 00392 if( !pAction ) { 00393 for( uint i = 0; i < d->m_docList.count() && !pAction; i++ ) 00394 pAction = d->m_docList[i]->action( name, classname ); 00395 } 00396 00397 return pAction; 00398 } 00399 00400 KAction* KActionCollection::action( int index ) const 00401 { 00402 QAsciiDictIterator<KAction> it( d->m_actionDict ); 00403 it += index; 00404 return it.current(); 00405 // return d->m_actions.at( index ); 00406 } 00407 00408 bool KActionCollection::readShortcutSettings( const QString& sConfigGroup, KConfigBase* pConfig ) 00409 { 00410 return KActionShortcutList(this).readSettings( sConfigGroup, pConfig ); 00411 } 00412 00413 bool KActionCollection::writeShortcutSettings( const QString& sConfigGroup, KConfigBase* pConfig ) const 00414 { 00415 return KActionShortcutList((KActionCollection*)this).writeSettings( sConfigGroup, pConfig ); 00416 } 00417 00418 uint KActionCollection::count() const 00419 { 00420 return d->m_actionDict.count(); 00421 } 00422 00423 QStringList KActionCollection::groups() const 00424 { 00425 QStringList lst; 00426 00427 QAsciiDictIterator<KAction> it( d->m_actionDict ); 00428 for( ; it.current(); ++it ) 00429 if ( !it.current()->group().isEmpty() && !lst.contains( it.current()->group() ) ) 00430 lst.append( it.current()->group() ); 00431 00432 return lst; 00433 } 00434 00435 KActionPtrList KActionCollection::actions( const QString& group ) const 00436 { 00437 KActionPtrList lst; 00438 00439 QAsciiDictIterator<KAction> it( d->m_actionDict ); 00440 for( ; it.current(); ++it ) 00441 if ( it.current()->group() == group ) 00442 lst.append( it.current() ); 00443 else if ( it.current()->group().isEmpty() && group.isEmpty() ) 00444 lst.append( it.current() ); 00445 00446 return lst; 00447 } 00448 00449 KActionPtrList KActionCollection::actions() const 00450 { 00451 KActionPtrList lst; 00452 00453 QAsciiDictIterator<KAction> it( d->m_actionDict ); 00454 for( ; it.current(); ++it ) 00455 lst.append( it.current() ); 00456 00457 return lst; 00458 } 00459 00460 void KActionCollection::setInstance( KInstance *instance ) 00461 { 00462 if ( instance ) 00463 d->m_instance = instance; 00464 else 00465 d->m_instance = KGlobal::instance(); 00466 } 00467 00468 KInstance *KActionCollection::instance() const 00469 { 00470 return d->m_instance; 00471 } 00472 00473 void KActionCollection::setXMLFile( const QString& sXMLFile ) 00474 { 00475 d->m_sXMLFile = sXMLFile; 00476 } 00477 00478 const QString& KActionCollection::xmlFile() const 00479 { 00480 return d->m_sXMLFile; 00481 } 00482 00483 void KActionCollection::setHighlightingEnabled( bool enable ) 00484 { 00485 d->m_highlight = enable; 00486 } 00487 00488 bool KActionCollection::highlightingEnabled() const 00489 { 00490 return d->m_highlight; 00491 } 00492 00493 void KActionCollection::connectHighlight( QWidget *container, KAction *action ) 00494 { 00495 if ( !d->m_highlight ) 00496 return; 00497 00498 QPtrList<KAction> *actionList = d->m_dctHighlightContainers[ container ]; 00499 00500 if ( !actionList ) 00501 { 00502 actionList = new QPtrList<KAction>; 00503 00504 if ( ::qt_cast<QPopupMenu *>( container ) ) 00505 { 00506 connect( container, SIGNAL( highlighted( int ) ), 00507 this, SLOT( slotMenuItemHighlighted( int ) ) ); 00508 connect( container, SIGNAL( aboutToHide() ), 00509 this, SLOT( slotMenuAboutToHide() ) ); 00510 } 00511 else if ( ::qt_cast<KToolBar *>( container ) ) 00512 { 00513 connect( container, SIGNAL( highlighted( int, bool ) ), 00514 this, SLOT( slotToolBarButtonHighlighted( int, bool ) ) ); 00515 } 00516 00517 connect( container, SIGNAL( destroyed() ), 00518 this, SLOT( slotDestroyed() ) ); 00519 00520 d->m_dctHighlightContainers.insert( container, actionList ); 00521 } 00522 00523 actionList->append( action ); 00524 } 00525 00526 void KActionCollection::disconnectHighlight( QWidget *container, KAction *action ) 00527 { 00528 if ( !d->m_highlight ) 00529 return; 00530 00531 QPtrList<KAction> *actionList = d->m_dctHighlightContainers[ container ]; 00532 00533 if ( !actionList ) 00534 return; 00535 00536 actionList->removeRef( action ); 00537 00538 if ( actionList->isEmpty() ) 00539 d->m_dctHighlightContainers.remove( container ); 00540 } 00541 00542 void KActionCollection::slotMenuItemHighlighted( int id ) 00543 { 00544 if ( !d->m_highlight ) 00545 return; 00546 00547 if ( d->m_currentHighlightAction ) 00548 emit actionHighlighted( d->m_currentHighlightAction, false ); 00549 00550 QWidget *container = static_cast<QWidget *>( const_cast<QObject *>( sender() ) ); 00551 00552 d->m_currentHighlightAction = findAction( container, id ); 00553 00554 if ( !d->m_currentHighlightAction ) 00555 { 00556 if ( !d->m_statusCleared ) 00557 emit clearStatusText(); 00558 d->m_statusCleared = true; 00559 return; 00560 } 00561 00562 d->m_statusCleared = false; 00563 emit actionHighlighted( d->m_currentHighlightAction ); 00564 emit actionHighlighted( d->m_currentHighlightAction, true ); 00565 emit actionStatusText( d->m_currentHighlightAction->toolTip() ); 00566 } 00567 00568 void KActionCollection::slotMenuAboutToHide() 00569 { 00570 if ( d->m_currentHighlightAction ) 00571 emit actionHighlighted( d->m_currentHighlightAction, false ); 00572 d->m_currentHighlightAction = 0; 00573 00574 if ( !d->m_statusCleared ) 00575 emit clearStatusText(); 00576 d->m_statusCleared = true; 00577 } 00578 00579 void KActionCollection::slotToolBarButtonHighlighted( int id, bool highlight ) 00580 { 00581 if ( !d->m_highlight ) 00582 return; 00583 00584 QWidget *container = static_cast<QWidget *>( const_cast<QObject *>( sender() ) ); 00585 00586 KAction *action = findAction( container, id ); 00587 00588 if ( !action ) 00589 { 00590 d->m_currentHighlightAction = 0; 00591 // use tooltip groups for toolbar status text stuff instead (Simon) 00592 // emit clearStatusText(); 00593 return; 00594 } 00595 00596 emit actionHighlighted( action, highlight ); 00597 00598 if ( highlight ) 00599 d->m_currentHighlightAction = action; 00600 else 00601 { 00602 d->m_currentHighlightAction = 0; 00603 // emit clearStatusText(); 00604 } 00605 } 00606 00607 void KActionCollection::slotDestroyed() 00608 { 00609 d->m_dctHighlightContainers.remove( reinterpret_cast<void *>( const_cast<QObject *>(sender()) ) ); 00610 } 00611 00612 KAction *KActionCollection::findAction( QWidget *container, int id ) 00613 { 00614 QPtrList<KAction> *actionList = d->m_dctHighlightContainers[ reinterpret_cast<void *>( container ) ]; 00615 00616 if ( !actionList ) 00617 return 0; 00618 00619 QPtrListIterator<KAction> it( *actionList ); 00620 for (; it.current(); ++it ) 00621 if ( it.current()->isPlugged( container, id ) ) 00622 return it.current(); 00623 00624 return 0; 00625 } 00626 00627 const KXMLGUIClient *KActionCollection::parentGUIClient() const 00628 { 00629 return d->m_parentGUIClient; 00630 } 00631 00632 #ifndef KDE_NO_COMPAT 00633 // KDE 4: remove 00634 KActionCollection KActionCollection::operator+(const KActionCollection &c ) const 00635 { 00636 kdWarning(129) << "KActionCollection::operator+(): function is severely deprecated." << endl; 00637 KActionCollection ret( *this ); 00638 00639 QValueList<KAction *> actions = c.actions(); 00640 QValueList<KAction *>::ConstIterator it = actions.begin(); 00641 QValueList<KAction *>::ConstIterator end = actions.end(); 00642 for (; it != end; ++it ) 00643 ret.insert( *it ); 00644 00645 return ret; 00646 } 00647 00648 KActionCollection &KActionCollection::operator=( const KActionCollection &copy ) 00649 { 00650 kdWarning(129) << "KActionCollection::operator=(): function is severely deprecated." << endl; 00651 //d->m_bOneKAccelOnly = copy.d->m_bOneKAccelOnly; 00652 //d->m_iWidgetCurrent = copy.d->m_iWidgetCurrent; 00653 //d->m_widgetList = copy.d->m_widgetList; 00654 //d->m_kaccelList = copy.d->m_kaccelList; 00655 d->m_widget = copy.d->m_widget; 00656 d->m_kaccel = copy.d->m_kaccel; 00657 d->m_actionDict = copy.d->m_actionDict; 00658 setInstance( copy.instance() ); 00659 return *this; 00660 } 00661 00662 KActionCollection &KActionCollection::operator+=( const KActionCollection &c ) 00663 { 00664 kdWarning(129) << "KActionCollection::operator+=(): function is severely deprecated." << endl; 00665 QAsciiDictIterator<KAction> it(c.d->m_actionDict); 00666 for ( ; it.current(); ++it ) 00667 insert( it.current() ); 00668 00669 return *this; 00670 } 00671 #endif // KDE 4: remove end 00672 00673 //--------------------------------------------------------------------- 00674 // KActionShortcutList 00675 //--------------------------------------------------------------------- 00676 00677 KActionShortcutList::KActionShortcutList( KActionCollection* pColl ) 00678 : m_actions( *pColl ) 00679 { } 00680 KActionShortcutList::~KActionShortcutList() 00681 { } 00682 uint KActionShortcutList::count() const 00683 { return m_actions.count(); } 00684 QString KActionShortcutList::name( uint i ) const 00685 { return m_actions.action(i)->name(); } 00686 QString KActionShortcutList::label( uint i ) const 00687 { return m_actions.action(i)->text(); } 00688 QString KActionShortcutList::whatsThis( uint i ) const 00689 { return m_actions.action(i)->whatsThis(); } 00690 const KShortcut& KActionShortcutList::shortcut( uint i ) const 00691 { return m_actions.action(i)->shortcut(); } 00692 const KShortcut& KActionShortcutList::shortcutDefault( uint i ) const 00693 { return m_actions.action(i)->shortcutDefault(); } 00694 bool KActionShortcutList::isConfigurable( uint i ) const 00695 { return m_actions.action(i)->isShortcutConfigurable(); } 00696 bool KActionShortcutList::setShortcut( uint i, const KShortcut& cut ) 00697 { return m_actions.action(i)->setShortcut( cut ); } 00698 const KInstance* KActionShortcutList::instance() const 00699 { return m_actions.instance(); } 00700 QVariant KActionShortcutList::getOther( Other, uint ) const 00701 { return QVariant(); } 00702 bool KActionShortcutList::setOther( Other, uint, QVariant ) 00703 { return false; } 00704 const KAction *KActionShortcutList::action( uint i) const 00705 { return m_actions.action(i); } 00706 00707 bool KActionShortcutList::save() const 00708 { 00709 const KXMLGUIClient* guiClient=m_actions.parentGUIClient(); 00710 const QString xmlFile=guiClient ? guiClient->xmlFile() : m_actions.xmlFile(); 00711 kdDebug(129) << "KActionShortcutList::save(): xmlFile = " << xmlFile << endl; 00712 00713 if( m_actions.xmlFile().isEmpty() ) 00714 return writeSettings(); 00715 00716 QString attrShortcut = QString::fromLatin1("shortcut"); 00717 QString attrAccel = QString::fromLatin1("accel"); // Depricated attribute 00718 00719 // Read XML file 00720 QString sXml( KXMLGUIFactory::readConfigFile( xmlFile, false, instance() ) ); 00721 QDomDocument doc; 00722 doc.setContent( sXml ); 00723 00724 // Process XML data 00725 00726 // Get hold of ActionProperties tag 00727 QDomElement elem = KXMLGUIFactory::actionPropertiesElement( doc ); 00728 00729 // now, iterate through our actions 00730 uint nSize = count(); 00731 for( uint i = 0; i < nSize; i++ ) { 00732 const QString& sName = name(i); 00733 00734 bool bSameAsDefault = (shortcut(i) == shortcutDefault(i)); 00735 //kdDebug(129) << "name = " << sName << " shortcut = " << shortcut(i).toStringInternal() << " def = " << shortcutDefault(i).toStringInternal() << endl; 00736 00737 // now see if this element already exists 00738 // and create it if necessary (unless bSameAsDefault) 00739 QDomElement act_elem = KXMLGUIFactory::findActionByName( elem, sName, !bSameAsDefault ); 00740 if ( act_elem.isNull() ) 00741 continue; 00742 00743 act_elem.removeAttribute( attrAccel ); 00744 if( bSameAsDefault ) { 00745 act_elem.removeAttribute( attrShortcut ); 00746 //kdDebug(129) << "act_elem.attributes().count() = " << act_elem.attributes().count() << endl; 00747 if( act_elem.attributes().count() == 1 ) 00748 elem.removeChild( act_elem ); 00749 } else { 00750 act_elem.setAttribute( attrShortcut, shortcut(i).toStringInternal() ); 00751 } 00752 } 00753 00754 // Write back to XML file 00755 return KXMLGUIFactory::saveConfigFile( doc, guiClient ? guiClient->localXMLFile() : m_actions.xmlFile(), instance() ); 00756 } 00757 00758 //--------------------------------------------------------------------- 00759 // KActionPtrShortcutList 00760 //--------------------------------------------------------------------- 00761 00762 KActionPtrShortcutList::KActionPtrShortcutList( KActionPtrList& list ) 00763 : m_actions( list ) 00764 { } 00765 KActionPtrShortcutList::~KActionPtrShortcutList() 00766 { } 00767 uint KActionPtrShortcutList::count() const 00768 { return m_actions.count(); } 00769 QString KActionPtrShortcutList::name( uint i ) const 00770 { return m_actions[i]->name(); } 00771 QString KActionPtrShortcutList::label( uint i ) const 00772 { return m_actions[i]->text(); } 00773 QString KActionPtrShortcutList::whatsThis( uint i ) const 00774 { return m_actions[i]->whatsThis(); } 00775 const KShortcut& KActionPtrShortcutList::shortcut( uint i ) const 00776 { return m_actions[i]->shortcut(); } 00777 const KShortcut& KActionPtrShortcutList::shortcutDefault( uint i ) const 00778 { return m_actions[i]->shortcutDefault(); } 00779 bool KActionPtrShortcutList::isConfigurable( uint i ) const 00780 { return m_actions[i]->isShortcutConfigurable(); } 00781 bool KActionPtrShortcutList::setShortcut( uint i, const KShortcut& cut ) 00782 { return m_actions[i]->setShortcut( cut ); } 00783 QVariant KActionPtrShortcutList::getOther( Other, uint ) const 00784 { return QVariant(); } 00785 bool KActionPtrShortcutList::setOther( Other, uint, QVariant ) 00786 { return false; } 00787 bool KActionPtrShortcutList::save() const 00788 { return false; } 00789 00790 void KActionShortcutList::virtual_hook( int id, void* data ) 00791 { KShortcutList::virtual_hook( id, data ); } 00792 00793 void KActionPtrShortcutList::virtual_hook( int id, void* data ) 00794 { KShortcutList::virtual_hook( id, data ); } 00795 00796 void KActionCollection::virtual_hook( int, void* ) 00797 { /*BASE::virtual_hook( id, data );*/ } 00798 00799 /* vim: et sw=2 ts=2 00800 */ 00801 00802 #include "kactioncollection.moc"
KDE Logo
This file is part of the documentation for kdeui Library Version 3.4.0.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Tue Apr 12 22:56:19 2005 by doxygen 1.3.7 written by Dimitri van Heesch, © 1997-2003