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