Commit c16eb7a4 authored by Noah Davis's avatar Noah Davis 🌵
Browse files

Add standard pen widths and replace hardcoded numbers

Summary:
The replaced numbers are directly related to the width of the pen.
This patch likely doesn't replace all of the numbers that could be replaced.
It just replaces the ones I'm currently certain of being related to pen width.
The goal is to make the code show the intent of the designer.

Reviewers: #breeze, #plasma, hpereiradacosta, ngraham

Reviewed By: #breeze, hpereiradacosta, ngraham

Subscribers: plasma-devel

Tags: #plasma

Differential Revision: https://phabricator.kde.org/D26217
parent 9a7ef259
......@@ -170,6 +170,23 @@ namespace Breeze
};
//* standard pen widths
namespace PenWidth
{
/* Using 1 instead of slightly more than 1 causes symbols drawn with
* pen strokes to look skewed. The exact amount added does not matter
* as long as it isn't too visible.
*/
// The standard pen stroke width for symbols.
static constexpr qreal Symbol = 1.1;
// The standard pen stroke width for frames.
static constexpr int Frame = 1;
// The standard pen stroke width for shadows.
static constexpr int Shadow = 1;
}
//* animation mode
enum AnimationMode
{
......
......@@ -875,7 +875,7 @@ namespace Breeze
// content
{
painter->setPen( QPen( color, 1 ) );
painter->setPen( QPen( color, PenWidth::Frame ) );
painter->setBrush( Qt::NoBrush );
radius = qMax( radius-1, qreal( 0.0 ) );
......@@ -978,7 +978,7 @@ namespace Breeze
// content
{
painter->setPen( QPen( color, 1 ) );
painter->setPen( QPen( color, PenWidth::Frame ) );
painter->setBrush( Qt::NoBrush );
const QRectF contentRect( strokedRect( frameRect ) );
......@@ -1309,7 +1309,7 @@ namespace Breeze
painter->setRenderHints( QPainter::Antialiasing );
painter->translate( QRectF( rect ).center() );
painter->setBrush( Qt::NoBrush );
QPen pen( color, 1.1 );
QPen pen( color, PenWidth::Symbol );
pen.setCapStyle(Qt::SquareCap);
pen.setJoinStyle(Qt::MiterJoin);
painter->setPen( pen );
......@@ -1352,7 +1352,7 @@ namespace Breeze
pen.setCapStyle( Qt::RoundCap );
pen.setJoinStyle( Qt::MiterJoin );
pen.setWidthF( 1.1*qMax(1.0, 18.0/rect.width() ) );
pen.setWidthF( PenWidth::Symbol*qMax(1.0, 18.0/rect.width() ) );
painter->setPen( pen );
switch( buttonType )
......@@ -1409,6 +1409,8 @@ namespace Breeze
painter->save();
qreal translation = 0.5 * PenWidth::Shadow; // Translate for the pen
/* Clipping prevents shadows from being visible inside checkboxes.
* Clipping away unneeded parts here also improves performance by 40-60%
* versus using just an outline of a rectangle.
......@@ -1416,15 +1418,15 @@ namespace Breeze
*/
// Right side
QRegion clip( rect.right() - std::ceil( radius ), rect.top(),
std::ceil( radius ) + 1, rect.height() );
std::ceil( radius ) + PenWidth::Shadow, rect.height() );
// Bottom side
clip = clip.united( QRegion( rect.left(), rect.bottom() - std::ceil( radius ),
rect.width(), std::ceil( radius ) + 1 ) );
rect.width(), std::ceil( radius ) + PenWidth::Shadow ) );
painter->setClipRegion( clip );
painter->setPen( color );
painter->setBrush( Qt::NoBrush );
painter->drawRoundedRect( rect.translated( 0.5, 0.5 ), radius, radius );
painter->drawRoundedRect( rect.translated( translation, translation ), radius, radius );
painter->restore();
}
......@@ -1438,13 +1440,14 @@ namespace Breeze
// Clipping does not improve performance here
// 0.5 is subtracted because of the pen
qreal radius = rect.width() / 2 - 0.5;
qreal adjustment = 0.5 * PenWidth::Shadow; // Adjust for the pen
qreal radius = rect.width() / 2 - adjustment;
/* The right side is offset by +0.5 for the visible part of the shadow.
* The other sides are offset by +0.5 or -0.5 because of the pen.
*/
QRectF shadowRect = rect.adjusted( 0.5, 0.5, 0.5, -0.5 );
QRectF shadowRect = rect.adjusted( adjustment, adjustment, adjustment, -adjustment );
painter->translate( rect.center() );
painter->rotate( 45 );
......
......@@ -315,10 +315,10 @@ namespace Breeze
{ 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 QRectF &rect, const int penWidth = 1 ) const;
QRectF strokedRect( const QRectF &rect, const int penWidth = PenWidth::Frame ) const;
//* return a QRectF with the appropriate size for a rectangle with a pen stroke
QRectF strokedRect( const QRect &rect, const int penWidth = 1 ) const;
QRectF strokedRect( const QRect &rect, const int penWidth = PenWidth::Frame ) const;
protected:
......
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