51 setVerticalScrollBarPolicy( HbScrollArea::ScrollBarAlwaysOff ); |
51 setVerticalScrollBarPolicy( HbScrollArea::ScrollBarAlwaysOff ); |
52 |
52 |
53 // mItemParent is used to hold the unused QGraphicsItem's in the pool. It's visibility is set to false |
53 // mItemParent is used to hold the unused QGraphicsItem's in the pool. It's visibility is set to false |
54 // so the visibility of the items doesn't need to be modified. |
54 // so the visibility of the items doesn't need to be modified. |
55 mItemPoolParent->setVisible( false ); |
55 mItemPoolParent->setVisible( false ); |
56 |
|
57 connectAndTest( this, SIGNAL(scrollPositionChanged(QPointF)), |
|
58 this, SLOT(scrollPositionChanged(QPointF))); |
|
59 } |
56 } |
60 |
57 |
61 /*! |
58 /*! |
62 * |
59 * |
63 */ |
60 */ |
264 return; |
242 return; |
265 } |
243 } |
266 |
244 |
267 mStripLength = boundingRect().width(); |
245 mStripLength = boundingRect().width(); |
268 qreal itemSize = mItemSize.width(); |
246 qreal itemSize = mItemSize.width(); |
269 mContentsLength = mModel->rowCount() * (itemSize + mSpacing) + mSpacing; |
247 mContentsLength = mModel->rowCount() * (itemSize - mOverlap); |
270 |
248 |
271 if ( mIsCyclic ) |
249 if ( mIsCyclic ) |
272 { |
250 { |
273 // if treating the items cyclically, double the content area so it can |
251 // if treating the items cyclically, double the content area so it can |
274 // be shifted back and forth as you scroll |
252 // be shifted back and forth as you scroll |
275 mContentsLength = mModel->rowCount() * (itemSize + mSpacing); |
253 mContentsLength *= 2; |
276 mContentsLength *= 2.0; |
254 } |
277 } |
255 |
278 |
256 qreal currPos = -mOverlap; |
279 qreal currPos = mSpacing; |
|
280 for ( int i = 0; i < mModel->rowCount(); ++i ) { |
257 for ( int i = 0; i < mModel->rowCount(); ++i ) { |
281 if ( currPos > mStripLength ) |
258 if ( currPos > mStripLength ) |
282 { |
259 { |
283 break; |
260 break; |
284 } |
261 } |
285 |
262 |
286 QGraphicsItem* item = constructItem( i, true ); |
263 QGraphicsItem* item = constructItem( i, true ); |
287 if ( item ) |
264 if ( item ) |
288 { |
265 { |
289 item->setPos( QPointF( currPos, mSpacing ) ); |
266 item->setPos( QPointF( currPos, 0 ) ); |
290 currPos += itemSize + mSpacing; |
267 currPos += itemSize - mOverlap; |
291 } |
268 } |
292 } |
269 } |
293 |
270 |
294 QRectF contentsRect(0,0,0,0); |
271 mStripContainer->setPreferredSize( mContentsLength, mItemSize.height() ); |
295 contentsRect.setBottom( itemSize + 2 * mSpacing ); |
|
296 contentsRect.setRight( mContentsLength ); |
|
297 |
|
298 mStripContainer->setGeometry( contentsRect ); |
|
299 |
272 |
300 if ( mCurrentIndex >= 0 ) |
273 if ( mCurrentIndex >= 0 ) |
301 { |
274 { |
302 setIndex( mCurrentIndex, false ); |
275 setIndex( mCurrentIndex, false ); |
303 } |
276 } |
371 /*! |
344 /*! |
372 * Returns starting coordinate of the item with the specified index |
345 * Returns starting coordinate of the item with the specified index |
373 */ |
346 */ |
374 qreal RadioStripBase::indexToOffset( int index ) |
347 qreal RadioStripBase::indexToOffset( int index ) |
375 { |
348 { |
376 return index * ( mItemSize.width() + mSpacing ) + mSpacing; |
349 return index * ( mItemSize.width() - mOverlap ) - mOverlap; |
377 } |
350 } |
378 |
351 |
379 /*! |
352 /*! |
380 * Returns item index for specified offset amount into the content |
353 * Returns item index for specified offset amount into the content |
381 */ |
354 */ |
382 int RadioStripBase::offsetToIndex( qreal offset ) |
355 int RadioStripBase::offsetToIndex( qreal offset ) |
383 { |
356 { |
384 const int rows = mModel->rowCount(); |
357 const int rows = mModel->rowCount(); |
385 int index = (int)( ( offset - mSpacing) / ( mItemSize.width() + mSpacing ) ); |
358 int index = (int)( offset / ( mItemSize.width() - mOverlap ) ); |
386 |
359 |
387 if ( mIsCyclic ) |
360 if ( mIsCyclic ) |
388 { |
361 { |
389 return qBound( 0, index, 2 * rows - 1 ); |
362 return qBound( 0, index, 2 * rows - 1 ); |
390 } |
363 } |
490 for ( int i = firstItemToCreate; i >= firstVisibleIndex; --i ) |
463 for ( int i = firstItemToCreate; i >= firstVisibleIndex; --i ) |
491 { |
464 { |
492 QGraphicsItem* item = constructItem( i, false ); |
465 QGraphicsItem* item = constructItem( i, false ); |
493 if ( item ) |
466 if ( item ) |
494 { |
467 { |
495 item->setPos( QPointF( indexToOffset( i ), mSpacing ) ); |
468 item->setPos( QPointF( indexToOffset( i ), 0 ) ); |
496 } |
469 } |
497 } |
470 } |
498 |
471 |
499 // add missing items at the end |
472 // add missing items at the end |
500 firstItemToCreate = mIndexAtSlot.last()+1; |
473 firstItemToCreate = mIndexAtSlot.last()+1; |
501 for ( int i = firstItemToCreate; i <= lastVisibleIndex; ++i ) |
474 for ( int i = firstItemToCreate; i <= lastVisibleIndex; ++i ) |
502 { |
475 { |
503 QGraphicsItem* item = constructItem( i, true ); |
476 QGraphicsItem* item = constructItem( i, true ); |
504 if ( item ) |
477 if ( item ) |
505 { |
478 { |
506 item->setPos( QPointF( indexToOffset( i ), mSpacing ) ); |
479 item->setPos( QPointF( indexToOffset( i ), 0 ) ); |
507 } |
480 } |
508 } |
481 } |
509 } |
482 } |
510 } |
483 } |
|
484 |
|
485 /*! |
|
486 * \reimp |
|
487 */ |
|
488 bool RadioStripBase::scrollByAmount( const QPointF& delta ) |
|
489 { |
|
490 bool ret = HbScrollArea::scrollByAmount( delta ); |
|
491 |
|
492 adjustItems(); |
|
493 scrollPosChanged(); |
|
494 |
|
495 return ret; |
|
496 } |