Diffstat (limited to 'core/multimedia/opieplayer/videowidget.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | core/multimedia/opieplayer/videowidget.cpp | 363 |
1 files changed, 181 insertions, 182 deletions
diff --git a/core/multimedia/opieplayer/videowidget.cpp b/core/multimedia/opieplayer/videowidget.cpp index 12ae4fd..1f128a4 100644 --- a/core/multimedia/opieplayer/videowidget.cpp +++ b/core/multimedia/opieplayer/videowidget.cpp | |||
@@ -1,5 +1,5 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of the Qtopia Environment. | 4 | ** This file is part of Qtopia Environment. |
5 | ** | 5 | ** |
@@ -19,5 +19,4 @@ | |||
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | |||
21 | #include <qpe/resource.h> | 20 | #include <qpe/resource.h> |
22 | #include <qpe/mediaplayerplugininterface.h> | 21 | #include "mediaplayerplugininterface.h" |
23 | #include <qwidget.h> | 22 | #include <qwidget.h> |
@@ -69,3 +68,3 @@ VideoWidget::VideoWidget(QWidget* parent, const char* name, WFlags f) : | |||
69 | QWidget( parent, name, f ), scaledWidth( 0 ), scaledHeight( 0 ) { | 68 | QWidget( parent, name, f ), scaledWidth( 0 ), scaledHeight( 0 ) { |
70 | setCaption( tr("MediaPlayer") ); | 69 | setCaption( tr("OpiePlayer") ); |
71 | setBackgroundPixmap( Resource::loadPixmap( "mpegplayer/metalFinish" ) ); | 70 | setBackgroundPixmap( Resource::loadPixmap( "mpegplayer/metalFinish" ) ); |
@@ -83,4 +82,4 @@ VideoWidget::VideoWidget(QWidget* parent, const char* name, WFlags f) : | |||
83 | 82 | ||
84 | connect( slider, SIGNAL( sliderPressed() ), this, SLOT( sliderPressed() ) ); | 83 | connect( slider, SIGNAL( sliderPressed() ), this, SLOT( sliderPressed() ) ); |
85 | connect( slider, SIGNAL( sliderReleased() ), this, SLOT( sliderReleased() ) ); | 84 | connect( slider, SIGNAL( sliderReleased() ), this, SLOT( sliderReleased() ) ); |
86 | 85 | ||
@@ -104,3 +103,3 @@ VideoWidget::~VideoWidget() { | |||
104 | for ( int i = 0; i < 3; i++ ) | 103 | for ( int i = 0; i < 3; i++ ) |
105 | delete pixmaps[i]; | 104 | delete pixmaps[i]; |
106 | delete currentFrame; | 105 | delete currentFrame; |
@@ -120,3 +119,3 @@ void VideoWidget::sliderReleased() { | |||
120 | if ( slider->width() == 0 ) | 119 | if ( slider->width() == 0 ) |
121 | return; | 120 | return; |
122 | long val = long((double)slider->value() * mediaPlayerState->length() / slider->width()); | 121 | long val = long((double)slider->value() * mediaPlayerState->length() / slider->width()); |
@@ -138,8 +137,8 @@ void VideoWidget::setView( char view ) { | |||
138 | if ( view == 'v' ) { | 137 | if ( view == 'v' ) { |
139 | makeVisible(); | 138 | makeVisible(); |
140 | } else { | 139 | } else { |
141 | // Effectively blank the view next time we show it so it looks nicer | 140 | // Effectively blank the view next time we show it so it looks nicer |
142 | scaledWidth = 0; | 141 | scaledWidth = 0; |
143 | scaledHeight = 0; | 142 | scaledHeight = 0; |
144 | hide(); | 143 | hide(); |
145 | } | 144 | } |
@@ -151,3 +150,3 @@ void VideoWidget::updateSlider( long i, long max ) { | |||
151 | if ( max == 0 ) | 150 | if ( max == 0 ) |
152 | return; | 151 | return; |
153 | int width = slider->width(); | 152 | int width = slider->width(); |
@@ -155,6 +154,6 @@ void VideoWidget::updateSlider( long i, long max ) { | |||
155 | if ( !mediaPlayerState->fullscreen() && !videoSliderBeingMoved ) { | 154 | if ( !mediaPlayerState->fullscreen() && !videoSliderBeingMoved ) { |
156 | if ( slider->value() != val ) | 155 | if ( slider->value() != val ) |
157 | slider->setValue( val ); | 156 | slider->setValue( val ); |
158 | if ( slider->maxValue() != width ) | 157 | if ( slider->maxValue() != width ) |
159 | slider->setMaxValue( width ); | 158 | slider->setMaxValue( width ); |
160 | } | 159 | } |
@@ -165,3 +164,3 @@ void VideoWidget::setToggleButton( int i, bool down ) { | |||
165 | if ( down != videoButtons[i].isDown ) | 164 | if ( down != videoButtons[i].isDown ) |
166 | toggleButton( i ); | 165 | toggleButton( i ); |
167 | } | 166 | } |
@@ -187,32 +186,32 @@ void VideoWidget::mouseMoveEvent( QMouseEvent *event ) { | |||
187 | for ( int i = 0; i < numButtons; i++ ) { | 186 | for ( int i = 0; i < numButtons; i++ ) { |
188 | int x = videoButtons[i].xPos; | 187 | int x = videoButtons[i].xPos; |
189 | int y = videoButtons[i].yPos; | 188 | int y = videoButtons[i].yPos; |
190 | if ( event->state() == QMouseEvent::LeftButton ) { | 189 | if ( event->state() == QMouseEvent::LeftButton ) { |
191 | // The test to see if the mouse click is inside the circular button or not | 190 | // The test to see if the mouse click is inside the circular button or not |
192 | // (compared with the radius squared to avoid a square-root of our distance) | 191 | // (compared with the radius squared to avoid a square-root of our distance) |
193 | int radius = 16; | 192 | int radius = 16; |
194 | QPoint center = QPoint( x + radius, y + radius ); | 193 | QPoint center = QPoint( x + radius, y + radius ); |
195 | QPoint dXY = center - event->pos(); | 194 | QPoint dXY = center - event->pos(); |
196 | int dist = dXY.x() * dXY.x() + dXY.y() * dXY.y(); | 195 | int dist = dXY.x() * dXY.x() + dXY.y() * dXY.y(); |
197 | bool isOnButton = dist <= (radius * radius); | 196 | bool isOnButton = dist <= (radius * radius); |
198 | if ( isOnButton != videoButtons[i].isHeld ) { | 197 | if ( isOnButton != videoButtons[i].isHeld ) { |
199 | videoButtons[i].isHeld = isOnButton; | 198 | videoButtons[i].isHeld = isOnButton; |
200 | toggleButton(i); | 199 | toggleButton(i); |
201 | } | 200 | } |
202 | } else { | 201 | } else { |
203 | if ( videoButtons[i].isHeld ) { | 202 | if ( videoButtons[i].isHeld ) { |
204 | videoButtons[i].isHeld = FALSE; | 203 | videoButtons[i].isHeld = FALSE; |
205 | if ( !videoButtons[i].isToggle ) | 204 | if ( !videoButtons[i].isToggle ) |
206 | setToggleButton( i, FALSE ); | 205 | setToggleButton( i, FALSE ); |
207 | switch (i) { | 206 | switch (i) { |
208 | case VideoPlay: mediaPlayerState->setPlaying(videoButtons[i].isDown); return; | 207 | case VideoPlay: mediaPlayerState->setPlaying(videoButtons[i].isDown); return; |
209 | case VideoStop: mediaPlayerState->setPlaying(FALSE); return; | 208 | case VideoStop: mediaPlayerState->setPlaying(FALSE); return; |
210 | case VideoPause: mediaPlayerState->setPaused(videoButtons[i].isDown); return; | 209 | case VideoPause: mediaPlayerState->setPaused(videoButtons[i].isDown); return; |
211 | case VideoNext: mediaPlayerState->setNext(); return; | 210 | case VideoNext: mediaPlayerState->setNext(); return; |
212 | case VideoPrevious: mediaPlayerState->setPrev(); return; | 211 | case VideoPrevious: mediaPlayerState->setPrev(); return; |
213 | case VideoPlayList: mediaPlayerState->setList(); return; | 212 | case VideoPlayList: mediaPlayerState->setList(); return; |
214 | case VideoFullscreen: mediaPlayerState->setFullscreen( TRUE ); makeVisible(); return; | 213 | case VideoFullscreen: mediaPlayerState->setFullscreen( TRUE ); makeVisible(); return; |
215 | } | 214 | } |
216 | } | 215 | } |
217 | } | 216 | } |
218 | } | 217 | } |
@@ -228,6 +227,6 @@ void VideoWidget::mouseReleaseEvent( QMouseEvent *event ) { | |||
228 | if ( mediaPlayerState->fullscreen() ) { | 227 | if ( mediaPlayerState->fullscreen() ) { |
229 | mediaPlayerState->setFullscreen( FALSE ); | 228 | mediaPlayerState->setFullscreen( FALSE ); |
230 | makeVisible(); | 229 | makeVisible(); |
231 | } else { | 230 | } else { |
232 | mouseMoveEvent( event ); | 231 | mouseMoveEvent( event ); |
233 | } | 232 | } |
@@ -238,11 +237,11 @@ void VideoWidget::makeVisible() { | |||
238 | if ( mediaPlayerState->fullscreen() ) { | 237 | if ( mediaPlayerState->fullscreen() ) { |
239 | setBackgroundMode( QWidget::NoBackground ); | 238 | setBackgroundMode( QWidget::NoBackground ); |
240 | showFullScreen(); | 239 | showFullScreen(); |
241 | resize( qApp->desktop()->size() ); | 240 | resize( qApp->desktop()->size() ); |
242 | slider->hide(); | 241 | slider->hide(); |
243 | } else { | 242 | } else { |
244 | setBackgroundPixmap( Resource::loadPixmap( "mpegplayer/metalFinish" ) ); | 243 | setBackgroundPixmap( Resource::loadPixmap( "mpegplayer/metalFinish" ) ); |
245 | showNormal(); | 244 | showNormal(); |
246 | showMaximized(); | 245 | showMaximized(); |
247 | slider->show(); | 246 | slider->show(); |
248 | } | 247 | } |
@@ -255,25 +254,25 @@ void VideoWidget::paintEvent( QPaintEvent * ) { | |||
255 | if ( mediaPlayerState->fullscreen() ) { | 254 | if ( mediaPlayerState->fullscreen() ) { |
256 | // Clear the background | 255 | // Clear the background |
257 | p.setBrush( QBrush( Qt::black ) ); | 256 | p.setBrush( QBrush( Qt::black ) ); |
258 | p.drawRect( rect() ); | 257 | p.drawRect( rect() ); |
259 | 258 | ||
260 | // Draw the current frame | 259 | // Draw the current frame |
261 | //p.drawImage( ); // If using directpainter we won't have a copy except whats on the screen | 260 | //p.drawImage( ); // If using directpainter we won't have a copy except whats on the screen |
262 | } else { | 261 | } else { |
263 | // draw border | 262 | // draw border |
264 | qDrawShadePanel( &p, 4, 15, 230, 170, colorGroup(), TRUE, 5, NULL ); | 263 | qDrawShadePanel( &p, 4, 15, 230, 170, colorGroup(), TRUE, 5, NULL ); |
265 | 264 | ||
266 | // Clear the movie screen first | 265 | // Clear the movie screen first |
267 | p.setBrush( QBrush( Qt::black ) ); | 266 | p.setBrush( QBrush( Qt::black ) ); |
268 | p.drawRect( 9, 20, 220, 160 ); | 267 | p.drawRect( 9, 20, 220, 160 ); |
269 | 268 | ||
270 | // draw current frame (centrally positioned from scaling to maintain aspect ratio) | 269 | // draw current frame (centrally positioned from scaling to maintain aspect ratio) |
271 | p.drawImage( 9 + (220 - scaledWidth) / 2, 20 + (160 - scaledHeight) / 2, *currentFrame, 0, 0, scaledWidth, scaledHeight ); | 270 | p.drawImage( 9 + (220 - scaledWidth) / 2, 20 + (160 - scaledHeight) / 2, *currentFrame, 0, 0, scaledWidth, scaledHeight ); |
272 | 271 | ||
273 | // draw the buttons | 272 | // draw the buttons |
274 | for ( int i = 0; i < numButtons; i++ ) | 273 | for ( int i = 0; i < numButtons; i++ ) |
275 | paintButton( &p, i ); | 274 | paintButton( &p, i ); |
276 | 275 | ||
277 | // draw the slider | 276 | // draw the slider |
278 | slider->repaint( TRUE ); | 277 | slider->repaint( TRUE ); |
279 | } | 278 | } |
@@ -302,89 +301,89 @@ bool VideoWidget::playVideo() { | |||
302 | #ifdef USE_DIRECT_PAINTER | 301 | #ifdef USE_DIRECT_PAINTER |
303 | QDirectPainter p(this); | 302 | QDirectPainter p(this); |
304 | 303 | ||
305 | if ( ( qt_screen->transformOrientation() == 3 ) && | 304 | if ( ( qt_screen->transformOrientation() == 3 ) && |
306 | ( ( dd == 16 ) || ( dd == 32 ) ) && ( p.numRects() == 1 ) ) { | 305 | ( ( dd == 16 ) || ( dd == 32 ) ) && ( p.numRects() == 1 ) ) { |
307 | 306 | ||
308 | w = 320; | 307 | w = 320; |
309 | h = 240; | 308 | h = 240; |
310 | 309 | ||
311 | if ( mediaPlayerState->scaled() ) { | 310 | if ( mediaPlayerState->scaled() ) { |
312 | // maintain aspect ratio | 311 | // maintain aspect ratio |
313 | if ( w * sh > sw * h ) | 312 | if ( w * sh > sw * h ) |
314 | w = sw * h / sh; | 313 | w = sw * h / sh; |
315 | else | 314 | else |
316 | h = sh * w / sw; | 315 | h = sh * w / sw; |
317 | } else { | 316 | } else { |
318 | w = sw; | 317 | w = sw; |
319 | h = sh; | 318 | h = sh; |
320 | } | 319 | } |
321 | 320 | ||
322 | w--; // we can't allow libmpeg to overwrite. | 321 | w--; // we can't allow libmpeg to overwrite. |
323 | QPoint roff = qt_screen->mapToDevice( p.offset(), QSize( qt_screen->width(), qt_screen->height() ) ); | 322 | QPoint roff = qt_screen->mapToDevice( p.offset(), QSize( qt_screen->width(), qt_screen->height() ) ); |
324 | 323 | ||
325 | int ox = roff.x() - height() + 2 + (height() - w) / 2; | 324 | int ox = roff.x() - height() + 2 + (height() - w) / 2; |
326 | int oy = roff.y() + (width() - h) / 2; | 325 | int oy = roff.y() + (width() - h) / 2; |
327 | int sx = 0, sy = 0; | 326 | int sx = 0, sy = 0; |
328 | 327 | ||
329 | uchar* fp = p.frameBuffer() + p.lineStep() * oy; | 328 | uchar* fp = p.frameBuffer() + p.lineStep() * oy; |
330 | fp += dd * ox / 8; | 329 | fp += dd * ox / 8; |
331 | uchar **jt = new uchar*[h]; | 330 | uchar **jt = new uchar*[h]; |
332 | for ( int i = h; i; i-- ) { | 331 | for ( int i = h; i; i-- ) { |
333 | jt[h - i] = fp; | 332 | jt[h - i] = fp; |
334 | fp += p.lineStep(); | 333 | fp += p.lineStep(); |
335 | } | 334 | } |
336 | 335 | ||
337 | result = mediaPlayerState->curDecoder()->videoReadScaledFrame( jt, sx, sy, sw, sh, w, h, format, 0) == 0; | 336 | result = mediaPlayerState->curDecoder()->videoReadScaledFrame( jt, sx, sy, sw, sh, w, h, format, 0) == 0; |
338 | 337 | ||
339 | delete [] jt; | 338 | delete [] jt; |
340 | } else { | 339 | } else { |
341 | #endif | 340 | #endif |
342 | QPainter p(this); | 341 | QPainter p(this); |
343 | 342 | ||
344 | w = 320; | 343 | w = 320; |
345 | h = 240; | 344 | h = 240; |
346 | 345 | ||
347 | if ( mediaPlayerState->scaled() ) { | 346 | if ( mediaPlayerState->scaled() ) { |
348 | // maintain aspect ratio | 347 | // maintain aspect ratio |
349 | if ( w * sh > sw * h ) | 348 | if ( w * sh > sw * h ) |
350 | w = sw * h / sh; | 349 | w = sw * h / sh; |
351 | else | 350 | else |
352 | h = sh * w / sw; | 351 | h = sh * w / sw; |
353 | } else { | 352 | } else { |
354 | w = sw; | 353 | w = sw; |
355 | h = sh; | 354 | h = sh; |
356 | } | 355 | } |
357 | 356 | ||
358 | int bytes = ( dd == 16 ) ? 2 : 4; | 357 | int bytes = ( dd == 16 ) ? 2 : 4; |
359 | QImage tempFrame( w, h, bytes << 3 ); | 358 | QImage tempFrame( w, h, bytes << 3 ); |
360 | result = mediaPlayerState->curDecoder()->videoReadScaledFrame( tempFrame.jumpTable(), | 359 | result = mediaPlayerState->curDecoder()->videoReadScaledFrame( tempFrame.jumpTable(), |
361 | 0, 0, sw, sh, w, h, format, 0) == 0; | 360 | 0, 0, sw, sh, w, h, format, 0) == 0; |
362 | if ( result && mediaPlayerState->fullscreen() ) { | 361 | if ( result && mediaPlayerState->fullscreen() ) { |
363 | 362 | ||
364 | int rw = h, rh = w; | 363 | int rw = h, rh = w; |
365 | QImage rotatedFrame( rw, rh, bytes << 3 ); | 364 | QImage rotatedFrame( rw, rh, bytes << 3 ); |
366 | 365 | ||
367 | ushort* in = (ushort*)tempFrame.bits(); | 366 | ushort* in = (ushort*)tempFrame.bits(); |
368 | ushort* out = (ushort*)rotatedFrame.bits(); | 367 | ushort* out = (ushort*)rotatedFrame.bits(); |
369 | int spl = rotatedFrame.bytesPerLine() / bytes; | 368 | int spl = rotatedFrame.bytesPerLine() / bytes; |
370 | for (int x=0; x<h; x++) { | 369 | for (int x=0; x<h; x++) { |
371 | if ( bytes == 2 ) { | 370 | if ( bytes == 2 ) { |
372 | ushort* lout = out++ + (w - 1)*spl; | 371 | ushort* lout = out++ + (w - 1)*spl; |
373 | for (int y=0; y<w; y++) { | 372 | for (int y=0; y<w; y++) { |
374 | *lout=*in++; | 373 | *lout=*in++; |
375 | lout-=spl; | 374 | lout-=spl; |
376 | } | 375 | } |
377 | } else { | 376 | } else { |
378 | ulong* lout = ((ulong *)out)++ + (w - 1)*spl; | 377 | ulong* lout = ((ulong *)out)++ + (w - 1)*spl; |
379 | for (int y=0; y<w; y++) { | 378 | for (int y=0; y<w; y++) { |
380 | *lout=*((ulong*)in)++; | 379 | *lout=*((ulong*)in)++; |
381 | lout-=spl; | 380 | lout-=spl; |
382 | } | 381 | } |
383 | } | 382 | } |
384 | } | 383 | } |
385 | 384 | ||
386 | p.drawImage( (240 - rw) / 2, (320 - rh) / 2, rotatedFrame, 0, 0, rw, rh ); | 385 | p.drawImage( (240 - rw) / 2, (320 - rh) / 2, rotatedFrame, 0, 0, rw, rh ); |
387 | } | 386 | } |
388 | #ifdef USE_DIRECT_PAINTER | 387 | #ifdef USE_DIRECT_PAINTER |
389 | } | 388 | } |
390 | #endif | 389 | #endif |
@@ -392,27 +391,27 @@ bool VideoWidget::playVideo() { | |||
392 | 391 | ||
393 | w = 220; | 392 | w = 220; |
394 | h = 160; | 393 | h = 160; |
395 | 394 | ||
396 | // maintain aspect ratio | 395 | // maintain aspect ratio |
397 | if ( w * sh > sw * h ) | 396 | if ( w * sh > sw * h ) |
398 | w = sw * h / sh; | 397 | w = sw * h / sh; |
399 | else | 398 | else |
400 | h = sh * w / sw; | 399 | h = sh * w / sw; |
401 | 400 | ||
402 | result = mediaPlayerState->curDecoder()->videoReadScaledFrame( currentFrame->jumpTable(), 0, 0, sw, sh, w, h, format, 0) == 0; | 401 | result = mediaPlayerState->curDecoder()->videoReadScaledFrame( currentFrame->jumpTable(), 0, 0, sw, sh, w, h, format, 0) == 0; |
403 | 402 | ||
404 | QPainter p( this ); | 403 | QPainter p( this ); |
405 | 404 | ||
406 | // Image changed size, therefore need to blank the possibly unpainted regions first | 405 | // Image changed size, therefore need to blank the possibly unpainted regions first |
407 | if ( scaledWidth != w || scaledHeight != h ) { | 406 | if ( scaledWidth != w || scaledHeight != h ) { |
408 | p.setBrush( QBrush( Qt::black ) ); | 407 | p.setBrush( QBrush( Qt::black ) ); |
409 | p.drawRect( 9, 20, 220, 160 ); | 408 | p.drawRect( 9, 20, 220, 160 ); |
410 | } | 409 | } |
411 | 410 | ||
412 | scaledWidth = w; | 411 | scaledWidth = w; |
413 | scaledHeight = h; | 412 | scaledHeight = h; |
414 | 413 | ||
415 | if ( result ) { | 414 | if ( result ) { |
416 | p.drawImage( 9 + (220 - scaledWidth) / 2, 20 + (160 - scaledHeight) / 2, *currentFrame, 0, 0, scaledWidth, scaledHeight ); | 415 | p.drawImage( 9 + (220 - scaledWidth) / 2, 20 + (160 - scaledHeight) / 2, *currentFrame, 0, 0, scaledWidth, scaledHeight ); |
417 | } | 416 | } |
418 | 417 | ||