| Line | Source | Count |
| 1 | | - |
| 2 | | - |
| 3 | | - |
| 4 | | - |
| 5 | | - |
| 6 | | - |
| 7 | | - |
| 8 | | - |
| 9 | | - |
| 10 | | - |
| 11 | | - |
| 12 | | - |
| 13 | | - |
| 14 | | - |
| 15 | | - |
| 16 | | - |
| 17 | | - |
| 18 | | - |
| 19 | | - |
| 20 | | - |
| 21 | | - |
| 22 | | - |
| 23 | | - |
| 24 | | - |
| 25 | | - |
| 26 | | - |
| 27 | | - |
| 28 | | - |
| 29 | | - |
| 30 | | - |
| 31 | | - |
| 32 | | - |
| 33 | | - |
| 34 | | - |
| 35 | | - |
| 36 | | - |
| 37 | | - |
| 38 | | - |
| 39 | | - |
| 40 | #include "private/qlayoutengine_p.h" | - |
| 41 | #include "qabstractitemdelegate.h" | - |
| 42 | #include "qapplication.h" | - |
| 43 | #include "qbitmap.h" | - |
| 44 | #include "qcursor.h" | - |
| 45 | #include "qevent.h" | - |
| 46 | #include "qpainter.h" | - |
| 47 | #include "qstyle.h" | - |
| 48 | #include "qstyleoption.h" | - |
| 49 | #include "qstylepainter.h" | - |
| 50 | #include "qtabwidget.h" | - |
| 51 | #include "qtooltip.h" | - |
| 52 | #include "qwhatsthis.h" | - |
| 53 | #include "private/qtextengine_p.h" | - |
| 54 | #ifndef QT_NO_ACCESSIBILITY | - |
| 55 | #include "qaccessible.h" | - |
| 56 | #endif | - |
| 57 | #ifdef Q_OS_OSX | - |
| 58 | #include <qpa/qplatformnativeinterface.h> | - |
| 59 | #endif | - |
| 60 | | - |
| 61 | #include "qdebug.h" | - |
| 62 | #include "private/qtabbar_p.h" | - |
| 63 | | - |
| 64 | #ifndef QT_NO_TABBAR | - |
| 65 | | - |
| 66 | #ifdef Q_DEAD_CODE_FROM_QT4_MAC | - |
| 67 | #include <private/qt_mac_p.h> | - |
| 68 | #include <private/qt_cocoa_helpers_mac_p.h> | - |
| 69 | #endif | - |
| 70 | | - |
| 71 | QT_BEGIN_NAMESPACE | - |
| 72 | | - |
| 73 | QMovableTabWidget::QMovableTabWidget(QWidget *parent) | - |
| 74 | : QWidget(parent) | - |
| 75 | { | - |
| 76 | } | - |
| 77 | | - |
| 78 | void QMovableTabWidget::setPixmap(const QPixmap &pixmap) | - |
| 79 | { | - |
| 80 | m_pixmap = pixmap; | - |
| 81 | update(); | - |
| 82 | } | - |
| 83 | | - |
| 84 | void QMovableTabWidget::paintEvent(QPaintEvent *e) | - |
| 85 | { | - |
| 86 | Q_UNUSED(e); | - |
| 87 | QPainter p(this); | - |
| 88 | p.drawPixmap(0, 0, m_pixmap); | - |
| 89 | } | - |
| 90 | | - |
| 91 | inline static bool verticalTabs(QTabBar::Shape shape) | - |
| 92 | { | - |
| 93 | return shape == QTabBar::RoundedWest | - |
| 94 | || shape == QTabBar::RoundedEast | - |
| 95 | || shape == QTabBar::TriangularWest | - |
| 96 | || shape == QTabBar::TriangularEast; | - |
| 97 | } | - |
| 98 | | - |
| 99 | void QTabBarPrivate::updateMacBorderMetrics() | - |
| 100 | { | - |
| 101 | #if defined(Q_OS_OSX) | - |
| 102 | Q_Q(QTabBar); | - |
| 103 | | - |
| 104 | | - |
| 105 | | - |
| 106 | | - |
| 107 | | - |
| 108 | | - |
| 109 | | - |
| 110 | int upper, lower; | - |
| 111 | if (documentMode) { | - |
| 112 | QPoint windowPos = q->mapTo(q->window(), QPoint(0,0)); | - |
| 113 | upper = windowPos.y(); | - |
| 114 | int tabStripHeight = q->tabSizeHint(0).height(); | - |
| 115 | int pixelTweak = -3; | - |
| 116 | lower = upper + tabStripHeight + pixelTweak; | - |
| 117 | } else { | - |
| 118 | upper = 0; | - |
| 119 | lower = 0; | - |
| 120 | } | - |
| 121 | | - |
| 122 | QPlatformNativeInterface *nativeInterface = QGuiApplication::platformNativeInterface(); | - |
| 123 | quintptr identifier = reinterpret_cast<quintptr>(q); | - |
| 124 | | - |
| 125 | | - |
| 126 | QPlatformNativeInterface::NativeResourceForIntegrationFunction function = | - |
| 127 | nativeInterface->nativeResourceFunctionForIntegration("registerContentBorderArea"); | - |
| 128 | if (!function) | - |
| 129 | return; | - |
| 130 | typedef void (*RegisterContentBorderAreaFunction)(QWindow *window, quintptr identifier, int upper, int lower); | - |
| 131 | (reinterpret_cast<RegisterContentBorderAreaFunction>(function))(q->window()->windowHandle(), identifier, upper, lower); | - |
| 132 | | - |
| 133 | | - |
| 134 | function = nativeInterface->nativeResourceFunctionForIntegration("setContentBorderAreaEnabled"); | - |
| 135 | if (!function) | - |
| 136 | return; | - |
| 137 | typedef void (*SetContentBorderAreaEnabledFunction)(QWindow *window, quintptr identifier, bool enable); | - |
| 138 | (reinterpret_cast<SetContentBorderAreaEnabledFunction>(function))(q->window()->windowHandle(), identifier, q->isVisible()); | - |
| 139 | #endif | - |
| 140 | } | - |
| 141 | | - |
| 142 | | - |
| 143 | | - |
| 144 | | - |
| 145 | | - |
| 146 | | - |
| 147 | | - |
| 148 | void QTabBarPrivate::initBasicStyleOption(QStyleOptionTab *option, int tabIndex) const | - |
| 149 | { | - |
| 150 | Q_Q(const QTabBar); | - |
| 151 | const int totalTabs = tabList.size(); | - |
| 152 | | - |
| 153 | if (!option || (tabIndex < 0 || tabIndex >= totalTabs))| TRUE | never evaluated | | FALSE | never evaluated |
| TRUE | never evaluated | | FALSE | never evaluated |
| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 154 | return; never executed: return; | 0 |
| 155 | | - |
| 156 | const QTabBarPrivate::Tab &tab = tabList.at(tabIndex); | - |
| 157 | option->initFrom(q); | - |
| 158 | option->state &= ~(QStyle::State_HasFocus | QStyle::State_MouseOver); | - |
| 159 | option->rect = q->tabRect(tabIndex); | - |
| 160 | const bool isCurrent = tabIndex == currentIndex; | - |
| 161 | option->row = 0; | - |
| 162 | if (tabIndex == pressedIndex)| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 163 | option->state |= QStyle::State_Sunken; never executed: option->state |= QStyle::State_Sunken; | 0 |
| 164 | if (isCurrent)| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 165 | option->state |= QStyle::State_Selected; never executed: option->state |= QStyle::State_Selected; | 0 |
| 166 | if (isCurrent && q->hasFocus())| TRUE | never evaluated | | FALSE | never evaluated |
| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 167 | option->state |= QStyle::State_HasFocus; never executed: option->state |= QStyle::State_HasFocus; | 0 |
| 168 | if (!tab.enabled)| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 169 | option->state &= ~QStyle::State_Enabled; never executed: option->state &= ~QStyle::State_Enabled; | 0 |
| 170 | if (q->isActiveWindow())| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 171 | option->state |= QStyle::State_Active; never executed: option->state |= QStyle::State_Active; | 0 |
| 172 | if (!dragInProgress && option->rect == hoverRect)| TRUE | never evaluated | | FALSE | never evaluated |
| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 173 | option->state |= QStyle::State_MouseOver; never executed: option->state |= QStyle::State_MouseOver; | 0 |
| 174 | option->shape = shape; | - |
| 175 | option->text = tab.text; | - |
| 176 | | - |
| 177 | if (tab.textColor.isValid())| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 178 | option->palette.setColor(q->foregroundRole(), tab.textColor); never executed: option->palette.setColor(q->foregroundRole(), tab.textColor); | 0 |
| 179 | #ifdef Q_OS_MACOS | - |
| 180 | else if (q->style()->inherits("QMacStyle") | - |
| &&isCurrent && !documentMode | |
| 181 | && (QSysInfo::MacintoshVersion < QSysInfo::MV_10_10 || q->isActiveWindow())) { | - |
| 182 | option->palette.setColor(QPalette::WindowText, Qt::white); | - |
| 183 | } | - |
| 184 | #endif | - |
| 185 | option->icon = tab.icon; | - |
| 186 | option->iconSize = q->iconSize(); | - |
| 187 | | - |
| 188 | option->leftButtonSize = tab.leftWidget ? tab.leftWidget->size() : QSize();| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 189 | option->rightButtonSize = tab.rightWidget ? tab.rightWidget->size() : QSize();| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 190 | option->documentMode = documentMode; | - |
| 191 | | - |
| 192 | if (tabIndex > 0 && tabIndex - 1 == currentIndex)| TRUE | never evaluated | | FALSE | never evaluated |
| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 193 | option->selectedPosition = QStyleOptionTab::PreviousIsSelected; never executed: option->selectedPosition = QStyleOptionTab::PreviousIsSelected; | 0 |
| 194 | else if (tabIndex + 1 < totalTabs && tabIndex + 1 == currentIndex)| TRUE | never evaluated | | FALSE | never evaluated |
| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 195 | option->selectedPosition = QStyleOptionTab::NextIsSelected; never executed: option->selectedPosition = QStyleOptionTab::NextIsSelected; | 0 |
| 196 | else | - |
| 197 | option->selectedPosition = QStyleOptionTab::NotAdjacent; never executed: option->selectedPosition = QStyleOptionTab::NotAdjacent; | 0 |
| 198 | | - |
| 199 | const bool paintBeginning = (tabIndex == 0) || (dragInProgress && tabIndex == pressedIndex + 1);| TRUE | never evaluated | | FALSE | never evaluated |
| TRUE | never evaluated | | FALSE | never evaluated |
| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 200 | const bool paintEnd = (tabIndex == totalTabs - 1) || (dragInProgress && tabIndex == pressedIndex - 1);| TRUE | never evaluated | | FALSE | never evaluated |
| TRUE | never evaluated | | FALSE | never evaluated |
| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 201 | if (paintBeginning) {| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 202 | if (paintEnd)| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 203 | option->position = QStyleOptionTab::OnlyOneTab; never executed: option->position = QStyleOptionTab::OnlyOneTab; | 0 |
| 204 | else | - |
| 205 | option->position = QStyleOptionTab::Beginning; never executed: option->position = QStyleOptionTab::Beginning; | 0 |
| 206 | } else if (paintEnd) {| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 207 | option->position = QStyleOptionTab::End; | - |
| 208 | } else { never executed: end of block | 0 |
| 209 | option->position = QStyleOptionTab::Middle; | - |
| 210 | } never executed: end of block | 0 |
| 211 | | - |
| 212 | #ifndef QT_NO_TABWIDGET | - |
| 213 | if (const QTabWidget *tw = qobject_cast<const QTabWidget *>(q->parentWidget())) {| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 214 | option->features |= QStyleOptionTab::HasFrame; | - |
| 215 | if (tw->cornerWidget(Qt::TopLeftCorner) || tw->cornerWidget(Qt::BottomLeftCorner))| TRUE | never evaluated | | FALSE | never evaluated |
| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 216 | option->cornerWidgets |= QStyleOptionTab::LeftCornerWidget; never executed: option->cornerWidgets |= QStyleOptionTab::LeftCornerWidget; | 0 |
| 217 | if (tw->cornerWidget(Qt::TopRightCorner) || tw->cornerWidget(Qt::BottomRightCorner))| TRUE | never evaluated | | FALSE | never evaluated |
| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 218 | option->cornerWidgets |= QStyleOptionTab::RightCornerWidget; never executed: option->cornerWidgets |= QStyleOptionTab::RightCornerWidget; | 0 |
| 219 | } never executed: end of block | 0 |
| 220 | #endif | - |
| 221 | } never executed: end of block | 0 |
| 222 | | - |
| 223 | | - |
| 224 | | - |
| 225 | | - |
| 226 | | - |
| 227 | | - |
| 228 | | - |
| 229 | | - |
| 230 | void QTabBar::initStyleOption(QStyleOptionTab *option, int tabIndex) const | - |
| 231 | { | - |
| 232 | Q_D(const QTabBar); | - |
| 233 | d->initBasicStyleOption(option, tabIndex); | - |
| 234 | | - |
| 235 | QRect textRect = style()->subElementRect(QStyle::SE_TabBarTabText, option, this); | - |
| 236 | option->text = fontMetrics().elidedText(option->text, d->elideMode, textRect.width(), | - |
| 237 | Qt::TextShowMnemonic); | - |
| 238 | } | - |
| 239 | | - |
| 240 | | - |
| 241 | | - |
| 242 | | - |
| 243 | | - |
| 244 | | - |
| 245 | | - |
| 246 | | - |
| 247 | | - |
| 248 | | - |
| 249 | | - |
| 250 | | - |
| 251 | | - |
| 252 | | - |
| 253 | | - |
| 254 | | - |
| 255 | | - |
| 256 | | - |
| 257 | | - |
| 258 | | - |
| 259 | | - |
| 260 | | - |
| 261 | | - |
| 262 | | - |
| 263 | | - |
| 264 | | - |
| 265 | | - |
| 266 | | - |
| 267 | | - |
| 268 | | - |
| 269 | | - |
| 270 | | - |
| 271 | | - |
| 272 | | - |
| 273 | | - |
| 274 | | - |
| 275 | | - |
| 276 | | - |
| 277 | | - |
| 278 | | - |
| 279 | | - |
| 280 | | - |
| 281 | | - |
| 282 | | - |
| 283 | | - |
| 284 | | - |
| 285 | | - |
| 286 | | - |
| 287 | | - |
| 288 | | - |
| 289 | | - |
| 290 | | - |
| 291 | | - |
| 292 | | - |
| 293 | | - |
| 294 | | - |
| 295 | | - |
| 296 | | - |
| 297 | | - |
| 298 | | - |
| 299 | | - |
| 300 | | - |
| 301 | | - |
| 302 | | - |
| 303 | | - |
| 304 | | - |
| 305 | | - |
| 306 | | - |
| 307 | | - |
| 308 | | - |
| 309 | | - |
| 310 | | - |
| 311 | | - |
| 312 | | - |
| 313 | | - |
| 314 | | - |
| 315 | | - |
| 316 | | - |
| 317 | | - |
| 318 | | - |
| 319 | | - |
| 320 | | - |
| 321 | | - |
| 322 | | - |
| 323 | | - |
| 324 | | - |
| 325 | | - |
| 326 | | - |
| 327 | | - |
| 328 | | - |
| 329 | | - |
| 330 | | - |
| 331 | | - |
| 332 | | - |
| 333 | | - |
| 334 | | - |
| 335 | | - |
| 336 | | - |
| 337 | | - |
| 338 | | - |
| 339 | | - |
| 340 | | - |
| 341 | | - |
| 342 | | - |
| 343 | | - |
| 344 | | - |
| 345 | | - |
| 346 | | - |
| 347 | | - |
| 348 | | - |
| 349 | | - |
| 350 | | - |
| 351 | | - |
| 352 | | - |
| 353 | | - |
| 354 | | - |
| 355 | | - |
| 356 | | - |
| 357 | | - |
| 358 | | - |
| 359 | | - |
| 360 | | - |
| 361 | | - |
| 362 | | - |
| 363 | | - |
| 364 | | - |
| 365 | | - |
| 366 | | - |
| 367 | | - |
| 368 | | - |
| 369 | | - |
| 370 | | - |
| 371 | | - |
| 372 | | - |
| 373 | | - |
| 374 | | - |
| 375 | | - |
| 376 | | - |
| 377 | | - |
| 378 | | - |
| 379 | | - |
| 380 | | - |
| 381 | | - |
| 382 | | - |
| 383 | | - |
| 384 | | - |
| 385 | | - |
| 386 | | - |
| 387 | | - |
| 388 | | - |
| 389 | | - |
| 390 | | - |
| int QTabBarPrivate::extraWidth() const | |
| { | |
| Q_Q(const QTabBar); | |
| return 2 * qMax(q->style()->pixelMetric(QStyle::PM_TabBarScrollButtonWidth, 0, q), | |
| QApplication::globalStrut().width()); | |
| }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 | } | - |
| 419 | | - |
| 420 | QTabBarPrivate::Tab *QTabBarPrivate::at(int index) | - |
| 421 | { | - |
| 422 | return validIndex(index)?&tabList[index]:0; | - |
| 423 | } | - |
| 424 | | - |
| 425 | const QTabBarPrivate::Tab *QTabBarPrivate::at(int index) const | - |
| 426 | { | - |
| 427 | return validIndex(index)?&tabList[index]:0; | - |
| 428 | } | - |
| 429 | | - |
| 430 | int QTabBarPrivate::indexAtPos(const QPoint &p) const | - |
| 431 | { | - |
| 432 | Q_Q(const QTabBar); | - |
| 433 | if (q->tabRect(currentIndex).contains(p)) | - |
| 434 | return currentIndex; | - |
| 435 | for (int i = 0; i < tabList.count(); ++i) | - |
| 436 | if (tabList.at(i).enabled && q->tabRect(i).contains(p)) | - |
| 437 | return i; | - |
| 438 | return -1; | - |
| 439 | } | - |
| 440 | | - |
| 441 | void QTabBarPrivate::layoutTabs() | - |
| 442 | { | - |
| 443 | Q_Q(QTabBar); | - |
| 444 | scrollOffset = 0;layoutDirty = false; | - |
| 445 | QSize size = q->size(); | - |
| 446 | int last, available; | - |
| 447 | int maxExtent; | - |
| 448 | int i; | - |
| 449 | bool vertTabs = verticalTabs(shape); | - |
| 450 | int tabChainIndex = 0; | - |
| 451 | | - |
| 452 | Qt::Alignment tabAlignment = Qt::Alignment(q->style()->styleHint(QStyle::SH_TabBar_Alignment, 0, q)); | - |
| 453 | QVector<QLayoutStruct> tabChain(tabList.count() + 2); | - |
| 454 | | - |
| 455 | | - |
| 456 | | - |
| 457 | tabChain[tabChainIndex].init(); | - |
| 458 | tabChain[tabChainIndex].expansive = (tabAlignment != Qt::AlignLeft)| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 459 | && (tabAlignment != Qt::AlignJustify);| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 460 | tabChain[tabChainIndex].empty = true; | - |
| 461 | ++tabChainIndex; | - |
| 462 | | - |
| 463 | | - |
| 464 | | - |
| 465 | | - |
| 466 | | - |
| 467 | | - |
| 468 | | - |
| 469 | | - |
| 470 | | - |
| 471 | if (!vertTabs) {| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 472 | int minx = 0; | - |
| 473 | int x = 0; | - |
| 474 | int maxHeight = 0; | - |
| 475 | for (i = 0; i < tabList.count(); ++i, ++tabChainIndex) {| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 476 | QSize sz = q->tabSizeHint(i); | - |
| 477 | tabList[i].maxRect = QRect(x, 0, sz.width(), sz.height()); | - |
| 478 | x += sz.width(); | - |
| 479 | maxHeight = qMax(maxHeight, sz.height()); | - |
| 480 | sz = q->minimumTabSizeHint(i); | - |
| 481 | tabList[i].minRect = QRect(minx, 0, sz.width(), sz.height()); | - |
| 482 | minx += sz.width(); | - |
| 483 | tabChain[tabChainIndex].init(); | - |
| 484 | tabChain[tabChainIndex].sizeHint = tabList.at(i).maxRect.width(); | - |
| 485 | tabChain[tabChainIndex].minimumSize = sz.width(); | - |
| 486 | tabChain[tabChainIndex].empty = false; | - |
| 487 | tabChain[tabChainIndex].expansive = true; | - |
| 488 | | - |
| 489 | if (!expanding)| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 490 | tabChain[tabChainIndex].maximumSize = tabChain[tabChainIndex].sizeHint; never executed: tabChain[tabChainIndex].maximumSize = tabChain[tabChainIndex].sizeHint; | 0 |
| 491 | } never executed: end of block | 0 |
| 492 | | - |
| 493 | last = minx; | - |
| 494 | available = size.width(); | - |
| 495 | maxExtent = maxHeight; | - |
| 496 | } else { never executed: end of block | 0 |
| 497 | int miny = 0; | - |
| 498 | int y = 0; | - |
| 499 | int maxWidth = 0; | - |
| 500 | for (i = 0; i < tabList.count(); ++i, ++tabChainIndex) {| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 501 | QSize sz = q->tabSizeHint(i); | - |
| 502 | tabList[i].maxRect = QRect(0, y, sz.width(), sz.height()); | - |
| 503 | y += sz.height(); | - |
| 504 | maxWidth = qMax(maxWidth, sz.width()); | - |
| 505 | sz = q->minimumTabSizeHint(i); | - |
| 506 | tabList[i].minRect = QRect(0, miny, sz.width(), sz.height()); | - |
| 507 | miny += sz.height(); | - |
| 508 | tabChain[tabChainIndex].init(); | - |
| 509 | tabChain[tabChainIndex].sizeHint = tabList.at(i).maxRect.height(); | - |
| 510 | tabChain[tabChainIndex].minimumSize = sz.height(); | - |
| 511 | tabChain[tabChainIndex].empty = false; | - |
| 512 | tabChain[tabChainIndex].expansive = true; | - |
| 513 | | - |
| 514 | if (!expanding)| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 515 | tabChain[tabChainIndex].maximumSize = tabChain[tabChainIndex].sizeHint; never executed: tabChain[tabChainIndex].maximumSize = tabChain[tabChainIndex].sizeHint; | 0 |
| 516 | } never executed: end of block | 0 |
| 517 | | - |
| 518 | last = miny; | - |
| 519 | available = size.height(); | - |
| 520 | maxExtent = maxWidth; | - |
| 521 | } never executed: end of block | 0 |
| 522 | | - |
| 523 | Q_ASSERT(tabChainIndex == tabChain.count() - 1); | - |
| 524 | | - |
| 525 | tabChain[tabChainIndex].init(); | - |
| 526 | tabChain[tabChainIndex].expansive = (tabAlignment != Qt::AlignRight)| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 527 | && (tabAlignment != Qt::AlignJustify);| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 528 | tabChain[tabChainIndex].empty = true; | - |
| 529 | | - |
| 530 | | - |
| 531 | qGeomCalc(tabChain, 0, tabChain.count(), 0, qMax(available, last), 0); | - |
| 532 | | - |
| 533 | | - |
| 534 | for (i = 0; i < tabList.count(); ++i) {| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 535 | const QLayoutStruct &lstruct = tabChain.at(i + 1); | - |
| 536 | if (!vertTabs)| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 537 | tabList[i].rect.setRect(lstruct.pos, 0, lstruct.size, maxExtent); never executed: tabList[i].rect.setRect(lstruct.pos, 0, lstruct.size, maxExtent); | 0 |
| 538 | else | - |
| 539 | tabList[i].rect.setRect(0, lstruct.pos, maxExtent, lstruct.size); never executed: tabList[i].rect.setRect(0, lstruct.pos, maxExtent, lstruct.size); | 0 |
| 540 | } | - |
| 541 | | - |
| 542 | if (useScrollButtons && tabList.count() && last > available) {| TRUE | never evaluated | | FALSE | never evaluated |
| TRUE | never evaluated | | FALSE | never evaluated |
| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 543 | int extraconst QRect scrollRect = extraWidth(); | - |
| if (!vertTabs) { | |
| Qt::LayoutDirection ldnormalizedScrollRect(0); | |
| 544 | scrollOffset = q->layoutDirection-scrollRect.left(); | - |
| 545 | | - |
| 546 | Q_Q(QTabBar); | - |
| 547 | QStyleOption opt; | - |
| 548 | opt.init(q); | - |
| 549 | QRect arrowsscrollButtonLeftRect = q->style()->subElementRect(QStyle::visualRect(ldSE_TabBarScrollLeftButton, &opt, q->rect(),); | - |
| 550 | QRect scrollButtonRightRect = q->style()->subElementRect(available - extra, 0QStyle::SE_TabBarScrollRightButton, extra&opt, size.height()));q); | - |
| 551 | int buttonOverlapscrollButtonWidth = q->style()->pixelMetric(QStyle::PM_TabBar_ScrollButtonOverlapPM_TabBarScrollButtonWidth, 0&opt, q); | - |
| 552 | | - |
| 553 | | - |
| 554 | | - |
| 555 | | - |
| 556 | if (ld == Qt::LeftToRightvertTabs) {| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 557 | leftB->setGeometry(arrows.left(), arrowsscrollButtonLeftRect.top(), extra/2, arrowssetHeight(scrollButtonWidth); | - |
| 558 | scrollButtonRightRect.height()); | - |
| rightB->setGeometrysetY(arrowsscrollButtonRightRect.rightbottom() - extra/2+ buttonOverlap, arrows.top(), | |
| extra/2, arrows1 - scrollButtonWidth); | |
| 559 | scrollButtonRightRect.height());setHeight(scrollButtonWidth); | - |
| 560 | leftB->setArrowType(Qt::LeftArrowUpArrow); | - |
| 561 | rightB->setArrowType(Qt::RightArrowDownArrow); | - |
| 562 | } else { never executed: end of block | TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| rightB->setGeometry never executed: end of block | TRUE | never evaluated | | FALSE | never evaluated |
if (arrows.left(), arrowsq->layoutDirection() == Qt::RightToLeft) {never executed: end of block | TRUE | never evaluated | | FALSE | never evaluated |
| |
| 563 | scrollButtonRightRect.top(), extra/2, arrowssetWidth(scrollButtonWidth); | - |
| 564 | scrollButtonLeftRect.height()); | - |
| leftB->setGeometrysetX(arrowsscrollButtonLeftRect.right() - extra/2+ buttonOverlap, arrows.top(), | |
| extra/2, arrows1 - scrollButtonWidth); | |
| 565 | scrollButtonLeftRect.height()); | - |
| rightBsetWidth(scrollButtonWidth); | |
| 566 | leftB->setArrowType(Qt::LeftArrowRightArrow); | - |
| 567 | leftBrightB->setArrowType(Qt::RightArrowLeftArrow); | - |
| 568 | }} else { never executed: end of block | 0 |
| 569 | QRect arrows = QRect(0, available - extra, sizescrollButtonLeftRect.width(), extra ); | - |
| leftB->setGeometrysetWidth(arrowsscrollButtonWidth); | |
| 570 | scrollButtonRightRect.left(), arrowssetX(scrollButtonRightRect.top(), arrowsright() + 1 - scrollButtonWidth); | - |
| 571 | scrollButtonRightRect.width(), extra/2setWidth(scrollButtonWidth); | - |
| 572 | leftB->setArrowType(Qt::UpArrow); | - |
| rightB->setGeometry(arrows.left(), arrows.bottom() - extra/2 + 1, | |
| arrows.width(), extra/2LeftArrow); | |
| 573 | rightB->setArrowType(Qt::DownArrowRightArrow); | - |
| 574 | } never executed: end of block | 0 |
| 575 | | - |
| 576 | leftB->setEnabledsetGeometry(scrollOffset > 0scrollButtonLeftRect); | - |
| 577 | rightBleftB->setEnabled(last - scrollOffset >= available - extrafalse); | - |
| 578 | leftB->show(); | - |
| 579 | | - |
| 580 | rightB->setGeometry(scrollButtonRightRect); | - |
| 581 | rightB->setEnabled(last - scrollOffset > scrollRect.x() + scrollRect.width()); | - |
| 582 | rightB->show(); | - |
| 583 | } else { never executed: end of block | 0 |
| 584 | scrollOffset = 0; | - |
| 585 | rightB->hide(); | - |
| 586 | leftB->hide(); | - |
| 587 | } never executed: end of block | 0 |
| 588 | | - |
| 589 | layoutWidgets(); | - |
| 590 | q->tabLayoutChange(); | - |
| 591 | } never executed: end of block | 0 |
| 592 | | - |
| 593 | QRect QTabBarPrivate::normalizedScrollRect(int index) | - |
| 594 | { | - |
| 595 | | - |
| 596 | | - |
| 597 | | - |
| 598 | | - |
| 599 | | - |
| 600 | Q_Q(QTabBar); | - |
| 601 | QStyleOptionTab opt; | - |
| 602 | q->initStyleOption(&opt, currentIndex); | - |
| 603 | opt.rect = q->rect(); | - |
| 604 | | - |
| 605 | QRect scrollButtonLeftRect = q->style()->subElementRect(QStyle::SE_TabBarScrollLeftButton, &opt, q); | - |
| 606 | QRect scrollButtonRightRect = q->style()->subElementRect(QStyle::SE_TabBarScrollRightButton, &opt, q); | - |
| 607 | QRect tearLeftRect = q->style()->subElementRect(QStyle::SE_TabBarTearIndicatorLeft, &opt, q); | - |
| 608 | QRect tearRightRect = q->style()->subElementRect(QStyle::SE_TabBarTearIndicatorRight, &opt, q); | - |
| 609 | | - |
| 610 | if (verticalTabs(shape)) {| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 611 | int topEdge, bottomEdge; | - |
| 612 | bool leftButtonIsOnTop = scrollButtonLeftRect.y() < q->height() / 2; | - |
| 613 | bool rightButtonIsOnTop = scrollButtonRightRect.y() < q->height() / 2; | - |
| 614 | | - |
| 615 | if (leftButtonIsOnTop && rightButtonIsOnTop) {| TRUE | never evaluated | | FALSE | never evaluated |
| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 616 | topEdge = scrollButtonRightRect.bottom() + 1; | - |
| 617 | bottomEdge = q->height(); | - |
| 618 | } else if (!leftButtonIsOnTop && !rightButtonIsOnTop) { never executed: end of block | TRUE | never evaluated | | FALSE | never evaluated |
| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 619 | topEdge = 0; | - |
| 620 | bottomEdge = scrollButtonLeftRect.top(); | - |
| 621 | } else { never executed: end of block | 0 |
| 622 | topEdge = scrollButtonLeftRect.bottom() + 1; | - |
| 623 | bottomEdge = scrollButtonRightRect.top(); | - |
| 624 | } never executed: end of block | 0 |
| 625 | | - |
| 626 | bool tearTopVisible = index != 0 && topEdge != -scrollOffset;| TRUE | never evaluated | | FALSE | never evaluated |
| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 627 | bool tearBottomVisible = index != tabList.size() - 1 && bottomEdge != tabList.constLast().rect.bottom() + 1 - scrollOffset;| TRUE | never evaluated | | FALSE | never evaluated |
| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 628 | if (tearTopVisible && !tearLeftRect.isNull())| TRUE | never evaluated | | FALSE | never evaluated |
| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 629 | topEdge = tearLeftRect.bottom() + 1; never executed: topEdge = tearLeftRect.bottom() + 1; | 0 |
| 630 | if (tearBottomVisible && !tearRightRect.isNull())| TRUE | never evaluated | | FALSE | never evaluated |
| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 631 | bottomEdge = tearRightRect.top(); never executed: bottomEdge = tearRightRect.top(); | 0 |
| 632 | | - |
| 633 | return QRect(topEdge, 0, bottomEdge - topEdge, q->height()); never executed: return QRect(topEdge, 0, bottomEdge - topEdge, q->height()); | 0 |
| 634 | } else { | - |
| 635 | if (q->layoutDirection() == Qt::RightToLeft) {| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 636 | scrollButtonLeftRect = QStyle::visualRect(Qt::RightToLeft, q->rect(), scrollButtonLeftRect); | - |
| 637 | scrollButtonRightRect = QStyle::visualRect(Qt::RightToLeft, q->rect(), scrollButtonRightRect); | - |
| 638 | tearLeftRect = QStyle::visualRect(Qt::RightToLeft, q->rect(), tearLeftRect); | - |
| 639 | tearRightRect = QStyle::visualRect(Qt::RightToLeft, q->rect(), tearRightRect); | - |
| 640 | } never executed: end of block | 0 |
| 641 | | - |
| 642 | int leftEdge, rightEdge; | - |
| 643 | bool leftButtonIsOnLeftSide = scrollButtonLeftRect.x() < q->width() / 2; | - |
| 644 | bool rightButtonIsOnLeftSide = scrollButtonRightRect.x() < q->width() / 2; | - |
| 645 | | - |
| 646 | if (leftButtonIsOnLeftSide && rightButtonIsOnLeftSide) {| TRUE | never evaluated | | FALSE | never evaluated |
| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 647 | leftEdge = scrollButtonRightRect.right() + 1; | - |
| 648 | rightEdge = q->width(); | - |
| 649 | } else if (!leftButtonIsOnLeftSide && !rightButtonIsOnLeftSide) { never executed: end of block | TRUE | never evaluated | | FALSE | never evaluated |
| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 650 | leftEdge = 0; | - |
| 651 | rightEdge = scrollButtonLeftRect.left(); | - |
| 652 | } else { never executed: end of block | 0 |
| 653 | leftEdge = scrollButtonLeftRect.right() + 1; | - |
| 654 | rightEdge = scrollButtonRightRect.left(); | - |
| 655 | } never executed: end of block | 0 |
| 656 | | - |
| 657 | bool tearLeftVisible = index != 0 && leftEdge != -scrollOffset;| TRUE | never evaluated | | FALSE | never evaluated |
| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 658 | bool tearRightVisible = index != tabList.size() - 1 && rightEdge != tabList.constLast().rect.right() + 1 - scrollOffset;| TRUE | never evaluated | | FALSE | never evaluated |
| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 659 | if (tearLeftVisible && !tearLeftRect.isNull())| TRUE | never evaluated | | FALSE | never evaluated |
| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 660 | leftEdge = tearLeftRect.right() + 1; never executed: leftEdge = tearLeftRect.right() + 1; | 0 |
| 661 | if (tearRightVisible && !tearRightRect.isNull())| TRUE | never evaluated | | FALSE | never evaluated |
| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 662 | rightEdge = tearRightRect.left never executed: rightEdge = tearRightRect.left(); ();never executed: rightEdge = tearRightRect.left(); | 0 |
| 663 | | - |
| 664 | return QRect(leftEdge, 0, rightEdge - leftEdge, q->height()); never executed: return QRect(leftEdge, 0, rightEdge - leftEdge, q->height()); | 0 |
| 665 | } | - |
| 666 | } | - |
| 667 | | - |
| 668 | void QTabBarPrivate::makeVisible(int index) | - |
| 669 | { | - |
| 670 | Q_Q(QTabBar); | - |
| 671 | if (!validIndex(index) || leftB->isHidden())| TRUE | never evaluated | | FALSE | never evaluated |
| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 672 | return; never executed: return; | 0 |
| 673 | | - |
| 674 | const QRect tabRect = tabList.at(index).rect; | - |
| 675 | const int oldScrollOffset = scrollOffset; | - |
| 676 | const bool horiz = !verticalTabs(shape); | - |
| 677 | const int availabletabStart = (horiz ? q->widthtabRect.left() : q->height()) - extraWidthtabRect.top();| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 678 | const int starttabEnd = horiz ? tabRect.leftright() : tabRect.topbottom();| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 679 | const int endlastTabEnd = horiz ? tabRecttabList.constLast().rect.right() : tabRecttabList.constLast().rect.bottom();| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 680 | const QRect scrollRect = normalizedScrollRect(index); | - |
| 681 | const int scrolledTabBarStart = qMax(1, scrollRect.left() + scrollOffset); | - |
| 682 | const int scrolledTabBarEnd = qMin(lastTabEnd - 1, scrollRect.right() + scrollOffset); | - |
| 683 | | - |
| 684 | if (starttabStart < scrollOffsetscrolledTabBarStart) {| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 685 | | - |
| 686 | scrollOffset = starttabStart - (index ? 8 : 0);scrollRect.left(); | - |
| 687 | } never executed: end of block | TRUE | never evaluated | | FALSE | never evaluated |
else if (endtabEnd > scrollOffset + availablescrolledTabBarEnd) {never executed: end of block | TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 688 | | - |
| 689 | scrollOffset = endtabEnd - available + 1;scrollRect.right(); | - |
| 690 | } never executed: end of block | 0 |
| 691 | | - |
| 692 | leftB->setEnabled(scrollOffset > 0); | - |
| const int last = horiz ? tabList.last().rect.right() : tabList.last().rect-scrollRect.bottom();left()); | |
| 693 | rightB->setEnabled(last -scrollOffset >= available);< lastTabEnd - scrollRect.right()); | - |
| 694 | | - |
| 695 | if (oldScrollOffset != scrollOffset) {| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 696 | q->update(); | - |
| 697 | layoutWidgets(); | - |
| 698 | } never executed: end of block | 0 |
| 699 | } never executed: end of block | 0 |
| 700 | | - |
| 701 | void QTabBarPrivate::killSwitchTabTimer() | - |
| 702 | { | - |
| 703 | Q_Q(QTabBar); | - |
| 704 | if (switchTabTimerId) { | - |
| 705 | q->killTimer(switchTabTimerId); | - |
| 706 | switchTabTimerId = 0; | - |
| 707 | } | - |
| 708 | switchTabCurrentIndex = -1; | - |
| 709 | } | - |
| 710 | | - |
| 711 | void QTabBarPrivate::layoutTab(int index) | - |
| 712 | { | - |
| 713 | Q_Q(QTabBar); | - |
| 714 | Q_ASSERT(index >= 0); | - |
| 715 | | - |
| 716 | Tab &tab = tabList[index]; | - |
| 717 | bool vertical = verticalTabs(shape); | - |
| 718 | if (!(tab.leftWidget || tab.rightWidget)) | - |
| 719 | return; | - |
| 720 | | - |
| 721 | QStyleOptionTab opt; | - |
| 722 | q->initStyleOption(&opt, index); | - |
| 723 | if (tab.leftWidget) { | - |
| 724 | QRect rect = q->style()->subElementRect(QStyle::SE_TabBarTabLeftButton, &opt, q); | - |
| 725 | QPoint p = rect.topLeft(); | - |
| 726 | if ((index == pressedIndex) || paintWithOffsets) { | - |
| 727 | if (vertical) | - |
| 728 | p.setY(p.y() + tabList[index].dragOffset); | - |
| 729 | else | - |
| 730 | p.setX(p.x() + tabList[index].dragOffset); | - |
| 731 | } | - |
| 732 | tab.leftWidget->move(p); | - |
| 733 | } | - |
| 734 | if (tab.rightWidget) { | - |
| 735 | QRect rect = q->style()->subElementRect(QStyle::SE_TabBarTabRightButton, &opt, q); | - |
| 736 | QPoint p = rect.topLeft(); | - |
| 737 | if ((index == pressedIndex) || paintWithOffsets) { | - |
| 738 | if (vertical) | - |
| 739 | p.setY(p.y() + tab.dragOffset); | - |
| 740 | else | - |
| 741 | p.setX(p.x() + tab.dragOffset); | - |
| 742 | } | - |
| 743 | tab.rightWidget->move(p); | - |
| 744 | } | - |
| 745 | } | - |
| 746 | | - |
| 747 | void QTabBarPrivate::layoutWidgets(int start) | - |
| 748 | { | - |
| 749 | Q_Q(QTabBar); | - |
| 750 | for (int i = start; i < q->count(); ++i) { | - |
| 751 | layoutTab(i); | - |
| 752 | } | - |
| 753 | } | - |
| 754 | | - |
| 755 | void QTabBarPrivate::autoHideTabs() | - |
| 756 | { | - |
| 757 | Q_Q(QTabBar); | - |
| 758 | | - |
| 759 | if (autoHide) | - |
| 760 | q->setVisible(q->count() > 1); | - |
| 761 | } | - |
| 762 | | - |
| 763 | void QTabBarPrivate::_q_closeTab() | - |
| 764 | { | - |
| 765 | Q_Q(QTabBar); | - |
| 766 | QObject *object = q->sender(); | - |
| 767 | int tabToClose = -1; | - |
| 768 | QTabBar::ButtonPosition closeSide = (QTabBar::ButtonPosition)q->style()->styleHint(QStyle::SH_TabBar_CloseButtonPosition, 0, q); | - |
| 769 | for (int i = 0; i < tabList.count(); ++i) { | - |
| 770 | if (closeSide == QTabBar::LeftSide) { | - |
| 771 | if (tabList.at(i).leftWidget == object) { | - |
| 772 | tabToClose = i; | - |
| 773 | break; | - |
| 774 | } | - |
| 775 | } else { | - |
| 776 | if (tabList.at(i).rightWidget == object) { | - |
| 777 | tabToClose = i; | - |
| 778 | break; | - |
| 779 | } | - |
| 780 | } | - |
| 781 | } | - |
| 782 | if (tabToClose != -1) | - |
| 783 | emit q->tabCloseRequested(tabToClose); | - |
| 784 | } | - |
| 785 | | - |
| 786 | void QTabBarPrivate::_q_scrollTabs() | - |
| 787 | { | - |
| 788 | Q_Q(QTabBar); | - |
| 789 | const QObject *sender = q->sender(); | - |
| 790 | const bool horizontal = !verticalTabs(shape); | - |
| 791 | const QRect scrollRect = normalizedScrollRect(); | - |
| 792 | int i = -1; | - |
| 793 | | - |
| 794 | if (!verticalTabs(shape)) {if (sender == leftB) {| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 795 | for (i = tabList.count() - 1; i >= 0; --i) {| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 796 | ifint start = horizontal ? tabList.at(i).rect.left() : tabList.at(i).rect.top();| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 797 | if (start < scrollRect| TRUE | never evaluated | | FALSE | never evaluated |
.left() -+ scrollOffset< 0) {| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 798 | makeVisible(i); | - |
| 799 | return; never executed: return; | 0 |
| 800 | } | - |
| 801 | } never executed: end of block | 0 |
| 802 | } else if (sender == rightB) { never executed: end of block | TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 803 | int availableWidth = q->width() - extraWidth();for (i = 0; i < tabList.count(); ++i) {| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 804 | if (int end = horizontal ? tabList.at(i).rect.right() - scrollOffset > availableWidth) {| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| makeVisible(i);| TRUE | never evaluated | | FALSE | never evaluated |
| |
| return;| TRUE | never evaluated | | FALSE | never evaluated |
| |
| }| TRUE | never evaluated | | FALSE | never evaluated |
| |
| }| TRUE | never evaluated | | FALSE | never evaluated |
| |
| }| TRUE | never evaluated | | FALSE | never evaluated |
| |
| } else { if (sender == leftB) {| TRUE | never evaluated | | FALSE | never evaluated |
| |
| for (i = tabList.count| TRUE | never evaluated | | FALSE | never evaluated |
() - 1; i >= 0; --i) {| TRUE | never evaluated | | FALSE | never evaluated |
| |
| if (| TRUE | never evaluated | | FALSE | never evaluated |
: tabList.at(i).rect.top() - scrollOffset < 0) {| TRUE | never evaluated | | FALSE | never evaluated |
| |
| makeVisible(i);| TRUE | never evaluated | | FALSE | never evaluated |
| |
| return;| TRUE | never evaluated | | FALSE | never evaluated |
| |
| }| TRUE | never evaluated | | FALSE | never evaluated |
| |
| }| TRUE | never evaluated | | FALSE | never evaluated |
| |
| } else if (sender == rightB) {| TRUE | never evaluated | | FALSE | never evaluated |
| |
| int available = q->height() - extraWidth();| TRUE | never evaluated | | FALSE | never evaluated |
| |
| for (i = 0; i < tabList| TRUE | never evaluated | | FALSE | never evaluated |
.countbottom();| TRUE | never evaluated | | FALSE | never evaluated |
| |
| 805 | ++i) {if (tabList.at(i).rectend > scrollRect.bottomright() -+ scrollOffset> available) {| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 806 | makeVisible(i); | - |
| 807 | return; never executed: return; | 0 |
| 808 | }} | - |
| 809 | } never executed: end of block | 0 |
| 810 | } never executed: end of block | 0 |
| 811 | } never executed: end of block | 0 |
| 812 | | - |
| 813 | void QTabBarPrivate::refresh() | - |
| 814 | { | - |
| 815 | Q_Q(QTabBar); | - |
| 816 | | - |
| 817 | | - |
| 818 | if (pressedIndex != -1 | - |
| 819 | && movable | - |
| 820 | && QApplication::mouseButtons() == Qt::NoButton) { | - |
| 821 | moveTabFinished(pressedIndex); | - |
| 822 | if (!validIndex(pressedIndex)) | - |
| 823 | pressedIndex = -1; | - |
| 824 | } | - |
| 825 | | - |
| 826 | if (!q->isVisible()) { | - |
| 827 | layoutDirty = true; | - |
| 828 | } else { | - |
| 829 | layoutTabs(); | - |
| 830 | makeVisible(currentIndex); | - |
| 831 | q->update(); | - |
| 832 | q->updateGeometry(); | - |
| 833 | } | - |
| 834 | } | - |
| 835 | | - |
| 836 | | - |
| 837 | | - |
| 838 | | - |
| 839 | QTabBar::QTabBar(QWidget* parent) | - |
| 840 | :QWidget(*new QTabBarPrivate, parent, 0) | - |
| 841 | { | - |
| 842 | Q_D(QTabBar); | - |
| 843 | d->init(); | - |
| 844 | } | - |
| 845 | | - |
| 846 | | - |
| 847 | | - |
| 848 | | - |
| 849 | | - |
| 850 | QTabBar::~QTabBar() | - |
| 851 | { | - |
| 852 | } | - |
| 853 | | - |
| 854 | | - |
| 855 | | - |
| 856 | | - |
| 857 | | - |
| 858 | | - |
| 859 | | - |
| 860 | | - |
| 861 | | - |
| 862 | QTabBar::Shape QTabBar::shape() const | - |
| 863 | { | - |
| 864 | Q_D(const QTabBar); | - |
| 865 | return d->shape; | - |
| 866 | } | - |
| 867 | | - |
| 868 | void QTabBar::setShape(Shape shape) | - |
| 869 | { | - |
| 870 | Q_D(QTabBar); | - |
| 871 | if (d->shape == shape) | - |
| 872 | return; | - |
| 873 | d->shape = shape; | - |
| 874 | d->refresh(); | - |
| 875 | } | - |
| 876 | | - |
| 877 | | - |
| 878 | | - |
| 879 | | - |
| 880 | | - |
| 881 | | - |
| 882 | | - |
| 883 | | - |
| 884 | | - |
| 885 | | - |
| 886 | | - |
| 887 | void QTabBar::setDrawBase(bool drawBase) | - |
| 888 | { | - |
| 889 | Q_D(QTabBar); | - |
| 890 | if (d->drawBase == drawBase) | - |
| 891 | return; | - |
| 892 | d->drawBase = drawBase; | - |
| 893 | update(); | - |
| 894 | } | - |
| 895 | | - |
| 896 | bool QTabBar::drawBase() const | - |
| 897 | { | - |
| 898 | Q_D(const QTabBar); | - |
| 899 | return d->drawBase; | - |
| 900 | } | - |
| 901 | | - |
| 902 | | - |
| 903 | | - |
| 904 | | - |
| 905 | | - |
| 906 | int QTabBar::addTab(const QString &text) | - |
| 907 | { | - |
| 908 | return insertTab(-1, text); | - |
| 909 | } | - |
| 910 | | - |
| 911 | | - |
| 912 | | - |
| 913 | | - |
| 914 | | - |
| 915 | | - |
| 916 | | - |
| 917 | int QTabBar::addTab(const QIcon& icon, const QString &text) | - |
| 918 | { | - |
| 919 | return insertTab(-1, icon, text); | - |
| 920 | } | - |
| 921 | | - |
| 922 | | - |
| 923 | | - |
| 924 | | - |
| 925 | | - |
| 926 | | - |
| 927 | int QTabBar::insertTab(int index, const QString &text) | - |
| 928 | { | - |
| 929 | return insertTab(index, QIcon(), text); | - |
| 930 | } | - |
| 931 | | - |
| 932 | | - |
| 933 | | - |
| 934 | | - |
| 935 | | - |
| 936 | | - |
| 937 | | - |
| 938 | | - |
| 939 | | - |
| 940 | | - |
| 941 | | - |
| 942 | | - |
| 943 | | - |
| 944 | int QTabBar::insertTab(int index, const QIcon& icon, const QString &text) | - |
| 945 | { | - |
| 946 | Q_D(QTabBar); | - |
| 947 | if (!d->validIndex(index)) { | - |
| 948 | index = d->tabList.count(); | - |
| 949 | d->tabList.append(QTabBarPrivate::Tab(icon, text)); | - |
| 950 | } else { | - |
| 951 | d->tabList.insert(index, QTabBarPrivate::Tab(icon, text)); | - |
| 952 | } | - |
| 953 | #ifndef QT_NO_SHORTCUT | - |
| 954 | d->tabList[index].shortcutId = grabShortcut(QKeySequence::mnemonic(text)); | - |
| 955 | #endif | - |
| 956 | d->refresh(); | - |
| 957 | if (d->tabList.count() == 1) | - |
| 958 | setCurrentIndex(index); | - |
| 959 | else if (index <= d->currentIndex) | - |
| 960 | ++d->currentIndex; | - |
| 961 | | - |
| 962 | if (d->closeButtonOnTabs) { | - |
| 963 | QStyleOptionTab opt; | - |
| 964 | initStyleOption(&opt, index); | - |
| 965 | ButtonPosition closeSide = (ButtonPosition)style()->styleHint(QStyle::SH_TabBar_CloseButtonPosition, 0, this); | - |
| 966 | QAbstractButton *closeButton = new CloseButton(this); | - |
| 967 | connect(closeButton, SIGNAL(clicked()), this, SLOT(_q_closeTab())); | - |
| 968 | setTabButton(index, closeSide, closeButton); | - |
| 969 | } | - |
| 970 | | - |
| 971 | for (int i = 0; i < d->tabList.count(); ++i) { | - |
| 972 | if (d->tabList[i].lastTab >= index) | - |
| 973 | ++d->tabList[i].lastTab; | - |
| 974 | } | - |
| 975 | | - |
| 976 | tabInserted(index); | - |
| 977 | d->autoHideTabs(); | - |
| 978 | return index; | - |
| 979 | } | - |
| 980 | | - |
| 981 | | - |
| 982 | | - |
| 983 | | - |
| 984 | | - |
| 985 | | - |
| 986 | | - |
| 987 | void QTabBar::removeTab(int index) | - |
| 988 | { | - |
| 989 | Q_D(QTabBar); | - |
| 990 | if (d->validIndex(index)) { | - |
| 991 | if (d->dragInProgress) | - |
| 992 | d->moveTabFinished(d->pressedIndex); | - |
| 993 | | - |
| 994 | #ifndef QT_NO_SHORTCUT | - |
| 995 | releaseShortcut(d->tabList.at(index).shortcutId); | - |
| 996 | #endif | - |
| 997 | if (d->tabList[index].leftWidget) { | - |
| 998 | d->tabList[index].leftWidget->hide(); | - |
| 999 | d->tabList[index].leftWidget->deleteLater(); | - |
| 1000 | d->tabList[index].leftWidget = 0; | - |
| 1001 | } | - |
| 1002 | if (d->tabList[index].rightWidget) { | - |
| 1003 | d->tabList[index].rightWidget->hide(); | - |
| 1004 | d->tabList[index].rightWidget->deleteLater(); | - |
| 1005 | d->tabList[index].rightWidget = 0; | - |
| 1006 | } | - |
| 1007 | | - |
| 1008 | int newIndex = d->tabList[index].lastTab; | - |
| 1009 | d->tabList.removeAt(index); | - |
| 1010 | for (int i = 0; i < d->tabList.count(); ++i) { | - |
| 1011 | if (d->tabList[i].lastTab == index) | - |
| 1012 | d->tabList[i].lastTab = -1; | - |
| 1013 | if (d->tabList[i].lastTab > index) | - |
| 1014 | --d->tabList[i].lastTab; | - |
| 1015 | } | - |
| 1016 | if (index == d->currentIndex) { | - |
| 1017 | | - |
| 1018 | | - |
| 1019 | | - |
| 1020 | d->currentIndex = -1; | - |
| 1021 | if (d->tabList.size() > 0) { | - |
| 1022 | switch(d->selectionBehaviorOnRemove) { | - |
| 1023 | case SelectPreviousTab: | - |
| 1024 | if (newIndex > index) | - |
| 1025 | newIndex--; | - |
| 1026 | if (d->validIndex(newIndex)) | - |
| 1027 | break; | - |
| 1028 | | - |
| 1029 | case SelectRightTab: | - |
| 1030 | newIndex = index; | - |
| 1031 | if (newIndex >= d->tabList.size()) | - |
| 1032 | newIndex = d->tabList.size() - 1; | - |
| 1033 | break; | - |
| 1034 | case SelectLeftTab: | - |
| 1035 | newIndex = index - 1; | - |
| 1036 | if (newIndex < 0) | - |
| 1037 | newIndex = 0; | - |
| 1038 | break; | - |
| 1039 | default: | - |
| 1040 | break; | - |
| 1041 | } | - |
| 1042 | | - |
| 1043 | if (d->validIndex(newIndex)) { | - |
| 1044 | | - |
| 1045 | int bump = d->tabList[newIndex].lastTab; | - |
| 1046 | setCurrentIndex(newIndex); | - |
| 1047 | d->tabList[newIndex].lastTab = bump; | - |
| 1048 | } | - |
| 1049 | } else { | - |
| 1050 | emit currentChanged(-1); | - |
| 1051 | } | - |
| 1052 | } else if (index < d->currentIndex) { | - |
| 1053 | setCurrentIndex(d->currentIndex - 1); | - |
| 1054 | } | - |
| 1055 | d->refresh(); | - |
| 1056 | d->autoHideTabs(); | - |
| 1057 | tabRemoved(index); | - |
| 1058 | } | - |
| 1059 | } | - |
| 1060 | | - |
| 1061 | | - |
| 1062 | | - |
| 1063 | | - |
| 1064 | | - |
| 1065 | | - |
| 1066 | bool QTabBar::isTabEnabled(int index) const | - |
| 1067 | { | - |
| 1068 | Q_D(const QTabBar); | - |
| 1069 | if (const QTabBarPrivate::Tab *tab = d->at(index)) | - |
| 1070 | return tab->enabled; | - |
| 1071 | return false; | - |
| 1072 | } | - |
| 1073 | | - |
| 1074 | | - |
| 1075 | | - |
| 1076 | | - |
| 1077 | | - |
| 1078 | void QTabBar::setTabEnabled(int index, bool enabled) | - |
| 1079 | { | - |
| 1080 | Q_D(QTabBar); | - |
| 1081 | if (QTabBarPrivate::Tab *tab = d->at(index)) { | - |
| 1082 | tab->enabled = enabled; | - |
| 1083 | #ifndef QT_NO_SHORTCUT | - |
| 1084 | setShortcutEnabled(tab->shortcutId, enabled); | - |
| 1085 | #endif | - |
| 1086 | update(); | - |
| 1087 | if (!enabled && index == d->currentIndex) | - |
| 1088 | setCurrentIndex(d->validIndex(index+1)?index+1:0); | - |
| 1089 | else if (enabled && !d->validIndex(d->currentIndex)) | - |
| 1090 | setCurrentIndex(index); | - |
| 1091 | } | - |
| 1092 | } | - |
| 1093 | | - |
| 1094 | | - |
| 1095 | | - |
| 1096 | | - |
| 1097 | | - |
| 1098 | | - |
| 1099 | QString QTabBar::tabText(int index) const | - |
| 1100 | { | - |
| 1101 | Q_D(const QTabBar); | - |
| 1102 | if (const QTabBarPrivate::Tab *tab = d->at(index)) | - |
| 1103 | return tab->text; | - |
| 1104 | return QString(); | - |
| 1105 | } | - |
| 1106 | | - |
| 1107 | | - |
| 1108 | | - |
| 1109 | | - |
| 1110 | void QTabBar::setTabText(int index, const QString &text) | - |
| 1111 | { | - |
| 1112 | Q_D(QTabBar); | - |
| 1113 | if (QTabBarPrivate::Tab *tab = d->at(index)) { | - |
| 1114 | d->textSizes.remove(tab->text); | - |
| 1115 | tab->text = text; | - |
| 1116 | #ifndef QT_NO_SHORTCUT | - |
| 1117 | releaseShortcut(tab->shortcutId); | - |
| 1118 | tab->shortcutId = grabShortcut(QKeySequence::mnemonic(text)); | - |
| 1119 | setShortcutEnabled(tab->shortcutId, tab->enabled); | - |
| 1120 | #endif | - |
| 1121 | d->refresh(); | - |
| 1122 | } | - |
| 1123 | } | - |
| 1124 | | - |
| 1125 | | - |
| 1126 | | - |
| 1127 | | - |
| 1128 | | - |
| 1129 | | - |
| 1130 | | - |
| 1131 | QColor QTabBar::tabTextColor(int index) const | - |
| 1132 | { | - |
| 1133 | Q_D(const QTabBar); | - |
| 1134 | if (const QTabBarPrivate::Tab *tab = d->at(index)) | - |
| 1135 | return tab->textColor; | - |
| 1136 | return QColor(); | - |
| 1137 | } | - |
| 1138 | | - |
| 1139 | | - |
| 1140 | | - |
| 1141 | | - |
| 1142 | | - |
| 1143 | | - |
| 1144 | | - |
| 1145 | | - |
| 1146 | void QTabBar::setTabTextColor(int index, const QColor &color) | - |
| 1147 | { | - |
| 1148 | Q_D(QTabBar); | - |
| 1149 | if (QTabBarPrivate::Tab *tab = d->at(index)) { | - |
| 1150 | tab->textColor = color; | - |
| 1151 | update(tabRect(index)); | - |
| 1152 | } | - |
| 1153 | } | - |
| 1154 | | - |
| 1155 | | - |
| 1156 | | - |
| 1157 | | - |
| 1158 | | - |
| 1159 | QIcon QTabBar::tabIcon(int index) const | - |
| 1160 | { | - |
| 1161 | Q_D(const QTabBar); | - |
| 1162 | if (const QTabBarPrivate::Tab *tab = d->at(index)) | - |
| 1163 | return tab->icon; | - |
| 1164 | return QIcon(); | - |
| 1165 | } | - |
| 1166 | | - |
| 1167 | | - |
| 1168 | | - |
| 1169 | | - |
| 1170 | void QTabBar::setTabIcon(int index, const QIcon & icon) | - |
| 1171 | { | - |
| 1172 | Q_D(QTabBar); | - |
| 1173 | if (QTabBarPrivate::Tab *tab = d->at(index)) { | - |
| 1174 | bool simpleIconChange = (!icon.isNull() && !tab->icon.isNull()); | - |
| 1175 | tab->icon = icon; | - |
| 1176 | if (simpleIconChange) | - |
| 1177 | update(tabRect(index)); | - |
| 1178 | else | - |
| 1179 | d->refresh(); | - |
| 1180 | } | - |
| 1181 | } | - |
| 1182 | | - |
| 1183 | #ifndef QT_NO_TOOLTIP | - |
| 1184 | | - |
| 1185 | | - |
| 1186 | | - |
| 1187 | void QTabBar::setTabToolTip(int index, const QString & tip) | - |
| 1188 | { | - |
| 1189 | Q_D(QTabBar); | - |
| 1190 | if (QTabBarPrivate::Tab *tab = d->at(index)) | - |
| 1191 | tab->toolTip = tip; | - |
| 1192 | } | - |
| 1193 | | - |
| 1194 | | - |
| 1195 | | - |
| 1196 | | - |
| 1197 | | - |
| 1198 | QString QTabBar::tabToolTip(int index) const | - |
| 1199 | { | - |
| 1200 | Q_D(const QTabBar); | - |
| 1201 | if (const QTabBarPrivate::Tab *tab = d->at(index)) | - |
| 1202 | return tab->toolTip; | - |
| 1203 | return QString(); | - |
| 1204 | } | - |
| 1205 | #endif // QT_NO_TOOLTIP | - |
| 1206 | | - |
| 1207 | #ifndef QT_NO_WHATSTHIS | - |
| 1208 | | - |
| 1209 | | - |
| 1210 | | - |
| 1211 | | - |
| 1212 | | - |
| 1213 | | - |
| 1214 | void QTabBar::setTabWhatsThis(int index, const QString &text) | - |
| 1215 | { | - |
| 1216 | Q_D(QTabBar); | - |
| 1217 | if (QTabBarPrivate::Tab *tab = d->at(index)) | - |
| 1218 | tab->whatsThis = text; | - |
| 1219 | } | - |
| 1220 | | - |
| 1221 | | - |
| 1222 | | - |
| 1223 | | - |
| 1224 | | - |
| 1225 | | - |
| 1226 | | - |
| 1227 | QString QTabBar::tabWhatsThis(int index) const | - |
| 1228 | { | - |
| 1229 | Q_D(const QTabBar); | - |
| 1230 | if (const QTabBarPrivate::Tab *tab = d->at(index)) | - |
| 1231 | return tab->whatsThis; | - |
| 1232 | return QString(); | - |
| 1233 | } | - |
| 1234 | | - |
| 1235 | #endif // QT_NO_WHATSTHIS | - |
| 1236 | | - |
| 1237 | | - |
| 1238 | | - |
| 1239 | | - |
| 1240 | void QTabBar::setTabData(int index, const QVariant & data) | - |
| 1241 | { | - |
| 1242 | Q_D(QTabBar); | - |
| 1243 | if (QTabBarPrivate::Tab *tab = d->at(index)) | - |
| 1244 | tab->data = data; | - |
| 1245 | } | - |
| 1246 | | - |
| 1247 | | - |
| 1248 | | - |
| 1249 | | - |
| 1250 | | - |
| 1251 | QVariant QTabBar::tabData(int index) const | - |
| 1252 | { | - |
| 1253 | Q_D(const QTabBar); | - |
| 1254 | if (const QTabBarPrivate::Tab *tab = d->at(index)) | - |
| 1255 | return tab->data; | - |
| 1256 | return QVariant(); | - |
| 1257 | } | - |
| 1258 | | - |
| 1259 | | - |
| 1260 | | - |
| 1261 | | - |
| 1262 | | - |
| 1263 | QRect QTabBar::tabRect(int index) const | - |
| 1264 | { | - |
| 1265 | Q_D(const QTabBar); | - |
| 1266 | if (const QTabBarPrivate::Tab *tab = d->at(index)) { | - |
| 1267 | if (d->layoutDirty) | - |
| 1268 | const_cast<QTabBarPrivate*>(d)->layoutTabs(); | - |
| 1269 | QRect r = tab->rect; | - |
| 1270 | if (verticalTabs(d->shape)) | - |
| 1271 | r.translate(0, -d->scrollOffset); | - |
| 1272 | else | - |
| 1273 | r.translate(-d->scrollOffset, 0); | - |
| 1274 | if (!verticalTabs(d->shape)) | - |
| 1275 | r = QStyle::visualRect(layoutDirection(), rect(), r); | - |
| 1276 | return r; | - |
| 1277 | } | - |
| 1278 | return QRect(); | - |
| 1279 | } | - |
| 1280 | | - |
| 1281 | | - |
| 1282 | | - |
| 1283 | | - |
| 1284 | | - |
| 1285 | | - |
| 1286 | | - |
| 1287 | int QTabBar::tabAt(const QPoint &position) const | - |
| 1288 | { | - |
| 1289 | Q_D(const QTabBar); | - |
| 1290 | if (d->validIndex(d->currentIndex) | - |
| 1291 | && tabRect(d->currentIndex).contains(position)) { | - |
| 1292 | return d->currentIndex; | - |
| 1293 | } | - |
| 1294 | const int max = d->tabList.size(); | - |
| 1295 | for (int i = 0; i < max; ++i) { | - |
| 1296 | if (tabRect(i).contains(position)) { | - |
| 1297 | return i; | - |
| 1298 | } | - |
| 1299 | } | - |
| 1300 | return -1; | - |
| 1301 | } | - |
| 1302 | | - |
| 1303 | | - |
| 1304 | | - |
| 1305 | | - |
| 1306 | | - |
| 1307 | | - |
| 1308 | | - |
| 1309 | | - |
| 1310 | int QTabBar::currentIndex() const | - |
| 1311 | { | - |
| 1312 | Q_D(const QTabBar); | - |
| 1313 | if (d->validIndex(d->currentIndex)) | - |
| 1314 | return d->currentIndex; | - |
| 1315 | return -1; | - |
| 1316 | } | - |
| 1317 | | - |
| 1318 | | - |
| 1319 | void QTabBar::setCurrentIndex(int index) | - |
| 1320 | { | - |
| 1321 | Q_D(QTabBar); | - |
| 1322 | if (d->dragInProgress && d->pressedIndex != -1) | - |
| 1323 | return; | - |
| 1324 | | - |
| 1325 | int oldIndex = d->currentIndex; | - |
| 1326 | if (d->validIndex(index) && d->currentIndex != index) { | - |
| 1327 | d->currentIndex = index; | - |
| 1328 | update(); | - |
| 1329 | d->makeVisible(index); | - |
| 1330 | d->tabList[index].lastTab = oldIndex; | - |
| 1331 | if (oldIndex >= 0 && oldIndex < count()) | - |
| 1332 | d->layoutTab(oldIndex); | - |
| 1333 | d->layoutTab(index); | - |
| 1334 | #ifndef QT_NO_ACCESSIBILITY | - |
| 1335 | if (QAccessible::isActive()) { | - |
| 1336 | if (hasFocus()) { | - |
| 1337 | QAccessibleEvent focusEvent(this, QAccessible::Focus); | - |
| 1338 | focusEvent.setChild(index); | - |
| 1339 | QAccessible::updateAccessibility(&focusEvent); | - |
| 1340 | } | - |
| 1341 | QAccessibleEvent selectionEvent(this, QAccessible::Selection); | - |
| 1342 | selectionEvent.setChild(index); | - |
| 1343 | QAccessible::updateAccessibility(&selectionEvent); | - |
| 1344 | } | - |
| 1345 | #endif | - |
| 1346 | emit currentChanged(index); | - |
| 1347 | } | - |
| 1348 | } | - |
| 1349 | | - |
| 1350 | | - |
| 1351 | | - |
| 1352 | | - |
| 1353 | | - |
| 1354 | | - |
| 1355 | | - |
| 1356 | | - |
| 1357 | | - |
| 1358 | | - |
| 1359 | | - |
| 1360 | QSize QTabBar::iconSize() const | - |
| 1361 | { | - |
| 1362 | Q_D(const QTabBar); | - |
| 1363 | if (d->iconSize.isValid()) | - |
| 1364 | return d->iconSize; | - |
| 1365 | int iconExtent = style()->pixelMetric(QStyle::PM_TabBarIconSize, 0, this); | - |
| 1366 | return QSize(iconExtent, iconExtent); | - |
| 1367 | | - |
| 1368 | } | - |
| 1369 | | - |
| 1370 | void QTabBar::setIconSize(const QSize &size) | - |
| 1371 | { | - |
| 1372 | Q_D(QTabBar); | - |
| 1373 | d->iconSize = size; | - |
| 1374 | d->layoutDirty = true; | - |
| 1375 | update(); | - |
| 1376 | updateGeometry(); | - |
| 1377 | } | - |
| 1378 | | - |
| 1379 | | - |
| 1380 | | - |
| 1381 | | - |
| 1382 | | - |
| 1383 | | - |
| 1384 | int QTabBar::count() const | - |
| 1385 | { | - |
| 1386 | Q_D(const QTabBar); | - |
| 1387 | return d->tabList.count(); | - |
| 1388 | } | - |
| 1389 | | - |
| 1390 | | - |
| 1391 | | - |
| 1392 | | - |
| 1393 | QSize QTabBar::sizeHint() const | - |
| 1394 | { | - |
| 1395 | Q_D(const QTabBar); | - |
| 1396 | if (d->layoutDirty) | - |
| 1397 | const_cast<QTabBarPrivate*>(d)->layoutTabs(); | - |
| 1398 | QRect r; | - |
| 1399 | for (int i = 0; i < d->tabList.count(); ++i) | - |
| 1400 | r = r.united(d->tabList.at(i).maxRect); | - |
| 1401 | QSize sz = QApplication::globalStrut(); | - |
| 1402 | return r.size().expandedTo(sz); | - |
| 1403 | } | - |
| 1404 | | - |
| 1405 | | - |
| 1406 | | - |
| 1407 | QSize QTabBar::minimumSizeHint() const | - |
| 1408 | { | - |
| 1409 | Q_D(const QTabBar); | - |
| 1410 | if (d->layoutDirty) | - |
| 1411 | const_cast<QTabBarPrivate*>(d)->layoutTabs(); | - |
| 1412 | if (!d->useScrollButtons) { | - |
| 1413 | QRect r; | - |
| 1414 | for (int i = 0; i < d->tabList.count(); ++i) | - |
| 1415 | r = r.united(d->tabList.at(i).minRect); | - |
| 1416 | return r.size().expandedTo(QApplication::globalStrut()); | - |
| 1417 | } | - |
| 1418 | if (verticalTabs(d->shape)) | - |
| 1419 | return QSize(sizeHint().width(), d->rightB->sizeHint().height() * 2 + 75); | - |
| 1420 | else | - |
| 1421 | return QSize(d->rightB->sizeHint().width() * 2 + 75, sizeHint().height()); | - |
| 1422 | } | - |
| 1423 | | - |
| 1424 | | - |
| 1425 | static QString computeElidedText(Qt::TextElideMode mode, const QString &text) | - |
| 1426 | { | - |
| 1427 | if (text.length() <= 3)| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 1428 | return text; never executed: return text; | 0 |
| 1429 | | - |
| 1430 | static const QLatin1String Ellipses("..."); | - |
| 1431 | QString ret; | - |
| 1432 | switch (mode) { | - |
| 1433 | case Qt::ElideRight: never executed: case Qt::ElideRight: | 0 |
| 1434 | ret = text.leftleftRef(2) + Ellipses; | - |
| 1435 | break; never executed: break; | 0 |
| 1436 | case Qt::ElideMiddle: never executed: case Qt::ElideMiddle: | 0 |
| 1437 | ret = text.leftleftRef(1) + Ellipses + text.rightrightRef(1); | - |
| 1438 | break; never executed: break; | 0 |
| 1439 | case Qt::ElideLeft: never executed: case Qt::ElideLeft: | 0 |
| 1440 | ret = Ellipses + text.rightrightRef(2); | - |
| 1441 | break; never executed: break; | 0 |
| 1442 | case Qt::ElideNone: never executed: case Qt::ElideNone: | 0 |
| 1443 | ret = text; | - |
| 1444 | break; never executed: break; | 0 |
| 1445 | } | - |
| 1446 | return ret; never executed: return ret; | 0 |
| 1447 | } | - |
| 1448 | | - |
| 1449 | | - |
| 1450 | | - |
| 1451 | | - |
| 1452 | | - |
| 1453 | | - |
| 1454 | QSize QTabBar::minimumTabSizeHint(int index) const | - |
| 1455 | { | - |
| 1456 | Q_D(const QTabBar); | - |
| 1457 | QTabBarPrivate::Tab &tab = const_cast<QTabBarPrivate::Tab&>(d->tabList[index]); | - |
| 1458 | QString oldText = tab.text; | - |
| 1459 | tab.text = computeElidedText(d->elideMode, oldText); | - |
| 1460 | QSize size = tabSizeHint(index); | - |
| 1461 | tab.text = oldText; | - |
| 1462 | return size; | - |
| 1463 | } | - |
| 1464 | | - |
| 1465 | | - |
| 1466 | | - |
| 1467 | | - |
| 1468 | QSize QTabBar::tabSizeHint(int index) const | - |
| 1469 | { | - |
| 1470 | | - |
| 1471 | Q_D(const QTabBar); | - |
| 1472 | if (const QTabBarPrivate::Tab *tab = d->at(index)) { | - |
| 1473 | QStyleOptionTab opt; | - |
| 1474 | d->initBasicStyleOption(&opt, index); | - |
| 1475 | opt.text = d->tabList.at(index).text; | - |
| 1476 | QSize iconSize = tab->icon.isNull() ? QSize(0, 0) : opt.iconSize; | - |
| 1477 | int hframe = style()->pixelMetric(QStyle::PM_TabBarTabHSpace, &opt, this); | - |
| 1478 | int vframe = style()->pixelMetric(QStyle::PM_TabBarTabVSpace, &opt, this); | - |
| 1479 | const QFontMetrics fm = fontMetrics(); | - |
| 1480 | | - |
| 1481 | int maxWidgetHeight = qMax(opt.leftButtonSize.height(), opt.rightButtonSize.height()); | - |
| 1482 | int maxWidgetWidth = qMax(opt.leftButtonSize.width(), opt.rightButtonSize.width()); | - |
| 1483 | | - |
| 1484 | int widgetWidth = 0; | - |
| 1485 | int widgetHeight = 0; | - |
| 1486 | int padding = 0; | - |
| 1487 | if (!opt.leftButtonSize.isEmpty()) { | - |
| 1488 | padding += 4; | - |
| 1489 | widgetWidth += opt.leftButtonSize.width(); | - |
| 1490 | widgetHeight += opt.leftButtonSize.height(); | - |
| 1491 | } | - |
| 1492 | if (!opt.rightButtonSize.isEmpty()) { | - |
| 1493 | padding += 4; | - |
| 1494 | widgetWidth += opt.rightButtonSize.width(); | - |
| 1495 | widgetHeight += opt.rightButtonSize.height(); | - |
| 1496 | } | - |
| 1497 | if (!opt.icon.isNull()) | - |
| 1498 | padding += 4; | - |
| 1499 | | - |
| 1500 | QHash<QString, QSize>::iterator it = d->textSizes.find(tab->text); | - |
| 1501 | if (it == d->textSizes.end()) | - |
| 1502 | it = d->textSizes.insert(tab->text, fm.size(Qt::TextShowMnemonic, tab->text)); | - |
| 1503 | const int textWidth = it.value().width(); | - |
| 1504 | QSize csz; | - |
| 1505 | if (verticalTabs(d->shape)) { | - |
| 1506 | csz = QSize( qMax(maxWidgetWidth, qMax(fm.height(), iconSize.height())) + vframe, | - |
| 1507 | textWidth + iconSize.width() + hframe + widgetHeight + padding); | - |
| 1508 | } else { | - |
| 1509 | csz = QSize(textWidth + iconSize.width() + hframe + widgetWidth + padding, | - |
| 1510 | qMax(maxWidgetHeight, qMax(fm.height(), iconSize.height())) + vframe); | - |
| 1511 | } | - |
| 1512 | | - |
| 1513 | QSize retSize = style()->sizeFromContents(QStyle::CT_TabBarTab, &opt, csz, this); | - |
| 1514 | return retSize; | - |
| 1515 | } | - |
| 1516 | return QSize(); | - |
| 1517 | } | - |
| 1518 | | - |
| 1519 | | - |
| 1520 | | - |
| 1521 | | - |
| 1522 | | - |
| 1523 | | - |
| 1524 | | - |
| 1525 | void QTabBar::tabInserted(int index) | - |
| 1526 | { | - |
| 1527 | Q_UNUSED(index) | - |
| 1528 | } | - |
| 1529 | | - |
| 1530 | | - |
| 1531 | | - |
| 1532 | | - |
| 1533 | | - |
| 1534 | | - |
| 1535 | | - |
| 1536 | void QTabBar::tabRemoved(int index) | - |
| 1537 | { | - |
| 1538 | Q_UNUSED(index) | - |
| 1539 | } | - |
| 1540 | | - |
| 1541 | | - |
| 1542 | | - |
| 1543 | | - |
| 1544 | | - |
| 1545 | | - |
| 1546 | void QTabBar::tabLayoutChange() | - |
| 1547 | { | - |
| 1548 | } | - |
| 1549 | | - |
| 1550 | | - |
| 1551 | | - |
| 1552 | | - |
| 1553 | void QTabBar::showEvent(QShowEvent *) | - |
| 1554 | { | - |
| 1555 | Q_D(QTabBar); | - |
| 1556 | if (d->layoutDirty) | - |
| 1557 | d->refresh(); | - |
| 1558 | if (!d->validIndex(d->currentIndex)) | - |
| 1559 | setCurrentIndex(0); | - |
| 1560 | d->updateMacBorderMetrics(); | - |
| 1561 | } | - |
| 1562 | | - |
| 1563 | | - |
| 1564 | | - |
| 1565 | void QTabBar::hideEvent(QHideEvent *) | - |
| 1566 | { | - |
| 1567 | Q_D(QTabBar); | - |
| 1568 | d->updateMacBorderMetrics(); | - |
| 1569 | } | - |
| 1570 | | - |
| 1571 | | - |
| 1572 | | - |
| 1573 | bool QTabBar::event(QEvent *event) | - |
| 1574 | { | - |
| 1575 | Q_D(QTabBar); | - |
| 1576 | if (event->type() == QEvent::HoverMove | - |
| 1577 | || event->type() == QEvent::HoverEnter) { | - |
| 1578 | QHoverEvent *he = static_cast<QHoverEvent *>(event); | - |
| 1579 | if (!d->hoverRect.contains(he->pos())) { | - |
| 1580 | QRect oldHoverRect = d->hoverRect; | - |
| 1581 | for (int i = 0; i < d->tabList.count(); ++i) { | - |
| 1582 | QRect area = tabRect(i); | - |
| 1583 | if (area.contains(he->pos())) { | - |
| 1584 | d->hoverRect = area; | - |
| 1585 | break; | - |
| 1586 | } | - |
| 1587 | } | - |
| 1588 | if (he->oldPos() != QPoint(-1, -1)) | - |
| 1589 | update(oldHoverRect); | - |
| 1590 | update(d->hoverRect); | - |
| 1591 | } | - |
| 1592 | return true; | - |
| 1593 | } else if (event->type() == QEvent::HoverLeave ) { | - |
| 1594 | QRect oldHoverRect = d->hoverRect; | - |
| 1595 | d->hoverRect = QRect(); | - |
| 1596 | update(oldHoverRect); | - |
| 1597 | return true; | - |
| 1598 | #ifndef QT_NO_TOOLTIP | - |
| 1599 | } else if (event->type() == QEvent::ToolTip) { | - |
| 1600 | if (const QTabBarPrivate::Tab *tab = d->at(tabAt(static_cast<QHelpEvent*>(event)->pos()))) { | - |
| 1601 | if (!tab->toolTip.isEmpty()) { | - |
| 1602 | QToolTip::showText(static_cast<QHelpEvent*>(event)->globalPos(), tab->toolTip, this); | - |
| 1603 | return true; | - |
| 1604 | } | - |
| 1605 | } | - |
| 1606 | #endif // QT_NO_TOOLTIP | - |
| 1607 | #ifndef QT_NO_WHATSTHIS | - |
| 1608 | } else if (event->type() == QEvent::QueryWhatsThis) { | - |
| 1609 | const QTabBarPrivate::Tab *tab = d->at(d->indexAtPos(static_cast<QHelpEvent*>(event)->pos())); | - |
| 1610 | if (!tab || tab->whatsThis.isEmpty()) | - |
| 1611 | event->ignore(); | - |
| 1612 | return true; | - |
| 1613 | } else if (event->type() == QEvent::WhatsThis) { | - |
| 1614 | if (const QTabBarPrivate::Tab *tab = d->at(d->indexAtPos(static_cast<QHelpEvent*>(event)->pos()))) { | - |
| 1615 | if (!tab->whatsThis.isEmpty()) { | - |
| 1616 | QWhatsThis::showText(static_cast<QHelpEvent*>(event)->globalPos(), | - |
| 1617 | tab->whatsThis, this); | - |
| 1618 | return true; | - |
| 1619 | } | - |
| 1620 | } | - |
| 1621 | #endif // QT_NO_WHATSTHIS | - |
| 1622 | #ifndef QT_NO_SHORTCUT | - |
| 1623 | } else if (event->type() == QEvent::Shortcut) { | - |
| 1624 | QShortcutEvent *se = static_cast<QShortcutEvent *>(event); | - |
| 1625 | for (int i = 0; i < d->tabList.count(); ++i) { | - |
| 1626 | const QTabBarPrivate::Tab *tab = &d->tabList.at(i); | - |
| 1627 | if (tab->shortcutId == se->shortcutId()) { | - |
| 1628 | setCurrentIndex(i); | - |
| 1629 | return true; | - |
| 1630 | } | - |
| 1631 | } | - |
| 1632 | #endif | - |
| 1633 | } else if (event->type() == QEvent::MouseButtonDblClick) { | - |
| 1634 | const QPoint pos = static_cast<const QMouseEvent *>(event)->pos(); | - |
| 1635 | const bool isEventInCornerButtons = (!d->leftB->isHidden() && d->leftB->geometry().contains(pos)) | - |
| 1636 | || (!d->rightB->isHidden() && d->rightB->geometry().contains(pos)); | - |
| 1637 | if (!isEventInCornerButtons) | - |
| 1638 | emit tabBarDoubleClicked(tabAt(pos)); | - |
| 1639 | } else if (event->type() == QEvent::Move) { | - |
| 1640 | d->updateMacBorderMetrics(); | - |
| 1641 | return QWidget::event(event); | - |
| 1642 | | - |
| 1643 | #ifndef QT_NO_DRAGANDDROP | - |
| 1644 | } else if (event->type() == QEvent::DragEnter) { | - |
| 1645 | if (d->changeCurrentOnDrag) | - |
| 1646 | event->accept(); | - |
| 1647 | } else if (event->type() == QEvent::DragMove) { | - |
| 1648 | if (d->changeCurrentOnDrag) { | - |
| 1649 | const int tabIndex = tabAt(static_cast<QDragMoveEvent *>(event)->pos()); | - |
| 1650 | if (isTabEnabled(tabIndex) && d->switchTabCurrentIndex != tabIndex) { | - |
| 1651 | d->switchTabCurrentIndex = tabIndex; | - |
| 1652 | if (d->switchTabTimerId) | - |
| 1653 | killTimer(d->switchTabTimerId); | - |
| 1654 | d->switchTabTimerId = startTimer(style()->styleHint(QStyle::SH_TabBar_ChangeCurrentDelay)); | - |
| 1655 | } | - |
| 1656 | event->ignore(); | - |
| 1657 | } | - |
| 1658 | } else if (event->type() == QEvent::DragLeave || event->type() == QEvent::Drop) { | - |
| 1659 | d->killSwitchTabTimer(); | - |
| 1660 | event->ignore(); | - |
| 1661 | #endif | - |
| 1662 | } | - |
| 1663 | return QWidget::event(event); | - |
| 1664 | } | - |
| 1665 | | - |
| 1666 | | - |
| 1667 | | - |
| 1668 | void QTabBar::resizeEvent(QResizeEvent *) | - |
| 1669 | { | - |
| 1670 | Q_D(QTabBar); | - |
| 1671 | if (d->layoutDirty) | - |
| 1672 | updateGeometry(); | - |
| 1673 | d->layoutTabs(); | - |
| 1674 | | - |
| 1675 | d->makeVisible(d->currentIndex); | - |
| 1676 | } | - |
| 1677 | | - |
| 1678 | | - |
| 1679 | | - |
| 1680 | void QTabBar::paintEvent(QPaintEvent *) | - |
| 1681 | { | - |
| 1682 | Q_D(QTabBar); | - |
| 1683 | | - |
| 1684 | QStyleOptionTabBarBase optTabBase; | - |
| 1685 | QTabBarPrivate::initStyleBaseOption(&optTabBase, this, size()); | - |
| 1686 | | - |
| 1687 | QStylePainter p(this); | - |
| 1688 | int selected = -1; | - |
| 1689 | int cutcutLeft = -1; | - |
| 1690 | bool rtlint cutRight = optTabBase.direction == Qt::RightToLeft-1; | - |
| 1691 | bool vertical = verticalTabs(d->shape); | - |
| 1692 | QStyleOptionTab cutTabcutTabLeft; | - |
| 1693 | QStyleOptionTab cutTabRight; | - |
| 1694 | selected = d->currentIndex; | - |
| 1695 | if (d->dragInProgress)| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 1696 | selected = d->pressedIndex; never executed: selected = d->pressedIndex; | 0 |
| 1697 | const QRect scrollRect = d->normalizedScrollRect(); | - |
| 1698 | | - |
| 1699 | for (int i = 0; i < d->tabList.count(); ++i)| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 1700 | optTabBase.tabBarRect |= tabRect(i); never executed: optTabBase.tabBarRect |= tabRect(i); | 0 |
| 1701 | | - |
| 1702 | optTabBase.selectedTabRect = tabRect(selected); | - |
| 1703 | | - |
| 1704 | if (d->drawBase)| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 1705 | p.drawPrimitive(QStyle::PE_FrameTabBarBase, optTabBase); never executed: p.drawPrimitive(QStyle::PE_FrameTabBarBase, optTabBase); | 0 |
| 1706 | | - |
| 1707 | for (int i = 0; i < d->tabList.count(); ++i) {| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 1708 | QStyleOptionTab tab; | - |
| 1709 | initStyleOption(&tab, i); | - |
| 1710 | if (d->paintWithOffsets && d->tabList[i].dragOffset != 0) {| TRUE | never evaluated | | FALSE | never evaluated |
| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 1711 | if (vertical) {| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 1712 | tab.rect.moveTop(tab.rect.y() + d->tabList[i].dragOffset); | - |
| 1713 | } else { never executed: end of block | 0 |
| 1714 | tab.rect.moveLeft(tab.rect.x() + d->tabList[i].dragOffset); | - |
| 1715 | } never executed: end of block | 0 |
| 1716 | } | - |
| 1717 | if (!(tab.state & QStyle::State_Enabled)) {| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 1718 | tab.palette.setCurrentColorGroup(QPalette::Disabled); | - |
| 1719 | } never executed: end of block | 0 |
| 1720 | | - |
| 1721 | | - |
| 1722 | | - |
| 1723 | if (((!QRect tabRect = d->tabList[i].rect; | - |
| 1724 | int tabStart =| TRUE | never evaluated | | FALSE | never evaluated |
vertical && (!rtl && tab? tabRect.recttop() : tabRect.left() < 0)) || (rtl && tab();| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 1725 | int tabEnd = vertical ? tabRect| TRUE | never evaluated | | FALSE | never evaluated |
.rectbottom() : tabRect.right() > width()))| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| ||| TRUE | never evaluated | | FALSE | never evaluated |
();| TRUE | never evaluated | | FALSE | never evaluated |
| |
| 1726 | if| TRUE | never evaluated | | FALSE | never evaluated |
(vertical && tabtabStart < scrollRect.rectleft() + d->scrollOffset) {| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 1727 | cutLeft = i; | - |
| 1728 | cutTabLeft = tab; | - |
| 1729 | } else if (tabEnd > scrollRect never executed: end of block | TRUE | never evaluated | | FALSE | never evaluated |
.topright() < 0))+ d->scrollOffset) {never executed: end of block | TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 1730 | cutcutRight = i; | - |
| 1731 | cutTabcutTabRight = tab; | - |
| 1732 | } never executed: end of block | 0 |
| 1733 | | - |
| 1734 | | - |
| 1735 | if ((!vertical && (tab.rect.right() < 0 || tab.rect.left() > width()))| TRUE | never evaluated | | FALSE | never evaluated |
| TRUE | never evaluated | | FALSE | never evaluated |
| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 1736 | || (vertical && (tab.rect.bottom() < 0 || tab.rect.top() > height())))| TRUE | never evaluated | | FALSE | never evaluated |
| TRUE | never evaluated | | FALSE | never evaluated |
| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 1737 | continue; never executed: continue; | 0 |
| 1738 | | - |
| 1739 | optTabBase.tabBarRect |= tab.rect; | - |
| 1740 | if (i == selected)| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 1741 | continue; never executed: continue; | 0 |
| 1742 | | - |
| 1743 | p.drawControl(QStyle::CE_TabBarTab, tab); | - |
| 1744 | } never executed: end of block | 0 |
| 1745 | | - |
| 1746 | | - |
| 1747 | if (selected >= 0) {| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 1748 | QStyleOptionTab tab; | - |
| 1749 | initStyleOption(&tab, selected); | - |
| 1750 | if (d->paintWithOffsets && d->tabList[selected].dragOffset != 0) {| TRUE | never evaluated | | FALSE | never evaluated |
| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 1751 | if (vertical)| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 1752 | tab.rect.moveTop(tab.rect.y() + d->tabList[selected].dragOffset); never executed: tab.rect.moveTop(tab.rect.y() + d->tabList[selected].dragOffset); | 0 |
| 1753 | else | - |
| 1754 | tab.rect.moveLeft(tab.rect.x() + d->tabList[selected].dragOffset); never executed: tab.rect.moveLeft(tab.rect.x() + d->tabList[selected].dragOffset); | 0 |
| 1755 | } | - |
| 1756 | if (!d->dragInProgress)| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 1757 | p.drawControl(QStyle::CE_TabBarTab, tab); never executed: p.drawControl(QStyle::CE_TabBarTab, tab); | 0 |
| 1758 | else { | - |
| 1759 | int taboverlap = style()->pixelMetric(QStyle::PM_TabBarTabOverlap, 0, this); | - |
| 1760 | d->movingTab->setGeometry(tab.rect.adjusted(-taboverlap, 0, taboverlap, 0)); | - |
| 1761 | } never executed: end of block | 0 |
| 1762 | } | - |
| 1763 | | - |
| 1764 | | - |
| 1765 | if (d->leftB->isVisible() && cutcutLeft >= 0) {| TRUE | never evaluated | | FALSE | never evaluated |
| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 1766 | cutTabcutTabLeft.rect = rect(); | - |
| 1767 | cutTabcutTabLeft.rect = style()->subElementRect(QStyle::SE_TabBarTearIndicatorSE_TabBarTearIndicatorLeft, &cutTab&cutTabLeft, this); | - |
| 1768 | p.drawPrimitive(QStyle::PE_IndicatorTabTearPE_IndicatorTabTearLeft, cutTabcutTabLeft); | - |
| 1769 | } never executed: end of block | 0 |
| 1770 | | - |
| 1771 | if (d->rightB->isVisible() && cutRight >= 0) {| TRUE | never evaluated | | FALSE | never evaluated |
| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 1772 | cutTabRight.rect = rect(); | - |
| 1773 | cutTabRight.rect = style()->subElementRect(QStyle::SE_TabBarTearIndicatorRight, &cutTabRight, this); | - |
| 1774 | p.drawPrimitive(QStyle::PE_IndicatorTabTearRight, cutTabRight); | - |
| 1775 | } never executed: end of block | 0 |
| 1776 | } never executed: end of block | 0 |
| 1777 | | - |
| 1778 | | - |
| 1779 | | - |
| 1780 | | - |
| 1781 | int QTabBarPrivate::calculateNewPosition(int from, int to, int index) const | - |
| 1782 | { | - |
| 1783 | if (index == from) | - |
| 1784 | return to; | - |
| 1785 | | - |
| 1786 | int start = qMin(from, to); | - |
| 1787 | int end = qMax(from, to); | - |
| 1788 | if (index >= start && index <= end) | - |
| 1789 | index += (from < to) ? -1 : 1; | - |
| 1790 | return index; | - |
| 1791 | } | - |
| 1792 | | - |
| 1793 | | - |
| 1794 | | - |
| 1795 | | - |
| 1796 | | - |
| 1797 | | - |
| 1798 | | - |
| 1799 | void QTabBar::moveTab(int from, int to) | - |
| 1800 | { | - |
| 1801 | Q_D(QTabBar); | - |
| 1802 | if (from == to | - |
| 1803 | || !d->validIndex(from) | - |
| 1804 | || !d->validIndex(to)) | - |
| 1805 | return; | - |
| 1806 | | - |
| 1807 | bool vertical = verticalTabs(d->shape); | - |
| 1808 | int oldPressedPosition = 0; | - |
| 1809 | if (d->pressedIndex != -1) { | - |
| 1810 | | - |
| 1811 | oldPressedPosition = vertical ? d->tabList[d->pressedIndex].rect.y() | - |
| 1812 | : d->tabList[d->pressedIndex].rect.x(); | - |
| 1813 | } | - |
| 1814 | | - |
| 1815 | | - |
| 1816 | int start = qMin(from, to); | - |
| 1817 | int end = qMax(from, to); | - |
| 1818 | int width = vertical ? d->tabList[from].rect.height() : d->tabList[from].rect.width(); | - |
| 1819 | if (from < to) | - |
| 1820 | width *= -1; | - |
| 1821 | bool rtl = isRightToLeft(); | - |
| 1822 | for (int i = start; i <= end; ++i) { | - |
| 1823 | if (i == from) | - |
| 1824 | continue; | - |
| 1825 | if (vertical) | - |
| 1826 | d->tabList[i].rect.moveTop(d->tabList[i].rect.y() + width); | - |
| 1827 | else | - |
| 1828 | d->tabList[i].rect.moveLeft(d->tabList[i].rect.x() + width); | - |
| 1829 | int direction = -1; | - |
| 1830 | if (rtl && !vertical) | - |
| 1831 | direction *= -1; | - |
| 1832 | if (d->tabList[i].dragOffset != 0) | - |
| 1833 | d->tabList[i].dragOffset += (direction * width); | - |
| 1834 | } | - |
| 1835 | | - |
| 1836 | if (vertical) { | - |
| 1837 | if (from < to) | - |
| 1838 | d->tabList[from].rect.moveTop(d->tabList[to].rect.bottom() + 1); | - |
| 1839 | else | - |
| 1840 | d->tabList[from].rect.moveTop(d->tabList[to].rect.top() - width); | - |
| 1841 | } else { | - |
| 1842 | if (from < to) | - |
| 1843 | d->tabList[from].rect.moveLeft(d->tabList[to].rect.right() + 1); | - |
| 1844 | else | - |
| 1845 | d->tabList[from].rect.moveLeft(d->tabList[to].rect.left() - width); | - |
| 1846 | } | - |
| 1847 | | - |
| 1848 | | - |
| 1849 | d->tabList.move(from, to); | - |
| 1850 | | - |
| 1851 | | - |
| 1852 | for (int i = 0; i < d->tabList.count(); ++i) | - |
| 1853 | d->tabList[i].lastTab = d->calculateNewPosition(from, to, d->tabList[i].lastTab); | - |
| 1854 | | - |
| 1855 | | - |
| 1856 | int previousIndex = d->currentIndex; | - |
| 1857 | d->currentIndex = d->calculateNewPosition(from, to, d->currentIndex); | - |
| 1858 | | - |
| 1859 | | - |
| 1860 | if (d->pressedIndex != -1) { | - |
| 1861 | d->pressedIndex = d->calculateNewPosition(from, to, d->pressedIndex); | - |
| 1862 | int newPressedPosition = vertical ? d->tabList[d->pressedIndex].rect.top() : d->tabList[d->pressedIndex].rect.left(); | - |
| 1863 | int diff = oldPressedPosition - newPressedPosition; | - |
| 1864 | if (isRightToLeft() && !vertical) | - |
| 1865 | diff *= -1; | - |
| 1866 | if (vertical) | - |
| 1867 | d->dragStartPosition.setY(d->dragStartPosition.y() - diff); | - |
| 1868 | else | - |
| 1869 | d->dragStartPosition.setX(d->dragStartPosition.x() - diff); | - |
| 1870 | } | - |
| 1871 | | - |
| 1872 | d->layoutWidgets(start); | - |
| 1873 | update(); | - |
| 1874 | emit tabMoved(from, to); | - |
| 1875 | if (previousIndex != d->currentIndex) | - |
| 1876 | emit currentChanged(d->currentIndex); | - |
| 1877 | emit tabLayoutChange(); | - |
| 1878 | } | - |
| 1879 | | - |
| 1880 | void QTabBarPrivate::slide(int from, int to) | - |
| 1881 | { | - |
| 1882 | Q_Q(QTabBar); | - |
| 1883 | if (from == to | - |
| 1884 | || !validIndex(from) | - |
| 1885 | || !validIndex(to)) | - |
| 1886 | return; | - |
| 1887 | bool vertical = verticalTabs(shape); | - |
| 1888 | int preLocation = vertical ? q->tabRect(from).y() : q->tabRect(from).x(); | - |
| 1889 | q->setUpdatesEnabled(false); | - |
| 1890 | q->moveTab(from, to); | - |
| 1891 | q->setUpdatesEnabled(true); | - |
| 1892 | int postLocation = vertical ? q->tabRect(to).y() : q->tabRect(to).x(); | - |
| 1893 | int length = postLocation - preLocation; | - |
| 1894 | tabList[to].dragOffset -= length; | - |
| 1895 | tabList[to].startAnimation(this, ANIMATION_DURATION); | - |
| 1896 | } | - |
| 1897 | | - |
| 1898 | void QTabBarPrivate::moveTab(int index, int offset) | - |
| 1899 | { | - |
| 1900 | if (!validIndex(index)) | - |
| 1901 | return; | - |
| 1902 | tabList[index].dragOffset = offset; | - |
| 1903 | layoutTab(index); | - |
| 1904 | q_func()->update(); | - |
| 1905 | } | - |
| 1906 | | - |
| 1907 | | - |
| 1908 | | - |
| 1909 | void QTabBar::mousePressEvent(QMouseEvent *event) | - |
| 1910 | { | - |
| 1911 | Q_D(QTabBar); | - |
| 1912 | | - |
| 1913 | const QPoint pos = event->pos(); | - |
| 1914 | const bool isEventInCornerButtons = (!d->leftB->isHidden() && d->leftB->geometry().contains(pos)) | - |
| 1915 | || (!d->rightB->isHidden() && d->rightB->geometry().contains(pos)); | - |
| 1916 | if (!isEventInCornerButtons) { | - |
| 1917 | const int index = d->indexAtPos(pos); | - |
| 1918 | emit tabBarClicked(index); | - |
| 1919 | } | - |
| 1920 | | - |
| 1921 | if (event->button() != Qt::LeftButton) { | - |
| 1922 | event->ignore(); | - |
| 1923 | return; | - |
| 1924 | } | - |
| 1925 | | - |
| 1926 | if (d->pressedIndex != -1 && d->movable) | - |
| 1927 | d->moveTabFinished(d->pressedIndex); | - |
| 1928 | | - |
| 1929 | d->pressedIndex = d->indexAtPos(event->pos()); | - |
| 1930 | #ifdef Q_DEAD_CODE_FROM_QT4_MAC | - |
| 1931 | d->previousPressedIndex = d->pressedIndex; | - |
| 1932 | #endif | - |
| 1933 | if (d->validIndex(d->pressedIndex)) { | - |
| 1934 | QStyleOptionTabBarBase optTabBase; | - |
| 1935 | optTabBase.init(this); | - |
| 1936 | optTabBase.documentMode = d->documentMode; | - |
| 1937 | if (event->type() == style()->styleHint(QStyle::SH_TabBar_SelectMouseType, &optTabBase, this)) | - |
| 1938 | setCurrentIndex(d->pressedIndex); | - |
| 1939 | else | - |
| 1940 | repaint(tabRect(d->pressedIndex)); | - |
| 1941 | if (d->movable) { | - |
| 1942 | d->dragStartPosition = event->pos(); | - |
| 1943 | } | - |
| 1944 | } | - |
| 1945 | } | - |
| 1946 | | - |
| 1947 | | - |
| 1948 | | - |
| 1949 | void QTabBar::mouseMoveEvent(QMouseEvent *event) | - |
| 1950 | { | - |
| 1951 | Q_D(QTabBar); | - |
| 1952 | if (d->movable) {| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 1953 | | - |
| 1954 | if (d->pressedIndex != -1| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 1955 | && event->buttons() == Qt::NoButton)| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 1956 | d->moveTabFinished(d->pressedIndex); never executed: d->moveTabFinished(d->pressedIndex); | 0 |
| 1957 | | - |
| 1958 | | - |
| 1959 | if (!d->dragInProgress && d->pressedIndex != -1) {| TRUE | never evaluated | | FALSE | never evaluated |
| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 1960 | if ((event->pos() - d->dragStartPosition).manhattanLength() > QApplication::startDragDistance()) {| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 1961 | d->dragInProgress = true; | - |
| 1962 | d->setupMovableTab(); | - |
| 1963 | } never executed: end of block | 0 |
| 1964 | } never executed: end of block | 0 |
| 1965 | | - |
| 1966 | if (event->buttons() == Qt::LeftButton| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 1967 | && d->dragInProgress| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 1968 | && d->validIndex(d->pressedIndex)) {| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 1969 | bool vertical = verticalTabs(d->shape); | - |
| 1970 | int dragDistance; | - |
| 1971 | if (vertical) {| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 1972 | dragDistance = (event->pos().y() - d->dragStartPosition.y()); | - |
| 1973 | } else { never executed: end of block | 0 |
| 1974 | dragDistance = (event->pos().x() - d->dragStartPosition.x()); | - |
| 1975 | } never executed: end of block | 0 |
| 1976 | d->tabList[d->pressedIndex].dragOffset = dragDistance; | - |
| 1977 | | - |
| 1978 | QRect startingRect = tabRect(d->pressedIndex); | - |
| 1979 | if (vertical)| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 1980 | startingRect.moveTop(startingRect.y() + dragDistance); never executed: startingRect.moveTop(startingRect.y() + dragDistance); | 0 |
| 1981 | else | - |
| 1982 | startingRect.moveLeft(startingRect.x() + dragDistance); never executed: startingRect.moveLeft(startingRect.x() + dragDistance); | 0 |
| 1983 | | - |
| 1984 | int overIndex; | - |
| 1985 | if (dragDistance < 0)| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 1986 | overIndex = tabAt(startingRect.topLeft()); never executed: overIndex = tabAt(startingRect.topLeft()); | 0 |
| 1987 | else | - |
| 1988 | overIndex = tabAt(startingRect.topRight()); never executed: overIndex = tabAt(startingRect.topRight()); | 0 |
| 1989 | | - |
| 1990 | if (overIndex != d->pressedIndex && overIndex != -1) {| TRUE | never evaluated | | FALSE | never evaluated |
| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 1991 | int offset = 1; | - |
| 1992 | if (isRightToLeft() && !vertical)| TRUE | never evaluated | | FALSE | never evaluated |
| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 1993 | offset *= -1; never executed: offset *= -1; | 0 |
| 1994 | if (dragDistance < 0) {| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 1995 | dragDistance *= -1; | - |
| 1996 | offset *= -1; | - |
| 1997 | } never executed: end of block | 0 |
| 1998 | for (int i = d->pressedIndex; | - |
| 1999 | offset > 0 ? i < overIndex : i > overIndex;| TRUE | never evaluated | | FALSE | never evaluated |
| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 2000 | i += offset) { | - |
| 2001 | QRect overIndexRect = tabRect(overIndex); | - |
| 2002 | int needsToBeOver = (vertical ? overIndexRect.height() : overIndexRect.width()) / 2;| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 2003 | if (dragDistance > needsToBeOver)| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 2004 | d->slide(i + offset, d->pressedIndex); never executed: d->slide(i + offset, d->pressedIndex); | 0 |
| 2005 | } never executed: end of block | 0 |
| 2006 | } never executed: end of block | 0 |
| 2007 | | - |
| 2008 | d->layoutTab(d->pressedIndex); | - |
| 2009 | | - |
| 2010 | update(); | - |
| 2011 | } never executed: end of block | 0 |
| 2012 | #ifdef Q_DEAD_CODE_FROM_QT4_MAC | - |
| 2013 | } else if (!d->documentMode && event->buttons() == Qt::LeftButton && d->previousPressedIndex != -1) { | - |
| 2014 | int newPressedIndex = d->indexAtPos(event->pos()); | - |
| 2015 | if (d->pressedIndex == -1 && d->previousPressedIndex == newPressedIndex) { | - |
| 2016 | d->pressedIndex = d->previousPressedIndex; | - |
| 2017 | update(tabRect(d->pressedIndex)); | - |
| 2018 | } else if(d->pressedIndex != newPressedIndex) { | - |
| 2019 | d->pressedIndex = -1; | - |
| 2020 | update(tabRect(d->previousPressedIndex)); | - |
| 2021 | } | - |
| 2022 | #endif | - |
| 2023 | } never executed: end of block | 0 |
| 2024 | | - |
| 2025 | if (event->buttons() != Qt::LeftButton) {| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 2026 | event->ignore(); | - |
| 2027 | return; never executed: return; | 0 |
| 2028 | }QStyleOptionTabBarBase optTabBase; | - |
| optTabBase.init(this); | |
| optTabBase.documentMode = d->documentMode; | |
| 2029 | } never executed: end of block | 0 |
| 2030 | | - |
| 2031 | void QTabBarPrivate::setupMovableTab() | - |
| 2032 | { | - |
| 2033 | Q_Q(QTabBar); | - |
| 2034 | if (!movingTab) | - |
| 2035 | movingTab = new QMovableTabWidget(q); | - |
| 2036 | | - |
| 2037 | int taboverlap = q->style()->pixelMetric(QStyle::PM_TabBarTabOverlap, 0 ,q); | - |
| 2038 | QRect grabRect = q->tabRect(pressedIndex); | - |
| 2039 | grabRect.adjust(-taboverlap, 0, taboverlap, 0); | - |
| 2040 | | - |
| 2041 | QPixmap grabImage(grabRect.size() * q->devicePixelRatioF()); | - |
| 2042 | grabImage.setDevicePixelRatio(q->devicePixelRatioF()); | - |
| 2043 | grabImage.fill(Qt::transparent); | - |
| 2044 | QStylePainter p(&grabImage, q); | - |
| 2045 | p.initFrom(q); | - |
| 2046 | | - |
| 2047 | QStyleOptionTab tab; | - |
| 2048 | q->initStyleOption(&tab, pressedIndex); | - |
| 2049 | tab.rect.moveTopLeft(QPoint(taboverlap, 0)); | - |
| 2050 | p.drawControl(QStyle::CE_TabBarTab, tab); | - |
| 2051 | p.end(); | - |
| 2052 | | - |
| 2053 | movingTab->setPixmap(grabImage); | - |
| 2054 | movingTab->setGeometry(grabRect); | - |
| 2055 | movingTab->raise(); | - |
| 2056 | | - |
| 2057 | | - |
| 2058 | if (tabList[pressedIndex].leftWidget) | - |
| 2059 | tabList[pressedIndex].leftWidget->raise(); | - |
| 2060 | if (tabList[pressedIndex].rightWidget) | - |
| 2061 | tabList[pressedIndex].rightWidget->raise(); | - |
| 2062 | if (leftB) | - |
| 2063 | leftB->raise(); | - |
| 2064 | if (rightB) | - |
| 2065 | rightB->raise(); | - |
| 2066 | movingTab->setVisible(true); | - |
| 2067 | } | - |
| 2068 | | - |
| 2069 | void QTabBarPrivate::moveTabFinished(int index) | - |
| 2070 | { | - |
| 2071 | Q_Q(QTabBar); | - |
| 2072 | bool cleanup = (pressedIndex == index) || (pressedIndex == -1) || !validIndex(index); | - |
| 2073 | bool allAnimationsFinished = true; | - |
| 2074 | #ifndef QT_NO_ANIMATION | - |
| 2075 | for(int i = 0; allAnimationsFinished && i < tabList.count(); ++i) { | - |
| 2076 | const Tab &t = tabList.at(i); | - |
| 2077 | if (t.animation && t.animation->state() == QAbstractAnimation::Running) | - |
| 2078 | allAnimationsFinished = false; | - |
| 2079 | } | - |
| 2080 | #endif //QT_NO_ANIMATION | - |
| 2081 | if (allAnimationsFinished && cleanup) { | - |
| 2082 | if(movingTab) | - |
| 2083 | movingTab->setVisible(false); | - |
| 2084 | for (int i = 0; i < tabList.count(); ++i) { | - |
| 2085 | tabList[i].dragOffset = 0; | - |
| 2086 | } | - |
| 2087 | if (pressedIndex != -1 && movable) { | - |
| 2088 | pressedIndex = -1; | - |
| 2089 | dragInProgress = false; | - |
| 2090 | dragStartPosition = QPoint(); | - |
| 2091 | } | - |
| 2092 | layoutWidgets(); | - |
| 2093 | } else { | - |
| 2094 | if (!validIndex(index)) | - |
| 2095 | return; | - |
| 2096 | tabList[index].dragOffset = 0; | - |
| 2097 | } | - |
| 2098 | q->update(); | - |
| 2099 | } | - |
| 2100 | | - |
| 2101 | | - |
| 2102 | | - |
| 2103 | void QTabBar::mouseReleaseEvent(QMouseEvent *event) | - |
| 2104 | { | - |
| 2105 | Q_D(QTabBar); | - |
| 2106 | if (event->button() != Qt::LeftButton) { | - |
| 2107 | event->ignore(); | - |
| 2108 | return; | - |
| 2109 | } | - |
| 2110 | #ifdef Q_DEAD_CODE_FROM_QT4_MAC | - |
| 2111 | d->previousPressedIndex = -1; | - |
| 2112 | #endif | - |
| 2113 | if (d->movable && d->dragInProgress && d->validIndex(d->pressedIndex)) { | - |
| 2114 | int length = d->tabList[d->pressedIndex].dragOffset; | - |
| 2115 | int width = verticalTabs(d->shape) | - |
| 2116 | ? tabRect(d->pressedIndex).height() | - |
| 2117 | : tabRect(d->pressedIndex).width(); | - |
| 2118 | int duration = qMin(ANIMATION_DURATION, | - |
| 2119 | (qAbs(length) * ANIMATION_DURATION) / width); | - |
| 2120 | d->tabList[d->pressedIndex].startAnimation(d, duration); | - |
| 2121 | d->dragInProgress = false; | - |
| 2122 | d->movingTab->setVisible(false); | - |
| 2123 | d->dragStartPosition = QPoint(); | - |
| 2124 | } | - |
| 2125 | | - |
| 2126 | int i = d->indexAtPos(event->pos()) == d->pressedIndex ? d->pressedIndex : -1; | - |
| 2127 | d->pressedIndex = -1; | - |
| 2128 | QStyleOptionTabBarBase optTabBase; | - |
| 2129 | optTabBase.initFrom(this); | - |
| 2130 | optTabBase.documentMode = d->documentMode; | - |
| 2131 | if (style()->styleHint(QStyle::SH_TabBar_SelectMouseType, &optTabBase, this) == QEvent::MouseButtonRelease) | - |
| 2132 | setCurrentIndex(i); | - |
| 2133 | } | - |
| 2134 | | - |
| 2135 | | - |
| 2136 | | - |
| 2137 | void QTabBar::keyPressEvent(QKeyEvent *event) | - |
| 2138 | { | - |
| 2139 | Q_D(QTabBar); | - |
| 2140 | if (event->key() != Qt::Key_Left && event->key() != Qt::Key_Right) { | - |
| 2141 | event->ignore(); | - |
| 2142 | return; | - |
| 2143 | } | - |
| 2144 | int offset = event->key() == (isRightToLeft() ? Qt::Key_Right : Qt::Key_Left) ? -1 : 1; | - |
| 2145 | d->setCurrentNextEnabledIndex(offset); | - |
| 2146 | } | - |
| 2147 | | - |
| 2148 | | - |
| 2149 | | - |
| 2150 | #ifndef QT_NO_WHEELEVENT | - |
| 2151 | void QTabBar::wheelEvent(QWheelEvent *event) | - |
| 2152 | { | - |
| 2153 | #ifndef Q_OS_MAC | - |
| 2154 | Q_D(QTabBar); | - |
| 2155 | int offset = event->delta() > 0 ? -1 : 1; | - |
| 2156 | d->setCurrentNextEnabledIndex(offset); | - |
| 2157 | QWidget::wheelEvent(event); | - |
| 2158 | #else | - |
| 2159 | Q_UNUSED(event) | - |
| 2160 | #endif | - |
| 2161 | } | - |
| 2162 | #endif //QT_NO_WHEELEVENT | - |
| 2163 | | - |
| 2164 | void QTabBarPrivate::setCurrentNextEnabledIndex(int offset) | - |
| 2165 | { | - |
| 2166 | Q_Q(QTabBar); | - |
| 2167 | for (int index = currentIndex + offset; validIndex(index); index += offset) { | - |
| 2168 | if (tabList.at(index).enabled) { | - |
| 2169 | q->setCurrentIndex(index); | - |
| 2170 | break; | - |
| 2171 | } | - |
| 2172 | } | - |
| 2173 | } | - |
| 2174 | | - |
| 2175 | | - |
| 2176 | | - |
| 2177 | void QTabBar::changeEvent(QEvent *event) | - |
| 2178 | { | - |
| 2179 | Q_D(QTabBar); | - |
| 2180 | switch (event->type()) { | - |
| 2181 | case QEvent::StyleChange: | - |
| 2182 | if (!d->elideModeSetByUser) | - |
| 2183 | d->elideMode = Qt::TextElideMode(style()->styleHint(QStyle::SH_TabBar_ElideMode, 0, this)); | - |
| 2184 | if (!d->useScrollButtonsSetByUser) | - |
| 2185 | d->useScrollButtons = !style()->styleHint(QStyle::SH_TabBar_PreferNoArrows, 0, this); | - |
| 2186 | | - |
| 2187 | case QEvent::FontChange: | - |
| 2188 | d->textSizes.clear(); | - |
| 2189 | d->refresh(); | - |
| 2190 | break; | - |
| 2191 | default: | - |
| 2192 | break; | - |
| 2193 | } | - |
| 2194 | | - |
| 2195 | QWidget::changeEvent(event); | - |
| 2196 | } | - |
| 2197 | | - |
| 2198 | | - |
| 2199 | | - |
| 2200 | | - |
| 2201 | void QTabBar::timerEvent(QTimerEvent *event) | - |
| 2202 | { | - |
| 2203 | Q_D(QTabBar); | - |
| 2204 | if (event->timerId() == d->switchTabTimerId) { | - |
| 2205 | killTimer(d->switchTabTimerId); | - |
| 2206 | d->switchTabTimerId = 0; | - |
| 2207 | setCurrentIndex(d->switchTabCurrentIndex); | - |
| 2208 | d->switchTabCurrentIndex = -1; | - |
| 2209 | } | - |
| 2210 | QWidget::timerEvent(event); | - |
| 2211 | } | - |
| 2212 | | - |
| 2213 | | - |
| 2214 | | - |
| 2215 | | - |
| 2216 | | - |
| 2217 | | - |
| 2218 | | - |
| 2219 | | - |
| 2220 | | - |
| 2221 | | - |
| 2222 | | - |
| 2223 | | - |
| 2224 | | - |
| 2225 | | - |
| 2226 | Qt::TextElideMode QTabBar::elideMode() const | - |
| 2227 | { | - |
| 2228 | Q_D(const QTabBar); | - |
| 2229 | return d->elideMode; | - |
| 2230 | } | - |
| 2231 | | - |
| 2232 | void QTabBar::setElideMode(Qt::TextElideMode mode) | - |
| 2233 | { | - |
| 2234 | Q_D(QTabBar); | - |
| 2235 | d->elideMode = mode; | - |
| 2236 | d->elideModeSetByUser = true; | - |
| 2237 | d->textSizes.clear(); | - |
| 2238 | d->refresh(); | - |
| 2239 | } | - |
| 2240 | | - |
| 2241 | | - |
| 2242 | | - |
| 2243 | | - |
| 2244 | | - |
| 2245 | | - |
| 2246 | | - |
| 2247 | | - |
| 2248 | | - |
| 2249 | | - |
| 2250 | | - |
| 2251 | | - |
| 2252 | | - |
| 2253 | | - |
| 2254 | bool QTabBar::usesScrollButtons() const | - |
| 2255 | { | - |
| 2256 | return d_func()->useScrollButtons; | - |
| 2257 | } | - |
| 2258 | | - |
| 2259 | void QTabBar::setUsesScrollButtons(bool useButtons) | - |
| 2260 | { | - |
| 2261 | Q_D(QTabBar); | - |
| 2262 | d->useScrollButtonsSetByUser = true; | - |
| 2263 | if (d->useScrollButtons == useButtons) | - |
| 2264 | return; | - |
| 2265 | d->useScrollButtons = useButtons; | - |
| 2266 | d->refresh(); | - |
| 2267 | } | - |
| 2268 | | - |
| 2269 | | - |
| 2270 | | - |
| 2271 | | - |
| 2272 | | - |
| 2273 | | - |
| 2274 | | - |
| 2275 | | - |
| 2276 | | - |
| 2277 | | - |
| 2278 | | - |
| 2279 | | - |
| 2280 | | - |
| 2281 | | - |
| 2282 | | - |
| 2283 | bool QTabBar::tabsClosable() const | - |
| 2284 | { | - |
| 2285 | Q_D(const QTabBar); | - |
| 2286 | return d->closeButtonOnTabs; | - |
| 2287 | } | - |
| 2288 | | - |
| 2289 | void QTabBar::setTabsClosable(bool closable) | - |
| 2290 | { | - |
| 2291 | Q_D(QTabBar); | - |
| 2292 | if (d->closeButtonOnTabs == closable) | - |
| 2293 | return; | - |
| 2294 | d->closeButtonOnTabs = closable; | - |
| 2295 | ButtonPosition closeSide = (ButtonPosition)style()->styleHint(QStyle::SH_TabBar_CloseButtonPosition, 0, this); | - |
| 2296 | if (!closable) { | - |
| 2297 | for (int i = 0; i < d->tabList.count(); ++i) { | - |
| 2298 | if (closeSide == LeftSide && d->tabList[i].leftWidget) { | - |
| 2299 | d->tabList[i].leftWidget->deleteLater(); | - |
| 2300 | d->tabList[i].leftWidget = 0; | - |
| 2301 | } | - |
| 2302 | if (closeSide == RightSide && d->tabList[i].rightWidget) { | - |
| 2303 | d->tabList[i].rightWidget->deleteLater(); | - |
| 2304 | d->tabList[i].rightWidget = 0; | - |
| 2305 | } | - |
| 2306 | } | - |
| 2307 | } else { | - |
| 2308 | bool newButtons = false; | - |
| 2309 | for (int i = 0; i < d->tabList.count(); ++i) { | - |
| 2310 | if (tabButton(i, closeSide)) | - |
| 2311 | continue; | - |
| 2312 | newButtons = true; | - |
| 2313 | QAbstractButton *closeButton = new CloseButton(this); | - |
| 2314 | connect(closeButton, SIGNAL(clicked()), this, SLOT(_q_closeTab())); | - |
| 2315 | setTabButton(i, closeSide, closeButton); | - |
| 2316 | } | - |
| 2317 | if (newButtons) | - |
| 2318 | d->layoutTabs(); | - |
| 2319 | } | - |
| 2320 | update(); | - |
| 2321 | } | - |
| 2322 | | - |
| 2323 | | - |
| 2324 | | - |
| 2325 | | - |
| 2326 | | - |
| 2327 | | - |
| 2328 | | - |
| 2329 | | - |
| 2330 | | - |
| 2331 | | - |
| 2332 | | - |
| 2333 | | - |
| 2334 | | - |
| 2335 | | - |
| 2336 | | - |
| 2337 | | - |
| 2338 | | - |
| 2339 | | - |
| 2340 | | - |
| 2341 | | - |
| 2342 | | - |
| 2343 | | - |
| 2344 | | - |
| 2345 | | - |
| 2346 | | - |
| 2347 | | - |
| 2348 | | - |
| 2349 | | - |
| 2350 | | - |
| 2351 | | - |
| 2352 | | - |
| 2353 | | - |
| 2354 | | - |
| 2355 | | - |
| 2356 | | - |
| 2357 | | - |
| 2358 | | - |
| 2359 | | - |
| 2360 | | - |
| 2361 | | - |
| 2362 | QTabBar::SelectionBehavior QTabBar::selectionBehaviorOnRemove() const | - |
| 2363 | { | - |
| 2364 | Q_D(const QTabBar); | - |
| 2365 | return d->selectionBehaviorOnRemove; | - |
| 2366 | } | - |
| 2367 | | - |
| 2368 | void QTabBar::setSelectionBehaviorOnRemove(QTabBar::SelectionBehavior behavior) | - |
| 2369 | { | - |
| 2370 | Q_D(QTabBar); | - |
| 2371 | d->selectionBehaviorOnRemove = behavior; | - |
| 2372 | } | - |
| 2373 | | - |
| 2374 | | - |
| 2375 | | - |
| 2376 | | - |
| 2377 | | - |
| 2378 | | - |
| 2379 | | - |
| 2380 | | - |
| 2381 | | - |
| 2382 | | - |
| 2383 | | - |
| 2384 | bool QTabBar::expanding() const | - |
| 2385 | { | - |
| 2386 | Q_D(const QTabBar); | - |
| 2387 | return d->expanding; | - |
| 2388 | } | - |
| 2389 | | - |
| 2390 | void QTabBar::setExpanding(bool enabled) | - |
| 2391 | { | - |
| 2392 | Q_D(QTabBar); | - |
| 2393 | if (d->expanding == enabled) | - |
| 2394 | return; | - |
| 2395 | d->expanding = enabled; | - |
| 2396 | d->layoutTabs(); | - |
| 2397 | } | - |
| 2398 | | - |
| 2399 | | - |
| 2400 | | - |
| 2401 | | - |
| 2402 | | - |
| 2403 | | - |
| 2404 | | - |
| 2405 | | - |
| 2406 | | - |
| 2407 | | - |
| 2408 | | - |
| 2409 | bool QTabBar::isMovable() const | - |
| 2410 | { | - |
| 2411 | Q_D(const QTabBar); | - |
| 2412 | return d->movable; | - |
| 2413 | } | - |
| 2414 | | - |
| 2415 | void QTabBar::setMovable(bool movable) | - |
| 2416 | { | - |
| 2417 | Q_D(QTabBar); | - |
| 2418 | d->movable = movable; | - |
| 2419 | } | - |
| 2420 | | - |
| 2421 | | - |
| 2422 | | - |
| 2423 | | - |
| 2424 | | - |
| 2425 | | - |
| 2426 | | - |
| 2427 | | - |
| 2428 | | - |
| 2429 | | - |
| 2430 | | - |
| 2431 | | - |
| 2432 | | - |
| 2433 | bool QTabBar::documentMode() const | - |
| 2434 | { | - |
| 2435 | return d_func()->documentMode; | - |
| 2436 | } | - |
| 2437 | | - |
| 2438 | void QTabBar::setDocumentMode(bool enabled) | - |
| 2439 | { | - |
| 2440 | Q_D(QTabBar); | - |
| 2441 | | - |
| 2442 | d->documentMode = enabled; | - |
| 2443 | d->updateMacBorderMetrics(); | - |
| 2444 | } | - |
| 2445 | | - |
| 2446 | | - |
| 2447 | | - |
| 2448 | | - |
| 2449 | | - |
| 2450 | | - |
| 2451 | | - |
| 2452 | | - |
| 2453 | | - |
| 2454 | | - |
| 2455 | | - |
| 2456 | | - |
| 2457 | bool QTabBar::autoHide() const | - |
| 2458 | { | - |
| 2459 | Q_D(const QTabBar); | - |
| 2460 | return d->autoHide; | - |
| 2461 | } | - |
| 2462 | | - |
| 2463 | void QTabBar::setAutoHide(bool hide) | - |
| 2464 | { | - |
| 2465 | Q_D(QTabBar); | - |
| 2466 | if (d->autoHide == hide) | - |
| 2467 | return; | - |
| 2468 | | - |
| 2469 | d->autoHide = hide; | - |
| 2470 | if (hide) | - |
| 2471 | d->autoHideTabs(); | - |
| 2472 | else | - |
| 2473 | setVisible(true); | - |
| 2474 | } | - |
| 2475 | | - |
| 2476 | | - |
| 2477 | | - |
| 2478 | | - |
| 2479 | | - |
| 2480 | | - |
| 2481 | | - |
| 2482 | | - |
| 2483 | | - |
| 2484 | | - |
| 2485 | | - |
| 2486 | | - |
| 2487 | | - |
| 2488 | bool QTabBar::changeCurrentOnDrag() const | - |
| 2489 | { | - |
| 2490 | Q_D(const QTabBar); | - |
| 2491 | return d->changeCurrentOnDrag; | - |
| 2492 | } | - |
| 2493 | | - |
| 2494 | void QTabBar::setChangeCurrentOnDrag(bool change) | - |
| 2495 | { | - |
| 2496 | Q_D(QTabBar); | - |
| 2497 | d->changeCurrentOnDrag = change; | - |
| 2498 | if (!change) | - |
| 2499 | d->killSwitchTabTimer(); | - |
| 2500 | } | - |
| 2501 | | - |
| 2502 | | - |
| 2503 | | - |
| 2504 | | - |
| 2505 | | - |
| 2506 | | - |
| 2507 | | - |
| 2508 | | - |
| 2509 | | - |
| 2510 | | - |
| 2511 | | - |
| 2512 | | - |
| 2513 | | - |
| 2514 | | - |
| 2515 | void QTabBar::setTabButton(int index, ButtonPosition position, QWidget *widget) | - |
| 2516 | { | - |
| 2517 | Q_D(QTabBar); | - |
| 2518 | if (index < 0 || index >= d->tabList.count()) | - |
| 2519 | return; | - |
| 2520 | if (widget) { | - |
| 2521 | widget->setParent(this); | - |
| 2522 | | - |
| 2523 | widget->lower(); | - |
| 2524 | widget->show(); | - |
| 2525 | } | - |
| 2526 | if (position == LeftSide) { | - |
| 2527 | if (d->tabList[index].leftWidget) | - |
| 2528 | d->tabList[index].leftWidget->hide(); | - |
| 2529 | d->tabList[index].leftWidget = widget; | - |
| 2530 | } else { | - |
| 2531 | if (d->tabList[index].rightWidget) | - |
| 2532 | d->tabList[index].rightWidget->hide(); | - |
| 2533 | d->tabList[index].rightWidget = widget; | - |
| 2534 | } | - |
| 2535 | d->layoutTabs(); | - |
| 2536 | d->refresh(); | - |
| 2537 | update(); | - |
| 2538 | } | - |
| 2539 | | - |
| 2540 | | - |
| 2541 | | - |
| 2542 | | - |
| 2543 | | - |
| 2544 | QWidget *QTabBar::tabButton(int index, ButtonPosition position) const | - |
| 2545 | { | - |
| 2546 | Q_D(const QTabBar); | - |
| 2547 | if (index < 0 || index >= d->tabList.count()) | - |
| 2548 | return 0; | - |
| 2549 | if (position == LeftSide) | - |
| 2550 | return d->tabList.at(index).leftWidget; | - |
| 2551 | else | - |
| 2552 | return d->tabList.at(index).rightWidget; | - |
| 2553 | } | - |
| 2554 | | - |
| 2555 | CloseButton::CloseButton(QWidget *parent) | - |
| 2556 | : QAbstractButton(parent) | - |
| 2557 | { | - |
| 2558 | setFocusPolicy(Qt::NoFocus); | - |
| 2559 | #ifndef QT_NO_CURSOR | - |
| 2560 | setCursor(Qt::ArrowCursor); | - |
| 2561 | #endif | - |
| 2562 | #ifndef QT_NO_TOOLTIP | - |
| 2563 | setToolTip(tr("Close Tab")); | - |
| 2564 | #endif | - |
| 2565 | resize(sizeHint()); | - |
| 2566 | } | - |
| 2567 | | - |
| 2568 | QSize CloseButton::sizeHint() const | - |
| 2569 | { | - |
| 2570 | ensurePolished(); | - |
| 2571 | int width = style()->pixelMetric(QStyle::PM_TabCloseIndicatorWidth, 0, this); | - |
| 2572 | int height = style()->pixelMetric(QStyle::PM_TabCloseIndicatorHeight, 0, this); | - |
| 2573 | return QSize(width, height); | - |
| 2574 | } | - |
| 2575 | | - |
| 2576 | void CloseButton::enterEvent(QEvent *event) | - |
| 2577 | { | - |
| 2578 | if (isEnabled()) | - |
| 2579 | update(); | - |
| 2580 | QAbstractButton::enterEvent(event); | - |
| 2581 | } | - |
| 2582 | | - |
| 2583 | void CloseButton::leaveEvent(QEvent *event) | - |
| 2584 | { | - |
| 2585 | if (isEnabled()) | - |
| 2586 | update(); | - |
| 2587 | QAbstractButton::leaveEvent(event); | - |
| 2588 | } | - |
| 2589 | | - |
| 2590 | void CloseButton::paintEvent(QPaintEvent *) | - |
| 2591 | { | - |
| 2592 | QPainter p(this); | - |
| 2593 | QStyleOption opt; | - |
| 2594 | opt.init(this); | - |
| 2595 | opt.state |= QStyle::State_AutoRaise; | - |
| 2596 | if (isEnabled() && underMouse() && !isChecked() && !isDown()) | - |
| 2597 | opt.state |= QStyle::State_Raised; | - |
| 2598 | if (isChecked()) | - |
| 2599 | opt.state |= QStyle::State_On; | - |
| 2600 | if (isDown()) | - |
| 2601 | opt.state |= QStyle::State_Sunken; | - |
| 2602 | | - |
| 2603 | if (const QTabBar *tb = qobject_cast<const QTabBar *>(parent())) { | - |
| 2604 | int index = tb->currentIndex(); | - |
| 2605 | QTabBar::ButtonPosition position = (QTabBar::ButtonPosition)style()->styleHint(QStyle::SH_TabBar_CloseButtonPosition, 0, tb); | - |
| 2606 | if (tb->tabButton(index, position) == this) | - |
| 2607 | opt.state |= QStyle::State_Selected; | - |
| 2608 | } | - |
| 2609 | | - |
| 2610 | style()->drawPrimitive(QStyle::PE_IndicatorTabClose, &opt, &p, this); | - |
| 2611 | } | - |
| 2612 | | - |
| 2613 | #ifndef QT_NO_ANIMATION | - |
| 2614 | void QTabBarPrivate::Tab::TabBarAnimation::updateCurrentValue(const QVariant ¤t) | - |
| 2615 | { | - |
| 2616 | priv->moveTab(priv->tabList.indexOf(*tab), current.toInt()); | - |
| 2617 | } | - |
| 2618 | | - |
| 2619 | void QTabBarPrivate::Tab::TabBarAnimation::updateState(QAbstractAnimation::State, QAbstractAnimation::State newState) | - |
| 2620 | { | - |
| 2621 | if (newState == Stopped) priv->moveTabFinished(priv->tabList.indexOf(*tab)); | - |
| 2622 | } | - |
| 2623 | #endif | - |
| 2624 | | - |
| 2625 | QT_END_NAMESPACE | - |
| 2626 | | - |
| 2627 | #include "moc_qtabbar.cpp" | - |
| 2628 | | - |
| 2629 | #endif // QT_NO_TABBAR | - |
| 2630 | | - |
| 2631 | #include "moc_qtabbar_p.cpp" | - |
| | |