| Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/widgets/widgets/qtabbar.cpp |
| Source code | Switch to Preprocessed file |
| Line | Source | Count | ||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | /**************************************************************************** | - | ||||||||||||||||||||||||||||||
| 2 | ** | - | ||||||||||||||||||||||||||||||
| 3 | ** Copyright (C) 2015 The Qt Company Ltd. | - | ||||||||||||||||||||||||||||||
| 4 | ** Contact: http://www.qt.io/licensing/ | - | ||||||||||||||||||||||||||||||
| 5 | ** | - | ||||||||||||||||||||||||||||||
| 6 | ** This file is part of the QtWidgets module of the Qt Toolkit. | - | ||||||||||||||||||||||||||||||
| 7 | ** | - | ||||||||||||||||||||||||||||||
| 8 | ** $QT_BEGIN_LICENSE:LGPL21$ | - | ||||||||||||||||||||||||||||||
| 9 | ** Commercial License Usage | - | ||||||||||||||||||||||||||||||
| 10 | ** Licensees holding valid commercial Qt licenses may use this file in | - | ||||||||||||||||||||||||||||||
| 11 | ** accordance with the commercial license agreement provided with the | - | ||||||||||||||||||||||||||||||
| 12 | ** Software or, alternatively, in accordance with the terms contained in | - | ||||||||||||||||||||||||||||||
| 13 | ** a written agreement between you and The Qt Company. For licensing terms | - | ||||||||||||||||||||||||||||||
| 14 | ** and conditions see http://www.qt.io/terms-conditions. For further | - | ||||||||||||||||||||||||||||||
| 15 | ** information use the contact form at http://www.qt.io/contact-us. | - | ||||||||||||||||||||||||||||||
| 16 | ** | - | ||||||||||||||||||||||||||||||
| 17 | ** GNU Lesser General Public License Usage | - | ||||||||||||||||||||||||||||||
| 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser | - | ||||||||||||||||||||||||||||||
| 19 | ** General Public License version 2.1 or version 3 as published by the Free | - | ||||||||||||||||||||||||||||||
| 20 | ** Software Foundation and appearing in the file LICENSE.LGPLv21 and | - | ||||||||||||||||||||||||||||||
| 21 | ** LICENSE.LGPLv3 included in the packaging of this file. Please review the | - | ||||||||||||||||||||||||||||||
| 22 | ** following information to ensure the GNU Lesser General Public License | - | ||||||||||||||||||||||||||||||
| 23 | ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and | - | ||||||||||||||||||||||||||||||
| 24 | ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | - | ||||||||||||||||||||||||||||||
| 25 | ** | - | ||||||||||||||||||||||||||||||
| 26 | ** As a special exception, The Qt Company gives you certain additional | - | ||||||||||||||||||||||||||||||
| 27 | ** rights. These rights are described in The Qt Company LGPL Exception | - | ||||||||||||||||||||||||||||||
| 28 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | - | ||||||||||||||||||||||||||||||
| 29 | ** | - | ||||||||||||||||||||||||||||||
| 30 | ** $QT_END_LICENSE$ | - | ||||||||||||||||||||||||||||||
| 31 | ** | - | ||||||||||||||||||||||||||||||
| 32 | ****************************************************************************/ | - | ||||||||||||||||||||||||||||||
| 33 | - | |||||||||||||||||||||||||||||||
| 34 | #include "private/qlayoutengine_p.h" | - | ||||||||||||||||||||||||||||||
| 35 | #include "qabstractitemdelegate.h" | - | ||||||||||||||||||||||||||||||
| 36 | #include "qapplication.h" | - | ||||||||||||||||||||||||||||||
| 37 | #include "qbitmap.h" | - | ||||||||||||||||||||||||||||||
| 38 | #include "qcursor.h" | - | ||||||||||||||||||||||||||||||
| 39 | #include "qevent.h" | - | ||||||||||||||||||||||||||||||
| 40 | #include "qpainter.h" | - | ||||||||||||||||||||||||||||||
| 41 | #include "qstyle.h" | - | ||||||||||||||||||||||||||||||
| 42 | #include "qstyleoption.h" | - | ||||||||||||||||||||||||||||||
| 43 | #include "qstylepainter.h" | - | ||||||||||||||||||||||||||||||
| 44 | #include "qtabwidget.h" | - | ||||||||||||||||||||||||||||||
| 45 | #include "qtooltip.h" | - | ||||||||||||||||||||||||||||||
| 46 | #include "qwhatsthis.h" | - | ||||||||||||||||||||||||||||||
| 47 | #include "private/qtextengine_p.h" | - | ||||||||||||||||||||||||||||||
| 48 | #ifndef QT_NO_ACCESSIBILITY | - | ||||||||||||||||||||||||||||||
| 49 | #include "qaccessible.h" | - | ||||||||||||||||||||||||||||||
| 50 | #endif | - | ||||||||||||||||||||||||||||||
| 51 | #ifdef Q_OS_OSX | - | ||||||||||||||||||||||||||||||
| 52 | #include <qpa/qplatformnativeinterface.h> | - | ||||||||||||||||||||||||||||||
| 53 | #endif | - | ||||||||||||||||||||||||||||||
| 54 | - | |||||||||||||||||||||||||||||||
| 55 | #include "qdebug.h" | - | ||||||||||||||||||||||||||||||
| 56 | #include "private/qtabbar_p.h" | - | ||||||||||||||||||||||||||||||
| 57 | - | |||||||||||||||||||||||||||||||
| 58 | #ifndef QT_NO_TABBAR | - | ||||||||||||||||||||||||||||||
| 59 | - | |||||||||||||||||||||||||||||||
| 60 | #ifdef Q_DEAD_CODE_FROM_QT4_MAC | - | ||||||||||||||||||||||||||||||
| 61 | #include <private/qt_mac_p.h> | - | ||||||||||||||||||||||||||||||
| 62 | #include <private/qt_cocoa_helpers_mac_p.h> | - | ||||||||||||||||||||||||||||||
| 63 | #endif | - | ||||||||||||||||||||||||||||||
| 64 | - | |||||||||||||||||||||||||||||||
| 65 | QT_BEGIN_NAMESPACE | - | ||||||||||||||||||||||||||||||
| 66 | - | |||||||||||||||||||||||||||||||
| 67 | QMovableTabWidget::QMovableTabWidget(QWidget *parent) | - | ||||||||||||||||||||||||||||||
| 68 | : QWidget(parent) | - | ||||||||||||||||||||||||||||||
| 69 | { | - | ||||||||||||||||||||||||||||||
| 70 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
| 71 | - | |||||||||||||||||||||||||||||||
| 72 | void QMovableTabWidget::setPixmap(const QPixmap &pixmap) | - | ||||||||||||||||||||||||||||||
| 73 | { | - | ||||||||||||||||||||||||||||||
| 74 | m_pixmap = pixmap; | - | ||||||||||||||||||||||||||||||
| 75 | update(); | - | ||||||||||||||||||||||||||||||
| 76 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
| 77 | - | |||||||||||||||||||||||||||||||
| 78 | void QMovableTabWidget::paintEvent(QPaintEvent *e) | - | ||||||||||||||||||||||||||||||
| 79 | { | - | ||||||||||||||||||||||||||||||
| 80 | Q_UNUSED(e); | - | ||||||||||||||||||||||||||||||
| 81 | QPainter p(this); | - | ||||||||||||||||||||||||||||||
| 82 | p.drawPixmap(0, 0, m_pixmap); | - | ||||||||||||||||||||||||||||||
| 83 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
| 84 | - | |||||||||||||||||||||||||||||||
| 85 | inline static bool verticalTabs(QTabBar::Shape shape) | - | ||||||||||||||||||||||||||||||
| 86 | { | - | ||||||||||||||||||||||||||||||
| 87 | return shape == QTabBar::RoundedWest never executed: return shape == QTabBar::RoundedWest || shape == QTabBar::RoundedEast || shape == QTabBar::TriangularWest || shape == QTabBar::TriangularEast;
| 0 | ||||||||||||||||||||||||||||||
| 88 | || shape == QTabBar::RoundedEast never executed: return shape == QTabBar::RoundedWest || shape == QTabBar::RoundedEast || shape == QTabBar::TriangularWest || shape == QTabBar::TriangularEast;
| 0 | ||||||||||||||||||||||||||||||
| 89 | || shape == QTabBar::TriangularWest never executed: return shape == QTabBar::RoundedWest || shape == QTabBar::RoundedEast || shape == QTabBar::TriangularWest || shape == QTabBar::TriangularEast;
| 0 | ||||||||||||||||||||||||||||||
| 90 | || shape == QTabBar::TriangularEast; never executed: return shape == QTabBar::RoundedWest || shape == QTabBar::RoundedEast || shape == QTabBar::TriangularWest || shape == QTabBar::TriangularEast;
| 0 | ||||||||||||||||||||||||||||||
| 91 | } | - | ||||||||||||||||||||||||||||||
| 92 | - | |||||||||||||||||||||||||||||||
| 93 | void QTabBarPrivate::updateMacBorderMetrics() | - | ||||||||||||||||||||||||||||||
| 94 | { | - | ||||||||||||||||||||||||||||||
| 95 | #if defined(Q_OS_OSX) | - | ||||||||||||||||||||||||||||||
| 96 | Q_Q(QTabBar); | - | ||||||||||||||||||||||||||||||
| 97 | // Extend the unified title and toolbar area to cover the tab bar iff | - | ||||||||||||||||||||||||||||||
| 98 | // 1) the tab bar is in document mode | - | ||||||||||||||||||||||||||||||
| 99 | // 2) the tab bar is directly below an "unified" area. | - | ||||||||||||||||||||||||||||||
| 100 | // The extending itself is done in the Cocoa platform plugin and Mac style, | - | ||||||||||||||||||||||||||||||
| 101 | // this function registers geometry and visibility state for the tab bar. | - | ||||||||||||||||||||||||||||||
| 102 | - | |||||||||||||||||||||||||||||||
| 103 | // Calculate geometry | - | ||||||||||||||||||||||||||||||
| 104 | int upper, lower; | - | ||||||||||||||||||||||||||||||
| 105 | if (documentMode) { | - | ||||||||||||||||||||||||||||||
| 106 | QPoint windowPos = q->mapTo(q->window(), QPoint(0,0)); | - | ||||||||||||||||||||||||||||||
| 107 | upper = windowPos.y(); | - | ||||||||||||||||||||||||||||||
| 108 | int tabStripHeight = q->tabSizeHint(0).height(); | - | ||||||||||||||||||||||||||||||
| 109 | int pixelTweak = -3; | - | ||||||||||||||||||||||||||||||
| 110 | lower = upper + tabStripHeight + pixelTweak; | - | ||||||||||||||||||||||||||||||
| 111 | } else { | - | ||||||||||||||||||||||||||||||
| 112 | upper = 0; | - | ||||||||||||||||||||||||||||||
| 113 | lower = 0; | - | ||||||||||||||||||||||||||||||
| 114 | } | - | ||||||||||||||||||||||||||||||
| 115 | - | |||||||||||||||||||||||||||||||
| 116 | QPlatformNativeInterface *nativeInterface = QGuiApplication::platformNativeInterface(); | - | ||||||||||||||||||||||||||||||
| 117 | quintptr identifier = reinterpret_cast<quintptr>(q); | - | ||||||||||||||||||||||||||||||
| 118 | - | |||||||||||||||||||||||||||||||
| 119 | // Set geometry | - | ||||||||||||||||||||||||||||||
| 120 | QPlatformNativeInterface::NativeResourceForIntegrationFunction function = | - | ||||||||||||||||||||||||||||||
| 121 | nativeInterface->nativeResourceFunctionForIntegration("registerContentBorderArea"); | - | ||||||||||||||||||||||||||||||
| 122 | if (!function) | - | ||||||||||||||||||||||||||||||
| 123 | return; // Not Cocoa platform plugin. | - | ||||||||||||||||||||||||||||||
| 124 | typedef void (*RegisterContentBorderAreaFunction)(QWindow *window, quintptr identifier, int upper, int lower); | - | ||||||||||||||||||||||||||||||
| 125 | (reinterpret_cast<RegisterContentBorderAreaFunction>(function))(q->window()->windowHandle(), identifier, upper, lower); | - | ||||||||||||||||||||||||||||||
| 126 | - | |||||||||||||||||||||||||||||||
| 127 | // Set visibility state | - | ||||||||||||||||||||||||||||||
| 128 | function = nativeInterface->nativeResourceFunctionForIntegration("setContentBorderAreaEnabled"); | - | ||||||||||||||||||||||||||||||
| 129 | if (!function) | - | ||||||||||||||||||||||||||||||
| 130 | return; | - | ||||||||||||||||||||||||||||||
| 131 | typedef void (*SetContentBorderAreaEnabledFunction)(QWindow *window, quintptr identifier, bool enable); | - | ||||||||||||||||||||||||||||||
| 132 | (reinterpret_cast<SetContentBorderAreaEnabledFunction>(function))(q->window()->windowHandle(), identifier, q->isVisible()); | - | ||||||||||||||||||||||||||||||
| 133 | #endif | - | ||||||||||||||||||||||||||||||
| 134 | } | - | ||||||||||||||||||||||||||||||
| 135 | - | |||||||||||||||||||||||||||||||
| 136 | /*! | - | ||||||||||||||||||||||||||||||
| 137 | \internal | - | ||||||||||||||||||||||||||||||
| 138 | This is basically QTabBar::initStyleOption() but | - | ||||||||||||||||||||||||||||||
| 139 | without the expensive QFontMetrics::elidedText() call. | - | ||||||||||||||||||||||||||||||
| 140 | */ | - | ||||||||||||||||||||||||||||||
| 141 | - | |||||||||||||||||||||||||||||||
| 142 | void QTabBarPrivate::initBasicStyleOption(QStyleOptionTab *option, int tabIndex) const | - | ||||||||||||||||||||||||||||||
| 143 | { | - | ||||||||||||||||||||||||||||||
| 144 | Q_Q(const QTabBar); | - | ||||||||||||||||||||||||||||||
| 145 | const int totalTabs = tabList.size(); | - | ||||||||||||||||||||||||||||||
| 146 | - | |||||||||||||||||||||||||||||||
| 147 | if (!option || (tabIndex < 0 || tabIndex >= totalTabs))
| 0 | ||||||||||||||||||||||||||||||
| 148 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||
| 149 | - | |||||||||||||||||||||||||||||||
| 150 | const QTabBarPrivate::Tab &tab = tabList.at(tabIndex); | - | ||||||||||||||||||||||||||||||
| 151 | option->initFrom(q); | - | ||||||||||||||||||||||||||||||
| 152 | option->state &= ~(QStyle::State_HasFocus | QStyle::State_MouseOver); | - | ||||||||||||||||||||||||||||||
| 153 | option->rect = q->tabRect(tabIndex); | - | ||||||||||||||||||||||||||||||
| 154 | const bool isCurrent = tabIndex == currentIndex; | - | ||||||||||||||||||||||||||||||
| 155 | option->row = 0; | - | ||||||||||||||||||||||||||||||
| 156 | if (tabIndex == pressedIndex)
| 0 | ||||||||||||||||||||||||||||||
| 157 | option->state |= QStyle::State_Sunken; never executed: option->state |= QStyle::State_Sunken; | 0 | ||||||||||||||||||||||||||||||
| 158 | if (isCurrent)
| 0 | ||||||||||||||||||||||||||||||
| 159 | option->state |= QStyle::State_Selected; never executed: option->state |= QStyle::State_Selected; | 0 | ||||||||||||||||||||||||||||||
| 160 | if (isCurrent && q->hasFocus())
| 0 | ||||||||||||||||||||||||||||||
| 161 | option->state |= QStyle::State_HasFocus; never executed: option->state |= QStyle::State_HasFocus; | 0 | ||||||||||||||||||||||||||||||
| 162 | if (!tab.enabled)
| 0 | ||||||||||||||||||||||||||||||
| 163 | option->state &= ~QStyle::State_Enabled; never executed: option->state &= ~QStyle::State_Enabled; | 0 | ||||||||||||||||||||||||||||||
| 164 | if (q->isActiveWindow())
| 0 | ||||||||||||||||||||||||||||||
| 165 | option->state |= QStyle::State_Active; never executed: option->state |= QStyle::State_Active; | 0 | ||||||||||||||||||||||||||||||
| 166 | if (!dragInProgress && option->rect == hoverRect)
| 0 | ||||||||||||||||||||||||||||||
| 167 | option->state |= QStyle::State_MouseOver; never executed: option->state |= QStyle::State_MouseOver; | 0 | ||||||||||||||||||||||||||||||
| 168 | option->shape = shape; | - | ||||||||||||||||||||||||||||||
| 169 | option->text = tab.text; | - | ||||||||||||||||||||||||||||||
| 170 | - | |||||||||||||||||||||||||||||||
| 171 | if (tab.textColor.isValid())
| 0 | ||||||||||||||||||||||||||||||
| 172 | option->palette.setColor(q->foregroundRole(), tab.textColor); never executed: option->palette.setColor(q->foregroundRole(), tab.textColor); | 0 | ||||||||||||||||||||||||||||||
| 173 | else if (q->style()->inherits("QMacStyle")
| 0 | ||||||||||||||||||||||||||||||
| 174 | && isCurrent && !documentMode
| 0 | ||||||||||||||||||||||||||||||
| 175 | && (QSysInfo::MacintoshVersion < QSysInfo::MV_10_10 || q->isActiveWindow())) {
| 0 | ||||||||||||||||||||||||||||||
| 176 | option->palette.setColor(QPalette::WindowText, Qt::white); | - | ||||||||||||||||||||||||||||||
| 177 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
| 178 | option->icon = tab.icon; | - | ||||||||||||||||||||||||||||||
| 179 | option->iconSize = q->iconSize(); // Will get the default value then. | - | ||||||||||||||||||||||||||||||
| 180 | - | |||||||||||||||||||||||||||||||
| 181 | option->leftButtonSize = tab.leftWidget ? tab.leftWidget->size() : QSize();
| 0 | ||||||||||||||||||||||||||||||
| 182 | option->rightButtonSize = tab.rightWidget ? tab.rightWidget->size() : QSize();
| 0 | ||||||||||||||||||||||||||||||
| 183 | option->documentMode = documentMode; | - | ||||||||||||||||||||||||||||||
| 184 | - | |||||||||||||||||||||||||||||||
| 185 | if (tabIndex > 0 && tabIndex - 1 == currentIndex)
| 0 | ||||||||||||||||||||||||||||||
| 186 | option->selectedPosition = QStyleOptionTab::PreviousIsSelected; never executed: option->selectedPosition = QStyleOptionTab::PreviousIsSelected; | 0 | ||||||||||||||||||||||||||||||
| 187 | else if (tabIndex + 1 < totalTabs && tabIndex + 1 == currentIndex)
| 0 | ||||||||||||||||||||||||||||||
| 188 | option->selectedPosition = QStyleOptionTab::NextIsSelected; never executed: option->selectedPosition = QStyleOptionTab::NextIsSelected; | 0 | ||||||||||||||||||||||||||||||
| 189 | else | - | ||||||||||||||||||||||||||||||
| 190 | option->selectedPosition = QStyleOptionTab::NotAdjacent; never executed: option->selectedPosition = QStyleOptionTab::NotAdjacent; | 0 | ||||||||||||||||||||||||||||||
| 191 | - | |||||||||||||||||||||||||||||||
| 192 | const bool paintBeginning = (tabIndex == 0) || (dragInProgress && tabIndex == pressedIndex + 1);
| 0 | ||||||||||||||||||||||||||||||
| 193 | const bool paintEnd = (tabIndex == totalTabs - 1) || (dragInProgress && tabIndex == pressedIndex - 1);
| 0 | ||||||||||||||||||||||||||||||
| 194 | if (paintBeginning) {
| 0 | ||||||||||||||||||||||||||||||
| 195 | if (paintEnd)
| 0 | ||||||||||||||||||||||||||||||
| 196 | option->position = QStyleOptionTab::OnlyOneTab; never executed: option->position = QStyleOptionTab::OnlyOneTab; | 0 | ||||||||||||||||||||||||||||||
| 197 | else | - | ||||||||||||||||||||||||||||||
| 198 | option->position = QStyleOptionTab::Beginning; never executed: option->position = QStyleOptionTab::Beginning; | 0 | ||||||||||||||||||||||||||||||
| 199 | } else if (paintEnd) {
| 0 | ||||||||||||||||||||||||||||||
| 200 | option->position = QStyleOptionTab::End; | - | ||||||||||||||||||||||||||||||
| 201 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||||||||
| 202 | option->position = QStyleOptionTab::Middle; | - | ||||||||||||||||||||||||||||||
| 203 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
| 204 | - | |||||||||||||||||||||||||||||||
| 205 | #ifndef QT_NO_TABWIDGET | - | ||||||||||||||||||||||||||||||
| 206 | if (const QTabWidget *tw = qobject_cast<const QTabWidget *>(q->parentWidget())) {
| 0 | ||||||||||||||||||||||||||||||
| 207 | option->features |= QStyleOptionTab::HasFrame; | - | ||||||||||||||||||||||||||||||
| 208 | if (tw->cornerWidget(Qt::TopLeftCorner) || tw->cornerWidget(Qt::BottomLeftCorner))
| 0 | ||||||||||||||||||||||||||||||
| 209 | option->cornerWidgets |= QStyleOptionTab::LeftCornerWidget; never executed: option->cornerWidgets |= QStyleOptionTab::LeftCornerWidget; | 0 | ||||||||||||||||||||||||||||||
| 210 | if (tw->cornerWidget(Qt::TopRightCorner) || tw->cornerWidget(Qt::BottomRightCorner))
| 0 | ||||||||||||||||||||||||||||||
| 211 | option->cornerWidgets |= QStyleOptionTab::RightCornerWidget; never executed: option->cornerWidgets |= QStyleOptionTab::RightCornerWidget; | 0 | ||||||||||||||||||||||||||||||
| 212 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
| 213 | #endif | - | ||||||||||||||||||||||||||||||
| 214 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
| 215 | - | |||||||||||||||||||||||||||||||
| 216 | /*! | - | ||||||||||||||||||||||||||||||
| 217 | Initialize \a option with the values from the tab at \a tabIndex. This method | - | ||||||||||||||||||||||||||||||
| 218 | is useful for subclasses when they need a QStyleOptionTab, | - | ||||||||||||||||||||||||||||||
| 219 | but don't want to fill in all the information themselves. | - | ||||||||||||||||||||||||||||||
| 220 | - | |||||||||||||||||||||||||||||||
| 221 | \sa QStyleOption::initFrom(), QTabWidget::initStyleOption() | - | ||||||||||||||||||||||||||||||
| 222 | */ | - | ||||||||||||||||||||||||||||||
| 223 | void QTabBar::initStyleOption(QStyleOptionTab *option, int tabIndex) const | - | ||||||||||||||||||||||||||||||
| 224 | { | - | ||||||||||||||||||||||||||||||
| 225 | Q_D(const QTabBar); | - | ||||||||||||||||||||||||||||||
| 226 | d->initBasicStyleOption(option, tabIndex); | - | ||||||||||||||||||||||||||||||
| 227 | - | |||||||||||||||||||||||||||||||
| 228 | QRect textRect = style()->subElementRect(QStyle::SE_TabBarTabText, option, this); | - | ||||||||||||||||||||||||||||||
| 229 | option->text = fontMetrics().elidedText(option->text, d->elideMode, textRect.width(), | - | ||||||||||||||||||||||||||||||
| 230 | Qt::TextShowMnemonic); | - | ||||||||||||||||||||||||||||||
| 231 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
| 232 | - | |||||||||||||||||||||||||||||||
| 233 | /*! | - | ||||||||||||||||||||||||||||||
| 234 | \class QTabBar | - | ||||||||||||||||||||||||||||||
| 235 | \brief The QTabBar class provides a tab bar, e.g. for use in tabbed dialogs. | - | ||||||||||||||||||||||||||||||
| 236 | - | |||||||||||||||||||||||||||||||
| 237 | \ingroup basicwidgets | - | ||||||||||||||||||||||||||||||
| 238 | \inmodule QtWidgets | - | ||||||||||||||||||||||||||||||
| 239 | - | |||||||||||||||||||||||||||||||
| 240 | QTabBar is straightforward to use; it draws the tabs using one of | - | ||||||||||||||||||||||||||||||
| 241 | the predefined \l{QTabBar::Shape}{shapes}, and emits a | - | ||||||||||||||||||||||||||||||
| 242 | signal when a tab is selected. It can be subclassed to tailor the | - | ||||||||||||||||||||||||||||||
| 243 | look and feel. Qt also provides a ready-made \l{QTabWidget}. | - | ||||||||||||||||||||||||||||||
| 244 | - | |||||||||||||||||||||||||||||||
| 245 | Each tab has a tabText(), an optional tabIcon(), an optional | - | ||||||||||||||||||||||||||||||
| 246 | tabToolTip(), optional tabWhatsThis() and optional tabData(). | - | ||||||||||||||||||||||||||||||
| 247 | The tabs's attributes can be changed with setTabText(), setTabIcon(), | - | ||||||||||||||||||||||||||||||
| 248 | setTabToolTip(), setTabWhatsThis and setTabData(). Each tabs can be | - | ||||||||||||||||||||||||||||||
| 249 | enabled or disabled individually with setTabEnabled(). | - | ||||||||||||||||||||||||||||||
| 250 | - | |||||||||||||||||||||||||||||||
| 251 | Each tab can display text in a distinct color. The current text color | - | ||||||||||||||||||||||||||||||
| 252 | for a tab can be found with the tabTextColor() function. Set the text | - | ||||||||||||||||||||||||||||||
| 253 | color for a particular tab with setTabTextColor(). | - | ||||||||||||||||||||||||||||||
| 254 | - | |||||||||||||||||||||||||||||||
| 255 | Tabs are added using addTab(), or inserted at particular positions | - | ||||||||||||||||||||||||||||||
| 256 | using insertTab(). The total number of tabs is given by | - | ||||||||||||||||||||||||||||||
| 257 | count(). Tabs can be removed from the tab bar with | - | ||||||||||||||||||||||||||||||
| 258 | removeTab(). Combining removeTab() and insertTab() allows you to | - | ||||||||||||||||||||||||||||||
| 259 | move tabs to different positions. | - | ||||||||||||||||||||||||||||||
| 260 | - | |||||||||||||||||||||||||||||||
| 261 | The \l shape property defines the tabs' appearance. The choice of | - | ||||||||||||||||||||||||||||||
| 262 | shape is a matter of taste, although tab dialogs (for preferences | - | ||||||||||||||||||||||||||||||
| 263 | and similar) invariably use \l RoundedNorth. | - | ||||||||||||||||||||||||||||||
| 264 | Tab controls in windows other than dialogs almost | - | ||||||||||||||||||||||||||||||
| 265 | always use either \l RoundedSouth or \l TriangularSouth. Many | - | ||||||||||||||||||||||||||||||
| 266 | spreadsheets and other tab controls in which all the pages are | - | ||||||||||||||||||||||||||||||
| 267 | essentially similar use \l TriangularSouth, whereas \l | - | ||||||||||||||||||||||||||||||
| 268 | RoundedSouth is used mostly when the pages are different (e.g. a | - | ||||||||||||||||||||||||||||||
| 269 | multi-page tool palette). The default in QTabBar is \l | - | ||||||||||||||||||||||||||||||
| 270 | RoundedNorth. | - | ||||||||||||||||||||||||||||||
| 271 | - | |||||||||||||||||||||||||||||||
| 272 | The most important part of QTabBar's API is the currentChanged() | - | ||||||||||||||||||||||||||||||
| 273 | signal. This is emitted whenever the current tab changes (even at | - | ||||||||||||||||||||||||||||||
| 274 | startup, when the current tab changes from 'none'). There is also | - | ||||||||||||||||||||||||||||||
| 275 | a slot, setCurrentIndex(), which can be used to select a tab | - | ||||||||||||||||||||||||||||||
| 276 | programmatically. The function currentIndex() returns the index of | - | ||||||||||||||||||||||||||||||
| 277 | the current tab, \l count holds the number of tabs. | - | ||||||||||||||||||||||||||||||
| 278 | - | |||||||||||||||||||||||||||||||
| 279 | QTabBar creates automatic mnemonic keys in the manner of QAbstractButton; | - | ||||||||||||||||||||||||||||||
| 280 | e.g. if a tab's label is "\&Graphics", Alt+G becomes a shortcut | - | ||||||||||||||||||||||||||||||
| 281 | key for switching to that tab. | - | ||||||||||||||||||||||||||||||
| 282 | - | |||||||||||||||||||||||||||||||
| 283 | The following virtual functions may need to be reimplemented in | - | ||||||||||||||||||||||||||||||
| 284 | order to tailor the look and feel or store extra data with each | - | ||||||||||||||||||||||||||||||
| 285 | tab: | - | ||||||||||||||||||||||||||||||
| 286 | - | |||||||||||||||||||||||||||||||
| 287 | \list | - | ||||||||||||||||||||||||||||||
| 288 | \li tabSizeHint() calcuates the size of a tab. | - | ||||||||||||||||||||||||||||||
| 289 | \li tabInserted() notifies that a new tab was added. | - | ||||||||||||||||||||||||||||||
| 290 | \li tabRemoved() notifies that a tab was removed. | - | ||||||||||||||||||||||||||||||
| 291 | \li tabLayoutChange() notifies that the tabs have been re-laid out. | - | ||||||||||||||||||||||||||||||
| 292 | \li paintEvent() paints all tabs. | - | ||||||||||||||||||||||||||||||
| 293 | \endlist | - | ||||||||||||||||||||||||||||||
| 294 | - | |||||||||||||||||||||||||||||||
| 295 | For subclasses, you might also need the tabRect() functions which | - | ||||||||||||||||||||||||||||||
| 296 | returns the visual geometry of a single tab. | - | ||||||||||||||||||||||||||||||
| 297 | - | |||||||||||||||||||||||||||||||
| 298 | \table 100% | - | ||||||||||||||||||||||||||||||
| 299 | \row \li \inlineimage fusion-tabbar.png Screenshot of a Fusion style tab bar | - | ||||||||||||||||||||||||||||||
| 300 | \li A tab bar shown in the Fusion widget style. | - | ||||||||||||||||||||||||||||||
| 301 | \row \li \inlineimage fusion-tabbar-truncated.png Screenshot of a truncated Fusion tab bar | - | ||||||||||||||||||||||||||||||
| 302 | \li A truncated tab bar shown in the Fusion widget style. | - | ||||||||||||||||||||||||||||||
| 303 | \endtable | - | ||||||||||||||||||||||||||||||
| 304 | - | |||||||||||||||||||||||||||||||
| 305 | \sa QTabWidget | - | ||||||||||||||||||||||||||||||
| 306 | */ | - | ||||||||||||||||||||||||||||||
| 307 | - | |||||||||||||||||||||||||||||||
| 308 | /*! | - | ||||||||||||||||||||||||||||||
| 309 | \enum QTabBar::Shape | - | ||||||||||||||||||||||||||||||
| 310 | - | |||||||||||||||||||||||||||||||
| 311 | This enum type lists the built-in shapes supported by QTabBar. Treat these | - | ||||||||||||||||||||||||||||||
| 312 | as hints as some styles may not render some of the shapes. However, | - | ||||||||||||||||||||||||||||||
| 313 | position should be honored. | - | ||||||||||||||||||||||||||||||
| 314 | - | |||||||||||||||||||||||||||||||
| 315 | \value RoundedNorth The normal rounded look above the pages | - | ||||||||||||||||||||||||||||||
| 316 | - | |||||||||||||||||||||||||||||||
| 317 | \value RoundedSouth The normal rounded look below the pages | - | ||||||||||||||||||||||||||||||
| 318 | - | |||||||||||||||||||||||||||||||
| 319 | \value RoundedWest The normal rounded look on the left side of the pages | - | ||||||||||||||||||||||||||||||
| 320 | - | |||||||||||||||||||||||||||||||
| 321 | \value RoundedEast The normal rounded look on the right side the pages | - | ||||||||||||||||||||||||||||||
| 322 | - | |||||||||||||||||||||||||||||||
| 323 | \value TriangularNorth Triangular tabs above the pages. | - | ||||||||||||||||||||||||||||||
| 324 | - | |||||||||||||||||||||||||||||||
| 325 | \value TriangularSouth Triangular tabs similar to those used in | - | ||||||||||||||||||||||||||||||
| 326 | the Excel spreadsheet, for example | - | ||||||||||||||||||||||||||||||
| 327 | - | |||||||||||||||||||||||||||||||
| 328 | \value TriangularWest Triangular tabs on the left of the pages. | - | ||||||||||||||||||||||||||||||
| 329 | - | |||||||||||||||||||||||||||||||
| 330 | \value TriangularEast Triangular tabs on the right of the pages. | - | ||||||||||||||||||||||||||||||
| 331 | */ | - | ||||||||||||||||||||||||||||||
| 332 | - | |||||||||||||||||||||||||||||||
| 333 | /*! | - | ||||||||||||||||||||||||||||||
| 334 | \fn void QTabBar::currentChanged(int index) | - | ||||||||||||||||||||||||||||||
| 335 | - | |||||||||||||||||||||||||||||||
| 336 | This signal is emitted when the tab bar's current tab changes. The | - | ||||||||||||||||||||||||||||||
| 337 | new current has the given \a index, or -1 if there isn't a new one | - | ||||||||||||||||||||||||||||||
| 338 | (for example, if there are no tab in the QTabBar) | - | ||||||||||||||||||||||||||||||
| 339 | */ | - | ||||||||||||||||||||||||||||||
| 340 | - | |||||||||||||||||||||||||||||||
| 341 | /*! | - | ||||||||||||||||||||||||||||||
| 342 | \fn void QTabBar::tabCloseRequested(int index) | - | ||||||||||||||||||||||||||||||
| 343 | \since 4.5 | - | ||||||||||||||||||||||||||||||
| 344 | - | |||||||||||||||||||||||||||||||
| 345 | This signal is emitted when the close button on a tab is clicked. | - | ||||||||||||||||||||||||||||||
| 346 | The \a index is the index that should be removed. | - | ||||||||||||||||||||||||||||||
| 347 | - | |||||||||||||||||||||||||||||||
| 348 | \sa setTabsClosable() | - | ||||||||||||||||||||||||||||||
| 349 | */ | - | ||||||||||||||||||||||||||||||
| 350 | - | |||||||||||||||||||||||||||||||
| 351 | /*! | - | ||||||||||||||||||||||||||||||
| 352 | \fn void QTabBar::tabMoved(int from, int to) | - | ||||||||||||||||||||||||||||||
| 353 | \since 4.5 | - | ||||||||||||||||||||||||||||||
| 354 | - | |||||||||||||||||||||||||||||||
| 355 | This signal is emitted when the tab has moved the tab | - | ||||||||||||||||||||||||||||||
| 356 | at index position \a from to index position \a to. | - | ||||||||||||||||||||||||||||||
| 357 | - | |||||||||||||||||||||||||||||||
| 358 | note: QTabWidget will automatically move the page when | - | ||||||||||||||||||||||||||||||
| 359 | this signal is emitted from its tab bar. | - | ||||||||||||||||||||||||||||||
| 360 | - | |||||||||||||||||||||||||||||||
| 361 | \sa moveTab() | - | ||||||||||||||||||||||||||||||
| 362 | */ | - | ||||||||||||||||||||||||||||||
| 363 | - | |||||||||||||||||||||||||||||||
| 364 | /*! | - | ||||||||||||||||||||||||||||||
| 365 | \fn void QTabBar::tabBarClicked(int index) | - | ||||||||||||||||||||||||||||||
| 366 | - | |||||||||||||||||||||||||||||||
| 367 | This signal is emitted when user clicks on a tab at an \a index. | - | ||||||||||||||||||||||||||||||
| 368 | - | |||||||||||||||||||||||||||||||
| 369 | \a index is the index of a clicked tab, or -1 if no tab is under the cursor. | - | ||||||||||||||||||||||||||||||
| 370 | - | |||||||||||||||||||||||||||||||
| 371 | \since 5.2 | - | ||||||||||||||||||||||||||||||
| 372 | */ | - | ||||||||||||||||||||||||||||||
| 373 | - | |||||||||||||||||||||||||||||||
| 374 | /*! | - | ||||||||||||||||||||||||||||||
| 375 | \fn void QTabBar::tabBarDoubleClicked(int index) | - | ||||||||||||||||||||||||||||||
| 376 | - | |||||||||||||||||||||||||||||||
| 377 | This signal is emitted when the user double clicks on a tab at \a index. | - | ||||||||||||||||||||||||||||||
| 378 | - | |||||||||||||||||||||||||||||||
| 379 | \a index refers to the tab clicked, or -1 if no tab is under the cursor. | - | ||||||||||||||||||||||||||||||
| 380 | - | |||||||||||||||||||||||||||||||
| 381 | \since 5.2 | - | ||||||||||||||||||||||||||||||
| 382 | */ | - | ||||||||||||||||||||||||||||||
| 383 | - | |||||||||||||||||||||||||||||||
| 384 | int QTabBarPrivate::extraWidth() const | - | ||||||||||||||||||||||||||||||
| 385 | { | - | ||||||||||||||||||||||||||||||
| 386 | Q_Q(const QTabBar); | - | ||||||||||||||||||||||||||||||
| 387 | return 2 * qMax(q->style()->pixelMetric(QStyle::PM_TabBarScrollButtonWidth, 0, q), never executed: return 2 * qMax(q->style()->pixelMetric(QStyle::PM_TabBarScrollButtonWidth, 0, q), QApplication::globalStrut().width()); | 0 | ||||||||||||||||||||||||||||||
| 388 | QApplication::globalStrut().width()); never executed: return 2 * qMax(q->style()->pixelMetric(QStyle::PM_TabBarScrollButtonWidth, 0, q), QApplication::globalStrut().width()); | 0 | ||||||||||||||||||||||||||||||
| 389 | } | - | ||||||||||||||||||||||||||||||
| 390 | - | |||||||||||||||||||||||||||||||
| 391 | void QTabBarPrivate::init() | - | ||||||||||||||||||||||||||||||
| 392 | { | - | ||||||||||||||||||||||||||||||
| 393 | Q_Q(QTabBar); | - | ||||||||||||||||||||||||||||||
| 394 | leftB = new QToolButton(q); | - | ||||||||||||||||||||||||||||||
| 395 | leftB->setAutoRepeat(true); | - | ||||||||||||||||||||||||||||||
| 396 | QObject::connect(leftB, SIGNAL(clicked()), q, SLOT(_q_scrollTabs())); | - | ||||||||||||||||||||||||||||||
| 397 | leftB->hide(); | - | ||||||||||||||||||||||||||||||
| 398 | rightB = new QToolButton(q); | - | ||||||||||||||||||||||||||||||
| 399 | rightB->setAutoRepeat(true); | - | ||||||||||||||||||||||||||||||
| 400 | QObject::connect(rightB, SIGNAL(clicked()), q, SLOT(_q_scrollTabs())); | - | ||||||||||||||||||||||||||||||
| 401 | rightB->hide(); | - | ||||||||||||||||||||||||||||||
| 402 | #ifdef QT_KEYPAD_NAVIGATION | - | ||||||||||||||||||||||||||||||
| 403 | if (QApplication::keypadNavigationEnabled()) { | - | ||||||||||||||||||||||||||||||
| 404 | leftB->setFocusPolicy(Qt::NoFocus); | - | ||||||||||||||||||||||||||||||
| 405 | rightB->setFocusPolicy(Qt::NoFocus); | - | ||||||||||||||||||||||||||||||
| 406 | q->setFocusPolicy(Qt::NoFocus); | - | ||||||||||||||||||||||||||||||
| 407 | } else | - | ||||||||||||||||||||||||||||||
| 408 | #endif | - | ||||||||||||||||||||||||||||||
| 409 | q->setFocusPolicy(Qt::TabFocus); | - | ||||||||||||||||||||||||||||||
| 410 | - | |||||||||||||||||||||||||||||||
| 411 | #ifndef QT_NO_ACCESSIBILITY | - | ||||||||||||||||||||||||||||||
| 412 | leftB->setAccessibleName(QTabBar::tr("Scroll Left")); | - | ||||||||||||||||||||||||||||||
| 413 | rightB->setAccessibleName(QTabBar::tr("Scroll Right")); | - | ||||||||||||||||||||||||||||||
| 414 | #endif | - | ||||||||||||||||||||||||||||||
| 415 | q->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed); | - | ||||||||||||||||||||||||||||||
| 416 | elideMode = Qt::TextElideMode(q->style()->styleHint(QStyle::SH_TabBar_ElideMode, 0, q)); | - | ||||||||||||||||||||||||||||||
| 417 | useScrollButtons = !q->style()->styleHint(QStyle::SH_TabBar_PreferNoArrows, 0, q); | - | ||||||||||||||||||||||||||||||
| 418 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
| 419 | - | |||||||||||||||||||||||||||||||
| 420 | QTabBarPrivate::Tab *QTabBarPrivate::at(int index) | - | ||||||||||||||||||||||||||||||
| 421 | { | - | ||||||||||||||||||||||||||||||
| 422 | return validIndex(index)?&tabList[index]:0; never executed: return validIndex(index)?&tabList[index]:0;
| 0 | ||||||||||||||||||||||||||||||
| 423 | } | - | ||||||||||||||||||||||||||||||
| 424 | - | |||||||||||||||||||||||||||||||
| 425 | const QTabBarPrivate::Tab *QTabBarPrivate::at(int index) const | - | ||||||||||||||||||||||||||||||
| 426 | { | - | ||||||||||||||||||||||||||||||
| 427 | return validIndex(index)?&tabList[index]:0; never executed: return validIndex(index)?&tabList[index]:0;
| 0 | ||||||||||||||||||||||||||||||
| 428 | } | - | ||||||||||||||||||||||||||||||
| 429 | - | |||||||||||||||||||||||||||||||
| 430 | int QTabBarPrivate::indexAtPos(const QPoint &p) const | - | ||||||||||||||||||||||||||||||
| 431 | { | - | ||||||||||||||||||||||||||||||
| 432 | Q_Q(const QTabBar); | - | ||||||||||||||||||||||||||||||
| 433 | if (q->tabRect(currentIndex).contains(p))
| 0 | ||||||||||||||||||||||||||||||
| 434 | return currentIndex; never executed: return currentIndex; | 0 | ||||||||||||||||||||||||||||||
| 435 | for (int i = 0; i < tabList.count(); ++i)
| 0 | ||||||||||||||||||||||||||||||
| 436 | if (tabList.at(i).enabled && q->tabRect(i).contains(p))
| 0 | ||||||||||||||||||||||||||||||
| 437 | return i; never executed: return i; | 0 | ||||||||||||||||||||||||||||||
| 438 | return -1; never executed: return -1; | 0 | ||||||||||||||||||||||||||||||
| 439 | } | - | ||||||||||||||||||||||||||||||
| 440 | - | |||||||||||||||||||||||||||||||
| 441 | void QTabBarPrivate::layoutTabs() | - | ||||||||||||||||||||||||||||||
| 442 | { | - | ||||||||||||||||||||||||||||||
| 443 | Q_Q(QTabBar); | - | ||||||||||||||||||||||||||||||
| 444 | scrollOffset = 0; | - | ||||||||||||||||||||||||||||||
| 445 | layoutDirty = false; | - | ||||||||||||||||||||||||||||||
| 446 | QSize size = q->size(); | - | ||||||||||||||||||||||||||||||
| 447 | int last, available; | - | ||||||||||||||||||||||||||||||
| 448 | int maxExtent; | - | ||||||||||||||||||||||||||||||
| 449 | int i; | - | ||||||||||||||||||||||||||||||
| 450 | bool vertTabs = verticalTabs(shape); | - | ||||||||||||||||||||||||||||||
| 451 | int tabChainIndex = 0; | - | ||||||||||||||||||||||||||||||
| 452 | - | |||||||||||||||||||||||||||||||
| 453 | Qt::Alignment tabAlignment = Qt::Alignment(q->style()->styleHint(QStyle::SH_TabBar_Alignment, 0, q)); | - | ||||||||||||||||||||||||||||||
| 454 | QVector<QLayoutStruct> tabChain(tabList.count() + 2); | - | ||||||||||||||||||||||||||||||
| 455 | - | |||||||||||||||||||||||||||||||
| 456 | // We put an empty item at the front and back and set its expansive attribute | - | ||||||||||||||||||||||||||||||
| 457 | // depending on tabAlignment. | - | ||||||||||||||||||||||||||||||
| 458 | tabChain[tabChainIndex].init(); | - | ||||||||||||||||||||||||||||||
| 459 | tabChain[tabChainIndex].expansive = (tabAlignment != Qt::AlignLeft)
| 0 | ||||||||||||||||||||||||||||||
| 460 | && (tabAlignment != Qt::AlignJustify);
| 0 | ||||||||||||||||||||||||||||||
| 461 | tabChain[tabChainIndex].empty = true; | - | ||||||||||||||||||||||||||||||
| 462 | ++tabChainIndex; | - | ||||||||||||||||||||||||||||||
| 463 | - | |||||||||||||||||||||||||||||||
| 464 | // We now go through our list of tabs and set the minimum size and the size hint | - | ||||||||||||||||||||||||||||||
| 465 | // This will allow us to elide text if necessary. Since we don't set | - | ||||||||||||||||||||||||||||||
| 466 | // a maximum size, tabs will EXPAND to fill up the empty space. | - | ||||||||||||||||||||||||||||||
| 467 | // Since tab widget is rather *ahem* strict about keeping the geometry of the | - | ||||||||||||||||||||||||||||||
| 468 | // tab bar to its absolute minimum, this won't bleed through, but will show up | - | ||||||||||||||||||||||||||||||
| 469 | // if you use tab bar on its own (a.k.a. not a bug, but a feature). | - | ||||||||||||||||||||||||||||||
| 470 | // Update: if expanding is false, we DO set a maximum size to prevent the tabs | - | ||||||||||||||||||||||||||||||
| 471 | // being wider than necessary. | - | ||||||||||||||||||||||||||||||
| 472 | if (!vertTabs) {
| 0 | ||||||||||||||||||||||||||||||
| 473 | int minx = 0; | - | ||||||||||||||||||||||||||||||
| 474 | int x = 0; | - | ||||||||||||||||||||||||||||||
| 475 | int maxHeight = 0; | - | ||||||||||||||||||||||||||||||
| 476 | for (i = 0; i < tabList.count(); ++i, ++tabChainIndex) {
| 0 | ||||||||||||||||||||||||||||||
| 477 | QSize sz = q->tabSizeHint(i); | - | ||||||||||||||||||||||||||||||
| 478 | tabList[i].maxRect = QRect(x, 0, sz.width(), sz.height()); | - | ||||||||||||||||||||||||||||||
| 479 | x += sz.width(); | - | ||||||||||||||||||||||||||||||
| 480 | maxHeight = qMax(maxHeight, sz.height()); | - | ||||||||||||||||||||||||||||||
| 481 | sz = q->minimumTabSizeHint(i); | - | ||||||||||||||||||||||||||||||
| 482 | tabList[i].minRect = QRect(minx, 0, sz.width(), sz.height()); | - | ||||||||||||||||||||||||||||||
| 483 | minx += sz.width(); | - | ||||||||||||||||||||||||||||||
| 484 | tabChain[tabChainIndex].init(); | - | ||||||||||||||||||||||||||||||
| 485 | tabChain[tabChainIndex].sizeHint = tabList.at(i).maxRect.width(); | - | ||||||||||||||||||||||||||||||
| 486 | tabChain[tabChainIndex].minimumSize = sz.width(); | - | ||||||||||||||||||||||||||||||
| 487 | tabChain[tabChainIndex].empty = false; | - | ||||||||||||||||||||||||||||||
| 488 | tabChain[tabChainIndex].expansive = true; | - | ||||||||||||||||||||||||||||||
| 489 | - | |||||||||||||||||||||||||||||||
| 490 | if (!expanding)
| 0 | ||||||||||||||||||||||||||||||
| 491 | tabChain[tabChainIndex].maximumSize = tabChain[tabChainIndex].sizeHint; never executed: tabChain[tabChainIndex].maximumSize = tabChain[tabChainIndex].sizeHint; | 0 | ||||||||||||||||||||||||||||||
| 492 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
| 493 | - | |||||||||||||||||||||||||||||||
| 494 | last = minx; | - | ||||||||||||||||||||||||||||||
| 495 | available = size.width(); | - | ||||||||||||||||||||||||||||||
| 496 | maxExtent = maxHeight; | - | ||||||||||||||||||||||||||||||
| 497 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||||||||
| 498 | int miny = 0; | - | ||||||||||||||||||||||||||||||
| 499 | int y = 0; | - | ||||||||||||||||||||||||||||||
| 500 | int maxWidth = 0; | - | ||||||||||||||||||||||||||||||
| 501 | for (i = 0; i < tabList.count(); ++i, ++tabChainIndex) {
| 0 | ||||||||||||||||||||||||||||||
| 502 | QSize sz = q->tabSizeHint(i); | - | ||||||||||||||||||||||||||||||
| 503 | tabList[i].maxRect = QRect(0, y, sz.width(), sz.height()); | - | ||||||||||||||||||||||||||||||
| 504 | y += sz.height(); | - | ||||||||||||||||||||||||||||||
| 505 | maxWidth = qMax(maxWidth, sz.width()); | - | ||||||||||||||||||||||||||||||
| 506 | sz = q->minimumTabSizeHint(i); | - | ||||||||||||||||||||||||||||||
| 507 | tabList[i].minRect = QRect(0, miny, sz.width(), sz.height()); | - | ||||||||||||||||||||||||||||||
| 508 | miny += sz.height(); | - | ||||||||||||||||||||||||||||||
| 509 | tabChain[tabChainIndex].init(); | - | ||||||||||||||||||||||||||||||
| 510 | tabChain[tabChainIndex].sizeHint = tabList.at(i).maxRect.height(); | - | ||||||||||||||||||||||||||||||
| 511 | tabChain[tabChainIndex].minimumSize = sz.height(); | - | ||||||||||||||||||||||||||||||
| 512 | tabChain[tabChainIndex].empty = false; | - | ||||||||||||||||||||||||||||||
| 513 | tabChain[tabChainIndex].expansive = true; | - | ||||||||||||||||||||||||||||||
| 514 | - | |||||||||||||||||||||||||||||||
| 515 | if (!expanding)
| 0 | ||||||||||||||||||||||||||||||
| 516 | tabChain[tabChainIndex].maximumSize = tabChain[tabChainIndex].sizeHint; never executed: tabChain[tabChainIndex].maximumSize = tabChain[tabChainIndex].sizeHint; | 0 | ||||||||||||||||||||||||||||||
| 517 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
| 518 | - | |||||||||||||||||||||||||||||||
| 519 | last = miny; | - | ||||||||||||||||||||||||||||||
| 520 | available = size.height(); | - | ||||||||||||||||||||||||||||||
| 521 | maxExtent = maxWidth; | - | ||||||||||||||||||||||||||||||
| 522 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
| 523 | - | |||||||||||||||||||||||||||||||
| 524 | Q_ASSERT(tabChainIndex == tabChain.count() - 1); // add an assert just to make sure. | - | ||||||||||||||||||||||||||||||
| 525 | // Mirror our front item. | - | ||||||||||||||||||||||||||||||
| 526 | tabChain[tabChainIndex].init(); | - | ||||||||||||||||||||||||||||||
| 527 | tabChain[tabChainIndex].expansive = (tabAlignment != Qt::AlignRight)
| 0 | ||||||||||||||||||||||||||||||
| 528 | && (tabAlignment != Qt::AlignJustify);
| 0 | ||||||||||||||||||||||||||||||
| 529 | tabChain[tabChainIndex].empty = true; | - | ||||||||||||||||||||||||||||||
| 530 | - | |||||||||||||||||||||||||||||||
| 531 | // Do the calculation | - | ||||||||||||||||||||||||||||||
| 532 | qGeomCalc(tabChain, 0, tabChain.count(), 0, qMax(available, last), 0); | - | ||||||||||||||||||||||||||||||
| 533 | - | |||||||||||||||||||||||||||||||
| 534 | // Use the results | - | ||||||||||||||||||||||||||||||
| 535 | for (i = 0; i < tabList.count(); ++i) {
| 0 | ||||||||||||||||||||||||||||||
| 536 | const QLayoutStruct &lstruct = tabChain.at(i + 1); | - | ||||||||||||||||||||||||||||||
| 537 | if (!vertTabs)
| 0 | ||||||||||||||||||||||||||||||
| 538 | tabList[i].rect.setRect(lstruct.pos, 0, lstruct.size, maxExtent); never executed: tabList[i].rect.setRect(lstruct.pos, 0, lstruct.size, maxExtent); | 0 | ||||||||||||||||||||||||||||||
| 539 | else | - | ||||||||||||||||||||||||||||||
| 540 | tabList[i].rect.setRect(0, lstruct.pos, maxExtent, lstruct.size); never executed: tabList[i].rect.setRect(0, lstruct.pos, maxExtent, lstruct.size); | 0 | ||||||||||||||||||||||||||||||
| 541 | } | - | ||||||||||||||||||||||||||||||
| 542 | - | |||||||||||||||||||||||||||||||
| 543 | if (useScrollButtons && tabList.count() && last > available) {
| 0 | ||||||||||||||||||||||||||||||
| 544 | int extra = extraWidth(); | - | ||||||||||||||||||||||||||||||
| 545 | if (!vertTabs) {
| 0 | ||||||||||||||||||||||||||||||
| 546 | Qt::LayoutDirection ld = q->layoutDirection(); | - | ||||||||||||||||||||||||||||||
| 547 | QRect arrows = QStyle::visualRect(ld, q->rect(), | - | ||||||||||||||||||||||||||||||
| 548 | QRect(available - extra, 0, extra, size.height())); | - | ||||||||||||||||||||||||||||||
| 549 | int buttonOverlap = q->style()->pixelMetric(QStyle::PM_TabBar_ScrollButtonOverlap, 0, q); | - | ||||||||||||||||||||||||||||||
| 550 | - | |||||||||||||||||||||||||||||||
| 551 | if (ld == Qt::LeftToRight) {
| 0 | ||||||||||||||||||||||||||||||
| 552 | leftB->setGeometry(arrows.left(), arrows.top(), extra/2, arrows.height()); | - | ||||||||||||||||||||||||||||||
| 553 | rightB->setGeometry(arrows.right() - extra/2 + buttonOverlap, arrows.top(), | - | ||||||||||||||||||||||||||||||
| 554 | extra/2, arrows.height()); | - | ||||||||||||||||||||||||||||||
| 555 | leftB->setArrowType(Qt::LeftArrow); | - | ||||||||||||||||||||||||||||||
| 556 | rightB->setArrowType(Qt::RightArrow); | - | ||||||||||||||||||||||||||||||
| 557 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||||||||
| 558 | rightB->setGeometry(arrows.left(), arrows.top(), extra/2, arrows.height()); | - | ||||||||||||||||||||||||||||||
| 559 | leftB->setGeometry(arrows.right() - extra/2 + buttonOverlap, arrows.top(), | - | ||||||||||||||||||||||||||||||
| 560 | extra/2, arrows.height()); | - | ||||||||||||||||||||||||||||||
| 561 | rightB->setArrowType(Qt::LeftArrow); | - | ||||||||||||||||||||||||||||||
| 562 | leftB->setArrowType(Qt::RightArrow); | - | ||||||||||||||||||||||||||||||
| 563 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
| 564 | } else { | - | ||||||||||||||||||||||||||||||
| 565 | QRect arrows = QRect(0, available - extra, size.width(), extra ); | - | ||||||||||||||||||||||||||||||
| 566 | leftB->setGeometry(arrows.left(), arrows.top(), arrows.width(), extra/2); | - | ||||||||||||||||||||||||||||||
| 567 | leftB->setArrowType(Qt::UpArrow); | - | ||||||||||||||||||||||||||||||
| 568 | rightB->setGeometry(arrows.left(), arrows.bottom() - extra/2 + 1, | - | ||||||||||||||||||||||||||||||
| 569 | arrows.width(), extra/2); | - | ||||||||||||||||||||||||||||||
| 570 | rightB->setArrowType(Qt::DownArrow); | - | ||||||||||||||||||||||||||||||
| 571 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
| 572 | leftB->setEnabled(scrollOffset > 0); | - | ||||||||||||||||||||||||||||||
| 573 | rightB->setEnabled(last - scrollOffset >= available - extra); | - | ||||||||||||||||||||||||||||||
| 574 | leftB->show(); | - | ||||||||||||||||||||||||||||||
| 575 | rightB->show(); | - | ||||||||||||||||||||||||||||||
| 576 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||||||||
| 577 | rightB->hide(); | - | ||||||||||||||||||||||||||||||
| 578 | leftB->hide(); | - | ||||||||||||||||||||||||||||||
| 579 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
| 580 | - | |||||||||||||||||||||||||||||||
| 581 | layoutWidgets(); | - | ||||||||||||||||||||||||||||||
| 582 | q->tabLayoutChange(); | - | ||||||||||||||||||||||||||||||
| 583 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
| 584 | - | |||||||||||||||||||||||||||||||
| 585 | void QTabBarPrivate::makeVisible(int index) | - | ||||||||||||||||||||||||||||||
| 586 | { | - | ||||||||||||||||||||||||||||||
| 587 | Q_Q(QTabBar); | - | ||||||||||||||||||||||||||||||
| 588 | if (!validIndex(index) || leftB->isHidden())
| 0 | ||||||||||||||||||||||||||||||
| 589 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||
| 590 | - | |||||||||||||||||||||||||||||||
| 591 | const QRect tabRect = tabList.at(index).rect; | - | ||||||||||||||||||||||||||||||
| 592 | const int oldScrollOffset = scrollOffset; | - | ||||||||||||||||||||||||||||||
| 593 | const bool horiz = !verticalTabs(shape); | - | ||||||||||||||||||||||||||||||
| 594 | const int available = (horiz ? q->width() : q->height()) - extraWidth();
| 0 | ||||||||||||||||||||||||||||||
| 595 | const int start = horiz ? tabRect.left() : tabRect.top();
| 0 | ||||||||||||||||||||||||||||||
| 596 | const int end = horiz ? tabRect.right() : tabRect.bottom();
| 0 | ||||||||||||||||||||||||||||||
| 597 | if (start < scrollOffset) // too far left
| 0 | ||||||||||||||||||||||||||||||
| 598 | scrollOffset = start - (index ? 8 : 0); never executed: scrollOffset = start - (index ? 8 : 0);
| 0 | ||||||||||||||||||||||||||||||
| 599 | else if (end > scrollOffset + available) // too far right
| 0 | ||||||||||||||||||||||||||||||
| 600 | scrollOffset = end - available + 1; never executed: scrollOffset = end - available + 1; | 0 | ||||||||||||||||||||||||||||||
| 601 | - | |||||||||||||||||||||||||||||||
| 602 | leftB->setEnabled(scrollOffset > 0); | - | ||||||||||||||||||||||||||||||
| 603 | const int last = horiz ? tabList.last().rect.right() : tabList.last().rect.bottom();
| 0 | ||||||||||||||||||||||||||||||
| 604 | rightB->setEnabled(last - scrollOffset >= available); | - | ||||||||||||||||||||||||||||||
| 605 | if (oldScrollOffset != scrollOffset) {
| 0 | ||||||||||||||||||||||||||||||
| 606 | q->update(); | - | ||||||||||||||||||||||||||||||
| 607 | layoutWidgets(); | - | ||||||||||||||||||||||||||||||
| 608 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
| 609 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
| 610 | - | |||||||||||||||||||||||||||||||
| 611 | void QTabBarPrivate::killSwitchTabTimer() | - | ||||||||||||||||||||||||||||||
| 612 | { | - | ||||||||||||||||||||||||||||||
| 613 | Q_Q(QTabBar); | - | ||||||||||||||||||||||||||||||
| 614 | if (switchTabTimerId) {
| 0 | ||||||||||||||||||||||||||||||
| 615 | q->killTimer(switchTabTimerId); | - | ||||||||||||||||||||||||||||||
| 616 | switchTabTimerId = 0; | - | ||||||||||||||||||||||||||||||
| 617 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
| 618 | switchTabCurrentIndex = -1; | - | ||||||||||||||||||||||||||||||
| 619 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
| 620 | - | |||||||||||||||||||||||||||||||
| 621 | void QTabBarPrivate::layoutTab(int index) | - | ||||||||||||||||||||||||||||||
| 622 | { | - | ||||||||||||||||||||||||||||||
| 623 | Q_Q(QTabBar); | - | ||||||||||||||||||||||||||||||
| 624 | Q_ASSERT(index >= 0); | - | ||||||||||||||||||||||||||||||
| 625 | - | |||||||||||||||||||||||||||||||
| 626 | Tab &tab = tabList[index]; | - | ||||||||||||||||||||||||||||||
| 627 | bool vertical = verticalTabs(shape); | - | ||||||||||||||||||||||||||||||
| 628 | if (!(tab.leftWidget || tab.rightWidget))
| 0 | ||||||||||||||||||||||||||||||
| 629 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||
| 630 | - | |||||||||||||||||||||||||||||||
| 631 | QStyleOptionTab opt; | - | ||||||||||||||||||||||||||||||
| 632 | q->initStyleOption(&opt, index); | - | ||||||||||||||||||||||||||||||
| 633 | if (tab.leftWidget) {
| 0 | ||||||||||||||||||||||||||||||
| 634 | QRect rect = q->style()->subElementRect(QStyle::SE_TabBarTabLeftButton, &opt, q); | - | ||||||||||||||||||||||||||||||
| 635 | QPoint p = rect.topLeft(); | - | ||||||||||||||||||||||||||||||
| 636 | if ((index == pressedIndex) || paintWithOffsets) {
| 0 | ||||||||||||||||||||||||||||||
| 637 | if (vertical)
| 0 | ||||||||||||||||||||||||||||||
| 638 | p.setY(p.y() + tabList[index].dragOffset); never executed: p.setY(p.y() + tabList[index].dragOffset); | 0 | ||||||||||||||||||||||||||||||
| 639 | else | - | ||||||||||||||||||||||||||||||
| 640 | p.setX(p.x() + tabList[index].dragOffset); never executed: p.setX(p.x() + tabList[index].dragOffset); | 0 | ||||||||||||||||||||||||||||||
| 641 | } | - | ||||||||||||||||||||||||||||||
| 642 | tab.leftWidget->move(p); | - | ||||||||||||||||||||||||||||||
| 643 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
| 644 | if (tab.rightWidget) {
| 0 | ||||||||||||||||||||||||||||||
| 645 | QRect rect = q->style()->subElementRect(QStyle::SE_TabBarTabRightButton, &opt, q); | - | ||||||||||||||||||||||||||||||
| 646 | QPoint p = rect.topLeft(); | - | ||||||||||||||||||||||||||||||
| 647 | if ((index == pressedIndex) || paintWithOffsets) {
| 0 | ||||||||||||||||||||||||||||||
| 648 | if (vertical)
| 0 | ||||||||||||||||||||||||||||||
| 649 | p.setY(p.y() + tab.dragOffset); never executed: p.setY(p.y() + tab.dragOffset); | 0 | ||||||||||||||||||||||||||||||
| 650 | else | - | ||||||||||||||||||||||||||||||
| 651 | p.setX(p.x() + tab.dragOffset); never executed: p.setX(p.x() + tab.dragOffset); | 0 | ||||||||||||||||||||||||||||||
| 652 | } | - | ||||||||||||||||||||||||||||||
| 653 | tab.rightWidget->move(p); | - | ||||||||||||||||||||||||||||||
| 654 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
| 655 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
| 656 | - | |||||||||||||||||||||||||||||||
| 657 | void QTabBarPrivate::layoutWidgets(int start) | - | ||||||||||||||||||||||||||||||
| 658 | { | - | ||||||||||||||||||||||||||||||
| 659 | Q_Q(QTabBar); | - | ||||||||||||||||||||||||||||||
| 660 | for (int i = start; i < q->count(); ++i) {
| 0 | ||||||||||||||||||||||||||||||
| 661 | layoutTab(i); | - | ||||||||||||||||||||||||||||||
| 662 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
| 663 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
| 664 | - | |||||||||||||||||||||||||||||||
| 665 | void QTabBarPrivate::autoHideTabs() | - | ||||||||||||||||||||||||||||||
| 666 | { | - | ||||||||||||||||||||||||||||||
| 667 | Q_Q(QTabBar); | - | ||||||||||||||||||||||||||||||
| 668 | - | |||||||||||||||||||||||||||||||
| 669 | if (autoHide)
| 0 | ||||||||||||||||||||||||||||||
| 670 | q->setVisible(q->count() > 1); never executed: q->setVisible(q->count() > 1); | 0 | ||||||||||||||||||||||||||||||
| 671 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
| 672 | - | |||||||||||||||||||||||||||||||
| 673 | void QTabBarPrivate::_q_closeTab() | - | ||||||||||||||||||||||||||||||
| 674 | { | - | ||||||||||||||||||||||||||||||
| 675 | Q_Q(QTabBar); | - | ||||||||||||||||||||||||||||||
| 676 | QObject *object = q->sender(); | - | ||||||||||||||||||||||||||||||
| 677 | int tabToClose = -1; | - | ||||||||||||||||||||||||||||||
| 678 | QTabBar::ButtonPosition closeSide = (QTabBar::ButtonPosition)q->style()->styleHint(QStyle::SH_TabBar_CloseButtonPosition, 0, q); | - | ||||||||||||||||||||||||||||||
| 679 | for (int i = 0; i < tabList.count(); ++i) {
| 0 | ||||||||||||||||||||||||||||||
| 680 | if (closeSide == QTabBar::LeftSide) {
| 0 | ||||||||||||||||||||||||||||||
| 681 | if (tabList.at(i).leftWidget == object) {
| 0 | ||||||||||||||||||||||||||||||
| 682 | tabToClose = i; | - | ||||||||||||||||||||||||||||||
| 683 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||
| 684 | } | - | ||||||||||||||||||||||||||||||
| 685 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||||||||
| 686 | if (tabList.at(i).rightWidget == object) {
| 0 | ||||||||||||||||||||||||||||||
| 687 | tabToClose = i; | - | ||||||||||||||||||||||||||||||
| 688 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||
| 689 | } | - | ||||||||||||||||||||||||||||||
| 690 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
| 691 | } | - | ||||||||||||||||||||||||||||||
| 692 | if (tabToClose != -1)
| 0 | ||||||||||||||||||||||||||||||
| 693 | emit q->tabCloseRequested(tabToClose); never executed: q->tabCloseRequested(tabToClose); | 0 | ||||||||||||||||||||||||||||||
| 694 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
| 695 | - | |||||||||||||||||||||||||||||||
| 696 | void QTabBarPrivate::_q_scrollTabs() | - | ||||||||||||||||||||||||||||||
| 697 | { | - | ||||||||||||||||||||||||||||||
| 698 | Q_Q(QTabBar); | - | ||||||||||||||||||||||||||||||
| 699 | const QObject *sender = q->sender(); | - | ||||||||||||||||||||||||||||||
| 700 | int i = -1; | - | ||||||||||||||||||||||||||||||
| 701 | if (!verticalTabs(shape)) {
| 0 | ||||||||||||||||||||||||||||||
| 702 | if (sender == leftB) {
| 0 | ||||||||||||||||||||||||||||||
| 703 | for (i = tabList.count() - 1; i >= 0; --i) {
| 0 | ||||||||||||||||||||||||||||||
| 704 | if (tabList.at(i).rect.left() - scrollOffset < 0) {
| 0 | ||||||||||||||||||||||||||||||
| 705 | makeVisible(i); | - | ||||||||||||||||||||||||||||||
| 706 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||
| 707 | } | - | ||||||||||||||||||||||||||||||
| 708 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
| 709 | } else if (sender == rightB) { never executed: end of block
| 0 | ||||||||||||||||||||||||||||||
| 710 | int availableWidth = q->width() - extraWidth(); | - | ||||||||||||||||||||||||||||||
| 711 | for (i = 0; i < tabList.count(); ++i) {
| 0 | ||||||||||||||||||||||||||||||
| 712 | if (tabList.at(i).rect.right() - scrollOffset > availableWidth) {
| 0 | ||||||||||||||||||||||||||||||
| 713 | makeVisible(i); | - | ||||||||||||||||||||||||||||||
| 714 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||
| 715 | } | - | ||||||||||||||||||||||||||||||
| 716 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
| 717 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
| 718 | } else { // vertical never executed: end of block | 0 | ||||||||||||||||||||||||||||||
| 719 | if (sender == leftB) {
| 0 | ||||||||||||||||||||||||||||||
| 720 | for (i = tabList.count() - 1; i >= 0; --i) {
| 0 | ||||||||||||||||||||||||||||||
| 721 | if (tabList.at(i).rect.top() - scrollOffset < 0) {
| 0 | ||||||||||||||||||||||||||||||
| 722 | makeVisible(i); | - | ||||||||||||||||||||||||||||||
| 723 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||
| 724 | } | - | ||||||||||||||||||||||||||||||
| 725 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
| 726 | } else if (sender == rightB) { never executed: end of block
| 0 | ||||||||||||||||||||||||||||||
| 727 | int available = q->height() - extraWidth(); | - | ||||||||||||||||||||||||||||||
| 728 | for (i = 0; i < tabList.count(); ++i) {
| 0 | ||||||||||||||||||||||||||||||
| 729 | if (tabList.at(i).rect.bottom() - scrollOffset > available) {
| 0 | ||||||||||||||||||||||||||||||
| 730 | makeVisible(i); | - | ||||||||||||||||||||||||||||||
| 731 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||
| 732 | } | - | ||||||||||||||||||||||||||||||
| 733 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
| 734 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
| 735 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
| 736 | } | - | ||||||||||||||||||||||||||||||
| 737 | - | |||||||||||||||||||||||||||||||
| 738 | void QTabBarPrivate::refresh() | - | ||||||||||||||||||||||||||||||
| 739 | { | - | ||||||||||||||||||||||||||||||
| 740 | Q_Q(QTabBar); | - | ||||||||||||||||||||||||||||||
| 741 | - | |||||||||||||||||||||||||||||||
| 742 | // be safe in case a subclass is also handling move with the tabs | - | ||||||||||||||||||||||||||||||
| 743 | if (pressedIndex != -1
| 0 | ||||||||||||||||||||||||||||||
| 744 | && movable
| 0 | ||||||||||||||||||||||||||||||
| 745 | && QApplication::mouseButtons() == Qt::NoButton) {
| 0 | ||||||||||||||||||||||||||||||
| 746 | moveTabFinished(pressedIndex); | - | ||||||||||||||||||||||||||||||
| 747 | if (!validIndex(pressedIndex))
| 0 | ||||||||||||||||||||||||||||||
| 748 | pressedIndex = -1; never executed: pressedIndex = -1; | 0 | ||||||||||||||||||||||||||||||
| 749 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
| 750 | - | |||||||||||||||||||||||||||||||
| 751 | if (!q->isVisible()) {
| 0 | ||||||||||||||||||||||||||||||
| 752 | layoutDirty = true; | - | ||||||||||||||||||||||||||||||
| 753 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||||||||
| 754 | layoutTabs(); | - | ||||||||||||||||||||||||||||||
| 755 | makeVisible(currentIndex); | - | ||||||||||||||||||||||||||||||
| 756 | q->update(); | - | ||||||||||||||||||||||||||||||
| 757 | q->updateGeometry(); | - | ||||||||||||||||||||||||||||||
| 758 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
| 759 | } | - | ||||||||||||||||||||||||||||||
| 760 | - | |||||||||||||||||||||||||||||||
| 761 | /*! | - | ||||||||||||||||||||||||||||||
| 762 | Creates a new tab bar with the given \a parent. | - | ||||||||||||||||||||||||||||||
| 763 | */ | - | ||||||||||||||||||||||||||||||
| 764 | QTabBar::QTabBar(QWidget* parent) | - | ||||||||||||||||||||||||||||||
| 765 | :QWidget(*new QTabBarPrivate, parent, 0) | - | ||||||||||||||||||||||||||||||
| 766 | { | - | ||||||||||||||||||||||||||||||
| 767 | Q_D(QTabBar); | - | ||||||||||||||||||||||||||||||
| 768 | d->init(); | - | ||||||||||||||||||||||||||||||
| 769 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
| 770 | - | |||||||||||||||||||||||||||||||
| 771 | - | |||||||||||||||||||||||||||||||
| 772 | /*! | - | ||||||||||||||||||||||||||||||
| 773 | Destroys the tab bar. | - | ||||||||||||||||||||||||||||||
| 774 | */ | - | ||||||||||||||||||||||||||||||
| 775 | QTabBar::~QTabBar() | - | ||||||||||||||||||||||||||||||
| 776 | { | - | ||||||||||||||||||||||||||||||
| 777 | } | - | ||||||||||||||||||||||||||||||
| 778 | - | |||||||||||||||||||||||||||||||
| 779 | /*! | - | ||||||||||||||||||||||||||||||
| 780 | \property QTabBar::shape | - | ||||||||||||||||||||||||||||||
| 781 | \brief the shape of the tabs in the tab bar | - | ||||||||||||||||||||||||||||||
| 782 | - | |||||||||||||||||||||||||||||||
| 783 | Possible values for this property are described by the Shape enum. | - | ||||||||||||||||||||||||||||||
| 784 | */ | - | ||||||||||||||||||||||||||||||
| 785 | - | |||||||||||||||||||||||||||||||
| 786 | - | |||||||||||||||||||||||||||||||
| 787 | QTabBar::Shape QTabBar::shape() const | - | ||||||||||||||||||||||||||||||
| 788 | { | - | ||||||||||||||||||||||||||||||
| 789 | Q_D(const QTabBar); | - | ||||||||||||||||||||||||||||||
| 790 | return d->shape; never executed: return d->shape; | 0 | ||||||||||||||||||||||||||||||
| 791 | } | - | ||||||||||||||||||||||||||||||
| 792 | - | |||||||||||||||||||||||||||||||
| 793 | void QTabBar::setShape(Shape shape) | - | ||||||||||||||||||||||||||||||
| 794 | { | - | ||||||||||||||||||||||||||||||
| 795 | Q_D(QTabBar); | - | ||||||||||||||||||||||||||||||
| 796 | if (d->shape == shape)
| 0 | ||||||||||||||||||||||||||||||
| 797 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||
| 798 | d->shape = shape; | - | ||||||||||||||||||||||||||||||
| 799 | d->refresh(); | - | ||||||||||||||||||||||||||||||
| 800 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
| 801 | - | |||||||||||||||||||||||||||||||
| 802 | /*! | - | ||||||||||||||||||||||||||||||
| 803 | \property QTabBar::drawBase | - | ||||||||||||||||||||||||||||||
| 804 | \brief defines whether or not tab bar should draw its base. | - | ||||||||||||||||||||||||||||||
| 805 | - | |||||||||||||||||||||||||||||||
| 806 | If true then QTabBar draws a base in relation to the styles overlab. | - | ||||||||||||||||||||||||||||||
| 807 | Otherwise only the tabs are drawn. | - | ||||||||||||||||||||||||||||||
| 808 | - | |||||||||||||||||||||||||||||||
| 809 | \sa QStyle::pixelMetric(), QStyle::PM_TabBarBaseOverlap, QStyleOptionTabBarBase | - | ||||||||||||||||||||||||||||||
| 810 | */ | - | ||||||||||||||||||||||||||||||
| 811 | - | |||||||||||||||||||||||||||||||
| 812 | void QTabBar::setDrawBase(bool drawBase) | - | ||||||||||||||||||||||||||||||
| 813 | { | - | ||||||||||||||||||||||||||||||
| 814 | Q_D(QTabBar); | - | ||||||||||||||||||||||||||||||
| 815 | if (d->drawBase == drawBase)
| 0 | ||||||||||||||||||||||||||||||
| 816 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||
| 817 | d->drawBase = drawBase; | - | ||||||||||||||||||||||||||||||
| 818 | update(); | - | ||||||||||||||||||||||||||||||
| 819 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
| 820 | - | |||||||||||||||||||||||||||||||
| 821 | bool QTabBar::drawBase() const | - | ||||||||||||||||||||||||||||||
| 822 | { | - | ||||||||||||||||||||||||||||||
| 823 | Q_D(const QTabBar); | - | ||||||||||||||||||||||||||||||
| 824 | return d->drawBase; never executed: return d->drawBase; | 0 | ||||||||||||||||||||||||||||||
| 825 | } | - | ||||||||||||||||||||||||||||||
| 826 | - | |||||||||||||||||||||||||||||||
| 827 | /*! | - | ||||||||||||||||||||||||||||||
| 828 | Adds a new tab with text \a text. Returns the new | - | ||||||||||||||||||||||||||||||
| 829 | tab's index. | - | ||||||||||||||||||||||||||||||
| 830 | */ | - | ||||||||||||||||||||||||||||||
| 831 | int QTabBar::addTab(const QString &text) | - | ||||||||||||||||||||||||||||||
| 832 | { | - | ||||||||||||||||||||||||||||||
| 833 | return insertTab(-1, text); never executed: return insertTab(-1, text); | 0 | ||||||||||||||||||||||||||||||
| 834 | } | - | ||||||||||||||||||||||||||||||
| 835 | - | |||||||||||||||||||||||||||||||
| 836 | /*! | - | ||||||||||||||||||||||||||||||
| 837 | \overload | - | ||||||||||||||||||||||||||||||
| 838 | - | |||||||||||||||||||||||||||||||
| 839 | Adds a new tab with icon \a icon and text \a | - | ||||||||||||||||||||||||||||||
| 840 | text. Returns the new tab's index. | - | ||||||||||||||||||||||||||||||
| 841 | */ | - | ||||||||||||||||||||||||||||||
| 842 | int QTabBar::addTab(const QIcon& icon, const QString &text) | - | ||||||||||||||||||||||||||||||
| 843 | { | - | ||||||||||||||||||||||||||||||
| 844 | return insertTab(-1, icon, text); never executed: return insertTab(-1, icon, text); | 0 | ||||||||||||||||||||||||||||||
| 845 | } | - | ||||||||||||||||||||||||||||||
| 846 | - | |||||||||||||||||||||||||||||||
| 847 | /*! | - | ||||||||||||||||||||||||||||||
| 848 | Inserts a new tab with text \a text at position \a index. If \a | - | ||||||||||||||||||||||||||||||
| 849 | index is out of range, the new tab is appened. Returns the new | - | ||||||||||||||||||||||||||||||
| 850 | tab's index. | - | ||||||||||||||||||||||||||||||
| 851 | */ | - | ||||||||||||||||||||||||||||||
| 852 | int QTabBar::insertTab(int index, const QString &text) | - | ||||||||||||||||||||||||||||||
| 853 | { | - | ||||||||||||||||||||||||||||||
| 854 | return insertTab(index, QIcon(), text); never executed: return insertTab(index, QIcon(), text); | 0 | ||||||||||||||||||||||||||||||
| 855 | } | - | ||||||||||||||||||||||||||||||
| 856 | - | |||||||||||||||||||||||||||||||
| 857 | /*!\overload | - | ||||||||||||||||||||||||||||||
| 858 | - | |||||||||||||||||||||||||||||||
| 859 | Inserts a new tab with icon \a icon and text \a text at position | - | ||||||||||||||||||||||||||||||
| 860 | \a index. If \a index is out of range, the new tab is | - | ||||||||||||||||||||||||||||||
| 861 | appended. Returns the new tab's index. | - | ||||||||||||||||||||||||||||||
| 862 | - | |||||||||||||||||||||||||||||||
| 863 | If the QTabBar was empty before this function is called, the inserted tab | - | ||||||||||||||||||||||||||||||
| 864 | becomes the current tab. | - | ||||||||||||||||||||||||||||||
| 865 | - | |||||||||||||||||||||||||||||||
| 866 | Inserting a new tab at an index less than or equal to the current index | - | ||||||||||||||||||||||||||||||
| 867 | will increment the current index, but keep the current tab. | - | ||||||||||||||||||||||||||||||
| 868 | */ | - | ||||||||||||||||||||||||||||||
| 869 | int QTabBar::insertTab(int index, const QIcon& icon, const QString &text) | - | ||||||||||||||||||||||||||||||
| 870 | { | - | ||||||||||||||||||||||||||||||
| 871 | Q_D(QTabBar); | - | ||||||||||||||||||||||||||||||
| 872 | if (!d->validIndex(index)) {
| 0 | ||||||||||||||||||||||||||||||
| 873 | index = d->tabList.count(); | - | ||||||||||||||||||||||||||||||
| 874 | d->tabList.append(QTabBarPrivate::Tab(icon, text)); | - | ||||||||||||||||||||||||||||||
| 875 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||||||||
| 876 | d->tabList.insert(index, QTabBarPrivate::Tab(icon, text)); | - | ||||||||||||||||||||||||||||||
| 877 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
| 878 | #ifndef QT_NO_SHORTCUT | - | ||||||||||||||||||||||||||||||
| 879 | d->tabList[index].shortcutId = grabShortcut(QKeySequence::mnemonic(text)); | - | ||||||||||||||||||||||||||||||
| 880 | #endif | - | ||||||||||||||||||||||||||||||
| 881 | d->refresh(); | - | ||||||||||||||||||||||||||||||
| 882 | if (d->tabList.count() == 1)
| 0 | ||||||||||||||||||||||||||||||
| 883 | setCurrentIndex(index); never executed: setCurrentIndex(index); | 0 | ||||||||||||||||||||||||||||||
| 884 | else if (index <= d->currentIndex)
| 0 | ||||||||||||||||||||||||||||||
| 885 | ++d->currentIndex; never executed: ++d->currentIndex; | 0 | ||||||||||||||||||||||||||||||
| 886 | - | |||||||||||||||||||||||||||||||
| 887 | if (d->closeButtonOnTabs) {
| 0 | ||||||||||||||||||||||||||||||
| 888 | QStyleOptionTab opt; | - | ||||||||||||||||||||||||||||||
| 889 | initStyleOption(&opt, index); | - | ||||||||||||||||||||||||||||||
| 890 | ButtonPosition closeSide = (ButtonPosition)style()->styleHint(QStyle::SH_TabBar_CloseButtonPosition, 0, this); | - | ||||||||||||||||||||||||||||||
| 891 | QAbstractButton *closeButton = new CloseButton(this); | - | ||||||||||||||||||||||||||||||
| 892 | connect(closeButton, SIGNAL(clicked()), this, SLOT(_q_closeTab())); | - | ||||||||||||||||||||||||||||||
| 893 | setTabButton(index, closeSide, closeButton); | - | ||||||||||||||||||||||||||||||
| 894 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
| 895 | - | |||||||||||||||||||||||||||||||
| 896 | for (int i = 0; i < d->tabList.count(); ++i) {
| 0 | ||||||||||||||||||||||||||||||
| 897 | if (d->tabList[i].lastTab >= index)
| 0 | ||||||||||||||||||||||||||||||
| 898 | ++d->tabList[i].lastTab; never executed: ++d->tabList[i].lastTab; | 0 | ||||||||||||||||||||||||||||||
| 899 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
| 900 | - | |||||||||||||||||||||||||||||||
| 901 | tabInserted(index); | - | ||||||||||||||||||||||||||||||
| 902 | d->autoHideTabs(); | - | ||||||||||||||||||||||||||||||
| 903 | return index; never executed: return index; | 0 | ||||||||||||||||||||||||||||||
| 904 | } | - | ||||||||||||||||||||||||||||||
| 905 | - | |||||||||||||||||||||||||||||||
| 906 | - | |||||||||||||||||||||||||||||||
| 907 | /*! | - | ||||||||||||||||||||||||||||||
| 908 | Removes the tab at position \a index. | - | ||||||||||||||||||||||||||||||
| 909 | - | |||||||||||||||||||||||||||||||
| 910 | \sa SelectionBehavior | - | ||||||||||||||||||||||||||||||
| 911 | */ | - | ||||||||||||||||||||||||||||||
| 912 | void QTabBar::removeTab(int index) | - | ||||||||||||||||||||||||||||||
| 913 | { | - | ||||||||||||||||||||||||||||||
| 914 | Q_D(QTabBar); | - | ||||||||||||||||||||||||||||||
| 915 | if (d->validIndex(index)) {
| 0 | ||||||||||||||||||||||||||||||
| 916 | if (d->dragInProgress)
| 0 | ||||||||||||||||||||||||||||||
| 917 | d->moveTabFinished(d->pressedIndex); never executed: d->moveTabFinished(d->pressedIndex); | 0 | ||||||||||||||||||||||||||||||
| 918 | - | |||||||||||||||||||||||||||||||
| 919 | #ifndef QT_NO_SHORTCUT | - | ||||||||||||||||||||||||||||||
| 920 | releaseShortcut(d->tabList.at(index).shortcutId); | - | ||||||||||||||||||||||||||||||
| 921 | #endif | - | ||||||||||||||||||||||||||||||
| 922 | if (d->tabList[index].leftWidget) {
| 0 | ||||||||||||||||||||||||||||||
| 923 | d->tabList[index].leftWidget->hide(); | - | ||||||||||||||||||||||||||||||
| 924 | d->tabList[index].leftWidget->deleteLater(); | - | ||||||||||||||||||||||||||||||
| 925 | d->tabList[index].leftWidget = 0; | - | ||||||||||||||||||||||||||||||
| 926 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
| 927 | if (d->tabList[index].rightWidget) {
| 0 | ||||||||||||||||||||||||||||||
| 928 | d->tabList[index].rightWidget->hide(); | - | ||||||||||||||||||||||||||||||
| 929 | d->tabList[index].rightWidget->deleteLater(); | - | ||||||||||||||||||||||||||||||
| 930 | d->tabList[index].rightWidget = 0; | - | ||||||||||||||||||||||||||||||
| 931 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
| 932 | - | |||||||||||||||||||||||||||||||
| 933 | int newIndex = d->tabList[index].lastTab; | - | ||||||||||||||||||||||||||||||
| 934 | d->tabList.removeAt(index); | - | ||||||||||||||||||||||||||||||
| 935 | for (int i = 0; i < d->tabList.count(); ++i) {
| 0 | ||||||||||||||||||||||||||||||
| 936 | if (d->tabList[i].lastTab == index)
| 0 | ||||||||||||||||||||||||||||||
| 937 | d->tabList[i].lastTab = -1; never executed: d->tabList[i].lastTab = -1; | 0 | ||||||||||||||||||||||||||||||
| 938 | if (d->tabList[i].lastTab > index)
| 0 | ||||||||||||||||||||||||||||||
| 939 | --d->tabList[i].lastTab; never executed: --d->tabList[i].lastTab; | 0 | ||||||||||||||||||||||||||||||
| 940 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
| 941 | if (index == d->currentIndex) {
| 0 | ||||||||||||||||||||||||||||||
| 942 | // The current tab is going away, in order to make sure | - | ||||||||||||||||||||||||||||||
| 943 | // we emit that "current has changed", we need to reset this | - | ||||||||||||||||||||||||||||||
| 944 | // around. | - | ||||||||||||||||||||||||||||||
| 945 | d->currentIndex = -1; | - | ||||||||||||||||||||||||||||||
| 946 | if (d->tabList.size() > 0) {
| 0 | ||||||||||||||||||||||||||||||
| 947 | switch(d->selectionBehaviorOnRemove) { | - | ||||||||||||||||||||||||||||||
| 948 | case SelectPreviousTab: never executed: case SelectPreviousTab: | 0 | ||||||||||||||||||||||||||||||
| 949 | if (newIndex > index)
| 0 | ||||||||||||||||||||||||||||||
| 950 | newIndex--; never executed: newIndex--; | 0 | ||||||||||||||||||||||||||||||
| 951 | if (d->validIndex(newIndex))
| 0 | ||||||||||||||||||||||||||||||
| 952 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||
| 953 | // else fallthrough | - | ||||||||||||||||||||||||||||||
| 954 | case SelectRightTab: code before this statement never executed: case SelectRightTab:never executed: case SelectRightTab: | 0 | ||||||||||||||||||||||||||||||
| 955 | newIndex = index; | - | ||||||||||||||||||||||||||||||
| 956 | if (newIndex >= d->tabList.size())
| 0 | ||||||||||||||||||||||||||||||
| 957 | newIndex = d->tabList.size() - 1; never executed: newIndex = d->tabList.size() - 1; | 0 | ||||||||||||||||||||||||||||||
| 958 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||
| 959 | case SelectLeftTab: never executed: case SelectLeftTab: | 0 | ||||||||||||||||||||||||||||||
| 960 | newIndex = index - 1; | - | ||||||||||||||||||||||||||||||
| 961 | if (newIndex < 0)
| 0 | ||||||||||||||||||||||||||||||
| 962 | newIndex = 0; never executed: newIndex = 0; | 0 | ||||||||||||||||||||||||||||||
| 963 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||
| 964 | default: never executed: default: | 0 | ||||||||||||||||||||||||||||||
| 965 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||
| 966 | } | - | ||||||||||||||||||||||||||||||
| 967 | - | |||||||||||||||||||||||||||||||
| 968 | if (d->validIndex(newIndex)) {
| 0 | ||||||||||||||||||||||||||||||
| 969 | // don't loose newIndex's old through setCurrentIndex | - | ||||||||||||||||||||||||||||||
| 970 | int bump = d->tabList[newIndex].lastTab; | - | ||||||||||||||||||||||||||||||
| 971 | setCurrentIndex(newIndex); | - | ||||||||||||||||||||||||||||||
| 972 | d->tabList[newIndex].lastTab = bump; | - | ||||||||||||||||||||||||||||||
| 973 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
| 974 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||||||||
| 975 | emit currentChanged(-1); | - | ||||||||||||||||||||||||||||||
| 976 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
| 977 | } else if (index < d->currentIndex) {
| 0 | ||||||||||||||||||||||||||||||
| 978 | setCurrentIndex(d->currentIndex - 1); | - | ||||||||||||||||||||||||||||||
| 979 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
| 980 | d->refresh(); | - | ||||||||||||||||||||||||||||||
| 981 | d->autoHideTabs(); | - | ||||||||||||||||||||||||||||||
| 982 | tabRemoved(index); | - | ||||||||||||||||||||||||||||||
| 983 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
| 984 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
| 985 | - | |||||||||||||||||||||||||||||||
| 986 | - | |||||||||||||||||||||||||||||||
| 987 | /*! | - | ||||||||||||||||||||||||||||||
| 988 | Returns \c true if the tab at position \a index is enabled; otherwise | - | ||||||||||||||||||||||||||||||
| 989 | returns \c false. | - | ||||||||||||||||||||||||||||||
| 990 | */ | - | ||||||||||||||||||||||||||||||
| 991 | bool QTabBar::isTabEnabled(int index) const | - | ||||||||||||||||||||||||||||||
| 992 | { | - | ||||||||||||||||||||||||||||||
| 993 | Q_D(const QTabBar); | - | ||||||||||||||||||||||||||||||
| 994 | if (const QTabBarPrivate::Tab *tab = d->at(index))
| 0 | ||||||||||||||||||||||||||||||
| 995 | return tab->enabled; never executed: return tab->enabled; | 0 | ||||||||||||||||||||||||||||||
| 996 | return false; never executed: return false; | 0 | ||||||||||||||||||||||||||||||
| 997 | } | - | ||||||||||||||||||||||||||||||
| 998 | - | |||||||||||||||||||||||||||||||
| 999 | /*! | - | ||||||||||||||||||||||||||||||
| 1000 | If \a enabled is true then the tab at position \a index is | - | ||||||||||||||||||||||||||||||
| 1001 | enabled; otherwise the item at position \a index is disabled. | - | ||||||||||||||||||||||||||||||
| 1002 | */ | - | ||||||||||||||||||||||||||||||
| 1003 | void QTabBar::setTabEnabled(int index, bool enabled) | - | ||||||||||||||||||||||||||||||
| 1004 | { | - | ||||||||||||||||||||||||||||||
| 1005 | Q_D(QTabBar); | - | ||||||||||||||||||||||||||||||
| 1006 | if (QTabBarPrivate::Tab *tab = d->at(index)) {
| 0 | ||||||||||||||||||||||||||||||
| 1007 | tab->enabled = enabled; | - | ||||||||||||||||||||||||||||||
| 1008 | #ifndef QT_NO_SHORTCUT | - | ||||||||||||||||||||||||||||||
| 1009 | setShortcutEnabled(tab->shortcutId, enabled); | - | ||||||||||||||||||||||||||||||
| 1010 | #endif | - | ||||||||||||||||||||||||||||||
| 1011 | update(); | - | ||||||||||||||||||||||||||||||
| 1012 | if (!enabled && index == d->currentIndex)
| 0 | ||||||||||||||||||||||||||||||
| 1013 | setCurrentIndex(d->validIndex(index+1)?index+1:0); never executed: setCurrentIndex(d->validIndex(index+1)?index+1:0); | 0 | ||||||||||||||||||||||||||||||
| 1014 | else if (enabled && !d->validIndex(d->currentIndex))
| 0 | ||||||||||||||||||||||||||||||
| 1015 | setCurrentIndex(index); never executed: setCurrentIndex(index); | 0 | ||||||||||||||||||||||||||||||
| 1016 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
| 1017 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
| 1018 | - | |||||||||||||||||||||||||||||||
| 1019 | - | |||||||||||||||||||||||||||||||
| 1020 | /*! | - | ||||||||||||||||||||||||||||||
| 1021 | Returns the text of the tab at position \a index, or an empty | - | ||||||||||||||||||||||||||||||
| 1022 | string if \a index is out of range. | - | ||||||||||||||||||||||||||||||
| 1023 | */ | - | ||||||||||||||||||||||||||||||
| 1024 | QString QTabBar::tabText(int index) const | - | ||||||||||||||||||||||||||||||
| 1025 | { | - | ||||||||||||||||||||||||||||||
| 1026 | Q_D(const QTabBar); | - | ||||||||||||||||||||||||||||||
| 1027 | if (const QTabBarPrivate::Tab *tab = d->at(index))
| 0 | ||||||||||||||||||||||||||||||
| 1028 | return tab->text; never executed: return tab->text; | 0 | ||||||||||||||||||||||||||||||
| 1029 | return QString(); never executed: return QString(); | 0 | ||||||||||||||||||||||||||||||
| 1030 | } | - | ||||||||||||||||||||||||||||||
| 1031 | - | |||||||||||||||||||||||||||||||
| 1032 | /*! | - | ||||||||||||||||||||||||||||||
| 1033 | Sets the text of the tab at position \a index to \a text. | - | ||||||||||||||||||||||||||||||
| 1034 | */ | - | ||||||||||||||||||||||||||||||
| 1035 | void QTabBar::setTabText(int index, const QString &text) | - | ||||||||||||||||||||||||||||||
| 1036 | { | - | ||||||||||||||||||||||||||||||
| 1037 | Q_D(QTabBar); | - | ||||||||||||||||||||||||||||||
| 1038 | if (QTabBarPrivate::Tab *tab = d->at(index)) {
| 0 | ||||||||||||||||||||||||||||||
| 1039 | d->textSizes.remove(tab->text); | - | ||||||||||||||||||||||||||||||
| 1040 | tab->text = text; | - | ||||||||||||||||||||||||||||||
| 1041 | #ifndef QT_NO_SHORTCUT | - | ||||||||||||||||||||||||||||||
| 1042 | releaseShortcut(tab->shortcutId); | - | ||||||||||||||||||||||||||||||
| 1043 | tab->shortcutId = grabShortcut(QKeySequence::mnemonic(text)); | - | ||||||||||||||||||||||||||||||
| 1044 | setShortcutEnabled(tab->shortcutId, tab->enabled); | - | ||||||||||||||||||||||||||||||
| 1045 | #endif | - | ||||||||||||||||||||||||||||||
| 1046 | d->refresh(); | - | ||||||||||||||||||||||||||||||
| 1047 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
| 1048 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
| 1049 | - | |||||||||||||||||||||||||||||||
| 1050 | /*! | - | ||||||||||||||||||||||||||||||
| 1051 | Returns the text color of the tab with the given \a index, or a invalid | - | ||||||||||||||||||||||||||||||
| 1052 | color if \a index is out of range. | - | ||||||||||||||||||||||||||||||
| 1053 | - | |||||||||||||||||||||||||||||||
| 1054 | \sa setTabTextColor() | - | ||||||||||||||||||||||||||||||
| 1055 | */ | - | ||||||||||||||||||||||||||||||
| 1056 | QColor QTabBar::tabTextColor(int index) const | - | ||||||||||||||||||||||||||||||
| 1057 | { | - | ||||||||||||||||||||||||||||||
| 1058 | Q_D(const QTabBar); | - | ||||||||||||||||||||||||||||||
| 1059 | if (const QTabBarPrivate::Tab *tab = d->at(index))
| 0 | ||||||||||||||||||||||||||||||
| 1060 | return tab->textColor; never executed: return tab->textColor; | 0 | ||||||||||||||||||||||||||||||
| 1061 | return QColor(); never executed: return QColor(); | 0 | ||||||||||||||||||||||||||||||
| 1062 | } | - | ||||||||||||||||||||||||||||||
| 1063 | - | |||||||||||||||||||||||||||||||
| 1064 | /*! | - | ||||||||||||||||||||||||||||||
| 1065 | Sets the color of the text in the tab with the given \a index to the specified \a color. | - | ||||||||||||||||||||||||||||||
| 1066 | - | |||||||||||||||||||||||||||||||
| 1067 | If an invalid color is specified, the tab will use the QTabBar foreground role instead. | - | ||||||||||||||||||||||||||||||
| 1068 | - | |||||||||||||||||||||||||||||||
| 1069 | \sa tabTextColor() | - | ||||||||||||||||||||||||||||||
| 1070 | */ | - | ||||||||||||||||||||||||||||||
| 1071 | void QTabBar::setTabTextColor(int index, const QColor &color) | - | ||||||||||||||||||||||||||||||
| 1072 | { | - | ||||||||||||||||||||||||||||||
| 1073 | Q_D(QTabBar); | - | ||||||||||||||||||||||||||||||
| 1074 | if (QTabBarPrivate::Tab *tab = d->at(index)) {
| 0 | ||||||||||||||||||||||||||||||
| 1075 | tab->textColor = color; | - | ||||||||||||||||||||||||||||||
| 1076 | update(tabRect(index)); | - | ||||||||||||||||||||||||||||||
| 1077 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
| 1078 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
| 1079 | - | |||||||||||||||||||||||||||||||
| 1080 | /*! | - | ||||||||||||||||||||||||||||||
| 1081 | Returns the icon of the tab at position \a index, or a null icon | - | ||||||||||||||||||||||||||||||
| 1082 | if \a index is out of range. | - | ||||||||||||||||||||||||||||||
| 1083 | */ | - | ||||||||||||||||||||||||||||||
| 1084 | QIcon QTabBar::tabIcon(int index) const | - | ||||||||||||||||||||||||||||||
| 1085 | { | - | ||||||||||||||||||||||||||||||
| 1086 | Q_D(const QTabBar); | - | ||||||||||||||||||||||||||||||
| 1087 | if (const QTabBarPrivate::Tab *tab = d->at(index))
| 0 | ||||||||||||||||||||||||||||||
| 1088 | return tab->icon; never executed: return tab->icon; | 0 | ||||||||||||||||||||||||||||||
| 1089 | return QIcon(); never executed: return QIcon(); | 0 | ||||||||||||||||||||||||||||||
| 1090 | } | - | ||||||||||||||||||||||||||||||
| 1091 | - | |||||||||||||||||||||||||||||||
| 1092 | /*! | - | ||||||||||||||||||||||||||||||
| 1093 | Sets the icon of the tab at position \a index to \a icon. | - | ||||||||||||||||||||||||||||||
| 1094 | */ | - | ||||||||||||||||||||||||||||||
| 1095 | void QTabBar::setTabIcon(int index, const QIcon & icon) | - | ||||||||||||||||||||||||||||||
| 1096 | { | - | ||||||||||||||||||||||||||||||
| 1097 | Q_D(QTabBar); | - | ||||||||||||||||||||||||||||||
| 1098 | if (QTabBarPrivate::Tab *tab = d->at(index)) {
| 0 | ||||||||||||||||||||||||||||||
| 1099 | bool simpleIconChange = (!icon.isNull() && !tab->icon.isNull());
| 0 | ||||||||||||||||||||||||||||||
| 1100 | tab->icon = icon; | - | ||||||||||||||||||||||||||||||
| 1101 | if (simpleIconChange)
| 0 | ||||||||||||||||||||||||||||||
| 1102 | update(tabRect(index)); never executed: update(tabRect(index)); | 0 | ||||||||||||||||||||||||||||||
| 1103 | else | - | ||||||||||||||||||||||||||||||
| 1104 | d->refresh(); never executed: d->refresh(); | 0 | ||||||||||||||||||||||||||||||
| 1105 | } | - | ||||||||||||||||||||||||||||||
| 1106 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
| 1107 | - | |||||||||||||||||||||||||||||||
| 1108 | #ifndef QT_NO_TOOLTIP | - | ||||||||||||||||||||||||||||||
| 1109 | /*! | - | ||||||||||||||||||||||||||||||
| 1110 | Sets the tool tip of the tab at position \a index to \a tip. | - | ||||||||||||||||||||||||||||||
| 1111 | */ | - | ||||||||||||||||||||||||||||||
| 1112 | void QTabBar::setTabToolTip(int index, const QString & tip) | - | ||||||||||||||||||||||||||||||
| 1113 | { | - | ||||||||||||||||||||||||||||||
| 1114 | Q_D(QTabBar); | - | ||||||||||||||||||||||||||||||
| 1115 | if (QTabBarPrivate::Tab *tab = d->at(index))
| 0 | ||||||||||||||||||||||||||||||
| 1116 | tab->toolTip = tip; never executed: tab->toolTip = tip; | 0 | ||||||||||||||||||||||||||||||
| 1117 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
| 1118 | - | |||||||||||||||||||||||||||||||
| 1119 | /*! | - | ||||||||||||||||||||||||||||||
| 1120 | Returns the tool tip of the tab at position \a index, or an empty | - | ||||||||||||||||||||||||||||||
| 1121 | string if \a index is out of range. | - | ||||||||||||||||||||||||||||||
| 1122 | */ | - | ||||||||||||||||||||||||||||||
| 1123 | QString QTabBar::tabToolTip(int index) const | - | ||||||||||||||||||||||||||||||
| 1124 | { | - | ||||||||||||||||||||||||||||||
| 1125 | Q_D(const QTabBar); | - | ||||||||||||||||||||||||||||||
| 1126 | if (const QTabBarPrivate::Tab *tab = d->at(index))
| 0 | ||||||||||||||||||||||||||||||
| 1127 | return tab->toolTip; never executed: return tab->toolTip; | 0 | ||||||||||||||||||||||||||||||
| 1128 | return QString(); never executed: return QString(); | 0 | ||||||||||||||||||||||||||||||
| 1129 | } | - | ||||||||||||||||||||||||||||||
| 1130 | #endif // QT_NO_TOOLTIP | - | ||||||||||||||||||||||||||||||
| 1131 | - | |||||||||||||||||||||||||||||||
| 1132 | #ifndef QT_NO_WHATSTHIS | - | ||||||||||||||||||||||||||||||
| 1133 | /*! | - | ||||||||||||||||||||||||||||||
| 1134 | \since 4.1 | - | ||||||||||||||||||||||||||||||
| 1135 | - | |||||||||||||||||||||||||||||||
| 1136 | Sets the What's This help text of the tab at position \a index | - | ||||||||||||||||||||||||||||||
| 1137 | to \a text. | - | ||||||||||||||||||||||||||||||
| 1138 | */ | - | ||||||||||||||||||||||||||||||
| 1139 | void QTabBar::setTabWhatsThis(int index, const QString &text) | - | ||||||||||||||||||||||||||||||
| 1140 | { | - | ||||||||||||||||||||||||||||||
| 1141 | Q_D(QTabBar); | - | ||||||||||||||||||||||||||||||
| 1142 | if (QTabBarPrivate::Tab *tab = d->at(index))
| 0 | ||||||||||||||||||||||||||||||
| 1143 | tab->whatsThis = text; never executed: tab->whatsThis = text; | 0 | ||||||||||||||||||||||||||||||
| 1144 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
| 1145 | - | |||||||||||||||||||||||||||||||
| 1146 | /*! | - | ||||||||||||||||||||||||||||||
| 1147 | \since 4.1 | - | ||||||||||||||||||||||||||||||
| 1148 | - | |||||||||||||||||||||||||||||||
| 1149 | Returns the What's This help text of the tab at position \a index, | - | ||||||||||||||||||||||||||||||
| 1150 | or an empty string if \a index is out of range. | - | ||||||||||||||||||||||||||||||
| 1151 | */ | - | ||||||||||||||||||||||||||||||
| 1152 | QString QTabBar::tabWhatsThis(int index) const | - | ||||||||||||||||||||||||||||||
| 1153 | { | - | ||||||||||||||||||||||||||||||
| 1154 | Q_D(const QTabBar); | - | ||||||||||||||||||||||||||||||
| 1155 | if (const QTabBarPrivate::Tab *tab = d->at(index))
| 0 | ||||||||||||||||||||||||||||||
| 1156 | return tab->whatsThis; never executed: return tab->whatsThis; | 0 | ||||||||||||||||||||||||||||||
| 1157 | return QString(); never executed: return QString(); | 0 | ||||||||||||||||||||||||||||||
| 1158 | } | - | ||||||||||||||||||||||||||||||
| 1159 | - | |||||||||||||||||||||||||||||||
| 1160 | #endif // QT_NO_WHATSTHIS | - | ||||||||||||||||||||||||||||||
| 1161 | - | |||||||||||||||||||||||||||||||
| 1162 | /*! | - | ||||||||||||||||||||||||||||||
| 1163 | Sets the data of the tab at position \a index to \a data. | - | ||||||||||||||||||||||||||||||
| 1164 | */ | - | ||||||||||||||||||||||||||||||
| 1165 | void QTabBar::setTabData(int index, const QVariant & data) | - | ||||||||||||||||||||||||||||||
| 1166 | { | - | ||||||||||||||||||||||||||||||
| 1167 | Q_D(QTabBar); | - | ||||||||||||||||||||||||||||||
| 1168 | if (QTabBarPrivate::Tab *tab = d->at(index))
| 0 | ||||||||||||||||||||||||||||||
| 1169 | tab->data = data; never executed: tab->data = data; | 0 | ||||||||||||||||||||||||||||||
| 1170 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
| 1171 | - | |||||||||||||||||||||||||||||||
| 1172 | /*! | - | ||||||||||||||||||||||||||||||
| 1173 | Returns the data of the tab at position \a index, or a null | - | ||||||||||||||||||||||||||||||
| 1174 | variant if \a index is out of range. | - | ||||||||||||||||||||||||||||||
| 1175 | */ | - | ||||||||||||||||||||||||||||||
| 1176 | QVariant QTabBar::tabData(int index) const | - | ||||||||||||||||||||||||||||||
| 1177 | { | - | ||||||||||||||||||||||||||||||
| 1178 | Q_D(const QTabBar); | - | ||||||||||||||||||||||||||||||
| 1179 | if (const QTabBarPrivate::Tab *tab = d->at(index))
| 0 | ||||||||||||||||||||||||||||||
| 1180 | return tab->data; never executed: return tab->data; | 0 | ||||||||||||||||||||||||||||||
| 1181 | return QVariant(); never executed: return QVariant(); | 0 | ||||||||||||||||||||||||||||||
| 1182 | } | - | ||||||||||||||||||||||||||||||
| 1183 | - | |||||||||||||||||||||||||||||||
| 1184 | /*! | - | ||||||||||||||||||||||||||||||
| 1185 | Returns the visual rectangle of the tab at position \a | - | ||||||||||||||||||||||||||||||
| 1186 | index, or a null rectangle if \a index is out of range. | - | ||||||||||||||||||||||||||||||
| 1187 | */ | - | ||||||||||||||||||||||||||||||
| 1188 | QRect QTabBar::tabRect(int index) const | - | ||||||||||||||||||||||||||||||
| 1189 | { | - | ||||||||||||||||||||||||||||||
| 1190 | Q_D(const QTabBar); | - | ||||||||||||||||||||||||||||||
| 1191 | if (const QTabBarPrivate::Tab *tab = d->at(index)) {
| 0 | ||||||||||||||||||||||||||||||
| 1192 | if (d->layoutDirty)
| 0 | ||||||||||||||||||||||||||||||
| 1193 | const_cast<QTabBarPrivate*>(d)->layoutTabs(); never executed: const_cast<QTabBarPrivate*>(d)->layoutTabs(); | 0 | ||||||||||||||||||||||||||||||
| 1194 | QRect r = tab->rect; | - | ||||||||||||||||||||||||||||||
| 1195 | if (verticalTabs(d->shape))
| 0 | ||||||||||||||||||||||||||||||
| 1196 | r.translate(0, -d->scrollOffset); never executed: r.translate(0, -d->scrollOffset); | 0 | ||||||||||||||||||||||||||||||
| 1197 | else | - | ||||||||||||||||||||||||||||||
| 1198 | r.translate(-d->scrollOffset, 0); never executed: r.translate(-d->scrollOffset, 0); | 0 | ||||||||||||||||||||||||||||||
| 1199 | if (!verticalTabs(d->shape))
| 0 | ||||||||||||||||||||||||||||||
| 1200 | r = QStyle::visualRect(layoutDirection(), rect(), r); never executed: r = QStyle::visualRect(layoutDirection(), rect(), r); | 0 | ||||||||||||||||||||||||||||||
| 1201 | return r; never executed: return r; | 0 | ||||||||||||||||||||||||||||||
| 1202 | } | - | ||||||||||||||||||||||||||||||
| 1203 | return QRect(); never executed: return QRect(); | 0 | ||||||||||||||||||||||||||||||
| 1204 | } | - | ||||||||||||||||||||||||||||||
| 1205 | - | |||||||||||||||||||||||||||||||
| 1206 | /*! | - | ||||||||||||||||||||||||||||||
| 1207 | \since 4.3 | - | ||||||||||||||||||||||||||||||
| 1208 | Returns the index of the tab that covers \a position or -1 if no | - | ||||||||||||||||||||||||||||||
| 1209 | tab covers \a position; | - | ||||||||||||||||||||||||||||||
| 1210 | */ | - | ||||||||||||||||||||||||||||||
| 1211 | - | |||||||||||||||||||||||||||||||
| 1212 | int QTabBar::tabAt(const QPoint &position) const | - | ||||||||||||||||||||||||||||||
| 1213 | { | - | ||||||||||||||||||||||||||||||
| 1214 | Q_D(const QTabBar); | - | ||||||||||||||||||||||||||||||
| 1215 | if (d->validIndex(d->currentIndex)
| 0 | ||||||||||||||||||||||||||||||
| 1216 | && tabRect(d->currentIndex).contains(position)) {
| 0 | ||||||||||||||||||||||||||||||
| 1217 | return d->currentIndex; never executed: return d->currentIndex; | 0 | ||||||||||||||||||||||||||||||
| 1218 | } | - | ||||||||||||||||||||||||||||||
| 1219 | const int max = d->tabList.size(); | - | ||||||||||||||||||||||||||||||
| 1220 | for (int i = 0; i < max; ++i) {
| 0 | ||||||||||||||||||||||||||||||
| 1221 | if (tabRect(i).contains(position)) {
| 0 | ||||||||||||||||||||||||||||||
| 1222 | return i; never executed: return i; | 0 | ||||||||||||||||||||||||||||||
| 1223 | } | - | ||||||||||||||||||||||||||||||
| 1224 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
| 1225 | return -1; never executed: return -1; | 0 | ||||||||||||||||||||||||||||||
| 1226 | } | - | ||||||||||||||||||||||||||||||
| 1227 | - | |||||||||||||||||||||||||||||||
| 1228 | /*! | - | ||||||||||||||||||||||||||||||
| 1229 | \property QTabBar::currentIndex | - | ||||||||||||||||||||||||||||||
| 1230 | \brief the index of the tab bar's visible tab | - | ||||||||||||||||||||||||||||||
| 1231 | - | |||||||||||||||||||||||||||||||
| 1232 | The current index is -1 if there is no current tab. | - | ||||||||||||||||||||||||||||||
| 1233 | */ | - | ||||||||||||||||||||||||||||||
| 1234 | - | |||||||||||||||||||||||||||||||
| 1235 | int QTabBar::currentIndex() const | - | ||||||||||||||||||||||||||||||
| 1236 | { | - | ||||||||||||||||||||||||||||||
| 1237 | Q_D(const QTabBar); | - | ||||||||||||||||||||||||||||||
| 1238 | if (d->validIndex(d->currentIndex))
| 0 | ||||||||||||||||||||||||||||||
| 1239 | return d->currentIndex; never executed: return d->currentIndex; | 0 | ||||||||||||||||||||||||||||||
| 1240 | return -1; never executed: return -1; | 0 | ||||||||||||||||||||||||||||||
| 1241 | } | - | ||||||||||||||||||||||||||||||
| 1242 | - | |||||||||||||||||||||||||||||||
| 1243 | - | |||||||||||||||||||||||||||||||
| 1244 | void QTabBar::setCurrentIndex(int index) | - | ||||||||||||||||||||||||||||||
| 1245 | { | - | ||||||||||||||||||||||||||||||
| 1246 | Q_D(QTabBar); | - | ||||||||||||||||||||||||||||||
| 1247 | if (d->dragInProgress && d->pressedIndex != -1)
| 0 | ||||||||||||||||||||||||||||||
| 1248 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||
| 1249 | - | |||||||||||||||||||||||||||||||
| 1250 | int oldIndex = d->currentIndex; | - | ||||||||||||||||||||||||||||||
| 1251 | if (d->validIndex(index) && d->currentIndex != index) {
| 0 | ||||||||||||||||||||||||||||||
| 1252 | d->currentIndex = index; | - | ||||||||||||||||||||||||||||||
| 1253 | update(); | - | ||||||||||||||||||||||||||||||
| 1254 | d->makeVisible(index); | - | ||||||||||||||||||||||||||||||
| 1255 | d->tabList[index].lastTab = oldIndex; | - | ||||||||||||||||||||||||||||||
| 1256 | if (oldIndex >= 0 && oldIndex < count())
| 0 | ||||||||||||||||||||||||||||||
| 1257 | d->layoutTab(oldIndex); never executed: d->layoutTab(oldIndex); | 0 | ||||||||||||||||||||||||||||||
| 1258 | d->layoutTab(index); | - | ||||||||||||||||||||||||||||||
| 1259 | #ifndef QT_NO_ACCESSIBILITY | - | ||||||||||||||||||||||||||||||
| 1260 | if (QAccessible::isActive()) {
| 0 | ||||||||||||||||||||||||||||||
| 1261 | if (hasFocus()) {
| 0 | ||||||||||||||||||||||||||||||
| 1262 | QAccessibleEvent focusEvent(this, QAccessible::Focus); | - | ||||||||||||||||||||||||||||||
| 1263 | focusEvent.setChild(index); | - | ||||||||||||||||||||||||||||||
| 1264 | QAccessible::updateAccessibility(&focusEvent); | - | ||||||||||||||||||||||||||||||
| 1265 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
| 1266 | QAccessibleEvent selectionEvent(this, QAccessible::Selection); | - | ||||||||||||||||||||||||||||||
| 1267 | selectionEvent.setChild(index); | - | ||||||||||||||||||||||||||||||
| 1268 | QAccessible::updateAccessibility(&selectionEvent); | - | ||||||||||||||||||||||||||||||
| 1269 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
| 1270 | #endif | - | ||||||||||||||||||||||||||||||
| 1271 | emit currentChanged(index); | - | ||||||||||||||||||||||||||||||
| 1272 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
| 1273 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
| 1274 | - | |||||||||||||||||||||||||||||||
| 1275 | /*! | - | ||||||||||||||||||||||||||||||
| 1276 | \property QTabBar::iconSize | - | ||||||||||||||||||||||||||||||
| 1277 | \brief The size for icons in the tab bar | - | ||||||||||||||||||||||||||||||
| 1278 | \since 4.1 | - | ||||||||||||||||||||||||||||||
| 1279 | - | |||||||||||||||||||||||||||||||
| 1280 | The default value is style-dependent. \c iconSize is a maximum | - | ||||||||||||||||||||||||||||||
| 1281 | size; icons that are smaller are not scaled up. | - | ||||||||||||||||||||||||||||||
| 1282 | - | |||||||||||||||||||||||||||||||
| 1283 | \sa QTabWidget::iconSize | - | ||||||||||||||||||||||||||||||
| 1284 | */ | - | ||||||||||||||||||||||||||||||
| 1285 | QSize QTabBar::iconSize() const | - | ||||||||||||||||||||||||||||||
| 1286 | { | - | ||||||||||||||||||||||||||||||
| 1287 | Q_D(const QTabBar); | - | ||||||||||||||||||||||||||||||
| 1288 | if (d->iconSize.isValid())
| 0 | ||||||||||||||||||||||||||||||
| 1289 | return d->iconSize; never executed: return d->iconSize; | 0 | ||||||||||||||||||||||||||||||
| 1290 | int iconExtent = style()->pixelMetric(QStyle::PM_TabBarIconSize, 0, this); | - | ||||||||||||||||||||||||||||||
| 1291 | return QSize(iconExtent, iconExtent); never executed: return QSize(iconExtent, iconExtent); | 0 | ||||||||||||||||||||||||||||||
| 1292 | - | |||||||||||||||||||||||||||||||
| 1293 | } | - | ||||||||||||||||||||||||||||||
| 1294 | - | |||||||||||||||||||||||||||||||
| 1295 | void QTabBar::setIconSize(const QSize &size) | - | ||||||||||||||||||||||||||||||
| 1296 | { | - | ||||||||||||||||||||||||||||||
| 1297 | Q_D(QTabBar); | - | ||||||||||||||||||||||||||||||
| 1298 | d->iconSize = size; | - | ||||||||||||||||||||||||||||||
| 1299 | d->layoutDirty = true; | - | ||||||||||||||||||||||||||||||
| 1300 | update(); | - | ||||||||||||||||||||||||||||||
| 1301 | updateGeometry(); | - | ||||||||||||||||||||||||||||||
| 1302 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
| 1303 | - | |||||||||||||||||||||||||||||||
| 1304 | /*! | - | ||||||||||||||||||||||||||||||
| 1305 | \property QTabBar::count | - | ||||||||||||||||||||||||||||||
| 1306 | \brief the number of tabs in the tab bar | - | ||||||||||||||||||||||||||||||
| 1307 | */ | - | ||||||||||||||||||||||||||||||
| 1308 | - | |||||||||||||||||||||||||||||||
| 1309 | int QTabBar::count() const | - | ||||||||||||||||||||||||||||||
| 1310 | { | - | ||||||||||||||||||||||||||||||
| 1311 | Q_D(const QTabBar); | - | ||||||||||||||||||||||||||||||
| 1312 | return d->tabList.count(); never executed: return d->tabList.count(); | 0 | ||||||||||||||||||||||||||||||
| 1313 | } | - | ||||||||||||||||||||||||||||||
| 1314 | - | |||||||||||||||||||||||||||||||
| 1315 | - | |||||||||||||||||||||||||||||||
| 1316 | /*!\reimp | - | ||||||||||||||||||||||||||||||
| 1317 | */ | - | ||||||||||||||||||||||||||||||
| 1318 | QSize QTabBar::sizeHint() const | - | ||||||||||||||||||||||||||||||
| 1319 | { | - | ||||||||||||||||||||||||||||||
| 1320 | Q_D(const QTabBar); | - | ||||||||||||||||||||||||||||||
| 1321 | if (d->layoutDirty)
| 0 | ||||||||||||||||||||||||||||||
| 1322 | const_cast<QTabBarPrivate*>(d)->layoutTabs(); never executed: const_cast<QTabBarPrivate*>(d)->layoutTabs(); | 0 | ||||||||||||||||||||||||||||||
| 1323 | QRect r; | - | ||||||||||||||||||||||||||||||
| 1324 | for (int i = 0; i < d->tabList.count(); ++i)
| 0 | ||||||||||||||||||||||||||||||
| 1325 | r = r.united(d->tabList.at(i).maxRect); never executed: r = r.united(d->tabList.at(i).maxRect); | 0 | ||||||||||||||||||||||||||||||
| 1326 | QSize sz = QApplication::globalStrut(); | - | ||||||||||||||||||||||||||||||
| 1327 | return r.size().expandedTo(sz); never executed: return r.size().expandedTo(sz); | 0 | ||||||||||||||||||||||||||||||
| 1328 | } | - | ||||||||||||||||||||||||||||||
| 1329 | - | |||||||||||||||||||||||||||||||
| 1330 | /*!\reimp | - | ||||||||||||||||||||||||||||||
| 1331 | */ | - | ||||||||||||||||||||||||||||||
| 1332 | QSize QTabBar::minimumSizeHint() const | - | ||||||||||||||||||||||||||||||
| 1333 | { | - | ||||||||||||||||||||||||||||||
| 1334 | Q_D(const QTabBar); | - | ||||||||||||||||||||||||||||||
| 1335 | if (d->layoutDirty)
| 0 | ||||||||||||||||||||||||||||||
| 1336 | const_cast<QTabBarPrivate*>(d)->layoutTabs(); never executed: const_cast<QTabBarPrivate*>(d)->layoutTabs(); | 0 | ||||||||||||||||||||||||||||||
| 1337 | if (!d->useScrollButtons) {
| 0 | ||||||||||||||||||||||||||||||
| 1338 | QRect r; | - | ||||||||||||||||||||||||||||||
| 1339 | for (int i = 0; i < d->tabList.count(); ++i)
| 0 | ||||||||||||||||||||||||||||||
| 1340 | r = r.united(d->tabList.at(i).minRect); never executed: r = r.united(d->tabList.at(i).minRect); | 0 | ||||||||||||||||||||||||||||||
| 1341 | return r.size().expandedTo(QApplication::globalStrut()); never executed: return r.size().expandedTo(QApplication::globalStrut()); | 0 | ||||||||||||||||||||||||||||||
| 1342 | } | - | ||||||||||||||||||||||||||||||
| 1343 | if (verticalTabs(d->shape))
| 0 | ||||||||||||||||||||||||||||||
| 1344 | return QSize(sizeHint().width(), d->rightB->sizeHint().height() * 2 + 75); never executed: return QSize(sizeHint().width(), d->rightB->sizeHint().height() * 2 + 75); | 0 | ||||||||||||||||||||||||||||||
| 1345 | else | - | ||||||||||||||||||||||||||||||
| 1346 | return QSize(d->rightB->sizeHint().width() * 2 + 75, sizeHint().height()); never executed: return QSize(d->rightB->sizeHint().width() * 2 + 75, sizeHint().height()); | 0 | ||||||||||||||||||||||||||||||
| 1347 | } | - | ||||||||||||||||||||||||||||||
| 1348 | - | |||||||||||||||||||||||||||||||
| 1349 | // Compute the most-elided possible text, for minimumSizeHint | - | ||||||||||||||||||||||||||||||
| 1350 | static QString computeElidedText(Qt::TextElideMode mode, const QString &text) | - | ||||||||||||||||||||||||||||||
| 1351 | { | - | ||||||||||||||||||||||||||||||
| 1352 | if (text.length() <= 3)
| 0 | ||||||||||||||||||||||||||||||
| 1353 | return text; never executed: return text; | 0 | ||||||||||||||||||||||||||||||
| 1354 | - | |||||||||||||||||||||||||||||||
| 1355 | static const QLatin1String Ellipses("..."); | - | ||||||||||||||||||||||||||||||
| 1356 | QString ret; | - | ||||||||||||||||||||||||||||||
| 1357 | switch (mode) { | - | ||||||||||||||||||||||||||||||
| 1358 | case Qt::ElideRight: never executed: case Qt::ElideRight: | 0 | ||||||||||||||||||||||||||||||
| 1359 | ret = text.left(2) + Ellipses; | - | ||||||||||||||||||||||||||||||
| 1360 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||
| 1361 | case Qt::ElideMiddle: never executed: case Qt::ElideMiddle: | 0 | ||||||||||||||||||||||||||||||
| 1362 | ret = text.left(1) + Ellipses + text.right(1); | - | ||||||||||||||||||||||||||||||
| 1363 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||
| 1364 | case Qt::ElideLeft: never executed: case Qt::ElideLeft: | 0 | ||||||||||||||||||||||||||||||
| 1365 | ret = Ellipses + text.right(2); | - | ||||||||||||||||||||||||||||||
| 1366 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||
| 1367 | case Qt::ElideNone: never executed: case Qt::ElideNone: | 0 | ||||||||||||||||||||||||||||||
| 1368 | ret = text; | - | ||||||||||||||||||||||||||||||
| 1369 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||
| 1370 | } | - | ||||||||||||||||||||||||||||||
| 1371 | return ret; never executed: return ret; | 0 | ||||||||||||||||||||||||||||||
| 1372 | } | - | ||||||||||||||||||||||||||||||
| 1373 | - | |||||||||||||||||||||||||||||||
| 1374 | /*! | - | ||||||||||||||||||||||||||||||
| 1375 | Returns the minimum tab size hint for the tab at position \a index. | - | ||||||||||||||||||||||||||||||
| 1376 | \since Qt 5.0 | - | ||||||||||||||||||||||||||||||
| 1377 | */ | - | ||||||||||||||||||||||||||||||
| 1378 | - | |||||||||||||||||||||||||||||||
| 1379 | QSize QTabBar::minimumTabSizeHint(int index) const | - | ||||||||||||||||||||||||||||||
| 1380 | { | - | ||||||||||||||||||||||||||||||
| 1381 | Q_D(const QTabBar); | - | ||||||||||||||||||||||||||||||
| 1382 | QTabBarPrivate::Tab &tab = const_cast<QTabBarPrivate::Tab&>(d->tabList[index]); | - | ||||||||||||||||||||||||||||||
| 1383 | QString oldText = tab.text; | - | ||||||||||||||||||||||||||||||
| 1384 | tab.text = computeElidedText(d->elideMode, oldText); | - | ||||||||||||||||||||||||||||||
| 1385 | QSize size = tabSizeHint(index); | - | ||||||||||||||||||||||||||||||
| 1386 | tab.text = oldText; | - | ||||||||||||||||||||||||||||||
| 1387 | return size; never executed: return size; | 0 | ||||||||||||||||||||||||||||||
| 1388 | } | - | ||||||||||||||||||||||||||||||
| 1389 | - | |||||||||||||||||||||||||||||||
| 1390 | /*! | - | ||||||||||||||||||||||||||||||
| 1391 | Returns the size hint for the tab at position \a index. | - | ||||||||||||||||||||||||||||||
| 1392 | */ | - | ||||||||||||||||||||||||||||||
| 1393 | QSize QTabBar::tabSizeHint(int index) const | - | ||||||||||||||||||||||||||||||
| 1394 | { | - | ||||||||||||||||||||||||||||||
| 1395 | //Note: this must match with the computations in QCommonStylePrivate::tabLayout | - | ||||||||||||||||||||||||||||||
| 1396 | Q_D(const QTabBar); | - | ||||||||||||||||||||||||||||||
| 1397 | if (const QTabBarPrivate::Tab *tab = d->at(index)) {
| 0 | ||||||||||||||||||||||||||||||
| 1398 | QStyleOptionTab opt; | - | ||||||||||||||||||||||||||||||
| 1399 | d->initBasicStyleOption(&opt, index); | - | ||||||||||||||||||||||||||||||
| 1400 | opt.text = d->tabList.at(index).text; | - | ||||||||||||||||||||||||||||||
| 1401 | QSize iconSize = tab->icon.isNull() ? QSize(0, 0) : opt.iconSize;
| 0 | ||||||||||||||||||||||||||||||
| 1402 | int hframe = style()->pixelMetric(QStyle::PM_TabBarTabHSpace, &opt, this); | - | ||||||||||||||||||||||||||||||
| 1403 | int vframe = style()->pixelMetric(QStyle::PM_TabBarTabVSpace, &opt, this); | - | ||||||||||||||||||||||||||||||
| 1404 | const QFontMetrics fm = fontMetrics(); | - | ||||||||||||||||||||||||||||||
| 1405 | - | |||||||||||||||||||||||||||||||
| 1406 | int maxWidgetHeight = qMax(opt.leftButtonSize.height(), opt.rightButtonSize.height()); | - | ||||||||||||||||||||||||||||||
| 1407 | int maxWidgetWidth = qMax(opt.leftButtonSize.width(), opt.rightButtonSize.width()); | - | ||||||||||||||||||||||||||||||
| 1408 | - | |||||||||||||||||||||||||||||||
| 1409 | int widgetWidth = 0; | - | ||||||||||||||||||||||||||||||
| 1410 | int widgetHeight = 0; | - | ||||||||||||||||||||||||||||||
| 1411 | int padding = 0; | - | ||||||||||||||||||||||||||||||
| 1412 | if (!opt.leftButtonSize.isEmpty()) {
| 0 | ||||||||||||||||||||||||||||||
| 1413 | padding += 4; | - | ||||||||||||||||||||||||||||||
| 1414 | widgetWidth += opt.leftButtonSize.width(); | - | ||||||||||||||||||||||||||||||
| 1415 | widgetHeight += opt.leftButtonSize.height(); | - | ||||||||||||||||||||||||||||||
| 1416 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
| 1417 | if (!opt.rightButtonSize.isEmpty()) {
| 0 | ||||||||||||||||||||||||||||||
| 1418 | padding += 4; | - | ||||||||||||||||||||||||||||||
| 1419 | widgetWidth += opt.rightButtonSize.width(); | - | ||||||||||||||||||||||||||||||
| 1420 | widgetHeight += opt.rightButtonSize.height(); | - | ||||||||||||||||||||||||||||||
| 1421 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
| 1422 | if (!opt.icon.isNull())
| 0 | ||||||||||||||||||||||||||||||
| 1423 | padding += 4; never executed: padding += 4; | 0 | ||||||||||||||||||||||||||||||
| 1424 | - | |||||||||||||||||||||||||||||||
| 1425 | QHash<QString, QSize>::iterator it = d->textSizes.find(tab->text); | - | ||||||||||||||||||||||||||||||
| 1426 | if (it == d->textSizes.end())
| 0 | ||||||||||||||||||||||||||||||
| 1427 | it = d->textSizes.insert(tab->text, fm.size(Qt::TextShowMnemonic, tab->text)); never executed: it = d->textSizes.insert(tab->text, fm.size(Qt::TextShowMnemonic, tab->text)); | 0 | ||||||||||||||||||||||||||||||
| 1428 | const int textWidth = it.value().width(); | - | ||||||||||||||||||||||||||||||
| 1429 | QSize csz; | - | ||||||||||||||||||||||||||||||
| 1430 | if (verticalTabs(d->shape)) {
| 0 | ||||||||||||||||||||||||||||||
| 1431 | csz = QSize( qMax(maxWidgetWidth, qMax(fm.height(), iconSize.height())) + vframe, | - | ||||||||||||||||||||||||||||||
| 1432 | textWidth + iconSize.width() + hframe + widgetHeight + padding); | - | ||||||||||||||||||||||||||||||
| 1433 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||||||||
| 1434 | csz = QSize(textWidth + iconSize.width() + hframe + widgetWidth + padding, | - | ||||||||||||||||||||||||||||||
| 1435 | qMax(maxWidgetHeight, qMax(fm.height(), iconSize.height())) + vframe); | - | ||||||||||||||||||||||||||||||
| 1436 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
| 1437 | - | |||||||||||||||||||||||||||||||
| 1438 | QSize retSize = style()->sizeFromContents(QStyle::CT_TabBarTab, &opt, csz, this); | - | ||||||||||||||||||||||||||||||
| 1439 | return retSize; never executed: return retSize; | 0 | ||||||||||||||||||||||||||||||
| 1440 | } | - | ||||||||||||||||||||||||||||||
| 1441 | return QSize(); never executed: return QSize(); | 0 | ||||||||||||||||||||||||||||||
| 1442 | } | - | ||||||||||||||||||||||||||||||
| 1443 | - | |||||||||||||||||||||||||||||||
| 1444 | /*! | - | ||||||||||||||||||||||||||||||
| 1445 | This virtual handler is called after a new tab was added or | - | ||||||||||||||||||||||||||||||
| 1446 | inserted at position \a index. | - | ||||||||||||||||||||||||||||||
| 1447 | - | |||||||||||||||||||||||||||||||
| 1448 | \sa tabRemoved() | - | ||||||||||||||||||||||||||||||
| 1449 | */ | - | ||||||||||||||||||||||||||||||
| 1450 | void QTabBar::tabInserted(int index) | - | ||||||||||||||||||||||||||||||
| 1451 | { | - | ||||||||||||||||||||||||||||||
| 1452 | Q_UNUSED(index) | - | ||||||||||||||||||||||||||||||
| 1453 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
| 1454 | - | |||||||||||||||||||||||||||||||
| 1455 | /*! | - | ||||||||||||||||||||||||||||||
| 1456 | This virtual handler is called after a tab was removed from | - | ||||||||||||||||||||||||||||||
| 1457 | position \a index. | - | ||||||||||||||||||||||||||||||
| 1458 | - | |||||||||||||||||||||||||||||||
| 1459 | \sa tabInserted() | - | ||||||||||||||||||||||||||||||
| 1460 | */ | - | ||||||||||||||||||||||||||||||
| 1461 | void QTabBar::tabRemoved(int index) | - | ||||||||||||||||||||||||||||||
| 1462 | { | - | ||||||||||||||||||||||||||||||
| 1463 | Q_UNUSED(index) | - | ||||||||||||||||||||||||||||||
| 1464 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
| 1465 | - | |||||||||||||||||||||||||||||||
| 1466 | /*! | - | ||||||||||||||||||||||||||||||
| 1467 | This virtual handler is called whenever the tab layout changes. | - | ||||||||||||||||||||||||||||||
| 1468 | - | |||||||||||||||||||||||||||||||
| 1469 | \sa tabRect() | - | ||||||||||||||||||||||||||||||
| 1470 | */ | - | ||||||||||||||||||||||||||||||
| 1471 | void QTabBar::tabLayoutChange() | - | ||||||||||||||||||||||||||||||
| 1472 | { | - | ||||||||||||||||||||||||||||||
| 1473 | } | - | ||||||||||||||||||||||||||||||
| 1474 | - | |||||||||||||||||||||||||||||||
| 1475 | - | |||||||||||||||||||||||||||||||
| 1476 | /*!\reimp | - | ||||||||||||||||||||||||||||||
| 1477 | */ | - | ||||||||||||||||||||||||||||||
| 1478 | void QTabBar::showEvent(QShowEvent *) | - | ||||||||||||||||||||||||||||||
| 1479 | { | - | ||||||||||||||||||||||||||||||
| 1480 | Q_D(QTabBar); | - | ||||||||||||||||||||||||||||||
| 1481 | if (d->layoutDirty)
| 0 | ||||||||||||||||||||||||||||||
| 1482 | d->refresh(); never executed: d->refresh(); | 0 | ||||||||||||||||||||||||||||||
| 1483 | if (!d->validIndex(d->currentIndex))
| 0 | ||||||||||||||||||||||||||||||
| 1484 | setCurrentIndex(0); never executed: setCurrentIndex(0); | 0 | ||||||||||||||||||||||||||||||
| 1485 | d->updateMacBorderMetrics(); | - | ||||||||||||||||||||||||||||||
| 1486 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
| 1487 | - | |||||||||||||||||||||||||||||||
| 1488 | /*!\reimp | - | ||||||||||||||||||||||||||||||
| 1489 | */ | - | ||||||||||||||||||||||||||||||
| 1490 | void QTabBar::hideEvent(QHideEvent *) | - | ||||||||||||||||||||||||||||||
| 1491 | { | - | ||||||||||||||||||||||||||||||
| 1492 | Q_D(QTabBar); | - | ||||||||||||||||||||||||||||||
| 1493 | d->updateMacBorderMetrics(); | - | ||||||||||||||||||||||||||||||
| 1494 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
| 1495 | - | |||||||||||||||||||||||||||||||
| 1496 | /*!\reimp | - | ||||||||||||||||||||||||||||||
| 1497 | */ | - | ||||||||||||||||||||||||||||||
| 1498 | bool QTabBar::event(QEvent *event) | - | ||||||||||||||||||||||||||||||
| 1499 | { | - | ||||||||||||||||||||||||||||||
| 1500 | Q_D(QTabBar); | - | ||||||||||||||||||||||||||||||
| 1501 | if (event->type() == QEvent::HoverMove
| 0 | ||||||||||||||||||||||||||||||
| 1502 | || event->type() == QEvent::HoverEnter) {
| 0 | ||||||||||||||||||||||||||||||
| 1503 | QHoverEvent *he = static_cast<QHoverEvent *>(event); | - | ||||||||||||||||||||||||||||||
| 1504 | if (!d->hoverRect.contains(he->pos())) {
| 0 | ||||||||||||||||||||||||||||||
| 1505 | QRect oldHoverRect = d->hoverRect; | - | ||||||||||||||||||||||||||||||
| 1506 | for (int i = 0; i < d->tabList.count(); ++i) {
| 0 | ||||||||||||||||||||||||||||||
| 1507 | QRect area = tabRect(i); | - | ||||||||||||||||||||||||||||||
| 1508 | if (area.contains(he->pos())) {
| 0 | ||||||||||||||||||||||||||||||
| 1509 | d->hoverRect = area; | - | ||||||||||||||||||||||||||||||
| 1510 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||
| 1511 | } | - | ||||||||||||||||||||||||||||||
| 1512 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
| 1513 | if (he->oldPos() != QPoint(-1, -1))
| 0 | ||||||||||||||||||||||||||||||
| 1514 | update(oldHoverRect); never executed: update(oldHoverRect); | 0 | ||||||||||||||||||||||||||||||
| 1515 | update(d->hoverRect); | - | ||||||||||||||||||||||||||||||
| 1516 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
| 1517 | return true; never executed: return true; | 0 | ||||||||||||||||||||||||||||||
| 1518 | } else if (event->type() == QEvent::HoverLeave ) {
| 0 | ||||||||||||||||||||||||||||||
| 1519 | QRect oldHoverRect = d->hoverRect; | - | ||||||||||||||||||||||||||||||
| 1520 | d->hoverRect = QRect(); | - | ||||||||||||||||||||||||||||||
| 1521 | update(oldHoverRect); | - | ||||||||||||||||||||||||||||||
| 1522 | return true; never executed: return true; | 0 | ||||||||||||||||||||||||||||||
| 1523 | #ifndef QT_NO_TOOLTIP | - | ||||||||||||||||||||||||||||||
| 1524 | } else if (event->type() == QEvent::ToolTip) {
| 0 | ||||||||||||||||||||||||||||||
| 1525 | if (const QTabBarPrivate::Tab *tab = d->at(tabAt(static_cast<QHelpEvent*>(event)->pos()))) {
| 0 | ||||||||||||||||||||||||||||||
| 1526 | if (!tab->toolTip.isEmpty()) {
| 0 | ||||||||||||||||||||||||||||||
| 1527 | QToolTip::showText(static_cast<QHelpEvent*>(event)->globalPos(), tab->toolTip, this); | - | ||||||||||||||||||||||||||||||
| 1528 | return true; never executed: return true; | 0 | ||||||||||||||||||||||||||||||
| 1529 | } | - | ||||||||||||||||||||||||||||||
| 1530 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
| 1531 | #endif // QT_NO_TOOLTIP | - | ||||||||||||||||||||||||||||||
| 1532 | #ifndef QT_NO_WHATSTHIS | - | ||||||||||||||||||||||||||||||
| 1533 | } else if (event->type() == QEvent::QueryWhatsThis) { never executed: end of block
| 0 | ||||||||||||||||||||||||||||||
| 1534 | const QTabBarPrivate::Tab *tab = d->at(d->indexAtPos(static_cast<QHelpEvent*>(event)->pos())); | - | ||||||||||||||||||||||||||||||
| 1535 | if (!tab || tab->whatsThis.isEmpty())
| 0 | ||||||||||||||||||||||||||||||
| 1536 | event->ignore(); never executed: event->ignore(); | 0 | ||||||||||||||||||||||||||||||
| 1537 | return true; never executed: return true; | 0 | ||||||||||||||||||||||||||||||
| 1538 | } else if (event->type() == QEvent::WhatsThis) {
| 0 | ||||||||||||||||||||||||||||||
| 1539 | if (const QTabBarPrivate::Tab *tab = d->at(d->indexAtPos(static_cast<QHelpEvent*>(event)->pos()))) {
| 0 | ||||||||||||||||||||||||||||||
| 1540 | if (!tab->whatsThis.isEmpty()) {
| 0 | ||||||||||||||||||||||||||||||
| 1541 | QWhatsThis::showText(static_cast<QHelpEvent*>(event)->globalPos(), | - | ||||||||||||||||||||||||||||||
| 1542 | tab->whatsThis, this); | - | ||||||||||||||||||||||||||||||
| 1543 | return true; never executed: return true; | 0 | ||||||||||||||||||||||||||||||
| 1544 | } | - | ||||||||||||||||||||||||||||||
| 1545 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
| 1546 | #endif // QT_NO_WHATSTHIS | - | ||||||||||||||||||||||||||||||
| 1547 | #ifndef QT_NO_SHORTCUT | - | ||||||||||||||||||||||||||||||
| 1548 | } else if (event->type() == QEvent::Shortcut) { never executed: end of block
| 0 | ||||||||||||||||||||||||||||||
| 1549 | QShortcutEvent *se = static_cast<QShortcutEvent *>(event); | - | ||||||||||||||||||||||||||||||
| 1550 | for (int i = 0; i < d->tabList.count(); ++i) {
| 0 | ||||||||||||||||||||||||||||||
| 1551 | const QTabBarPrivate::Tab *tab = &d->tabList.at(i); | - | ||||||||||||||||||||||||||||||
| 1552 | if (tab->shortcutId == se->shortcutId()) {
| 0 | ||||||||||||||||||||||||||||||
| 1553 | setCurrentIndex(i); | - | ||||||||||||||||||||||||||||||
| 1554 | return true; never executed: return true; | 0 | ||||||||||||||||||||||||||||||
| 1555 | } | - | ||||||||||||||||||||||||||||||
| 1556 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
| 1557 | #endif | - | ||||||||||||||||||||||||||||||
| 1558 | } else if (event->type() == QEvent::MouseButtonDblClick) { // ### fixme Qt 6: move to mouseDoubleClickEvent(), here for BC reasons. never executed: end of block
| 0 | ||||||||||||||||||||||||||||||
| 1559 | const QPoint pos = static_cast<const QMouseEvent *>(event)->pos(); | - | ||||||||||||||||||||||||||||||
| 1560 | const bool isEventInCornerButtons = (!d->leftB->isHidden() && d->leftB->geometry().contains(pos))
| 0 | ||||||||||||||||||||||||||||||
| 1561 | || (!d->rightB->isHidden() && d->rightB->geometry().contains(pos));
| 0 | ||||||||||||||||||||||||||||||
| 1562 | if (!isEventInCornerButtons)
| 0 | ||||||||||||||||||||||||||||||
| 1563 | emit tabBarDoubleClicked(tabAt(pos)); never executed: tabBarDoubleClicked(tabAt(pos)); | 0 | ||||||||||||||||||||||||||||||
| 1564 | } else if (event->type() == QEvent::Move) { never executed: end of block
| 0 | ||||||||||||||||||||||||||||||
| 1565 | d->updateMacBorderMetrics(); | - | ||||||||||||||||||||||||||||||
| 1566 | return QWidget::event(event); never executed: return QWidget::event(event); | 0 | ||||||||||||||||||||||||||||||
| 1567 | - | |||||||||||||||||||||||||||||||
| 1568 | #ifndef QT_NO_DRAGANDDROP | - | ||||||||||||||||||||||||||||||
| 1569 | } else if (event->type() == QEvent::DragEnter) {
| 0 | ||||||||||||||||||||||||||||||
| 1570 | if (d->changeCurrentOnDrag)
| 0 | ||||||||||||||||||||||||||||||
| 1571 | event->accept(); never executed: event->accept(); | 0 | ||||||||||||||||||||||||||||||
| 1572 | } else if (event->type() == QEvent::DragMove) { never executed: end of block
| 0 | ||||||||||||||||||||||||||||||
| 1573 | if (d->changeCurrentOnDrag) {
| 0 | ||||||||||||||||||||||||||||||
| 1574 | const int tabIndex = tabAt(static_cast<QDragMoveEvent *>(event)->pos()); | - | ||||||||||||||||||||||||||||||
| 1575 | if (isTabEnabled(tabIndex) && d->switchTabCurrentIndex != tabIndex) {
| 0 | ||||||||||||||||||||||||||||||
| 1576 | d->switchTabCurrentIndex = tabIndex; | - | ||||||||||||||||||||||||||||||
| 1577 | if (d->switchTabTimerId)
| 0 | ||||||||||||||||||||||||||||||
| 1578 | killTimer(d->switchTabTimerId); never executed: killTimer(d->switchTabTimerId); | 0 | ||||||||||||||||||||||||||||||
| 1579 | d->switchTabTimerId = startTimer(style()->styleHint(QStyle::SH_TabBar_ChangeCurrentDelay)); | - | ||||||||||||||||||||||||||||||
| 1580 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
| 1581 | event->ignore(); | - | ||||||||||||||||||||||||||||||
| 1582 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
| 1583 | } else if (event->type() == QEvent::DragLeave || event->type() == QEvent::Drop) { never executed: end of block
| 0 | ||||||||||||||||||||||||||||||
| 1584 | d->killSwitchTabTimer(); | - | ||||||||||||||||||||||||||||||
| 1585 | event->ignore(); | - | ||||||||||||||||||||||||||||||
| 1586 | #endif | - | ||||||||||||||||||||||||||||||
| 1587 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
| 1588 | return QWidget::event(event); never executed: return QWidget::event(event); | 0 | ||||||||||||||||||||||||||||||
| 1589 | } | - | ||||||||||||||||||||||||||||||
| 1590 | - | |||||||||||||||||||||||||||||||
| 1591 | /*!\reimp | - | ||||||||||||||||||||||||||||||
| 1592 | */ | - | ||||||||||||||||||||||||||||||
| 1593 | void QTabBar::resizeEvent(QResizeEvent *) | - | ||||||||||||||||||||||||||||||
| 1594 | { | - | ||||||||||||||||||||||||||||||
| 1595 | Q_D(QTabBar); | - | ||||||||||||||||||||||||||||||
| 1596 | if (d->layoutDirty)
| 0 | ||||||||||||||||||||||||||||||
| 1597 | updateGeometry(); never executed: updateGeometry(); | 0 | ||||||||||||||||||||||||||||||
| 1598 | d->layoutTabs(); | - | ||||||||||||||||||||||||||||||
| 1599 | - | |||||||||||||||||||||||||||||||
| 1600 | d->makeVisible(d->currentIndex); | - | ||||||||||||||||||||||||||||||
| 1601 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
| 1602 | - | |||||||||||||||||||||||||||||||
| 1603 | /*!\reimp | - | ||||||||||||||||||||||||||||||
| 1604 | */ | - | ||||||||||||||||||||||||||||||
| 1605 | void QTabBar::paintEvent(QPaintEvent *) | - | ||||||||||||||||||||||||||||||
| 1606 | { | - | ||||||||||||||||||||||||||||||
| 1607 | Q_D(QTabBar); | - | ||||||||||||||||||||||||||||||
| 1608 | - | |||||||||||||||||||||||||||||||
| 1609 | QStyleOptionTabBarBase optTabBase; | - | ||||||||||||||||||||||||||||||
| 1610 | QTabBarPrivate::initStyleBaseOption(&optTabBase, this, size()); | - | ||||||||||||||||||||||||||||||
| 1611 | - | |||||||||||||||||||||||||||||||
| 1612 | QStylePainter p(this); | - | ||||||||||||||||||||||||||||||
| 1613 | int selected = -1; | - | ||||||||||||||||||||||||||||||
| 1614 | int cut = -1; | - | ||||||||||||||||||||||||||||||
| 1615 | bool rtl = optTabBase.direction == Qt::RightToLeft; | - | ||||||||||||||||||||||||||||||
| 1616 | bool vertical = verticalTabs(d->shape); | - | ||||||||||||||||||||||||||||||
| 1617 | QStyleOptionTab cutTab; | - | ||||||||||||||||||||||||||||||
| 1618 | selected = d->currentIndex; | - | ||||||||||||||||||||||||||||||
| 1619 | if (d->dragInProgress)
| 0 | ||||||||||||||||||||||||||||||
| 1620 | selected = d->pressedIndex; never executed: selected = d->pressedIndex; | 0 | ||||||||||||||||||||||||||||||
| 1621 | - | |||||||||||||||||||||||||||||||
| 1622 | for (int i = 0; i < d->tabList.count(); ++i)
| 0 | ||||||||||||||||||||||||||||||
| 1623 | optTabBase.tabBarRect |= tabRect(i); never executed: optTabBase.tabBarRect |= tabRect(i); | 0 | ||||||||||||||||||||||||||||||
| 1624 | - | |||||||||||||||||||||||||||||||
| 1625 | optTabBase.selectedTabRect = tabRect(selected); | - | ||||||||||||||||||||||||||||||
| 1626 | - | |||||||||||||||||||||||||||||||
| 1627 | if (d->drawBase)
| 0 | ||||||||||||||||||||||||||||||
| 1628 | p.drawPrimitive(QStyle::PE_FrameTabBarBase, optTabBase); never executed: p.drawPrimitive(QStyle::PE_FrameTabBarBase, optTabBase); | 0 | ||||||||||||||||||||||||||||||
| 1629 | - | |||||||||||||||||||||||||||||||
| 1630 | for (int i = 0; i < d->tabList.count(); ++i) {
| 0 | ||||||||||||||||||||||||||||||
| 1631 | QStyleOptionTab tab; | - | ||||||||||||||||||||||||||||||
| 1632 | initStyleOption(&tab, i); | - | ||||||||||||||||||||||||||||||
| 1633 | if (d->paintWithOffsets && d->tabList[i].dragOffset != 0) {
| 0 | ||||||||||||||||||||||||||||||
| 1634 | if (vertical) {
| 0 | ||||||||||||||||||||||||||||||
| 1635 | tab.rect.moveTop(tab.rect.y() + d->tabList[i].dragOffset); | - | ||||||||||||||||||||||||||||||
| 1636 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||||||||
| 1637 | tab.rect.moveLeft(tab.rect.x() + d->tabList[i].dragOffset); | - | ||||||||||||||||||||||||||||||
| 1638 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
| 1639 | } | - | ||||||||||||||||||||||||||||||
| 1640 | if (!(tab.state & QStyle::State_Enabled)) {
| 0 | ||||||||||||||||||||||||||||||
| 1641 | tab.palette.setCurrentColorGroup(QPalette::Disabled); | - | ||||||||||||||||||||||||||||||
| 1642 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
| 1643 | // If this tab is partially obscured, make a note of it so that we can pass the information | - | ||||||||||||||||||||||||||||||
| 1644 | // along when we draw the tear. | - | ||||||||||||||||||||||||||||||
| 1645 | if (((!vertical && (!rtl && tab.rect.left() < 0)) || (rtl && tab.rect.right() > width()))
| 0 | ||||||||||||||||||||||||||||||
| 1646 | || (vertical && tab.rect.top() < 0)) {
| 0 | ||||||||||||||||||||||||||||||
| 1647 | cut = i; | - | ||||||||||||||||||||||||||||||
| 1648 | cutTab = tab; | - | ||||||||||||||||||||||||||||||
| 1649 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
| 1650 | // Don't bother drawing a tab if the entire tab is outside of the visible tab bar. | - | ||||||||||||||||||||||||||||||
| 1651 | if ((!vertical && (tab.rect.right() < 0 || tab.rect.left() > width()))
| 0 | ||||||||||||||||||||||||||||||
| 1652 | || (vertical && (tab.rect.bottom() < 0 || tab.rect.top() > height())))
| 0 | ||||||||||||||||||||||||||||||
| 1653 | continue; never executed: continue; | 0 | ||||||||||||||||||||||||||||||
| 1654 | - | |||||||||||||||||||||||||||||||
| 1655 | optTabBase.tabBarRect |= tab.rect; | - | ||||||||||||||||||||||||||||||
| 1656 | if (i == selected)
| 0 | ||||||||||||||||||||||||||||||
| 1657 | continue; never executed: continue; | 0 | ||||||||||||||||||||||||||||||
| 1658 | - | |||||||||||||||||||||||||||||||
| 1659 | p.drawControl(QStyle::CE_TabBarTab, tab); | - | ||||||||||||||||||||||||||||||
| 1660 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
| 1661 | - | |||||||||||||||||||||||||||||||
| 1662 | // Draw the selected tab last to get it "on top" | - | ||||||||||||||||||||||||||||||
| 1663 | if (selected >= 0) {
| 0 | ||||||||||||||||||||||||||||||
| 1664 | QStyleOptionTab tab; | - | ||||||||||||||||||||||||||||||
| 1665 | initStyleOption(&tab, selected); | - | ||||||||||||||||||||||||||||||
| 1666 | if (d->paintWithOffsets && d->tabList[selected].dragOffset != 0) {
| 0 | ||||||||||||||||||||||||||||||
| 1667 | if (vertical)
| 0 | ||||||||||||||||||||||||||||||
| 1668 | tab.rect.moveTop(tab.rect.y() + d->tabList[selected].dragOffset); never executed: tab.rect.moveTop(tab.rect.y() + d->tabList[selected].dragOffset); | 0 | ||||||||||||||||||||||||||||||
| 1669 | else | - | ||||||||||||||||||||||||||||||
| 1670 | tab.rect.moveLeft(tab.rect.x() + d->tabList[selected].dragOffset); never executed: tab.rect.moveLeft(tab.rect.x() + d->tabList[selected].dragOffset); | 0 | ||||||||||||||||||||||||||||||
| 1671 | } | - | ||||||||||||||||||||||||||||||
| 1672 | if (!d->dragInProgress)
| 0 | ||||||||||||||||||||||||||||||
| 1673 | p.drawControl(QStyle::CE_TabBarTab, tab); never executed: p.drawControl(QStyle::CE_TabBarTab, tab); | 0 | ||||||||||||||||||||||||||||||
| 1674 | else { | - | ||||||||||||||||||||||||||||||
| 1675 | int taboverlap = style()->pixelMetric(QStyle::PM_TabBarTabOverlap, 0, this); | - | ||||||||||||||||||||||||||||||
| 1676 | d->movingTab->setGeometry(tab.rect.adjusted(-taboverlap, 0, taboverlap, 0)); | - | ||||||||||||||||||||||||||||||
| 1677 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
| 1678 | } | - | ||||||||||||||||||||||||||||||
| 1679 | - | |||||||||||||||||||||||||||||||
| 1680 | // Only draw the tear indicator if necessary. Most of the time we don't need too. | - | ||||||||||||||||||||||||||||||
| 1681 | if (d->leftB->isVisible() && cut >= 0) {
| 0 | ||||||||||||||||||||||||||||||
| 1682 | cutTab.rect = rect(); | - | ||||||||||||||||||||||||||||||
| 1683 | cutTab.rect = style()->subElementRect(QStyle::SE_TabBarTearIndicator, &cutTab, this); | - | ||||||||||||||||||||||||||||||
| 1684 | p.drawPrimitive(QStyle::PE_IndicatorTabTear, cutTab); | - | ||||||||||||||||||||||||||||||
| 1685 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
| 1686 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
| 1687 | - | |||||||||||||||||||||||||||||||
| 1688 | /* | - | ||||||||||||||||||||||||||||||
| 1689 | Given that index at position from moved to position to where return where index goes. | - | ||||||||||||||||||||||||||||||
| 1690 | */ | - | ||||||||||||||||||||||||||||||
| 1691 | int QTabBarPrivate::calculateNewPosition(int from, int to, int index) const | - | ||||||||||||||||||||||||||||||
| 1692 | { | - | ||||||||||||||||||||||||||||||
| 1693 | if (index == from)
| 0 | ||||||||||||||||||||||||||||||
| 1694 | return to; never executed: return to; | 0 | ||||||||||||||||||||||||||||||
| 1695 | - | |||||||||||||||||||||||||||||||
| 1696 | int start = qMin(from, to); | - | ||||||||||||||||||||||||||||||
| 1697 | int end = qMax(from, to); | - | ||||||||||||||||||||||||||||||
| 1698 | if (index >= start && index <= end)
| 0 | ||||||||||||||||||||||||||||||
| 1699 | index += (from < to) ? -1 : 1; never executed: index += (from < to) ? -1 : 1;
| 0 | ||||||||||||||||||||||||||||||
| 1700 | return index; never executed: return index; | 0 | ||||||||||||||||||||||||||||||
| 1701 | } | - | ||||||||||||||||||||||||||||||
| 1702 | - | |||||||||||||||||||||||||||||||
| 1703 | /*! | - | ||||||||||||||||||||||||||||||
| 1704 | Moves the item at index position \a from to index position \a to. | - | ||||||||||||||||||||||||||||||
| 1705 | \since 4.5 | - | ||||||||||||||||||||||||||||||
| 1706 | - | |||||||||||||||||||||||||||||||
| 1707 | \sa tabMoved(), tabLayoutChange() | - | ||||||||||||||||||||||||||||||
| 1708 | */ | - | ||||||||||||||||||||||||||||||
| 1709 | void QTabBar::moveTab(int from, int to) | - | ||||||||||||||||||||||||||||||
| 1710 | { | - | ||||||||||||||||||||||||||||||
| 1711 | Q_D(QTabBar); | - | ||||||||||||||||||||||||||||||
| 1712 | if (from == to
| 0 | ||||||||||||||||||||||||||||||
| 1713 | || !d->validIndex(from)
| 0 | ||||||||||||||||||||||||||||||
| 1714 | || !d->validIndex(to))
| 0 | ||||||||||||||||||||||||||||||
| 1715 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||
| 1716 | - | |||||||||||||||||||||||||||||||
| 1717 | bool vertical = verticalTabs(d->shape); | - | ||||||||||||||||||||||||||||||
| 1718 | int oldPressedPosition = 0; | - | ||||||||||||||||||||||||||||||
| 1719 | if (d->pressedIndex != -1) {
| 0 | ||||||||||||||||||||||||||||||
| 1720 | // Record the position of the pressed tab before reordering the tabs. | - | ||||||||||||||||||||||||||||||
| 1721 | oldPressedPosition = vertical ? d->tabList[d->pressedIndex].rect.y()
| 0 | ||||||||||||||||||||||||||||||
| 1722 | : d->tabList[d->pressedIndex].rect.x(); | - | ||||||||||||||||||||||||||||||
| 1723 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
| 1724 | - | |||||||||||||||||||||||||||||||
| 1725 | // Update the locations of the tabs first | - | ||||||||||||||||||||||||||||||
| 1726 | int start = qMin(from, to); | - | ||||||||||||||||||||||||||||||
| 1727 | int end = qMax(from, to); | - | ||||||||||||||||||||||||||||||
| 1728 | int width = vertical ? d->tabList[from].rect.height() : d->tabList[from].rect.width();
| 0 | ||||||||||||||||||||||||||||||
| 1729 | if (from < to)
| 0 | ||||||||||||||||||||||||||||||
| 1730 | width *= -1; never executed: width *= -1; | 0 | ||||||||||||||||||||||||||||||
| 1731 | bool rtl = isRightToLeft(); | - | ||||||||||||||||||||||||||||||
| 1732 | for (int i = start; i <= end; ++i) {
| 0 | ||||||||||||||||||||||||||||||
| 1733 | if (i == from)
| 0 | ||||||||||||||||||||||||||||||
| 1734 | continue; never executed: continue; | 0 | ||||||||||||||||||||||||||||||
| 1735 | if (vertical)
| 0 | ||||||||||||||||||||||||||||||
| 1736 | d->tabList[i].rect.moveTop(d->tabList[i].rect.y() + width); never executed: d->tabList[i].rect.moveTop(d->tabList[i].rect.y() + width); | 0 | ||||||||||||||||||||||||||||||
| 1737 | else | - | ||||||||||||||||||||||||||||||
| 1738 | d->tabList[i].rect.moveLeft(d->tabList[i].rect.x() + width); never executed: d->tabList[i].rect.moveLeft(d->tabList[i].rect.x() + width); | 0 | ||||||||||||||||||||||||||||||
| 1739 | int direction = -1; | - | ||||||||||||||||||||||||||||||
| 1740 | if (rtl && !vertical)
| 0 | ||||||||||||||||||||||||||||||
| 1741 | direction *= -1; never executed: direction *= -1; | 0 | ||||||||||||||||||||||||||||||
| 1742 | if (d->tabList[i].dragOffset != 0)
| 0 | ||||||||||||||||||||||||||||||
| 1743 | d->tabList[i].dragOffset += (direction * width); never executed: d->tabList[i].dragOffset += (direction * width); | 0 | ||||||||||||||||||||||||||||||
| 1744 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
| 1745 | - | |||||||||||||||||||||||||||||||
| 1746 | if (vertical) {
| 0 | ||||||||||||||||||||||||||||||
| 1747 | if (from < to)
| 0 | ||||||||||||||||||||||||||||||
| 1748 | d->tabList[from].rect.moveTop(d->tabList[to].rect.bottom() + 1); never executed: d->tabList[from].rect.moveTop(d->tabList[to].rect.bottom() + 1); | 0 | ||||||||||||||||||||||||||||||
| 1749 | else | - | ||||||||||||||||||||||||||||||
| 1750 | d->tabList[from].rect.moveTop(d->tabList[to].rect.top() - width); never executed: d->tabList[from].rect.moveTop(d->tabList[to].rect.top() - width); | 0 | ||||||||||||||||||||||||||||||
| 1751 | } else { | - | ||||||||||||||||||||||||||||||
| 1752 | if (from < to)
| 0 | ||||||||||||||||||||||||||||||
| 1753 | d->tabList[from].rect.moveLeft(d->tabList[to].rect.right() + 1); never executed: d->tabList[from].rect.moveLeft(d->tabList[to].rect.right() + 1); | 0 | ||||||||||||||||||||||||||||||
| 1754 | else | - | ||||||||||||||||||||||||||||||
| 1755 | d->tabList[from].rect.moveLeft(d->tabList[to].rect.left() - width); never executed: d->tabList[from].rect.moveLeft(d->tabList[to].rect.left() - width); | 0 | ||||||||||||||||||||||||||||||
| 1756 | } | - | ||||||||||||||||||||||||||||||
| 1757 | - | |||||||||||||||||||||||||||||||
| 1758 | // Move the actual data structures | - | ||||||||||||||||||||||||||||||
| 1759 | d->tabList.move(from, to); | - | ||||||||||||||||||||||||||||||
| 1760 | - | |||||||||||||||||||||||||||||||
| 1761 | // update lastTab locations | - | ||||||||||||||||||||||||||||||
| 1762 | for (int i = 0; i < d->tabList.count(); ++i)
| 0 | ||||||||||||||||||||||||||||||
| 1763 | d->tabList[i].lastTab = d->calculateNewPosition(from, to, d->tabList[i].lastTab); never executed: d->tabList[i].lastTab = d->calculateNewPosition(from, to, d->tabList[i].lastTab); | 0 | ||||||||||||||||||||||||||||||
| 1764 | - | |||||||||||||||||||||||||||||||
| 1765 | // update external variables | - | ||||||||||||||||||||||||||||||
| 1766 | int previousIndex = d->currentIndex; | - | ||||||||||||||||||||||||||||||
| 1767 | d->currentIndex = d->calculateNewPosition(from, to, d->currentIndex); | - | ||||||||||||||||||||||||||||||
| 1768 | - | |||||||||||||||||||||||||||||||
| 1769 | // If we are in the middle of a drag update the dragStartPosition | - | ||||||||||||||||||||||||||||||
| 1770 | if (d->pressedIndex != -1) {
| 0 | ||||||||||||||||||||||||||||||
| 1771 | d->pressedIndex = d->calculateNewPosition(from, to, d->pressedIndex); | - | ||||||||||||||||||||||||||||||
| 1772 | int newPressedPosition = vertical ? d->tabList[d->pressedIndex].rect.top() : d->tabList[d->pressedIndex].rect.left();
| 0 | ||||||||||||||||||||||||||||||
| 1773 | int diff = oldPressedPosition - newPressedPosition; | - | ||||||||||||||||||||||||||||||
| 1774 | if (isRightToLeft() && !vertical)
| 0 | ||||||||||||||||||||||||||||||
| 1775 | diff *= -1; never executed: diff *= -1; | 0 | ||||||||||||||||||||||||||||||
| 1776 | if (vertical)
| 0 | ||||||||||||||||||||||||||||||
| 1777 | d->dragStartPosition.setY(d->dragStartPosition.y() - diff); never executed: d->dragStartPosition.setY(d->dragStartPosition.y() - diff); | 0 | ||||||||||||||||||||||||||||||
| 1778 | else | - | ||||||||||||||||||||||||||||||
| 1779 | d->dragStartPosition.setX(d->dragStartPosition.x() - diff); never executed: d->dragStartPosition.setX(d->dragStartPosition.x() - diff); | 0 | ||||||||||||||||||||||||||||||
| 1780 | } | - | ||||||||||||||||||||||||||||||
| 1781 | - | |||||||||||||||||||||||||||||||
| 1782 | d->layoutWidgets(start); | - | ||||||||||||||||||||||||||||||
| 1783 | update(); | - | ||||||||||||||||||||||||||||||
| 1784 | emit tabMoved(from, to); | - | ||||||||||||||||||||||||||||||
| 1785 | if (previousIndex != d->currentIndex)
| 0 | ||||||||||||||||||||||||||||||
| 1786 | emit currentChanged(d->currentIndex); never executed: currentChanged(d->currentIndex); | 0 | ||||||||||||||||||||||||||||||
| 1787 | emit tabLayoutChange(); | - | ||||||||||||||||||||||||||||||
| 1788 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
| 1789 | - | |||||||||||||||||||||||||||||||
| 1790 | void QTabBarPrivate::slide(int from, int to) | - | ||||||||||||||||||||||||||||||
| 1791 | { | - | ||||||||||||||||||||||||||||||
| 1792 | Q_Q(QTabBar); | - | ||||||||||||||||||||||||||||||
| 1793 | if (from == to
| 0 | ||||||||||||||||||||||||||||||
| 1794 | || !validIndex(from)
| 0 | ||||||||||||||||||||||||||||||
| 1795 | || !validIndex(to))
| 0 | ||||||||||||||||||||||||||||||
| 1796 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||
| 1797 | bool vertical = verticalTabs(shape); | - | ||||||||||||||||||||||||||||||
| 1798 | int preLocation = vertical ? q->tabRect(from).y() : q->tabRect(from).x();
| 0 | ||||||||||||||||||||||||||||||
| 1799 | q->setUpdatesEnabled(false); | - | ||||||||||||||||||||||||||||||
| 1800 | q->moveTab(from, to); | - | ||||||||||||||||||||||||||||||
| 1801 | q->setUpdatesEnabled(true); | - | ||||||||||||||||||||||||||||||
| 1802 | int postLocation = vertical ? q->tabRect(to).y() : q->tabRect(to).x();
| 0 | ||||||||||||||||||||||||||||||
| 1803 | int length = postLocation - preLocation; | - | ||||||||||||||||||||||||||||||
| 1804 | tabList[to].dragOffset -= length; | - | ||||||||||||||||||||||||||||||
| 1805 | tabList[to].startAnimation(this, ANIMATION_DURATION); | - | ||||||||||||||||||||||||||||||
| 1806 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
| 1807 | - | |||||||||||||||||||||||||||||||
| 1808 | void QTabBarPrivate::moveTab(int index, int offset) | - | ||||||||||||||||||||||||||||||
| 1809 | { | - | ||||||||||||||||||||||||||||||
| 1810 | if (!validIndex(index))
| 0 | ||||||||||||||||||||||||||||||
| 1811 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||
| 1812 | tabList[index].dragOffset = offset; | - | ||||||||||||||||||||||||||||||
| 1813 | layoutTab(index); // Make buttons follow tab | - | ||||||||||||||||||||||||||||||
| 1814 | q_func()->update(); | - | ||||||||||||||||||||||||||||||
| 1815 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
| 1816 | - | |||||||||||||||||||||||||||||||
| 1817 | /*!\reimp | - | ||||||||||||||||||||||||||||||
| 1818 | */ | - | ||||||||||||||||||||||||||||||
| 1819 | void QTabBar::mousePressEvent(QMouseEvent *event) | - | ||||||||||||||||||||||||||||||
| 1820 | { | - | ||||||||||||||||||||||||||||||
| 1821 | Q_D(QTabBar); | - | ||||||||||||||||||||||||||||||
| 1822 | - | |||||||||||||||||||||||||||||||
| 1823 | const QPoint pos = event->pos(); | - | ||||||||||||||||||||||||||||||
| 1824 | const bool isEventInCornerButtons = (!d->leftB->isHidden() && d->leftB->geometry().contains(pos))
| 0 | ||||||||||||||||||||||||||||||
| 1825 | || (!d->rightB->isHidden() && d->rightB->geometry().contains(pos));
| 0 | ||||||||||||||||||||||||||||||
| 1826 | if (!isEventInCornerButtons) {
| 0 | ||||||||||||||||||||||||||||||
| 1827 | const int index = d->indexAtPos(pos); | - | ||||||||||||||||||||||||||||||
| 1828 | emit tabBarClicked(index); | - | ||||||||||||||||||||||||||||||
| 1829 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
| 1830 | - | |||||||||||||||||||||||||||||||
| 1831 | if (event->button() != Qt::LeftButton) {
| 0 | ||||||||||||||||||||||||||||||
| 1832 | event->ignore(); | - | ||||||||||||||||||||||||||||||
| 1833 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||
| 1834 | } | - | ||||||||||||||||||||||||||||||
| 1835 | // Be safe! | - | ||||||||||||||||||||||||||||||
| 1836 | if (d->pressedIndex != -1 && d->movable)
| 0 | ||||||||||||||||||||||||||||||
| 1837 | d->moveTabFinished(d->pressedIndex); never executed: d->moveTabFinished(d->pressedIndex); | 0 | ||||||||||||||||||||||||||||||
| 1838 | - | |||||||||||||||||||||||||||||||
| 1839 | d->pressedIndex = d->indexAtPos(event->pos()); | - | ||||||||||||||||||||||||||||||
| 1840 | #ifdef Q_DEAD_CODE_FROM_QT4_MAC | - | ||||||||||||||||||||||||||||||
| 1841 | d->previousPressedIndex = d->pressedIndex; | - | ||||||||||||||||||||||||||||||
| 1842 | #endif | - | ||||||||||||||||||||||||||||||
| 1843 | if (d->validIndex(d->pressedIndex)) {
| 0 | ||||||||||||||||||||||||||||||
| 1844 | QStyleOptionTabBarBase optTabBase; | - | ||||||||||||||||||||||||||||||
| 1845 | optTabBase.init(this); | - | ||||||||||||||||||||||||||||||
| 1846 | optTabBase.documentMode = d->documentMode; | - | ||||||||||||||||||||||||||||||
| 1847 | if (event->type() == style()->styleHint(QStyle::SH_TabBar_SelectMouseType, &optTabBase, this))
| 0 | ||||||||||||||||||||||||||||||
| 1848 | setCurrentIndex(d->pressedIndex); never executed: setCurrentIndex(d->pressedIndex); | 0 | ||||||||||||||||||||||||||||||
| 1849 | else | - | ||||||||||||||||||||||||||||||
| 1850 | repaint(tabRect(d->pressedIndex)); never executed: repaint(tabRect(d->pressedIndex)); | 0 | ||||||||||||||||||||||||||||||
| 1851 | if (d->movable) {
| 0 | ||||||||||||||||||||||||||||||
| 1852 | d->dragStartPosition = event->pos(); | - | ||||||||||||||||||||||||||||||
| 1853 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
| 1854 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
| 1855 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
| 1856 | - | |||||||||||||||||||||||||||||||
| 1857 | /*!\reimp | - | ||||||||||||||||||||||||||||||
| 1858 | */ | - | ||||||||||||||||||||||||||||||
| 1859 | void QTabBar::mouseMoveEvent(QMouseEvent *event) | - | ||||||||||||||||||||||||||||||
| 1860 | { | - | ||||||||||||||||||||||||||||||
| 1861 | Q_D(QTabBar); | - | ||||||||||||||||||||||||||||||
| 1862 | if (d->movable) {
| 0 | ||||||||||||||||||||||||||||||
| 1863 | // Be safe! | - | ||||||||||||||||||||||||||||||
| 1864 | if (d->pressedIndex != -1
| 0 | ||||||||||||||||||||||||||||||
| 1865 | && event->buttons() == Qt::NoButton)
| 0 | ||||||||||||||||||||||||||||||
| 1866 | d->moveTabFinished(d->pressedIndex); never executed: d->moveTabFinished(d->pressedIndex); | 0 | ||||||||||||||||||||||||||||||
| 1867 | - | |||||||||||||||||||||||||||||||
| 1868 | // Start drag | - | ||||||||||||||||||||||||||||||
| 1869 | if (!d->dragInProgress && d->pressedIndex != -1) {
| 0 | ||||||||||||||||||||||||||||||
| 1870 | if ((event->pos() - d->dragStartPosition).manhattanLength() > QApplication::startDragDistance()) {
| 0 | ||||||||||||||||||||||||||||||
| 1871 | d->dragInProgress = true; | - | ||||||||||||||||||||||||||||||
| 1872 | d->setupMovableTab(); | - | ||||||||||||||||||||||||||||||
| 1873 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
| 1874 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
| 1875 | - | |||||||||||||||||||||||||||||||
| 1876 | if (event->buttons() == Qt::LeftButton
| 0 | ||||||||||||||||||||||||||||||
| 1877 | && d->dragInProgress
| 0 | ||||||||||||||||||||||||||||||
| 1878 | && d->validIndex(d->pressedIndex)) {
| 0 | ||||||||||||||||||||||||||||||
| 1879 | bool vertical = verticalTabs(d->shape); | - | ||||||||||||||||||||||||||||||
| 1880 | int dragDistance; | - | ||||||||||||||||||||||||||||||
| 1881 | if (vertical) {
| 0 | ||||||||||||||||||||||||||||||
| 1882 | dragDistance = (event->pos().y() - d->dragStartPosition.y()); | - | ||||||||||||||||||||||||||||||
| 1883 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||||||||
| 1884 | dragDistance = (event->pos().x() - d->dragStartPosition.x()); | - | ||||||||||||||||||||||||||||||
| 1885 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
| 1886 | d->tabList[d->pressedIndex].dragOffset = dragDistance; | - | ||||||||||||||||||||||||||||||
| 1887 | - | |||||||||||||||||||||||||||||||
| 1888 | QRect startingRect = tabRect(d->pressedIndex); | - | ||||||||||||||||||||||||||||||
| 1889 | if (vertical)
| 0 | ||||||||||||||||||||||||||||||
| 1890 | startingRect.moveTop(startingRect.y() + dragDistance); never executed: startingRect.moveTop(startingRect.y() + dragDistance); | 0 | ||||||||||||||||||||||||||||||
| 1891 | else | - | ||||||||||||||||||||||||||||||
| 1892 | startingRect.moveLeft(startingRect.x() + dragDistance); never executed: startingRect.moveLeft(startingRect.x() + dragDistance); | 0 | ||||||||||||||||||||||||||||||
| 1893 | - | |||||||||||||||||||||||||||||||
| 1894 | int overIndex; | - | ||||||||||||||||||||||||||||||
| 1895 | if (dragDistance < 0)
| 0 | ||||||||||||||||||||||||||||||
| 1896 | overIndex = tabAt(startingRect.topLeft()); never executed: overIndex = tabAt(startingRect.topLeft()); | 0 | ||||||||||||||||||||||||||||||
| 1897 | else | - | ||||||||||||||||||||||||||||||
| 1898 | overIndex = tabAt(startingRect.topRight()); never executed: overIndex = tabAt(startingRect.topRight()); | 0 | ||||||||||||||||||||||||||||||
| 1899 | - | |||||||||||||||||||||||||||||||
| 1900 | if (overIndex != d->pressedIndex && overIndex != -1) {
| 0 | ||||||||||||||||||||||||||||||
| 1901 | int offset = 1; | - | ||||||||||||||||||||||||||||||
| 1902 | if (isRightToLeft() && !vertical)
| 0 | ||||||||||||||||||||||||||||||
| 1903 | offset *= -1; never executed: offset *= -1; | 0 | ||||||||||||||||||||||||||||||
| 1904 | if (dragDistance < 0) {
| 0 | ||||||||||||||||||||||||||||||
| 1905 | dragDistance *= -1; | - | ||||||||||||||||||||||||||||||
| 1906 | offset *= -1; | - | ||||||||||||||||||||||||||||||
| 1907 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
| 1908 | for (int i = d->pressedIndex; | - | ||||||||||||||||||||||||||||||
| 1909 | offset > 0 ? i < overIndex : i > overIndex;
| 0 | ||||||||||||||||||||||||||||||
| 1910 | i += offset) { | - | ||||||||||||||||||||||||||||||
| 1911 | QRect overIndexRect = tabRect(overIndex); | - | ||||||||||||||||||||||||||||||
| 1912 | int needsToBeOver = (vertical ? overIndexRect.height() : overIndexRect.width()) / 2;
| 0 | ||||||||||||||||||||||||||||||
| 1913 | if (dragDistance > needsToBeOver)
| 0 | ||||||||||||||||||||||||||||||
| 1914 | d->slide(i + offset, d->pressedIndex); never executed: d->slide(i + offset, d->pressedIndex); | 0 | ||||||||||||||||||||||||||||||
| 1915 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
| 1916 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
| 1917 | // Buttons needs to follow the dragged tab | - | ||||||||||||||||||||||||||||||
| 1918 | d->layoutTab(d->pressedIndex); | - | ||||||||||||||||||||||||||||||
| 1919 | - | |||||||||||||||||||||||||||||||
| 1920 | update(); | - | ||||||||||||||||||||||||||||||
| 1921 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
| 1922 | #ifdef Q_DEAD_CODE_FROM_QT4_MAC | - | ||||||||||||||||||||||||||||||
| 1923 | } else if (!d->documentMode && event->buttons() == Qt::LeftButton && d->previousPressedIndex != -1) { | - | ||||||||||||||||||||||||||||||
| 1924 | int newPressedIndex = d->indexAtPos(event->pos()); | - | ||||||||||||||||||||||||||||||
| 1925 | if (d->pressedIndex == -1 && d->previousPressedIndex == newPressedIndex) { | - | ||||||||||||||||||||||||||||||
| 1926 | d->pressedIndex = d->previousPressedIndex; | - | ||||||||||||||||||||||||||||||
| 1927 | update(tabRect(d->pressedIndex)); | - | ||||||||||||||||||||||||||||||
| 1928 | } else if(d->pressedIndex != newPressedIndex) { | - | ||||||||||||||||||||||||||||||
| 1929 | d->pressedIndex = -1; | - | ||||||||||||||||||||||||||||||
| 1930 | update(tabRect(d->previousPressedIndex)); | - | ||||||||||||||||||||||||||||||
| 1931 | } | - | ||||||||||||||||||||||||||||||
| 1932 | #endif | - | ||||||||||||||||||||||||||||||
| 1933 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
| 1934 | - | |||||||||||||||||||||||||||||||
| 1935 | if (event->buttons() != Qt::LeftButton) {
| 0 | ||||||||||||||||||||||||||||||
| 1936 | event->ignore(); | - | ||||||||||||||||||||||||||||||
| 1937 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||
| 1938 | } | - | ||||||||||||||||||||||||||||||
| 1939 | QStyleOptionTabBarBase optTabBase; | - | ||||||||||||||||||||||||||||||
| 1940 | optTabBase.init(this); | - | ||||||||||||||||||||||||||||||
| 1941 | optTabBase.documentMode = d->documentMode; | - | ||||||||||||||||||||||||||||||
| 1942 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
| 1943 | - | |||||||||||||||||||||||||||||||
| 1944 | void QTabBarPrivate::setupMovableTab() | - | ||||||||||||||||||||||||||||||
| 1945 | { | - | ||||||||||||||||||||||||||||||
| 1946 | Q_Q(QTabBar); | - | ||||||||||||||||||||||||||||||
| 1947 | if (!movingTab)
| 0 | ||||||||||||||||||||||||||||||
| 1948 | movingTab = new QMovableTabWidget(q); never executed: movingTab = new QMovableTabWidget(q); | 0 | ||||||||||||||||||||||||||||||
| 1949 | - | |||||||||||||||||||||||||||||||
| 1950 | int taboverlap = q->style()->pixelMetric(QStyle::PM_TabBarTabOverlap, 0 ,q); | - | ||||||||||||||||||||||||||||||
| 1951 | QRect grabRect = q->tabRect(pressedIndex); | - | ||||||||||||||||||||||||||||||
| 1952 | grabRect.adjust(-taboverlap, 0, taboverlap, 0); | - | ||||||||||||||||||||||||||||||
| 1953 | - | |||||||||||||||||||||||||||||||
| 1954 | QPixmap grabImage(grabRect.size() * q->devicePixelRatioF()); | - | ||||||||||||||||||||||||||||||
| 1955 | grabImage.setDevicePixelRatio(q->devicePixelRatioF()); | - | ||||||||||||||||||||||||||||||
| 1956 | grabImage.fill(Qt::transparent); | - | ||||||||||||||||||||||||||||||
| 1957 | QStylePainter p(&grabImage, q); | - | ||||||||||||||||||||||||||||||
| 1958 | p.initFrom(q); | - | ||||||||||||||||||||||||||||||
| 1959 | - | |||||||||||||||||||||||||||||||
| 1960 | QStyleOptionTab tab; | - | ||||||||||||||||||||||||||||||
| 1961 | q->initStyleOption(&tab, pressedIndex); | - | ||||||||||||||||||||||||||||||
| 1962 | tab.rect.moveTopLeft(QPoint(taboverlap, 0)); | - | ||||||||||||||||||||||||||||||
| 1963 | p.drawControl(QStyle::CE_TabBarTab, tab); | - | ||||||||||||||||||||||||||||||
| 1964 | p.end(); | - | ||||||||||||||||||||||||||||||
| 1965 | - | |||||||||||||||||||||||||||||||
| 1966 | movingTab->setPixmap(grabImage); | - | ||||||||||||||||||||||||||||||
| 1967 | movingTab->setGeometry(grabRect); | - | ||||||||||||||||||||||||||||||
| 1968 | movingTab->raise(); | - | ||||||||||||||||||||||||||||||
| 1969 | - | |||||||||||||||||||||||||||||||
| 1970 | // Re-arrange widget order to avoid overlaps | - | ||||||||||||||||||||||||||||||
| 1971 | if (tabList[pressedIndex].leftWidget)
| 0 | ||||||||||||||||||||||||||||||
| 1972 | tabList[pressedIndex].leftWidget->raise(); never executed: tabList[pressedIndex].leftWidget->raise(); | 0 | ||||||||||||||||||||||||||||||
| 1973 | if (tabList[pressedIndex].rightWidget)
| 0 | ||||||||||||||||||||||||||||||
| 1974 | tabList[pressedIndex].rightWidget->raise(); never executed: tabList[pressedIndex].rightWidget->raise(); | 0 | ||||||||||||||||||||||||||||||
| 1975 | if (leftB)
| 0 | ||||||||||||||||||||||||||||||
| 1976 | leftB->raise(); never executed: leftB->raise(); | 0 | ||||||||||||||||||||||||||||||
| 1977 | if (rightB)
| 0 | ||||||||||||||||||||||||||||||
| 1978 | rightB->raise(); never executed: rightB->raise(); | 0 | ||||||||||||||||||||||||||||||
| 1979 | movingTab->setVisible(true); | - | ||||||||||||||||||||||||||||||
| 1980 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
| 1981 | - | |||||||||||||||||||||||||||||||
| 1982 | void QTabBarPrivate::moveTabFinished(int index) | - | ||||||||||||||||||||||||||||||
| 1983 | { | - | ||||||||||||||||||||||||||||||
| 1984 | Q_Q(QTabBar); | - | ||||||||||||||||||||||||||||||
| 1985 | bool cleanup = (pressedIndex == index) || (pressedIndex == -1) || !validIndex(index);
| 0 | ||||||||||||||||||||||||||||||
| 1986 | bool allAnimationsFinished = true; | - | ||||||||||||||||||||||||||||||
| 1987 | #ifndef QT_NO_ANIMATION | - | ||||||||||||||||||||||||||||||
| 1988 | for(int i = 0; allAnimationsFinished && i < tabList.count(); ++i) {
| 0 | ||||||||||||||||||||||||||||||
| 1989 | const Tab &t = tabList.at(i); | - | ||||||||||||||||||||||||||||||
| 1990 | if (t.animation && t.animation->state() == QAbstractAnimation::Running)
| 0 | ||||||||||||||||||||||||||||||
| 1991 | allAnimationsFinished = false; never executed: allAnimationsFinished = false; | 0 | ||||||||||||||||||||||||||||||
| 1992 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
| 1993 | #endif //QT_NO_ANIMATION | - | ||||||||||||||||||||||||||||||
| 1994 | if (allAnimationsFinished && cleanup) {
| 0 | ||||||||||||||||||||||||||||||
| 1995 | if(movingTab)
| 0 | ||||||||||||||||||||||||||||||
| 1996 | movingTab->setVisible(false); // We might not get a mouse release never executed: movingTab->setVisible(false); | 0 | ||||||||||||||||||||||||||||||
| 1997 | for (int i = 0; i < tabList.count(); ++i) {
| 0 | ||||||||||||||||||||||||||||||
| 1998 | tabList[i].dragOffset = 0; | - | ||||||||||||||||||||||||||||||
| 1999 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
| 2000 | if (pressedIndex != -1 && movable) {
| 0 | ||||||||||||||||||||||||||||||
| 2001 | pressedIndex = -1; | - | ||||||||||||||||||||||||||||||
| 2002 | dragInProgress = false; | - | ||||||||||||||||||||||||||||||
| 2003 | dragStartPosition = QPoint(); | - | ||||||||||||||||||||||||||||||
| 2004 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
| 2005 | layoutWidgets(); | - | ||||||||||||||||||||||||||||||
| 2006 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||||||||
| 2007 | if (!validIndex(index))
| 0 | ||||||||||||||||||||||||||||||
| 2008 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||
| 2009 | tabList[index].dragOffset = 0; | - | ||||||||||||||||||||||||||||||
| 2010 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
| 2011 | q->update(); | - | ||||||||||||||||||||||||||||||
| 2012 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
| 2013 | - | |||||||||||||||||||||||||||||||
| 2014 | /*!\reimp | - | ||||||||||||||||||||||||||||||
| 2015 | */ | - | ||||||||||||||||||||||||||||||
| 2016 | void QTabBar::mouseReleaseEvent(QMouseEvent *event) | - | ||||||||||||||||||||||||||||||
| 2017 | { | - | ||||||||||||||||||||||||||||||
| 2018 | Q_D(QTabBar); | - | ||||||||||||||||||||||||||||||
| 2019 | if (event->button() != Qt::LeftButton) {
| 0 | ||||||||||||||||||||||||||||||
| 2020 | event->ignore(); | - | ||||||||||||||||||||||||||||||
| 2021 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||
| 2022 | } | - | ||||||||||||||||||||||||||||||
| 2023 | #ifdef Q_DEAD_CODE_FROM_QT4_MAC | - | ||||||||||||||||||||||||||||||
| 2024 | d->previousPressedIndex = -1; | - | ||||||||||||||||||||||||||||||
| 2025 | #endif | - | ||||||||||||||||||||||||||||||
| 2026 | if (d->movable && d->dragInProgress && d->validIndex(d->pressedIndex)) {
| 0 | ||||||||||||||||||||||||||||||
| 2027 | int length = d->tabList[d->pressedIndex].dragOffset; | - | ||||||||||||||||||||||||||||||
| 2028 | int width = verticalTabs(d->shape)
| 0 | ||||||||||||||||||||||||||||||
| 2029 | ? tabRect(d->pressedIndex).height() | - | ||||||||||||||||||||||||||||||
| 2030 | : tabRect(d->pressedIndex).width(); | - | ||||||||||||||||||||||||||||||
| 2031 | int duration = qMin(ANIMATION_DURATION, | - | ||||||||||||||||||||||||||||||
| 2032 | (qAbs(length) * ANIMATION_DURATION) / width); | - | ||||||||||||||||||||||||||||||
| 2033 | d->tabList[d->pressedIndex].startAnimation(d, duration); | - | ||||||||||||||||||||||||||||||
| 2034 | d->dragInProgress = false; | - | ||||||||||||||||||||||||||||||
| 2035 | d->movingTab->setVisible(false); | - | ||||||||||||||||||||||||||||||
| 2036 | d->dragStartPosition = QPoint(); | - | ||||||||||||||||||||||||||||||
| 2037 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
| 2038 | - | |||||||||||||||||||||||||||||||
| 2039 | int i = d->indexAtPos(event->pos()) == d->pressedIndex ? d->pressedIndex : -1;
| 0 | ||||||||||||||||||||||||||||||
| 2040 | d->pressedIndex = -1; | - | ||||||||||||||||||||||||||||||
| 2041 | QStyleOptionTabBarBase optTabBase; | - | ||||||||||||||||||||||||||||||
| 2042 | optTabBase.initFrom(this); | - | ||||||||||||||||||||||||||||||
| 2043 | optTabBase.documentMode = d->documentMode; | - | ||||||||||||||||||||||||||||||
| 2044 | if (style()->styleHint(QStyle::SH_TabBar_SelectMouseType, &optTabBase, this) == QEvent::MouseButtonRelease)
| 0 | ||||||||||||||||||||||||||||||
| 2045 | setCurrentIndex(i); never executed: setCurrentIndex(i); | 0 | ||||||||||||||||||||||||||||||
| 2046 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
| 2047 | - | |||||||||||||||||||||||||||||||
| 2048 | /*!\reimp | - | ||||||||||||||||||||||||||||||
| 2049 | */ | - | ||||||||||||||||||||||||||||||
| 2050 | void QTabBar::keyPressEvent(QKeyEvent *event) | - | ||||||||||||||||||||||||||||||
| 2051 | { | - | ||||||||||||||||||||||||||||||
| 2052 | Q_D(QTabBar); | - | ||||||||||||||||||||||||||||||
| 2053 | if (event->key() != Qt::Key_Left && event->key() != Qt::Key_Right) {
| 0 | ||||||||||||||||||||||||||||||
| 2054 | event->ignore(); | - | ||||||||||||||||||||||||||||||
| 2055 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||
| 2056 | } | - | ||||||||||||||||||||||||||||||
| 2057 | int offset = event->key() == (isRightToLeft() ? Qt::Key_Right : Qt::Key_Left) ? -1 : 1;
| 0 | ||||||||||||||||||||||||||||||
| 2058 | d->setCurrentNextEnabledIndex(offset); | - | ||||||||||||||||||||||||||||||
| 2059 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
| 2060 | - | |||||||||||||||||||||||||||||||
| 2061 | /*!\reimp | - | ||||||||||||||||||||||||||||||
| 2062 | */ | - | ||||||||||||||||||||||||||||||
| 2063 | #ifndef QT_NO_WHEELEVENT | - | ||||||||||||||||||||||||||||||
| 2064 | void QTabBar::wheelEvent(QWheelEvent *event) | - | ||||||||||||||||||||||||||||||
| 2065 | { | - | ||||||||||||||||||||||||||||||
| 2066 | #ifndef Q_OS_MAC | - | ||||||||||||||||||||||||||||||
| 2067 | Q_D(QTabBar); | - | ||||||||||||||||||||||||||||||
| 2068 | int offset = event->delta() > 0 ? -1 : 1;
| 0 | ||||||||||||||||||||||||||||||
| 2069 | d->setCurrentNextEnabledIndex(offset); | - | ||||||||||||||||||||||||||||||
| 2070 | QWidget::wheelEvent(event); | - | ||||||||||||||||||||||||||||||
| 2071 | #else | - | ||||||||||||||||||||||||||||||
| 2072 | Q_UNUSED(event) | - | ||||||||||||||||||||||||||||||
| 2073 | #endif | - | ||||||||||||||||||||||||||||||
| 2074 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
| 2075 | #endif //QT_NO_WHEELEVENT | - | ||||||||||||||||||||||||||||||
| 2076 | - | |||||||||||||||||||||||||||||||
| 2077 | void QTabBarPrivate::setCurrentNextEnabledIndex(int offset) | - | ||||||||||||||||||||||||||||||
| 2078 | { | - | ||||||||||||||||||||||||||||||
| 2079 | Q_Q(QTabBar); | - | ||||||||||||||||||||||||||||||
| 2080 | for (int index = currentIndex + offset; validIndex(index); index += offset) {
| 0 | ||||||||||||||||||||||||||||||
| 2081 | if (tabList.at(index).enabled) {
| 0 | ||||||||||||||||||||||||||||||
| 2082 | q->setCurrentIndex(index); | - | ||||||||||||||||||||||||||||||
| 2083 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||
| 2084 | } | - | ||||||||||||||||||||||||||||||
| 2085 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
| 2086 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
| 2087 | - | |||||||||||||||||||||||||||||||
| 2088 | /*!\reimp | - | ||||||||||||||||||||||||||||||
| 2089 | */ | - | ||||||||||||||||||||||||||||||
| 2090 | void QTabBar::changeEvent(QEvent *event) | - | ||||||||||||||||||||||||||||||
| 2091 | { | - | ||||||||||||||||||||||||||||||
| 2092 | Q_D(QTabBar); | - | ||||||||||||||||||||||||||||||
| 2093 | switch (event->type()) { | - | ||||||||||||||||||||||||||||||
| 2094 | case QEvent::StyleChange: never executed: case QEvent::StyleChange: | 0 | ||||||||||||||||||||||||||||||
| 2095 | if (!d->elideModeSetByUser)
| 0 | ||||||||||||||||||||||||||||||
| 2096 | d->elideMode = Qt::TextElideMode(style()->styleHint(QStyle::SH_TabBar_ElideMode, 0, this)); never executed: d->elideMode = Qt::TextElideMode(style()->styleHint(QStyle::SH_TabBar_ElideMode, 0, this)); | 0 | ||||||||||||||||||||||||||||||
| 2097 | if (!d->useScrollButtonsSetByUser)
| 0 | ||||||||||||||||||||||||||||||
| 2098 | d->useScrollButtons = !style()->styleHint(QStyle::SH_TabBar_PreferNoArrows, 0, this); never executed: d->useScrollButtons = !style()->styleHint(QStyle::SH_TabBar_PreferNoArrows, 0, this); | 0 | ||||||||||||||||||||||||||||||
| 2099 | // fallthrough | - | ||||||||||||||||||||||||||||||
| 2100 | case QEvent::FontChange: code before this statement never executed: case QEvent::FontChange:never executed: case QEvent::FontChange: | 0 | ||||||||||||||||||||||||||||||
| 2101 | d->textSizes.clear(); | - | ||||||||||||||||||||||||||||||
| 2102 | d->refresh(); | - | ||||||||||||||||||||||||||||||
| 2103 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||
| 2104 | default: never executed: default: | 0 | ||||||||||||||||||||||||||||||
| 2105 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||
| 2106 | } | - | ||||||||||||||||||||||||||||||
| 2107 | - | |||||||||||||||||||||||||||||||
| 2108 | QWidget::changeEvent(event); | - | ||||||||||||||||||||||||||||||
| 2109 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
| 2110 | - | |||||||||||||||||||||||||||||||
| 2111 | /*! | - | ||||||||||||||||||||||||||||||
| 2112 | \reimp | - | ||||||||||||||||||||||||||||||
| 2113 | */ | - | ||||||||||||||||||||||||||||||
| 2114 | void QTabBar::timerEvent(QTimerEvent *event) | - | ||||||||||||||||||||||||||||||
| 2115 | { | - | ||||||||||||||||||||||||||||||
| 2116 | Q_D(QTabBar); | - | ||||||||||||||||||||||||||||||
| 2117 | if (event->timerId() == d->switchTabTimerId) {
| 0 | ||||||||||||||||||||||||||||||
| 2118 | killTimer(d->switchTabTimerId); | - | ||||||||||||||||||||||||||||||
| 2119 | d->switchTabTimerId = 0; | - | ||||||||||||||||||||||||||||||
| 2120 | setCurrentIndex(d->switchTabCurrentIndex); | - | ||||||||||||||||||||||||||||||
| 2121 | d->switchTabCurrentIndex = -1; | - | ||||||||||||||||||||||||||||||
| 2122 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
| 2123 | QWidget::timerEvent(event); | - | ||||||||||||||||||||||||||||||
| 2124 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
| 2125 | - | |||||||||||||||||||||||||||||||
| 2126 | /*! | - | ||||||||||||||||||||||||||||||
| 2127 | \property QTabBar::elideMode | - | ||||||||||||||||||||||||||||||
| 2128 | \brief how to elide text in the tab bar | - | ||||||||||||||||||||||||||||||
| 2129 | \since 4.2 | - | ||||||||||||||||||||||||||||||
| 2130 | - | |||||||||||||||||||||||||||||||
| 2131 | This property controls how items are elided when there is not | - | ||||||||||||||||||||||||||||||
| 2132 | enough space to show them for a given tab bar size. | - | ||||||||||||||||||||||||||||||
| 2133 | - | |||||||||||||||||||||||||||||||
| 2134 | By default the value is style dependent. | - | ||||||||||||||||||||||||||||||
| 2135 | - | |||||||||||||||||||||||||||||||
| 2136 | \sa QTabWidget::elideMode, usesScrollButtons, QStyle::SH_TabBar_ElideMode | - | ||||||||||||||||||||||||||||||
| 2137 | */ | - | ||||||||||||||||||||||||||||||
| 2138 | - | |||||||||||||||||||||||||||||||
| 2139 | Qt::TextElideMode QTabBar::elideMode() const | - | ||||||||||||||||||||||||||||||
| 2140 | { | - | ||||||||||||||||||||||||||||||
| 2141 | Q_D(const QTabBar); | - | ||||||||||||||||||||||||||||||
| 2142 | return d->elideMode; never executed: return d->elideMode; | 0 | ||||||||||||||||||||||||||||||
| 2143 | } | - | ||||||||||||||||||||||||||||||
| 2144 | - | |||||||||||||||||||||||||||||||
| 2145 | void QTabBar::setElideMode(Qt::TextElideMode mode) | - | ||||||||||||||||||||||||||||||
| 2146 | { | - | ||||||||||||||||||||||||||||||
| 2147 | Q_D(QTabBar); | - | ||||||||||||||||||||||||||||||
| 2148 | d->elideMode = mode; | - | ||||||||||||||||||||||||||||||
| 2149 | d->elideModeSetByUser = true; | - | ||||||||||||||||||||||||||||||
| 2150 | d->textSizes.clear(); | - | ||||||||||||||||||||||||||||||
| 2151 | d->refresh(); | - | ||||||||||||||||||||||||||||||
| 2152 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
| 2153 | - | |||||||||||||||||||||||||||||||
| 2154 | /*! | - | ||||||||||||||||||||||||||||||
| 2155 | \property QTabBar::usesScrollButtons | - | ||||||||||||||||||||||||||||||
| 2156 | \brief Whether or not a tab bar should use buttons to scroll tabs when it | - | ||||||||||||||||||||||||||||||
| 2157 | has many tabs. | - | ||||||||||||||||||||||||||||||
| 2158 | \since 4.2 | - | ||||||||||||||||||||||||||||||
| 2159 | - | |||||||||||||||||||||||||||||||
| 2160 | When there are too many tabs in a tab bar for its size, the tab bar can either choose | - | ||||||||||||||||||||||||||||||
| 2161 | to expand its size or to add buttons that allow you to scroll through the tabs. | - | ||||||||||||||||||||||||||||||
| 2162 | - | |||||||||||||||||||||||||||||||
| 2163 | By default the value is style dependant. | - | ||||||||||||||||||||||||||||||
| 2164 | - | |||||||||||||||||||||||||||||||
| 2165 | \sa elideMode, QTabWidget::usesScrollButtons, QStyle::SH_TabBar_PreferNoArrows | - | ||||||||||||||||||||||||||||||
| 2166 | */ | - | ||||||||||||||||||||||||||||||
| 2167 | bool QTabBar::usesScrollButtons() const | - | ||||||||||||||||||||||||||||||
| 2168 | { | - | ||||||||||||||||||||||||||||||
| 2169 | return d_func()->useScrollButtons; never executed: return d_func()->useScrollButtons; | 0 | ||||||||||||||||||||||||||||||
| 2170 | } | - | ||||||||||||||||||||||||||||||
| 2171 | - | |||||||||||||||||||||||||||||||
| 2172 | void QTabBar::setUsesScrollButtons(bool useButtons) | - | ||||||||||||||||||||||||||||||
| 2173 | { | - | ||||||||||||||||||||||||||||||
| 2174 | Q_D(QTabBar); | - | ||||||||||||||||||||||||||||||
| 2175 | d->useScrollButtonsSetByUser = true; | - | ||||||||||||||||||||||||||||||
| 2176 | if (d->useScrollButtons == useButtons)
| 0 | ||||||||||||||||||||||||||||||
| 2177 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||
| 2178 | d->useScrollButtons = useButtons; | - | ||||||||||||||||||||||||||||||
| 2179 | d->refresh(); | - | ||||||||||||||||||||||||||||||
| 2180 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
| 2181 | - | |||||||||||||||||||||||||||||||
| 2182 | /*! | - | ||||||||||||||||||||||||||||||
| 2183 | \property QTabBar::tabsClosable | - | ||||||||||||||||||||||||||||||
| 2184 | \brief Whether or not a tab bar should place close buttons on each tab | - | ||||||||||||||||||||||||||||||
| 2185 | \since 4.5 | - | ||||||||||||||||||||||||||||||
| 2186 | - | |||||||||||||||||||||||||||||||
| 2187 | When tabsClosable is set to true a close button will appear on the tab on | - | ||||||||||||||||||||||||||||||
| 2188 | either the left or right hand side depending upon the style. When the button | - | ||||||||||||||||||||||||||||||
| 2189 | is clicked the tab the signal tabCloseRequested will be emitted. | - | ||||||||||||||||||||||||||||||
| 2190 | - | |||||||||||||||||||||||||||||||
| 2191 | By default the value is false. | - | ||||||||||||||||||||||||||||||
| 2192 | - | |||||||||||||||||||||||||||||||
| 2193 | \sa setTabButton(), tabRemoved() | - | ||||||||||||||||||||||||||||||
| 2194 | */ | - | ||||||||||||||||||||||||||||||
| 2195 | - | |||||||||||||||||||||||||||||||
| 2196 | bool QTabBar::tabsClosable() const | - | ||||||||||||||||||||||||||||||
| 2197 | { | - | ||||||||||||||||||||||||||||||
| 2198 | Q_D(const QTabBar); | - | ||||||||||||||||||||||||||||||
| 2199 | return d->closeButtonOnTabs; never executed: return d->closeButtonOnTabs; | 0 | ||||||||||||||||||||||||||||||
| 2200 | } | - | ||||||||||||||||||||||||||||||
| 2201 | - | |||||||||||||||||||||||||||||||
| 2202 | void QTabBar::setTabsClosable(bool closable) | - | ||||||||||||||||||||||||||||||
| 2203 | { | - | ||||||||||||||||||||||||||||||
| 2204 | Q_D(QTabBar); | - | ||||||||||||||||||||||||||||||
| 2205 | if (d->closeButtonOnTabs == closable)
| 0 | ||||||||||||||||||||||||||||||
| 2206 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||
| 2207 | d->closeButtonOnTabs = closable; | - | ||||||||||||||||||||||||||||||
| 2208 | ButtonPosition closeSide = (ButtonPosition)style()->styleHint(QStyle::SH_TabBar_CloseButtonPosition, 0, this); | - | ||||||||||||||||||||||||||||||
| 2209 | if (!closable) {
| 0 | ||||||||||||||||||||||||||||||
| 2210 | for (int i = 0; i < d->tabList.count(); ++i) {
| 0 | ||||||||||||||||||||||||||||||
| 2211 | if (closeSide == LeftSide && d->tabList[i].leftWidget) {
| 0 | ||||||||||||||||||||||||||||||
| 2212 | d->tabList[i].leftWidget->deleteLater(); | - | ||||||||||||||||||||||||||||||
| 2213 | d->tabList[i].leftWidget = 0; | - | ||||||||||||||||||||||||||||||
| 2214 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
| 2215 | if (closeSide == RightSide && d->tabList[i].rightWidget) {
| 0 | ||||||||||||||||||||||||||||||
| 2216 | d->tabList[i].rightWidget->deleteLater(); | - | ||||||||||||||||||||||||||||||
| 2217 | d->tabList[i].rightWidget = 0; | - | ||||||||||||||||||||||||||||||
| 2218 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
| 2219 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
| 2220 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||||||||
| 2221 | bool newButtons = false; | - | ||||||||||||||||||||||||||||||
| 2222 | for (int i = 0; i < d->tabList.count(); ++i) {
| 0 | ||||||||||||||||||||||||||||||
| 2223 | if (tabButton(i, closeSide))
| 0 | ||||||||||||||||||||||||||||||
| 2224 | continue; never executed: continue; | 0 | ||||||||||||||||||||||||||||||
| 2225 | newButtons = true; | - | ||||||||||||||||||||||||||||||
| 2226 | QAbstractButton *closeButton = new CloseButton(this); | - | ||||||||||||||||||||||||||||||
| 2227 | connect(closeButton, SIGNAL(clicked()), this, SLOT(_q_closeTab())); | - | ||||||||||||||||||||||||||||||
| 2228 | setTabButton(i, closeSide, closeButton); | - | ||||||||||||||||||||||||||||||
| 2229 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
| 2230 | if (newButtons)
| 0 | ||||||||||||||||||||||||||||||
| 2231 | d->layoutTabs(); never executed: d->layoutTabs(); | 0 | ||||||||||||||||||||||||||||||
| 2232 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
| 2233 | update(); | - | ||||||||||||||||||||||||||||||
| 2234 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
| 2235 | - | |||||||||||||||||||||||||||||||
| 2236 | /*! | - | ||||||||||||||||||||||||||||||
| 2237 | \enum QTabBar::ButtonPosition | - | ||||||||||||||||||||||||||||||
| 2238 | \since 4.5 | - | ||||||||||||||||||||||||||||||
| 2239 | - | |||||||||||||||||||||||||||||||
| 2240 | This enum type lists the location of the widget on a tab. | - | ||||||||||||||||||||||||||||||
| 2241 | - | |||||||||||||||||||||||||||||||
| 2242 | \value LeftSide Left side of the tab. | - | ||||||||||||||||||||||||||||||
| 2243 | - | |||||||||||||||||||||||||||||||
| 2244 | \value RightSide Right side of the tab. | - | ||||||||||||||||||||||||||||||
| 2245 | - | |||||||||||||||||||||||||||||||
| 2246 | */ | - | ||||||||||||||||||||||||||||||
| 2247 | - | |||||||||||||||||||||||||||||||
| 2248 | /*! | - | ||||||||||||||||||||||||||||||
| 2249 | \enum QTabBar::SelectionBehavior | - | ||||||||||||||||||||||||||||||
| 2250 | \since 4.5 | - | ||||||||||||||||||||||||||||||
| 2251 | - | |||||||||||||||||||||||||||||||
| 2252 | This enum type lists the behavior of QTabBar when a tab is removed | - | ||||||||||||||||||||||||||||||
| 2253 | and the tab being removed is also the current tab. | - | ||||||||||||||||||||||||||||||
| 2254 | - | |||||||||||||||||||||||||||||||
| 2255 | \value SelectLeftTab Select the tab to the left of the one being removed. | - | ||||||||||||||||||||||||||||||
| 2256 | - | |||||||||||||||||||||||||||||||
| 2257 | \value SelectRightTab Select the tab to the right of the one being removed. | - | ||||||||||||||||||||||||||||||
| 2258 | - | |||||||||||||||||||||||||||||||
| 2259 | \value SelectPreviousTab Select the previously selected tab. | - | ||||||||||||||||||||||||||||||
| 2260 | - | |||||||||||||||||||||||||||||||
| 2261 | */ | - | ||||||||||||||||||||||||||||||
| 2262 | - | |||||||||||||||||||||||||||||||
| 2263 | /*! | - | ||||||||||||||||||||||||||||||
| 2264 | \property QTabBar::selectionBehaviorOnRemove | - | ||||||||||||||||||||||||||||||
| 2265 | \brief What tab should be set as current when removeTab is called if | - | ||||||||||||||||||||||||||||||
| 2266 | the removed tab is also the current tab. | - | ||||||||||||||||||||||||||||||
| 2267 | \since 4.5 | - | ||||||||||||||||||||||||||||||
| 2268 | - | |||||||||||||||||||||||||||||||
| 2269 | By default the value is SelectRightTab. | - | ||||||||||||||||||||||||||||||
| 2270 | - | |||||||||||||||||||||||||||||||
| 2271 | \sa removeTab() | - | ||||||||||||||||||||||||||||||
| 2272 | */ | - | ||||||||||||||||||||||||||||||
| 2273 | - | |||||||||||||||||||||||||||||||
| 2274 | - | |||||||||||||||||||||||||||||||
| 2275 | QTabBar::SelectionBehavior QTabBar::selectionBehaviorOnRemove() const | - | ||||||||||||||||||||||||||||||
| 2276 | { | - | ||||||||||||||||||||||||||||||
| 2277 | Q_D(const QTabBar); | - | ||||||||||||||||||||||||||||||
| 2278 | return d->selectionBehaviorOnRemove; never executed: return d->selectionBehaviorOnRemove; | 0 | ||||||||||||||||||||||||||||||
| 2279 | } | - | ||||||||||||||||||||||||||||||
| 2280 | - | |||||||||||||||||||||||||||||||
| 2281 | void QTabBar::setSelectionBehaviorOnRemove(QTabBar::SelectionBehavior behavior) | - | ||||||||||||||||||||||||||||||
| 2282 | { | - | ||||||||||||||||||||||||||||||
| 2283 | Q_D(QTabBar); | - | ||||||||||||||||||||||||||||||
| 2284 | d->selectionBehaviorOnRemove = behavior; | - | ||||||||||||||||||||||||||||||
| 2285 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
| 2286 | - | |||||||||||||||||||||||||||||||
| 2287 | /*! | - | ||||||||||||||||||||||||||||||
| 2288 | \property QTabBar::expanding | - | ||||||||||||||||||||||||||||||
| 2289 | \brief When expanding is true QTabBar will expand the tabs to use the empty space. | - | ||||||||||||||||||||||||||||||
| 2290 | \since 4.5 | - | ||||||||||||||||||||||||||||||
| 2291 | - | |||||||||||||||||||||||||||||||
| 2292 | By default the value is true. | - | ||||||||||||||||||||||||||||||
| 2293 | - | |||||||||||||||||||||||||||||||
| 2294 | \sa QTabWidget::documentMode | - | ||||||||||||||||||||||||||||||
| 2295 | */ | - | ||||||||||||||||||||||||||||||
| 2296 | - | |||||||||||||||||||||||||||||||
| 2297 | bool QTabBar::expanding() const | - | ||||||||||||||||||||||||||||||
| 2298 | { | - | ||||||||||||||||||||||||||||||
| 2299 | Q_D(const QTabBar); | - | ||||||||||||||||||||||||||||||
| 2300 | return d->expanding; never executed: return d->expanding; | 0 | ||||||||||||||||||||||||||||||
| 2301 | } | - | ||||||||||||||||||||||||||||||
| 2302 | - | |||||||||||||||||||||||||||||||
| 2303 | void QTabBar::setExpanding(bool enabled) | - | ||||||||||||||||||||||||||||||
| 2304 | { | - | ||||||||||||||||||||||||||||||
| 2305 | Q_D(QTabBar); | - | ||||||||||||||||||||||||||||||
| 2306 | if (d->expanding == enabled)
| 0 | ||||||||||||||||||||||||||||||
| 2307 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||
| 2308 | d->expanding = enabled; | - | ||||||||||||||||||||||||||||||
| 2309 | d->layoutTabs(); | - | ||||||||||||||||||||||||||||||
| 2310 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
| 2311 | - | |||||||||||||||||||||||||||||||
| 2312 | /*! | - | ||||||||||||||||||||||||||||||
| 2313 | \property QTabBar::movable | - | ||||||||||||||||||||||||||||||
| 2314 | \brief This property holds whether the user can move the tabs | - | ||||||||||||||||||||||||||||||
| 2315 | within the tabbar area. | - | ||||||||||||||||||||||||||||||
| 2316 | - | |||||||||||||||||||||||||||||||
| 2317 | \since 4.5 | - | ||||||||||||||||||||||||||||||
| 2318 | - | |||||||||||||||||||||||||||||||
| 2319 | By default, this property is \c false; | - | ||||||||||||||||||||||||||||||
| 2320 | */ | - | ||||||||||||||||||||||||||||||
| 2321 | - | |||||||||||||||||||||||||||||||
| 2322 | bool QTabBar::isMovable() const | - | ||||||||||||||||||||||||||||||
| 2323 | { | - | ||||||||||||||||||||||||||||||
| 2324 | Q_D(const QTabBar); | - | ||||||||||||||||||||||||||||||
| 2325 | return d->movable; never executed: return d->movable; | 0 | ||||||||||||||||||||||||||||||
| 2326 | } | - | ||||||||||||||||||||||||||||||
| 2327 | - | |||||||||||||||||||||||||||||||
| 2328 | void QTabBar::setMovable(bool movable) | - | ||||||||||||||||||||||||||||||
| 2329 | { | - | ||||||||||||||||||||||||||||||
| 2330 | Q_D(QTabBar); | - | ||||||||||||||||||||||||||||||
| 2331 | d->movable = movable; | - | ||||||||||||||||||||||||||||||
| 2332 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
| 2333 | - | |||||||||||||||||||||||||||||||
| 2334 | - | |||||||||||||||||||||||||||||||
| 2335 | /*! | - | ||||||||||||||||||||||||||||||
| 2336 | \property QTabBar::documentMode | - | ||||||||||||||||||||||||||||||
| 2337 | \brief Whether or not the tab bar is rendered in a mode suitable for the main window. | - | ||||||||||||||||||||||||||||||
| 2338 | \since 4.5 | - | ||||||||||||||||||||||||||||||
| 2339 | - | |||||||||||||||||||||||||||||||
| 2340 | This property is used as a hint for styles to draw the tabs in a different | - | ||||||||||||||||||||||||||||||
| 2341 | way then they would normally look in a tab widget. On \macos this will | - | ||||||||||||||||||||||||||||||
| 2342 | look similar to the tabs in Safari or Leopard's Terminal.app. | - | ||||||||||||||||||||||||||||||
| 2343 | - | |||||||||||||||||||||||||||||||
| 2344 | \sa QTabWidget::documentMode | - | ||||||||||||||||||||||||||||||
| 2345 | */ | - | ||||||||||||||||||||||||||||||
| 2346 | bool QTabBar::documentMode() const | - | ||||||||||||||||||||||||||||||
| 2347 | { | - | ||||||||||||||||||||||||||||||
| 2348 | return d_func()->documentMode; never executed: return d_func()->documentMode; | 0 | ||||||||||||||||||||||||||||||
| 2349 | } | - | ||||||||||||||||||||||||||||||
| 2350 | - | |||||||||||||||||||||||||||||||
| 2351 | void QTabBar::setDocumentMode(bool enabled) | - | ||||||||||||||||||||||||||||||
| 2352 | { | - | ||||||||||||||||||||||||||||||
| 2353 | Q_D(QTabBar); | - | ||||||||||||||||||||||||||||||
| 2354 | - | |||||||||||||||||||||||||||||||
| 2355 | d->documentMode = enabled; | - | ||||||||||||||||||||||||||||||
| 2356 | d->updateMacBorderMetrics(); | - | ||||||||||||||||||||||||||||||
| 2357 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
| 2358 | - | |||||||||||||||||||||||||||||||
| 2359 | /*! | - | ||||||||||||||||||||||||||||||
| 2360 | \property QTabBar::autoHide | - | ||||||||||||||||||||||||||||||
| 2361 | \brief If true, the tab bar is automatically hidden when it contains less | - | ||||||||||||||||||||||||||||||
| 2362 | than 2 tabs. | - | ||||||||||||||||||||||||||||||
| 2363 | \since 5.4 | - | ||||||||||||||||||||||||||||||
| 2364 | - | |||||||||||||||||||||||||||||||
| 2365 | By default, this property is false. | - | ||||||||||||||||||||||||||||||
| 2366 | - | |||||||||||||||||||||||||||||||
| 2367 | \sa QWidget::visible | - | ||||||||||||||||||||||||||||||
| 2368 | */ | - | ||||||||||||||||||||||||||||||
| 2369 | - | |||||||||||||||||||||||||||||||
| 2370 | bool QTabBar::autoHide() const | - | ||||||||||||||||||||||||||||||
| 2371 | { | - | ||||||||||||||||||||||||||||||
| 2372 | Q_D(const QTabBar); | - | ||||||||||||||||||||||||||||||
| 2373 | return d->autoHide; never executed: return d->autoHide; | 0 | ||||||||||||||||||||||||||||||
| 2374 | } | - | ||||||||||||||||||||||||||||||
| 2375 | - | |||||||||||||||||||||||||||||||
| 2376 | void QTabBar::setAutoHide(bool hide) | - | ||||||||||||||||||||||||||||||
| 2377 | { | - | ||||||||||||||||||||||||||||||
| 2378 | Q_D(QTabBar); | - | ||||||||||||||||||||||||||||||
| 2379 | if (d->autoHide == hide)
| 0 | ||||||||||||||||||||||||||||||
| 2380 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||
| 2381 | - | |||||||||||||||||||||||||||||||
| 2382 | d->autoHide = hide; | - | ||||||||||||||||||||||||||||||
| 2383 | if (hide)
| 0 | ||||||||||||||||||||||||||||||
| 2384 | d->autoHideTabs(); never executed: d->autoHideTabs(); | 0 | ||||||||||||||||||||||||||||||
| 2385 | else | - | ||||||||||||||||||||||||||||||
| 2386 | setVisible(true); never executed: setVisible(true); | 0 | ||||||||||||||||||||||||||||||
| 2387 | } | - | ||||||||||||||||||||||||||||||
| 2388 | - | |||||||||||||||||||||||||||||||
| 2389 | /*! | - | ||||||||||||||||||||||||||||||
| 2390 | \property QTabBar::changeCurrentOnDrag | - | ||||||||||||||||||||||||||||||
| 2391 | \brief If true, then the current tab is automatically changed when dragging | - | ||||||||||||||||||||||||||||||
| 2392 | over the tabbar. | - | ||||||||||||||||||||||||||||||
| 2393 | \since 5.4 | - | ||||||||||||||||||||||||||||||
| 2394 | - | |||||||||||||||||||||||||||||||
| 2395 | \note You should also set acceptDrops property to true to make this feature | - | ||||||||||||||||||||||||||||||
| 2396 | work. | - | ||||||||||||||||||||||||||||||
| 2397 | - | |||||||||||||||||||||||||||||||
| 2398 | By default, this property is false. | - | ||||||||||||||||||||||||||||||
| 2399 | */ | - | ||||||||||||||||||||||||||||||
| 2400 | - | |||||||||||||||||||||||||||||||
| 2401 | bool QTabBar::changeCurrentOnDrag() const | - | ||||||||||||||||||||||||||||||
| 2402 | { | - | ||||||||||||||||||||||||||||||
| 2403 | Q_D(const QTabBar); | - | ||||||||||||||||||||||||||||||
| 2404 | return d->changeCurrentOnDrag; never executed: return d->changeCurrentOnDrag; | 0 | ||||||||||||||||||||||||||||||
| 2405 | } | - | ||||||||||||||||||||||||||||||
| 2406 | - | |||||||||||||||||||||||||||||||
| 2407 | void QTabBar::setChangeCurrentOnDrag(bool change) | - | ||||||||||||||||||||||||||||||
| 2408 | { | - | ||||||||||||||||||||||||||||||
| 2409 | Q_D(QTabBar); | - | ||||||||||||||||||||||||||||||
| 2410 | d->changeCurrentOnDrag = change; | - | ||||||||||||||||||||||||||||||
| 2411 | if (!change)
| 0 | ||||||||||||||||||||||||||||||
| 2412 | d->killSwitchTabTimer(); never executed: d->killSwitchTabTimer(); | 0 | ||||||||||||||||||||||||||||||
| 2413 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
| 2414 | - | |||||||||||||||||||||||||||||||
| 2415 | /*! | - | ||||||||||||||||||||||||||||||
| 2416 | Sets \a widget on the tab \a index. The widget is placed | - | ||||||||||||||||||||||||||||||
| 2417 | on the left or right hand side depending upon the \a position. | - | ||||||||||||||||||||||||||||||
| 2418 | \since 4.5 | - | ||||||||||||||||||||||||||||||
| 2419 | - | |||||||||||||||||||||||||||||||
| 2420 | Any previously set widget in \a position is hidden. | - | ||||||||||||||||||||||||||||||
| 2421 | - | |||||||||||||||||||||||||||||||
| 2422 | The tab bar will take ownership of the widget and so all widgets set here | - | ||||||||||||||||||||||||||||||
| 2423 | will be deleted by the tab bar when it is destroyed unless you separately | - | ||||||||||||||||||||||||||||||
| 2424 | reparent the widget after setting some other widget (or 0). | - | ||||||||||||||||||||||||||||||
| 2425 | - | |||||||||||||||||||||||||||||||
| 2426 | \sa tabsClosable() | - | ||||||||||||||||||||||||||||||
| 2427 | */ | - | ||||||||||||||||||||||||||||||
| 2428 | void QTabBar::setTabButton(int index, ButtonPosition position, QWidget *widget) | - | ||||||||||||||||||||||||||||||
| 2429 | { | - | ||||||||||||||||||||||||||||||
| 2430 | Q_D(QTabBar); | - | ||||||||||||||||||||||||||||||
| 2431 | if (index < 0 || index >= d->tabList.count())
| 0 | ||||||||||||||||||||||||||||||
| 2432 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||
| 2433 | if (widget) {
| 0 | ||||||||||||||||||||||||||||||
| 2434 | widget->setParent(this); | - | ||||||||||||||||||||||||||||||
| 2435 | // make sure our left and right widgets stay on top | - | ||||||||||||||||||||||||||||||
| 2436 | widget->lower(); | - | ||||||||||||||||||||||||||||||
| 2437 | widget->show(); | - | ||||||||||||||||||||||||||||||
| 2438 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
| 2439 | if (position == LeftSide) {
| 0 | ||||||||||||||||||||||||||||||
| 2440 | if (d->tabList[index].leftWidget)
| 0 | ||||||||||||||||||||||||||||||
| 2441 | d->tabList[index].leftWidget->hide(); never executed: d->tabList[index].leftWidget->hide(); | 0 | ||||||||||||||||||||||||||||||
| 2442 | d->tabList[index].leftWidget = widget; | - | ||||||||||||||||||||||||||||||
| 2443 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||||||||
| 2444 | if (d->tabList[index].rightWidget)
| 0 | ||||||||||||||||||||||||||||||
| 2445 | d->tabList[index].rightWidget->hide(); never executed: d->tabList[index].rightWidget->hide(); | 0 | ||||||||||||||||||||||||||||||
| 2446 | d->tabList[index].rightWidget = widget; | - | ||||||||||||||||||||||||||||||
| 2447 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
| 2448 | d->layoutTabs(); | - | ||||||||||||||||||||||||||||||
| 2449 | d->refresh(); | - | ||||||||||||||||||||||||||||||
| 2450 | update(); | - | ||||||||||||||||||||||||||||||
| 2451 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
| 2452 | - | |||||||||||||||||||||||||||||||
| 2453 | /*! | - | ||||||||||||||||||||||||||||||
| 2454 | Returns the widget set a tab \a index and \a position or 0 if | - | ||||||||||||||||||||||||||||||
| 2455 | one is not set. | - | ||||||||||||||||||||||||||||||
| 2456 | */ | - | ||||||||||||||||||||||||||||||
| 2457 | QWidget *QTabBar::tabButton(int index, ButtonPosition position) const | - | ||||||||||||||||||||||||||||||
| 2458 | { | - | ||||||||||||||||||||||||||||||
| 2459 | Q_D(const QTabBar); | - | ||||||||||||||||||||||||||||||
| 2460 | if (index < 0 || index >= d->tabList.count())
| 0 | ||||||||||||||||||||||||||||||
| 2461 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||||||||
| 2462 | if (position == LeftSide)
| 0 | ||||||||||||||||||||||||||||||
| 2463 | return d->tabList.at(index).leftWidget; never executed: return d->tabList.at(index).leftWidget; | 0 | ||||||||||||||||||||||||||||||
| 2464 | else | - | ||||||||||||||||||||||||||||||
| 2465 | return d->tabList.at(index).rightWidget; never executed: return d->tabList.at(index).rightWidget; | 0 | ||||||||||||||||||||||||||||||
| 2466 | } | - | ||||||||||||||||||||||||||||||
| 2467 | - | |||||||||||||||||||||||||||||||
| 2468 | CloseButton::CloseButton(QWidget *parent) | - | ||||||||||||||||||||||||||||||
| 2469 | : QAbstractButton(parent) | - | ||||||||||||||||||||||||||||||
| 2470 | { | - | ||||||||||||||||||||||||||||||
| 2471 | setFocusPolicy(Qt::NoFocus); | - | ||||||||||||||||||||||||||||||
| 2472 | #ifndef QT_NO_CURSOR | - | ||||||||||||||||||||||||||||||
| 2473 | setCursor(Qt::ArrowCursor); | - | ||||||||||||||||||||||||||||||
| 2474 | #endif | - | ||||||||||||||||||||||||||||||
| 2475 | #ifndef QT_NO_TOOLTIP | - | ||||||||||||||||||||||||||||||
| 2476 | setToolTip(tr("Close Tab")); | - | ||||||||||||||||||||||||||||||
| 2477 | #endif | - | ||||||||||||||||||||||||||||||
| 2478 | resize(sizeHint()); | - | ||||||||||||||||||||||||||||||
| 2479 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
| 2480 | - | |||||||||||||||||||||||||||||||
| 2481 | QSize CloseButton::sizeHint() const | - | ||||||||||||||||||||||||||||||
| 2482 | { | - | ||||||||||||||||||||||||||||||
| 2483 | ensurePolished(); | - | ||||||||||||||||||||||||||||||
| 2484 | int width = style()->pixelMetric(QStyle::PM_TabCloseIndicatorWidth, 0, this); | - | ||||||||||||||||||||||||||||||
| 2485 | int height = style()->pixelMetric(QStyle::PM_TabCloseIndicatorHeight, 0, this); | - | ||||||||||||||||||||||||||||||
| 2486 | return QSize(width, height); never executed: return QSize(width, height); | 0 | ||||||||||||||||||||||||||||||
| 2487 | } | - | ||||||||||||||||||||||||||||||
| 2488 | - | |||||||||||||||||||||||||||||||
| 2489 | void CloseButton::enterEvent(QEvent *event) | - | ||||||||||||||||||||||||||||||
| 2490 | { | - | ||||||||||||||||||||||||||||||
| 2491 | if (isEnabled())
| 0 | ||||||||||||||||||||||||||||||
| 2492 | update(); never executed: update(); | 0 | ||||||||||||||||||||||||||||||
| 2493 | QAbstractButton::enterEvent(event); | - | ||||||||||||||||||||||||||||||
| 2494 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
| 2495 | - | |||||||||||||||||||||||||||||||
| 2496 | void CloseButton::leaveEvent(QEvent *event) | - | ||||||||||||||||||||||||||||||
| 2497 | { | - | ||||||||||||||||||||||||||||||
| 2498 | if (isEnabled())
| 0 | ||||||||||||||||||||||||||||||
| 2499 | update(); never executed: update(); | 0 | ||||||||||||||||||||||||||||||
| 2500 | QAbstractButton::leaveEvent(event); | - | ||||||||||||||||||||||||||||||
| 2501 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
| 2502 | - | |||||||||||||||||||||||||||||||
| 2503 | void CloseButton::paintEvent(QPaintEvent *) | - | ||||||||||||||||||||||||||||||
| 2504 | { | - | ||||||||||||||||||||||||||||||
| 2505 | QPainter p(this); | - | ||||||||||||||||||||||||||||||
| 2506 | QStyleOption opt; | - | ||||||||||||||||||||||||||||||
| 2507 | opt.init(this); | - | ||||||||||||||||||||||||||||||
| 2508 | opt.state |= QStyle::State_AutoRaise; | - | ||||||||||||||||||||||||||||||
| 2509 | if (isEnabled() && underMouse() && !isChecked() && !isDown())
| 0 | ||||||||||||||||||||||||||||||
| 2510 | opt.state |= QStyle::State_Raised; never executed: opt.state |= QStyle::State_Raised; | 0 | ||||||||||||||||||||||||||||||
| 2511 | if (isChecked())
| 0 | ||||||||||||||||||||||||||||||
| 2512 | opt.state |= QStyle::State_On; never executed: opt.state |= QStyle::State_On; | 0 | ||||||||||||||||||||||||||||||
| 2513 | if (isDown())
| 0 | ||||||||||||||||||||||||||||||
| 2514 | opt.state |= QStyle::State_Sunken; never executed: opt.state |= QStyle::State_Sunken; | 0 | ||||||||||||||||||||||||||||||
| 2515 | - | |||||||||||||||||||||||||||||||
| 2516 | if (const QTabBar *tb = qobject_cast<const QTabBar *>(parent())) {
| 0 | ||||||||||||||||||||||||||||||
| 2517 | int index = tb->currentIndex(); | - | ||||||||||||||||||||||||||||||
| 2518 | QTabBar::ButtonPosition position = (QTabBar::ButtonPosition)style()->styleHint(QStyle::SH_TabBar_CloseButtonPosition, 0, tb); | - | ||||||||||||||||||||||||||||||
| 2519 | if (tb->tabButton(index, position) == this)
| 0 | ||||||||||||||||||||||||||||||
| 2520 | opt.state |= QStyle::State_Selected; never executed: opt.state |= QStyle::State_Selected; | 0 | ||||||||||||||||||||||||||||||
| 2521 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
| 2522 | - | |||||||||||||||||||||||||||||||
| 2523 | style()->drawPrimitive(QStyle::PE_IndicatorTabClose, &opt, &p, this); | - | ||||||||||||||||||||||||||||||
| 2524 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
| 2525 | - | |||||||||||||||||||||||||||||||
| 2526 | #ifndef QT_NO_ANIMATION | - | ||||||||||||||||||||||||||||||
| 2527 | void QTabBarPrivate::Tab::TabBarAnimation::updateCurrentValue(const QVariant ¤t) | - | ||||||||||||||||||||||||||||||
| 2528 | { | - | ||||||||||||||||||||||||||||||
| 2529 | priv->moveTab(priv->tabList.indexOf(*tab), current.toInt()); | - | ||||||||||||||||||||||||||||||
| 2530 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
| 2531 | - | |||||||||||||||||||||||||||||||
| 2532 | void QTabBarPrivate::Tab::TabBarAnimation::updateState(QAbstractAnimation::State, QAbstractAnimation::State newState) | - | ||||||||||||||||||||||||||||||
| 2533 | { | - | ||||||||||||||||||||||||||||||
| 2534 | if (newState == Stopped) priv->moveTabFinished(priv->tabList.indexOf(*tab)); never executed: priv->moveTabFinished(priv->tabList.indexOf(*tab));
| 0 | ||||||||||||||||||||||||||||||
| 2535 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
| 2536 | #endif | - | ||||||||||||||||||||||||||||||
| 2537 | - | |||||||||||||||||||||||||||||||
| 2538 | QT_END_NAMESPACE | - | ||||||||||||||||||||||||||||||
| 2539 | - | |||||||||||||||||||||||||||||||
| 2540 | #include "moc_qtabbar.cpp" | - | ||||||||||||||||||||||||||||||
| 2541 | - | |||||||||||||||||||||||||||||||
| 2542 | #endif // QT_NO_TABBAR | - | ||||||||||||||||||||||||||||||
| 2543 | - | |||||||||||||||||||||||||||||||
| 2544 | #include "moc_qtabbar_p.cpp" | - | ||||||||||||||||||||||||||||||
| Source code | Switch to Preprocessed file |