radioapp/radiowidgets/src/radiostationcarousel.cpp
changeset 32 189d20c34778
parent 28 075425b8d9a4
child 33 11b6825f0862
equal deleted inserted replaced
28:075425b8d9a4 32:189d20c34778
    20 #include <QGraphicsSceneResizeEvent>
    20 #include <QGraphicsSceneResizeEvent>
    21 #include <QTimer>
    21 #include <QTimer>
    22 #include <HbPanGesture>
    22 #include <HbPanGesture>
    23 #include <HbSwipeGesture>
    23 #include <HbSwipeGesture>
    24 #include <HbFontSpec>
    24 #include <HbFontSpec>
       
    25 #include <HbMenu>
    25 
    26 
    26 // User includes
    27 // User includes
    27 #include "radiostationcarousel.h"
    28 #include "radiostationcarousel.h"
    28 #include "radiocarouselanimator.h"
    29 #include "radiocarouselanimator.h"
    29 #include "radiouiloader.h"
    30 #include "radiouiloader.h"
    61     HbScrollArea( parent ),
    62     HbScrollArea( parent ),
    62     mUiEngine( NULL ),
    63     mUiEngine( NULL ),
    63     mAutoScrollTime( 300 ),
    64     mAutoScrollTime( 300 ),
    64     mGenericTimer( new QTimer( this ) ),
    65     mGenericTimer( new QTimer( this ) ),
    65     mTimerMode( NoTimer ),
    66     mTimerMode( NoTimer ),
    66     mAnimator( NULL ),
       
    67     mInfoText( NULL ),
    67     mInfoText( NULL ),
       
    68     mRadiotextPopup( NULL ),
    68     mContainer( new HbWidget( this ) ),
    69     mContainer( new HbWidget( this ) ),
    69     mMidScrollPos( 0 ),
    70     mMidScrollPos( 0 ),
    70     mMaxScrollPos( 0 ),
    71     mMaxScrollPos( 0 ),
    71     mCurrentIndex( 0 ),
    72     mCurrentIndex( 0 ),
    72     mTargetIndex( -1 ),
    73     mTargetIndex( -1 ),
   141 void RadioStationCarousel::init( RadioUiLoader& uiLoader, RadioUiEngine* uiEngine )
   142 void RadioStationCarousel::init( RadioUiLoader& uiLoader, RadioUiEngine* uiEngine )
   142 {
   143 {
   143     mUiEngine = uiEngine;
   144     mUiEngine = uiEngine;
   144     RadioUtil::setCarousel( this );
   145     RadioUtil::setCarousel( this );
   145 
   146 
   146     mItems[LeftItem] = new RadioCarouselItem( *this );
   147     mItems[CenterItem] = new RadioCarouselItem( *this, this, true );
   147     mItems[CenterItem] = new RadioCarouselItem( *this );
   148     mItems[LeftItem] = new RadioCarouselItem( *this, this );
   148     mItems[RightItem] = new RadioCarouselItem( *this );
   149     mItems[RightItem] = new RadioCarouselItem( *this, this );
   149 
   150 
   150     QGraphicsLinearLayout* layout = new QGraphicsLinearLayout( Qt::Horizontal );
   151     QGraphicsLinearLayout* layout = new QGraphicsLinearLayout( Qt::Horizontal );
   151     layout->setContentsMargins( 0, 0, 0, 0 );
   152     layout->setContentsMargins( 0, 0, 0, 0 );
   152     layout->setSpacing( 0 );
   153     layout->setSpacing( 0 );
   153     layout->addItem( mItems[LeftItem] );
   154     layout->addItem( mItems[LeftItem] );
   164     setVerticalScrollBarPolicy( HbScrollArea::ScrollBarAlwaysOff );
   165     setVerticalScrollBarPolicy( HbScrollArea::ScrollBarAlwaysOff );
   165 
   166 
   166     mInfoText = uiLoader.findWidget<HbLabel>( DOCML::MV_NAME_INFO_TEXT );
   167     mInfoText = uiLoader.findWidget<HbLabel>( DOCML::MV_NAME_INFO_TEXT );
   167     mInfoText->setTextWrapping( Hb::TextWordWrap );
   168     mInfoText->setTextWrapping( Hb::TextWordWrap );
   168 
   169 
       
   170     mRadiotextPopup = uiLoader.findObject<HbMenu>( DOCML::MV_NAME_CAROUSEL_RT_MENU );
       
   171 
   169 #ifdef BUILD_WIN32
   172 #ifdef BUILD_WIN32
   170     HbFontSpec spec = mInfoText->fontSpec();
   173     HbFontSpec spec = mInfoText->fontSpec();
   171     spec.setRole( HbFontSpec::Secondary );
   174     spec.setRole( HbFontSpec::Secondary );
   172     mInfoText->setFontSpec( spec );
   175     mInfoText->setFontSpec( spec );
   173 #endif
   176 #endif
   174 
   177 
   175     setScrollDirections( Qt::Horizontal );
   178     setScrollDirections( Qt::Horizontal );
   176 //    grabGesture( Qt::SwipeGesture );
   179 
   177 
       
   178 //    Radio::connect( this,           SIGNAL(scrollPositionChanged(QPointF)),
       
   179 //                    this,           SLOT(scrollPosChanged(QPointF)) );
       
   180     Radio::connect( this,           SIGNAL(scrollingEnded()),
   180     Radio::connect( this,           SIGNAL(scrollingEnded()),
   181                     this,           SLOT(adjustAfterScroll()) );
   181                     this,           SLOT(adjustAfterScroll()) );
   182 
   182 
   183     mModel = &mUiEngine->stationModel();
   183     mModel = &mUiEngine->stationModel();
   184     Radio::connect( mModel,         SIGNAL(favoriteChanged(RadioStation)),
   184     Radio::connect( mModel,         SIGNAL(favoriteChanged(RadioStation)),
   288     if ( scanning ) {
   288     if ( scanning ) {
   289         setInfoText( CarouselInfoText::Scanning );
   289         setInfoText( CarouselInfoText::Scanning );
   290         if ( !mAnimator ) {
   290         if ( !mAnimator ) {
   291             mAnimator = new RadioCarouselAnimator( *this );
   291             mAnimator = new RadioCarouselAnimator( *this );
   292         }
   292         }
   293         mAnimator->startFlashingText();
   293         mAnimator.data()->startFlashingText();
   294     } else {
   294     } else {
   295         if ( mAnimator ) {
   295         if ( mAnimator ) {
   296             mAnimator->stopFlashingText();
   296             mAnimator.data()->stopFlashingText();
   297         }
   297         }
   298         clearInfoText();
   298         clearInfoText();
   299         setCenterIndex( 0 );
   299         setCenterIndex( 0 );
   300         mTimerMode = FavoriteHintShow;
   300         mTimerMode = FavoriteHintShow;
   301         mGenericTimer->start( FAVORITE_HINT_SHOW_DELAY );
   301         mGenericTimer->start( FAVORITE_HINT_SHOW_DELAY );
   329         const uint previousFrequency = mItems[CenterItem]->frequency();
   329         const uint previousFrequency = mItems[CenterItem]->frequency();
   330 
   330 
   331         mItems[RightItem]->setFrequency( previousFrequency );
   331         mItems[RightItem]->setFrequency( previousFrequency );
   332         mCurrentIndex = mModel->indexFromFrequency( station.frequency() );
   332         mCurrentIndex = mModel->indexFromFrequency( station.frequency() );
   333 
   333 
   334         mAnimator->startNumberScroll( previousFrequency, station.frequency() );
   334         mAnimator.data()->startNumberScroll( previousFrequency, station.frequency() );
   335     }
   335     }
   336 }
   336 }
   337 
   337 
   338 /*!
   338 /*!
   339  *
   339  *
   340  */
   340  */
   341 void RadioStationCarousel::cancelAnimation()
   341 void RadioStationCarousel::cancelAnimation()
   342 {
   342 {
   343     if ( mAnimator ) {
   343     if ( mAnimator ) {
   344         mAnimator->stopAll();
   344         mAnimator.data()->stopAll();
   345     }
   345     }
   346 }
   346 }
   347 
   347 
   348 /*!
   348 /*!
   349  *
   349  *
   362         mGenericTimer->start();
   362         mGenericTimer->start();
   363 
   363 
   364         if ( !mAnimator ) {
   364         if ( !mAnimator ) {
   365             mAnimator = new RadioCarouselAnimator( *this );
   365             mAnimator = new RadioCarouselAnimator( *this );
   366         }
   366         }
   367         mAnimator->startFlashingIcon();
   367         mAnimator.data()->startFlashingIcon();
   368 
   368 
   369     } else if ( type == CarouselInfoText::ConnectAntenna ) {
   369     } else if ( type == CarouselInfoText::ConnectAntenna ) {
   370         cleanRdsData();
   370         cleanRdsData();
   371         mInfoText->setPlainText( hbTrId( "txt_rad_info_connect_wired_headset1" ) );
   371         mInfoText->setPlainText( hbTrId( "txt_rad_info_connect_wired_headset1" ) );
   372         mInfoText->setAlignment( Qt::AlignBottom | Qt::AlignHCenter );
   372         mInfoText->setAlignment( Qt::AlignBottom | Qt::AlignHCenter );
   391  */
   391  */
   392 void RadioStationCarousel::clearInfoText()
   392 void RadioStationCarousel::clearInfoText()
   393 {
   393 {
   394     if ( mInfoTextType != CarouselInfoText::None ) {
   394     if ( mInfoTextType != CarouselInfoText::None ) {
   395         if ( mAnimator ) {
   395         if ( mAnimator ) {
   396             mAnimator->stopFlashingIcon();
   396             mAnimator.data()->stopFlashingIcon();
   397         }
   397         }
   398 
   398 
   399         mGenericTimer->stop();
   399         mGenericTimer->stop();
   400         mInfoTextType = CarouselInfoText::None;
   400         mInfoTextType = CarouselInfoText::None;
   401         mInfoText->setVisible( false );
   401         mInfoText->setVisible( false );
   523         clearInfoText();
   523         clearInfoText();
   524         mTimerMode = NoTimer;
   524         mTimerMode = NoTimer;
   525     }
   525     }
   526 }
   526 }
   527 
   527 
   528 /*!
       
   529  * Private slot
       
   530  */
       
   531 void RadioStationCarousel::toggleFavorite()
       
   532 {
       
   533     if ( mModel ) {
       
   534         mModel->setData( QModelIndex(), mItems[CenterItem]->frequency(), RadioRole::ToggleFavoriteRole );
       
   535     }
       
   536 }
       
   537 
       
   538 /*!
       
   539  * Private slot
       
   540  */
       
   541 //void RadioStationCarousel::openContextMenu( HbAbstractViewItem* item, const QPointF& coords )
       
   542 //{
       
   543 //    if ( item ) {
       
   544 //        static_cast<RadioStationItem*>( item )->handleLongPress( coords );
       
   545 //    }
       
   546 //}
       
   547 
       
   548 #ifdef USE_DEBUGGING_CONTROLS
   528 #ifdef USE_DEBUGGING_CONTROLS
   549 /*!
   529 /*!
   550  * Public slot
   530  * Public slot
   551  */
   531  */
   552 void RadioStationCarousel::setRdsAvailable( bool available )
   532 void RadioStationCarousel::setRdsAvailable( bool available )
   639     if ( HbPanGesture* gesture = qobject_cast<HbPanGesture*>( event->gesture( Qt::PanGesture ) ) ) {
   619     if ( HbPanGesture* gesture = qobject_cast<HbPanGesture*>( event->gesture( Qt::PanGesture ) ) ) {
   640         if ( gesture->state() == Qt::GestureFinished ) {
   620         if ( gesture->state() == Qt::GestureFinished ) {
   641             adjustPos( (int)gesture->offset().x() );
   621             adjustPos( (int)gesture->offset().x() );
   642         }
   622         }
   643     }
   623     }
       
   624 }
       
   625 
       
   626 /*!
       
   627  * \reimp
       
   628  */
       
   629 void RadioStationCarousel::handleIconClicked( const RadioStation& station )
       
   630 {
       
   631     if ( mModel ) {
       
   632         mModel->setData( QModelIndex(), station.frequency(), RadioRole::ToggleFavoriteRole );
       
   633     }
       
   634 }
       
   635 
       
   636 /*!
       
   637  * \reimp
       
   638  */
       
   639 void RadioStationCarousel::handleRadiotextClicked( const RadioStation& station )
       
   640 {
       
   641     Q_UNUSED( station );
       
   642     mRadiotextPopup->show();
       
   643 }
       
   644 
       
   645 /*!
       
   646  * \reimp
       
   647  */
       
   648 void RadioStationCarousel::handleUrlClicked( const RadioStation& station )
       
   649 {
       
   650     mUiEngine->launchBrowser( station.url() );
       
   651 }
       
   652 
       
   653 /*!
       
   654  * \reimp
       
   655  */
       
   656 QString RadioStationCarousel::localizeGenre( int genre )
       
   657 {
       
   658     return mUiEngine->genreToString( genre, GenreTarget::Carousel );
       
   659 }
       
   660 
       
   661 /*!
       
   662  * \reimp
       
   663  */
       
   664 bool RadioStationCarousel::isInManualSeek() const
       
   665 {
       
   666     return mManualSeekMode;
       
   667 }
       
   668 
       
   669 /*!
       
   670  *
       
   671  */
       
   672 RadioStation RadioStationCarousel::findStation( uint frequency )
       
   673 {
       
   674     return mModel->findStation( frequency, FindCriteria::IncludeManualStation );
   644 }
   675 }
   645 
   676 
   646 /*!
   677 /*!
   647  *
   678  *
   648  */
   679  */