summaryrefslogtreecommitdiff
path: root/core/multimedia/opieplayer/videowidget.cpp
authorllornkcor <llornkcor>2002-02-25 05:10:32 (UTC)
committer llornkcor <llornkcor>2002-02-25 05:10:32 (UTC)
commit1bebd27631a6c9d1ab967cbb32dd4e796b3b0402 (patch) (unidiff)
tree8ce49800cba26f6f2c33de74a71d4efe0338843f /core/multimedia/opieplayer/videowidget.cpp
parentd948361c1b475fab4660b28fbf5ec21fd34d923f (diff)
downloadopie-1bebd27631a6c9d1ab967cbb32dd4e796b3b0402.zip
opie-1bebd27631a6c9d1ab967cbb32dd4e796b3b0402.tar.gz
opie-1bebd27631a6c9d1ab967cbb32dd4e796b3b0402.tar.bz2
fixed 2
Diffstat (limited to 'core/multimedia/opieplayer/videowidget.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--core/multimedia/opieplayer/videowidget.cpp363
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,7 +1,7 @@
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**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
@@ -17,9 +17,8 @@
17** not clear to you. 17** not clear to you.
18** 18**
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>
24#include <qpainter.h> 23#include <qpainter.h>
25#include <qpixmap.h> 24#include <qpixmap.h>
@@ -67,7 +66,7 @@ static const int numButtons = (sizeof(videoButtons)/sizeof(MediaButton));
67 66
68VideoWidget::VideoWidget(QWidget* parent, const char* name, WFlags f) : 67VideoWidget::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" ) );
72 pixmaps[0] = new QPixmap( Resource::loadPixmap( "mpegplayer/mediaButton0a" ) ); 71 pixmaps[0] = new QPixmap( Resource::loadPixmap( "mpegplayer/mediaButton0a" ) );
73 pixmaps[1] = new QPixmap( Resource::loadPixmap( "mpegplayer/mediaButton0b" ) ); 72 pixmaps[1] = new QPixmap( Resource::loadPixmap( "mpegplayer/mediaButton0b" ) );
@@ -81,8 +80,8 @@ VideoWidget::VideoWidget(QWidget* parent, const char* name, WFlags f) :
81 slider->setFocusPolicy( QWidget::NoFocus ); 80 slider->setFocusPolicy( QWidget::NoFocus );
82 slider->setGeometry( QRect( 7, 250, 220, 20 ) ); 81 slider->setGeometry( QRect( 7, 250, 220, 20 ) );
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
87 connect( mediaPlayerState, SIGNAL( lengthChanged(long) ), this, SLOT( setLength(long) ) ); 86 connect( mediaPlayerState, SIGNAL( lengthChanged(long) ), this, SLOT( setLength(long) ) );
88 connect( mediaPlayerState, SIGNAL( positionChanged(long) ),this, SLOT( setPosition(long) ) ); 87 connect( mediaPlayerState, SIGNAL( positionChanged(long) ),this, SLOT( setPosition(long) ) );
@@ -102,7 +101,7 @@ VideoWidget::VideoWidget(QWidget* parent, const char* name, WFlags f) :
102 101
103VideoWidget::~VideoWidget() { 102VideoWidget::~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;
107} 106}
108 107
@@ -118,7 +117,7 @@ void VideoWidget::sliderPressed() {
118void VideoWidget::sliderReleased() { 117void VideoWidget::sliderReleased() {
119 videoSliderBeingMoved = FALSE; 118 videoSliderBeingMoved = FALSE;
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());
123 mediaPlayerState->setPosition( val ); 122 mediaPlayerState->setPosition( val );
124} 123}
@@ -136,12 +135,12 @@ void VideoWidget::setLength( long max ) {
136 135
137void VideoWidget::setView( char view ) { 136void 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 }
146} 145}
147 146
@@ -149,21 +148,21 @@ void VideoWidget::setView( char view ) {
149void VideoWidget::updateSlider( long i, long max ) { 148void VideoWidget::updateSlider( long i, long max ) {
150 // Will flicker too much if we don't do this 149 // Will flicker too much if we don't do this
151 if ( max == 0 ) 150 if ( max == 0 )
152 return; 151 return;
153 int width = slider->width(); 152 int width = slider->width();
154 int val = int((double)i * width / max); 153 int val = int((double)i * width / 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 }
161} 160}
162 161
163 162
164void VideoWidget::setToggleButton( int i, bool down ) { 163void 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}
168 167
169 168
@@ -185,36 +184,36 @@ void VideoWidget::paintButton( QPainter *p, int i ) {
185 184
186void VideoWidget::mouseMoveEvent( QMouseEvent *event ) { 185void 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 }
219} 218}
220 219
@@ -226,25 +225,25 @@ void VideoWidget::mousePressEvent( QMouseEvent *event ) {
226 225
227void VideoWidget::mouseReleaseEvent( QMouseEvent *event ) { 226void 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 }
234} 233}
235 234
236 235
237void VideoWidget::makeVisible() { 236void 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 }
249} 248}
250 249
@@ -253,29 +252,29 @@ void VideoWidget::paintEvent( QPaintEvent * ) {
253 QPainter p( this ); 252 QPainter p( this );
254 253
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 }
280} 279}
281 280
@@ -300,121 +299,121 @@ bool VideoWidget::playVideo() {
300 299
301 if ( mediaPlayerState->fullscreen() ) { 300 if ( mediaPlayerState->fullscreen() ) {
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
391 } else { 390 } else {
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
419 } 418 }
420 419