1 #include <QGraphicsWidget>
3 #include <QAbstractAnimation>
4 #include <QParallelAnimationGroup>
6 #include <QPropertyAnimation>
8 #include "proxyopacitysetter.h"
10 PulseBase::~PulseBase()
16 void PulseBase::start()
18 under
->setOpacity( 1 );
22 QRectF
PulseBase::geometry()
24 return under
->geometry();
28 void PulseBase::updateGeometry(QRectF updated
, qreal zCoordinate
, qreal scale
)
32 under
->setGeometry( updated
);
33 under
->setPos( 0, 0 );
34 under
->setOpacity( 0 );
35 under
->setZValue( zvalue
);
37 /* TODO: move this to a function */
38 QRectF
initial( under
->geometry() );
39 qreal W
= initial
.width() * scale
* 0.33;
40 qreal H
= initial
.height() * scale
* 0.33;
41 QRectF
end( initial
.x() - W
, initial
.y() - H
, initial
.width() * scale
,
42 initial
.height() * scale
);
43 anim2
->setEndValue(end
);
45 anim2
->setEndValue(end
);
50 void PulseBase::resetPulser()
52 under
->setGeometry( *pulseGeometry
);
53 under
->setOpacity( 0 );
54 under
->setZValue( zvalue
);
55 under
->setScale( mscale
);
58 void PulseBase::createAnimation( qreal duration
, qreal scale
,
59 ProxyOpacitySetter
*setter
)
62 pulseGeometry
= new QRectF( under
->geometry() );
63 QParallelAnimationGroup
*group
= new QParallelAnimationGroup(this);
64 anim1
= new QPropertyAnimation(under
, "opacity");
65 anim1
->setDuration(duration
);
66 anim1
->setEndValue(0);
67 group
->addAnimation(anim1
);
69 /* TODO: move this to a function */
70 anim2
= new QPropertyAnimation(under
, "geometry");
71 anim2
->setDuration(duration
);
72 QRectF
initial( under
->geometry() );
73 qreal W
= initial
.width() * scale
* 0.33;
74 qreal H
= initial
.height() * scale
* 0.33;
75 QRectF
end( initial
.x() - W
, initial
.y() - H
, initial
.width() * scale
,
76 initial
.height() * scale
);
77 anim2
->setEndValue(end
);
78 group
->addAnimation(anim2
);
80 anim3
= new QPropertyAnimation(under
, "scale");
81 anim3
->setDuration( duration
);
82 anim3
->setEndValue( scale
);
83 group
->addAnimation( anim3
);
87 connect( animation
, SIGNAL( finished() ), this, SLOT( resetPulser() ) );
91 //XXX: if someday exists a C++ compiler that works, use it!
92 // template <typename TYPE>
93 // Pulser<TYPE>::Pulser( TYPE *target, qreal duration, qreal scale,
94 // ProxyOpacitySetter *setter )
97 // TYPE *under = new TYPE( *target );
98 // under->setZValue( target->zValue() - 1 );
99 // under->setParentItem( target );
100 // QParallelAnimationGroup *group = new QParallelAnimationGroup(this);
101 // QPropertyAnimation *anim1 = new QPropertyAnimation(under, "opacity");
102 // anim1->setDuration(duration);
103 // anim1->setEndValue(0);
104 // group->addAnimation(anim1);
106 // QPropertyAnimation *anim2 = new QPropertyAnimation(under, "geometry");
107 // anim2->setDuration(duration);
109 // if ( under->geometry().x() != 0 )
110 // end = QRectF( under->geometry().x() - under->geometry().width() * scale,
111 // under->geometry().y() - under->geometry().height() * scale,
112 // under->geometry().width() * scale,
113 // under->geometry().height() * scale );
115 // end = QRectF( under->geometry().width() * -.25,
116 // under->geometry().height() * -.25,
117 // under->geometry().width() * scale,
118 // under->geometry().height() * scale );
121 // anim2->setEndValue(end);
122 // group->addAnimation(anim2);
123 // animation = group;