radioapp/radiowidgets/src/radiostationitem.cpp
changeset 14 63aabac4416d
child 16 f54ebcfc1b80
equal deleted inserted replaced
13:46974bebc798 14:63aabac4416d
       
     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 <HbStyleLoader>
       
    20 #include <HbPushButton>
       
    21 #include <HbAnchorLayout>
       
    22 
       
    23 // User includes
       
    24 #include "radiostationitem.h"
       
    25 #include "radiostationcarousel.h"
       
    26 #include "radiouiengine.h"
       
    27 #include "radiofadinglabel.h"
       
    28 #include "radiostationmodel.h"
       
    29 #include "radiolocalization.h"
       
    30 #include "radiologger.h"
       
    31 
       
    32 //static const char* FILE_PATH_WIDGETML   = ":/layout/radiostationitem.widgetml";
       
    33 //static const char* FILE_PATH_CSS        = ":/layout/radiostationitem.css";
       
    34 //static const char* GENRE_LABEL          = "genre_label";
       
    35 //static const char* NAME_LABEL           = "name_label";
       
    36 //static const char* RADIOTEXT_LABEL      = "radiotext_label";
       
    37 //static const char* URL_LABEL            = "url_label";
       
    38 //static const char* FAVORITE_BUTTON      = "favorite_button";
       
    39 
       
    40 const char* SEEKING_TEXT = "txt_rad_list_tuning";
       
    41 const char* CONNECT_HEADSET_TEXT = "txt_rad_list_connect_wireless_antenna_headset_with";
       
    42 
       
    43 /*!
       
    44  *
       
    45  */
       
    46 RadioStationItem::RadioStationItem( RadioStationCarousel& carousel ) :
       
    47     HbAbstractViewItem( &carousel ),
       
    48     mCarousel( carousel ),
       
    49     mLayout( 0 ),
       
    50     mNameLabel( 0 ),
       
    51     mIconButton( 0 ),
       
    52     mGenreLabel( 0 ),
       
    53     mRadiotextLabel( 0 ),
       
    54     mUrlLabel( 0 )
       
    55 {
       
    56     setFlag( QGraphicsItem::ItemIsFocusable, true );
       
    57 }
       
    58 
       
    59 /*!
       
    60  * From HbAbstractViewItem
       
    61  *
       
    62  */
       
    63 HbAbstractViewItem* RadioStationItem::createItem()
       
    64 {
       
    65     RadioStationItem* item = new RadioStationItem( *this ); // Calls copy constructor
       
    66 //    item->setParent( &mCarousel );
       
    67 //    item->setParentItem( &mCarousel );
       
    68 //    item->setItemView( itemView() );
       
    69 //    item->updateChildItems();
       
    70     return item;
       
    71 }
       
    72 
       
    73 /*!
       
    74  * From HbAbstractViewItem
       
    75  */
       
    76 void RadioStationItem::updateChildItems()
       
    77 {
       
    78     if ( !mLayout )
       
    79     {
       
    80         mIconButton = new HbPushButton( this );
       
    81         QPixmap background( QSize( 50, 50 ) );
       
    82         background.fill( Qt::transparent );
       
    83         mIconButton->setBackground( HbIcon( background ) );
       
    84         mIconButton->setOrientation( Qt::Horizontal );
       
    85         mIconButton->setIcon( mCarousel.nonFavoriteIcon() );
       
    86         mIconButton->setMaximumSize( 50, 50 );
       
    87         connectAndTest( mIconButton, SIGNAL(clicked()), this, SLOT(toggleFavorite()));
       
    88 
       
    89         mNameLabel = new RadioFadingLabel( this );
       
    90         mNameLabel->setAlignment( Qt::AlignCenter );
       
    91         HbFontSpec spec = mNameLabel->fontSpec();
       
    92         spec.setRole( HbFontSpec::Primary );
       
    93         mNameLabel->setFontSpec( spec );
       
    94 
       
    95         spec.setRole( HbFontSpec::Secondary );
       
    96 
       
    97         mGenreLabel = new RadioFadingLabel( this );
       
    98         mGenreLabel->setAlignment( Qt::AlignCenter );
       
    99         mGenreLabel->setTextColor( Qt::white );
       
   100 
       
   101         mRadiotextLabel = new RadioFadingLabel( this );
       
   102         mRadiotextLabel->setAlignment( Qt::AlignCenter );
       
   103         mRadiotextLabel->setTextWrapping( Hb::TextWordWrap );
       
   104 //        mRadiotextLabel->setFadingEnabled( true );    TODO
       
   105 //        mRadiotextLabel->setFontSpec( spec );
       
   106         mRadiotextLabel->setTextColor( Qt::white );
       
   107 
       
   108         mUrlLabel = new RadioFadingLabel( this );
       
   109         mUrlLabel->setAlignment( Qt::AlignCenter );
       
   110         mUrlLabel->setTextColor( Qt::white );
       
   111 
       
   112         mLayout = new HbAnchorLayout();
       
   113 
       
   114         mLayout->setAnchor( mLayout, Hb::TopEdge, mIconButton, Hb::TopEdge, 20.0 );
       
   115         mLayout->setAnchor( mLayout, Hb::LeftEdge, mIconButton, Hb::LeftEdge, 20.0 );
       
   116 
       
   117         mLayout->setAnchor( mIconButton, Hb::CenterVEdge, mGenreLabel, Hb::CenterVEdge, 0.0 );
       
   118         mLayout->setAnchor( mIconButton, Hb::RightEdge, mGenreLabel, Hb::LeftEdge, 20.0 );
       
   119         mLayout->setAnchor( mLayout, Hb::RightEdge, mGenreLabel, Hb::RightEdge, -70.0 );
       
   120 
       
   121         mLayout->setAnchor( mGenreLabel, Hb::BottomEdge, mNameLabel, Hb::TopEdge, 0.0 );
       
   122         mLayout->setAnchor( mLayout, Hb::LeftEdge, mNameLabel, Hb::LeftEdge, 10.0 );
       
   123         mLayout->setAnchor( mLayout, Hb::RightEdge, mNameLabel, Hb::RightEdge, -10.0 );
       
   124 
       
   125         mLayout->setAnchor( mNameLabel, Hb::BottomEdge, mRadiotextLabel, Hb::TopEdge, 10.0 );
       
   126         mLayout->setAnchor( mLayout, Hb::LeftEdge, mRadiotextLabel, Hb::LeftEdge, 10.0 );
       
   127         mLayout->setAnchor( mLayout, Hb::RightEdge, mRadiotextLabel, Hb::RightEdge, -10.0 );
       
   128 
       
   129         mLayout->setAnchor( mRadiotextLabel, Hb::BottomEdge, mUrlLabel, Hb::TopEdge, 10.0 );
       
   130         mLayout->setAnchor( mLayout, Hb::LeftEdge, mUrlLabel, Hb::LeftEdge, 10.0 );
       
   131         mLayout->setAnchor( mLayout, Hb::RightEdge, mUrlLabel, Hb::RightEdge, -10.0 );
       
   132         mLayout->setAnchor( mLayout, Hb::BottomEdge, mUrlLabel, Hb::BottomEdge, -10.0 );
       
   133 
       
   134         setLayout( mLayout );
       
   135     }
       
   136 
       
   137     update();
       
   138 }
       
   139 
       
   140 /*!
       
   141  * Private slot
       
   142  *
       
   143  */
       
   144 void RadioStationItem::toggleFavorite()
       
   145 {
       
   146     carousel()->uiEngine().model().setData( modelIndex(), mFrequency, RadioStationModel::ToggleFavoriteRole );
       
   147 }
       
   148 
       
   149 /*!
       
   150  *
       
   151  */
       
   152 uint RadioStationItem::frequency() const
       
   153 {
       
   154     return mFrequency;
       
   155 }
       
   156 
       
   157 /*!
       
   158  *
       
   159  */
       
   160 void RadioStationItem::update( const RadioStation* station )
       
   161 {
       
   162     QModelIndex index = modelIndex();
       
   163     if ( !( station && station->isValid() ) && !index.isValid() ) {
       
   164         return;
       
   165     }
       
   166 
       
   167     RadioStation tempStation = ( station && station->isValid() ) ? *station
       
   168                     : index.data( RadioStationModel::RadioStationRole ).value<RadioStation>();
       
   169 
       
   170     mNameLabel->setTextWithoutFading( RadioUiEngine::nameOrFrequency( tempStation ) );
       
   171     mGenreLabel->setText( carousel()->uiEngine().genreToString( tempStation.genre() ) );
       
   172     if ( !carousel()->isAntennaAttached() ) {
       
   173         mRadiotextLabel->setText( hbTrId( CONNECT_HEADSET_TEXT ) );
       
   174     } else {
       
   175         if ( !tempStation.radioText().isEmpty() ) {
       
   176             mRadiotextLabel->setText( tempStation.radioText() );
       
   177         } else if ( !tempStation.dynamicPsText().isEmpty() ) {
       
   178             mRadiotextLabel->setText( tempStation.dynamicPsText() );
       
   179         } else {
       
   180             mRadiotextLabel->setText( "" );
       
   181         }
       
   182     }
       
   183 
       
   184     mUrlLabel->setText( tempStation.url() );
       
   185 
       
   186     mFrequency = tempStation.frequency();
       
   187 
       
   188     updateFavoriteIcon( tempStation.isFavorite() );
       
   189 }
       
   190 
       
   191 /*!
       
   192  *
       
   193  */
       
   194 void RadioStationItem::setFrequency( uint frequency )
       
   195 {
       
   196     LOG_FORMAT( "RadioStationItem::setFrequency: %u", frequency );
       
   197     mNameLabel->setTextWithoutFading( RadioUiEngine::parseFrequency( frequency ) );
       
   198     mGenreLabel->setTextWithoutFading( "" );
       
   199     mRadiotextLabel->setTextWithoutFading( carousel()->isAntennaAttached() ? "" : hbTrId( CONNECT_HEADSET_TEXT ) );
       
   200     mUrlLabel->setTextWithoutFading( "" );
       
   201     mFrequency = frequency;
       
   202     updateFavoriteIcon( false );
       
   203 }
       
   204 
       
   205 /*!
       
   206  *
       
   207  */
       
   208 void RadioStationItem::setSeekingText()
       
   209 {
       
   210     mNameLabel->setTextWithoutFading( hbTrId( SEEKING_TEXT ) );
       
   211     mGenreLabel->setTextWithoutFading( "" );
       
   212     mUrlLabel->setTextWithoutFading( "" );
       
   213     mRadiotextLabel->setTextWithoutFading( "" );
       
   214 }
       
   215 
       
   216 /*!
       
   217  *
       
   218  */
       
   219 void RadioStationItem::updateFavoriteIcon( bool isFavorite )
       
   220 {
       
   221     mIconButton->setIcon( isFavorite ? mCarousel.favoriteIcon() : mCarousel.nonFavoriteIcon() );
       
   222 }
       
   223 
       
   224 /*!
       
   225  *
       
   226  */
       
   227 RadioStationCarousel* RadioStationItem::carousel()
       
   228 {
       
   229     return static_cast<RadioStationCarousel*>( itemView() );
       
   230 }
       
   231