40 #include <qmath.h> |
40 #include <qmath.h> |
41 #include <QPainter> |
41 #include <QPainter> |
42 #include <QPropertyAnimation> |
42 #include <QPropertyAnimation> |
43 |
43 |
44 //#define HB_DEBUG_MARQUEE_DRAW_RECTS |
44 //#define HB_DEBUG_MARQUEE_DRAW_RECTS |
|
45 //#define HB_DEBUG_MARQUEE_LOGS |
|
46 #ifdef HB_DEBUG_MARQUEE_LOGS |
|
47 #include <QDebug> |
|
48 #endif |
45 |
49 |
46 namespace { |
50 namespace { |
47 // The bigger the value the slower the animation |
51 // The bigger the value the slower the animation |
48 static const qreal ANIMATION_SPEED_FACTOR = 2.5; |
52 static const int ANIMATION_LEAD_TIME = 500; |
49 static const int ANIMATION_LEAD_TIME = 500; |
53 static const int ANIMATION_MAXIMUM_RETURN_TIME = 780; |
50 static const int ANIMATION_IDENT_BY_PIXEL = 5; |
54 static const qreal ANIMATION_IDENT_BY_MM = 8; |
|
55 static const qreal ANIMATION_SPEED_METERS_PER_SEC = 0.012; // mm/ms |
51 |
56 |
52 static const QString DEFAULT_COLORGROUP = "qtc_view_normal"; |
57 static const QString DEFAULT_COLORGROUP = "qtc_view_normal"; |
53 } |
58 } |
54 |
59 |
55 |
60 |
251 |
256 |
252 // get pixel per millimeter value to ensure same animation speed on each device |
257 // get pixel per millimeter value to ensure same animation speed on each device |
253 qreal ppmValue = HbDeviceProfile::profile(q).ppmValue(); |
258 qreal ppmValue = HbDeviceProfile::profile(q).ppmValue(); |
254 |
259 |
255 // Calculate the offset for scrolling |
260 // Calculate the offset for scrolling |
256 qreal scrollOffsetX = content->mTextWidth+ANIMATION_IDENT_BY_PIXEL - q->contentsRect().width(); |
261 qreal ident = qMin(ANIMATION_IDENT_BY_MM * ppmValue, q->contentsRect().width()); |
257 |
262 qreal scrollOffsetX = content->mTextWidth+ident-q->contentsRect().width(); |
258 // animation duration depends on the length of the scrolled text and is not linear |
263 qreal v = ANIMATION_SPEED_METERS_PER_SEC*ppmValue; // pisxels per milisecond |
259 int duration = (int)((qSqrt(scrollOffsetX)*1000*ANIMATION_SPEED_FACTOR)/ppmValue); |
264 int duration = qRound(scrollOffsetX/v); // t = s/v in miliseconds |
|
265 |
|
266 #ifdef HB_DEBUG_MARQUEE_LOGS |
|
267 qDebug() << "HbMarqueeItemPrivate::initAnimations " |
|
268 << "scrollOffsetX" << scrollOffsetX |
|
269 << "HbMarqueeItemPrivate::initAnimations duration" << dura; |
|
270 #endif // HB_DEBUG_MARQUEE_LOGS |
260 |
271 |
261 if (content->mTextDirection != Qt::LeftToRight) { |
272 if (content->mTextDirection != Qt::LeftToRight) { |
262 scrollOffsetX = -scrollOffsetX; |
273 scrollOffsetX = -scrollOffsetX; |
263 } |
274 } |
264 |
275 |
276 anim->setEndValue(0xFF); |
287 anim->setEndValue(0xFF); |
277 anim->setDuration(1000); |
288 anim->setDuration(1000); |
278 mAnimGroup.addAnimation(anim); |
289 mAnimGroup.addAnimation(anim); |
279 |
290 |
280 anim = new QPropertyAnimation; |
291 anim = new QPropertyAnimation; |
281 anim->setEasingCurve(QEasingCurve::SineCurve); |
292 anim->setEasingCurve(QEasingCurve::Linear); |
282 anim->setTargetObject(content); |
293 anim->setTargetObject(content); |
283 anim->setPropertyName("pos"); |
294 anim->setPropertyName("pos"); |
284 anim->setStartValue(content->pos()); |
295 anim->setStartValue(content->pos()); |
285 anim->setEndValue(scrolledOutPos); |
296 anim->setEndValue(scrolledOutPos); |
286 anim->setDuration(duration); |
297 anim->setDuration(duration); |
|
298 mAnimGroup.addAnimation(anim); |
|
299 |
|
300 anim = new QPropertyAnimation; |
|
301 anim->setEasingCurve(QEasingCurve::Linear); |
|
302 anim->setTargetObject(content); |
|
303 anim->setPropertyName("pos"); |
|
304 anim->setStartValue(scrolledOutPos); |
|
305 anim->setEndValue(content->pos()); |
|
306 anim->setDuration(qMin(duration, ANIMATION_MAXIMUM_RETURN_TIME)); |
287 mAnimGroup.addAnimation(anim); |
307 mAnimGroup.addAnimation(anim); |
288 |
308 |
289 anim = new QPropertyAnimation; |
309 anim = new QPropertyAnimation; |
290 anim->setEasingCurve(QEasingCurve::Linear); |
310 anim->setEasingCurve(QEasingCurve::Linear); |
291 anim->setTargetObject(content); |
311 anim->setTargetObject(content); |