src/hbcore/gui/hbscrollarea.cpp
changeset 21 4633027730f5
parent 7 923ff622b8b9
child 23 e6ad4ef83b23
--- a/src/hbcore/gui/hbscrollarea.cpp	Tue Jul 06 14:36:53 2010 +0300
+++ b/src/hbcore/gui/hbscrollarea.cpp	Wed Aug 18 10:05:37 2010 +0300
@@ -42,19 +42,23 @@
  @beta
  @hbcore
  \class HbScrollArea
- \brief HbScrollArea provides a finger-touch enabled scrollable container class.  
- 
+ \brief HbScrollArea provides a finger-touch enabled scrollable container class.
+
  HbScrollArea handles the events need to scroll the contents placed inside it.  It also
  handles the display of scrollbar while scrolling is occurring.
- 
- HbScrollArea is used by constructing a QGraphicsWidget that contains the content to be
- displayed, then calling the setContentWidget() method.  The content widget must have its size
- set appropriately either by associating a layout with the widget or by explicitly setting
- the size (e.g. by calling QGraphicsWidget::setGeometry()).
- 
+
+ HbScrollArea is used by constructing a QGraphicsWidget widget that contains the content to be
+ displayed by calling the HbScrollArea::setContentWidget() method. Scrollarea resizes the content
+ widget by using QGraphicsWidget::sizeHint() function. This function returns the sizehint i.e.
+ height and width of the content widget which is constrained by scrollarea based on the scrollarea
+ direction.
+
+ If the scrollarea direction is Vertical, scrollarea resizes the width of the content widget
+ else if it is horizontal, it resizes the height of contect widget.
+
  The class can be used by itself to provide default scrolling behavior or can be
  subclassed to add touch feedback, selection feedback, etc.
- 
+
  By default, the class provides dragging, flicking with animated follow-on, a
  simple inertia algorithm for slowing the animated follow-on scrolling and
  a bounce-back algorithm for animating the content back to its bounding
@@ -764,6 +768,7 @@
                 }
                 if (sizeChanged) {
                     d->mContents->resize(newSize);
+                    d->updateScrollMetrics();
                 } else {
                     d->adjustContent();
                 }
@@ -1091,46 +1096,49 @@
  */
 void HbScrollArea::polish(HbStyleParameters& params)
 {
-    Q_D(HbScrollArea);
-
-    d->doLazyInit();
+    if (isVisible()) {
+        Q_D(HbScrollArea);
+        d->doLazyInit();
 
-    // fetch scrolling parameters from css
-    const QString SpeedFactor = "speed-factor";
-    const QString IntertiaSpeedFactor = "inertia-speed-factor";
-    const QString MaxScrollSpeed = "max-scroll-speed";
-    const QString SpringStrength = "spring-strength";
-    const QString SpringDampingFactor = "spring-damping-factor";
-    const QString FrictionPerMilliSecond = "friction";
+        // fetch scrolling parameters from css
+        const QLatin1String SpeedFactor("speed-factor");
+        const QLatin1String IntertiaSpeedFactor("inertia-speed-factor");
+        const QLatin1String MaxScrollSpeed("max-scroll-speed");
+        const QLatin1String SpringStrength("spring-strength");
+        const QLatin1String SpringDampingFactor("spring-damping-factor");
+        const QLatin1String FrictionPerMilliSecond("friction");
 
-    params.addParameter(SpeedFactor);
-    params.addParameter(IntertiaSpeedFactor);
-    params.addParameter(MaxScrollSpeed);
-    params.addParameter(SpringStrength);
-    params.addParameter(SpringDampingFactor);
-    params.addParameter(FrictionPerMilliSecond);
-    HbWidget::polish(params);
+        params.addParameter(SpeedFactor);
+        params.addParameter(IntertiaSpeedFactor);
+        params.addParameter(MaxScrollSpeed);
+        params.addParameter(SpringStrength);
+        params.addParameter(SpringDampingFactor);
+        params.addParameter(FrictionPerMilliSecond);
+        HbWidget::polish(params);
 
-    if (!params.value(SpeedFactor).isNull()) {
-        d->mSpeedFactor = params.value(SpeedFactor).toDouble();
-    }
-    if (!params.value(IntertiaSpeedFactor).isNull()) {
-        d->mInertiaSpeedFactor = params.value(IntertiaSpeedFactor).toDouble();
-    }
-    if (!params.value(MaxScrollSpeed).isNull()) {
-        d->mMaxScrollSpeed = params.value(MaxScrollSpeed).toDouble();
-    }
-    if (!params.value(SpringStrength).isNull()) {
-        d->mSpringStrength = params.value(SpringStrength).toDouble();
-    }
-    if (!params.value(SpringDampingFactor).isNull()) {
-        d->mSpringDampingFactor = params.value(SpringDampingFactor).toDouble();
-    }
-    if (!params.value(FrictionPerMilliSecond).isNull()) {
-        d->mFrictionPerMilliSecond = params.value(FrictionPerMilliSecond).toDouble();
-    }
-    if (d->mContinuationIndicators) {
-        d->updateIndicators(-d->mContents->pos());
+        if (!params.value(SpeedFactor).isNull()) {
+            d->mSpeedFactor = params.value(SpeedFactor).toDouble();
+        }
+        if (!params.value(IntertiaSpeedFactor).isNull()) {
+            d->mInertiaSpeedFactor = params.value(IntertiaSpeedFactor).toDouble();
+        }
+        if (!params.value(MaxScrollSpeed).isNull()) {
+            d->mMaxScrollSpeed = params.value(MaxScrollSpeed).toDouble();
+        }
+        if (!params.value(SpringStrength).isNull()) {
+            d->mSpringStrength = params.value(SpringStrength).toDouble();
+        }
+        if (!params.value(SpringDampingFactor).isNull()) {
+            d->mSpringDampingFactor = params.value(SpringDampingFactor).toDouble();
+        }
+        if (!params.value(FrictionPerMilliSecond).isNull()) {
+            d->mFrictionPerMilliSecond = params.value(FrictionPerMilliSecond).toDouble();
+        }
+        if (d->mContinuationIndicators) {
+            d->updateIndicators(-d->mContents->pos());
+        }
+    } else {
+        HbWidget::polish(params);
     }
 }
 
@@ -1149,6 +1157,41 @@
 }
 
 /*!
+ \reimp
+ */
+QPainterPath HbScrollArea::shape() const
+{
+    Q_D(const HbScrollArea);
+    if ( d->mClearCachedRect){
+        d->reCalculateCachedValue();
+    }
+    return d->mShape;
+}
+
+/*!
+ \reimp
+ */
+QRectF HbScrollArea::boundingRect() const
+
+{
+    Q_D(const HbScrollArea);
+    if (d->mClearCachedRect) {
+        d->reCalculateCachedValue();
+    }
+    return d->mBoundingRect;
+}
+
+/*!
+ \reimp
+ */
+void HbScrollArea::setGeometry(const QRectF& rect)
+{
+    Q_D(HbScrollArea);
+    d->mClearCachedRect = true;
+    HbWidget::setGeometry(rect);
+}
+
+/*!
     \reimp
 */
 void HbScrollArea::disconnectNotify (const char *signal)