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 ( !::qt_cast<QPopupMenu *>( widget ) && !::qt_cast<KToolBar *>( widget ) ) 00137 { 00138 kdWarning() << "Can not plug KToggleAction in " << widget->className() << endl; 00139 return -1; 00140 } 00141 if (kapp && !kapp->authorizeKAction(name())) 00142 return -1; 00143 00144 int _index = KAction::plug( widget, index ); 00145 if ( _index == -1 ) 00146 return _index; 00147 00148 if ( ::qt_cast<KToolBar *>( widget ) ) { 00149 KToolBar *bar = static_cast<KToolBar *>( widget ); 00150 00151 bar->setToggle( itemId( _index ), true ); 00152 bar->setButton( itemId( _index ), isChecked() ); 00153 } 00154 00155 if ( d->m_checked ) 00156 updateChecked( _index ); 00157 00158 return _index; 00159 } 00160 00161 void KToggleAction::setChecked( bool c ) 00162 { 00163 if ( c == d->m_checked ) 00164 return; 00165 //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 ( ::qt_cast<KToggleAction *>( it.current() ) && it.current() != this && 00180 static_cast<KToggleAction*>(it.current())->exclusiveGroup() == exclusiveGroup() ) { 00181 KToggleAction *a = static_cast<KToggleAction*>(it.current()); 00182 if( a->isChecked() ) { 00183 a->setChecked( false ); 00184 emit a->toggled( false ); 00185 } 00186 } 00187 } 00188 } 00189 } 00190 } 00191 00192 void KToggleAction::updateChecked( int id ) 00193 { 00194 QWidget *w = container( id ); 00195 00196 if ( ::qt_cast<QPopupMenu *>( w ) ) { 00197 QPopupMenu* pm = static_cast<QPopupMenu*>(w); 00198 int itemId_ = itemId( id ); 00199 if ( !d->m_checkedGuiItem ) 00200 pm->setItemChecked( itemId_, d->m_checked ); 00201 else { 00202 const KGuiItem* gui = d->m_checked ? d->m_checkedGuiItem : &guiItem(); 00203 if ( d->m_checkedGuiItem->hasIcon() ) 00204 pm->changeItem( itemId_, gui->iconSet( KIcon::Small ), gui->text() ); 00205 else 00206 pm->changeItem( itemId_, gui->text() ); 00207 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 ( ::qt_cast<QMenuBar *>( w ) ) // not handled in plug... 00213 static_cast<QMenuBar*>(w)->setItemChecked( itemId( id ), d->m_checked ); 00214 else if ( ::qt_cast<KToolBar *>( w ) ) 00215 { 00216 QWidget* r = static_cast<KToolBar*>( w )->getButton( itemId( id ) ); 00217 if ( r && ::qt_cast<KToolBarButton *>( r ) ) { 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 KAction::slotActivated(); 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 || !::qt_cast<const KToolBarButton *>( senderObj ) ) 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 ( ::qt_cast<KToolBar *>( w ) ) 00523 { 00524 QWidget* r = (static_cast<KToolBar*>( w ))->getWidget( itemId( id ) ); 00525 if ( ::qt_cast<QComboBox *>( r ) ) 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 ( ::qt_cast<KToolBar *>( w ) ) { 00573 QWidget* r = static_cast<KToolBar*>( w )->getWidget( itemId( id ) ); 00574 if ( ::qt_cast<QComboBox *>( r ) ) { 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 ( ::qt_cast<KToolBar *>( w ) ) { 00590 QWidget* r = static_cast<KToolBar*>( w )->getWidget( itemId( id ) ); 00591 if ( ::qt_cast<QComboBox *>( r ) ) { 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 ( ::qt_cast<KToolBar *>( w ) ) { 00604 QWidget* r = static_cast<KToolBar*>( w )->getWidget( itemId( id ) ); 00605 if ( ::qt_cast<QComboBox *>( r ) ) { 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 // qt caches and never recalculates the sizeHint() 00613 // qcombobox.cpp recommends calling setFont to invalidate the sizeHint 00614 // setFont sets own_font = True, so we're a bit mean and calll 00615 // unsetFont which calls setFont and then overwrites the own_font 00616 cb->unsetFont(); 00617 } 00618 } 00619 } 00620 00621 int KSelectAction::plug( QWidget *widget, int index ) 00622 { 00623 if (kapp && !kapp->authorizeKAction(name())) 00624 return -1; 00625 kdDebug(129) << "KAction::plug( " << widget << ", " << index << " )" << endl; // remove -- ellis 00626 if ( ::qt_cast<QPopupMenu *>( widget) ) 00627 { 00628 // Create the PopupMenu and store it in m_menu 00629 (void)popupMenu(); 00630 00631 QPopupMenu* menu = static_cast<QPopupMenu*>( widget ); 00632 int id; 00633 if ( hasIcon() ) 00634 id = menu->insertItem( iconSet(), text(), d->m_menu, -1, index ); 00635 else 00636 id = menu->insertItem( text(), d->m_menu, -1, index ); 00637 00638 if ( !isEnabled() ) 00639 menu->setItemEnabled( id, false ); 00640 00641 QString wth = whatsThis(); 00642 if ( !wth.isEmpty() ) 00643 menu->setWhatsThis( id, wth ); 00644 00645 addContainer( menu, id ); 00646 connect( menu, SIGNAL( destroyed() ), this, SLOT( slotDestroyed() ) ); 00647 00648 return containerCount() - 1; 00649 } 00650 else if ( ::qt_cast<KToolBar *>( widget ) ) 00651 { 00652 KToolBar* bar = static_cast<KToolBar*>( widget ); 00653 int id_ = KAction::getToolButtonID(); 00654 bar->insertCombo( comboItems(), id_, isEditable(), 00655 SIGNAL( activated( const QString & ) ), this, 00656 SLOT( slotActivated( const QString & ) ), isEnabled(), 00657 toolTip(), -1, index ); 00658 00659 QComboBox *cb = bar->getCombo( id_ ); 00660 if ( cb ) 00661 { 00662 if (!isEditable()) cb->setFocusPolicy(QWidget::NoFocus); 00663 cb->setMinimumWidth( cb->sizeHint().width() ); 00664 if ( d->m_comboWidth > 0 ) 00665 { 00666 cb->setMinimumWidth( d->m_comboWidth ); 00667 cb->setMaximumWidth( d->m_comboWidth ); 00668 } 00669 cb->setInsertionPolicy( QComboBox::NoInsertion ); 00670 QWhatsThis::add( cb, whatsThis() ); 00671 } 00672 00673 addContainer( bar, id_ ); 00674 00675 connect( bar, SIGNAL( destroyed() ), this, SLOT( slotDestroyed() ) ); 00676 00677 updateCurrentItem( containerCount() - 1 ); 00678 00679 return containerCount() - 1; 00680 } 00681 else if ( ::qt_cast<QMenuBar *>( widget ) ) 00682 { 00683 // Create the PopupMenu and store it in m_menu 00684 (void)popupMenu(); 00685 00686 QMenuBar* menu = static_cast<QMenuBar*>( widget ); 00687 int id = menu->insertItem( text(), d->m_menu, -1, index ); 00688 00689 if ( !isEnabled() ) 00690 menu->setItemEnabled( id, false ); 00691 00692 QString wth = whatsThis(); 00693 if ( !wth.isEmpty() ) 00694 menu->setWhatsThis( id, wth ); 00695 00696 addContainer( menu, id ); 00697 connect( menu, SIGNAL( destroyed() ), this, SLOT( slotDestroyed() ) ); 00698 00699 return containerCount() - 1; 00700 } 00701 00702 kdWarning() << "Can not plug KAction in " << widget->className() << endl; 00703 return -1; 00704 } 00705 00706 QStringList KSelectAction::comboItems() const 00707 { 00708 if( d->m_menuAccelsEnabled ) { 00709 QStringList lst; 00710 QStringList::ConstIterator it = d->m_list.begin(); 00711 for( ; it != d->m_list.end(); ++it ) 00712 { 00713 QString item = *it; 00714 int i = item.find( '&' ); 00715 if ( i > -1 ) 00716 item = item.remove( i, 1 ); 00717 lst.append( item ); 00718 } 00719 return lst; 00720 } 00721 else 00722 return d->m_list; 00723 } 00724 00725 void KSelectAction::clear() 00726 { 00727 if ( d->m_menu ) 00728 d->m_menu->clear(); 00729 00730 int len = containerCount(); 00731 for( int i = 0; i < len; ++i ) 00732 updateClear( i ); 00733 } 00734 00735 void KSelectAction::updateClear( int id ) 00736 { 00737 QWidget* w = container( id ); 00738 if ( ::qt_cast<KToolBar *>( w ) ) { 00739 QWidget* r = static_cast<KToolBar*>( w )->getWidget( itemId( id ) ); 00740 if ( ::qt_cast<QComboBox *>( r ) ) { 00741 QComboBox *b = static_cast<QComboBox*>( r ); 00742 b->clear(); 00743 } 00744 } 00745 } 00746 00747 void KSelectAction::slotActivated( int id ) 00748 { 00749 if ( d->m_current == id ) 00750 return; 00751 00752 setCurrentItem( id ); 00753 // Delay this. Especially useful when the slot connected to activated() will re-create 00754 // the menu, e.g. in the recent files action. This prevents a crash. 00755 QTimer::singleShot( 0, this, SLOT( slotActivated() ) ); 00756 } 00757 00758 void KSelectAction::slotActivated( const QString &text ) 00759 { 00760 if ( isEditable() ) 00761 { 00762 QStringList lst = items(); 00763 if(!lst.contains(text)) 00764 { 00765 lst.append( text ); 00766 setItems( lst ); 00767 } 00768 } 00769 00770 int i = items().findIndex( text ); 00771 if ( i > -1 ) 00772 setCurrentItem( i ); 00773 else 00774 setCurrentItem( comboItems().findIndex( text ) ); 00775 // Delay this. Especially useful when the slot connected to activated() will re-create 00776 // the menu, e.g. in the recent files action. This prevents a crash. 00777 QTimer::singleShot( 0, this, SLOT( slotActivated() ) ); 00778 } 00779 00780 void KSelectAction::slotActivated() 00781 { 00782 KAction::slotActivated(); 00783 kdDebug(129) << "KSelectAction::slotActivated currentItem=" << currentItem() << " currentText=" << currentText() << endl; 00784 emit activated( currentItem() ); 00785 emit activated( currentText() ); 00786 } 00787 00788 void KSelectAction::setEditable( bool edit ) 00789 { 00790 d->m_edit = edit; 00791 } 00792 00793 bool KSelectAction::isEditable() const 00794 { 00795 return d->m_edit; 00796 } 00797 00798 void KSelectAction::setRemoveAmpersandsInCombo( bool b ) 00799 { 00800 setMenuAccelsEnabled( b ); 00801 } 00802 00803 bool KSelectAction::removeAmpersandsInCombo() const 00804 { 00805 return menuAccelsEnabled( ); 00806 } 00807 00808 void KSelectAction::setMenuAccelsEnabled( bool b ) 00809 { 00810 d->m_menuAccelsEnabled = b; 00811 } 00812 00813 bool KSelectAction::menuAccelsEnabled() const 00814 { 00815 return d->m_menuAccelsEnabled; 00816 } 00817 00818 class KListAction::KListActionPrivate 00819 { 00820 public: 00821 KListActionPrivate() 00822 { 00823 m_current = 0; 00824 } 00825 int m_current; 00826 }; 00827 00828 KListAction::KListAction( const QString& text, const KShortcut& cut, 00829 QObject* parent, const char* name ) 00830 : KSelectAction( text, cut, parent, name ) 00831 { 00832 d = new KListActionPrivate; 00833 } 00834 00835 KListAction::KListAction( const QString& text, const KShortcut& cut, 00836 const QObject* receiver, const char* slot, 00837 QObject* parent, const char* name ) 00838 : KSelectAction( text, cut, parent, name ) 00839 { 00840 d = new KListActionPrivate; 00841 if ( receiver ) 00842 connect( this, SIGNAL( activated( int ) ), receiver, slot ); 00843 } 00844 00845 KListAction::KListAction( const QString& text, const QIconSet& pix, 00846 const KShortcut& cut, 00847 QObject* parent, const char* name ) 00848 : KSelectAction( text, pix, cut, parent, name ) 00849 { 00850 d = new KListActionPrivate; 00851 } 00852 00853 KListAction::KListAction( const QString& text, const QString& pix, 00854 const KShortcut& cut, 00855 QObject* parent, const char* name ) 00856 : KSelectAction( text, pix, cut, parent, name ) 00857 { 00858 d = new KListActionPrivate; 00859 } 00860 00861 KListAction::KListAction( const QString& text, const QIconSet& pix, 00862 const KShortcut& cut, const QObject* receiver, 00863 const char* slot, QObject* parent, 00864 const char* name ) 00865 : KSelectAction( text, pix, cut, parent, name ) 00866 { 00867 d = new KListActionPrivate; 00868 if ( receiver ) 00869 connect( this, SIGNAL( activated( int ) ), receiver, slot ); 00870 } 00871 00872 KListAction::KListAction( const QString& text, const QString& pix, 00873 const KShortcut& cut, const QObject* receiver, 00874 const char* slot, QObject* parent, 00875 const char* name ) 00876 : KSelectAction( text, pix, cut, parent, name ) 00877 { 00878 d = new KListActionPrivate; 00879 if ( receiver ) 00880 connect( this, SIGNAL( activated( int ) ), receiver, slot ); 00881 } 00882 00883 KListAction::KListAction( QObject* parent, const char* name ) 00884 : KSelectAction( parent, name ) 00885 { 00886 d = new KListActionPrivate; 00887 } 00888 00889 KListAction::~KListAction() 00890 { 00891 delete d; d = 0; 00892 } 00893 00894 void KListAction::setCurrentItem( int index ) 00895 { 00896 KSelectAction::setCurrentItem( index ); 00897 d->m_current = index; 00898 00899 // emit KAction::activated(); 00900 // emit activated( currentItem() ); 00901 // emit activated( currentText() ); 00902 } 00903 00904 QString KListAction::currentText() const 00905 { 00906 if ( currentItem() < 0 ) 00907 return QString::null; 00908 00909 return items()[ currentItem() ]; 00910 } 00911 00912 int KListAction::currentItem() const 00913 { 00914 return d->m_current; 00915 } 00916 00917 class KRecentFilesAction::KRecentFilesActionPrivate 00918 { 00919 public: 00920 KRecentFilesActionPrivate() 00921 { 00922 m_maxItems = 0; 00923 m_popup = 0; 00924 } 00925 uint m_maxItems; 00926 KPopupMenu *m_popup; 00927 }; 00928 00929 KRecentFilesAction::KRecentFilesAction( const QString& text, 00930 const KShortcut& cut, 00931 QObject* parent, const char* name, 00932 uint maxItems ) 00933 : KListAction( text, cut, parent, name) 00934 { 00935 d = new KRecentFilesActionPrivate; 00936 d->m_maxItems = maxItems; 00937 00938 init(); 00939 } 00940 00941 KRecentFilesAction::KRecentFilesAction( const QString& text, 00942 const KShortcut& cut, 00943 const QObject* receiver, 00944 const char* slot, 00945 QObject* parent, const char* name, 00946 uint maxItems ) 00947 : KListAction( text, cut, parent, name) 00948 { 00949 d = new KRecentFilesActionPrivate; 00950 d->m_maxItems = maxItems; 00951 00952 init(); 00953 00954 if ( receiver ) 00955 connect( this, SIGNAL(urlSelected(const KURL&)), 00956 receiver, slot ); 00957 } 00958 00959 KRecentFilesAction::KRecentFilesAction( const QString& text, 00960 const QIconSet& pix, 00961 const KShortcut& cut, 00962 QObject* parent, const char* name, 00963 uint maxItems ) 00964 : KListAction( text, pix, cut, parent, name) 00965 { 00966 d = new KRecentFilesActionPrivate; 00967 d->m_maxItems = maxItems; 00968 00969 init(); 00970 } 00971 00972 KRecentFilesAction::KRecentFilesAction( const QString& text, 00973 const QString& pix, 00974 const KShortcut& cut, 00975 QObject* parent, const char* name, 00976 uint maxItems ) 00977 : KListAction( text, pix, cut, parent, name) 00978 { 00979 d = new KRecentFilesActionPrivate; 00980 d->m_maxItems = maxItems; 00981 00982 init(); 00983 } 00984 00985 KRecentFilesAction::KRecentFilesAction( const QString& text, 00986 const QIconSet& pix, 00987 const KShortcut& cut, 00988 const QObject* receiver, 00989 const char* slot, 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 if ( receiver ) 01000 connect( this, SIGNAL(urlSelected(const KURL&)), 01001 receiver, slot ); 01002 } 01003 01004 KRecentFilesAction::KRecentFilesAction( const QString& text, 01005 const QString& pix, 01006 const KShortcut& cut, 01007 const QObject* receiver, 01008 const char* slot, 01009 QObject* parent, const char* name, 01010 uint maxItems ) 01011 : KListAction( text, pix, cut, parent, name) 01012 { 01013 d = new KRecentFilesActionPrivate; 01014 d->m_maxItems = maxItems; 01015 01016 init(); 01017 01018 if ( receiver ) 01019 connect( this, SIGNAL(urlSelected(const KURL&)), 01020 receiver, slot ); 01021 } 01022 01023 KRecentFilesAction::KRecentFilesAction( QObject* parent, const char* name, 01024 uint maxItems ) 01025 : KListAction( parent, name ) 01026 { 01027 d = new KRecentFilesActionPrivate; 01028 d->m_maxItems = maxItems; 01029 01030 init(); 01031 } 01032 01033 void KRecentFilesAction::init() 01034 { 01035 KRecentFilesAction *that = const_cast<KRecentFilesAction*>(this); 01036 that->d->m_popup = new KPopupMenu; 01037 connect(d->m_popup, SIGNAL(aboutToShow()), this, SLOT(menuAboutToShow())); 01038 connect(d->m_popup, SIGNAL(activated(int)), this, SLOT(menuItemActivated(int))); 01039 connect( this, SIGNAL( activated( const QString& ) ), 01040 this, SLOT( itemSelected( const QString& ) ) ); 01041 01042 setMenuAccelsEnabled( false ); 01043 } 01044 01045 KRecentFilesAction::~KRecentFilesAction() 01046 { 01047 delete d->m_popup; 01048 delete d; d = 0; 01049 } 01050 01051 uint KRecentFilesAction::maxItems() const 01052 { 01053 return d->m_maxItems; 01054 } 01055 01056 void KRecentFilesAction::setMaxItems( uint maxItems ) 01057 { 01058 QStringList lst = items(); 01059 uint oldCount = lst.count(); 01060 01061 // set new maxItems 01062 d->m_maxItems = maxItems; 01063 01064 // remove all items that are too much 01065 while( lst.count() > maxItems ) 01066 { 01067 // remove last item 01068 lst.remove( lst.last() ); 01069 } 01070 01071 // set new list if changed 01072 if( lst.count() != oldCount ) 01073 setItems( lst ); 01074 } 01075 01076 void KRecentFilesAction::addURL( const KURL& url ) 01077 { 01078 if ( url.isLocalFile() && !KGlobal::dirs()->relativeLocation("tmp", url.path()).startsWith("/")) 01079 return; 01080 QString file = url.pathOrURL(); 01081 QStringList lst = items(); 01082 01083 // remove file if already in list 01084 lst.remove( file ); 01085 01086 // remove last item if already maxitems in list 01087 if( lst.count() == d->m_maxItems ) 01088 { 01089 // remove last item 01090 lst.remove( lst.last() ); 01091 } 01092 01093 // add file to list 01094 lst.prepend( file ); 01095 setItems( lst ); 01096 } 01097 01098 void KRecentFilesAction::removeURL( const KURL& url ) 01099 { 01100 QStringList lst = items(); 01101 QString file = url.pathOrURL(); 01102 01103 // remove url 01104 if( lst.count() > 0 ) 01105 { 01106 lst.remove( file ); 01107 setItems( lst ); 01108 } 01109 } 01110 01111 void KRecentFilesAction::clearURLList() 01112 { 01113 clear(); 01114 } 01115 01116 void KRecentFilesAction::loadEntries( KConfig* config, QString groupname) 01117 { 01118 QString key; 01119 QString value; 01120 QString oldGroup; 01121 QStringList lst; 01122 01123 oldGroup = config->group(); 01124 01125 if (groupname.isEmpty()) 01126 groupname = "RecentFiles"; 01127 config->setGroup( groupname ); 01128 01129 // read file list 01130 for( unsigned int i = 1 ; i <= d->m_maxItems ; i++ ) 01131 { 01132 key = QString( "File%1" ).arg( i ); 01133 value = config->readPathEntry( key ); 01134 01135 if (!value.isNull()) 01136 lst.append( value ); 01137 } 01138 01139 // set file 01140 setItems( lst ); 01141 01142 config->setGroup( oldGroup ); 01143 } 01144 01145 void KRecentFilesAction::saveEntries( KConfig* config, QString groupname ) 01146 { 01147 QString key; 01148 QString value; 01149 QString oldGroup; 01150 QStringList lst = items(); 01151 01152 oldGroup = config->group(); 01153 01154 if (groupname.isEmpty()) 01155 groupname = "RecentFiles"; 01156 config->deleteGroup( groupname, true ); 01157 config->setGroup( groupname ); 01158 01159 // write file list 01160 for( unsigned int i = 1 ; i <= lst.count() ; i++ ) 01161 { 01162 key = QString( "File%1" ).arg( i ); 01163 value = lst[ i - 1 ]; 01164 config->writePathEntry( key, value ); 01165 } 01166 01167 config->setGroup( oldGroup ); 01168 } 01169 01170 void KRecentFilesAction::itemSelected( const QString& text ) 01171 { 01172 emit urlSelected( KURL( text ) ); 01173 } 01174 01175 void KRecentFilesAction::menuItemActivated( int id ) 01176 { 01177 emit urlSelected( KURL(d->m_popup->text(id)) ); 01178 } 01179 01180 void KRecentFilesAction::menuAboutToShow() 01181 { 01182 KPopupMenu *menu = d->m_popup; 01183 menu->clear(); 01184 QStringList list = items(); 01185 for ( QStringList::Iterator it = list.begin(); it != list.end(); ++it ) 01186 menu->insertItem(*it); 01187 } 01188 01189 int KRecentFilesAction::plug( QWidget *widget, int index ) 01190 { 01191 if (kapp && !kapp->authorizeKAction(name())) 01192 return -1; 01193 // This is very related to KActionMenu::plug. 01194 // In fact this class could be an interesting base class for KActionMenu 01195 if ( ::qt_cast<KToolBar *>( widget ) ) 01196 { 01197 KToolBar *bar = (KToolBar *)widget; 01198 01199 int id_ = KAction::getToolButtonID(); 01200 01201 KInstance * instance; 01202 if ( m_parentCollection ) 01203 instance = m_parentCollection->instance(); 01204 else 01205 instance = KGlobal::instance(); 01206 01207 bar->insertButton( icon(), id_, SIGNAL( clicked() ), this, 01208 SLOT( slotClicked() ), isEnabled(), plainText(), 01209 index, instance ); 01210 01211 addContainer( bar, id_ ); 01212 01213 connect( bar, SIGNAL( destroyed() ), this, SLOT( slotDestroyed() ) ); 01214 01215 bar->setDelayedPopup( id_, d->m_popup, true); 01216 01217 if ( !whatsThis().isEmpty() ) 01218 QWhatsThis::add( bar->getButton( id_ ), whatsThisWithIcon() ); 01219 01220 return containerCount() - 1; 01221 } 01222 01223 return KListAction::plug( widget, index ); 01224 } 01225 01226 void KRecentFilesAction::slotClicked() 01227 { 01228 KAction::slotActivated(); 01229 } 01230 01231 void KRecentFilesAction::slotActivated(const QString& text) 01232 { 01233 KListAction::slotActivated(text); 01234 } 01235 01236 01237 void KRecentFilesAction::slotActivated(int id) 01238 { 01239 KListAction::slotActivated(id); 01240 } 01241 01242 01243 void KRecentFilesAction::slotActivated() 01244 { 01245 emit activated( currentItem() ); 01246 emit activated( currentText() ); 01247 } 01248 01249 01250 class KFontAction::KFontActionPrivate 01251 { 01252 public: 01253 KFontActionPrivate() 01254 { 01255 } 01256 QStringList m_fonts; 01257 }; 01258 01259 KFontAction::KFontAction( const QString& text, 01260 const KShortcut& cut, QObject* parent, 01261 const char* name ) 01262 : KSelectAction( text, cut, parent, name ) 01263 { 01264 d = new KFontActionPrivate; 01265 KFontChooser::getFontList( d->m_fonts, 0 ); 01266 KSelectAction::setItems( d->m_fonts ); 01267 setEditable( true ); 01268 } 01269 01270 KFontAction::KFontAction( const QString& text, const KShortcut& cut, 01271 const QObject* receiver, const char* slot, 01272 QObject* parent, const char* name ) 01273 : KSelectAction( text, cut, receiver, slot, parent, name ) 01274 { 01275 d = new KFontActionPrivate; 01276 KFontChooser::getFontList( d->m_fonts, 0 ); 01277 KSelectAction::setItems( d->m_fonts ); 01278 setEditable( true ); 01279 } 01280 01281 KFontAction::KFontAction( const QString& text, const QIconSet& pix, 01282 const KShortcut& cut, 01283 QObject* parent, const char* name ) 01284 : KSelectAction( text, pix, cut, parent, name ) 01285 { 01286 d = new KFontActionPrivate; 01287 KFontChooser::getFontList( d->m_fonts, 0 ); 01288 KSelectAction::setItems( d->m_fonts ); 01289 setEditable( true ); 01290 } 01291 01292 KFontAction::KFontAction( const QString& text, const QString& pix, 01293 const KShortcut& cut, 01294 QObject* parent, const char* name ) 01295 : KSelectAction( text, pix, cut, parent, name ) 01296 { 01297 d = new KFontActionPrivate; 01298 KFontChooser::getFontList( d->m_fonts, 0 ); 01299 KSelectAction::setItems( d->m_fonts ); 01300 setEditable( true ); 01301 } 01302 01303 KFontAction::KFontAction( const QString& text, const QIconSet& pix, 01304 const KShortcut& cut, 01305 const QObject* receiver, const char* slot, 01306 QObject* parent, const char* name ) 01307 : KSelectAction( text, pix, cut, receiver, slot, parent, name ) 01308 { 01309 d = new KFontActionPrivate; 01310 KFontChooser::getFontList( d->m_fonts, 0 ); 01311 KSelectAction::setItems( d->m_fonts ); 01312 setEditable( true ); 01313 } 01314 01315 KFontAction::KFontAction( const QString& text, const QString& pix, 01316 const KShortcut& cut, 01317 const QObject* receiver, const char* slot, 01318 QObject* parent, const char* name ) 01319 : KSelectAction( text, pix, cut, receiver, slot, parent, name ) 01320 { 01321 d = new KFontActionPrivate; 01322 KFontChooser::getFontList( d->m_fonts, 0 ); 01323 KSelectAction::setItems( d->m_fonts ); 01324 setEditable( true ); 01325 } 01326 01327 KFontAction::KFontAction( uint fontListCriteria, const QString& text, 01328 const KShortcut& cut, QObject* parent, 01329 const char* name ) 01330 : KSelectAction( text, cut, parent, name ) 01331 { 01332 d = new KFontActionPrivate; 01333 KFontChooser::getFontList( d->m_fonts, fontListCriteria ); 01334 KSelectAction::setItems( d->m_fonts ); 01335 setEditable( true ); 01336 } 01337 01338 KFontAction::KFontAction( uint fontListCriteria, const QString& text, const QString& pix, 01339 const KShortcut& cut, 01340 QObject* parent, const char* name ) 01341 : KSelectAction( text, pix, cut, parent, name ) 01342 { 01343 d = new KFontActionPrivate; 01344 KFontChooser::getFontList( d->m_fonts, fontListCriteria ); 01345 KSelectAction::setItems( d->m_fonts ); 01346 setEditable( true ); 01347 } 01348 01349 KFontAction::KFontAction( QObject* parent, const char* name ) 01350 : KSelectAction( parent, name ) 01351 { 01352 d = new KFontActionPrivate; 01353 KFontChooser::getFontList( d->m_fonts, 0 ); 01354 KSelectAction::setItems( d->m_fonts ); 01355 setEditable( true ); 01356 } 01357 01358 KFontAction::~KFontAction() 01359 { 01360 delete d; 01361 d = 0; 01362 } 01363 01364 /* 01365 * Maintenance note: Keep in sync with KFontCombo::setCurrentFont() 01366 */ 01367 void KFontAction::setFont( const QString &family ) 01368 { 01369 QString lowerName = family.lower(); 01370 int i = 0; 01371 for ( QStringList::Iterator it = d->m_fonts.begin(); it != d->m_fonts.end(); ++it, ++i ) 01372 { 01373 if ((*it).lower() == lowerName) 01374 { 01375 setCurrentItem(i); 01376 return; 01377 } 01378 } 01379 i = lowerName.find(" ["); 01380 if (i>-1) 01381 { 01382 lowerName = lowerName.left(i); 01383 i = 0; 01384 for ( QStringList::Iterator it = d->m_fonts.begin(); it != d->m_fonts.end(); ++it, ++i ) 01385 { 01386 if ((*it).lower() == lowerName) 01387 { 01388 setCurrentItem(i); 01389 return; 01390 } 01391 } 01392 } 01393 01394 lowerName += " ["; 01395 i = 0; 01396 for ( QStringList::Iterator it = d->m_fonts.begin(); it != d->m_fonts.end(); ++it, ++i ) 01397 { 01398 if ((*it).lower().startsWith(lowerName)) 01399 { 01400 setCurrentItem(i); 01401 return; 01402 } 01403 } 01404 kdDebug(129) << "Font not found " << family.lower() << endl; 01405 } 01406 01407 int KFontAction::plug( QWidget *w, int index ) 01408 { 01409 if (kapp && !kapp->authorizeKAction(name())) 01410 return -1; 01411 if ( ::qt_cast<KToolBar *>( w ) ) 01412 { 01413 KToolBar* bar = static_cast<KToolBar*>( w ); 01414 int id_ = KAction::getToolButtonID(); 01415 KFontCombo *cb = new KFontCombo( items(), bar ); 01416 connect( cb, SIGNAL( activated( const QString & ) ), 01417 SLOT( slotActivated( const QString & ) ) ); 01418 cb->setEnabled( isEnabled() ); 01419 bar->insertWidget( id_, comboWidth(), cb, index ); 01420 cb->setMinimumWidth( cb->sizeHint().width() ); 01421 01422 addContainer( bar, id_ ); 01423 01424 connect( bar, SIGNAL( destroyed() ), this, SLOT( slotDestroyed() ) ); 01425 01426 updateCurrentItem( containerCount() - 1 ); 01427 01428 return containerCount() - 1; 01429 } 01430 else return KSelectAction::plug( w, index ); 01431 } 01432 01433 class KFontSizeAction::KFontSizeActionPrivate 01434 { 01435 public: 01436 KFontSizeActionPrivate() 01437 { 01438 } 01439 }; 01440 01441 KFontSizeAction::KFontSizeAction( const QString& text, 01442 const KShortcut& cut, 01443 QObject* parent, const char* name ) 01444 : KSelectAction( text, cut, parent, name ) 01445 { 01446 init(); 01447 } 01448 01449 KFontSizeAction::KFontSizeAction( const QString& text, 01450 const KShortcut& cut, 01451 const QObject* receiver, const char* slot, 01452 QObject* parent, const char* name ) 01453 : KSelectAction( text, cut, receiver, slot, parent, name ) 01454 { 01455 init(); 01456 } 01457 01458 KFontSizeAction::KFontSizeAction( const QString& text, const QIconSet& pix, 01459 const KShortcut& cut, 01460 QObject* parent, const char* name ) 01461 : KSelectAction( text, pix, cut, parent, name ) 01462 { 01463 init(); 01464 } 01465 01466 KFontSizeAction::KFontSizeAction( const QString& text, const QString& pix, 01467 const KShortcut& cut, 01468 QObject* parent, const char* name ) 01469 : KSelectAction( text, pix, cut, parent, name ) 01470 { 01471 init(); 01472 } 01473 01474 KFontSizeAction::KFontSizeAction( const QString& text, const QIconSet& pix, 01475 const KShortcut& cut, 01476 const QObject* receiver, 01477 const char* slot, QObject* parent, 01478 const char* name ) 01479 : KSelectAction( text, pix, cut, receiver, slot, parent, name ) 01480 { 01481 init(); 01482 } 01483 01484 KFontSizeAction::KFontSizeAction( const QString& text, const QString& pix, 01485 const KShortcut& cut, 01486 const QObject* receiver, 01487 const char* slot, QObject* parent, 01488 const char* name ) 01489 : KSelectAction( text, pix, cut, receiver, slot, parent, name ) 01490 { 01491 init(); 01492 } 01493 01494 KFontSizeAction::KFontSizeAction( QObject* parent, const char* name ) 01495 : KSelectAction( parent, name ) 01496 { 01497 init(); 01498 } 01499 01500 KFontSizeAction::~KFontSizeAction() 01501 { 01502 delete d; 01503 d = 0; 01504 } 01505 01506 void KFontSizeAction::init() 01507 { 01508 d = new KFontSizeActionPrivate; 01509 01510 setEditable( true ); 01511 QFontDatabase fontDB; 01512 QValueList<int> sizes = fontDB.standardSizes(); 01513 QStringList lst; 01514 for ( QValueList<int>::Iterator it = sizes.begin(); it != sizes.end(); ++it ) 01515 lst.append( QString::number( *it ) ); 01516 01517 setItems( lst ); 01518 } 01519 01520 void KFontSizeAction::setFontSize( int size ) 01521 { 01522 if ( size == fontSize() ) { 01523 setCurrentItem( items().findIndex( QString::number( size ) ) ); 01524 return; 01525 } 01526 01527 if ( size < 1 ) { 01528 kdWarning() << "KFontSizeAction: Size " << size << " is out of range" << endl; 01529 return; 01530 } 01531 01532 int index = items().findIndex( QString::number( size ) ); 01533 if ( index == -1 ) { 01534 // Insert at the correct position in the list (to keep sorting) 01535 QValueList<int> lst; 01536 // Convert to list of ints 01537 QStringList itemsList = items(); 01538 for (QStringList::Iterator it = itemsList.begin() ; it != itemsList.end() ; ++it) 01539 lst.append( (*it).toInt() ); 01540 // New size 01541 lst.append( size ); 01542 // Sort the list 01543 qHeapSort( lst ); 01544 // Convert back to string list 01545 QStringList strLst; 01546 for (QValueList<int>::Iterator it = lst.begin() ; it != lst.end() ; ++it) 01547 strLst.append( QString::number(*it) ); 01548 KSelectAction::setItems( strLst ); 01549 // Find new current item 01550 index = lst.findIndex( size ); 01551 setCurrentItem( index ); 01552 } 01553 else 01554 setCurrentItem( index ); 01555 01556 01557 //emit KAction::activated(); 01558 //emit activated( index ); 01559 //emit activated( QString::number( size ) ); 01560 //emit fontSizeChanged( size ); 01561 } 01562 01563 int KFontSizeAction::fontSize() const 01564 { 01565 return currentText().toInt(); 01566 } 01567 01568 void KFontSizeAction::slotActivated( int index ) 01569 { 01570 KSelectAction::slotActivated( index ); 01571 01572 emit fontSizeChanged( items()[ index ].toInt() ); 01573 } 01574 01575 void KFontSizeAction::slotActivated( const QString& size ) 01576 { 01577 setFontSize( size.toInt() ); // insert sorted first 01578 KSelectAction::slotActivated( size ); 01579 emit fontSizeChanged( size.toInt() ); 01580 } 01581 01582 class KActionMenu::KActionMenuPrivate 01583 { 01584 public: 01585 KActionMenuPrivate() 01586 { 01587 m_popup = new KPopupMenu(0L,"KActionMenu::KActionMenuPrivate"); 01588 m_delayed = true; 01589 m_stickyMenu = true; 01590 } 01591 ~KActionMenuPrivate() 01592 { 01593 delete m_popup; m_popup = 0; 01594 } 01595 KPopupMenu *m_popup; 01596 bool m_delayed; 01597 bool m_stickyMenu; 01598 }; 01599 01600 KActionMenu::KActionMenu( QObject* parent, const char* name ) 01601 : KAction( parent, name ) 01602 { 01603 d = new KActionMenuPrivate; 01604 setShortcutConfigurable( false ); 01605 } 01606 01607 KActionMenu::KActionMenu( const QString& text, QObject* parent, 01608 const char* name ) 01609 : KAction( text, 0, parent, name ) 01610 { 01611 d = new KActionMenuPrivate; 01612 setShortcutConfigurable( false ); 01613 } 01614 01615 KActionMenu::KActionMenu( const QString& text, const QIconSet& icon, 01616 QObject* parent, const char* name ) 01617 : KAction( text, icon, 0, parent, name ) 01618 { 01619 d = new KActionMenuPrivate; 01620 setShortcutConfigurable( false ); 01621 } 01622 01623 KActionMenu::KActionMenu( const QString& text, const QString& icon, 01624 QObject* parent, const char* name ) 01625 : KAction( text, icon, 0, parent, name ) 01626 { 01627 d = new KActionMenuPrivate; 01628 setShortcutConfigurable( false ); 01629 } 01630 01631 KActionMenu::~KActionMenu() 01632 { 01633 unplugAll(); 01634 kdDebug(129) << "KActionMenu::~KActionMenu()" << endl; // ellis 01635 delete d; d = 0; 01636 } 01637 01638 void KActionMenu::popup( const QPoint& global ) 01639 { 01640 popupMenu()->popup( global ); 01641 } 01642 01643 KPopupMenu* KActionMenu::popupMenu() const 01644 { 01645 return d->m_popup; 01646 } 01647 01648 void KActionMenu::insert( KAction* cmd, int index ) 01649 { 01650 if ( cmd ) 01651 cmd->plug( d->m_popup, index ); 01652 } 01653 01654 void KActionMenu::remove( KAction* cmd ) 01655 { 01656 if ( cmd ) 01657 cmd->unplug( d->m_popup ); 01658 } 01659 01660 bool KActionMenu::delayed() const { 01661 return d->m_delayed; 01662 } 01663 01664 void KActionMenu::setDelayed(bool _delayed) { 01665 d->m_delayed = _delayed; 01666 } 01667 01668 bool KActionMenu::stickyMenu() const { 01669 return d->m_stickyMenu; 01670 } 01671 01672 void KActionMenu::setStickyMenu(bool sticky) { 01673 d->m_stickyMenu = sticky; 01674 } 01675 01676 int KActionMenu::plug( QWidget* widget, int index ) 01677 { 01678 if (kapp && !kapp->authorizeKAction(name())) 01679 return -1; 01680 kdDebug(129) << "KAction::plug( " << widget << ", " << index << " )" << endl; // remove -- ellis 01681 if ( ::qt_cast<QPopupMenu *>( widget ) ) 01682 { 01683 QPopupMenu* menu = static_cast<QPopupMenu*>( widget ); 01684 int id; 01685 if ( hasIcon() ) 01686 id = menu->insertItem( iconSet(), text(), d->m_popup, -1, index ); 01687 else 01688 id = menu->insertItem( text(), d->m_popup, -1, index ); 01689 01690 if ( !isEnabled() ) 01691 menu->setItemEnabled( id, false ); 01692 01693 addContainer( menu, id ); 01694 connect( menu, SIGNAL( destroyed() ), this, SLOT( slotDestroyed() ) ); 01695 01696 if ( m_parentCollection ) 01697 m_parentCollection->connectHighlight( menu, this ); 01698 01699 return containerCount() - 1; 01700 } 01701 else if ( ::qt_cast<KToolBar *>( widget ) ) 01702 { 01703 KToolBar *bar = static_cast<KToolBar *>( widget ); 01704 01705 int id_ = KAction::getToolButtonID(); 01706 01707 if ( icon().isEmpty() && !iconSet().isNull() ) 01708 bar->insertButton( iconSet().pixmap(), id_, SIGNAL( clicked() ), this, 01709 SLOT( slotActivated() ), isEnabled(), plainText(), 01710 index ); 01711 else 01712 { 01713 KInstance *instance; 01714 01715 if ( m_parentCollection ) 01716 instance = m_parentCollection->instance(); 01717 else 01718 instance = KGlobal::instance(); 01719 01720 bar->insertButton( icon(), id_, SIGNAL( clicked() ), this, 01721 SLOT( slotActivated() ), isEnabled(), plainText(), 01722 index, instance ); 01723 } 01724 01725 addContainer( bar, id_ ); 01726 01727 if (!whatsThis().isEmpty()) 01728 QWhatsThis::add( bar->getButton(id_), whatsThis() ); 01729 01730 connect( bar, SIGNAL( destroyed() ), this, SLOT( slotDestroyed() ) ); 01731 01732 if (delayed()) { 01733 bar->setDelayedPopup( id_, popupMenu(), stickyMenu() ); 01734 } else { 01735 bar->getButton(id_)->setPopup(popupMenu(), stickyMenu() ); 01736 } 01737 01738 if ( m_parentCollection ) 01739 m_parentCollection->connectHighlight( bar, this ); 01740 01741 return containerCount() - 1; 01742 } 01743 else if ( ::qt_cast<QMenuBar *>( widget ) ) 01744 { 01745 QMenuBar *bar = static_cast<QMenuBar *>( widget ); 01746 01747 int id; 01748 01749 id = bar->insertItem( text(), popupMenu(), -1, index ); 01750 01751 if ( !isEnabled() ) 01752 bar->setItemEnabled( id, false ); 01753 01754 addContainer( bar, id ); 01755 connect( bar, SIGNAL( destroyed() ), this, SLOT( slotDestroyed() ) ); 01756 01757 return containerCount() - 1; 01758 } 01759 01760 return -1; 01761 } 01762 01764 01765 KToolBarPopupAction::KToolBarPopupAction( const QString& text, 01766 const QString& icon, 01767 const KShortcut& cut, 01768 QObject* parent, const char* name ) 01769 : KAction( text, icon, cut, parent, name ) 01770 { 01771 m_popup = 0; 01772 m_delayed = true; 01773 m_stickyMenu = true; 01774 } 01775 01776 KToolBarPopupAction::KToolBarPopupAction( const QString& text, 01777 const QString& icon, 01778 const KShortcut& cut, 01779 const QObject* receiver, 01780 const char* slot, QObject* parent, 01781 const char* name ) 01782 : KAction( text, icon, cut, receiver, slot, parent, name ) 01783 { 01784 m_popup = 0; 01785 m_delayed = true; 01786 m_stickyMenu = true; 01787 } 01788 01789 KToolBarPopupAction::KToolBarPopupAction( const KGuiItem& item, 01790 const KShortcut& cut, 01791 const QObject* receiver, 01792 const char* slot, KActionCollection* parent, 01793 const char* name ) 01794 : KAction( item, cut, receiver, slot, parent, name ) 01795 { 01796 m_popup = 0; 01797 m_delayed = true; 01798 m_stickyMenu = true; 01799 } 01800 01801 KToolBarPopupAction::~KToolBarPopupAction() 01802 { 01803 delete m_popup; 01804 } 01805 01806 bool KToolBarPopupAction::delayed() const { 01807 return m_delayed; 01808 } 01809 01810 void KToolBarPopupAction::setDelayed(bool delayed) { 01811 m_delayed = delayed; 01812 } 01813 01814 bool KToolBarPopupAction::stickyMenu() const { 01815 return m_stickyMenu; 01816 } 01817 01818 void KToolBarPopupAction::setStickyMenu(bool sticky) { 01819 m_stickyMenu = sticky; 01820 } 01821 01822 int KToolBarPopupAction::plug( QWidget *widget, int index ) 01823 { 01824 if (kapp && !kapp->authorizeKAction(name())) 01825 return -1; 01826 // This is very related to KActionMenu::plug. 01827 // In fact this class could be an interesting base class for KActionMenu 01828 if ( ::qt_cast<KToolBar *>( widget ) ) 01829 { 01830 KToolBar *bar = (KToolBar *)widget; 01831 01832 int id_ = KAction::getToolButtonID(); 01833 01834 if ( icon().isEmpty() && !iconSet().isNull() ) { 01835 bar->insertButton( iconSet().pixmap(), id_, SIGNAL( buttonClicked(int, Qt::ButtonState) ), this, 01836 SLOT( slotButtonClicked(int, Qt::ButtonState) ), 01837 isEnabled(), plainText(), 01838 index ); 01839 } else { 01840 KInstance * instance; 01841 if ( m_parentCollection ) 01842 instance = m_parentCollection->instance(); 01843 else 01844 instance = KGlobal::instance(); 01845 01846 bar->insertButton( icon(), id_, SIGNAL( buttonClicked(int, Qt::ButtonState) ), this, 01847 SLOT( slotButtonClicked(int, Qt::ButtonState) ), 01848 isEnabled(), plainText(), 01849 index, instance ); 01850 } 01851 01852 addContainer( bar, id_ ); 01853 01854 connect( bar, SIGNAL( destroyed() ), this, SLOT( slotDestroyed() ) ); 01855 01856 if (delayed()) { 01857 bar->setDelayedPopup( id_, popupMenu(), stickyMenu() ); 01858 } else { 01859 bar->getButton(id_)->setPopup(popupMenu(), stickyMenu()); 01860 } 01861 01862 if ( !whatsThis().isEmpty() ) 01863 QWhatsThis::add( bar->getButton( id_ ), whatsThisWithIcon() ); 01864 01865 return containerCount() - 1; 01866 } 01867 01868 return KAction::plug( widget, index ); 01869 } 01870 01871 KPopupMenu *KToolBarPopupAction::popupMenu() const 01872 { 01873 if ( !m_popup ) { 01874 KToolBarPopupAction *that = const_cast<KToolBarPopupAction*>(this); 01875 that->m_popup = new KPopupMenu; 01876 } 01877 return m_popup; 01878 } 01879 01881 01882 KToggleToolBarAction::KToggleToolBarAction( const char* toolBarName, 01883 const QString& text, KActionCollection* parent, const char* name ) 01884 : KToggleAction( text, KShortcut(), parent, name ) 01885 , m_toolBarName( toolBarName ) 01886 , m_toolBar( 0L ) 01887 { 01888 } 01889 01890 KToggleToolBarAction::KToggleToolBarAction( KToolBar *toolBar, const QString &text, 01891 KActionCollection *parent, const char *name ) 01892 : KToggleAction( text, KShortcut(), parent, name ) 01893 , m_toolBarName( 0 ), m_toolBar( toolBar ) 01894 { 01895 } 01896 01897 KToggleToolBarAction::~KToggleToolBarAction() 01898 { 01899 } 01900 01901 int KToggleToolBarAction::plug( QWidget* w, int index ) 01902 { 01903 if (kapp && !kapp->authorizeKAction(name())) 01904 return -1; 01905 01906 if ( !m_toolBar ) { 01907 // Note: topLevelWidget() stops too early, we can't use it. 01908 QWidget * tl = w; 01909 QWidget * n; 01910 while ( !tl->isDialog() && ( n = tl->parentWidget() ) ) // lookup parent and store 01911 tl = n; 01912 01913 KMainWindow * mw = dynamic_cast<KMainWindow *>(tl); // try to see if it's a kmainwindow 01914 01915 if ( mw ) 01916 m_toolBar = mw->toolBar( m_toolBarName ); 01917 } 01918 01919 if( m_toolBar ) { 01920 setChecked( m_toolBar->isVisible() ); 01921 connect( m_toolBar, SIGNAL(visibilityChanged(bool)), this, SLOT(setChecked(bool)) ); 01922 // Also emit toggled when the toolbar's visibility changes (see comment in header) 01923 connect( m_toolBar, SIGNAL(visibilityChanged(bool)), this, SIGNAL(toggled(bool)) ); 01924 } else { 01925 setEnabled( false ); 01926 } 01927 01928 return KToggleAction::plug( w, index ); 01929 } 01930 01931 void KToggleToolBarAction::setChecked( bool c ) 01932 { 01933 if( m_toolBar && c != m_toolBar->isVisible() ) { 01934 if( c ) { 01935 m_toolBar->show(); 01936 } else { 01937 m_toolBar->hide(); 01938 } 01939 QMainWindow* mw = m_toolBar->mainWindow(); 01940 if ( mw && ::qt_cast<KMainWindow *>( mw ) ) 01941 static_cast<KMainWindow *>( mw )->setSettingsDirty(); 01942 } 01943 KToggleAction::setChecked( c ); 01944 } 01945 01947 01948 KToggleFullScreenAction::KToggleFullScreenAction( const KShortcut &cut, 01949 const QObject* receiver, const char* slot, 01950 QObject* parent, QWidget* window, 01951 const char* name ) 01952 : KToggleAction( QString::null, cut, receiver, slot, parent, name ), 01953 window( NULL ) 01954 { 01955 setWindow( window ); 01956 } 01957 01958 KToggleFullScreenAction::~KToggleFullScreenAction() 01959 { 01960 } 01961 01962 void KToggleFullScreenAction::setWindow( QWidget* w ) 01963 { 01964 if( window ) 01965 window->removeEventFilter( this ); 01966 window = w; 01967 if( window ) 01968 window->installEventFilter( this ); 01969 } 01970 01971 void KToggleFullScreenAction::setChecked( bool c ) 01972 { 01973 if (c) 01974 { 01975 setText(i18n("Exit F&ull Screen Mode")); 01976 setIcon("window_nofullscreen"); 01977 } 01978 else 01979 { 01980 setText(i18n("F&ull Screen Mode")); 01981 setIcon("window_fullscreen"); 01982 } 01983 KToggleAction::setChecked( c ); 01984 } 01985 01986 bool KToggleFullScreenAction::eventFilter( QObject* o, QEvent* e ) 01987 { 01988 if( o == window ) 01989 #if QT_VERSION >= 0x030300 01990 if( e->type() == QEvent::WindowStateChange ) 01991 #else 01992 if( e->type() == QEvent::ShowFullScreen || e->type() == QEvent::ShowNormal 01993 || e->type() == QEvent::ShowMaximized || e->type() == QEvent::ShowMinimized ) 01994 #endif 01995 { 01996 if( window->isFullScreen() != isChecked()) 01997 slotActivated(); // setChecked( window->isFullScreen()) wouldn't emit signals 01998 } 01999 return false; 02000 } 02001 02003 02004 KWidgetAction::KWidgetAction( QWidget* widget, 02005 const QString& text, const KShortcut& cut, 02006 const QObject* receiver, const char* slot, 02007 KActionCollection* parent, const char* name ) 02008 : KAction( text, cut, receiver, slot, parent, name ) 02009 , m_widget( widget ) 02010 , m_autoSized( false ) 02011 { 02012 connect( this, SIGNAL(enabled(bool)), widget, SLOT(setEnabled(bool)) ); 02013 } 02014 02015 KWidgetAction::~KWidgetAction() 02016 { 02017 } 02018 02019 void KWidgetAction::setAutoSized( bool autoSized ) 02020 { 02021 if( m_autoSized == autoSized ) 02022 return; 02023 02024 m_autoSized = autoSized; 02025 02026 if( !m_widget || !isPlugged() ) 02027 return; 02028 02029 KToolBar* toolBar = (KToolBar*)m_widget->parent(); 02030 int i = findContainer( toolBar ); 02031 if ( i == -1 ) 02032 return; 02033 int id = itemId( i ); 02034 02035 toolBar->setItemAutoSized( id, m_autoSized ); 02036 } 02037 02038 int KWidgetAction::plug( QWidget* w, int index ) 02039 { 02040 if (kapp && !kapp->authorizeKAction(name())) 02041 return -1; 02042 02043 if ( !::qt_cast<KToolBar *>( w ) ) { 02044 kdError() << "KWidgetAction::plug: KWidgetAction must be plugged into KToolBar." << endl; 02045 return -1; 02046 } 02047 if ( !m_widget ) { 02048 kdError() << "KWidgetAction::plug: Widget was deleted or null!" << endl; 02049 return -1; 02050 } 02051 02052 KToolBar* toolBar = static_cast<KToolBar*>( w ); 02053 02054 int id = KAction::getToolButtonID(); 02055 02056 m_widget->reparent( toolBar, QPoint() ); 02057 toolBar->insertWidget( id, 0, m_widget, index ); 02058 toolBar->setItemAutoSized( id, m_autoSized ); 02059 02060 QWhatsThis::add( m_widget, whatsThis() ); 02061 addContainer( toolBar, id ); 02062 02063 connect( toolBar, SIGNAL( toolbarDestroyed() ), this, SLOT( slotToolbarDestroyed() ) ); 02064 connect( toolBar, SIGNAL( destroyed() ), this, SLOT( slotDestroyed() ) ); 02065 02066 return containerCount() - 1; 02067 } 02068 02069 void KWidgetAction::unplug( QWidget *w ) 02070 { 02071 if( !m_widget || !isPlugged() ) 02072 return; 02073 02074 KToolBar* toolBar = (KToolBar*)m_widget->parent(); 02075 if ( toolBar == w ) 02076 { 02077 disconnect( toolBar, SIGNAL( toolbarDestroyed() ), this, SLOT( slotToolbarDestroyed() ) ); 02078 m_widget->reparent( 0L, QPoint(), false /*showIt*/ ); 02079 } 02080 KAction::unplug( w ); 02081 } 02082 02083 void KWidgetAction::slotToolbarDestroyed() 02084 { 02085 //Q_ASSERT( m_widget ); // When exiting the app the widget could be destroyed before the toolbar. 02086 Q_ASSERT( isPlugged() ); 02087 if( !m_widget || !isPlugged() ) 02088 return; 02089 02090 // Don't let a toolbar being destroyed, delete my widget. 02091 m_widget->reparent( 0L, QPoint(), false /*showIt*/ ); 02092 } 02093 02095 02096 KActionSeparator::KActionSeparator( QObject *parent, const char *name ) 02097 : KAction( parent, name ) 02098 { 02099 } 02100 02101 KActionSeparator::~KActionSeparator() 02102 { 02103 } 02104 02105 int KActionSeparator::plug( QWidget *widget, int index ) 02106 { 02107 if ( ::qt_cast<QPopupMenu *>( widget) ) 02108 { 02109 QPopupMenu* menu = static_cast<QPopupMenu*>( widget ); 02110 02111 int id = menu->insertSeparator( index ); 02112 02113 addContainer( menu, id ); 02114 connect( menu, SIGNAL( destroyed() ), this, SLOT( slotDestroyed() ) ); 02115 02116 return containerCount() - 1; 02117 } 02118 else if ( ::qt_cast<QMenuBar *>( widget ) ) 02119 { 02120 QMenuBar *menuBar = static_cast<QMenuBar *>( widget ); 02121 02122 int id = menuBar->insertSeparator( index ); 02123 02124 addContainer( menuBar, id ); 02125 02126 connect( menuBar, SIGNAL( destroyed() ), this, SLOT( slotDestroyed() ) ); 02127 02128 return containerCount() - 1; 02129 } 02130 else if ( ::qt_cast<KToolBar *>( widget ) ) 02131 { 02132 KToolBar *toolBar = static_cast<KToolBar *>( widget ); 02133 02134 int id = toolBar->insertSeparator( index ); 02135 02136 addContainer( toolBar, id ); 02137 02138 connect( toolBar, SIGNAL( destroyed() ), this, SLOT( slotDestroyed() ) ); 02139 02140 return containerCount() - 1; 02141 } 02142 02143 return -1; 02144 } 02145 02146 KPasteTextAction::KPasteTextAction( const QString& text, 02147 const QString& icon, 02148 const KShortcut& cut, 02149 const QObject* receiver, 02150 const char* slot, QObject* parent, 02151 const char* name) 02152 : KAction( text, icon, cut, receiver, slot, parent, name ) 02153 { 02154 m_popup = new KPopupMenu; 02155 connect(m_popup, SIGNAL(aboutToShow()), this, SLOT(menuAboutToShow())); 02156 connect(m_popup, SIGNAL(activated(int)), this, SLOT(menuItemActivated(int))); 02157 m_popup->setCheckable(true); 02158 m_mixedMode = true; 02159 } 02160 02161 KPasteTextAction::~KPasteTextAction() 02162 { 02163 delete m_popup; 02164 } 02165 02166 void KPasteTextAction::setMixedMode(bool mode) 02167 { 02168 m_mixedMode = mode; 02169 } 02170 02171 int KPasteTextAction::plug( QWidget *widget, int index ) 02172 { 02173 if (kapp && !kapp->authorizeKAction(name())) 02174 return -1; 02175 if ( ::qt_cast<KToolBar *>( widget ) ) 02176 { 02177 KToolBar *bar = (KToolBar *)widget; 02178 02179 int id_ = KAction::getToolButtonID(); 02180 02181 KInstance * instance; 02182 if ( m_parentCollection ) 02183 instance = m_parentCollection->instance(); 02184 else 02185 instance = KGlobal::instance(); 02186 02187 bar->insertButton( icon(), id_, SIGNAL( clicked() ), this, 02188 SLOT( slotActivated() ), isEnabled(), plainText(), 02189 index, instance ); 02190 02191 addContainer( bar, id_ ); 02192 02193 connect( bar, SIGNAL( destroyed() ), this, SLOT( slotDestroyed() ) ); 02194 02195 bar->setDelayedPopup( id_, m_popup, true ); 02196 02197 if ( !whatsThis().isEmpty() ) 02198 QWhatsThis::add( bar->getButton( id_ ), whatsThisWithIcon() ); 02199 02200 return containerCount() - 1; 02201 } 02202 02203 return KAction::plug( widget, index ); 02204 } 02205 02206 void KPasteTextAction::menuAboutToShow() 02207 { 02208 m_popup->clear(); 02209 QStringList list; 02210 DCOPClient *client = kapp->dcopClient(); 02211 if (client->isAttached() && client->isApplicationRegistered("klipper")) { 02212 DCOPRef klipper("klipper","klipper"); 02213 DCOPReply reply = klipper.call("getClipboardHistoryMenu"); 02214 if (reply.isValid()) 02215 list = reply; 02216 } 02217 QString clipboardText = qApp->clipboard()->text(QClipboard::Clipboard); 02218 if (list.isEmpty()) 02219 list << clipboardText; 02220 bool found = false; 02221 for ( QStringList::ConstIterator it = list.begin(); it != list.end(); ++it ) 02222 { 02223 QString text = KStringHandler::cEmSqueeze((*it).simplifyWhiteSpace(), m_popup->fontMetrics(), 20); 02224 text.replace("&", "&&"); 02225 int id = m_popup->insertItem(text); 02226 if (!found && *it == clipboardText) 02227 { 02228 m_popup->setItemChecked(id, true); 02229 found = true; 02230 } 02231 } 02232 } 02233 02234 void KPasteTextAction::menuItemActivated( int id) 02235 { 02236 DCOPClient *client = kapp->dcopClient(); 02237 if (client->isAttached() && client->isApplicationRegistered("klipper")) { 02238 DCOPRef klipper("klipper","klipper"); 02239 DCOPReply reply = klipper.call("getClipboardHistoryItem(int)", m_popup->indexOf(id)); 02240 if (!reply.isValid()) 02241 return; 02242 QString clipboardText = reply; 02243 reply = klipper.call("setClipboardContents(QString)", clipboardText); 02244 if (reply.isValid()) 02245 kdDebug(129) << "Clipboard: " << qApp->clipboard()->text(QClipboard::Clipboard) << endl; 02246 } 02247 QTimer::singleShot(20, this, SLOT(slotActivated())); 02248 } 02249 02250 void KPasteTextAction::slotActivated() 02251 { 02252 if (!m_mixedMode) { 02253 QWidget *w = qApp->widgetAt(QCursor::pos(), true); 02254 QMimeSource *data = QApplication::clipboard()->data(); 02255 if (!data->provides("text/plain") && w) { 02256 m_popup->popup(w->mapToGlobal(QPoint(0, w->height()))); 02257 } else 02258 KAction::slotActivated(); 02259 } else 02260 KAction::slotActivated(); 02261 } 02262 02263 02264 void KToggleAction::virtual_hook( int id, void* data ) 02265 { KAction::virtual_hook( id, data ); } 02266 02267 void KRadioAction::virtual_hook( int id, void* data ) 02268 { KToggleAction::virtual_hook( id, data ); } 02269 02270 void KSelectAction::virtual_hook( int id, void* data ) 02271 { KAction::virtual_hook( id, data ); } 02272 02273 void KListAction::virtual_hook( int id, void* data ) 02274 { KSelectAction::virtual_hook( id, data ); } 02275 02276 void KRecentFilesAction::virtual_hook( int id, void* data ) 02277 { KListAction::virtual_hook( id, data ); } 02278 02279 void KFontAction::virtual_hook( int id, void* data ) 02280 { KSelectAction::virtual_hook( id, data ); } 02281 02282 void KFontSizeAction::virtual_hook( int id, void* data ) 02283 { KSelectAction::virtual_hook( id, data ); } 02284 02285 void KActionMenu::virtual_hook( int id, void* data ) 02286 { KAction::virtual_hook( id, data ); } 02287 02288 void KToolBarPopupAction::virtual_hook( int id, void* data ) 02289 { KAction::virtual_hook( id, data ); } 02290 02291 void KToggleToolBarAction::virtual_hook( int id, void* data ) 02292 { KToggleAction::virtual_hook( id, data ); } 02293 02294 void KToggleFullScreenAction::virtual_hook( int id, void* data ) 02295 { KToggleAction::virtual_hook( id, data ); } 02296 02297 void KWidgetAction::virtual_hook( int id, void* data ) 02298 { KAction::virtual_hook( id, data ); } 02299 02300 void KActionSeparator::virtual_hook( int id, void* data ) 02301 { KAction::virtual_hook( id, data ); } 02302 02303 void KPasteTextAction::virtual_hook( int id, void* data ) 02304 { KAction::virtual_hook( id, data ); } 02305 02306 /* vim: et sw=2 ts=2 02307 */ 02308 02309 #include "kactionclasses.moc"
KDE Logo
This file is part of the documentation for kdeui Library Version 3.4.0.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Tue Apr 12 22:56:19 2005 by doxygen 1.3.7 written by Dimitri van Heesch, © 1997-2003