Commit dcfdaa13 authored by Nathaniel Graham's avatar Nathaniel Graham

Use combobox to choose shadow size and use more appropriate values for menu & tooltip shadow sizes

Summary:
This implements the menu shadow changes proposed in D9549; now we use a combobox with five options: None, Small, Medium, Large, and Very Large.

Large is the new default value (64px window shadows, 16px menu/tooltip shadows), and implements what we recently changed the default to. Small is the old default value (16px window shadows, 12px menu/tooltip shadows) for people who preferred that.

I had a massive amount of help from @hpereiradacosta; in fact, probably 75% of these changes are his. It's a shame multiple authorship isn't possible. Hugo, feel free to commandeer the revision if you'd like the credit!

Test Plan:
Tested in KDE Neon. New smaller menu shadows for the default window shadow size:

{F5615780}

New shadow chooser UI, with different options:

None (1px border for windows, menus, and tooltips):
{F5623069}

Small (16px window shadows, 12px menu/tooltip shadows); replicates the the old default value:
{F5623071}

Medium (32px window shadows, 14px menu/tooltip shadows):
{F5623072}

Large (64px window shadows, 16px menu/tooltip shadows); the new default:
{F5623073}

Very Large (96px window shadows, 24px menu/tooltip shadows):
{F5623074}

Upgrade story: since this changes the way shadow size is stored in the breezerc file, users who previously had manually set their shadow size to some arbitrary pixel value will now get the new default Large 64 px shadow size.

Reviewers: #vdg, #breeze, hpereiradacosta, abetts, rkflx

Reviewed By: #vdg, hpereiradacosta, abetts, rkflx

Subscribers: rkflx, plasma-devel

Tags: #plasma

Differential Revision: https://phabricator.kde.org/D9627
parent a4e2e37f
......@@ -65,8 +65,8 @@ namespace Breeze
//________________________________________________________________
static int g_sDecoCount = 0;
static int g_shadowSize = 0;
static int g_shadowStrength = 0;
static int g_shadowSizeEnum = InternalSettings::ShadowLarge;
static int g_shadowStrength = 90;
static QColor g_shadowColor = Qt::black;
static QSharedPointer<KDecoration2::DecorationShadow> g_sShadow;
......@@ -626,24 +626,39 @@ namespace Breeze
// assign global shadow if exists and parameters match
if(
!g_sShadow ||
g_shadowSize != m_internalSettings->shadowSize() ||
g_shadowSizeEnum != m_internalSettings->shadowSize() ||
g_shadowStrength != m_internalSettings->shadowStrength() ||
g_shadowColor != m_internalSettings->shadowColor()
)
{
// assign parameters
g_shadowSize = m_internalSettings->shadowSize();
g_shadowSizeEnum = m_internalSettings->shadowSize();
g_shadowStrength = m_internalSettings->shadowStrength();
g_shadowColor = m_internalSettings->shadowColor();
const int shadowOffset = qMax( 6*g_shadowSize/16, Metrics::Shadow_Overlap*2 );
// shadow size from enum
int shadowSize = 0;
switch( g_shadowSizeEnum )
{
default:
case InternalSettings::ShadowLarge: shadowSize = 64; break;
case InternalSettings::ShadowNone: shadowSize = Metrics::Shadow_Overlap + 1; break;
case InternalSettings::ShadowSmall: shadowSize = 16; break;
case InternalSettings::ShadowMedium: shadowSize = 32; break;
case InternalSettings::ShadowVeryLarge: shadowSize = 96; break;
}
// offset
int shadowOffset = (g_shadowSizeEnum == InternalSettings::ShadowNone) ? 0 : qMax( 6*shadowSize/16, Metrics::Shadow_Overlap*2 );
// create image
QImage image(2*g_shadowSize, 2*g_shadowSize, QImage::Format_ARGB32_Premultiplied);
QImage image(2*shadowSize, 2*shadowSize, QImage::Format_ARGB32_Premultiplied);
image.fill(Qt::transparent);
// create gradient
// gaussian delta function
auto alpha = [](qreal x) { return std::exp( -x*x/0.15 ); };
// painter
QPainter painter(&image);
painter.setRenderHint( QPainter::Antialiasing, true );
// color calculation delta function
auto gradientStopColor = [](QColor color, int alpha)
......@@ -652,26 +667,33 @@ namespace Breeze
return color;
};
QRadialGradient radialGradient( g_shadowSize, g_shadowSize, g_shadowSize );
for( int i = 0; i < 10; ++i )
// create gradient
if( g_shadowSizeEnum != InternalSettings::ShadowNone )
{
const qreal x( qreal( i )/9 );
radialGradient.setColorAt(x, gradientStopColor( g_shadowColor, alpha(x)*g_shadowStrength ) );
}
radialGradient.setColorAt(1, gradientStopColor( g_shadowColor, 0 ) );
// gaussian lambda function
auto alpha = [](qreal x) { return std::exp( -x*x/0.15 ); };
// fill
QPainter painter(&image);
painter.setRenderHint( QPainter::Antialiasing, true );
painter.fillRect( image.rect(), radialGradient);
QRadialGradient radialGradient( shadowSize, shadowSize, shadowSize );
for( int i = 0; i < 10; ++i )
{
const qreal x( qreal( i )/9 );
radialGradient.setColorAt(x, gradientStopColor( g_shadowColor, alpha(x)*g_shadowStrength ) );
}
radialGradient.setColorAt(1, gradientStopColor( g_shadowColor, 0 ) );
// fill
painter.fillRect( image.rect(), radialGradient);
}
// contrast pixel
QRectF innerRect = QRectF(
g_shadowSize - Metrics::Shadow_Overlap, g_shadowSize - shadowOffset - Metrics::Shadow_Overlap,
shadowSize - Metrics::Shadow_Overlap, shadowSize - shadowOffset - Metrics::Shadow_Overlap,
2*Metrics::Shadow_Overlap, shadowOffset + 2*Metrics::Shadow_Overlap );
painter.setPen( gradientStopColor( g_shadowColor, g_shadowStrength*0.5 ) );
painter.setPen( gradientStopColor( g_shadowColor, (g_shadowSizeEnum == InternalSettings::ShadowNone) ? g_shadowStrength:(g_shadowStrength*0.5) ) );
painter.setBrush( Qt::NoBrush );
painter.drawRoundedRect( innerRect, -0.5 + Metrics::Frame_FrameRadius, -0.5 + Metrics::Frame_FrameRadius );
......@@ -685,12 +707,12 @@ namespace Breeze
g_sShadow = QSharedPointer<KDecoration2::DecorationShadow>::create();
g_sShadow->setPadding( QMargins(
g_shadowSize - Metrics::Shadow_Overlap,
g_shadowSize - shadowOffset - Metrics::Shadow_Overlap,
g_shadowSize - Metrics::Shadow_Overlap,
g_shadowSize - Metrics::Shadow_Overlap ) );
shadowSize - Metrics::Shadow_Overlap,
shadowSize - shadowOffset - Metrics::Shadow_Overlap,
shadowSize - Metrics::Shadow_Overlap,
shadowSize - Metrics::Shadow_Overlap ) );
g_sShadow->setInnerShadowRect(QRect( g_shadowSize, g_shadowSize, 1, 1) );
g_sShadow->setInnerShadowRect(QRect( shadowSize, shadowSize, 1, 1) );
// assign image
g_sShadow->setShadow(image);
......
......@@ -6,17 +6,22 @@
<!-- common options -->
<group name="Common">
<!-- shadow -->
<entry name="ShadowStrength" type = "Int">
<default>90</default>
<min>25</min>
<max>255</max>
</entry>
<entry name="ShadowSize" type = "Int">
<default>64</default>
<min>6</min>
<max>100</max>
<!-- shadow -->
<entry name="ShadowSize" type = "Enum">
<choices>
<choice name="ShadowNone"/>
<choice name="ShadowSmall"/>
<choice name="ShadowMedium"/>
<choice name="ShadowLarge"/>
<choice name="ShadowVeryLarge"/>
</choices>
<default>ShadowLarge</default>
</entry>
<entry name="ShadowColor" type = "Color">
......
......@@ -59,7 +59,7 @@ namespace Breeze
connect( m_ui.animationsDuration, SIGNAL(valueChanged(int)), SLOT(updateChanged()) );
// track shadows changes
connect( m_ui.shadowSize, SIGNAL(valueChanged(int)), SLOT(updateChanged()) );
connect( m_ui.shadowSize, SIGNAL(currentIndexChanged(int)), SLOT(updateChanged()) );
connect( m_ui.shadowStrength, SIGNAL(valueChanged(int)), SLOT(updateChanged()) );
connect( m_ui.shadowColor, SIGNAL(changed(QColor)), SLOT(updateChanged()) );
......@@ -88,7 +88,9 @@ namespace Breeze
m_ui.drawTitleBarSeparator->setChecked( m_internalSettings->drawTitleBarSeparator() );
// load shadows
m_ui.shadowSize->setValue( m_internalSettings->shadowSize() );
if( m_internalSettings->shadowSize() <= InternalSettings::ShadowVeryLarge ) m_ui.shadowSize->setCurrentIndex( m_internalSettings->shadowSize() );
else m_ui.shadowSize->setCurrentIndex( InternalSettings::ShadowLarge );
m_ui.shadowStrength->setValue( qRound(qreal(m_internalSettings->shadowStrength()*100)/255 ) );
m_ui.shadowColor->setColor( m_internalSettings->shadowColor() );
......@@ -119,7 +121,7 @@ namespace Breeze
m_internalSettings->setAnimationsDuration( m_ui.animationsDuration->value() );
m_internalSettings->setDrawTitleBarSeparator(m_ui.drawTitleBarSeparator->isChecked());
m_internalSettings->setShadowSize( m_ui.shadowSize->value() );
m_internalSettings->setShadowSize( m_ui.shadowSize->currentIndex() );
m_internalSettings->setShadowStrength( qRound( qreal(m_ui.shadowStrength->value()*255)/100 ) );
m_internalSettings->setShadowColor( m_ui.shadowColor->color() );
......@@ -166,7 +168,7 @@ namespace Breeze
m_ui.animationsDuration->setValue( m_internalSettings->animationsDuration() );
m_ui.drawTitleBarSeparator->setChecked( m_internalSettings->drawTitleBarSeparator() );
m_ui.shadowSize->setValue( m_internalSettings->shadowSize() );
m_ui.shadowSize->setCurrentIndex( m_internalSettings->shadowSize() );
m_ui.shadowStrength->setValue( qRound(qreal(m_internalSettings->shadowStrength()*100)/255 ) );
m_ui.shadowColor->setColor( m_internalSettings->shadowColor() );
......@@ -195,7 +197,7 @@ namespace Breeze
else if( m_ui.animationsDuration->value() != m_internalSettings->animationsDuration() ) modified = true;
// shadows
else if( m_ui.shadowSize->value() != m_internalSettings->shadowSize() ) modified = true;
else if( m_ui.shadowSize->currentIndex() != m_internalSettings->shadowSize() ) modified = true;
else if( qRound( qreal(m_ui.shadowStrength->value()*255)/100 ) != m_internalSettings->shadowStrength() ) modified = true;
else if( m_ui.shadowColor->color() != m_internalSettings->shadowColor() ) modified = true;
......
......@@ -11,16 +11,7 @@
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<property name="margin">
<number>0</number>
</property>
<item>
......@@ -73,7 +64,7 @@
</item>
<item>
<property name="text">
<string comment="@item:inlistbox Button size:">Normal</string>
<string comment="@item:inlistbox Button size:">Medium</string>
</property>
</item>
<item>
......@@ -263,16 +254,32 @@
</widget>
</item>
<item row="0" column="1">
<widget class="QSpinBox" name="shadowSize">
<property name="suffix">
<string>px</string>
</property>
<property name="minimum">
<number>6</number>
</property>
<property name="maximum">
<number>64</number>
</property>
<widget class="QComboBox" name="shadowSize">
<item>
<property name="text">
<string comment="@item:inlistbox Button size:">None</string>
</property>
</item>
<item>
<property name="text">
<string comment="@item:inlistbox Button size:">Small</string>
</property>
</item>
<item>
<property name="text">
<string comment="@item:inlistbox Button size:">Medium</string>
</property>
</item>
<item>
<property name="text">
<string comment="@item:inlistbox Button size:">Large</string>
</property>
</item>
<item>
<property name="text">
<string comment="@item:inlistbox Button size:">Very Large</string>
</property>
</item>
</widget>
</item>
<item row="1" column="0">
......
......@@ -15,10 +15,16 @@
<max>255</max>
</entry>
<entry name="ShadowSize" type = "Int">
<default>64</default>
<min>6</min>
<max>100</max>
<!-- shadow -->
<entry name="ShadowSize" type = "Enum">
<choices>
<choice name="ShadowNone"/>
<choice name="ShadowSmall"/>
<choice name="ShadowMedium"/>
<choice name="ShadowLarge"/>
<choice name="ShadowVeryLarge"/>
</choices>
<default>ShadowLarge</default>
</entry>
<entry name="ShadowColor" type = "Color">
......
......@@ -46,6 +46,27 @@
#include <KWayland/Client/surface.h>
#endif
namespace
{
int shadowSize( int shadowSizeEnum )
{
switch( shadowSizeEnum )
{
default:
case Breeze::StyleConfigData::ShadowLarge: return 16;
case Breeze::StyleConfigData::ShadowNone: return 0;
case Breeze::StyleConfigData::ShadowSmall: return 12;
case Breeze::StyleConfigData::ShadowMedium: return 14;
case Breeze::StyleConfigData::ShadowVeryLarge: return 24;
}
}
}
namespace Breeze
{
......@@ -217,14 +238,14 @@ namespace Breeze
//_______________________________________________________
TileSet ShadowHelper::shadowTiles()
{
if( !_shadowTiles.isValid() )
// metrics
const int shadowSize = ::shadowSize( StyleConfigData::shadowSize() );
if( !shadowSize ) return TileSet();
else if( !_shadowTiles.isValid() )
{
const QPalette palette( QApplication::palette() );
const QColor shadowColor( StyleConfigData::shadowColor() );
// metrics
const int shadowSize = StyleConfigData::shadowSize()*12/16;
const int shadowOffset = qMax( shadowSize/2, Metrics::Shadow_Overlap*2 );
const int shadowStrength = StyleConfigData::shadowStrength();
......@@ -509,7 +530,8 @@ namespace Breeze
const qreal devicePixelRatio( _helper.devicePixelRatio( _shadowTiles.pixmap( 0 ) ) );
// metrics
const int shadowSize = StyleConfigData::shadowSize()*12/16;
const int shadowSize = ::shadowSize( StyleConfigData::shadowSize() );
if( !shadowSize ) return QMargins();
const int shadowOffset = qMax( shadowSize/2, Metrics::Shadow_Overlap*2 );
// define shadows padding
......
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