• Skip to content
  • Skip to link menu
KDE 4.6 API Reference
  • KDE API Reference
  • kdelibs
  • KDE Home
  • Contact Us
 

KDEUI

ktabwidget.cpp

Go to the documentation of this file.
00001 /* This file is part of the KDE libraries
00002   Copyright (C) 2003 Stephan Binner <binner@kde.org>
00003   Copyright (C) 2003 Zack Rusin <zack@kde.org>
00004   Copyright (C) 2009 Urs Wolfer <uwolfer @ kde.org>
00005 
00006   This library is free software; you can redistribute it and/or
00007   modify it under the terms of the GNU Library General Public
00008   License as published by the Free Software Foundation; either
00009   version 2 of the License, or (at your option) any later version.
00010 
00011   This library is distributed in the hope that it will be useful,
00012   but WITHOUT ANY WARRANTY; without even the implied warranty of
00013   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014   Library General Public License for more details.
00015 
00016   You should have received a copy of the GNU Library General Public License
00017   along with this library; see the file COPYING.LIB.  If not, write to
00018   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00019   Boston, MA 02110-1301, USA.
00020 */
00021 
00022 #include "ktabwidget.h"
00023 
00024 #include <QtGui/QApplication>
00025 #include <QtGui/QDragMoveEvent>
00026 #include <QtGui/QDropEvent>
00027 #include <QtGui/QMouseEvent>
00028 #include <QtGui/QStyle>
00029 #include <QtGui/QStyleOption>
00030 #include <QtGui/QTextDocument>
00031 #include <QtGui/QWheelEvent>
00032 #include <QtCore/QList>
00033 
00034 #include <ksharedconfig.h>
00035 #include <kiconloader.h>
00036 #include <kstringhandler.h>
00037 #include <kdebug.h>
00038 
00039 #include <ktabbar.h>
00040 
00041 #include <kconfiggroup.h>
00042 
00043 class KTabWidget::Private
00044 {
00045   public:
00046     enum {
00047         ResizeEnabled = 0,
00048         ResizeDisabled,
00049         ResizeLater
00050     } m_resizeSuspend;
00051 
00052     Private( KTabWidget *parent )
00053       : m_resizeSuspend(ResizeEnabled),
00054         m_parent( parent ),
00055         m_automaticResizeTabs( false ),
00056         m_tabBarHidden( false )
00057     {
00058 
00059       KConfigGroup cg(KGlobal::config(), "General");
00060       m_maxLength = cg.readEntry("MaximumTabLength", 30);
00061       m_minLength = cg.readEntry("MinimumTabLength", 3);
00062       Q_ASSERT(m_maxLength >= m_minLength);
00063       m_currentTabLength = m_minLength;
00064     }
00065 
00066     KTabWidget *m_parent;
00067     bool m_automaticResizeTabs;
00068     bool m_tabBarHidden;
00069     int m_maxLength;
00070     int m_minLength;
00071     int m_currentTabLength;
00072 
00073     //holds the full names of the tab, otherwise all we
00074     //know about is the shortened name
00075     QStringList m_tabNames;
00076 
00077     bool isEmptyTabbarSpace( const QPoint & )  const;
00078     void resizeTabs( int changedTabIndex = -1 );
00079     void updateTab( int index );
00080     void removeTab( int index );
00081 };
00082 
00083 bool KTabWidget::Private::isEmptyTabbarSpace( const QPoint &point ) const
00084 {
00085     if (m_parent->count() == 0) {
00086         return true;
00087     }
00088     if (m_parent->tabBar()->isHidden()) {
00089         return false;
00090     }
00091   QSize size( m_parent->tabBar()->sizeHint() );
00092   if ( ( m_parent->tabPosition() == QTabWidget::North && point.y() < size.height() ) ||
00093        ( m_parent->tabPosition() == QTabWidget::South && point.y() > (m_parent->height() - size.height() ) ) ) {
00094 
00095     QWidget *rightcorner = m_parent->cornerWidget( Qt::TopRightCorner );
00096     if ( rightcorner && rightcorner->isVisible() ) {
00097       if ( point.x() >= m_parent->width()-rightcorner->width() )
00098         return false;
00099     }
00100 
00101     QWidget *leftcorner = m_parent->cornerWidget( Qt::TopLeftCorner );
00102     if ( leftcorner && leftcorner->isVisible() ) {
00103       if ( point.x() <= leftcorner->width() )
00104         return false;
00105     }
00106 
00107     for ( int i = 0; i < m_parent->count(); ++i )
00108       if ( m_parent->tabBar()->tabRect( i ).contains( m_parent->tabBar()->mapFromParent( point ) ) )
00109         return false;
00110 
00111     return true;
00112   }
00113 
00114   return false;
00115 }
00116 
00117 void KTabWidget::Private::removeTab( int index )
00118 {
00119   // prevent cascading resize slowness, not to mention crashes due to tab count()
00120   // and m_tabNames.count() being out of sync!
00121   m_resizeSuspend = ResizeDisabled;
00122 
00123   // Need to do this here, rather than in tabRemoved().  Calling
00124   // QTabWidget::removeTab() below may cause a relayout of the tab bar, which
00125   // will call resizeTabs() immediately.  If m_automaticResizeTabs is true,
00126   // that will use the m_tabNames[] list before it has been updated to reflect
00127   // the new tab arrangement.  See bug 190528.
00128   m_tabNames.removeAt( index );
00129 
00130   m_parent->QTabWidget::removeTab( index );
00131 
00132   const bool doResize = (m_resizeSuspend == ResizeLater) || m_automaticResizeTabs;
00133   m_resizeSuspend = ResizeEnabled;
00134   if (doResize) {
00135     resizeTabs();
00136   }
00137 
00138 }
00139 
00140 void KTabWidget::Private::resizeTabs( int changeTabIndex )
00141 {
00142     if (m_resizeSuspend != ResizeEnabled) {
00143         m_resizeSuspend = ResizeLater;
00144         return;
00145     }
00146 
00147     int newTabLength = m_maxLength;
00148 
00149     if (m_automaticResizeTabs) {
00150         // Calculate new max length
00151         int lcw = 0, rcw = 0;
00152 
00153         const int tabBarHeight = m_parent->tabBar()->sizeHint().height();
00154         if (m_parent->cornerWidget(Qt::TopLeftCorner) &&
00155             m_parent->cornerWidget( Qt::TopLeftCorner )->isVisible()) {
00156             lcw = qMax(m_parent->cornerWidget(Qt::TopLeftCorner)->width(), tabBarHeight);
00157         }
00158         if (m_parent->cornerWidget(Qt::TopRightCorner) &&
00159             m_parent->cornerWidget(Qt::TopRightCorner)->isVisible()) {
00160             rcw = qMax( m_parent->cornerWidget(Qt::TopRightCorner)->width(), tabBarHeight);
00161         }
00162 
00163         const int maxTabBarWidth = m_parent->width() - lcw - rcw;
00164 
00165         // binary search for the best fitting tab title length; some wiggling was
00166         // required to make this behave in the face of rounding.
00167         int newTabLengthHi = m_maxLength + 1;
00168         int newTabLengthLo = m_minLength;
00169         int prevTabLengthMid = -1;
00170         while (true) {
00171             int newTabLengthMid = (newTabLengthHi + newTabLengthLo) / 2;
00172             if (prevTabLengthMid == newTabLengthMid) {
00173                 // no change, we're stuck due to rounding.
00174                 break;
00175             }
00176             prevTabLengthMid = newTabLengthMid;
00177 
00178             if (m_parent->tabBarWidthForMaxChars(newTabLengthMid) > maxTabBarWidth) {
00179                 newTabLengthHi = newTabLengthMid;
00180             } else {
00181                 newTabLengthLo = newTabLengthMid;
00182             }
00183         }
00184         newTabLength = qMin(newTabLengthLo, m_maxLength);
00185     }
00186 
00187     // Update hinted or all tabs
00188     if (m_currentTabLength != newTabLength) {
00189         m_currentTabLength = newTabLength;
00190         for (int i = 0; i < m_parent->count(); i++) {
00191             updateTab(i);
00192         }
00193     } else if (changeTabIndex != -1) {
00194         updateTab(changeTabIndex);
00195     }
00196 }
00197 
00198 void KTabWidget::Private::updateTab( int index )
00199 {
00200   QString title = m_automaticResizeTabs ? m_tabNames[ index ] : m_parent->QTabWidget::tabText( index );
00201   m_parent->setTabToolTip( index, QString() );
00202 
00203   if ( title.length() > m_currentTabLength ) {
00204     QString toolTipText = title;
00205     // Remove '&'s, which are indicators for keyboard shortcuts in tab titles. "&&" is replaced by '&'.
00206     for ( int i = toolTipText.indexOf( '&' ); i >= 0 && i < toolTipText.length(); i = toolTipText.indexOf( '&', i + 1 ) )
00207       toolTipText.remove( i, 1 );
00208 
00209     if ( Qt::mightBeRichText( toolTipText ) )
00210       m_parent->setTabToolTip( index, Qt::escape( toolTipText ) );
00211     else
00212       m_parent->setTabToolTip( index, toolTipText );
00213   }
00214 
00215   title = KStringHandler::rsqueeze( title, m_currentTabLength ).leftJustified( m_minLength, ' ' );
00216 
00217   if ( m_parent->QTabWidget::tabText( index ) != title )
00218     m_parent->QTabWidget::setTabText( index, title );
00219 }
00220 
00221 KTabWidget::KTabWidget( QWidget *parent, Qt::WFlags flags )
00222   : QTabWidget( parent ),
00223     d( new Private( this ) )
00224 {
00225   setWindowFlags( flags );
00226   setTabBar( new KTabBar( this ) );
00227   setObjectName( "tabbar" );
00228   setAcceptDrops( true );
00229 
00230   connect(tabBar(), SIGNAL(contextMenu( int, const QPoint & )), SLOT(contextMenu( int, const QPoint & )));
00231   connect(tabBar(), SIGNAL(tabDoubleClicked( int )), SLOT(mouseDoubleClick( int )));
00232   connect(tabBar(), SIGNAL(newTabRequest()), this, SIGNAL(mouseDoubleClick())); // #185487
00233   connect(tabBar(), SIGNAL(mouseMiddleClick( int )), SLOT(mouseMiddleClick( int )));
00234   connect(tabBar(), SIGNAL(initiateDrag( int )), SLOT(initiateDrag( int )));
00235   connect(tabBar(), SIGNAL(testCanDecode(const QDragMoveEvent *, bool & )), SIGNAL(testCanDecode(const QDragMoveEvent *, bool & )));
00236   connect(tabBar(), SIGNAL(receivedDropEvent( int, QDropEvent * )), SLOT(receivedDropEvent( int, QDropEvent * )));
00237   connect(tabBar(), SIGNAL(moveTab( int, int )), SLOT(moveTab( int, int )));
00238   connect(tabBar(), SIGNAL(tabCloseRequested( int )), SLOT(closeRequest( int )));
00239 }
00240 
00241 KTabWidget::~KTabWidget()
00242 {
00243   delete d;
00244 }
00245 
00246 /*void KTabWidget::insertTab( QWidget *child, const QString &label, int index )
00247 {
00248   QTabWidget::insertTab( child, label, index );
00249 }
00250 
00251 void KTabWidget::insertTab( QWidget *child, const QIcon& iconset, const QString &label, int index )
00252 {
00253   QTabWidget::insertTab( child, iconset, label, index );
00254 }
00255 
00256 void KTabWidget::insertTab( QWidget *child, QTab *tab, int index )
00257 {
00258   QTabWidget::insertTab( child, tab, index);
00259   if ( d->m_automaticResizeTabs ) {
00260     if ( index < 0 || index >= count() ) {
00261       d->m_tabNames.append( tab->text() );
00262       d->resizeTabs( d->m_tabNames.count()-1 );
00263     }
00264     else {
00265       d->m_tabNames.insert( d->m_tabNames.at( index ), tab->text() );
00266       d->resizeTabs( index );
00267     }
00268   }
00269 }*/
00270 
00271 void KTabWidget::setTabBarHidden( bool hide )
00272 {
00273   if (hide == isTabBarHidden())
00274     return;
00275 
00276   QWidget *rightcorner = cornerWidget( Qt::TopRightCorner );
00277   QWidget *leftcorner = cornerWidget( Qt::TopLeftCorner );
00278 
00279   d->m_tabBarHidden = hide;
00280   if ( hide ) {
00281     if ( leftcorner ) leftcorner->hide();
00282     if ( rightcorner ) rightcorner->hide();
00283     tabBar()->hide();
00284   } else {
00285     tabBar()->show();
00286     if ( leftcorner ) leftcorner->show();
00287     if ( rightcorner ) rightcorner->show();
00288   }
00289 }
00290 
00291 bool KTabWidget::isTabBarHidden() const
00292 {
00293   return d->m_tabBarHidden;
00294 }
00295 
00296 void KTabWidget::setTabTextColor( int index, const QColor& color )
00297 {
00298   tabBar()->setTabTextColor( index, color );
00299 }
00300 
00301 QColor KTabWidget::tabTextColor( int index ) const
00302 {
00303   return tabBar()->tabTextColor( index );
00304 }
00305 
00306 #ifndef KDE_NO_DEPRECATED
00307 void KTabWidget::setTabReorderingEnabled( bool on)
00308 {
00309   static_cast<KTabBar*>(tabBar())->setTabReorderingEnabled( on );
00310 }
00311 #endif
00312 
00313 #ifndef KDE_NO_DEPRECATED
00314 bool KTabWidget::isTabReorderingEnabled() const
00315 {
00316   return static_cast<KTabBar*>(tabBar())->isTabReorderingEnabled();
00317 }
00318 #endif
00319 
00320 #ifndef KDE_NO_DEPRECATED
00321 void KTabWidget::setTabCloseActivatePrevious( bool previous)
00322 {
00323   static_cast<KTabBar*>(tabBar())->setTabCloseActivatePrevious( previous );
00324 }
00325 #endif
00326 
00327 #ifndef KDE_NO_DEPRECATED
00328 bool KTabWidget::tabCloseActivatePrevious() const
00329 {
00330   return static_cast<KTabBar*>(tabBar())->tabCloseActivatePrevious();
00331 }
00332 #endif
00333 
00334 int KTabWidget::tabBarWidthForMaxChars( int maxLength )
00335 {
00336   int hframe, overlap;
00337   hframe  = tabBar()->style()->pixelMetric( QStyle::PM_TabBarTabHSpace, 0L, tabBar() );
00338   overlap = tabBar()->style()->pixelMetric( QStyle::PM_TabBarTabOverlap, 0L, tabBar() );
00339 
00340   const QFontMetrics fm = tabBar()->fontMetrics();
00341   int x = 0;
00342   for ( int i = 0; i < count(); ++i ) {
00343     QString newTitle = d->m_tabNames.value( i );
00344     newTitle = KStringHandler::rsqueeze( newTitle, maxLength ).leftJustified( d->m_minLength, ' ' );
00345 
00346     int lw = fm.width( newTitle );
00347     int iw = 0;
00348     if ( !tabBar()->tabIcon( i ).isNull() ) {
00349       iw = tabBar()->tabIcon( i ).pixmap( style()->pixelMetric( QStyle::PM_SmallIconSize ), QIcon::Normal ).width() + 4;
00350     }
00351 #ifndef KDE_NO_DEPRECATED
00352     if ( isCloseButtonEnabled() ) {
00353       // FIXME: how to get the size of the close button directly from the tabBar()?
00354       iw += KIconLoader::SizeSmall * 3 / 2;
00355     }
00356 #endif
00357     x += ( tabBar()->style()->sizeFromContents( QStyle::CT_TabBarTab, 0L,
00358          QSize( qMax( lw + hframe + iw, QApplication::globalStrut().width() ), 0 ),
00359          this ) ).width();
00360   }
00361 
00362   return x;
00363 }
00364 
00365 QString KTabWidget::tabText( int index ) const
00366 {
00367     if ( d->m_automaticResizeTabs ) {
00368         if (index >= 0 && index < count()) {
00369             if (index >= d->m_tabNames.count()) {
00370                 // Ooops, the tab exists, but tabInserted wasn't called yet.
00371                 // This can happen when inserting the first tab,
00372                 // and calling tabText from slotCurrentChanged,
00373                 // see KTabWidget_UnitTest.
00374                 const_cast<KTabWidget*>(this)->tabInserted(index);
00375             }
00376             return d->m_tabNames[ index ];
00377         }
00378         else
00379             return QString();
00380     }
00381     else
00382         return QTabWidget::tabText( index );
00383 }
00384 
00385 void KTabWidget::setTabText( int index, const QString &text )
00386 {
00387   if (text == tabText(index))
00388     return;
00389 
00390   if ( d->m_automaticResizeTabs ) {
00391 
00392     tabBar()->setUpdatesEnabled(false); //no flicker
00393 
00394     QTabWidget::setTabText( index, text );
00395 
00396     if ( index != -1 ) {
00397         if (index >= d->m_tabNames.count()) {
00398             kWarning(240) << "setTabText(" << index << ") called but d->m_tabNames has only" << d->m_tabNames.count() << "entries";
00399             while (index >= d->m_tabNames.count()) {
00400                 d->m_tabNames.append(QString());
00401             }
00402         }
00403       d->m_tabNames[ index ] = text;
00404       d->resizeTabs( index );
00405     }
00406 
00407     tabBar()->setUpdatesEnabled(true);
00408 
00409   } else {
00410     QTabWidget::setTabText( index, text );
00411   }
00412 }
00413 
00414 
00415 void KTabWidget::dragEnterEvent( QDragEnterEvent *event )
00416 {
00417   if ( d->isEmptyTabbarSpace( event->pos() ) ) {
00418     bool accept = false;
00419     // The receivers of the testCanDecode() signal has to adjust
00420     // 'accept' accordingly.
00421     emit testCanDecode( event, accept);
00422 
00423     event->setAccepted( accept );
00424     return;
00425   }
00426 
00427   QTabWidget::dragEnterEvent( event );
00428 }
00429 
00430 void KTabWidget::dragMoveEvent( QDragMoveEvent *event )
00431 {
00432   if ( d->isEmptyTabbarSpace( event->pos() ) ) {
00433     bool accept = false;
00434     // The receivers of the testCanDecode() signal has to adjust
00435     // 'accept' accordingly.
00436     emit testCanDecode( event, accept);
00437 
00438     event->setAccepted( accept );
00439     return;
00440   }
00441 
00442   QTabWidget::dragMoveEvent( event );
00443 }
00444 
00445 void KTabWidget::dropEvent( QDropEvent *event )
00446 {
00447   if ( d->isEmptyTabbarSpace( event->pos() ) ) {
00448     emit ( receivedDropEvent( event ) );
00449     return;
00450   }
00451 
00452   QTabWidget::dropEvent( event );
00453 }
00454 
00455 #ifndef QT_NO_WHEELEVENT
00456 void KTabWidget::wheelEvent( QWheelEvent *event )
00457 {
00458   if ( d->isEmptyTabbarSpace( event->pos() ) )
00459     QCoreApplication::sendEvent( tabBar(), event );
00460   else
00461     QTabWidget::wheelEvent( event );
00462 }
00463 
00464 void KTabWidget::wheelDelta( int delta )
00465 {
00466   if ( count() < 2 )
00467     return;
00468 
00469   int page = currentIndex();
00470   if ( delta < 0 )
00471      page = (page + 1) % count();
00472   else {
00473     page--;
00474     if ( page < 0 )
00475       page = count() - 1;
00476   }
00477   setCurrentIndex( page );
00478 }
00479 #endif
00480 
00481 void KTabWidget::mouseDoubleClickEvent( QMouseEvent *event )
00482 {
00483   if ( event->button() != Qt::LeftButton )
00484     return;
00485 
00486   if ( d->isEmptyTabbarSpace( event->pos() ) ) {
00487     emit( mouseDoubleClick() );
00488     return;
00489   }
00490 
00491   QTabWidget::mouseDoubleClickEvent( event );
00492 }
00493 
00494 void KTabWidget::mousePressEvent( QMouseEvent *event )
00495 {
00496   if ( event->button() == Qt::RightButton ) {
00497     if ( d->isEmptyTabbarSpace( event->pos() ) ) {
00498       emit( contextMenu( mapToGlobal( event->pos() ) ) );
00499       return;
00500     }
00501   }
00502 
00503   QTabWidget::mousePressEvent( event );
00504 }
00505 
00506 void KTabWidget::mouseReleaseEvent( QMouseEvent *event )
00507 {
00508   if ( event->button() == Qt::MidButton ) {
00509     if ( d->isEmptyTabbarSpace( event->pos() ) ) {
00510       emit( mouseMiddleClick() );
00511       return;
00512     }
00513   }
00514 
00515   QTabWidget::mouseReleaseEvent( event );
00516 }
00517 
00518 void KTabWidget::receivedDropEvent( int index, QDropEvent *event )
00519 {
00520   emit( receivedDropEvent( widget( index ), event ) );
00521 }
00522 
00523 void KTabWidget::initiateDrag( int index )
00524 {
00525   emit( initiateDrag( widget( index ) ) );
00526 }
00527 
00528 void KTabWidget::contextMenu( int index, const QPoint &point )
00529 {
00530   emit( contextMenu( widget( index ), point ) );
00531 }
00532 
00533 void KTabWidget::mouseDoubleClick( int index )
00534 {
00535   emit( mouseDoubleClick( widget( index ) ) );
00536 }
00537 
00538 void KTabWidget::mouseMiddleClick( int index )
00539 {
00540   emit( mouseMiddleClick( widget( index ) ) );
00541 }
00542 
00543 void KTabWidget::moveTab( int from, int to )
00544 {
00545   setUpdatesEnabled(false);
00546 
00547   const QString tablabel = tabText( from );
00548   QWidget *w = widget( from );
00549   const QColor color = tabTextColor( from );
00550   const QIcon tabiconset = tabIcon( from );
00551   const QString tabtooltip = tabToolTip( from );
00552   const bool current = ( from == currentIndex() );
00553   const bool enabled = isTabEnabled( from );
00554 
00555   const bool blocked = blockSignals( true );
00556 
00557   QWidget *fw = QApplication::focusWidget();
00558 
00559   removeTab( from );
00560   insertTab( to, w, tablabel );
00561 
00562   // Don't lose focus due to moving the tab (#159295)
00563   // (removeTab hides the widget, which gives focus to the "next in chain", could be anything)
00564   if (w->isAncestorOf(fw)) {
00565       fw->setFocus();
00566   }
00567 
00568   setTabIcon( to, tabiconset );
00569   setTabText( to, tablabel );
00570   setTabToolTip( to, tabtooltip );
00571   setTabTextColor( to, color );
00572   if ( current )
00573     setCurrentIndex( to );
00574   setTabEnabled( to, enabled );
00575   if ( d->m_automaticResizeTabs ) {
00576     d->resizeTabs( to );
00577   }
00578   blockSignals( blocked );
00579 
00580   setUpdatesEnabled(true);
00581 
00582   emit ( movedTab( from, to ) );
00583 }
00584 
00585 void KTabWidget::removePage( QWidget *widget )
00586 {
00587   // not just calling removeTab() because that one is also virtual.
00588   const int index = indexOf(widget);
00589   if ( d->m_automaticResizeTabs ) {
00590     setUpdatesEnabled(false);
00591     d->removeTab(index);
00592     setUpdatesEnabled(true);
00593   } else {
00594     d->removeTab(index);
00595   }
00596 }
00597 
00598 void KTabWidget::removeTab( int index )
00599 {
00600   if ( d->m_automaticResizeTabs ) {
00601     const bool wasUpdatesEnabled = updatesEnabled();
00602     setUpdatesEnabled(false);
00603     d->removeTab( index );
00604     setUpdatesEnabled(wasUpdatesEnabled);
00605   } else {
00606     d->removeTab( index );
00607   }
00608 }
00609 
00610 #ifndef KDE_NO_DEPRECATED
00611 void KTabWidget::setHoverCloseButton( bool button )
00612 {
00613   // deprecated
00614   setTabsClosable( button );
00615 }
00616 #endif
00617 
00618 #ifndef KDE_NO_DEPRECATED
00619 bool KTabWidget::hoverCloseButton() const
00620 {
00621   // deprecated
00622   return false;
00623 }
00624 #endif
00625 
00626 #ifndef KDE_NO_DEPRECATED
00627 void KTabWidget::setHoverCloseButtonDelayed( bool delayed )
00628 {
00629   // deprecated
00630   Q_UNUSED( delayed );
00631 }
00632 #endif
00633 
00634 #ifndef KDE_NO_DEPRECATED
00635 bool KTabWidget::hoverCloseButtonDelayed() const
00636 {
00637   // deprecated
00638   return tabsClosable();
00639 }
00640 #endif
00641 
00642 #ifndef KDE_NO_DEPRECATED
00643 void KTabWidget::setCloseButtonEnabled( bool enable )
00644 {
00645   static_cast<KTabBar*>( tabBar() )->setTabsClosable( enable );
00646 }
00647 #endif
00648 
00649 #ifndef KDE_NO_DEPRECATED
00650 bool KTabWidget::isCloseButtonEnabled() const
00651 {
00652   return static_cast<KTabBar*>( tabBar() )->tabsClosable();
00653 }
00654 #endif
00655 
00656 void KTabWidget::setAutomaticResizeTabs( bool enabled )
00657 {
00658   if ( d->m_automaticResizeTabs == enabled )
00659     return;
00660 
00661   setUpdatesEnabled(false);
00662 
00663   d->m_automaticResizeTabs = enabled;
00664   if ( enabled ) {
00665     d->m_tabNames.clear();
00666     for ( int i = 0; i < count(); ++i )
00667       d->m_tabNames.append( tabBar()->tabText( i ) );
00668   } else
00669     for ( int i = 0; i < count(); ++i )
00670       tabBar()->setTabText( i, d->m_tabNames[ i ] );
00671 
00672   d->resizeTabs();
00673 
00674   setUpdatesEnabled(true);
00675 }
00676 
00677 bool KTabWidget::automaticResizeTabs() const
00678 {
00679   return d->m_automaticResizeTabs;
00680 }
00681 
00682 void KTabWidget::closeRequest( int index )
00683 {
00684   emit( closeRequest( widget( index ) ) );
00685 }
00686 
00687 void KTabWidget::resizeEvent( QResizeEvent *event )
00688 {
00689   QTabWidget::resizeEvent( event );
00690   d->resizeTabs();
00691 }
00692 
00693 void KTabWidget::tabInserted( int idx )
00694 {
00695    d->m_tabNames.insert( idx, tabBar()->tabText( idx ) );
00696 }
00697 
00698 void KTabWidget::tabRemoved( int idx )
00699 {
00700   Q_UNUSED(idx)
00701 // d->m_tabNames is now updated in KTabWidget::Private::removeTab()
00702 }
00703 
00704 /* This function is kept only for BC reasons, it is not useful anymore */
00705 #ifndef KDE_NO_DEPRECATED
00706 void KTabWidget::currentChanged( int )
00707 {
00708 }
00709 #endif
00710 
00711 #include "ktabwidget.moc"

KDEUI

Skip menu "KDEUI"
  • Main Page
  • Modules
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.7.3
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal