summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorGabriel de Dietrich <gabriel.dedietrich@qt.io>2017-06-30 11:28:23 -0700
committerGabriel de Dietrich <gabriel.dedietrich@qt.io>2017-07-06 00:58:27 +0000
commite4c39d5e1e7ee8c2bba273e6d613ec519b7fa9c2 (patch)
treef6b85c30fde88a2f8a53edc3f54f5b5a19af224f /src
parent462d26f265d516fc77ff28f975e4801722c6b703 (diff)
QMacStyle: Bring back always visible close button in non-document QTabBar
This case is not supported by the Mac HIG, so we need to improvise some colors that look better than those used in document mode. Change-Id: I9858be468680303fdf65e17aa10ca1f90718b236 Task-number: QTBUG-61092 Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
Diffstat (limited to 'src')
-rw-r--r--src/widgets/styles/qmacstyle_mac.mm20
1 files changed, 14 insertions, 6 deletions
diff --git a/src/widgets/styles/qmacstyle_mac.mm b/src/widgets/styles/qmacstyle_mac.mm
index 978810572b..906bc85fa6 100644
--- a/src/widgets/styles/qmacstyle_mac.mm
+++ b/src/widgets/styles/qmacstyle_mac.mm
@@ -242,7 +242,7 @@ static bool isInMacUnifiedToolbarArea(QWindow *window, int windowY)
}
-void drawTabCloseButton(QPainter *p, bool hover, bool selected, bool pressed)
+static void drawTabCloseButton(QPainter *p, bool hover, bool selected, bool pressed, bool documentMode)
{
p->setRenderHints(QPainter::Antialiasing);
QRect rect(0, 0, closeButtonSize, closeButtonSize);
@@ -253,10 +253,16 @@ void drawTabCloseButton(QPainter *p, bool hover, bool selected, bool pressed)
// draw background circle
QColor background;
if (selected) {
- background = pressed ? tabBarCloseButtonBackgroundSelectedPressed : tabBarCloseButtonBackgroundSelectedHovered;
+ if (documentMode)
+ background = pressed ? tabBarCloseButtonBackgroundSelectedPressed : tabBarCloseButtonBackgroundSelectedHovered;
+ else
+ background = QColor(255, 255, 255, pressed ? 150 : 100); // Translucent white
} else {
background = pressed ? tabBarCloseButtonBackgroundPressed : tabBarCloseButtonBackgroundHovered;
+ if (!documentMode)
+ background = background.lighter(pressed ? 135 : 140); // Lighter tab background, lighter color
}
+
p->setPen(Qt::transparent);
p->setBrush(background);
p->drawRoundedRect(rect, closeButtonCornerRadius, closeButtonCornerRadius);
@@ -265,7 +271,7 @@ void drawTabCloseButton(QPainter *p, bool hover, bool selected, bool pressed)
// draw cross
const int margin = 3;
QPen crossPen;
- crossPen.setColor(selected ? tabBarCloseButtonCrossSelected : tabBarCloseButtonCross);
+ crossPen.setColor(selected ? (documentMode ? tabBarCloseButtonCrossSelected : Qt::white) : tabBarCloseButtonCross);
crossPen.setWidthF(1.1);
crossPen.setCapStyle(Qt::FlatCap);
p->setPen(crossPen);
@@ -3551,14 +3557,16 @@ void QMacStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, QPai
case PE_IndicatorTabClose: {
// Make close button visible only on the hovered tab.
if (QTabBar *tabBar = qobject_cast<QTabBar*>(w->parentWidget())) {
+ const bool documentMode = tabBar->documentMode();
const QTabBarPrivate *tabBarPrivate = static_cast<QTabBarPrivate *>(QObjectPrivate::get(tabBar));
const int hoveredTabIndex = tabBarPrivate->hoveredTabIndex();
- if (hoveredTabIndex != -1 && ((w == tabBar->tabButton(hoveredTabIndex, QTabBar::LeftSide)) ||
- (w == tabBar->tabButton(hoveredTabIndex, QTabBar::RightSide)))) {
+ if (!documentMode ||
+ (hoveredTabIndex != -1 && ((w == tabBar->tabButton(hoveredTabIndex, QTabBar::LeftSide)) ||
+ (w == tabBar->tabButton(hoveredTabIndex, QTabBar::RightSide))))) {
const bool hover = (opt->state & State_MouseOver);
const bool selected = (opt->state & State_Selected);
const bool pressed = (opt->state & State_Sunken);
- drawTabCloseButton(p, hover, selected, pressed);
+ drawTabCloseButton(p, hover, selected, pressed, documentMode);
}
}
} break;