Commit c5e48d76 authored by Hugo Pereira Da Costa's avatar Hugo Pereira Da Costa
Browse files

- 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
parent a513f4e0
......@@ -120,7 +120,6 @@ set(breeze_PART_SRCS
breezehelper.cpp
breezemdiwindowshadow.cpp
breezemnemonics.cpp
breezepalettehelper.cpp
breezepropertynames.cpp
breezeshadowhelper.cpp
breezesplitterproxy.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
......
......@@ -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;
......
/*************************************************************************
* 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;
}
}
#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
......@@ -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 );
......@@ -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<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 ) );
......
......@@ -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;
......
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