radioapp/radiowidgets/inc/radiostationcarousel.h
branchGCC_SURGE
changeset 37 451b2e1545b2
parent 19 afea38384506
parent 33 11b6825f0862
equal deleted inserted replaced
26:6bcf277166c1 37:451b2e1545b2
    17 
    17 
    18 #ifndef RADIOSTATIONCAROUSEL_H
    18 #ifndef RADIOSTATIONCAROUSEL_H
    19 #define RADIOSTATIONCAROUSEL_H
    19 #define RADIOSTATIONCAROUSEL_H
    20 
    20 
    21 // System includes
    21 // System includes
    22 #include <HbGridView>
    22 #include <HbScrollArea>
    23 #include <QMap>
       
    24 #include <QAbstractItemModel>
       
    25 #include <HbIcon>
    23 #include <HbIcon>
       
    24 #include <QWeakPointer>
    26 
    25 
    27 // User includes
    26 // User includes
       
    27 #include "radiocarouselitemobserver.h"
    28 #include "radiowidgetsexport.h"
    28 #include "radiowidgetsexport.h"
    29 #include "radio_global.h"
    29 #include "radio_global.h"
    30 
    30 
    31 // Forward declarations
    31 // Forward declarations
    32 class RadioUiEngine;
    32 class RadioUiEngine;
    33 class RadioUiLoader;
    33 class RadioUiLoader;
       
    34 class RadioCarouselItem;
    34 class RadioStation;
    35 class RadioStation;
    35 class RadioStationItem;
    36 class RadioStationModel;
    36 class RadioStationCarousel;
    37 class RadioStationCarousel;
    37 class RadioCarouselModel;
    38 class RadioCarouselAnimator;
    38 class RadioFadingLabel;
       
    39 class QTimeLine;
       
    40 class HbLabel;
    39 class HbLabel;
       
    40 class HbMenu;
    41 
    41 
    42 namespace CarouselInfoText
    42 namespace CarouselInfoText
    43 {
    43 {
    44     enum Type
    44     enum Type
    45     {
    45     {
    46         None,
    46         None,
    47         ConnectAntenna,
    47         ConnectAntenna,
    48         NoFavorites,
    48         NoFavorites,
       
    49         FavoriteIconHint,
    49         Seeking,
    50         Seeking,
    50         Scanning
    51         Scanning,
       
    52         ManualSeek
    51     };
    53     };
    52 }
    54 }
    53 
    55 
    54 // Class declaration
    56 // Class declaration
    55 class ScanningHelper : public QObject
    57 class WIDGETS_DLL_EXPORT RadioStationCarousel : public HbScrollArea
    56 {
    58                                               , public RadioCarouselItemObserver
    57     Q_OBJECT
       
    58 
       
    59 public:
       
    60 
       
    61     ScanningHelper( RadioStationCarousel& carousel );
       
    62 
       
    63     void start();
       
    64 
       
    65 private slots:
       
    66 
       
    67     void startSlide();
       
    68     void startNumberScroll();
       
    69     void numberScrollUpdate( int value );
       
    70 
       
    71 public:
       
    72 
       
    73     RadioStationCarousel&   mCarousel;
       
    74     uint                    mCurrentFrequency;
       
    75     uint                    mPreviousFrequency;
       
    76     RadioStationItem*       mStationItem;
       
    77     QTimeLine*              mNumberScrollingTimeLine;
       
    78     QModelIndex             mModelIndex;
       
    79 
       
    80 };
       
    81 
       
    82 // Class declaration
       
    83 class WIDGETS_DLL_EXPORT RadioStationCarousel : public HbGridView
       
    84 {
    59 {
    85     Q_OBJECT
    60     Q_OBJECT
    86     Q_PROPERTY(HbIcon favoriteIcon READ favoriteIcon WRITE setFavoriteIcon)
    61     Q_PROPERTY(HbIcon favoriteIcon READ favoriteIcon WRITE setFavoriteIcon)
    87     Q_PROPERTY(HbIcon nonFavoriteIcon READ nonFavoriteIcon WRITE setNonFavoriteIcon)
    62     Q_PROPERTY(HbIcon nonFavoriteIcon READ nonFavoriteIcon WRITE setNonFavoriteIcon)
    88     Q_PROPERTY( int autoScrollTime READ autoScrollTime WRITE setAutoScrollTime )
    63     Q_PROPERTY( int autoScrollTime READ autoScrollTime WRITE setAutoScrollTime )
    89 
    64 
    90     friend class ScanningHelper;
    65     friend class RadioCarouselAnimator;
       
    66     friend class RadioCarouselItem;
    91 
    67 
    92 public:
    68 public:
    93 
    69 
    94     enum ScrollFlag
    70     enum ScrollFlag
    95     {
    71     {
    96         Default         = 0,
    72         Default             = 0,
    97         NoAnim          = 1 << 0,
    73         NoAnim              = 1 << 0,
    98         NoSignal        = 1 << 1,
    74         NoSignal            = 1 << 1,
    99         UpdateItem      = 1 << 2
    75         IgnoreCenter        = 1 << 2,
       
    76         UpdateItem          = 1 << 3,
       
    77         FromPanGesture      = 1 << 4,
       
    78         FromSwipeGesture    = 1 << 5
   100     };
    79     };
   101     Q_DECLARE_FLAGS( ScrollMode, ScrollFlag )
    80     Q_DECLARE_FLAGS( ScrollMode, ScrollFlag )
   102 
    81 
   103     RadioStationCarousel( RadioUiEngine* uiEngine = 0 );
    82     RadioStationCarousel( QGraphicsItem* parent = 0 );
   104 
    83 
   105     void setFavoriteIcon( const HbIcon& favoriteIcon );
    84     void setFavoriteIcon( const HbIcon& favoriteIcon );
   106     HbIcon favoriteIcon() const;
    85     HbIcon favoriteIcon() const;
   107 
    86 
   108     void setNonFavoriteIcon( const HbIcon& nonFavoriteIcon );
    87     void setNonFavoriteIcon( const HbIcon& nonFavoriteIcon );
   111     void setAutoScrollTime( const int time );
    90     void setAutoScrollTime( const int time );
   112     int autoScrollTime() const;
    91     int autoScrollTime() const;
   113 
    92 
   114     void init( RadioUiLoader& uiLoader, RadioUiEngine* uiEngine );
    93     void init( RadioUiLoader& uiLoader, RadioUiEngine* uiEngine );
   115 
    94 
   116     void setCarouselModel( RadioCarouselModel* carouselModel );
    95     void setFrequency( uint frequency, int reason, Scroll::Direction direction = Scroll::Shortest );
   117 
       
   118     void setFrequency( uint frequency, int reason );
       
   119 
    96 
   120     RadioUiEngine* uiEngine();
    97     RadioUiEngine* uiEngine();
   121 
    98 
   122     bool isAntennaAttached() const;
    99     bool isAntennaAttached() const;
   123 
   100 
   124     void setScanningMode( bool scanning );
   101     void setScanningMode( bool scanning );
   125     bool isInScanningMode() const;
   102     bool isInScanningMode() const;
   126 
   103 
   127     void cleanRdsData();
   104     void cleanRdsData();
   128 
   105 
   129     void updateCurrentItem();
       
   130 
       
   131     void animateNewStation( const RadioStation& station );
   106     void animateNewStation( const RadioStation& station );
   132 
   107     void cancelAnimation();
   133     void setItemVisible( bool visible );
       
   134 
   108 
   135     void setInfoText( CarouselInfoText::Type type );
   109     void setInfoText( CarouselInfoText::Type type );
   136     void clearInfoText();
   110     void clearInfoText();
   137 
   111 
       
   112     void setManualSeekMode( bool manualSeekActive );
       
   113 
       
   114     void drawOffScreen( QPainter& painter );
       
   115 
       
   116     void setAlternateSkippingMode( bool alternateSkipping ); //TODO: Remove this! This is test code
       
   117 
   138 signals:
   118 signals:
   139 
   119 
   140     void frequencyChanged( uint frequency, int reason );
   120     void frequencyChanged( uint frequency, int reason, int direction );
       
   121     void skipRequested( int skipMode );
   141     void scanAnimationFinished();
   122     void scanAnimationFinished();
   142 
   123 
   143 public slots:
   124 public slots:
   144 
   125 
   145     void updateAntennaStatus( bool connected );
   126     void updateAntennaStatus( bool connected );
   146 
   127 
   147 private slots:
   128 private slots:
   148 
   129 
       
   130     void scrollPosChanged( const QPointF& newPosition );
       
   131     void adjustAfterScroll();
   149     void update( const RadioStation& station );
   132     void update( const RadioStation& station );
   150     void updateRadioText( const RadioStation& station );
   133     void updateRadioText( const RadioStation& station );
   151     void insertFrequency( const QModelIndex& parent, int first, int last );
   134     void updateStations();
   152     void prepareToRemoveFrequency( const QModelIndex& parent, int first, int last );
       
   153     void removeFrequency( const QModelIndex& parent, int first, int last );
       
   154     void updateFrequencies();
       
   155     void timerFired();
   135     void timerFired();
   156     void openContextMenu( HbAbstractViewItem* item, const QPointF& coords );
       
   157 
   136 
   158 #ifdef USE_DEBUGGING_CONTROLS
   137 #ifdef USE_DEBUGGING_CONTROLS
   159     void setRdsAvailable( bool available );
   138     void setRdsAvailable( bool available );
   160 #endif // USE_DEBUGGING_CONTROLS
   139 #endif // USE_DEBUGGING_CONTROLS
   161 
   140 
   162 private:
   141 private:
   163 
   142 
   164 // from base class QGraphicsItem
   143 // from base class QGraphicsItem
   165 
   144 
   166     void mousePressEvent( QGraphicsSceneMouseEvent* event );
   145     void mousePressEvent( QGraphicsSceneMouseEvent* event );
   167 
   146     void resizeEvent( QGraphicsSceneResizeEvent* event );
       
   147     void showEvent( QShowEvent* event );
   168     void gestureEvent( QGestureEvent* event );
   148     void gestureEvent( QGestureEvent* event );
   169 
   149 
       
   150 // from base class RadioCarouselItemObserver
       
   151 
       
   152     void handleIconClicked( const RadioStation& station );
       
   153     void handleRadiotextClicked( const RadioStation& station );
       
   154     void handleUrlClicked( const RadioStation& station );
       
   155     QString localizeGenre( int genre );
       
   156     bool isInManualSeek() const;
       
   157     RadioStation findStation( uint frequency );
       
   158 
   170 // New functions
   159 // New functions
   171 
   160 
   172     void initToLastTunedFrequency();
   161     bool isInitialized() const;
   173 
   162 
   174     void updateClampingStyle();
   163     void setCenterIndex( int index, ScrollMode mode = Default );
   175 
   164 
   176     void initCurrentStationItem();
   165     void scrollToIndex( int index, Scroll::Direction direction = Scroll::Shortest,
   177 
   166                         ScrollMode mode = Default );
   178     RadioStationItem* currentStationItem();
   167 
   179 
   168     int calculateDifference( int targetIndex, Scroll::Direction& direction );
   180     RadioCarouselModel* carouselModel() const;
   169 
   181 
   170     bool isScrollingAllowed() const;
   182     void scrollToIndex( const QModelIndex& index, ScrollMode mode = Default );
   171 
   183 
   172     void adjustPos( int offset );
   184     void updatePos( int offset );
   173 
       
   174     int trimIndex( int index );
       
   175 
       
   176     int prevIndex( int index );
       
   177     int nextIndex( int index );
   185 
   178 
   186     void skip( StationSkip::Mode mode );
   179     void skip( StationSkip::Mode mode );
   187 
   180 
   188 private: // data
   181 private: // data
   189 
   182 
   190     enum TimerMode { NoTimer, RtPlusCheck, InfoText };
   183     enum TimerMode { NoTimer, SetFrequency, RtPlusCheck, InfoText, FavoriteHintShow, FavoriteHintHide };
   191 
   184 
   192     RadioUiEngine*          mUiEngine;
   185     RadioUiEngine*                      mUiEngine;
   193 
   186 
   194     bool                    mAntennaAttached;
   187     int                                 mAutoScrollTime;
   195 
   188 
   196     int                     mAutoScrollTime;
   189     HbIcon                              mFavoriteIcon;
   197 
   190     HbIcon                              mNonFavoriteIcon;
   198     QMap<uint,QModelIndex>  mModelIndexes;
   191 
   199 
   192     QTimer*                             mGenericTimer;
   200     HbIcon                  mFavoriteIcon;
   193     TimerMode                           mTimerMode;
   201     HbIcon                  mNonFavoriteIcon;
   194 
   202 
   195     QString                             mRadioTextHolder;
   203     QTimer*                 mGenericTimer;
   196 
   204     TimerMode               mTimerMode;
   197     QWeakPointer<RadioCarouselAnimator> mAnimator;
   205 
   198 
   206     QString                 mRadioTextHolder;
   199     HbLabel*                            mInfoText;
   207 
   200 
   208     ScanningHelper*         mScanningHelper;
   201     HbMenu*                             mRadiotextPopup;
   209 
   202 
   210     HbLabel*                mInfoText;
   203     HbWidget*                           mContainer;
   211 
   204 
   212     RadioStationItem*       mCurrentItem;
   205     enum CarouselItem                   { LeftItem, CenterItem, RightItem };
   213 
   206     RadioCarouselItem*                  mItems[3];
   214     CarouselInfoText::Type  mInfoTextType;
   207 
   215 
   208     int                                 mMidScrollPos;
   216     int                     mPanStartPos;
   209     int                                 mMaxScrollPos;
   217 	
   210 
       
   211     int                                 mCurrentIndex;
       
   212     int                                 mTargetIndex;
       
   213     bool                                mIsCustomFreq;
       
   214 
       
   215     CarouselInfoText::Type              mInfoTextType;
       
   216 
       
   217     RadioStationModel*                  mModel;
       
   218 
       
   219     bool                                mPosAdjustmentDisabled;
       
   220 
       
   221     Scroll::Direction                   mScrollDirection;
       
   222 
       
   223     bool                                mManualSeekMode;
       
   224 
       
   225     bool                                mAlternateSkipping;
       
   226 
   218 #ifdef USE_DEBUGGING_CONTROLS
   227 #ifdef USE_DEBUGGING_CONTROLS
   219     RadioFadingLabel*       mRdsLabel;
   228     RadioFadingLabel*                   mRdsLabel;
   220 #endif
   229 #endif
   221 
   230 
   222 };
   231 };
   223 
   232 
   224 Q_DECLARE_OPERATORS_FOR_FLAGS( RadioStationCarousel::ScrollMode )
   233 Q_DECLARE_OPERATORS_FOR_FLAGS( RadioStationCarousel::ScrollMode )