From e4c39d5e1e7ee8c2bba273e6d613ec519b7fa9c2 Mon Sep 17 00:00:00 2001 From: Gabriel de Dietrich Date: Fri, 30 Jun 2017 11:28:23 -0700 Subject: QMacStyle: Bring back always visible close button in non-document QTabBar MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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ø --- src/widgets/styles/qmacstyle_mac.mm | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) (limited to 'src') 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(w->parentWidget())) { + const bool documentMode = tabBar->documentMode(); const QTabBarPrivate *tabBarPrivate = static_cast(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; -- cgit v1.2.3