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

KDE's Doxygen guidelines are available online.

KDEUI

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

kdelibs-4.8.3 API Reference

Skip menu "kdelibs-4.8.3 API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • 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
Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal