1
#ifndef oxygenframeshadow_h
2
#define oxygenframeshadow_h
4
//////////////////////////////////////////////////////////////////////////////
6
// handle frames' shadows and rounded corners
9
// Copyright (c) 2010 Hugo Pereira Da Costa <hugo@oxygen-icons.org>
11
// Largely inspired from skulpture widget style
12
// Copyright (c) 2007-2009 Christoph Feck <christoph@maxiom.de>
14
// Permission is hereby granted, free of charge, to any person obtaining a copy
15
// of this software and associated documentation files (the "Software"), to
16
// deal in the Software without restriction, including without limitation the
17
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
18
// sell copies of the Software, and to permit persons to whom the Software is
19
// furnished to do so, subject to the following conditions:
21
// The above copyright notice and this permission notice shall be included in
22
// all copies or substantial portions of the Software.
24
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
25
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
27
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
28
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
29
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
31
//////////////////////////////////////////////////////////////////////////////
33
#include <QtCore/QEvent>
34
#include <QtCore/QObject>
35
#include <QtCore/QSet>
37
#include <QtGui/QWidget>
38
#include <QtGui/QPaintEvent>
39
#include <KColorScheme>
41
#include "oxygenstylehelper.h"
56
class FrameShadowFactory: public QObject
64
FrameShadowFactory( QObject* parent ):
69
virtual ~FrameShadowFactory( void )
73
bool registerWidget( QWidget*, StyleHelper& );
76
void unregisterWidget( QWidget* );
78
//! true if widget is registered
79
bool isRegistered( const QWidget* widget ) const
80
{ return _registeredWidgets.contains( widget ); }
83
virtual bool eventFilter( QObject*, QEvent*);
86
void setHasContrast( const QWidget* widget, bool ) const;
89
void updateState( const QWidget*, bool focus, bool hover, qreal opacity, AnimationMode ) const;
93
//! install shadows on given widget
94
void installShadows( QWidget*, StyleHelper&, bool flat = false );
96
//! remove shadows from widget
97
void removeShadows( QWidget* );
99
//! update shadows geometry
100
void updateShadowsGeometry( QObject* ) const;
103
void raiseShadows( QObject* ) const;
106
void update( QObject* ) const;
108
//! install shadow on given side
109
void installShadow( QWidget*, StyleHelper&, ShadowArea, bool flat = false ) const;
113
//! triggered by object destruction
114
void widgetDestroyed( QObject* );
118
//! set of registered widgets
119
QSet<const QObject*> _registeredWidgets;
124
/*! this allows the shadow to be painted over the widgets viewport */
125
class FrameShadowBase: public QWidget
133
explicit FrameShadowBase( ShadowArea area ):
139
virtual ~FrameShadowBase( void )
143
void setShadowArea(ShadowArea area)
147
const ShadowArea& shadowArea() const
151
void setHasContrast( bool value )
153
if( _contrast == value ) return;
158
//! true if contrast pixel is enabled
159
bool hasContrast( void ) const
160
{ return _contrast; }
163
virtual void updateGeometry( void ) = 0;
166
virtual void updateState( bool, bool, qreal, AnimationMode )
172
virtual bool event(QEvent *e);
177
//! return viewport associated to parent widget
178
virtual QWidget* viewport( void ) const;
191
/*! this allows the shadow to be painted over the widgets viewport */
192
class SunkenFrameShadow : public FrameShadowBase
199
SunkenFrameShadow( ShadowArea area, StyleHelper& helper ):
200
FrameShadowBase( area ),
202
_viewFocusBrush( helper.viewFocusBrush() ),
203
_viewHoverBrush( helper.viewHoverBrush() ),
207
_mode( AnimationNone )
212
virtual ~SunkenFrameShadow()
216
virtual void updateGeometry( void );
219
void updateState( bool focus, bool hover, qreal opacity, AnimationMode mode );
224
virtual void paintEvent(QPaintEvent *);
232
SHADOW_SIZE_BOTTOM = 3,
233
SHADOW_SIZE_LEFT = 3,
234
SHADOW_SIZE_RIGHT = 3
238
StyleHelper& _helper;
240
KStatefulBrush _viewFocusBrush;
241
KStatefulBrush _viewHoverBrush;
243
//!@name widget state
254
/*! this allows the shadow to be painted over the widgets viewport */
255
class FlatFrameShadow : public FrameShadowBase
262
FlatFrameShadow( ShadowArea area, StyleHelper& helper ):
263
FrameShadowBase( area ),
269
virtual ~FlatFrameShadow()
273
virtual void updateGeometry( void );
278
virtual void paintEvent(QPaintEvent *);
286
SHADOW_SIZE_BOTTOM = 5,
287
SHADOW_SIZE_LEFT = 5,
288
SHADOW_SIZE_RIGHT = 5
292
StyleHelper& _helper;