Commit 5bd591bb authored by Noah Davis's avatar Noah Davis 🌵
Browse files

Change frameRadius to use pen widths, add frameRadiusForNewPenWidth, add PenWidth::NoPen

Summary: This patch reduces the amount of duplicate code and makes every part of the helper functions use the correct frame radius.

Reviewers: #breeze, #plasma, hpereiradacosta, ngraham

Reviewed By: hpereiradacosta

Subscribers: plasma-devel

Tags: #plasma

Differential Revision: https://phabricator.kde.org/D26225
parent ff333a47
......@@ -185,6 +185,9 @@ namespace Breeze
// 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
......
......@@ -461,7 +461,7 @@ namespace Breeze
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,7 +500,7 @@ namespace Breeze
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() )
......@@ -508,7 +508,7 @@ namespace Breeze
painter->setPen( outline );
frameRect = strokedRect( frameRect );
radius = qMax( radius - 1, qreal( 0.0 ) );
radius = frameRadiusForNewPenWidth( radius, PenWidth::Frame );
} else {
......@@ -561,7 +561,7 @@ namespace Breeze
case AllSides:
{
const qreal radius( frameRadius( -1.0 ) );
const qreal radius( frameRadius( PenWidth::Frame, -1 ) );
painter->drawRoundedRect( frameRect, radius, radius );
break;
}
......@@ -586,7 +586,7 @@ namespace Breeze
painter->setRenderHint( QPainter::Antialiasing );
QRectF frameRect( rect );
qreal radius( frameRadius() );
qreal radius( frameRadius( PenWidth::NoPen, -1 ) );
// set pen
if( outline.isValid() )
......@@ -594,7 +594,7 @@ namespace Breeze
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 @@ namespace Breeze
// 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 @@ namespace Breeze
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,7 +691,7 @@ namespace Breeze
if( sunken )
{
const qreal radius( frameRadius() );
const qreal radius( frameRadius( PenWidth::NoPen ) );
painter->setPen( Qt::NoPen );
painter->setBrush( color );
......@@ -700,7 +700,7 @@ namespace Breeze
} else {
const qreal radius( frameRadius(-0.5) );
const qreal radius( frameRadius( PenWidth::Frame ) );
painter->setPen( color );
painter->setBrush( Qt::NoBrush );
......@@ -720,7 +720,7 @@ namespace Breeze
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,7 +761,7 @@ namespace Breeze
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() )
......@@ -769,7 +769,7 @@ namespace Breeze
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 @@ namespace Breeze
// 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 @@ namespace Breeze
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,7 +1263,7 @@ namespace Breeze
painter->setRenderHint( QPainter::Antialiasing, true );
QRectF frameRect( rect );
qreal radius( frameRadius() );
qreal radius( frameRadius( PenWidth::NoPen, -1 ) );
// pen
if( outline.isValid() )
......@@ -1271,7 +1271,7 @@ namespace Breeze
painter->setPen( outline );
frameRect = strokedRect( frameRect );
radius = qMax( radius-1, qreal( 0.0 ) );
radius = frameRadiusForNewPenWidth( radius, PenWidth::Frame );
} else painter->setPen( Qt::NoPen );
......
......@@ -311,8 +311,12 @@ namespace Breeze
//@}
//* 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;
......
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