radioapp/radiowidgets/inc/radiostationcarousel.h
branchRCL_3
changeset 20 93c594350b9a
parent 19 cce62ebc198e
equal deleted inserted replaced
19:cce62ebc198e 20:93c594350b9a
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:
       
    15 *
       
    16 */
       
    17 
       
    18 #ifndef RADIOSTATIONCAROUSEL_H
       
    19 #define RADIOSTATIONCAROUSEL_H
       
    20 
       
    21 // System includes
       
    22 #include <HbScrollArea>
       
    23 #include <HbIcon>
       
    24 #include <QWeakPointer>
       
    25 
       
    26 // User includes
       
    27 #include "radiocarouselitemobserver.h"
       
    28 #include "radiowidgetsexport.h"
       
    29 #include "radiofrequencystripdef.h"
       
    30 #include "radio_global.h"
       
    31 
       
    32 // Forward declarations
       
    33 class RadioUiEngine;
       
    34 class RadioUiLoader;
       
    35 class RadioCarouselItem;
       
    36 class RadioStation;
       
    37 class RadioStationModel;
       
    38 class RadioStationCarousel;
       
    39 class RadioCarouselAnimator;
       
    40 class HbLabel;
       
    41 class HbMenu;
       
    42 
       
    43 namespace CarouselInfoText
       
    44 {
       
    45     enum Type
       
    46     {
       
    47         None,
       
    48         ConnectAntenna,
       
    49         NoFavorites,
       
    50         FavoriteIconHint,
       
    51         Seeking,
       
    52         Scanning,
       
    53         ManualSeek
       
    54     };
       
    55 }
       
    56 
       
    57 // Class declaration
       
    58 class WIDGETS_DLL_EXPORT RadioStationCarousel : public HbScrollArea
       
    59                                               , public RadioCarouselItemObserver
       
    60 {
       
    61     Q_OBJECT
       
    62     Q_PROPERTY(HbIcon favoriteIcon READ favoriteIcon WRITE setFavoriteIcon)
       
    63     Q_PROPERTY(HbIcon nonFavoriteIcon READ nonFavoriteIcon WRITE setNonFavoriteIcon)
       
    64     Q_PROPERTY( int autoScrollTime READ autoScrollTime WRITE setAutoScrollTime )
       
    65 
       
    66     friend class RadioCarouselAnimator;
       
    67     friend class RadioCarouselItem;
       
    68 
       
    69 public:
       
    70 
       
    71     enum ScrollFlag
       
    72     {
       
    73         Default             = 0,
       
    74         NoAnim              = 1 << 0,
       
    75         NoSignal            = 1 << 1,
       
    76         IgnoreCenter        = 1 << 2,
       
    77         UpdateItem          = 1 << 3,
       
    78         FromPanGesture      = 1 << 4,
       
    79         FromSwipeGesture    = 1 << 5
       
    80     };
       
    81     Q_DECLARE_FLAGS( ScrollMode, ScrollFlag )
       
    82 
       
    83     RadioStationCarousel( QGraphicsItem* parent = 0 );
       
    84 
       
    85     void setFavoriteIcon( const HbIcon& favoriteIcon );
       
    86     HbIcon favoriteIcon() const;
       
    87 
       
    88     void setNonFavoriteIcon( const HbIcon& nonFavoriteIcon );
       
    89     HbIcon nonFavoriteIcon() const;
       
    90 
       
    91     void setAutoScrollTime( const int time );
       
    92     int autoScrollTime() const;
       
    93 
       
    94     void init( RadioUiLoader& uiLoader, RadioUiEngine* uiEngine );
       
    95 
       
    96     void setFrequency( uint frequency, int reason, Scroll::Direction direction = Scroll::Shortest );
       
    97 
       
    98     RadioUiEngine* uiEngine();
       
    99 
       
   100     bool isAntennaAttached() const;
       
   101 
       
   102     void setScanningMode( bool scanning );
       
   103     bool isInScanningMode() const;
       
   104 
       
   105     void cleanRdsData();
       
   106 
       
   107     void animateNewStation( const RadioStation& station );
       
   108     void cancelAnimation();
       
   109 
       
   110     void setInfoText( CarouselInfoText::Type type );
       
   111     void clearInfoText();
       
   112 
       
   113     void setManualSeekMode( bool manualSeekActive );
       
   114 
       
   115     void drawOffScreen( QPainter& painter );
       
   116 
       
   117     void setLandscape( bool landscape );
       
   118 
       
   119 signals:
       
   120 
       
   121     void frequencyChanged( uint frequency, int reason, int direction );
       
   122     void skipRequested( int skipMode );
       
   123     void scanAnimationFinished();
       
   124 
       
   125 public slots:
       
   126 
       
   127     void updateAntennaStatus( bool connected );
       
   128 
       
   129 private slots:
       
   130 
       
   131     void scrollPosChanged( const QPointF& newPosition );
       
   132     void adjustAfterScroll();
       
   133     void update( const RadioStation& station );
       
   134     void updateRadioText( const RadioStation& station );
       
   135     void updateStations();
       
   136     void timerFired();
       
   137 
       
   138 #ifdef USE_DEBUGGING_CONTROLS
       
   139     void setRdsAvailable( bool available );
       
   140 #endif // USE_DEBUGGING_CONTROLS
       
   141 
       
   142 private:
       
   143 
       
   144 // from base class QGraphicsItem
       
   145 
       
   146     void mousePressEvent( QGraphicsSceneMouseEvent* event );
       
   147     void resizeEvent( QGraphicsSceneResizeEvent* event );
       
   148     void showEvent( QShowEvent* event );
       
   149     void gestureEvent( QGestureEvent* event );
       
   150 
       
   151 // from base class RadioCarouselItemObserver
       
   152 
       
   153     void handleIconClicked( const RadioStation& station );
       
   154     void handleRadiotextClicked( const RadioStation& station );
       
   155     void handleUrlClicked( const RadioStation& station );
       
   156     QString localizeGenre( int genre );
       
   157     bool isInManualSeek() const;
       
   158     RadioStation findStation( uint frequency );
       
   159 
       
   160 // New functions
       
   161 
       
   162     bool isInitialized() const;
       
   163 
       
   164     void setCenterIndex( int index, ScrollMode mode = Default );
       
   165 
       
   166     void scrollToIndex( int index, Scroll::Direction direction = Scroll::Shortest,
       
   167                         ScrollMode mode = Default );
       
   168 
       
   169     int calculateDifference( int targetIndex, Scroll::Direction& direction );
       
   170 
       
   171     bool isScrollingAllowed() const;
       
   172 
       
   173     void adjustPos( int offset );
       
   174 
       
   175     int trimIndex( int index );
       
   176 
       
   177     int prevIndex( int index );
       
   178     int nextIndex( int index );
       
   179 
       
   180     void skip( StationSkip::Mode mode );
       
   181 
       
   182 private: // data
       
   183 
       
   184     enum TimerMode { NoTimer, SetFrequency, RtPlusCheck, InfoText, FavoriteHintShow, FavoriteHintHide };
       
   185 
       
   186     RadioUiEngine*                      mUiEngine;
       
   187 
       
   188     int                                 mAutoScrollTime;
       
   189 
       
   190     HbIcon                              mFavoriteIcon;
       
   191     HbIcon                              mNonFavoriteIcon;
       
   192 
       
   193     QTimer*                             mGenericTimer;
       
   194     TimerMode                           mTimerMode;
       
   195 
       
   196     QString                             mRadioTextHolder;
       
   197 
       
   198     QWeakPointer<RadioCarouselAnimator> mAnimator;
       
   199 
       
   200     HbLabel*                            mInfoText;
       
   201 
       
   202     HbMenu*                             mRadiotextPopup;
       
   203 
       
   204     HbWidget*                           mContainer;
       
   205 
       
   206     enum CarouselItem                   { LeftItem, CenterItem, RightItem };
       
   207     RadioCarouselItem*                  mItems[3];
       
   208 
       
   209     int                                 mMidScrollPos;
       
   210     int                                 mMaxScrollPos;
       
   211 
       
   212     int                                 mCurrentIndex;
       
   213     int                                 mTargetIndex;
       
   214     bool                                mIsCustomFreq;
       
   215 
       
   216     CarouselInfoText::Type              mInfoTextType;
       
   217 
       
   218     RadioStationModel*                  mModel;
       
   219 
       
   220     bool                                mPosAdjustmentDisabled;
       
   221 
       
   222     Scroll::Direction                   mScrollDirection;
       
   223 
       
   224     bool                                mManualSeekMode;
       
   225 
       
   226 #ifdef USE_DEBUGGING_CONTROLS
       
   227     RadioFadingLabel*                   mRdsLabel;
       
   228 #endif
       
   229 
       
   230 };
       
   231 
       
   232 Q_DECLARE_OPERATORS_FOR_FLAGS( RadioStationCarousel::ScrollMode )
       
   233 
       
   234 #endif // RADIOSTATIONCAROUSEL_H