qtabbar.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/widgets/widgets/qtabbar.cpp
Source codeSwitch to Preprocessed file
LineSourceCount
1/****************************************************************************-
2**-
3** Copyright (C) 2016 The Qt Company Ltd.-
4** Contact: https://www.qt.io/licensing/-
5**-
6** This file is part of the QtWidgets module of the Qt Toolkit.-
7**-
8** $QT_BEGIN_LICENSE:LGPL$-
9** Commercial License Usage-
10** Licensees holding valid commercial Qt licenses may use this file in-
11** accordance with the commercial license agreement provided with the-
12** Software or, alternatively, in accordance with the terms contained in-
13** a written agreement between you and The Qt Company. For licensing terms-
14** and conditions see https://www.qt.io/terms-conditions. For further-
15** information use the contact form at https://www.qt.io/contact-us.-
16**-
17** GNU Lesser General Public License Usage-
18** Alternatively, this file may be used under the terms of the GNU Lesser-
19** General Public License version 3 as published by the Free Software-
20** Foundation and appearing in the file LICENSE.LGPL3 included in the-
21** packaging of this file. Please review the following information to-
22** ensure the GNU Lesser General Public License version 3 requirements-
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.-
24**-
25** GNU General Public License Usage-
26** Alternatively, this file may be used under the terms of the GNU-
27** General Public License version 2.0 or (at your option) the GNU General-
28** Public license version 3 or any later version approved by the KDE Free-
29** Qt Foundation. The licenses are as published by the Free Software-
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3-
31** included in the packaging of this file. Please review the following-
32** information to ensure the GNU General Public License requirements will-
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and-
34** https://www.gnu.org/licenses/gpl-3.0.html.-
35**-
36** $QT_END_LICENSE$-
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-
71QT_BEGIN_NAMESPACE-
72-
73QMovableTabWidget::QMovableTabWidget(QWidget *parent)-
74 : QWidget(parent)-
75{-
76}-
77-
78void QMovableTabWidget::setPixmap(const QPixmap &pixmap)-
79{-
80 m_pixmap = pixmap;-
81 update();-
82}-
83-
84void QMovableTabWidget::paintEvent(QPaintEvent *e)-
85{-
86 Q_UNUSED(e);-
87 QPainter p(this);-
88 p.drawPixmap(0, 0, m_pixmap);-
89}-
90-
91inline 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-
99void QTabBarPrivate::updateMacBorderMetrics()-
100{-
101#if defined(Q_OS_OSX)-
102 Q_Q(QTabBar);-
103 // Extend the unified title and toolbar area to cover the tab bar iff-
104 // 1) the tab bar is in document mode-
105 // 2) the tab bar is directly below an "unified" area.-
106 // The extending itself is done in the Cocoa platform plugin and Mac style,-
107 // this function registers geometry and visibility state for the tab bar.-
108-
109 // Calculate geometry-
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 // Set geometry-
126 QPlatformNativeInterface::NativeResourceForIntegrationFunction function =-
127 nativeInterface->nativeResourceFunctionForIntegration("registerContentBorderArea");-
128 if (!function)-
129 return; // Not Cocoa platform plugin.-
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 // Set visibility state-
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 \internal-
144 This is basically QTabBar::initStyleOption() but-
145 without the expensive QFontMetrics::elidedText() call.-
146*/-
147-
148void 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))
!optionDescription
TRUEnever evaluated
FALSEnever evaluated
tabIndex < 0Description
TRUEnever evaluated
FALSEnever evaluated
tabIndex >= totalTabsDescription
TRUEnever evaluated
FALSEnever 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)
tabIndex == pressedIndexDescription
TRUEnever evaluated
FALSEnever evaluated
0
163 option->state |= QStyle::State_Sunken;
never executed: option->state |= QStyle::State_Sunken;
0
164 if (isCurrent)
isCurrentDescription
TRUEnever evaluated
FALSEnever evaluated
0
165 option->state |= QStyle::State_Selected;
never executed: option->state |= QStyle::State_Selected;
0
166 if (isCurrent && q->hasFocus())
isCurrentDescription
TRUEnever evaluated
FALSEnever evaluated
q->hasFocus()Description
TRUEnever evaluated
FALSEnever evaluated
0
167 option->state |= QStyle::State_HasFocus;
never executed: option->state |= QStyle::State_HasFocus;
0
168 if (!tab.enabled)
!tab.enabledDescription
TRUEnever evaluated
FALSEnever evaluated
0
169 option->state &= ~QStyle::State_Enabled;
never executed: option->state &= ~QStyle::State_Enabled;
0
170 if (q->isActiveWindow())
q->isActiveWindow()Description
TRUEnever evaluated
FALSEnever evaluated
0
171 option->state |= QStyle::State_Active;
never executed: option->state |= QStyle::State_Active;
0
172 if (!dragInProgress && option->rect == hoverRect)
!dragInProgressDescription
TRUEnever evaluated
FALSEnever evaluated
option->rect == hoverRectDescription
TRUEnever evaluated
FALSEnever 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())
tab.textColor.isValid()Description
TRUEnever evaluated
FALSEnever 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(); // Will get the default value then.-
187-
188 option->leftButtonSize = tab.leftWidget ? tab.leftWidget->size() : QSize();
tab.leftWidgetDescription
TRUEnever evaluated
FALSEnever evaluated
0
189 option->rightButtonSize = tab.rightWidget ? tab.rightWidget->size() : QSize();
tab.rightWidgetDescription
TRUEnever evaluated
FALSEnever evaluated
0
190 option->documentMode = documentMode;-
191-
192 if (tabIndex > 0 && tabIndex - 1 == currentIndex)
tabIndex > 0Description
TRUEnever evaluated
FALSEnever evaluated
tabIndex - 1 == currentIndexDescription
TRUEnever evaluated
FALSEnever evaluated
0
193 option->selectedPosition = QStyleOptionTab::PreviousIsSelected;
never executed: option->selectedPosition = QStyleOptionTab::PreviousIsSelected;
0
194 else if (tabIndex + 1 < totalTabs && tabIndex + 1 == currentIndex)
tabIndex + 1 < totalTabsDescription
TRUEnever evaluated
FALSEnever evaluated
tabIndex + 1 == currentIndexDescription
TRUEnever evaluated
FALSEnever 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);
(tabIndex == 0)Description
TRUEnever evaluated
FALSEnever evaluated
dragInProgressDescription
TRUEnever evaluated
FALSEnever evaluated
tabIndex == pressedIndex + 1Description
TRUEnever evaluated
FALSEnever evaluated
0
200 const bool paintEnd = (tabIndex == totalTabs - 1) || (dragInProgress && tabIndex == pressedIndex - 1);
(tabIndex == totalTabs - 1)Description
TRUEnever evaluated
FALSEnever evaluated
dragInProgressDescription
TRUEnever evaluated
FALSEnever evaluated
tabIndex == pressedIndex - 1Description
TRUEnever evaluated
FALSEnever evaluated
0
201 if (paintBeginning) {
paintBeginningDescription
TRUEnever evaluated
FALSEnever evaluated
0
202 if (paintEnd)
paintEndDescription
TRUEnever evaluated
FALSEnever 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) {
paintEndDescription
TRUEnever evaluated
FALSEnever 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())) {
const QTabWidg...arentWidget())Description
TRUEnever evaluated
FALSEnever evaluated
0
214 option->features |= QStyleOptionTab::HasFrame;-
215 if (tw->cornerWidget(Qt::TopLeftCorner) || tw->cornerWidget(Qt::BottomLeftCorner))
tw->cornerWidg...TopLeftCorner)Description
TRUEnever evaluated
FALSEnever evaluated
tw->cornerWidg...tomLeftCorner)Description
TRUEnever evaluated
FALSEnever evaluated
0
216 option->cornerWidgets |= QStyleOptionTab::LeftCornerWidget;
never executed: option->cornerWidgets |= QStyleOptionTab::LeftCornerWidget;
0
217 if (tw->cornerWidget(Qt::TopRightCorner) || tw->cornerWidget(Qt::BottomRightCorner))
tw->cornerWidg...opRightCorner)Description
TRUEnever evaluated
FALSEnever evaluated
tw->cornerWidg...omRightCorner)Description
TRUEnever evaluated
FALSEnever 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 Initialize \a option with the values from the tab at \a tabIndex. This method-
225 is useful for subclasses when they need a QStyleOptionTab,-
226 but don't want to fill in all the information themselves.-
227-
228 \sa QStyleOption::initFrom(), QTabWidget::initStyleOption()-
229*/-
230void 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 \class QTabBar-
242 \brief The QTabBar class provides a tab bar, e.g. for use in tabbed dialogs.-
243-
244 \ingroup basicwidgets-
245 \inmodule QtWidgets-
246-
247 QTabBar is straightforward to use; it draws the tabs using one of-
248 the predefined \l{QTabBar::Shape}{shapes}, and emits a-
249 signal when a tab is selected. It can be subclassed to tailor the-
250 look and feel. Qt also provides a ready-made \l{QTabWidget}.-
251-
252 Each tab has a tabText(), an optional tabIcon(), an optional-
253 tabToolTip(), optional tabWhatsThis() and optional tabData().-
254 The tabs's attributes can be changed with setTabText(), setTabIcon(),-
255 setTabToolTip(), setTabWhatsThis and setTabData(). Each tabs can be-
256 enabled or disabled individually with setTabEnabled().-
257-
258 Each tab can display text in a distinct color. The current text color-
259 for a tab can be found with the tabTextColor() function. Set the text-
260 color for a particular tab with setTabTextColor().-
261-
262 Tabs are added using addTab(), or inserted at particular positions-
263 using insertTab(). The total number of tabs is given by-
264 count(). Tabs can be removed from the tab bar with-
265 removeTab(). Combining removeTab() and insertTab() allows you to-
266 move tabs to different positions.-
267-
268 The \l shape property defines the tabs' appearance. The choice of-
269 shape is a matter of taste, although tab dialogs (for preferences-
270 and similar) invariably use \l RoundedNorth.-
271 Tab controls in windows other than dialogs almost-
272 always use either \l RoundedSouth or \l TriangularSouth. Many-
273 spreadsheets and other tab controls in which all the pages are-
274 essentially similar use \l TriangularSouth, whereas \l-
275 RoundedSouth is used mostly when the pages are different (e.g. a-
276 multi-page tool palette). The default in QTabBar is \l-
277 RoundedNorth.-
278-
279 The most important part of QTabBar's API is the currentChanged()-
280 signal. This is emitted whenever the current tab changes (even at-
281 startup, when the current tab changes from 'none'). There is also-
282 a slot, setCurrentIndex(), which can be used to select a tab-
283 programmatically. The function currentIndex() returns the index of-
284 the current tab, \l count holds the number of tabs.-
285-
286 QTabBar creates automatic mnemonic keys in the manner of QAbstractButton;-
287 e.g. if a tab's label is "\&Graphics", Alt+G becomes a shortcut-
288 key for switching to that tab.-
289-
290 The following virtual functions may need to be reimplemented in-
291 order to tailor the look and feel or store extra data with each-
292 tab:-
293-
294 \list-
295 \li tabSizeHint() calcuates the size of a tab.-
296 \li tabInserted() notifies that a new tab was added.-
297 \li tabRemoved() notifies that a tab was removed.-
298 \li tabLayoutChange() notifies that the tabs have been re-laid out.-
299 \li paintEvent() paints all tabs.-
300 \endlist-
301-
302 For subclasses, you might also need the tabRect() functions which-
303 returns the visual geometry of a single tab.-
304-
305 \table 100%-
306 \row \li \inlineimage fusion-tabbar.png Screenshot of a Fusion style tab bar-
307 \li A tab bar shown in the Fusion widget style.-
308 \row \li \inlineimage fusion-tabbar-truncated.png Screenshot of a truncated Fusion tab bar-
309 \li A truncated tab bar shown in the Fusion widget style.-
310 \endtable-
311-
312 \sa QTabWidget-
313*/-
314-
315/*!-
316 \enum QTabBar::Shape-
317-
318 This enum type lists the built-in shapes supported by QTabBar. Treat these-
319 as hints as some styles may not render some of the shapes. However,-
320 position should be honored.-
321-
322 \value RoundedNorth The normal rounded look above the pages-
323-
324 \value RoundedSouth The normal rounded look below the pages-
325-
326 \value RoundedWest The normal rounded look on the left side of the pages-
327-
328 \value RoundedEast The normal rounded look on the right side the pages-
329-
330 \value TriangularNorth Triangular tabs above the pages.-
331-
332 \value TriangularSouth Triangular tabs similar to those used in-
333 the Excel spreadsheet, for example-
334-
335 \value TriangularWest Triangular tabs on the left of the pages.-
336-
337 \value TriangularEast Triangular tabs on the right of the pages.-
338*/-
339-
340/*!-
341 \fn void QTabBar::currentChanged(int index)-
342-
343 This signal is emitted when the tab bar's current tab changes. The-
344 new current has the given \a index, or -1 if there isn't a new one-
345 (for example, if there are no tab in the QTabBar)-
346*/-
347-
348/*!-
349 \fn void QTabBar::tabCloseRequested(int index)-
350 \since 4.5-
351-
352 This signal is emitted when the close button on a tab is clicked.-
353 The \a index is the index that should be removed.-
354-
355 \sa setTabsClosable()-
356*/-
357-
358/*!-
359 \fn void QTabBar::tabMoved(int from, int to)-
360 \since 4.5-
361-
362 This signal is emitted when the tab has moved the tab-
363 at index position \a from to index position \a to.-
364-
365 note: QTabWidget will automatically move the page when-
366 this signal is emitted from its tab bar.-
367-
368 \sa moveTab()-
369*/-
370-
371/*!-
372 \fn void QTabBar::tabBarClicked(int index)-
373-
374 This signal is emitted when user clicks on a tab at an \a index.-
375-
376 \a index is the index of a clicked tab, or -1 if no tab is under the cursor.-
377-
378 \since 5.2-
379*/-
380-
381/*!-
382 \fn void QTabBar::tabBarDoubleClicked(int index)-
383-
384 This signal is emitted when the user double clicks on a tab at \a index.-
385-
386 \a index refers to the tab clicked, or -1 if no tab is under the cursor.-
387-
388 \since 5.2-
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-
420QTabBarPrivate::Tab *QTabBarPrivate::at(int index)-
421{-
422 return validIndex(index)?&tabList[index]:0;-
423}-
424-
425const QTabBarPrivate::Tab *QTabBarPrivate::at(int index) const-
426{-
427 return validIndex(index)?&tabList[index]:0;-
428}-
429-
430int 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-
441void 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 // We put an empty item at the front and back and set its expansive attribute-
456 // depending on tabAlignment.-
457 tabChain[tabChainIndex].init();-
458 tabChain[tabChainIndex].expansive = (tabAlignment != Qt::AlignLeft)
(tabAlignment ...Qt::AlignLeft)Description
TRUEnever evaluated
FALSEnever evaluated
0
459 && (tabAlignment != Qt::AlignJustify);
(tabAlignment ...:AlignJustify)Description
TRUEnever evaluated
FALSEnever evaluated
0
460 tabChain[tabChainIndex].empty = true;-
461 ++tabChainIndex;-
462-
463 // We now go through our list of tabs and set the minimum size and the size hint-
464 // This will allow us to elide text if necessary. Since we don't set-
465 // a maximum size, tabs will EXPAND to fill up the empty space.-
466 // Since tab widget is rather *ahem* strict about keeping the geometry of the-
467 // tab bar to its absolute minimum, this won't bleed through, but will show up-
468 // if you use tab bar on its own (a.k.a. not a bug, but a feature).-
469 // Update: if expanding is false, we DO set a maximum size to prevent the tabs-
470 // being wider than necessary.-
471 if (!vertTabs) {
!vertTabsDescription
TRUEnever evaluated
FALSEnever evaluated
0
472 int minx = 0;-
473 int x = 0;-
474 int maxHeight = 0;-
475 for (i = 0; i < tabList.count(); ++i, ++tabChainIndex) {
i < tabList.count()Description
TRUEnever evaluated
FALSEnever 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)
!expandingDescription
TRUEnever evaluated
FALSEnever 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) {
i < tabList.count()Description
TRUEnever evaluated
FALSEnever 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)
!expandingDescription
TRUEnever evaluated
FALSEnever 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); // add an assert just to make sure.-
524 // Mirror our front item.-
525 tabChain[tabChainIndex].init();-
526 tabChain[tabChainIndex].expansive = (tabAlignment != Qt::AlignRight)
(tabAlignment ...t::AlignRight)Description
TRUEnever evaluated
FALSEnever evaluated
0
527 && (tabAlignment != Qt::AlignJustify);
(tabAlignment ...:AlignJustify)Description
TRUEnever evaluated
FALSEnever evaluated
0
528 tabChain[tabChainIndex].empty = true;-
529-
530 // Do the calculation-
531 qGeomCalc(tabChain, 0, tabChain.count(), 0, qMax(available, last), 0);-
532-
533 // Use the results-
534 for (i = 0; i < tabList.count(); ++i) {
i < tabList.count()Description
TRUEnever evaluated
FALSEnever evaluated
0
535 const QLayoutStruct &lstruct = tabChain.at(i + 1);-
536 if (!vertTabs)
!vertTabsDescription
TRUEnever evaluated
FALSEnever 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) {
useScrollButtonsDescription
TRUEnever evaluated
FALSEnever evaluated
tabList.count()Description
TRUEnever evaluated
FALSEnever evaluated
last > availableDescription
TRUEnever evaluated
FALSEnever 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 // Normally SE_TabBarScrollLeftButton should have the same width as PM_TabBarScrollButtonWidth.-
554 // But if that is not the case, we set the actual button width to PM_TabBarScrollButtonWidth, and-
555 // use the extra space from SE_TabBarScrollLeftButton as margins towards the tabs.-
556 if (ld == Qt::LeftToRightvertTabs) {
vertTabsDescription
TRUEnever evaluated
FALSEnever 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
q->layoutDirec...t::RightToLeftDescription
TRUEnever evaluated
FALSEnever evaluated
0
rightB->setGeometry
never executed: end of block
q->layoutDirec...t::RightToLeftDescription
TRUEnever evaluated
FALSEnever evaluated
if (arrows.left(), arrowsq->layoutDirection() == Qt::RightToLeft) {
never executed: end of block
q->layoutDirec...t::RightToLeftDescription
TRUEnever evaluated
FALSEnever 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-
593QRect QTabBarPrivate::normalizedScrollRect(int index)-
594{-
595 // "Normalized scroll rect" means return the free space on the tab bar-
596 // that doesn't overlap with scroll buttons or tear indicators, and-
597 // always return the rect as horizontal Qt::LeftToRight, even if the-
598 // tab bar itself is in a different orientation.-
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)) {
verticalTabs(shape)Description
TRUEnever evaluated
FALSEnever 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) {
leftButtonIsOnTopDescription
TRUEnever evaluated
FALSEnever evaluated
rightButtonIsOnTopDescription
TRUEnever evaluated
FALSEnever evaluated
0
616 topEdge = scrollButtonRightRect.bottom() + 1;-
617 bottomEdge = q->height();-
618 } else if (!leftButtonIsOnTop && !rightButtonIsOnTop) {
never executed: end of block
!leftButtonIsOnTopDescription
TRUEnever evaluated
FALSEnever evaluated
!rightButtonIsOnTopDescription
TRUEnever evaluated
FALSEnever 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;
index != 0Description
TRUEnever evaluated
FALSEnever evaluated
topEdge != -scrollOffsetDescription
TRUEnever evaluated
FALSEnever evaluated
0
627 bool tearBottomVisible = index != tabList.size() - 1 && bottomEdge != tabList.constLast().rect.bottom() + 1 - scrollOffset;
index != tabList.size() - 1Description
TRUEnever evaluated
FALSEnever evaluated
bottomEdge != ...- scrollOffsetDescription
TRUEnever evaluated
FALSEnever evaluated
0
628 if (tearTopVisible && !tearLeftRect.isNull())
tearTopVisibleDescription
TRUEnever evaluated
FALSEnever evaluated
!tearLeftRect.isNull()Description
TRUEnever evaluated
FALSEnever evaluated
0
629 topEdge = tearLeftRect.bottom() + 1;
never executed: topEdge = tearLeftRect.bottom() + 1;
0
630 if (tearBottomVisible && !tearRightRect.isNull())
tearBottomVisibleDescription
TRUEnever evaluated
FALSEnever evaluated
!tearRightRect.isNull()Description
TRUEnever evaluated
FALSEnever 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) {
q->layoutDirec...t::RightToLeftDescription
TRUEnever evaluated
FALSEnever 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) {
leftButtonIsOnLeftSideDescription
TRUEnever evaluated
FALSEnever evaluated
rightButtonIsOnLeftSideDescription
TRUEnever evaluated
FALSEnever evaluated
0
647 leftEdge = scrollButtonRightRect.right() + 1;-
648 rightEdge = q->width();-
649 } else if (!leftButtonIsOnLeftSide && !rightButtonIsOnLeftSide) {
never executed: end of block
!leftButtonIsOnLeftSideDescription
TRUEnever evaluated
FALSEnever evaluated
!rightButtonIsOnLeftSideDescription
TRUEnever evaluated
FALSEnever 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;
index != 0Description
TRUEnever evaluated
FALSEnever evaluated
leftEdge != -scrollOffsetDescription
TRUEnever evaluated
FALSEnever evaluated
0
658 bool tearRightVisible = index != tabList.size() - 1 && rightEdge != tabList.constLast().rect.right() + 1 - scrollOffset;
index != tabList.size() - 1Description
TRUEnever evaluated
FALSEnever evaluated
rightEdge != t...- scrollOffsetDescription
TRUEnever evaluated
FALSEnever evaluated
0
659 if (tearLeftVisible && !tearLeftRect.isNull())
tearLeftVisibleDescription
TRUEnever evaluated
FALSEnever evaluated
!tearLeftRect.isNull()Description
TRUEnever evaluated
FALSEnever evaluated
0
660 leftEdge = tearLeftRect.right() + 1;
never executed: leftEdge = tearLeftRect.right() + 1;
0
661 if (tearRightVisible && !tearRightRect.isNull())
tearRightVisibleDescription
TRUEnever evaluated
FALSEnever evaluated
!tearRightRect.isNull()Description
TRUEnever evaluated
FALSEnever 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-
668void QTabBarPrivate::makeVisible(int index)-
669{-
670 Q_Q(QTabBar);-
671 if (!validIndex(index) || leftB->isHidden())
!validIndex(index)Description
TRUEnever evaluated
FALSEnever evaluated
leftB->isHidden()Description
TRUEnever evaluated
FALSEnever 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();
horizDescription
TRUEnever evaluated
FALSEnever evaluated
0
678 const int starttabEnd = horiz ? tabRect.leftright() : tabRect.topbottom();
horizDescription
TRUEnever evaluated
FALSEnever evaluated
0
679 const int endlastTabEnd = horiz ? tabRecttabList.constLast().rect.right() : tabRecttabList.constLast().rect.bottom();
horizDescription
TRUEnever evaluated
FALSEnever 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) {
tabStart < scrolledTabBarStartDescription
TRUEnever evaluated
FALSEnever evaluated
0
685 // Tab is outside on the left, so scroll left.-
686 scrollOffset = starttabStart - (index ? 8 : 0);scrollRect.left();-
687 }
never executed: end of block
tabEnd > scrolledTabBarEndDescription
TRUEnever evaluated
FALSEnever evaluated
else if (endtabEnd > scrollOffset + availablescrolledTabBarEnd) {
never executed: end of block
tabEnd > scrolledTabBarEndDescription
TRUEnever evaluated
FALSEnever evaluated
0
688 // Tab is outside on the right, so scroll right.-
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) {
oldScrollOffse...= scrollOffsetDescription
TRUEnever evaluated
FALSEnever evaluated
0
696 q->update();-
697 layoutWidgets();-
698 }
never executed: end of block
0
699}
never executed: end of block
0
700-
701void QTabBarPrivate::killSwitchTabTimer()-
702{-
703 Q_Q(QTabBar);-
704 if (switchTabTimerId) {-
705 q->killTimer(switchTabTimerId);-
706 switchTabTimerId = 0;-
707 }-
708 switchTabCurrentIndex = -1;-
709}-
710-
711void 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-
747void QTabBarPrivate::layoutWidgets(int start)-
748{-
749 Q_Q(QTabBar);-
750 for (int i = start; i < q->count(); ++i) {-
751 layoutTab(i);-
752 }-
753}-
754-
755void QTabBarPrivate::autoHideTabs()-
756{-
757 Q_Q(QTabBar);-
758-
759 if (autoHide)-
760 q->setVisible(q->count() > 1);-
761}-
762-
763void 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-
786void 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) {
sender == leftBDescription
TRUEnever evaluated
FALSEnever evaluated
0
795 for (i = tabList.count() - 1; i >= 0; --i) {
i >= 0Description
TRUEnever evaluated
FALSEnever evaluated
0
796 ifint start = horizontal ? tabList.at(i).rect.left() : tabList.at(i).rect.top();
horizontalDescription
TRUEnever evaluated
FALSEnever evaluated
0
797 if (start < scrollRect
start < scroll...+ scrollOffsetDescription
TRUEnever evaluated
FALSEnever evaluated
.left() -+ scrollOffset< 0) {
start < scroll...+ scrollOffsetDescription
TRUEnever evaluated
FALSEnever 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
sender == rightBDescription
TRUEnever evaluated
FALSEnever evaluated
0
803 int availableWidth = q->width() - extraWidth();for (i = 0; i < tabList.count(); ++i) {
i < tabList.count()Description
TRUEnever evaluated
FALSEnever evaluated
0
804 if (int end = horizontal ? tabList.at(i).rect.right() - scrollOffset > availableWidth) {
horizontalDescription
TRUEnever evaluated
FALSEnever evaluated
0
makeVisible(i);
horizontalDescription
TRUEnever evaluated
FALSEnever evaluated
return;
horizontalDescription
TRUEnever evaluated
FALSEnever evaluated
}
horizontalDescription
TRUEnever evaluated
FALSEnever evaluated
}
horizontalDescription
TRUEnever evaluated
FALSEnever evaluated
}
horizontalDescription
TRUEnever evaluated
FALSEnever evaluated
} else { if (sender == leftB) {
horizontalDescription
TRUEnever evaluated
FALSEnever evaluated
for (i = tabList.count
horizontalDescription
TRUEnever evaluated
FALSEnever evaluated
() - 1; i >= 0; --i) {
horizontalDescription
TRUEnever evaluated
FALSEnever evaluated
if (
horizontalDescription
TRUEnever evaluated
FALSEnever evaluated
: tabList.at(i).rect.top() - scrollOffset < 0) {
horizontalDescription
TRUEnever evaluated
FALSEnever evaluated
makeVisible(i);
horizontalDescription
TRUEnever evaluated
FALSEnever evaluated
return;
horizontalDescription
TRUEnever evaluated
FALSEnever evaluated
}
horizontalDescription
TRUEnever evaluated
FALSEnever evaluated
}
horizontalDescription
TRUEnever evaluated
FALSEnever evaluated
} else if (sender == rightB) {
horizontalDescription
TRUEnever evaluated
FALSEnever evaluated
int available = q->height() - extraWidth();
horizontalDescription
TRUEnever evaluated
FALSEnever evaluated
for (i = 0; i < tabList
horizontalDescription
TRUEnever evaluated
FALSEnever evaluated
.countbottom();
horizontalDescription
TRUEnever evaluated
FALSEnever evaluated
805 ++i) {if (tabList.at(i).rectend > scrollRect.bottomright() -+ scrollOffset> available) {
end > scrollRe...+ scrollOffsetDescription
TRUEnever evaluated
FALSEnever 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-
813void QTabBarPrivate::refresh()-
814{-
815 Q_Q(QTabBar);-
816-
817 // be safe in case a subclass is also handling move with the tabs-
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 Creates a new tab bar with the given \a parent.-
838*/-
839QTabBar::QTabBar(QWidget* parent)-
840 :QWidget(*new QTabBarPrivate, parent, 0)-
841{-
842 Q_D(QTabBar);-
843 d->init();-
844}-
845-
846-
847/*!-
848 Destroys the tab bar.-
849*/-
850QTabBar::~QTabBar()-
851{-
852}-
853-
854/*!-
855 \property QTabBar::shape-
856 \brief the shape of the tabs in the tab bar-
857-
858 Possible values for this property are described by the Shape enum.-
859*/-
860-
861-
862QTabBar::Shape QTabBar::shape() const-
863{-
864 Q_D(const QTabBar);-
865 return d->shape;-
866}-
867-
868void 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 \property QTabBar::drawBase-
879 \brief defines whether or not tab bar should draw its base.-
880-
881 If true then QTabBar draws a base in relation to the styles overlab.-
882 Otherwise only the tabs are drawn.-
883-
884 \sa QStyle::pixelMetric(), QStyle::PM_TabBarBaseOverlap, QStyleOptionTabBarBase-
885*/-
886-
887void QTabBar::setDrawBase(bool drawBase)-
888{-
889 Q_D(QTabBar);-
890 if (d->drawBase == drawBase)-
891 return;-
892 d->drawBase = drawBase;-
893 update();-
894}-
895-
896bool QTabBar::drawBase() const-
897{-
898 Q_D(const QTabBar);-
899 return d->drawBase;-
900}-
901-
902/*!-
903 Adds a new tab with text \a text. Returns the new-
904 tab's index.-
905*/-
906int QTabBar::addTab(const QString &text)-
907{-
908 return insertTab(-1, text);-
909}-
910-
911/*!-
912 \overload-
913-
914 Adds a new tab with icon \a icon and text \a-
915 text. Returns the new tab's index.-
916*/-
917int QTabBar::addTab(const QIcon& icon, const QString &text)-
918{-
919 return insertTab(-1, icon, text);-
920}-
921-
922/*!-
923 Inserts a new tab with text \a text at position \a index. If \a-
924 index is out of range, the new tab is appened. Returns the new-
925 tab's index.-
926*/-
927int QTabBar::insertTab(int index, const QString &text)-
928{-
929 return insertTab(index, QIcon(), text);-
930}-
931-
932/*!\overload-
933-
934 Inserts a new tab with icon \a icon and text \a text at position-
935 \a index. If \a index is out of range, the new tab is-
936 appended. Returns the new tab's index.-
937-
938 If the QTabBar was empty before this function is called, the inserted tab-
939 becomes the current tab.-
940-
941 Inserting a new tab at an index less than or equal to the current index-
942 will increment the current index, but keep the current tab.-
943*/-
944int 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 Removes the tab at position \a index.-
984-
985 \sa SelectionBehavior-
986 */-
987void 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 // The current tab is going away, in order to make sure-
1018 // we emit that "current has changed", we need to reset this-
1019 // around.-
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 // else fallthrough-
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 // don't loose newIndex's old through setCurrentIndex-
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 Returns \c true if the tab at position \a index is enabled; otherwise-
1064 returns \c false.-
1065*/-
1066bool 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 If \a enabled is true then the tab at position \a index is-
1076 enabled; otherwise the item at position \a index is disabled.-
1077*/-
1078void 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 Returns the text of the tab at position \a index, or an empty-
1097 string if \a index is out of range.-
1098*/-
1099QString 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 Sets the text of the tab at position \a index to \a text.-
1109*/-
1110void 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 Returns the text color of the tab with the given \a index, or a invalid-
1127 color if \a index is out of range.-
1128-
1129 \sa setTabTextColor()-
1130*/-
1131QColor 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 Sets the color of the text in the tab with the given \a index to the specified \a color.-
1141-
1142 If an invalid color is specified, the tab will use the QTabBar foreground role instead.-
1143-
1144 \sa tabTextColor()-
1145*/-
1146void 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 Returns the icon of the tab at position \a index, or a null icon-
1157 if \a index is out of range.-
1158*/-
1159QIcon 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 Sets the icon of the tab at position \a index to \a icon.-
1169*/-
1170void 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 Sets the tool tip of the tab at position \a index to \a tip.-
1186*/-
1187void 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 Returns the tool tip of the tab at position \a index, or an empty-
1196 string if \a index is out of range.-
1197*/-
1198QString 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 \since 4.1-
1210-
1211 Sets the What's This help text of the tab at position \a index-
1212 to \a text.-
1213*/-
1214void 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 \since 4.1-
1223-
1224 Returns the What's This help text of the tab at position \a index,-
1225 or an empty string if \a index is out of range.-
1226*/-
1227QString 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 Sets the data of the tab at position \a index to \a data.-
1239*/-
1240void 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 Returns the data of the tab at position \a index, or a null-
1249 variant if \a index is out of range.-
1250*/-
1251QVariant 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 Returns the visual rectangle of the tab at position \a-
1261 index, or a null rectangle if \a index is out of range.-
1262*/-
1263QRect 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 \since 4.3-
1283 Returns the index of the tab that covers \a position or -1 if no-
1284 tab covers \a position;-
1285*/-
1286-
1287int 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 \property QTabBar::currentIndex-
1305 \brief the index of the tab bar's visible tab-
1306-
1307 The current index is -1 if there is no current tab.-
1308*/-
1309-
1310int 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-
1319void 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 \property QTabBar::iconSize-
1352 \brief The size for icons in the tab bar-
1353 \since 4.1-
1354-
1355 The default value is style-dependent. \c iconSize is a maximum-
1356 size; icons that are smaller are not scaled up.-
1357-
1358 \sa QTabWidget::iconSize-
1359*/-
1360QSize 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-
1370void 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 \property QTabBar::count-
1381 \brief the number of tabs in the tab bar-
1382*/-
1383-
1384int QTabBar::count() const-
1385{-
1386 Q_D(const QTabBar);-
1387 return d->tabList.count();-
1388}-
1389-
1390-
1391/*!\reimp-
1392 */-
1393QSize 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/*!\reimp-
1406 */-
1407QSize 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// Compute the most-elided possible text, for minimumSizeHint-
1425static QString computeElidedText(Qt::TextElideMode mode, const QString &text)-
1426{-
1427 if (text.length() <= 3)
text.length() <= 3Description
TRUEnever evaluated
FALSEnever 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 Returns the minimum tab size hint for the tab at position \a index.-
1451 \since Qt 5.0-
1452*/-
1453-
1454QSize 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 Returns the size hint for the tab at position \a index.-
1467*/-
1468QSize QTabBar::tabSizeHint(int index) const-
1469{-
1470 //Note: this must match with the computations in QCommonStylePrivate::tabLayout-
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 This virtual handler is called after a new tab was added or-
1521 inserted at position \a index.-
1522-
1523 \sa tabRemoved()-
1524 */-
1525void QTabBar::tabInserted(int index)-
1526{-
1527 Q_UNUSED(index)-
1528}-
1529-
1530/*!-
1531 This virtual handler is called after a tab was removed from-
1532 position \a index.-
1533-
1534 \sa tabInserted()-
1535 */-
1536void QTabBar::tabRemoved(int index)-
1537{-
1538 Q_UNUSED(index)-
1539}-
1540-
1541/*!-
1542 This virtual handler is called whenever the tab layout changes.-
1543-
1544 \sa tabRect()-
1545 */-
1546void QTabBar::tabLayoutChange()-
1547{-
1548}-
1549-
1550-
1551/*!\reimp-
1552 */-
1553void 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/*!\reimp-
1564 */-
1565void QTabBar::hideEvent(QHideEvent *)-
1566{-
1567 Q_D(QTabBar);-
1568 d->updateMacBorderMetrics();-
1569}-
1570-
1571/*!\reimp-
1572 */-
1573bool 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) { // ### fixme Qt 6: move to mouseDoubleClickEvent(), here for BC reasons.-
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/*!\reimp-
1667 */-
1668void 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/*!\reimp-
1679 */-
1680void 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)
d->dragInProgressDescription
TRUEnever evaluated
FALSEnever 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)
i < d->tabList.count()Description
TRUEnever evaluated
FALSEnever 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)
d->drawBaseDescription
TRUEnever evaluated
FALSEnever 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) {
i < d->tabList.count()Description
TRUEnever evaluated
FALSEnever evaluated
0
1708 QStyleOptionTab tab;-
1709 initStyleOption(&tab, i);-
1710 if (d->paintWithOffsets && d->tabList[i].dragOffset != 0) {
d->paintWithOffsetsDescription
TRUEnever evaluated
FALSEnever evaluated
d->tabList[i].dragOffset != 0Description
TRUEnever evaluated
FALSEnever evaluated
0
1711 if (vertical) {
verticalDescription
TRUEnever evaluated
FALSEnever 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)) {
!(tab.state & ...State_Enabled)Description
TRUEnever evaluated
FALSEnever evaluated
0
1718 tab.palette.setCurrentColorGroup(QPalette::Disabled);-
1719 }
never executed: end of block
0
1720-
1721 // If this tab is partially obscured, make a note of it so that we can pass the information-
1722 // along when we draw the tear.-
1723 if (((!QRect tabRect = d->tabList[i].rect;-
1724 int tabStart =
verticalDescription
TRUEnever evaluated
FALSEnever evaluated
vertical && (!rtl && tab? tabRect.recttop() : tabRect.left() < 0)) || (rtl && tab();
verticalDescription
TRUEnever evaluated
FALSEnever evaluated
0
1725 int tabEnd = vertical ? tabRect
verticalDescription
TRUEnever evaluated
FALSEnever evaluated
.rectbottom() : tabRect.right() > width()))
verticalDescription
TRUEnever evaluated
FALSEnever evaluated
0
||
verticalDescription
TRUEnever evaluated
FALSEnever evaluated
();
verticalDescription
TRUEnever evaluated
FALSEnever evaluated
1726 if
tabStart < scr...->scrollOffsetDescription
TRUEnever evaluated
FALSEnever evaluated
(vertical && tabtabStart < scrollRect.rectleft() + d->scrollOffset) {
tabStart < scr...->scrollOffsetDescription
TRUEnever evaluated
FALSEnever evaluated
0
1727 cutLeft = i;-
1728 cutTabLeft = tab;-
1729 } else if (tabEnd > scrollRect
never executed: end of block
tabEnd > scrol...->scrollOffsetDescription
TRUEnever evaluated
FALSEnever evaluated
.topright() < 0))+ d->scrollOffset) {
never executed: end of block
tabEnd > scrol...->scrollOffsetDescription
TRUEnever evaluated
FALSEnever evaluated
0
1730 cutcutRight = i;-
1731 cutTabcutTabRight = tab;-
1732 }
never executed: end of block
0
1733-
1734 // Don't bother drawing a tab if the entire tab is outside of the visible tab bar.-
1735 if ((!vertical && (tab.rect.right() < 0 || tab.rect.left() > width()))
!verticalDescription
TRUEnever evaluated
FALSEnever evaluated
tab.rect.right() < 0Description
TRUEnever evaluated
FALSEnever evaluated
tab.rect.left() > width()Description
TRUEnever evaluated
FALSEnever evaluated
0
1736 || (vertical && (tab.rect.bottom() < 0 || tab.rect.top() > height())))
verticalDescription
TRUEnever evaluated
FALSEnever evaluated
tab.rect.bottom() < 0Description
TRUEnever evaluated
FALSEnever evaluated
tab.rect.top() > height()Description
TRUEnever evaluated
FALSEnever evaluated
0
1737 continue;
never executed: continue;
0
1738-
1739 optTabBase.tabBarRect |= tab.rect;-
1740 if (i == selected)
i == selectedDescription
TRUEnever evaluated
FALSEnever 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 // Draw the selected tab last to get it "on top"-
1747 if (selected >= 0) {
selected >= 0Description
TRUEnever evaluated
FALSEnever evaluated
0
1748 QStyleOptionTab tab;-
1749 initStyleOption(&tab, selected);-
1750 if (d->paintWithOffsets && d->tabList[selected].dragOffset != 0) {
d->paintWithOffsetsDescription
TRUEnever evaluated
FALSEnever evaluated
d->tabList[sel...ragOffset != 0Description
TRUEnever evaluated
FALSEnever evaluated
0
1751 if (vertical)
verticalDescription
TRUEnever evaluated
FALSEnever 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)
!d->dragInProgressDescription
TRUEnever evaluated
FALSEnever 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 // Only draw the tear indicator if necessary. Most of the time we don't need too.-
1765 if (d->leftB->isVisible() && cutcutLeft >= 0) {
d->leftB->isVisible()Description
TRUEnever evaluated
FALSEnever evaluated
cutLeft >= 0Description
TRUEnever evaluated
FALSEnever 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) {
d->rightB->isVisible()Description
TRUEnever evaluated
FALSEnever evaluated
cutRight >= 0Description
TRUEnever evaluated
FALSEnever 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 Given that index at position from moved to position to where return where index goes.-
1780 */-
1781int 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 Moves the item at index position \a from to index position \a to.-
1795 \since 4.5-
1796-
1797 \sa tabMoved(), tabLayoutChange()-
1798 */-
1799void 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 // Record the position of the pressed tab before reordering the tabs.-
1811 oldPressedPosition = vertical ? d->tabList[d->pressedIndex].rect.y()-
1812 : d->tabList[d->pressedIndex].rect.x();-
1813 }-
1814-
1815 // Update the locations of the tabs first-
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 // Move the actual data structures-
1849 d->tabList.move(from, to);-
1850-
1851 // update lastTab locations-
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 // update external variables-
1856 int previousIndex = d->currentIndex;-
1857 d->currentIndex = d->calculateNewPosition(from, to, d->currentIndex);-
1858-
1859 // If we are in the middle of a drag update the dragStartPosition-
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-
1880void 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-
1898void QTabBarPrivate::moveTab(int index, int offset)-
1899{-
1900 if (!validIndex(index))-
1901 return;-
1902 tabList[index].dragOffset = offset;-
1903 layoutTab(index); // Make buttons follow tab-
1904 q_func()->update();-
1905}-
1906-
1907/*!\reimp-
1908*/-
1909void 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 // Be safe!-
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/*!\reimp-
1948 */-
1949void QTabBar::mouseMoveEvent(QMouseEvent *event)-
1950{-
1951 Q_D(QTabBar);-
1952 if (d->movable) {
d->movableDescription
TRUEnever evaluated
FALSEnever evaluated
0
1953 // Be safe!-
1954 if (d->pressedIndex != -1
d->pressedIndex != -1Description
TRUEnever evaluated
FALSEnever evaluated
0
1955 && event->buttons() == Qt::NoButton)
event->buttons...= Qt::NoButtonDescription
TRUEnever evaluated
FALSEnever evaluated
0
1956 d->moveTabFinished(d->pressedIndex);
never executed: d->moveTabFinished(d->pressedIndex);
0
1957-
1958 // Start drag-
1959 if (!d->dragInProgress && d->pressedIndex != -1) {
!d->dragInProgressDescription
TRUEnever evaluated
FALSEnever evaluated
d->pressedIndex != -1Description
TRUEnever evaluated
FALSEnever evaluated
0
1960 if ((event->pos() - d->dragStartPosition).manhattanLength() > QApplication::startDragDistance()) {
(event->pos() ...DragDistance()Description
TRUEnever evaluated
FALSEnever 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
event->buttons...Qt::LeftButtonDescription
TRUEnever evaluated
FALSEnever evaluated
0
1967 && d->dragInProgress
d->dragInProgressDescription
TRUEnever evaluated
FALSEnever evaluated
0
1968 && d->validIndex(d->pressedIndex)) {
d->validIndex(d->pressedIndex)Description
TRUEnever evaluated
FALSEnever evaluated
0
1969 bool vertical = verticalTabs(d->shape);-
1970 int dragDistance;-
1971 if (vertical) {
verticalDescription
TRUEnever evaluated
FALSEnever 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)
verticalDescription
TRUEnever evaluated
FALSEnever 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)
dragDistance < 0Description
TRUEnever evaluated
FALSEnever 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) {
overIndex != d->pressedIndexDescription
TRUEnever evaluated
FALSEnever evaluated
overIndex != -1Description
TRUEnever evaluated
FALSEnever evaluated
0
1991 int offset = 1;-
1992 if (isRightToLeft() && !vertical)
isRightToLeft()Description
TRUEnever evaluated
FALSEnever evaluated
!verticalDescription
TRUEnever evaluated
FALSEnever evaluated
0
1993 offset *= -1;
never executed: offset *= -1;
0
1994 if (dragDistance < 0) {
dragDistance < 0Description
TRUEnever evaluated
FALSEnever 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;
offset > 0 ? i... i > overIndexDescription
TRUEnever evaluated
FALSEnever evaluated
offset > 0Description
TRUEnever evaluated
FALSEnever evaluated
0
2000 i += offset) {-
2001 QRect overIndexRect = tabRect(overIndex);-
2002 int needsToBeOver = (vertical ? overIndexRect.height() : overIndexRect.width()) / 2;
verticalDescription
TRUEnever evaluated
FALSEnever evaluated
0
2003 if (dragDistance > needsToBeOver)
dragDistance > needsToBeOverDescription
TRUEnever evaluated
FALSEnever 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 // Buttons needs to follow the dragged tab-
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) {
event->buttons...Qt::LeftButtonDescription
TRUEnever evaluated
FALSEnever 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-
2031void 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 // Re-arrange widget order to avoid overlaps-
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-
2069void 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); // We might not get a mouse release-
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/*!\reimp-
2102*/-
2103void 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/*!\reimp-
2136 */-
2137void 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/*!\reimp-
2149 */-
2150#ifndef QT_NO_WHEELEVENT-
2151void 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-
2164void 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/*!\reimp-
2176 */-
2177void 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 // fallthrough-
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 \reimp-
2200*/-
2201void 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 \property QTabBar::elideMode-
2215 \brief how to elide text in the tab bar-
2216 \since 4.2-
2217-
2218 This property controls how items are elided when there is not-
2219 enough space to show them for a given tab bar size.-
2220-
2221 By default the value is style dependent.-
2222-
2223 \sa QTabWidget::elideMode, usesScrollButtons, QStyle::SH_TabBar_ElideMode-
2224*/-
2225-
2226Qt::TextElideMode QTabBar::elideMode() const-
2227{-
2228 Q_D(const QTabBar);-
2229 return d->elideMode;-
2230}-
2231-
2232void 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 \property QTabBar::usesScrollButtons-
2243 \brief Whether or not a tab bar should use buttons to scroll tabs when it-
2244 has many tabs.-
2245 \since 4.2-
2246-
2247 When there are too many tabs in a tab bar for its size, the tab bar can either choose-
2248 to expand its size or to add buttons that allow you to scroll through the tabs.-
2249-
2250 By default the value is style dependant.-
2251-
2252 \sa elideMode, QTabWidget::usesScrollButtons, QStyle::SH_TabBar_PreferNoArrows-
2253*/-
2254bool QTabBar::usesScrollButtons() const-
2255{-
2256 return d_func()->useScrollButtons;-
2257}-
2258-
2259void 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 \property QTabBar::tabsClosable-
2271 \brief Whether or not a tab bar should place close buttons on each tab-
2272 \since 4.5-
2273-
2274 When tabsClosable is set to true a close button will appear on the tab on-
2275 either the left or right hand side depending upon the style. When the button-
2276 is clicked the tab the signal tabCloseRequested will be emitted.-
2277-
2278 By default the value is false.-
2279-
2280 \sa setTabButton(), tabRemoved()-
2281*/-
2282-
2283bool QTabBar::tabsClosable() const-
2284{-
2285 Q_D(const QTabBar);-
2286 return d->closeButtonOnTabs;-
2287}-
2288-
2289void 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 \enum QTabBar::ButtonPosition-
2325 \since 4.5-
2326-
2327 This enum type lists the location of the widget on a tab.-
2328-
2329 \value LeftSide Left side of the tab.-
2330-
2331 \value RightSide Right side of the tab.-
2332-
2333*/-
2334-
2335/*!-
2336 \enum QTabBar::SelectionBehavior-
2337 \since 4.5-
2338-
2339 This enum type lists the behavior of QTabBar when a tab is removed-
2340 and the tab being removed is also the current tab.-
2341-
2342 \value SelectLeftTab Select the tab to the left of the one being removed.-
2343-
2344 \value SelectRightTab Select the tab to the right of the one being removed.-
2345-
2346 \value SelectPreviousTab Select the previously selected tab.-
2347-
2348*/-
2349-
2350/*!-
2351 \property QTabBar::selectionBehaviorOnRemove-
2352 \brief What tab should be set as current when removeTab is called if-
2353 the removed tab is also the current tab.-
2354 \since 4.5-
2355-
2356 By default the value is SelectRightTab.-
2357-
2358 \sa removeTab()-
2359*/-
2360-
2361-
2362QTabBar::SelectionBehavior QTabBar::selectionBehaviorOnRemove() const-
2363{-
2364 Q_D(const QTabBar);-
2365 return d->selectionBehaviorOnRemove;-
2366}-
2367-
2368void QTabBar::setSelectionBehaviorOnRemove(QTabBar::SelectionBehavior behavior)-
2369{-
2370 Q_D(QTabBar);-
2371 d->selectionBehaviorOnRemove = behavior;-
2372}-
2373-
2374/*!-
2375 \property QTabBar::expanding-
2376 \brief When expanding is true QTabBar will expand the tabs to use the empty space.-
2377 \since 4.5-
2378-
2379 By default the value is true.-
2380-
2381 \sa QTabWidget::documentMode-
2382*/-
2383-
2384bool QTabBar::expanding() const-
2385{-
2386 Q_D(const QTabBar);-
2387 return d->expanding;-
2388}-
2389-
2390void 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 \property QTabBar::movable-
2401 \brief This property holds whether the user can move the tabs-
2402 within the tabbar area.-
2403-
2404 \since 4.5-
2405-
2406 By default, this property is \c false;-
2407*/-
2408-
2409bool QTabBar::isMovable() const-
2410{-
2411 Q_D(const QTabBar);-
2412 return d->movable;-
2413}-
2414-
2415void QTabBar::setMovable(bool movable)-
2416{-
2417 Q_D(QTabBar);-
2418 d->movable = movable;-
2419}-
2420-
2421-
2422/*!-
2423 \property QTabBar::documentMode-
2424 \brief Whether or not the tab bar is rendered in a mode suitable for the main window.-
2425 \since 4.5-
2426-
2427 This property is used as a hint for styles to draw the tabs in a different-
2428 way then they would normally look in a tab widget. On \macos this will-
2429 look similar to the tabs in Safari or Leopard's Terminal.app.-
2430-
2431 \sa QTabWidget::documentMode-
2432*/-
2433bool QTabBar::documentMode() const-
2434{-
2435 return d_func()->documentMode;-
2436}-
2437-
2438void QTabBar::setDocumentMode(bool enabled)-
2439{-
2440 Q_D(QTabBar);-
2441-
2442 d->documentMode = enabled;-
2443 d->updateMacBorderMetrics();-
2444}-
2445-
2446/*!-
2447 \property QTabBar::autoHide-
2448 \brief If true, the tab bar is automatically hidden when it contains less-
2449 than 2 tabs.-
2450 \since 5.4-
2451-
2452 By default, this property is false.-
2453-
2454 \sa QWidget::visible-
2455*/-
2456-
2457bool QTabBar::autoHide() const-
2458{-
2459 Q_D(const QTabBar);-
2460 return d->autoHide;-
2461}-
2462-
2463void 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 \property QTabBar::changeCurrentOnDrag-
2478 \brief If true, then the current tab is automatically changed when dragging-
2479 over the tabbar.-
2480 \since 5.4-
2481-
2482 \note You should also set acceptDrops property to true to make this feature-
2483 work.-
2484-
2485 By default, this property is false.-
2486*/-
2487-
2488bool QTabBar::changeCurrentOnDrag() const-
2489{-
2490 Q_D(const QTabBar);-
2491 return d->changeCurrentOnDrag;-
2492}-
2493-
2494void QTabBar::setChangeCurrentOnDrag(bool change)-
2495{-
2496 Q_D(QTabBar);-
2497 d->changeCurrentOnDrag = change;-
2498 if (!change)-
2499 d->killSwitchTabTimer();-
2500}-
2501-
2502/*!-
2503 Sets \a widget on the tab \a index. The widget is placed-
2504 on the left or right hand side depending upon the \a position.-
2505 \since 4.5-
2506-
2507 Any previously set widget in \a position is hidden.-
2508-
2509 The tab bar will take ownership of the widget and so all widgets set here-
2510 will be deleted by the tab bar when it is destroyed unless you separately-
2511 reparent the widget after setting some other widget (or 0).-
2512-
2513 \sa tabsClosable()-
2514 */-
2515void 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 // make sure our left and right widgets stay on top-
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 Returns the widget set a tab \a index and \a position or 0 if-
2542 one is not set.-
2543 */-
2544QWidget *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-
2555CloseButton::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-
2568QSize 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-
2576void CloseButton::enterEvent(QEvent *event)-
2577{-
2578 if (isEnabled())-
2579 update();-
2580 QAbstractButton::enterEvent(event);-
2581}-
2582-
2583void CloseButton::leaveEvent(QEvent *event)-
2584{-
2585 if (isEnabled())-
2586 update();-
2587 QAbstractButton::leaveEvent(event);-
2588}-
2589-
2590void 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-
2614void QTabBarPrivate::Tab::TabBarAnimation::updateCurrentValue(const QVariant &current)-
2615{-
2616 priv->moveTab(priv->tabList.indexOf(*tab), current.toInt());-
2617}-
2618-
2619void QTabBarPrivate::Tab::TabBarAnimation::updateState(QAbstractAnimation::State, QAbstractAnimation::State newState)-
2620{-
2621 if (newState == Stopped) priv->moveTabFinished(priv->tabList.indexOf(*tab));-
2622}-
2623#endif-
2624-
2625QT_END_NAMESPACE-
2626-
2627#include "moc_qtabbar.cpp"-
2628-
2629#endif // QT_NO_TABBAR-
2630-
2631#include "moc_qtabbar_p.cpp"-
Source codeSwitch to Preprocessed file

Generated by Squish Coco Non-Commercial 4.3.0-BETA-master-30-08-2018-4cb69e9