radioapp/radiowidgets/src/radiocarouselitem.cpp
changeset 57 21be958eb3ce
parent 54 a8ba0c289b44
equal deleted inserted replaced
56:04837bf3a628 57:21be958eb3ce
    54 /*!
    54 /*!
    55  *
    55  *
    56  */
    56  */
    57 RadioCarouselItem::RadioCarouselItem( RadioCarouselItemObserver& observer, QGraphicsItem* parent, bool registerCss ) :
    57 RadioCarouselItem::RadioCarouselItem( RadioCarouselItemObserver& observer, QGraphicsItem* parent, bool registerCss ) :
    58     HbWidget( parent ),
    58     HbWidget( parent ),
       
    59     mFrequency( 0 ),
    59     mObserver( observer ),
    60     mObserver( observer ),
    60     mFavoriteItem( NULL ),
    61     mFavoriteItem( NULL ),
    61     mGenreItem( NULL ),
    62     mGenreItem( NULL ),
    62     mFavoriteTouchArea( NULL ),
    63     mFavoriteTouchArea( NULL ),
    63     mNameItem( NULL ),
    64     mNameItem( NULL ),
   167             const QPointF mappedHotSpot = event->mapToGraphicsScene( gesture->hotSpot() );
   168             const QPointF mappedHotSpot = event->mapToGraphicsScene( gesture->hotSpot() );
   168 
   169 
   169             if ( mFlags.testFlag( FavoriteTouchable ) &&
   170             if ( mFlags.testFlag( FavoriteTouchable ) &&
   170                     mFavoriteTouchArea->sceneBoundingRect().contains( mappedHotSpot ) ) {
   171                     mFavoriteTouchArea->sceneBoundingRect().contains( mappedHotSpot ) ) {
   171 
   172 
   172                 mObserver.handleIconClicked( *mStation );
   173                 mObserver.handleIconClicked( mFrequency );
   173 
   174 
   174             } else if ( mFlags.testFlag( RadiotextTouchable ) &&
   175             } else if ( mFlags.testFlag( RadiotextTouchable ) &&
   175                     mRadiotextItem->sceneBoundingRect().contains( mappedHotSpot ) ) {
   176                     mRadiotextItem->sceneBoundingRect().contains( mappedHotSpot ) ) {
   176 
   177 
   177                 mObserver.handleRadiotextClicked( *mStation );
   178                 mObserver.handleRadiotextClicked( *mStation );
   282  *
   283  *
   283  */
   284  */
   284 void RadioCarouselItem::setStation( const RadioStation& station )
   285 void RadioCarouselItem::setStation( const RadioStation& station )
   285 {
   286 {
   286     *mStation = station;
   287     *mStation = station;
       
   288     mFrequency = station.frequency();
   287 
   289 
   288     updateLayout();
   290     updateLayout();
   289 
   291 
   290     update();
   292     update();
   291 }
   293 }
   293 /*!
   295 /*!
   294  *
   296  *
   295  */
   297  */
   296 uint RadioCarouselItem::frequency() const
   298 uint RadioCarouselItem::frequency() const
   297 {
   299 {
   298     return mStation->frequency();
   300     return mFrequency;
   299 }
   301 }
   300 
   302 
   301 /*!
   303 /*!
   302  *
   304  *
   303  */
   305  */
   304 void RadioCarouselItem::update( const RadioStation* station )
   306 void RadioCarouselItem::update( const RadioStation* station )
   305 {
   307 {
   306     if ( station ) {
   308     if ( station ) {
   307         *mStation = *station;
   309         *mStation = *station;
       
   310         mFrequency = station->frequency();
   308         updateLayout();
   311         updateLayout();
   309     }
   312     }
   310 
   313 
   311     if ( mStation->isValid() ) {
   314     if ( mStation->isValid() ) {
   312         mGenreItem->setText( mObserver.localizeGenre( mStation->genre() ) );
   315         mGenreItem->setText( mObserver.localizeGenre( mStation->genre() ) );
   323         } else {
   326         } else {
   324             mNameItem->setAlignment( Qt::AlignHCenter );
   327             mNameItem->setAlignment( Qt::AlignHCenter );
   325             mNameItem->setText( mStation->frequencyString() );
   328             mNameItem->setText( mStation->frequencyString() );
   326         }
   329         }
   327 
   330 
   328         if ( mStation->hasRadiotext() ) {
   331         if ( mObserver.isAntennaAttached() ) {
   329             mRadiotextItem->setText( mStation->radioText() );
   332 
   330         } else {
   333             if ( mStation->hasRadiotext() ) {
   331             if ( mStation->hasDynamicPs() ) {
   334                 mRadiotextItem->setText( mStation->radioText() );
   332                 mRadiotextItem->setText( mStation->dynamicPsText() );
       
   333             } else if ( hasName ) {
       
   334                 const QString loc = hbTrId( "txt_rad_list_l1_mhz_small" );
       
   335                 mRadiotextItem->setText( loc.arg( mStation->frequencyString() ) );
       
   336             } else {
   335             } else {
   337                 mRadiotextItem->setText( "" );
   336                 if ( mStation->hasDynamicPs() ) {
       
   337                     mRadiotextItem->setText( mStation->dynamicPsText() );
       
   338                 } else if ( hasName ) {
       
   339                     const QString loc = hbTrId( "txt_rad_list_l1_mhz_small" );
       
   340                     mRadiotextItem->setText( loc.arg( mStation->frequencyString() ) );
       
   341                 } else {
       
   342                     mRadiotextItem->setText( "" );
       
   343                 }
   338             }
   344             }
   339         }
   345 
   340 
   346             mUrlItem->setText( mStation->url() );
   341         mUrlItem->setText( mStation->url() );
   347             if ( mStation->hasUrl() ) {
   342         if ( mStation->hasUrl() ) {
   348                 HbStyle::setItemName( mUrlItem, URL_LABEL );
   343             HbStyle::setItemName( mUrlItem, URL_LABEL );
   349                 setFlags( UrlVisible | UrlTouchable );
   344             setFlags( UrlVisible | UrlTouchable );
   350             } else {
   345         } else {
   351                 HbStyle::setItemName( mUrlItem, "" ); // Clear the name so the item disappears from layout
   346             HbStyle::setItemName( mUrlItem, "" ); // Clear the name so the item disappears from layout
   352                 clearFlags( UrlVisible | UrlTouchable );
   347             clearFlags( UrlVisible | UrlTouchable );
   353             }
   348         }
   354         }
   349 
   355 
   350         updateFavoriteIcon( mStation->isFavorite() );
   356         updateFavoriteIcon( mStation->isFavorite() );
   351     } else {
   357     } else {
   352         cleanRdsData();
   358         cleanRdsData();
   358  */
   364  */
   359 void RadioCarouselItem::setFrequency( uint frequency )
   365 void RadioCarouselItem::setFrequency( uint frequency )
   360 {
   366 {
   361     LOG_FORMAT( "RadioCarouselItem::setFrequency: %d", frequency );
   367     LOG_FORMAT( "RadioCarouselItem::setFrequency: %d", frequency );
   362 
   368 
   363     if ( mStation->hasName() && mStation->frequency() == frequency ) {
   369     QString text = RadioStation::parseFrequency( frequency );
   364         mNameItem->setText( mStation->name() );
       
   365     } else {
       
   366         mNameItem->setText( RadioStation::parseFrequency( frequency ) );
       
   367     }
       
   368 
       
   369 
       
   370     if ( !mObserver.isInManualSeek() ) {
   370     if ( !mObserver.isInManualSeek() ) {
   371         *mStation = mObserver.findStation( frequency );
   371         *mStation = mObserver.findStation( frequency );
   372     }
   372     }
       
   373     mFrequency = frequency;
       
   374     mNameItem->setText( text );
   373 }
   375 }
   374 
   376 
   375 /*!
   377 /*!
   376  *
   378  *
   377  */
   379  */