|
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: Implementation of QMPXVideoPlaybackProgressBar |
|
15 * |
|
16 */ |
|
17 |
|
18 // Version : %version: da1mmcf#14 % |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 #include <QTime> |
|
24 #include <QGraphicsSceneMouseEvent> |
|
25 |
|
26 #include <hblabel.h> |
|
27 #include <hbprogressbar.h> |
|
28 |
|
29 #include "mpxvideo_debug.h" |
|
30 #include "mpxvideoplaybackprogressbar.h" |
|
31 #include "mpxvideoplaybackdocumentloader.h" |
|
32 #include "mpxvideoplaybackcontrolscontroller.h" |
|
33 |
|
34 // ------------------------------------------------------------------------------------------------- |
|
35 // QMPXVideoPlaybackProgressBar::QMPXVideoPlaybackProgressBar |
|
36 // ------------------------------------------------------------------------------------------------- |
|
37 // |
|
38 QMPXVideoPlaybackProgressBar::QMPXVideoPlaybackProgressBar( |
|
39 QMPXVideoPlaybackControlsController* controller ) |
|
40 : mController( controller ) |
|
41 , mDuration( -1 ) |
|
42 , mNeedToResumeAfterSetPosition( false ) |
|
43 , mInitialized( false ) |
|
44 , mDragging( false ) |
|
45 { |
|
46 MPX_ENTER_EXIT(_L("QMPXVideoPlaybackProgressBar::QMPXVideoPlaybackProgressBar()")); |
|
47 } |
|
48 |
|
49 // ------------------------------------------------------------------------------------------------- |
|
50 // QMPXVideoPlaybackProgressBar::~QMPXVideoPlaybackProgressBar |
|
51 // ------------------------------------------------------------------------------------------------- |
|
52 // |
|
53 QMPXVideoPlaybackProgressBar::~QMPXVideoPlaybackProgressBar() |
|
54 { |
|
55 MPX_ENTER_EXIT(_L("QMPXVideoPlaybackProgressBar::~QMPXVideoPlaybackProgressBar()")); |
|
56 } |
|
57 |
|
58 // ------------------------------------------------------------------------------------------------- |
|
59 // QMPXVideoPlaybackProgressBar::initialize |
|
60 // ------------------------------------------------------------------------------------------------- |
|
61 // |
|
62 void QMPXVideoPlaybackProgressBar::initialize() |
|
63 { |
|
64 MPX_ENTER_EXIT(_L("QMPXVideoPlaybackProgressBar::initialize()")); |
|
65 |
|
66 QMPXVideoPlaybackDocumentLoader *loader = mController->layoutLoader(); |
|
67 |
|
68 // |
|
69 // Don't need to initialize buttons once it gets initialized |
|
70 // |
|
71 if ( loader && ! mInitialized ) |
|
72 { |
|
73 mInitialized = true; |
|
74 |
|
75 // |
|
76 // progress slider |
|
77 // |
|
78 QGraphicsWidget *widget = loader->findWidget( QString( "progressSlider" ) ); |
|
79 mProgressSlider = qobject_cast<HbProgressBar*>( widget ); |
|
80 |
|
81 // |
|
82 // position label |
|
83 // |
|
84 widget = loader->findWidget( QString( "positionLabel" ) ); |
|
85 mPositionLabel= qobject_cast<HbLabel*>( widget ); |
|
86 |
|
87 // |
|
88 // duration label |
|
89 // |
|
90 widget = loader->findWidget( QString( "durationLabel" ) ); |
|
91 mDurationLabel= qobject_cast<HbLabel*>( widget ); |
|
92 |
|
93 // |
|
94 // If we init the progress bar after pp sends the duration informatin |
|
95 // we need to set the duration manually |
|
96 // |
|
97 durationChanged( (qreal)mController->fileDetails()->mDuration / (qreal)KPbMilliMultiplier ); |
|
98 } |
|
99 } |
|
100 |
|
101 // ------------------------------------------------------------------------------------------------- |
|
102 // QMPXVideoPlaybackProgressBar::durationChanged |
|
103 // ------------------------------------------------------------------------------------------------- |
|
104 // |
|
105 void QMPXVideoPlaybackProgressBar::durationChanged( int duration ) |
|
106 { |
|
107 MPX_DEBUG(_L("QMPXVideoPlaybackControlsController::durationChanged duration = %d"), duration ); |
|
108 |
|
109 mDuration = duration; |
|
110 |
|
111 mDurationLabel->setPlainText( valueToReadableFormat( mDuration ) ); |
|
112 mProgressSlider->setRange( 0, mDuration ); |
|
113 } |
|
114 |
|
115 // ------------------------------------------------------------------------------------------------- |
|
116 // QMPXVideoPlaybackProgressBar::positionChanged |
|
117 // ------------------------------------------------------------------------------------------------- |
|
118 // |
|
119 void QMPXVideoPlaybackProgressBar::positionChanged( int position ) |
|
120 { |
|
121 MPX_DEBUG(_L("QMPXVideoPlaybackControlsController::positionChanged position = %d"), position ); |
|
122 |
|
123 // |
|
124 // While dragging event, don't update old position information from mpx framework |
|
125 // |
|
126 if ( ! mDragging ) |
|
127 { |
|
128 updatePostion( position ); |
|
129 } |
|
130 } |
|
131 |
|
132 // ------------------------------------------------------------------------------------------------- |
|
133 // QMPXVideoPlaybackProgressBar::updatePostion |
|
134 // ------------------------------------------------------------------------------------------------- |
|
135 // |
|
136 void QMPXVideoPlaybackProgressBar::updatePostion( int position ) |
|
137 { |
|
138 if ( position < 0 ) |
|
139 { |
|
140 position = 0; |
|
141 } |
|
142 else if ( position > mDuration ) |
|
143 { |
|
144 position = mDuration; |
|
145 } |
|
146 |
|
147 MPX_DEBUG(_L("QMPXVideoPlaybackControlsController::updatePostion position = %d"), position ); |
|
148 |
|
149 mPositionLabel->setPlainText( valueToReadableFormat( position ) ); |
|
150 mProgressSlider->setProgressValue( position ); |
|
151 } |
|
152 |
|
153 // ------------------------------------------------------------------------------------------------- |
|
154 // QMPXVideoPlaybackProgressBar::valueToReadableFormat |
|
155 // ------------------------------------------------------------------------------------------------- |
|
156 // |
|
157 QString QMPXVideoPlaybackProgressBar::valueToReadableFormat( int value ) |
|
158 { |
|
159 MPX_DEBUG(_L("QMPXVideoPlaybackControlsController::valueToReadableFormat value = %d"), value); |
|
160 |
|
161 int hour = value / 3600; |
|
162 value = value % 3600; |
|
163 int minutes = value / 60; |
|
164 value = value % 60; |
|
165 int second = value; |
|
166 |
|
167 QTime time( hour ,minutes ,second ); |
|
168 QString str; |
|
169 |
|
170 if ( hour == 0 ) |
|
171 { |
|
172 str = time.toString("mm:ss"); |
|
173 } |
|
174 else |
|
175 { |
|
176 str = time.toString("hh:mm:ss"); |
|
177 } |
|
178 |
|
179 return str; |
|
180 } |
|
181 |
|
182 // ------------------------------------------------------------------------------------------------- |
|
183 // QMPXVideoPlaybackProgressBar::mousePressEvent |
|
184 // ------------------------------------------------------------------------------------------------- |
|
185 // |
|
186 void QMPXVideoPlaybackProgressBar::mousePressEvent( QGraphicsSceneMouseEvent *event ) |
|
187 { |
|
188 MPX_DEBUG(_L("QMPXVideoPlaybackProgressBar::mousePressEvent()")); |
|
189 |
|
190 mDragging = true; |
|
191 |
|
192 mController->resetDisappearingTimers( EMPXTimerCancel ); |
|
193 |
|
194 // |
|
195 // Pause the playback if it's playing |
|
196 // |
|
197 if( mController->state() == EPbStatePlaying ) |
|
198 { |
|
199 mNeedToResumeAfterSetPosition = true; |
|
200 mController->handleCommand( EMPXPbvCmdCustomPause ); |
|
201 } |
|
202 |
|
203 event->accept(); |
|
204 } |
|
205 |
|
206 // ------------------------------------------------------------------------------------------------- |
|
207 // QMPXVideoPlaybackProgressBar::mouseReleaseEvent |
|
208 // ------------------------------------------------------------------------------------------------- |
|
209 // |
|
210 void QMPXVideoPlaybackProgressBar::mouseReleaseEvent( QGraphicsSceneMouseEvent *event ) |
|
211 { |
|
212 MPX_DEBUG(_L("QMPXVideoPlaybackProgressBar::mouseReleaseEvent()")); |
|
213 |
|
214 mDragging = false; |
|
215 |
|
216 mController->resetDisappearingTimers( EMPXTimerReset ); |
|
217 |
|
218 int position = |
|
219 (int)( ( event->scenePos().x() - mProgressSlider->geometry().x() ) / |
|
220 mProgressSlider->geometry().width() * (qreal)mDuration ); |
|
221 |
|
222 if ( position > mDuration ) |
|
223 { |
|
224 mController->handleCommand( EMPXPbvCmdEndOfClip ); |
|
225 } |
|
226 else |
|
227 { |
|
228 if ( position < 0 ) |
|
229 { |
|
230 position = 0; |
|
231 } |
|
232 |
|
233 mController->handleCommand( EMPXPbvCmdSetPosition, position ); |
|
234 |
|
235 // |
|
236 // Resume if it was playing |
|
237 // |
|
238 if( mNeedToResumeAfterSetPosition ) |
|
239 { |
|
240 mNeedToResumeAfterSetPosition = false; |
|
241 mController->handleCommand( EMPXPbvCmdCustomPlay ); |
|
242 } |
|
243 } |
|
244 |
|
245 event->accept(); |
|
246 } |
|
247 |
|
248 // ------------------------------------------------------------------------------------------------- |
|
249 // QMPXVideoPlaybackProgressBar::mouseMoveEvent |
|
250 // ------------------------------------------------------------------------------------------------- |
|
251 // |
|
252 void QMPXVideoPlaybackProgressBar::mouseMoveEvent( QGraphicsSceneMouseEvent *event ) |
|
253 { |
|
254 qreal result = |
|
255 ( event->scenePos().x() - mProgressSlider->geometry().x() ) / |
|
256 mProgressSlider->geometry().width() * (qreal)mDuration; |
|
257 |
|
258 updatePostion( result ); |
|
259 |
|
260 event->accept(); |
|
261 } |
|
262 |
|
263 // ------------------------------------------------------------------------------------------------- |
|
264 // QMPXVideoPlaybackProgressBar::updateWithFileDetails() |
|
265 // ------------------------------------------------------------------------------------------------- |
|
266 // |
|
267 void QMPXVideoPlaybackProgressBar::updateWithFileDetails( |
|
268 QMPXVideoPlaybackViewFileDetails* details ) |
|
269 { |
|
270 MPX_DEBUG(_L("QMPXVideoPlaybackProgressBar::updateControlsWithFileDetails()")); |
|
271 |
|
272 if ( details->mPlaybackMode == EMPXVideoLiveStreaming ) |
|
273 { |
|
274 setEnabled( false ); |
|
275 mDurationLabel->setPlainText( "Live" ); |
|
276 } |
|
277 else if ( details->mTvOutConnected && ! details->mTvOutPlayAllowed ) |
|
278 { |
|
279 setEnabled( false ); |
|
280 } |
|
281 else |
|
282 { |
|
283 setEnabled( true ); |
|
284 } |
|
285 } |
|
286 |
|
287 // ------------------------------------------------------------------------------------------------- |
|
288 // QMPXVideoPlaybackProgressBar::updateState() |
|
289 // ------------------------------------------------------------------------------------------------- |
|
290 // |
|
291 void QMPXVideoPlaybackProgressBar::updateState( TMPXPlaybackState state ) |
|
292 { |
|
293 MPX_DEBUG(_L("QMPXVideoPlaybackProgressBar::updateState() state = %d"), state ); |
|
294 |
|
295 if ( mController->viewMode() == EAudioOnlyView ) |
|
296 { |
|
297 switch ( state ) |
|
298 { |
|
299 case EPbStatePlaying: |
|
300 case EPbStatePaused: |
|
301 { |
|
302 updateWithFileDetails( mController->fileDetails() ); |
|
303 break; |
|
304 } |
|
305 case EPbStateNotInitialised: |
|
306 case EPbStateInitialising: |
|
307 case EPbStateBuffering: |
|
308 { |
|
309 setEnabled( false ); |
|
310 break; |
|
311 } |
|
312 } |
|
313 } |
|
314 } |
|
315 |
|
316 //End of file |