|
1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 #ifndef RADIOSTRIPBASE_H_ |
|
19 #define RADIOSTRIPBASE_H_ |
|
20 |
|
21 // System includes |
|
22 #include <hbscrollarea.h> |
|
23 |
|
24 // Forward declarations |
|
25 class HbWidget; |
|
26 class QAbstractItemModel; |
|
27 |
|
28 // Class declaration |
|
29 class RadioStripBase : public HbScrollArea |
|
30 { |
|
31 Q_OBJECT |
|
32 Q_PROPERTY( HbIcon background READ background WRITE setBackground ) |
|
33 Q_PROPERTY( int autoScrollTime READ autoScrollTime WRITE setAutoScrollTime ) |
|
34 |
|
35 public: |
|
36 |
|
37 virtual ~RadioStripBase(); |
|
38 |
|
39 void setBackground( const HbIcon& background ); |
|
40 HbIcon background() const; |
|
41 void setAutoScrollTime( const int time ); |
|
42 int autoScrollTime() const; |
|
43 |
|
44 void setModel( QAbstractItemModel* model ); |
|
45 QAbstractItemModel* model() const; |
|
46 |
|
47 void setCyclic( bool isCyclic ); |
|
48 void setSpacing( qreal spacing ); |
|
49 void setAutoCenter( bool autoCenter ); |
|
50 void setItemSize( const QSizeF& size ); |
|
51 void setIndex( int index, bool animateToCenter ); |
|
52 |
|
53 protected: |
|
54 |
|
55 RadioStripBase( QGraphicsItem* parent ); |
|
56 |
|
57 // from base class QGraphicsWidget |
|
58 |
|
59 void resizeEvent( QGraphicsSceneResizeEvent* event ); |
|
60 |
|
61 // from base class QGraphicsItem |
|
62 |
|
63 void mousePressEvent( QGraphicsSceneMouseEvent* event ); |
|
64 void mouseReleaseEvent( QGraphicsSceneMouseEvent* event ); |
|
65 |
|
66 private slots: |
|
67 |
|
68 void scrollPositionChanged( QPointF newPosition ); |
|
69 |
|
70 private: |
|
71 |
|
72 Q_DISABLE_COPY( RadioStripBase ) |
|
73 |
|
74 virtual void updateItemPrimitive( QGraphicsItem* itemToUpdate, int itemIndex ) = 0; |
|
75 virtual QGraphicsItem* createItemPrimitive( QGraphicsItem *parent ) = 0; |
|
76 |
|
77 virtual void scrollPosChanged( QPointF newPosition ); |
|
78 |
|
79 void moveAllItemsToPool(); |
|
80 |
|
81 void populateAndLayout(); |
|
82 |
|
83 QGraphicsItem* constructItem( int index, bool append ); |
|
84 |
|
85 QGraphicsItem* getFromPool(); |
|
86 |
|
87 void returnToPool( QGraphicsItem* item ); |
|
88 |
|
89 qreal indexToOffset( int index ); |
|
90 |
|
91 int offsetToIndex( qreal offset ); |
|
92 |
|
93 void updateItemWithIndex( int index ); |
|
94 |
|
95 void adjustItems(); |
|
96 |
|
97 protected: // data |
|
98 |
|
99 int mAutoScrollTime; |
|
100 |
|
101 private: //data |
|
102 |
|
103 HbWidget* mStripContainer; |
|
104 |
|
105 QAbstractItemModel* mModel; |
|
106 |
|
107 bool mIsCyclic; |
|
108 bool mAutoCenter; |
|
109 |
|
110 qreal mSpacing; |
|
111 |
|
112 QSizeF mItemSize; |
|
113 |
|
114 QList<QGraphicsItem*> mItemPool; |
|
115 QGraphicsWidget* mItemPoolParent; |
|
116 |
|
117 int mCurrentIndex; |
|
118 int mPressedIndex; |
|
119 |
|
120 qreal mStripLength; |
|
121 qreal mContentsLength; |
|
122 |
|
123 QList<QGraphicsItem*> mItemAtSlot; |
|
124 QList<int> mIndexAtSlot; // Can be bigger than rowcount if cyclic is used |
|
125 |
|
126 HbIcon mBackground; |
|
127 |
|
128 QGraphicsPixmapItem* mBackgroundImage; |
|
129 |
|
130 }; |
|
131 |
|
132 |
|
133 #endif // RADIOSTRIPBASE_H_ |