src/hbcore/gui/hbscrollbar.cpp
branchGCC_SURGE
changeset 15 f378acbc9cfb
parent 6 c3690ec91ef8
child 21 4633027730f5
child 34 ed14f46c0e55
--- a/src/hbcore/gui/hbscrollbar.cpp	Thu Jul 15 14:03:49 2010 +0100
+++ b/src/hbcore/gui/hbscrollbar.cpp	Thu Jul 22 16:36:53 2010 +0100
@@ -68,9 +68,24 @@
 /*!
     \fn void HbScrollBar::valueChanged( qreal value, Qt::Orientation orientation )
 
-    This signal is emitted when thumb position is changed from user interaction.
+    This signal is emitted when thumb position is changed by the user.
 */
 
+/*!
+    \fn void valueChangeRequested( qreal value, Qt::Orientation orientation );
+
+    This signal is emitted when the user presses scrollbar groove.
+
+    \param value, the new value of scrollbar after the change
+  */
+
+/*!
+    \primitives
+    \primitive{groove} HbFrameItem representing the groove of a scrollbar.
+    \primitive{handle} HbFrameItem representing the handle of a scrollbar.
+    \primitive{toucharea} HbTouchArea representing the scrollbar toucharea.
+  */
+
 HbScrollBarPrivate::HbScrollBarPrivate():
         mOrientation(Qt::Vertical),
         mCurrentPosition(0.5),
@@ -83,7 +98,8 @@
         grooveItem(0),
         handleItem(0),
         mTouchArea(0),
-        mBoundingRect(QRectF(0,0,0,0)),
+        mLimitingFactor(0.0),
+        mTopLeft(0.0),
         lastEmittedPos(QPointF()),
         emittedPos(false)
 {
@@ -123,13 +139,11 @@
 
 void HbScrollBarPrivate::updatePosition()
 {
-    if(!mHandleGeometry.isValid() || !handleItem)
-        return;
     if (handleItem){
         if (mOrientation == Qt::Vertical) {
-            handleItem->setPos(mHandleGeometry.topLeft().x(), mCurrentPosition * (mBoundingRect.height() - mHandleGeometry.height()));
+            handleItem->setPos(mTopLeft, mCurrentPosition * mLimitingFactor);
         } else {
-            handleItem->setPos(mCurrentPosition * (mBoundingRect.width() - mHandleGeometry.width()), mHandleGeometry.topLeft().y());
+            handleItem->setPos(mCurrentPosition * mLimitingFactor, mTopLeft);
         }
     }
 }
@@ -141,22 +155,25 @@
     Q_Q(HbScrollBar);
     if(handleItem){
         HbFrameItem *item = qgraphicsitem_cast<HbFrameItem*>(handleItem);
-        mBoundingRect = q->boundingRect();
+        QRectF bRect = q->boundingRect();
         if(item){
             if (mOrientation == Qt::Vertical) {
-                qreal height(mPageSize * mBoundingRect.height());
+                qreal height(mPageSize * bRect.height());
                 if(!qFuzzyCompare(item->preferredHeight(),height)){
                     item->setPreferredHeight(height);
                     item->resize(item->size().width(), height);
                 }
+                mLimitingFactor =  bRect.height() - item->geometry().height();
+                mTopLeft = item->geometry().topLeft().x();
             } else {
-                qreal width(mPageSize * mBoundingRect.width());
+                qreal width(mPageSize * bRect.width());
                 if(!qFuzzyCompare(item->preferredWidth(),width)){
                     item->setPreferredWidth(width);
                     item->resize(width, item->size().height());
                 }
+                mLimitingFactor =  bRect.width() - item->geometry().width();
+                mTopLeft = item->geometry().topLeft().y();
             }
-            mHandleGeometry = item->geometry();
             updatePosition();
         }
     }
@@ -239,7 +256,7 @@
     The value corresponds to the position of the thumb.
 
     \sa HbScrollBar::setValue()
-*/
+ */
 qreal HbScrollBar::value() const
 {
     Q_D( const HbScrollBar );
@@ -253,7 +270,7 @@
 
    The size is in range of 0.0 to 1.0.
    \sa HbScrollBar::setPageSize()
-*/
+ */
 qreal HbScrollBar::pageSize() const
 {
     Q_D( const HbScrollBar );
@@ -264,7 +281,7 @@
     Returns the orientation of scrollbar.
 
     \sa HbScrollBar::setOrientation()
-*/
+ */
 Qt::Orientation HbScrollBar::orientation() const
 {
     Q_D( const HbScrollBar );
@@ -317,7 +334,7 @@
 {
     Q_D(HbScrollBar);        
 
-    value = qBound(static_cast<qreal>(0.0), value, static_cast<qreal>(1.0));
+    value = qBound(qreal(0.0), value, qreal(1.0));
     if( !qFuzzyCompare(d->mCurrentPosition,value )) {
         d->mCurrentPosition = value;
         d->updatePosition();
@@ -335,7 +352,7 @@
 void HbScrollBar::setPageSize( qreal size )
 {
     Q_D(HbScrollBar);
-    size = qBound(static_cast<qreal>(0.0), size, static_cast<qreal>(1.0));
+    size = qBound(qreal(0.0), size, qreal(1.0));
 
     if(!qFuzzyCompare(d->mPageSize,size)) {
         d->mPageSize = size;
@@ -601,7 +618,14 @@
     Q_D(HbScrollBar);
     if (d->handleItem) {
         HbFrameItem* item = (qgraphicsitem_cast<HbFrameItem*>(d->handleItem));
-        d->mHandleGeometry = item->geometry();
+        QRectF geo = item->geometry();
+        if (d->mOrientation == Qt::Vertical) {
+            d->mTopLeft = geo.topLeft().x();
+            d->mLimitingFactor =  boundingRect().height() - geo.height();
+        } else {
+            d->mTopLeft = geo.topLeft().y();
+            d->mLimitingFactor =  boundingRect().width() - geo.width();
+        }
     }
 }