Skip to content

Commit 71374bb

Browse files
committedJul 2, 2019
Make indicator backgrounds a bit more subtle
The default color was very visually dominant on some platforms/themes, so pull it back a couple of shades closer to the background color
1 parent 03e8f87 commit 71374bb

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed
 

‎src/gui/layertree/qgslayertreeviewitemdelegate.cpp

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,15 @@ void QgsLayerTreeViewItemDelegate::paint( QPainter *painter, const QStyleOptionV
8989
QBrush pb = painter->brush();
9090
QPen pp = painter->pen();
9191
painter->setPen( QPen( Qt::NoPen ) );
92-
painter->setBrush( QBrush( opt.palette.mid() ) );
92+
QBrush b = QBrush( opt.palette.mid() );
93+
QColor bc = b.color();
94+
// mix mid color with base color for a less dominant, yet still opaque, version of the color
95+
const QColor baseColor = opt.palette.base().color();
96+
bc.setRed( static_cast< int >( bc.red() * 0.3 + baseColor.red() * 0.7 ) );
97+
bc.setGreen( static_cast< int >( bc.green() * 0.3 + baseColor.green() * 0.7 ) );
98+
bc.setBlue( static_cast< int >( bc.blue() * 0.3 + baseColor.blue() * 0.7 ) );
99+
b.setColor( bc );
100+
painter->setBrush( b );
93101
painter->drawRect( mRect );
94102
painter->setBrush( pb );
95103
painter->setPen( pp );
@@ -120,7 +128,13 @@ void QgsLayerTreeViewItemDelegate::paint( QPainter *painter, const QStyleOptionV
120128
qreal bradius = spacing;
121129
QBrush pb = painter->brush();
122130
QPen pp = painter->pen();
123-
painter->setBrush( opt.palette.midlight() );
131+
QBrush b = QBrush( opt.palette.midlight() );
132+
QColor bc = b.color();
133+
bc.setRed( static_cast< int >( bc.red() * 0.3 + baseColor.red() * 0.7 ) );
134+
bc.setGreen( static_cast< int >( bc.green() * 0.3 + baseColor.green() * 0.7 ) );
135+
bc.setBlue( static_cast< int >( bc.blue() * 0.3 + baseColor.blue() * 0.7 ) );
136+
b.setColor( bc );
137+
painter->setBrush( b );
124138
painter->setPen( QPen( QBrush( opt.palette.mid() ), 0.25 ) );
125139
painter->drawRoundedRect( rect, bradius, bradius );
126140
painter->setBrush( pb );
@@ -145,8 +159,6 @@ bool QgsLayerTreeViewItemDelegate::helpEvent( QHelpEvent *event, QAbstractItemVi
145159
{
146160
if ( event && event->type() == QEvent::ToolTip )
147161
{
148-
QHelpEvent *he = static_cast<QHelpEvent *>( event );
149-
150162
QgsLayerTreeNode *node = mLayerTreeView->layerTreeModel()->index2node( index );
151163
if ( node )
152164
{
@@ -159,15 +171,15 @@ bool QgsLayerTreeViewItemDelegate::helpEvent( QHelpEvent *event, QAbstractItemVi
159171

160172
QRect indRect = mLayerTreeView->style()->subElementRect( static_cast<QStyle::SubElement>( QgsLayerTreeViewProxyStyle::SE_LayerTreeItemIndicator ), &opt, mLayerTreeView );
161173

162-
if ( indRect.contains( he->pos() ) )
174+
if ( indRect.contains( event->pos() ) )
163175
{
164-
int indicatorIndex = ( he->pos().x() - indRect.left() ) / indRect.height();
176+
int indicatorIndex = ( event->pos().x() - indRect.left() ) / indRect.height();
165177
if ( indicatorIndex >= 0 && indicatorIndex < indicators.count() )
166178
{
167179
const QString tooltip = indicators[indicatorIndex]->toolTip();
168180
if ( !tooltip.isEmpty() )
169181
{
170-
QToolTip::showText( he->globalPos(), tooltip, view );
182+
QToolTip::showText( event->globalPos(), tooltip, view );
171183
return true;
172184
}
173185
}

0 commit comments

Comments
 (0)
Please sign in to comment.