00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #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
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 ) {
00214 connect(kapp, SIGNAL(toolbarAppearanceChanged(int)), this, SLOT(slotAppearanceChanged()));
00215
00216 kapp->addKipcEventMask(KIPC::IconChanged);
00217 connect(kapp, SIGNAL(iconChanged(int)), this, SLOT(slotIconChanged(int)));
00218 }
00219
00220
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 , QWidget *widget, int index)
00386 {
00387 removeWidgetInternal( widget );
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();
00846
00847
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();
00883
00884
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 )
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
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
00957 if ( d->m_xmlguiClient && !d->m_xmlguiClient->xmlFile().isEmpty() ) {
00958
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
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
00979 if ( !d->modified )
00980 return;
00981
00982
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
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
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
01040
01041 QString position, icontext, index, offset, newLine;
01042 getAttributes( position, icontext, index, offset, newLine );
01043
01044
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
01070 setLabel( txt + " ( " + kapp->caption() + " ) " );
01071 }
01072
01073
01074 QString KToolBar::text() const
01075 {
01076 return label();
01077 }
01078
01079
01080 void KToolBar::doConnections( KToolBarButton *button )
01081 {
01082 connect(button, SIGNAL(clicked(int)), this, SIGNAL( clicked( int ) ) );
01083 connect(button, SIGNAL(doubleClicked(int)), this, SIGNAL( doubleClicked( int ) ) );
01084 connect(button, SIGNAL(released(int)), this, SIGNAL( released( int ) ) );
01085 connect(button, SIGNAL(pressed(int)), this, SIGNAL( pressed( int ) ) );
01086 connect(button, SIGNAL(toggled(int)), this, SIGNAL( toggled( int ) ) );
01087 connect(button, SIGNAL(highlighted(int, bool)), this, SIGNAL( highlighted( int, bool ) ) );
01088 }
01089
01090 void KToolBar::mousePressEvent ( QMouseEvent *m )
01091 {
01092 if ( !mainWindow() )
01093 return;
01094 QMainWindow *mw = mainWindow();
01095 if ( mw->toolBarsMovable() && d->m_enableContext ) {
01096 if ( m->button() == RightButton ) {
01097 int i = contextMenu()->exec( m->globalPos(), 0 );
01098 switch ( i ) {
01099 case -1:
01100 return;
01101 case CONTEXT_LEFT:
01102 mw->moveDockWindow( this, DockLeft );
01103 break;
01104 case CONTEXT_RIGHT:
01105 mw->moveDockWindow( this, DockRight );
01106 break;
01107 case CONTEXT_TOP:
01108 mw->moveDockWindow( this, DockTop );
01109 break;
01110 case CONTEXT_BOTTOM:
01111 mw->moveDockWindow( this, DockBottom );
01112 break;
01113 case CONTEXT_FLOAT:
01114 break;
01115 case CONTEXT_FLAT:
01116 mw->moveDockWindow( this, DockMinimized );
01117 break;
01118 case CONTEXT_ICONS:
01119 setIconText( IconOnly );
01120 break;
01121 case CONTEXT_TEXTRIGHT:
01122 setIconText( IconTextRight );
01123 break;
01124 case CONTEXT_TEXT:
01125 setIconText( TextOnly );
01126 break;
01127 case CONTEXT_TEXTUNDER:
01128 setIconText( IconTextBottom );
01129 break;
01130 default:
01131 if ( i >= CONTEXT_ICONSIZES )
01132 setIconSize( i - CONTEXT_ICONSIZES );
01133 else
01134 return;
01135 }
01136 if ( mw->inherits("KMainWindow") )
01137 static_cast<KMainWindow *>(mw)->setSettingsDirty();
01138 }
01139 }
01140 }
01141
01142
01143 void KToolBar::rebuildLayout()
01144 {
01145 layoutTimer->stop();
01146 QApplication::sendPostedEvents( this, QEvent::ChildInserted );
01147 QBoxLayout *l = boxLayout();
01148
01149
01150 QLayoutIterator it = l->iterator();
01151 while ( it.current() )
01152 it.deleteCurrent();
01153
01154 for ( QWidget *w = widgets.first(); w; w = widgets.next() ) {
01155 if ( w == rightAligned )
01156 continue;
01157 if ( w->inherits( "KToolBarSeparator" ) &&
01158 !( (KToolBarSeparator*)w )->showLine() ) {
01159 l->addSpacing( 6 );
01160 w->hide();
01161 continue;
01162 }
01163 if ( w->inherits( "QPopupMenu" ) )
01164 continue;
01165 l->addWidget( w );
01166 w->show();
01167 }
01168 if ( rightAligned ) {
01169 l->addStretch();
01170 l->addWidget( rightAligned );
01171 rightAligned->show();
01172 }
01173
01174 if ( fullSize() ) {
01175
01176
01177
01178
01179 if ( !rightAligned )
01180 l->addStretch();
01181 if ( stretchableWidget )
01182 l->setStretchFactor( stretchableWidget, 10 );
01183 }
01184 l->invalidate();
01185 QApplication::postEvent( this, new QEvent( QEvent::LayoutHint ) );
01186 }
01187
01188 void KToolBar::childEvent( QChildEvent *e )
01189 {
01190 if ( e->child()->isWidgetType() ) {
01191 QWidget * w = (QWidget*)e->child();
01192 if ( e->type() == QEvent::ChildInserted ) {
01193 if ( !e->child()->inherits( "QPopupMenu" ) &&
01194 ::qstrcmp( "qt_dockwidget_internal", e->child()->name() ) != 0 ) {
01195
01196
01197
01198 if ( !widget2id.contains( w ) )
01199 {
01200 int dummy = -1;
01201 insertWidgetInternal( w, dummy, -1 );
01202 }
01203 }
01204 } else {
01205 removeWidgetInternal( w );
01206 }
01207 if ( isVisibleTo( 0 ) )
01208 layoutTimer->start( 50, TRUE );
01209 }
01210 QToolBar::childEvent( e );
01211 }
01212
01213 void KToolBar::insertWidgetInternal( QWidget *w, int &index, int id )
01214 {
01215
01216
01217
01218 connect( w, SIGNAL( destroyed() ),
01219 this, SLOT( widgetDestroyed() ) );
01220 if ( index == -1 || index > (int)widgets.count() ) {
01221 widgets.append( w );
01222 index = (int)widgets.count();
01223 }
01224 else
01225 widgets.insert( index, w );
01226 if ( id == -1 )
01227 id = id2widget.count();
01228 id2widget.insert( id, w );
01229 widget2id.insert( w, id );
01230 }
01231
01232 void KToolBar::showEvent( QShowEvent *e )
01233 {
01234 QToolBar::showEvent( e );
01235 rebuildLayout();
01236 }
01237
01238 void KToolBar::setStretchableWidget( QWidget *w )
01239 {
01240 QToolBar::setStretchableWidget( w );
01241 stretchableWidget = w;
01242 }
01243
01244 QSizePolicy KToolBar::sizePolicy() const
01245 {
01246 if ( orientation() == Horizontal )
01247 return QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed );
01248 else
01249 return QSizePolicy( QSizePolicy::Fixed, QSizePolicy::Expanding );
01250 }
01251
01252 QSize KToolBar::sizeHint() const
01253 {
01254 QSize minSize(0,0);
01255 KToolBar *this_too = (KToolBar *)this;
01256
01257 this_too->polish();
01258
01259 int margin = ((QWidget *)this)->layout()->margin() + frameWidth();
01260
01261 switch( barPos() )
01262 {
01263 case KToolBar::Top:
01264 case KToolBar::Bottom:
01265 for ( QWidget *w = this_too->widgets.first(); w; w = this_too->widgets.next() )
01266 {
01267 if ( w->inherits( "KToolBarSeparator" ) &&
01268 !( (KToolBarSeparator*)w )->showLine() )
01269 {
01270 minSize += QSize(6, 0);
01271 }
01272 else
01273 {
01274 QSize sh = w->sizeHint();
01275 if (!sh.isValid())
01276 sh = w->minimumSize();
01277 minSize = minSize.expandedTo(QSize(0, sh.height()));
01278 minSize += QSize(sh.width()+1, 0);
01279 }
01280 }
01281 minSize += QSize(QApplication::style().pixelMetric( QStyle::PM_DockWindowHandleExtent ), 0);
01282 minSize += QSize(margin*2, margin*2);
01283 break;
01284
01285 case KToolBar::Left:
01286 case KToolBar::Right:
01287 for ( QWidget *w = this_too->widgets.first(); w; w = this_too->widgets.next() )
01288 {
01289 if ( w->inherits( "KToolBarSeparator" ) &&
01290 !( (KToolBarSeparator*)w )->showLine() )
01291 {
01292 minSize += QSize(0, 6);
01293 }
01294 else
01295 {
01296 QSize sh = w->sizeHint();
01297 if (!sh.isValid())
01298 sh = w->minimumSize();
01299 minSize = minSize.expandedTo(QSize(sh.width(), 0));
01300 minSize += QSize(0, sh.height()+1);
01301 }
01302 }
01303 minSize += QSize(0, QApplication::style().pixelMetric( QStyle::PM_DockWindowHandleExtent ));
01304 minSize += QSize(margin*2, margin*2);
01305 break;
01306
01307 default:
01308 minSize = QToolBar::sizeHint();
01309 break;
01310 }
01311 return minSize;
01312 }
01313
01314 QSize KToolBar::minimumSize() const
01315 {
01316 return minimumSizeHint();
01317 }
01318
01319 QSize KToolBar::minimumSizeHint() const
01320 {
01321 return sizeHint();
01322 }
01323
01324 bool KToolBar::highlight() const
01325 {
01326 return d->m_highlight;
01327 }
01328
01329 void KToolBar::hide()
01330 {
01331 QToolBar::hide();
01332 }
01333
01334 void KToolBar::show()
01335 {
01336 QToolBar::show();
01337 }
01338
01339 void KToolBar::resizeEvent( QResizeEvent *e )
01340 {
01341 bool b = isUpdatesEnabled();
01342 setUpdatesEnabled( FALSE );
01343 QToolBar::resizeEvent( e );
01344 if (b)
01345 d->repaintTimer.start( 100, true );
01346 }
01347
01348 void KToolBar::slotIconChanged(int group)
01349 {
01350 if ((group != KIcon::Toolbar) && (group != KIcon::MainToolbar))
01351 return;
01352 if ((group == KIcon::MainToolbar) != !::qstrcmp(name(), "mainToolBar"))
01353 return;
01354
01355 emit modechange();
01356 if (isVisible())
01357 updateGeometry();
01358 }
01359
01360 void KToolBar::slotReadConfig()
01361 {
01362
01363
01364
01365
01366 applyAppearanceSettings(KGlobal::config(), QString::null );
01367 }
01368
01369 void KToolBar::slotAppearanceChanged()
01370 {
01371
01372 applyAppearanceSettings(KGlobal::config(), QString::null, true );
01373
01374 if ( mainWindow() && mainWindow()->inherits( "KMainWindow" ) )
01375 static_cast<KMainWindow *>(mainWindow())->setSettingsDirty();
01376 }
01377
01378
01379 bool KToolBar::highlightSetting()
01380 {
01381 QString grpToolbar(QString::fromLatin1("Toolbar style"));
01382 KConfigGroupSaver saver(KGlobal::config(), grpToolbar);
01383 return KGlobal::config()->readBoolEntry(QString::fromLatin1("Highlighting"),true);
01384 }
01385
01386
01387 bool KToolBar::transparentSetting()
01388 {
01389 QString grpToolbar(QString::fromLatin1("Toolbar style"));
01390 KConfigGroupSaver saver(KGlobal::config(), grpToolbar);
01391 return KGlobal::config()->readBoolEntry(QString::fromLatin1("TransparentMoving"),true);
01392 }
01393
01394
01395 KToolBar::IconText KToolBar::iconTextSetting()
01396 {
01397 QString grpToolbar(QString::fromLatin1("Toolbar style"));
01398 KConfigGroupSaver saver(KGlobal::config(), grpToolbar);
01399 QString icontext = KGlobal::config()->readEntry(QString::fromLatin1("IconText"),QString::fromLatin1("IconOnly"));
01400 if ( icontext == "IconTextRight" )
01401 return IconTextRight;
01402 else if ( icontext == "IconTextBottom" )
01403 return IconTextBottom;
01404 else if ( icontext == "TextOnly" )
01405 return TextOnly;
01406 else
01407 return IconOnly;
01408 }
01409
01410 void KToolBar::applyAppearanceSettings(KConfig *config, const QString &_configGroup, bool forceGlobal)
01411 {
01412 QString configGroup = _configGroup.isEmpty() ? settingsGroup() : _configGroup;
01413
01414
01415
01416
01417
01418 if ( d->m_xmlguiClient && !d->m_xmlguiClient->xmlFile().isEmpty() &&
01419 !config->hasGroup(configGroup) )
01420 return;
01421
01422 KConfig *gconfig = KGlobal::config();
01423
01424 static const QString &attrIconText = KGlobal::staticQString("IconText");
01425 static const QString &attrHighlight = KGlobal::staticQString("Highlighting");
01426 static const QString &attrTrans = KGlobal::staticQString("TransparentMoving");
01427 static const QString &attrSize = KGlobal::staticQString("IconSize");
01428
01429
01430
01431
01432 bool highlight;
01433 int transparent;
01434 QString icontext;
01435 int iconsize = 0;
01436
01437
01438 QString grpToolbar(QString::fromLatin1("Toolbar style"));
01439 {
01440 KConfigGroupSaver saver(gconfig, grpToolbar);
01441
01442
01443 highlight = gconfig->readBoolEntry(attrHighlight, true);
01444 transparent = gconfig->readBoolEntry(attrTrans, true);
01445
01446
01447
01448 if (d->m_honorStyle)
01449 icontext = gconfig->readEntry(attrIconText, "IconOnly");
01450 else
01451 icontext = "IconOnly";
01452
01453
01454 iconsize = gconfig->readNumEntry(attrSize, 0);
01455
01456 if ( !forceGlobal && config->hasGroup(configGroup) )
01457 {
01458 config->setGroup(configGroup);
01459
01460
01461 highlight = config->readBoolEntry(attrHighlight, highlight);
01462 transparent = config->readBoolEntry(attrTrans, transparent);
01463
01464 icontext = config->readEntry(attrIconText, icontext);
01465
01466
01467 iconsize = config->readNumEntry(attrSize, iconsize);
01468 }
01469
01470 }
01471
01472 bool doUpdate = false;
01473
01474 IconText icon_text;
01475 if ( icontext == "IconTextRight" )
01476 icon_text = IconTextRight;
01477 else if ( icontext == "IconTextBottom" )
01478 icon_text = IconTextBottom;
01479 else if ( icontext == "TextOnly" )
01480 icon_text = TextOnly;
01481 else
01482 icon_text = IconOnly;
01483
01484
01485 if (icon_text != d->m_iconText) {
01486
01487 setIconText(icon_text, false);
01488 doUpdate = true;
01489 }
01490
01491
01492 if (iconsize != d->m_iconSize) {
01493 setIconSize(iconsize, false);
01494 doUpdate = true;
01495 }
01496
01497 QMainWindow *mw = mainWindow();
01498
01499
01500 if ( highlight != d->m_highlight ) {
01501 d->m_highlight = highlight;
01502 doUpdate = true;
01503 }
01504
01505
01506 if ( mw && transparent != (!mw->opaqueMoving()) ) {
01507 mw->setOpaqueMoving( !transparent );
01508 }
01509
01510 if (doUpdate)
01511 emit modechange();
01512 if (isVisible ())
01513 updateGeometry();
01514 }
01515
01516 void KToolBar::applySettings(KConfig *config, const QString &_configGroup)
01517 {
01518
01519
01520 QString configGroup = _configGroup.isEmpty() ? settingsGroup() : _configGroup;
01521
01522
01523
01524
01525
01526
01527
01528
01529
01530
01531
01532
01533
01534
01535
01536 applyAppearanceSettings( config, _configGroup );
01537
01538
01539 if ( config->hasGroup(configGroup) )
01540 {
01541 KConfigGroupSaver cgs(config, configGroup);
01542
01543 static const QString &attrPosition = KGlobal::staticQString("Position");
01544 static const QString &attrIndex = KGlobal::staticQString("Index");
01545 static const QString &attrOffset = KGlobal::staticQString("Offset");
01546 static const QString &attrNewLine = KGlobal::staticQString("NewLine");
01547 static const QString &attrHidden = KGlobal::staticQString("Hidden");
01548
01549 QString position = config->readEntry(attrPosition, "Top");
01550 int index = config->readNumEntry(attrIndex, 0 );
01551 int offset = config->readNumEntry(attrOffset, -1 );
01552 bool newLine = config->readEntry(attrNewLine).lower() == "true";
01553 bool hidden = config->readBoolEntry(attrHidden, false);
01554
01555 Dock pos(DockTop);
01556 if ( position == "Top" )
01557 pos = DockTop;
01558 else if ( position == "Bottom" )
01559 pos = DockBottom;
01560 else if ( position == "Left" )
01561 pos = DockLeft;
01562 else if ( position == "Right" )
01563 pos = DockRight;
01564 else if ( position == "Floating" )
01565 pos = DockTornOff;
01566 else if ( position == "Flat" )
01567 pos = DockMinimized;
01568
01569
01570 if (hidden)
01571 hide();
01572 else
01573 show();
01574
01575 if ( mainWindow() )
01576 {
01577 QMainWindow *mw = mainWindow();
01578
01579
01580 d->toolBarInfo = KToolBarPrivate::ToolBarInfo( pos, index, newLine, offset );
01581
01582
01583
01584 bool doHide = isHidden();
01585
01586 mw->moveDockWindow( this, pos, newLine, index, offset );
01587
01588 if ( doHide )
01589 hide();
01590 }
01591 if (isVisible ())
01592 updateGeometry();
01593 }
01594 }
01595
01596 bool KToolBar::event( QEvent *e )
01597 {
01598 if ( (e->type() == QEvent::LayoutHint) && isUpdatesEnabled() )
01599 d->repaintTimer.start( 100, true );
01600
01601 if (e->type() == QEvent::ChildInserted )
01602 {
01603
01604
01605
01606 childEvent((QChildEvent *)e);
01607 return true;
01608 }
01609
01610 return QToolBar::event( e );
01611 }
01612
01613 void KToolBar::slotRepaint()
01614 {
01615 setUpdatesEnabled( FALSE );
01616
01617
01618
01619 QResizeEvent ev(size(), size());
01620 resizeEvent(&ev);
01621 QApplication::sendPostedEvents( this, QEvent::LayoutHint );
01622 setUpdatesEnabled( TRUE );
01623 repaint( TRUE );
01624 }
01625
01626 void KToolBar::toolBarPosChanged( QToolBar *tb )
01627 {
01628 if ( tb != this )
01629 return;
01630 if ( d->oldPos == DockMinimized )
01631 rebuildLayout();
01632 d->oldPos = (QMainWindow::ToolBarDock)barPos();
01633 if ( mainWindow() && mainWindow()->inherits( "KMainWindow" ) )
01634 static_cast<KMainWindow *>(mainWindow())->setSettingsDirty();
01635 }
01636
01637 void KToolBar::loadState( const QDomElement &element )
01638 {
01639
01640 if ( !mainWindow() || !mainWindow()->inherits( "KMainWindow") )
01641 return;
01642 KMainWindow *mw = static_cast<KMainWindow *>( mainWindow() );
01643
01644 QCString text = element.namedItem( "text" ).toElement().text().utf8();
01645 if ( text.isEmpty() )
01646 text = element.namedItem( "Text" ).toElement().text().utf8();
01647
01648 if ( !text.isEmpty() )
01649 setText( i18n( text ) );
01650
01651 mw->addToolBar( this );
01652 QCString attrFullWidth = element.attribute( "fullWidth" ).lower().latin1();
01653 QCString attrPosition = element.attribute( "position" ).lower().latin1();
01654 QCString attrIconText = element.attribute( "iconText" ).lower().latin1();
01655 QString attrIconSize = element.attribute( "iconSize" ).lower();
01656 QString attrIndex = element.attribute( "index" ).lower();
01657 QString attrOffset = element.attribute( "offset" ).lower();
01658 QString attrNewLine = element.attribute( "newline" ).lower();
01659 QString attrHidden = element.attribute( "hidden" ).lower();
01660
01661 if ( !attrFullWidth.isEmpty() ) {
01662 if ( attrFullWidth == "true" )
01663 setFullSize( TRUE );
01664 else
01665 setFullSize( FALSE );
01666 }
01667
01668 Dock dock = DockTop;
01669 int index = -1 , offset = -1;
01670 bool nl = FALSE;
01671
01672
01673 if ( !attrPosition.isEmpty() ) {
01674 if ( attrPosition == "top" )
01675 dock = DockTop;
01676 else if ( attrPosition == "left" )
01677 dock = DockLeft;
01678 else if ( attrPosition == "right" )
01679 dock = DockRight;
01680 else if ( attrPosition == "bottom" )
01681 dock = DockBottom;
01682 else if ( attrPosition == "floating" )
01683 dock = DockTornOff;
01684 else if ( attrPosition == "flat" )
01685 dock = DockMinimized;
01686 }
01687
01688 if ( !attrIndex.isEmpty() )
01689 index = attrIndex.toInt();
01690 if ( !attrOffset.isEmpty() )
01691 offset = attrOffset.toInt();
01692 if ( !attrNewLine.isEmpty() )
01693 nl = attrNewLine == "true" ? TRUE : FALSE;
01694
01695
01696 d->toolBarInfo = KToolBarPrivate::ToolBarInfo( dock, index, nl, offset );
01697 if ( mw )
01698 {
01699 mw->moveDockWindow( this, dock, nl, index, offset );
01700
01701 }
01702
01703 if ( !attrIconText.isEmpty() ) {
01704
01705 if ( attrIconText == "icontextright" )
01706 setIconText( KToolBar::IconTextRight );
01707 else if ( attrIconText == "textonly" )
01708 setIconText( KToolBar::TextOnly );
01709 else if ( attrIconText == "icontextbottom" )
01710 setIconText( KToolBar::IconTextBottom );
01711 else if ( attrIconText == "icononly" )
01712 setIconText( KToolBar::IconOnly );
01713 } else
01714
01715 setIconText( iconTextSetting() );
01716
01717 if ( !attrIconSize.isEmpty() )
01718 setIconSize( attrIconSize.toInt() );
01719
01720
01721 d->m_highlight = highlightSetting();
01722
01723
01724
01725 if ( transparentSetting() != (!mw->opaqueMoving()) )
01726 mw->setOpaqueMoving( !transparentSetting() );
01727
01728 if ( attrHidden == "true" )
01729 hide();
01730 else
01731 show();
01732 }
01733
01734 void KToolBar::getAttributes( QString &position, QString &icontext, QString &index, QString &offset, QString &newLine )
01735 {
01736
01737 switch ( barPos() ) {
01738 case KToolBar::Flat:
01739 position = "Flat";
01740 break;
01741 case KToolBar::Bottom:
01742 position = "Bottom";
01743 break;
01744 case KToolBar::Left:
01745 position = "Left";
01746 break;
01747 case KToolBar::Right:
01748 position = "Right";
01749 break;
01750 case KToolBar::Floating:
01751 position = "Floating";
01752 break;
01753 case KToolBar::Top:
01754 default:
01755 position = "Top";
01756 break;
01757 }
01758 if ( mainWindow() ) {
01759 QMainWindow::ToolBarDock dock;
01760 int index_;
01761 bool nl;
01762 int offset_;
01763 mainWindow()->getLocation( (QToolBar*)this, dock, index_, nl, offset_ );
01764 index = QString::number( index_ );
01765 offset = QString::number( offset_ );
01766 newLine = nl ? "true" : "false";
01767 }
01768
01769 switch (d->m_iconText) {
01770 case KToolBar::IconTextRight:
01771 icontext = "IconTextRight";
01772 break;
01773 case KToolBar::IconTextBottom:
01774 icontext = "IconTextBottom";
01775 break;
01776 case KToolBar::TextOnly:
01777 icontext = "TextOnly";
01778 break;
01779 case KToolBar::IconOnly:
01780 default:
01781 icontext = "IconOnly";
01782 break;
01783 }
01784 }
01785
01786 void KToolBar::saveState( QDomElement ¤t )
01787 {
01788 QString position, icontext, index, offset, newLine;
01789 getAttributes( position, icontext, index, offset, newLine );
01790
01791 current.setAttribute( "noMerge", "1" );
01792 current.setAttribute( "position", position );
01793 current.setAttribute( "iconText", icontext );
01794 if ( !index.isEmpty() )
01795 current.setAttribute( "index", index );
01796 if ( !offset.isEmpty() )
01797 current.setAttribute( "offset", offset );
01798 if ( !newLine.isEmpty() )
01799 current.setAttribute( "newline", newLine );
01800 if ( isHidden() )
01801 current.setAttribute( "hidden", "true" );
01802 d->modified = true;
01803 }
01804
01805 void KToolBar::positionYourself( bool force )
01806 {
01807 if (force)
01808 d->positioned = false;
01809
01810 if ( d->positioned || !mainWindow() )
01811 {
01812
01813 return;
01814 }
01815
01816
01817 bool doHide = isHidden();
01818
01819 mainWindow()->moveDockWindow( this, d->toolBarInfo.dock,
01820 d->toolBarInfo.newline,
01821 d->toolBarInfo.index,
01822 d->toolBarInfo.offset );
01823 if ( doHide )
01824 hide();
01825
01826 d->positioned = TRUE;
01827 }
01828
01829 KPopupMenu *KToolBar::contextMenu()
01830 {
01831 if ( context )
01832 return context;
01833
01834
01835
01836 context = new KPopupMenu( this, "qt_dockwidget_internal" );
01837 context->insertTitle(i18n("Toolbar Menu"));
01838
01839 KPopupMenu *orient = new KPopupMenu( context, "orient" );
01840 orient->insertItem( i18n("toolbar position string","Top"), CONTEXT_TOP );
01841 orient->insertItem( i18n("toolbar position string","Left"), CONTEXT_LEFT );
01842 orient->insertItem( i18n("toolbar position string","Right"), CONTEXT_RIGHT );
01843 orient->insertItem( i18n("toolbar position string","Bottom"), CONTEXT_BOTTOM );
01844 orient->insertSeparator(-1);
01845
01846 orient->insertItem( i18n("min toolbar", "Flat"), CONTEXT_FLAT );
01847
01848 KPopupMenu *mode = new KPopupMenu( context, "mode" );
01849 mode->insertItem( i18n("Icons Only"), CONTEXT_ICONS );
01850 mode->insertItem( i18n("Text Only"), CONTEXT_TEXT );
01851 mode->insertItem( i18n("Text Alongside Icons"), CONTEXT_TEXTRIGHT );
01852 mode->insertItem( i18n("Text Under Icons"), CONTEXT_TEXTUNDER );
01853
01854 KPopupMenu *size = new KPopupMenu( context, "size" );
01855 size->insertItem( i18n("Default"), CONTEXT_ICONSIZES );
01856
01857 KIconTheme *theme = KGlobal::instance()->iconLoader()->theme();
01858 QValueList<int> avSizes;
01859 if (!::qstrcmp(QObject::name(), "mainToolBar"))
01860 avSizes = theme->querySizes( KIcon::MainToolbar);
01861 else
01862 avSizes = theme->querySizes( KIcon::Toolbar);
01863
01864 d->iconSizes = avSizes;
01865
01866 QValueList<int>::Iterator it;
01867 for (it=avSizes.begin(); it!=avSizes.end(); it++) {
01868 QString text;
01869 if ( *it < 19 )
01870 text = i18n("Small (%1x%2)").arg(*it).arg(*it);
01871 else if (*it < 25)
01872 text = i18n("Medium (%1x%2)").arg(*it).arg(*it);
01873 else
01874 text = i18n("Large (%1x%2)").arg(*it).arg(*it);
01875
01876 size->insertItem( text, CONTEXT_ICONSIZES + *it );
01877 }
01878
01879 context->insertItem( i18n("Orientation"), orient );
01880 orient->setItemChecked(CONTEXT_TOP, true);
01881 context->insertItem( i18n("Text Position"), mode );
01882 context->setItemChecked(CONTEXT_ICONS, true);
01883 context->insertItem( i18n("Icon Size"), size );
01884
01885 if (mainWindow()->inherits("KMainWindow"))
01886 {
01887 if ( (static_cast<KMainWindow*>(mainWindow())->toolBarMenuAction()) &&
01888 (static_cast<KMainWindow*>(mainWindow())->hasMenuBar()) )
01889
01890 (static_cast<KMainWindow*>(mainWindow()))->toolBarMenuAction()->plug(context);
01891 }
01892
01893
01894 connect( context, SIGNAL( aboutToShow() ), this, SLOT( slotContextAboutToShow() ) );
01895 return context;
01896 }
01897
01898 void KToolBar::slotContextAboutToShow()
01899 {
01900 if (!d->m_configurePlugged)
01901 {
01902
01903 KXMLGUIClient *xmlGuiClient = d->m_xmlguiClient;
01904 if ( !xmlGuiClient && mainWindow() && mainWindow()->inherits( "KMainWindow" ) )
01905 xmlGuiClient = (KMainWindow *)mainWindow();
01906 if ( xmlGuiClient )
01907 {
01908 KAction *configureAction = xmlGuiClient->actionCollection()->action(KStdAction::stdName(KStdAction::ConfigureToolbars));
01909 if ( configureAction )
01910 {
01911 configureAction->plug(context);
01912 d->m_configurePlugged = true;
01913 }
01914 }
01915 }
01916
01917 for(int i = CONTEXT_ICONS; i <= CONTEXT_TEXTUNDER; ++i)
01918 context->setItemChecked(i, false);
01919
01920 switch( d->m_iconText )
01921 {
01922 case IconOnly:
01923 default:
01924 context->setItemChecked(CONTEXT_ICONS, true);
01925 break;
01926 case IconTextRight:
01927 context->setItemChecked(CONTEXT_TEXTRIGHT, true);
01928 break;
01929 case TextOnly:
01930 context->setItemChecked(CONTEXT_TEXT, true);
01931 break;
01932 case IconTextBottom:
01933 context->setItemChecked(CONTEXT_TEXTUNDER, true);
01934 break;
01935 }
01936
01937 QValueList<int>::ConstIterator iIt = d->iconSizes.begin();
01938 QValueList<int>::ConstIterator iEnd = d->iconSizes.end();
01939 for (; iIt != iEnd; ++iIt )
01940 context->setItemChecked( CONTEXT_ICONSIZES + *iIt, false );
01941
01942 context->setItemChecked( CONTEXT_ICONSIZES, false );
01943
01944 context->setItemChecked( CONTEXT_ICONSIZES + d->m_iconSize, true );
01945
01946 for ( int i = CONTEXT_TOP; i <= CONTEXT_FLAT; ++i )
01947 context->setItemChecked( i, false );
01948
01949 switch ( barPos() )
01950 {
01951 case KToolBar::Flat:
01952 context->setItemChecked( CONTEXT_FLAT, true );
01953 break;
01954 case KToolBar::Bottom:
01955 context->setItemChecked( CONTEXT_BOTTOM, true );
01956 break;
01957 case KToolBar::Left:
01958 context->setItemChecked( CONTEXT_LEFT, true );
01959 break;
01960 case KToolBar::Right:
01961 context->setItemChecked( CONTEXT_RIGHT, true );
01962 break;
01963 case KToolBar::Floating:
01964 context->setItemChecked( CONTEXT_FLOAT, true );
01965 break;
01966 case KToolBar::Top:
01967 context->setItemChecked( CONTEXT_TOP, true );
01968 break;
01969 default: break;
01970 }
01971 }
01972
01973 void KToolBar::widgetDestroyed()
01974 {
01975 removeWidgetInternal( (QWidget*)sender() );
01976 }
01977
01978 void KToolBar::removeWidgetInternal( QWidget * w )
01979 {
01980 widgets.removeRef( w );
01981 QMap< QWidget*, int >::Iterator it = widget2id.find( w );
01982 if ( it == widget2id.end() )
01983 return;
01984 id2widget.remove( *it );
01985 widget2id.remove( it );
01986 }
01987
01988 void KToolBar::virtual_hook( int, void* )
01989 { }
01990
01991 #include "ktoolbar.moc"
01992