mpviewplugins/mpmediawallviewplugin/src/mptracklistwidget.cpp
changeset 41 ea59c434026a
parent 29 8192e5b5c935
child 43 0f32e550d9d8
child 48 af3740e3753f
equal deleted inserted replaced
32:c163ef0b758d 41:ea59c434026a
    14 * Description: Track List Widget for Music Player Media Wall.
    14 * Description: Track List Widget for Music Player Media Wall.
    15 *
    15 *
    16 */
    16 */
    17 
    17 
    18 
    18 
    19 #include <QGraphicsLinearLayout>
       
    20 #include <QGraphicsSceneMouseEvent>
    19 #include <QGraphicsSceneMouseEvent>
    21 #include <QBrush>
       
    22 
    20 
       
    21 #include <hbinstance.h>
       
    22 #include <hblistview.h>
    23 #include <hbframeitem.h>
    23 #include <hbframeitem.h>
    24 #include <hbinstance.h>
       
    25 #include <hbmainwindow.h>
    24 #include <hbmainwindow.h>
       
    25 #include <hbstyleloader.h>
    26 
    26 
    27 
    27 
    28 #include "mptracklistwidget.h"
    28 #include "mptracklistwidget.h"
       
    29 #include "mpreflectioneffect.h"
    29 
    30 
    30 const int swipeAngleTolerance = 30; // angle is from 0 to 360
    31 const int swipeAngleTolerance = 30; // angle is from 0 to 360
    31 
    32 
       
    33 /*!
       
    34     \class MpTrackListWidget
       
    35     \brief Widget with a list of tracks for Media Wall.
       
    36     
       
    37     This widget provides a list with custom style and a background.
    32 
    38 
       
    39 */
       
    40 
       
    41 /*!
       
    42     \fn void closed()
       
    43 
       
    44     This signal is emitted when the track list is closed by the user with a 
       
    45     left swipe gesture.
       
    46  */
       
    47 
       
    48 
       
    49 /*!
       
    50    Creates the MpTrackListWidget. 
       
    51  */
    33 MpTrackListWidget::MpTrackListWidget( QGraphicsItem *parent ) : HbWidget( parent ) 
    52 MpTrackListWidget::MpTrackListWidget( QGraphicsItem *parent ) : HbWidget( parent ) 
    34 {
    53 {
    35     mList = new HbListView( );
    54     // Register the custorm css path for the list items.
    36     QGraphicsLinearLayout   *layout = new QGraphicsLinearLayout( );
    55     HbStyleLoader::registerFilePath(":/css/mpcustomlistitem.css");
    37     layout->addItem( mList );
    56     HbStyleLoader::registerFilePath(":/css/mpcustomlistitem.hblistviewitem.widgetml");    
    38     setLayout( layout );
    57     mList = new HbListView( this );
       
    58     // set layout name that matches the custom list item layout.
       
    59     mList->setLayoutName("mpmwtracklist");
    39     
    60     
       
    61     //grab the gesture for close.
    40     grabGesture(Qt::SwipeGesture);
    62     grabGesture(Qt::SwipeGesture);
       
    63     
    41     mFrameItem = new HbFrameItem( this );
    64     mFrameItem = new HbFrameItem( this );
    42     mFrameItem->frameDrawer().setFrameType( HbFrameDrawer::NinePieces );
    65     mFrameItem->frameDrawer().setFrameType( HbFrameDrawer::NinePieces );
       
    66     mFrameItem->frameDrawer().setFrameGraphicsName( "qtg_fr_multimedia_trans" );  
       
    67     mFrameItem->setZValue(-1);
    43     
    68     
    44     //TODO: REMOVE PAINT and enable frame drawer when graphic is delibered.
    69     MpReflectionEffect *effect = new MpReflectionEffect(this);
    45     //mFrameItem->frameDrawer().setFrameGraphicsName( "qtg_fr_popup" );  
    70     setGraphicsEffect(effect);
    46     mFrameItem->setZValue(-1);
       
    47 }
    71 }
    48 
    72 
    49 /*!
    73 /*!
    50     \reimp
    74  Destructs the track list widget.
    51  */
    75  */
    52 void MpTrackListWidget::resizeEvent(QGraphicsSceneResizeEvent *event)
    76 MpTrackListWidget::~MpTrackListWidget()
    53 {
    77 {
    54     mFrameItem->setGeometry( rect() );
       
    55     HbWidget::resizeEvent( event );
       
    56 }
       
    57 
       
    58 
       
    59 /*!
       
    60     \reimp
       
    61  */
       
    62 void MpTrackListWidget::paint( QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget )
       
    63 {
       
    64     Q_UNUSED( widget )
       
    65     Q_UNUSED( option )
       
    66     painter->setPen(Qt::darkGray);
       
    67     painter->setBrush(QBrush(Qt::gray ));
       
    68     painter->drawRoundedRect( rect(), 4.0 , 4.0 );
       
    69 }
       
    70 
       
    71 /*!
       
    72     \reimp
       
    73  */
       
    74 void MpTrackListWidget::gestureEvent(QGestureEvent *event)
       
    75 {
       
    76     QGesture* gesture = event->gesture(Qt::SwipeGesture);
       
    77     if (gesture) {
       
    78         QSwipeGesture* swipe = static_cast<QSwipeGesture *>(gesture);
       
    79         if (swipe->state() == Qt::GestureFinished && 
       
    80                 swipeAngleToDirection (swipe->swipeAngle()) == QSwipeGesture::Left ) {
       
    81             //Left gesture is the direction in wich the track list slides to close.
       
    82             emit close();
       
    83             event->accept(Qt::SwipeGesture);
       
    84         }
       
    85     }    
       
    86 }
    78 }
    87 
    79 
    88 /*!
    80 /*!
    89     Returns the HbListView instance.
    81     Returns the HbListView instance.
    90  */
    82  */
    92 {
    84 {
    93     return mList;
    85     return mList;
    94 } 
    86 } 
    95 
    87 
    96 /*!
    88 /*!
    97     Maps swipe angle to SwipeDirection based on a tolerance parameter and orientation.
    89     \reimp
    98  */
    90  */
    99 QSwipeGesture::SwipeDirection MpTrackListWidget::swipeAngleToDirection(
    91 void MpTrackListWidget::resizeEvent(QGraphicsSceneResizeEvent *event)
   100         int angle)
       
   101 {
    92 {
   102     int delta = swipeAngleTolerance;
    93     mFrameItem->setGeometry( rect() );
   103     if ( hbInstance->allMainWindows()[0]->orientation() == Qt::Horizontal ) {
    94     qreal margin = 0.0;
   104         //correction for transformation on rotation.
    95     style()->parameter(QString("var(hb-param-margin-gene-middle-vertical)"), margin);
   105         angle += ( angle < 90 ) ? 270 : -90;  
    96     mList->setGeometry( rect().adjusted( margin, margin, -margin, -margin ) );
   106     }
    97     HbWidget::resizeEvent( event );
   107     QSwipeGesture::SwipeDirection direction(QSwipeGesture::NoDirection);
       
   108     if ((angle > 90-delta) && (angle < 90+delta)) {
       
   109         direction = QSwipeGesture::Up;
       
   110     } else if ((angle > 270-delta) && (angle < 270+delta)) {
       
   111         direction = QSwipeGesture::Down;
       
   112     } else if (((angle >= 0) && (angle < delta)) 
       
   113             || ((angle > 360-delta) && (angle <= 360))) {
       
   114         direction = QSwipeGesture::Right;
       
   115     } else if ((angle > 180-delta) && (angle < 180+delta)) {
       
   116         direction = QSwipeGesture::Left;
       
   117     }
       
   118     return direction;    
       
   119 }
    98 }
   120 
    99 
   121 /*!
   100 /*!
   122     \reimp
   101     \reimp
   123  */
   102  */
   142     else {
   121     else {
   143         event->ignore();
   122         event->ignore();
   144     }
   123     }
   145 }
   124 }
   146 
   125 
       
   126 /*!
       
   127     \reimp
       
   128  */
       
   129 void MpTrackListWidget::gestureEvent(QGestureEvent *event)
       
   130 {
       
   131     QGesture* gesture = event->gesture(Qt::SwipeGesture);
       
   132     if (gesture) {
       
   133         QSwipeGesture* swipe = static_cast<QSwipeGesture *>(gesture);
       
   134         if (swipe->state() == Qt::GestureFinished && 
       
   135                 swipeAngleToDirection (swipe->swipeAngle()) == QSwipeGesture::Left ) {
       
   136             //Left gesture is the direction in wich the track list slides to close.
       
   137             emit closed();
       
   138             event->accept(Qt::SwipeGesture);
       
   139         }
       
   140     }    
       
   141 }
   147 
   142 
       
   143 /*!
       
   144     Maps swipe \a angle to QSwipeGesture::SwipeDirection based on a tolerance 
       
   145     parameter and orientation. This funtions helps to identify a swipe even 
       
   146     if it is not sharp movement from 180 to 0 degrees on the righ swipe 
       
   147     gesture for instance. Since gesture events are mesured on device 
       
   148     cordinates this also helps to correct the gesture to local cordinates 
       
   149     bases on device orientation, wich is done using QT transformations, 
       
   150     meaning local cordinates and device cordinates are not always aligned.
       
   151  */
       
   152 QSwipeGesture::SwipeDirection MpTrackListWidget::swipeAngleToDirection(
       
   153         int angle )
       
   154 {
       
   155     int delta = swipeAngleTolerance;
       
   156     if ( hbInstance->allMainWindows()[0]->orientation() == Qt::Horizontal ) {
       
   157     //correction for transformation on rotation.
       
   158 #ifdef __WINS__ //wincw with forced rotation is to the right.
       
   159     angle += ( angle < 90 ) ? 270 : -90; 
       
   160 #else//currently hardware rotations is to the left.
       
   161     angle += 90;
       
   162     if ( angle > 360 ) {
       
   163         angle -= 360;
       
   164     }
       
   165 #endif    
       
   166       
       
   167     }
       
   168     QSwipeGesture::SwipeDirection direction( QSwipeGesture::NoDirection );
       
   169     if ( ( angle > 90 - delta) && ( angle < 90 + delta ) ) {
       
   170         direction = QSwipeGesture::Up;
       
   171     } else if ( ( angle > 270 - delta ) && (angle < 270 + delta ) ) {
       
   172         direction = QSwipeGesture::Down;
       
   173     } else if ( ( ( angle >= 0 ) && ( angle < delta ) ) 
       
   174             || ( ( angle > 360 - delta ) && ( angle <= 360 ) ) ) {
       
   175         direction = QSwipeGesture::Right;
       
   176     } else if ( ( angle > 180 - delta ) && ( angle < 180 + delta ) ) {
       
   177         direction = QSwipeGesture::Left;
       
   178     }
       
   179     return direction;    
       
   180 }
       
   181 
       
   182 //EOF