44 static const qreal THRESHOLD_VALUE = 2.0; |
44 static const qreal THRESHOLD_VALUE = 2.0; |
45 /*! |
45 /*! |
46 @stable |
46 @stable |
47 @hbcore |
47 @hbcore |
48 \class HbScrollBar |
48 \class HbScrollBar |
49 \brief HbScrollBar represents a scrollbar that can be used in different kinds of lists, options |
49 \brief The HbScrollBar class provides a vertical or horizontal scroll bar. |
50 menus and editors. |
50 |
51 |
51 Scroll bars indicate that more content is available than can fit within a container and |
52 A vertical scrollbar is created in this example to listview-parent and also shown: |
52 that the contents can be scrolled. A scroll bar consists of a groove and a handle (which |
|
53 is sometimes called a thumb). The position of the handle on the groove indicates the |
|
54 position of the visible content within the available contents. The size of the handle |
|
55 indicates the amount of content that is visible relative to the total. For example, a |
|
56 small handle indicates that there is a lot more content that is out of view. |
|
57 |
|
58 Scroll bars float above the content and do not need reserved space. There are two types of |
|
59 scroll bar: |
|
60 |
|
61 - <b>Indicative</b>. These scroll bars simply give an indication that the content can be |
|
62 scrolled and they do not provide features that enable scrolling (the ability to scroll |
|
63 is provided by the widget to which the scroll bar is attached). Indicative scroll bars are |
|
64 suitable for shorter lists and content that you expect the user to browse rather than to |
|
65 search for specific items. This is the default type of scroll bar. |
|
66 |
|
67 - <b>Interactive</b>. With this type of scroll bar, the user can drag the handle or press the |
|
68 groove to change the scroll position. When used in an item model view (classes derived |
|
69 from HbAbstractItemView), these scroll bars can provide index feedback (HbIndexFeedback |
|
70 class) when the user drags the scroll bar or taps on the groove. The feedback is a popup |
|
71 that shows, for example, the initial letter in an alphabetical list. Interactive scroll bars |
|
72 are particularly suitable for long lists. |
|
73 |
|
74 Call \link HbScrollBar::setInteractive() setInteractive(true)\endlink to make a scroll bar |
|
75 interactive. Call isInteractive() to discover whether a scroll bar is interactive. |
|
76 |
|
77 \image html hbscrollbar.png A list view with a vertical interactive scroll bar |
|
78 |
|
79 %HbScrollBar provides other properties that control the following aspects of a scroll bar: |
|
80 |
|
81 - <b>Value</b>. This is a real value in the range 0.0 to 1.0 that indicates how far the handle |
|
82 is from the start of the groove. For example, 0.5 means the handle is half way along the |
|
83 groove. Call setValue() to set this property. |
|
84 |
|
85 - <b>Page size</b>. This is a real value in the range 0.0 to 1.0 that indicates how much of the |
|
86 total contents are currently visible. This property also controls the size of the handle. |
|
87 For example, a page size of 0.1 indicates that one out of ten pages are visible. Call |
|
88 setPageSize() to set this property. |
|
89 |
|
90 - <b>Orientation</b>. This controls whether the scroll bar is horizontal or vertical. Call |
|
91 setOrientation() to set this property. |
|
92 |
|
93 \section _usecases_hbscrollbar Using the HbScrollBar class |
|
94 |
|
95 Although it is possible to create an HbScrollBar object directly, scroll bars are created |
|
96 automatically when you create an HbScrollArea object or one of the item view classes that |
|
97 are derived from it. This example demonstrates changing the default scroll bars |
|
98 created for an HbScrollArea object from indicative to interactive: |
53 |
99 |
54 \code |
100 \code |
55 //HbListView *listView is defined already |
101 scrollArea->verticalScrollBar()->setInteractive(true); |
56 HbScrollBar *scrollbar = new HbScrollBar(Qt::Vertical, listView); |
102 scrollArea->horizontalScrollBar()->setInteractive(true); |
57 scrollbar->show(); |
|
58 \endcode |
103 \endcode |
59 |
104 |
60 By default scrollbar is hidden. |
105 You can replace the existing scroll bars by calling HbScrollArea::setHorizontalScrollBar() |
61 */ |
106 and HbScrollArea::setVerticalScrollBar(). |
62 |
107 |
63 /*! |
108 \sa HbScrollArea, HbAbstractItemView, HbIndexFeedback |
64 \reimp |
109 */ |
|
110 |
|
111 /*! |
65 \fn int HbScrollBar::type() const |
112 \fn int HbScrollBar::type() const |
66 */ |
113 */ |
67 |
114 |
68 /*! |
115 /*! |
69 \fn void HbScrollBar::valueChanged( qreal value, Qt::Orientation orientation ) |
116 \fn void HbScrollBar::valueChanged( qreal value, Qt::Orientation orientation ); |
70 |
117 |
71 This signal is emitted when thumb position is changed by the user. |
118 This signal is emitted when the user changes the position of the handle in an interactive |
72 */ |
119 scroll bar. |
73 |
120 */ |
74 /*! |
121 |
75 \fn void valueChangeRequested( qreal value, Qt::Orientation orientation ); |
122 /*! |
76 |
123 \fn void HbScrollBar::valueChangeRequested( qreal value, Qt::Orientation orientation ); |
77 This signal is emitted when the user presses scrollbar groove. |
124 |
78 |
125 This signal is emitted when the user presses an interactive scroll bar's groove. The widget |
79 \param value, the new value of scrollbar after the change |
126 using the scroll bar must handle this signal (for example, by providing an animation that |
80 */ |
127 scrolls to the target position). |
|
128 |
|
129 \param value The value to which the user wants to scroll. |
|
130 \param orientation The scroll bar's orientation. |
|
131 |
|
132 \sa HbScrollBar::setInteractive() |
|
133 */ |
81 |
134 |
82 /*! |
135 /*! |
83 \primitives |
136 \primitives |
84 \primitive{groove} HbFrameItem representing the groove of a scrollbar. |
137 \primitive{groove} HbFrameItem representing the groove of a scroll bar. |
85 \primitive{handle} HbFrameItem representing the handle of a scrollbar. |
138 \primitive{handle} HbFrameItem representing the handle of a scroll bar. |
86 \primitive{toucharea} HbTouchArea representing the scrollbar toucharea. |
139 \primitive{toucharea} HbTouchArea representing the scroll bar toucharea. |
87 */ |
140 */ |
88 |
141 |
89 HbScrollBarPrivate::HbScrollBarPrivate(): |
142 HbScrollBarPrivate::HbScrollBarPrivate(): |
90 mOrientation(Qt::Vertical), |
143 mOrientation(Qt::Vertical), |
91 mCurrentPosition(0.5), |
144 mCurrentPosition(0.5), |
92 mPageSize(1.0), |
145 mPageSize(1.0), |
220 } |
273 } |
221 #endif |
274 #endif |
222 } |
275 } |
223 |
276 |
224 /*! |
277 /*! |
225 Constructs a scrollbar with \a parent. |
278 Constructs a scroll bar with the given \a parent. |
226 */ |
279 */ |
227 HbScrollBar::HbScrollBar( QGraphicsItem *parent ) : |
280 HbScrollBar::HbScrollBar( QGraphicsItem *parent ) : |
228 HbWidget(*new HbScrollBarPrivate, parent) |
281 HbWidget(*new HbScrollBarPrivate, parent) |
229 { |
282 { |
230 Q_D(HbScrollBar); |
283 Q_D(HbScrollBar); |
231 d->q_ptr = this; |
284 d->q_ptr = this; |
232 d->init(); |
285 d->init(); |
233 } |
286 } |
234 |
287 |
235 /*! |
288 /*! |
236 Constructs a scrollbar with \a orientation and \a parent. |
289 Constructs a scroll bar with the given \a orientation and \a parent. |
237 */ |
290 */ |
238 HbScrollBar::HbScrollBar( Qt::Orientation orientation, QGraphicsItem *parent ) : |
291 HbScrollBar::HbScrollBar( Qt::Orientation orientation, QGraphicsItem *parent ) : |
239 HbWidget( *new HbScrollBarPrivate, parent ) |
292 HbWidget( *new HbScrollBarPrivate, parent ) |
240 { |
293 { |
241 Q_D(HbScrollBar); |
294 Q_D(HbScrollBar); |
242 d->q_ptr = this; |
295 d->q_ptr = this; |
243 d->mOrientation = orientation; |
296 d->mOrientation = orientation; |
244 d->init(); |
297 d->init(); |
245 } |
298 } |
246 |
299 |
247 /*! |
300 /*! |
248 Destructor |
301 Destructor. |
249 */ |
302 */ |
250 HbScrollBar::~HbScrollBar() |
303 HbScrollBar::~HbScrollBar() |
251 { |
304 { |
252 } |
305 } |
253 |
306 |
254 /*! |
307 /*! |
255 Returns the value of the scrollbar. The value is in range of 0.0 to 1.0. |
308 Returns the scroll bar's \c value property. This indicates how far the handle is |
256 The value corresponds to the position of the thumb. |
309 from the start of the groove and can be in range of 0.0 to 1.0. |
257 |
310 |
258 \sa HbScrollBar::setValue() |
311 \sa HbScrollBar::setValue() |
259 */ |
312 */ |
260 qreal HbScrollBar::value() const |
313 qreal HbScrollBar::value() const |
261 { |
314 { |
262 Q_D( const HbScrollBar ); |
315 Q_D( const HbScrollBar ); |
263 return d->mCurrentPosition; |
316 return d->mCurrentPosition; |
264 } |
317 } |
265 |
318 |
266 /*! |
319 /*! |
267 Returns relative size of the visible area the scrollbar is attached to. |
320 Returns scroll bar's \c pageSize property. This is a real value in the range of 0.0 to |
268 For example if the pageSize is 0.2 it means that the overall size of the content |
321 1.0, which indicates the size of the visible content relative to the whole content. |
269 is five times larger than what is shown currently. |
322 For example, a page size of 0.2 indicates that the overall size of the content is five |
270 |
323 times larger than what is currently visible. |
271 The size is in range of 0.0 to 1.0. |
324 |
272 \sa HbScrollBar::setPageSize() |
325 \sa HbScrollBar::setPageSize() |
273 */ |
326 */ |
274 qreal HbScrollBar::pageSize() const |
327 qreal HbScrollBar::pageSize() const |
275 { |
328 { |
276 Q_D( const HbScrollBar ); |
329 Q_D( const HbScrollBar ); |
277 return d->mPageSize; |
330 return d->mPageSize; |
278 } |
331 } |
279 |
332 |
280 /*! |
333 /*! |
281 Returns the orientation of scrollbar. |
334 Returns the orientation of scroll bar. |
282 |
335 |
283 \sa HbScrollBar::setOrientation() |
336 \sa HbScrollBar::setOrientation() |
284 */ |
337 */ |
285 Qt::Orientation HbScrollBar::orientation() const |
338 Qt::Orientation HbScrollBar::orientation() const |
286 { |
339 { |
287 Q_D( const HbScrollBar ); |
340 Q_D( const HbScrollBar ); |
288 return d->mOrientation; |
341 return d->mOrientation; |
289 } |
342 } |
290 |
343 |
291 /*! |
344 /*! |
292 Returns whether scrollbar is in interactive mode. |
345 Returns true if the scroll bar is interactive and false if it is indicative. |
293 |
346 |
294 \sa HbScrollBar::setInteractive() |
347 \sa HbScrollBar::setInteractive() |
295 */ |
348 */ |
296 bool HbScrollBar::isInteractive() const |
349 bool HbScrollBar::isInteractive() const |
297 { |
350 { |
298 const Q_D(HbScrollBar); |
351 const Q_D(HbScrollBar); |
299 return d->mInteractive; |
352 return d->mInteractive; |
300 } |
353 } |
301 |
354 |
302 /*! |
355 /*! |
303 Sets the value of interactive property. If this value is set |
356 Sets the value of the scroll bar's \c interactive property, which controls whether the |
304 to true scrollbar is interactive, the user can change the scroll position by |
357 scroll bar is interactive or indicative (the default). |
305 dragging the thumb or pressing the groove. Dragging the thumb emits valueChanged |
358 |
306 signal and pressing the groove emits valueChangeRequested which means |
359 When the scroll bar is interactive, the user can drag the handle or press the groove to |
307 that the widget using scrollbars should handle the value change (for example |
360 change the scroll position. The following table lists the signals that an interactive |
308 by animating to the given target value). |
361 scroll bar emits when the user drags the handle or presses the groove. |
309 |
362 |
310 The default behavior is non interactive, |
363 <table border="1" style="border-collapse: collapse; border: solid;"> |
311 which means that the scrollbar is just indicative. |
364 <tr><th>Signal</th><th>Description</th></tr> |
|
365 <tr><td>valueChanged()</td><td>This signal is emitted when the user drags the handle.</td></tr> |
|
366 <tr><td>valueChangeRequested()</td><td>This signal is emitted when the user presses the scroll |
|
367 bar's groove. The widget using the scroll bar must handle this signal (for example, by |
|
368 providing an animation that moves to the target position).</td></tr> |
|
369 </table> |
|
370 |
|
371 \param enabled A Boolean value; true for an interactive scroll bar, false for an indicative |
|
372 scroll bar. |
312 |
373 |
313 \sa HbScrollBar::isInteractive() |
374 \sa HbScrollBar::isInteractive() |
314 */ |
375 */ |
315 void HbScrollBar::setInteractive( bool enabled ) |
376 void HbScrollBar::setInteractive( bool enabled ) |
316 { |
377 { |