src/hbcore/gui/hbscrollbar.cpp
branchGCC_SURGE
changeset 15 f378acbc9cfb
parent 6 c3690ec91ef8
child 21 4633027730f5
child 34 ed14f46c0e55
equal deleted inserted replaced
9:730c025d4b77 15:f378acbc9cfb
    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 
   121     q->updatePrimitives();
   137     q->updatePrimitives();
   122 }
   138 }
   123 
   139 
   124 void HbScrollBarPrivate::updatePosition()
   140 void HbScrollBarPrivate::updatePosition()
   125 {
   141 {
   126     if(!mHandleGeometry.isValid() || !handleItem)
       
   127         return;
       
   128     if (handleItem){
   142     if (handleItem){
   129         if (mOrientation == Qt::Vertical) {
   143         if (mOrientation == Qt::Vertical) {
   130             handleItem->setPos(mHandleGeometry.topLeft().x(), mCurrentPosition * (mBoundingRect.height() - mHandleGeometry.height()));
   144             handleItem->setPos(mTopLeft, mCurrentPosition * mLimitingFactor);
   131         } else {
   145         } else {
   132             handleItem->setPos(mCurrentPosition * (mBoundingRect.width() - mHandleGeometry.width()), mHandleGeometry.topLeft().y());
   146             handleItem->setPos(mCurrentPosition * mLimitingFactor, mTopLeft);
   133         }
   147         }
   134     }
   148     }
   135 }
   149 }
   136 
   150 
   137 void HbScrollBarPrivate::sizeHelper()
   151 void HbScrollBarPrivate::sizeHelper()
   139     if(!polished)
   153     if(!polished)
   140         return;
   154         return;
   141     Q_Q(HbScrollBar);
   155     Q_Q(HbScrollBar);
   142     if(handleItem){
   156     if(handleItem){
   143         HbFrameItem *item = qgraphicsitem_cast<HbFrameItem*>(handleItem);
   157         HbFrameItem *item = qgraphicsitem_cast<HbFrameItem*>(handleItem);
   144         mBoundingRect = q->boundingRect();
   158         QRectF bRect = q->boundingRect();
   145         if(item){
   159         if(item){
   146             if (mOrientation == Qt::Vertical) {
   160             if (mOrientation == Qt::Vertical) {
   147                 qreal height(mPageSize * mBoundingRect.height());
   161                 qreal height(mPageSize * bRect.height());
   148                 if(!qFuzzyCompare(item->preferredHeight(),height)){
   162                 if(!qFuzzyCompare(item->preferredHeight(),height)){
   149                     item->setPreferredHeight(height);
   163                     item->setPreferredHeight(height);
   150                     item->resize(item->size().width(), height);
   164                     item->resize(item->size().width(), height);
   151                 }
   165                 }
       
   166                 mLimitingFactor =  bRect.height() - item->geometry().height();
       
   167                 mTopLeft = item->geometry().topLeft().x();
   152             } else {
   168             } else {
   153                 qreal width(mPageSize * mBoundingRect.width());
   169                 qreal width(mPageSize * bRect.width());
   154                 if(!qFuzzyCompare(item->preferredWidth(),width)){
   170                 if(!qFuzzyCompare(item->preferredWidth(),width)){
   155                     item->setPreferredWidth(width);
   171                     item->setPreferredWidth(width);
   156                     item->resize(width, item->size().height());
   172                     item->resize(width, item->size().height());
   157                 }
   173                 }
       
   174                 mLimitingFactor =  bRect.width() - item->geometry().width();
       
   175                 mTopLeft = item->geometry().topLeft().y();
   158             }
   176             }
   159             mHandleGeometry = item->geometry();
       
   160             updatePosition();
   177             updatePosition();
   161         }
   178         }
   162     }
   179     }
   163 }
   180 }
   164 
   181 
   237 /*!
   254 /*!
   238     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.
   239     The value corresponds to the position of the thumb.
   256     The value corresponds to the position of the thumb.
   240 
   257 
   241     \sa HbScrollBar::setValue()
   258     \sa HbScrollBar::setValue()
   242 */
   259  */
   243 qreal HbScrollBar::value() const
   260 qreal HbScrollBar::value() const
   244 {
   261 {
   245     Q_D( const HbScrollBar );
   262     Q_D( const HbScrollBar );
   246     return d->mCurrentPosition;
   263     return d->mCurrentPosition;
   247 }
   264 }
   251    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
   252    is five times larger than what is shown currently.
   269    is five times larger than what is shown currently.
   253 
   270 
   254    The size is in range of 0.0 to 1.0.
   271    The size is in range of 0.0 to 1.0.
   255    \sa HbScrollBar::setPageSize()
   272    \sa HbScrollBar::setPageSize()
   256 */
   273  */
   257 qreal HbScrollBar::pageSize() const
   274 qreal HbScrollBar::pageSize() const
   258 {
   275 {
   259     Q_D( const HbScrollBar );
   276     Q_D( const HbScrollBar );
   260     return d->mPageSize;
   277     return d->mPageSize;
   261 }
   278 }
   262 
   279 
   263 /*!
   280 /*!
   264     Returns the orientation of scrollbar.
   281     Returns the orientation of scrollbar.
   265 
   282 
   266     \sa HbScrollBar::setOrientation()
   283     \sa HbScrollBar::setOrientation()
   267 */
   284  */
   268 Qt::Orientation HbScrollBar::orientation() const
   285 Qt::Orientation HbScrollBar::orientation() const
   269 {
   286 {
   270     Q_D( const HbScrollBar );
   287     Q_D( const HbScrollBar );
   271     return d->mOrientation;
   288     return d->mOrientation;
   272 }
   289 }
   315 */
   332 */
   316 void HbScrollBar::setValue( qreal value )
   333 void HbScrollBar::setValue( qreal value )
   317 {
   334 {
   318     Q_D(HbScrollBar);        
   335     Q_D(HbScrollBar);        
   319 
   336 
   320     value = qBound(static_cast<qreal>(0.0), value, static_cast<qreal>(1.0));
   337     value = qBound(qreal(0.0), value, qreal(1.0));
   321     if( !qFuzzyCompare(d->mCurrentPosition,value )) {
   338     if( !qFuzzyCompare(d->mCurrentPosition,value )) {
   322         d->mCurrentPosition = value;
   339         d->mCurrentPosition = value;
   323         d->updatePosition();
   340         d->updatePosition();
   324     }
   341     }
   325 }
   342 }
   333     \sa HbScrollBar::pageSize()
   350     \sa HbScrollBar::pageSize()
   334 */
   351 */
   335 void HbScrollBar::setPageSize( qreal size )
   352 void HbScrollBar::setPageSize( qreal size )
   336 {
   353 {
   337     Q_D(HbScrollBar);
   354     Q_D(HbScrollBar);
   338     size = qBound(static_cast<qreal>(0.0), size, static_cast<qreal>(1.0));
   355     size = qBound(qreal(0.0), size, qreal(1.0));
   339 
   356 
   340     if(!qFuzzyCompare(d->mPageSize,size)) {
   357     if(!qFuzzyCompare(d->mPageSize,size)) {
   341         d->mPageSize = size;
   358         d->mPageSize = size;
   342         d->sizeHelper();
   359         d->sizeHelper();
   343     }
   360     }
   599 {
   616 {
   600     HbWidget::resizeEvent(event);
   617     HbWidget::resizeEvent(event);
   601     Q_D(HbScrollBar);
   618     Q_D(HbScrollBar);
   602     if (d->handleItem) {
   619     if (d->handleItem) {
   603         HbFrameItem* item = (qgraphicsitem_cast<HbFrameItem*>(d->handleItem));
   620         HbFrameItem* item = (qgraphicsitem_cast<HbFrameItem*>(d->handleItem));
   604         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         }
   605     }
   629     }
   606 }
   630 }
   607 
   631 
   608 /*!
   632 /*!
   609     \reimp
   633     \reimp