1
//////////////////////////////////////////////////////////////////////////////
3
// data container for QLabel transition
6
// Copyright (c) 2009 Hugo Pereira Da Costa <hugo@oxygen-icons.org>
8
// Permission is hereby granted, free of charge, to any person obtaining a copy
9
// of this software and associated documentation files (the "Software"), to
10
// deal in the Software without restriction, including without limitation the
11
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
12
// sell copies of the Software, and to permit persons to whom the Software is
13
// furnished to do so, subject to the following conditions:
15
// The above copyright notice and this permission notice shall be included in
16
// all copies or substantial portions of the Software.
18
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
25
//////////////////////////////////////////////////////////////////////////////
27
#include "oxygenlabeldata.h"
28
#include "oxygenlabeldata.moc"
30
#include <QtCore/QEvent>
31
#include <QtCore/QTextStream>
32
#include <QtGui/QPainter>
37
// use 300 milliseconds for animation lock
38
const int LabelData::_lockTime = 300;
40
//______________________________________________________
41
LabelData::LabelData( QObject* parent, QLabel* target, int duration ):
42
TransitionData( parent, target, duration ),
45
_target.data()->installEventFilter( this );
47
const bool hasProxy( _target.data()->graphicsProxyWidget() );
48
const bool hasMessageWidget( hasParent( target, "KMessageWidget" ) );
50
transition().data()->setFlags( hasProxy||hasMessageWidget ? TransitionWidget::Transparent : TransitionWidget::GrabFromWindow );
52
connect( _target.data(), SIGNAL( destroyed() ), SLOT( targetDestroyed() ) );
56
//___________________________________________________________________
57
bool LabelData::eventFilter( QObject* object, QEvent* event )
60
if( object != _target.data() ) return TransitionData::eventFilter( object, event );
61
switch( event->type() )
66
at show event, on set the old text to current
67
to avoid animate the "first" paint event.
68
text mnemonic is always removed to avoid triggering the animation when only the
71
_text = _target.data()->text().remove( '&' );
77
if( enabled() && _target )
80
// remove showMnemonic from text before comparing
81
QString text( _target.data()->text().remove( '&' ) );
86
transition().data()->isAnimated() &&
87
TransitionWidget::paintEnabled() ) return true;
91
// update text and pixmap
94
if( !(transition() && _target.data()->isVisible() ) ) break;
96
if( transition().data()->isAnimated() )
97
{ transition().data()->endAnimation(); }
99
// check whether animations are locked
103
// hide transition widget
104
transition().data()->hide();
106
// restart the lock timer
107
// and abort transition
112
// restart the lock timer
113
// and prepare transition
115
initializeAnimation();
116
_timer.start( 0, this );
118
if( !transition().data()->startPixmap().isNull() && TransitionWidget::paintEnabled() )
121
// show the transition widget
122
// and disable this event painting
123
transition().data()->show();
124
transition().data()->raise();
125
if( transparent() ) return true;
130
// hide transition widget and abort transition
131
transition().data()->hide();
136
} else if( transition().data()->isAnimated() && TransitionWidget::paintEnabled() ) {
138
// disable painting when transition is running
139
// since label is obscured by transition widget
148
return TransitionData::eventFilter( object, event );
152
//___________________________________________________________________
153
void LabelData::timerEvent( QTimerEvent* event )
155
if( event->timerId() == _timer.timerId() )
160
// check transition and widget validity
161
if( !( enabled() && _target && transition() ) ) return;
164
transition().data()->setEndPixmap( transition().data()->grab( _target.data() ) );
169
} else if( event->timerId() == _animationLockTimer.timerId() ) {
173
// check transition and widget validity
174
if( !( enabled() && _target && transition() ) ) return;
176
// reassign end pixmap for the next transition to be properly initialized
177
transition().data()->setEndPixmap( transition().data()->grab( _target.data() ) );
179
} else return TransitionData::timerEvent( event );
183
//___________________________________________________________________
184
bool LabelData::initializeAnimation( void )
187
transition().data()->setOpacity(0);
188
QRect current( _target.data()->geometry() );
189
if( _widgetRect.isValid() && _widgetRect != current )
192
_widgetRect = current;
193
transition().data()->resetStartPixmap();
194
transition().data()->resetEndPixmap();
199
transition().data()->setStartPixmap( transition().data()->currentPixmap() );
200
transition().data()->setGeometry( _target.data()->rect() );
201
_widgetRect = current;
205
//___________________________________________________________________
206
bool LabelData::animate( void )
209
if( transition().data()->startPixmap().isNull() ) return false;
211
transition().data()->animate();
216
//___________________________________________________________________
217
void LabelData::targetDestroyed( void )