kdeui Library API Documentation

kactionclasses.cpp

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