[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [breeze/Plasma/5.5] kstyle: - Removed palette helper.
From:       Hugo Pereira Da Costa <hugo.pereira () free ! fr>
Date:       2016-01-11 19:20:48
Message-ID: E1aIi1I-00081E-HL () scm ! kde ! org
[Download RAW message or body]

Git commit 2cae9359188af85ac884e2709c17592bc67b0e73 by Hugo Pereira Da Costa.
Committed on 11/01/2016 at 19:20.
Pushed by hpereiradacosta into branch 'Plasma/5.5'.

- 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

M  +0    -1    kstyle/CMakeLists.txt
M  +2    -37   kstyle/breezehelper.cpp
M  +0    -13   kstyle/breezehelper.h
D  +0    -188  kstyle/breezepalettehelper.cpp
D  +0    -94   kstyle/breezepalettehelper.h
M  +43   -15   kstyle/breezestyle.cpp
M  +0    -4    kstyle/breezestyle.h

http://commits.kde.org/breeze/2cae9359188af85ac884e2709c17592bc67b0e73

diff --git a/kstyle/CMakeLists.txt b/kstyle/CMakeLists.txt
index 08832c9..b2c6dc8 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 5b4bf7b..a0b95ff 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<QPalette::ColorGroup> 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<QPalette::ColorGroup> 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 cdc224b..1634468 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 f2eec41..0000000
--- a/kstyle/breezepalettehelper.cpp
+++ /dev/null
@@ -1,188 +0,0 @@
-/*************************************************************************
- * Copyright (C) 2014 by Hugo Pereira Da Costa <hugo.pereira@free.fr>    *
- *                                                                       *
- * 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 <QAbstractScrollArea>
-#include <QApplication>
-#include <QDockWidget>
-#include <QGroupBox>
-#include <QMenu>
-#include <QPalette>
-#include <QTabWidget>
-#include <QTextStream>
-#include <QTimer>
-
-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<QWidget*>( object ), qApp->palette() );
-            _registeredWidgets.insert( object );
-        }
-        _pendingWidgets.clear();
-    }
-
-    //_____________________________________________________
-    void PaletteHelper::adjustPalettes( const QPalette& palette )
-    {
-        foreach( QObject* object, _registeredWidgets )
-        { adjustPalette( static_cast<QWidget*>( 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<QAbstractScrollArea*>( 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<QGroupBox*>( widget ) ||
-            qobject_cast<QMenu*>( widget ) ||
-            widget->inherits( "QComboBoxPrivateContainer" ) )
-        {
-
-            widget->setPalette( _helper.framePalette( palette ) );
-            return true;
-
-        } else if( QTabWidget *tabWidget = qobject_cast<QTabWidget*>( widget ) ) {
-
-            if( !tabWidget->documentMode() )
-            {
-                widget->setPalette( _helper.framePalette( palette ) );
-                return true;
-            }
-
-        } else if( qobject_cast<QDockWidget*>( 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<QAbstractScrollArea*>( widget \
                );
-        if( scrollArea &&
-            !StyleConfigData::sidePanelDrawFrame() &&
-            ( widget->inherits( "KDEPrivate::KPageListView" ) ||
-            widget->inherits( "KDEPrivate::KPageTreeView" ) ||
-            widget->property( PropertyNames::sidePanelView ).toBool() ) )
-        {
-
-            return true;
-
-        } else if( qobject_cast<QGroupBox*>( widget ) ||
-            qobject_cast<QMenu*>( widget ) ||
-            widget->inherits( "QComboBoxPrivateContainer" ) )
-        {
-
-            return true;
-
-        } else if( QTabWidget *tabWidget = qobject_cast<QTabWidget*>( widget ) ) {
-
-            if( !tabWidget->documentMode() ) return true;
-
-        } else if( qobject_cast<QDockWidget*>( widget ) && \
                StyleConfigData::dockWidgetDrawFrame() ) {
-
-            return true;
-
-        }
-
-        return false;
-
-    }
-
-}
diff --git a/kstyle/breezepalettehelper.h b/kstyle/breezepalettehelper.h
deleted file mode 100644
index 5b73b21..0000000
--- a/kstyle/breezepalettehelper.h
+++ /dev/null
@@ -1,94 +0,0 @@
-#ifndef breezepalettehelper_h
-#define breezepalettehelper_h
-
-/*************************************************************************
- * Copyright (C) 2014 by Hugo Pereira Da Costa <hugo.pereira@free.fr>    *
- *                                                                       *
- * 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 <QObject>
-#include <QPalette>
-#include <QSet>
-#include <QWidget>
-
-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<QObject*> _pendingWidgets;
-
-        //* widget set
-        QSet<QObject*> _registeredWidgets;
-
-    };
-
-}
-
-#endif
diff --git a/kstyle/breezestyle.cpp b/kstyle/breezestyle.cpp
index 9743ad4..ec34bee 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<QGroupBox*>( widget ) )  {
 
@@ -289,7 +288,7 @@ namespace Breeze
             // remove opaque painting for scrollbars
             widget->setAttribute( Qt::WA_OpaquePaintEvent, false );
 
-        } else if( qobject_cast<QAbstractScrollArea*>( widget ) ) {
+        } else if( QAbstractScrollArea* scrollArea = \
qobject_cast<QAbstractScrollArea*>( 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 \
);  
@@ -5367,8 +5378,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<const \
QStyleOptionTabV3*>( 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<const QTabWidget *>( 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 cb11e1f..1024341 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;
 


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic