File indexing completed on 2024-04-28 11:36:34
0001 /* This file is part of the KDE libraries 0002 Copyright (C) 2003 Stephan Binner <binner@kde.org> 0003 Copyright (C) 2003 Zack Rusin <zack@kde.org> 0004 Copyright (C) 2009 Urs Wolfer <uwolfer @ kde.org> 0005 0006 This library is free software; you can redistribute it and/or 0007 modify it under the terms of the GNU Library General Public 0008 License as published by the Free Software Foundation; either 0009 version 2 of the License, or (at your option) any later version. 0010 0011 This library is distributed in the hope that it will be useful, 0012 but WITHOUT ANY WARRANTY; without even the implied warranty of 0013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0014 Library General Public License for more details. 0015 0016 You should have received a copy of the GNU Library General Public License 0017 along with this library; see the file COPYING.LIB. If not, write to 0018 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0019 Boston, MA 02110-1301, USA. 0020 */ 0021 0022 #include "ktabwidget.h" 0023 0024 #include <QApplication> 0025 #include <QDragMoveEvent> 0026 #include <QDropEvent> 0027 #include <QMouseEvent> 0028 #include <QStyle> 0029 #include <QStyleOption> 0030 #include <QTextDocument> 0031 #include <QWheelEvent> 0032 #include <QList> 0033 0034 #include <ksharedconfig.h> 0035 #include <kiconloader.h> 0036 #include <kstringhandler.h> 0037 #include <kdebug.h> 0038 0039 #include <ktabbar.h> 0040 0041 #include <kconfiggroup.h> 0042 0043 class Q_DECL_HIDDEN KTabWidget::Private 0044 { 0045 public: 0046 enum { 0047 ResizeEnabled = 0, 0048 ResizeDisabled, 0049 ResizeLater 0050 } m_resizeSuspend; 0051 0052 Private(KTabWidget *parent) 0053 : m_resizeSuspend(ResizeEnabled), 0054 m_parent(parent), 0055 m_automaticResizeTabs(false), 0056 m_tabBarHidden(false) 0057 { 0058 0059 KConfigGroup cg(KSharedConfig::openConfig(), "General"); 0060 m_maxLength = cg.readEntry("MaximumTabLength", 30); 0061 m_minLength = cg.readEntry("MinimumTabLength", 3); 0062 Q_ASSERT(m_maxLength >= m_minLength); 0063 m_currentTabLength = m_minLength; 0064 } 0065 0066 KTabWidget *m_parent; 0067 bool m_automaticResizeTabs; 0068 bool m_tabBarHidden; 0069 int m_maxLength; 0070 int m_minLength; 0071 int m_currentTabLength; 0072 0073 //holds the full names of the tab, otherwise all we 0074 //know about is the shortened name 0075 QStringList m_tabNames; 0076 0077 bool isEmptyTabbarSpace(const QPoint &) const; 0078 void resizeTabs(int changedTabIndex = -1); 0079 void updateTab(int index); 0080 void removeTab(int index); 0081 0082 void slotTabMoved(int from, int to); 0083 }; 0084 0085 bool KTabWidget::Private::isEmptyTabbarSpace(const QPoint &point) const 0086 { 0087 if (m_parent->count() == 0) { 0088 return true; 0089 } 0090 if (m_parent->tabBar()->isHidden()) { 0091 return false; 0092 } 0093 QSize size(m_parent->tabBar()->sizeHint()); 0094 if ((m_parent->tabPosition() == QTabWidget::North && point.y() < size.height()) || 0095 (m_parent->tabPosition() == QTabWidget::South && point.y() > (m_parent->height() - size.height()))) { 0096 0097 QWidget *rightcorner = m_parent->cornerWidget(Qt::TopRightCorner); 0098 if (rightcorner && rightcorner->isVisible()) { 0099 if (point.x() >= m_parent->width() - rightcorner->width()) { 0100 return false; 0101 } 0102 } 0103 0104 QWidget *leftcorner = m_parent->cornerWidget(Qt::TopLeftCorner); 0105 if (leftcorner && leftcorner->isVisible()) { 0106 if (point.x() <= leftcorner->width()) { 0107 return false; 0108 } 0109 } 0110 0111 for (int i = 0; i < m_parent->count(); ++i) 0112 if (m_parent->tabBar()->tabRect(i).contains(m_parent->tabBar()->mapFromParent(point))) { 0113 return false; 0114 } 0115 0116 return true; 0117 } 0118 0119 return false; 0120 } 0121 0122 void KTabWidget::Private::removeTab(int index) 0123 { 0124 // prevent cascading resize slowness, not to mention crashes due to tab count() 0125 // and m_tabNames.count() being out of sync! 0126 m_resizeSuspend = ResizeDisabled; 0127 0128 // Need to do this here, rather than in tabRemoved(). Calling 0129 // QTabWidget::removeTab() below may cause a relayout of the tab bar, which 0130 // will call resizeTabs() immediately. If m_automaticResizeTabs is true, 0131 // that will use the m_tabNames[] list before it has been updated to reflect 0132 // the new tab arrangement. See bug 190528. 0133 m_tabNames.removeAt(index); 0134 0135 m_parent->QTabWidget::removeTab(index); 0136 0137 const bool doResize = (m_resizeSuspend == ResizeLater) || m_automaticResizeTabs; 0138 m_resizeSuspend = ResizeEnabled; 0139 if (doResize) { 0140 resizeTabs(); 0141 } 0142 0143 } 0144 0145 void KTabWidget::Private::resizeTabs(int changeTabIndex) 0146 { 0147 if (m_resizeSuspend != ResizeEnabled) { 0148 m_resizeSuspend = ResizeLater; 0149 return; 0150 } 0151 0152 int newTabLength = m_maxLength; 0153 0154 if (m_automaticResizeTabs) { 0155 // Calculate new max length 0156 int lcw = 0, rcw = 0; 0157 0158 const int tabBarHeight = m_parent->tabBar()->sizeHint().height(); 0159 if (m_parent->cornerWidget(Qt::TopLeftCorner) && 0160 m_parent->cornerWidget(Qt::TopLeftCorner)->isVisible()) { 0161 lcw = qMax(m_parent->cornerWidget(Qt::TopLeftCorner)->width(), tabBarHeight); 0162 } 0163 if (m_parent->cornerWidget(Qt::TopRightCorner) && 0164 m_parent->cornerWidget(Qt::TopRightCorner)->isVisible()) { 0165 rcw = qMax(m_parent->cornerWidget(Qt::TopRightCorner)->width(), tabBarHeight); 0166 } 0167 0168 const int maxTabBarWidth = m_parent->width() - lcw - rcw; 0169 0170 // binary search for the best fitting tab title length; some wiggling was 0171 // required to make this behave in the face of rounding. 0172 int newTabLengthHi = m_maxLength + 1; 0173 int newTabLengthLo = m_minLength; 0174 int prevTabLengthMid = -1; 0175 while (true) { 0176 int newTabLengthMid = (newTabLengthHi + newTabLengthLo) / 2; 0177 if (prevTabLengthMid == newTabLengthMid) { 0178 // no change, we're stuck due to rounding. 0179 break; 0180 } 0181 prevTabLengthMid = newTabLengthMid; 0182 0183 if (m_parent->tabBarWidthForMaxChars(newTabLengthMid) > maxTabBarWidth) { 0184 newTabLengthHi = newTabLengthMid; 0185 } else { 0186 newTabLengthLo = newTabLengthMid; 0187 } 0188 } 0189 newTabLength = qMin(newTabLengthLo, m_maxLength); 0190 } 0191 0192 // Update hinted or all tabs 0193 if (m_currentTabLength != newTabLength) { 0194 m_currentTabLength = newTabLength; 0195 for (int i = 0; i < m_parent->count(); i++) { 0196 updateTab(i); 0197 } 0198 } else if (changeTabIndex != -1) { 0199 updateTab(changeTabIndex); 0200 } 0201 } 0202 0203 void KTabWidget::Private::updateTab(int index) 0204 { 0205 QString title = m_automaticResizeTabs ? m_tabNames[ index ] : m_parent->QTabWidget::tabText(index); 0206 m_parent->setTabToolTip(index, QString()); 0207 0208 if (title.length() > m_currentTabLength) { 0209 QString toolTipText = title; 0210 // Remove '&'s, which are indicators for keyboard shortcuts in tab titles. "&&" is replaced by '&'. 0211 for (int i = toolTipText.indexOf('&'); i >= 0 && i < toolTipText.length(); i = toolTipText.indexOf('&', i + 1)) { 0212 toolTipText.remove(i, 1); 0213 } 0214 0215 if (Qt::mightBeRichText(toolTipText)) { 0216 m_parent->setTabToolTip(index, toolTipText.toHtmlEscaped()); 0217 } else { 0218 m_parent->setTabToolTip(index, toolTipText); 0219 } 0220 } 0221 0222 title = KStringHandler::rsqueeze(title, m_currentTabLength).leftJustified(m_minLength, ' '); 0223 0224 if (m_parent->QTabWidget::tabText(index) != title) { 0225 m_parent->QTabWidget::setTabText(index, title); 0226 } 0227 } 0228 0229 void KTabWidget::Private::slotTabMoved(int from, int to) 0230 { 0231 /* called from Qt slot when Qt has moved the tab, so we only 0232 need to adjust the m_tabNames list */ 0233 if (m_automaticResizeTabs) { 0234 QString movedName = m_tabNames.takeAt(from); 0235 m_tabNames.insert(to, movedName); 0236 } 0237 } 0238 0239 KTabWidget::KTabWidget(QWidget *parent, Qt::WindowFlags flags) 0240 : QTabWidget(parent), 0241 d(new Private(this)) 0242 { 0243 setWindowFlags(flags); 0244 setTabBar(new KTabBar(this)); 0245 setObjectName("tabbar"); 0246 setAcceptDrops(true); 0247 0248 connect(tabBar(), SIGNAL(contextMenu(int,QPoint)), SLOT(contextMenu(int,QPoint))); 0249 connect(tabBar(), SIGNAL(tabDoubleClicked(int)), SLOT(mouseDoubleClick(int))); 0250 connect(tabBar(), SIGNAL(newTabRequest()), this, SIGNAL(mouseDoubleClick())); // #185487 0251 connect(tabBar(), SIGNAL(mouseMiddleClick(int)), SLOT(mouseMiddleClick(int))); 0252 connect(tabBar(), SIGNAL(initiateDrag(int)), SLOT(initiateDrag(int))); 0253 connect(tabBar(), SIGNAL(testCanDecode(const QDragMoveEvent*,bool&)), SIGNAL(testCanDecode(const QDragMoveEvent*,bool&))); 0254 connect(tabBar(), SIGNAL(receivedDropEvent(int,QDropEvent*)), SLOT(receivedDropEvent(int,QDropEvent*))); 0255 connect(tabBar(), SIGNAL(moveTab(int,int)), SLOT(moveTab(int,int))); 0256 connect(tabBar(), SIGNAL(tabMoved(int,int)), SLOT(slotTabMoved(int,int))); 0257 connect(tabBar(), SIGNAL(tabCloseRequested(int)), SLOT(closeRequest(int))); 0258 } 0259 0260 KTabWidget::~KTabWidget() 0261 { 0262 delete d; 0263 } 0264 0265 /*void KTabWidget::insertTab( QWidget *child, const QString &label, int index ) 0266 { 0267 QTabWidget::insertTab( child, label, index ); 0268 } 0269 0270 void KTabWidget::insertTab( QWidget *child, const QIcon& iconset, const QString &label, int index ) 0271 { 0272 QTabWidget::insertTab( child, iconset, label, index ); 0273 } 0274 0275 void KTabWidget::insertTab( QWidget *child, QTab *tab, int index ) 0276 { 0277 QTabWidget::insertTab( child, tab, index); 0278 if ( d->m_automaticResizeTabs ) { 0279 if ( index < 0 || index >= count() ) { 0280 d->m_tabNames.append( tab->text() ); 0281 d->resizeTabs( d->m_tabNames.count()-1 ); 0282 } 0283 else { 0284 d->m_tabNames.insert( d->m_tabNames.at( index ), tab->text() ); 0285 d->resizeTabs( index ); 0286 } 0287 } 0288 }*/ 0289 0290 void KTabWidget::setTabBarHidden(bool hide) 0291 { 0292 if (hide == isTabBarHidden()) { 0293 return; 0294 } 0295 0296 QWidget *rightcorner = cornerWidget(Qt::TopRightCorner); 0297 QWidget *leftcorner = cornerWidget(Qt::TopLeftCorner); 0298 0299 d->m_tabBarHidden = hide; 0300 if (hide) { 0301 if (leftcorner) { 0302 leftcorner->hide(); 0303 } 0304 if (rightcorner) { 0305 rightcorner->hide(); 0306 } 0307 tabBar()->hide(); 0308 } else { 0309 tabBar()->show(); 0310 if (leftcorner) { 0311 leftcorner->show(); 0312 } 0313 if (rightcorner) { 0314 rightcorner->show(); 0315 } 0316 } 0317 } 0318 0319 bool KTabWidget::isTabBarHidden() const 0320 { 0321 return d->m_tabBarHidden; 0322 } 0323 0324 void KTabWidget::setTabTextColor(int index, const QColor &color) 0325 { 0326 tabBar()->setTabTextColor(index, color); 0327 } 0328 0329 QColor KTabWidget::tabTextColor(int index) const 0330 { 0331 return tabBar()->tabTextColor(index); 0332 } 0333 0334 #ifndef KDELIBS4SUPPORT_NO_DEPRECATED 0335 void KTabWidget::setTabReorderingEnabled(bool on) 0336 { 0337 static_cast<KTabBar *>(tabBar())->setTabReorderingEnabled(on); 0338 } 0339 #endif 0340 0341 #ifndef KDELIBS4SUPPORT_NO_DEPRECATED 0342 bool KTabWidget::isTabReorderingEnabled() const 0343 { 0344 return static_cast<KTabBar *>(tabBar())->isTabReorderingEnabled(); 0345 } 0346 #endif 0347 0348 #ifndef KDELIBS4SUPPORT_NO_DEPRECATED 0349 void KTabWidget::setTabCloseActivatePrevious(bool previous) 0350 { 0351 static_cast<KTabBar *>(tabBar())->setTabCloseActivatePrevious(previous); 0352 } 0353 #endif 0354 0355 #ifndef KDELIBS4SUPPORT_NO_DEPRECATED 0356 bool KTabWidget::tabCloseActivatePrevious() const 0357 { 0358 return static_cast<KTabBar *>(tabBar())->tabCloseActivatePrevious(); 0359 } 0360 #endif 0361 0362 int KTabWidget::tabBarWidthForMaxChars(int maxLength) 0363 { 0364 const int hframe = tabBar()->style()->pixelMetric(QStyle::PM_TabBarTabHSpace, nullptr, tabBar()); 0365 0366 const QFontMetrics fm = tabBar()->fontMetrics(); 0367 int x = 0; 0368 for (int i = 0; i < count(); ++i) { 0369 QString newTitle = d->m_tabNames.value(i); 0370 newTitle = KStringHandler::rsqueeze(newTitle, maxLength).leftJustified(d->m_minLength, ' '); 0371 0372 int lw = fm.width(newTitle); 0373 int iw = 0; 0374 if (!tabBar()->tabIcon(i).isNull()) { 0375 iw = tabBar()->tabIcon(i).pixmap(style()->pixelMetric(QStyle::PM_SmallIconSize), QIcon::Normal).width() + 4; 0376 } 0377 #ifndef KDELIBS4SUPPORT_NO_DEPRECATED 0378 if (isCloseButtonEnabled()) { 0379 // FIXME: how to get the size of the close button directly from the tabBar()? 0380 iw += KIconLoader::SizeSmall * 3 / 2; 0381 } 0382 #endif 0383 x += (tabBar()->style()->sizeFromContents(QStyle::CT_TabBarTab, nullptr, 0384 QSize(qMax(lw + hframe + iw, QApplication::globalStrut().width()), 0), 0385 this)).width(); 0386 } 0387 0388 return x; 0389 } 0390 0391 QString KTabWidget::tabText(int index) const 0392 { 0393 if (d->m_automaticResizeTabs) { 0394 if (index >= 0 && index < count()) { 0395 if (index >= d->m_tabNames.count()) { 0396 // Ooops, the tab exists, but tabInserted wasn't called yet. 0397 // This can happen when inserting the first tab, 0398 // and calling tabText from slotCurrentChanged, 0399 // see KTabWidget_UnitTest. 0400 const_cast<KTabWidget *>(this)->tabInserted(index); 0401 } 0402 return d->m_tabNames[ index ]; 0403 } else { 0404 return QString(); 0405 } 0406 } else { 0407 return QTabWidget::tabText(index); 0408 } 0409 } 0410 0411 void KTabWidget::setTabText(int index, const QString &text) 0412 { 0413 if (text == tabText(index)) { 0414 return; 0415 } 0416 0417 if (d->m_automaticResizeTabs) { 0418 0419 tabBar()->setUpdatesEnabled(false); //no flicker 0420 0421 QTabWidget::setTabText(index, text); 0422 0423 if (index != -1) { 0424 if (index >= d->m_tabNames.count()) { 0425 kWarning(240) << "setTabText(" << index << ") called but d->m_tabNames has only" << d->m_tabNames.count() << "entries"; 0426 while (index >= d->m_tabNames.count()) { 0427 d->m_tabNames.append(QString()); 0428 } 0429 } 0430 d->m_tabNames[ index ] = text; 0431 d->resizeTabs(index); 0432 } 0433 0434 tabBar()->setUpdatesEnabled(true); 0435 0436 } else { 0437 QTabWidget::setTabText(index, text); 0438 } 0439 } 0440 0441 void KTabWidget::dragEnterEvent(QDragEnterEvent *event) 0442 { 0443 if (d->isEmptyTabbarSpace(event->pos())) { 0444 bool accept = false; 0445 // The receivers of the testCanDecode() signal has to adjust 0446 // 'accept' accordingly. 0447 emit testCanDecode(event, accept); 0448 0449 event->setAccepted(accept); 0450 return; 0451 } 0452 0453 QTabWidget::dragEnterEvent(event); 0454 } 0455 0456 void KTabWidget::dragMoveEvent(QDragMoveEvent *event) 0457 { 0458 if (d->isEmptyTabbarSpace(event->pos())) { 0459 bool accept = false; 0460 // The receivers of the testCanDecode() signal has to adjust 0461 // 'accept' accordingly. 0462 emit testCanDecode(event, accept); 0463 0464 event->setAccepted(accept); 0465 return; 0466 } 0467 0468 QTabWidget::dragMoveEvent(event); 0469 } 0470 0471 void KTabWidget::dropEvent(QDropEvent *event) 0472 { 0473 if (d->isEmptyTabbarSpace(event->pos())) { 0474 emit(receivedDropEvent(event)); 0475 return; 0476 } 0477 0478 QTabWidget::dropEvent(event); 0479 } 0480 0481 #ifndef QT_NO_WHEELEVENT 0482 void KTabWidget::wheelEvent(QWheelEvent *event) 0483 { 0484 if (d->isEmptyTabbarSpace(event->pos())) { 0485 QCoreApplication::sendEvent(tabBar(), event); 0486 } else { 0487 QTabWidget::wheelEvent(event); 0488 } 0489 } 0490 0491 void KTabWidget::wheelDelta(int delta) 0492 { 0493 if (count() < 2) { 0494 return; 0495 } 0496 0497 int page = currentIndex(); 0498 if (delta < 0) { 0499 page = (page + 1) % count(); 0500 } else { 0501 page--; 0502 if (page < 0) { 0503 page = count() - 1; 0504 } 0505 } 0506 setCurrentIndex(page); 0507 } 0508 #endif 0509 0510 void KTabWidget::mouseDoubleClickEvent(QMouseEvent *event) 0511 { 0512 if (event->button() != Qt::LeftButton) { 0513 return; 0514 } 0515 0516 if (d->isEmptyTabbarSpace(event->pos())) { 0517 emit(mouseDoubleClick()); 0518 return; 0519 } 0520 0521 QTabWidget::mouseDoubleClickEvent(event); 0522 } 0523 0524 void KTabWidget::mousePressEvent(QMouseEvent *event) 0525 { 0526 if (event->button() == Qt::RightButton) { 0527 if (d->isEmptyTabbarSpace(event->pos())) { 0528 emit(contextMenu(mapToGlobal(event->pos()))); 0529 return; 0530 } 0531 } 0532 0533 QTabWidget::mousePressEvent(event); 0534 } 0535 0536 void KTabWidget::mouseReleaseEvent(QMouseEvent *event) 0537 { 0538 if (event->button() == Qt::MidButton) { 0539 if (d->isEmptyTabbarSpace(event->pos())) { 0540 emit(mouseMiddleClick()); 0541 return; 0542 } 0543 } 0544 0545 QTabWidget::mouseReleaseEvent(event); 0546 } 0547 0548 void KTabWidget::receivedDropEvent(int index, QDropEvent *event) 0549 { 0550 emit(receivedDropEvent(widget(index), event)); 0551 } 0552 0553 void KTabWidget::initiateDrag(int index) 0554 { 0555 emit(initiateDrag(widget(index))); 0556 } 0557 0558 void KTabWidget::contextMenu(int index, const QPoint &point) 0559 { 0560 emit(contextMenu(widget(index), point)); 0561 } 0562 0563 void KTabWidget::mouseDoubleClick(int index) 0564 { 0565 emit(mouseDoubleClick(widget(index))); 0566 } 0567 0568 void KTabWidget::mouseMiddleClick(int index) 0569 { 0570 emit(mouseMiddleClick(widget(index))); 0571 } 0572 0573 void KTabWidget::moveTab(int from, int to) 0574 { 0575 setUpdatesEnabled(false); 0576 0577 const QString tablabel = tabText(from); 0578 QWidget *w = widget(from); 0579 const QColor color = tabTextColor(from); 0580 const QIcon tabiconset = tabIcon(from); 0581 const QString tabtooltip = tabToolTip(from); 0582 const bool current = (from == currentIndex()); 0583 const bool enabled = isTabEnabled(from); 0584 0585 const bool blocked = blockSignals(true); 0586 0587 QWidget *fw = QApplication::focusWidget(); 0588 0589 removeTab(from); 0590 insertTab(to, w, tablabel); 0591 0592 // Don't lose focus due to moving the tab (#159295) 0593 // (removeTab hides the widget, which gives focus to the "next in chain", could be anything) 0594 if (w->isAncestorOf(fw)) { 0595 fw->setFocus(); 0596 } 0597 0598 setTabIcon(to, tabiconset); 0599 setTabText(to, tablabel); 0600 setTabToolTip(to, tabtooltip); 0601 setTabTextColor(to, color); 0602 if (current) { 0603 setCurrentIndex(to); 0604 } 0605 setTabEnabled(to, enabled); 0606 if (d->m_automaticResizeTabs) { 0607 d->resizeTabs(to); 0608 } 0609 blockSignals(blocked); 0610 0611 setUpdatesEnabled(true); 0612 0613 #ifndef KDELIBS4SUPPORT_NO_DEPRECATED 0614 emit(movedTab(from, to)); 0615 #endif 0616 } 0617 0618 void KTabWidget::removePage(QWidget *widget) 0619 { 0620 // not just calling removeTab() because that one is also virtual. 0621 const int index = indexOf(widget); 0622 if (d->m_automaticResizeTabs) { 0623 setUpdatesEnabled(false); 0624 d->removeTab(index); 0625 setUpdatesEnabled(true); 0626 } else { 0627 d->removeTab(index); 0628 } 0629 } 0630 0631 void KTabWidget::removeTab(int index) 0632 { 0633 if (d->m_automaticResizeTabs) { 0634 const bool wasUpdatesEnabled = updatesEnabled(); 0635 setUpdatesEnabled(false); 0636 d->removeTab(index); 0637 setUpdatesEnabled(wasUpdatesEnabled); 0638 } else { 0639 d->removeTab(index); 0640 } 0641 } 0642 0643 #ifndef KDELIBS4SUPPORT_NO_DEPRECATED 0644 void KTabWidget::setHoverCloseButton(bool button) 0645 { 0646 // deprecated 0647 setTabsClosable(button); 0648 } 0649 #endif 0650 0651 #ifndef KDELIBS4SUPPORT_NO_DEPRECATED 0652 bool KTabWidget::hoverCloseButton() const 0653 { 0654 // deprecated 0655 return false; 0656 } 0657 #endif 0658 0659 #ifndef KDELIBS4SUPPORT_NO_DEPRECATED 0660 void KTabWidget::setHoverCloseButtonDelayed(bool delayed) 0661 { 0662 // deprecated 0663 Q_UNUSED(delayed); 0664 } 0665 #endif 0666 0667 #ifndef KDELIBS4SUPPORT_NO_DEPRECATED 0668 bool KTabWidget::hoverCloseButtonDelayed() const 0669 { 0670 // deprecated 0671 return tabsClosable(); 0672 } 0673 #endif 0674 0675 #ifndef KDELIBS4SUPPORT_NO_DEPRECATED 0676 void KTabWidget::setCloseButtonEnabled(bool enable) 0677 { 0678 static_cast<KTabBar *>(tabBar())->setTabsClosable(enable); 0679 } 0680 #endif 0681 0682 #ifndef KDELIBS4SUPPORT_NO_DEPRECATED 0683 bool KTabWidget::isCloseButtonEnabled() const 0684 { 0685 return static_cast<KTabBar *>(tabBar())->tabsClosable(); 0686 } 0687 #endif 0688 0689 void KTabWidget::setAutomaticResizeTabs(bool enabled) 0690 { 0691 if (d->m_automaticResizeTabs == enabled) { 0692 return; 0693 } 0694 0695 setUpdatesEnabled(false); 0696 0697 d->m_automaticResizeTabs = enabled; 0698 if (enabled) { 0699 d->m_tabNames.clear(); 0700 for (int i = 0; i < count(); ++i) { 0701 d->m_tabNames.append(tabBar()->tabText(i)); 0702 } 0703 } else 0704 for (int i = 0; i < count(); ++i) { 0705 tabBar()->setTabText(i, d->m_tabNames[ i ]); 0706 } 0707 0708 d->resizeTabs(); 0709 0710 setUpdatesEnabled(true); 0711 } 0712 0713 bool KTabWidget::automaticResizeTabs() const 0714 { 0715 return d->m_automaticResizeTabs; 0716 } 0717 0718 void KTabWidget::closeRequest(int index) 0719 { 0720 emit(closeRequest(widget(index))); 0721 } 0722 0723 void KTabWidget::resizeEvent(QResizeEvent *event) 0724 { 0725 QTabWidget::resizeEvent(event); 0726 d->resizeTabs(); 0727 } 0728 0729 void KTabWidget::tabInserted(int idx) 0730 { 0731 d->m_tabNames.insert(idx, tabBar()->tabText(idx)); 0732 } 0733 0734 void KTabWidget::tabRemoved(int idx) 0735 { 0736 Q_UNUSED(idx) 0737 // d->m_tabNames is now updated in KTabWidget::Private::removeTab() 0738 } 0739 0740 /* This function is kept only for BC reasons, it is not useful anymore */ 0741 #ifndef KDELIBS4SUPPORT_NO_DEPRECATED 0742 void KTabWidget::currentChanged(int) 0743 { 0744 } 0745 #endif 0746 0747 #include "moc_ktabwidget.cpp"