From dcfdaa138fb70da7b9ab9255b6ba923eb2abe379 Mon Sep 17 00:00:00 2001 From: Nathaniel Graham Date: Mon, 8 Jan 2018 14:22:29 -0700 Subject: [PATCH] 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 --- kdecoration/breezedecoration.cpp | 74 ++++++++++++------- kdecoration/breezesettingsdata.kcfg | 15 ++-- kdecoration/config/breezeconfigwidget.cpp | 12 +-- .../config/ui/breezeconfigurationui.ui | 49 ++++++------ kstyle/breeze.kcfg | 14 +++- kstyle/breezeshadowhelper.cpp | 32 ++++++-- 6 files changed, 130 insertions(+), 66 deletions(-) diff --git a/kdecoration/breezedecoration.cpp b/kdecoration/breezedecoration.cpp index 46644c21..800a5174 100644 --- a/kdecoration/breezedecoration.cpp +++ b/kdecoration/breezedecoration.cpp @@ -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 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::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); diff --git a/kdecoration/breezesettingsdata.kcfg b/kdecoration/breezesettingsdata.kcfg index 47d3f2f4..dcfd9d36 100644 --- a/kdecoration/breezesettingsdata.kcfg +++ b/kdecoration/breezesettingsdata.kcfg @@ -6,17 +6,22 @@ - 90 25 255 - - 64 - 6 - 100 + + + + + + + + + + ShadowLarge diff --git a/kdecoration/config/breezeconfigwidget.cpp b/kdecoration/config/breezeconfigwidget.cpp index 779f4308..1e5476c8 100644 --- a/kdecoration/config/breezeconfigwidget.cpp +++ b/kdecoration/config/breezeconfigwidget.cpp @@ -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; diff --git a/kdecoration/config/ui/breezeconfigurationui.ui b/kdecoration/config/ui/breezeconfigurationui.ui index 3d73d543..8899ee98 100644 --- a/kdecoration/config/ui/breezeconfigurationui.ui +++ b/kdecoration/config/ui/breezeconfigurationui.ui @@ -11,16 +11,7 @@ - - 0 - - - 0 - - - 0 - - + 0 @@ -73,7 +64,7 @@ - Normal + Medium @@ -263,16 +254,32 @@ - - - px - - - 6 - - - 64 - + + + + None + + + + + Small + + + + + Medium + + + + + Large + + + + + Very Large + + diff --git a/kstyle/breeze.kcfg b/kstyle/breeze.kcfg index cf29759a..bd2cc407 100644 --- a/kstyle/breeze.kcfg +++ b/kstyle/breeze.kcfg @@ -15,10 +15,16 @@ 255 - - 64 - 6 - 100 + + + + + + + + + + ShadowLarge diff --git a/kstyle/breezeshadowhelper.cpp b/kstyle/breezeshadowhelper.cpp index 4e4d33cc..43dc8926 100644 --- a/kstyle/breezeshadowhelper.cpp +++ b/kstyle/breezeshadowhelper.cpp @@ -46,6 +46,27 @@ #include #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