kdeui Library API Documentation

kactionclasses.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               (C) 2003 Andras Mantia <amantia@kde.org>
00011 
00012     This library is free software; you can redistribute it and/or
00013     modify it under the terms of the GNU Library General Public
00014     License version 2 as published by the Free Software Foundation.
00015 
00016     This library is distributed in the hope that it will be useful,
00017     but WITHOUT ANY WARRANTY; without even the implied warranty of
00018     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00019     Library General Public License for more details.
00020 
00021     You should have received a copy of the GNU Library General Public License
00022     along with this library; see the file COPYING.LIB.  If not, write to
00023     the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00024     Boston, MA 02111-1307, USA.
00025 */
00026 
00027 #include "kactionclasses.h"
00028 
00029 #include <assert.h>
00030 
00031 #include <qcursor.h>
00032 #include <qclipboard.h>
00033 #include <qfontdatabase.h>
00034 #include <qobjectlist.h>
00035 #include <qwhatsthis.h>
00036 #include <qtimer.h>
00037 
00038 #include <dcopclient.h>
00039 #include <dcopref.h>
00040 #include <kaccel.h>
00041 #include <kapplication.h>
00042 #include <kconfig.h>
00043 #include <kdebug.h>
00044 #include <kfontcombo.h>
00045 #include <kfontdialog.h>
00046 #include <klocale.h>
00047 #include <kmainwindow.h>
00048 #include <kmenubar.h>
00049 #include <kpopupmenu.h>
00050 #include <ktoolbar.h>
00051 #include <ktoolbarbutton.h>
00052 #include <kurl.h>
00053 #include <kstandarddirs.h>
00054 #include <kstringhandler.h>
00055 
00056 class KToggleAction::KToggleActionPrivate
00057 {
00058 public:
00059   KToggleActionPrivate()
00060   {
00061     m_checked = false;
00062     m_checkedGuiItem = 0;
00063   }
00064 
00065   bool m_checked;
00066   QString m_exclusiveGroup;
00067   KGuiItem* m_checkedGuiItem;
00068 };
00069 
00070 KToggleAction::KToggleAction( const QString& text, const KShortcut& cut,
00071                               QObject* parent,
00072                               const char* name )
00073     : KAction( text, cut, parent, name )
00074 {
00075   d = new KToggleActionPrivate;
00076 }
00077 
00078 KToggleAction::KToggleAction( const QString& text, const KShortcut& cut,
00079                               const QObject* receiver, const char* slot,
00080                               QObject* parent, const char* name )
00081   : KAction( text, cut, receiver, slot, parent, name )
00082 {
00083   d = new KToggleActionPrivate;
00084 }
00085 
00086 KToggleAction::KToggleAction( const QString& text, const QIconSet& pix,
00087                               const KShortcut& cut,
00088                               QObject* parent, const char* name )
00089   : KAction( text, pix, cut, parent, name )
00090 {
00091   d = new KToggleActionPrivate;
00092 }
00093 
00094 KToggleAction::KToggleAction( const QString& text, const QString& pix,
00095                               const KShortcut& cut,
00096                               QObject* parent, const char* name )
00097  : KAction( text, pix, cut, parent, name )
00098 {
00099   d = new KToggleActionPrivate;
00100 }
00101 
00102 KToggleAction::KToggleAction( const QString& text, const QIconSet& pix,
00103                               const KShortcut& cut,
00104                               const QObject* receiver,
00105                               const char* slot, QObject* parent,
00106                               const char* name )
00107   : KAction( text, pix, cut, receiver, slot, parent, name )
00108 {
00109   d = new KToggleActionPrivate;
00110 }
00111 
00112 KToggleAction::KToggleAction( const QString& text, const QString& pix,
00113                               const KShortcut& cut,
00114                               const QObject* receiver,
00115                               const char* slot, QObject* parent,
00116                               const char* name )
00117   : KAction( text, pix, cut, receiver, slot, parent, name )
00118 {
00119   d = new KToggleActionPrivate;
00120 }
00121 
00122 KToggleAction::KToggleAction( QObject* parent, const char* name )
00123     : KAction( parent, name )
00124 {
00125   d = new KToggleActionPrivate;
00126 }
00127 
00128 KToggleAction::~KToggleAction()
00129 {
00130   delete d->m_checkedGuiItem;
00131   delete d;
00132 }
00133 
00134 int KToggleAction::plug( QWidget* widget, int index )
00135 {
00136   if ( !widget->inherits("QPopupMenu") && !widget->inherits("KToolBar") )
00137   {
00138     kdWarning() << "Can not plug KToggleAction in " << widget->className() << endl;
00139     return -1;
00140   }
00141   if (kapp && !kapp->authorizeKAction(name()))
00142     return -1;
00143 
00144   int _index = KAction::plug( widget, index );
00145   if ( _index == -1 )
00146     return _index;
00147 
00148   if ( widget->inherits( "KToolBar" ) ) {
00149     KToolBar *bar = static_cast<KToolBar *>( widget );
00150 
00151     bar->setToggle( itemId( _index ), true );
00152     bar->setButton( itemId( _index ), isChecked() );
00153   }
00154 
00155   if ( d->m_checked )
00156     updateChecked( _index );
00157 
00158   return _index;
00159 }
00160 
00161 void KToggleAction::setChecked( bool c )
00162 {
00163   if ( c == d->m_checked )
00164     return;
00165   //kdDebug(129) << "KToggleAction::setChecked(" << c << ") " << this << " " << name() << endl;
00166 
00167   d->m_checked = c;
00168 
00169   int len = containerCount();
00170 
00171   for( int i = 0; i < len; ++i )
00172     updateChecked( i );
00173 
00174   if ( c && parent() && !exclusiveGroup().isEmpty() ) {
00175     const QObjectList *list = parent()->children();
00176     if ( list ) {
00177       QObjectListIt it( *list );
00178       for( ; it.current(); ++it ) {
00179         if ( it.current()->inherits( "KToggleAction" ) && it.current() != this &&
00180             static_cast<KToggleAction*>(it.current())->exclusiveGroup() == exclusiveGroup() ) {
00181       KToggleAction *a = static_cast<KToggleAction*>(it.current());
00182       if( a->isChecked() ) {
00183         a->setChecked( false );
00184         emit a->toggled( false );
00185       }
00186         }
00187       }
00188     }
00189   }
00190 }
00191 
00192 void KToggleAction::updateChecked( int id )
00193 {
00194   QWidget *w = container( id );
00195 
00196   if ( w->inherits( "QPopupMenu" ) ) {
00197     QPopupMenu* pm = static_cast<QPopupMenu*>(w);
00198     int itemId_ = itemId( id );
00199     if ( !d->m_checkedGuiItem )
00200       pm->setItemChecked( itemId_, d->m_checked );
00201     else {
00202       const KGuiItem* gui = d->m_checked ? d->m_checkedGuiItem : &guiItem();
00203       if ( d->m_checkedGuiItem->hasIcon() )
00204           pm->changeItem( itemId_, gui->iconSet( KIcon::Small ), gui->text() );
00205       else
00206           pm->changeItem( itemId_, gui->text() );
00207       if ( !d->m_checkedGuiItem->whatsThis().isEmpty() ) // if empty, we keep the initial one
00208           pm->setWhatsThis( itemId_, gui->whatsThis() );
00209       updateShortcut( pm, itemId_ );
00210     }
00211   }
00212   else if ( w->inherits( "QMenuBar" ) ) // not handled in plug...
00213     static_cast<QMenuBar*>(w)->setItemChecked( itemId( id ), d->m_checked );
00214   else if ( w->inherits( "KToolBar" ) )
00215   {
00216     QWidget* r = static_cast<KToolBar*>( w )->getButton( itemId( id ) );
00217     if ( r && r->inherits( "KToolBarButton" ) ) {
00218       static_cast<KToolBar*>( w )->setButton( itemId( id ), d->m_checked );
00219       if ( d->m_checkedGuiItem && d->m_checkedGuiItem->hasIcon() ) {
00220         const KGuiItem* gui = d->m_checked ? d->m_checkedGuiItem : &guiItem();
00221         static_cast<KToolBar*>( w )->setButtonIconSet( itemId( id ), gui->iconSet( KIcon::Toolbar ) );
00222       }
00223     }
00224   }
00225 }
00226 
00227 void KToggleAction::slotActivated()
00228 {
00229   setChecked( !isChecked() );
00230   emit activated();
00231   emit toggled( isChecked() );
00232 }
00233 
00234 bool KToggleAction::isChecked() const
00235 {
00236   return d->m_checked;
00237 }
00238 
00239 void KToggleAction::setExclusiveGroup( const QString& name )
00240 {
00241   d->m_exclusiveGroup = name;
00242 }
00243 
00244 QString KToggleAction::exclusiveGroup() const
00245 {
00246   return d->m_exclusiveGroup;
00247 }
00248 
00249 void KToggleAction::setCheckedState( const KGuiItem& checkedItem )
00250 {
00251   delete d->m_checkedGuiItem;
00252   d->m_checkedGuiItem = new KGuiItem( checkedItem );
00253 }
00254 
00255 QString KToggleAction::toolTip() const
00256 {
00257   if ( d->m_checkedGuiItem && d->m_checked )
00258       return d->m_checkedGuiItem->toolTip();
00259   else
00260       return KAction::toolTip();
00261 }
00262 
00263 KRadioAction::KRadioAction( const QString& text, const KShortcut& cut,
00264                             QObject* parent, const char* name )
00265 : KToggleAction( text, cut, parent, name )
00266 {
00267 }
00268 
00269 KRadioAction::KRadioAction( const QString& text, const KShortcut& cut,
00270                             const QObject* receiver, const char* slot,
00271                             QObject* parent, const char* name )
00272 : KToggleAction( text, cut, receiver, slot, parent, name )
00273 {
00274 }
00275 
00276 KRadioAction::KRadioAction( const QString& text, const QIconSet& pix,
00277                             const KShortcut& cut,
00278                             QObject* parent, const char* name )
00279 : KToggleAction( text, pix, cut, parent, name )
00280 {
00281 }
00282 
00283 KRadioAction::KRadioAction( const QString& text, const QString& pix,
00284                             const KShortcut& cut,
00285                             QObject* parent, const char* name )
00286 : KToggleAction( text, pix, cut, parent, name )
00287 {
00288 }
00289 
00290 KRadioAction::KRadioAction( const QString& text, const QIconSet& pix,
00291                             const KShortcut& cut,
00292                             const QObject* receiver, const char* slot,
00293                             QObject* parent, const char* name )
00294 : KToggleAction( text, pix, cut, receiver, slot, parent, name )
00295 {
00296 }
00297 
00298 KRadioAction::KRadioAction( const QString& text, const QString& pix,
00299                             const KShortcut& cut,
00300                             const QObject* receiver, const char* slot,
00301                             QObject* parent, const char* name )
00302 : KToggleAction( text, pix, cut, receiver, slot, parent, name )
00303 {
00304 }
00305 
00306 KRadioAction::KRadioAction( QObject* parent, const char* name )
00307 : KToggleAction( parent, name )
00308 {
00309 }
00310 
00311 void KRadioAction::slotActivated()
00312 {
00313   if ( isChecked() )
00314   {
00315     const QObject *senderObj = sender();
00316 
00317     if ( !senderObj || !senderObj->inherits( "KToolBarButton" ) )
00318       return;
00319 
00320     const_cast<KToolBarButton *>( static_cast<const KToolBarButton *>( senderObj ) )->on( true );
00321 
00322     return;
00323   }
00324 
00325   KToggleAction::slotActivated();
00326 }
00327 
00328 class KSelectAction::KSelectActionPrivate
00329 {
00330 public:
00331   KSelectActionPrivate()
00332   {
00333     m_edit = false;
00334     m_menuAccelsEnabled = true;
00335     m_menu = 0;
00336     m_current = -1;
00337     m_comboWidth = -1;
00338   }
00339   bool m_edit;
00340   bool m_menuAccelsEnabled;
00341   QPopupMenu *m_menu;
00342   int m_current;
00343   int m_comboWidth;
00344   QStringList m_list;
00345 
00346   QString makeMenuText( const QString &_text )
00347   {
00348       if ( m_menuAccelsEnabled )
00349         return _text;
00350       QString text = _text;
00351       uint i = 0;
00352       while ( i < text.length() ) {
00353           if ( text[ i ] == '&' ) {
00354               text.insert( i, '&' );
00355               i += 2;
00356           }
00357           else
00358               ++i;
00359       }
00360       return text;
00361   }
00362 };
00363 
00364 KSelectAction::KSelectAction( const QString& text, const KShortcut& cut,
00365                               QObject* parent, const char* name )
00366   : KAction( text, cut, parent, name )
00367 {
00368   d = new KSelectActionPrivate;
00369 }
00370 
00371 KSelectAction::KSelectAction( const QString& text, const KShortcut& cut,
00372                               const QObject* receiver, const char* slot,
00373                               QObject* parent, const char* name )
00374   : KAction( text, cut, receiver, slot, parent, name )
00375 {
00376   d = new KSelectActionPrivate;
00377 }
00378 
00379 KSelectAction::KSelectAction( const QString& text, const QIconSet& pix,
00380                               const KShortcut& cut,
00381                               QObject* parent, const char* name )
00382   : KAction( text, pix, cut, parent, name )
00383 {
00384   d = new KSelectActionPrivate;
00385 }
00386 
00387 KSelectAction::KSelectAction( const QString& text, const QString& pix,
00388                               const KShortcut& cut,
00389                               QObject* parent, const char* name )
00390   : KAction( text, pix, cut, parent, name )
00391 {
00392   d = new KSelectActionPrivate;
00393 }
00394 
00395 KSelectAction::KSelectAction( const QString& text, const QIconSet& pix,
00396                               const KShortcut& cut,
00397                               const QObject* receiver,
00398                               const char* slot, QObject* parent,
00399                               const char* name )
00400   : KAction( text, pix, cut, receiver, slot, parent, name )
00401 {
00402   d = new KSelectActionPrivate;
00403 }
00404 
00405 KSelectAction::KSelectAction( const QString& text, const QString& pix,
00406                               const KShortcut& cut,
00407                               const QObject* receiver,
00408                               const char* slot, QObject* parent,
00409                               const char* name )
00410   : KAction( text, pix, cut, receiver, slot, parent, name )
00411 {
00412   d = new KSelectActionPrivate;
00413 }
00414 
00415 KSelectAction::KSelectAction( QObject* parent, const char* name )
00416   : KAction( parent, name )
00417 {
00418   d = new KSelectActionPrivate;
00419 }
00420 
00421 KSelectAction::~KSelectAction()
00422 {
00423   assert(d);
00424   delete d->m_menu;
00425   delete d; d = 0;
00426 }
00427 
00428 void KSelectAction::setCurrentItem( int id )
00429 {
00430     if ( id >= (int)d->m_list.count() ) {
00431         Q_ASSERT(id < (int)d->m_list.count());
00432         return;
00433     }
00434 
00435     if ( d->m_menu )
00436     {
00437         if ( d->m_current >= 0 )
00438             d->m_menu->setItemChecked( d->m_current, false );
00439         if ( id >= 0 )
00440             d->m_menu->setItemChecked( id, true );
00441     }
00442 
00443     d->m_current = id;
00444 
00445     int len = containerCount();
00446 
00447     for( int i = 0; i < len; ++i )
00448         updateCurrentItem( i );
00449 
00450     //    emit KAction::activated();
00451     //    emit activated( currentItem() );
00452     //    emit activated( currentText() );
00453 }
00454 
00455 void KSelectAction::setComboWidth( int width )
00456 {
00457   if ( width < 0 )
00458     return;
00459 
00460   d->m_comboWidth=width;
00461 
00462   int len = containerCount();
00463 
00464   for( int i = 0; i < len; ++i )
00465     updateComboWidth( i );
00466 
00467 }
00468 QPopupMenu* KSelectAction::popupMenu() const
00469 {
00470     kdDebug(129) << "KAction::popupMenu()" << endl; // remove -- ellis
00471   if ( !d->m_menu )
00472   {
00473     d->m_menu = new KPopupMenu(0L, "KSelectAction::popupMenu()");
00474     setupMenu();
00475     if ( d->m_current >= 0 )
00476       d->m_menu->setItemChecked( d->m_current, true );
00477   }
00478 
00479   return d->m_menu;
00480 }
00481 
00482 void KSelectAction::setupMenu() const
00483 {
00484     if ( !d->m_menu )
00485         return;
00486     d->m_menu->clear();
00487 
00488     QStringList::ConstIterator it = d->m_list.begin();
00489     for( uint id = 0; it != d->m_list.end(); ++it, ++id ) {
00490         QString text = *it;
00491         if ( !text.isEmpty() )
00492             d->m_menu->insertItem( d->makeMenuText( text ), this, SLOT( slotActivated( int ) ), 0, id );
00493         else
00494             d->m_menu->insertSeparator();
00495     }
00496 }
00497 
00498 void KSelectAction::changeItem( int index, const QString& text )
00499 {
00500   if ( index < 0 || index >= (int)d->m_list.count() )
00501   {
00502     kdWarning() << "KSelectAction::changeItem Index out of scope" << endl;
00503     return;
00504   }
00505 
00506   d->m_list[ index ] = text;
00507 
00508   if ( d->m_menu )
00509     d->m_menu->changeItem( index, d->makeMenuText( text ) );
00510 
00511   int len = containerCount();
00512   for( int i = 0; i < len; ++i )
00513     changeItem( i, index, text );
00514 }
00515 
00516 void KSelectAction::changeItem( int id, int index, const QString& text)
00517 {
00518   if ( index < 0 )
00519         return;
00520 
00521   QWidget* w = container( id );
00522   if ( w->inherits( "KToolBar" ) )
00523   {
00524      QWidget* r = (static_cast<KToolBar*>( w ))->getWidget( itemId( id ) );
00525      if ( r->inherits( "QComboBox" ) )
00526      {
00527         QComboBox *b = static_cast<QComboBox*>( r );
00528         b->changeItem(text, index );
00529      }
00530   }
00531 }
00532 
00533 void KSelectAction::setItems( const QStringList &lst )
00534 {
00535   d->m_list = lst;
00536   d->m_current = -1;
00537 
00538   setupMenu();
00539 
00540   int len = containerCount();
00541   for( int i = 0; i < len; ++i )
00542     updateItems( i );
00543 
00544   // Disable if empty and not editable
00545   setEnabled ( lst.count() > 0 || d->m_edit );
00546 }
00547 
00548 QStringList KSelectAction::items() const
00549 {
00550   return d->m_list;
00551 }
00552 
00553 QString KSelectAction::currentText() const
00554 {
00555   if ( currentItem() < 0 )
00556     return QString::null;
00557 
00558   return d->m_list[ currentItem() ];
00559 }
00560 
00561 int KSelectAction::currentItem() const
00562 {
00563   return d->m_current;
00564 }
00565 
00566 void KSelectAction::updateCurrentItem( int id )
00567 {
00568   if ( d->m_current < 0 )
00569         return;
00570 
00571   QWidget* w = container( id );
00572   if ( w->inherits( "KToolBar" ) ) {
00573     QWidget* r = static_cast<KToolBar*>( w )->getWidget( itemId( id ) );
00574     if ( r->inherits( "QComboBox" ) ) {
00575       QComboBox *b = static_cast<QComboBox*>( r );
00576       b->setCurrentItem( d->m_current );
00577     }
00578   }
00579 }
00580 
00581 int KSelectAction::comboWidth() const
00582 {
00583   return d->m_comboWidth;
00584 }
00585 
00586 void KSelectAction::updateComboWidth( int id )
00587 {
00588   QWidget* w = container( id );
00589   if ( w->inherits( "KToolBar" ) ) {
00590     QWidget* r = static_cast<KToolBar*>( w )->getWidget( itemId( id ) );
00591     if ( r->inherits( "QComboBox" ) ) {
00592       QComboBox *cb = static_cast<QComboBox*>( r );
00593       cb->setMinimumWidth( d->m_comboWidth );
00594       cb->setMaximumWidth( d->m_comboWidth );
00595     }
00596   }
00597 }
00598 
00599 void KSelectAction::updateItems( int id )
00600 {
00601     kdDebug(129) << "KAction::updateItems( " << id << ", lst )" << endl; // remove -- ellis
00602   QWidget* w = container( id );
00603   if ( w->inherits( "KToolBar" ) ) {
00604     QWidget* r = static_cast<KToolBar*>( w )->getWidget( itemId( id ) );
00605     if ( r->inherits( "QComboBox" ) ) {
00606       QComboBox *cb = static_cast<QComboBox*>( r );
00607       cb->clear();
00608       QStringList lst = comboItems();
00609       QStringList::ConstIterator it = lst.begin();
00610       for( ; it != lst.end(); ++it )
00611         cb->insertItem( *it );
00612       // Ok, this currently doesn't work due to a bug in QComboBox
00613       // (the sizehint is cached for ever and never recalculated)
00614       // Bug reported (against Qt 2.3.1).
00615       cb->setMinimumWidth( cb->sizeHint().width() );
00616     }
00617    }
00618 }
00619 
00620 int KSelectAction::plug( QWidget *widget, int index )
00621 {
00622   if (kapp && !kapp->authorizeKAction(name()))
00623     return -1;
00624   kdDebug(129) << "KAction::plug( " << widget << ", " << index << " )" << endl; // remove -- ellis
00625   if ( widget->inherits("QPopupMenu") )
00626   {
00627     // Create the PopupMenu and store it in m_menu
00628     (void)popupMenu();
00629 
00630     QPopupMenu* menu = static_cast<QPopupMenu*>( widget );
00631     int id;
00632     if ( hasIconSet() )
00633       id = menu->insertItem( iconSet(), text(), d->m_menu, -1, index );
00634     else
00635       id = menu->insertItem( text(), d->m_menu, -1, index );
00636 
00637     if ( !isEnabled() )
00638         menu->setItemEnabled( id, false );
00639 
00640     QString wth = whatsThis();
00641     if ( !wth.isEmpty() )
00642         menu->setWhatsThis( id, wth );
00643 
00644     addContainer( menu, id );
00645     connect( menu, SIGNAL( destroyed() ), this, SLOT( slotDestroyed() ) );
00646 
00647     return containerCount() - 1;
00648   }
00649   else if ( widget->inherits("KToolBar") )
00650   {
00651     KToolBar* bar = static_cast<KToolBar*>( widget );
00652     int id_ = KAction::getToolButtonID();
00653     bar->insertCombo( comboItems(), id_, isEditable(),
00654                       SIGNAL( activated( const QString & ) ), this,
00655                       SLOT( slotActivated( const QString & ) ), isEnabled(),
00656                       toolTip(), -1, index );
00657 
00658     QComboBox *cb = bar->getCombo( id_ );
00659     if ( cb )
00660     {
00661       if (!isEditable()) cb->setFocusPolicy(QWidget::NoFocus);
00662       cb->setMinimumWidth( cb->sizeHint().width() );
00663       if ( d->m_comboWidth > 0 )
00664       {
00665         cb->setMinimumWidth( d->m_comboWidth );
00666         cb->setMaximumWidth( d->m_comboWidth );
00667       }
00668       cb->setInsertionPolicy( QComboBox::NoInsertion );
00669       QWhatsThis::add( cb, whatsThis() );
00670     }
00671 
00672     addContainer( bar, id_ );
00673 
00674     connect( bar, SIGNAL( destroyed() ), this, SLOT( slotDestroyed() ) );
00675 
00676     updateCurrentItem( containerCount() - 1 );
00677 
00678     return containerCount() - 1;
00679   }
00680   else if ( widget->inherits("QMenuBar") )
00681   {
00682     // Create the PopupMenu and store it in m_menu
00683     (void)popupMenu();
00684 
00685     QMenuBar* menu = static_cast<QMenuBar*>( widget );
00686     int id = menu->insertItem( text(), d->m_menu, -1, index );
00687 
00688     if ( !isEnabled() )
00689         menu->setItemEnabled( id, false );
00690 
00691     QString wth = whatsThis();
00692     if ( !wth.isEmpty() )
00693         menu->setWhatsThis( id, wth );
00694 
00695     addContainer( menu, id );
00696     connect( menu, SIGNAL( destroyed() ), this, SLOT( slotDestroyed() ) );
00697 
00698     return containerCount() - 1;
00699   }
00700 
00701   kdWarning() << "Can not plug KAction in " << widget->className() << endl;
00702   return -1;
00703 }
00704 
00705 QStringList KSelectAction::comboItems() const
00706 {
00707   if( d->m_menuAccelsEnabled ) {
00708     QStringList lst;
00709     QStringList::ConstIterator it = d->m_list.begin();
00710     for( ; it != d->m_list.end(); ++it )
00711     {
00712       QString item = *it;
00713       int i = item.find( '&' );
00714       if ( i > -1 )
00715         item = item.remove( i, 1 );
00716       lst.append( item );
00717     }
00718     return lst;
00719   }
00720   else
00721     return d->m_list;
00722 }
00723 
00724 void KSelectAction::clear()
00725 {
00726   if ( d->m_menu )
00727     d->m_menu->clear();
00728 
00729   int len = containerCount();
00730   for( int i = 0; i < len; ++i )
00731     updateClear( i );
00732 }
00733 
00734 void KSelectAction::updateClear( int id )
00735 {
00736   QWidget* w = container( id );
00737   if ( w->inherits( "KToolBar" ) ) {
00738     QWidget* r = static_cast<KToolBar*>( w )->getWidget( itemId( id ) );
00739     if ( r->inherits( "QComboBox" ) ) {
00740       QComboBox *b = static_cast<QComboBox*>( r );
00741       b->clear();
00742     }
00743   }
00744 }
00745 
00746 void KSelectAction::slotActivated( int id )
00747 {
00748   if ( d->m_current == id )
00749     return;
00750 
00751   setCurrentItem( id );
00752   // Delay this. Especially useful when the slot connected to activated() will re-create
00753   // the menu, e.g. in the recent files action. This prevents a crash.
00754   QTimer::singleShot( 0, this, SLOT( slotActivated() ) );
00755 }
00756 
00757 void KSelectAction::slotActivated( const QString &text )
00758 {
00759   if ( isEditable() )
00760   {
00761     QStringList lst = items();
00762     if(lst.contains(text)==0)
00763     {
00764       lst.append( text );
00765       setItems( lst );
00766     }
00767   }
00768 
00769   int i = items().findIndex( text );
00770   if ( i > -1 )
00771       setCurrentItem( i );
00772   else
00773       setCurrentItem( comboItems().findIndex( text ) );
00774   // Delay this. Especially useful when the slot connected to activated() will re-create
00775   // the menu, e.g. in the recent files action. This prevents a crash.
00776   QTimer::singleShot( 0, this, SLOT( slotActivated() ) );
00777 }
00778 
00779 void KSelectAction::slotActivated()
00780 {
00781   KAction::slotActivated();
00782   kdDebug(129) << "KSelectAction::slotActivated currentItem=" << currentItem() << " currentText=" << currentText() << endl;
00783   emit activated( currentItem() );
00784   emit activated( currentText() );
00785 }
00786 
00787 void KSelectAction::setEditable( bool edit )
00788 {
00789   d->m_edit = edit;
00790 }
00791 
00792 bool KSelectAction::isEditable() const
00793 {
00794   return d->m_edit;
00795 }
00796 
00797 void KSelectAction::setRemoveAmpersandsInCombo( bool b )
00798 {
00799   setMenuAccelsEnabled( b );
00800 }
00801 
00802 bool KSelectAction::removeAmpersandsInCombo() const
00803 {
00804   return menuAccelsEnabled( );
00805 }
00806 
00807 void KSelectAction::setMenuAccelsEnabled( bool b )
00808 {
00809   d->m_menuAccelsEnabled = b;
00810 }
00811 
00812 bool KSelectAction::menuAccelsEnabled() const
00813 {
00814   return d->m_menuAccelsEnabled;
00815 }
00816 
00817 class KListAction::KListActionPrivate
00818 {
00819 public:
00820   KListActionPrivate()
00821   {
00822     m_current = 0;
00823   }
00824   int m_current;
00825 };
00826 
00827 KListAction::KListAction( const QString& text, const KShortcut& cut,
00828                           QObject* parent, const char* name )
00829   : KSelectAction( text, cut, parent, name )
00830 {
00831   d = new KListActionPrivate;
00832 }
00833 
00834 KListAction::KListAction( const QString& text, const KShortcut& cut,
00835                           const QObject* receiver, const char* slot,
00836                           QObject* parent, const char* name )
00837   : KSelectAction( text, cut, parent, name )
00838 {
00839   d = new KListActionPrivate;
00840   if ( receiver )
00841     connect( this, SIGNAL( activated( int ) ), receiver, slot );
00842 }
00843 
00844 KListAction::KListAction( const QString& text, const QIconSet& pix,
00845                           const KShortcut& cut,
00846                           QObject* parent, const char* name )
00847   : KSelectAction( text, pix, cut, parent, name )
00848 {
00849   d = new KListActionPrivate;
00850 }
00851 
00852 KListAction::KListAction( const QString& text, const QString& pix,
00853                           const KShortcut& cut,
00854                           QObject* parent, const char* name )
00855   : KSelectAction( text, pix, cut, parent, name )
00856 {
00857   d = new KListActionPrivate;
00858 }
00859 
00860 KListAction::KListAction( const QString& text, const QIconSet& pix,
00861                           const KShortcut& cut, const QObject* receiver,
00862                           const char* slot, QObject* parent,
00863                           const char* name )
00864   : KSelectAction( text, pix, cut, parent, name )
00865 {
00866   d = new KListActionPrivate;
00867   if ( receiver )
00868     connect( this, SIGNAL( activated( int ) ), receiver, slot );
00869 }
00870 
00871 KListAction::KListAction( const QString& text, const QString& pix,
00872                           const KShortcut& cut, const QObject* receiver,
00873                           const char* slot, QObject* parent,
00874                           const char* name )
00875   : KSelectAction( text, pix, cut, parent, name )
00876 {
00877   d = new KListActionPrivate;
00878   if ( receiver )
00879     connect( this, SIGNAL( activated( int ) ), receiver, slot );
00880 }
00881 
00882 KListAction::KListAction( QObject* parent, const char* name )
00883   : KSelectAction( parent, name )
00884 {
00885   d = new KListActionPrivate;
00886 }
00887 
00888 KListAction::~KListAction()
00889 {
00890   delete d; d = 0;
00891 }
00892 
00893 void KListAction::setCurrentItem( int index )
00894 {
00895   KSelectAction::setCurrentItem( index );
00896   d->m_current = index;
00897 
00898   //  emit KAction::activated();
00899   //  emit activated( currentItem() );
00900   // emit activated( currentText() );
00901 }
00902 
00903 QString KListAction::currentText() const
00904 {
00905   if ( currentItem() < 0 )
00906       return QString::null;
00907 
00908   return items()[ currentItem() ];
00909 }
00910 
00911 int KListAction::currentItem() const
00912 {
00913   return d->m_current;
00914 }
00915 
00916 class KRecentFilesAction::KRecentFilesActionPrivate
00917 {
00918 public:
00919   KRecentFilesActionPrivate()
00920   {
00921     m_maxItems = 0;
00922     m_popup = 0;
00923   }
00924   uint m_maxItems;
00925   KPopupMenu *m_popup;
00926 };
00927 
00928 KRecentFilesAction::KRecentFilesAction( const QString& text,
00929                                         const KShortcut& cut,
00930                                         QObject* parent, const char* name,
00931                                         uint maxItems )
00932   : KListAction( text, cut, parent, name)
00933 {
00934   d = new KRecentFilesActionPrivate;
00935   d->m_maxItems = maxItems;
00936 
00937   init();
00938 }
00939 
00940 KRecentFilesAction::KRecentFilesAction( const QString& text,
00941                                         const KShortcut& cut,
00942                                         const QObject* receiver,
00943                                         const char* slot,
00944                                         QObject* parent, const char* name,
00945                                         uint maxItems )
00946   : KListAction( text, cut, parent, name)
00947 {
00948   d = new KRecentFilesActionPrivate;
00949   d->m_maxItems = maxItems;
00950 
00951   init();
00952 
00953   if ( receiver )
00954     connect( this,     SIGNAL(urlSelected(const KURL&)),
00955              receiver, slot );
00956 }
00957 
00958 KRecentFilesAction::KRecentFilesAction( const QString& text,
00959                                         const QIconSet& pix,
00960                                         const KShortcut& cut,
00961                                         QObject* parent, const char* name,
00962                                         uint maxItems )
00963   : KListAction( text, pix, cut, parent, name)
00964 {
00965   d = new KRecentFilesActionPrivate;
00966   d->m_maxItems = maxItems;
00967 
00968   init();
00969 }
00970 
00971 KRecentFilesAction::KRecentFilesAction( const QString& text,
00972                                         const QString& pix,
00973                                         const KShortcut& cut,
00974                                         QObject* parent, const char* name,
00975                                         uint maxItems )
00976   : KListAction( text, pix, cut, parent, name)
00977 {
00978   d = new KRecentFilesActionPrivate;
00979   d->m_maxItems = maxItems;
00980 
00981   init();
00982 }
00983 
00984 KRecentFilesAction::KRecentFilesAction( const QString& text,
00985                                         const QIconSet& pix,
00986                                         const KShortcut& cut,
00987                                         const QObject* receiver,
00988                                         const char* slot,
00989                                         QObject* parent, const char* name,
00990                                         uint maxItems )
00991   : KListAction( text, pix, cut, parent, name)
00992 {
00993   d = new KRecentFilesActionPrivate;
00994   d->m_maxItems = maxItems;
00995 
00996   init();
00997 
00998   if ( receiver )
00999     connect( this,     SIGNAL(urlSelected(const KURL&)),
01000              receiver, slot );
01001 }
01002 
01003 KRecentFilesAction::KRecentFilesAction( const QString& text,
01004                                         const QString& pix,
01005                                         const KShortcut& cut,
01006                                         const QObject* receiver,
01007                                         const char* slot,
01008                                         QObject* parent, const char* name,
01009                                         uint maxItems )
01010   : KListAction( text, pix, cut, parent, name)
01011 {
01012   d = new KRecentFilesActionPrivate;
01013   d->m_maxItems = maxItems;
01014 
01015   init();
01016 
01017   if ( receiver )
01018     connect( this,     SIGNAL(urlSelected(const KURL&)),
01019              receiver, slot );
01020 }
01021 
01022 KRecentFilesAction::KRecentFilesAction( QObject* parent, const char* name,
01023                                         uint maxItems )
01024   : KListAction( parent, name )
01025 {
01026   d = new KRecentFilesActionPrivate;
01027   d->m_maxItems = maxItems;
01028 
01029   init();
01030 }
01031 
01032 void KRecentFilesAction::init()
01033 {
01034   KRecentFilesAction *that = const_cast<KRecentFilesAction*>(this);
01035   that->d->m_popup = new KPopupMenu;
01036   connect(d->m_popup, SIGNAL(aboutToShow()), this, SLOT(menuAboutToShow()));
01037   connect(d->m_popup, SIGNAL(activated(int)), this, SLOT(menuItemActivated(int)));
01038   connect( this, SIGNAL( activated( const QString& ) ),
01039            this, SLOT( itemSelected( const QString& ) ) );
01040 
01041   setMenuAccelsEnabled( false );
01042 }
01043 
01044 KRecentFilesAction::~KRecentFilesAction()
01045 {
01046   delete d->m_popup;
01047   delete d; d = 0;
01048 }
01049 
01050 uint KRecentFilesAction::maxItems() const
01051 {
01052     return d->m_maxItems;
01053 }
01054 
01055 void KRecentFilesAction::setMaxItems( uint maxItems )
01056 {
01057     QStringList lst = items();
01058     uint oldCount   = lst.count();
01059 
01060     // set new maxItems
01061     d->m_maxItems = maxItems;
01062 
01063     // remove all items that are too much
01064     while( lst.count() > maxItems )
01065     {
01066         // remove last item
01067         lst.remove( lst.last() );
01068     }
01069 
01070     // set new list if changed
01071     if( lst.count() != oldCount )
01072         setItems( lst );
01073 }
01074 
01075 void KRecentFilesAction::addURL( const KURL& url )
01076 {
01077     QString     file = url.prettyURL();
01078     if ( url.isLocalFile() && !KGlobal::dirs()->relativeLocation("tmp", url.path()).startsWith("/"))
01079        return;
01080     QStringList lst = items();
01081 
01082     // remove file if already in list
01083     lst.remove( file );
01084 
01085     // remove las item if already maxitems in list
01086     if( lst.count() == d->m_maxItems )
01087     {
01088         // remove last item
01089         lst.remove( lst.last() );
01090     }
01091 
01092     // add file to list
01093     lst.prepend( file );
01094     setItems( lst );
01095 }
01096 
01097 void KRecentFilesAction::removeURL( const KURL& url )
01098 {
01099     QStringList lst = items();
01100     QString     file = url.prettyURL();
01101 
01102     // remove url
01103     if( lst.count() > 0 )
01104     {
01105         lst.remove( file );
01106         setItems( lst );
01107     }
01108 }
01109 
01110 void KRecentFilesAction::clearURLList()
01111 {
01112     clear();
01113 }
01114 
01115 void KRecentFilesAction::loadEntries( KConfig* config, QString groupname)
01116 {
01117     QString     key;
01118     QString     value;
01119     QString     oldGroup;
01120     QStringList lst;
01121 
01122     oldGroup = config->group();
01123 
01124     if (groupname.isEmpty())
01125       groupname = "RecentFiles";
01126     config->setGroup( groupname );
01127 
01128     // read file list
01129     for( unsigned int i = 1 ; i <= d->m_maxItems ; i++ )
01130     {
01131         key = QString( "File%1" ).arg( i );
01132         value = config->readPathEntry( key );
01133 
01134         if (!value.isNull())
01135             lst.append( value );
01136     }
01137 
01138     // set file
01139     setItems( lst );
01140 
01141     config->setGroup( oldGroup );
01142 }
01143 
01144 void KRecentFilesAction::saveEntries( KConfig* config, QString groupname )
01145 {
01146     QString     key;
01147     QString     value;
01148     QString     oldGroup;
01149     QStringList lst = items();
01150 
01151     oldGroup = config->group();
01152 
01153     if (groupname.isEmpty())
01154       groupname = "RecentFiles";
01155     config->deleteGroup( groupname, true );
01156     config->setGroup( groupname );
01157 
01158     // write file list
01159     for( unsigned int i = 1 ; i <= lst.count() ; i++ )
01160     {
01161         key = QString( "File%1" ).arg( i );
01162         value = lst[ i - 1 ];
01163         config->writePathEntry( key, value );
01164     }
01165 
01166     config->setGroup( oldGroup );
01167 }
01168 
01169 void KRecentFilesAction::itemSelected( const QString& text )
01170 {
01171     emit urlSelected( KURL( text ) );
01172 }
01173 
01174 void KRecentFilesAction::menuItemActivated( int id )
01175 {
01176     emit urlSelected( KURL(d->m_popup->text(id)) );
01177 }
01178 
01179 void KRecentFilesAction::menuAboutToShow()
01180 {
01181     KPopupMenu *menu = d->m_popup;
01182     menu->clear();
01183     QStringList list = items();
01184     for ( QStringList::Iterator it = list.begin(); it != list.end(); ++it )
01185         menu->insertItem(*it);
01186 }
01187 
01188 int KRecentFilesAction::plug( QWidget *widget, int index )
01189 {
01190   if (kapp && !kapp->authorizeKAction(name()))
01191     return -1;
01192   // This is very related to KActionMenu::plug.
01193   // In fact this class could be an interesting base class for KActionMenu
01194   if ( widget->inherits( "KToolBar" ) )
01195   {
01196     KToolBar *bar = (KToolBar *)widget;
01197 
01198     int id_ = KAction::getToolButtonID();
01199 
01200     KInstance * instance;
01201     if ( m_parentCollection )
01202         instance = m_parentCollection->instance();
01203     else
01204         instance = KGlobal::instance();
01205 
01206     bar->insertButton( icon(), id_, SIGNAL( clicked() ), this,
01207                        SLOT( slotClicked() ), isEnabled(), plainText(),
01208                        index, instance );
01209 
01210     addContainer( bar, id_ );
01211 
01212     connect( bar, SIGNAL( destroyed() ), this, SLOT( slotDestroyed() ) );
01213 
01214     bar->setDelayedPopup( id_, d->m_popup, true);
01215 
01216     if ( !whatsThis().isEmpty() )
01217         QWhatsThis::add( bar->getButton( id_ ), whatsThisWithIcon() );
01218 
01219     return containerCount() - 1;
01220   }
01221 
01222   return KListAction::plug( widget, index );
01223 }
01224 
01225 void KRecentFilesAction::slotClicked()
01226 {
01227   KAction::slotActivated();
01228 }
01229 
01230 void KRecentFilesAction::slotActivated(const QString& text)
01231 {
01232   KListAction::slotActivated(text);
01233 }
01234 
01235 
01236 void KRecentFilesAction::slotActivated(int id)
01237 {
01238   KListAction::slotActivated(id);
01239 }
01240 
01241 
01242 void KRecentFilesAction::slotActivated()
01243 {
01244   emit activated( currentItem() );
01245   emit activated( currentText() );
01246 }
01247 
01248 
01249 class KFontAction::KFontActionPrivate
01250 {
01251 public:
01252   KFontActionPrivate()
01253   {
01254   }
01255   QStringList m_fonts;
01256 };
01257 
01258 KFontAction::KFontAction( const QString& text,
01259                           const KShortcut& cut, QObject* parent,
01260                           const char* name )
01261   : KSelectAction( text, cut, parent, name )
01262 {
01263     d = new KFontActionPrivate;
01264     KFontChooser::getFontList( d->m_fonts, 0 );
01265     KSelectAction::setItems( d->m_fonts );
01266     setEditable( true );
01267 }
01268 
01269 KFontAction::KFontAction( const QString& text, const KShortcut& cut,
01270                           const QObject* receiver, const char* slot,
01271                           QObject* parent, const char* name )
01272     : KSelectAction( text, cut, receiver, slot, parent, name )
01273 {
01274     d = new KFontActionPrivate;
01275     KFontChooser::getFontList( d->m_fonts, 0 );
01276     KSelectAction::setItems( d->m_fonts );
01277     setEditable( true );
01278 }
01279 
01280 KFontAction::KFontAction( const QString& text, const QIconSet& pix,
01281                           const KShortcut& cut,
01282                           QObject* parent, const char* name )
01283     : KSelectAction( text, pix, cut, parent, name )
01284 {
01285     d = new KFontActionPrivate;
01286     KFontChooser::getFontList( d->m_fonts, 0 );
01287     KSelectAction::setItems( d->m_fonts );
01288     setEditable( true );
01289 }
01290 
01291 KFontAction::KFontAction( const QString& text, const QString& pix,
01292                           const KShortcut& cut,
01293                           QObject* parent, const char* name )
01294     : KSelectAction( text, pix, cut, parent, name )
01295 {
01296     d = new KFontActionPrivate;
01297     KFontChooser::getFontList( d->m_fonts, 0 );
01298     KSelectAction::setItems( d->m_fonts );
01299     setEditable( true );
01300 }
01301 
01302 KFontAction::KFontAction( const QString& text, const QIconSet& pix,
01303                           const KShortcut& cut,
01304                           const QObject* receiver, const char* slot,
01305                           QObject* parent, const char* name )
01306     : KSelectAction( text, pix, cut, receiver, slot, parent, name )
01307 {
01308     d = new KFontActionPrivate;
01309     KFontChooser::getFontList( d->m_fonts, 0 );
01310     KSelectAction::setItems( d->m_fonts );
01311     setEditable( true );
01312 }
01313 
01314 KFontAction::KFontAction( const QString& text, const QString& pix,
01315                           const KShortcut& cut,
01316                           const QObject* receiver, const char* slot,
01317                           QObject* parent, const char* name )
01318     : KSelectAction( text, pix, cut, receiver, slot, parent, name )
01319 {
01320     d = new KFontActionPrivate;
01321     KFontChooser::getFontList( d->m_fonts, 0 );
01322     KSelectAction::setItems( d->m_fonts );
01323     setEditable( true );
01324 }
01325 
01326 KFontAction::KFontAction( uint fontListCriteria, const QString& text,
01327                           const KShortcut& cut, QObject* parent,
01328                           const char* name )
01329     : KSelectAction( text, cut, parent, name )
01330 {
01331     d = new KFontActionPrivate;
01332     KFontChooser::getFontList( d->m_fonts, fontListCriteria );
01333     KSelectAction::setItems( d->m_fonts );
01334     setEditable( true );
01335 }
01336 
01337 KFontAction::KFontAction( uint fontListCriteria, const QString& text, const QString& pix,
01338                           const KShortcut& cut,
01339                           QObject* parent, const char* name )
01340     : KSelectAction( text, pix, cut, parent, name )
01341 {
01342     d = new KFontActionPrivate;
01343     KFontChooser::getFontList( d->m_fonts, fontListCriteria );
01344     KSelectAction::setItems( d->m_fonts );
01345     setEditable( true );
01346 }
01347 
01348 KFontAction::KFontAction( QObject* parent, const char* name )
01349   : KSelectAction( parent, name )
01350 {
01351     d = new KFontActionPrivate;
01352     KFontChooser::getFontList( d->m_fonts, 0 );
01353     KSelectAction::setItems( d->m_fonts );
01354     setEditable( true );
01355 }
01356 
01357 KFontAction::~KFontAction()
01358 {
01359     delete d;
01360     d = 0;
01361 }
01362 
01363 /*
01364  * Maintenance note: Keep in sync with KFontCombo::setCurrentFont()
01365  */
01366 void KFontAction::setFont( const QString &family )
01367 {
01368     QString lowerName = family.lower();
01369     int i = 0;
01370     for ( QStringList::Iterator it = d->m_fonts.begin(); it != d->m_fonts.end(); ++it, ++i )
01371     {
01372        if ((*it).lower() == lowerName)
01373        {
01374           setCurrentItem(i);
01375           return;
01376        }
01377     }
01378     i = lowerName.find(" [");
01379     if (i>-1)
01380     {
01381        lowerName = lowerName.left(i);
01382        i = 0;
01383        for ( QStringList::Iterator it = d->m_fonts.begin(); it != d->m_fonts.end(); ++it, ++i )
01384        {
01385           if ((*it).lower() == lowerName)
01386           {
01387              setCurrentItem(i);
01388              return;
01389           }
01390        }
01391     }
01392 
01393     lowerName += " [";
01394     i = 0;
01395     for ( QStringList::Iterator it = d->m_fonts.begin(); it != d->m_fonts.end(); ++it, ++i )
01396     {
01397        if ((*it).lower().startsWith(lowerName))
01398        {
01399           setCurrentItem(i);
01400           return;
01401        }
01402     }
01403     kdDebug(129) << "Font not found " << family.lower() << endl;
01404 }
01405 
01406 int KFontAction::plug( QWidget *w, int index )
01407 {
01408   if (kapp && !kapp->authorizeKAction(name()))
01409     return -1;
01410   if ( w->inherits("KToolBar") )
01411   {
01412     KToolBar* bar = static_cast<KToolBar*>( w );
01413     int id_ = KAction::getToolButtonID();
01414     KFontCombo *cb = new KFontCombo( items(), bar );
01415     connect( cb, SIGNAL( activated( const QString & ) ),
01416              SLOT( slotActivated( const QString & ) ) );
01417     cb->setEnabled( isEnabled() );
01418     bar->insertWidget( id_, comboWidth(), cb, index );
01419     cb->setMinimumWidth( cb->sizeHint().width() );
01420 
01421     addContainer( bar, id_ );
01422 
01423     connect( bar, SIGNAL( destroyed() ), this, SLOT( slotDestroyed() ) );
01424 
01425     updateCurrentItem( containerCount() - 1 );
01426 
01427     return containerCount() - 1;
01428   }
01429   else return KSelectAction::plug( w, index );
01430 }
01431 
01432 class KFontSizeAction::KFontSizeActionPrivate
01433 {
01434 public:
01435   KFontSizeActionPrivate()
01436   {
01437   }
01438 };
01439 
01440 KFontSizeAction::KFontSizeAction( const QString& text,
01441                                   const KShortcut& cut,
01442                                   QObject* parent, const char* name )
01443   : KSelectAction( text, cut, parent, name )
01444 {
01445   init();
01446 }
01447 
01448 KFontSizeAction::KFontSizeAction( const QString& text,
01449                                   const KShortcut& cut,
01450                                   const QObject* receiver, const char* slot,
01451                                   QObject* parent, const char* name )
01452   : KSelectAction( text, cut, receiver, slot, parent, name )
01453 {
01454   init();
01455 }
01456 
01457 KFontSizeAction::KFontSizeAction( const QString& text, const QIconSet& pix,
01458                                   const KShortcut& cut,
01459                                   QObject* parent, const char* name )
01460   : KSelectAction( text, pix, cut, parent, name )
01461 {
01462   init();
01463 }
01464 
01465 KFontSizeAction::KFontSizeAction( const QString& text, const QString& pix,
01466                                   const KShortcut& cut,
01467                                   QObject* parent, const char* name )
01468   : KSelectAction( text, pix, cut, parent, name )
01469 {
01470   init();
01471 }
01472 
01473 KFontSizeAction::KFontSizeAction( const QString& text, const QIconSet& pix,
01474                                   const KShortcut& cut,
01475                                   const QObject* receiver,
01476                                   const char* slot, QObject* parent,
01477                                   const char* name )
01478     : KSelectAction( text, pix, cut, receiver, slot, parent, name )
01479 {
01480   init();
01481 }
01482 
01483 KFontSizeAction::KFontSizeAction( const QString& text, const QString& pix,
01484                                   const KShortcut& cut,
01485                                   const QObject* receiver,
01486                                   const char* slot, QObject* parent,
01487                                   const char* name )
01488   : KSelectAction( text, pix, cut, receiver, slot, parent, name )
01489 {
01490   init();
01491 }
01492 
01493 KFontSizeAction::KFontSizeAction( QObject* parent, const char* name )
01494   : KSelectAction( parent, name )
01495 {
01496   init();
01497 }
01498 
01499 KFontSizeAction::~KFontSizeAction()
01500 {
01501     delete d;
01502     d = 0;
01503 }
01504 
01505 void KFontSizeAction::init()
01506 {
01507     d = new KFontSizeActionPrivate;
01508 
01509     setEditable( true );
01510     QFontDatabase fontDB;
01511     QValueList<int> sizes = fontDB.standardSizes();
01512     QStringList lst;
01513     for ( QValueList<int>::Iterator it = sizes.begin(); it != sizes.end(); ++it )
01514         lst.append( QString::number( *it ) );
01515 
01516     setItems( lst );
01517 }
01518 
01519 void KFontSizeAction::setFontSize( int size )
01520 {
01521     if ( size == fontSize() ) {
01522         setCurrentItem( items().findIndex( QString::number( size ) ) );
01523         return;
01524     }
01525 
01526     if ( size < 1 ) {
01527         kdWarning() << "KFontSizeAction: Size " << size << " is out of range" << endl;
01528         return;
01529     }
01530 
01531     int index = items().findIndex( QString::number( size ) );
01532     if ( index == -1 ) {
01533         // Insert at the correct position in the list (to keep sorting)
01534         QValueList<int> lst;
01535         // Convert to list of ints
01536         QStringList itemsList = items();
01537         for (QStringList::Iterator it = itemsList.begin() ; it != itemsList.end() ; ++it)
01538             lst.append( (*it).toInt() );
01539         // New size
01540         lst.append( size );
01541         // Sort the list
01542         qHeapSort( lst );
01543         // Convert back to string list
01544         QStringList strLst;
01545         for (QValueList<int>::Iterator it = lst.begin() ; it != lst.end() ; ++it)
01546             strLst.append( QString::number(*it) );
01547         KSelectAction::setItems( strLst );
01548         // Find new current item
01549         index = lst.findIndex( size );
01550         setCurrentItem( index );
01551     }
01552     else
01553         setCurrentItem( index );
01554 
01555 
01556     //emit KAction::activated();
01557     //emit activated( index );
01558     //emit activated( QString::number( size ) );
01559     //emit fontSizeChanged( size );
01560 }
01561 
01562 int KFontSizeAction::fontSize() const
01563 {
01564   return currentText().toInt();
01565 }
01566 
01567 void KFontSizeAction::slotActivated( int index )
01568 {
01569   KSelectAction::slotActivated( index );
01570 
01571   emit fontSizeChanged( items()[ index ].toInt() );
01572 }
01573 
01574 void KFontSizeAction::slotActivated( const QString& size )
01575 {
01576   setFontSize( size.toInt() ); // insert sorted first
01577   KSelectAction::slotActivated( size );
01578   emit fontSizeChanged( size.toInt() );
01579 }
01580 
01581 class KActionMenu::KActionMenuPrivate
01582 {
01583 public:
01584   KActionMenuPrivate()
01585   {
01586     m_popup = new KPopupMenu(0L,"KActionMenu::KActionMenuPrivate");
01587     m_delayed = true;
01588     m_stickyMenu = true;
01589   }
01590   ~KActionMenuPrivate()
01591   {
01592     delete m_popup; m_popup = 0;
01593   }
01594   KPopupMenu *m_popup;
01595   bool m_delayed;
01596   bool m_stickyMenu;
01597 };
01598 
01599 KActionMenu::KActionMenu( QObject* parent, const char* name )
01600   : KAction( parent, name )
01601 {
01602   d = new KActionMenuPrivate;
01603   setShortcutConfigurable( false );
01604 }
01605 
01606 KActionMenu::KActionMenu( const QString& text, QObject* parent,
01607                           const char* name )
01608   : KAction( text, 0, parent, name )
01609 {
01610   d = new KActionMenuPrivate;
01611   setShortcutConfigurable( false );
01612 }
01613 
01614 KActionMenu::KActionMenu( const QString& text, const QIconSet& icon,
01615                           QObject* parent, const char* name )
01616   : KAction( text, icon, 0, parent, name )
01617 {
01618   d = new KActionMenuPrivate;
01619   setShortcutConfigurable( false );
01620 }
01621 
01622 KActionMenu::KActionMenu( const QString& text, const QString& icon,
01623                           QObject* parent, const char* name )
01624   : KAction( text, icon, 0, parent, name )
01625 {
01626   d = new KActionMenuPrivate;
01627   setShortcutConfigurable( false );
01628 }
01629 
01630 KActionMenu::~KActionMenu()
01631 {
01632     unplugAll();
01633     kdDebug(129) << "KActionMenu::~KActionMenu()" << endl; // ellis
01634     delete d; d = 0;
01635 }
01636 
01637 void KActionMenu::popup( const QPoint& global )
01638 {
01639   popupMenu()->popup( global );
01640 }
01641 
01642 KPopupMenu* KActionMenu::popupMenu() const
01643 {
01644   return d->m_popup;
01645 }
01646 
01647 void KActionMenu::insert( KAction* cmd, int index )
01648 {
01649   if ( cmd )
01650     cmd->plug( d->m_popup, index );
01651 }
01652 
01653 void KActionMenu::remove( KAction* cmd )
01654 {
01655   if ( cmd )
01656     cmd->unplug( d->m_popup );
01657 }
01658 
01659 bool KActionMenu::delayed() const {
01660     return d->m_delayed;
01661 }
01662 
01663 void KActionMenu::setDelayed(bool _delayed) {
01664     d->m_delayed = _delayed;
01665 }
01666 
01667 bool KActionMenu::stickyMenu() const {
01668     return d->m_stickyMenu;
01669 }
01670 
01671 void KActionMenu::setStickyMenu(bool sticky) {
01672     d->m_stickyMenu = sticky;
01673 }
01674 
01675 int KActionMenu::plug( QWidget* widget, int index )
01676 {
01677   if (kapp && !kapp->authorizeKAction(name()))
01678     return -1;
01679   kdDebug(129) << "KAction::plug( " << widget << ", " << index << " )" << endl; // remove -- ellis
01680   if ( widget->inherits("QPopupMenu") )
01681   {
01682     QPopupMenu* menu = static_cast<QPopupMenu*>( widget );
01683     int id;
01684     if ( hasIconSet() )
01685       id = menu->insertItem( iconSet(), text(), d->m_popup, -1, index );
01686     else
01687       id = menu->insertItem( text(), d->m_popup, -1, index );
01688 
01689     if ( !isEnabled() )
01690       menu->setItemEnabled( id, false );
01691 
01692     addContainer( menu, id );
01693     connect( menu, SIGNAL( destroyed() ), this, SLOT( slotDestroyed() ) );
01694 
01695     if ( m_parentCollection )
01696       m_parentCollection->connectHighlight( menu, this );
01697 
01698     return containerCount() - 1;
01699   }
01700   else if ( widget->inherits( "KToolBar" ) )
01701   {
01702     KToolBar *bar = static_cast<KToolBar *>( widget );
01703 
01704     int id_ = KAction::getToolButtonID();
01705 
01706     if ( icon().isEmpty() && !iconSet().isNull() )
01707       bar->insertButton( iconSet().pixmap(), id_, SIGNAL( clicked() ), this,
01708                          SLOT( slotActivated() ), isEnabled(), plainText(),
01709                          index );
01710     else
01711     {
01712       KInstance *instance;
01713 
01714       if ( m_parentCollection )
01715         instance = m_parentCollection->instance();
01716       else
01717         instance = KGlobal::instance();
01718 
01719       bar->insertButton( icon(), id_, SIGNAL( clicked() ), this,
01720                          SLOT( slotActivated() ), isEnabled(), plainText(),
01721                          index, instance );
01722     }
01723 
01724     addContainer( bar, id_ );
01725 
01726     if (!whatsThis().isEmpty())
01727       QWhatsThis::add( bar->getButton(id_), whatsThis() );
01728 
01729     connect( bar, SIGNAL( destroyed() ), this, SLOT( slotDestroyed() ) );
01730 
01731     if (delayed()) {
01732         bar->setDelayedPopup( id_, popupMenu(), stickyMenu() );
01733     } else {
01734         bar->getButton(id_)->setPopup(popupMenu(), stickyMenu() );
01735     }
01736 
01737     if ( m_parentCollection )
01738       m_parentCollection->connectHighlight( bar, this );
01739 
01740     return containerCount() - 1;
01741   }
01742   else if ( widget->inherits( "QMenuBar" ) )
01743   {
01744     QMenuBar *bar = static_cast<QMenuBar *>( widget );
01745 
01746     int id;
01747 
01748     id = bar->insertItem( text(), popupMenu(), -1, index );
01749 
01750     if ( !isEnabled() )
01751         bar->setItemEnabled( id, false );
01752 
01753     addContainer( bar, id );
01754     connect( bar, SIGNAL( destroyed() ), this, SLOT( slotDestroyed() ) );
01755 
01756     return containerCount() - 1;
01757   }
01758 
01759   return -1;
01760 }
01761 
01763 
01764 KToolBarPopupAction::KToolBarPopupAction( const QString& text,
01765                                           const QString& icon,
01766                                           const KShortcut& cut,
01767                                           QObject* parent, const char* name )
01768   : KAction( text, icon, cut, parent, name )
01769 {
01770   m_popup = 0;
01771   m_delayed = true;
01772   m_stickyMenu = true;
01773 }
01774 
01775 KToolBarPopupAction::KToolBarPopupAction( const QString& text,
01776                                           const QString& icon,
01777                                           const KShortcut& cut,
01778                                           const QObject* receiver,
01779                                           const char* slot, QObject* parent,
01780                                           const char* name )
01781   : KAction( text, icon, cut, receiver, slot, parent, name )
01782 {
01783   m_popup = 0;
01784   m_delayed = true;
01785   m_stickyMenu = true;
01786 }
01787 
01788 KToolBarPopupAction::KToolBarPopupAction( const KGuiItem& item,
01789                                           const KShortcut& cut,
01790                                           const QObject* receiver,
01791                                           const char* slot, KActionCollection* parent,
01792                                           const char* name )
01793   : KAction( item, cut, receiver, slot, parent, name )
01794 {
01795   m_popup = 0;
01796   m_delayed = true;
01797   m_stickyMenu = true;
01798 }
01799 
01800 KToolBarPopupAction::~KToolBarPopupAction()
01801 {
01802   if ( m_popup )
01803     delete m_popup;
01804 }
01805 
01806 bool KToolBarPopupAction::delayed() const {
01807     return m_delayed;
01808 }
01809 
01810 void KToolBarPopupAction::setDelayed(bool delayed) {
01811     m_delayed = delayed;
01812 }
01813 
01814 bool KToolBarPopupAction::stickyMenu() const {
01815     return m_stickyMenu;
01816 }
01817 
01818 void KToolBarPopupAction::setStickyMenu(bool sticky) {
01819     m_stickyMenu = sticky;
01820 }
01821 
01822 int KToolBarPopupAction::plug( QWidget *widget, int index )
01823 {
01824   if (kapp && !kapp->authorizeKAction(name()))
01825     return -1;
01826   // This is very related to KActionMenu::plug.
01827   // In fact this class could be an interesting base class for KActionMenu
01828   if ( widget->inherits( "KToolBar" ) )
01829   {
01830     KToolBar *bar = (KToolBar *)widget;
01831 
01832     int id_ = KAction::getToolButtonID();
01833 
01834     if ( icon().isEmpty() && !iconSet().isNull() ) {
01835         bar->insertButton( iconSet().pixmap(), id_, SIGNAL( clicked() ), this,
01836                            SLOT( slotActivated() ), isEnabled(), plainText(),
01837                            index );
01838     } else {
01839         KInstance * instance;
01840         if ( m_parentCollection )
01841             instance = m_parentCollection->instance();
01842         else
01843             instance = KGlobal::instance();
01844 
01845         bar->insertButton( icon(), id_, SIGNAL( clicked() ), this,
01846                            SLOT( slotActivated() ), isEnabled(), plainText(),
01847                            index, instance );
01848     }
01849 
01850     addContainer( bar, id_ );
01851 
01852     connect( bar, SIGNAL( destroyed() ), this, SLOT( slotDestroyed() ) );
01853 
01854     if (delayed()) {
01855         bar->setDelayedPopup( id_, popupMenu(), stickyMenu() );
01856     } else {
01857         bar->getButton(id_)->setPopup(popupMenu(), stickyMenu());
01858     }
01859 
01860     if ( !whatsThis().isEmpty() )
01861         QWhatsThis::add( bar->getButton( id_ ), whatsThisWithIcon() );
01862 
01863     return containerCount() - 1;
01864   }
01865 
01866   return KAction::plug( widget, index );
01867 }
01868 
01869 KPopupMenu *KToolBarPopupAction::popupMenu() const
01870 {
01871     if ( !m_popup ) {
01872         KToolBarPopupAction *that = const_cast<KToolBarPopupAction*>(this);
01873         that->m_popup = new KPopupMenu;
01874     }
01875     return m_popup;
01876 }
01877 
01879 
01880 KToggleToolBarAction::KToggleToolBarAction( const char* toolBarName,
01881          const QString& text, KActionCollection* parent, const char* name )
01882   : KToggleAction( text, KShortcut(), parent, name )
01883   , m_toolBarName( toolBarName )
01884   , m_toolBar( 0L )
01885 {
01886 }
01887 
01888 KToggleToolBarAction::KToggleToolBarAction( KToolBar *toolBar, const QString &text,
01889                                             KActionCollection *parent, const char *name )
01890   : KToggleAction( text, KShortcut(), parent, name )
01891   , m_toolBarName( 0 ), m_toolBar( toolBar )
01892 {
01893 }
01894 
01895 KToggleToolBarAction::~KToggleToolBarAction()
01896 {
01897 }
01898 
01899 int KToggleToolBarAction::plug( QWidget* w, int index )
01900 {
01901   if (kapp && !kapp->authorizeKAction(name()))
01902       return -1;
01903 
01904   if ( !m_toolBar ) {
01905     // Note: topLevelWidget() stops too early, we can't use it.
01906     QWidget * tl = w;
01907     QWidget * n;
01908     while ( !tl->isDialog() && ( n = tl->parentWidget() ) ) // lookup parent and store
01909       tl = n;
01910 
01911     KMainWindow * mw = dynamic_cast<KMainWindow *>(tl); // try to see if it's a kmainwindow
01912 
01913     if ( mw )
01914         m_toolBar = mw->toolBar( m_toolBarName );
01915   }
01916 
01917   if( m_toolBar ) {
01918     setChecked( m_toolBar->isVisible() );
01919     connect( m_toolBar, SIGNAL(visibilityChanged(bool)), this, SLOT(setChecked(bool)) );
01920     // Also emit toggled when the toolbar's visibility changes (see comment in header)
01921     connect( m_toolBar, SIGNAL(visibilityChanged(bool)), this, SIGNAL(toggled(bool)) );
01922   } else {
01923     setEnabled( false );
01924   }
01925 
01926   return KToggleAction::plug( w, index );
01927 }
01928 
01929 void KToggleToolBarAction::setChecked( bool c )
01930 {
01931   if( m_toolBar && c != m_toolBar->isVisible() ) {
01932     if( c ) {
01933       m_toolBar->show();
01934     } else {
01935       m_toolBar->hide();
01936     }
01937     QMainWindow* mw = m_toolBar->mainWindow();
01938     if ( mw && mw->inherits( "KMainWindow" ) )
01939       static_cast<KMainWindow *>( mw )->setSettingsDirty();
01940   }
01941   KToggleAction::setChecked( c );
01942 }
01943 
01945 
01946 KToggleFullScreenAction::KToggleFullScreenAction( const KShortcut &cut,
01947                              const QObject* receiver, const char* slot,
01948                              QObject* parent, QWidget* window,
01949                              const char* name )
01950   : KToggleAction( QString::null, cut, receiver, slot, parent, name ),
01951     window( NULL )
01952 {
01953   setWindow( window );
01954 }
01955 
01956 KToggleFullScreenAction::~KToggleFullScreenAction()
01957 {
01958 }
01959 
01960 void KToggleFullScreenAction::setWindow( QWidget* w )
01961 {
01962   if( window )
01963     window->removeEventFilter( this );
01964   window = w;
01965   if( window )
01966     window->installEventFilter( this );
01967 }
01968 
01969 void KToggleFullScreenAction::setChecked( bool c )
01970 {
01971   if (c)
01972   {
01973      setText(i18n("Exit F&ull Screen Mode"));
01974      setIcon("window_nofullscreen");
01975   }
01976   else
01977   {
01978      setText(i18n("F&ull Screen Mode"));
01979      setIcon("window_fullscreen");
01980   }
01981   KToggleAction::setChecked( c );
01982 }
01983 
01984 bool KToggleFullScreenAction::eventFilter( QObject* o, QEvent* e )
01985 {
01986     if( o == window )
01987 #if QT_VERSION >= 0x030300
01988         if( e->type() == QEvent::WindowStateChange )
01989 #else
01990         if( e->type() == QEvent::ShowFullScreen || e->type() == QEvent::ShowNormal
01991             || e->type() == QEvent::ShowMaximized || e->type() == QEvent::ShowMinimized )
01992 #endif
01993             {
01994             if( window->isFullScreen() != isChecked())
01995                 slotActivated(); // setChecked( window->isFullScreen()) wouldn't emit signals
01996             }
01997     return false;
01998 }
01999 
02001 
02002 KWidgetAction::KWidgetAction( QWidget* widget,
02003     const QString& text, const KShortcut& cut,
02004     const QObject* receiver, const char* slot,
02005     KActionCollection* parent, const char* name )
02006   : KAction( text, cut, receiver, slot, parent, name )
02007   , m_widget( widget )
02008   , m_autoSized( false )
02009 {
02010 }
02011 
02012 KWidgetAction::~KWidgetAction()
02013 {
02014 }
02015 
02016 void KWidgetAction::setAutoSized( bool autoSized )
02017 {
02018   if( m_autoSized == autoSized )
02019     return;
02020 
02021   m_autoSized = autoSized;
02022 
02023   if( !m_widget || !isPlugged() )
02024     return;
02025 
02026   KToolBar* toolBar = (KToolBar*)m_widget->parent();
02027   int i = findContainer( toolBar );
02028   if ( i == -1 )
02029     return;
02030   int id = itemId( i );
02031 
02032   toolBar->setItemAutoSized( id, m_autoSized );
02033 }
02034 
02035 int KWidgetAction::plug( QWidget* w, int index )
02036 {
02037   if (kapp && !kapp->authorizeKAction(name()))
02038       return -1;
02039 
02040   if ( !w->inherits( "KToolBar" ) ) {
02041     kdError() << "KWidgetAction::plug: KWidgetAction must be plugged into KToolBar." << endl;
02042     return -1;
02043   }
02044   if ( !m_widget ) {
02045     kdError() << "KWidgetAction::plug: Widget was deleted or null!" << endl;
02046     return -1;
02047   }
02048 
02049   KToolBar* toolBar = static_cast<KToolBar*>( w );
02050 
02051   int id = KAction::getToolButtonID();
02052 
02053   m_widget->reparent( toolBar, QPoint() );
02054   toolBar->insertWidget( id, 0, m_widget, index );
02055   toolBar->setItemAutoSized( id, m_autoSized );
02056 
02057   QWhatsThis::add( m_widget, whatsThis() );
02058   addContainer( toolBar, id );
02059 
02060   connect( toolBar, SIGNAL( toolbarDestroyed() ), this, SLOT( slotToolbarDestroyed() ) );
02061   connect( toolBar, SIGNAL( destroyed() ), this, SLOT( slotDestroyed() ) );
02062 
02063   return containerCount() - 1;
02064 }
02065 
02066 void KWidgetAction::unplug( QWidget *w )
02067 {
02068   if( !m_widget || !isPlugged() )
02069     return;
02070 
02071   KToolBar* toolBar = (KToolBar*)m_widget->parent();
02072   if ( toolBar == w )
02073   {
02074       disconnect( toolBar, SIGNAL( toolbarDestroyed() ), this, SLOT( slotToolbarDestroyed() ) );
02075       m_widget->reparent( 0L, QPoint(), false /*showIt*/ );
02076   }
02077   KAction::unplug( w );
02078 }
02079 
02080 void KWidgetAction::slotToolbarDestroyed()
02081 {
02082   //Q_ASSERT( m_widget ); // When exiting the app the widget could be destroyed before the toolbar.
02083   Q_ASSERT( isPlugged() );
02084   if( !m_widget || !isPlugged() )
02085     return;
02086 
02087   // Don't let a toolbar being destroyed, delete my widget.
02088   m_widget->reparent( 0L, QPoint(), false /*showIt*/ );
02089 }
02090 
02092 
02093 KActionSeparator::KActionSeparator( QObject *parent, const char *name )
02094   : KAction( parent, name )
02095 {
02096 }
02097 
02098 KActionSeparator::~KActionSeparator()
02099 {
02100 }
02101 
02102 int KActionSeparator::plug( QWidget *widget, int index )
02103 {
02104   if ( widget->inherits("QPopupMenu") )
02105   {
02106     QPopupMenu* menu = static_cast<QPopupMenu*>( widget );
02107 
02108     int id = menu->insertSeparator( index );
02109 
02110     addContainer( menu, id );
02111     connect( menu, SIGNAL( destroyed() ), this, SLOT( slotDestroyed() ) );
02112 
02113     return containerCount() - 1;
02114   }
02115   else if ( widget->inherits( "QMenuBar" ) )
02116   {
02117     QMenuBar *menuBar = static_cast<QMenuBar *>( widget );
02118 
02119     int id = menuBar->insertSeparator( index );
02120 
02121     addContainer( menuBar, id );
02122 
02123     connect( menuBar, SIGNAL( destroyed() ), this, SLOT( slotDestroyed() ) );
02124 
02125     return containerCount() - 1;
02126   }
02127   else if ( widget->inherits( "KToolBar" ) )
02128   {
02129     KToolBar *toolBar = static_cast<KToolBar *>( widget );
02130 
02131     int id = toolBar->insertSeparator( index );
02132 
02133     addContainer( toolBar, id );
02134 
02135     connect( toolBar, SIGNAL( destroyed() ), this, SLOT( slotDestroyed() ) );
02136 
02137     return containerCount() - 1;
02138   }
02139 
02140   return -1;
02141 }
02142 
02143 KPasteTextAction::KPasteTextAction( const QString& text,
02144                             const QString& icon,
02145                             const KShortcut& cut,
02146                             const QObject* receiver,
02147                             const char* slot, QObject* parent,
02148                             const char* name)
02149   : KAction( text, icon, cut, receiver, slot, parent, name )
02150 {
02151   m_popup = new KPopupMenu;
02152   connect(m_popup, SIGNAL(aboutToShow()), this, SLOT(menuAboutToShow()));
02153   connect(m_popup, SIGNAL(activated(int)), this, SLOT(menuItemActivated(int)));
02154   m_popup->setCheckable(true);
02155   m_mixedMode = true;
02156 }
02157 
02158 KPasteTextAction::~KPasteTextAction()
02159 {
02160   delete m_popup;
02161 }
02162 
02163 void KPasteTextAction::setMixedMode(bool mode)
02164 {
02165   m_mixedMode = mode;
02166 }
02167 
02168 int KPasteTextAction::plug( QWidget *widget, int index )
02169 {
02170   if (kapp && !kapp->authorizeKAction(name()))
02171     return -1;
02172   if ( widget->inherits( "KToolBar" ) )
02173   {
02174     KToolBar *bar = (KToolBar *)widget;
02175 
02176     int id_ = KAction::getToolButtonID();
02177 
02178     KInstance * instance;
02179     if ( m_parentCollection )
02180         instance = m_parentCollection->instance();
02181     else
02182         instance = KGlobal::instance();
02183 
02184     bar->insertButton( icon(), id_, SIGNAL( clicked() ), this,
02185                        SLOT( slotActivated() ), isEnabled(), plainText(),
02186                        index, instance );
02187 
02188     addContainer( bar, id_ );
02189 
02190     connect( bar, SIGNAL( destroyed() ), this, SLOT( slotDestroyed() ) );
02191 
02192     bar->setDelayedPopup( id_, m_popup, true );
02193 
02194     if ( !whatsThis().isEmpty() )
02195         QWhatsThis::add( bar->getButton( id_ ), whatsThisWithIcon() );
02196 
02197     return containerCount() - 1;
02198   }
02199 
02200   return KAction::plug( widget, index );
02201 }
02202 
02203 void KPasteTextAction::menuAboutToShow()
02204 {
02205     m_popup->clear();
02206     QStringList list;
02207     DCOPClient *client = kapp->dcopClient();
02208     if (client->isAttached() && client->isApplicationRegistered("klipper")) {
02209       DCOPRef klipper("klipper","klipper");
02210       DCOPReply reply = klipper.call("getClipboardHistoryMenu");
02211       if (reply.isValid())
02212         list = reply;
02213     }
02214     QString clipboardText = qApp->clipboard()->text(QClipboard::Clipboard);
02215     clipboardText.replace("&", "&&");
02216     clipboardText = KStringHandler::csqueeze(clipboardText, 45);
02217     if (list.isEmpty())
02218         list << clipboardText;
02219     bool found = false;
02220     for ( QStringList::Iterator it = list.begin(); it != list.end(); ++it )
02221     {
02222       int id = m_popup->insertItem(*it);
02223       if (!found && *it == clipboardText)
02224       {
02225         m_popup->setItemChecked(id, true);
02226         found = true;
02227       }
02228     }
02229 }
02230 
02231 void KPasteTextAction::menuItemActivated( int id)
02232 {
02233     DCOPClient *client = kapp->dcopClient();
02234     if (client->isAttached() && client->isApplicationRegistered("klipper")) {
02235       DCOPRef klipper("klipper","klipper");
02236       DCOPReply reply = klipper.call("getClipboardHistoryItem(int)", m_popup->indexOf(id));
02237       if (!reply.isValid())
02238         return;
02239       QString clipboardText = reply;
02240       reply = klipper.call("setClipboardContents(QString)", clipboardText);
02241       if (reply.isValid())
02242         kdDebug(129) << "Clipboard: " << qApp->clipboard()->text(QClipboard::Clipboard) << endl;
02243     }
02244     QTimer::singleShot(20, this, SLOT(slotActivated()));
02245 }
02246 
02247 void KPasteTextAction::slotActivated()
02248 {
02249   if (!m_mixedMode) {
02250     QWidget *w = qApp->widgetAt(QCursor::pos(), true);
02251     QMimeSource *data = QApplication::clipboard()->data();
02252     if (!data->provides("text/plain") && w) {
02253       m_popup->popup(w->mapToGlobal(QPoint(0, w->height())));
02254     } else
02255       KAction::slotActivated();
02256   } else
02257     KAction::slotActivated();
02258 }
02259 
02260 
02261 void KToggleAction::virtual_hook( int id, void* data )
02262 { KAction::virtual_hook( id, data ); }
02263 
02264 void KRadioAction::virtual_hook( int id, void* data )
02265 { KToggleAction::virtual_hook( id, data ); }
02266 
02267 void KSelectAction::virtual_hook( int id, void* data )
02268 { KAction::virtual_hook( id, data ); }
02269 
02270 void KListAction::virtual_hook( int id, void* data )
02271 { KSelectAction::virtual_hook( id, data ); }
02272 
02273 void KRecentFilesAction::virtual_hook( int id, void* data )
02274 { KListAction::virtual_hook( id, data ); }
02275 
02276 void KFontAction::virtual_hook( int id, void* data )
02277 { KSelectAction::virtual_hook( id, data ); }
02278 
02279 void KFontSizeAction::virtual_hook( int id, void* data )
02280 { KSelectAction::virtual_hook( id, data ); }
02281 
02282 void KActionMenu::virtual_hook( int id, void* data )
02283 { KAction::virtual_hook( id, data ); }
02284 
02285 void KToolBarPopupAction::virtual_hook( int id, void* data )
02286 { KAction::virtual_hook( id, data ); }
02287 
02288 void KToggleToolBarAction::virtual_hook( int id, void* data )
02289 { KToggleAction::virtual_hook( id, data ); }
02290 
02291 void KToggleFullScreenAction::virtual_hook( int id, void* data )
02292 { KToggleAction::virtual_hook( id, data ); }
02293 
02294 void KWidgetAction::virtual_hook( int id, void* data )
02295 { KAction::virtual_hook( id, data ); }
02296 
02297 void KActionSeparator::virtual_hook( int id, void* data )
02298 { KAction::virtual_hook( id, data ); }
02299 
02300 void KPasteTextAction::virtual_hook( int id, void* data )
02301 { KAction::virtual_hook( id, data ); }
02302 
02303 /* vim: et sw=2 ts=2
02304  */
02305 
02306 #include "kactionclasses.moc"
KDE Logo
This file is part of the documentation for kdeui Library Version 3.3.0.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Sat Nov 27 13:42:54 2004 by doxygen 1.3.9.1 written by Dimitri van Heesch, © 1997-2003