13 * |
13 * |
14 * Description: |
14 * Description: |
15 * |
15 * |
16 */ |
16 */ |
17 |
17 |
18 #ifndef FREQUENCYSTRIP_H |
18 #ifndef RADIOFREQUENCYSTRIP_H |
19 #define FREQUENCYSTRIP_H |
19 #define RADIOFREQUENCYSTRIP_H |
20 |
|
21 // System includes |
|
22 #include <QMap> |
|
23 #include <QHash> |
|
24 #include <HbEffect> |
|
25 #include <QColor> |
|
26 |
20 |
27 // User includes |
21 // User includes |
28 #include "radiostripbase.h" |
22 #include "radiofrequencystripbase.h" |
29 #include "radio_global.h" |
23 #include "radio_global.h" |
30 #include "radiowidgetsexport.h" |
24 #include "radiowidgetsexport.h" |
31 |
25 |
32 // Forward declarations |
26 // Forward declarations |
33 class RadioUiEngine; |
27 class RadioUiEngine; |
34 class RadioFrequencyItem; |
|
35 class RadioStation; |
28 class RadioStation; |
36 class HbPushButton; |
|
37 class QTimer; |
|
38 class QModelIndex; |
|
39 class RadioUiLoader; |
29 class RadioUiLoader; |
40 |
30 |
41 typedef QList<RadioStation> StationList; |
31 typedef QList<RadioStation> StationList; |
42 |
32 |
43 // Class declaration |
33 // Class declaration |
44 class WIDGETS_DLL_EXPORT RadioFrequencyStrip : public RadioStripBase |
34 class WIDGETS_DLL_EXPORT RadioFrequencyStrip : public RadioFrequencyStripBase |
45 { |
35 { |
46 Q_OBJECT |
36 Q_OBJECT |
47 Q_PROPERTY(int itemHeight READ itemHeight WRITE setItemHeight) |
|
48 Q_PROPERTY(uint frequency READ frequency) |
|
49 |
|
50 friend class RadioFrequencyItem; |
|
51 |
37 |
52 public: |
38 public: |
53 |
39 |
54 RadioFrequencyStrip(); |
40 RadioFrequencyStrip(); |
55 |
41 |
56 void setItemHeight( int itemHeight ); |
|
57 int itemHeight() const; |
|
58 |
|
59 void init( RadioUiEngine* engine, RadioUiLoader& uiLoader ); |
42 void init( RadioUiEngine* engine, RadioUiLoader& uiLoader ); |
60 |
43 |
61 void setFrequency( const uint frequency, int reason, Scroll::Direction direction = Scroll::Shortest ); |
44 void setFrequency( const uint newFrequency, int reason, Scroll::Direction direction = Scroll::Shortest ); |
62 uint frequency() const; |
|
63 |
|
64 bool isInManualSeekMode() const; |
|
65 void cancelManualSeek(); |
|
66 |
|
67 void addScannedStation( const RadioStation& station ); |
|
68 |
|
69 void updateFavorite( const RadioStation& station ); |
|
70 |
|
71 public slots: |
|
72 |
|
73 void setScanningMode( bool isScanning ); |
|
74 |
45 |
75 signals: |
46 signals: |
76 |
47 |
77 void frequencyChanged( uint frequency, int reason, int direction ); |
48 void frequencyChanged( uint frequency, int reason, int direction ); |
78 void skipRequested( int skipMode ); |
49 void skipRequested( int skipMode ); |
79 void seekRequested( int seekDirection ); |
50 void seekRequested( int seekDirection ); |
80 void manualSeekChanged( bool manualSeek ); |
|
81 |
|
82 private slots: |
|
83 |
|
84 void removeStation( const QModelIndex& parent, int first, int last ); |
|
85 void updateStation( const QModelIndex& parent, int first, int last ); |
|
86 void initEmptyItems(); |
|
87 void handleLeftButton(); |
|
88 void handleLongLeftButton(); |
|
89 void handleRightButton(); |
|
90 void handleLongRightButton(); |
|
91 void toggleManualSeek(); |
|
92 void handleScrollingEnd(); |
|
93 |
51 |
94 private: |
52 private: |
95 |
53 |
96 // from base class RadioStripBase |
54 // from base class RadioFrequencyStripBase |
97 |
55 |
98 void updateItemPrimitive( QGraphicsItem* itemToUpdate, int itemIndex ); |
56 bool isInitialized() const; |
99 QGraphicsItem* createItemPrimitive( QGraphicsItem *parent ); |
57 QList<FrequencyStrip::StationMarker> stationsInRange( uint minFrequency, uint maxFrequency ) const; |
100 void scrollPosChanged(); |
58 void emitFrequencyChanged( uint frequency, int reason, int direction ); |
101 |
59 void skipToPrevious(); |
102 // from base class QGraphicsWidget |
60 void skipToPreviousFavorite(); |
103 |
61 void skipToNext(); |
104 void resizeEvent ( QGraphicsSceneResizeEvent* event ); |
62 void skipToNextFavorite(); |
105 // void showEvent( QShowEvent* event ); |
63 void seekDown(); |
106 void changeEvent( QEvent* event ); |
64 void seekUp(); |
107 |
65 bool isScanning() const; |
108 // from base class HbScrollArea |
66 uint frequencyAtIndex( int index ) const; |
109 |
|
110 void mousePressEvent( QGraphicsSceneMouseEvent* event ); |
|
111 void mouseReleaseEvent( QGraphicsSceneMouseEvent* event ); |
|
112 void gestureEvent( QGestureEvent* event ); |
|
113 |
|
114 // from base class QObject |
|
115 |
|
116 void timerEvent( QTimerEvent* event ); |
|
117 |
|
118 // New functions |
|
119 |
|
120 void initModel(); |
|
121 |
|
122 void initSelector(); |
|
123 |
|
124 void initPositions(); |
|
125 |
|
126 void initButtons(); |
|
127 |
|
128 void addFrequencyPos( int pos, uint frequency, RadioFrequencyItem* item ); |
|
129 |
|
130 void updateStationsInRange( int first, int last, bool stationRemoved = false ); |
|
131 |
|
132 void updateItem( RadioFrequencyItem* item, uint upperRange = 0, uint ignoredFrequency = 0 ); |
|
133 |
|
134 void updateAllItems(); |
|
135 |
|
136 QPixmap drawPixmap( uint frequency, QList<RadioStation> stations, RadioFrequencyItem* item ); |
|
137 |
|
138 QLineF makeTab( qreal pos, int height ); |
|
139 |
|
140 void emitFrequencyChanged( uint frequency ); |
|
141 |
|
142 int selectorPos() const; |
|
143 |
|
144 void scrollToFrequency( uint frequency, |
|
145 Scroll::Direction direction = Scroll::Shortest, |
|
146 int time = 0, |
|
147 TuneReason::Reason reason = TuneReason::Unspecified ); |
|
148 |
|
149 void hideButtons(); |
|
150 void showButtons(); |
|
151 |
67 |
152 private: // data |
68 private: // data |
153 |
69 |
154 class FrequencyPos |
|
155 { |
|
156 public: |
|
157 explicit FrequencyPos( int pos, RadioFrequencyItem* item ) : |
|
158 mPosition( pos ), |
|
159 mItem( item ) {} |
|
160 |
|
161 FrequencyPos() : |
|
162 mPosition( 0 ), |
|
163 mItem( 0 ) {} |
|
164 |
|
165 int mPosition; |
|
166 RadioFrequencyItem* mItem; |
|
167 |
|
168 }; |
|
169 |
|
170 RadioUiEngine* mUiEngine; |
70 RadioUiEngine* mUiEngine; |
171 |
|
172 int mItemHeight; |
|
173 |
|
174 uint mMinFrequency; |
|
175 |
|
176 uint mMaxFrequency; |
|
177 |
|
178 uint mFrequencyStepSize; |
|
179 |
|
180 uint mFrequency; |
|
181 |
|
182 QGraphicsPixmapItem* mSelectorImage; |
|
183 |
|
184 qreal mSeparatorPos; |
|
185 |
|
186 short mMaxWidth; |
|
187 |
|
188 qreal mSelectorPos; |
|
189 |
|
190 QList<RadioFrequencyItem*> mFrequencyItems; |
|
191 |
|
192 /** |
|
193 * Container to help map a frequency to strip position and additional information about the frequency. |
|
194 * In the default region contains an item for every valid frequency from 87.50 Mhz to 108.00 Mhz with |
|
195 * stepsize 50 Khz which amounts to 410 items. |
|
196 */ |
|
197 QMap<uint,FrequencyPos> mFrequencies; |
|
198 |
|
199 /** |
|
200 * Container to help map strip position to frequency. |
|
201 * It is queried every time the strip moves so the lookup time needs to be fast. QHash is used because |
|
202 * it offers the fastest lookup time of any other QT container. QHash stores the items in arbitrary |
|
203 * order so we must never try to loop through them and assume they are in any particular order. |
|
204 */ |
|
205 QHash<int,uint> mPositions; |
|
206 |
|
207 HbPushButton* mLeftButton; |
|
208 |
|
209 HbPushButton* mRightButton; |
|
210 |
|
211 QTimer* mManualSeekTimer; |
|
212 |
|
213 bool mManualSeekMode; |
|
214 |
|
215 uint mLastReportedFrequency; |
|
216 |
|
217 int mManualSeekTimerId; |
|
218 |
|
219 QColor mForegroundColor; |
|
220 |
71 |
221 }; |
72 }; |
222 |
73 |
223 #endif // FREQUENCYSTRIP_H |
74 #endif // RADIOFREQUENCYSTRIP_H |