|
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.h> |
|
25 #include <hbeffect.h> |
|
26 |
|
27 // User includes |
|
28 #include "radiostripbase.h" |
|
29 #include "radio_global.h" |
|
30 |
|
31 // Forward declarations |
|
32 class RadioUiEngine; |
|
33 class RadioFrequencyItem; |
|
34 class RadioStation; |
|
35 class HbPushButton; |
|
36 class QTimer; |
|
37 |
|
38 const int KOneHertz = KFrequencyMultiplier; |
|
39 const int KHalfHertz = KOneHertz / 2; |
|
40 const int KOneTabDistance = 15; |
|
41 const uint KOneTabInHz = 0.2 * KOneHertz; |
|
42 const qreal KPixelInHz = KOneTabInHz / KOneTabDistance; |
|
43 //const int KCharWidth = 8; // TODO: Remove hardcoding |
|
44 const int KWidth = KOneTabDistance * 5; |
|
45 const int KHeight = 50; //TODO: Remove hardcoding |
|
46 |
|
47 // Class declaration |
|
48 class RadioFrequencyStrip : public RadioStripBase |
|
49 { |
|
50 Q_OBJECT |
|
51 Q_PROPERTY( HbIcon leftButtonIcon READ leftButtonIcon WRITE setLeftButtonIcon ) |
|
52 Q_PROPERTY( HbIcon rightButtonIcon READ rightButtonIcon WRITE setRightButtonIcon ) |
|
53 |
|
54 friend class RadioFrequencyItem; |
|
55 |
|
56 public: |
|
57 |
|
58 RadioFrequencyStrip( uint minFrequency, |
|
59 uint maxFrequency, |
|
60 uint stepSize, |
|
61 uint currentFrequency, |
|
62 RadioUiEngine* engine = 0 ); |
|
63 |
|
64 void setLeftButtonIcon( const HbIcon& leftButtonIcon ); |
|
65 HbIcon leftButtonIcon() const; |
|
66 |
|
67 void setRightButtonIcon( const HbIcon& rightButtonIcon ); |
|
68 HbIcon rightButtonIcon() const; |
|
69 |
|
70 uint frequency( bool* favorite = 0 ) const; |
|
71 |
|
72 void connectLeftButton( const char* signal, QObject* receiver, const char* slot ); |
|
73 void connectRightButton( const char* signal, QObject* receiver, const char* slot ); |
|
74 |
|
75 |
|
76 |
|
77 public slots: |
|
78 |
|
79 void favoriteChanged( const RadioStation& station ); |
|
80 void setFrequency( const uint frequency, int commandSender = 0 ); |
|
81 |
|
82 signals: |
|
83 |
|
84 void frequencyChanged( uint frequency, int sender ); // sender is always CommandSender::RadioFrequencyStrip |
|
85 void frequencyIsFavorite( bool favorite ); |
|
86 void swipedLeft(); |
|
87 void swipedRight(); |
|
88 |
|
89 private slots: |
|
90 |
|
91 void leftGesture( int speedPixelsPerSecond ); |
|
92 void rightGesture( int speedPixelsPerSecond ); |
|
93 void panGesture( const QPointF& point ); |
|
94 void toggleButtons(); |
|
95 |
|
96 private: |
|
97 |
|
98 // from base class RadioStripBase |
|
99 |
|
100 void updateItemPrimitive( QGraphicsItem* itemToUpdate, int itemIndex ); |
|
101 QGraphicsItem* createItemPrimitive( QGraphicsItem *parent ); |
|
102 void scrollPosChanged( QPointF newPosition ); |
|
103 |
|
104 // from base class QGraphicsWidget |
|
105 |
|
106 void resizeEvent ( QGraphicsSceneResizeEvent* event ); |
|
107 void showEvent( QShowEvent* event ); |
|
108 |
|
109 // from base class HbScrollArea |
|
110 |
|
111 void mousePressEvent( QGraphicsSceneMouseEvent* event ); |
|
112 void mouseReleaseEvent( QGraphicsSceneMouseEvent* event ); |
|
113 |
|
114 // virtual void dragLeaveEvent(QGraphicsSceneDragDropEvent *event); |
|
115 |
|
116 // New functions |
|
117 |
|
118 void initModel(); |
|
119 |
|
120 void initSelector(); |
|
121 |
|
122 void initItems(); |
|
123 |
|
124 void initButtons(); |
|
125 |
|
126 void addFrequencyPos( int pos, uint frequency, RadioFrequencyItem* item ); |
|
127 |
|
128 void updateFavorites( RadioFrequencyItem* item ); |
|
129 |
|
130 QPixmap drawPixmap( uint frequency, QList<RadioStation> stations, RadioFrequencyItem* item ); |
|
131 |
|
132 void emitFrequencyChanged( uint frequency ); |
|
133 |
|
134 void emitFavoriteSelected( bool favoriteSelected ); |
|
135 |
|
136 int selectorPos() const; |
|
137 |
|
138 void scrollToFrequency( uint frequency, int time = 0 ); |
|
139 |
|
140 private: // data |
|
141 |
|
142 class FrequencyPos |
|
143 { |
|
144 public: |
|
145 explicit FrequencyPos( int pos, bool favorite, bool localStation, RadioFrequencyItem* item ) : |
|
146 mPosition( pos ), |
|
147 mFavorite( favorite ), |
|
148 mLocalStation( localStation ), |
|
149 mItem( item ) {} |
|
150 |
|
151 |
|
152 FrequencyPos() : |
|
153 mPosition( 0 ), |
|
154 mFavorite( false ), |
|
155 mLocalStation( false ), |
|
156 mItem( 0 ) {} |
|
157 |
|
158 int mPosition; |
|
159 bool mFavorite; |
|
160 bool mLocalStation; |
|
161 RadioFrequencyItem* mItem; |
|
162 |
|
163 }; |
|
164 |
|
165 uint mMinFrequency; |
|
166 |
|
167 uint mMaxFrequency; |
|
168 |
|
169 uint mFrequencyStepSize; |
|
170 |
|
171 RadioUiEngine* mEngine; |
|
172 |
|
173 QGraphicsPixmapItem* mSelectorImage; |
|
174 |
|
175 qreal mSeparatorPos; |
|
176 |
|
177 short mMaxWidth; |
|
178 |
|
179 qreal mSelectorPos; |
|
180 |
|
181 uint mFrequency; |
|
182 |
|
183 QList<RadioFrequencyItem*> mFrequencyItems; |
|
184 |
|
185 bool mFavoriteSelected; |
|
186 |
|
187 /** |
|
188 * Container to help map a frequency to strip position and additional information about the frequency. |
|
189 * In the default region contains an item for every valid frequency from 87.50 Mhz to 108.00 Mhz with |
|
190 * stepsize 50 Khz which amounts to 410 items. |
|
191 */ |
|
192 QMap<uint,FrequencyPos> mFrequencies; |
|
193 |
|
194 /** |
|
195 * Container to help map strip position to frequency. |
|
196 * It is queried every time the strip moves so the lookup time needs to be fast. QHash is used because |
|
197 * it offers the fastest lookup time of any other QT container. QHash stores the items in arbitrary |
|
198 * order so we must never try to loop through them and assume they are in any particular order. |
|
199 */ |
|
200 QHash<int,uint> mPositions; |
|
201 |
|
202 HbIcon mLeftButtonIcon; |
|
203 |
|
204 HbIcon mRightButtonIcon; |
|
205 |
|
206 HbPushButton* mLeftButton; |
|
207 |
|
208 HbPushButton* mRightButton; |
|
209 |
|
210 QTimer* mButtonTimer; |
|
211 |
|
212 bool mIsPanGesture; |
|
213 |
|
214 }; |
|
215 |
|
216 #endif // FREQUENCYSTRIP_H |