radioapp/radiowidgets/src/radiocarouselitem.cpp
author hgs
Fri, 23 Jul 2010 10:16:59 +0300
changeset 38 f8c3d4e6102c
parent 36 ba22309243a1
child 51 bbebb0235466
permissions -rw-r--r--
201029
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
28
075425b8d9a4 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     1
/*
075425b8d9a4 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     2
* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
075425b8d9a4 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     3
* All rights reserved.
075425b8d9a4 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     4
* This component and the accompanying materials are made available
075425b8d9a4 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     5
* under the terms of "Eclipse Public License v1.0"
075425b8d9a4 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     6
* which accompanies this distribution, and is available
075425b8d9a4 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
075425b8d9a4 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     8
*
075425b8d9a4 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     9
* Initial Contributors:
075425b8d9a4 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    10
* Nokia Corporation - initial contribution.
075425b8d9a4 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    11
*
075425b8d9a4 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    12
* Contributors:
075425b8d9a4 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    13
*
075425b8d9a4 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    14
* Description:
075425b8d9a4 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    15
*
075425b8d9a4 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    16
*/
075425b8d9a4 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    17
075425b8d9a4 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    18
// System includes
075425b8d9a4 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    19
#include <HbStyleLoader>
34
hgs
parents: 28
diff changeset
    20
#include <HbTextItem>
hgs
parents: 28
diff changeset
    21
#include <HbRichTextItem>
hgs
parents: 28
diff changeset
    22
#include <HbIconItem>
hgs
parents: 28
diff changeset
    23
#include <HbTouchArea>
hgs
parents: 28
diff changeset
    24
#include <HbTapGesture>
hgs
parents: 28
diff changeset
    25
#include <QPainter>
28
075425b8d9a4 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    26
075425b8d9a4 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    27
// User includes
075425b8d9a4 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    28
#include "radiocarouselitem.h"
34
hgs
parents: 28
diff changeset
    29
#include "radiocarouselitemobserver.h"
28
075425b8d9a4 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    30
#include "radiostation.h"
075425b8d9a4 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    31
#include "radiologger.h"
075425b8d9a4 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    32
34
hgs
parents: 28
diff changeset
    33
const QLatin1String FILE_PATH_WIDGETML   ( ":/layout/radiocarouselitem.widgetml" );
hgs
parents: 28
diff changeset
    34
const QLatin1String FILE_PATH_CSS        ( ":/layout/radiocarouselitem.css" );
hgs
parents: 28
diff changeset
    35
const QLatin1String ICON_BUTTON          ( "star_button" );
hgs
parents: 28
diff changeset
    36
const QLatin1String GENRE_LABEL          ( "genre_label" );
hgs
parents: 28
diff changeset
    37
const QLatin1String FAVORITE_TOUCH_AREA  ( "favorite_touch_area" );
hgs
parents: 28
diff changeset
    38
const QLatin1String NAME_LABEL           ( "name_label" );
hgs
parents: 28
diff changeset
    39
const QLatin1String RT_LABEL             ( "rt_label" );
hgs
parents: 28
diff changeset
    40
const QLatin1String URL_LABEL            ( "url_label" );
28
075425b8d9a4 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    41
34
hgs
parents: 28
diff changeset
    42
const QLatin1String SEEKING_TEXT        ( "txt_rad_list_tuning" );
hgs
parents: 28
diff changeset
    43
const QLatin1String CONNECT_HEADSET_TEXT( "txt_rad_list_connect_wireless_antenna_headset_with" );
28
075425b8d9a4 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    44
075425b8d9a4 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    45
/*!
075425b8d9a4 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    46
 *
075425b8d9a4 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    47
 */
34
hgs
parents: 28
diff changeset
    48
static void registerAndCheck( const QString& file ) {
hgs
parents: 28
diff changeset
    49
    bool registered = HbStyleLoader::registerFilePath( file );
hgs
parents: 28
diff changeset
    50
    Q_ASSERT_X( registered, "RadioCarouselItem", "Failed to register CSS or WIDGETML!" );
hgs
parents: 28
diff changeset
    51
}
28
075425b8d9a4 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    52
34
hgs
parents: 28
diff changeset
    53
/*!
hgs
parents: 28
diff changeset
    54
 *
hgs
parents: 28
diff changeset
    55
 */
hgs
parents: 28
diff changeset
    56
RadioCarouselItem::RadioCarouselItem( RadioCarouselItemObserver& observer, QGraphicsItem* parent, bool registerCss ) :
hgs
parents: 28
diff changeset
    57
    HbWidget( parent ),
hgs
parents: 28
diff changeset
    58
    mObserver( observer ),
hgs
parents: 28
diff changeset
    59
    mFavoriteItem( NULL ),
hgs
parents: 28
diff changeset
    60
    mGenreItem( NULL ),
hgs
parents: 28
diff changeset
    61
    mFavoriteTouchArea( NULL ),
hgs
parents: 28
diff changeset
    62
    mNameItem( NULL ),
hgs
parents: 28
diff changeset
    63
    mRadiotextItem( NULL ),
hgs
parents: 28
diff changeset
    64
    mUrlItem( NULL ),
hgs
parents: 28
diff changeset
    65
    mAppearance( Default ),
hgs
parents: 28
diff changeset
    66
    mOwnsCss( registerCss ),
38
hgs
parents: 36
diff changeset
    67
    mLandscapeMode( false ),
34
hgs
parents: 28
diff changeset
    68
    mFlags( DefaultFlags )
hgs
parents: 28
diff changeset
    69
{
hgs
parents: 28
diff changeset
    70
    mStation.reset( new RadioStation() );
28
075425b8d9a4 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    71
34
hgs
parents: 28
diff changeset
    72
    if ( mOwnsCss ) {
hgs
parents: 28
diff changeset
    73
        registerAndCheck( FILE_PATH_CSS );
hgs
parents: 28
diff changeset
    74
        registerAndCheck( FILE_PATH_WIDGETML );
hgs
parents: 28
diff changeset
    75
    }
28
075425b8d9a4 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    76
34
hgs
parents: 28
diff changeset
    77
    createPrimitives();
hgs
parents: 28
diff changeset
    78
    updatePrimitives();
28
075425b8d9a4 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    79
34
hgs
parents: 28
diff changeset
    80
    updateFavoriteIcon( false );
28
075425b8d9a4 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    81
34
hgs
parents: 28
diff changeset
    82
    updateVisibilities();
hgs
parents: 28
diff changeset
    83
hgs
parents: 28
diff changeset
    84
    grabGesture( Qt::TapGesture );
28
075425b8d9a4 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    85
}
075425b8d9a4 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    86
075425b8d9a4 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    87
/*!
075425b8d9a4 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    88
 *
075425b8d9a4 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    89
 */
075425b8d9a4 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    90
RadioCarouselItem::~RadioCarouselItem()
075425b8d9a4 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    91
{
34
hgs
parents: 28
diff changeset
    92
    if ( mOwnsCss ) {
hgs
parents: 28
diff changeset
    93
        HbStyleLoader::unregisterFilePath( FILE_PATH_CSS );
hgs
parents: 28
diff changeset
    94
        HbStyleLoader::unregisterFilePath( FILE_PATH_WIDGETML );
hgs
parents: 28
diff changeset
    95
    }
hgs
parents: 28
diff changeset
    96
}
hgs
parents: 28
diff changeset
    97
hgs
parents: 28
diff changeset
    98
/*!
hgs
parents: 28
diff changeset
    99
 *
hgs
parents: 28
diff changeset
   100
 */
hgs
parents: 28
diff changeset
   101
void RadioCarouselItem::createPrimitives()
hgs
parents: 28
diff changeset
   102
{
hgs
parents: 28
diff changeset
   103
    mFavoriteItem = new HbIconItem( this );
hgs
parents: 28
diff changeset
   104
    HbStyle::setItemName( mFavoriteItem, ICON_BUTTON );
hgs
parents: 28
diff changeset
   105
hgs
parents: 28
diff changeset
   106
    mGenreItem = new HbTextItem( this );
hgs
parents: 28
diff changeset
   107
    HbStyle::setItemName( mGenreItem, GENRE_LABEL );
hgs
parents: 28
diff changeset
   108
hgs
parents: 28
diff changeset
   109
    mNameItem = new HbTextItem( this );
hgs
parents: 28
diff changeset
   110
    HbStyle::setItemName( mNameItem, NAME_LABEL );
hgs
parents: 28
diff changeset
   111
hgs
parents: 28
diff changeset
   112
    mRadiotextItem = new HbRichTextItem( this );
hgs
parents: 28
diff changeset
   113
    HbStyle::setItemName( mRadiotextItem, RT_LABEL );
hgs
parents: 28
diff changeset
   114
hgs
parents: 28
diff changeset
   115
    mUrlItem = new HbTextItem( this );
hgs
parents: 28
diff changeset
   116
    HbStyle::setItemName( mUrlItem, URL_LABEL );
hgs
parents: 28
diff changeset
   117
hgs
parents: 28
diff changeset
   118
    mFavoriteTouchArea = new HbTouchArea( this );
hgs
parents: 28
diff changeset
   119
    HbStyle::setItemName( mFavoriteTouchArea, FAVORITE_TOUCH_AREA );
hgs
parents: 28
diff changeset
   120
hgs
parents: 28
diff changeset
   121
    // Matti testing needs these
hgs
parents: 28
diff changeset
   122
    mFavoriteItem->setObjectName( ICON_BUTTON );
hgs
parents: 28
diff changeset
   123
    mGenreItem->setObjectName( GENRE_LABEL );
hgs
parents: 28
diff changeset
   124
    mNameItem->setObjectName( NAME_LABEL );
hgs
parents: 28
diff changeset
   125
    mRadiotextItem->setObjectName( RT_LABEL );
hgs
parents: 28
diff changeset
   126
    mUrlItem->setObjectName( URL_LABEL );
hgs
parents: 28
diff changeset
   127
    mFavoriteTouchArea->setObjectName( FAVORITE_TOUCH_AREA );
hgs
parents: 28
diff changeset
   128
}
hgs
parents: 28
diff changeset
   129
hgs
parents: 28
diff changeset
   130
/*!
hgs
parents: 28
diff changeset
   131
 *
hgs
parents: 28
diff changeset
   132
 */
hgs
parents: 28
diff changeset
   133
void RadioCarouselItem::drawOffScreen( QPainter& painter )
hgs
parents: 28
diff changeset
   134
{
hgs
parents: 28
diff changeset
   135
    QStyleOptionGraphicsItem option;
hgs
parents: 28
diff changeset
   136
hgs
parents: 28
diff changeset
   137
    foreach ( QGraphicsItem* child, childItems() ) {
hgs
parents: 28
diff changeset
   138
        QGraphicsWidget* childWidget = static_cast<QGraphicsWidget*>( child );
hgs
parents: 28
diff changeset
   139
        option.exposedRect = childWidget->rect();
hgs
parents: 28
diff changeset
   140
        painter.save();
hgs
parents: 28
diff changeset
   141
        painter.translate( childWidget->pos() );
hgs
parents: 28
diff changeset
   142
        childWidget->paint( &painter, &option, NULL );
hgs
parents: 28
diff changeset
   143
        painter.restore();
hgs
parents: 28
diff changeset
   144
    }
hgs
parents: 28
diff changeset
   145
}
hgs
parents: 28
diff changeset
   146
hgs
parents: 28
diff changeset
   147
/*!
hgs
parents: 28
diff changeset
   148
 *
hgs
parents: 28
diff changeset
   149
 */
hgs
parents: 28
diff changeset
   150
void RadioCarouselItem::updatePrimitives()
hgs
parents: 28
diff changeset
   151
{
hgs
parents: 28
diff changeset
   152
    update();
hgs
parents: 28
diff changeset
   153
}
hgs
parents: 28
diff changeset
   154
hgs
parents: 28
diff changeset
   155
/*!
hgs
parents: 28
diff changeset
   156
 * \reimp
hgs
parents: 28
diff changeset
   157
 */
hgs
parents: 28
diff changeset
   158
void RadioCarouselItem::gestureEvent( QGestureEvent* event )
hgs
parents: 28
diff changeset
   159
{
hgs
parents: 28
diff changeset
   160
    if ( HbTapGesture* gesture = qobject_cast<HbTapGesture*>( event->gesture( Qt::TapGesture ) ) ) {
hgs
parents: 28
diff changeset
   161
        if ( gesture->state() == Qt::GestureFinished ) {
hgs
parents: 28
diff changeset
   162
            const QPointF mappedHotSpot = event->mapToGraphicsScene( gesture->hotSpot() );
hgs
parents: 28
diff changeset
   163
hgs
parents: 28
diff changeset
   164
            if ( mFlags.testFlag( FavoriteTouchable ) &&
hgs
parents: 28
diff changeset
   165
                    mFavoriteTouchArea->sceneBoundingRect().contains( mappedHotSpot ) ) {
hgs
parents: 28
diff changeset
   166
hgs
parents: 28
diff changeset
   167
                mObserver.handleIconClicked( *mStation );
hgs
parents: 28
diff changeset
   168
hgs
parents: 28
diff changeset
   169
            } else if ( mFlags.testFlag( RadiotextTouchable ) &&
hgs
parents: 28
diff changeset
   170
                    mRadiotextItem->sceneBoundingRect().contains( mappedHotSpot ) ) {
hgs
parents: 28
diff changeset
   171
hgs
parents: 28
diff changeset
   172
                mObserver.handleRadiotextClicked( *mStation );
hgs
parents: 28
diff changeset
   173
hgs
parents: 28
diff changeset
   174
            } else if ( mFlags.testFlag( UrlTouchable ) &&
hgs
parents: 28
diff changeset
   175
                    mUrlItem->sceneBoundingRect().contains( mappedHotSpot ) ) {
hgs
parents: 28
diff changeset
   176
hgs
parents: 28
diff changeset
   177
                mObserver.handleUrlClicked( *mStation );
hgs
parents: 28
diff changeset
   178
hgs
parents: 28
diff changeset
   179
            }
hgs
parents: 28
diff changeset
   180
        }
hgs
parents: 28
diff changeset
   181
    }
hgs
parents: 28
diff changeset
   182
}
hgs
parents: 28
diff changeset
   183
hgs
parents: 28
diff changeset
   184
/*!
hgs
parents: 28
diff changeset
   185
 *
hgs
parents: 28
diff changeset
   186
 */
hgs
parents: 28
diff changeset
   187
void RadioCarouselItem::setFlags( CarouselItemFlags flags )
hgs
parents: 28
diff changeset
   188
{
hgs
parents: 28
diff changeset
   189
    mFlags |= flags;
hgs
parents: 28
diff changeset
   190
    updateVisibilities();
hgs
parents: 28
diff changeset
   191
}
hgs
parents: 28
diff changeset
   192
hgs
parents: 28
diff changeset
   193
/*!
hgs
parents: 28
diff changeset
   194
 *
hgs
parents: 28
diff changeset
   195
 */
hgs
parents: 28
diff changeset
   196
void RadioCarouselItem::clearFlags( CarouselItemFlags flags )
hgs
parents: 28
diff changeset
   197
{
hgs
parents: 28
diff changeset
   198
    for ( int i = 1; i < LastFlagMarker; i = i << 1 ) {
hgs
parents: 28
diff changeset
   199
        if ( flags.testFlag( static_cast<ItemFlag>( i ) ) ) {
hgs
parents: 28
diff changeset
   200
            mFlags &= ~i;
hgs
parents: 28
diff changeset
   201
        }
hgs
parents: 28
diff changeset
   202
    }
hgs
parents: 28
diff changeset
   203
    updateVisibilities();
hgs
parents: 28
diff changeset
   204
}
hgs
parents: 28
diff changeset
   205
hgs
parents: 28
diff changeset
   206
/*!
hgs
parents: 28
diff changeset
   207
 *
hgs
parents: 28
diff changeset
   208
 */
hgs
parents: 28
diff changeset
   209
void RadioCarouselItem::updateVisibilities()
hgs
parents: 28
diff changeset
   210
{
hgs
parents: 28
diff changeset
   211
    mFavoriteItem->setVisible( mFlags.testFlag( FavoriteVisible ) );
hgs
parents: 28
diff changeset
   212
    mGenreItem->setVisible( mFlags.testFlag( GenreVisible ) );
hgs
parents: 28
diff changeset
   213
    mRadiotextItem->setVisible( mFlags.testFlag( RadiotextVisible ) );
hgs
parents: 28
diff changeset
   214
    mUrlItem->setVisible( mFlags.testFlag( UrlVisible ) );
hgs
parents: 28
diff changeset
   215
}
hgs
parents: 28
diff changeset
   216
hgs
parents: 28
diff changeset
   217
/*!
hgs
parents: 28
diff changeset
   218
 *
hgs
parents: 28
diff changeset
   219
 */
hgs
parents: 28
diff changeset
   220
void RadioCarouselItem::setAppearance( Appearance appearance )
hgs
parents: 28
diff changeset
   221
{
hgs
parents: 28
diff changeset
   222
    mAppearance = appearance;
hgs
parents: 28
diff changeset
   223
hgs
parents: 28
diff changeset
   224
    if ( mAppearance == ManualSeek ) {
hgs
parents: 28
diff changeset
   225
        mFlags = ManualSeekFlags;
hgs
parents: 28
diff changeset
   226
        mGenreItem->setText( "" );
hgs
parents: 28
diff changeset
   227
        mRadiotextItem->setText( "" );
hgs
parents: 28
diff changeset
   228
        mUrlItem->setText( "" );
hgs
parents: 28
diff changeset
   229
        mNameItem->setText( mStation->frequencyString() );
hgs
parents: 28
diff changeset
   230
        updateFavoriteIcon( false );
hgs
parents: 28
diff changeset
   231
    } else {
hgs
parents: 28
diff changeset
   232
        mFlags = DefaultFlags;
hgs
parents: 28
diff changeset
   233
    }
hgs
parents: 28
diff changeset
   234
hgs
parents: 28
diff changeset
   235
    updateVisibilities();
hgs
parents: 28
diff changeset
   236
hgs
parents: 28
diff changeset
   237
    repolish();
hgs
parents: 28
diff changeset
   238
}
hgs
parents: 28
diff changeset
   239
hgs
parents: 28
diff changeset
   240
/*!
hgs
parents: 28
diff changeset
   241
 *
hgs
parents: 28
diff changeset
   242
 */
hgs
parents: 28
diff changeset
   243
RadioCarouselItem::Appearance RadioCarouselItem::appearance() const
hgs
parents: 28
diff changeset
   244
{
hgs
parents: 28
diff changeset
   245
    return mAppearance;
hgs
parents: 28
diff changeset
   246
}
hgs
parents: 28
diff changeset
   247
hgs
parents: 28
diff changeset
   248
/*!
hgs
parents: 28
diff changeset
   249
 *
hgs
parents: 28
diff changeset
   250
 */
38
hgs
parents: 36
diff changeset
   251
void RadioCarouselItem::setLandscape( bool landscape )
hgs
parents: 36
diff changeset
   252
{
hgs
parents: 36
diff changeset
   253
    mLandscapeMode = landscape;
hgs
parents: 36
diff changeset
   254
}
hgs
parents: 36
diff changeset
   255
hgs
parents: 36
diff changeset
   256
/*!
hgs
parents: 36
diff changeset
   257
 *
hgs
parents: 36
diff changeset
   258
 */
hgs
parents: 36
diff changeset
   259
bool RadioCarouselItem::landscape() const
hgs
parents: 36
diff changeset
   260
{
hgs
parents: 36
diff changeset
   261
    return mLandscapeMode;
hgs
parents: 36
diff changeset
   262
}
hgs
parents: 36
diff changeset
   263
hgs
parents: 36
diff changeset
   264
/*!
hgs
parents: 36
diff changeset
   265
 *
hgs
parents: 36
diff changeset
   266
 */
34
hgs
parents: 28
diff changeset
   267
void RadioCarouselItem::setSeekLayout( bool seekLayout )
hgs
parents: 28
diff changeset
   268
{
hgs
parents: 28
diff changeset
   269
    if ( seekLayout ) {
hgs
parents: 28
diff changeset
   270
        setAppearance( ManualSeek );
hgs
parents: 28
diff changeset
   271
    } else {
hgs
parents: 28
diff changeset
   272
        setAppearance( mStation->radioText().isEmpty() ? Default : Full );
hgs
parents: 28
diff changeset
   273
    }
28
075425b8d9a4 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   274
}
075425b8d9a4 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   275
075425b8d9a4 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   276
/*!
075425b8d9a4 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   277
 *
075425b8d9a4 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   278
 */
075425b8d9a4 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   279
void RadioCarouselItem::setStation( const RadioStation& station )
075425b8d9a4 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   280
{
34
hgs
parents: 28
diff changeset
   281
    *mStation = station;
28
075425b8d9a4 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   282
34
hgs
parents: 28
diff changeset
   283
    updateLayout();
28
075425b8d9a4 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   284
34
hgs
parents: 28
diff changeset
   285
    update();
28
075425b8d9a4 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   286
}
075425b8d9a4 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   287
075425b8d9a4 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   288
/*!
075425b8d9a4 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   289
 *
075425b8d9a4 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   290
 */
075425b8d9a4 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   291
uint RadioCarouselItem::frequency() const
075425b8d9a4 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   292
{
34
hgs
parents: 28
diff changeset
   293
    return mStation->frequency();
28
075425b8d9a4 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   294
}
075425b8d9a4 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   295
075425b8d9a4 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   296
/*!
075425b8d9a4 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   297
 *
075425b8d9a4 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   298
 */
075425b8d9a4 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   299
void RadioCarouselItem::update( const RadioStation* station )
075425b8d9a4 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   300
{
075425b8d9a4 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   301
    if ( station ) {
34
hgs
parents: 28
diff changeset
   302
        *mStation = *station;
hgs
parents: 28
diff changeset
   303
        updateLayout();
28
075425b8d9a4 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   304
    }
075425b8d9a4 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   305
34
hgs
parents: 28
diff changeset
   306
    if ( mStation->isValid() ) {
hgs
parents: 28
diff changeset
   307
        mGenreItem->setText( mObserver.localizeGenre( mStation->genre() ) );
28
075425b8d9a4 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   308
34
hgs
parents: 28
diff changeset
   309
        const bool hasName = mStation->hasName();
hgs
parents: 28
diff changeset
   310
        if ( hasName ) {
hgs
parents: 28
diff changeset
   311
            mNameItem->setText( mStation->name() );
28
075425b8d9a4 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   312
        } else {
34
hgs
parents: 28
diff changeset
   313
            mNameItem->setText( mStation->frequencyString() );
28
075425b8d9a4 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   314
        }
075425b8d9a4 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   315
34
hgs
parents: 28
diff changeset
   316
        if ( mStation->hasRadiotext() ) {
hgs
parents: 28
diff changeset
   317
            mRadiotextItem->setText( mStation->radioText() );
hgs
parents: 28
diff changeset
   318
        } else {
hgs
parents: 28
diff changeset
   319
            if ( mStation->hasDynamicPs() ) {
hgs
parents: 28
diff changeset
   320
                mRadiotextItem->setText( mStation->dynamicPsText() );
hgs
parents: 28
diff changeset
   321
            } else if ( hasName ) {
hgs
parents: 28
diff changeset
   322
                const QString loc = "%L1 Mhz"; //hbTrId( "txt_rad_list_l1_mhz_small" );
hgs
parents: 28
diff changeset
   323
                mRadiotextItem->setText( loc.arg( mStation->frequencyString() ) );
hgs
parents: 28
diff changeset
   324
            } else {
hgs
parents: 28
diff changeset
   325
                mRadiotextItem->setText( "" );
hgs
parents: 28
diff changeset
   326
            }
hgs
parents: 28
diff changeset
   327
        }
28
075425b8d9a4 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   328
34
hgs
parents: 28
diff changeset
   329
        mUrlItem->setText( mStation->url() );
hgs
parents: 28
diff changeset
   330
        if ( mStation->hasUrl() ) {
hgs
parents: 28
diff changeset
   331
            HbStyle::setItemName( mUrlItem, URL_LABEL );
hgs
parents: 28
diff changeset
   332
            setFlags( UrlVisible | UrlTouchable );
hgs
parents: 28
diff changeset
   333
        } else {
hgs
parents: 28
diff changeset
   334
            HbStyle::setItemName( mUrlItem, "" ); // Clear the name so the item disappears from layout
hgs
parents: 28
diff changeset
   335
            clearFlags( UrlVisible | UrlTouchable );
hgs
parents: 28
diff changeset
   336
        }
hgs
parents: 28
diff changeset
   337
hgs
parents: 28
diff changeset
   338
        updateFavoriteIcon( mStation->isFavorite() );
28
075425b8d9a4 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   339
    } else {
075425b8d9a4 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   340
        cleanRdsData();
075425b8d9a4 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   341
    }
075425b8d9a4 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   342
}
075425b8d9a4 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   343
075425b8d9a4 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   344
/*!
075425b8d9a4 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   345
 *
075425b8d9a4 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   346
 */
075425b8d9a4 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   347
void RadioCarouselItem::setFrequency( uint frequency )
075425b8d9a4 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   348
{
34
hgs
parents: 28
diff changeset
   349
    LOG_FORMAT( "RadioCarouselItem::setFrequency: %d", frequency );
28
075425b8d9a4 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   350
34
hgs
parents: 28
diff changeset
   351
    mNameItem->setText( RadioStation::parseFrequency( frequency ) );
hgs
parents: 28
diff changeset
   352
hgs
parents: 28
diff changeset
   353
    if ( !mObserver.isInManualSeek() ) {
hgs
parents: 28
diff changeset
   354
        *mStation = mObserver.findStation( frequency );
28
075425b8d9a4 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   355
    }
075425b8d9a4 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   356
}
075425b8d9a4 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   357
075425b8d9a4 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   358
/*!
075425b8d9a4 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   359
 *
075425b8d9a4 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   360
 */
075425b8d9a4 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   361
void RadioCarouselItem::cleanRdsData()
075425b8d9a4 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   362
{
34
hgs
parents: 28
diff changeset
   363
    mGenreItem->setText( "" );
hgs
parents: 28
diff changeset
   364
    mRadiotextItem->setText( "" );
hgs
parents: 28
diff changeset
   365
    mUrlItem->setText( "" );
28
075425b8d9a4 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   366
}
075425b8d9a4 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   367
075425b8d9a4 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   368
/*!
075425b8d9a4 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   369
 *
075425b8d9a4 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   370
 */
075425b8d9a4 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   371
void RadioCarouselItem::setRadioText( const QString& text )
075425b8d9a4 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   372
{
34
hgs
parents: 28
diff changeset
   373
    mRadiotextItem->setText( text );
28
075425b8d9a4 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   374
}
075425b8d9a4 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   375
075425b8d9a4 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   376
/*!
075425b8d9a4 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   377
 *
075425b8d9a4 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   378
 */
075425b8d9a4 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   379
void RadioCarouselItem::setItemVisibility( ItemVisibility visibility )
075425b8d9a4 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   380
{
34
hgs
parents: 28
diff changeset
   381
    CarouselItemFlags flags = 0;
28
075425b8d9a4 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   382
    if ( visibility == AllVisible ) {
34
hgs
parents: 28
diff changeset
   383
        flags = DefaultFlags;
28
075425b8d9a4 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   384
    } else if ( visibility == AllHidden ) {
34
hgs
parents: 28
diff changeset
   385
28
075425b8d9a4 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   386
    } else if ( visibility == IconVisible ) {
34
hgs
parents: 28
diff changeset
   387
        flags = FavoriteVisible;
28
075425b8d9a4 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   388
    }
34
hgs
parents: 28
diff changeset
   389
hgs
parents: 28
diff changeset
   390
    setFlags( flags );
28
075425b8d9a4 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   391
}
075425b8d9a4 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   392
075425b8d9a4 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   393
/*!
075425b8d9a4 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   394
 *
075425b8d9a4 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   395
 */
075425b8d9a4 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   396
void RadioCarouselItem::setIconOpacity( qreal opacity )
075425b8d9a4 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   397
{
34
hgs
parents: 28
diff changeset
   398
    mFavoriteItem->setOpacity( opacity );
28
075425b8d9a4 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   399
}
075425b8d9a4 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   400
075425b8d9a4 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   401
/*!
075425b8d9a4 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   402
 *
075425b8d9a4 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   403
 */
075425b8d9a4 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   404
void RadioCarouselItem::updateFavoriteIcon( bool isFavorite )
075425b8d9a4 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   405
{
34
hgs
parents: 28
diff changeset
   406
    if ( isFavorite ) {
hgs
parents: 28
diff changeset
   407
        mFavoriteItem->setIcon( mObserver.favoriteIcon() );
28
075425b8d9a4 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   408
    } else {
34
hgs
parents: 28
diff changeset
   409
        mFavoriteItem->setIcon( mObserver.nonFavoriteIcon() );
28
075425b8d9a4 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   410
    }
075425b8d9a4 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   411
}
075425b8d9a4 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   412
075425b8d9a4 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   413
/*!
075425b8d9a4 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   414
 *
075425b8d9a4 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   415
 */
34
hgs
parents: 28
diff changeset
   416
void RadioCarouselItem::updateLayout()
28
075425b8d9a4 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   417
{
36
hgs
parents: 34
diff changeset
   418
    setAppearance( mStation->hasSentRds() ? Full : Default );
28
075425b8d9a4 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   419
}