src/hbcore/gui/hbscrollarea.cpp
changeset 28 b7da29130b0e
parent 23 e6ad4ef83b23
child 30 80e4d18b72f5
equal deleted inserted replaced
23:e6ad4ef83b23 28:b7da29130b0e
    37 #include <QGesture>
    37 #include <QGesture>
    38 
    38 
    39 #include <QDebug>
    39 #include <QDebug>
    40 
    40 
    41 /*!
    41 /*!
    42  @beta
    42     @beta
    43  @hbcore
    43     @hbcore
    44  \class HbScrollArea
    44     \class HbScrollArea
    45  \brief HbScrollArea provides a finger-touch enabled scrollable container class.
    45     \brief The HbScrollArea class provides a touch-enabled scrolling view onto another
    46 
    46     widget.
    47  HbScrollArea handles the events need to scroll the contents placed inside it.  It also
    47 
    48  handles the display of scrollbar while scrolling is occurring.
    48     A scroll area displays the contents of another widget within a frame. If the size of
    49 
    49     this widget exceeds the size of the frame, the user can scroll so that the entire
    50  HbScrollArea is used by constructing a QGraphicsWidget widget that contains the content to be
    50     contents can be viewed. The user scrolls through the contents by using a dragging
    51  displayed by calling the HbScrollArea::setContentWidget() method. Scrollarea resizes the content
    51     gesture. If scroll bars are enabled and the scroll bar is interactive, the user can
    52  widget by using QGraphicsWidget::sizeHint() function. This function returns the sizehint i.e.
    52     also scroll through the contents using the scroll bar (HbScrollBar class).
    53  height and width of the content widget which is constrained by scrollarea based on the scrollarea
    53 
    54  direction.
    54     %HbScrollArea is a concrete class that you can use directly in your applications to
    55 
    55     provide default scrolling behavior. %HbScrollArea is also a base class for
    56  If the scrollarea direction is Vertical, scrollarea resizes the width of the content widget
    56     HbAbstractItemView and the item view classes that derive from it. If necessary, you
    57  else if it is horizontal, it resizes the height of contect widget.
    57     can subclass %HbScrollArea to add additional features, such as touch and selection
    58 
    58     feedback.
    59  The class can be used by itself to provide default scrolling behavior or can be
    59 
    60  subclassed to add touch feedback, selection feedback, etc.
    60     \image html hbscrollarea.png A scroll area containing a large image and showing scrollbars
    61 
    61 
    62  By default, the class provides dragging, flicking with animated follow-on, a
    62     %HbScrollArea provides properties that you can use to customize the following aspects
    63  simple inertia algorithm for slowing the animated follow-on scrolling and
    63     of the scroll area:
    64  a bounce-back algorithm for animating the content back to its bounding
    64 
    65  limits at the end of a drag or flick action.
    65     - <b>Scrolling style</b>. The user scrolls through the contents by using a dragging
    66  */
    66          movement. This property controls what happens when the user releases the pressure.
    67 
    67          The default is that a follow-on animation continues the scrolling if the dragging
    68 /*!
    68          was fast. Alternatively, the scrolling can stop as soon as the user releases the
    69  Here are the main properties of the class:
    69          pressure, regardless of the dragging speed. Call setScrollingStyle() to set this
    70 
    70          property.
    71  \li HbScrollArea::scrollDirections     : 
    71 
    72  \li HbScrollArea::clampingStyle        : 
    72     - <b>Friction effect</b>. This property controls the speed of the follow-on scrolling
    73  \li HbScrollArea::scrollingStyle       : 
    73          animation. When the friction effect is enabled, it slows the animation and causes
    74  \li HbScrollArea::showScrollBars       : 
    74          it to stop more quickly than when the effect is not enabled. Call setFrictionEnabled()
    75  \li HbScrollArea::scrollBarWidth       :  
    75          to set this property.
    76  \li HbScrollArea::scrollBarMargin      : 
    76 
    77  \li HbScrollArea::frictionEnabled      :
    77     - <b>Clamping style</b>. This property controls how scrolling is constrained relative
    78  \li HbScrollArea::handleLongPress      :  
    78          to the contents of the scrolling area. Scrolling can be limited to the bounding
    79  */
    79          rectangle of the contents or it can go beyond the bounding rectangle and bounce
    80 
    80          back to its limits (this is the default). Call setClampingStyle() to set this
    81 /*!
    81          property.
    82     \property HbScrollArea::showScrollBars
    82 
    83     \brief
    83     - <b>Scroll direction</b>. This property controls the scrolling direction. The default is
    84 */
    84          vertical scrolling, but this can be changed to horizontal or bi-directional scrolling.
    85 
    85          Call setScrollDirections() to set this property.
    86 /*!
    86 
    87     \property HbScrollArea::scrollBarWidth
    87     - <b>Scrollbar policy</b>. There is a separate scrollbar policy property for both scrollbars.
    88     \brief
    88          You can set these so that the scrollbar is always shown, never shown, only shown when
    89 */
    89          needed or for short periods (autohide), which is the default behavior. Call
    90 
    90          setVerticalScrollBarPolicy() and setHorizontalScrollBarPolicy() to set these properties.
    91 /*!
    91 
    92     \property HbScrollArea::scrollBarMargin
    92     - <b>Continuation indicators</b>. This property controls whether visual feedback is provided
    93     \brief
    93          to indicate when scrolling is possible. The default value is false. Call
    94 */
    94          setContinuationIndicators() to set this property.
    95 
    95 
    96 /*!
    96     The contents widget must be an object of a class derived from QGraphicsWidget. After
    97     \property HbScrollArea::scrollDirections
    97     constructing this widget, you set it into the scroll area by calling setContentWidget().
    98     \brief 
    98     The scroll area uses QGraphicsWidget::sizeHint() to resize the content widget to fit,
    99 */
    99     taking into account the scroll direction. For example, when the scrolling direction is
   100 
   100     vertical, the scroll area resizes the contents widget to fit the width of the scroll area.
   101 /*!
   101 
   102     \property HbScrollArea::clampingStyle
   102     \section _usecases_hbscrollarea Using the HbScrollArea class
   103     \brief 
   103 
   104 */
   104     This example creates an HbScrollArea widget and sets a large photo as its contents.
   105 
   105 
   106 /*!
   106     \code
   107     \property HbScrollArea::scrollingStyle
   107 int main(int argc, char *argv[])
   108     \brief 
   108 {
   109 */
   109     HbApplication app(argc, argv);
   110 
   110     app.setApplicationName( "Scroll Area" );
   111 /*!
   111 
   112     \property HbScrollArea::frictionEnabled
   112     HbMainWindow window;
   113     \brief
   113     HbView* view = new HbView();
   114 */
   114 
   115 
   115     // Create the scroll area object.
   116 /*!
   116     HbScrollArea* scrollArea = new HbScrollArea();
   117     \property HbScrollArea::handleLongPress
   117 
   118     \brief 
   118     // Create the content widget.
   119 */
   119     QGraphicsWidget* content = new QGraphicsWidget();
   120 
   120 
   121 /*!
   121     // Create a pixmap as a child of the content widget.
   122     \property HbScrollArea::verticalScrollBarPolicy
   122     QString string(":/gfx/beach.jpg");
   123     \brief
   123     QGraphicsPixmapItem* pixmapItem = new QGraphicsPixmapItem(string, content);
   124 */
   124 
   125 
   125     // Set the preferred size of the content widget to match the full size of the photo.
   126 /*!
   126     content->setPreferredSize(pixmapItem->boundingRect().size());
   127     \property HbScrollArea::horizontalScrollBarPolicy
   127 
   128     \brief
   128     // Load the content widget into the scrolling area.
   129 */
   129     scrollArea->setContentWidget(content);
       
   130 
       
   131     // Set the scroll area to scroll in both directions.
       
   132     scrollArea->setScrollDirections(Qt::Vertical | Qt::Horizontal);
       
   133 
       
   134     view->setWidget(scrollArea);
       
   135     window.addView(view);
       
   136     window.show();
       
   137     return app.exec();
       
   138 }
       
   139     \endcode
       
   140 
       
   141     \sa HbScrollBar
       
   142  */
   130 
   143 
   131 /*!
   144 /*!
   132     \fn void HbScrollArea::scrollDirectionsChanged(Qt::Orientations newValue)
   145     \fn void HbScrollArea::scrollDirectionsChanged(Qt::Orientations newValue)
   133 
   146 
   134     This signal is emitted when scrolling direction is changed.
   147     This signal is emitted when the scrolling direction changes.
   135 */
   148 */
   136 
   149 
   137 /*!
   150 /*!
   138     \fn void HbScrollArea::scrollingStarted()
   151     \fn void HbScrollArea::scrollingStarted()
   139 
   152 
   140     This signal is emitted whenever a scrolling action begins.
   153     This signal is emitted when a scrolling action begins.
   141 */
   154 */
   142 
   155 
   143 /*!
   156 /*!
   144     \fn void HbScrollArea::scrollingEnded()
   157     \fn void HbScrollArea::scrollingEnded()
   145 
   158 
   146     This signal is emitted whenever a scrolling action ends.
   159     This signal is emitted when a scrolling action ends.
   147 */
   160 */
   148 
   161 
   149 /*!
   162 /*!
   150     \fn void HbScrollArea::scrollPositionChanged(QPointF newposition)
   163     \fn void HbScrollArea::scrollPositionChanged(const QPointF &newPosition)
   151     This signal is emitted when scroll position is changed and someone is connected to the signal.
   164 
       
   165     This signal is emitted when the scroll position is changed, but only if this signal
       
   166     is connected to a slot.
   152 */
   167 */
   153 
   168 
   154 /*!
   169 /*!
   155     \enum HbScrollArea::ClampingStyle
   170     \enum HbScrollArea::ClampingStyle
   156 
   171 
   157     Clamping styles supported by HbScrollArea.
   172     Defines the clamping styles supported by HbScrollArea. The clamping style
   158 
   173     controls the behavior when scrolling to the edge of the contents of the scrolling
   159     This enum describes how scrolling is behaving when reaching boundaries of the content item.
   174     area.
   160 */
   175 
       
   176     \sa setClampingStyle(), clampingStyle()
       
   177 */
       
   178 
   161 /*!
   179 /*!
   162     \var HbScrollArea::StrictClamping
   180     \var HbScrollArea::StrictClamping
   163 
   181     Scrolling is limited to the bounding rectangle of the contents.
   164     Scrolling is limited to the bounding rectangle of the content item.
   182 */
   165 */
   183 
   166 /*!
   184 /*!
   167     \var HbScrollArea::BounceBackClamping
   185     \var HbScrollArea::BounceBackClamping
   168 
   186     Scrolling can go beyond the bounding rectangle of the contents, but bounces
   169     Scrolling can go beyond the bounding rectangle of the content item, but bounces back to the
   187     back to the limits of the bounding rectangle when released or when the follow-on
   170     limits of the bounding rectangle when released or when inertia scrolling stops.
   188     scrolling animation stops. This is the default clamping style.
   171 */
   189 */
       
   190 
   172 /*!
   191 /*!
   173     \var HbScrollArea::NoClamping
   192     \var HbScrollArea::NoClamping
   174 
   193     Scrolling is unclamped. Typically you use this only in a subclass that implements
   175     Scrolling is completely unclamped (this is usually used when the subclass implements its own).
   194     its own custom clamping behavior.
   176 */
   195 */
       
   196 
   177 /*!
   197 /*!
   178     \enum HbScrollArea::ScrollingStyle
   198     \enum HbScrollArea::ScrollingStyle
   179 
   199 
   180     Different scrolling styles supported by HbScrollArea.
   200     Defines the scrolling styles supported by HbScrollArea. The scrolling style
   181 
   201     controls which gestures the user can use to scroll the contents and how the scrolling
   182     This enum describes how scroll area can be scrolled.
   202     responds to those gestures.
   183 */
   203 
       
   204     \sa setScrollingStyle(), scrollingStyle()
       
   205 */
       
   206 
   184 /*!
   207 /*!
   185     \var HbScrollArea::Pan
   208     \var HbScrollArea::Pan
   186 
   209 
   187     Dragging motion pans the view with no follow-on scrolling animation.
   210     The user can scroll through the contents by using a dragging motion. The scrolling
   188 */
   211     stops as soon as the user stops the dragging motion.
       
   212 */
       
   213 
   189 /*!
   214 /*!
   190     \var HbScrollArea::PanOrFlick
   215     \var HbScrollArea::PanOrFlick
   191 
   216 
   192     Dragging motion pans the view with no follow-on scrolling animation,
   217     \deprecated
   193     quick flicking motion triggers scrolling animation.
   218     The user can scroll through the contents by using a dragging motion and a quick
   194 */
   219     flicking motion triggers a follow-on scrolling animation.
       
   220 */
       
   221 
   195 /*!
   222 /*!
   196     \var HbScrollArea::PanWithFollowOn
   223     \var HbScrollArea::PanWithFollowOn
   197 
   224 
   198     Dragging motion pans the view, velocity at end of drag motion triggers follow-on animated scrolling.
   225     The user can scroll through the contents by using a dragging motion. In addition
       
   226     a fast dragging motion triggers a follow-on scrolling animation when the user
       
   227     stops dragging and releases the pressure. This is the default scrolling style.
   199 */
   228 */
   200 
   229 
   201 /*!
   230 /*!
   202     \enum HbScrollArea::ScrollBarPolicy
   231     \enum HbScrollArea::ScrollBarPolicy
   203 
   232 
   204     This enum type describes the various visibility modes of HbScrollArea's scroll bars.
   233     Defines the scroll bar visibility modes supported by  HbScrollArea.
       
   234 
       
   235     \sa setVerticalScrollBarPolicy(), verticalScrollBarPolicy(),
       
   236     setHorizontalScrollBarPolicy(), horizontalScrollBarPolicy()
   205 */
   237 */
   206 
   238 
   207 /*!
   239 /*!
   208     \var HbScrollArea::ScrollBarAsNeeded
   240     \var HbScrollArea::ScrollBarAsNeeded
   209 
   241 
   210     HbScrollArea shows a scroll bar when the content is too large to fit and not otherwise.
   242     Show the scroll bar only when the contents are too large to fit.
   211 */
   243 */
   212 /*!
   244 /*!
   213     \var HbScrollArea::ScrollBarAlwaysOff
   245     \var HbScrollArea::ScrollBarAlwaysOff
   214 
   246 
   215     HbScrollArea never shows a scroll bar.
   247     Never show the scroll bar.
   216 */
   248 */
   217 /*!
   249 /*!
   218     \var HbScrollArea::ScrollBarAlwaysOn
   250     \var HbScrollArea::ScrollBarAlwaysOn
   219 
   251 
   220     HbScrollArea always shows a scroll bar.
   252     Always show the scroll bar.
   221 */
   253 */
   222 /*!
   254 /*!
   223     \var HbScrollArea::ScrollBarAutoHide
   255     \var HbScrollArea::ScrollBarAutoHide
   224 
   256 
   225     HbScrollArea shows scroll bar for short period of time when the content is displayed or scrolled. Scroll bar is not shown if not needed.
   257     Show the scroll bar for a short period when the contents are first displayed or
   226 
   258     when the user scrolls the contents. This is the default behavior.
   227     This is the default behavior.
   259 */
   228 */
   260 
   229 
   261 /*
   230 /*!
       
   231     \primitives
   262     \primitives
   232     \primitives{continuation-indicator-bottom} HbFrameItem representing the scrollarea continuation indicator on the bottom of the scrollarea.
   263     \primitives{continuation-indicator-bottom} HbFrameItem representing the scrollarea continuation indicator on the bottom of the scrollarea.
   233     \primitives{continuation-indicator-top} HbFrameItem representing the scrollarea continuation indicator on the top of the scrollarea.
   264     \primitives{continuation-indicator-top} HbFrameItem representing the scrollarea continuation indicator on the top of the scrollarea.
   234     \primitives{continuation-indicator-left} HbFrameItem representing the scrollarea continuation indicator on the left side of the scrollarea.
   265     \primitives{continuation-indicator-left} HbFrameItem representing the scrollarea continuation indicator on the left side of the scrollarea.
   235     \primitives{continuation-indicator-right} HbFrameItem representing the scrollarea continuation indicator on the right side of the scrollarea.
   266     \primitives{continuation-indicator-right} HbFrameItem representing the scrollarea continuation indicator on the right side of the scrollarea.
   236   */
   267   */
   237 
   268 
   238 /*!
   269 /*!
   239   Constructor
   270     Constructs an HbScrollArea object with the given \a parent.
   240  
   271  */
   241   \sa HbScrollArea::HbScrollArea
   272 HbScrollArea::HbScrollArea(QGraphicsItem* parent) :
   242  */
       
   243 HbScrollArea::HbScrollArea(QGraphicsItem* parent) : 
       
   244         HbWidget( *new HbScrollAreaPrivate, parent )
   273         HbWidget( *new HbScrollAreaPrivate, parent )
   245 {
   274 {
   246     Q_D( HbScrollArea );
   275     Q_D( HbScrollArea );
   247     d->q_ptr = this;
   276     d->q_ptr = this;
   248     d->init();
   277     d->init();
   249 }
   278 }
   250 
   279 
   251 /*!
   280 /*!
   252   Protected constructor.
   281     Protected constructor.
   253   */
   282   */
   254 HbScrollArea::HbScrollArea(HbScrollAreaPrivate &dd, QGraphicsItem *parent):
   283 HbScrollArea::HbScrollArea(HbScrollAreaPrivate &dd, QGraphicsItem *parent):
   255         HbWidget( dd, parent  )
   284         HbWidget( dd, parent  )
   256 {
   285 {
   257     Q_D( HbScrollArea );
   286     Q_D( HbScrollArea );
   258     d->q_ptr = this;
   287     d->q_ptr = this;
   259     d->init();
   288     d->init();
   260 }
   289 }
   261    
   290    
   262 /*!
   291 /*!
   263  Destructor
   292     Destructor
   264  
       
   265  \sa HbScrollArea::~HbScrollArea
       
   266  */
   293  */
   267 HbScrollArea::~HbScrollArea()
   294 HbScrollArea::~HbScrollArea()
   268 {
   295 {
   269     Q_D( HbScrollArea );
   296     Q_D( HbScrollArea );
   270     if (d && d->mContents) {
   297     if (d && d->mContents) {
   271         d->mContents->setParentLayoutItem(0);
   298         d->mContents->setParentLayoutItem(0);
   272     }
   299     }
   273 }
   300 }
   274 
   301 
   275 /*!
   302 /*!
   276  Returns a pointer to the QGraphicsWidget,which is the content of scrollable area.
   303     Returns a pointer to the widget that is contained within the scroll area
   277  
   304     and that defines the contents to be scrolled.
   278  \sa HbScrollArea::setContentWidget()
   305 
       
   306     \sa setContentWidget()
   279  */
   307  */
   280 QGraphicsWidget* HbScrollArea::contentWidget() const
   308 QGraphicsWidget* HbScrollArea::contentWidget() const
   281 {
   309 {
   282     Q_D( const HbScrollArea );
   310     Q_D( const HbScrollArea );
   283 
   311 
   284     return d->mContents;
   312     return d->mContents;
   285 }
   313 }
   286 
   314 
   287 /*!
   315 /*!
   288  Assigns the QGraphicsWidget that is to be scrolled.  The HbScrollArea widget takes ownership of
   316    Assigns a widget (QGraphicsWidget object) to the scroll area. This widget defines
   289  the QGraphicsWidget.
   317    the contents of the scroll area. The HbScrollArea object takes ownership of the
   290  
   318    contents widget.
   291  \sa HbScrollArea::contentWidget()
   319 
       
   320    \sa contentWidget()
   292  */
   321  */
   293 void HbScrollArea::setContentWidget(QGraphicsWidget* contents)
   322 void HbScrollArea::setContentWidget(QGraphicsWidget* contents)
   294 {
   323 {
   295     Q_D( HbScrollArea );
   324     Q_D( HbScrollArea );
   296 
   325 
   318         d->hideChildComponents();
   347         d->hideChildComponents();
   319     }
   348     }
   320 }
   349 }
   321 
   350 
   322 /*!
   351 /*!
   323 Removes the content widget, which is set to the scrollarea and returns it.
   352     Removes the scroll area's content widget from the scroll area, returns it, and
   324 The ownership of the \a QGraphicsWidget is transferred to the caller.
   353     transfers ownership of the content widget to the caller. This is useful when you
   325 
   354     need to switch the contents without deleting previous contents.
   326 \note This function is particularly useful if one wants to switch between
       
   327 different contents without deleting previous content.
       
   328 
   355 
   329     \sa setContentWidget()
   356     \sa setContentWidget()
   330 */
   357  */
   331 QGraphicsWidget *HbScrollArea::takeContentWidget()
   358 QGraphicsWidget *HbScrollArea::takeContentWidget()
   332 {
   359 {
   333     Q_D(HbScrollArea);
   360     Q_D(HbScrollArea);
   334     QGraphicsWidget* content = d->mContents;
   361     QGraphicsWidget* content = d->mContents;
   335     d->mContents = 0;
   362     d->mContents = 0;
   344     d->hideChildComponents();
   371     d->hideChildComponents();
   345     return content;
   372     return content;
   346 }
   373 }
   347 
   374 
   348 /*!
   375 /*!
   349  Returns the value of the clampingStyle property
   376     Returns the value of the \c clampingStyle property.
   350  
   377 
   351  \sa HbScrollArea::setClampingStyle()
   378     \sa setClampingStyle(), HbScrollArea::ClampingStyle
   352  */
   379  */
   353 HbScrollArea::ClampingStyle HbScrollArea::clampingStyle() const
   380 HbScrollArea::ClampingStyle HbScrollArea::clampingStyle() const
   354 {
   381 {
   355     Q_D( const HbScrollArea );
   382     Q_D( const HbScrollArea );
   356 
   383 
   357     return d->mClampingStyle;
   384     return d->mClampingStyle;
   358 }
   385 }
   359 
   386 
   360 /*!
   387 /*!
   361  Sets the clampingStyle property that controls how the scrolling is constrained
   388     Sets the \c clampingStyle property, which controls how scrolling is constrained
   362  relative to the contents of the scrolling area.
   389     relative to the contents of the scrolling area. The possible values are defined
   363  
   390     by the HbScrollArea::ClampingStyle enum. The default is
   364  Possible values for the clamping style include:
   391     HbScrollArea::BounceBackClamping.
   365  
   392 
   366     StrictClamping - scrolling is limited to the bounding rectangle of the content item
   393     \sa clampingStyle()
   367     BounceBackClamping - scrolling can go beyond the bounding rectangle of the content item, but bounces back to the
       
   368                     limits of the bounding rectangle when released or when inertia scrolling stops
       
   369     NoClamping - scrolling is completely unclamped (this is usually used when the subclass implements its own
       
   370                     custom clamping behavior)
       
   371  
       
   372  The default value is BounceBackClamping.
       
   373  
       
   374  \sa HbScrollArea::clampingStyle()
       
   375  */
   394  */
   376 void HbScrollArea::setClampingStyle(ClampingStyle value)
   395 void HbScrollArea::setClampingStyle(ClampingStyle value)
   377 {
   396 {
   378     Q_D( HbScrollArea );
   397     Q_D( HbScrollArea );
   379 
   398 
   380     d->mClampingStyle = value;
   399     d->mClampingStyle = value;
   381 }
   400 }
   382 
   401 
   383 /*!
   402 /*!
   384   Returns the value of the scrollingStyle property
   403     Returns the value of the \c scrollingStyle property.
   385  
   404 
   386   \sa HbScrollArea::setScrollingStyle()
   405     \sa setScrollingStyle()
   387  */
   406  */
   388 HbScrollArea::ScrollingStyle HbScrollArea::scrollingStyle() const
   407 HbScrollArea::ScrollingStyle HbScrollArea::scrollingStyle() const
   389 {
   408 {
   390     Q_D( const HbScrollArea );
   409     Q_D( const HbScrollArea );
   391 
   410 
   392     return d->mScrollingStyle;
   411     return d->mScrollingStyle;
   393 }
   412 }
   394 
   413 
   395 /*!
   414 /*!
   396   Sets the scrollingStyle property that controls how the style of scrolling interaction
   415     Sets the \c scrollingStyle property, which controls which gestures the user can
   397   provided by the widget
   416     use to scroll the contents and how the scrolling responds to those gestures. The
   398  
   417     possible values are defined by the HbScrollArea::ScrollingStyle enum. The default
   399   Possible values for the clamping style include:
   418     value is HbScrollArea::PanWithFollowOn.
   400  
   419 
   401         Pan - dragging motion pans the view with no follow-on scrolling animation
   420     \sa scrollingStyle()
   402                \deprecated PanOrFlick
       
   403                     is deprecated.
       
   404         PanWithFollowOn - dragging motion pans the view, velocity at end of drag motion triggers follow-on animated scrolling
       
   405  
       
   406   The default value is PanWithFollowOn.
       
   407  
       
   408   \sa HbScrollArea::scrollingStyle()
       
   409  */
   421  */
   410 void HbScrollArea::setScrollingStyle(ScrollingStyle value)
   422 void HbScrollArea::setScrollingStyle(ScrollingStyle value)
   411 {
   423 {
   412     Q_D( HbScrollArea );
   424     Q_D( HbScrollArea );
   413 
   425 
   418         d->mScrollingStyle = value;
   430         d->mScrollingStyle = value;
   419     }
   431     }
   420 }
   432 }
   421 
   433 
   422 /*!
   434 /*!
   423   Returns the value of the scrollDirections property.
   435     Returns the value of the \c scrollDirections property.
   424  
   436  
   425   \sa HbScrollArea::setScrollDirections()
   437     \sa setScrollDirections()
   426  */
   438  */
   427 Qt::Orientations HbScrollArea::scrollDirections() const
   439 Qt::Orientations HbScrollArea::scrollDirections() const
   428 {
   440 {
   429     Q_D( const HbScrollArea );
   441     Q_D( const HbScrollArea );
   430 
   442 
   431     return d->mScrollDirections;
   443     return d->mScrollDirections;
   432 }
   444 }
   433 
   445 
   434 /*!
   446 /*!
   435   Sets the value of the scrollDirections property.  This value is of
   447     Sets the \c scrollDirections property, which controls the scrolling direction. The
   436   type Qt::Orientations and can set to either Qt::Horizontal to enable horizontal scrolling,
   448     possible values are defined by the Qt::Orientations enum, as shown in the following
   437   Qt::Vertical to enable vertical scrolling or (Qt::Horizontal | Qt::Vertical) to enable
   449     table. The default value is Qt::Vertical.
   438   scrolling in both directions.
   450 
   439  
   451     <table border="1" style="border-collapse: collapse; border: solid;">
   440   The default value is Qt::Vertical.
   452     <tr><th>To enable:</th><th>Set to:</th></tr>
   441  
   453     <tr><td>Horizontal scrolling</td><td>Qt::Horizontal</td></tr>
   442   \sa HbScrollArea::scrollDirections()
   454     <tr><td>Vertical scrolling</td><td>Qt::Vertical</td></tr>
       
   455     <tr><td>Scrolling in both directions</td><td>Qt::Horizontal | Qt::Vertical</td></tr>
       
   456     </table>
       
   457 
       
   458     \sa scrollDirections()
   443  */
   459  */
   444 void HbScrollArea::setScrollDirections(Qt::Orientations value)
   460 void HbScrollArea::setScrollDirections(Qt::Orientations value)
   445 {
   461 {
   446     Q_D( HbScrollArea );
   462     Q_D( HbScrollArea );
   447 
   463 
   459         emit scrollDirectionsChanged( value );
   475         emit scrollDirectionsChanged( value );
   460     }
   476     }
   461 }
   477 }
   462 
   478 
   463 /*!
   479 /*!
   464   Returns true if the inertia scrolling effect is enabled, false otherwise.
   480     Returns true if the friction effect is enabled, false otherwise.
   465  
   481  
   466   \sa HbScrollArea::setFrictionEnabled()
   482     \sa setFrictionEnabled()
   467  */
   483  */
   468 bool HbScrollArea::frictionEnabled() const
   484 bool HbScrollArea::frictionEnabled() const
   469 {
   485 {
   470     Q_D( const HbScrollArea );
   486     Q_D( const HbScrollArea );
   471 
   487 
   472     return d->mFrictionEnabled;
   488     return d->mFrictionEnabled;
   473 }
   489 }
   474 
   490 
   475 /*!
   491 /*!
   476   Enables/disables the inertia scrolling effect.
   492     Sets the \c frictionEnabled property. The default value is true, which
   477   By default, the inertia effect is enabled.
   493     indicates that the friction effect is enabled.
   478  
   494 
   479   \sa HbScrollArea::frictionEnabled()
   495     When the HbScrollArea::PanWithFollowOn scrolling style is in use, the
       
   496     \c frictionEnabled property controls the speed of the follow-on scrolling
       
   497     animation. When the friction effect is enabled (the default), it slows the
       
   498     animation and causes it to stop earlier than when the friction effect is not
       
   499     in use.
       
   500 
       
   501     \sa frictionEnabled()
   480  */
   502  */
   481 void HbScrollArea::setFrictionEnabled(bool value)
   503 void HbScrollArea::setFrictionEnabled(bool value)
   482 {
   504 {
   483     Q_D( HbScrollArea );
   505     Q_D( HbScrollArea );
   484 
   506 
   485     d->mFrictionEnabled = value;
   507     d->mFrictionEnabled = value;
   486 }
   508 }
   487 
   509 
   488 /*!
   510 /*!
   489   Returns true if the scroll area handles
   511     Returns true if the scroll area handles long press gestures, false otherwise.
   490   long press gestures, false otherwise
   512 
   491  
   513     \deprecated This function is deprecated.
   492   \deprecated HbScrollArea::longPressEnabled()
       
   493       is deprecated.
       
   494  
       
   495   \sa HbScrollArea::setHandleLongPress()
       
   496  */
   514  */
   497 bool HbScrollArea::longPressEnabled() const
   515 bool HbScrollArea::longPressEnabled() const
   498 {
   516 {
   499     HB_DEPRECATED("HbScrollArea::longPressEnabled() is deprecated");    
   517     HB_DEPRECATED("HbScrollArea::longPressEnabled() is deprecated");    
   500     return false;
   518     return false;
   501 }
   519 }
   502 
   520 
   503 /*!
   521 /*!
   504   Sets the value of the handleLongPress property.  This value is set
   522     Sets the value of the \c handleLongPress property. Set \a value to true if
   505   to true if the widget is to respond to long press gestures, false otherwise.
   523     the widget responds to long press gestures. Otherwise set it to false.
   506  
   524     The default value is false.
   507   The default value is false.
   525 
   508  
   526     \deprecated This function is deprecated.
   509   \deprecated HbScrollArea::setLongPressEnabled(bool)
       
   510         is deprecated.
       
   511  
       
   512   \sa HbScrollArea::handleLongPress()
       
   513  */
   527  */
   514 void HbScrollArea::setLongPressEnabled (bool value)
   528 void HbScrollArea::setLongPressEnabled (bool value)
   515 {
   529 {
   516     HB_DEPRECATED("HbScrollArea::setLongPressEnabled(bool) is deprecated");
   530     HB_DEPRECATED("HbScrollArea::setLongPressEnabled(bool) is deprecated");
   517     Q_UNUSED(value);
   531     Q_UNUSED(value);
   518 }
   532 }
   519 
   533 
   520 /*
   534 /*!
   521   \reimp
   535     \reimp
   522  */
   536  */
   523 QVariant HbScrollArea::itemChange(GraphicsItemChange change, const QVariant &value)
   537 QVariant HbScrollArea::itemChange(GraphicsItemChange change, const QVariant &value)
   524 {
   538 {
   525     Q_D( HbScrollArea );
   539     Q_D( HbScrollArea );
   526 
   540 
   532     }
   546     }
   533 
   547 
   534     return HbWidget::itemChange(change, value);
   548     return HbWidget::itemChange(change, value);
   535 }
   549 }
   536 
   550 
   537 /*! @beta
   551 /*!
   538   upGesture() is a virtual slot function that is called whenever an
   552     A virtual slot function that is called when an upwards flick gesture is detected
   539   up flick gesture is detected, if the scrollDirection is set to
   553     while vertical scrolling is enabled.
   540   enable vertical scrolling.
   554 
   541  
   555     \deprecated This function is deprecated.
   542   Derived classes can override this method to add custom handling of
       
   543   the gesture.  In most cases, derived classes should call up to the
       
   544   HbScrollArea parent method.
       
   545  
       
   546   \deprecated HbScrollArea::upGesture(int)
       
   547         is deprecated.
       
   548  */
   556  */
   549 void HbScrollArea::upGesture(int speedPixelsPerSecond)
   557 void HbScrollArea::upGesture(int speedPixelsPerSecond)
   550 {
   558 {
   551     HB_DEPRECATED("HbScrollArea::upGesture(int) is deprecated. Use gesture FW.");
   559     HB_DEPRECATED("HbScrollArea::upGesture(int) is deprecated. Use gesture FW.");
   552 
   560 
   553     Q_UNUSED(speedPixelsPerSecond);
   561     Q_UNUSED(speedPixelsPerSecond);
   554 }
   562 }
   555 
   563 
   556 /*! @beta
   564 /*!
   557   downGesture() is a virtual slot function that is called whenever an
   565     A virtual slot function that is called when a downwards flick gesture is
   558   down flick gesture is detected, if the scrollDirection is set to
   566     detected while vertical scrolling is enabled.
   559   enable vertical scrolling. 
   567 
   560  
   568     \deprecated This function is deprecated.
   561   Derived classes can override this method to add custom handling of
       
   562   the gesture.  In most cases, derived classes should call up to the
       
   563   HbScrollArea parent method.
       
   564  
       
   565   \deprecated HbScrollArea::downGesture(int)
       
   566         is deprecated.
       
   567  */
   569  */
   568 void HbScrollArea::downGesture(int speedPixelsPerSecond)
   570 void HbScrollArea::downGesture(int speedPixelsPerSecond)
   569 {
   571 {
   570     HB_DEPRECATED("HbScrollArea::downGesture(int) is deprecated. Use gesture FW.");
   572     HB_DEPRECATED("HbScrollArea::downGesture(int) is deprecated. Use gesture FW.");
   571     Q_UNUSED(speedPixelsPerSecond);
   573     Q_UNUSED(speedPixelsPerSecond);
   572 }
   574 }
   573 
   575 
   574 /*! @beta
   576 /*!
   575   leftGesture() is a virtual slot function that is called whenever an
   577     A virtual slot function that is called when a left flick gesture
   576   left flick gesture is detected, if the scrollDirection is set to
   578     is detected while horizontal scrolling is enabled.
   577   enable horizontal scrolling.
   579 
   578  
   580     \deprecated This function is deprecated.
   579   Derived classes can override this method to add custom handling of
       
   580   the gesture.  In most cases, derived classes should call up to the
       
   581   HbScrollArea parent method.
       
   582  
       
   583   \deprecated HbScrollArea::leftGesture(int)
       
   584             is deprecated.
       
   585  */
   581  */
   586 void HbScrollArea::leftGesture(int speedPixelsPerSecond)
   582 void HbScrollArea::leftGesture(int speedPixelsPerSecond)
   587 {
   583 {
   588     HB_DEPRECATED("HbScrollArea::leftGesture(int) is deprecated. Use gesture FW.");
   584     HB_DEPRECATED("HbScrollArea::leftGesture(int) is deprecated. Use gesture FW.");
   589     Q_UNUSED(speedPixelsPerSecond);
   585     Q_UNUSED(speedPixelsPerSecond);
   590 }
   586 }
   591 
   587 
   592 /*! @beta
   588 /*!
   593   rightGesture() is a virtual slot function that is called whenever an
   589     A virtual slot function that is called when a right flick gesture is detected
   594   right flick gesture is detected, if the scrollDirection is set to
   590     while horizontal scrolling is enabled.
   595   enable horizontal scrolling.
   591 
   596  
   592     \deprecated This function is deprecated.
   597   Derived classes can override this method to add custom handling of
       
   598   the gesture.  In most cases, derived classes should call up to the
       
   599   HbScrollArea parent method.
       
   600  
       
   601   \deprecated HbScrollArea::rightGesture(int)
       
   602         is deprecated.
       
   603  */
   593  */
   604 void HbScrollArea::rightGesture(int speedPixelsPerSecond)
   594 void HbScrollArea::rightGesture(int speedPixelsPerSecond)
   605 {
   595 {
   606     HB_DEPRECATED("HbScrollArea::rightGesture(int) is deprecated. Use gesture FW.");
   596     HB_DEPRECATED("HbScrollArea::rightGesture(int) is deprecated. Use gesture FW.");
   607     Q_UNUSED(speedPixelsPerSecond);
   597     Q_UNUSED(speedPixelsPerSecond);
   608 }
   598 }
   609 
   599 
   610 
   600 
   611 /*!
   601 /*!
   612   panGesture() is a virtual slot function that is called whenever an
   602     A virtual slot function that is called when a pan gesture is detected.
   613   pan gesture is detected.
   603 
   614  
   604     \deprecated This function is deprecated.
   615   Derived classes can override this method to add custom handling of
       
   616   the gesture.  In most cases, derived classes should call up to the
       
   617   HbScrollArea parent method.
       
   618  
       
   619   \deprecated HbScrollArea::panGesture(const QPointF&)
       
   620    is deprecated.
       
   621  */
   605  */
   622 void HbScrollArea::panGesture(const QPointF &delta)
   606 void HbScrollArea::panGesture(const QPointF &delta)
   623 {
   607 {
   624     HB_DEPRECATED("HbScrollArea::panGesture(const QPointF &) is deprecated. Use gesture FW.");
   608     HB_DEPRECATED("HbScrollArea::panGesture(const QPointF &) is deprecated. Use gesture FW.");
   625     Q_UNUSED(delta);
   609     Q_UNUSED(delta);
   626 }
   610 }
   627 
   611 
   628 /*!  @beta
   612 /*!
   629   longPressGesture() is a virtual slot function that is called whenever an
   613     A virtual slot function that is called when a long press gesture is
   630   long press gesture is detected, if the handleLongPress property is set to true.
   614     detected while the \c handleLongPress property is set to true.
       
   615 
       
   616     \deprecated This function is deprecated.
       
   617  */
       
   618 void HbScrollArea::longPressGesture(const QPointF &)
       
   619 {
       
   620     HB_DEPRECATED("HbScrollArea::longPressGesture(const QPointF &) is deprecated. Use gesture FW.");
       
   621 }
       
   622 
       
   623 /*!
       
   624     Reimplemented from QObject.
       
   625  */
       
   626 void HbScrollArea::mousePressEvent(QGraphicsSceneMouseEvent *event)
       
   627 {
       
   628     Q_UNUSED (event);
       
   629 }
       
   630 
       
   631 /*!
       
   632     Returns true if a scrolling action is in progress, false otherwise.
       
   633  */
       
   634 bool HbScrollArea::isScrolling() const
       
   635 {
       
   636     Q_D( const HbScrollArea );
       
   637 
       
   638     return d->mIsScrolling;
       
   639 }
       
   640 
       
   641 /*!
       
   642     Returns true if the scrolling is in a response to the user dragging, false if it
       
   643     is the follow-on scrolling animation.
       
   644  */
       
   645 bool HbScrollArea::isDragging() const
       
   646 {
       
   647     Q_D( const HbScrollArea );
       
   648 
       
   649     return (d->mIsScrolling && !d->mIsAnimating);
       
   650 }
       
   651 
       
   652 /*!
       
   653     Scrolls the view by the amount indicated by \a delta and returns true if
       
   654     the scroll was successful and false otherwise.
       
   655 
       
   656     This is a virtual function, which subclasses can override to customize the
       
   657     behavior; for example, to clamp the position so that at least one item in
       
   658     the view remains visible.
       
   659  */
       
   660 bool HbScrollArea::scrollByAmount(const QPointF& delta)
       
   661 {
       
   662     Q_D( HbScrollArea );
       
   663 
       
   664     return d->scrollByAmount(delta);
       
   665 }
   631  
   666  
   632   Derived classes can override this method to add custom handling of
       
   633   the gesture.  By default, HbScrollArea does not respond to a long press.
       
   634  
       
   635   \deprecated HbScrollArea::longPressGesture(const QPointF&)
       
   636    is deprecated.
       
   637  
       
   638   \sa setHandleLongPress(), handleLongPress()
       
   639  */
       
   640 void HbScrollArea::longPressGesture(const QPointF &)
       
   641 {
       
   642     HB_DEPRECATED("HbScrollArea::longPressGesture(const QPointF &) is deprecated. Use gesture FW.");
       
   643 }
       
   644 
       
   645 /*!
   667 /*!
   646     \reimp
   668     \reimp
   647  */
       
   648 void HbScrollArea::mousePressEvent(QGraphicsSceneMouseEvent *event)
       
   649 {
       
   650     Q_UNUSED (event);
       
   651 }
       
   652 
       
   653 /*!
       
   654   Returns true if a scrolling action is in progress, false otherwise.
       
   655  */
       
   656 bool HbScrollArea::isScrolling() const
       
   657 {
       
   658     Q_D( const HbScrollArea );
       
   659 
       
   660     return d->mIsScrolling;
       
   661 }
       
   662 
       
   663 /*!
       
   664   Returns true if the scrolling is due to dragging as opposed to follow-on scrolling
       
   665  */
       
   666 bool HbScrollArea::isDragging() const
       
   667 {
       
   668     Q_D( const HbScrollArea );
       
   669 
       
   670     return (d->mIsScrolling && !d->mIsAnimating);
       
   671 }
       
   672 
       
   673 /*!
       
   674   Scrolls the view by the amount indicated by "delta".
       
   675  
       
   676   The function returns TRUE if the view was able to scroll, FALSE otherwise.
       
   677  
       
   678   The function is virtual so subclasses can override it to customize the behavior by, for example, 
       
   679   clamping the position so that at least one item in the view remains visible.
       
   680  */
       
   681 bool HbScrollArea::scrollByAmount(const QPointF& delta)
       
   682 {
       
   683     Q_D( HbScrollArea );
       
   684 
       
   685     return d->scrollByAmount(delta);
       
   686 }
       
   687  
       
   688 /*!
       
   689    \reimp
       
   690  */
   669  */
   691 bool HbScrollArea::event(QEvent *event)
   670 bool HbScrollArea::event(QEvent *event)
   692 {
   671 {
   693     Q_D(HbScrollArea);
   672     Q_D(HbScrollArea);
   694     bool value(false);
   673     bool value(false);
   766                     newSize.setWidth(size().width());
   745                     newSize.setWidth(size().width());
   767                     sizeChanged = true;
   746                     sizeChanged = true;
   768                 }
   747                 }
   769                 if (sizeChanged) {
   748                 if (sizeChanged) {
   770                     d->mContents->resize(newSize);
   749                     d->mContents->resize(newSize);
   771                     d->updateScrollMetrics();
       
   772                 } else {
       
   773                     d->adjustContent();
       
   774                 }
   750                 }
       
   751                 d->adjustContent();
   775             }
   752             }
   776         }
   753         }
   777     }
   754     }
   778   return value;
   755   return value;
   779 }
   756 }
   780 
   757 
   781 /*!
   758 /*!
   782    \reimp
   759     Reimplemented from QObject.
   783  */
   760  */
   784 bool HbScrollArea::eventFilter(QObject *obj, QEvent *event)
   761 bool HbScrollArea::eventFilter(QObject *obj, QEvent *event)
   785 {
   762 {
   786     Q_UNUSED(obj);
   763     Q_UNUSED(obj);
   787     Q_D(HbScrollArea);
   764     Q_D(HbScrollArea);
   801 
   778 
   802     return false;
   779     return false;
   803 }
   780 }
   804 
   781 
   805 /*!
   782 /*!
   806     \reimp
   783     Reimplemented from QGraphicsWidget.
   807 */
   784  */
   808 QSizeF HbScrollArea::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const
   785 QSizeF HbScrollArea::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const
   809 {
   786 {
   810     Q_D ( const HbScrollArea );
   787     Q_D ( const HbScrollArea );
   811 
   788 
   812     QSizeF sh(0, 0);
   789     QSizeF sh(0, 0);
   814     switch (which) {
   791     switch (which) {
   815         case Qt::MinimumSize:
   792         case Qt::MinimumSize:
   816             break;
   793             break;
   817         case Qt::PreferredSize:
   794         case Qt::PreferredSize:
   818             if (d->mContents) {
   795             if (d->mContents) {
   819                 sh = d->mContents->effectiveSizeHint( which, constraint );
   796                 sh = d->mContents->effectiveSizeHint( which );
   820             } else {
   797             } else {
   821                 sh = HbWidget::sizeHint( which, constraint );
   798                 sh = HbWidget::sizeHint( which, constraint );
   822             }
   799             }
   823             break;
   800             break;
   824         case Qt::MaximumSize:
   801         case Qt::MaximumSize:
   831     
   808     
   832     return sh;
   809     return sh;
   833 }
   810 }
   834 
   811 
   835 /*!
   812 /*!
   836  \reimp
   813     \reimp
   837  */
   814  */
   838 void HbScrollArea::focusOutEvent( QFocusEvent *event )
   815 void HbScrollArea::focusOutEvent( QFocusEvent *event )
   839 {
   816 {
   840     Q_D ( HbScrollArea );
   817     Q_D ( HbScrollArea );
   841     Q_UNUSED ( event );
   818     Q_UNUSED ( event );
   873 }
   850 }
   874 
   851 
   875 #endif
   852 #endif
   876 
   853 
   877 /*!
   854 /*!
   878     Returns the scrollbar policy for vertical scrollbar
   855     Returns the display policy for the vertical scrollbar.
   879 
   856 
   880     \sa horizontalScrollBarPolicy(), setVerticalScrollBarPolicy()
   857     \sa horizontalScrollBarPolicy(), setVerticalScrollBarPolicy()
   881 */
   858  */
   882 HbScrollArea::ScrollBarPolicy HbScrollArea::verticalScrollBarPolicy() const
   859 HbScrollArea::ScrollBarPolicy HbScrollArea::verticalScrollBarPolicy() const
   883 {
   860 {
   884     Q_D(const HbScrollArea);
   861     Q_D(const HbScrollArea);
   885     return d->mVerticalScrollBarPolicy;
   862     return d->mVerticalScrollBarPolicy;
   886 }
   863 }
   887 
   864 
   888 /*!
   865 /*!
   889     Sets the policy for vertical scrollbar
   866     Sets the display policy for the vertical scrollbar. The possible values are
   890 
   867     defined by the HbScrollArea::ScrollBarPolicy enum. The default value is
   891     The default policy is HbScrollArea::ScrollBarAutoHide.
   868     HbScrollArea::ScrollBarAutoHide.
   892 
   869 
   893     \sa setHorizontalScrollBarPolicy(), verticalScrollBarPolicy()
   870     \sa setHorizontalScrollBarPolicy(), verticalScrollBarPolicy(), setVerticalScrollBar()
   894 */
   871 */
   895 void HbScrollArea::setVerticalScrollBarPolicy(ScrollBarPolicy policy)
   872 void HbScrollArea::setVerticalScrollBarPolicy(ScrollBarPolicy policy)
   896 {
   873 {
   897     Q_D(HbScrollArea);
   874     Q_D(HbScrollArea);
   898     d->setScrollBarPolicy(Qt::Vertical, policy);
   875     d->setScrollBarPolicy(Qt::Vertical, policy);
   899 }
   876 }
   900 
   877 
   901 /*!
   878 /*!
   902   Returns the vertical scroll bar.
   879     Returns the vertical scroll bar.
   903 
   880 
   904   \sa verticalScrollBarPolicy(), horizontalScrollBar()
   881     \sa verticalScrollBarPolicy(), horizontalScrollBar()
   905  */
   882  */
   906 HbScrollBar *HbScrollArea::verticalScrollBar() const
   883 HbScrollBar *HbScrollArea::verticalScrollBar() const
   907 {
   884 {
   908     Q_D(const HbScrollArea);
   885     Q_D(const HbScrollArea);
   909     return d->mVerticalScrollBar;
   886     return d->mVerticalScrollBar;
   910 }
   887 }
   911 
   888 
   912 /*!
   889 /*!
   913    Replaces the existing vertical scroll bar with \a scrollBar. The former
   890     Replaces the existing vertical scroll bar with \a scrollBar. The former
   914    scroll bar is deleted.
   891     scroll bar is deleted.
   915 
   892 
   916    HbScrollArea already provides vertical and horizontal scroll bars by
   893     %HbScrollArea provides provides vertical and horizontal scroll bars by default.
   917    default. You can call this function to replace the default vertical
   894     Call this function to replace the default vertical scroll bar with your own
   918    scroll bar with your own custom scroll bar.
   895     custom scroll bar, if required.
   919 
   896 
   920    \sa verticalScrollBar(), setHorizontalScrollBar()
   897     \sa verticalScrollBar(), setHorizontalScrollBar()
   921 */
   898  */
   922 void HbScrollArea::setVerticalScrollBar(HbScrollBar *scrollBar)
   899 void HbScrollArea::setVerticalScrollBar(HbScrollBar *scrollBar)
   923 {
   900 {
   924     Q_D(HbScrollArea);
   901     Q_D(HbScrollArea);
   925     if (!scrollBar) {
   902     if (!scrollBar) {
   926         qWarning("HbScrollArea::setVerticalScrollBar: Cannot set a null scroll bar");
   903         qWarning("HbScrollArea::setVerticalScrollBar: Cannot set a null scroll bar");
   929 
   906 
   930     d->replaceScrollBar(Qt::Vertical, scrollBar);
   907     d->replaceScrollBar(Qt::Vertical, scrollBar);
   931 }
   908 }
   932 
   909 
   933 /*!
   910 /*!
   934     \brief Returns the policy for horizontal scrollbar
   911     Returns the display policy for the horizontal scrollbar.
   935 
   912 
   936     \sa verticalScrollBarPolicy(), setHorizontalScrollBarPolicy()
   913     \sa verticalScrollBarPolicy(), setHorizontalScrollBarPolicy()
   937 */
   914  */
   938 HbScrollArea::ScrollBarPolicy HbScrollArea::horizontalScrollBarPolicy() const
   915 HbScrollArea::ScrollBarPolicy HbScrollArea::horizontalScrollBarPolicy() const
   939 {
   916 {
   940     Q_D(const HbScrollArea);
   917     Q_D(const HbScrollArea);
   941     return d->mHorizontalScrollBarPolicy;
   918     return d->mHorizontalScrollBarPolicy;
   942 }
   919 }
   943 
   920 
   944 /*!
   921 /*!
   945     \brief Sets the policy for horizontal scrollbar
   922     Sets the display policy for the horizontal scrollbar. The possible values are
   946 
   923     defined by the HbScrollArea::ScrollBarPolicy enum. The default value is
   947     The default policy is HbScrollArea::ScrollBarAutoHide.
   924     HbScrollArea::ScrollBarAutoHide.
   948 
   925 
   949     \sa setVerticalScrollBarPolicy(), horizontalScrollBarPolicy()
   926     \sa setVerticalScrollBarPolicy(), horizontalScrollBarPolicy(), setHorizontalScrollBar()
   950 */
   927 */
   951 void HbScrollArea::setHorizontalScrollBarPolicy(ScrollBarPolicy policy)
   928 void HbScrollArea::setHorizontalScrollBarPolicy(ScrollBarPolicy policy)
   952 {
   929 {
   953     Q_D(HbScrollArea);    
   930     Q_D(HbScrollArea);    
   954     d->setScrollBarPolicy(Qt::Horizontal, policy);
   931     d->setScrollBarPolicy(Qt::Horizontal, policy);
   955 }
   932 }
   956 
   933 
   957 /*!
   934 /*!
   958   Returns the horizontal scroll bar.
   935     Returns the horizontal scroll bar.
   959 
   936 
   960   \sa horizontalScrollBarPolicy(), verticalScrollBar()
   937     \sa horizontalScrollBarPolicy(), verticalScrollBar()
   961  */
   938  */
   962 HbScrollBar *HbScrollArea::horizontalScrollBar() const
   939 HbScrollBar *HbScrollArea::horizontalScrollBar() const
   963 {
   940 {
   964     Q_D(const HbScrollArea);
   941     Q_D(const HbScrollArea);
   965     return d->mHorizontalScrollBar;
   942     return d->mHorizontalScrollBar;
   967 
   944 
   968 /*!
   945 /*!
   969    Replaces the existing horizontal scroll bar with \a scrollBar. The former
   946    Replaces the existing horizontal scroll bar with \a scrollBar. The former
   970    scroll bar is deleted.
   947    scroll bar is deleted.
   971 
   948 
   972    HbScrollArea already provides vertical and horizontal scroll bars by
   949    %HbScrollArea provides vertical and horizontal scroll bars by default.
   973    default. You can call this function to replace the default horizontal
   950    Call this function to replace the default horizontal scroll bar with your
   974    scroll bar with your own custom scroll bar.
   951    own custom scroll bar, if required.
   975 
   952 
   976    \sa horizontalScrollBar(), setVerticalScrollBar()
   953    \sa horizontalScrollBar(), setVerticalScrollBar()
   977 */
   954 */
   978 void HbScrollArea::setHorizontalScrollBar(HbScrollBar *scrollBar)
   955 void HbScrollArea::setHorizontalScrollBar(HbScrollBar *scrollBar)
   979 {
   956 {
   985 
   962 
   986     d->replaceScrollBar(Qt::Horizontal, scrollBar);
   963     d->replaceScrollBar(Qt::Horizontal, scrollBar);
   987 }
   964 }
   988 
   965 
   989 /*!
   966 /*!
   990     \brief the alignment of the scroll area's widget    
   967     Sets the alignment of the scroll area's content widget. The possible values are
   991 
   968     defined by the Qt::Alignment enum.
   992     By default, the widget stays rooted to the top-left corner of the
   969 
   993     scroll area.
   970     The default value is \c Qt::AlignLeft | \c Qt::AlignTop, which roots the content
   994     \sa alignment
   971     widget in the top-left corner of the scroll area.
       
   972 
       
   973     \sa alignment()
   995 */
   974 */
   996 
   975 
   997 void HbScrollArea::setAlignment(Qt::Alignment alignment)
   976 void HbScrollArea::setAlignment(Qt::Alignment alignment)
   998 {
   977 {
   999     Q_D(HbScrollArea);
   978     Q_D(HbScrollArea);
  1001     d->mResetAlignment = true;
   980     d->mResetAlignment = true;
  1002     if (d->mContents)
   981     if (d->mContents)
  1003         d->adjustContent();
   982         d->adjustContent();
  1004 }
   983 }
  1005 /*!
   984 /*!
  1006     \brief the alignment of the scroll area's widget
   985     Returns the alignment of the scroll area's content widget.
  1007 
   986 
  1008     By default, the widget stays rooted to the top-left corner of the
   987     \sa setAlignment()
  1009     scroll area.
   988  */
  1010     \sa setAlignment
       
  1011 */
       
  1012 Qt::Alignment HbScrollArea::alignment() const
   989 Qt::Alignment HbScrollArea::alignment() const
  1013 {
   990 {
  1014     Q_D(const HbScrollArea);
   991     Q_D(const HbScrollArea);
  1015     return d->mAlignment;
   992     return d->mAlignment;
  1016 }
   993 }
  1017 
   994 
  1018 
   995 
  1019 /*!
   996 /*!
  1020     \brief Contination indicators for scroll area
   997     Sets the \c contuationIndicators property for the scroll area. Set
  1021 
   998     \a indication to true if you want the scroll area to provide visual
  1022     By default continuation graphics are disabled. When continuation
   999     feedback when scrolling is possible. The default value is false.
  1023     graphics are enabled, scroll area shows indications where it is
  1000 
  1024     possible to scroll.
  1001     \sa continuationIndicators()
  1025 
  1002  */
  1026     \sa continuationIndicators
       
  1027 */
       
  1028 
       
  1029 void HbScrollArea::setContinuationIndicators(bool indication)
  1003 void HbScrollArea::setContinuationIndicators(bool indication)
  1030 {
  1004 {
  1031     Q_D(HbScrollArea);
  1005     Q_D(HbScrollArea);
  1032     if (d->mContinuationIndicators == indication)
  1006     if (d->mContinuationIndicators == indication)
  1033         return;
  1007         return;
  1039     }
  1013     }
  1040     repolish();
  1014     repolish();
  1041 }
  1015 }
  1042 
  1016 
  1043 /*!
  1017 /*!
  1044     \brief Contination indicators for scroll area
  1018     Returns the value of the \c continuationIndicators property for the
  1045 
  1019     scroll area.
  1046     By default continuation graphics are disabled. When continuation
  1020 
  1047     graphics are enabled, scroll area shows indications where it is
  1021     \sa setContinuationIndicators()
  1048     possible to scroll.
       
  1049 
       
  1050     \sa setContinuationIndicators
       
  1051 */
  1022 */
  1052 bool HbScrollArea::continuationIndicators() const
  1023 bool HbScrollArea::continuationIndicators() const
  1053 {
  1024 {
  1054     Q_D(const HbScrollArea);
  1025     Q_D(const HbScrollArea);
  1055     return d->mContinuationIndicators;
  1026     return d->mContinuationIndicators;
  1056 }
  1027 }
  1057 
  1028 
  1058 
  1029 
  1059 /*!
  1030 
  1060     Scrolls the contents of the scroll area so that the point \a position is visible
  1031 /*!
  1061     inside the region of the scrollArea with margins specified in pixels by \a xMargin and
  1032     Scrolls the contents of the scroll area so that \a position is visible within
  1062     \a yMargin. If the specified point cannot be reached, the contents are scrolled to
  1033     the scroll area with the given margins. If the specified point cannot be shown,
  1063     the nearest valid position. The default and minimum valid value for both margins is 0 pixels.
  1034     the contents are scrolled to the nearest valid position.
  1064     Valid range for \a xMargin is between 0 and width of scrollArea, valid range for \a yMargin is
  1035 
  1065     between 0 and height of scrollArea.\a xMargin, \a yMargin, x and y values of \a position will be
  1036     \param position Defines the position within the content widget that is to be shown within
  1066     ignored depending on scrollingDirection.
  1037                the scroll area.
       
  1038     \param xMargin The width of the vertical margins in pixels. This can be between 0 and the
       
  1039                width of the scroll area. The default value is 0.
       
  1040 
       
  1041     \param yMargin The height of the horizontal margins in pixels. This can be between 0
       
  1042                and the height of the scroll area. The default value is 0.
  1067 
  1043 
  1068     \sa setScrollDirections()
  1044     \sa setScrollDirections()
  1069 */
  1045  */
  1070 void HbScrollArea::ensureVisible(const QPointF& position, qreal xMargin, qreal yMargin)
  1046 void HbScrollArea::ensureVisible(const QPointF& position, qreal xMargin, qreal yMargin)
  1071 {
  1047 {
  1072     Q_D(HbScrollArea);
  1048     Q_D(HbScrollArea);
  1073     d->ensureVisible(position, xMargin, yMargin);
  1049     d->ensureVisible(position, xMargin, yMargin);
  1074 }
  1050 }
  1075 
  1051 
  1076 /*!
  1052 /*!
  1077     Scrolls the contents of the scroll area to the \a newPosition in a given \a time.
  1053     Scrolls the contents of the scroll area to \a newPosition in the given \a time.
  1078     If the time is 0, contents is scrolled to the position instantly.
  1054     If \a time is 0, the contents are scrolled to the position immediately.
  1079 */
  1055  */
  1080 void HbScrollArea::scrollContentsTo (const QPointF& newPosition, int time) {
  1056 void HbScrollArea::scrollContentsTo (const QPointF& newPosition, int time) {
  1081     Q_D(HbScrollArea);
  1057     Q_D(HbScrollArea);
  1082 
  1058 
  1083     if (!contentWidget())
  1059     if (!contentWidget())
  1084         return;
  1060         return;
       
  1061 
       
  1062     d->stopAnimating();
       
  1063     d->stopScrolling();
  1085 
  1064 
  1086     if (time > 0){
  1065     if (time > 0){
  1087         d->startTargetAnimation (newPosition, qMax (0, time));
  1066         d->startTargetAnimation (newPosition, qMax (0, time));
  1088     } else {
  1067     } else {
  1089         scrollByAmount(newPosition - (-d->mContents->pos()));
  1068         scrollByAmount(newPosition - (-d->mContents->pos()));
  1090         d->stopScrolling();
  1069         d->stopScrolling();
  1091     }
  1070     }
  1092 }
  1071 }
  1093 
  1072 
  1094 /*!
  1073 /*!
  1095   \reimp
  1074     \reimp
  1096  */
  1075  */
  1097 void HbScrollArea::polish(HbStyleParameters& params)
  1076 void HbScrollArea::polish(HbStyleParameters& params)
  1098 {
  1077 {
  1099     if (isVisible()) {
  1078     if (isVisible()) {
  1100         Q_D(HbScrollArea);
  1079         Q_D(HbScrollArea);
  1141         HbWidget::polish(params);
  1120         HbWidget::polish(params);
  1142     }
  1121     }
  1143 }
  1122 }
  1144 
  1123 
  1145 /*!
  1124 /*!
  1146   \reimp
  1125     Reimplemented from QObject.
  1147 
       
  1148  */
  1126  */
  1149 void HbScrollArea::timerEvent(QTimerEvent *event)
  1127 void HbScrollArea::timerEvent(QTimerEvent *event)
  1150 {
  1128 {
  1151     Q_D(HbScrollArea);
  1129     Q_D(HbScrollArea);
  1152     if (event->timerId() == d->mScrollTimerId) {
  1130     if (event->timerId() == d->mScrollTimerId) {
  1155         d->_q_hideScrollBars();
  1133         d->_q_hideScrollBars();
  1156     }
  1134     }
  1157 }
  1135 }
  1158 
  1136 
  1159 /*!
  1137 /*!
  1160  \reimp
  1138     Reimplemented from QGraphicsWidget.
  1161  */
  1139  */
  1162 QPainterPath HbScrollArea::shape() const
  1140 QPainterPath HbScrollArea::shape() const
  1163 {
  1141 {
  1164     Q_D(const HbScrollArea);
  1142     Q_D(const HbScrollArea);
  1165     if ( d->mClearCachedRect){
  1143     if ( d->mClearCachedRect){
  1167     }
  1145     }
  1168     return d->mShape;
  1146     return d->mShape;
  1169 }
  1147 }
  1170 
  1148 
  1171 /*!
  1149 /*!
  1172  \reimp
  1150     Reimplemented from QGraphicsWidget.
  1173  */
  1151  */
  1174 QRectF HbScrollArea::boundingRect() const
  1152 QRectF HbScrollArea::boundingRect() const
  1175 
  1153 
  1176 {
  1154 {
  1177     Q_D(const HbScrollArea);
  1155     Q_D(const HbScrollArea);
  1180     }
  1158     }
  1181     return d->mBoundingRect;
  1159     return d->mBoundingRect;
  1182 }
  1160 }
  1183 
  1161 
  1184 /*!
  1162 /*!
  1185  \reimp
  1163     Reimplemented from QGraphicsWidget.
  1186  */
  1164  */
  1187 void HbScrollArea::setGeometry(const QRectF& rect)
  1165 void HbScrollArea::setGeometry(const QRectF& rect)
  1188 {
  1166 {
  1189     Q_D(HbScrollArea);
  1167     Q_D(HbScrollArea);
  1190     d->mClearCachedRect = true;
  1168     d->mClearCachedRect = true;
  1191     HbWidget::setGeometry(rect);
  1169     HbWidget::setGeometry(rect);
  1192 }
  1170 }
  1193 
  1171 
  1194 /*!
  1172 /*!
  1195     \reimp
  1173     Reimplemented from QObject.
  1196 */
  1174  */
  1197 void HbScrollArea::disconnectNotify (const char *signal)
  1175 void HbScrollArea::disconnectNotify (const char *signal)
  1198 {
  1176 {
  1199     Q_D(HbScrollArea);
  1177     Q_D(HbScrollArea);
  1200     if (d->mEmitPositionChangedSignal &&
  1178     if (d->mEmitPositionChangedSignal &&
  1201         QLatin1String(signal) == SIGNAL(scrollPositionChanged(QPointF))) {
  1179         QLatin1String(signal) == SIGNAL(scrollPositionChanged(QPointF))) {
  1205     }
  1183     }
  1206     HbWidget::disconnectNotify(signal);
  1184     HbWidget::disconnectNotify(signal);
  1207 }
  1185 }
  1208 
  1186 
  1209 /*!
  1187 /*!
  1210     \reimp
  1188     Reimplemented from QObject.
  1211 */
  1189  */
  1212 void HbScrollArea::connectNotify(const char * signal)
  1190 void HbScrollArea::connectNotify(const char * signal)
  1213 {
  1191 {
  1214     Q_D(HbScrollArea);
  1192     Q_D(HbScrollArea);
  1215     if (!d->mEmitPositionChangedSignal &&
  1193     if (!d->mEmitPositionChangedSignal &&
  1216         QLatin1String(signal) == SIGNAL(scrollPositionChanged(QPointF))) {
  1194         QLatin1String(signal) == SIGNAL(scrollPositionChanged(QPointF))) {