diff --git a/kstyle/breeze.h b/kstyle/breeze.h --- a/kstyle/breeze.h +++ b/kstyle/breeze.h @@ -185,6 +185,9 @@ // The standard pen stroke width for shadows. static constexpr int Shadow = 1; + + // A value for pen width arguments to make it clear that there is no pen stroke + static constexpr int NoPen = 0; } //* animation mode diff --git a/kstyle/breezehelper.h b/kstyle/breezehelper.h --- a/kstyle/breezehelper.h +++ b/kstyle/breezehelper.h @@ -311,8 +311,12 @@ //@} //* frame radius - qreal frameRadius( qreal bias = 0 ) const - { return qMax( qreal( Metrics::Frame_FrameRadius ) - 0.5 + bias, 0.0 ); } + constexpr qreal frameRadius( const int penWidth = PenWidth::NoPen, const qreal bias = 0 ) const + { return qMax( Metrics::Frame_FrameRadius - (0.5 * penWidth) + bias, 0.0 ); } + + //* frame radius with new pen width + constexpr qreal frameRadiusForNewPenWidth( const qreal oldRadius, const int penWidth ) const + { return qMax( oldRadius - (0.5 * penWidth), 0.0 ); } //* return a QRectF with the appropriate size for a rectangle with a pen stroke QRectF strokedRect( const QRectF &rect, const int penWidth = PenWidth::Frame ) const; diff --git a/kstyle/breezehelper.cpp b/kstyle/breezehelper.cpp --- a/kstyle/breezehelper.cpp +++ b/kstyle/breezehelper.cpp @@ -461,7 +461,7 @@ QRectF copy( strokedRect( rect ) ); - const qreal radius( frameRadius( -1.0 ) ); + const qreal radius( frameRadius( PenWidth::Frame, -1 ) ); if( !(sides&SideTop) ) copy.adjust( 0, -radius, 0, 0 ); if( !(sides&SideBottom) ) copy.adjust( 0, 0, 0, radius ); if( !(sides&SideLeft) ) copy.adjust( -radius, 0, 0, 0 ); @@ -500,15 +500,15 @@ painter->setRenderHint( QPainter::Antialiasing ); QRectF frameRect( rect.adjusted( 1, 1, -1, -1 ) ); - qreal radius( frameRadius() ); + qreal radius( frameRadius( PenWidth::NoPen, -1 ) ); // set pen if( outline.isValid() ) { painter->setPen( outline ); frameRect = strokedRect( frameRect ); - radius = qMax( radius - 1, qreal( 0.0 ) ); + radius = frameRadiusForNewPenWidth( radius, PenWidth::Frame ); } else { @@ -561,7 +561,7 @@ case AllSides: { - const qreal radius( frameRadius( -1.0 ) ); + const qreal radius( frameRadius( PenWidth::Frame, -1 ) ); painter->drawRoundedRect( frameRect, radius, radius ); break; } @@ -586,15 +586,15 @@ painter->setRenderHint( QPainter::Antialiasing ); QRectF frameRect( rect ); - qreal radius( frameRadius() ); + qreal radius( frameRadius( PenWidth::NoPen, -1 ) ); // set pen if( outline.isValid() ) { painter->setPen( outline ); frameRect = strokedRect( frameRect ); - radius = qMax( radius - 1, qreal( 0.0 ) ); + radius = frameRadiusForNewPenWidth( radius, PenWidth::Frame ); } else painter->setPen( Qt::NoPen ); @@ -632,7 +632,7 @@ // copy rect QRectF frameRect( rect ); frameRect.adjust( 1, 1, -1, -1 ); - qreal radius( frameRadius() ); + qreal radius( frameRadius( PenWidth::NoPen, -1 ) ); // shadow if( sunken ) { @@ -654,7 +654,7 @@ painter->setPen( QPen( QBrush( gradient ), 1.0 ) ); frameRect = strokedRect( frameRect ); - radius = qMax( radius - 1, qreal( 0.0 ) ); + radius = frameRadiusForNewPenWidth( radius, PenWidth::Frame ); } else painter->setPen( Qt::NoPen ); @@ -691,16 +691,16 @@ if( sunken ) { - const qreal radius( frameRadius() ); + const qreal radius( frameRadius( PenWidth::NoPen ) ); painter->setPen( Qt::NoPen ); painter->setBrush( color ); painter->drawRoundedRect( baseRect, radius, radius ); } else { - const qreal radius( frameRadius(-0.5) ); + const qreal radius( frameRadius( PenWidth::Frame ) ); painter->setPen( color ); painter->setBrush( Qt::NoBrush ); @@ -720,7 +720,7 @@ if( !outline.isValid() ) return; // round radius - const qreal radius( frameRadius() ); + const qreal radius( frameRadius( PenWidth::Frame ) ); const QSizeF cornerSize( 2*radius, 2*radius ); // if rect - tabwidth is even, need to increase tabWidth by 1 unit @@ -761,15 +761,15 @@ painter->setRenderHint( QPainter::Antialiasing ); QRectF frameRect( rect.adjusted( 1, 1, -1, -1 ) ); - qreal radius( frameRadius() ); + qreal radius( frameRadius( PenWidth::NoPen, -1 ) ); // set pen if( outline.isValid() ) { painter->setPen( outline ); frameRect = strokedRect( frameRect ); - radius = qMax( radius-1, qreal( 0.0 ) ); + radius = frameRadiusForNewPenWidth( radius, PenWidth::Frame ); } else painter->setPen( Qt::NoPen ); @@ -858,7 +858,7 @@ // copy rect and radius QRectF frameRect( rect ); frameRect.adjust( 2, 2, -2, -2 ); - qreal radius( frameRadius() ); + qreal radius( frameRadius( PenWidth::NoPen, -1 ) ); // shadow if( sunken ) @@ -878,7 +878,7 @@ painter->setPen( QPen( color, PenWidth::Frame ) ); painter->setBrush( Qt::NoBrush ); - radius = qMax( radius-1, qreal( 0.0 ) ); + radius = frameRadiusForNewPenWidth( radius, PenWidth::Frame ); const QRectF contentRect( strokedRect( frameRect ) ); painter->drawRoundedRect( contentRect, radius, radius ); @@ -1263,15 +1263,15 @@ painter->setRenderHint( QPainter::Antialiasing, true ); QRectF frameRect( rect ); - qreal radius( frameRadius() ); + qreal radius( frameRadius( PenWidth::NoPen, -1 ) ); // pen if( outline.isValid() ) { painter->setPen( outline ); frameRect = strokedRect( frameRect ); - radius = qMax( radius-1, qreal( 0.0 ) ); + radius = frameRadiusForNewPenWidth( radius, PenWidth::Frame ); } else painter->setPen( Qt::NoPen );