kdeui Library API Documentation

ktoolbar.cpp

00001 /* This file is part of the KDE libraries 00002 Copyright 00003 (C) 2000 Reginald Stadlbauer (reggie@kde.org) 00004 (C) 1997, 1998 Stephan Kulow (coolo@kde.org) 00005 (C) 1997, 1998 Mark Donohoe (donohoe@kde.org) 00006 (C) 1997, 1998 Sven Radej (radej@kde.org) 00007 (C) 1997, 1998 Matthias Ettrich (ettrich@kde.org) 00008 (C) 1999 Chris Schlaeger (cs@kde.org) 00009 (C) 1999 Kurt Granroth (granroth@kde.org) 00010 00011 This library is free software; you can redistribute it and/or 00012 modify it under the terms of the GNU Library General Public 00013 License version 2 as published by the Free Software Foundation. 00014 00015 This library is distributed in the hope that it will be useful, 00016 but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00018 Library General Public License for more details. 00019 00020 You should have received a copy of the GNU Library General Public License 00021 along with this library; see the file COPYING.LIB. If not, write to 00022 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 00023 Boston, MA 02111-1307, USA. 00024 */ 00025 00026 #include <config.h> 00027 00028 #ifdef KDE_USE_FINAL 00029 #undef Always 00030 #include <qdockwindow.h> 00031 #endif 00032 #include "ktoolbar.h" 00033 #include "kmainwindow.h" 00034 00035 #include <string.h> 00036 00037 #include <qpainter.h> 00038 #include <qtooltip.h> 00039 #include <qdrawutil.h> 00040 #include <qstring.h> 00041 #include <qrect.h> 00042 #include <qobjectlist.h> 00043 #include <qtimer.h> 00044 #include <qstyle.h> 00045 00046 #include "klineedit.h" 00047 #include "kseparator.h" 00048 #include <klocale.h> 00049 #include <kapplication.h> 00050 #include <kaction.h> 00051 #include <kstdaction.h> 00052 #include <kglobal.h> 00053 #include <kconfig.h> 00054 #include <kiconloader.h> 00055 #include <kcombobox.h> 00056 #include <kpopupmenu.h> 00057 #include <kanimwidget.h> 00058 #include <kedittoolbar.h> 00059 00060 #if defined Q_WS_X11 && ! defined K_WS_QTONLY 00061 #include <kipc.h> 00062 #endif 00063 00064 #include <kwin.h> 00065 #include <kdebug.h> 00066 #include <qlayout.h> 00067 00068 #include "ktoolbarbutton.h" 00069 00070 enum { 00071 CONTEXT_TOP = 0, 00072 CONTEXT_LEFT = 1, 00073 CONTEXT_RIGHT = 2, 00074 CONTEXT_BOTTOM = 3, 00075 CONTEXT_FLOAT = 4, 00076 CONTEXT_FLAT = 5, 00077 CONTEXT_ICONS = 6, 00078 CONTEXT_TEXT = 7, 00079 CONTEXT_TEXTRIGHT = 8, 00080 CONTEXT_TEXTUNDER = 9, 00081 CONTEXT_ICONSIZES = 50 // starting point for the icon size list, put everything else before 00082 }; 00083 00084 class KToolBarPrivate 00085 { 00086 public: 00087 KToolBarPrivate() { 00088 m_iconSize = 0; 00089 m_iconText = KToolBar::IconOnly; 00090 m_highlight = true; 00091 m_transparent = true; 00092 m_honorStyle = false; 00093 00094 m_enableContext = true; 00095 00096 m_xmlguiClient = 0; 00097 m_configurePlugged = false; 00098 00099 oldPos = Qt::DockUnmanaged; 00100 00101 modified = m_isHorizontal = positioned = false; 00102 00103 IconSizeDefault = 0; 00104 IconTextDefault = "IconOnly"; 00105 00106 NewLineDefault = false; 00107 OffsetDefault = 0; 00108 PositionDefault = "Top"; 00109 HiddenDefault = false; 00110 idleButtons.setAutoDelete(true); 00111 } 00112 00113 int m_iconSize; 00114 KToolBar::IconText m_iconText; 00115 bool m_highlight : 1; 00116 bool m_transparent : 1; 00117 bool m_honorStyle : 1; 00118 bool m_isHorizontal : 1; 00119 bool m_enableContext : 1; 00120 bool m_configurePlugged : 1; 00121 bool modified : 1; 00122 bool positioned : 1; 00123 00124 QWidget *m_parent; 00125 00126 QMainWindow::ToolBarDock oldPos; 00127 00128 KXMLGUIClient *m_xmlguiClient; 00129 00130 struct ToolBarInfo 00131 { 00132 ToolBarInfo() : index( -1 ), offset( -1 ), newline( false ), dock( Qt::DockTop ) {} 00133 ToolBarInfo( Qt::Dock d, int i, bool n, int o ) : index( i ), offset( o ), newline( n ), dock( d ) {} 00134 int index, offset; 00135 bool newline; 00136 Qt::Dock dock; 00137 }; 00138 00139 ToolBarInfo toolBarInfo; 00140 QValueList<int> iconSizes; 00141 QTimer repaintTimer; 00142 00143 // Default Values. 00144 bool HiddenDefault; 00145 int IconSizeDefault; 00146 QString IconTextDefault; 00147 bool NewLineDefault; 00148 int OffsetDefault; 00149 QString PositionDefault; 00150 00151 QPtrList<QWidget> idleButtons; 00152 }; 00153 00154 KToolBarSeparator::KToolBarSeparator(Orientation o , bool l, QToolBar *parent, 00155 const char* name ) 00156 :QFrame( parent, name ), line( l ) 00157 { 00158 connect( parent, SIGNAL(orientationChanged(Orientation)), 00159 this, SLOT(setOrientation(Orientation)) ); 00160 setOrientation( o ); 00161 setBackgroundMode( parent->backgroundMode() ); 00162 setBackgroundOrigin( ParentOrigin ); 00163 } 00164 00165 void KToolBarSeparator::setOrientation( Orientation o ) 00166 { 00167 orient = o; 00168 setFrameStyle( NoFrame ); 00169 } 00170 00171 void KToolBarSeparator::drawContents( QPainter* p ) 00172 { 00173 if ( line ) { 00174 QStyle::SFlags flags = QStyle::Style_Default; 00175 00176 if ( orientation() == Horizontal ) 00177 flags = flags | QStyle::Style_Horizontal; 00178 00179 style().drawPrimitive(QStyle::PE_DockWindowSeparator, p, 00180 contentsRect(), colorGroup(), flags); 00181 } else { 00182 QFrame::drawContents(p); 00183 } 00184 } 00185 00186 void KToolBarSeparator::styleChange( QStyle& ) 00187 { 00188 setOrientation( orient ); 00189 } 00190 00191 QSize KToolBarSeparator::sizeHint() const 00192 { 00193 int dim = style().pixelMetric( QStyle::PM_DockWindowSeparatorExtent, this ); 00194 return orientation() == Vertical ? QSize( 0, dim ) : QSize( dim, 0 ); 00195 } 00196 00197 QSizePolicy KToolBarSeparator::sizePolicy() const 00198 { 00199 return QSizePolicy( QSizePolicy::Minimum, QSizePolicy::Minimum ); 00200 } 00201 00202 KToolBar::KToolBar( QWidget *parent, const char *name, bool honorStyle, bool readConfig ) 00203 : QToolBar( QString::fromLatin1( name ), 00204 dynamic_cast<QMainWindow*>(parent), 00205 parent, false, 00206 name ? name : "mainToolBar") 00207 { 00208 init( readConfig, honorStyle ); 00209 } 00210 00211 KToolBar::KToolBar( QMainWindow *parentWindow, QMainWindow::ToolBarDock dock, bool newLine, const char *name, bool honorStyle, bool readConfig ) 00212 : QToolBar( QString::fromLatin1( name ), 00213 parentWindow, dock, newLine, 00214 name ? name : "mainToolBar") 00215 { 00216 init( readConfig, honorStyle ); 00217 } 00218 00219 KToolBar::KToolBar( QMainWindow *parentWindow, QWidget *dock, bool newLine, const char *name, bool honorStyle, bool readConfig ) 00220 : QToolBar( QString::fromLatin1( name ), 00221 parentWindow, dock, newLine, 00222 name ? name : "mainToolBar") 00223 { 00224 init( readConfig, honorStyle ); 00225 } 00226 00227 KToolBar::~KToolBar() 00228 { 00229 emit toolbarDestroyed(); 00230 delete d; 00231 } 00232 00233 void KToolBar::init( bool readConfig, bool honorStyle ) 00234 { 00235 d = new KToolBarPrivate; 00236 // Get the default iconSize sense m_iconSize == 0 which isn't the default 00237 d->IconSizeDefault = iconSize(); 00238 setFullSize( true ); 00239 d->m_honorStyle = honorStyle; 00240 context = 0; 00241 layoutTimer = new QTimer( this ); 00242 connect( layoutTimer, SIGNAL( timeout() ), 00243 this, SLOT( rebuildLayout() ) ); 00244 connect( &(d->repaintTimer), SIGNAL( timeout() ), 00245 this, SLOT( slotRepaint() ) ); 00246 00247 if ( kapp ) { // may be null when started inside designer 00248 connect(kapp, SIGNAL(toolbarAppearanceChanged(int)), this, SLOT(slotAppearanceChanged())); 00249 // request notification of changes in icon style 00250 #if defined Q_WS_X11 && ! defined K_WS_QTONLY 00251 kapp->addKipcEventMask(KIPC::IconChanged); 00252 #endif 00253 connect(kapp, SIGNAL(iconChanged(int)), this, SLOT(slotIconChanged(int))); 00254 } 00255 00256 // finally, read in our configurable settings 00257 if ( readConfig ) 00258 slotReadConfig(); 00259 00260 if ( mainWindow() ) 00261 connect( mainWindow(), SIGNAL( toolBarPositionChanged( QToolBar * ) ), 00262 this, SLOT( toolBarPosChanged( QToolBar * ) ) ); 00263 00264 // Hack to make sure we recalculate our size when we dock. 00265 connect( this, SIGNAL(placeChanged(QDockWindow::Place)), SLOT(rebuildLayout()) ); 00266 } 00267 00268 int KToolBar::insertButton(const QString& icon, int id, bool enabled, 00269 const QString& text, int index, KInstance *_instance ) 00270 { 00271 KToolBarButton *button = new KToolBarButton( icon, id, this, 0, text, _instance ); 00272 00273 insertWidgetInternal( button, index, id ); 00274 button->setEnabled( enabled ); 00275 doConnections( button ); 00276 return index; 00277 } 00278 00279 00280 int KToolBar::insertButton(const QString& icon, int id, const char *signal, 00281 const QObject *receiver, const char *slot, 00282 bool enabled, const QString& text, int index, KInstance *_instance ) 00283 { 00284 KToolBarButton *button = new KToolBarButton( icon, id, this, 0, text, _instance); 00285 insertWidgetInternal( button, index, id ); 00286 button->setEnabled( enabled ); 00287 connect( button, signal, receiver, slot ); 00288 doConnections( button ); 00289 return index; 00290 } 00291 00292 00293 int KToolBar::insertButton(const QPixmap& pixmap, int id, bool enabled, 00294 const QString& text, int index ) 00295 { 00296 KToolBarButton *button = new KToolBarButton( pixmap, id, this, 0, text); 00297 insertWidgetInternal( button, index, id ); 00298 button->setEnabled( enabled ); 00299 doConnections( button ); 00300 return index; 00301 } 00302 00303 00304 int KToolBar::insertButton(const QPixmap& pixmap, int id, const char *signal, 00305 const QObject *receiver, const char *slot, 00306 bool enabled, const QString& text, 00307 int index ) 00308 { 00309 KToolBarButton *button = new KToolBarButton( pixmap, id, this, 0, text); 00310 insertWidgetInternal( button, index, id ); 00311 button->setEnabled( enabled ); 00312 connect( button, signal, receiver, slot ); 00313 doConnections( button ); 00314 return index; 00315 } 00316 00317 00318 int KToolBar::insertButton(const QString& icon, int id, QPopupMenu *popup, 00319 bool enabled, const QString &text, int index ) 00320 { 00321 KToolBarButton *button = new KToolBarButton( icon, id, this, 0, text ); 00322 insertWidgetInternal( button, index, id ); 00323 button->setEnabled( enabled ); 00324 button->setPopup( popup ); 00325 doConnections( button ); 00326 return index; 00327 } 00328 00329 00330 int KToolBar::insertButton(const QPixmap& pixmap, int id, QPopupMenu *popup, 00331 bool enabled, const QString &text, int index ) 00332 { 00333 KToolBarButton *button = new KToolBarButton( pixmap, id, this, 0, text ); 00334 insertWidgetInternal( button, index, id ); 00335 button->setEnabled( enabled ); 00336 button->setPopup( popup ); 00337 doConnections( button ); 00338 return index; 00339 } 00340 00341 00342 int KToolBar::insertLined (const QString& text, int id, 00343 const char *signal, 00344 const QObject *receiver, const char *slot, 00345 bool enabled , 00346 const QString& toolTipText, 00347 int size, int index ) 00348 { 00349 KLineEdit *lined = new KLineEdit ( this, 0 ); 00350 if ( !toolTipText.isEmpty() ) 00351 QToolTip::add( lined, toolTipText ); 00352 if ( size > 0 ) 00353 lined->setMinimumWidth( size ); 00354 insertWidgetInternal( lined, index, id ); 00355 connect( lined, signal, receiver, slot ); 00356 lined->setText(text); 00357 lined->setEnabled( enabled ); 00358 return index; 00359 } 00360 00361 int KToolBar::insertCombo (const QStringList &list, int id, bool writable, 00362 const char *signal, const QObject *receiver, 00363 const char *slot, bool enabled, 00364 const QString& tooltiptext, 00365 int size, int index, 00366 QComboBox::Policy policy ) 00367 { 00368 KComboBox *combo = new KComboBox ( writable, this ); 00369 00370 insertWidgetInternal( combo, index, id ); 00371 combo->insertStringList (list); 00372 combo->setInsertionPolicy(policy); 00373 combo->setEnabled( enabled ); 00374 if ( size > 0 ) 00375 combo->setMinimumWidth( size ); 00376 if (!tooltiptext.isNull()) 00377 QToolTip::add( combo, tooltiptext ); 00378 00379 if ( signal && receiver && slot ) 00380 connect ( combo, signal, receiver, slot ); 00381 return index; 00382 } 00383 00384 00385 int KToolBar::insertCombo (const QString& text, int id, bool writable, 00386 const char *signal, QObject *receiver, 00387 const char *slot, bool enabled, 00388 const QString& tooltiptext, 00389 int size, int index, 00390 QComboBox::Policy policy ) 00391 { 00392 KComboBox *combo = new KComboBox ( writable, this ); 00393 insertWidgetInternal( combo, index, id ); 00394 combo->insertItem (text); 00395 combo->setInsertionPolicy(policy); 00396 combo->setEnabled( enabled ); 00397 if ( size > 0 ) 00398 combo->setMinimumWidth( size ); 00399 if (!tooltiptext.isNull()) 00400 QToolTip::add( combo, tooltiptext ); 00401 connect (combo, signal, receiver, slot); 00402 return index; 00403 } 00404 00405 int KToolBar::insertSeparator(int index, int id) 00406 { 00407 QWidget *w = new KToolBarSeparator( orientation(), false, this, "tool bar separator" ); 00408 insertWidgetInternal( w, index, id ); 00409 return index; 00410 } 00411 00412 int KToolBar::insertLineSeparator(int index, int id) 00413 { 00414 QWidget *w = new KToolBarSeparator( orientation(), true, this, "tool bar separator" ); 00415 insertWidgetInternal( w, index, id ); 00416 return index; 00417 } 00418 00419 00420 int KToolBar::insertWidget(int id, int /*width*/, QWidget *widget, int index) 00421 { 00422 removeWidgetInternal( widget ); // in case we already have it ? 00423 insertWidgetInternal( widget, index, id ); 00424 return index; 00425 } 00426 00427 int KToolBar::insertAnimatedWidget(int id, QObject *receiver, const char *slot, 00428 const QString& icons, int index ) 00429 { 00430 KAnimWidget *anim = new KAnimWidget( icons, d->m_iconSize, this ); 00431 insertWidgetInternal( anim, index, id ); 00432 00433 if ( receiver ) 00434 connect( anim, SIGNAL(clicked()), receiver, slot); 00435 00436 return index; 00437 } 00438 00439 KAnimWidget *KToolBar::animatedWidget( int id ) 00440 { 00441 Id2WidgetMap::Iterator it = id2widget.find( id ); 00442 if ( it == id2widget.end() ) 00443 return 0; 00444 KAnimWidget *aw = dynamic_cast<KAnimWidget *>(*it); 00445 if ( aw ) 00446 return aw; 00447 QObjectList *l = queryList( "KAnimWidget" ); 00448 if ( !l || !l->first() ) { 00449 delete l; 00450 return 0; 00451 } 00452 00453 for ( QObject *o = l->first(); o; o = l->next() ) { 00454 KAnimWidget *aw = dynamic_cast<KAnimWidget *>(o); 00455 if ( aw ) 00456 { 00457 delete l; 00458 return aw; 00459 } 00460 } 00461 00462 delete l; 00463 return 0; 00464 } 00465 00466 00467 void KToolBar::addConnection (int id, const char *signal, 00468 const QObject *receiver, const char *slot) 00469 { 00470 QWidget* w = getWidget( id ); 00471 if ( w ) 00472 connect( w, signal, receiver, slot ); 00473 } 00474 00475 void KToolBar::setItemEnabled( int id, bool enabled ) 00476 { 00477 QWidget* w = getWidget( id ); 00478 if ( w ) 00479 w->setEnabled( enabled ); 00480 } 00481 00482 00483 void KToolBar::setButtonPixmap( int id, const QPixmap& _pixmap ) 00484 { 00485 KToolBarButton * button = getButton( id ); 00486 if ( button ) 00487 button->setPixmap( _pixmap ); 00488 } 00489 00490 00491 void KToolBar::setButtonIcon( int id, const QString& _icon ) 00492 { 00493 KToolBarButton * button = getButton( id ); 00494 if ( button ) 00495 button->setIcon( _icon ); 00496 } 00497 00498 void KToolBar::setButtonIconSet( int id, const QIconSet& iconset ) 00499 { 00500 KToolBarButton * button = getButton( id ); 00501 if ( button ) 00502 button->setIconSet( iconset ); 00503 } 00504 00505 00506 void KToolBar::setDelayedPopup (int id , QPopupMenu *_popup, bool toggle ) 00507 { 00508 KToolBarButton * button = getButton( id ); 00509 if ( button ) 00510 button->setDelayedPopup( _popup, toggle ); 00511 } 00512 00513 00514 void KToolBar::setAutoRepeat (int id, bool flag) 00515 { 00516 KToolBarButton * button = getButton( id ); 00517 if ( button ) 00518 button->setAutoRepeat( flag ); 00519 } 00520 00521 00522 void KToolBar::setToggle (int id, bool flag ) 00523 { 00524 KToolBarButton * button = getButton( id ); 00525 if ( button ) 00526 button->setToggle( flag ); 00527 } 00528 00529 00530 void KToolBar::toggleButton (int id) 00531 { 00532 KToolBarButton * button = getButton( id ); 00533 if ( button ) 00534 button->toggle(); 00535 } 00536 00537 00538 void KToolBar::setButton (int id, bool flag) 00539 { 00540 KToolBarButton * button = getButton( id ); 00541 if ( button ) 00542 button->on( flag ); 00543 } 00544 00545 00546 bool KToolBar::isButtonOn (int id) const 00547 { 00548 KToolBarButton * button = const_cast<KToolBar*>( this )->getButton( id ); 00549 return button ? button->isOn() : false; 00550 } 00551 00552 00553 void KToolBar::setLinedText (int id, const QString& text) 00554 { 00555 KLineEdit * lineEdit = getLined( id ); 00556 if ( lineEdit ) 00557 lineEdit->setText( text ); 00558 } 00559 00560 00561 QString KToolBar::getLinedText (int id) const 00562 { 00563 KLineEdit * lineEdit = const_cast<KToolBar*>( this )->getLined( id ); 00564 return lineEdit ? lineEdit->text() : QString::null; 00565 } 00566 00567 00568 void KToolBar::insertComboItem (int id, const QString& text, int index) 00569 { 00570 KComboBox * comboBox = getCombo( id ); 00571 if (comboBox) 00572 comboBox->insertItem( text, index ); 00573 } 00574 00575 void KToolBar::insertComboList (int id, const QStringList &list, int index) 00576 { 00577 KComboBox * comboBox = getCombo( id ); 00578 if (comboBox) 00579 comboBox->insertStringList( list, index ); 00580 } 00581 00582 00583 void KToolBar::removeComboItem (int id, int index) 00584 { 00585 KComboBox * comboBox = getCombo( id ); 00586 if (comboBox) 00587 comboBox->removeItem( index ); 00588 } 00589 00590 00591 void KToolBar::setCurrentComboItem (int id, int index) 00592 { 00593 KComboBox * comboBox = getCombo( id ); 00594 if (comboBox) 00595 comboBox->setCurrentItem( index ); 00596 } 00597 00598 00599 void KToolBar::changeComboItem (int id, const QString& text, int index) 00600 { 00601 KComboBox * comboBox = getCombo( id ); 00602 if (comboBox) 00603 comboBox->changeItem( text, index ); 00604 } 00605 00606 00607 void KToolBar::clearCombo (int id) 00608 { 00609 KComboBox * comboBox = getCombo( id ); 00610 if (comboBox) 00611 comboBox->clear(); 00612 } 00613 00614 00615 QString KToolBar::getComboItem (int id, int index) const 00616 { 00617 KComboBox * comboBox = const_cast<KToolBar*>( this )->getCombo( id ); 00618 return comboBox ? comboBox->text( index ) : QString::null; 00619 } 00620 00621 00622 KComboBox * KToolBar::getCombo(int id) 00623 { 00624 Id2WidgetMap::Iterator it = id2widget.find( id ); 00625 if ( it == id2widget.end() ) 00626 return 0; 00627 return dynamic_cast<KComboBox *>( *it ); 00628 } 00629 00630 00631 KLineEdit * KToolBar::getLined (int id) 00632 { 00633 Id2WidgetMap::Iterator it = id2widget.find( id ); 00634 if ( it == id2widget.end() ) 00635 return 0; 00636 return dynamic_cast<KLineEdit *>( *it ); 00637 } 00638 00639 00640 KToolBarButton * KToolBar::getButton (int id) 00641 { 00642 Id2WidgetMap::Iterator it = id2widget.find( id ); 00643 if ( it == id2widget.end() ) 00644 return 0; 00645 return dynamic_cast<KToolBarButton *>( *it ); 00646 } 00647 00648 00649 void KToolBar::alignItemRight (int id, bool right ) 00650 { 00651 Id2WidgetMap::Iterator it = id2widget.find( id ); 00652 if ( it == id2widget.end() ) 00653 return; 00654 if ( rightAligned && !right && (*it) == rightAligned ) 00655 rightAligned = 0; 00656 if ( (*it) && right ) 00657 rightAligned = (*it); 00658 } 00659 00660 00661 QWidget *KToolBar::getWidget (int id) 00662 { 00663 Id2WidgetMap::Iterator it = id2widget.find( id ); 00664 return ( it == id2widget.end() ) ? 0 : (*it); 00665 } 00666 00667 00668 void KToolBar::setItemAutoSized (int id, bool yes ) 00669 { 00670 QWidget *w = getWidget(id); 00671 if ( w && yes ) 00672 setStretchableWidget( w ); 00673 } 00674 00675 00676 void KToolBar::clear () 00677 { 00678 QToolBar::clear(); 00679 widget2id.clear(); 00680 id2widget.clear(); 00681 } 00682 00683 00684 void KToolBar::removeItem(int id) 00685 { 00686 Id2WidgetMap::Iterator it = id2widget.find( id ); 00687 if ( it == id2widget.end() ) 00688 { 00689 kdDebug(220) << name() << " KToolBar::removeItem item " << id << " not found" << endl; 00690 return; 00691 } 00692 QWidget * w = (*it); 00693 id2widget.remove( id ); 00694 widget2id.remove( w ); 00695 widgets.removeRef( w ); 00696 delete w; 00697 } 00698 00699 00700 void KToolBar::removeItemDelayed(int id) 00701 { 00702 Id2WidgetMap::Iterator it = id2widget.find( id ); 00703 if ( it == id2widget.end() ) 00704 { 00705 kdDebug(220) << name() << " KToolBar::removeItem item " << id << " not found" << endl; 00706 return; 00707 } 00708 QWidget * w = (*it); 00709 id2widget.remove( id ); 00710 widget2id.remove( w ); 00711 widgets.removeRef( w ); 00712 00713 w->blockSignals(true); 00714 d->idleButtons.append(w); 00715 layoutTimer->start( 50, true ); 00716 } 00717 00718 00719 void KToolBar::hideItem (int id) 00720 { 00721 QWidget *w = getWidget(id); 00722 if ( w ) 00723 w->hide(); 00724 } 00725 00726 00727 void KToolBar::showItem (int id) 00728 { 00729 QWidget *w = getWidget(id); 00730 if ( w ) 00731 w->show(); 00732 } 00733 00734 00735 int KToolBar::itemIndex (int id) 00736 { 00737 QWidget *w = getWidget(id); 00738 return w ? widgets.findRef(w) : -1; 00739 } 00740 00741 int KToolBar::idAt (int index) 00742 { 00743 QWidget *w = widgets.at(index); 00744 return widget2id[w]; 00745 } 00746 00747 void KToolBar::setFullSize(bool flag ) 00748 { 00749 setHorizontalStretchable( flag ); 00750 setVerticalStretchable( flag ); 00751 } 00752 00753 00754 bool KToolBar::fullSize() const 00755 { 00756 return isHorizontalStretchable() || isVerticalStretchable(); 00757 } 00758 00759 00760 void KToolBar::enableMoving(bool flag ) 00761 { 00762 setMovingEnabled(flag); 00763 } 00764 00765 00766 void KToolBar::setBarPos (BarPosition bpos) 00767 { 00768 if ( !mainWindow() ) 00769 return; 00770 mainWindow()->moveDockWindow( this, (Dock)bpos ); 00771 //kdDebug(220) << name() << " setBarPos dockWindowIndex=" << dockWindowIndex() << endl; 00772 } 00773 00774 00775 KToolBar::BarPosition KToolBar::barPos() const 00776 { 00777 if ( !this->mainWindow() ) 00778 return KToolBar::Top; 00779 Dock dock; 00780 int dm1, dm2; 00781 bool dm3; 00782 this->mainWindow()->getLocation( (QToolBar*)this, dock, dm1, dm3, dm2 ); 00783 if ( dock == DockUnmanaged ) { 00784 return (KToolBar::BarPosition)DockTop; 00785 } 00786 return (BarPosition)dock; 00787 } 00788 00789 00790 bool KToolBar::enable(BarStatus stat) 00791 { 00792 bool mystat = isVisible(); 00793 00794 if ( (stat == Toggle && mystat) || stat == Hide ) 00795 hide(); 00796 else 00797 show(); 00798 00799 return isVisible() == mystat; 00800 } 00801 00802 00803 void KToolBar::setMaxHeight ( int h ) 00804 { 00805 setMaximumHeight( h ); 00806 } 00807 00808 int KToolBar::maxHeight() 00809 { 00810 return maximumHeight(); 00811 } 00812 00813 00814 void KToolBar::setMaxWidth (int dw) 00815 { 00816 setMaximumWidth( dw ); 00817 } 00818 00819 00820 int KToolBar::maxWidth() 00821 { 00822 return maximumWidth(); 00823 } 00824 00825 00826 void KToolBar::setTitle (const QString& _title) 00827 { 00828 setLabel( _title ); 00829 } 00830 00831 00832 void KToolBar::enableFloating (bool ) 00833 { 00834 } 00835 00836 00837 void KToolBar::setIconText(IconText it) 00838 { 00839 setIconText( it, true ); 00840 } 00841 00842 00843 void KToolBar::setIconText(IconText icontext, bool update) 00844 { 00845 bool doUpdate=false; 00846 00847 if (icontext != d->m_iconText) { 00848 d->m_iconText = icontext; 00849 doUpdate=true; 00850 //kdDebug(220) << name() << " icontext has changed, doUpdate=true" << endl; 00851 } 00852 else { 00853 //kdDebug(220) << name() << " icontext hasn't changed, doUpdate=false" << endl; 00854 } 00855 00856 if (update == false) 00857 return; 00858 00859 if (doUpdate) 00860 doModeChange(); // tell buttons what happened 00861 00862 // ugly hack to force a QMainWindow::triggerLayout( true ) 00863 QMainWindow *mw = mainWindow(); 00864 if ( mw ) { 00865 mw->setUpdatesEnabled( false ); 00866 mw->setToolBarsMovable( !mw->toolBarsMovable() ); 00867 mw->setToolBarsMovable( !mw->toolBarsMovable() ); 00868 mw->setUpdatesEnabled( true ); 00869 } 00870 } 00871 00872 00873 KToolBar::IconText KToolBar::iconText() const 00874 { 00875 return d->m_iconText; 00876 } 00877 00878 00879 void KToolBar::setIconSize(int size) 00880 { 00881 setIconSize( size, true ); 00882 } 00883 00884 void KToolBar::setIconSize(int size, bool update) 00885 { 00886 bool doUpdate=false; 00887 00888 if ( size != d->m_iconSize ) { 00889 d->m_iconSize = size; 00890 doUpdate=true; 00891 } 00892 00893 if (update == false) 00894 return; 00895 00896 if (doUpdate) 00897 doModeChange(); // tell buttons what happened 00898 00899 // ugly hack to force a QMainWindow::triggerLayout( true ) 00900 if ( mainWindow() ) { 00901 QMainWindow *mw = mainWindow(); 00902 mw->setUpdatesEnabled( false ); 00903 mw->setToolBarsMovable( !mw->toolBarsMovable() ); 00904 mw->setToolBarsMovable( !mw->toolBarsMovable() ); 00905 mw->setUpdatesEnabled( true ); 00906 } 00907 } 00908 00909 00910 int KToolBar::iconSize() const 00911 { 00912 if ( !d->m_iconSize ) // default value? 00913 { 00914 if (!::qstrcmp(QObject::name(), "mainToolBar")) 00915 return KGlobal::iconLoader()->currentSize(KIcon::MainToolbar); 00916 else 00917 return KGlobal::iconLoader()->currentSize(KIcon::Toolbar); 00918 } 00919 return d->m_iconSize; 00920 } 00921 00922 00923 void KToolBar::setEnableContextMenu(bool enable ) 00924 { 00925 d->m_enableContext = enable; 00926 } 00927 00928 00929 bool KToolBar::contextMenuEnabled() const 00930 { 00931 return d->m_enableContext; 00932 } 00933 00934 00935 void KToolBar::setItemNoStyle(int id, bool no_style ) 00936 { 00937 KToolBarButton * button = getButton( id ); 00938 if (button) 00939 button->setNoStyle( no_style ); 00940 } 00941 00942 00943 void KToolBar::setFlat (bool flag) 00944 { 00945 if ( !mainWindow() ) 00946 return; 00947 if ( flag ) 00948 mainWindow()->moveDockWindow( this, DockMinimized ); 00949 else 00950 mainWindow()->moveDockWindow( this, DockTop ); 00951 // And remember to save the new look later 00952 KMainWindow *kmw = dynamic_cast<KMainWindow *>(mainWindow()); 00953 if ( kmw ) 00954 kmw->setSettingsDirty(); 00955 } 00956 00957 00958 int KToolBar::count() const 00959 { 00960 return id2widget.count(); 00961 } 00962 00963 00964 void KToolBar::saveState() 00965 { 00966 // first, try to save to the xml file 00967 if ( d->m_xmlguiClient && !d->m_xmlguiClient->xmlFile().isEmpty() ) { 00968 //kdDebug(220) << name() << " saveState: saving to " << d->m_xmlguiClient->xmlFile() << endl; 00969 QString barname(!::qstrcmp(name(), "unnamed") ? "mainToolBar" : name()); 00970 // try to find our toolbar 00971 d->modified = false; 00972 // go down one level to get to the right tags 00973 QDomElement current; 00974 for( QDomNode n = d->m_xmlguiClient->domDocument().documentElement().firstChild(); 00975 !n.isNull(); n = n.nextSibling()) { 00976 current = n.toElement(); 00977 00978 if ( current.tagName().lower() != "toolbar" ) 00979 continue; 00980 00981 QString curname(current.attribute( "name" )); 00982 00983 if ( curname == barname ) { 00984 saveState( current ); 00985 break; 00986 } 00987 } 00988 // if we didn't make changes, then just return 00989 if ( !d->modified ) 00990 return; 00991 00992 // now we load in the (non-merged) local file 00993 QString local_xml(KXMLGUIFactory::readConfigFile(d->m_xmlguiClient->xmlFile(), true, d->m_xmlguiClient->instance())); 00994 QDomDocument local; 00995 local.setContent(local_xml); 00996 00997 // make sure we don't append if this toolbar already exists locally 00998 bool just_append = true; 00999 01000 for( QDomNode n = local.documentElement().firstChild(); 01001 !n.isNull(); n = n.nextSibling()) { 01002 QDomElement elem = n.toElement(); 01003 01004 if ( elem.tagName().lower() != "toolbar" ) 01005 continue; 01006 01007 QString curname(elem.attribute( "name" )); 01008 01009 if ( curname == barname ) { 01010 just_append = false; 01011 local.documentElement().replaceChild( current, elem ); 01012 break; 01013 } 01014 } 01015 01016 if (just_append) 01017 local.documentElement().appendChild( current ); 01018 01019 KXMLGUIFactory::saveConfigFile(local, d->m_xmlguiClient->localXMLFile(), d->m_xmlguiClient->instance() ); 01020 01021 return; 01022 } 01023 01024 // if that didn't work, we save to the config file 01025 KConfig *config = KGlobal::config(); 01026 saveSettings(config, QString::null); 01027 config->sync(); 01028 } 01029 01030 QString KToolBar::settingsGroup() const 01031 { 01032 QString configGroup; 01033 if (!::qstrcmp(name(), "unnamed") || !::qstrcmp(name(), "mainToolBar")) 01034 configGroup = "Toolbar style"; 01035 else 01036 configGroup = QString(name()) + " Toolbar style"; 01037 if ( this->mainWindow() ) 01038 { 01039 configGroup.prepend(" "); 01040 configGroup.prepend( this->mainWindow()->name() ); 01041 } 01042 return configGroup; 01043 } 01044 01045 void KToolBar::saveSettings(KConfig *config, const QString &_configGroup) 01046 { 01047 QString configGroup = _configGroup; 01048 if (configGroup.isEmpty()) 01049 configGroup = settingsGroup(); 01050 //kdDebug(220) << name() << " saveSettings() group=" << _configGroup << " -> " << configGroup << endl; 01051 01052 QString position, icontext; 01053 int index; 01054 getAttributes( position, icontext, index ); 01055 01056 //kdDebug(220) << name() << " position=" << position << " index=" << index << " offset=" << offset() << " newLine=" << newLine() << endl; 01057 01058 KConfigGroupSaver saver(config, configGroup); 01059 01060 if(!config->hasDefault("Position") && position == d->PositionDefault ) 01061 config->revertToDefault("Position"); 01062 else 01063 config->writeEntry("Position", position); 01064 01065 //kdDebug(220) << name() << " icontext=" << icontext << " hasDefault:" << config->hasDefault( "IconText" ) << " d->IconTextDefault=" << d->IconTextDefault << endl; 01066 01067 if(d->m_honorStyle && icontext == d->IconTextDefault && !config->hasDefault("IconText") ) 01068 { 01069 //kdDebug(220) << name() << " reverting icontext to default" << endl; 01070 config->revertToDefault("IconText"); 01071 } 01072 else 01073 { 01074 //kdDebug(220) << name() << " writing icontext " << icontext << endl; 01075 config->writeEntry("IconText", icontext); 01076 } 01077 01078 if(!config->hasDefault("IconSize") && iconSize() == d->IconSizeDefault ) 01079 config->revertToDefault("IconSize"); 01080 else 01081 config->writeEntry("IconSize", iconSize()); 01082 01083 if(!config->hasDefault("Hidden") && isHidden() == d->HiddenDefault ) 01084 config->revertToDefault("Hidden"); 01085 else 01086 config->writeEntry("Hidden", isHidden()); 01087 01088 // Note that index, unlike the other settings, depends on the other toolbars 01089 // So on the first run with a clean local config file, even the usual 01090 // hasDefault/==IndexDefault test would save the toolbar indexes 01091 // (IndexDefault was 0, whereas index is the real index in the GUI) 01092 // 01093 // Saving the whole set of indexes is necessary though. When moving only 01094 // one toolbar, if we only saved the changed indexes, the toolbars wouldn't 01095 // reappear at the same position the next time. 01096 // The whole set of indexes has to be saved. 01097 //kdDebug(220) << name() << " writing index " << index << endl; 01098 KMainWindow *kmw = dynamic_cast<KMainWindow *>(mainWindow()); 01099 // don't save if there's only one toolbar 01100 01101 // Don't use kmw->toolBarIterator() because you might 01102 // mess up someone else's iterator. Make the list on your own 01103 QPtrList<KToolBar> toolbarList; 01104 QPtrList<QToolBar> lst; 01105 for ( int i = (int)QMainWindow::DockUnmanaged; i <= (int)DockMinimized; ++i ) { 01106 lst = kmw->toolBars( (ToolBarDock)i ); 01107 for ( QToolBar *tb = lst.first(); tb; tb = lst.next() ) { 01108 if ( !tb->inherits( "KToolBar" ) ) 01109 continue; 01110 toolbarList.append( (KToolBar*)tb ); 01111 } 01112 } 01113 QPtrListIterator<KToolBar> toolbarIterator( toolbarList ); 01114 if ( !kmw || toolbarIterator.count() > 1 ) 01115 config->writeEntry("Index", index); 01116 else 01117 config->revertToDefault("Index"); 01118 01119 if(!config->hasDefault("Offset") && offset() == d->OffsetDefault ) 01120 config->revertToDefault("Offset"); 01121 else 01122 config->writeEntry("Offset", offset()); 01123 01124 if(!config->hasDefault("NewLine") && newLine() == d->NewLineDefault ) 01125 config->revertToDefault("NewLine"); 01126 else 01127 config->writeEntry("NewLine", newLine()); 01128 } 01129 01130 01131 void KToolBar::setXMLGUIClient( KXMLGUIClient *client ) 01132 { 01133 d->m_xmlguiClient = client; 01134 } 01135 01136 void KToolBar::setText( const QString & txt ) 01137 { 01138 setLabel( txt + " (" + kapp->caption() + ") " ); 01139 } 01140 01141 01142 QString KToolBar::text() const 01143 { 01144 return label(); 01145 } 01146 01147 01148 void KToolBar::doConnections( KToolBarButton *button ) 01149 { 01150 connect(button, SIGNAL(clicked(int)), this, SIGNAL( clicked( int ) ) ); 01151 connect(button, SIGNAL(doubleClicked(int)), this, SIGNAL( doubleClicked( int ) ) ); 01152 connect(button, SIGNAL(released(int)), this, SIGNAL( released( int ) ) ); 01153 connect(button, SIGNAL(pressed(int)), this, SIGNAL( pressed( int ) ) ); 01154 connect(button, SIGNAL(toggled(int)), this, SIGNAL( toggled( int ) ) ); 01155 connect(button, SIGNAL(highlighted(int, bool)), this, SIGNAL( highlighted( int, bool ) ) ); 01156 } 01157 01158 void KToolBar::mousePressEvent ( QMouseEvent *m ) 01159 { 01160 if ( !mainWindow() ) 01161 return; 01162 QMainWindow *mw = mainWindow(); 01163 if ( mw->toolBarsMovable() && d->m_enableContext ) { 01164 if ( m->button() == RightButton ) { 01165 int i = contextMenu()->exec( m->globalPos(), 0 ); 01166 switch ( i ) { 01167 case -1: 01168 return; // popup canceled 01169 case CONTEXT_LEFT: 01170 mw->moveDockWindow( this, DockLeft ); 01171 break; 01172 case CONTEXT_RIGHT: 01173 mw->moveDockWindow( this, DockRight ); 01174 break; 01175 case CONTEXT_TOP: 01176 mw->moveDockWindow( this, DockTop ); 01177 break; 01178 case CONTEXT_BOTTOM: 01179 mw->moveDockWindow( this, DockBottom ); 01180 break; 01181 case CONTEXT_FLOAT: 01182 mw->moveDockWindow( this, DockTornOff ); 01183 break; 01184 case CONTEXT_FLAT: 01185 mw->moveDockWindow( this, DockMinimized ); 01186 break; 01187 case CONTEXT_ICONS: 01188 setIconText( IconOnly ); 01189 break; 01190 case CONTEXT_TEXTRIGHT: 01191 setIconText( IconTextRight ); 01192 break; 01193 case CONTEXT_TEXT: 01194 setIconText( TextOnly ); 01195 break; 01196 case CONTEXT_TEXTUNDER: 01197 setIconText( IconTextBottom ); 01198 break; 01199 default: 01200 if ( i >= CONTEXT_ICONSIZES ) 01201 setIconSize( i - CONTEXT_ICONSIZES ); 01202 else 01203 return; // assume this was an action handled elsewhere, no need for setSettingsDirty() 01204 } 01205 KMainWindow *kmw = dynamic_cast<KMainWindow *>(mw); 01206 if ( kmw ) 01207 kmw->setSettingsDirty(); 01208 } 01209 } 01210 } 01211 01212 void KToolBar::doModeChange() 01213 { 01214 for(QWidget *w=d->idleButtons.first(); w; w=d->idleButtons.next()) 01215 w->blockSignals(false); 01216 d->idleButtons.clear(); 01217 01218 emit modechange(); 01219 } 01220 01221 void KToolBar::rebuildLayout() 01222 { 01223 for(QWidget *w=d->idleButtons.first(); w; w=d->idleButtons.next()) 01224 w->blockSignals(false); 01225 d->idleButtons.clear(); 01226 01227 layoutTimer->stop(); 01228 QApplication::sendPostedEvents( this, QEvent::ChildInserted ); 01229 QBoxLayout *l = boxLayout(); 01230 01231 // clear the old layout 01232 QLayoutIterator it = l->iterator(); 01233 while ( it.current() ) 01234 it.deleteCurrent(); 01235 01236 for ( QWidget *w = widgets.first(); w; w = widgets.next() ) { 01237 if ( w == rightAligned ) 01238 continue; 01239 KToolBarSeparator *ktbs = dynamic_cast<KToolBarSeparator *>(w); 01240 if ( ktbs && !ktbs->showLine() ) { 01241 l->addSpacing( orientation() == Vertical ? w->sizeHint().height() : w->sizeHint().width() ); 01242 w->hide(); 01243 continue; 01244 } 01245 if ( dynamic_cast<QPopupMenu *>(w) ) // w is a QPopupMenu? 01246 continue; 01247 l->addWidget( w ); 01248 w->show(); 01249 if ((orientation() == Horizontal) && dynamic_cast<QLineEdit *>(w)) // w is QLineEdit ? 01250 l->addSpacing(2); // A little bit extra spacing behind it. 01251 } 01252 if ( rightAligned ) { 01253 l->addStretch(); 01254 l->addWidget( rightAligned ); 01255 rightAligned->show(); 01256 } 01257 01258 if ( fullSize() ) { 01259 if ( !rightAligned ) 01260 l->addStretch(); 01261 if ( stretchableWidget ) 01262 l->setStretchFactor( stretchableWidget, 10 ); 01263 } 01264 l->invalidate(); 01265 QApplication::postEvent( this, new QEvent( QEvent::LayoutHint ) ); 01266 } 01267 01268 void KToolBar::childEvent( QChildEvent *e ) 01269 { 01270 if ( e->child()->isWidgetType() ) { 01271 QWidget * w = dynamic_cast<QWidget *>(e->child()); 01272 if (!w || (::qstrcmp( "qt_dockwidget_internal", w->name()) == 0)) 01273 { 01274 QToolBar::childEvent( e ); 01275 return; 01276 } 01277 if ( e->type() == QEvent::ChildInserted ) { 01278 if ( !dynamic_cast<QPopupMenu *>(w)) { // e->child() is not a QPopupMenu 01279 // prevent items that have been explicitly inserted by insert*() from 01280 // being inserted again 01281 if ( !widget2id.contains( w ) ) 01282 { 01283 int dummy = -1; 01284 insertWidgetInternal( w, dummy, -1 ); 01285 } 01286 } 01287 } else { 01288 removeWidgetInternal( w ); 01289 } 01290 if ( isVisibleTo( 0 ) ) 01291 { 01292 layoutTimer->start( 50, true ); 01293 QBoxLayout *l = boxLayout(); 01294 01295 // clear the old layout so that we don't get unnecassery layout 01296 // changes till we have rebuild the thing 01297 QLayoutIterator it = l->iterator(); 01298 while ( it.current() ) 01299 it.deleteCurrent(); 01300 } 01301 } 01302 QToolBar::childEvent( e ); 01303 } 01304 01305 void KToolBar::insertWidgetInternal( QWidget *w, int &index, int id ) 01306 { 01307 // we can't have it in widgets, or something is really wrong 01308 //widgets.removeRef( w ); 01309 01310 connect( w, SIGNAL( destroyed() ), 01311 this, SLOT( widgetDestroyed() ) ); 01312 if ( index == -1 || index > (int)widgets.count() ) { 01313 index = (int)widgets.count(); 01314 widgets.append( w ); 01315 } 01316 else 01317 widgets.insert( index, w ); 01318 if ( id == -1 ) 01319 id = id2widget.count(); 01320 id2widget.insert( id, w ); 01321 widget2id.insert( w, id ); 01322 } 01323 01324 void KToolBar::showEvent( QShowEvent *e ) 01325 { 01326 QToolBar::showEvent( e ); 01327 rebuildLayout(); 01328 } 01329 01330 void KToolBar::setStretchableWidget( QWidget *w ) 01331 { 01332 QToolBar::setStretchableWidget( w ); 01333 stretchableWidget = w; 01334 } 01335 01336 QSizePolicy KToolBar::sizePolicy() const 01337 { 01338 if ( orientation() == Horizontal ) 01339 return QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ); 01340 else 01341 return QSizePolicy( QSizePolicy::Fixed, QSizePolicy::Expanding ); 01342 } 01343 01344 QSize KToolBar::sizeHint() const 01345 { 01346 QSize minSize(0,0); 01347 KToolBar *ncThis = const_cast<KToolBar *>(this); 01348 01349 ncThis->polish(); 01350 01351 int margin = static_cast<QWidget*>(ncThis)->layout()->margin() + frameWidth(); 01352 switch( barPos() ) 01353 { 01354 case KToolBar::Top: 01355 case KToolBar::Bottom: 01356 for ( QWidget *w = ncThis->widgets.first(); w; w = ncThis->widgets.next() ) 01357 { 01358 QSize sh = w->sizeHint(); 01359 if ( w->sizePolicy().horData() == QSizePolicy::Ignored ) 01360 sh.setWidth( 1 ); 01361 if ( w->sizePolicy().verData() == QSizePolicy::Ignored ) 01362 sh.setHeight( 1 ); 01363 sh = sh.boundedTo( w->maximumSize() ) 01364 .expandedTo( w->minimumSize() ).expandedTo( QSize(1, 1) ); 01365 01366 minSize = minSize.expandedTo(QSize(0, sh.height())); 01367 minSize += QSize(sh.width()+1, 0); 01368 if (dynamic_cast<QLineEdit *>(w)) // w is a QLineEdit ? 01369 minSize += QSize(2, 0); // A little bit extra spacing behind it. 01370 } 01371 01372 minSize += QSize(QApplication::style().pixelMetric( QStyle::PM_DockWindowHandleExtent ), 0); 01373 minSize += QSize(margin*2, margin*2); 01374 break; 01375 01376 case KToolBar::Left: 01377 case KToolBar::Right: 01378 for ( QWidget *w = ncThis->widgets.first(); w; w = ncThis->widgets.next() ) 01379 { 01380 QSize sh = w->sizeHint(); 01381 if ( w->sizePolicy().horData() == QSizePolicy::Ignored ) 01382 sh.setWidth( 1 ); 01383 if ( w->sizePolicy().verData() == QSizePolicy::Ignored ) 01384 sh.setHeight( 1 ); 01385 sh = sh.boundedTo( w->maximumSize() ) 01386 .expandedTo( w->minimumSize() ).expandedTo( QSize(1, 1) ); 01387 01388 minSize = minSize.expandedTo(QSize(sh.width(), 0)); 01389 minSize += QSize(0, sh.height()+1); 01390 } 01391 minSize += QSize(0, QApplication::style().pixelMetric( QStyle::PM_DockWindowHandleExtent )); 01392 minSize += QSize(margin*2, margin*2); 01393 break; 01394 01395 default: 01396 minSize = QToolBar::sizeHint(); 01397 break; 01398 } 01399 return minSize; 01400 } 01401 01402 QSize KToolBar::minimumSize() const 01403 { 01404 return minimumSizeHint(); 01405 } 01406 01407 QSize KToolBar::minimumSizeHint() const 01408 { 01409 return sizeHint(); 01410 } 01411 01412 bool KToolBar::highlight() const 01413 { 01414 return d->m_highlight; 01415 } 01416 01417 void KToolBar::hide() 01418 { 01419 QToolBar::hide(); 01420 } 01421 01422 void KToolBar::show() 01423 { 01424 QToolBar::show(); 01425 } 01426 01427 void KToolBar::resizeEvent( QResizeEvent *e ) 01428 { 01429 bool b = isUpdatesEnabled(); 01430 setUpdatesEnabled( false ); 01431 QToolBar::resizeEvent( e ); 01432 if (b) 01433 { 01434 if (layoutTimer->isActive()) 01435 { 01436 // Wait with repainting till layout is complete. 01437 d->repaintTimer.start( 100, true ); 01438 } 01439 else 01440 { 01441 // Repaint now 01442 slotRepaint(); 01443 } 01444 } 01445 } 01446 01447 void KToolBar::slotIconChanged(int group) 01448 { 01449 if ((group != KIcon::Toolbar) && (group != KIcon::MainToolbar)) 01450 return; 01451 if ((group == KIcon::MainToolbar) != !::qstrcmp(name(), "mainToolBar")) 01452 return; 01453 01454 doModeChange(); 01455 01456 if (isVisible()) 01457 updateGeometry(); 01458 } 01459 01460 void KToolBar::slotReadConfig() 01461 { 01462 //kdDebug(220) << name() << " slotReadConfig" << endl; 01463 // Read appearance settings (hmm, we used to do both here, 01464 // but a well behaved application will call applyMainWindowSettings 01465 // anyway, right ?) 01466 applyAppearanceSettings(KGlobal::config(), QString::null ); 01467 } 01468 01469 void KToolBar::slotAppearanceChanged() 01470 { 01471 // Read appearance settings from global file. 01472 applyAppearanceSettings(KGlobal::config(), QString::null, true /* lose local settings */ ); 01473 01474 // And remember to save the new look later 01475 KMainWindow *kmw = dynamic_cast<KMainWindow *>(mainWindow()); 01476 if ( kmw ) 01477 kmw->setSettingsDirty(); 01478 } 01479 01480 //static 01481 bool KToolBar::highlightSetting() 01482 { 01483 QString grpToolbar(QString::fromLatin1("Toolbar style")); 01484 KConfigGroupSaver saver(KGlobal::config(), grpToolbar); 01485 return KGlobal::config()->readBoolEntry(QString::fromLatin1("Highlighting"),true); 01486 } 01487 01488 //static 01489 bool KToolBar::transparentSetting() 01490 { 01491 QString grpToolbar(QString::fromLatin1("Toolbar style")); 01492 KConfigGroupSaver saver(KGlobal::config(), grpToolbar); 01493 return KGlobal::config()->readBoolEntry(QString::fromLatin1("TransparentMoving"),true); 01494 } 01495 01496 //static 01497 KToolBar::IconText KToolBar::iconTextSetting() 01498 { 01499 QString grpToolbar(QString::fromLatin1("Toolbar style")); 01500 KConfigGroupSaver saver(KGlobal::config(), grpToolbar); 01501 QString icontext = KGlobal::config()->readEntry(QString::fromLatin1("IconText"),QString::fromLatin1("IconOnly")); 01502 if ( icontext == "IconTextRight" ) 01503 return IconTextRight; 01504 else if ( icontext == "IconTextBottom" ) 01505 return IconTextBottom; 01506 else if ( icontext == "TextOnly" ) 01507 return TextOnly; 01508 else 01509 return IconOnly; 01510 } 01511 01512 void KToolBar::applyAppearanceSettings(KConfig *config, const QString &_configGroup, bool forceGlobal) 01513 { 01514 QString configGroup = _configGroup.isEmpty() ? settingsGroup() : _configGroup; 01515 //kdDebug(220) << name() << " applyAppearanceSettings: configGroup=" << configGroup << " forceGlobal=" << forceGlobal << endl; 01516 01517 // If we have application-specific settings in the XML file, 01518 // and nothing in the application's config file, then 01519 // we don't apply the global defaults, the XML ones are preferred 01520 // (see applySettings for a full explanation) 01521 // This is the reason for the xmlgui tests below. 01522 bool xmlgui = d->m_xmlguiClient && !d->m_xmlguiClient->xmlFile().isEmpty(); 01523 01524 KConfig *gconfig = KGlobal::config(); 01525 01526 static const QString &attrIconText = KGlobal::staticQString("IconText"); 01527 static const QString &attrHighlight = KGlobal::staticQString("Highlighting"); 01528 static const QString &attrTrans = KGlobal::staticQString("TransparentMoving"); 01529 static const QString &attrIconSize = KGlobal::staticQString("IconSize"); 01530 01531 // we actually do this in two steps. 01532 // First, we read in the global styles [Toolbar style] (from the KControl module). 01533 // Then, if the toolbar is NOT 'mainToolBar', we will also try to read in [barname Toolbar style] 01534 bool highlight; 01535 int transparent; 01536 bool applyIconText = !xmlgui; // if xmlgui is used, global defaults won't apply 01537 bool applyIconSize = !xmlgui; 01538 01539 int iconSize = d->IconSizeDefault; 01540 QString iconText = d->IconTextDefault; 01541 01542 // this is the first iteration 01543 QString grpToolbar(QString::fromLatin1("Toolbar style")); 01544 { // start block for KConfigGroupSaver 01545 KConfigGroupSaver saver(gconfig, grpToolbar); 01546 01547 // first, get the generic settings 01548 highlight = gconfig->readBoolEntry(attrHighlight, true); 01549 transparent = gconfig->readBoolEntry(attrTrans, true); 01550 01551 // we read in the IconText property *only* if we intend on actually 01552 // honoring it 01553 if (d->m_honorStyle) 01554 d->IconTextDefault = gconfig->readEntry(attrIconText, d->IconTextDefault); 01555 else 01556 d->IconTextDefault = "IconOnly"; 01557 01558 // Use the default icon size for toolbar icons. 01559 d->IconSizeDefault = gconfig->readNumEntry(attrIconSize, d->IconSizeDefault); 01560 01561 iconSize = d->IconSizeDefault; 01562 iconText = d->IconTextDefault; 01563 01564 if ( !forceGlobal && config->hasGroup(configGroup) ) 01565 { 01566 config->setGroup(configGroup); 01567 01568 // first, get the generic settings 01569 highlight = config->readBoolEntry(attrHighlight, highlight); 01570 transparent = config->readBoolEntry(attrTrans, transparent); 01571 01572 // read in the IconText property 01573 if ( config->hasKey( attrIconText ) ) { 01574 iconText = config->readEntry(attrIconText); 01575 applyIconText = true; 01576 //kdDebug(220) << name() << " read icontext=" << d->IconTextDefault << ", that will be the default" << endl; 01577 } 01578 01579 // now get the size 01580 if ( config->hasKey( attrIconSize ) ) { 01581 iconSize = config->readNumEntry(attrIconSize); 01582 applyIconSize = true; 01583 } 01584 } 01585 01586 // revert back to the old group 01587 } // end block for KConfigGroupSaver 01588 01589 bool doUpdate = false; 01590 01591 IconText icon_text; 01592 if ( iconText == "IconTextRight" ) 01593 icon_text = IconTextRight; 01594 else if ( iconText == "IconTextBottom" ) 01595 icon_text = IconTextBottom; 01596 else if ( iconText == "TextOnly" ) 01597 icon_text = TextOnly; 01598 else 01599 icon_text = IconOnly; 01600 01601 // check if the icon/text has changed 01602 if (icon_text != d->m_iconText && applyIconText) { 01603 //kdDebug(220) << name() << " applyAppearanceSettings setIconText " << icon_text << endl; 01604 setIconText(icon_text, false); 01605 doUpdate = true; 01606 } 01607 01608 // ...and check if the icon size has changed 01609 if (iconSize != d->m_iconSize && applyIconSize) { 01610 setIconSize(iconSize, false); 01611 doUpdate = true; 01612 } 01613 01614 QMainWindow *mw = mainWindow(); 01615 01616 // ...and if we should highlight 01617 if ( highlight != d->m_highlight ) { 01618 d->m_highlight = highlight; 01619 doUpdate = true; 01620 } 01621 01622 // ...and if we should move transparently 01623 if ( mw && transparent != (!mw->opaqueMoving()) ) { 01624 mw->setOpaqueMoving( !transparent ); 01625 } 01626 01627 if (doUpdate) 01628 doModeChange(); // tell buttons what happened 01629 01630 if (isVisible ()) 01631 updateGeometry(); 01632 } 01633 01634 void KToolBar::applySettings(KConfig *config, const QString &_configGroup) 01635 { 01636 return applySettings(config,_configGroup,false); 01637 } 01638 01639 void KToolBar::applySettings(KConfig *config, const QString &_configGroup,bool force) 01640 { 01641 //kdDebug(220) << name() << " applySettings group=" << _configGroup << endl; 01642 01643 QString configGroup = _configGroup.isEmpty() ? settingsGroup() : _configGroup; 01644 01645 /* 01646 Let's explain this a bit more in details. 01647 The order in which we apply settings is : 01648 Global config / <appnamerc> user settings if no XMLGUI is used 01649 Global config / App-XML attributes / <appnamerc> user settings if XMLGUI is used 01650 01651 So in the first case, we simply read everything from KConfig as below, 01652 but in the second case we don't do anything here if there is no app-specific config, 01653 and the XMLGUI-related code (loadState()) uses the static methods of this class 01654 to get the global defaults. 01655 01656 Global config doesn't include position (index, offset, newline and hidden/shown). 01657 */ 01658 01659 // First the appearance stuff - the one which has a global config 01660 applyAppearanceSettings( config, configGroup ); 01661 01662 // ...and now the position stuff 01663 if ( config->hasGroup(configGroup) || force ) 01664 { 01665 KConfigGroupSaver cgs(config, configGroup); 01666 01667 static const QString &attrPosition = KGlobal::staticQString("Position"); 01668 static const QString &attrIndex = KGlobal::staticQString("Index"); 01669 static const QString &attrOffset = KGlobal::staticQString("Offset"); 01670 static const QString &attrNewLine = KGlobal::staticQString("NewLine"); 01671 static const QString &attrHidden = KGlobal::staticQString("Hidden"); 01672 01673 QString position = config->readEntry(attrPosition, d->PositionDefault); 01674 int index = config->readNumEntry(attrIndex, -1); 01675 int offset = config->readNumEntry(attrOffset, d->OffsetDefault); 01676 bool newLine = config->readBoolEntry(attrNewLine, d->NewLineDefault); 01677 bool hidden = config->readBoolEntry(attrHidden, d->HiddenDefault); 01678 01679 Dock pos(DockTop); 01680 if ( position == "Top" ) 01681 pos = DockTop; 01682 else if ( position == "Bottom" ) 01683 pos = DockBottom; 01684 else if ( position == "Left" ) 01685 pos = DockLeft; 01686 else if ( position == "Right" ) 01687 pos = DockRight; 01688 else if ( position == "Floating" ) 01689 pos = DockTornOff; 01690 else if ( position == "Flat" ) 01691 pos = DockMinimized; 01692 01693 //kdDebug(220) << name() << " applySettings hidden=" << hidden << endl; 01694 if (hidden) 01695 hide(); 01696 else 01697 show(); 01698 01699 if ( mainWindow() ) 01700 { 01701 //kdDebug(220) << name() << " applySettings updating ToolbarInfo" << endl; 01702 d->toolBarInfo = KToolBarPrivate::ToolBarInfo( pos, index, newLine, offset ); 01703 positionYourself( true ); 01704 } 01705 if (isVisible ()) 01706 updateGeometry(); 01707 } 01708 } 01709 01710 bool KToolBar::event( QEvent *e ) 01711 { 01712 if ( (e->type() == QEvent::LayoutHint) && isUpdatesEnabled() ) 01713 d->repaintTimer.start( 100, true ); 01714 01715 if (e->type() == QEvent::ChildInserted ) 01716 { 01717 // Bypass QToolBar::event, 01718 // it will show() the inserted child and we don't want to 01719 // do that until we have rebuilt the layout. 01720 childEvent((QChildEvent *)e); 01721 return true; 01722 } 01723 01724 return QToolBar::event( e ); 01725 } 01726 01727 void KToolBar::slotRepaint() 01728 { 01729 setUpdatesEnabled( false ); 01730 // Send a resizeEvent to update the "toolbar extension arrow" 01731 // (The button you get when your toolbar-items don't fit in 01732 // the available space) 01733 QResizeEvent ev(size(), size()); 01734 resizeEvent(&ev); 01735 QApplication::sendPostedEvents( this, QEvent::LayoutHint ); 01736 setUpdatesEnabled( true ); 01737 repaint( true ); 01738 } 01739 01740 void KToolBar::toolBarPosChanged( QToolBar *tb ) 01741 { 01742 if ( tb != this ) 01743 return; 01744 if ( d->oldPos == DockMinimized ) 01745 rebuildLayout(); 01746 d->oldPos = (QMainWindow::ToolBarDock)barPos(); 01747 KMainWindow *kmw = dynamic_cast<KMainWindow *>(mainWindow()); 01748 if ( kmw ) 01749 kmw->setSettingsDirty(); 01750 } 01751 01752 void KToolBar::loadState( const QDomElement &element ) 01753 { 01754 //kdDebug(220) << name() << " loadState " << this << endl; 01755 QMainWindow *mw = mainWindow(); 01756 01757 if ( !mw ) 01758 return; 01759 01760 { 01761 QCString text = element.namedItem( "text" ).toElement().text().utf8(); 01762 if ( text.isEmpty() ) 01763 text = element.namedItem( "Text" ).toElement().text().utf8(); 01764 if ( !text.isEmpty() ) 01765 setText( i18n( text ) ); 01766 } 01767 01768 { 01769 QCString attrFullWidth = element.attribute( "fullWidth" ).lower().latin1(); 01770 if ( !attrFullWidth.isEmpty() ) 01771 setFullSize( attrFullWidth == "true" ); 01772 } 01773 01774 Dock dock = DockTop; 01775 { 01776 QCString attrPosition = element.attribute( "position" ).lower().latin1(); 01777 //kdDebug(220) << name() << " loadState attrPosition=" << attrPosition << endl; 01778 if ( !attrPosition.isEmpty() ) { 01779 if ( attrPosition == "top" ) 01780 dock = DockTop; 01781 else if ( attrPosition == "left" ) 01782 dock = DockLeft; 01783 else if ( attrPosition == "right" ) 01784 dock = DockRight; 01785 else if ( attrPosition == "bottom" ) 01786 dock = DockBottom; 01787 else if ( attrPosition == "floating" ) 01788 dock = DockTornOff; 01789 else if ( attrPosition == "flat" ) 01790 dock = DockMinimized; 01791 } 01792 } 01793 01794 { 01795 QCString attrIconText = element.attribute( "iconText" ).lower().latin1(); 01796 if ( !attrIconText.isEmpty() ) { 01797 //kdDebug(220) << name() << " loadState attrIconText=" << attrIconText << endl; 01798 if ( attrIconText == "icontextright" ) 01799 setIconText( KToolBar::IconTextRight ); 01800 else if ( attrIconText == "textonly" ) 01801 setIconText( KToolBar::TextOnly ); 01802 else if ( attrIconText == "icontextbottom" ) 01803 setIconText( KToolBar::IconTextBottom ); 01804 else if ( attrIconText == "icononly" ) 01805 setIconText( KToolBar::IconOnly ); 01806 } else 01807 { 01808 //kdDebug(220) << name() << " loadState no iconText attribute in XML, using iconTextSetting=" << iconTextSetting() << endl; 01809 // Use global setting 01810 if (d->m_honorStyle) 01811 setIconText( iconTextSetting() ); 01812 else 01813 setIconText( d->IconTextDefault); 01814 } 01815 } 01816 01817 { 01818 QString attrIconSize = element.attribute( "iconSize" ).lower(); 01819 if ( !attrIconSize.isEmpty() ) 01820 d->IconSizeDefault = attrIconSize.toInt(); 01821 setIconSize( d->IconSizeDefault ); 01822 } 01823 01824 int index = -1; // append by default. This is very important, otherwise 01825 // with all 0 indexes, we keep reversing the toolbars. 01826 { 01827 QString attrIndex = element.attribute( "index" ).lower(); 01828 if ( !attrIndex.isEmpty() ) 01829 index = attrIndex.toInt(); 01830 } 01831 01832 { 01833 QString attrOffset = element.attribute( "offset" ).lower(); 01834 if ( !attrOffset.isEmpty() ) 01835 d->OffsetDefault = attrOffset.toInt(); 01836 } 01837 01838 { 01839 QString attrNewLine = element.attribute( "newline" ).lower(); 01840 if ( !attrNewLine.isEmpty() ) 01841 d->NewLineDefault = attrNewLine == "true"; 01842 } 01843 01844 { 01845 QString attrHidden = element.attribute( "hidden" ).lower(); 01846 if ( !attrHidden.isEmpty() ) 01847 d->HiddenDefault = attrHidden == "true"; 01848 } 01849 01850 d->toolBarInfo = KToolBarPrivate::ToolBarInfo( dock, index, d->NewLineDefault, d->OffsetDefault ); 01851 mw->addDockWindow( this, dock, d->NewLineDefault ); 01852 mw->moveDockWindow( this, dock, d->NewLineDefault, index, d->OffsetDefault ); 01853 01854 // Apply the highlight button setting 01855 d->m_highlight = highlightSetting(); 01856 01857 // Apply transparent-toolbar-moving setting (ok, this is global to the mainwindow, 01858 // but we do it only if there are toolbars...) 01859 if ( transparentSetting() != !mw->opaqueMoving() ) 01860 mw->setOpaqueMoving( !transparentSetting() ); 01861 01862 if ( d->HiddenDefault ) 01863 hide(); 01864 else 01865 show(); 01866 01867 getAttributes( d->PositionDefault, d->IconTextDefault, index ); 01868 //kdDebug(220) << name() << " loadState IconTextDefault=" << d->IconTextDefault << endl; 01869 } 01870 01871 int KToolBar::dockWindowIndex() 01872 { 01873 int index = 0; 01874 Q_ASSERT( mainWindow() ); 01875 if ( mainWindow() ) { 01876 QMainWindow::ToolBarDock dock; 01877 bool newLine; 01878 int offset; 01879 mainWindow()->getLocation( this, dock, index, newLine, offset ); 01880 } 01881 return index; 01882 } 01883 01884 void KToolBar::getAttributes( QString &position, QString &icontext, int &index ) 01885 { 01886 // get all of the stuff to save 01887 switch ( barPos() ) { 01888 case KToolBar::Flat: 01889 position = "Flat"; 01890 break; 01891 case KToolBar::Bottom: 01892 position = "Bottom"; 01893 break; 01894 case KToolBar::Left: 01895 position = "Left"; 01896 break; 01897 case KToolBar::Right: 01898 position = "Right"; 01899 break; 01900 case KToolBar::Floating: 01901 position = "Floating"; 01902 break; 01903 case KToolBar::Top: 01904 default: 01905 position = "Top"; 01906 break; 01907 } 01908 01909 index = dockWindowIndex(); 01910 01911 switch (d->m_iconText) { 01912 case KToolBar::IconTextRight: 01913 icontext = "IconTextRight"; 01914 break; 01915 case KToolBar::IconTextBottom: 01916 icontext = "IconTextBottom"; 01917 break; 01918 case KToolBar::TextOnly: 01919 icontext = "TextOnly"; 01920 break; 01921 case KToolBar::IconOnly: 01922 default: 01923 icontext = "IconOnly"; 01924 break; 01925 } 01926 //kdDebug(220) << name() << " getAttributes: icontext=" << icontext << endl; 01927 } 01928 01929 void KToolBar::saveState( QDomElement &current ) 01930 { 01931 Q_ASSERT( !current.isNull() ); 01932 QString position, icontext; 01933 int index = -1; 01934 getAttributes( position, icontext, index ); 01935 01936 current.setAttribute( "noMerge", "1" ); 01937 current.setAttribute( "position", position ); 01938 current.setAttribute( "iconText", icontext ); 01939 current.setAttribute( "index", index ); 01940 current.setAttribute( "offset", offset() ); 01941 current.setAttribute( "newline", newLine() ); 01942 if ( isHidden() ) 01943 current.setAttribute( "hidden", "true" ); 01944 d->modified = true; 01945 //kdDebug(220) << name() << " saveState: saving index=" << index << " iconText=" << icontext << endl; 01946 } 01947 01948 // Called by KMainWindow::finalizeGUI 01949 void KToolBar::positionYourself( bool force ) 01950 { 01951 if (force) 01952 d->positioned = false; 01953 01954 if ( d->positioned || !mainWindow() ) 01955 { 01956 //kdDebug(220) << name() << " positionYourself d->positioned=true ALREADY DONE" << endl; 01957 return; 01958 } 01959 // we can't test for ForceHide after moveDockWindow because QDockArea 01960 // does a reparent() with showIt == true 01961 bool doHide = isHidden(); 01962 //kdDebug(220) << name() << " positionYourself dock=" << d->toolBarInfo.dock << " newLine=" << d->toolBarInfo.newline << " index=" << d->toolBarInfo.index << " offset=" << d->toolBarInfo.offset << endl; 01963 mainWindow()->moveDockWindow( this, d->toolBarInfo.dock, 01964 d->toolBarInfo.newline, 01965 d->toolBarInfo.index, 01966 d->toolBarInfo.offset ); 01967 01968 //kdDebug(220) << name() << " positionYourself dockWindowIndex=" << dockWindowIndex() << endl; 01969 if ( doHide ) 01970 hide(); 01971 // This method can only have an effect once - unless force is set 01972 d->positioned = true; 01973 } 01974 01975 KPopupMenu *KToolBar::contextMenu() 01976 { 01977 if ( context ) 01978 return context; 01979 01980 // Construct our context popup menu. Name it qt_dockwidget_internal so it 01981 // won't be deleted by QToolBar::clear(). 01982 context = new KPopupMenu( this, "qt_dockwidget_internal" ); 01983 context->insertTitle(i18n("Toolbar Menu")); 01984 01985 KPopupMenu *orient = new KPopupMenu( context, "orient" ); 01986 orient->insertItem( i18n("toolbar position string","Top"), CONTEXT_TOP ); 01987 orient->insertItem( i18n("toolbar position string","Left"), CONTEXT_LEFT ); 01988 orient->insertItem( i18n("toolbar position string","Right"), CONTEXT_RIGHT ); 01989 orient->insertItem( i18n("toolbar position string","Bottom"), CONTEXT_BOTTOM ); 01990 orient->insertSeparator(-1); 01991 orient->insertItem( i18n("toolbar position string","Floating"), CONTEXT_FLOAT ); 01992 orient->insertItem( i18n("min toolbar", "Flat"), CONTEXT_FLAT ); 01993 01994 KPopupMenu *mode = new KPopupMenu( context, "mode" ); 01995 mode->insertItem( i18n("Icons Only"), CONTEXT_ICONS ); 01996 mode->insertItem( i18n("Text Only"), CONTEXT_TEXT ); 01997 mode->insertItem( i18n("Text Alongside Icons"), CONTEXT_TEXTRIGHT ); 01998 mode->insertItem( i18n("Text Under Icons"), CONTEXT_TEXTUNDER ); 01999 02000 KPopupMenu *size = new KPopupMenu( context, "size" ); 02001 size->insertItem( i18n("Default"), CONTEXT_ICONSIZES ); 02002 // Query the current theme for available sizes 02003 KIconTheme *theme = KGlobal::instance()->iconLoader()->theme(); 02004 QValueList<int> avSizes; 02005 if (theme) 02006 { 02007 if (!::qstrcmp(QObject::name(), "mainToolBar")) 02008 avSizes = theme->querySizes( KIcon::MainToolbar); 02009 else 02010 avSizes = theme->querySizes( KIcon::Toolbar); 02011 } 02012 02013 d->iconSizes = avSizes; 02014 qHeapSort(avSizes); 02015 02016 QValueList<int>::Iterator it; 02017 if (avSizes.count() < 10) { 02018 // Fixed or threshold type icons 02019 for (it=avSizes.begin(); it!=avSizes.end(); it++) { 02020 QString text; 02021 if ( *it < 19 ) 02022 text = i18n("Small (%1x%2)").arg(*it).arg(*it); 02023 else if (*it < 25) 02024 text = i18n("Medium (%1x%2)").arg(*it).arg(*it); 02025 else if (*it < 35) 02026 text = i18n("Large (%1x%2)").arg(*it).arg(*it); 02027 else 02028 text = i18n("Huge (%1x%2)").arg(*it).arg(*it); 02029 //we use the size as an id, with an offset 02030 size->insertItem( text, CONTEXT_ICONSIZES + *it ); 02031 } 02032 } 02033 else { 02034 // Scalable icons. 02035 const int progression[] = {16, 22, 32, 48, 64, 96, 128, 192, 256}; 02036 02037 it = avSizes.begin(); 02038 for (uint i = 0; i < 9; i++) { 02039 while (it++ != avSizes.end()) { 02040 if (*it >= progression[i]) { 02041 QString text; 02042 if ( *it < 19 ) 02043 text = i18n("Small (%1x%2)").arg(*it).arg(*it); 02044 else if (*it < 25) 02045 text = i18n("Medium (%1x%2)").arg(*it).arg(*it); 02046 else if (*it < 35) 02047 text = i18n("Large (%1x%2)").arg(*it).arg(*it); 02048 else 02049 text = i18n("Huge (%1x%2)").arg(*it).arg(*it); 02050 //we use the size as an id, with an offset 02051 size->insertItem( text, CONTEXT_ICONSIZES + *it ); 02052 break; 02053 } 02054 } 02055 } 02056 } 02057 02058 context->insertItem( i18n("Orientation"), orient ); 02059 orient->setItemChecked(CONTEXT_TOP, true); 02060 context->insertItem( i18n("Text Position"), mode ); 02061 context->setItemChecked(CONTEXT_ICONS, true); 02062 context->insertItem( i18n("Icon Size"), size ); 02063 02064 KMainWindow *kmw = dynamic_cast<KMainWindow *>(mainWindow()); 02065 if ( kmw ) 02066 { 02067 if ( kmw->toolBarMenuAction() && kmw->hasMenuBar() ) 02068 kmw->toolBarMenuAction()->plug(context); 02069 } 02070 02071 connect( context, SIGNAL( aboutToShow() ), this, SLOT( slotContextAboutToShow() ) ); 02072 connect( context, SIGNAL( aboutToHide() ), this, SLOT( slotContextAboutToHide() ) ); 02073 return context; 02074 } 02075 02076 void KToolBar::slotContextAboutToShow() 02077 { 02078 if (!d->m_configurePlugged) 02079 { 02080 // try to find "configure toolbars" action 02081 KXMLGUIClient *xmlGuiClient = d->m_xmlguiClient; 02082 02083 KMainWindow *kmw = dynamic_cast<KMainWindow *>(mainWindow()); 02084 if ( !xmlGuiClient && kmw ) 02085 xmlGuiClient = kmw; 02086 if ( xmlGuiClient ) 02087 { 02088 KAction *configureAction = xmlGuiClient->actionCollection()->action(KStdAction::stdName(KStdAction::ConfigureToolbars)); 02089 if ( configureAction ) 02090 { 02091 configureAction->plug(context); 02092 d->m_configurePlugged = true; 02093 } 02094 } 02095 } 02096 KEditToolbar::setDefaultToolbar(QObject::name()); 02097 02098 for(int i = CONTEXT_ICONS; i <= CONTEXT_TEXTUNDER; ++i) 02099 context->setItemChecked(i, false); 02100 02101 switch( d->m_iconText ) 02102 { 02103 case IconOnly: 02104 default: 02105 context->setItemChecked(CONTEXT_ICONS, true); 02106 break; 02107 case IconTextRight: 02108 context->setItemChecked(CONTEXT_TEXTRIGHT, true); 02109 break; 02110 case TextOnly: 02111 context->setItemChecked(CONTEXT_TEXT, true); 02112 break; 02113 case IconTextBottom: 02114 context->setItemChecked(CONTEXT_TEXTUNDER, true); 02115 break; 02116 } 02117 02118 QValueList<int>::ConstIterator iIt = d->iconSizes.begin(); 02119 QValueList<int>::ConstIterator iEnd = d->iconSizes.end(); 02120 for (; iIt != iEnd; ++iIt ) 02121 context->setItemChecked( CONTEXT_ICONSIZES + *iIt, false ); 02122 02123 context->setItemChecked( CONTEXT_ICONSIZES, false ); 02124 02125 context->setItemChecked( CONTEXT_ICONSIZES + d->m_iconSize, true ); 02126 02127 for ( int i = CONTEXT_TOP; i <= CONTEXT_FLAT; ++i ) 02128 context->setItemChecked( i, false ); 02129 02130 switch ( barPos() ) 02131 { 02132 case KToolBar::Flat: 02133 context->setItemChecked( CONTEXT_FLAT, true ); 02134 break; 02135 case KToolBar::Bottom: 02136 context->setItemChecked( CONTEXT_BOTTOM, true ); 02137 break; 02138 case KToolBar::Left: 02139 context->setItemChecked( CONTEXT_LEFT, true ); 02140 break; 02141 case KToolBar::Right: 02142 context->setItemChecked( CONTEXT_RIGHT, true ); 02143 break; 02144 case KToolBar::Floating: 02145 context->setItemChecked( CONTEXT_FLOAT, true ); 02146 break; 02147 case KToolBar::Top: 02148 context->setItemChecked( CONTEXT_TOP, true ); 02149 break; 02150 default: break; 02151 } 02152 } 02153 02154 void KToolBar::slotContextAboutToHide() 02155 { 02156 QPtrListIterator<QWidget> it( widgets ); 02157 QWidget *wdg; 02158 while ( ( wdg = it.current() ) != 0 ) { 02159 if ( wdg->inherits( "QToolButton" ) ) 02160 static_cast<QToolButton*>( wdg )->setDown( false ); 02161 ++it; 02162 } 02163 } 02164 02165 void KToolBar::widgetDestroyed() 02166 { 02167 removeWidgetInternal( (QWidget*)sender() ); 02168 } 02169 02170 void KToolBar::removeWidgetInternal( QWidget * w ) 02171 { 02172 widgets.removeRef( w ); 02173 QMap< QWidget*, int >::Iterator it = widget2id.find( w ); 02174 if ( it == widget2id.end() ) 02175 return; 02176 id2widget.remove( *it ); 02177 widget2id.remove( it ); 02178 } 02179 02180 void KToolBar::virtual_hook( int, void* ) 02181 { /*BASE::virtual_hook( id, data );*/ } 02182 02183 #include "ktoolbar.moc" 02184
KDE Logo
This file is part of the documentation for kdeui Library Version 3.3.0.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Wed Sep 29 09:40:35 2004 by doxygen 1.3.8 written by Dimitri van Heesch, © 1997-2003