src/hbcore/primitives/hbmarqueeitem.cpp
changeset 28 b7da29130b0e
parent 21 4633027730f5
child 30 80e4d18b72f5
--- a/src/hbcore/primitives/hbmarqueeitem.cpp	Thu Sep 02 20:44:51 2010 +0300
+++ b/src/hbcore/primitives/hbmarqueeitem.cpp	Fri Sep 17 08:32:10 2010 +0300
@@ -42,12 +42,17 @@
 #include <QPropertyAnimation>
 
 //#define HB_DEBUG_MARQUEE_DRAW_RECTS
+//#define HB_DEBUG_MARQUEE_LOGS
+#ifdef HB_DEBUG_MARQUEE_LOGS
+#include <QDebug>
+#endif
 
 namespace {
     // The bigger the value the slower the animation
-    static const qreal ANIMATION_SPEED_FACTOR = 2.5;
-    static const int ANIMATION_LEAD_TIME = 500;
-    static const int ANIMATION_IDENT_BY_PIXEL = 5;
+    static const int   ANIMATION_LEAD_TIME = 500;
+    static const int   ANIMATION_MAXIMUM_RETURN_TIME = 780;
+    static const qreal ANIMATION_IDENT_BY_MM = 8;
+    static const qreal ANIMATION_SPEED_METERS_PER_SEC = 0.012; // mm/ms
 
     static const QString DEFAULT_COLORGROUP = "qtc_view_normal";
 }
@@ -253,10 +258,16 @@
         qreal ppmValue = HbDeviceProfile::profile(q).ppmValue();
 
         // Calculate the offset for scrolling
-        qreal scrollOffsetX = content->mTextWidth+ANIMATION_IDENT_BY_PIXEL - q->contentsRect().width();
+        qreal ident = qMin(ANIMATION_IDENT_BY_MM * ppmValue, q->contentsRect().width());
+        qreal scrollOffsetX = content->mTextWidth+ident-q->contentsRect().width();
+        qreal v = ANIMATION_SPEED_METERS_PER_SEC*ppmValue; // pisxels per milisecond
+        int duration = qRound(scrollOffsetX/v);  // t = s/v in miliseconds
 
-        // animation duration depends on the length of the scrolled text and is not linear
-        int duration = (int)((qSqrt(scrollOffsetX)*1000*ANIMATION_SPEED_FACTOR)/ppmValue);
+#ifdef HB_DEBUG_MARQUEE_LOGS
+        qDebug() << "HbMarqueeItemPrivate::initAnimations "
+                << "scrollOffsetX" << scrollOffsetX
+                << "HbMarqueeItemPrivate::initAnimations duration" << dura;
+#endif // HB_DEBUG_MARQUEE_LOGS
 
         if (content->mTextDirection != Qt::LeftToRight) {
             scrollOffsetX = -scrollOffsetX;
@@ -278,7 +289,7 @@
         mAnimGroup.addAnimation(anim);
 
         anim = new QPropertyAnimation;
-        anim->setEasingCurve(QEasingCurve::SineCurve);
+        anim->setEasingCurve(QEasingCurve::Linear);
         anim->setTargetObject(content);
         anim->setPropertyName("pos");
         anim->setStartValue(content->pos());
@@ -289,6 +300,15 @@
         anim = new QPropertyAnimation;
         anim->setEasingCurve(QEasingCurve::Linear);
         anim->setTargetObject(content);
+        anim->setPropertyName("pos");
+        anim->setStartValue(scrolledOutPos);
+        anim->setEndValue(content->pos());
+        anim->setDuration(qMin(duration, ANIMATION_MAXIMUM_RETURN_TIME));
+        mAnimGroup.addAnimation(anim);
+
+        anim = new QPropertyAnimation;
+        anim->setEasingCurve(QEasingCurve::Linear);
+        anim->setTargetObject(content);
         anim->setPropertyName("alpha");
         anim->setEndValue(0);
         anim->setDuration(1000);