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 // System includes |
|
19 #include <QGraphicsLinearLayout> |
|
20 #include <HbAnchorLayout> |
|
21 #include <QPixmap> |
|
22 #include <QGraphicsSceneMouseEvent> |
|
23 #include <HbEffect> |
|
24 #include <QTimer> |
|
25 #include <QTimeLine> |
|
26 #include <HbPanGesture> |
|
27 |
|
28 // User includes |
|
29 #include "radiostationcarousel.h" |
|
30 #include "radiouiloader.h" |
|
31 #include "radiostationitem.h" |
|
32 #include "radiostation.h" |
|
33 #include "radiouiengine.h" |
|
34 #include "radiostationmodel.h" |
|
35 #include "radiofadinglabel.h" |
|
36 #include "radiologger.h" |
|
37 #include "radiocarouselmodel.h" |
|
38 #include "radiouiutilities.h" |
|
39 #include "radio_global.h" |
|
40 |
|
41 #ifdef USE_LAYOUT_FROM_E_DRIVE |
|
42 const QString KFavoriteIconPath = "e:/radiotest/images/favoriteiconactive.png"; |
|
43 const QString KNonFavoriteIconPath = "e:/radiotest/images/favoriteiconinactive.png"; |
|
44 #else |
|
45 const QString KFavoriteIconPath = ":/images/favoriteiconactive.png"; |
|
46 const QString KNonFavoriteIconPath = ":/images/favoriteiconinactive.png"; |
|
47 #endif |
|
48 |
|
49 const int KRadioTextPlusCheckTimeout = 700; // 700 ms |
|
50 const int KFreqScrollDivider = 100000; |
|
51 const int INFOTEXT_NOFAVORITES_TIMEOUT = 15000; |
|
52 |
|
53 // =============================================================== |
|
54 // Scanning helper |
|
55 // =============================================================== |
|
56 |
|
57 /*! |
|
58 * |
|
59 */ |
|
60 ScanningHelper::ScanningHelper( RadioStationCarousel& carousel ) : |
|
61 mCarousel( carousel ), |
|
62 mCurrentFrequency( 0 ), |
|
63 mPreviousFrequency( 0 ), |
|
64 mStationItem( 0 ), |
|
65 mNumberScrollingTimeLine( new QTimeLine( 1000, this ) ) |
|
66 { |
|
67 mNumberScrollingTimeLine->setCurveShape( QTimeLine::EaseInCurve ); |
|
68 connectAndTest( mNumberScrollingTimeLine, SIGNAL(finished()), |
|
69 &mCarousel, SIGNAL(scanAnimationFinished()) ); |
|
70 connectAndTest( mNumberScrollingTimeLine, SIGNAL(frameChanged(int)), |
|
71 this, SLOT(numberScrollUpdate(int)) ); |
|
72 } |
|
73 |
|
74 /*! |
|
75 * |
|
76 */ |
|
77 void ScanningHelper::start() |
|
78 { |
|
79 QTimer::singleShot( 0, this, SLOT(startSlide()) ); |
|
80 } |
|
81 |
|
82 /*! |
|
83 * Private slot |
|
84 */ |
|
85 void ScanningHelper::startSlide() |
|
86 { |
|
87 mCarousel.scrollToIndex( mModelIndex, RadioStationCarousel::NoSignal ); |
|
88 startNumberScroll(); |
|
89 } |
|
90 |
|
91 /*! |
|
92 * Private slot |
|
93 */ |
|
94 void ScanningHelper::startNumberScroll() |
|
95 { |
|
96 //TODO: Take italy case into account |
|
97 if ( mPreviousFrequency ) { |
|
98 mNumberScrollingTimeLine->setFrameRange( mPreviousFrequency / KFreqScrollDivider, mCurrentFrequency / KFreqScrollDivider ); |
|
99 mNumberScrollingTimeLine->start(); |
|
100 } else { |
|
101 emit mCarousel.scanAnimationFinished(); |
|
102 } |
|
103 } |
|
104 |
|
105 /*! |
|
106 * Private slot |
|
107 */ |
|
108 void ScanningHelper::numberScrollUpdate( int value ) |
|
109 { |
|
110 if ( mStationItem ) { |
|
111 mStationItem->setFrequency( value * KFreqScrollDivider ); |
|
112 } |
|
113 } |
|
114 |
|
115 // =============================================================== |
|
116 // Carousel |
|
117 // =============================================================== |
|
118 |
|
119 /*! |
|
120 * |
|
121 */ |
|
122 RadioStationCarousel::RadioStationCarousel( RadioUiEngine* uiEngine ) : |
|
123 HbGridView( 0 ), |
|
124 mUiEngine( uiEngine ), |
|
125 mAntennaAttached( false ), |
|
126 mAutoScrollTime( 300 ), |
|
127 mGenericTimer( new QTimer( this ) ), |
|
128 mTimerMode( NoTimer ), |
|
129 mScanningHelper( 0 ), |
|
130 mInfoText( 0 ), |
|
131 mCurrentItem( 0 ), |
|
132 mPanStartPos( 0 ) |
|
133 #ifdef USE_DEBUGGING_CONTROLS |
|
134 ,mRdsLabel( new RadioFadingLabel( this ) ) |
|
135 #endif // USE_DEBUGGING_CONTROLS |
|
136 { |
|
137 RadioUiUtilities::setCarousel( this ); |
|
138 setClampingStyle( HbScrollArea::StrictClamping ); |
|
139 setScrollingStyle( HbScrollArea::Pan ); |
|
140 } |
|
141 |
|
142 /*! |
|
143 * Property |
|
144 * |
|
145 */ |
|
146 void RadioStationCarousel::setFavoriteIcon( const HbIcon& favoriteIcon ) |
|
147 { |
|
148 mFavoriteIcon = favoriteIcon; |
|
149 } |
|
150 |
|
151 /*! |
|
152 * Property |
|
153 * |
|
154 */ |
|
155 HbIcon RadioStationCarousel::favoriteIcon() const |
|
156 { |
|
157 return mFavoriteIcon; |
|
158 } |
|
159 |
|
160 /*! |
|
161 * Property |
|
162 * |
|
163 */ |
|
164 void RadioStationCarousel::setNonFavoriteIcon( const HbIcon& nonFavoriteIcon ) |
|
165 { |
|
166 mNonFavoriteIcon = nonFavoriteIcon; |
|
167 } |
|
168 |
|
169 /*! |
|
170 * Property |
|
171 * |
|
172 */ |
|
173 HbIcon RadioStationCarousel::nonFavoriteIcon() const |
|
174 { |
|
175 return mNonFavoriteIcon; |
|
176 } |
|
177 |
|
178 /*! |
|
179 * |
|
180 */ |
|
181 void RadioStationCarousel::setAutoScrollTime( const int time ) |
|
182 { |
|
183 mAutoScrollTime = time; |
|
184 } |
|
185 |
|
186 /*! |
|
187 * |
|
188 */ |
|
189 int RadioStationCarousel::autoScrollTime() const |
|
190 { |
|
191 return mAutoScrollTime; |
|
192 } |
|
193 |
|
194 /*! |
|
195 * |
|
196 */ |
|
197 void RadioStationCarousel::init( RadioUiLoader& uiLoader, RadioUiEngine* uiEngine ) |
|
198 { |
|
199 mUiEngine = uiEngine; |
|
200 mAntennaAttached = mUiEngine->isAntennaAttached(); |
|
201 |
|
202 mInfoText = uiLoader.findWidget<HbLabel>( DOCML::MV_NAME_INFO_TEXT ); |
|
203 mInfoText->setTextWrapping( Hb::TextWordWrap ); |
|
204 |
|
205 setRowCount( 1 ); |
|
206 setColumnCount( 1 ); |
|
207 setScrollDirections( Qt::Horizontal ); |
|
208 setFrictionEnabled( true ); |
|
209 setLongPressEnabled( false ); |
|
210 setItemRecycling( false ); |
|
211 setUniformItemSizes( true ); |
|
212 setItemPrototype( new RadioStationItem( *this ) ); |
|
213 setSelectionMode( NoSelection ); |
|
214 |
|
215 // grabGesture( Qt::PanGesture ); |
|
216 |
|
217 RadioCarouselModel* carouselModel = mUiEngine->carouselModel(); |
|
218 setCarouselModel( carouselModel ); |
|
219 |
|
220 mCurrentItem = static_cast<RadioStationItem*>( itemByIndex( carouselModel->index( 0, 0 ) ) ); |
|
221 |
|
222 RadioStationModel* stationModel = &mUiEngine->stationModel(); |
|
223 connectAndTest( stationModel, SIGNAL(favoriteChanged(RadioStation)), |
|
224 this, SLOT(update(RadioStation)) ); |
|
225 connectAndTest( stationModel, SIGNAL(stationDataChanged(RadioStation)), |
|
226 this, SLOT(update(RadioStation))); |
|
227 connectAndTest( stationModel, SIGNAL(radioTextReceived(RadioStation)), |
|
228 this, SLOT(updateRadioText(RadioStation))); |
|
229 connectAndTest( stationModel, SIGNAL(dynamicPsChanged(RadioStation)), |
|
230 this, SLOT(update(RadioStation))); |
|
231 |
|
232 updateClampingStyle(); |
|
233 |
|
234 connectAndTest( this, SIGNAL(longPressed(HbAbstractViewItem*,QPointF)), |
|
235 this, SLOT(openContextMenu(HbAbstractViewItem*,QPointF)) ); |
|
236 setLongPressEnabled( true ); |
|
237 |
|
238 mGenericTimer->setSingleShot( true ); |
|
239 connectAndTest( mGenericTimer, SIGNAL(timeout()), |
|
240 this, SLOT(timerFired())); |
|
241 |
|
242 initToLastTunedFrequency(); |
|
243 |
|
244 #ifdef USE_DEBUGGING_CONTROLS |
|
245 mRdsLabel->setPos( QPoint( 300, 10 ) ); |
|
246 mRdsLabel->setText( "RDS" ); |
|
247 mRdsLabel->setElideMode( Qt::ElideNone ); |
|
248 HbFontSpec spec = mRdsLabel->fontSpec(); |
|
249 spec.setTextPaneHeight( 10 ); |
|
250 spec.setRole( HbFontSpec::Secondary ); |
|
251 mRdsLabel->setFontSpec( spec ); |
|
252 mRdsLabel->setTextColor( Qt::gray ); |
|
253 if ( mUiEngine ) { |
|
254 connectAndTest( mUiEngine, SIGNAL(rdsAvailabilityChanged(bool)), |
|
255 this, SLOT(setRdsAvailable(bool)) ); |
|
256 } |
|
257 #endif // USE_DEBUGGING_CONTROLS |
|
258 } |
|
259 |
|
260 /*! |
|
261 * |
|
262 */ |
|
263 void RadioStationCarousel::setCarouselModel( RadioCarouselModel* carouselModel ) |
|
264 { |
|
265 if ( carouselModel ) { |
|
266 connectAndTest( carouselModel, SIGNAL(rowsInserted(QModelIndex,int,int)), |
|
267 this, SLOT(insertFrequency(QModelIndex,int,int)) ); |
|
268 connectAndTest( carouselModel, SIGNAL(rowsAboutToBeRemoved(QModelIndex,int,int)), |
|
269 this, SLOT(prepareToRemoveFrequency(QModelIndex,int,int)) ); |
|
270 connectAndTest( carouselModel, SIGNAL(rowsRemoved(QModelIndex,int,int)), |
|
271 this, SLOT(removeFrequency(QModelIndex,int,int)) ); |
|
272 } else { |
|
273 QAbstractItemModel* currentModel = model(); |
|
274 disconnect( currentModel, SIGNAL(rowsInserted(QModelIndex,int,int)), |
|
275 this, SLOT(insertFrequency(QModelIndex,int,int)) ); |
|
276 disconnect( currentModel, SIGNAL(rowsAboutToBeRemoved(QModelIndex,int,int)), |
|
277 this, SLOT(prepareToRemoveFrequency(QModelIndex,int,int)) ); |
|
278 disconnect( currentModel, SIGNAL(rowsRemoved(QModelIndex,int,int)), |
|
279 this, SLOT(removeFrequency(QModelIndex,int,int)) ); |
|
280 } |
|
281 setModel( carouselModel ); |
|
282 updateFrequencies(); |
|
283 initCurrentStationItem(); |
|
284 } |
|
285 |
|
286 /*! |
|
287 * |
|
288 */ |
|
289 void RadioStationCarousel::setFrequency( uint frequency, int reason ) |
|
290 { |
|
291 RadioStationItem* item = currentStationItem(); |
|
292 // if ( item && item->mFrequency == frequency ) { |
|
293 // return; |
|
294 // } |
|
295 |
|
296 if ( mModelIndexes.contains( frequency ) ) { |
|
297 QModelIndex index = mModelIndexes.value( frequency ); |
|
298 |
|
299 if ( reason == TuneReason::FrequencyStrip || reason == TuneReason::StationsList ) { |
|
300 scrollToIndex( index, RadioStationCarousel::NoAnim | RadioStationCarousel::NoSignal ); |
|
301 } else if ( reason == TuneReason::Skip || reason == TuneReason::StationScan ) { |
|
302 scrollToIndex( index, RadioStationCarousel::NoSignal ); |
|
303 } else { |
|
304 scrollToIndex( index ); |
|
305 } |
|
306 } else { |
|
307 if ( item ) { |
|
308 item->setFrequency( frequency ); |
|
309 } |
|
310 } |
|
311 } |
|
312 |
|
313 /*! |
|
314 * |
|
315 */ |
|
316 RadioUiEngine* RadioStationCarousel::uiEngine() |
|
317 { |
|
318 return mUiEngine; |
|
319 } |
|
320 |
|
321 /*! |
|
322 * |
|
323 */ |
|
324 bool RadioStationCarousel::isAntennaAttached() const |
|
325 { |
|
326 return mAntennaAttached; |
|
327 } |
|
328 |
|
329 /*! |
|
330 * |
|
331 */ |
|
332 void RadioStationCarousel::setScanningMode( bool scanning ) |
|
333 { |
|
334 initCurrentStationItem(); |
|
335 |
|
336 if ( scanning ) { |
|
337 |
|
338 setInfoText( CarouselInfoText::Scanning ); |
|
339 if ( !mScanningHelper ) { |
|
340 mScanningHelper = new ScanningHelper( *this ); |
|
341 } |
|
342 } else { |
|
343 delete mScanningHelper; |
|
344 mScanningHelper = 0; |
|
345 clearInfoText(); |
|
346 } |
|
347 setEnabled( !scanning ); |
|
348 } |
|
349 |
|
350 /*! |
|
351 * |
|
352 */ |
|
353 bool RadioStationCarousel::isInScanningMode() const |
|
354 { |
|
355 return RadioUiUtilities::isScannerAlive(); |
|
356 } |
|
357 |
|
358 /*! |
|
359 * |
|
360 */ |
|
361 void RadioStationCarousel::cleanRdsData() |
|
362 { |
|
363 RadioStationItem* item = currentStationItem(); |
|
364 if ( item ) { |
|
365 item->cleanRdsData(); |
|
366 } |
|
367 } |
|
368 |
|
369 /*! |
|
370 * |
|
371 */ |
|
372 void RadioStationCarousel::updateCurrentItem() |
|
373 { |
|
374 RadioStationItem* item = currentStationItem(); |
|
375 if ( item ) { |
|
376 item->update(); |
|
377 } |
|
378 } |
|
379 |
|
380 /*! |
|
381 * |
|
382 */ |
|
383 void RadioStationCarousel::animateNewStation( const RadioStation& station ) |
|
384 { |
|
385 if ( mScanningHelper ) { |
|
386 RadioCarouselModel* model = carouselModel(); |
|
387 const QModelIndex index = model->modelIndexFromFrequency( station.frequency() ); |
|
388 mScanningHelper->mModelIndex = index; |
|
389 mScanningHelper->mCurrentFrequency = station.frequency(); |
|
390 mScanningHelper->mStationItem = static_cast<RadioStationItem*>( itemByIndex( index ) ); |
|
391 |
|
392 uint prevFrequency = 0; |
|
393 if ( model->rowCount() > 1 ) { |
|
394 const int prevIndex = index.row() - 1; |
|
395 RadioStation prevStation = model->data( model->index( prevIndex, 0 ), RadioStationModel::RadioStationRole ).value<RadioStation>(); |
|
396 prevFrequency = prevStation.frequency(); |
|
397 } else if ( mUiEngine ) { |
|
398 prevFrequency = mUiEngine->minFrequency(); |
|
399 } |
|
400 |
|
401 mScanningHelper->mPreviousFrequency = prevFrequency; |
|
402 if ( mScanningHelper->mStationItem ) { |
|
403 mScanningHelper->mStationItem->setFrequency( prevFrequency ); |
|
404 mScanningHelper->mStationItem->cleanRdsData(); |
|
405 } |
|
406 |
|
407 mScanningHelper->start(); |
|
408 } |
|
409 } |
|
410 |
|
411 /*! |
|
412 * |
|
413 */ |
|
414 void RadioStationCarousel::setItemVisible( bool visible ) |
|
415 { |
|
416 RadioStationItem* item = currentStationItem(); |
|
417 if ( item ) { |
|
418 item->setVisible( visible ); |
|
419 } |
|
420 } |
|
421 |
|
422 /*! |
|
423 * |
|
424 */ |
|
425 void RadioStationCarousel::setInfoText( CarouselInfoText::Type type ) |
|
426 { |
|
427 mInfoTextType = type; |
|
428 if ( type == CarouselInfoText::NoFavorites ) { |
|
429 mInfoText->setPlainText( hbTrId( "txt_rad_dialog_long_press_arrow_keys_to_search_str" ) ); |
|
430 mInfoText->setAlignment( Qt::AlignCenter ); |
|
431 setItemVisible( false ); |
|
432 mTimerMode = InfoText; |
|
433 mGenericTimer->setInterval( INFOTEXT_NOFAVORITES_TIMEOUT ); |
|
434 mGenericTimer->start(); |
|
435 } else if ( type == CarouselInfoText::ConnectAntenna ) { |
|
436 cleanRdsData(); |
|
437 mInfoText->setPlainText( hbTrId( "txt_rad_info_connect_wired_headset1" ) ); |
|
438 mInfoText->setAlignment( Qt::AlignBottom | Qt::AlignHCenter ); |
|
439 } else if ( type == CarouselInfoText::Seeking ) { |
|
440 cleanRdsData(); |
|
441 mInfoText->setAlignment( Qt::AlignBottom | Qt::AlignHCenter ); |
|
442 mInfoText->setPlainText( hbTrId( "txt_rad_list_seeking" ) ); |
|
443 } else if ( type == CarouselInfoText::Scanning ) { |
|
444 cleanRdsData(); |
|
445 mInfoText->setAlignment( Qt::AlignBottom | Qt::AlignHCenter ); |
|
446 mInfoText->setPlainText( hbTrId( "txt_rad_list_searching_all_available_stations_ple" ) ); |
|
447 } |
|
448 |
|
449 mInfoText->setVisible( true ); |
|
450 } |
|
451 |
|
452 /*! |
|
453 * |
|
454 */ |
|
455 void RadioStationCarousel::clearInfoText() |
|
456 { |
|
457 if ( mInfoTextType != CarouselInfoText::None ) { |
|
458 mGenericTimer->stop(); |
|
459 mInfoTextType = CarouselInfoText::None; |
|
460 mInfoText->setVisible( false ); |
|
461 mInfoText->clear(); |
|
462 setItemVisible( true ); |
|
463 updateCurrentItem(); |
|
464 } |
|
465 } |
|
466 |
|
467 /*! |
|
468 * Private slot |
|
469 */ |
|
470 void RadioStationCarousel::update( const RadioStation& station ) |
|
471 { |
|
472 RadioStationItem* item = currentStationItem(); |
|
473 if ( item && item->frequency() == station.frequency() && !isInScanningMode() ) { |
|
474 item->update( &station ); |
|
475 } |
|
476 } |
|
477 |
|
478 /*! |
|
479 * Private slot |
|
480 */ |
|
481 void RadioStationCarousel::updateRadioText( const RadioStation& station ) |
|
482 { |
|
483 if ( isAntennaAttached() && !isInScanningMode() ) { |
|
484 if ( station.radioText().isEmpty() ) { |
|
485 RadioStationItem* item = currentStationItem(); |
|
486 if ( item ) { |
|
487 item->mRadiotextLabel->setText( "" ); |
|
488 } |
|
489 } else { |
|
490 mRadioTextHolder = station.radioText(); |
|
491 mTimerMode = RtPlusCheck; |
|
492 mGenericTimer->stop(); |
|
493 mGenericTimer->setInterval( KRadioTextPlusCheckTimeout ); |
|
494 mGenericTimer->start(); |
|
495 } |
|
496 } |
|
497 } |
|
498 |
|
499 /*! |
|
500 * Private slot |
|
501 */ |
|
502 void RadioStationCarousel::insertFrequency( const QModelIndex& parent, int first, int last ) |
|
503 { |
|
504 Q_UNUSED( parent ); |
|
505 QAbstractItemModel* freqModel = model(); |
|
506 |
|
507 for ( int i = first; freqModel && i <= last; ++i ) { |
|
508 QModelIndex index = freqModel->index( i, 0 ); |
|
509 RadioStation station = freqModel->data( index, RadioStationModel::RadioStationRole ).value<RadioStation>(); |
|
510 mModelIndexes.insert( station.frequency(), index ); |
|
511 LOG_FORMAT( "Added frequency %u", station.frequency() ); |
|
512 if ( !isInScanningMode() ) { |
|
513 scrollToIndex( index, RadioStationCarousel::NoAnim | RadioStationCarousel::NoSignal ); |
|
514 } |
|
515 } |
|
516 |
|
517 initCurrentStationItem(); |
|
518 |
|
519 updateClampingStyle(); |
|
520 } |
|
521 |
|
522 /*! |
|
523 * Private slot |
|
524 */ |
|
525 void RadioStationCarousel::prepareToRemoveFrequency( const QModelIndex& parent, int first, int last ) |
|
526 { |
|
527 Q_UNUSED( parent ); |
|
528 QAbstractItemModel* freqModel = model(); |
|
529 for ( int i = first; freqModel && i <= last; ++i ) { |
|
530 QModelIndex index = freqModel->index( i, 0 ); |
|
531 RadioStation station = freqModel->data( index, RadioStationModel::RadioStationRole ).value<RadioStation>(); |
|
532 mModelIndexes.remove( station.frequency() ); |
|
533 } |
|
534 } |
|
535 |
|
536 /*! |
|
537 * Private slot |
|
538 */ |
|
539 void RadioStationCarousel::removeFrequency( const QModelIndex& parent, int first, int last ) |
|
540 { |
|
541 Q_UNUSED( parent ); |
|
542 Q_UNUSED( first ); |
|
543 Q_UNUSED( last ); |
|
544 |
|
545 initCurrentStationItem(); |
|
546 updateClampingStyle(); |
|
547 } |
|
548 |
|
549 /*! |
|
550 * Private slot |
|
551 */ |
|
552 void RadioStationCarousel::updateFrequencies() |
|
553 { |
|
554 mModelIndexes.clear(); |
|
555 QAbstractItemModel* itemModel = model(); |
|
556 if ( itemModel ) { |
|
557 const int count = itemModel->rowCount(); |
|
558 for ( int i = 0; i < count; ++i ) { |
|
559 QModelIndex index = itemModel->index( i, 0 ); |
|
560 uint frequency = itemModel->data( index, RadioStationModel::RadioStationRole ).value<RadioStation>().frequency(); |
|
561 mModelIndexes.insert( frequency, index ); |
|
562 } |
|
563 } |
|
564 } |
|
565 |
|
566 /*! |
|
567 * Private slot |
|
568 */ |
|
569 void RadioStationCarousel::timerFired() |
|
570 { |
|
571 if ( mTimerMode == RtPlusCheck ) { |
|
572 RadioStationItem* item = currentStationItem(); |
|
573 if ( item ) { |
|
574 item->mRadiotextLabel->setText( mRadioTextHolder ); |
|
575 } |
|
576 mRadioTextHolder = ""; |
|
577 } else if ( mTimerMode == InfoText ) { |
|
578 clearInfoText(); |
|
579 } |
|
580 |
|
581 mTimerMode = NoTimer; |
|
582 } |
|
583 |
|
584 /*! |
|
585 * Private slot |
|
586 */ |
|
587 void RadioStationCarousel::openContextMenu( HbAbstractViewItem* item, const QPointF& coords ) |
|
588 { |
|
589 if ( item ) { |
|
590 static_cast<RadioStationItem*>( item )->handleLongPress( coords ); |
|
591 } |
|
592 } |
|
593 |
|
594 #ifdef USE_DEBUGGING_CONTROLS |
|
595 /*! |
|
596 * Public slot |
|
597 */ |
|
598 void RadioStationCarousel::setRdsAvailable( bool available ) |
|
599 { |
|
600 QColor color = Qt::green; |
|
601 if ( !available && mUiEngine ) { |
|
602 LOG_FORMAT( "No RDS signal: Station has sent RDS earlier: %d", mUiEngine.model().currentStation().hasRds() ); |
|
603 color = mUiEngine.model().currentStation().hasRds() ? Qt::yellow : Qt::gray; |
|
604 mRdsLabel->setText( "RDS" ); |
|
605 } else { |
|
606 mRdsLabel->setText( "-RDS-" ); |
|
607 } |
|
608 mRdsLabel->setTextColor( color ); |
|
609 } |
|
610 #endif // USE_DEBUGGING_CONTROLS |
|
611 |
|
612 /*! |
|
613 * Public slot |
|
614 */ |
|
615 void RadioStationCarousel::updateAntennaStatus( bool connected ) |
|
616 { |
|
617 mAntennaAttached = connected; |
|
618 mGenericTimer->stop(); |
|
619 |
|
620 if ( !connected ) { |
|
621 setInfoText( CarouselInfoText::ConnectAntenna ); |
|
622 } else { |
|
623 clearInfoText(); |
|
624 } |
|
625 } |
|
626 |
|
627 /*! |
|
628 * \reimp |
|
629 */ |
|
630 void RadioStationCarousel::mousePressEvent( QGraphicsSceneMouseEvent* event ) |
|
631 { |
|
632 if ( mInfoTextType == CarouselInfoText::NoFavorites ) { |
|
633 clearInfoText(); |
|
634 } |
|
635 |
|
636 HbGridView::mousePressEvent( event ); |
|
637 } |
|
638 |
|
639 /*! |
|
640 * \reimp |
|
641 */ |
|
642 void RadioStationCarousel::gestureEvent( QGestureEvent* event ) |
|
643 { |
|
644 HbGridView::gestureEvent( event ); |
|
645 |
|
646 if ( HbPanGesture* gesture = qobject_cast<HbPanGesture*>( event->gesture( Qt::PanGesture ) ) ) { |
|
647 if ( gesture->state() == Qt::GestureFinished ) { |
|
648 updatePos( (int)gesture->offset().x() ); |
|
649 } |
|
650 } |
|
651 } |
|
652 |
|
653 /*! |
|
654 * |
|
655 */ |
|
656 void RadioStationCarousel::initToLastTunedFrequency() |
|
657 { |
|
658 const uint currentFrequency = mUiEngine->currentFrequency(); |
|
659 const QModelIndex currentIndex = carouselModel()->modelIndexFromFrequency( currentFrequency ); |
|
660 |
|
661 if ( currentIndex.isValid() ) {//&& itemByIndex( currentIndex ) ) { |
|
662 scrollToIndex( currentIndex, RadioStationCarousel::NoSignal | RadioStationCarousel::NoAnim ); |
|
663 } else { |
|
664 RadioStationItem* item = static_cast<RadioStationItem*>( itemAt( 0, 0 ) ); |
|
665 if ( item ) { |
|
666 item->setFrequency( currentFrequency ); |
|
667 } |
|
668 } |
|
669 } |
|
670 |
|
671 /*! |
|
672 * |
|
673 */ |
|
674 void RadioStationCarousel::updateClampingStyle() |
|
675 { |
|
676 if ( model()->rowCount() > 1 ) { |
|
677 setClampingStyle( HbScrollArea::StrictClamping ); |
|
678 } else { |
|
679 setClampingStyle( HbScrollArea::BounceBackClamping ); |
|
680 update( mUiEngine->stationModel().currentStation() ); |
|
681 } |
|
682 } |
|
683 |
|
684 /*! |
|
685 * |
|
686 */ |
|
687 void RadioStationCarousel::initCurrentStationItem() |
|
688 { |
|
689 mCurrentItem = static_cast<RadioStationItem*>( visibleItems().first() ); |
|
690 } |
|
691 |
|
692 /*! |
|
693 * |
|
694 */ |
|
695 RadioStationItem* RadioStationCarousel::currentStationItem() |
|
696 { |
|
697 return mCurrentItem; |
|
698 } |
|
699 |
|
700 /*! |
|
701 * |
|
702 */ |
|
703 RadioCarouselModel* RadioStationCarousel::carouselModel() const |
|
704 { |
|
705 return static_cast<RadioCarouselModel*>( model() ); |
|
706 } |
|
707 |
|
708 /*! |
|
709 * |
|
710 */ |
|
711 void RadioStationCarousel::scrollToIndex( const QModelIndex& index, RadioStationCarousel::ScrollMode mode ) |
|
712 { |
|
713 RadioStationItem* item = static_cast<RadioStationItem*>( itemByIndex( index ) ); |
|
714 if ( index.isValid() && item ) { |
|
715 const int posX = index.row() * (int)size().width(); |
|
716 setCurrentIndex( index, QItemSelectionModel::ClearAndSelect ); |
|
717 |
|
718 if ( mode.testFlag( UpdateItem ) ) { |
|
719 item->update(); |
|
720 } |
|
721 |
|
722 int scrollTime = mAutoScrollTime; |
|
723 if ( mode.testFlag( NoAnim ) ) { |
|
724 scrollTime = 0; |
|
725 } |
|
726 scrollContentsTo( QPointF( posX, 0 ), scrollTime ); |
|
727 mCurrentItem = static_cast<RadioStationItem*>( item ); |
|
728 if ( !mode.testFlag( NoSignal ) ) { |
|
729 uint frequency = model()->data( index, RadioStationModel::RadioStationRole ).value<RadioStation>().frequency(); |
|
730 emit frequencyChanged( frequency, TuneReason::StationCarousel ); |
|
731 } |
|
732 } |
|
733 } |
|
734 |
|
735 /*! |
|
736 * |
|
737 */ |
|
738 void RadioStationCarousel::updatePos( int offset ) |
|
739 { |
|
740 // QModelIndex index = currentIndex(); |
|
741 // |
|
742 // ScrollMode mode = 0; |
|
743 // const qreal threshold = size().width() / 3; |
|
744 // if ( abs( offset ) >= threshold ) { |
|
745 // if ( offset > 0 ) { |
|
746 // index = previousIndex( index ); |
|
747 // } else { |
|
748 // index = nextIndex( index ); |
|
749 // } |
|
750 // } else { |
|
751 // mode |= RadioStationCarousel::NoSignal; |
|
752 // } |
|
753 // |
|
754 // scrollToIndex( index, mode ); |
|
755 } |
|
756 |
|
757 /*! |
|
758 * |
|
759 */ |
|
760 void RadioStationCarousel::skip( StationSkip::Mode mode ) |
|
761 { |
|
762 RadioStationItem* item = currentStationItem(); |
|
763 if ( item ) { |
|
764 RadioCarouselModel* model = carouselModel(); |
|
765 const uint frequency = model->findClosest( item->frequency(), mode ).frequency(); |
|
766 const QModelIndex& index = model->modelIndexFromFrequency( frequency ); |
|
767 scrollToIndex( index, RadioStationCarousel::NoSignal ); |
|
768 } |
|
769 } |
|