radioapp/radiowidgets/inc/radiostripbase.h
changeset 23 a2b50a479edf
parent 19 afea38384506
child 24 6df133bd92e1
equal deleted inserted replaced
19:afea38384506 23:a2b50a479edf
     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 RADIOSTRIPBASE_H_
       
    19 #define RADIOSTRIPBASE_H_
       
    20 
       
    21 // System includes
       
    22 #include <HbScrollArea>
       
    23 
       
    24 // Forward declarations
       
    25 class HbWidget;
       
    26 class QAbstractItemModel;
       
    27 
       
    28 // Class declaration
       
    29 class RadioStripBase : public HbScrollArea
       
    30 {
       
    31     Q_OBJECT
       
    32     Q_PROPERTY( int autoScrollTime READ autoScrollTime WRITE setAutoScrollTime )
       
    33 
       
    34 public:
       
    35 
       
    36     virtual ~RadioStripBase();
       
    37 
       
    38     void setAutoScrollTime( const int time );
       
    39     int autoScrollTime() const;
       
    40 
       
    41     void setModel( QAbstractItemModel* model );
       
    42     QAbstractItemModel* model() const;
       
    43 
       
    44     void setCyclic( bool isCyclic );
       
    45     void setSpacing( qreal spacing );
       
    46     void setAutoCenter( bool autoCenter );
       
    47     void setItemSize( const QSizeF& size );
       
    48     void setIndex( int index, bool animateToCenter );
       
    49 
       
    50 protected:
       
    51 
       
    52     RadioStripBase( QGraphicsItem* parent = 0 );
       
    53 
       
    54 // from base class QGraphicsWidget
       
    55 
       
    56     void resizeEvent( QGraphicsSceneResizeEvent* event );
       
    57 
       
    58 // from base class QGraphicsItem
       
    59 
       
    60     void mousePressEvent( QGraphicsSceneMouseEvent* event );
       
    61     void mouseReleaseEvent( QGraphicsSceneMouseEvent* event );
       
    62 
       
    63 private slots:
       
    64 
       
    65     void scrollPositionChanged( QPointF newPosition );
       
    66 
       
    67 private:
       
    68 
       
    69     Q_DISABLE_COPY( RadioStripBase )
       
    70 
       
    71     virtual void updateItemPrimitive( QGraphicsItem* itemToUpdate, int itemIndex ) = 0;
       
    72     virtual QGraphicsItem* createItemPrimitive( QGraphicsItem *parent ) = 0;
       
    73 
       
    74     virtual void scrollPosChanged( QPointF newPosition ) = 0;
       
    75 
       
    76     void moveAllItemsToPool();
       
    77 
       
    78     void populateAndLayout();
       
    79 
       
    80     QGraphicsItem* constructItem( int index, bool append );
       
    81 
       
    82     QGraphicsItem* getFromPool();
       
    83 
       
    84     void returnToPool( QGraphicsItem* item );
       
    85 
       
    86     qreal indexToOffset( int index );
       
    87 
       
    88     int offsetToIndex( qreal offset );
       
    89 
       
    90     void updateItemWithIndex( int index );
       
    91 
       
    92     void adjustItems();
       
    93 
       
    94 protected: // data
       
    95 
       
    96     int                     mAutoScrollTime;
       
    97 
       
    98 private: //data
       
    99 
       
   100     HbWidget*               mStripContainer;
       
   101 
       
   102     QAbstractItemModel*     mModel;
       
   103 
       
   104     bool                    mIsCyclic;
       
   105     bool                    mAutoCenter;
       
   106 
       
   107     qreal                   mSpacing;
       
   108 
       
   109     QSizeF                  mItemSize;
       
   110 
       
   111     QList<QGraphicsItem*>   mItemPool;
       
   112     QGraphicsWidget*        mItemPoolParent;
       
   113 
       
   114     int                     mCurrentIndex;
       
   115     int                     mPressedIndex;
       
   116 
       
   117     qreal                   mStripLength;
       
   118     qreal                   mContentsLength;
       
   119 
       
   120     QList<QGraphicsItem*>   mItemAtSlot;
       
   121     QList<int>              mIndexAtSlot; // Can be bigger than rowcount if cyclic is used
       
   122 
       
   123 };
       
   124 
       
   125 
       
   126 #endif // RADIOSTRIPBASE_H_