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 |
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 |
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); |
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"); |
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); |