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

« back to all changes in this revision

Viewing changes to kstyles/oxygen/animations/oxygenheaderviewdata.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 oxygenheaderview_datah
 
2
#define oxygenheaderview_datah
 
3
 
 
4
//////////////////////////////////////////////////////////////////////////////
 
5
// oxygenheaderviewdata.h
 
6
// data container for QHeaderView animations
 
7
// -------------------
 
8
//
 
9
// Copyright (c) 2009 Hugo Pereira Da Costa <hugo@oxygen-icons.org>
 
10
//
 
11
// Permission is hereby granted, free of charge, to any person obtaining a copy
 
12
// of this software and associated documentation files (the "Software"), to
 
13
// deal in the Software without restriction, including without limitation the
 
14
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
 
15
// sell copies of the Software, and to permit persons to whom the Software is
 
16
// furnished to do so, subject to the following conditions:
 
17
//
 
18
// The above copyright notice and this permission notice shall be included in
 
19
// all copies or substantial portions of the Software.
 
20
//
 
21
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 
22
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 
23
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 
24
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 
25
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 
26
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 
27
// IN THE SOFTWARE.
 
28
//////////////////////////////////////////////////////////////////////////////
 
29
 
 
30
#include "oxygenanimationdata.h"
 
31
#include <QtGui/QHeaderView>
 
32
 
 
33
namespace Oxygen
 
34
{
 
35
 
 
36
    //! headerviews
 
37
    class HeaderViewData: public AnimationData
 
38
    {
 
39
 
 
40
        Q_OBJECT
 
41
 
 
42
        //! declare opacity property
 
43
        Q_PROPERTY( qreal currentOpacity READ currentOpacity WRITE setCurrentOpacity )
 
44
        Q_PROPERTY( qreal previousOpacity READ previousOpacity WRITE setPreviousOpacity )
 
45
 
 
46
        public:
 
47
 
 
48
        //! constructor
 
49
        HeaderViewData( QObject* parent, QWidget* target, int duration );
 
50
 
 
51
        //! destructor
 
52
        virtual ~HeaderViewData( void )
 
53
        {}
 
54
 
 
55
        //! duration
 
56
        void setDuration( int duration )
 
57
        {
 
58
            currentIndexAnimation().data()->setDuration( duration );
 
59
            previousIndexAnimation().data()->setDuration( duration );
 
60
        }
 
61
 
 
62
        //! update state
 
63
        bool updateState( const QPoint&, bool );
 
64
 
 
65
        //!@name current index handling
 
66
        //@{
 
67
 
 
68
        //! current opacity
 
69
        virtual qreal currentOpacity( void ) const
 
70
        { return _current._opacity; }
 
71
 
 
72
        //! current opacity
 
73
        virtual void setCurrentOpacity( qreal value )
 
74
        {
 
75
            value = digitize( value );
 
76
            if( _current._opacity == value ) return;
 
77
            _current._opacity = value;
 
78
            setDirty();
 
79
        }
 
80
 
 
81
        //! current index
 
82
        virtual int currentIndex( void ) const
 
83
        { return _current._index; }
 
84
 
 
85
        //! current index
 
86
        virtual void setCurrentIndex( int index )
 
87
        { _current._index = index; }
 
88
 
 
89
        //! current index animation
 
90
        virtual const Animation::Pointer& currentIndexAnimation( void ) const
 
91
        { return _current._animation; }
 
92
 
 
93
        //@}
 
94
 
 
95
        //!@name previous index handling
 
96
        //@{
 
97
 
 
98
        //! previous opacity
 
99
        virtual qreal previousOpacity( void ) const
 
100
        { return _previous._opacity; }
 
101
 
 
102
        //! previous opacity
 
103
        virtual void setPreviousOpacity( qreal value )
 
104
        {
 
105
            value = digitize( value );
 
106
            if( _previous._opacity == value ) return;
 
107
            _previous._opacity = value;
 
108
            setDirty();
 
109
        }
 
110
 
 
111
        //! previous index
 
112
        virtual int previousIndex( void ) const
 
113
        { return _previous._index; }
 
114
 
 
115
        //! previous index
 
116
        virtual void setPreviousIndex( int index )
 
117
        { _previous._index = index; }
 
118
 
 
119
        //! previous index Animation
 
120
        virtual const Animation::Pointer& previousIndexAnimation( void ) const
 
121
        { return _previous._animation; }
 
122
 
 
123
        //@}
 
124
 
 
125
        //! return Animation associated to action at given position, if any
 
126
        virtual Animation::Pointer animation( const QPoint& position ) const;
 
127
 
 
128
        //! return opacity associated to action at given position, if any
 
129
        virtual qreal opacity( const QPoint& position ) const;
 
130
 
 
131
        protected:
 
132
 
 
133
        //! dirty
 
134
        inline virtual void setDirty( void ) const;
 
135
 
 
136
        private:
 
137
 
 
138
        //! container for needed animation data
 
139
        class Data
 
140
        {
 
141
            public:
 
142
 
 
143
            //! default constructor
 
144
            Data( void ):
 
145
                _opacity(0),
 
146
                _index(-1)
 
147
            {}
 
148
 
 
149
            Animation::Pointer _animation;
 
150
            qreal _opacity;
 
151
            int _index;
 
152
        };
 
153
 
 
154
        //! current tab animation data (for hover enter animations)
 
155
        Data _current;
 
156
 
 
157
        //! previous tab animations data (for hover leave animations)
 
158
        Data _previous;
 
159
 
 
160
    };
 
161
 
 
162
 
 
163
    //__________________________________________________________
 
164
    void HeaderViewData::setDirty( void ) const
 
165
    {
 
166
        if( QHeaderView* header = qobject_cast<QHeaderView*>( target().data() ) )
 
167
        {
 
168
            const int firstIndex( qMin( previousIndex(), currentIndex() ) );
 
169
            const int lastIndex( qMax( previousIndex(), currentIndex() ) );
 
170
            if( firstIndex >= 0 ) header->headerDataChanged( header->orientation(), firstIndex, lastIndex );
 
171
            else if( lastIndex >= 0 ) header->headerDataChanged( header->orientation(), lastIndex, lastIndex );
 
172
        }
 
173
    }
 
174
 
 
175
 
 
176
}
 
177
 
 
178
#endif