From 336cf7b63a6aea76d9ffd33bbb38c352f63eefdf Mon Sep 17 00:00:00 2001 From: Hugo Pereira Da Costa Date: Fri, 16 Feb 2018 17:27:21 +0100 Subject: [PATCH] Added option to set transparency and blur behind menu frames such as right click context menu, toolbar menu, etc. Transparency and blur is disabled by default. Submitted on behalf of Alex Nemeth Differential Revision: https://phabricator.kde.org/D10170 --- kstyle/CMakeLists.txt | 1 + kstyle/breeze.kcfg | 9 +- kstyle/breezestyle.cpp | 23 +++- kstyle/breezestyle.h | 4 + kstyle/config/breezestyleconfig.cpp | 6 +- kstyle/config/ui/breezestyleconfig.ui | 146 +++++++++++++++++++++++++- 6 files changed, 180 insertions(+), 9 deletions(-) diff --git a/kstyle/CMakeLists.txt b/kstyle/CMakeLists.txt index 6b95c401..7e90a130 100644 --- a/kstyle/CMakeLists.txt +++ b/kstyle/CMakeLists.txt @@ -128,6 +128,7 @@ set(breeze_PART_SRCS animations/breezewidgetstateengine.cpp animations/breezewidgetstatedata.cpp debug/breezewidgetexplorer.cpp + breezeblurhelper.cpp breezeaddeventfilter.cpp breezeframeshadow.cpp breezehelper.cpp diff --git a/kstyle/breeze.kcfg b/kstyle/breeze.kcfg index bd2cc407..1a20350f 100644 --- a/kstyle/breeze.kcfg +++ b/kstyle/breeze.kcfg @@ -40,7 +40,7 @@ - + true @@ -97,7 +97,7 @@ true - + true @@ -185,6 +185,11 @@ false + + + 100 + + diff --git a/kstyle/breezestyle.cpp b/kstyle/breezestyle.cpp index 51092586..fbe020b1 100644 --- a/kstyle/breezestyle.cpp +++ b/kstyle/breezestyle.cpp @@ -30,6 +30,7 @@ #include "breezestyleconfigdata.h" #include "breezewidgetexplorer.h" #include "breezewindowmanager.h" +#include "breezeblurhelper.h" #include @@ -152,6 +153,7 @@ namespace Breeze , _helper( new Helper( "breeze" ) ) #else , _helper( new Helper( StyleConfigData::self()->sharedConfig() ) ) + , _blurHelper( new BlurHelper( this ) ) #endif , _shadowHelper( new ShadowHelper( this, *_helper ) ) @@ -317,6 +319,12 @@ namespace Breeze setTranslucentBackground( widget ); + #if !BREEZE_USE_KDE4 + if ( _helper->hasAlphaChannel( widget ) && StyleConfigData::menuOpacity() < 100 ) { + _blurHelper->registerWidget( widget->window() ); + } + #endif + #if QT_VERSION >= 0x050000 } else if( qobject_cast( widget ) ) { @@ -439,6 +447,10 @@ namespace Breeze _windowManager->unregisterWidget( widget ); _splitterFactory->unregisterWidget( widget ); + #if !BREEZE_USE_KDE4 + _blurHelper->unregisterWidget( widget ); + #endif + // remove event filter if( qobject_cast( widget ) || qobject_cast( widget ) || @@ -3609,7 +3621,6 @@ namespace Breeze //___________________________________________________________________________________ bool Style::drawPanelMenuPrimitive( const QStyleOption* option, QPainter* painter, const QWidget* widget ) const { - /* * do nothing if menu is embedded in another widget * this corresponds to having a transparent background @@ -3617,10 +3628,16 @@ namespace Breeze if( widget && !widget->isWindow() ) return true; const auto& palette( option->palette ); - const auto background( _helper->frameBackgroundColor( palette ) ); const auto outline( _helper->frameOutlineColor( palette ) ); - const bool hasAlpha( _helper->hasAlphaChannel( widget ) ); + auto background( _helper->frameBackgroundColor( palette ) ); + + #if !BREEZE_USE_KDE4 + if ( hasAlpha ) { + background.setAlphaF(StyleConfigData::menuOpacity() / 100.0); + } + #endif + _helper->renderMenuFrame( painter, option->rect, background, outline, hasAlpha ); return true; diff --git a/kstyle/breezestyle.h b/kstyle/breezestyle.h index 12548c92..c9ac1221 100644 --- a/kstyle/breezestyle.h +++ b/kstyle/breezestyle.h @@ -66,6 +66,7 @@ namespace Breeze class SplitterFactory; class WidgetExplorer; class WindowManager; + class BlurHelper; //* convenience typedef for base class #if BREEZE_USE_KDE4 @@ -497,6 +498,9 @@ namespace Breeze //* keyboard accelerators Mnemonics* _mnemonics = nullptr; + //* blur helper + BlurHelper* _blurHelper = nullptr; + //* window manager WindowManager* _windowManager = nullptr; diff --git a/kstyle/config/breezestyleconfig.cpp b/kstyle/config/breezestyleconfig.cpp index ee761ef6..6fb5302a 100644 --- a/kstyle/config/breezestyleconfig.cpp +++ b/kstyle/config/breezestyleconfig.cpp @@ -64,6 +64,7 @@ namespace Breeze connect( _scrollBarAddLineButtons, SIGNAL(currentIndexChanged(int)), SLOT(updateChanged()) ); connect( _scrollBarSubLineButtons, SIGNAL(currentIndexChanged(int)), SLOT(updateChanged()) ); connect( _windowDragMode, SIGNAL(currentIndexChanged(int)), SLOT(updateChanged()) ); + connect( _menuOpacity, SIGNAL(valueChanged(int)), SLOT(updateChanged()) ); } @@ -84,7 +85,8 @@ namespace Breeze StyleConfigData::setScrollBarSubLineButtons( _scrollBarSubLineButtons->currentIndex() ); StyleConfigData::setAnimationsEnabled( _animationsEnabled->isChecked() ); StyleConfigData::setAnimationsDuration( _animationsDuration->value() ); - StyleConfigData::setWindowDragMode( _windowDragMode->currentIndex() ); + StyleConfigData::setWindowDragMode( _windowDragMode->currentIndex() ); + StyleConfigData::setMenuOpacity( _menuOpacity->value() ); #if BREEZE_USE_KDE4 StyleConfigData::self()->writeConfig(); @@ -147,6 +149,7 @@ namespace Breeze else if( _animationsEnabled->isChecked() != StyleConfigData::animationsEnabled() ) modified = true; else if( _animationsDuration->value() != StyleConfigData::animationsDuration() ) modified = true; else if( _windowDragMode->currentIndex() != StyleConfigData::windowDragMode() ) modified = true; + else if( _menuOpacity->value() != StyleConfigData::menuOpacity() ) modified = true; emit changed(modified); @@ -171,6 +174,7 @@ namespace Breeze _animationsEnabled->setChecked( StyleConfigData::animationsEnabled() ); _animationsDuration->setValue( StyleConfigData::animationsDuration() ); _windowDragMode->setCurrentIndex( StyleConfigData::windowDragMode() ); + _menuOpacity->setValue( StyleConfigData::menuOpacity() ); } diff --git a/kstyle/config/ui/breezestyleconfig.ui b/kstyle/config/ui/breezestyleconfig.ui index ee33a114..30fb9131 100644 --- a/kstyle/config/ui/breezestyleconfig.ui +++ b/kstyle/config/ui/breezestyleconfig.ui @@ -6,10 +6,16 @@ 0 0 - 522 - 257 + 562 + 264 + + + 0 + 0 + + 0 @@ -177,7 +183,7 @@ false - Anima&tions duration: + A&nimations duration: Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter @@ -380,6 +386,140 @@ + + + Transparency + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + Transparent + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + 0 + 0 + + + + Opaque + + + + + + + + + + + Menu: + + + + + + + 0 + + + 100 + + + 1 + + + 10 + + + 100 + + + Qt::Horizontal + + + false + + + false + + + QSlider::TicksBelow + + + 10 + + + + + + + + + Qt::Horizontal + + + QSizePolicy::Fixed + + + + 40 + 20 + + + + + + + + Qt::Horizontal + + + QSizePolicy::Preferred + + + + 542 + 20 + + + + + +