radioapp/radiowidgets/src/radiofrequencystrip.cpp
changeset 16 f54ebcfc1b80
parent 14 63aabac4416d
child 19 afea38384506
equal deleted inserted replaced
14:63aabac4416d 16:f54ebcfc1b80
    20 #include <QStringListModel>
    20 #include <QStringListModel>
    21 #include <QGraphicsSceneResizeEvent>
    21 #include <QGraphicsSceneResizeEvent>
    22 #include <QPen>
    22 #include <QPen>
    23 #include <HbPushButton>
    23 #include <HbPushButton>
    24 #include <QTimer>
    24 #include <QTimer>
       
    25 #include <HbColorScheme>
       
    26 #include <HbEvent>
    25 
    27 
    26 #include "radiofrequencystrip.h"
    28 #include "radiofrequencystrip.h"
    27 #include "radiofrequencyitem.h"
    29 #include "radiofrequencyitem.h"
    28 #include "radiouiengine.h"
    30 #include "radiouiengine.h"
    29 #include "radiostation.h"
    31 #include "radiostation.h"
    39 
    41 
    40 const qreal KRounder = 0.5;
    42 const qreal KRounder = 0.5;
    41 const int KSelectorWidth = 2;
    43 const int KSelectorWidth = 2;
    42 const int KSelectorZPos = 100;
    44 const int KSelectorZPos = 100;
    43 
    45 
       
    46 const int KHalfHertz = KOneHertz / 2;
       
    47 const int KOneTabDistance = 15;
       
    48 const uint KOneTabInHz = 0.2 * KOneHertz;
       
    49 const qreal KPixelInHz = KOneTabInHz / KOneTabDistance;
       
    50 //const int KCharWidth = 8;                  // TODO: Remove hardcoding
       
    51 const int KWidth = KOneTabDistance * 5;
       
    52 const int KHeight = 50;                 //TODO: Remove hardcoding
       
    53 
    44 const int K100Khz = 100000;
    54 const int K100Khz = 100000;
    45 
    55 
    46 //const int KTouchPosThreshold = 30;
    56 //const int KTouchPosThreshold = 30;
    47 
    57 
    48 const QString KSlideToLeft      = "SlideToLeft";
    58 const QString KSlideToLeft      = "SlideToLeft";
    49 const QString KSlideFromLeft    = "SlideFromLeft";
    59 const QString KSlideFromLeft    = "SlideFromLeft";
    50 const QString KSlideToRight     = "SlideToRight";
    60 const QString KSlideToRight     = "SlideToRight";
    51 const QString KSlideFromRight   = "SlideFromRight";
    61 const QString KSlideFromRight   = "SlideFromRight";
       
    62 static const char* BUTTON_LEFT  = "button_left";
       
    63 static const char* BUTTON_RIGHT = "button_right";
       
    64 
       
    65 static const char* TEXT_COLOR_ATTRIBUTE = "text";
    52 
    66 
    53 /*!
    67 /*!
    54  *
    68  *
    55  */
    69  */
    56 static QLineF makeTab( qreal pos, int height )
    70 static QLineF makeTab( qreal pos, int height )
    59 }
    73 }
    60 
    74 
    61 /*!
    75 /*!
    62  *
    76  *
    63  */
    77  */
    64 RadioFrequencyStrip::RadioFrequencyStrip( uint minFrequency,
    78 RadioFrequencyStrip::RadioFrequencyStrip( RadioUiEngine* engine ) :
    65                                           uint maxFrequency,
       
    66                                           uint stepSize,
       
    67                                           uint currentFrequency,
       
    68                                           RadioUiEngine* engine ) :
       
    69     RadioStripBase( 0 ),
    79     RadioStripBase( 0 ),
    70     mMinFrequency( minFrequency ),
    80     mUiEngine( engine ),
    71     mMaxFrequency( maxFrequency ),
    81     mMinFrequency( mUiEngine ? mUiEngine->minFrequency() : 87500000 ),
    72     mFrequencyStepSize( stepSize ),
    82     mMaxFrequency( mUiEngine ? mUiEngine->maxFrequency() : 108000000 ),
    73     mEngine( engine ),
    83     mFrequencyStepSize( mUiEngine ? mUiEngine->frequencyStepSize() : 100000 ),
       
    84     mFrequency( mUiEngine ? mUiEngine->currentFrequency() : 87500000 ),
    74     mSelectorImage( new QGraphicsPixmapItem( this ) ),
    85     mSelectorImage( new QGraphicsPixmapItem( this ) ),
    75     mSeparatorPos( 0.0 ),
    86     mSeparatorPos( 0.0 ),
    76     mMaxWidth( 0 ),
    87     mMaxWidth( 0 ),
    77     mSelectorPos( 0.0 ),
    88     mSelectorPos( 0.0 ),
    78     mFrequency( currentFrequency ),
       
    79     mFavoriteSelected( false ),
    89     mFavoriteSelected( false ),
    80     mLeftButton( new HbPushButton( this ) ),
    90     mLeftButton( new HbPushButton( this ) ),
    81     mRightButton( new HbPushButton( this ) ),
    91     mRightButton( new HbPushButton( this ) ),
    82     mButtonTimer( new QTimer( this ) ),
    92     mButtonTimer( new QTimer( this ) ),
    83     mIsPanGesture( false )
    93     mIsPanGesture( false ),
    84 {
    94     mForegroundColor( HbColorScheme::color( TEXT_COLOR_ATTRIBUTE ) )
       
    95 {
       
    96     RadioUiUtilities::setFrequencyStrip( this );
    85     mButtonTimer->setInterval( 500 );
    97     mButtonTimer->setInterval( 500 );
    86     mButtonTimer->setSingleShot( true );
    98     mButtonTimer->setSingleShot( true );
    87     connectAndTest( mButtonTimer, SIGNAL(timeout()), this, SLOT(toggleButtons()) );
    99     connectAndTest( mButtonTimer, SIGNAL(timeout()), this, SLOT(toggleButtons()) );
    88 
   100 
    89     //TODO: Remove. Stepsize hardcoded to 100 Khz in europe region during demo
   101     //TODO: Remove. Stepsize hardcoded to 100 Khz in europe region during demo
   201 {
   213 {
   202     LOG_SLOT_CALLER;
   214     LOG_SLOT_CALLER;
   203     uint frequency = station.frequency();
   215     uint frequency = station.frequency();
   204     if ( mFrequencies.contains( frequency ) ) {
   216     if ( mFrequencies.contains( frequency ) ) {
   205         FrequencyPos pos = mFrequencies.value( frequency );
   217         FrequencyPos pos = mFrequencies.value( frequency );
   206         mFrequencies.remove( frequency );
   218 //        mFrequencies.remove( frequency );
   207         updateFavorites( pos.mItem );
   219         updateFavorites( pos.mItem );
   208     }
   220     }
   209 }
   221 }
   210 
   222 
   211 /*!
   223 /*!
   212  * Public slot
   224  * Public slot
   213  *
   225  *
   214  */
   226  */
   215 void RadioFrequencyStrip::setFrequency( const uint frequency, int commandSender )
   227 void RadioFrequencyStrip::setFrequency( const uint frequency, int reason )
   216 {
   228 {
   217 //    LOG_SLOT_CALLER;
   229 //    LOG_SLOT_CALLER;
   218 //    LOG_FORMAT( "RadioFrequencyStrip::setFrequency, frequency: %d, sender: %d", frequency, commandSender );
   230 //    LOG_FORMAT( "RadioFrequencyStrip::setFrequency, frequency: %d, sender: %d", frequency, commandSender );
   219     if ( commandSender != CommandSender::FrequencyStrip &&  // Not sent by the FrequencyStrip
   231     if ( reason != TuneReason::FrequencyStrip &&            // Not sent by the FrequencyStrip
   220          frequency != mFrequency &&                         // Different from the current
   232          frequency != mFrequency &&                         // Different from the current
   221          mFrequencies.contains( frequency ) )               // 0 frequency means any illegal value
   233          mFrequencies.contains( frequency ) )               // 0 frequency means any illegal value
   222     {
   234     {
   223         scrollToFrequency( frequency, mAutoScrollTime );
   235         scrollToFrequency( frequency, mAutoScrollTime );
   224         emitFrequencyChanged( frequency );
   236         emitFrequencyChanged( frequency );
   225     }
   237     }
   226 }
   238 }
   227 
   239 
   228 /*!
   240 /*!
       
   241  * Public slot
       
   242  *
       
   243  */
       
   244 void RadioFrequencyStrip::setScanningMode( bool isScanning )
       
   245 {
       
   246     if (isScanning)
       
   247     {
       
   248         HbEffect::start( mLeftButton, KSlideToLeft );
       
   249         HbEffect::start( mRightButton, KSlideToRight );
       
   250     }
       
   251     else
       
   252     {
       
   253         HbEffect::start( mLeftButton, KSlideFromLeft );
       
   254         HbEffect::start( mRightButton, KSlideFromRight );
       
   255 
       
   256     }
       
   257     setEnabled( !isScanning );
       
   258 }
       
   259 
       
   260 /*!
   229  * Private slot
   261  * Private slot
   230  *
   262  *
   231  */
   263  */
   232 void RadioFrequencyStrip::leftGesture( int DEBUGVAR( speedPixelsPerSecond ) )
   264 void RadioFrequencyStrip::leftGesture( int DEBUGVAR( speedPixelsPerSecond ) )
   233 {
   265 {
   333  */
   365  */
   334 void RadioFrequencyStrip::showEvent( QShowEvent* event )
   366 void RadioFrequencyStrip::showEvent( QShowEvent* event )
   335 {
   367 {
   336     Q_UNUSED( event );
   368     Q_UNUSED( event );
   337     scrollToFrequency( mFrequency, 0 );
   369     scrollToFrequency( mFrequency, 0 );
       
   370 }
       
   371 
       
   372 /*!
       
   373  * \reimp
       
   374  */
       
   375 void RadioFrequencyStrip::changeEvent( QEvent* event )
       
   376 {
       
   377     if ( event->type() == HbEvent::ThemeChanged ) {
       
   378         // Update the foreground color and redraw each item
       
   379         mForegroundColor = HbColorScheme::color( TEXT_COLOR_ATTRIBUTE );
       
   380         foreach ( RadioFrequencyItem* item, mFrequencyItems ) {
       
   381             updateFavorites( item );
       
   382         }
       
   383     }
       
   384 
       
   385     return HbWidgetBase::changeEvent(event);
   338 }
   386 }
   339 
   387 
   340 /*!
   388 /*!
   341  * \reimp
   389  * \reimp
   342  */
   390  */
   450     LOG_METHOD;
   498     LOG_METHOD;
   451     foreach ( RadioFrequencyItem* item, mFrequencyItems ) {
   499     foreach ( RadioFrequencyItem* item, mFrequencyItems ) {
   452         updateFavorites( item );
   500         updateFavorites( item );
   453     }
   501     }
   454 
   502 
   455     if ( mEngine ) {
   503     if ( mUiEngine ) {
   456         QList<RadioStation> stations = mEngine->stationsInRange( mMinFrequency, mMaxFrequency );
   504         QList<RadioStation> stations = mUiEngine->stationsInRange( mMinFrequency, mMaxFrequency );
   457         foreach ( const RadioStation& station, stations ) {
   505         foreach ( const RadioStation& station, stations ) {
   458             if ( station.isFavorite() ) {
   506             if ( station.isFavorite() ) {
   459                 mFrequencies[ station.frequency() ].mFavorite = true;
   507                 mFrequencies[ station.frequency() ].mFavorite = true;
   460             }
   508             }
   461             if ( station.isType( RadioStation::LocalStation ) ) {
   509             if ( station.isType( RadioStation::LocalStation ) ) {
   487  *
   535  *
   488  */
   536  */
   489 void RadioFrequencyStrip::initButtons()
   537 void RadioFrequencyStrip::initButtons()
   490 {
   538 {
   491     mLeftButton->setZValue( KSelectorZPos );
   539     mLeftButton->setZValue( KSelectorZPos );
       
   540     mLeftButton->setObjectName( BUTTON_LEFT );
   492     mRightButton->setZValue( KSelectorZPos );
   541     mRightButton->setZValue( KSelectorZPos );
       
   542     mRightButton->setObjectName( BUTTON_RIGHT );
   493 
   543 
   494     QEffectList effectList;
   544     QEffectList effectList;
   495     effectList.append( EffectInfo( mLeftButton, ":/effects/slide_to_left.fxml", KSlideToLeft ) );
   545     effectList.append( EffectInfo( mLeftButton, ":/effects/slide_to_left.fxml", KSlideToLeft ) );
   496     effectList.append( EffectInfo( mLeftButton, ":/effects/slide_from_left.fxml", KSlideFromLeft ) );
   546     effectList.append( EffectInfo( mLeftButton, ":/effects/slide_from_left.fxml", KSlideFromLeft ) );
   497     effectList.append( EffectInfo( mRightButton, ":/effects/slide_to_right.fxml", KSlideToRight ) );
   547     effectList.append( EffectInfo( mRightButton, ":/effects/slide_to_right.fxml", KSlideToRight ) );
   511 /*!
   561 /*!
   512  *
   562  *
   513  */
   563  */
   514 void RadioFrequencyStrip::updateFavorites( RadioFrequencyItem* item )
   564 void RadioFrequencyStrip::updateFavorites( RadioFrequencyItem* item )
   515 {
   565 {
   516     uint frequency = item->frequency();
   566     if ( item ) {
   517     QList<RadioStation> stations;
   567         uint frequency = item->frequency();
   518     if ( mEngine ) {
   568         QList<RadioStation> stations;
   519         stations = mEngine->stationsInRange( frequency - KHalfHertz, frequency + KHalfHertz );
   569         if ( mUiEngine ) {
   520     }
   570             stations = mUiEngine->stationsInRange( frequency - KHalfHertz, frequency + KHalfHertz );
   521 
   571         }
   522     QPixmap pixmap = drawPixmap( frequency, stations, item );
   572 
   523     item->setPixmap( pixmap );
   573         QPixmap pixmap = drawPixmap( frequency, stations, item );
   524 
   574         item->setPixmap( pixmap );
   525     foreach ( const RadioStation& station, stations ) {
   575 
   526         frequency = station.frequency();
   576         foreach ( const RadioStation& station, stations ) {
   527         FrequencyPos pos = mFrequencies.value( frequency );
   577             frequency = station.frequency();
   528         pos.mFavorite = station.isFavorite();
   578             FrequencyPos pos = mFrequencies.value( frequency );
   529         pos.mLocalStation = station.isType( RadioStation::LocalStation );
   579             pos.mFavorite = station.isFavorite();
   530         mFrequencies.insert( frequency, pos );
   580             pos.mLocalStation = station.isType( RadioStation::LocalStation );
       
   581             mFrequencies.insert( frequency, pos );
       
   582         }
   531     }
   583     }
   532 }
   584 }
   533 
   585 
   534 /*!
   586 /*!
   535  *
   587  *
   539     QPixmap pixmap( KWidth, KHeight );
   591     QPixmap pixmap( KWidth, KHeight );
   540     pixmap.fill( Qt::transparent );
   592     pixmap.fill( Qt::transparent );
   541     QPainter painter( &pixmap );
   593     QPainter painter( &pixmap );
   542     QPen normalPen = painter.pen();
   594     QPen normalPen = painter.pen();
   543     QPen favoritePen = normalPen;
   595     QPen favoritePen = normalPen;
   544     normalPen.setColor( Qt::white );
   596     normalPen.setColor( mForegroundColor );
   545     painter.setPen( normalPen );
   597     painter.setPen( normalPen );
   546 
   598 
   547     if ( frequency == 0 ) {
   599     if ( frequency == 0 ) {
   548         painter.drawLine( makeTab( mSeparatorPos - 1 + KRounder, KHeight ) );
   600         painter.drawLine( makeTab( mSeparatorPos - 1 + KRounder, KHeight ) );
   549         painter.drawLine( makeTab( mSeparatorPos + KRounder, KHeight ) );
   601         painter.drawLine( makeTab( mSeparatorPos + KRounder, KHeight ) );
   622 void RadioFrequencyStrip::emitFrequencyChanged( uint frequency )
   674 void RadioFrequencyStrip::emitFrequencyChanged( uint frequency )
   623 {
   675 {
   624 //    LOG_FORMAT( "RadioFrequencyStrip::emitFrequencyChanged, frequency: %d", frequency );
   676 //    LOG_FORMAT( "RadioFrequencyStrip::emitFrequencyChanged, frequency: %d", frequency );
   625     if ( frequency > 0 && frequency != mFrequency ) {
   677     if ( frequency > 0 && frequency != mFrequency ) {
   626         mFrequency = frequency;
   678         mFrequency = frequency;
   627         emit frequencyChanged( frequency, CommandSender::FrequencyStrip );
   679         emit frequencyChanged( frequency, TuneReason::FrequencyStrip );
   628         emitFavoriteSelected( mFrequencies.value( frequency ).mFavorite );
   680         emitFavoriteSelected( mFrequencies.value( frequency ).mFavorite );
   629     }
   681     }
   630 }
   682 }
   631 
   683 
   632 /*!
   684 /*!