From 7d3c5c9b6c0ea8330462cd7999c370db764649a5 Mon Sep 17 00:00:00 2001 From: Jan Blackquill Date: Tue, 2 Feb 2021 16:53:24 -0500 Subject: [PATCH] [kstyle]: Give active document tabs a thick highlight BUG: 356037 --- kstyle/breezehelper.cpp | 23 +++++++++++++++++++++-- kstyle/breezehelper.h | 5 ++++- kstyle/breezestyle.cpp | 13 +++++++++++-- 3 files changed, 36 insertions(+), 5 deletions(-) diff --git a/kstyle/breezehelper.cpp b/kstyle/breezehelper.cpp index 2ae186e5..3b53f7b4 100644 --- a/kstyle/breezehelper.cpp +++ b/kstyle/breezehelper.cpp @@ -1294,8 +1294,11 @@ namespace Breeze } //______________________________________________________________________________ - void Helper::renderTabBarTab( QPainter* painter, const QRect& rect, const QColor& color, const QColor& outline, Corners corners ) const - { + void Helper::renderTabBarTab(QPainter *painter, const QRect &rect, + const QColor &color, const QColor &highlight, + const QColor &outline, Corners corners, + bool document, bool bottom) const { + // setup painter painter->setRenderHint( QPainter::Antialiasing, true ); @@ -1322,6 +1325,22 @@ namespace Breeze QPainterPath path( roundedPath( frameRect, corners, radius ) ); painter->drawPath( path ); + if (highlight.isValid() && document) { + auto rect = frameRect; + rect.setHeight(2); + if (bottom) { + rect.setTop(frameRect.bottom()-2); + rect.setBottom(frameRect.bottom()); + } + + QPainterPath rectAsPath; + rectAsPath.addRect(rect); + + painter->setClipPath(path.intersected(rectAsPath)); + painter->setBrush(highlight); + painter->drawRect(frameRect); + } + } //______________________________________________________________________________ diff --git a/kstyle/breezehelper.h b/kstyle/breezehelper.h index a2728482..dedf4a90 100644 --- a/kstyle/breezehelper.h +++ b/kstyle/breezehelper.h @@ -240,7 +240,10 @@ namespace Breeze void renderScrollBarBorder( QPainter*, const QRect&, const QColor& ) const; //* tabbar tab - void renderTabBarTab( QPainter*, const QRect&, const QColor& color, const QColor& outline, Corners ) const; + void renderTabBarTab( QPainter*, const QRect&, const QColor& color, const QColor& highlight, const QColor& outline, Corners, bool document, bool bottom ) const; + // TODO(janet): document should be set based on whether or not we consider the + // tab user-editable, but Qt apps often misuse or don't use documentMode property + // so we're currently just always setting it to true for now //* generic arrow void renderArrow( QPainter*, const QRect&, const QColor&, ArrowOrientation ) const; diff --git a/kstyle/breezestyle.cpp b/kstyle/breezestyle.cpp index 91a645e2..bde64c24 100644 --- a/kstyle/breezestyle.cpp +++ b/kstyle/breezestyle.cpp @@ -5707,6 +5707,8 @@ namespace Breeze // for QtQuickControls, ovelap is already accounted of in the option. Unlike in the qwidget case const int overlap( isQtQuickControl ? 0:Metrics::TabBar_TabOverlap ); + bool bottom = false; + // adjust rect and define corners based on tabbar orientation Corners corners; switch( tabOption->shape ) @@ -5738,6 +5740,7 @@ namespace Breeze corners = CornerBottomLeft|CornerBottomRight; rect.adjust( 0, - 1, 0, 0 ); + bottom = true; } else { @@ -5820,18 +5823,24 @@ namespace Breeze // outline const auto outline( selected ? _helper->alphaColor( palette.color( QPalette::WindowText ), 0.25 ) : QColor() ); + QColor accent; + if ( selected ) + { + accent = palette.color( QPalette::Active, QPalette::Highlight ); + } + // render if( selected ) { QRegion oldRegion( painter->clipRegion() ); painter->setClipRect( option->rect, Qt::IntersectClip ); - _helper->renderTabBarTab( painter, rect, color, outline, corners ); + _helper->renderTabBarTab( painter, rect, color, accent, outline, corners, true, bottom ); painter->setClipRegion( oldRegion ); } else { - _helper->renderTabBarTab( painter, rect, color, outline, corners ); + _helper->renderTabBarTab( painter, rect, color, accent, outline, corners, true, bottom ); }