kactionclasses.cpp
00001 /* This file is part of the KDE libraries 00002 Copyright (C) 1999 Reginald Stadlbauer <reggie@kde.org> 00003 (C) 1999 Simon Hausmann <hausmann@kde.org> 00004 (C) 2000 Nicolas Hadacek <haadcek@kde.org> 00005 (C) 2000 Kurt Granroth <granroth@kde.org> 00006 (C) 2000 Michael Koch <koch@kde.org> 00007 (C) 2001 Holger Freyther <freyther@kde.org> 00008 (C) 2002 Ellis Whitehead <ellis@kde.org> 00009 (C) 2002 Joseph Wenninger <jowenn@kde.org> 00010 (C) 2003 Andras Mantia <amantia@kde.org> 00011 00012 This library is free software; you can redistribute it and/or 00013 modify it under the terms of the GNU Library General Public 00014 License version 2 as published by the Free Software Foundation. 00015 00016 This library is distributed in the hope that it will be useful, 00017 but WITHOUT ANY WARRANTY; without even the implied warranty of 00018 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00019 Library General Public License for more details. 00020 00021 You should have received a copy of the GNU Library General Public License 00022 along with this library; see the file COPYING.LIB. If not, write to 00023 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00024 Boston, MA 02110-1301, USA. 00025 */ 00026 00027 #include "kactionclasses.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 <kaccel.h> 00045 #include <kapplication.h> 00046 #include <kconfig.h> 00047 #include <kdebug.h> 00048 #include <kfontcombo.h> 00049 #include <kfontdialog.h> 00050 #include <klocale.h> 00051 #include <kmainwindow.h> 00052 #include <kmenubar.h> 00053 #include <kpopupmenu.h> 00054 #include <ktoolbar.h> 00055 #include <ktoolbarbutton.h> 00056 #include <kurl.h> 00057 #include <kstandarddirs.h> 00058 #include <kstringhandler.h> 00059 00060 class KToggleAction::KToggleActionPrivate 00061 { 00062 public: 00063 KToggleActionPrivate() 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 KToggleAction::KToggleAction( const TQString& text, const KShortcut& cut, 00075 TQObject* parent, 00076 const char* name ) 00077 : KAction( text, cut, parent, name ) 00078 { 00079 d = new KToggleActionPrivate; 00080 } 00081 00082 KToggleAction::KToggleAction( const TQString& text, const KShortcut& cut, 00083 const TQObject* receiver, const char* slot, 00084 TQObject* parent, const char* name ) 00085 : KAction( text, cut, receiver, slot, parent, name ) 00086 { 00087 d = new KToggleActionPrivate; 00088 } 00089 00090 KToggleAction::KToggleAction( const TQString& text, const TQIconSet& pix, 00091 const KShortcut& cut, 00092 TQObject* parent, const char* name ) 00093 : KAction( text, pix, cut, parent, name ) 00094 { 00095 d = new KToggleActionPrivate; 00096 } 00097 00098 KToggleAction::KToggleAction( const TQString& text, const TQString& pix, 00099 const KShortcut& cut, 00100 TQObject* parent, const char* name ) 00101 : KAction( text, pix, cut, parent, name ) 00102 { 00103 d = new KToggleActionPrivate; 00104 } 00105 00106 KToggleAction::KToggleAction( const TQString& text, const TQIconSet& pix, 00107 const KShortcut& cut, 00108 const TQObject* receiver, 00109 const char* slot, TQObject* parent, 00110 const char* name ) 00111 : KAction( text, pix, cut, receiver, slot, parent, name ) 00112 { 00113 d = new KToggleActionPrivate; 00114 } 00115 00116 KToggleAction::KToggleAction( const TQString& text, const TQString& pix, 00117 const KShortcut& cut, 00118 const TQObject* receiver, 00119 const char* slot, TQObject* parent, 00120 const char* name ) 00121 : KAction( text, pix, cut, receiver, slot, parent, name ) 00122 { 00123 d = new KToggleActionPrivate; 00124 } 00125 00126 KToggleAction::KToggleAction( TQObject* parent, const char* name ) 00127 : KAction( parent, name ) 00128 { 00129 d = new KToggleActionPrivate; 00130 } 00131 00132 KToggleAction::~KToggleAction() 00133 { 00134 delete d->m_checkedGuiItem; 00135 delete d; 00136 } 00137 00138 int KToggleAction::plug( TQWidget* widget, int index ) 00139 { 00140 if ( !::tqqt_cast<TQPopupMenu *>( widget ) && !::tqqt_cast<KToolBar *>( widget ) ) 00141 { 00142 kdWarning() << "Can not plug KToggleAction in " << widget->className() << endl; 00143 return -1; 00144 } 00145 if (kapp && !kapp->authorizeKAction(name())) 00146 return -1; 00147 00148 int _index = KAction::plug( widget, index ); 00149 if ( _index == -1 ) 00150 return _index; 00151 00152 if ( ::tqqt_cast<KToolBar *>( widget ) ) { 00153 KToolBar *bar = static_cast<KToolBar *>( 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 KToggleAction::setChecked( bool c ) 00166 { 00167 if ( c == d->m_checked ) 00168 return; 00169 //kdDebug(129) << "KToggleAction::setChecked(" << c << ") " << this << " " << name() << endl; 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<KToggleAction *>( it.current() ) && it.current() != this && 00184 static_cast<KToggleAction*>(it.current())->exclusiveGroup() == exclusiveGroup() ) { 00185 KToggleAction *a = static_cast<KToggleAction*>(it.current()); 00186 if( a->isChecked() ) { 00187 a->setChecked( false ); 00188 emit a->toggled( false ); 00189 } 00190 } 00191 } 00192 } 00193 } 00194 } 00195 00196 void KToggleAction::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( KIcon::Small ), gui->text() ); 00209 else 00210 pm->changeItem( itemId_, gui->text() ); 00211 00212 // If the text doesn't change, then set the icon to be "pressed", otherwise 00213 // there is too little difference between checked and unchecked. 00214 if ( d->m_checkedGuiItem->text() == guiItem().text() ) 00215 pm->setItemChecked( itemId_, d->m_checked ); 00216 00217 if ( !d->m_checkedGuiItem->whatsThis().isEmpty() ) // if empty, we keep the initial one 00218 pm->TQMenuData::setWhatsThis( itemId_, gui->whatsThis() ); 00219 updateShortcut( pm, itemId_ ); 00220 } 00221 } 00222 else if ( ::tqqt_cast<TQMenuBar *>( w ) ) // not handled in plug... 00223 static_cast<TQMenuBar*>(w)->setItemChecked( itemId( id ), d->m_checked ); 00224 else if ( ::tqqt_cast<KToolBar *>( w ) ) 00225 { 00226 TQWidget* r = static_cast<KToolBar*>( w )->getButton( itemId( id ) ); 00227 if ( r && ::tqqt_cast<KToolBarButton *>( r ) ) { 00228 static_cast<KToolBar*>( 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<KToolBar*>( w )->setButtonIconSet( itemId( id ), gui->iconSet( KIcon::Toolbar ) ); 00232 } 00233 } 00234 } 00235 } 00236 00237 void KToggleAction::slotActivated() 00238 { 00239 setChecked( !isChecked() ); 00240 KAction::slotActivated(); 00241 emit toggled( isChecked() ); 00242 } 00243 00244 bool KToggleAction::isChecked() const 00245 { 00246 return d->m_checked; 00247 } 00248 00249 void KToggleAction::setExclusiveGroup( const TQString& name ) 00250 { 00251 d->m_exclusiveGroup = name; 00252 } 00253 00254 TQString KToggleAction::exclusiveGroup() const 00255 { 00256 return d->m_exclusiveGroup; 00257 } 00258 00259 void KToggleAction::setCheckedState( const KGuiItem& checkedItem ) 00260 { 00261 delete d->m_checkedGuiItem; 00262 d->m_checkedGuiItem = new KGuiItem( checkedItem ); 00263 } 00264 00265 TQString KToggleAction::toolTip() const 00266 { 00267 if ( d->m_checkedGuiItem && d->m_checked ) 00268 return d->m_checkedGuiItem->toolTip(); 00269 else 00270 return KAction::toolTip(); 00271 } 00272 00273 KRadioAction::KRadioAction( const TQString& text, const KShortcut& cut, 00274 TQObject* parent, const char* name ) 00275 : KToggleAction( text, cut, parent, name ) 00276 { 00277 } 00278 00279 KRadioAction::KRadioAction( const TQString& text, const KShortcut& cut, 00280 const TQObject* receiver, const char* slot, 00281 TQObject* parent, const char* name ) 00282 : KToggleAction( text, cut, receiver, slot, parent, name ) 00283 { 00284 } 00285 00286 KRadioAction::KRadioAction( const TQString& text, const TQIconSet& pix, 00287 const KShortcut& cut, 00288 TQObject* parent, const char* name ) 00289 : KToggleAction( text, pix, cut, parent, name ) 00290 { 00291 } 00292 00293 KRadioAction::KRadioAction( const TQString& text, const TQString& pix, 00294 const KShortcut& cut, 00295 TQObject* parent, const char* name ) 00296 : KToggleAction( text, pix, cut, parent, name ) 00297 { 00298 } 00299 00300 KRadioAction::KRadioAction( const TQString& text, const TQIconSet& pix, 00301 const KShortcut& cut, 00302 const TQObject* receiver, const char* slot, 00303 TQObject* parent, const char* name ) 00304 : KToggleAction( text, pix, cut, receiver, slot, parent, name ) 00305 { 00306 } 00307 00308 KRadioAction::KRadioAction( const TQString& text, const TQString& pix, 00309 const KShortcut& cut, 00310 const TQObject* receiver, const char* slot, 00311 TQObject* parent, const char* name ) 00312 : KToggleAction( text, pix, cut, receiver, slot, parent, name ) 00313 { 00314 } 00315 00316 KRadioAction::KRadioAction( TQObject* parent, const char* name ) 00317 : KToggleAction( parent, name ) 00318 { 00319 } 00320 00321 void KRadioAction::slotActivated() 00322 { 00323 if ( isChecked() ) 00324 { 00325 const TQObject *senderObj = TQT_TQOBJECT_CONST(sender()); 00326 00327 if ( !senderObj || !::tqqt_cast<const KToolBarButton *>( senderObj ) ) 00328 return; 00329 00330 const_cast<KToolBarButton *>( static_cast<const KToolBarButton *>( TQT_TQWIDGET_CONST(senderObj) ) )->on( true ); 00331 00332 return; 00333 } 00334 00335 KToggleAction::slotActivated(); 00336 } 00337 00338 class KSelectAction::KSelectActionPrivate 00339 { 00340 public: 00341 KSelectActionPrivate() 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 KSelectAction::KSelectAction( const TQString& text, const KShortcut& cut, 00377 TQObject* parent, const char* name ) 00378 : KAction( text, cut, parent, name ) 00379 { 00380 d = new KSelectActionPrivate; 00381 } 00382 00383 KSelectAction::KSelectAction( const TQString& text, const KShortcut& cut, 00384 const TQObject* receiver, const char* slot, 00385 TQObject* parent, const char* name ) 00386 : KAction( text, cut, receiver, slot, parent, name ) 00387 { 00388 d = new KSelectActionPrivate; 00389 } 00390 00391 KSelectAction::KSelectAction( const TQString& text, const TQIconSet& pix, 00392 const KShortcut& cut, 00393 TQObject* parent, const char* name ) 00394 : KAction( text, pix, cut, parent, name ) 00395 { 00396 d = new KSelectActionPrivate; 00397 } 00398 00399 KSelectAction::KSelectAction( const TQString& text, const TQString& pix, 00400 const KShortcut& cut, 00401 TQObject* parent, const char* name ) 00402 : KAction( text, pix, cut, parent, name ) 00403 { 00404 d = new KSelectActionPrivate; 00405 } 00406 00407 KSelectAction::KSelectAction( const TQString& text, const TQIconSet& pix, 00408 const KShortcut& cut, 00409 const TQObject* receiver, 00410 const char* slot, TQObject* parent, 00411 const char* name ) 00412 : KAction( text, pix, cut, receiver, slot, parent, name ) 00413 { 00414 d = new KSelectActionPrivate; 00415 } 00416 00417 KSelectAction::KSelectAction( const TQString& text, const TQString& pix, 00418 const KShortcut& cut, 00419 const TQObject* receiver, 00420 const char* slot, TQObject* parent, 00421 const char* name ) 00422 : KAction( text, pix, cut, receiver, slot, parent, name ) 00423 { 00424 d = new KSelectActionPrivate; 00425 } 00426 00427 KSelectAction::KSelectAction( TQObject* parent, const char* name ) 00428 : KAction( parent, name ) 00429 { 00430 d = new KSelectActionPrivate; 00431 } 00432 00433 KSelectAction::~KSelectAction() 00434 { 00435 assert(d); 00436 delete d->m_menu; 00437 delete d; d = 0; 00438 } 00439 00440 void KSelectAction::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 // emit KAction::activated(); 00463 // emit activated( currentItem() ); 00464 // emit activated( currentText() ); 00465 } 00466 00467 void KSelectAction::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 KSelectAction::setMaxComboViewCount( int n ) 00482 { 00483 d->m_maxComboViewCount = n; 00484 } 00485 00486 TQPopupMenu* KSelectAction::popupMenu() const 00487 { 00488 kdDebug(129) << "KAction::popupMenu()" << endl; // remove -- ellis 00489 if ( !d->m_menu ) 00490 { 00491 d->m_menu = new KPopupMenu(0L, "KSelectAction::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 KSelectAction::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 KSelectAction::changeItem( int index, const TQString& text ) 00517 { 00518 if ( index < 0 || index >= (int)d->m_list.count() ) 00519 { 00520 kdWarning() << "KSelectAction::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 KSelectAction::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<KToolBar *>( w ) ) 00541 { 00542 TQWidget* r = (static_cast<KToolBar*>( 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 KSelectAction::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 // Disable if empty and not editable 00563 setEnabled ( lst.count() > 0 || d->m_edit ); 00564 } 00565 00566 TQStringList KSelectAction::items() const 00567 { 00568 return d->m_list; 00569 } 00570 00571 TQString KSelectAction::currentText() const 00572 { 00573 if ( currentItem() < 0 ) 00574 return TQString::null; 00575 00576 return d->m_list[ currentItem() ]; 00577 } 00578 00579 int KSelectAction::currentItem() const 00580 { 00581 return d->m_current; 00582 } 00583 00584 void KSelectAction::updateCurrentItem( int id ) 00585 { 00586 if ( d->m_current < 0 ) 00587 return; 00588 00589 TQWidget* w = container( id ); 00590 if ( ::tqqt_cast<KToolBar *>( w ) ) { 00591 TQWidget* r = static_cast<KToolBar*>( 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 KSelectAction::comboWidth() const 00600 { 00601 return d->m_comboWidth; 00602 } 00603 00604 void KSelectAction::updateComboWidth( int id ) 00605 { 00606 TQWidget* w = container( id ); 00607 if ( ::tqqt_cast<KToolBar *>( w ) ) { 00608 TQWidget* r = static_cast<KToolBar*>( 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 KSelectAction::updateItems( int id ) 00618 { 00619 kdDebug(129) << "KAction::updateItems( " << id << ", lst )" << endl; // remove -- ellis 00620 TQWidget* w = container( id ); 00621 if ( ::tqqt_cast<KToolBar *>( w ) ) { 00622 TQWidget* r = static_cast<KToolBar*>( 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 // qt caches and never recalculates the sizeHint() 00631 // qcombobox.cpp recommends calling setFont to invalidate the sizeHint 00632 // setFont sets own_font = True, so we're a bit mean and calll 00633 // unsetFont which calls setFont and then overwrites the own_font 00634 cb->unsetFont(); 00635 } 00636 } 00637 } 00638 00639 int KSelectAction::plug( TQWidget *widget, int index ) 00640 { 00641 if (kapp && !kapp->authorizeKAction(name())) 00642 return -1; 00643 kdDebug(129) << "KSelectAction::plug( " << widget << ", " << index << " )" << endl; // remove -- ellis 00644 if ( ::tqqt_cast<TQPopupMenu *>( widget) ) 00645 { 00646 // Create the PopupMenu and store it in m_menu 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<KToolBar *>( widget ) ) 00669 { 00670 KToolBar* bar = static_cast<KToolBar*>( widget ); 00671 int id_ = KAction::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 // Create the PopupMenu and store it in m_menu 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 KAction in " << widget->className() << endl; 00722 return -1; 00723 } 00724 00725 TQStringList KSelectAction::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 KSelectAction::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 KSelectAction::updateClear( int id ) 00755 { 00756 TQWidget* w = container( id ); 00757 if ( ::tqqt_cast<KToolBar *>( w ) ) { 00758 TQWidget* r = static_cast<KToolBar*>( 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 KSelectAction::slotActivated( int id ) 00767 { 00768 if ( d->m_current == id ) 00769 return; 00770 00771 setCurrentItem( id ); 00772 // Delay this. Especially useful when the slot connected to activated() will re-create 00773 // the menu, e.g. in the recent files action. This prevents a crash. 00774 TQTimer::singleShot( 0, this, TQT_SLOT( slotActivated() ) ); 00775 } 00776 00777 void KSelectAction::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 // Delay this. Especially useful when the slot connected to activated() will re-create 00795 // the menu, e.g. in the recent files action. This prevents a crash. 00796 TQTimer::singleShot( 0, this, TQT_SLOT( slotActivated() ) ); 00797 } 00798 00799 void KSelectAction::slotActivated() 00800 { 00801 KAction::slotActivated(); 00802 kdDebug(129) << "KSelectAction::slotActivated currentItem=" << currentItem() << " currentText=" << currentText() << endl; 00803 emit activated( currentItem() ); 00804 emit activated( currentText() ); 00805 } 00806 00807 void KSelectAction::setEditable( bool edit ) 00808 { 00809 d->m_edit = edit; 00810 } 00811 00812 bool KSelectAction::isEditable() const 00813 { 00814 return d->m_edit; 00815 } 00816 00817 void KSelectAction::setRemoveAmpersandsInCombo( bool b ) 00818 { 00819 setMenuAccelsEnabled( b ); 00820 } 00821 00822 bool KSelectAction::removeAmpersandsInCombo() const 00823 { 00824 return menuAccelsEnabled( ); 00825 } 00826 00827 void KSelectAction::setMenuAccelsEnabled( bool b ) 00828 { 00829 d->m_menuAccelsEnabled = b; 00830 } 00831 00832 bool KSelectAction::menuAccelsEnabled() const 00833 { 00834 return d->m_menuAccelsEnabled; 00835 } 00836 00837 class KListAction::KListActionPrivate 00838 { 00839 public: 00840 KListActionPrivate() 00841 { 00842 m_current = 0; 00843 } 00844 int m_current; 00845 }; 00846 00847 KListAction::KListAction( const TQString& text, const KShortcut& cut, 00848 TQObject* parent, const char* name ) 00849 : KSelectAction( text, cut, parent, name ) 00850 { 00851 d = new KListActionPrivate; 00852 } 00853 00854 KListAction::KListAction( const TQString& text, const KShortcut& cut, 00855 const TQObject* receiver, const char* slot, 00856 TQObject* parent, const char* name ) 00857 : KSelectAction( text, cut, parent, name ) 00858 { 00859 d = new KListActionPrivate; 00860 if ( receiver ) 00861 connect( this, TQT_SIGNAL( activated( int ) ), receiver, slot ); 00862 } 00863 00864 KListAction::KListAction( const TQString& text, const TQIconSet& pix, 00865 const KShortcut& cut, 00866 TQObject* parent, const char* name ) 00867 : KSelectAction( text, pix, cut, parent, name ) 00868 { 00869 d = new KListActionPrivate; 00870 } 00871 00872 KListAction::KListAction( const TQString& text, const TQString& pix, 00873 const KShortcut& cut, 00874 TQObject* parent, const char* name ) 00875 : KSelectAction( text, pix, cut, parent, name ) 00876 { 00877 d = new KListActionPrivate; 00878 } 00879 00880 KListAction::KListAction( const TQString& text, const TQIconSet& pix, 00881 const KShortcut& cut, const TQObject* receiver, 00882 const char* slot, TQObject* parent, 00883 const char* name ) 00884 : KSelectAction( text, pix, cut, parent, name ) 00885 { 00886 d = new KListActionPrivate; 00887 if ( receiver ) 00888 connect( this, TQT_SIGNAL( activated( int ) ), receiver, slot ); 00889 } 00890 00891 KListAction::KListAction( const TQString& text, const TQString& pix, 00892 const KShortcut& cut, const TQObject* receiver, 00893 const char* slot, TQObject* parent, 00894 const char* name ) 00895 : KSelectAction( text, pix, cut, parent, name ) 00896 { 00897 d = new KListActionPrivate; 00898 if ( receiver ) 00899 connect( this, TQT_SIGNAL( activated( int ) ), receiver, slot ); 00900 } 00901 00902 KListAction::KListAction( TQObject* parent, const char* name ) 00903 : KSelectAction( parent, name ) 00904 { 00905 d = new KListActionPrivate; 00906 } 00907 00908 KListAction::~KListAction() 00909 { 00910 delete d; d = 0; 00911 } 00912 00913 void KListAction::setCurrentItem( int index ) 00914 { 00915 KSelectAction::setCurrentItem( index ); 00916 d->m_current = index; 00917 00918 // emit KAction::activated(); 00919 // emit activated( currentItem() ); 00920 // emit activated( currentText() ); 00921 } 00922 00923 TQString KListAction::currentText() const 00924 { 00925 return KSelectAction::currentText(); 00926 } 00927 00928 int KListAction::currentItem() const 00929 { 00930 return d->m_current; 00931 } 00932 00933 class KRecentFilesAction::KRecentFilesActionPrivate 00934 { 00935 public: 00936 KRecentFilesActionPrivate() 00937 { 00938 m_maxItems = 0; 00939 m_popup = 0; 00940 } 00941 uint m_maxItems; 00942 KPopupMenu *m_popup; 00943 TQMap<TQString, TQString> m_shortNames; 00944 TQMap<TQString, KURL> m_urls; 00945 }; 00946 00947 KRecentFilesAction::KRecentFilesAction( const TQString& text, 00948 const KShortcut& cut, 00949 TQObject* parent, const char* name, 00950 uint maxItems ) 00951 : KListAction( text, cut, parent, name) 00952 { 00953 d = new KRecentFilesActionPrivate; 00954 d->m_maxItems = maxItems; 00955 00956 init(); 00957 } 00958 00959 KRecentFilesAction::KRecentFilesAction( const TQString& text, 00960 const KShortcut& cut, 00961 const TQObject* receiver, 00962 const char* slot, 00963 TQObject* parent, const char* name, 00964 uint maxItems ) 00965 : KListAction( text, cut, parent, name) 00966 { 00967 d = new KRecentFilesActionPrivate; 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 KRecentFilesAction::KRecentFilesAction( const TQString& text, 00978 const TQIconSet& pix, 00979 const KShortcut& cut, 00980 TQObject* parent, const char* name, 00981 uint maxItems ) 00982 : KListAction( text, pix, cut, parent, name) 00983 { 00984 d = new KRecentFilesActionPrivate; 00985 d->m_maxItems = maxItems; 00986 00987 init(); 00988 } 00989 00990 KRecentFilesAction::KRecentFilesAction( const TQString& text, 00991 const TQString& pix, 00992 const KShortcut& cut, 00993 TQObject* parent, const char* name, 00994 uint maxItems ) 00995 : KListAction( text, pix, cut, parent, name) 00996 { 00997 d = new KRecentFilesActionPrivate; 00998 d->m_maxItems = maxItems; 00999 01000 init(); 01001 } 01002 01003 KRecentFilesAction::KRecentFilesAction( const TQString& text, 01004 const TQIconSet& pix, 01005 const KShortcut& cut, 01006 const TQObject* receiver, 01007 const char* slot, 01008 TQObject* parent, const char* name, 01009 uint maxItems ) 01010 : KListAction( text, pix, cut, parent, name) 01011 { 01012 d = new KRecentFilesActionPrivate; 01013 d->m_maxItems = maxItems; 01014 01015 init(); 01016 01017 if ( receiver ) 01018 connect( this, TQT_SIGNAL(urlSelected(const KURL&)), 01019 receiver, slot ); 01020 } 01021 01022 KRecentFilesAction::KRecentFilesAction( const TQString& text, 01023 const TQString& pix, 01024 const KShortcut& cut, 01025 const TQObject* receiver, 01026 const char* slot, 01027 TQObject* parent, const char* name, 01028 uint maxItems ) 01029 : KListAction( text, pix, cut, parent, name) 01030 { 01031 d = new KRecentFilesActionPrivate; 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 KRecentFilesAction::KRecentFilesAction( TQObject* parent, const char* name, 01042 uint maxItems ) 01043 : KListAction( parent, name ) 01044 { 01045 d = new KRecentFilesActionPrivate; 01046 d->m_maxItems = maxItems; 01047 01048 init(); 01049 } 01050 01051 void KRecentFilesAction::init() 01052 { 01053 KRecentFilesAction *that = const_cast<KRecentFilesAction*>(this); 01054 that->d->m_popup = new KPopupMenu; 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 KRecentFilesAction::~KRecentFilesAction() 01064 { 01065 delete d->m_popup; 01066 delete d; d = 0; 01067 } 01068 01069 uint KRecentFilesAction::maxItems() const 01070 { 01071 return d->m_maxItems; 01072 } 01073 01074 void KRecentFilesAction::setMaxItems( uint maxItems ) 01075 { 01076 TQStringList lst = KSelectAction::items(); 01077 uint oldCount = lst.count(); 01078 01079 // set new maxItems 01080 d->m_maxItems = maxItems; 01081 01082 // remove all items that are too much 01083 while( lst.count() > maxItems ) 01084 { 01085 // remove last item 01086 TQString lastItem = lst.last(); 01087 d->m_shortNames.erase( lastItem ); 01088 d->m_urls.erase( lastItem ); 01089 lst.remove( lastItem ); 01090 } 01091 01092 // set new list if changed 01093 if( lst.count() != oldCount ) 01094 setItems( lst ); 01095 } 01096 01097 void KRecentFilesAction::addURL( const KURL& url ) 01098 { 01099 addURL( url, url.fileName() ); 01100 } 01101 01102 void KRecentFilesAction::addURL( const KURL& url, const TQString& name ) 01103 { 01104 if ( url.isLocalFile() && !KGlobal::dirs()->relativeLocation("tmp", url.path()).startsWith("/")) 01105 return; 01106 const TQString file = url.pathOrURL(); 01107 TQStringList lst = KSelectAction::items(); 01108 01109 // remove file if already in list 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 // remove last item if already maxitems in list 01123 if( lst.count() == d->m_maxItems ) 01124 { 01125 // remove last item 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 // add file to list 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 KRecentFilesAction::removeURL( const KURL& url ) 01141 { 01142 TQStringList lst = KSelectAction::items(); 01143 TQString file = url.pathOrURL(); 01144 01145 // remove url 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 KRecentFilesAction::clearURLList() 01161 { 01162 clear(); 01163 d->m_shortNames.clear(); 01164 d->m_urls.clear(); 01165 } 01166 01167 void KRecentFilesAction::loadEntries( KConfig* 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 // read file list 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 // Don't restore if file doesn't exist anymore 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 // set file 01207 setItems( lst ); 01208 01209 config->setGroup( oldGroup ); 01210 } 01211 01212 void KRecentFilesAction::saveEntries( KConfig* config, TQString groupname ) 01213 { 01214 TQString key; 01215 TQString value; 01216 TQString oldGroup; 01217 TQStringList lst = KSelectAction::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 // write file list 01227 for( unsigned int i = 1 ; i <= lst.count() ; i++ ) 01228 { 01229 //kdDebug(129) << "Entry for " << lst[i-1] << d->m_urls[ lst[ i - 1 ] ] << endl; 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 KRecentFilesAction::itemSelected( const TQString& text ) 01242 { 01243 //return a copy of the URL since the slot where it is connected might call 01244 //addURL or removeURL where the d->m_urls.erase( title ) could destroy the 01245 //d->m_urls[ text ] and the emitted URL will be invalid in the rest of the slot 01246 emit urlSelected( KURL(d->m_urls[ text ]) ); 01247 } 01248 01249 void KRecentFilesAction::menuItemActivated( int id ) 01250 { 01251 TQString text = d->m_popup->text(id); 01252 //return a copy of the URL since the slot where it is connected might call 01253 //addURL or removeURL where the d->m_urls.erase( title ) could destroy the 01254 //d->m_urls[ text ] and the emitted URL will be invalid in the rest of the slot 01255 emit urlSelected( KURL(d->m_urls[ text ]) ); 01256 } 01257 01258 void KRecentFilesAction::menuAboutToShow() 01259 { 01260 KPopupMenu *menu = d->m_popup; 01261 menu->clear(); 01262 TQStringList list = KSelectAction::items(); 01263 for ( TQStringList::Iterator it = list.begin(); it != list.end(); ++it ) 01264 { 01265 menu->insertItem(*it); 01266 } 01267 } 01268 01269 int KRecentFilesAction::plug( TQWidget *widget, int index ) 01270 { 01271 if (kapp && !kapp->authorizeKAction(name())) 01272 return -1; 01273 // This is very related to KActionMenu::plug. 01274 // In fact this class could be an interesting base class for KActionMenu 01275 if ( ::tqqt_cast<KToolBar *>( widget ) ) 01276 { 01277 KToolBar *bar = (KToolBar *)widget; 01278 01279 int id_ = KAction::getToolButtonID(); 01280 01281 KInstance * instance; 01282 if ( m_parentCollection ) 01283 instance = m_parentCollection->instance(); 01284 else 01285 instance = KGlobal::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 KListAction::plug( widget, index ); 01304 } 01305 01306 void KRecentFilesAction::slotClicked() 01307 { 01308 KAction::slotActivated(); 01309 } 01310 01311 void KRecentFilesAction::slotActivated(const TQString& text) 01312 { 01313 KListAction::slotActivated(text); 01314 } 01315 01316 01317 void KRecentFilesAction::slotActivated(int id) 01318 { 01319 KListAction::slotActivated(id); 01320 } 01321 01322 01323 void KRecentFilesAction::slotActivated() 01324 { 01325 emit activated( currentItem() ); 01326 emit activated( currentText() ); 01327 } 01328 01329 //KDE4: rename to urls() and return a KURL::List 01330 TQStringList KRecentFilesAction::items() const 01331 { 01332 TQStringList lst = KSelectAction::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 //KDE4: remove 01344 TQStringList KRecentFilesAction::completeItems() const 01345 { 01346 return KSelectAction::items(); 01347 } 01348 01349 01350 class KFontAction::KFontActionPrivate 01351 { 01352 public: 01353 KFontActionPrivate() 01354 { 01355 } 01356 TQStringList m_fonts; 01357 }; 01358 01359 KFontAction::KFontAction( const TQString& text, 01360 const KShortcut& cut, TQObject* parent, 01361 const char* name ) 01362 : KSelectAction( text, cut, parent, name ) 01363 { 01364 d = new KFontActionPrivate; 01365 KFontChooser::getFontList( d->m_fonts, 0 ); 01366 KSelectAction::setItems( d->m_fonts ); 01367 setEditable( true ); 01368 } 01369 01370 KFontAction::KFontAction( const TQString& text, const KShortcut& cut, 01371 const TQObject* receiver, const char* slot, 01372 TQObject* parent, const char* name ) 01373 : KSelectAction( text, cut, receiver, slot, parent, name ) 01374 { 01375 d = new KFontActionPrivate; 01376 KFontChooser::getFontList( d->m_fonts, 0 ); 01377 KSelectAction::setItems( d->m_fonts ); 01378 setEditable( true ); 01379 } 01380 01381 KFontAction::KFontAction( const TQString& text, const TQIconSet& pix, 01382 const KShortcut& cut, 01383 TQObject* parent, const char* name ) 01384 : KSelectAction( text, pix, cut, parent, name ) 01385 { 01386 d = new KFontActionPrivate; 01387 KFontChooser::getFontList( d->m_fonts, 0 ); 01388 KSelectAction::setItems( d->m_fonts ); 01389 setEditable( true ); 01390 } 01391 01392 KFontAction::KFontAction( const TQString& text, const TQString& pix, 01393 const KShortcut& cut, 01394 TQObject* parent, const char* name ) 01395 : KSelectAction( text, pix, cut, parent, name ) 01396 { 01397 d = new KFontActionPrivate; 01398 KFontChooser::getFontList( d->m_fonts, 0 ); 01399 KSelectAction::setItems( d->m_fonts ); 01400 setEditable( true ); 01401 } 01402 01403 KFontAction::KFontAction( const TQString& text, const TQIconSet& pix, 01404 const KShortcut& cut, 01405 const TQObject* receiver, const char* slot, 01406 TQObject* parent, const char* name ) 01407 : KSelectAction( text, pix, cut, receiver, slot, parent, name ) 01408 { 01409 d = new KFontActionPrivate; 01410 KFontChooser::getFontList( d->m_fonts, 0 ); 01411 KSelectAction::setItems( d->m_fonts ); 01412 setEditable( true ); 01413 } 01414 01415 KFontAction::KFontAction( const TQString& text, const TQString& pix, 01416 const KShortcut& cut, 01417 const TQObject* receiver, const char* slot, 01418 TQObject* parent, const char* name ) 01419 : KSelectAction( text, pix, cut, receiver, slot, parent, name ) 01420 { 01421 d = new KFontActionPrivate; 01422 KFontChooser::getFontList( d->m_fonts, 0 ); 01423 KSelectAction::setItems( d->m_fonts ); 01424 setEditable( true ); 01425 } 01426 01427 KFontAction::KFontAction( uint fontListCriteria, const TQString& text, 01428 const KShortcut& cut, TQObject* parent, 01429 const char* name ) 01430 : KSelectAction( text, cut, parent, name ) 01431 { 01432 d = new KFontActionPrivate; 01433 KFontChooser::getFontList( d->m_fonts, fontListCriteria ); 01434 KSelectAction::setItems( d->m_fonts ); 01435 setEditable( true ); 01436 } 01437 01438 KFontAction::KFontAction( uint fontListCriteria, const TQString& text, const TQString& pix, 01439 const KShortcut& cut, 01440 TQObject* parent, const char* name ) 01441 : KSelectAction( text, pix, cut, parent, name ) 01442 { 01443 d = new KFontActionPrivate; 01444 KFontChooser::getFontList( d->m_fonts, fontListCriteria ); 01445 KSelectAction::setItems( d->m_fonts ); 01446 setEditable( true ); 01447 } 01448 01449 KFontAction::KFontAction( TQObject* parent, const char* name ) 01450 : KSelectAction( parent, name ) 01451 { 01452 d = new KFontActionPrivate; 01453 KFontChooser::getFontList( d->m_fonts, 0 ); 01454 KSelectAction::setItems( d->m_fonts ); 01455 setEditable( true ); 01456 } 01457 01458 KFontAction::~KFontAction() 01459 { 01460 delete d; 01461 d = 0; 01462 } 01463 01464 /* 01465 * Maintenance note: Keep in sync with KFontCombo::setCurrentFont() 01466 */ 01467 void KFontAction::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 // nothing matched yet, try a fontconfig reverse lookup and 01506 // check again to solve an alias 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 KFontAction::plug( TQWidget *w, int index ) 01526 { 01527 if (kapp && !kapp->authorizeKAction(name())) 01528 return -1; 01529 if ( ::tqqt_cast<KToolBar *>( w ) ) 01530 { 01531 KToolBar* bar = static_cast<KToolBar*>( w ); 01532 int id_ = KAction::getToolButtonID(); 01533 KFontCombo *cb = new KFontCombo( 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 KSelectAction::plug( w, index ); 01549 } 01550 01551 class KFontSizeAction::KFontSizeActionPrivate 01552 { 01553 public: 01554 KFontSizeActionPrivate() 01555 { 01556 } 01557 }; 01558 01559 KFontSizeAction::KFontSizeAction( const TQString& text, 01560 const KShortcut& cut, 01561 TQObject* parent, const char* name ) 01562 : KSelectAction( text, cut, parent, name ) 01563 { 01564 init(); 01565 } 01566 01567 KFontSizeAction::KFontSizeAction( const TQString& text, 01568 const KShortcut& cut, 01569 const TQObject* receiver, const char* slot, 01570 TQObject* parent, const char* name ) 01571 : KSelectAction( text, cut, receiver, slot, parent, name ) 01572 { 01573 init(); 01574 } 01575 01576 KFontSizeAction::KFontSizeAction( const TQString& text, const TQIconSet& pix, 01577 const KShortcut& cut, 01578 TQObject* parent, const char* name ) 01579 : KSelectAction( text, pix, cut, parent, name ) 01580 { 01581 init(); 01582 } 01583 01584 KFontSizeAction::KFontSizeAction( const TQString& text, const TQString& pix, 01585 const KShortcut& cut, 01586 TQObject* parent, const char* name ) 01587 : KSelectAction( text, pix, cut, parent, name ) 01588 { 01589 init(); 01590 } 01591 01592 KFontSizeAction::KFontSizeAction( const TQString& text, const TQIconSet& pix, 01593 const KShortcut& cut, 01594 const TQObject* receiver, 01595 const char* slot, TQObject* parent, 01596 const char* name ) 01597 : KSelectAction( text, pix, cut, receiver, slot, parent, name ) 01598 { 01599 init(); 01600 } 01601 01602 KFontSizeAction::KFontSizeAction( const TQString& text, const TQString& pix, 01603 const KShortcut& cut, 01604 const TQObject* receiver, 01605 const char* slot, TQObject* parent, 01606 const char* name ) 01607 : KSelectAction( text, pix, cut, receiver, slot, parent, name ) 01608 { 01609 init(); 01610 } 01611 01612 KFontSizeAction::KFontSizeAction( TQObject* parent, const char* name ) 01613 : KSelectAction( parent, name ) 01614 { 01615 init(); 01616 } 01617 01618 KFontSizeAction::~KFontSizeAction() 01619 { 01620 delete d; 01621 d = 0; 01622 } 01623 01624 void KFontSizeAction::init() 01625 { 01626 d = new KFontSizeActionPrivate; 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 KFontSizeAction::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() << "KFontSizeAction: Size " << size << " is out of range" << endl; 01647 return; 01648 } 01649 01650 int index = items().findIndex( TQString::number( size ) ); 01651 if ( index == -1 ) { 01652 // Insert at the correct position in the list (to keep sorting) 01653 TQValueList<int> lst; 01654 // Convert to list of ints 01655 TQStringList itemsList = items(); 01656 for (TQStringList::Iterator it = itemsList.begin() ; it != itemsList.end() ; ++it) 01657 lst.append( (*it).toInt() ); 01658 // New size 01659 lst.append( size ); 01660 // Sort the list 01661 qHeapSort( lst ); 01662 // Convert back to string list 01663 TQStringList strLst; 01664 for (TQValueList<int>::Iterator it = lst.begin() ; it != lst.end() ; ++it) 01665 strLst.append( TQString::number(*it) ); 01666 KSelectAction::setItems( strLst ); 01667 // Find new current item 01668 index = lst.findIndex( size ); 01669 setCurrentItem( index ); 01670 } 01671 else 01672 setCurrentItem( index ); 01673 01674 01675 //emit KAction::activated(); 01676 //emit activated( index ); 01677 //emit activated( TQString::number( size ) ); 01678 //emit fontSizeChanged( size ); 01679 } 01680 01681 int KFontSizeAction::fontSize() const 01682 { 01683 return currentText().toInt(); 01684 } 01685 01686 void KFontSizeAction::slotActivated( int index ) 01687 { 01688 KSelectAction::slotActivated( index ); 01689 01690 emit fontSizeChanged( items()[ index ].toInt() ); 01691 } 01692 01693 void KFontSizeAction::slotActivated( const TQString& size ) 01694 { 01695 setFontSize( size.toInt() ); // insert sorted first 01696 KSelectAction::slotActivated( size ); 01697 emit fontSizeChanged( size.toInt() ); 01698 } 01699 01700 class KActionMenu::KActionMenuPrivate 01701 { 01702 public: 01703 KActionMenuPrivate() 01704 { 01705 m_popup = new KPopupMenu(0L,"KActionMenu::KActionMenuPrivate"); 01706 m_delayed = true; 01707 m_stickyMenu = true; 01708 } 01709 ~KActionMenuPrivate() 01710 { 01711 delete m_popup; m_popup = 0; 01712 } 01713 KPopupMenu *m_popup; 01714 bool m_delayed; 01715 bool m_stickyMenu; 01716 }; 01717 01718 KActionMenu::KActionMenu( TQObject* parent, const char* name ) 01719 : KAction( parent, name ) 01720 { 01721 d = new KActionMenuPrivate; 01722 setShortcutConfigurable( false ); 01723 } 01724 01725 KActionMenu::KActionMenu( const TQString& text, TQObject* parent, 01726 const char* name ) 01727 : KAction( text, 0, parent, name ) 01728 { 01729 d = new KActionMenuPrivate; 01730 setShortcutConfigurable( false ); 01731 } 01732 01733 KActionMenu::KActionMenu( const TQString& text, const TQIconSet& icon, 01734 TQObject* parent, const char* name ) 01735 : KAction( text, icon, 0, parent, name ) 01736 { 01737 d = new KActionMenuPrivate; 01738 setShortcutConfigurable( false ); 01739 } 01740 01741 KActionMenu::KActionMenu( const TQString& text, const TQString& icon, 01742 TQObject* parent, const char* name ) 01743 : KAction( text, icon, 0, parent, name ) 01744 { 01745 d = new KActionMenuPrivate; 01746 setShortcutConfigurable( false ); 01747 } 01748 01749 KActionMenu::~KActionMenu() 01750 { 01751 unplugAll(); 01752 kdDebug(129) << "KActionMenu::~KActionMenu()" << endl; // ellis 01753 delete d; d = 0; 01754 } 01755 01756 void KActionMenu::popup( const TQPoint& global ) 01757 { 01758 popupMenu()->popup( global ); 01759 } 01760 01761 KPopupMenu* KActionMenu::popupMenu() const 01762 { 01763 return d->m_popup; 01764 } 01765 01766 void KActionMenu::insert( KAction* cmd, int index ) 01767 { 01768 if ( cmd ) 01769 cmd->plug( d->m_popup, index ); 01770 } 01771 01772 void KActionMenu::remove( KAction* cmd ) 01773 { 01774 if ( cmd ) 01775 cmd->unplug( d->m_popup ); 01776 } 01777 01778 bool KActionMenu::delayed() const { 01779 return d->m_delayed; 01780 } 01781 01782 void KActionMenu::setDelayed(bool _delayed) { 01783 d->m_delayed = _delayed; 01784 } 01785 01786 bool KActionMenu::stickyMenu() const { 01787 return d->m_stickyMenu; 01788 } 01789 01790 void KActionMenu::setStickyMenu(bool sticky) { 01791 d->m_stickyMenu = sticky; 01792 } 01793 01794 int KActionMenu::plug( TQWidget* widget, int index ) 01795 { 01796 if (kapp && !kapp->authorizeKAction(name())) 01797 return -1; 01798 kdDebug(129) << "KActionMenu::plug( " << widget << ", " << index << " )" << endl; // remove -- ellis 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<KToolBar *>( widget ) ) 01820 { 01821 KToolBar *bar = static_cast<KToolBar *>( widget ); 01822 01823 int id_ = KAction::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 KInstance *instance; 01832 01833 if ( m_parentCollection ) 01834 instance = m_parentCollection->instance(); 01835 else 01836 instance = KGlobal::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 KToolBarPopupAction::KToolBarPopupAction( const TQString& text, 01884 const TQString& icon, 01885 const KShortcut& cut, 01886 TQObject* parent, const char* name ) 01887 : KAction( text, icon, cut, parent, name ) 01888 { 01889 m_popup = 0; 01890 m_delayed = true; 01891 m_stickyMenu = true; 01892 } 01893 01894 KToolBarPopupAction::KToolBarPopupAction( const TQString& text, 01895 const TQString& icon, 01896 const KShortcut& cut, 01897 const TQObject* receiver, 01898 const char* slot, TQObject* parent, 01899 const char* name ) 01900 : KAction( text, icon, cut, receiver, slot, parent, name ) 01901 { 01902 m_popup = 0; 01903 m_delayed = true; 01904 m_stickyMenu = true; 01905 } 01906 01907 KToolBarPopupAction::KToolBarPopupAction( const KGuiItem& item, 01908 const KShortcut& cut, 01909 const TQObject* receiver, 01910 const char* slot, KActionCollection* parent, 01911 const char* name ) 01912 : KAction( item, cut, receiver, slot, parent, name ) 01913 { 01914 m_popup = 0; 01915 m_delayed = true; 01916 m_stickyMenu = true; 01917 } 01918 01919 KToolBarPopupAction::~KToolBarPopupAction() 01920 { 01921 delete m_popup; 01922 } 01923 01924 bool KToolBarPopupAction::delayed() const { 01925 return m_delayed; 01926 } 01927 01928 void KToolBarPopupAction::setDelayed(bool delayed) { 01929 m_delayed = delayed; 01930 } 01931 01932 bool KToolBarPopupAction::stickyMenu() const { 01933 return m_stickyMenu; 01934 } 01935 01936 void KToolBarPopupAction::setStickyMenu(bool sticky) { 01937 m_stickyMenu = sticky; 01938 } 01939 01940 int KToolBarPopupAction::plug( TQWidget *widget, int index ) 01941 { 01942 if (kapp && !kapp->authorizeKAction(name())) 01943 return -1; 01944 // This is very related to KActionMenu::plug. 01945 // In fact this class could be an interesting base class for KActionMenu 01946 if ( ::tqqt_cast<KToolBar *>( widget ) ) 01947 { 01948 KToolBar *bar = (KToolBar *)widget; 01949 01950 int id_ = KAction::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 KInstance * instance; 01959 if ( m_parentCollection ) 01960 instance = m_parentCollection->instance(); 01961 else 01962 instance = KGlobal::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 KAction::plug( widget, index ); 01987 } 01988 01989 KPopupMenu *KToolBarPopupAction::popupMenu() const 01990 { 01991 if ( !m_popup ) { 01992 KToolBarPopupAction *that = const_cast<KToolBarPopupAction*>(this); 01993 that->m_popup = new KPopupMenu; 01994 } 01995 return m_popup; 01996 } 01997 01999 02000 KToggleToolBarAction::KToggleToolBarAction( const char* toolBarName, 02001 const TQString& text, KActionCollection* parent, const char* name ) 02002 : KToggleAction( text, KShortcut(), parent, name ) 02003 , m_toolBarName( toolBarName ) 02004 , m_toolBar( 0L ) 02005 { 02006 } 02007 02008 KToggleToolBarAction::KToggleToolBarAction( KToolBar *toolBar, const TQString &text, 02009 KActionCollection *parent, const char *name ) 02010 : KToggleAction( text, KShortcut(), parent, name ) 02011 , m_toolBarName( 0 ), m_toolBar( toolBar ) 02012 { 02013 } 02014 02015 KToggleToolBarAction::~KToggleToolBarAction() 02016 { 02017 } 02018 02019 int KToggleToolBarAction::plug( TQWidget* w, int index ) 02020 { 02021 if (kapp && !kapp->authorizeKAction(name())) 02022 return -1; 02023 02024 if ( !m_toolBar ) { 02025 // Note: topLevelWidget() stops too early, we can't use it. 02026 TQWidget * tl = w; 02027 TQWidget * n; 02028 while ( !tl->isDialog() && ( n = tl->parentWidget() ) ) // lookup parent and store 02029 tl = n; 02030 02031 KMainWindow * mw = tqt_dynamic_cast<KMainWindow *>(tl); // try to see if it's a kmainwindow 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 // Also emit toggled when the toolbar's visibility changes (see comment in header) 02041 connect( m_toolBar, TQT_SIGNAL(visibilityChanged(bool)), this, TQT_SIGNAL(toggled(bool)) ); 02042 } else { 02043 setEnabled( false ); 02044 } 02045 02046 return KToggleAction::plug( w, index ); 02047 } 02048 02049 void KToggleToolBarAction::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<KMainWindow *>( mw ) ) 02059 static_cast<KMainWindow *>( mw )->setSettingsDirty(); 02060 } 02061 KToggleAction::setChecked( c ); 02062 } 02063 02065 02066 KToggleFullScreenAction::KToggleFullScreenAction( const KShortcut &cut, 02067 const TQObject* receiver, const char* slot, 02068 TQObject* parent, TQWidget* window, 02069 const char* name ) 02070 : KToggleAction( TQString::null, cut, receiver, slot, parent, name ), 02071 window( NULL ) 02072 { 02073 setWindow( window ); 02074 } 02075 02076 KToggleFullScreenAction::~KToggleFullScreenAction() 02077 { 02078 } 02079 02080 void KToggleFullScreenAction::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 KToggleFullScreenAction::setChecked( bool c ) 02090 { 02091 if (c) 02092 { 02093 setText(i18n("Exit F&ull Screen Mode")); 02094 setIcon("window_nofullscreen"); 02095 } 02096 else 02097 { 02098 setText(i18n("F&ull Screen Mode")); 02099 setIcon("window_fullscreen"); 02100 } 02101 KToggleAction::setChecked( c ); 02102 } 02103 02104 bool KToggleFullScreenAction::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(); // setChecked( window->isFullScreen()) wouldn't emit signals 02111 } 02112 return false; 02113 } 02114 02116 02117 KWidgetAction::KWidgetAction( TQWidget* widget, 02118 const TQString& text, const KShortcut& cut, 02119 const TQObject* receiver, const char* slot, 02120 KActionCollection* parent, const char* name ) 02121 : KAction( 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 KToolBar* toolBar = (KToolBar*)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->authorizeKAction(name())) 02154 return -1; 02155 02156 if ( !::tqqt_cast<KToolBar *>( w ) ) { 02157 kdError() << "KWidgetAction::plug: KWidgetAction must be plugged into KToolBar." << 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 KToolBar* toolBar = static_cast<KToolBar*>( w ); 02166 02167 int id = KAction::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 KToolBar* toolBar = (KToolBar*)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 /*showIt*/ ); 02192 } 02193 KAction::unplug( w ); 02194 } 02195 02196 void KWidgetAction::slotToolbarDestroyed() 02197 { 02198 //Q_ASSERT( m_widget ); // When exiting the app the widget could be destroyed before the toolbar. 02199 Q_ASSERT( isPlugged() ); 02200 if( !m_widget || !isPlugged() ) 02201 return; 02202 02203 // Don't let a toolbar being destroyed, delete my widget. 02204 m_widget->reparent( 0L, TQPoint(), false /*showIt*/ ); 02205 } 02206 02208 02209 KActionSeparator::KActionSeparator( TQObject *parent, const char *name ) 02210 : KAction( parent, name ) 02211 { 02212 } 02213 02214 KActionSeparator::~KActionSeparator() 02215 { 02216 } 02217 02218 int KActionSeparator::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<KToolBar *>( widget ) ) 02244 { 02245 KToolBar *toolBar = static_cast<KToolBar *>( 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 KPasteTextAction::KPasteTextAction( const TQString& text, 02260 const TQString& icon, 02261 const KShortcut& cut, 02262 const TQObject* receiver, 02263 const char* slot, TQObject* parent, 02264 const char* name) 02265 : KAction( text, icon, cut, receiver, slot, parent, name ) 02266 { 02267 m_popup = new KPopupMenu; 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 KPasteTextAction::~KPasteTextAction() 02275 { 02276 delete m_popup; 02277 } 02278 02279 void KPasteTextAction::setMixedMode(bool mode) 02280 { 02281 m_mixedMode = mode; 02282 } 02283 02284 int KPasteTextAction::plug( TQWidget *widget, int index ) 02285 { 02286 if (kapp && !kapp->authorizeKAction(name())) 02287 return -1; 02288 if ( ::tqqt_cast<KToolBar *>( widget ) ) 02289 { 02290 KToolBar *bar = (KToolBar *)widget; 02291 02292 int id_ = KAction::getToolButtonID(); 02293 02294 KInstance * instance; 02295 if ( m_parentCollection ) 02296 instance = m_parentCollection->instance(); 02297 else 02298 instance = KGlobal::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 KAction::plug( widget, index ); 02317 } 02318 02319 void KPasteTextAction::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 KPasteTextAction::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 KPasteTextAction::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 KAction::slotActivated(); 02372 } else 02373 KAction::slotActivated(); 02374 } 02375 02376 02377 void KToggleAction::virtual_hook( int id, void* data ) 02378 { KAction::virtual_hook( id, data ); } 02379 02380 void KRadioAction::virtual_hook( int id, void* data ) 02381 { KToggleAction::virtual_hook( id, data ); } 02382 02383 void KSelectAction::virtual_hook( int id, void* data ) 02384 { KAction::virtual_hook( id, data ); } 02385 02386 void KListAction::virtual_hook( int id, void* data ) 02387 { KSelectAction::virtual_hook( id, data ); } 02388 02389 void KRecentFilesAction::virtual_hook( int id, void* data ) 02390 { KListAction::virtual_hook( id, data ); } 02391 02392 void KFontAction::virtual_hook( int id, void* data ) 02393 { KSelectAction::virtual_hook( id, data ); } 02394 02395 void KFontSizeAction::virtual_hook( int id, void* data ) 02396 { KSelectAction::virtual_hook( id, data ); } 02397 02398 void KActionMenu::virtual_hook( int id, void* data ) 02399 { KAction::virtual_hook( id, data ); } 02400 02401 void KToolBarPopupAction::virtual_hook( int id, void* data ) 02402 { KAction::virtual_hook( id, data ); } 02403 02404 void KToggleToolBarAction::virtual_hook( int id, void* data ) 02405 { KToggleAction::virtual_hook( id, data ); } 02406 02407 void KToggleFullScreenAction::virtual_hook( int id, void* data ) 02408 { KToggleAction::virtual_hook( id, data ); } 02409 02410 void KWidgetAction::virtual_hook( int id, void* data ) 02411 { KAction::virtual_hook( id, data ); } 02412 02413 void KActionSeparator::virtual_hook( int id, void* data ) 02414 { KAction::virtual_hook( id, data ); } 02415 02416 void KPasteTextAction::virtual_hook( int id, void* data ) 02417 { KAction::virtual_hook( id, data ); } 02418 02419 /* vim: et sw=2 ts=2 02420 */ 02421 02422 #include "kactionclasses.moc"