diff --git a/kstyle/breezehelper.h b/kstyle/breezehelper.h --- a/kstyle/breezehelper.h +++ b/kstyle/breezehelper.h @@ -307,6 +307,12 @@ //* 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: diff --git a/kstyle/breezehelper.cpp b/kstyle/breezehelper.cpp --- a/kstyle/breezehelper.cpp +++ b/kstyle/breezehelper.cpp @@ -1436,10 +1436,29 @@ #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 { diff --git a/kstyle/breezestyle.cpp b/kstyle/breezestyle.cpp --- a/kstyle/breezestyle.cpp +++ b/kstyle/breezestyle.cpp @@ -5388,15 +5388,19 @@ 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; }