mpviewplugins/mpmediawallviewplugin/src/mptracklistwidget.cpp
changeset 29 8192e5b5c935
child 37 eb79a7c355bf
equal deleted inserted replaced
25:3ec52facab4d 29:8192e5b5c935
       
     1 /*
       
     2 * Copyright (c) 2010 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: Track List Widget for Music Player Media Wall.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <QGraphicsLinearLayout>
       
    20 #include <QGraphicsSceneMouseEvent>
       
    21 #include <QBrush>
       
    22 
       
    23 #include <hbframeitem.h>
       
    24 #include <hbinstance.h>
       
    25 #include <hbmainwindow.h>
       
    26 
       
    27 
       
    28 #include "mptracklistwidget.h"
       
    29 
       
    30 const int swipeAngleTolerance = 30; // angle is from 0 to 360
       
    31 
       
    32 
       
    33 MpTrackListWidget::MpTrackListWidget( QGraphicsItem *parent ) : HbWidget( parent ) 
       
    34 {
       
    35     mList = new HbListView( );
       
    36     QGraphicsLinearLayout   *layout = new QGraphicsLinearLayout( );
       
    37     layout->addItem( mList );
       
    38     setLayout( layout );
       
    39     
       
    40     grabGesture(Qt::SwipeGesture);
       
    41     mFrameItem = new HbFrameItem( this );
       
    42     mFrameItem->frameDrawer().setFrameType( HbFrameDrawer::NinePieces );
       
    43     
       
    44     //TODO: REMOVE PAINT and enable frame drawer when graphic is delibered.
       
    45     //mFrameItem->frameDrawer().setFrameGraphicsName( "qtg_fr_popup" );  
       
    46     mFrameItem->setZValue(-1);
       
    47 }
       
    48 
       
    49 /*!
       
    50     \reimp
       
    51  */
       
    52 void MpTrackListWidget::resizeEvent(QGraphicsSceneResizeEvent *event)
       
    53 {
       
    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 }
       
    87 
       
    88 /*!
       
    89     Returns the HbListView instance.
       
    90  */
       
    91 HbListView *MpTrackListWidget::list()
       
    92 {
       
    93     return mList;
       
    94 } 
       
    95 
       
    96 /*!
       
    97     Maps swipe angle to SwipeDirection based on a tolerance parameter and orientation.
       
    98  */
       
    99 QSwipeGesture::SwipeDirection MpTrackListWidget::swipeAngleToDirection(
       
   100         int angle)
       
   101 {
       
   102     int delta = swipeAngleTolerance;
       
   103     if ( hbInstance->allMainWindows()[0]->orientation() == Qt::Horizontal ) {
       
   104         //correction for transformation on rotation.
       
   105         angle += ( angle < 90 ) ? 270 : -90;  
       
   106     }
       
   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 }
       
   120 
       
   121 /*!
       
   122     \reimp
       
   123  */
       
   124 void MpTrackListWidget::mousePressEvent( QGraphicsSceneMouseEvent *event )
       
   125 {
       
   126     if ( event->button() == Qt::LeftButton ) {
       
   127         event->accept();
       
   128     }
       
   129     else {
       
   130         event->ignore();
       
   131     }
       
   132 }
       
   133 
       
   134 /*!
       
   135     \reimp
       
   136  */
       
   137 void MpTrackListWidget::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
       
   138 {
       
   139     if ( event->button() == Qt::LeftButton ) {
       
   140         event->accept();
       
   141     }
       
   142     else {
       
   143         event->ignore();
       
   144     }
       
   145 }
       
   146 
       
   147