src/hbcore/gui/hbscrollarea.cpp
changeset 0 16d8024aca5e
child 1 f7ac710697a9
equal deleted inserted replaced
-1:000000000000 0:16d8024aca5e
       
     1 /****************************************************************************
       
     2 **
       
     3 ** Copyright (C) 2008-2010 Nokia Corporation and/or its subsidiary(-ies).
       
     4 ** All rights reserved.
       
     5 ** Contact: Nokia Corporation (developer.feedback@nokia.com)
       
     6 **
       
     7 ** This file is part of the HbCore module of the UI Extensions for Mobile.
       
     8 **
       
     9 ** GNU Lesser General Public License Usage
       
    10 ** This file may be used under the terms of the GNU Lesser General Public
       
    11 ** License version 2.1 as published by the Free Software Foundation and
       
    12 ** appearing in the file LICENSE.LGPL included in the packaging of this file.
       
    13 ** Please review the following information to ensure the GNU Lesser General
       
    14 ** Public License version 2.1 requirements will be met:
       
    15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
       
    16 **
       
    17 ** In addition, as a special exception, Nokia gives you certain additional
       
    18 ** rights.  These rights are described in the Nokia Qt LGPL Exception
       
    19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
       
    20 **
       
    21 ** If you have questions regarding the use of this file, please contact
       
    22 ** Nokia at developer.feedback@nokia.com.
       
    23 **
       
    24 ****************************************************************************/
       
    25 
       
    26 #include "hbscrollarea.h"
       
    27 #include "hbscrollarea_p.h"
       
    28 #include "hbscrollbar.h"
       
    29 #include "hbdeviceprofile.h"
       
    30 #include <hbwidgetfeedback.h>
       
    31 #include <hbevent.h>
       
    32 
       
    33 #include <QDebug>
       
    34 
       
    35 /*!
       
    36  *  @stable
       
    37  *  @hbcore
       
    38  *  \class HbScrollArea
       
    39  *  \brief HbScrollArea provides a finger-touch enabled scrollable container class.  
       
    40  *
       
    41  *  HbScrollArea handles the events need to scroll the contents placed inside it.  It also
       
    42  *  handles the display of scrollbar while scrolling is occurring.
       
    43  *
       
    44  *  HbScrollArea is used by constructing a QGraphicsWidget that contains the content to be
       
    45  *  displayed, then calling the setContentWidget() method.  The content widget must have its size
       
    46  *  set appropriately either by associating a layout with the widget or by explicitly setting
       
    47  *  the size (e.g. by calling QGraphicsWidget::setGeometry()).
       
    48  * 
       
    49  *  The class can be used by itself to provide default scrolling behavior or can be
       
    50  *  subclassed to add touch feedback, selection feedback, etc.
       
    51  *
       
    52  *  By default, the class provides dragging, flicking with animated follow-on, a
       
    53  *  simple inertia algorithm for slowing the animated follow-on scrolling and
       
    54  *  a bounce-back algorithm for animating the content back to its bounding
       
    55  *  limits at the end of a drag or flick action.
       
    56  */
       
    57 
       
    58 /*!
       
    59  Here are the main properties of the class:
       
    60 
       
    61  \li HbScrollArea::scrollDirections     : 
       
    62  \li HbScrollArea::clampingStyle        : 
       
    63  \li HbScrollArea::scrollingStyle       : 
       
    64  \li HbScrollArea::showScrollBars       : 
       
    65  \li HbScrollArea::scrollBarWidth       :  
       
    66  \li HbScrollArea::scrollBarMargin      : 
       
    67  \li HbScrollArea::frictionEnabled      :
       
    68  \li HbScrollArea::handleLongPress      :  
       
    69  */
       
    70 
       
    71 /*!
       
    72     \property HbScrollArea::showScrollBars
       
    73     \brief
       
    74 */
       
    75 
       
    76 /*!
       
    77     \property HbScrollArea::scrollBarWidth
       
    78     \brief
       
    79 */
       
    80 
       
    81 /*!
       
    82     \property HbScrollArea::scrollBarMargin
       
    83     \brief
       
    84 */
       
    85 
       
    86 /*!
       
    87     \property HbScrollArea::scrollDirections
       
    88     \brief 
       
    89 */
       
    90 
       
    91 /*!
       
    92     \property HbScrollArea::clampingStyle
       
    93     \brief 
       
    94 */
       
    95 
       
    96 /*!
       
    97     \property HbScrollArea::scrollingStyle
       
    98     \brief 
       
    99 */
       
   100 
       
   101 /*!
       
   102     \property HbScrollArea::frictionEnabled
       
   103     \brief
       
   104 */
       
   105 
       
   106 /*!
       
   107     \property HbScrollArea::handleLongPress
       
   108     \brief 
       
   109 */
       
   110 
       
   111 /*!
       
   112     \property HbScrollArea::verticalScrollBarPolicy
       
   113     \brief
       
   114 */
       
   115 
       
   116 /*!
       
   117     \property HbScrollArea::horizontalScrollBarPolicy
       
   118     \brief
       
   119 */
       
   120 
       
   121 /*!
       
   122     \fn void HbScrollArea::scrollDirectionsChanged(Qt::Orientations newValue)
       
   123 
       
   124     This signal is emitted when scrolling direction is changed.
       
   125 */
       
   126 
       
   127 /*!
       
   128     \fn void HbScrollArea::gestureSceneFilterChanged(HbGestureSceneFilter* newFilter)
       
   129 
       
   130     This signal is emitted when gesture filters are changed.
       
   131 */
       
   132 
       
   133 /*!
       
   134     \fn void HbScrollArea::scrollingStarted()
       
   135 
       
   136     This signal is emitted whenever a scrolling action begins.
       
   137 */
       
   138 
       
   139 /*!
       
   140     \fn void HbScrollArea::scrollingEnded()
       
   141 
       
   142     This signal is emitted whenever a scrolling action ends.
       
   143 */
       
   144 
       
   145 /*!
       
   146     \fn void HbScrollArea::scrollPositionChanged(QPointF newposition)
       
   147     This signal is emitted when scroll position is changed.
       
   148 */
       
   149 
       
   150 /*!
       
   151     \enum HbScrollArea::ClampingStyle
       
   152 
       
   153     Clamping styles supported by HbScrollArea.
       
   154 
       
   155     This enum describes how scrolling is behaving when reaching boundaries of the content item.
       
   156 */
       
   157 /*!
       
   158     \var HbScrollArea::StrictClamping
       
   159 
       
   160     Scrolling is limited to the bounding rectangle of the content item.
       
   161 */
       
   162 /*!
       
   163     \var HbScrollArea::BounceBackClamping
       
   164 
       
   165     Scrolling can go beyond the bounding rectangle of the content item, but bounces back to the
       
   166     limits of the bounding rectangle when released or when inertia scrolling stops.
       
   167 */
       
   168 /*!
       
   169     \var HbScrollArea::NoClamping
       
   170 
       
   171     Scrolling is completely unclamped (this is usually used when the subclass implements its own).
       
   172 */
       
   173 /*!
       
   174     \enum HbScrollArea::ScrollingStyle
       
   175 
       
   176     Different scrolling styles supported by HbScrollArea.
       
   177 
       
   178     This enum describes how scroll area can be scrolled.
       
   179 */
       
   180 /*!
       
   181     \var HbScrollArea::Pan
       
   182 
       
   183     Dragging motion pans the view with no follow-on scrolling animation.
       
   184 */
       
   185 /*!
       
   186     \var HbScrollArea::PanOrFlick
       
   187 
       
   188     Dragging motion pans the view with no follow-on scrolling animation,
       
   189     quick flicking motion triggers scrolling animation.
       
   190 */
       
   191 /*!
       
   192     \var HbScrollArea::PanWithFollowOn
       
   193 
       
   194     Dragging motion pans the view, velocity at end of drag motion triggers follow-on animated scrolling.
       
   195 */
       
   196 
       
   197 /*!
       
   198     \enum HbScrollArea::ScrollBarPolicy
       
   199 
       
   200     This enum type describes the various visibility modes of HbScrollArea's scroll bars.
       
   201 */
       
   202 
       
   203 /*!
       
   204     \var HbScrollArea::ScrollBarAsNeeded
       
   205 
       
   206     HbScrollArea shows a scroll bar when the content is too large to fit and not otherwise.
       
   207 */
       
   208 /*!
       
   209     \var HbScrollArea::ScrollBarAlwaysOff
       
   210 
       
   211     HbScrollArea never shows a scroll bar.
       
   212 */
       
   213 /*!
       
   214     \var HbScrollArea::ScrollBarAlwaysOn
       
   215 
       
   216     HbScrollArea always shows a scroll bar.
       
   217 */
       
   218 /*!
       
   219     \var HbScrollArea::ScrollBarAutoHide
       
   220 
       
   221     HbScrollArea shows scroll bar for short period of time when the content is displayed or scrolled. Scroll bar is not shown if not needed.
       
   222 
       
   223     This is the default behavior.
       
   224 */
       
   225 
       
   226 /*!
       
   227  * Constructor
       
   228  *
       
   229  * \sa HbScrollArea::HbScrollArea
       
   230  */
       
   231 HbScrollArea::HbScrollArea(QGraphicsItem* parent) : 
       
   232         HbWidget( *new HbScrollAreaPrivate, parent )
       
   233 {
       
   234     Q_D( HbScrollArea );
       
   235     d->q_ptr = this;
       
   236     d->init();
       
   237 }
       
   238 
       
   239 HbScrollArea::HbScrollArea(HbScrollAreaPrivate &dd, QGraphicsItem *parent):
       
   240         HbWidget( dd, parent  )
       
   241 {
       
   242     Q_D( HbScrollArea );
       
   243     d->q_ptr = this;
       
   244     d->init();
       
   245 }
       
   246    
       
   247 /*!
       
   248  * Destructor
       
   249  *
       
   250  * \sa HbScrollArea::~HbScrollArea
       
   251  */
       
   252 HbScrollArea::~HbScrollArea()
       
   253 {
       
   254 }
       
   255 
       
   256 /*!
       
   257  * Returns a pointer to the QGraphicsWidget,which is the content of scrollable area.
       
   258  *
       
   259  * \sa HbScrollArea::setContentWidget()
       
   260  */
       
   261 QGraphicsWidget* HbScrollArea::contentWidget() const
       
   262 {
       
   263     Q_D( const HbScrollArea );
       
   264 
       
   265     return d->mContents;
       
   266 }
       
   267 
       
   268 /*!
       
   269  * Assigns the QGraphicsWidget that is to be scrolled.  The HbScrollArea widget takes ownership of
       
   270  * the QGraphicsWidget.
       
   271  *
       
   272  * \sa HbScrollArea::contentWidget()
       
   273  */
       
   274 void HbScrollArea::setContentWidget(QGraphicsWidget* contents)
       
   275 {
       
   276     Q_D( HbScrollArea );
       
   277 
       
   278     if ( contents == d->mContents ) {
       
   279         return;
       
   280     }
       
   281 
       
   282     d->stopAnimating();
       
   283 
       
   284     if (0 != d->mContents) {
       
   285         delete d->mContents;
       
   286     }
       
   287     d->mContents = contents;
       
   288     updateGeometry();
       
   289 
       
   290     if (0 != contents) {
       
   291         contents->setParentItem(this);
       
   292         contents->installEventFilter(this);
       
   293         d->adjustContent();
       
   294         setContinuationIndicators(d->mContinuationIndicators);
       
   295     } else {
       
   296         d->hideChildComponents();
       
   297     }
       
   298 }
       
   299 
       
   300 /*!
       
   301 Removes the content widget, which is set to the scrollarea and returns it.
       
   302 The ownership of the \a QGraphicsWidget is transferred to the caller.
       
   303 
       
   304 \note This function is particularly useful if one wants to switch between
       
   305 different contents without deleting previous content.
       
   306 
       
   307     \sa setContentWidget()
       
   308 */
       
   309 QGraphicsWidget *HbScrollArea::takeContentWidget()
       
   310 {
       
   311     Q_D(HbScrollArea);
       
   312     QGraphicsWidget* content = d->mContents;
       
   313     d->mContents = 0;
       
   314 
       
   315     // Reset the ownership
       
   316     if (content) {
       
   317         content->setParentItem(0);
       
   318         content->removeEventFilter(this);
       
   319     }
       
   320 
       
   321     d->hideChildComponents();
       
   322     return content;
       
   323 }
       
   324 
       
   325 /*!
       
   326  * Returns the value of the clampingStyle property
       
   327  *
       
   328  * \sa HbScrollArea::setClampingStyle()
       
   329  */
       
   330 HbScrollArea::ClampingStyle HbScrollArea::clampingStyle() const
       
   331 {
       
   332     Q_D( const HbScrollArea );
       
   333 
       
   334     return d->mClampingStyle;
       
   335 }
       
   336 
       
   337 /*!
       
   338  * Sets the clampingStyle property that controls how the scrolling is constrained
       
   339  * relative to the contents of the scrolling area.
       
   340  *
       
   341  * Possible values for the clamping style include:
       
   342  *
       
   343  *		StrictClamping - scrolling is limited to the bounding rectangle of the content item
       
   344  *		BounceBackClamping - scrolling can go beyond the bounding rectangle of the content item, but bounces back to the
       
   345  *						limits of the bounding rectangle when released or when inertia scrolling stops
       
   346  *		NoClamping - scrolling is completely unclamped (this is usually used when the subclass implements its own
       
   347  *						custom clamping behavior)
       
   348  *
       
   349  * The default value is BounceBackClamping.
       
   350  *
       
   351  * \sa HbScrollArea::clampingStyle()
       
   352  */
       
   353 void HbScrollArea::setClampingStyle(ClampingStyle value)
       
   354 {
       
   355     Q_D( HbScrollArea );
       
   356 
       
   357     d->mClampingStyle = value;
       
   358 }
       
   359 
       
   360 /*!
       
   361  * Returns the value of the scrollingStyle property
       
   362  *
       
   363  * \sa HbScrollArea::setScrollingStyle()
       
   364  */
       
   365 HbScrollArea::ScrollingStyle HbScrollArea::scrollingStyle() const
       
   366 {
       
   367     Q_D( const HbScrollArea );
       
   368 
       
   369     return d->mScrollingStyle;
       
   370 }
       
   371 
       
   372 /*!
       
   373  * Sets the scrollingStyle property that controls how the style of scrolling interaction
       
   374  * provided by the widget
       
   375  *
       
   376  * Possible values for the clamping style include:
       
   377  *
       
   378  *		Pan - dragging motion pans the view with no follow-on scrolling animation
       
   379  *		PanOrFlick - dragging motion pans the view with no follow-on scrolling animation, quick flicking motion triggers scrolling animation
       
   380  *		PanWithFollowOn - dragging motion pans the view, velocity at end of drag motion triggers follow-on animated scrolling
       
   381  *
       
   382  * The default value is PanWithFollowOn.
       
   383  *
       
   384  * \sa HbScrollArea::scrollingStyle()
       
   385  */
       
   386 void HbScrollArea::setScrollingStyle(ScrollingStyle value)
       
   387 {
       
   388     Q_D( HbScrollArea );
       
   389 
       
   390     bool isChanged = (d->mScrollingStyle != value);
       
   391 
       
   392     d->mScrollingStyle = value;
       
   393 
       
   394     if (isChanged) {
       
   395         d->updateGestures();
       
   396         emit gestureSceneFilterChanged( d->mGestureFilter );
       
   397     }
       
   398 }
       
   399 
       
   400 /*!
       
   401  * Returns the value of the scrollDirections property.
       
   402  *
       
   403  * \sa HbScrollArea::setScrollDirections()
       
   404  */
       
   405 Qt::Orientations HbScrollArea::scrollDirections() const
       
   406 {
       
   407     Q_D( const HbScrollArea );
       
   408 
       
   409     return d->mScrollDirections;
       
   410 }
       
   411 
       
   412 /*!
       
   413  * Sets the value of the scrollDirections property.  This value is of
       
   414  * type Qt::Orientations and can set to either Qt::Horizontal to enable horizontal scrolling,
       
   415  * Qt::Vertical to enable vertical scrolling or (Qt::Horizontal | Qt::Vertical) to enable
       
   416  * scrolling in both directions.
       
   417  *
       
   418  * The default value is Qt::Vertical.
       
   419  *
       
   420  * \sa HbScrollArea::scrollDirections()
       
   421  */
       
   422 void HbScrollArea::setScrollDirections(Qt::Orientations value)
       
   423 {
       
   424     Q_D( HbScrollArea );
       
   425 
       
   426     bool isChanged = (d->mScrollDirections != value);
       
   427 
       
   428     d->mScrollDirections = value;
       
   429 
       
   430     if (isChanged) {
       
   431         d->updateGestures();
       
   432 
       
   433         emit scrollDirectionsChanged( value );
       
   434 
       
   435         emit gestureSceneFilterChanged( d->mGestureFilter );
       
   436     }
       
   437 }
       
   438 
       
   439 /*!
       
   440  * Returns true if the inertia scrolling effect is enabled, false otherwise.
       
   441  *
       
   442  * \sa HbScrollArea::setFrictionEnabled()
       
   443  */
       
   444 bool HbScrollArea::frictionEnabled() const
       
   445 {
       
   446     Q_D( const HbScrollArea );
       
   447 
       
   448     return d->mFrictionEnabled;
       
   449 }
       
   450 
       
   451 /*!
       
   452  * Enables/disables the inertia scrolling effect.
       
   453  * By default, the inertia effect is enabled.
       
   454  *
       
   455  * \sa HbScrollArea::frictionEnabled()
       
   456  */
       
   457 void HbScrollArea::setFrictionEnabled(bool value)
       
   458 {
       
   459     Q_D( HbScrollArea );
       
   460 
       
   461     d->mFrictionEnabled = value;
       
   462 }
       
   463 
       
   464 /*!
       
   465  * Returns true if the scroll area handles
       
   466  * long press gestures, false otherwise
       
   467  *
       
   468  * \sa HbScrollArea::setHandleLongPress()
       
   469  */
       
   470 bool HbScrollArea::longPressEnabled() const
       
   471 {
       
   472     Q_D( const HbScrollArea );
       
   473 
       
   474     return d->mHandleLongPress;
       
   475 }
       
   476 
       
   477 /*!
       
   478  * Sets the value of the handleLongPress property.  This value is set
       
   479  * to true if the widget is to respond to long press gestures, false otherwise.
       
   480  *
       
   481  * The default value is false.
       
   482  *
       
   483  * \sa HbScrollArea::handleLongPress()
       
   484  */
       
   485 void HbScrollArea::setLongPressEnabled (bool value)
       
   486 {
       
   487     Q_D( HbScrollArea );
       
   488 
       
   489     bool isChanged = (d->mHandleLongPress != value);
       
   490 
       
   491     d->mHandleLongPress = value;
       
   492 
       
   493     if (isChanged) {
       
   494         d->updateGestures();
       
   495         emit gestureSceneFilterChanged( d->mGestureFilter );
       
   496     }
       
   497 }
       
   498 
       
   499 /*
       
   500  * \reimp
       
   501  */
       
   502 QVariant HbScrollArea::itemChange(GraphicsItemChange change, const QVariant &value)
       
   503 {
       
   504     Q_D( HbScrollArea );
       
   505 
       
   506     // ??? need to support other changes ???
       
   507     if ( change == QGraphicsItem::ItemSceneHasChanged ) {
       
   508         d->updateGestures();
       
   509 
       
   510         emit gestureSceneFilterChanged( d->mGestureFilter );
       
   511     } else if (change == QGraphicsItem::ItemVisibleHasChanged && d->mContents) {
       
   512         if (value.toBool() == true)
       
   513             d->adjustContent();
       
   514         else
       
   515             d->_q_hideScrollBars();
       
   516     }
       
   517 
       
   518     return HbWidget::itemChange(change, value);
       
   519 }
       
   520 
       
   521 /*! @beta
       
   522  * upGesture() is a virtual slot function that is called whenever an
       
   523  * up flick gesture is detected, if the scrollDirection is set to
       
   524  * enable vertical scrolling.
       
   525  *
       
   526  * Derived classes can override this method to add custom handling of
       
   527  * the gesture.  In most cases, derived classes should call up to the
       
   528  * HbScrollArea parent method.
       
   529  *
       
   530  */
       
   531 void HbScrollArea::upGesture(int speedPixelsPerSecond)
       
   532 {
       
   533     Q_D( HbScrollArea );
       
   534 
       
   535     // convert the speedPixelsPerSecond to pixels per msec
       
   536     QPointF speed;
       
   537     speed.setX(0.0f);
       
   538     speed.setY(-speedPixelsPerSecond * d->mSpeedFactor);
       
   539     d->animateScroll(speed);
       
   540 }
       
   541 
       
   542 /*! @beta
       
   543  * downGesture() is a virtual slot function that is called whenever an
       
   544  * down flick gesture is detected, if the scrollDirection is set to
       
   545  * enable vertical scrolling. 
       
   546  *
       
   547  * Derived classes can override this method to add custom handling of
       
   548  * the gesture.  In most cases, derived classes should call up to the
       
   549  * HbScrollArea parent method.
       
   550  */
       
   551 void HbScrollArea::downGesture(int speedPixelsPerSecond)
       
   552 {
       
   553     Q_D( HbScrollArea );
       
   554 
       
   555     // convert the speedPixelsPerSecond to pixels per msec
       
   556     QPointF speed;
       
   557     speed.setX(0.0f);
       
   558     speed.setY(speedPixelsPerSecond * d->mSpeedFactor);
       
   559     d->animateScroll(speed);
       
   560 }
       
   561 
       
   562 /*! @beta
       
   563  * leftGesture() is a virtual slot function that is called whenever an
       
   564  * left flick gesture is detected, if the scrollDirection is set to
       
   565  * enable horizontal scrolling.
       
   566  *
       
   567  * Derived classes can override this method to add custom handling of
       
   568  * the gesture.  In most cases, derived classes should call up to the
       
   569  * HbScrollArea parent method.
       
   570  */
       
   571 void HbScrollArea::leftGesture(int speedPixelsPerSecond)
       
   572 {
       
   573     Q_D( HbScrollArea );
       
   574     
       
   575     // convert the speedPixelsPerSecond to pixels per msec
       
   576     QPointF speed;
       
   577     speed.setX(-speedPixelsPerSecond * d->mSpeedFactor);
       
   578     speed.setY(0.0f);
       
   579     d->animateScroll(speed);
       
   580 }
       
   581 
       
   582 /*! @beta
       
   583  * rightGesture() is a virtual slot function that is called whenever an
       
   584  * right flick gesture is detected, if the scrollDirection is set to
       
   585  * enable horizontal scrolling.
       
   586  *
       
   587  * Derived classes can override this method to add custom handling of
       
   588  * the gesture.  In most cases, derived classes should call up to the
       
   589  * HbScrollArea parent method.
       
   590  */
       
   591 void HbScrollArea::rightGesture(int speedPixelsPerSecond)
       
   592 {
       
   593     Q_D( HbScrollArea );
       
   594     
       
   595     // convert the speedPixelsPerSecond to pixels per msec
       
   596     QPointF speed;
       
   597     speed.setX(speedPixelsPerSecond * d->mSpeedFactor);
       
   598     speed.setY(0.0f);
       
   599     d->animateScroll(speed);
       
   600 }
       
   601 
       
   602 /*!  @beta
       
   603  * panGesture() is a virtual slot function that is called whenever an
       
   604  * pan gesture is detected.
       
   605  *
       
   606  * Derived classes can override this method to add custom handling of
       
   607  * the gesture.  In most cases, derived classes should call up to the
       
   608  * HbScrollArea parent method.
       
   609  */
       
   610 void HbScrollArea::panGesture(const QPointF &delta)
       
   611 {
       
   612     Q_D( HbScrollArea );
       
   613     if ( d->mIsAnimating ) {
       
   614         d->stopAnimating();
       
   615     }
       
   616     if (scrollingStyle() == HbScrollArea::PanWithFollowOn) {
       
   617         d->addPositionToQueue(-delta, d->mDragElapsedTime.elapsed(), true);
       
   618     }
       
   619     if (d->mAbleToScrollY || d->mAbleToScrollX) {
       
   620         // initiate scroll feedback
       
   621         HbWidgetFeedback::continuousTriggered(this, Hb::ContinuousScrolled, delta);
       
   622         d->mScrollFeedbackOngoing = true;
       
   623     }
       
   624     scrollByAmount(-delta);
       
   625 }
       
   626 
       
   627 /*!  @beta
       
   628  * longPressGesture() is a virtual slot function that is called whenever an
       
   629  * long press gesture is detected, if the handleLongPress property is set to true.
       
   630  *
       
   631  * Derived classes can override this method to add custom handling of
       
   632  * the gesture.  By default, HbScrollArea does not respond to a long press.
       
   633  *
       
   634  * \sa setHandleLongPress(), handleLongPress()
       
   635  */
       
   636 void HbScrollArea::longPressGesture(const QPointF &/* point */)
       
   637 {
       
   638     //	qDebug() << "GOT LONG PRESS GESTURE" << point;
       
   639 }
       
   640 
       
   641 /*
       
   642     \reimp
       
   643  */
       
   644 void HbScrollArea::mousePressEvent(QGraphicsSceneMouseEvent *event)
       
   645 {
       
   646     Q_D( HbScrollArea );
       
   647     if (d->mContents) {
       
   648         d->mousePressEvent( event );
       
   649     }
       
   650 }
       
   651 
       
   652 /*
       
   653     \reimp
       
   654  */
       
   655 void HbScrollArea::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
       
   656 {    
       
   657     Q_D( HbScrollArea );
       
   658     if (d->mContents) {
       
   659         d->mouseReleaseEvent ( event );
       
   660     }
       
   661 }
       
   662 
       
   663 /*!
       
   664  * Returns true if a scrolling action is in progress, false otherwise.
       
   665  */
       
   666 bool HbScrollArea::isScrolling() const
       
   667 {
       
   668     Q_D( const HbScrollArea );
       
   669 
       
   670     return d->mIsScrolling;
       
   671 }
       
   672 
       
   673 /*!
       
   674  * Returns true if the scrolling is due to dragging as opposed to follow-on scrolling
       
   675  */
       
   676 bool HbScrollArea::isDragging() const
       
   677 {
       
   678     Q_D( const HbScrollArea );
       
   679 
       
   680     return (d->mIsScrolling && !d->mIsAnimating);
       
   681 }
       
   682 
       
   683 /*!
       
   684  * Scrolls the view by the amount indicated by "delta".
       
   685  *
       
   686  * The function returns TRUE if the view was able to scroll, FALSE otherwise.
       
   687  *
       
   688  * The function is virtual so subclasses can override it to customize the behavior by, for example, 
       
   689  * clamping the position so that at least one item in the view remains visible.
       
   690  */
       
   691 bool HbScrollArea::scrollByAmount(const QPointF& delta)
       
   692 {
       
   693     Q_D( HbScrollArea );
       
   694 
       
   695     return d->scrollByAmount(delta);
       
   696 }
       
   697 
       
   698 #if 0
       
   699 
       
   700 bool HbScrollArea::sceneEvent(QEvent *event)
       
   701 {
       
   702     Q_D( HbScrollArea );
       
   703     bool eventAccepted(false);
       
   704     eventAccepted = d->sceneEvent(event);
       
   705     if(!eventAccepted);
       
   706         eventAccepted = HbWidget::sceneEvent(event);
       
   707     return eventAccepted;
       
   708 }
       
   709 
       
   710 #endif // HB_NEW_GESTURE_FW
       
   711 
       
   712 /*!
       
   713    \reimp
       
   714  */
       
   715 bool HbScrollArea::event(QEvent *event)
       
   716 {
       
   717     Q_D(HbScrollArea);
       
   718     bool value(false);
       
   719     if(event) {
       
   720         value = HbWidget::event(event);
       
   721         if(event->type() == QEvent::ApplicationLayoutDirectionChange
       
   722                    || event->type() == QEvent::LayoutDirectionChange) {
       
   723              d->changeLayoutDirection(layoutDirection());
       
   724         } else if (event->type() == QEvent::GraphicsSceneResize) {
       
   725             if (isVisible() && d->mContents) {
       
   726                 d->orientationChanged();
       
   727             }
       
   728         }  else if (event->type() == HbEvent::ChildFocusOut) {
       
   729             //qDebug() << "focusout";
       
   730             if ( !d->positionOutOfBounds() ) {
       
   731                 d->stopAnimating();
       
   732             }
       
   733         }
       
   734     }
       
   735   return value;
       
   736 }
       
   737 
       
   738 /*!
       
   739    \reimp
       
   740  */
       
   741 bool HbScrollArea::eventFilter(QObject *obj, QEvent *event)
       
   742 {
       
   743     Q_UNUSED(obj);
       
   744     Q_D(HbScrollArea);
       
   745     if (event && event->type() == QEvent::GraphicsSceneResize) {
       
   746         if (isVisible()) {            
       
   747             d->adjustContent();
       
   748         }
       
   749     }  // no else
       
   750 
       
   751     return false;
       
   752 }
       
   753 
       
   754 /*!
       
   755     \reimp
       
   756 */
       
   757 QSizeF HbScrollArea::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const
       
   758 {
       
   759     Q_D ( const HbScrollArea );
       
   760 
       
   761     QSizeF sh(0, 0);
       
   762 
       
   763     switch (which) {
       
   764         case Qt::MinimumSize:
       
   765             break;
       
   766         case Qt::PreferredSize:
       
   767             if (d->mContents) {
       
   768                 sh = d->mContents->effectiveSizeHint( which, constraint );
       
   769             } else {
       
   770                 sh = HbWidget::sizeHint( which, constraint );
       
   771             }
       
   772             break;
       
   773         case Qt::MaximumSize:
       
   774             sh = QSizeF(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX);
       
   775             break;
       
   776         default:
       
   777             qWarning("QGraphicsWidget::sizeHint(): Don't know how to handle the value of 'which'");
       
   778             break;
       
   779     }
       
   780     
       
   781     return sh;
       
   782 }
       
   783 
       
   784 /*!
       
   785  \reimp
       
   786  */
       
   787 void HbScrollArea::focusOutEvent( QFocusEvent *event )
       
   788 {
       
   789     Q_D ( HbScrollArea );
       
   790     Q_UNUSED ( event );
       
   791 
       
   792     if ( !d->positionOutOfBounds() ) {
       
   793         d->stopAnimating();
       
   794     }
       
   795 
       
   796 }
       
   797 
       
   798 /*!
       
   799     Returns the scrollbar policy for vertical scrollbar
       
   800 
       
   801     \sa horizontalScrollBarPolicy(), setVerticalScrollBarPolicy()
       
   802 */
       
   803 
       
   804 HbScrollArea::ScrollBarPolicy HbScrollArea::verticalScrollBarPolicy() const
       
   805 {
       
   806     Q_D(const HbScrollArea);
       
   807     return d->mVerticalScrollBarPolicy;
       
   808 }
       
   809 
       
   810 /*!
       
   811     Sets the policy for vertical scrollbar
       
   812 
       
   813     The default policy is HbScrollArea::ScrollBarAutoHide.
       
   814 
       
   815     \sa setHorizontalScrollBarPolicy(), verticalScrollBarPolicy()
       
   816 */
       
   817 void HbScrollArea::setVerticalScrollBarPolicy(ScrollBarPolicy policy)
       
   818 {
       
   819     Q_D(HbScrollArea);
       
   820     d->setScrollBarPolicy(Qt::Vertical, policy);
       
   821 }
       
   822 
       
   823 /*!
       
   824   Returns the vertical scroll bar.
       
   825 
       
   826   \sa verticalScrollBarPolicy(), horizontalScrollBar()
       
   827  */
       
   828 HbScrollBar *HbScrollArea::verticalScrollBar() const
       
   829 {
       
   830     Q_D(const HbScrollArea);
       
   831     return d->mVerticalScrollBar;
       
   832 }
       
   833 
       
   834 /*!
       
   835    Replaces the existing vertical scroll bar with \a scrollBar. The former
       
   836    scroll bar is deleted.
       
   837 
       
   838    HbScrollArea already provides vertical and horizontal scroll bars by
       
   839    default. You can call this function to replace the default vertical
       
   840    scroll bar with your own custom scroll bar.
       
   841 
       
   842    \sa verticalScrollBar(), setHorizontalScrollBar()
       
   843 */
       
   844 void HbScrollArea::setVerticalScrollBar(HbScrollBar *scrollBar)
       
   845 {
       
   846     Q_D(HbScrollArea);
       
   847     if (!scrollBar) {
       
   848         qWarning("HbScrollArea::setVerticalScrollBar: Cannot set a null scroll bar");
       
   849         return;
       
   850     }
       
   851 
       
   852     d->replaceScrollBar(Qt::Vertical, scrollBar);
       
   853 }
       
   854 
       
   855 /*!
       
   856     \brief Returns the policy for horizontal scrollbar
       
   857 
       
   858     \sa verticalScrollBarPolicy(), setHorizontalScrollBarPolicy()
       
   859 */
       
   860 
       
   861 HbScrollArea::ScrollBarPolicy HbScrollArea::horizontalScrollBarPolicy() const
       
   862 {
       
   863     Q_D(const HbScrollArea);
       
   864     return d->mHorizontalScrollBarPolicy;
       
   865 }
       
   866 
       
   867 /*!
       
   868     \brief Sets the policy for horizontal scrollbar
       
   869 
       
   870     The default policy is HbScrollArea::ScrollBarAutoHide.
       
   871 
       
   872     \sa setVerticalScrollBarPolicy(), horizontalScrollBarPolicy()
       
   873 */
       
   874 void HbScrollArea::setHorizontalScrollBarPolicy(ScrollBarPolicy policy)
       
   875 {
       
   876     Q_D(HbScrollArea);    
       
   877     d->setScrollBarPolicy(Qt::Horizontal, policy);
       
   878 }
       
   879 
       
   880 /*!
       
   881   Returns the horizontal scroll bar.
       
   882 
       
   883   \sa horizontalScrollBarPolicy(), verticalScrollBar()
       
   884  */
       
   885 HbScrollBar *HbScrollArea::horizontalScrollBar() const
       
   886 {
       
   887     Q_D(const HbScrollArea);
       
   888     return d->mHorizontalScrollBar;
       
   889 }
       
   890 
       
   891 /*!
       
   892    Replaces the existing horizontal scroll bar with \a scrollBar. The former
       
   893    scroll bar is deleted.
       
   894 
       
   895    HbScrollArea already provides vertical and horizontal scroll bars by
       
   896    default. You can call this function to replace the default horizontal
       
   897    scroll bar with your own custom scroll bar.
       
   898 
       
   899    \sa horizontalScrollBar(), setVerticalScrollBar()
       
   900 */
       
   901 void HbScrollArea::setHorizontalScrollBar(HbScrollBar *scrollBar)
       
   902 {
       
   903     Q_D(HbScrollArea);
       
   904     if (!scrollBar) {
       
   905         qWarning("HbScrollArea::setHorizontalScrollBar: Cannot set a null scroll bar");
       
   906         return;
       
   907     }
       
   908 
       
   909     d->replaceScrollBar(Qt::Horizontal, scrollBar);
       
   910 }
       
   911 
       
   912 /*!
       
   913     \brief the alignment of the scroll area's widget    
       
   914 
       
   915     By default, the widget stays rooted to the top-left corner of the
       
   916     scroll area.
       
   917     \sa alignment
       
   918 */
       
   919 
       
   920 void HbScrollArea::setAlignment(Qt::Alignment alignment)
       
   921 {
       
   922     Q_D(HbScrollArea);
       
   923     d->mAlignment = alignment;
       
   924     if (d->mContents)
       
   925         d->adjustContent();
       
   926 }
       
   927 /*!
       
   928     \brief the alignment of the scroll area's widget
       
   929 
       
   930     By default, the widget stays rooted to the top-left corner of the
       
   931     scroll area.
       
   932     \sa setAlignment
       
   933 */
       
   934 Qt::Alignment HbScrollArea::alignment() const
       
   935 {
       
   936     Q_D(const HbScrollArea);
       
   937     return d->mAlignment;
       
   938 }
       
   939 
       
   940 
       
   941 /*!
       
   942     \brief Contination indicators for scroll area
       
   943 
       
   944     By default continuation graphics are disabled. When continuation
       
   945     graphics are enabled, scroll area shows indications where it is
       
   946     possible to scroll.
       
   947 
       
   948     \sa continuationIndicators
       
   949 */
       
   950 
       
   951 void HbScrollArea::setContinuationIndicators(bool indication)
       
   952 {
       
   953     Q_D(HbScrollArea);
       
   954     if (d->mContinuationIndicators == indication)
       
   955         return;
       
   956     d->mContinuationIndicators = indication;
       
   957     d->createPrimitives();
       
   958     d->updatePrimitives();
       
   959     if (d->mContents && indication) {
       
   960         d->updateIndicators(-d->mContents->pos());
       
   961     }
       
   962     repolish();
       
   963 }
       
   964 
       
   965 /*!
       
   966     \brief Contination indicators for scroll area
       
   967 
       
   968     By default continuation graphics are disabled. When continuation
       
   969     graphics are enabled, scroll area shows indications where it is
       
   970     possible to scroll.
       
   971 
       
   972     \sa setContinuationIndicators
       
   973 */
       
   974 bool HbScrollArea::continuationIndicators() const
       
   975 {
       
   976     Q_D(const HbScrollArea);
       
   977     return d->mContinuationIndicators;
       
   978 }
       
   979 
       
   980 
       
   981 /*!
       
   982     Scrolls the contents of the scroll area so that the point \a position is visible
       
   983     inside the region of the scrollArea with margins specified in pixels by \a xMargin and
       
   984     \a yMargin. If the specified point cannot be reached, the contents are scrolled to
       
   985     the nearest valid position. The default and minimum valid value for both margins is 0 pixels.
       
   986     Valid range for \a xMargin is between 0 and width of scrollArea, valid range for \a yMargin is
       
   987     between 0 and height of scrollArea.\a xMargin, \a yMargin, x and y values of \a position will be
       
   988     ignored depending on scrollingDirection.
       
   989 
       
   990     \sa setScrollDirections()
       
   991 */
       
   992 void HbScrollArea::ensureVisible(const QPointF& position, qreal xMargin, qreal yMargin)
       
   993 {
       
   994     Q_D(HbScrollArea);
       
   995     d->ensureVisible(position, xMargin, yMargin);
       
   996 }
       
   997 
       
   998 /*!
       
   999     Scrolls the contents of the scroll area to the \a newPosition in a given \a time.
       
  1000     If the time is 0, contents is scrolled to the position instantly.
       
  1001 */
       
  1002 void HbScrollArea::scrollContentsTo (const QPointF& newPosition, int time) {
       
  1003     Q_D(HbScrollArea);
       
  1004     if (time > 0){
       
  1005         d->startTargetAnimation (newPosition, qMax (0, time));
       
  1006     } else {
       
  1007         scrollByAmount(newPosition - (-d->mContents->pos()));
       
  1008         if (d->positionOutOfBounds() && d->mClampingStyle == BounceBackClamping) {
       
  1009             d->startAnimating();
       
  1010         } else {
       
  1011             d->stopScrolling();
       
  1012         }
       
  1013     }
       
  1014 }
       
  1015 
       
  1016 /*
       
  1017  * \reimp
       
  1018  */
       
  1019 void HbScrollArea::polish(HbStyleParameters& params)
       
  1020 {
       
  1021     Q_D(HbScrollArea);
       
  1022 
       
  1023     d->doLazyInit();
       
  1024 
       
  1025     // fetch scrolling parameters from css
       
  1026     const QString SpeedFactor = "speed-factor";
       
  1027     const QString IntertiaSpeedFactor = "inertia-speed-factor";
       
  1028     const QString MaxScrollSpeed = "max-scroll-speed";
       
  1029     const QString SpringStrength = "spring-strength";
       
  1030     const QString SpringDampingFactor = "spring-damping-factor";
       
  1031     const QString FrictionPerMilliSecond = "friction";
       
  1032 
       
  1033     params.addParameter(SpeedFactor);
       
  1034     params.addParameter(IntertiaSpeedFactor);
       
  1035     params.addParameter(MaxScrollSpeed);
       
  1036     params.addParameter(SpringStrength);
       
  1037     params.addParameter(SpringDampingFactor);
       
  1038     params.addParameter(FrictionPerMilliSecond);
       
  1039     HbWidget::polish(params);
       
  1040 
       
  1041     if (!params.value(SpeedFactor).isNull()) {
       
  1042         d->mSpeedFactor = params.value(SpeedFactor).toDouble();
       
  1043     }
       
  1044     if (!params.value(IntertiaSpeedFactor).isNull()) {
       
  1045         d->mInertiaSpeedFactor = params.value(IntertiaSpeedFactor).toDouble();
       
  1046     }
       
  1047     if (!params.value(MaxScrollSpeed).isNull()) {
       
  1048         d->mMaxScrollSpeed = params.value(MaxScrollSpeed).toDouble();
       
  1049     }
       
  1050     if (!params.value(SpringStrength).isNull()) {
       
  1051         d->mSpringStrength = params.value(SpringStrength).toDouble();
       
  1052     }
       
  1053     if (!params.value(SpringDampingFactor).isNull()) {
       
  1054         d->mSpringDampingFactor = params.value(SpringDampingFactor).toDouble();
       
  1055     }
       
  1056     if (!params.value(FrictionPerMilliSecond).isNull()) {
       
  1057         d->mFrictionPerMilliSecond = params.value(FrictionPerMilliSecond).toDouble();
       
  1058     }
       
  1059     if (d->mContinuationIndicators) {
       
  1060         d->updateIndicators(-d->mContents->pos());
       
  1061     }
       
  1062 }
       
  1063 
       
  1064 #include "moc_hbscrollarea.cpp"