~ubuntu-branches/ubuntu/utopic/kde-workspace/utopic-proposed

« back to all changes in this revision

Viewing changes to kstyles/oxygen/oxygenframeshadow.h

  • Committer: Bazaar Package Importer
  • Author(s): Michał Zając
  • Date: 2011-07-09 08:31:15 UTC
  • Revision ID: james.westby@ubuntu.com-20110709083115-ohyxn6z93mily9fc
Tags: upstream-4.6.90
Import upstream version 4.6.90

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#ifndef oxygenframeshadow_h
 
2
#define oxygenframeshadow_h
 
3
 
 
4
//////////////////////////////////////////////////////////////////////////////
 
5
// oxygenframeshadow.h
 
6
// handle frames' shadows and rounded corners
 
7
// -------------------
 
8
//
 
9
// Copyright (c) 2010 Hugo Pereira Da Costa <hugo@oxygen-icons.org>
 
10
//
 
11
// Largely inspired from skulpture widget style
 
12
// Copyright (c) 2007-2009 Christoph Feck <christoph@maxiom.de>
 
13
//
 
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:
 
20
//
 
21
// The above copyright notice and this permission notice shall be included in
 
22
// all copies or substantial portions of the Software.
 
23
//
 
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
 
30
// IN THE SOFTWARE.
 
31
//////////////////////////////////////////////////////////////////////////////
 
32
 
 
33
#include <QtCore/QEvent>
 
34
#include <QtCore/QObject>
 
35
#include <QtCore/QSet>
 
36
 
 
37
#include <QtGui/QWidget>
 
38
#include <QtGui/QPaintEvent>
 
39
#include <KColorScheme>
 
40
 
 
41
#include "oxygenstylehelper.h"
 
42
 
 
43
namespace Oxygen
 
44
{
 
45
 
 
46
    //! shadow area
 
47
    enum ShadowArea {
 
48
        Unknown,
 
49
        Left,
 
50
        Top,
 
51
        Right,
 
52
        Bottom
 
53
    };
 
54
 
 
55
    //! shadow manager
 
56
    class FrameShadowFactory: public QObject
 
57
    {
 
58
 
 
59
        Q_OBJECT
 
60
 
 
61
        public:
 
62
 
 
63
        //! constructor
 
64
        FrameShadowFactory( QObject* parent ):
 
65
        QObject( parent )
 
66
        {}
 
67
 
 
68
        //! destructor
 
69
        virtual ~FrameShadowFactory( void )
 
70
        {}
 
71
 
 
72
        //! register widget
 
73
        bool registerWidget( QWidget*, StyleHelper& );
 
74
 
 
75
        //! unregister
 
76
        void unregisterWidget( QWidget* );
 
77
 
 
78
        //! true if widget is registered
 
79
        bool isRegistered( const QWidget* widget ) const
 
80
        { return _registeredWidgets.contains( widget ); }
 
81
 
 
82
        //! event filter
 
83
        virtual bool eventFilter( QObject*, QEvent*);
 
84
 
 
85
        //! set contrast
 
86
        void setHasContrast( const QWidget* widget, bool ) const;
 
87
 
 
88
        //! update state
 
89
        void updateState( const QWidget*, bool focus, bool hover, qreal opacity, AnimationMode ) const;
 
90
 
 
91
        protected:
 
92
 
 
93
        //! install shadows on given widget
 
94
        void installShadows( QWidget*, StyleHelper&, bool flat = false );
 
95
 
 
96
        //! remove shadows from widget
 
97
        void removeShadows( QWidget* );
 
98
 
 
99
        //! update shadows geometry
 
100
        void updateShadowsGeometry( QObject* ) const;
 
101
 
 
102
        //! raise shadows
 
103
        void raiseShadows( QObject* ) const;
 
104
 
 
105
        //! update shadows
 
106
        void update( QObject* ) const;
 
107
 
 
108
        //! install shadow on given side
 
109
        void installShadow( QWidget*, StyleHelper&, ShadowArea, bool flat = false ) const;
 
110
 
 
111
        protected slots:
 
112
 
 
113
        //! triggered by object destruction
 
114
        void widgetDestroyed( QObject* );
 
115
 
 
116
        private:
 
117
 
 
118
        //! set of registered widgets
 
119
        QSet<const QObject*> _registeredWidgets;
 
120
 
 
121
    };
 
122
 
 
123
    //! frame shadow
 
124
    /*! this allows the shadow to be painted over the widgets viewport */
 
125
    class FrameShadowBase: public QWidget
 
126
    {
 
127
 
 
128
        Q_OBJECT
 
129
 
 
130
        public:
 
131
 
 
132
        //! constructor
 
133
        explicit FrameShadowBase( ShadowArea area ):
 
134
            _area( area ),
 
135
            _contrast( false )
 
136
        {}
 
137
 
 
138
        //! destructor
 
139
        virtual ~FrameShadowBase( void )
 
140
        {}
 
141
 
 
142
        //! shadow area
 
143
        void setShadowArea(ShadowArea area)
 
144
        { _area = area; }
 
145
 
 
146
        //! shadow area
 
147
        const ShadowArea& shadowArea() const
 
148
        { return _area; }
 
149
 
 
150
        //! set contrast
 
151
        void setHasContrast( bool value )
 
152
        {
 
153
            if( _contrast == value ) return;
 
154
            _contrast = value;
 
155
            updateGeometry();
 
156
        }
 
157
 
 
158
        //! true if contrast pixel is enabled
 
159
        bool hasContrast( void ) const
 
160
        { return _contrast; }
 
161
 
 
162
        //! update geometry
 
163
        virtual void updateGeometry( void ) = 0;
 
164
 
 
165
        //! update state
 
166
        virtual void updateState( bool, bool, qreal, AnimationMode )
 
167
        {}
 
168
 
 
169
        protected:
 
170
 
 
171
        //! event handler
 
172
        virtual bool event(QEvent *e);
 
173
 
 
174
        //! initialization
 
175
        virtual void init();
 
176
 
 
177
        //! return viewport associated to parent widget
 
178
        virtual QWidget* viewport( void ) const;
 
179
 
 
180
        private:
 
181
 
 
182
        //! shadow area
 
183
        ShadowArea _area;
 
184
 
 
185
        //! contrast pixel
 
186
        bool _contrast;
 
187
 
 
188
    };
 
189
 
 
190
    //! frame shadow
 
191
    /*! this allows the shadow to be painted over the widgets viewport */
 
192
    class SunkenFrameShadow : public FrameShadowBase
 
193
    {
 
194
        Q_OBJECT
 
195
 
 
196
        public:
 
197
 
 
198
        //! constructor
 
199
        SunkenFrameShadow( ShadowArea area, StyleHelper& helper ):
 
200
            FrameShadowBase( area ),
 
201
            _helper( helper ),
 
202
            _viewFocusBrush( helper.viewFocusBrush() ),
 
203
            _viewHoverBrush( helper.viewHoverBrush() ),
 
204
            _focus( false ),
 
205
            _hover( false ),
 
206
            _opacity( -1 ),
 
207
            _mode( AnimationNone )
 
208
        { init(); }
 
209
 
 
210
 
 
211
        //! destructor
 
212
        virtual ~SunkenFrameShadow()
 
213
        {}
 
214
 
 
215
        //! update geometry
 
216
        virtual void updateGeometry( void );
 
217
 
 
218
        //! update state
 
219
        void updateState( bool focus, bool hover, qreal opacity, AnimationMode mode );
 
220
 
 
221
        protected:
 
222
 
 
223
        //! painting
 
224
        virtual void paintEvent(QPaintEvent *);
 
225
 
 
226
        private:
 
227
 
 
228
        //! shadow sizes
 
229
        enum
 
230
        {
 
231
            SHADOW_SIZE_TOP = 3,
 
232
            SHADOW_SIZE_BOTTOM = 3,
 
233
            SHADOW_SIZE_LEFT = 3,
 
234
            SHADOW_SIZE_RIGHT = 3
 
235
        };
 
236
 
 
237
        //! helper
 
238
        StyleHelper& _helper;
 
239
 
 
240
        KStatefulBrush _viewFocusBrush;
 
241
        KStatefulBrush _viewHoverBrush;
 
242
 
 
243
        //!@name widget state
 
244
        //@{
 
245
        bool _focus;
 
246
        bool _hover;
 
247
        qreal _opacity;
 
248
        AnimationMode _mode;
 
249
 
 
250
    };
 
251
 
 
252
 
 
253
    //! frame shadow
 
254
    /*! this allows the shadow to be painted over the widgets viewport */
 
255
    class FlatFrameShadow : public FrameShadowBase
 
256
    {
 
257
        Q_OBJECT
 
258
 
 
259
        public:
 
260
 
 
261
        //! constructor
 
262
        FlatFrameShadow( ShadowArea area, StyleHelper& helper ):
 
263
            FrameShadowBase( area ),
 
264
            _helper( helper )
 
265
        { init(); }
 
266
 
 
267
 
 
268
        //! destructor
 
269
        virtual ~FlatFrameShadow()
 
270
        {}
 
271
 
 
272
        //! update geometry
 
273
        virtual void updateGeometry( void );
 
274
 
 
275
        protected:
 
276
 
 
277
        //! painting
 
278
        virtual void paintEvent(QPaintEvent *);
 
279
 
 
280
        private:
 
281
 
 
282
        //! shadow sizes
 
283
        enum
 
284
        {
 
285
            SHADOW_SIZE_TOP = 5,
 
286
            SHADOW_SIZE_BOTTOM = 5,
 
287
            SHADOW_SIZE_LEFT = 5,
 
288
            SHADOW_SIZE_RIGHT = 5
 
289
        };
 
290
 
 
291
        //! helper
 
292
        StyleHelper& _helper;
 
293
 
 
294
    };
 
295
}
 
296
 
 
297
#endif