src/hbcore/gui/hbscrollbar.cpp
changeset 6 c3690ec91ef8
parent 5 627c4a0fd0e7
child 21 4633027730f5
child 34 ed14f46c0e55
equal deleted inserted replaced
5:627c4a0fd0e7 6:c3690ec91ef8
    66  */
    66  */
    67 
    67 
    68 /*!
    68 /*!
    69     \fn void HbScrollBar::valueChanged( qreal value, Qt::Orientation orientation )
    69     \fn void HbScrollBar::valueChanged( qreal value, Qt::Orientation orientation )
    70 
    70 
    71     This signal is emitted when thumb position is changed from user interaction.
    71     This signal is emitted when thumb position is changed by the user.
    72 */
    72 */
       
    73 
       
    74 /*!
       
    75     \fn void valueChangeRequested( qreal value, Qt::Orientation orientation );
       
    76 
       
    77     This signal is emitted when the user presses scrollbar groove.
       
    78 
       
    79     \param value, the new value of scrollbar after the change
       
    80   */
       
    81 
       
    82 /*!
       
    83     \primitives
       
    84     \primitive{groove} HbFrameItem representing the groove of a scrollbar.
       
    85     \primitive{handle} HbFrameItem representing the handle of a scrollbar.
       
    86     \primitive{toucharea} HbTouchArea representing the scrollbar toucharea.
       
    87   */
    73 
    88 
    74 HbScrollBarPrivate::HbScrollBarPrivate():
    89 HbScrollBarPrivate::HbScrollBarPrivate():
    75         mOrientation(Qt::Vertical),
    90         mOrientation(Qt::Vertical),
    76         mCurrentPosition(0.5),
    91         mCurrentPosition(0.5),
    77         mPageSize(1.0),
    92         mPageSize(1.0),
    81         mInteractive(false),
    96         mInteractive(false),
    82         mPressedTargetValue(0.0),
    97         mPressedTargetValue(0.0),
    83         grooveItem(0),
    98         grooveItem(0),
    84         handleItem(0),
    99         handleItem(0),
    85         mTouchArea(0),
   100         mTouchArea(0),
    86         mBoundingRect(QRectF(0,0,0,0)),
   101         mLimitingFactor(0.0),
       
   102         mTopLeft(0.0),
    87         lastEmittedPos(QPointF()),
   103         lastEmittedPos(QPointF()),
    88         emittedPos(false)
   104         emittedPos(false)
    89 {
   105 {
    90 }
   106 }
    91 
   107 
    96 void HbScrollBarPrivate::init()
   112 void HbScrollBarPrivate::init()
    97 {
   113 {
    98     Q_Q(HbScrollBar);
   114     Q_Q(HbScrollBar);
    99     q->grabGesture(Qt::PanGesture);
   115     q->grabGesture(Qt::PanGesture);
   100     q->grabGesture(Qt::TapGesture);
   116     q->grabGesture(Qt::TapGesture);
   101     q->setFlag(QGraphicsItem::ItemHasNoContents, true);
       
   102 }
   117 }
   103 
   118 
   104 void HbScrollBarPrivate::createPrimitives()
   119 void HbScrollBarPrivate::createPrimitives()
   105 {
   120 {
   106     Q_Q(HbScrollBar);
   121     Q_Q(HbScrollBar);
   122     q->updatePrimitives();
   137     q->updatePrimitives();
   123 }
   138 }
   124 
   139 
   125 void HbScrollBarPrivate::updatePosition()
   140 void HbScrollBarPrivate::updatePosition()
   126 {
   141 {
   127     if(!mHandleGeometry.isValid() || !handleItem)
       
   128         return;
       
   129     if (handleItem){
   142     if (handleItem){
   130         if (mOrientation == Qt::Vertical) {
   143         if (mOrientation == Qt::Vertical) {
   131             handleItem->setPos(mHandleGeometry.topLeft().x(), mCurrentPosition * (mBoundingRect.height() - mHandleGeometry.height()));
   144             handleItem->setPos(mTopLeft, mCurrentPosition * mLimitingFactor);
   132         } else {
   145         } else {
   133             handleItem->setPos(mCurrentPosition * (mBoundingRect.width() - mHandleGeometry.width()), mHandleGeometry.topLeft().y());
   146             handleItem->setPos(mCurrentPosition * mLimitingFactor, mTopLeft);
   134         }
   147         }
   135     }
   148     }
   136 }
   149 }
   137 
   150 
   138 void HbScrollBarPrivate::sizeHelper()
   151 void HbScrollBarPrivate::sizeHelper()
   140     if(!polished)
   153     if(!polished)
   141         return;
   154         return;
   142     Q_Q(HbScrollBar);
   155     Q_Q(HbScrollBar);
   143     if(handleItem){
   156     if(handleItem){
   144         HbFrameItem *item = qgraphicsitem_cast<HbFrameItem*>(handleItem);
   157         HbFrameItem *item = qgraphicsitem_cast<HbFrameItem*>(handleItem);
   145         mBoundingRect = q->boundingRect();
   158         QRectF bRect = q->boundingRect();
   146         if(item){
   159         if(item){
   147             if (mOrientation == Qt::Vertical) {
   160             if (mOrientation == Qt::Vertical) {
   148                 qreal height(mPageSize * mBoundingRect.height());
   161                 qreal height(mPageSize * bRect.height());
   149                 if(!qFuzzyCompare(item->preferredHeight(),height)){
   162                 if(!qFuzzyCompare(item->preferredHeight(),height)){
   150                     item->setPreferredHeight(height);
   163                     item->setPreferredHeight(height);
   151                     item->resize(item->size().width(), height);
   164                     item->resize(item->size().width(), height);
   152                 }
   165                 }
       
   166                 mLimitingFactor =  bRect.height() - item->geometry().height();
       
   167                 mTopLeft = item->geometry().topLeft().x();
   153             } else {
   168             } else {
   154                 qreal width(mPageSize * mBoundingRect.width());
   169                 qreal width(mPageSize * bRect.width());
   155                 if(!qFuzzyCompare(item->preferredWidth(),width)){
   170                 if(!qFuzzyCompare(item->preferredWidth(),width)){
   156                     item->setPreferredWidth(width);
   171                     item->setPreferredWidth(width);
   157                     item->resize(width, item->size().height());
   172                     item->resize(width, item->size().height());
   158                 }
   173                 }
       
   174                 mLimitingFactor =  bRect.width() - item->geometry().width();
       
   175                 mTopLeft = item->geometry().topLeft().y();
   159             }
   176             }
   160             mHandleGeometry = item->geometry();
       
   161             updatePosition();
   177             updatePosition();
   162         }
   178         }
   163     }
   179     }
   164 }
   180 }
   165 
   181 
   238 /*!
   254 /*!
   239     Returns the value of the scrollbar. The value is in range of 0.0 to 1.0.
   255     Returns the value of the scrollbar. The value is in range of 0.0 to 1.0.
   240     The value corresponds to the position of the thumb.
   256     The value corresponds to the position of the thumb.
   241 
   257 
   242     \sa HbScrollBar::setValue()
   258     \sa HbScrollBar::setValue()
   243 */
   259  */
   244 qreal HbScrollBar::value() const
   260 qreal HbScrollBar::value() const
   245 {
   261 {
   246     Q_D( const HbScrollBar );
   262     Q_D( const HbScrollBar );
   247     return d->mCurrentPosition;
   263     return d->mCurrentPosition;
   248 }
   264 }
   252    For example if the pageSize is 0.2 it means that the overall size of the content
   268    For example if the pageSize is 0.2 it means that the overall size of the content
   253    is five times larger than what is shown currently.
   269    is five times larger than what is shown currently.
   254 
   270 
   255    The size is in range of 0.0 to 1.0.
   271    The size is in range of 0.0 to 1.0.
   256    \sa HbScrollBar::setPageSize()
   272    \sa HbScrollBar::setPageSize()
   257 */
   273  */
   258 qreal HbScrollBar::pageSize() const
   274 qreal HbScrollBar::pageSize() const
   259 {
   275 {
   260     Q_D( const HbScrollBar );
   276     Q_D( const HbScrollBar );
   261     return d->mPageSize;
   277     return d->mPageSize;
   262 }
   278 }
   263 
   279 
   264 /*!
   280 /*!
   265     Returns the orientation of scrollbar.
   281     Returns the orientation of scrollbar.
   266 
   282 
   267     \sa HbScrollBar::setOrientation()
   283     \sa HbScrollBar::setOrientation()
   268 */
   284  */
   269 Qt::Orientation HbScrollBar::orientation() const
   285 Qt::Orientation HbScrollBar::orientation() const
   270 {
   286 {
   271     Q_D( const HbScrollBar );
   287     Q_D( const HbScrollBar );
   272     return d->mOrientation;
   288     return d->mOrientation;
   273 }
   289 }
   316 */
   332 */
   317 void HbScrollBar::setValue( qreal value )
   333 void HbScrollBar::setValue( qreal value )
   318 {
   334 {
   319     Q_D(HbScrollBar);        
   335     Q_D(HbScrollBar);        
   320 
   336 
   321     value = qBound(static_cast<qreal>(0.0), value, static_cast<qreal>(1.0));
   337     value = qBound(qreal(0.0), value, qreal(1.0));
   322     if( !qFuzzyCompare(d->mCurrentPosition,value )) {
   338     if( !qFuzzyCompare(d->mCurrentPosition,value )) {
   323         d->mCurrentPosition = value;
   339         d->mCurrentPosition = value;
   324         d->updatePosition();
   340         d->updatePosition();
   325     }
   341     }
   326 }
   342 }
   334     \sa HbScrollBar::pageSize()
   350     \sa HbScrollBar::pageSize()
   335 */
   351 */
   336 void HbScrollBar::setPageSize( qreal size )
   352 void HbScrollBar::setPageSize( qreal size )
   337 {
   353 {
   338     Q_D(HbScrollBar);
   354     Q_D(HbScrollBar);
   339     size = qBound(static_cast<qreal>(0.0), size, static_cast<qreal>(1.0));
   355     size = qBound(qreal(0.0), size, qreal(1.0));
   340 
   356 
   341     if(!qFuzzyCompare(d->mPageSize,size)) {
   357     if(!qFuzzyCompare(d->mPageSize,size)) {
   342         d->mPageSize = size;
   358         d->mPageSize = size;
   343         d->sizeHelper();
   359         d->sizeHelper();
   344     }
   360     }
   600 {
   616 {
   601     HbWidget::resizeEvent(event);
   617     HbWidget::resizeEvent(event);
   602     Q_D(HbScrollBar);
   618     Q_D(HbScrollBar);
   603     if (d->handleItem) {
   619     if (d->handleItem) {
   604         HbFrameItem* item = (qgraphicsitem_cast<HbFrameItem*>(d->handleItem));
   620         HbFrameItem* item = (qgraphicsitem_cast<HbFrameItem*>(d->handleItem));
   605         d->mHandleGeometry = item->geometry();
   621         QRectF geo = item->geometry();
       
   622         if (d->mOrientation == Qt::Vertical) {
       
   623             d->mTopLeft = geo.topLeft().x();
       
   624             d->mLimitingFactor =  boundingRect().height() - geo.height();
       
   625         } else {
       
   626             d->mTopLeft = geo.topLeft().y();
       
   627             d->mLimitingFactor =  boundingRect().width() - geo.width();
       
   628         }
   606     }
   629     }
   607 }
   630 }
   608 
   631 
   609 /*!
   632 /*!
   610     \reimp
   633     \reimp