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