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