Commit 80650e0e authored by Noah Davis's avatar Noah Davis 🌵
Browse files

Fix rubberband selection outline position

Summary:
Before this patch, the outline of the rubberband selection control was down and to the right half a pixel too far.
This wasn't visible at 1x scaling because of the lack of antialiasing, but resulted in the top/left being too thin and bottom/right being too thick on high DPI displays.
To fix the issue, I enabled antialiasing and moved all sides inwards by half a pixel so that the outline would be pixel perfect.
I also added a function to get a QRectF with the correct size and position for rectangles with pen strokes.

Test Plan:
- Open dolphin and make a selection with the mouse
- Go to a Folder View Plasma widget and make a selection with the mouse

2x scaling
before: {F7818498, size=full}
after: {F7818500, size=full}

3x scaling
before: {F7818484}
after: {F7818483}

Reviewers: #vdg, #breeze, #plasma, hpereiradacosta, broulik

Reviewed By: hpereiradacosta

Subscribers: broulik, plasma-devel

Tags: #plasma, #breeze, #vdg

Differential Revision: https://phabricator.kde.org/D26001
parent a268d593
......@@ -1436,10 +1436,29 @@ namespace Breeze
#endif
}
//______________________________________________________________________________
QRectF Helper::strokedRect( const QRect &rect, const int penWidth ) const
{
/* With a pen stroke width of 1, the rectangle should have each of its
* sides moved inwards by half a pixel. This allows the stroke to be
* pixel perfect instead of blurry from sitting between pixels and
* prevents the rectangle with a stroke from becoming larger than the
* original size of the rectangle.
*/
qreal adjustment = 0.5 * penWidth;
return QRectF( rect ).adjusted( adjustment, adjustment, -adjustment, -adjustment );
}
QRectF Helper::strokedRect( const QRectF &rect, const int penWidth ) const
{
qreal adjustment = 0.5 * penWidth;
return rect.adjusted( adjustment, adjustment, -adjustment, -adjustment );
}
//______________________________________________________________________________
QRectF Helper::shadowRect( const QRectF& rect ) const
{ return rect.adjusted( 0.5, 0.5, -0.5, -0.5 ).translated( 0.5, 0.5 ); }
//______________________________________________________________________________
QPainterPath Helper::roundedPath( const QRectF& rect, Corners corners, qreal radius ) const
{
......
......@@ -307,6 +307,12 @@ namespace Breeze
//* frame radius
qreal frameRadius( qreal bias = 0 ) const
{ return qMax( qreal( Metrics::Frame_FrameRadius ) - 0.5 + bias, 0.0 ); }
//* return a QRectF with the appropriate size for a rectangle with a pen stroke
QRectF strokedRect( const QRect &rect, const int penWidth = 1 ) const;
//* return a QRectF with the appropriate size for a rectangle with a pen stroke
QRectF strokedRect( const QRectF &rect, const int penWidth = 1 ) const;
protected:
......
......@@ -5388,15 +5388,19 @@ namespace Breeze
bool Style::drawRubberBandControl( const QStyleOption* option, QPainter* painter, const QWidget* ) const
{
const auto& palette( option->palette );
const auto rect( option->rect );
painter->save();
painter->setRenderHints( QPainter::Antialiasing );
const auto& palette( option->palette );
auto color = palette.color( QPalette::Highlight );
painter->setPen( KColorUtils::mix( color, palette.color( QPalette::Active, QPalette::WindowText ) ) );
QPen pen = KColorUtils::mix( color, palette.color( QPalette::Active, QPalette::WindowText ) );
pen.setJoinStyle(Qt::RoundJoin);
painter->setPen( pen );
color.setAlpha( 50 );
painter->setBrush( color );
painter->setClipRegion( rect );
painter->drawRect( rect.adjusted( 0, 0, -1, -1 ) );
painter->drawRect( _helper->strokedRect( option->rect ) );
painter->restore();
return true;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment