1
#ifndef oxygenheaderview_datah
2
#define oxygenheaderview_datah
4
//////////////////////////////////////////////////////////////////////////////
5
// oxygenheaderviewdata.h
6
// data container for QHeaderView animations
9
// Copyright (c) 2009 Hugo Pereira Da Costa <hugo@oxygen-icons.org>
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:
18
// The above copyright notice and this permission notice shall be included in
19
// all copies or substantial portions of the Software.
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
28
//////////////////////////////////////////////////////////////////////////////
30
#include "oxygenanimationdata.h"
31
#include <QtGui/QHeaderView>
37
class HeaderViewData: public AnimationData
42
//! declare opacity property
43
Q_PROPERTY( qreal currentOpacity READ currentOpacity WRITE setCurrentOpacity )
44
Q_PROPERTY( qreal previousOpacity READ previousOpacity WRITE setPreviousOpacity )
49
HeaderViewData( QObject* parent, QWidget* target, int duration );
52
virtual ~HeaderViewData( void )
56
void setDuration( int duration )
58
currentIndexAnimation().data()->setDuration( duration );
59
previousIndexAnimation().data()->setDuration( duration );
63
bool updateState( const QPoint&, bool );
65
//!@name current index handling
69
virtual qreal currentOpacity( void ) const
70
{ return _current._opacity; }
73
virtual void setCurrentOpacity( qreal value )
75
value = digitize( value );
76
if( _current._opacity == value ) return;
77
_current._opacity = value;
82
virtual int currentIndex( void ) const
83
{ return _current._index; }
86
virtual void setCurrentIndex( int index )
87
{ _current._index = index; }
89
//! current index animation
90
virtual const Animation::Pointer& currentIndexAnimation( void ) const
91
{ return _current._animation; }
95
//!@name previous index handling
99
virtual qreal previousOpacity( void ) const
100
{ return _previous._opacity; }
103
virtual void setPreviousOpacity( qreal value )
105
value = digitize( value );
106
if( _previous._opacity == value ) return;
107
_previous._opacity = value;
112
virtual int previousIndex( void ) const
113
{ return _previous._index; }
116
virtual void setPreviousIndex( int index )
117
{ _previous._index = index; }
119
//! previous index Animation
120
virtual const Animation::Pointer& previousIndexAnimation( void ) const
121
{ return _previous._animation; }
125
//! return Animation associated to action at given position, if any
126
virtual Animation::Pointer animation( const QPoint& position ) const;
128
//! return opacity associated to action at given position, if any
129
virtual qreal opacity( const QPoint& position ) const;
134
inline virtual void setDirty( void ) const;
138
//! container for needed animation data
143
//! default constructor
149
Animation::Pointer _animation;
154
//! current tab animation data (for hover enter animations)
157
//! previous tab animations data (for hover leave animations)
163
//__________________________________________________________
164
void HeaderViewData::setDirty( void ) const
166
if( QHeaderView* header = qobject_cast<QHeaderView*>( target().data() ) )
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 );