|
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 <QGraphicsSceneMouseEvent> |
|
20 |
|
21 #include <hbinstance.h> |
|
22 #include <hblistview.h> |
|
23 #include <hbframeitem.h> |
|
24 #include <hbmainwindow.h> |
|
25 #include <hbstyleloader.h> |
|
26 |
|
27 |
|
28 #include "mptracklistwidget.h" |
|
29 #include "mpreflectioneffect.h" |
|
30 |
|
31 const int swipeAngleTolerance = 30; // angle is from 0 to 360 |
|
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. |
|
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 */ |
|
52 MpTrackListWidget::MpTrackListWidget( QGraphicsItem *parent ) : HbWidget( parent ) |
|
53 { |
|
54 // Register the custorm css path for the list items. |
|
55 HbStyleLoader::registerFilePath(":/css/mpcustomlistitem.css"); |
|
56 HbStyleLoader::registerFilePath(":/css/mpcustomlistitem.hblistviewitem.widgetml"); |
|
57 mList = new HbListView( this ); |
|
58 // set layout name that matches the custom list item layout. |
|
59 mList->setLayoutName("mpmwtracklist"); |
|
60 |
|
61 //grab the gesture for close. |
|
62 grabGesture(Qt::SwipeGesture); |
|
63 |
|
64 mFrameItem = new HbFrameItem( this ); |
|
65 mFrameItem->frameDrawer().setFrameType( HbFrameDrawer::NinePieces ); |
|
66 mFrameItem->frameDrawer().setFrameGraphicsName( "qtg_fr_multimedia_trans" ); |
|
67 mFrameItem->setZValue(-1); |
|
68 |
|
69 MpReflectionEffect *effect = new MpReflectionEffect(this); |
|
70 setGraphicsEffect(effect); |
|
71 } |
|
72 |
|
73 /*! |
|
74 Destructs the track list widget. |
|
75 */ |
|
76 MpTrackListWidget::~MpTrackListWidget() |
|
77 { |
|
78 } |
|
79 |
|
80 /*! |
|
81 Returns the HbListView instance. |
|
82 */ |
|
83 HbListView *MpTrackListWidget::list() |
|
84 { |
|
85 return mList; |
|
86 } |
|
87 |
|
88 /*! |
|
89 \reimp |
|
90 */ |
|
91 void MpTrackListWidget::resizeEvent(QGraphicsSceneResizeEvent *event) |
|
92 { |
|
93 mFrameItem->setGeometry( rect() ); |
|
94 qreal margin = 0.0; |
|
95 style()->parameter(QString("var(hb-param-margin-gene-middle-vertical)"), margin); |
|
96 mList->setGeometry( rect().adjusted( margin, margin, -margin, -margin ) ); |
|
97 HbWidget::resizeEvent( event ); |
|
98 } |
|
99 |
|
100 /*! |
|
101 \reimp |
|
102 */ |
|
103 void MpTrackListWidget::mousePressEvent( QGraphicsSceneMouseEvent *event ) |
|
104 { |
|
105 if ( event->button() == Qt::LeftButton ) { |
|
106 event->accept(); |
|
107 } |
|
108 else { |
|
109 event->ignore(); |
|
110 } |
|
111 } |
|
112 |
|
113 /*! |
|
114 \reimp |
|
115 */ |
|
116 void MpTrackListWidget::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) |
|
117 { |
|
118 if ( event->button() == Qt::LeftButton ) { |
|
119 event->accept(); |
|
120 } |
|
121 else { |
|
122 event->ignore(); |
|
123 } |
|
124 } |
|
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 } |
|
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 |