summaryrefslogtreecommitdiffstats
path: root/src/widgets/widgets/qtabbar.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/widgets/widgets/qtabbar.cpp')
-rw-r--r--src/widgets/widgets/qtabbar.cpp63
1 files changed, 51 insertions, 12 deletions
diff --git a/src/widgets/widgets/qtabbar.cpp b/src/widgets/widgets/qtabbar.cpp
index 35d9498413..eeece1a42a 100644
--- a/src/widgets/widgets/qtabbar.cpp
+++ b/src/widgets/widgets/qtabbar.cpp
@@ -177,8 +177,7 @@ void QTabBarPrivate::initBasicStyleOption(QStyleOptionTab *option, int tabIndex)
if (tab.textColor.isValid())
option->palette.setColor(q->foregroundRole(), tab.textColor);
#ifdef Q_OS_MACOS
- else if (isCurrent && !documentMode
- && (QSysInfo::MacintoshVersion < QSysInfo::MV_10_10 || q->isActiveWindow())) {
+ else if (isCurrent && !documentMode && q->isActiveWindow()) {
option->palette.setColor(QPalette::WindowText, Qt::white);
}
#endif
@@ -520,12 +519,14 @@ void QTabBarPrivate::layoutTabs()
maxExtent = maxWidth;
}
+ if (!expanding) {
+ // Mirror our front item.
+ tabChain[tabChainIndex].init();
+ tabChain[tabChainIndex].expansive = (tabAlignment != Qt::AlignRight)
+ && (tabAlignment != Qt::AlignJustify);
+ tabChain[tabChainIndex].empty = true;
+ }
Q_ASSERT(tabChainIndex == tabChain.count() - 1); // add an assert just to make sure.
- // Mirror our front item.
- tabChain[tabChainIndex].init();
- tabChain[tabChainIndex].expansive = (tabAlignment != Qt::AlignRight)
- && (tabAlignment != Qt::AlignJustify);
- tabChain[tabChainIndex].empty = true;
// Do the calculation
qGeomCalc(tabChain, 0, tabChain.count(), 0, qMax(available, last), 0);
@@ -665,6 +666,15 @@ QRect QTabBarPrivate::normalizedScrollRect(int index)
}
}
+int QTabBarPrivate::hoveredTabIndex() const
+{
+ if (dragInProgress)
+ return currentIndex;
+ if (hoverIndex >= 0)
+ return hoverIndex;
+ return -1;
+}
+
void QTabBarPrivate::makeVisible(int index)
{
Q_Q(QTabBar);
@@ -1054,6 +1064,17 @@ void QTabBar::removeTab(int index)
}
d->refresh();
d->autoHideTabs();
+ if (!d->hoverRect.isEmpty()) {
+ for (int i = 0; i < d->tabList.count(); ++i) {
+ const QRect area = tabRect(i);
+ if (area.contains(mapFromGlobal(QCursor::pos()))) {
+ d->hoverIndex = i;
+ d->hoverRect = area;
+ break;
+ }
+ }
+ update(d->hoverRect);
+ }
tabRemoved(index);
}
}
@@ -1578,20 +1599,28 @@ bool QTabBar::event(QEvent *event)
QHoverEvent *he = static_cast<QHoverEvent *>(event);
if (!d->hoverRect.contains(he->pos())) {
QRect oldHoverRect = d->hoverRect;
+ bool cursorOverTabs = false;
for (int i = 0; i < d->tabList.count(); ++i) {
QRect area = tabRect(i);
if (area.contains(he->pos())) {
+ d->hoverIndex = i;
d->hoverRect = area;
+ cursorOverTabs = true;
break;
}
}
+ if (!cursorOverTabs) {
+ d->hoverIndex = -1;
+ d->hoverRect = QRect();
+ }
if (he->oldPos() != QPoint(-1, -1))
update(oldHoverRect);
update(d->hoverRect);
}
return true;
- } else if (event->type() == QEvent::HoverLeave ) {
+ } else if (event->type() == QEvent::HoverLeave) {
QRect oldHoverRect = d->hoverRect;
+ d->hoverIndex = -1;
d->hoverRect = QRect();
update(oldHoverRect);
return true;
@@ -1757,7 +1786,10 @@ void QTabBar::paintEvent(QPaintEvent *)
p.drawControl(QStyle::CE_TabBarTab, tab);
else {
int taboverlap = style()->pixelMetric(QStyle::PM_TabBarTabOverlap, 0, this);
- d->movingTab->setGeometry(tab.rect.adjusted(-taboverlap, 0, taboverlap, 0));
+ if (verticalTabs(d->shape))
+ d->movingTab->setGeometry(tab.rect.adjusted(0, -taboverlap, 0, taboverlap));
+ else
+ d->movingTab->setGeometry(tab.rect.adjusted(-taboverlap, 0, taboverlap, 0));
}
}
@@ -2036,7 +2068,10 @@ void QTabBarPrivate::setupMovableTab()
int taboverlap = q->style()->pixelMetric(QStyle::PM_TabBarTabOverlap, 0 ,q);
QRect grabRect = q->tabRect(pressedIndex);
- grabRect.adjust(-taboverlap, 0, taboverlap, 0);
+ if (verticalTabs(shape))
+ grabRect.adjust(0, -taboverlap, 0, taboverlap);
+ else
+ grabRect.adjust(-taboverlap, 0, taboverlap, 0);
QPixmap grabImage(grabRect.size() * q->devicePixelRatioF());
grabImage.setDevicePixelRatio(q->devicePixelRatioF());
@@ -2046,7 +2081,11 @@ void QTabBarPrivate::setupMovableTab()
QStyleOptionTab tab;
q->initStyleOption(&tab, pressedIndex);
- tab.rect.moveTopLeft(QPoint(taboverlap, 0));
+ tab.position = QStyleOptionTab::OnlyOneTab;
+ if (verticalTabs(shape))
+ tab.rect.moveTopLeft(QPoint(0, taboverlap));
+ else
+ tab.rect.moveTopLeft(QPoint(taboverlap, 0));
p.drawControl(QStyle::CE_TabBarTab, tab);
p.end();
@@ -2426,7 +2465,7 @@ void QTabBar::setMovable(bool movable)
This property is used as a hint for styles to draw the tabs in a different
way then they would normally look in a tab widget. On \macos this will
- look similar to the tabs in Safari or Leopard's Terminal.app.
+ look similar to the tabs in Safari or Sierra's Terminal.app.
\sa QTabWidget::documentMode
*/