20 #include <HbAnchorLayout> |
20 #include <HbAnchorLayout> |
21 #include <QPixmap> |
21 #include <QPixmap> |
22 #include <QGraphicsSceneMouseEvent> |
22 #include <QGraphicsSceneMouseEvent> |
23 #include <HbEffect> |
23 #include <HbEffect> |
24 #include <QTimer> |
24 #include <QTimer> |
|
25 #include <QTimeLine> |
25 |
26 |
26 // User includes |
27 // User includes |
27 #include "radiostationcarousel.h" |
28 #include "radiostationcarousel.h" |
28 #include "radiostationitem.h" |
29 #include "radiostationitem.h" |
29 #include "radiouiengine.h" |
30 #include "radiouiengine.h" |
30 #include "radiostationmodel.h" |
31 #include "radiostationmodel.h" |
31 #include "radiofadinglabel.h" |
32 #include "radiofadinglabel.h" |
32 #include "radiologger.h" |
33 #include "radiologger.h" |
33 #include "radiolocalization.h" |
34 #include "radiostationmodel.h" |
34 #include "radiostationfiltermodel.h" |
35 #include "radiouiutilities.h" |
35 #include "radio_global.h" |
36 #include "radio_global.h" |
36 |
37 |
37 #ifdef USE_LAYOUT_FROM_E_DRIVE |
38 #ifdef USE_LAYOUT_FROM_E_DRIVE |
38 const QString KFavoriteIconPath = "e:/radiotest/images/favoriteiconactive.png"; |
39 const QString KFavoriteIconPath = "e:/radiotest/images/favoriteiconactive.png"; |
39 const QString KNonFavoriteIconPath = "e:/radiotest/images/favoriteiconinactive.png"; |
40 const QString KNonFavoriteIconPath = "e:/radiotest/images/favoriteiconinactive.png"; |
41 const QString KFavoriteIconPath = ":/images/favoriteiconactive.png"; |
42 const QString KFavoriteIconPath = ":/images/favoriteiconactive.png"; |
42 const QString KNonFavoriteIconPath = ":/images/favoriteiconinactive.png"; |
43 const QString KNonFavoriteIconPath = ":/images/favoriteiconinactive.png"; |
43 #endif |
44 #endif |
44 |
45 |
45 const int KRadioTextPlusCheckTimeout = 700; // 700 ms |
46 const int KRadioTextPlusCheckTimeout = 700; // 700 ms |
46 |
47 const int KFreqScrollDivider = 100000; |
47 /*! |
48 |
48 * |
49 // =============================================================== |
49 */ |
50 // Scanning helper |
50 RadioStationCarousel::RadioStationCarousel( RadioUiEngine& uiEngine, QGraphicsItem* parent ) : |
51 // =============================================================== |
51 HbGridView( parent ), |
52 |
|
53 /*! |
|
54 * |
|
55 */ |
|
56 ScanningHelper::ScanningHelper( RadioStationCarousel& carousel ) : |
|
57 mCarousel( carousel ), |
|
58 mCurrentFrequency( 0 ), |
|
59 mPreviousFrequency( 0 ), |
|
60 mStationItem( 0 ), |
|
61 mNumberScrollingTimeLine( new QTimeLine( 1000, this ) ) |
|
62 { |
|
63 mNumberScrollingTimeLine->setCurveShape( QTimeLine::EaseInCurve ); |
|
64 connectAndTest( mNumberScrollingTimeLine, SIGNAL(finished()), |
|
65 &mCarousel, SIGNAL(scanAnimationFinished()) ); |
|
66 connectAndTest( mNumberScrollingTimeLine, SIGNAL(frameChanged(int)), |
|
67 this, SLOT(numberScrollUpdate(int)) ); |
|
68 } |
|
69 |
|
70 /*! |
|
71 * |
|
72 */ |
|
73 void ScanningHelper::start() |
|
74 { |
|
75 QTimer::singleShot( 0, this, SLOT(startSlide()) ); |
|
76 } |
|
77 |
|
78 /*! |
|
79 * Private slot |
|
80 */ |
|
81 void ScanningHelper::startSlide() |
|
82 { |
|
83 mCarousel.scrollToIndex( mModelIndex, 1000 ); |
|
84 startNumberScroll(); |
|
85 } |
|
86 |
|
87 /*! |
|
88 * Private slot |
|
89 */ |
|
90 void ScanningHelper::startNumberScroll() |
|
91 { |
|
92 //TODO: Take italy case into account |
|
93 if ( mPreviousFrequency ) { |
|
94 mNumberScrollingTimeLine->setFrameRange( mPreviousFrequency / KFreqScrollDivider, mCurrentFrequency / KFreqScrollDivider ); |
|
95 mNumberScrollingTimeLine->start(); |
|
96 } else { |
|
97 emit mCarousel.scanAnimationFinished(); |
|
98 } |
|
99 } |
|
100 |
|
101 /*! |
|
102 * Private slot |
|
103 */ |
|
104 void ScanningHelper::numberScrollUpdate( int value ) |
|
105 { |
|
106 if ( mStationItem ) { |
|
107 mStationItem->setFrequency( value * KFreqScrollDivider ); |
|
108 } |
|
109 } |
|
110 |
|
111 // =============================================================== |
|
112 // Carousel |
|
113 // =============================================================== |
|
114 |
|
115 /*! |
|
116 * |
|
117 */ |
|
118 RadioStationCarousel::RadioStationCarousel( RadioUiEngine* uiEngine ) : |
|
119 HbGridView( 0 ), |
52 mUiEngine( uiEngine ), |
120 mUiEngine( uiEngine ), |
53 mAntennaAttached( false ), |
121 mAntennaAttached( false ), |
54 mAutoScrollTime( 1000 ), |
122 mAutoScrollTime( 300 ), |
55 mPreviousButtonPos( 0.0 ), |
123 mPreviousButtonPos( 0.0 ), |
56 mMovingLeft( false ), |
124 mMovingLeft( false ), |
57 mCurrentItem( 0 ), |
125 mCurrentItem( 0 ), |
58 mRadioTextTimer( new QTimer( this ) ) |
126 mRadioTextTimer( new QTimer( this ) ), |
|
127 mScrollPos( 0 ), |
|
128 mScanningHelper( 0 ) |
59 #ifdef USE_DEBUGGING_CONTROLS |
129 #ifdef USE_DEBUGGING_CONTROLS |
60 ,mRdsLabel( new RadioFadingLabel( this ) ) |
130 ,mRdsLabel( new RadioFadingLabel( this ) ) |
61 #endif // USE_DEBUGGING_CONTROLS |
131 #endif // USE_DEBUGGING_CONTROLS |
62 { |
132 { |
63 mAntennaAttached = mUiEngine.isAntennaAttached(); |
133 RadioUiUtilities::setCarousel( this ); |
64 |
134 |
65 setScrollDirections( Qt::Horizontal ); |
135 setScrollDirections( Qt::Horizontal ); |
66 setFrictionEnabled( true ); |
136 setFrictionEnabled( true ); |
67 setRowCount( 1 ); |
137 setRowCount( 1 ); |
68 setColumnCount( 1 ); |
138 setColumnCount( 1 ); |
72 setItemRecycling( false ); // TODO: Enable recycling |
142 setItemRecycling( false ); // TODO: Enable recycling |
73 setUniformItemSizes( true ); |
143 setUniformItemSizes( true ); |
74 setItemPrototype( new RadioStationItem( *this ) ); |
144 setItemPrototype( new RadioStationItem( *this ) ); |
75 setSelectionMode( SingleSelection ); |
145 setSelectionMode( SingleSelection ); |
76 |
146 |
77 RadioStationFilterModel* filterModel = mUiEngine.createNewFilterModel( this ); |
|
78 filterModel->setCyclic( false ); |
|
79 |
|
80 setModel( filterModel ); |
|
81 mCurrentItem = static_cast<RadioStationItem*>( itemByIndex( model()->index( 0, 0 ) ) ); |
|
82 |
|
83 updateFrequencies(); |
|
84 |
|
85 connectAndTest( model(), SIGNAL(rowsInserted(QModelIndex,int,int)), |
|
86 this, SLOT(insertFrequency(QModelIndex,int,int)) ); |
|
87 connectAndTest( model(), SIGNAL(rowsAboutToBeRemoved(QModelIndex,int,int)), |
|
88 this, SLOT(removeFrequency(QModelIndex,int,int)) ); |
|
89 // connectAndTest( model(), SIGNAL(layoutChanged()), |
|
90 // this, SLOT(updateFrequencies()) ); |
|
91 connectAndTest( this, SIGNAL(scrollingEnded()), |
|
92 this, SLOT(updateLoopedPos()) ); |
|
93 |
|
94 RadioStationModel* stationModel = &mUiEngine.model(); |
|
95 connectAndTest( stationModel, SIGNAL(favoriteChanged(RadioStation)), |
|
96 this, SLOT(update(RadioStation)) ); |
|
97 connectAndTest( stationModel, SIGNAL(stationDataChanged(RadioStation)), |
|
98 this, SLOT(update(RadioStation))); |
|
99 connectAndTest( stationModel, SIGNAL(radioTextReceived(RadioStation)), |
|
100 this, SLOT(updateRadioText(RadioStation))); |
|
101 connectAndTest( stationModel, SIGNAL(dynamicPsChanged(RadioStation)), |
|
102 this, SLOT(update(RadioStation))); |
|
103 |
|
104 mRadioTextTimer->setSingleShot( true ); |
147 mRadioTextTimer->setSingleShot( true ); |
105 mRadioTextTimer->setInterval( KRadioTextPlusCheckTimeout ); |
148 mRadioTextTimer->setInterval( KRadioTextPlusCheckTimeout ); |
106 connectAndTest( mRadioTextTimer, SIGNAL(timeout()), |
149 connectAndTest( mRadioTextTimer, SIGNAL(timeout()), |
107 this, SLOT(radioTextPlusCheckEnded())); |
150 this, SLOT(radioTextPlusCheckEnded())); |
108 |
151 |
113 HbFontSpec spec = mRdsLabel->fontSpec(); |
156 HbFontSpec spec = mRdsLabel->fontSpec(); |
114 spec.setTextPaneHeight( 10 ); |
157 spec.setTextPaneHeight( 10 ); |
115 spec.setRole( HbFontSpec::Secondary ); |
158 spec.setRole( HbFontSpec::Secondary ); |
116 mRdsLabel->setFontSpec( spec ); |
159 mRdsLabel->setFontSpec( spec ); |
117 mRdsLabel->setTextColor( Qt::gray ); |
160 mRdsLabel->setTextColor( Qt::gray ); |
118 connectAndTest( &mUiEngine, SIGNAL(rdsAvailabilityChanged(bool)), |
161 if ( mUiEngine ) { |
119 this, SLOT(setRdsAvailable(bool)) ); |
162 connectAndTest( mUiEngine, SIGNAL(rdsAvailabilityChanged(bool)), |
|
163 this, SLOT(setRdsAvailable(bool)) ); |
|
164 } |
120 #endif // USE_DEBUGGING_CONTROLS |
165 #endif // USE_DEBUGGING_CONTROLS |
121 } |
166 } |
122 |
167 |
123 /*! |
168 /*! |
124 * Property |
169 * Property |
125 * |
170 * |
126 */ |
171 */ |
127 void RadioStationCarousel::setBackground( const HbIcon& background ) |
172 void RadioStationCarousel::setFavoriteIcon( const HbIcon& favoriteIcon ) |
128 { |
173 { |
129 mBackground = background; |
174 mFavoriteIcon = favoriteIcon; |
130 } |
175 } |
131 |
176 |
132 /*! |
177 /*! |
133 * Property |
178 * Property |
134 * |
179 * |
135 */ |
180 */ |
136 HbIcon RadioStationCarousel::background() const |
181 HbIcon RadioStationCarousel::favoriteIcon() const |
137 { |
182 { |
138 return mBackground; |
183 return mFavoriteIcon; |
139 } |
184 } |
140 |
185 |
141 /*! |
186 /*! |
142 * Property |
187 * Property |
143 * |
188 * |
144 */ |
189 */ |
145 void RadioStationCarousel::setFavoriteIcon( const HbIcon& favoriteIcon ) |
190 void RadioStationCarousel::setNonFavoriteIcon( const HbIcon& nonFavoriteIcon ) |
146 { |
191 { |
147 mFavoriteIcon = favoriteIcon; |
192 mNonFavoriteIcon = nonFavoriteIcon; |
148 } |
193 } |
149 |
194 |
150 /*! |
195 /*! |
151 * Property |
196 * Property |
152 * |
197 * |
153 */ |
198 */ |
154 HbIcon RadioStationCarousel::favoriteIcon() const |
|
155 { |
|
156 return mFavoriteIcon; |
|
157 } |
|
158 |
|
159 /*! |
|
160 * Property |
|
161 * |
|
162 */ |
|
163 void RadioStationCarousel::setNonFavoriteIcon( const HbIcon& nonFavoriteIcon ) |
|
164 { |
|
165 mNonFavoriteIcon = nonFavoriteIcon; |
|
166 } |
|
167 |
|
168 /*! |
|
169 * Property |
|
170 * |
|
171 */ |
|
172 HbIcon RadioStationCarousel::nonFavoriteIcon() const |
199 HbIcon RadioStationCarousel::nonFavoriteIcon() const |
173 { |
200 { |
174 return mNonFavoriteIcon; |
201 return mNonFavoriteIcon; |
175 } |
202 } |
176 |
203 |
177 /*! |
204 /*! |
178 * |
205 * |
179 */ |
206 */ |
180 RadioUiEngine& RadioStationCarousel::uiEngine() |
207 void RadioStationCarousel::setAutoScrollTime( const int time ) |
|
208 { |
|
209 mAutoScrollTime = time; |
|
210 } |
|
211 |
|
212 /*! |
|
213 * |
|
214 */ |
|
215 int RadioStationCarousel::autoScrollTime() const |
|
216 { |
|
217 return mAutoScrollTime; |
|
218 } |
|
219 |
|
220 /*! |
|
221 * |
|
222 */ |
|
223 void RadioStationCarousel::init( RadioUiEngine* uiEngine ) |
|
224 { |
|
225 mUiEngine = uiEngine; |
|
226 mAntennaAttached = mUiEngine->isAntennaAttached(); |
|
227 |
|
228 setStationModel( &mUiEngine->model() ); |
|
229 |
|
230 mCurrentItem = static_cast<RadioStationItem*>( itemByIndex( model()->index( 0, 0 ) ) ); |
|
231 } |
|
232 |
|
233 /*! |
|
234 * |
|
235 */ |
|
236 void RadioStationCarousel::setStationModel( RadioStationModel* stationModel ) |
|
237 { |
|
238 if ( stationModel ) { |
|
239 connectAndTest( stationModel, SIGNAL(rowsInserted(QModelIndex,int,int)), |
|
240 this, SLOT(insertFrequency(QModelIndex,int,int)) ); |
|
241 connectAndTest( stationModel, SIGNAL(rowsAboutToBeRemoved(QModelIndex,int,int)), |
|
242 this, SLOT(removeFrequency(QModelIndex,int,int)) ); |
|
243 connectAndTest( stationModel, SIGNAL(favoriteChanged(RadioStation)), |
|
244 this, SLOT(update(RadioStation)) ); |
|
245 connectAndTest( stationModel, SIGNAL(stationDataChanged(RadioStation)), |
|
246 this, SLOT(update(RadioStation))); |
|
247 connectAndTest( stationModel, SIGNAL(radioTextReceived(RadioStation)), |
|
248 this, SLOT(updateRadioText(RadioStation))); |
|
249 connectAndTest( stationModel, SIGNAL(dynamicPsChanged(RadioStation)), |
|
250 this, SLOT(update(RadioStation))); |
|
251 } else { |
|
252 QAbstractItemModel* currentModel = model(); |
|
253 // disconnect( currentModel, SIGNAL(rowsInserted(QModelIndex,int,int)), |
|
254 // this, SLOT(insertFrequency(QModelIndex,int,int)) ); |
|
255 // disconnect( currentModel, SIGNAL(rowsAboutToBeRemoved(QModelIndex,int,int)), |
|
256 // this, SLOT(removeFrequency(QModelIndex,int,int)) ); |
|
257 disconnect( currentModel, SIGNAL(favoriteChanged(RadioStation)), |
|
258 this, SLOT(update(RadioStation)) ); |
|
259 disconnect( currentModel, SIGNAL(stationDataChanged(RadioStation)), |
|
260 this, SLOT(update(RadioStation))); |
|
261 disconnect( currentModel, SIGNAL(radioTextReceived(RadioStation)), |
|
262 this, SLOT(updateRadioText(RadioStation))); |
|
263 disconnect( currentModel, SIGNAL(dynamicPsChanged(RadioStation)), |
|
264 this, SLOT(update(RadioStation))); |
|
265 } |
|
266 setModel( stationModel ); |
|
267 updateFrequencies(); |
|
268 } |
|
269 |
|
270 /*! |
|
271 * |
|
272 */ |
|
273 RadioUiEngine* RadioStationCarousel::uiEngine() |
181 { |
274 { |
182 return mUiEngine; |
275 return mUiEngine; |
183 } |
276 } |
184 |
277 |
185 /*! |
278 /*! |
189 { |
282 { |
190 return mAntennaAttached; |
283 return mAntennaAttached; |
191 } |
284 } |
192 |
285 |
193 /*! |
286 /*! |
|
287 * |
|
288 */ |
|
289 void RadioStationCarousel::setScanningMode( bool scanning ) |
|
290 { |
|
291 RadioStationItem* item = currentStationItem(); |
|
292 |
|
293 if ( scanning ) { |
|
294 cleanRdsData(); |
|
295 if ( !mScanningHelper ) { |
|
296 mScanningHelper = new ScanningHelper( *this ); |
|
297 } |
|
298 } else { |
|
299 delete mScanningHelper; |
|
300 mScanningHelper = 0; |
|
301 if ( item ) { |
|
302 item->update(); |
|
303 } |
|
304 } |
|
305 setEnabled( !scanning ); |
|
306 } |
|
307 |
|
308 /*! |
|
309 * |
|
310 */ |
|
311 bool RadioStationCarousel::isInScanningMode() const |
|
312 { |
|
313 return mScanningHelper != 0; |
|
314 } |
|
315 |
|
316 /*! |
|
317 * |
|
318 */ |
|
319 void RadioStationCarousel::cleanRdsData() |
|
320 { |
|
321 RadioStationItem* item = currentStationItem(); |
|
322 if ( item ) { |
|
323 item->cleanRdsData(); |
|
324 } |
|
325 } |
|
326 |
|
327 /*! |
|
328 * |
|
329 */ |
|
330 void RadioStationCarousel::animateNewStation( const RadioStation& station ) |
|
331 { |
|
332 if ( mScanningHelper ) { |
|
333 RadioStationModel* model = stationModel(); |
|
334 const QModelIndex index = model->modelIndexFromFrequency( station.frequency() ); |
|
335 mScanningHelper->mModelIndex = index; |
|
336 mScanningHelper->mCurrentFrequency = station.frequency(); |
|
337 mScanningHelper->mStationItem = static_cast<RadioStationItem*>( itemByIndex( index ) ); |
|
338 |
|
339 uint prevFrequency = 0; |
|
340 if ( model->rowCount() > 1 ) { |
|
341 QModelIndex prevIndex = model->index( index.row() - 1, 0 ); |
|
342 RadioStation prevStation = model->data( prevIndex, RadioStationModel::RadioStationRole ).value<RadioStation>(); |
|
343 prevFrequency = prevStation.frequency(); |
|
344 } else if ( mUiEngine ) { |
|
345 prevFrequency = mUiEngine->minFrequency(); |
|
346 } |
|
347 mScanningHelper->mPreviousFrequency = prevFrequency; |
|
348 mScanningHelper->mStationItem->setFrequency( prevFrequency ); |
|
349 mScanningHelper->mStationItem->cleanRdsData(); |
|
350 |
|
351 mScanningHelper->start(); |
|
352 } |
|
353 } |
|
354 |
|
355 /*! |
|
356 * |
|
357 */ |
|
358 void RadioStationCarousel::setItemVisibility( bool visible ) |
|
359 { |
|
360 RadioStationItem* item = currentStationItem(); |
|
361 if ( item ) { |
|
362 item->setVisible( visible ); |
|
363 } |
|
364 } |
|
365 |
|
366 /*! |
194 * Private slot |
367 * Private slot |
195 */ |
368 */ |
196 void RadioStationCarousel::update( const RadioStation& station ) |
369 void RadioStationCarousel::update( const RadioStation& station ) |
197 { |
370 { |
198 RadioStationItem* item = currentStationItem(); |
371 RadioStationItem* item = currentStationItem(); |
199 if ( item && item->frequency() == station.frequency() ) { |
372 if ( item && item->frequency() == station.frequency() && !isInScanningMode() ) { |
200 item->update( &station ); |
373 item->update( &station ); |
201 } |
374 } |
202 } |
375 } |
203 |
376 |
204 /*! |
377 /*! |
205 * Private slot |
378 * Private slot |
206 */ |
379 */ |
207 void RadioStationCarousel::updateRadioText( const RadioStation& station ) |
380 void RadioStationCarousel::updateRadioText( const RadioStation& station ) |
208 { |
381 { |
209 if ( isAntennaAttached() ) { |
382 if ( isAntennaAttached() && !isInScanningMode() ) { |
210 if ( station.radioText().isEmpty() ) { |
383 if ( station.radioText().isEmpty() ) { |
211 RadioStationItem* item = currentStationItem(); |
384 RadioStationItem* item = currentStationItem(); |
212 if ( item ) { |
385 if ( item ) { |
213 item->mRadiotextLabel->setText( "" ); |
386 item->mRadiotextLabel->setText( "" ); |
214 } |
387 } |
226 void RadioStationCarousel::leftGesture( int speedPixelsPerSecond ) |
399 void RadioStationCarousel::leftGesture( int speedPixelsPerSecond ) |
227 { |
400 { |
228 Q_UNUSED( speedPixelsPerSecond ); |
401 Q_UNUSED( speedPixelsPerSecond ); |
229 QModelIndex index = currentIndex(); |
402 QModelIndex index = currentIndex(); |
230 |
403 |
231 if ( index == model()->index( model()->rowCount() - 1, 0 ) ) { |
404 // if ( index == model()->index( model()->rowCount() - 1, 0 ) ) { |
232 index = model()->index( 0, 0 ); |
405 // index = model()->index( 0, 0 ); |
233 } else { |
406 // } else { |
234 index = nextIndex( index ); |
407 // index = nextIndex( index ); |
235 } |
408 // } |
236 |
409 |
237 scrollToIndex( index, mAutoScrollTime ); |
410 index = nextIndex( index ); |
|
411 if ( index.isValid() ) { |
|
412 scrollToIndex( index, mAutoScrollTime ); |
|
413 } |
238 } |
414 } |
239 |
415 |
240 /*! |
416 /*! |
241 * Private slot |
417 * Private slot |
242 */ |
418 */ |
243 void RadioStationCarousel::rightGesture( int speedPixelsPerSecond ) |
419 void RadioStationCarousel::rightGesture( int speedPixelsPerSecond ) |
244 { |
420 { |
245 Q_UNUSED( speedPixelsPerSecond ); |
421 Q_UNUSED( speedPixelsPerSecond ); |
246 QModelIndex index = currentIndex(); |
422 QModelIndex index = currentIndex(); |
247 |
423 |
248 if ( index == model()->index( 0, 0 ) ) { |
424 // if ( index == model()->index( 0, 0 ) ) { |
249 index = model()->index( model()->rowCount() - 1, 0 ); |
425 // index = model()->index( model()->rowCount() - 1, 0 ); |
250 } else { |
426 // } else { |
251 index = previousIndex( index ); |
427 // index = previousIndex( index ); |
252 } |
428 // } |
253 |
429 |
254 scrollToIndex( index, mAutoScrollTime ); |
430 index = previousIndex( index ); |
|
431 if ( index.isValid() ) { |
|
432 scrollToIndex( index, mAutoScrollTime ); |
|
433 } |
255 } |
434 } |
256 |
435 |
257 /*! |
436 /*! |
258 * Private slot |
437 * Private slot |
259 */ |
438 */ |
260 void RadioStationCarousel::insertFrequency( const QModelIndex& parent, int first, int last ) |
439 void RadioStationCarousel::insertFrequency( const QModelIndex& parent, int first, int last ) |
261 { |
440 { |
262 Q_UNUSED( parent ); |
441 Q_UNUSED( parent ); |
263 QAbstractItemModel* freqModel = model(); |
442 QAbstractItemModel* freqModel = model(); |
264 for ( int i = first; i <= last; ++i ) { |
443 |
|
444 for ( int i = first; freqModel && i <= last; ++i ) { |
265 QModelIndex index = freqModel->index( i, 0 ); |
445 QModelIndex index = freqModel->index( i, 0 ); |
266 RadioStation station = freqModel->data( index, RadioStationModel::RadioStationRole ).value<RadioStation>(); |
446 RadioStation station = freqModel->data( index, RadioStationModel::RadioStationRole ).value<RadioStation>(); |
267 mModelIndexes.insert( station.frequency(), index ); |
447 mModelIndexes.insert( station.frequency(), index ); |
268 LOG_FORMAT( "Added frequency %u", station.frequency() ); |
448 LOG_FORMAT( "Added frequency %u", station.frequency() ); |
269 scrollToIndex( index, 0 ); |
449 if ( !isInScanningMode() ) { |
|
450 scrollToIndex( index, mAutoScrollTime ); |
|
451 } |
270 } |
452 } |
271 } |
453 } |
272 |
454 |
273 /*! |
455 /*! |
274 * Private slot |
456 * Private slot |
275 */ |
457 */ |
276 void RadioStationCarousel::removeFrequency( const QModelIndex& parent, int first, int last ) |
458 void RadioStationCarousel::removeFrequency( const QModelIndex& parent, int first, int last ) |
277 { |
459 { |
278 Q_UNUSED( parent ); |
460 Q_UNUSED( parent ); |
279 QAbstractItemModel* freqModel = model(); |
461 QAbstractItemModel* freqModel = model(); |
280 for ( int i = first; i <= last; ++i ) { |
462 for ( int i = first; freqModel && i <= last; ++i ) { |
281 QModelIndex index = freqModel->index( i, 0 ); |
463 QModelIndex index = freqModel->index( i, 0 ); |
282 RadioStation station = freqModel->data( index, RadioStationModel::RadioStationRole ).value<RadioStation>(); |
464 RadioStation station = freqModel->data( index, RadioStationModel::RadioStationRole ).value<RadioStation>(); |
283 mModelIndexes.remove( station.frequency() ); |
465 mModelIndexes.remove( station.frequency() ); |
284 } |
466 } |
285 } |
467 } |
289 */ |
471 */ |
290 void RadioStationCarousel::updateFrequencies() |
472 void RadioStationCarousel::updateFrequencies() |
291 { |
473 { |
292 mModelIndexes.clear(); |
474 mModelIndexes.clear(); |
293 QAbstractItemModel* itemModel = model(); |
475 QAbstractItemModel* itemModel = model(); |
294 const int count = itemModel->rowCount(); |
476 if ( itemModel ) { |
295 for ( int i = 0; i < count; ++i ) { |
477 const int count = itemModel->rowCount(); |
296 QModelIndex index = itemModel->index( i, 0 ); |
478 for ( int i = 0; i < count; ++i ) { |
297 uint frequency = itemModel->data( index, RadioStationModel::RadioStationRole ).value<RadioStation>().frequency(); |
479 QModelIndex index = itemModel->index( i, 0 ); |
298 mModelIndexes.insert( frequency, index ); |
480 uint frequency = itemModel->data( index, RadioStationModel::RadioStationRole ).value<RadioStation>().frequency(); |
|
481 mModelIndexes.insert( frequency, index ); |
|
482 } |
299 } |
483 } |
300 } |
484 } |
301 |
485 |
302 /*! |
486 /*! |
303 * Private slot |
487 * Private slot |
304 */ |
488 */ |
305 void RadioStationCarousel::updateLoopedPos() |
489 void RadioStationCarousel::updateLoopedPos() |
306 { |
490 { |
307 const int row = currentIndex().row(); |
491 // const int row = currentIndex().row(); |
308 if ( filterModel()->hasLooped( currentIndex() ) ) { |
492 // if ( filterModel()->hasLooped( currentIndex() ) ) { |
309 QModelIndex realIndex = filterModel()->realIndex( currentIndex() ); |
493 // QModelIndex realIndex = filterModel()->realIndex( currentIndex() ); |
310 scrollTo( realIndex ); |
494 // scrollTo( realIndex ); |
311 setCurrentIndex( realIndex, QItemSelectionModel::SelectCurrent ); |
495 // setCurrentIndex( realIndex, QItemSelectionModel::SelectCurrent ); |
312 // scrollToIndex( realIndex , 0 ); |
496 //// scrollToIndex( realIndex , 0 ); |
313 LOG_FORMAT( "Index %d has looped. real index is %d", row, realIndex.row() ); |
497 // LOG_FORMAT( "Index %d has looped. real index is %d", row, realIndex.row() ); |
314 } |
498 // } |
315 } |
499 } |
316 |
500 |
317 /*! |
501 /*! |
318 * Private slot |
502 * Private slot |
319 */ |
503 */ |
325 } |
509 } |
326 mRadioTextHolder = ""; |
510 mRadioTextHolder = ""; |
327 mRadioTextTimer->stop(); |
511 mRadioTextTimer->stop(); |
328 } |
512 } |
329 |
513 |
|
514 /*! |
|
515 * Private slot |
|
516 */ |
|
517 void RadioStationCarousel::delayedScroll() |
|
518 { |
|
519 scrollContentsTo( QPointF( mScrollPos, 0 ) , 1000 ); |
|
520 } |
|
521 |
330 #ifdef USE_DEBUGGING_CONTROLS |
522 #ifdef USE_DEBUGGING_CONTROLS |
331 /*! |
523 /*! |
332 * Public slot |
524 * Public slot |
333 */ |
525 */ |
334 void RadioStationCarousel::setRdsAvailable( bool available ) |
526 void RadioStationCarousel::setRdsAvailable( bool available ) |
335 { |
527 { |
336 QColor color = Qt::green; |
528 QColor color = Qt::green; |
337 if ( !available ) { |
529 if ( !available && mUiEngine ) { |
338 LOG_FORMAT( "No RDS signal: Station has sent RDS earlier: %d", mUiEngine.model().currentStation().hasRds() ); |
530 LOG_FORMAT( "No RDS signal: Station has sent RDS earlier: %d", mUiEngine.model().currentStation().hasRds() ); |
339 color = mUiEngine.model().currentStation().hasRds() ? Qt::yellow : Qt::gray; |
531 color = mUiEngine.model().currentStation().hasRds() ? Qt::yellow : Qt::gray; |
340 mRdsLabel->setText( "RDS" ); |
532 mRdsLabel->setText( "RDS" ); |
341 } else { |
533 } else { |
342 mRdsLabel->setText( "-RDS-" ); |
534 mRdsLabel->setText( "-RDS-" ); |
380 } |
572 } |
381 */ |
573 */ |
382 |
574 |
383 if ( mModelIndexes.contains( frequency ) ) { |
575 if ( mModelIndexes.contains( frequency ) ) { |
384 QModelIndex index = mModelIndexes.value( frequency ); |
576 QModelIndex index = mModelIndexes.value( frequency ); |
385 scrollToIndex( index, 0 ); |
577 scrollToIndex( index, mAutoScrollTime ); |
386 } else { |
578 } else { |
387 if ( item ) { |
579 if ( item ) { |
388 item->setFrequency( frequency ); |
580 item->setFrequency( frequency ); |
389 } |
581 } |
390 } |
582 } |
391 } |
583 } |
392 |
584 |
393 /*! |
585 /*! |
394 * Public slot |
586 * Public slot |
395 * |
587 */ |
396 */ |
588 void RadioStationCarousel::updateAntennaStatus( bool connected ) |
397 void RadioStationCarousel::setSeekingText() |
|
398 { |
|
399 mRadioTextTimer->stop(); |
|
400 RadioStationItem* item = currentStationItem(); |
|
401 if ( item ) { |
|
402 item->setSeekingText(); |
|
403 } |
|
404 |
|
405 #ifdef USE_DEBUGGING_CONTROLS |
|
406 mRdsLabel->setTextColor( Qt::gray ); |
|
407 #endif //USE_DEBUGGING_CONTROLS |
|
408 } |
|
409 |
|
410 /*! |
|
411 * Public slot |
|
412 */ |
|
413 void RadioStationCarousel::updateHeadsetStatus( bool connected ) |
|
414 { |
589 { |
415 mRadioTextTimer->stop(); |
590 mRadioTextTimer->stop(); |
416 mAntennaAttached = connected; |
591 mAntennaAttached = connected; |
417 RadioStationItem* item = currentStationItem(); |
592 RadioStationItem* item = currentStationItem(); |
418 if ( item ) { |
593 if ( item ) { |
420 } |
595 } |
421 } |
596 } |
422 |
597 |
423 /*! |
598 /*! |
424 * \reimp |
599 * \reimp |
425 * |
600 */ |
426 */ |
601 void RadioStationCarousel::mouseMoveEvent( QGraphicsSceneMouseEvent* event ) |
427 void RadioStationCarousel::paint( QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget ) |
602 { |
428 { |
603 HbGridView::mouseMoveEvent( event ); |
429 mBackground.paint( painter, QRectF( QPoint( 0, 0 ), size() ), Qt::IgnoreAspectRatio ); |
|
430 HbGridView::paint( painter, option, widget ); |
|
431 } |
604 } |
432 |
605 |
433 /*! |
606 /*! |
434 * \reimp |
607 * \reimp |
435 */ |
608 */ |
436 void RadioStationCarousel::mouseMoveEvent( QGraphicsSceneMouseEvent* event ) |
609 void RadioStationCarousel::mouseReleaseEvent( QGraphicsSceneMouseEvent* event ) |
437 { |
610 { |
438 HbGridView::mouseMoveEvent( event ); |
611 // QPointF pos = QPointF( size().width() / 2, size().height() / 2 ); |
|
612 // HbAbstractViewItem* item = itemAtPosition( pos ); |
|
613 // if ( item ) { |
|
614 // scrollToIndex( item->modelIndex(), mAutoScrollTime ); |
|
615 // } |
|
616 |
|
617 HbGridView::mouseReleaseEvent( event ); |
439 } |
618 } |
440 |
619 |
441 /*! |
620 /*! |
442 * \reimp |
621 * \reimp |
443 */ |
622 */ |
444 void RadioStationCarousel::mouseReleaseEvent( QGraphicsSceneMouseEvent* event ) |
|
445 { |
|
446 QPointF pos = QPointF( size().width() / 2, size().height() / 2 ); |
|
447 HbAbstractViewItem* item = itemAtPosition( pos ); |
|
448 if ( item ) { |
|
449 scrollToIndex( item->modelIndex(), mAutoScrollTime ); |
|
450 } |
|
451 |
|
452 HbGridView::mouseReleaseEvent( event ); |
|
453 } |
|
454 |
|
455 /*! |
|
456 * \reimp |
|
457 */ |
|
458 void RadioStationCarousel::resizeEvent( QGraphicsSceneResizeEvent* event ) |
623 void RadioStationCarousel::resizeEvent( QGraphicsSceneResizeEvent* event ) |
459 { |
624 { |
460 HbGridView::resizeEvent( event ); |
625 HbGridView::resizeEvent( event ); |
461 QModelIndex index = filterModel()->modelIndexFromFrequency( mUiEngine.currentFrequency() ); |
626 // QModelIndex index = filterModel()->modelIndexFromFrequency( mUiEngine.currentFrequency() ); |
462 setCurrentIndex( index, QItemSelectionModel::SelectCurrent ); |
627 // setCurrentIndex( index, QItemSelectionModel::SelectCurrent ); |
463 scrollTo( index ); |
628 // scrollTo( index ); |
464 } |
629 } |
465 |
630 |
466 /*! |
631 /*! |
467 * |
632 * |
468 */ |
633 */ |
469 RadioStationItem* RadioStationCarousel::currentStationItem() |
634 RadioStationItem* RadioStationCarousel::currentStationItem() |
470 { |
635 { |
471 return static_cast<RadioStationItem*>( currentViewItem() ); |
636 return static_cast<RadioStationItem*>( currentViewItem() ); |
472 // return mCurrentItem; |
637 } |
473 } |
638 |
474 |
639 /*! |
475 /*! |
640 * |
476 * |
641 */ |
477 */ |
642 RadioStationModel* RadioStationCarousel::stationModel() const |
478 RadioStationFilterModel* RadioStationCarousel::filterModel() const |
643 { |
479 { |
644 return static_cast<RadioStationModel*>( model() ); |
480 return static_cast<RadioStationFilterModel*>( model() ); |
|
481 } |
645 } |
482 |
646 |
483 /*! |
647 /*! |
484 * |
648 * |
485 */ |
649 */ |
486 void RadioStationCarousel::scrollToIndex( const QModelIndex& index, int time ) |
650 void RadioStationCarousel::scrollToIndex( const QModelIndex& index, int time ) |
487 { |
651 { |
488 RadioStationItem* item = static_cast<RadioStationItem*>( itemByIndex( index ) ); |
652 RadioStationItem* item = static_cast<RadioStationItem*>( itemByIndex( index ) ); |
489 if ( index.isValid() && item ) { |
653 if ( index.isValid() && item ) { |
490 int posX = item->pos().x(); |
654 // int posX = item->pos().x(); |
|
655 int width = this->size().width(); |
|
656 int posX = index.row() * width; |
491 const int currentRow = currentIndex().row(); |
657 const int currentRow = currentIndex().row(); |
492 const int nextRow = index.row(); |
658 const int nextRow = index.row(); |
493 if ( currentRow != nextRow ) { |
659 if ( currentRow != nextRow ) { |
494 LOG_FORMAT( "Current row is %d, scrolling to row %d", currentRow, nextRow); |
660 LOG_FORMAT( "Current row is %d, scrolling to row %d", currentRow, nextRow); |
495 } |
661 } |
496 if ( !filterModel()->isEqual( currentIndex(), index ) ) { |
662 |
497 setCurrentIndex( index, QItemSelectionModel::SelectCurrent ); |
663 setCurrentIndex( index, QItemSelectionModel::SelectCurrent ); |
498 mCurrentItem = static_cast<RadioStationItem*>( item ); |
664 mCurrentItem = static_cast<RadioStationItem*>( item ); |
499 uint frequency = model()->data( index, RadioStationModel::RadioStationRole ).value<RadioStation>().frequency(); |
665 uint frequency = model()->data( index, RadioStationModel::RadioStationRole ).value<RadioStation>().frequency(); |
500 if ( item->frequency() != frequency ) { |
666 emit frequencyChanged( frequency, TuneReason::StationCarousel ); |
501 item->setFrequency( frequency ); |
667 |
502 } |
668 mScrollPos = posX; |
503 emit frequencyChanged( frequency, CommandSender::StationCarousel ); |
|
504 } |
|
505 scrollContentsTo( QPointF( posX, 0 ) , time ); |
669 scrollContentsTo( QPointF( posX, 0 ) , time ); |
506 } |
670 } |
507 } |
671 } |