35
|
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 |
|
47
|
21 |
#ifndef UNIT_TESTING
|
37
|
22 |
#include <hbinstance.h>
|
47
|
23 |
#else
|
|
24 |
#include "hbinstancestub.h"
|
|
25 |
#endif
|
|
26 |
|
37
|
27 |
#include <hblistview.h>
|
35
|
28 |
#include <hbframeitem.h>
|
|
29 |
#include <hbmainwindow.h>
|
37
|
30 |
#include <hbstyleloader.h>
|
55
|
31 |
#include <hbscrollbar.h>
|
|
32 |
#include <hbcolorscheme.h>
|
35
|
33 |
|
|
34 |
|
|
35 |
#include "mptracklistwidget.h"
|
43
|
36 |
|
35
|
37 |
|
|
38 |
const int swipeAngleTolerance = 30; // angle is from 0 to 360
|
55
|
39 |
const int tracklistOutlineSize = 1; //
|
35
|
40 |
|
37
|
41 |
/*!
|
|
42 |
\class MpTrackListWidget
|
|
43 |
\brief Widget with a list of tracks for Media Wall.
|
|
44 |
|
|
45 |
This widget provides a list with custom style and a background.
|
35
|
46 |
|
37
|
47 |
*/
|
|
48 |
|
|
49 |
/*!
|
|
50 |
\fn void closed()
|
|
51 |
|
|
52 |
This signal is emitted when the track list is closed by the user with a
|
|
53 |
left swipe gesture.
|
|
54 |
*/
|
|
55 |
|
|
56 |
|
|
57 |
/*!
|
|
58 |
Creates the MpTrackListWidget.
|
|
59 |
*/
|
35
|
60 |
MpTrackListWidget::MpTrackListWidget( QGraphicsItem *parent ) : HbWidget( parent )
|
|
61 |
{
|
55
|
62 |
setFlag( QGraphicsItem::ItemHasNoContents, false );
|
37
|
63 |
// Register the custorm css path for the list items.
|
55
|
64 |
HbStyleLoader::registerFilePath( ":/css/mpcustomlistitem.css" );
|
|
65 |
HbStyleLoader::registerFilePath( ":/css/mpcustomlistitem.hblistviewitem.widgetml" );
|
37
|
66 |
mList = new HbListView( this );
|
|
67 |
// set layout name that matches the custom list item layout.
|
55
|
68 |
mList->setLayoutName( "mpmwtracklist" );
|
|
69 |
HbScrollBar *scrollbar = mList->verticalScrollBar();
|
|
70 |
scrollbar->show();
|
|
71 |
scrollbar->setInteractive( true );
|
|
72 |
mList->setVerticalScrollBarPolicy( HbScrollArea::ScrollBarAlwaysOn );
|
35
|
73 |
|
37
|
74 |
//grab the gesture for close.
|
35
|
75 |
grabGesture(Qt::SwipeGesture);
|
37
|
76 |
|
35
|
77 |
mFrameItem = new HbFrameItem( this );
|
55
|
78 |
mFrameItem->frameDrawer().setFrameType( HbFrameDrawer::OnePiece );
|
|
79 |
mFrameItem->frameDrawer().setFrameGraphicsName( "qtg_fr_popup_c" ); //replace for qtg_graf_mediawall_list_bg when available.
|
|
80 |
mFrameItem->setFlag(QGraphicsItem::ItemStacksBehindParent);
|
35
|
81 |
}
|
|
82 |
|
|
83 |
/*!
|
37
|
84 |
Destructs the track list widget.
|
35
|
85 |
*/
|
37
|
86 |
MpTrackListWidget::~MpTrackListWidget()
|
35
|
87 |
{
|
|
88 |
}
|
|
89 |
|
|
90 |
/*!
|
|
91 |
Returns the HbListView instance.
|
|
92 |
*/
|
|
93 |
HbListView *MpTrackListWidget::list()
|
|
94 |
{
|
|
95 |
return mList;
|
|
96 |
}
|
|
97 |
|
|
98 |
/*!
|
37
|
99 |
\reimp
|
35
|
100 |
*/
|
37
|
101 |
void MpTrackListWidget::resizeEvent(QGraphicsSceneResizeEvent *event)
|
35
|
102 |
{
|
37
|
103 |
mFrameItem->setGeometry( rect() );
|
55
|
104 |
qreal margin = tracklistOutlineSize;
|
37
|
105 |
mList->setGeometry( rect().adjusted( margin, margin, -margin, -margin ) );
|
|
106 |
HbWidget::resizeEvent( event );
|
35
|
107 |
}
|
|
108 |
|
|
109 |
/*!
|
|
110 |
\reimp
|
|
111 |
*/
|
|
112 |
void MpTrackListWidget::mousePressEvent( QGraphicsSceneMouseEvent *event )
|
|
113 |
{
|
|
114 |
if ( event->button() == Qt::LeftButton ) {
|
|
115 |
event->accept();
|
|
116 |
}
|
|
117 |
else {
|
|
118 |
event->ignore();
|
|
119 |
}
|
|
120 |
}
|
|
121 |
|
|
122 |
/*!
|
|
123 |
\reimp
|
|
124 |
*/
|
|
125 |
void MpTrackListWidget::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
|
|
126 |
{
|
|
127 |
if ( event->button() == Qt::LeftButton ) {
|
|
128 |
event->accept();
|
|
129 |
}
|
|
130 |
else {
|
|
131 |
event->ignore();
|
|
132 |
}
|
|
133 |
}
|
|
134 |
|
37
|
135 |
/*!
|
|
136 |
\reimp
|
|
137 |
*/
|
|
138 |
void MpTrackListWidget::gestureEvent(QGestureEvent *event)
|
|
139 |
{
|
|
140 |
QGesture* gesture = event->gesture(Qt::SwipeGesture);
|
|
141 |
if (gesture) {
|
|
142 |
QSwipeGesture* swipe = static_cast<QSwipeGesture *>(gesture);
|
|
143 |
if (swipe->state() == Qt::GestureFinished &&
|
|
144 |
swipeAngleToDirection (swipe->swipeAngle()) == QSwipeGesture::Left ) {
|
|
145 |
//Left gesture is the direction in wich the track list slides to close.
|
|
146 |
emit closed();
|
|
147 |
event->accept(Qt::SwipeGesture);
|
|
148 |
}
|
|
149 |
}
|
|
150 |
}
|
35
|
151 |
|
37
|
152 |
/*!
|
55
|
153 |
\reimp
|
|
154 |
*/
|
|
155 |
void MpTrackListWidget::paint( QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget )
|
|
156 |
{
|
|
157 |
Q_UNUSED( widget )
|
|
158 |
Q_UNUSED( option )
|
|
159 |
painter->save();
|
|
160 |
qreal outlineWidth(tracklistOutlineSize);
|
|
161 |
painter->setPen(QPen(HbColorScheme::color("qtc_view_normal_secondary"), outlineWidth,Qt::SolidLine,Qt::FlatCap,Qt::MiterJoin));
|
|
162 |
painter->drawRect( rect().adjusted(outlineWidth/2,outlineWidth/2,-outlineWidth/2,-outlineWidth/2) );
|
|
163 |
painter->restore();
|
|
164 |
}
|
|
165 |
|
|
166 |
/*!
|
37
|
167 |
Maps swipe \a angle to QSwipeGesture::SwipeDirection based on a tolerance
|
|
168 |
parameter and orientation. This funtions helps to identify a swipe even
|
|
169 |
if it is not sharp movement from 180 to 0 degrees on the righ swipe
|
|
170 |
gesture for instance. Since gesture events are mesured on device
|
|
171 |
cordinates this also helps to correct the gesture to local cordinates
|
|
172 |
bases on device orientation, wich is done using QT transformations,
|
|
173 |
meaning local cordinates and device cordinates are not always aligned.
|
|
174 |
*/
|
|
175 |
QSwipeGesture::SwipeDirection MpTrackListWidget::swipeAngleToDirection(
|
|
176 |
int angle )
|
|
177 |
{
|
|
178 |
int delta = swipeAngleTolerance;
|
|
179 |
if ( hbInstance->allMainWindows()[0]->orientation() == Qt::Horizontal ) {
|
|
180 |
//correction for transformation on rotation.
|
|
181 |
#ifdef __WINS__ //wincw with forced rotation is to the right.
|
|
182 |
angle += ( angle < 90 ) ? 270 : -90;
|
|
183 |
#else//currently hardware rotations is to the left.
|
|
184 |
angle += 90;
|
|
185 |
if ( angle > 360 ) {
|
|
186 |
angle -= 360;
|
|
187 |
}
|
|
188 |
#endif
|
|
189 |
|
|
190 |
}
|
|
191 |
QSwipeGesture::SwipeDirection direction( QSwipeGesture::NoDirection );
|
|
192 |
if ( ( angle > 90 - delta) && ( angle < 90 + delta ) ) {
|
|
193 |
direction = QSwipeGesture::Up;
|
|
194 |
} else if ( ( angle > 270 - delta ) && (angle < 270 + delta ) ) {
|
|
195 |
direction = QSwipeGesture::Down;
|
|
196 |
} else if ( ( ( angle >= 0 ) && ( angle < delta ) )
|
|
197 |
|| ( ( angle > 360 - delta ) && ( angle <= 360 ) ) ) {
|
|
198 |
direction = QSwipeGesture::Right;
|
|
199 |
} else if ( ( angle > 180 - delta ) && ( angle < 180 + delta ) ) {
|
|
200 |
direction = QSwipeGesture::Left;
|
|
201 |
}
|
|
202 |
return direction;
|
|
203 |
}
|
|
204 |
|
|
205 |
//EOF
|