00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include <math.h>
00023
00024
00025
00026
00027 #include <kdebug.h>
00028 #include <kconfig.h>
00029
00030
00031 #include "introsprite.h"
00032
00033
00034 IntroSprite::IntroSprite(QString id, ThemeManager* theme, int advancePeriod, int no, QGraphicsScene* canvas)
00035 : Themable(id, theme), PixmapSprite(advancePeriod, no, canvas)
00036 {
00037 hide();
00038
00039 mAdvancePeriod = advancePeriod;
00040 mNo = no;
00041 mAnimationState = Idle;
00042
00043 if (theme) theme->updateTheme(this);
00044 }
00045
00046
00047
00048 IntroSprite::~IntroSprite()
00049 {
00050 }
00051
00052
00053
00054 void IntroSprite::changeTheme()
00055 {
00056 PixmapSprite::changeTheme();
00057 }
00058
00059
00060
00061 void IntroSprite::startIntro(QPointF start, QPointF end, double radius, double duration, double delay)
00062 {
00063 mStart = start;
00064 mEnd = end;
00065 mDuration = duration;
00066 mRadius = radius;
00067 mDelay = delay;
00068 mAnimationState = IntroDelay;
00069 mTime = 0;
00070 setPos(mStart.x()*getScale(), mStart.y()*getScale());
00071 show();
00072 }
00073
00074
00075
00076 void IntroSprite::startLinear(QPointF start, QPointF end, double duration)
00077 {
00078 mStart = start;
00079 mEnd = end;
00080 mDuration = duration;
00081 mAnimationState = LinearMove;
00082 mTime = 0;
00083 setPos(mStart.x()*getScale(), mStart.y()*getScale());
00084 show();
00085 }
00086
00087
00088
00089 void IntroSprite::startLinear(QPointF end, double duration)
00090 {
00091 mStart = QPointF(x()/getScale(), y()/getScale());
00092 mEnd = end;
00093 mDuration = duration;
00094 mAnimationState = LinearMove;
00095 mTime = 0;
00096 show();
00097 }
00098
00099
00100
00101 void IntroSprite::advance(int phase)
00102 {
00103
00104 if (phase == 0)
00105 {
00106 QGraphicsItem::advance(phase);
00107 return ;
00108 }
00109
00110 double scale = this->getScale();
00111
00112
00113 mTime += mAdvancePeriod;
00114
00115
00116 if (mAnimationState == IntroDelay)
00117 {
00118 if (mTime >= mDelay)
00119 {
00120 mAnimationState = IntroLinear1;
00121 mTime = 0.0;
00122 }
00123 }
00124
00125
00126 if (mAnimationState == IntroLinear1)
00127 {
00128 if (mTime >= 0.25*mDuration)
00129 {
00130 mAnimationState = IntroCircle;
00131 }
00132 else
00133 {
00134 double t = 2.0*mTime/mDuration;
00135 qreal x = mStart.x() + t*(mEnd.x()-mStart.x());
00136 qreal y = mStart.y() + t*(mEnd.y()-mStart.y());
00137 setPos(x*scale, y*scale);
00138 }
00139 }
00140
00141
00142 if (mAnimationState == IntroCircle)
00143 {
00144 if (mTime >= 0.75*mDuration)
00145 {
00146 mAnimationState = IntroLinear2;
00147 }
00148 else
00149 {
00150 double t = 2.0*(mTime/mDuration-0.25);
00151 double sign = 1.0;
00152 if (mStart.x() > 0.5) sign = -1.0;
00153 qreal cx = mStart.x() + 0.5*(mEnd.x()-mStart.x());
00154 qreal cy = mStart.y() + 0.5*(mEnd.y()-mStart.y());
00155 qreal x = cx + mRadius*sin(sign*t*2.0*M_PI);
00156 qreal y = cy-mRadius + mRadius*cos(sign*t*2.0*M_PI);
00157 setPos(x*scale, y*scale);
00158 }
00159 }
00160
00161
00162 if (mAnimationState == IntroLinear2)
00163 {
00164 if (mTime >= 1.00*mDuration)
00165 {
00166 mAnimationState = Idle;
00167 setPos(mEnd.x()*scale, mEnd.y()*scale);
00168 }
00169 else
00170 {
00171 double t = 2.0*(mTime/mDuration-0.75)+0.5;
00172 qreal x = mStart.x() + t*(mEnd.x()-mStart.x());
00173 qreal y = mStart.y() + t*(mEnd.y()-mStart.y());
00174 setPos(x*scale, y*scale);
00175 }
00176 }
00177
00178
00179 if (mAnimationState == LinearMove)
00180 {
00181 if (mTime >= mDuration)
00182 {
00183 mAnimationState = Idle;
00184 setPos(mEnd.x()*scale, mEnd.y()*scale);
00185 }
00186 else
00187 {
00188 double t = mTime/mDuration;
00189 qreal x = mStart.x() + t*(mEnd.x()-mStart.x());
00190 qreal y = mStart.y() + t*(mEnd.y()-mStart.y());
00191 setPos(x*scale, y*scale);
00192 }
00193 }
00194
00195 QGraphicsItem::advance(phase);
00196 }
00197