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 FREQUENCYSTRIP_H |
|
19 #define FREQUENCYSTRIP_H |
|
20 |
|
21 // System includes |
|
22 #include <QMap> |
|
23 #include <QHash> |
|
24 #include <HbIcon> |
|
25 #include <HbEffect> |
|
26 #include <QColor> |
|
27 |
|
28 // User includes |
|
29 #include "radiostripbase.h" |
|
30 #include "radio_global.h" |
|
31 #include "radiowidgetsexport.h" |
|
32 |
|
33 // Forward declarations |
|
34 class RadioUiEngine; |
|
35 class RadioFrequencyItem; |
|
36 class RadioStation; |
|
37 class HbPushButton; |
|
38 class QTimer; |
|
39 class QModelIndex; |
|
40 |
|
41 // Class declaration |
|
42 class WIDGETS_DLL_EXPORT RadioFrequencyStrip : public RadioStripBase |
|
43 { |
|
44 Q_OBJECT |
|
45 Q_PROPERTY( HbIcon leftButtonIcon READ leftButtonIcon WRITE setLeftButtonIcon ) |
|
46 Q_PROPERTY( HbIcon rightButtonIcon READ rightButtonIcon WRITE setRightButtonIcon ) |
|
47 |
|
48 friend class RadioFrequencyItem; |
|
49 |
|
50 public: |
|
51 |
|
52 RadioFrequencyStrip(); |
|
53 |
|
54 void setLeftButtonIcon( const HbIcon& leftButtonIcon ); |
|
55 HbIcon leftButtonIcon() const; |
|
56 |
|
57 void setRightButtonIcon( const HbIcon& rightButtonIcon ); |
|
58 HbIcon rightButtonIcon() const; |
|
59 |
|
60 void init( RadioUiEngine* engine ); |
|
61 |
|
62 void setFrequency( const uint frequency, int reason = 0 ); |
|
63 uint frequency() const; |
|
64 |
|
65 public slots: |
|
66 |
|
67 void updateFavorite( const RadioStation& station ); |
|
68 void setScanningMode( bool isScanning ); |
|
69 |
|
70 signals: |
|
71 |
|
72 void frequencyChanged( uint frequency, int reason ); // reason is always CommandSender::RadioFrequencyStrip |
|
73 void skipRequested( int skipMode ); |
|
74 void seekRequested( int seekDirection ); |
|
75 |
|
76 private slots: |
|
77 |
|
78 void updateStation( const QModelIndex& parent, int first, int last ); |
|
79 void initEmptyItems(); |
|
80 void handleLeftButton(); |
|
81 void handleLongLeftButton(); |
|
82 void handleRightButton(); |
|
83 void handleLongRightButton(); |
|
84 void toggleButtons(); |
|
85 void checkIllegalPos(); |
|
86 |
|
87 private: |
|
88 |
|
89 // from base class RadioStripBase |
|
90 |
|
91 void updateItemPrimitive( QGraphicsItem* itemToUpdate, int itemIndex ); |
|
92 QGraphicsItem* createItemPrimitive( QGraphicsItem *parent ); |
|
93 void scrollPosChanged( QPointF newPosition ); |
|
94 |
|
95 // from base class QGraphicsWidget |
|
96 |
|
97 void resizeEvent ( QGraphicsSceneResizeEvent* event ); |
|
98 void showEvent( QShowEvent* event ); |
|
99 void changeEvent( QEvent* event ); |
|
100 |
|
101 // from base class HbScrollArea |
|
102 |
|
103 void mousePressEvent( QGraphicsSceneMouseEvent* event ); |
|
104 void mouseReleaseEvent( QGraphicsSceneMouseEvent* event ); |
|
105 void gestureEvent( QGestureEvent* event ); |
|
106 |
|
107 // New functions |
|
108 |
|
109 void initModel(); |
|
110 |
|
111 void initSelector(); |
|
112 |
|
113 void initPositions(); |
|
114 |
|
115 void initButtons(); |
|
116 |
|
117 void addFrequencyPos( int pos, uint frequency, RadioFrequencyItem* item ); |
|
118 |
|
119 void updateFavorites( RadioFrequencyItem* item ); |
|
120 |
|
121 void updateItems(); |
|
122 |
|
123 QPixmap drawPixmap( uint frequency, QList<RadioStation> stations, RadioFrequencyItem* item ); |
|
124 |
|
125 void emitFrequencyChanged( uint frequency ); |
|
126 |
|
127 int selectorPos() const; |
|
128 |
|
129 void scrollToFrequency( uint frequency, int time = 0 ); |
|
130 |
|
131 void hideButtons(); |
|
132 void showButtons(); |
|
133 |
|
134 private: // data |
|
135 |
|
136 class FrequencyPos |
|
137 { |
|
138 public: |
|
139 explicit FrequencyPos( int pos, RadioFrequencyItem* item ) : |
|
140 mPosition( pos ), |
|
141 mItem( item ) {} |
|
142 |
|
143 FrequencyPos() : |
|
144 mPosition( 0 ), |
|
145 mItem( 0 ) {} |
|
146 |
|
147 int mPosition; |
|
148 RadioFrequencyItem* mItem; |
|
149 |
|
150 }; |
|
151 |
|
152 RadioUiEngine* mUiEngine; |
|
153 |
|
154 uint mMinFrequency; |
|
155 |
|
156 uint mMaxFrequency; |
|
157 |
|
158 uint mFrequencyStepSize; |
|
159 |
|
160 uint mFrequency; |
|
161 |
|
162 QGraphicsPixmapItem* mSelectorImage; |
|
163 |
|
164 qreal mSeparatorPos; |
|
165 |
|
166 short mMaxWidth; |
|
167 |
|
168 qreal mSelectorPos; |
|
169 |
|
170 QList<RadioFrequencyItem*> mFrequencyItems; |
|
171 |
|
172 /** |
|
173 * Container to help map a frequency to strip position and additional information about the frequency. |
|
174 * In the default region contains an item for every valid frequency from 87.50 Mhz to 108.00 Mhz with |
|
175 * stepsize 50 Khz which amounts to 410 items. |
|
176 */ |
|
177 QMap<uint,FrequencyPos> mFrequencies; |
|
178 |
|
179 /** |
|
180 * Container to help map strip position to frequency. |
|
181 * It is queried every time the strip moves so the lookup time needs to be fast. QHash is used because |
|
182 * it offers the fastest lookup time of any other QT container. QHash stores the items in arbitrary |
|
183 * order so we must never try to loop through them and assume they are in any particular order. |
|
184 */ |
|
185 QHash<int,uint> mPositions; |
|
186 |
|
187 HbIcon mLeftButtonIcon; |
|
188 |
|
189 HbIcon mRightButtonIcon; |
|
190 |
|
191 HbPushButton* mLeftButton; |
|
192 |
|
193 HbPushButton* mRightButton; |
|
194 |
|
195 QTimer* mButtonTimer; |
|
196 bool mButtonsVisible; |
|
197 |
|
198 bool mUserIsScrolling; |
|
199 |
|
200 QColor mForegroundColor; |
|
201 |
|
202 }; |
|
203 |
|
204 #endif // FREQUENCYSTRIP_H |
|