radioapp/radiowidgets/src/radiofrequencystripbase.cpp
author hgs
Fri, 15 Oct 2010 16:26:27 +0300
changeset 57 21be958eb3ce
parent 54 a8ba0c289b44
permissions -rw-r--r--
201041
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
39
hgs
parents:
diff changeset
     1
/*
57
hgs
parents: 54
diff changeset
     2
 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
hgs
parents: 54
diff changeset
     3
 * All rights reserved.
hgs
parents: 54
diff changeset
     4
 * This component and the accompanying materials are made available
hgs
parents: 54
diff changeset
     5
 * under the terms of "Eclipse Public License v1.0"
hgs
parents: 54
diff changeset
     6
 * which accompanies this distribution, and is available
hgs
parents: 54
diff changeset
     7
 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
hgs
parents: 54
diff changeset
     8
 *
hgs
parents: 54
diff changeset
     9
 * Initial Contributors:
hgs
parents: 54
diff changeset
    10
 * Nokia Corporation - initial contribution.
hgs
parents: 54
diff changeset
    11
 *
hgs
parents: 54
diff changeset
    12
 * Contributors:
hgs
parents: 54
diff changeset
    13
 *
hgs
parents: 54
diff changeset
    14
 * Description:
hgs
parents: 54
diff changeset
    15
 *
hgs
parents: 54
diff changeset
    16
 */
39
hgs
parents:
diff changeset
    17
hgs
parents:
diff changeset
    18
// System includes
hgs
parents:
diff changeset
    19
#include <HbDocumentLoader>
hgs
parents:
diff changeset
    20
#include <HbEffect>
hgs
parents:
diff changeset
    21
#include <QPainter>
hgs
parents:
diff changeset
    22
#include <QStringListModel>
hgs
parents:
diff changeset
    23
#include <QGraphicsSceneResizeEvent>
hgs
parents:
diff changeset
    24
#include <QPen>
hgs
parents:
diff changeset
    25
#include <HbPushButton>
hgs
parents:
diff changeset
    26
#include <QTimer>
hgs
parents:
diff changeset
    27
#include <HbColorScheme>
hgs
parents:
diff changeset
    28
#include <HbEvent>
hgs
parents:
diff changeset
    29
#include <HbSwipeGesture>
hgs
parents:
diff changeset
    30
#include <HbDeviceProfile>
hgs
parents:
diff changeset
    31
#include <QDebug>
hgs
parents:
diff changeset
    32
hgs
parents:
diff changeset
    33
// User includes
hgs
parents:
diff changeset
    34
#include "radiofrequencystripbase.h"
hgs
parents:
diff changeset
    35
#include "radiofrequencystripdef.h"
hgs
parents:
diff changeset
    36
#include "radiofrequencyitem.h"
hgs
parents:
diff changeset
    37
hgs
parents:
diff changeset
    38
/*!
hgs
parents:
diff changeset
    39
 * Convenience function to check signal-slot connections
hgs
parents:
diff changeset
    40
 */
hgs
parents:
diff changeset
    41
//#define CHECK_SIGNAL_CONNECTIONS
hgs
parents:
diff changeset
    42
static bool connectAndCheck( const QObject* sender, const char* signal,
hgs
parents:
diff changeset
    43
                             const QObject* receiver, const char* member,
hgs
parents:
diff changeset
    44
                             Qt::ConnectionType type = Qt::AutoConnection )
hgs
parents:
diff changeset
    45
{
hgs
parents:
diff changeset
    46
    bool connected = QObject::connect( sender, signal, receiver, member, type );
hgs
parents:
diff changeset
    47
hgs
parents:
diff changeset
    48
    #ifdef CHECK_SIGNAL_CONNECTIONS
hgs
parents:
diff changeset
    49
hgs
parents:
diff changeset
    50
    if ( !connected ) {
hgs
parents:
diff changeset
    51
        qDebug() << "Failed to make a signal-slot connection!";
hgs
parents:
diff changeset
    52
        qDebug() << "sender: " << sender->metaObject()->className();
hgs
parents:
diff changeset
    53
        qDebug() << "signal: " << signal;
hgs
parents:
diff changeset
    54
        qDebug() << "receiver: " << receiver->metaObject()->className();
hgs
parents:
diff changeset
    55
        qDebug() << "slot/signal: " << signal;
hgs
parents:
diff changeset
    56
hgs
parents:
diff changeset
    57
        Q_ASSERT( false );
hgs
parents:
diff changeset
    58
hgs
parents:
diff changeset
    59
        // ----------------------------------------------------------------
hgs
parents:
diff changeset
    60
        // SIGNAL-SLOT CONNECT FAILED!
hgs
parents:
diff changeset
    61
        // ----------------------------------------------------------------
hgs
parents:
diff changeset
    62
    }
hgs
parents:
diff changeset
    63
hgs
parents:
diff changeset
    64
    #endif // CHECK_SIGNAL_CONNECTIONS
hgs
parents:
diff changeset
    65
hgs
parents:
diff changeset
    66
    return connected;
hgs
parents:
diff changeset
    67
}
hgs
parents:
diff changeset
    68
hgs
parents:
diff changeset
    69
/*!
hgs
parents:
diff changeset
    70
 *
hgs
parents:
diff changeset
    71
 */
hgs
parents:
diff changeset
    72
RadioFrequencyStripBase::RadioFrequencyStripBase( QGraphicsItem* parent ) :
hgs
parents:
diff changeset
    73
    RadioStripBase( parent ),
57
hgs
parents: 54
diff changeset
    74
    mItemHeight( FrequencyStrip::DEFAULT_ITEM_HEIGHT_UNITS ),
hgs
parents: 54
diff changeset
    75
    mMinFrequency( FrequencyStrip::DEFAULT_MIN_FREQUENCY ),
hgs
parents: 54
diff changeset
    76
    mMaxFrequency( FrequencyStrip::DEFAULT_MAX_FREQUENCY ),
hgs
parents: 54
diff changeset
    77
    mFrequencyStepSize( FrequencyStrip::DEFAULT_FREQUENCY_STEP ),
hgs
parents: 54
diff changeset
    78
    mFrequency( FrequencyStrip::DEFAULT_MIN_FREQUENCY ),
39
hgs
parents:
diff changeset
    79
    mSelectorImage( new QGraphicsPixmapItem( this ) ),
hgs
parents:
diff changeset
    80
    mSeparatorPos( 0.0 ),
hgs
parents:
diff changeset
    81
    mMaxWidth( 0 ),
hgs
parents:
diff changeset
    82
    mSelectorPos( 0.0 ),
hgs
parents:
diff changeset
    83
    mLeftButton( 0 ),
hgs
parents:
diff changeset
    84
    mRightButton( 0 ),
hgs
parents:
diff changeset
    85
    mManualSeekTimer( NULL ),
hgs
parents:
diff changeset
    86
    mManualSeekMode( false ),
hgs
parents:
diff changeset
    87
    mLastReportedFrequency( 0 ),
hgs
parents:
diff changeset
    88
    mManualSeekTimerId( 0 ),
57
hgs
parents: 54
diff changeset
    89
    mForegroundColor( HbColorScheme::color( FrequencyStrip::TEXT_COLOR_ATTRIBUTE ) ),
54
hgs
parents: 47
diff changeset
    90
    mIgnoreScrollingEnd( false )
39
hgs
parents:
diff changeset
    91
{
hgs
parents:
diff changeset
    92
}
hgs
parents:
diff changeset
    93
hgs
parents:
diff changeset
    94
/*!
57
hgs
parents: 54
diff changeset
    95
 *
hgs
parents: 54
diff changeset
    96
 */
hgs
parents: 54
diff changeset
    97
RadioFrequencyStripBase::~RadioFrequencyStripBase()
hgs
parents: 54
diff changeset
    98
{
hgs
parents: 54
diff changeset
    99
    qDeleteAll( mFrequencyItems );
hgs
parents: 54
diff changeset
   100
}
hgs
parents: 54
diff changeset
   101
hgs
parents: 54
diff changeset
   102
/*!
39
hgs
parents:
diff changeset
   103
 * Property
hgs
parents:
diff changeset
   104
 */
hgs
parents:
diff changeset
   105
void RadioFrequencyStripBase::setItemHeight( int itemHeight )
hgs
parents:
diff changeset
   106
{
hgs
parents:
diff changeset
   107
    mItemHeight = itemHeight;
hgs
parents:
diff changeset
   108
}
hgs
parents:
diff changeset
   109
hgs
parents:
diff changeset
   110
/*!
hgs
parents:
diff changeset
   111
 * Property
hgs
parents:
diff changeset
   112
 */
hgs
parents:
diff changeset
   113
int RadioFrequencyStripBase::itemHeight() const
hgs
parents:
diff changeset
   114
{
hgs
parents:
diff changeset
   115
    return mItemHeight;
hgs
parents:
diff changeset
   116
}
hgs
parents:
diff changeset
   117
hgs
parents:
diff changeset
   118
/*!
hgs
parents:
diff changeset
   119
 *
hgs
parents:
diff changeset
   120
 */
hgs
parents:
diff changeset
   121
void RadioFrequencyStripBase::initbase( uint minFrequency, uint maxFrequency, uint stepSize, uint frequency )
hgs
parents:
diff changeset
   122
{
hgs
parents:
diff changeset
   123
    mMinFrequency       = minFrequency;
hgs
parents:
diff changeset
   124
    mMaxFrequency       = maxFrequency;
hgs
parents:
diff changeset
   125
    mFrequencyStepSize  = stepSize;
hgs
parents:
diff changeset
   126
    mFrequency          = frequency;
hgs
parents:
diff changeset
   127
54
hgs
parents: 47
diff changeset
   128
    setScrollingStyle( HbScrollArea::PanWithFollowOn );
hgs
parents: 47
diff changeset
   129
hgs
parents: 47
diff changeset
   130
    HbDeviceProfile deviceProfile;
hgs
parents: 47
diff changeset
   131
    mItemHeight = static_cast<int>( mItemHeight * deviceProfile.unitValue() );
hgs
parents: 47
diff changeset
   132
    setItemSize( QSizeF( FrequencyStrip::ITEM_WIDTH + FrequencyStrip::PIXMAP_OVERLAP / 2, mItemHeight ) );
hgs
parents: 47
diff changeset
   133
hgs
parents: 47
diff changeset
   134
    setOverlap( FrequencyStrip::PIXMAP_OVERLAP / 2 );
hgs
parents: 47
diff changeset
   135
57
hgs
parents: 54
diff changeset
   136
    mStationIcon.setIconName("qtg_graf_tuner_unselected");
hgs
parents: 54
diff changeset
   137
    mFavoriteIcon.setIconName("qtg_graf_tuner_selected");
hgs
parents: 54
diff changeset
   138
    mStationIcon.setSize( QSizeF( FrequencyStrip::STATION_MARKER_SIZE, FrequencyStrip::STATION_MARKER_SIZE ) );
hgs
parents: 54
diff changeset
   139
    mFavoriteIcon.setSize( QSizeF( FrequencyStrip::STATION_MARKER_SIZE, FrequencyStrip::STATION_MARKER_SIZE ) );
hgs
parents: 54
diff changeset
   140
39
hgs
parents:
diff changeset
   141
    initModel();
hgs
parents:
diff changeset
   142
    initEmptyItems();
hgs
parents:
diff changeset
   143
    initPositions();
hgs
parents:
diff changeset
   144
hgs
parents:
diff changeset
   145
    mManualSeekTimer = new QTimer( this );
hgs
parents:
diff changeset
   146
    mManualSeekTimer->setInterval( FrequencyStrip::MANUALSEEK_START_TIMEOUT );
hgs
parents:
diff changeset
   147
    mManualSeekTimer->setSingleShot( true );
hgs
parents:
diff changeset
   148
    connectAndCheck( mManualSeekTimer,   SIGNAL(timeout()),
hgs
parents:
diff changeset
   149
                     this,               SLOT(toggleManualSeek()) );
hgs
parents:
diff changeset
   150
hgs
parents:
diff changeset
   151
    connectAndCheck( this,           SIGNAL(scrollingEnded()),
hgs
parents:
diff changeset
   152
                     this,           SLOT(handleScrollingEnd()) );
hgs
parents:
diff changeset
   153
hgs
parents:
diff changeset
   154
    grabGesture( Qt::SwipeGesture );
hgs
parents:
diff changeset
   155
hgs
parents:
diff changeset
   156
    //TODO: Remove. Stepsize temporarily hardcoded to 100 Khz in europe region
hgs
parents:
diff changeset
   157
    if ( mFrequencyStepSize < FrequencyStrip::ONE_HUNDRED_KHZ ) {
hgs
parents:
diff changeset
   158
        mFrequencyStepSize = FrequencyStrip::ONE_HUNDRED_KHZ;
hgs
parents:
diff changeset
   159
    }
hgs
parents:
diff changeset
   160
hgs
parents:
diff changeset
   161
    updateAllItems();
hgs
parents:
diff changeset
   162
hgs
parents:
diff changeset
   163
    showButtons();
hgs
parents:
diff changeset
   164
}
hgs
parents:
diff changeset
   165
hgs
parents:
diff changeset
   166
/*!
hgs
parents:
diff changeset
   167
 *
hgs
parents:
diff changeset
   168
 */
hgs
parents:
diff changeset
   169
void RadioFrequencyStripBase::createButtonsFromDocml( HbDocumentLoader& uiLoader, const QString& leftButtonName, const QString& rightButtonName )
hgs
parents:
diff changeset
   170
{
hgs
parents:
diff changeset
   171
    Q_ASSERT( !mLeftButton && !mRightButton );
hgs
parents:
diff changeset
   172
    mLeftButton = qobject_cast<HbPushButton*>( uiLoader.findWidget( leftButtonName ) );
hgs
parents:
diff changeset
   173
    mRightButton = qobject_cast<HbPushButton*>( uiLoader.findWidget( rightButtonName ) );
hgs
parents:
diff changeset
   174
hgs
parents:
diff changeset
   175
    initButtons();
hgs
parents:
diff changeset
   176
}
hgs
parents:
diff changeset
   177
hgs
parents:
diff changeset
   178
/*!
hgs
parents:
diff changeset
   179
 *
hgs
parents:
diff changeset
   180
 */
hgs
parents:
diff changeset
   181
void RadioFrequencyStripBase::createButtons()
hgs
parents:
diff changeset
   182
{
hgs
parents:
diff changeset
   183
    Q_ASSERT( !mLeftButton && !mRightButton );
hgs
parents:
diff changeset
   184
    mLeftButton = new HbPushButton( this );
hgs
parents:
diff changeset
   185
    mRightButton = new HbPushButton( this );
hgs
parents:
diff changeset
   186
hgs
parents:
diff changeset
   187
    mLeftButton->setIcon( HbIcon( "qtg_mono_previous" ) );
hgs
parents:
diff changeset
   188
    mRightButton->setIcon( HbIcon( "qtg_mono_next" ) );
hgs
parents:
diff changeset
   189
hgs
parents:
diff changeset
   190
    initButtons();
hgs
parents:
diff changeset
   191
}
hgs
parents:
diff changeset
   192
hgs
parents:
diff changeset
   193
/*!
hgs
parents:
diff changeset
   194
 *
hgs
parents:
diff changeset
   195
 */
hgs
parents:
diff changeset
   196
void RadioFrequencyStripBase::setFrequency( const uint frequency, int reason, Scroll::Direction direction )
hgs
parents:
diff changeset
   197
{
47
hgs
parents: 44
diff changeset
   198
    Q_UNUSED( reason );
hgs
parents: 44
diff changeset
   199
39
hgs
parents:
diff changeset
   200
    if ( mFrequencies.contains( frequency ) ) {
hgs
parents:
diff changeset
   201
        scrollToFrequency( frequency, direction, mAutoScrollTime );
hgs
parents:
diff changeset
   202
    }
hgs
parents:
diff changeset
   203
}
hgs
parents:
diff changeset
   204
hgs
parents:
diff changeset
   205
/*!
hgs
parents:
diff changeset
   206
 *
hgs
parents:
diff changeset
   207
 */
hgs
parents:
diff changeset
   208
uint RadioFrequencyStripBase::frequency() const
hgs
parents:
diff changeset
   209
{
hgs
parents:
diff changeset
   210
    return mFrequency;
hgs
parents:
diff changeset
   211
}
hgs
parents:
diff changeset
   212
hgs
parents:
diff changeset
   213
/*!
hgs
parents:
diff changeset
   214
 *
hgs
parents:
diff changeset
   215
 */
hgs
parents:
diff changeset
   216
bool RadioFrequencyStripBase::isInManualSeekMode() const
hgs
parents:
diff changeset
   217
{
hgs
parents:
diff changeset
   218
    return mManualSeekMode;
hgs
parents:
diff changeset
   219
}
hgs
parents:
diff changeset
   220
hgs
parents:
diff changeset
   221
/*!
hgs
parents:
diff changeset
   222
 *
hgs
parents:
diff changeset
   223
 */
hgs
parents:
diff changeset
   224
void RadioFrequencyStripBase::cancelManualSeek()
hgs
parents:
diff changeset
   225
{
hgs
parents:
diff changeset
   226
    mManualSeekTimer->stop();
hgs
parents:
diff changeset
   227
    if ( mManualSeekMode ) {
hgs
parents:
diff changeset
   228
        toggleManualSeek();
hgs
parents:
diff changeset
   229
    }
hgs
parents:
diff changeset
   230
}
hgs
parents:
diff changeset
   231
hgs
parents:
diff changeset
   232
/*!
hgs
parents:
diff changeset
   233
 *
hgs
parents:
diff changeset
   234
 */
hgs
parents:
diff changeset
   235
void RadioFrequencyStripBase::addScannedStation( uint frequency )
hgs
parents:
diff changeset
   236
{
hgs
parents:
diff changeset
   237
    FrequencyPos pos = mFrequencies.value( frequency );
hgs
parents:
diff changeset
   238
    updateItem( pos.mItem, frequency );
hgs
parents:
diff changeset
   239
}
hgs
parents:
diff changeset
   240
hgs
parents:
diff changeset
   241
/*!
hgs
parents:
diff changeset
   242
 *
hgs
parents:
diff changeset
   243
 */
hgs
parents:
diff changeset
   244
void RadioFrequencyStripBase::updateFavorite( uint frequency )
hgs
parents:
diff changeset
   245
{
hgs
parents:
diff changeset
   246
    FrequencyPos pos = mFrequencies.value( frequency );
hgs
parents:
diff changeset
   247
    updateItem( pos.mItem );
hgs
parents:
diff changeset
   248
}
hgs
parents:
diff changeset
   249
hgs
parents:
diff changeset
   250
/*!
hgs
parents:
diff changeset
   251
 * Public slot
hgs
parents:
diff changeset
   252
 *
hgs
parents:
diff changeset
   253
 */
hgs
parents:
diff changeset
   254
void RadioFrequencyStripBase::setScanningMode( bool isScanning )
hgs
parents:
diff changeset
   255
{
hgs
parents:
diff changeset
   256
    mManualSeekTimer->stop();
hgs
parents:
diff changeset
   257
    if ( isScanning ) {
hgs
parents:
diff changeset
   258
        initEmptyItems();
hgs
parents:
diff changeset
   259
        hideButtons();
hgs
parents:
diff changeset
   260
        scrollToFrequency( mMinFrequency, Scroll::Shortest, mAutoScrollTime );
hgs
parents:
diff changeset
   261
    } else {
hgs
parents:
diff changeset
   262
        showButtons();
hgs
parents:
diff changeset
   263
    }
hgs
parents:
diff changeset
   264
    setEnabled( !isScanning );
hgs
parents:
diff changeset
   265
}
hgs
parents:
diff changeset
   266
hgs
parents:
diff changeset
   267
/*!
hgs
parents:
diff changeset
   268
 * Private slot
hgs
parents:
diff changeset
   269
 *
hgs
parents:
diff changeset
   270
 */
hgs
parents:
diff changeset
   271
void RadioFrequencyStripBase::initEmptyItems()
hgs
parents:
diff changeset
   272
{
hgs
parents:
diff changeset
   273
    //TODO: Remove the weird hack of checking the sender
hgs
parents:
diff changeset
   274
    if ( !sender() || !isScanning() ) {
hgs
parents:
diff changeset
   275
        QList<FrequencyStrip::StationMarker> emptyList;
hgs
parents:
diff changeset
   276
        foreach ( RadioFrequencyItem* item, mFrequencyItems ) {
hgs
parents:
diff changeset
   277
            QPixmap pixmap = drawPixmap( item->frequency(), emptyList, item );
hgs
parents:
diff changeset
   278
            item->setPixmap( pixmap );
hgs
parents:
diff changeset
   279
        }
hgs
parents:
diff changeset
   280
    }
hgs
parents:
diff changeset
   281
}
hgs
parents:
diff changeset
   282
hgs
parents:
diff changeset
   283
/*!
hgs
parents:
diff changeset
   284
 * Private slot
hgs
parents:
diff changeset
   285
 *
hgs
parents:
diff changeset
   286
 */
57
hgs
parents: 54
diff changeset
   287
void RadioFrequencyStripBase::stationsRemoved( const QList<uint>& frequencies )
39
hgs
parents:
diff changeset
   288
{
57
hgs
parents: 54
diff changeset
   289
    QList<uint>::const_iterator end = frequencies.constEnd();
hgs
parents: 54
diff changeset
   290
    QSet<RadioFrequencyItem*> freqItems;
hgs
parents: 54
diff changeset
   291
    // go frequencies list throught and fetch all frequencyItems required. Duplicates will be removed
hgs
parents: 54
diff changeset
   292
    // using set to prevent unneccessary item updates.
hgs
parents: 54
diff changeset
   293
    for( QList<uint>::const_iterator iter = frequencies.constBegin(); iter != end; ++iter ) {
hgs
parents: 54
diff changeset
   294
        freqItems.insert( mFrequencies.value( *iter ).mItem );                
hgs
parents: 54
diff changeset
   295
    }
hgs
parents: 54
diff changeset
   296
    QSet<RadioFrequencyItem*>::const_iterator setEnd = freqItems.constEnd();
hgs
parents: 54
diff changeset
   297
    QSet<RadioFrequencyItem*>::const_iterator setIter = freqItems.constBegin();
hgs
parents: 54
diff changeset
   298
    for( ; setIter != setEnd; ++setIter ) {
hgs
parents: 54
diff changeset
   299
        updateItem( *setIter, 0, 0 );             
hgs
parents: 54
diff changeset
   300
    }
39
hgs
parents:
diff changeset
   301
}
hgs
parents:
diff changeset
   302
hgs
parents:
diff changeset
   303
/*!
hgs
parents:
diff changeset
   304
 * Private slot
hgs
parents:
diff changeset
   305
 *
hgs
parents:
diff changeset
   306
 */
hgs
parents:
diff changeset
   307
void RadioFrequencyStripBase::updateStation( const QModelIndex& parent, int first, int last )
hgs
parents:
diff changeset
   308
{
hgs
parents:
diff changeset
   309
    Q_UNUSED( parent );
hgs
parents:
diff changeset
   310
    updateStationsInRange( first, last );
hgs
parents:
diff changeset
   311
}
hgs
parents:
diff changeset
   312
hgs
parents:
diff changeset
   313
/*!
hgs
parents:
diff changeset
   314
 * Private slot
hgs
parents:
diff changeset
   315
 */
hgs
parents:
diff changeset
   316
void RadioFrequencyStripBase::handleLeftButton()
hgs
parents:
diff changeset
   317
{
44
hgs
parents: 39
diff changeset
   318
    skipToPrevious();
39
hgs
parents:
diff changeset
   319
}
hgs
parents:
diff changeset
   320
hgs
parents:
diff changeset
   321
/*!
hgs
parents:
diff changeset
   322
 * Private slot
hgs
parents:
diff changeset
   323
 */
hgs
parents:
diff changeset
   324
void RadioFrequencyStripBase::handleRightButton()
hgs
parents:
diff changeset
   325
{
44
hgs
parents: 39
diff changeset
   326
    skipToNext();
39
hgs
parents:
diff changeset
   327
}
hgs
parents:
diff changeset
   328
hgs
parents:
diff changeset
   329
/*!
hgs
parents:
diff changeset
   330
 * Private slot
hgs
parents:
diff changeset
   331
 */
hgs
parents:
diff changeset
   332
void RadioFrequencyStripBase::handleLongLeftButton()
hgs
parents:
diff changeset
   333
{
hgs
parents:
diff changeset
   334
    seekDown();
hgs
parents:
diff changeset
   335
}
hgs
parents:
diff changeset
   336
hgs
parents:
diff changeset
   337
/*!
hgs
parents:
diff changeset
   338
 * Private slot
hgs
parents:
diff changeset
   339
 */
hgs
parents:
diff changeset
   340
void RadioFrequencyStripBase::handleLongRightButton()
hgs
parents:
diff changeset
   341
{
hgs
parents:
diff changeset
   342
    seekUp();
hgs
parents:
diff changeset
   343
}
hgs
parents:
diff changeset
   344
hgs
parents:
diff changeset
   345
/*!
hgs
parents:
diff changeset
   346
 * Private slot
hgs
parents:
diff changeset
   347
 *
hgs
parents:
diff changeset
   348
 */
hgs
parents:
diff changeset
   349
void RadioFrequencyStripBase::toggleManualSeek()
hgs
parents:
diff changeset
   350
{
hgs
parents:
diff changeset
   351
    mManualSeekMode = !mManualSeekMode;
hgs
parents:
diff changeset
   352
    emit manualSeekChanged( mManualSeekMode );
hgs
parents:
diff changeset
   353
hgs
parents:
diff changeset
   354
    if ( mManualSeekMode ) {
hgs
parents:
diff changeset
   355
        grabMouse();
hgs
parents:
diff changeset
   356
        hideButtons();
hgs
parents:
diff changeset
   357
        mManualSeekTimerId = startTimer( FrequencyStrip::MANUALSEEK_SIGNAL_DELAY );
hgs
parents:
diff changeset
   358
    } else {
hgs
parents:
diff changeset
   359
        ungrabMouse();
hgs
parents:
diff changeset
   360
        showButtons();
hgs
parents:
diff changeset
   361
        killTimer( mManualSeekTimerId );
hgs
parents:
diff changeset
   362
        mManualSeekTimerId = 0;
hgs
parents:
diff changeset
   363
    }
hgs
parents:
diff changeset
   364
}
hgs
parents:
diff changeset
   365
hgs
parents:
diff changeset
   366
/*!
hgs
parents:
diff changeset
   367
 * Private slot
hgs
parents:
diff changeset
   368
 */
hgs
parents:
diff changeset
   369
void RadioFrequencyStripBase::handleScrollingEnd()
hgs
parents:
diff changeset
   370
{
54
hgs
parents: 47
diff changeset
   371
    if ( mIgnoreScrollingEnd ) {
hgs
parents: 47
diff changeset
   372
        mIgnoreScrollingEnd = false;
hgs
parents: 47
diff changeset
   373
        return;
hgs
parents: 47
diff changeset
   374
    }
hgs
parents: 47
diff changeset
   375
39
hgs
parents:
diff changeset
   376
    // Check if the selector is in the invalid area where the strip loops around
hgs
parents:
diff changeset
   377
    const int selectorPosition = selectorPos();
hgs
parents:
diff changeset
   378
    if ( mManualSeekMode ) {
hgs
parents:
diff changeset
   379
        if ( !mPositions.contains( selectorPosition ) ) {
hgs
parents:
diff changeset
   380
            if ( selectorPosition < mMaxWidth - FrequencyStrip::ITEM_WIDTH + mSeparatorPos ) {
57
hgs
parents: 54
diff changeset
   381
                scrollToFrequency( mMaxFrequency, Scroll::Shortest, FrequencyStrip::POS_ADJUST_DELAY_MS );
39
hgs
parents:
diff changeset
   382
                emitFrequencyChanged( mMaxFrequency, FrequencyStrip::ManualSeekUpdate, Scroll::Shortest );
hgs
parents:
diff changeset
   383
            } else {
57
hgs
parents: 54
diff changeset
   384
                scrollToFrequency( mMinFrequency, Scroll::Shortest, FrequencyStrip::POS_ADJUST_DELAY_MS );
39
hgs
parents:
diff changeset
   385
                emitFrequencyChanged( mMinFrequency, FrequencyStrip::ManualSeekUpdate, Scroll::Shortest );
hgs
parents:
diff changeset
   386
            }
hgs
parents:
diff changeset
   387
        }
hgs
parents:
diff changeset
   388
hgs
parents:
diff changeset
   389
        mManualSeekTimer->start( FrequencyStrip::MANUALSEEK_END_TIMEOUT );
hgs
parents:
diff changeset
   390
    }
hgs
parents:
diff changeset
   391
}
hgs
parents:
diff changeset
   392
hgs
parents:
diff changeset
   393
/*!
hgs
parents:
diff changeset
   394
 * \reimp
hgs
parents:
diff changeset
   395
 */
hgs
parents:
diff changeset
   396
void RadioFrequencyStripBase::updateItemPrimitive( QGraphicsItem* itemToUpdate, int itemIndex )
hgs
parents:
diff changeset
   397
{
hgs
parents:
diff changeset
   398
    QGraphicsPixmapItem* item = static_cast<QGraphicsPixmapItem*>( itemToUpdate );
hgs
parents:
diff changeset
   399
    if ( itemIndex < mFrequencyItems.count() ) {
hgs
parents:
diff changeset
   400
        item->setPixmap( mFrequencyItems.at( itemIndex )->updatePrimitive( item ) );
hgs
parents:
diff changeset
   401
    }
hgs
parents:
diff changeset
   402
}
hgs
parents:
diff changeset
   403
hgs
parents:
diff changeset
   404
/*!
hgs
parents:
diff changeset
   405
 * \reimp
hgs
parents:
diff changeset
   406
 */
hgs
parents:
diff changeset
   407
QGraphicsItem* RadioFrequencyStripBase::createItemPrimitive( QGraphicsItem* parent )
hgs
parents:
diff changeset
   408
{
hgs
parents:
diff changeset
   409
    return new QGraphicsPixmapItem( parent );
hgs
parents:
diff changeset
   410
}
hgs
parents:
diff changeset
   411
hgs
parents:
diff changeset
   412
/*!
hgs
parents:
diff changeset
   413
 * \reimp
hgs
parents:
diff changeset
   414
 */
hgs
parents:
diff changeset
   415
void RadioFrequencyStripBase::scrollPosChanged()
hgs
parents:
diff changeset
   416
{
hgs
parents:
diff changeset
   417
    if ( mManualSeekMode ) {
hgs
parents:
diff changeset
   418
        const int pos = selectorPos();
hgs
parents:
diff changeset
   419
        const uint frequency = mPositions.value( pos );
54
hgs
parents: 47
diff changeset
   420
        if ( frequency > 0 && mFrequency != frequency ) {
hgs
parents: 47
diff changeset
   421
            mFrequency = frequency;
39
hgs
parents:
diff changeset
   422
            emitFrequencyChanged( mFrequency, FrequencyStrip::ManualSeekUpdate, Scroll::Shortest );
hgs
parents:
diff changeset
   423
        }
hgs
parents:
diff changeset
   424
    }
hgs
parents:
diff changeset
   425
}
hgs
parents:
diff changeset
   426
hgs
parents:
diff changeset
   427
/*!
hgs
parents:
diff changeset
   428
 * \reimp
hgs
parents:
diff changeset
   429
 */
hgs
parents:
diff changeset
   430
void RadioFrequencyStripBase::resizeEvent ( QGraphicsSceneResizeEvent* event )
hgs
parents:
diff changeset
   431
{
hgs
parents:
diff changeset
   432
    RadioStripBase::resizeEvent( event );
hgs
parents:
diff changeset
   433
hgs
parents:
diff changeset
   434
    initSelector();
hgs
parents:
diff changeset
   435
hgs
parents:
diff changeset
   436
    const qreal height = event->newSize().height();
hgs
parents:
diff changeset
   437
    const qreal width = event->newSize().width();
hgs
parents:
diff changeset
   438
hgs
parents:
diff changeset
   439
    mSelectorPos = width / 2;
hgs
parents:
diff changeset
   440
    mSelectorImage->setOffset( mSelectorPos - ( FrequencyStrip::INDICATOR_WIDTH / 2 ), 0.0 );
hgs
parents:
diff changeset
   441
hgs
parents:
diff changeset
   442
    if ( mLeftButton && mRightButton ) {
hgs
parents:
diff changeset
   443
        mLeftButton->resize( height, height );
hgs
parents:
diff changeset
   444
        mRightButton->resize( height, height );
hgs
parents:
diff changeset
   445
        mRightButton->setPos( QPointF( width - height, 0 ) );
hgs
parents:
diff changeset
   446
    }
hgs
parents:
diff changeset
   447
hgs
parents:
diff changeset
   448
    scrollToFrequency( mFrequency );
hgs
parents:
diff changeset
   449
}
hgs
parents:
diff changeset
   450
hgs
parents:
diff changeset
   451
/*!
hgs
parents:
diff changeset
   452
 * \reimp
hgs
parents:
diff changeset
   453
 */
hgs
parents:
diff changeset
   454
void RadioFrequencyStripBase::changeEvent( QEvent* event )
hgs
parents:
diff changeset
   455
{
hgs
parents:
diff changeset
   456
    if ( event->type() == HbEvent::ThemeChanged ) {
hgs
parents:
diff changeset
   457
        // Update the foreground color and redraw each item
hgs
parents:
diff changeset
   458
        mForegroundColor = Qt::white;// HbColorScheme::color( FrequencyStrip::TEXT_COLOR_ATTRIBUTE );
hgs
parents:
diff changeset
   459
        updateAllItems();
hgs
parents:
diff changeset
   460
    }
hgs
parents:
diff changeset
   461
hgs
parents:
diff changeset
   462
    return RadioStripBase::changeEvent(event);
hgs
parents:
diff changeset
   463
}
hgs
parents:
diff changeset
   464
hgs
parents:
diff changeset
   465
/*!
hgs
parents:
diff changeset
   466
 * \reimp
hgs
parents:
diff changeset
   467
 */
hgs
parents:
diff changeset
   468
void RadioFrequencyStripBase::mousePressEvent( QGraphicsSceneMouseEvent* event )
hgs
parents:
diff changeset
   469
{
hgs
parents:
diff changeset
   470
    RadioStripBase::mousePressEvent( event );
hgs
parents:
diff changeset
   471
hgs
parents:
diff changeset
   472
    mManualSeekTimer->stop();
hgs
parents:
diff changeset
   473
    if ( mManualSeekMode ) {
hgs
parents:
diff changeset
   474
        const bool insideStrip = rect().contains( event->pos() );
hgs
parents:
diff changeset
   475
        if ( !insideStrip ) {
hgs
parents:
diff changeset
   476
            toggleManualSeek();
hgs
parents:
diff changeset
   477
        }
hgs
parents:
diff changeset
   478
    } else {
hgs
parents:
diff changeset
   479
        mManualSeekTimer->start( FrequencyStrip::MANUALSEEK_START_TIMEOUT );
hgs
parents:
diff changeset
   480
    }
hgs
parents:
diff changeset
   481
}
hgs
parents:
diff changeset
   482
hgs
parents:
diff changeset
   483
/*!
hgs
parents:
diff changeset
   484
 * \reimp
hgs
parents:
diff changeset
   485
 */
hgs
parents:
diff changeset
   486
void RadioFrequencyStripBase::mouseReleaseEvent( QGraphicsSceneMouseEvent* event )
hgs
parents:
diff changeset
   487
{
hgs
parents:
diff changeset
   488
    RadioStripBase::mouseReleaseEvent( event );
hgs
parents:
diff changeset
   489
hgs
parents:
diff changeset
   490
    mManualSeekTimer->stop();
44
hgs
parents: 39
diff changeset
   491
    if ( mManualSeekMode ) {
39
hgs
parents:
diff changeset
   492
        mManualSeekTimer->start( FrequencyStrip::MANUALSEEK_END_TIMEOUT );
hgs
parents:
diff changeset
   493
    }
hgs
parents:
diff changeset
   494
}
hgs
parents:
diff changeset
   495
hgs
parents:
diff changeset
   496
/*!
hgs
parents:
diff changeset
   497
 * \reimp
hgs
parents:
diff changeset
   498
 */
hgs
parents:
diff changeset
   499
void RadioFrequencyStripBase::gestureEvent( QGestureEvent* event )
hgs
parents:
diff changeset
   500
{
54
hgs
parents: 47
diff changeset
   501
    mIgnoreScrollingEnd = true;
39
hgs
parents:
diff changeset
   502
    HbSwipeGesture* swipeGesture = static_cast<HbSwipeGesture*>( event->gesture( Qt::SwipeGesture ) );
hgs
parents:
diff changeset
   503
    if ( swipeGesture && !mManualSeekMode ) {
hgs
parents:
diff changeset
   504
        if ( swipeGesture->state() == Qt::GestureFinished ) {
hgs
parents:
diff changeset
   505
            if ( swipeGesture->horizontalDirection() == QSwipeGesture::Left ) {
hgs
parents:
diff changeset
   506
                skipToNext();
hgs
parents:
diff changeset
   507
            } else if ( swipeGesture->horizontalDirection() == QSwipeGesture::Right ) {
hgs
parents:
diff changeset
   508
                skipToPrevious();
hgs
parents:
diff changeset
   509
            }
hgs
parents:
diff changeset
   510
        }
hgs
parents:
diff changeset
   511
    } else if ( mManualSeekMode ) {
hgs
parents:
diff changeset
   512
        RadioStripBase::gestureEvent( event );
hgs
parents:
diff changeset
   513
    }
hgs
parents:
diff changeset
   514
}
hgs
parents:
diff changeset
   515
hgs
parents:
diff changeset
   516
/*!
hgs
parents:
diff changeset
   517
 * \reimp
hgs
parents:
diff changeset
   518
 */
hgs
parents:
diff changeset
   519
void RadioFrequencyStripBase::timerEvent( QTimerEvent* event )
hgs
parents:
diff changeset
   520
{
57
hgs
parents: 54
diff changeset
   521
    RadioStripBase::timerEvent( event );
39
hgs
parents:
diff changeset
   522
    if ( mLastReportedFrequency != mFrequency ) {
hgs
parents:
diff changeset
   523
        mLastReportedFrequency = mFrequency;
hgs
parents:
diff changeset
   524
        emitFrequencyChanged( mFrequency, FrequencyStrip::ManualSeekTune, Scroll::Shortest );
hgs
parents:
diff changeset
   525
    }
hgs
parents:
diff changeset
   526
}
hgs
parents:
diff changeset
   527
hgs
parents:
diff changeset
   528
/*!
hgs
parents:
diff changeset
   529
 *
hgs
parents:
diff changeset
   530
 */
hgs
parents:
diff changeset
   531
void RadioFrequencyStripBase::initModel()
hgs
parents:
diff changeset
   532
{
hgs
parents:
diff changeset
   533
    const uint minFreq = uint( qreal(mMinFrequency) / FrequencyStrip::ONE_HERTZ + FrequencyStrip::ROUNDER );
hgs
parents:
diff changeset
   534
    const uint maxFreq = uint( qreal(mMaxFrequency) / FrequencyStrip::ONE_HERTZ + 0.9 ); // always round up
hgs
parents:
diff changeset
   535
hgs
parents:
diff changeset
   536
    QStringList list;
hgs
parents:
diff changeset
   537
    for ( uint i = minFreq; i <= maxFreq; ++i ) {
54
hgs
parents: 47
diff changeset
   538
        list.append( QString::number( i ) );
hgs
parents: 47
diff changeset
   539
        mFrequencyItems.append( new RadioFrequencyItem( i ) );
39
hgs
parents:
diff changeset
   540
    }
54
hgs
parents: 47
diff changeset
   541
    mFrequencyItems.append( new RadioFrequencyItem( 0 ) );
39
hgs
parents:
diff changeset
   542
    list.append( "" );
hgs
parents:
diff changeset
   543
hgs
parents:
diff changeset
   544
    mMaxWidth = list.count() * FrequencyStrip::ITEM_WIDTH;
hgs
parents:
diff changeset
   545
hgs
parents:
diff changeset
   546
    mSeparatorPos = qreal(FrequencyStrip::ITEM_WIDTH) / 2;
57
hgs
parents: 54
diff changeset
   547
    const uint minDrawableFreq = minFreq * FrequencyStrip::ONE_HERTZ - FrequencyStrip::HALF_HERTZ;
39
hgs
parents:
diff changeset
   548
    const uint maxDrawableFreq = maxFreq * FrequencyStrip::ONE_HERTZ + FrequencyStrip::HALF_HERTZ;
hgs
parents:
diff changeset
   549
    mSeparatorPos += qreal( ( mMinFrequency  - minDrawableFreq ) / 2 ) / FrequencyStrip::PIXEL_IN_HZ;
hgs
parents:
diff changeset
   550
    mSeparatorPos -= qreal( ( maxDrawableFreq - mMaxFrequency ) / 2 ) / FrequencyStrip::PIXEL_IN_HZ;
hgs
parents:
diff changeset
   551
hgs
parents:
diff changeset
   552
    setModel( new QStringListModel( list, this ) );
hgs
parents:
diff changeset
   553
}
hgs
parents:
diff changeset
   554
hgs
parents:
diff changeset
   555
/*!
hgs
parents:
diff changeset
   556
 *
hgs
parents:
diff changeset
   557
 */
hgs
parents:
diff changeset
   558
void RadioFrequencyStripBase::initSelector()
hgs
parents:
diff changeset
   559
{
54
hgs
parents: 47
diff changeset
   560
    QPixmap selectorPixmap = QPixmap( QSize( FrequencyStrip::SELECTOR_WIDTH, (int)size().height() - FrequencyStrip::SELECTOR_MARGIN * 2 ) );
39
hgs
parents:
diff changeset
   561
    selectorPixmap.fill( Qt::red );
hgs
parents:
diff changeset
   562
    mSelectorImage->setPixmap( selectorPixmap );
hgs
parents:
diff changeset
   563
    mSelectorImage->setZValue( FrequencyStrip::SELECTOR_Z_POS );
54
hgs
parents: 47
diff changeset
   564
    mSelectorImage->setPos( 0, FrequencyStrip::SELECTOR_MARGIN );
39
hgs
parents:
diff changeset
   565
}
hgs
parents:
diff changeset
   566
hgs
parents:
diff changeset
   567
/*!
hgs
parents:
diff changeset
   568
 *
hgs
parents:
diff changeset
   569
 */
hgs
parents:
diff changeset
   570
void RadioFrequencyStripBase::initPositions()
hgs
parents:
diff changeset
   571
{
hgs
parents:
diff changeset
   572
    int prevPos = 0;
hgs
parents:
diff changeset
   573
    int nextPos = 0;
hgs
parents:
diff changeset
   574
    const int lastPos = mFrequencies.value( mMaxFrequency ).mPosition;
hgs
parents:
diff changeset
   575
    for ( int i = mFrequencies.value( mMinFrequency ).mPosition; i < lastPos; ++i ) {
hgs
parents:
diff changeset
   576
        if ( mPositions.contains( i ) ) {
hgs
parents:
diff changeset
   577
            prevPos = i;
hgs
parents:
diff changeset
   578
            const uint freq = mPositions.value( prevPos ) + mFrequencyStepSize;
hgs
parents:
diff changeset
   579
            if ( mFrequencies.contains( freq ) ) {
hgs
parents:
diff changeset
   580
                nextPos = mFrequencies.value( freq ).mPosition;
hgs
parents:
diff changeset
   581
            } else {
hgs
parents:
diff changeset
   582
                nextPos = prevPos;
hgs
parents:
diff changeset
   583
            }
hgs
parents:
diff changeset
   584
        } else {
hgs
parents:
diff changeset
   585
            const int nearestHit = ( i - prevPos ) < ( nextPos - i ) ? prevPos : nextPos;
hgs
parents:
diff changeset
   586
            mPositions.insert( i, mPositions.value( nearestHit ) );
hgs
parents:
diff changeset
   587
        }
hgs
parents:
diff changeset
   588
    }
hgs
parents:
diff changeset
   589
}
hgs
parents:
diff changeset
   590
hgs
parents:
diff changeset
   591
/*!
hgs
parents:
diff changeset
   592
 *
hgs
parents:
diff changeset
   593
 */
hgs
parents:
diff changeset
   594
void RadioFrequencyStripBase::initButtons()
hgs
parents:
diff changeset
   595
{
hgs
parents:
diff changeset
   596
    Q_ASSERT( mLeftButton && mRightButton );
hgs
parents:
diff changeset
   597
    connectAndCheck( mLeftButton,    SIGNAL(clicked()),
hgs
parents:
diff changeset
   598
                     this,           SLOT(handleLeftButton()) );
hgs
parents:
diff changeset
   599
    connectAndCheck( mRightButton,   SIGNAL(clicked()),
hgs
parents:
diff changeset
   600
                     this,           SLOT(handleRightButton()) );
hgs
parents:
diff changeset
   601
    connectAndCheck( mLeftButton,    SIGNAL(longPress(QPointF)),
hgs
parents:
diff changeset
   602
                     this,           SLOT(handleLongLeftButton()) );
hgs
parents:
diff changeset
   603
    connectAndCheck( mRightButton,   SIGNAL(longPress(QPointF)),
hgs
parents:
diff changeset
   604
                     this,           SLOT(handleLongRightButton()) );
hgs
parents:
diff changeset
   605
hgs
parents:
diff changeset
   606
    mLeftButton->setZValue( FrequencyStrip::SELECTOR_Z_POS );
hgs
parents:
diff changeset
   607
    mLeftButton->setObjectName( FrequencyStrip::LEFT_BUTTON );
hgs
parents:
diff changeset
   608
    mRightButton->setZValue( FrequencyStrip::SELECTOR_Z_POS );
hgs
parents:
diff changeset
   609
    mRightButton->setObjectName( FrequencyStrip::RIGHT_BUTTON );
hgs
parents:
diff changeset
   610
hgs
parents:
diff changeset
   611
    const qreal height = size().height();
hgs
parents:
diff changeset
   612
    const qreal width = size().width();
hgs
parents:
diff changeset
   613
    mLeftButton->resize( height, height );
hgs
parents:
diff changeset
   614
    mRightButton->resize( height, height );
hgs
parents:
diff changeset
   615
    mRightButton->setPos( QPointF( width - height, 0 ) );
hgs
parents:
diff changeset
   616
hgs
parents:
diff changeset
   617
    // Add left button effects
hgs
parents:
diff changeset
   618
    QStringList pathList;
hgs
parents:
diff changeset
   619
    pathList << ":/effects/slide_to_left.fxml" << ":/effects/slide_from_left.fxml";
hgs
parents:
diff changeset
   620
    QStringList eventList;
hgs
parents:
diff changeset
   621
    eventList << FrequencyStrip::SLIDE_TO_LEFT << FrequencyStrip::SLIDE_FROM_LEFT;
hgs
parents:
diff changeset
   622
    HbEffect::add( mLeftButton, pathList, eventList );
hgs
parents:
diff changeset
   623
hgs
parents:
diff changeset
   624
    // Add right button effects
hgs
parents:
diff changeset
   625
    pathList.clear();
hgs
parents:
diff changeset
   626
    pathList << ":/effects/slide_to_right.fxml" << ":/effects/slide_from_right.fxml";
hgs
parents:
diff changeset
   627
    eventList.clear();
hgs
parents:
diff changeset
   628
    eventList << FrequencyStrip::SLIDE_TO_RIGHT << FrequencyStrip::SLIDE_FROM_RIGHT;
hgs
parents:
diff changeset
   629
    HbEffect::add( mRightButton, pathList, eventList );
hgs
parents:
diff changeset
   630
}
hgs
parents:
diff changeset
   631
hgs
parents:
diff changeset
   632
/*!
hgs
parents:
diff changeset
   633
 *
hgs
parents:
diff changeset
   634
 */
hgs
parents:
diff changeset
   635
void RadioFrequencyStripBase::addFrequencyPos( int pos, uint frequency, RadioFrequencyItem* item )
hgs
parents:
diff changeset
   636
{
hgs
parents:
diff changeset
   637
    mFrequencies.insert( frequency, FrequencyPos( pos, item ) );
hgs
parents:
diff changeset
   638
    mPositions.insert( pos, frequency );
hgs
parents:
diff changeset
   639
}
hgs
parents:
diff changeset
   640
hgs
parents:
diff changeset
   641
/*!
hgs
parents:
diff changeset
   642
 *
hgs
parents:
diff changeset
   643
 */
hgs
parents:
diff changeset
   644
void RadioFrequencyStripBase::updateStationsInRange( int first, int last, bool stationRemoved )
hgs
parents:
diff changeset
   645
{
hgs
parents:
diff changeset
   646
    if ( !isScanning() ) {
hgs
parents:
diff changeset
   647
        uint frequency = 0;
hgs
parents:
diff changeset
   648
        for ( int i = first; i <= last; ++i ) {
hgs
parents:
diff changeset
   649
            frequency = frequencyAtIndex( i );
hgs
parents:
diff changeset
   650
            if ( mFrequencies.contains( frequency ) ) {
hgs
parents:
diff changeset
   651
                FrequencyPos pos = mFrequencies.value( frequency );
hgs
parents:
diff changeset
   652
                updateItem( pos.mItem, 0, stationRemoved ? frequency : 0 );
hgs
parents:
diff changeset
   653
            }
hgs
parents:
diff changeset
   654
        }
hgs
parents:
diff changeset
   655
    }
hgs
parents:
diff changeset
   656
}
hgs
parents:
diff changeset
   657
hgs
parents:
diff changeset
   658
/*!
hgs
parents:
diff changeset
   659
 *
hgs
parents:
diff changeset
   660
 */
hgs
parents:
diff changeset
   661
void RadioFrequencyStripBase::updateItem( RadioFrequencyItem* item, uint upperRange, uint ignoredFrequency )
hgs
parents:
diff changeset
   662
{
hgs
parents:
diff changeset
   663
    if ( item ) {
hgs
parents:
diff changeset
   664
        uint frequency = item->frequency();
hgs
parents:
diff changeset
   665
        QList<FrequencyStrip::StationMarker> markers;
hgs
parents:
diff changeset
   666
hgs
parents:
diff changeset
   667
        if ( upperRange == 0 ) {
hgs
parents:
diff changeset
   668
            upperRange = frequency + FrequencyStrip::HALF_HERTZ;
hgs
parents:
diff changeset
   669
        }
hgs
parents:
diff changeset
   670
hgs
parents:
diff changeset
   671
        if ( isInitialized() ) {
hgs
parents:
diff changeset
   672
            markers = stationsInRange( frequency - FrequencyStrip::HALF_HERTZ, upperRange );
hgs
parents:
diff changeset
   673
            for ( int i = markers.count() - 1; ignoredFrequency > 0 && i >= 0; --i ) {
hgs
parents:
diff changeset
   674
                if ( markers[i].mFrequency == ignoredFrequency ) {
hgs
parents:
diff changeset
   675
                    markers.removeAt( i );
hgs
parents:
diff changeset
   676
                    break;
hgs
parents:
diff changeset
   677
                }
hgs
parents:
diff changeset
   678
            }
hgs
parents:
diff changeset
   679
        }
hgs
parents:
diff changeset
   680
hgs
parents:
diff changeset
   681
        QPixmap pixmap = drawPixmap( frequency, markers, item );
hgs
parents:
diff changeset
   682
        item->setPixmap( pixmap );
hgs
parents:
diff changeset
   683
hgs
parents:
diff changeset
   684
        foreach ( const FrequencyStrip::StationMarker& marker, markers ) {
hgs
parents:
diff changeset
   685
            FrequencyPos pos = mFrequencies.value( marker.mFrequency );
hgs
parents:
diff changeset
   686
            mFrequencies.insert( marker.mFrequency, pos );
hgs
parents:
diff changeset
   687
        }
hgs
parents:
diff changeset
   688
    }
hgs
parents:
diff changeset
   689
}
hgs
parents:
diff changeset
   690
hgs
parents:
diff changeset
   691
/*!
hgs
parents:
diff changeset
   692
 *
hgs
parents:
diff changeset
   693
 */
hgs
parents:
diff changeset
   694
void RadioFrequencyStripBase::updateAllItems()
hgs
parents:
diff changeset
   695
{
hgs
parents:
diff changeset
   696
    foreach ( RadioFrequencyItem* item, mFrequencyItems ) {
hgs
parents:
diff changeset
   697
        updateItem( item );
hgs
parents:
diff changeset
   698
    }
hgs
parents:
diff changeset
   699
}
hgs
parents:
diff changeset
   700
hgs
parents:
diff changeset
   701
/*!
hgs
parents:
diff changeset
   702
 *
hgs
parents:
diff changeset
   703
 */
54
hgs
parents: 47
diff changeset
   704
QPixmap RadioFrequencyStripBase::drawPixmap( uint mainFrequency, QList<FrequencyStrip::StationMarker> stations, RadioFrequencyItem* item )
39
hgs
parents:
diff changeset
   705
{
hgs
parents:
diff changeset
   706
    QPixmap pixmap( FrequencyStrip::PIXMAP_WIDTH, mItemHeight );
hgs
parents:
diff changeset
   707
    pixmap.fill( Qt::transparent );
54
hgs
parents: 47
diff changeset
   708
hgs
parents: 47
diff changeset
   709
    if ( mainFrequency == 0 ) {
hgs
parents: 47
diff changeset
   710
        return pixmap;
hgs
parents: 47
diff changeset
   711
    }
hgs
parents: 47
diff changeset
   712
39
hgs
parents:
diff changeset
   713
    QPainter painter( &pixmap );
hgs
parents:
diff changeset
   714
    QPen normalPen = painter.pen();
57
hgs
parents: 54
diff changeset
   715
    normalPen.setColor(mForegroundColor);
hgs
parents: 54
diff changeset
   716
    painter.setPen(normalPen);
39
hgs
parents:
diff changeset
   717
54
hgs
parents: 47
diff changeset
   718
    const uint frequencyIncrement = qMin( mFrequencyStepSize, FrequencyStrip::ONE_HUNDRED_KHZ );
hgs
parents: 47
diff changeset
   719
    const QString itemText = QString::number( mainFrequency / FrequencyStrip::ONE_HERTZ );
hgs
parents: 47
diff changeset
   720
    const uint startFrequency = mainFrequency - FrequencyStrip::HALF_HERTZ + frequencyIncrement;
hgs
parents: 47
diff changeset
   721
    const uint endFrequency = mainFrequency + FrequencyStrip::HALF_HERTZ;
39
hgs
parents:
diff changeset
   722
    const uint  roundedMin = int( qreal(mMinFrequency) / FrequencyStrip::ONE_HERTZ + FrequencyStrip::ROUNDER );
54
hgs
parents: 47
diff changeset
   723
    const uint freq = mainFrequency / FrequencyStrip::ONE_HERTZ;
39
hgs
parents:
diff changeset
   724
    const int diff = freq - roundedMin;
hgs
parents:
diff changeset
   725
    const qreal startPixel = diff * FrequencyStrip::ITEM_WIDTH;
hgs
parents:
diff changeset
   726
    qreal pixels = 0.0;
hgs
parents:
diff changeset
   727
    const qreal leftOverlap = FrequencyStrip::PIXMAP_OVERLAP / 2;
hgs
parents:
diff changeset
   728
54
hgs
parents: 47
diff changeset
   729
    for ( uint loopFrequency = startFrequency; loopFrequency <= endFrequency; loopFrequency += frequencyIncrement ) {
39
hgs
parents:
diff changeset
   730
54
hgs
parents: 47
diff changeset
   731
        pixels = qreal( loopFrequency - startFrequency ) / FrequencyStrip::PIXEL_IN_HZ;
hgs
parents: 47
diff changeset
   732
        if ( loopFrequency % FrequencyStrip::ONE_HERTZ == 0 ) {
39
hgs
parents:
diff changeset
   733
hgs
parents:
diff changeset
   734
            // Draw the high frequency tab and the frequency text for the even number
hgs
parents:
diff changeset
   735
            normalPen.setWidth( 3 );
hgs
parents:
diff changeset
   736
            painter.setPen( normalPen );
hgs
parents:
diff changeset
   737
            painter.drawLine( makeTab( pixels + leftOverlap - 1, FrequencyStrip::TAB_HEIGHT_BIG ) );
hgs
parents:
diff changeset
   738
            normalPen.setWidth( 1 );
hgs
parents:
diff changeset
   739
            painter.setPen( normalPen );
hgs
parents:
diff changeset
   740
54
hgs
parents: 47
diff changeset
   741
            // Draw the frequency text and its decimals
39
hgs
parents:
diff changeset
   742
            painter.setFont( FrequencyStrip::DECIMAL_FONT );
hgs
parents:
diff changeset
   743
            const int decimalWidth = painter.fontMetrics().width( FrequencyStrip::DECIMAL_TEXT );
hgs
parents:
diff changeset
   744
            const int decimalSpace = painter.fontMetrics().leftBearing( '.' );
hgs
parents:
diff changeset
   745
            painter.setFont( FrequencyStrip::FREQUENCY_FONT );
hgs
parents:
diff changeset
   746
            const int frequencyWidth = painter.fontMetrics().width( itemText );
hgs
parents:
diff changeset
   747
            const int textPosX = int( pixels + leftOverlap - ( frequencyWidth + decimalSpace + decimalWidth ) / 2 );
hgs
parents:
diff changeset
   748
            painter.drawText( QPoint( textPosX, FrequencyStrip::FREQUENCY_TEXT_Y_POS ), itemText );
hgs
parents:
diff changeset
   749
            painter.setFont( FrequencyStrip::DECIMAL_FONT );
hgs
parents:
diff changeset
   750
            painter.drawText( QPoint( textPosX + frequencyWidth + decimalSpace, FrequencyStrip::FREQUENCY_TEXT_Y_POS ), FrequencyStrip::DECIMAL_TEXT );
hgs
parents:
diff changeset
   751
54
hgs
parents: 47
diff changeset
   752
        } else if ( loopFrequency % FrequencyStrip::ONE_TAB_IN_HZ == 0 ) {
39
hgs
parents:
diff changeset
   753
hgs
parents:
diff changeset
   754
            // Draw the low frequency tab for the uneven number
hgs
parents:
diff changeset
   755
            painter.drawLine( makeTab( pixels + leftOverlap, FrequencyStrip::TAB_HEIGHT_SMALL ) );
hgs
parents:
diff changeset
   756
hgs
parents:
diff changeset
   757
        }
hgs
parents:
diff changeset
   758
54
hgs
parents: 47
diff changeset
   759
        if ( ( loopFrequency - mMinFrequency ) % mFrequencyStepSize == 0  && loopFrequency >= mMinFrequency && loopFrequency <= mMaxFrequency ) {
hgs
parents: 47
diff changeset
   760
            addFrequencyPos( int( startPixel + pixels + FrequencyStrip::ROUNDER ), loopFrequency, item );
hgs
parents: 47
diff changeset
   761
        }
39
hgs
parents:
diff changeset
   762
    }
hgs
parents:
diff changeset
   763
54
hgs
parents: 47
diff changeset
   764
    const int markerYPos = mItemHeight - 18;
57
hgs
parents: 54
diff changeset
   765
    const int markerHalf = FrequencyStrip::STATION_MARKER_SIZE / 2;
39
hgs
parents:
diff changeset
   766
    foreach ( const FrequencyStrip::StationMarker& station, stations ) {
hgs
parents:
diff changeset
   767
        const uint frequency = station.mFrequency;
57
hgs
parents: 54
diff changeset
   768
        pixels = qreal(frequency - startFrequency) / FrequencyStrip::PIXEL_IN_HZ;
39
hgs
parents:
diff changeset
   769
57
hgs
parents: 54
diff changeset
   770
        const QPoint point( int(pixels + leftOverlap - markerHalf ), markerYPos - markerHalf );
39
hgs
parents:
diff changeset
   771
        if ( station.mIsFavorite ) {
57
hgs
parents: 54
diff changeset
   772
            painter.drawPixmap( point, mFavoriteIcon.pixmap() );
39
hgs
parents:
diff changeset
   773
        } else {
57
hgs
parents: 54
diff changeset
   774
            painter.drawPixmap( point, mStationIcon.pixmap() );
39
hgs
parents:
diff changeset
   775
        }
hgs
parents:
diff changeset
   776
    }
hgs
parents:
diff changeset
   777
hgs
parents:
diff changeset
   778
    return pixmap;
hgs
parents:
diff changeset
   779
}
hgs
parents:
diff changeset
   780
hgs
parents:
diff changeset
   781
/*!
hgs
parents:
diff changeset
   782
 *
hgs
parents:
diff changeset
   783
 */
hgs
parents:
diff changeset
   784
QLineF RadioFrequencyStripBase::makeTab( qreal pos, int height )
hgs
parents:
diff changeset
   785
{
hgs
parents:
diff changeset
   786
    return QLineF( pos, mItemHeight - height, pos, mItemHeight );
hgs
parents:
diff changeset
   787
}
hgs
parents:
diff changeset
   788
hgs
parents:
diff changeset
   789
/*!
hgs
parents:
diff changeset
   790
 *
hgs
parents:
diff changeset
   791
 */
hgs
parents:
diff changeset
   792
int RadioFrequencyStripBase::selectorPos() const
hgs
parents:
diff changeset
   793
{
hgs
parents:
diff changeset
   794
    const int pos = int( -contentWidget()->x() + mSelectorPos + FrequencyStrip::ROUNDER );
hgs
parents:
diff changeset
   795
    return pos % mMaxWidth;
hgs
parents:
diff changeset
   796
}
hgs
parents:
diff changeset
   797
hgs
parents:
diff changeset
   798
/*!
hgs
parents:
diff changeset
   799
 *
hgs
parents:
diff changeset
   800
 */
hgs
parents:
diff changeset
   801
void RadioFrequencyStripBase::scrollToFrequency( uint frequency, Scroll::Direction direction, int time )
hgs
parents:
diff changeset
   802
{
47
hgs
parents: 44
diff changeset
   803
    Q_UNUSED( time );
hgs
parents: 44
diff changeset
   804
39
hgs
parents:
diff changeset
   805
    int targetFreqPos = mFrequencies.value( frequency ).mPosition;
hgs
parents:
diff changeset
   806
    const int currentFreqPos = mFrequencies.value( mFrequency ).mPosition;
hgs
parents:
diff changeset
   807
    const int currentPos = int( -contentWidget()->x() + mSelectorPos + FrequencyStrip::ROUNDER );
hgs
parents:
diff changeset
   808
    const bool isInSecondHalf = currentPos >= mMaxWidth - FrequencyStrip::ITEM_WIDTH + mSeparatorPos;
hgs
parents:
diff changeset
   809
hgs
parents:
diff changeset
   810
    // Special case: When there is only one favorite and the user presses skip
hgs
parents:
diff changeset
   811
    // the strip must scroll around to the same frequency.
hgs
parents:
diff changeset
   812
    if ( mFrequency == frequency && direction != Scroll::Shortest ) {
hgs
parents:
diff changeset
   813
        if ( direction == Scroll::Left ) {
hgs
parents:
diff changeset
   814
            targetFreqPos += mMaxWidth;
hgs
parents:
diff changeset
   815
        } else {
hgs
parents:
diff changeset
   816
            targetFreqPos -= mMaxWidth;
hgs
parents:
diff changeset
   817
        }
hgs
parents:
diff changeset
   818
    }
hgs
parents:
diff changeset
   819
hgs
parents:
diff changeset
   820
    mFrequency = frequency;
hgs
parents:
diff changeset
   821
hgs
parents:
diff changeset
   822
    qreal newPos = targetFreqPos;
hgs
parents:
diff changeset
   823
    if ( direction == Scroll::Left ) {
hgs
parents:
diff changeset
   824
hgs
parents:
diff changeset
   825
        if ( currentFreqPos > targetFreqPos ) {
hgs
parents:
diff changeset
   826
            newPos += mMaxWidth;
hgs
parents:
diff changeset
   827
        }
hgs
parents:
diff changeset
   828
hgs
parents:
diff changeset
   829
    } else if ( direction == Scroll::Right ) {
hgs
parents:
diff changeset
   830
hgs
parents:
diff changeset
   831
        if ( currentFreqPos < targetFreqPos ) {
hgs
parents:
diff changeset
   832
            newPos -= mMaxWidth;
hgs
parents:
diff changeset
   833
        }
hgs
parents:
diff changeset
   834
hgs
parents:
diff changeset
   835
    }
hgs
parents:
diff changeset
   836
hgs
parents:
diff changeset
   837
    if ( isInSecondHalf ) {
hgs
parents:
diff changeset
   838
        newPos += mMaxWidth;
hgs
parents:
diff changeset
   839
    }
hgs
parents:
diff changeset
   840
hgs
parents:
diff changeset
   841
    newPos -= mSelectorPos - FrequencyStrip::ROUNDER;
hgs
parents:
diff changeset
   842
57
hgs
parents: 54
diff changeset
   843
    scrollContentsTo( QPointF( newPos, 0 ), time );
39
hgs
parents:
diff changeset
   844
}
hgs
parents:
diff changeset
   845
hgs
parents:
diff changeset
   846
/*!
hgs
parents:
diff changeset
   847
 *
hgs
parents:
diff changeset
   848
 */
hgs
parents:
diff changeset
   849
void RadioFrequencyStripBase::hideButtons()
hgs
parents:
diff changeset
   850
{
hgs
parents:
diff changeset
   851
    HbEffect::start( mLeftButton, FrequencyStrip::SLIDE_TO_LEFT );
hgs
parents:
diff changeset
   852
    HbEffect::start( mRightButton, FrequencyStrip::SLIDE_TO_RIGHT );
hgs
parents:
diff changeset
   853
}
hgs
parents:
diff changeset
   854
hgs
parents:
diff changeset
   855
/*!
hgs
parents:
diff changeset
   856
 *
hgs
parents:
diff changeset
   857
 */
hgs
parents:
diff changeset
   858
void RadioFrequencyStripBase::showButtons()
hgs
parents:
diff changeset
   859
{
hgs
parents:
diff changeset
   860
    HbEffect::start( mLeftButton, FrequencyStrip::SLIDE_FROM_LEFT );
hgs
parents:
diff changeset
   861
    HbEffect::start( mRightButton, FrequencyStrip::SLIDE_FROM_RIGHT );
hgs
parents:
diff changeset
   862
}