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