From c5e48d765ab7ea71b0a4e30fe6482ed7e7be026f Mon Sep 17 00:00:00 2001 From: Hugo Pereira Da Costa Date: Tue, 15 Dec 2015 15:47:29 +0100 Subject: [PATCH] - Removed palette helper. Special background for groupboxes, menus, etc is now handled directly in the painting routine rather than adjusting the palette. This was indeed breaking palette inheritance, and requiring hacks that apparently posed some performance regressions. - check documentMode to decide tab background color. BUG: 356561 BUG: 356343 --- kstyle/CMakeLists.txt | 1 - kstyle/breezehelper.cpp | 39 +------ kstyle/breezehelper.h | 13 --- kstyle/breezepalettehelper.cpp | 188 --------------------------------- kstyle/breezepalettehelper.h | 94 ----------------- kstyle/breezestyle.cpp | 58 +++++++--- kstyle/breezestyle.h | 4 - 7 files changed, 45 insertions(+), 352 deletions(-) delete mode 100644 kstyle/breezepalettehelper.cpp delete mode 100644 kstyle/breezepalettehelper.h diff --git a/kstyle/CMakeLists.txt b/kstyle/CMakeLists.txt index 08832c92..b2c6dc84 100644 --- a/kstyle/CMakeLists.txt +++ b/kstyle/CMakeLists.txt @@ -120,7 +120,6 @@ set(breeze_PART_SRCS breezehelper.cpp breezemdiwindowshadow.cpp breezemnemonics.cpp - breezepalettehelper.cpp breezepropertynames.cpp breezeshadowhelper.cpp breezesplitterproxy.cpp diff --git a/kstyle/breezehelper.cpp b/kstyle/breezehelper.cpp index a5f7a6c7..1c35f25f 100644 --- a/kstyle/breezehelper.cpp +++ b/kstyle/breezehelper.cpp @@ -145,43 +145,8 @@ namespace Breeze } //____________________________________________________________________ - QColor Helper::frameBackgroundColor( const QPalette& palette, QPalette::ColorGroup role ) const - { return KColorUtils::mix( palette.color( role, QPalette::Window ), palette.color( role, QPalette::Base ), 0.3 ); } - - //____________________________________________________________________ - QColor Helper::sidePanelBackgroundColor( const QPalette& palette, QPalette::ColorGroup role ) const - { return palette.color( role, QPalette::Window ); } - - //____________________________________________________________________ - QColor Helper::sidePanelForegroundColor( const QPalette& palette, QPalette::ColorGroup role ) const - { return palette.color( role, QPalette::WindowText ); } - - //____________________________________________________________________ - QPalette Helper::framePalette( const QPalette& palette ) const - { - QPalette copy( palette ); - - const QList groups = { QPalette::Disabled, QPalette::Active, QPalette::Inactive }; - foreach( const QPalette::ColorGroup& group, groups ) - { copy.setColor( group, QPalette::Window, frameBackgroundColor( palette, group ) ); } - - return copy; - } - - //____________________________________________________________________ - QPalette Helper::sideViewPalette( const QPalette& palette ) const - { - QPalette copy( palette ); - - const QList groups = { QPalette::Disabled, QPalette::Active, QPalette::Inactive }; - foreach( const QPalette::ColorGroup& group, groups ) - { - copy.setColor( group, QPalette::Base, sidePanelBackgroundColor( palette, group ) ); - copy.setColor( group, QPalette::Text, sidePanelForegroundColor( palette, group ) ); - } - - return copy; - } + QColor Helper::frameBackgroundColor( const QPalette& palette, QPalette::ColorGroup group ) const + { return KColorUtils::mix( palette.color( group, QPalette::Window ), palette.color( group, QPalette::Base ), 0.3 ); } //____________________________________________________________________ QColor Helper::arrowColor( const QPalette& palette, QPalette::ColorGroup group, QPalette::ColorRole role ) const diff --git a/kstyle/breezehelper.h b/kstyle/breezehelper.h index cdc224bd..16344687 100644 --- a/kstyle/breezehelper.h +++ b/kstyle/breezehelper.h @@ -112,7 +112,6 @@ namespace Breeze //* hover outline color, using animations QColor buttonHoverOutlineColor( const QPalette& ) const; - //* side panel outline color, using animations QColor sidePanelOutlineColor( const QPalette&, bool hasFocus = false, qreal opacity = AnimationData::OpacityInvalid, AnimationMode = AnimationNone ) const; @@ -123,18 +122,6 @@ namespace Breeze //* frame background color QColor frameBackgroundColor( const QPalette&, QPalette::ColorGroup ) const; - //* side panel background color - QColor sidePanelBackgroundColor( const QPalette&, QPalette::ColorGroup ) const; - - //* side panel foreground color - QColor sidePanelForegroundColor( const QPalette&, QPalette::ColorGroup ) const; - - //* return altered palette suitable for tinted frames - QPalette framePalette( const QPalette& ) const; - - //* return altered palette suitable for tinted frames - QPalette sideViewPalette( const QPalette& ) const; - //* arrow outline color QColor arrowColor( const QPalette&, QPalette::ColorGroup, QPalette::ColorRole ) const; diff --git a/kstyle/breezepalettehelper.cpp b/kstyle/breezepalettehelper.cpp deleted file mode 100644 index f2eec413..00000000 --- a/kstyle/breezepalettehelper.cpp +++ /dev/null @@ -1,188 +0,0 @@ -/************************************************************************* - * Copyright (C) 2014 by Hugo Pereira Da Costa * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * - *************************************************************************/ - -#include "breezepalettehelper.h" - -#include "breezehelper.h" -#include "breezepropertynames.h" -#include "breezestyleconfigdata.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace Breeze -{ - - //_____________________________________________________ - PaletteHelper::PaletteHelper( QObject* parent, Helper& helper ): - QObject( parent ), - _helper( helper ) - {} - - //_____________________________________________________ - PaletteHelper::~PaletteHelper() - { if( _widget ) _widget->deleteLater(); } - - //_____________________________________________________ - bool PaletteHelper::registerWidget( QWidget* widget ) - { - if( _registeredWidgets.contains( widget ) ) return false; - if( acceptWidget( widget ) ) - { - - if( !_widget ) - { - _widget = new QWidget(); - _widget->installEventFilter( this ); - } - - _pendingWidgets.insert( widget ); - connect( widget, SIGNAL(destroyed(QObject*)), SLOT(unregisterWidget(QObject*)) ); - - QTimer::singleShot( 0, this, SLOT(adjustPendingPalettes()) ); - - return true; - - } else return false; - - } - - //_____________________________________________________ - void PaletteHelper::unregisterWidget( QObject* object ) - { - _pendingWidgets.remove( object ); - _registeredWidgets.remove( object ); - } - - //_____________________________________________________ - bool PaletteHelper::eventFilter( QObject*, QEvent* event ) - { - if( event->type() == QEvent::ApplicationPaletteChange ) - { adjustPalettes( qApp->palette() ); } - - return false; - } - - - //_____________________________________________________ - void PaletteHelper::adjustPendingPalettes( void ) - { - foreach( QObject* object, _pendingWidgets ) - { - adjustPalette( static_cast( object ), qApp->palette() ); - _registeredWidgets.insert( object ); - } - _pendingWidgets.clear(); - } - - //_____________________________________________________ - void PaletteHelper::adjustPalettes( const QPalette& palette ) - { - foreach( QObject* object, _registeredWidgets ) - { adjustPalette( static_cast( object ), palette ); } - } - - //_____________________________________________________ - bool PaletteHelper::adjustPalette( QWidget* widget, const QPalette& palette ) const - { - - // force side panels as flat, on option, and change font to not-bold - QAbstractScrollArea *scrollArea = qobject_cast( widget ); - if( scrollArea && - !StyleConfigData::sidePanelDrawFrame() && - widget->property( PropertyNames::sidePanelView ).toBool() ) - { - - scrollArea->setPalette( _helper.sideViewPalette( palette ) ); - if( QWidget *viewport = scrollArea->viewport() ) - { viewport->setPalette( _helper.sideViewPalette( palette ) ); } - - return true; - - } else if( qobject_cast( widget ) || - qobject_cast( widget ) || - widget->inherits( "QComboBoxPrivateContainer" ) ) - { - - widget->setPalette( _helper.framePalette( palette ) ); - return true; - - } else if( QTabWidget *tabWidget = qobject_cast( widget ) ) { - - if( !tabWidget->documentMode() ) - { - widget->setPalette( _helper.framePalette( palette ) ); - return true; - } - - } else if( qobject_cast( widget ) && StyleConfigData::dockWidgetDrawFrame() ) { - - widget->setPalette( _helper.framePalette( palette ) ); - return true; - - } - - return false; - - } - - //_____________________________________________________ - bool PaletteHelper::acceptWidget( QWidget* widget ) const - { - - // force side panels as flat, on option, and change font to not-bold - QAbstractScrollArea *scrollArea = qobject_cast( widget ); - if( scrollArea && - !StyleConfigData::sidePanelDrawFrame() && - ( widget->inherits( "KDEPrivate::KPageListView" ) || - widget->inherits( "KDEPrivate::KPageTreeView" ) || - widget->property( PropertyNames::sidePanelView ).toBool() ) ) - { - - return true; - - } else if( qobject_cast( widget ) || - qobject_cast( widget ) || - widget->inherits( "QComboBoxPrivateContainer" ) ) - { - - return true; - - } else if( QTabWidget *tabWidget = qobject_cast( widget ) ) { - - if( !tabWidget->documentMode() ) return true; - - } else if( qobject_cast( widget ) && StyleConfigData::dockWidgetDrawFrame() ) { - - return true; - - } - - return false; - - } - -} diff --git a/kstyle/breezepalettehelper.h b/kstyle/breezepalettehelper.h deleted file mode 100644 index 5b73b21a..00000000 --- a/kstyle/breezepalettehelper.h +++ /dev/null @@ -1,94 +0,0 @@ -#ifndef breezepalettehelper_h -#define breezepalettehelper_h - -/************************************************************************* - * Copyright (C) 2014 by Hugo Pereira Da Costa * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * - *************************************************************************/ - -#include -#include -#include -#include - -namespace Breeze -{ - - //* forward declaration - class Helper; - - //* handle palette change - class PaletteHelper: public QObject - { - - Q_OBJECT - - public: - - //* constructor - PaletteHelper( QObject*, Helper& ); - - //* destructor - virtual ~PaletteHelper( void ); - - //* register widget - virtual bool registerWidget( QWidget* ); - - //* event filter - virtual bool eventFilter( QObject*, QEvent* event ); - - public Q_SLOTS: - - //* unregister widget - void unregisterWidget( QObject* ); - - protected Q_SLOTS: - - //* adjust palettes - void adjustPendingPalettes( void ); - - protected: - - //* adjust widget palette - bool acceptWidget( QWidget* ) const; - - //* adjust palettes - void adjustPalettes( const QPalette& ); - - //* adjust widget palette - bool adjustPalette( QWidget*, const QPalette& ) const; - - private: - - //* helper - const Helper& _helper; - - //* dummy widget - /** it is used to keep track of application palette changes */ - QWidget* _widget = nullptr; - - //* widget set - QSet _pendingWidgets; - - //* widget set - QSet _registeredWidgets; - - }; - -} - -#endif diff --git a/kstyle/breezestyle.cpp b/kstyle/breezestyle.cpp index 1e407fde..9d0d61b2 100644 --- a/kstyle/breezestyle.cpp +++ b/kstyle/breezestyle.cpp @@ -25,7 +25,6 @@ #include "breezehelper.h" #include "breezemdiwindowshadow.h" #include "breezemnemonics.h" -#include "breezepalettehelper.h" #include "breezepropertynames.h" #include "breezeshadowhelper.h" #include "breezesplitterproxy.h" @@ -163,7 +162,6 @@ namespace Breeze , _helper( new Helper( StyleConfigData::self()->sharedConfig() ) ) #endif - , _paletteHelper( new PaletteHelper( this, *_helper ) ) , _shadowHelper( new ShadowHelper( this, *_helper ) ) , _animations( new Animations( this ) ) , _mnemonics( new Mnemonics( this ) ) @@ -200,7 +198,6 @@ namespace Breeze //______________________________________________________________ Style::~Style( void ) { - delete _paletteHelper; delete _shadowHelper; delete _helper; } @@ -215,7 +212,6 @@ namespace Breeze _windowManager->registerWidget( widget ); _frameShadowFactory->registerWidget( widget, *_helper ); _mdiWindowShadowFactory->registerWidget( widget ); - _paletteHelper->registerWidget( widget ); _shadowHelper->registerWidget( widget ); _splitterFactory->registerWidget( widget ); @@ -259,7 +255,10 @@ namespace Breeze { widget->setAttribute( Qt::WA_Hover ); } if( scrollArea->viewport() && scrollArea->inherits( "KItemListContainer" ) && scrollArea->frameShape() == QFrame::NoFrame ) - { scrollArea->viewport()->setBackgroundRole( QPalette::Window ); } + { + scrollArea->viewport()->setBackgroundRole( QPalette::Window ); + scrollArea->viewport()->setForegroundRole( QPalette::WindowText ); + } } else if( QGroupBox* groupBox = qobject_cast( widget ) ) { @@ -289,7 +288,7 @@ namespace Breeze // remove opaque painting for scrollbars widget->setAttribute( Qt::WA_OpaquePaintEvent, false ); - } else if( qobject_cast( widget ) ) { + } else if( QAbstractScrollArea* scrollArea = qobject_cast( widget ) ) { addEventFilter( widget ); @@ -307,6 +306,19 @@ namespace Breeze font.setBold( false ); widget->setFont( font ); + if( !StyleConfigData::sidePanelDrawFrame() ) + { + scrollArea->setBackgroundRole( QPalette::Window ); + scrollArea->setForegroundRole( QPalette::WindowText ); + + if( scrollArea->viewport() ) + { + scrollArea->viewport()->setBackgroundRole( QPalette::Window ); + scrollArea->viewport()->setForegroundRole( QPalette::WindowText ); + } + + } + } } else if( widget->inherits( "KTextEditor::View" ) ) { @@ -393,7 +405,6 @@ namespace Breeze _animations->unregisterWidget( widget ); _frameShadowFactory->unregisterWidget( widget ); _mdiWindowShadowFactory->unregisterWidget( widget ); - _paletteHelper->unregisterWidget( widget ); _shadowHelper->unregisterWidget( widget ); _windowManager->unregisterWidget( widget ); _splitterFactory->unregisterWidget( widget ); @@ -1090,7 +1101,7 @@ namespace Breeze const QRect rect( widget->rect() ); const QPalette& palette( widget->palette() ); - const QColor background( palette.color( QPalette::Window ) ); + const QColor background( _helper->frameBackgroundColor( palette ) ); const QColor outline( _helper->frameOutlineColor( palette ) ); const bool hasAlpha( _helper->hasAlphaChannel( widget ) ); @@ -1124,7 +1135,7 @@ namespace Breeze // store palette and set colors const QPalette& palette( dockWidget->palette() ); - const QColor background( palette.color( QPalette::Window ) ); + const QColor background( _helper->frameBackgroundColor( palette ) ); const QColor outline( _helper->frameOutlineColor( palette ) ); // store rect @@ -3011,7 +3022,7 @@ namespace Breeze { const QPalette& palette( option->palette ); - const QColor background( palette.color( QPalette::Window ) ); + const QColor background( _helper->frameBackgroundColor( palette ) ); const QColor outline( _helper->frameOutlineColor( palette ) ); const bool hasAlpha( _helper->hasAlphaChannel( widget ) ); @@ -3021,7 +3032,7 @@ namespace Breeze } else if( option->styleObject && option->styleObject->inherits( "QQuickItem" ) ) { const QPalette& palette( option->palette ); - const QColor background( palette.color( QPalette::Window ) ); + const QColor background( _helper->frameBackgroundColor( palette ) ); const QColor outline( _helper->frameOutlineColor( palette ) ); const bool hasAlpha( _helper->hasAlphaChannel( widget ) ); @@ -3048,7 +3059,7 @@ namespace Breeze // normal frame const QPalette& palette( option->palette ); - const QColor background( palette.color( QPalette::Window ) ); + const QColor background( _helper->frameBackgroundColor( palette ) ); const QColor outline( _helper->frameOutlineColor( palette ) ); /* @@ -3117,7 +3128,7 @@ namespace Breeze // define colors const QPalette& palette( option->palette ); - const QColor background( palette.color( QPalette::Window ) ); + const QColor background( _helper->frameBackgroundColor( palette ) ); const QColor outline( _helper->frameOutlineColor( palette ) ); _helper->renderTabWidgetFrame( painter, rect, background, outline, corners ); @@ -5370,8 +5381,25 @@ namespace Breeze // color QColor color; - if( selected ) color = palette.color( QPalette::Window ); - else { + if( selected ) + { + + #if QT_VERSION >= 0x050000 + bool documentMode = tabOption->documentMode; + #else + bool documentMode = false; + if( const QStyleOptionTabV3* tabOptionV3 = qstyleoption_cast( option ) ) + { documentMode = tabOptionV3->documentMode; } + #endif + + // flag passed to QStyleOptionTab is unfortunately not reliable enough + // also need to check on parent widget + const QTabWidget *tabWidget = ( widget && widget->parentWidget() ) ? qobject_cast( widget->parentWidget() ) : nullptr; + documentMode |= ( tabWidget ? tabWidget->documentMode() : true ); + + color = documentMode ? palette.color( QPalette::Window ) : _helper->frameBackgroundColor( palette ); + + } else { const QColor normal( _helper->alphaColor( palette.color( QPalette::WindowText ), 0.2 ) ); const QColor hover( _helper->alphaColor( _helper->hoverColor( palette ), 0.2 ) ); diff --git a/kstyle/breezestyle.h b/kstyle/breezestyle.h index cb11e1fd..10243414 100644 --- a/kstyle/breezestyle.h +++ b/kstyle/breezestyle.h @@ -59,7 +59,6 @@ namespace Breeze class Helper; class MdiWindowShadowFactory; class Mnemonics; - class PaletteHelper; class ShadowHelper; class SplitterFactory; class WidgetExplorer; @@ -466,9 +465,6 @@ namespace Breeze //* helper Helper* _helper; - //* palette helper - PaletteHelper* _paletteHelper; - //* shadow helper ShadowHelper* _shadowHelper;