# kdeui Library API Documentation

Overview | Class Hierarchy | Classes | Classes (annotated) | Members | Source Files

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

This file is part of the documentation for kdelibs Version 3.1.5.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Wed Jan 28 12:57:55 2004 by doxygen 1.3.4 written by Dimitri van Heesch, © 1997-2001