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