summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/multimedia/opieplayer/videowidget.cpp158
1 files changed, 79 insertions, 79 deletions
diff --git a/core/multimedia/opieplayer/videowidget.cpp b/core/multimedia/opieplayer/videowidget.cpp
index e851044..2396ed5 100644
--- a/core/multimedia/opieplayer/videowidget.cpp
+++ b/core/multimedia/opieplayer/videowidget.cpp
@@ -29,182 +29,179 @@
29#include <opie2/odebug.h> 29#include <opie2/odebug.h>
30 30
31/* QT */ 31/* QT */
32#include <qdir.h> 32#include <qdir.h>
33#include <qslider.h> 33#include <qslider.h>
34 34
35 35
36#ifdef Q_WS_QWS 36#ifdef Q_WS_QWS
37# define USE_DIRECT_PAINTER 37# define USE_DIRECT_PAINTER
38# include <qdirectpainter_qws.h> 38# include <qdirectpainter_qws.h>
39# include <qgfxraster_qws.h> 39# include <qgfxraster_qws.h>
40#endif 40#endif
41 41
42 42
43extern MediaPlayerState *mediaPlayerState; 43extern MediaPlayerState *mediaPlayerState;
44 44
45 45
46static const int xo = 2; // movable x offset 46static const int xo = 2; // movable x offset
47static const int yo = 0; // movable y offset 47static const int yo = 0; // movable y offset
48 48
49 49
50struct MediaButton { 50struct MediaButton {
51// int xPos, yPos; 51// int xPos, yPos;
52 bool isToggle, isHeld, isDown; 52 bool isToggle, isHeld, isDown;
53// int controlType; 53// int controlType;
54}; 54};
55 55
56 56
57// Layout information for the videoButtons (and if it is a toggle button or not) 57// Layout information for the videoButtons (and if it is a toggle button or not)
58MediaButton videoButtons[] = { 58MediaButton videoButtons[] = {
59 { FALSE, FALSE, FALSE }, // stop 59 { FALSE, FALSE, FALSE }, // stop
60 { FALSE, FALSE, FALSE }, // play 60 { FALSE, FALSE, FALSE }, // play
61 { FALSE, FALSE, FALSE }, // previous 61 { FALSE, FALSE, FALSE }, // previous
62 { FALSE, FALSE, FALSE }, // next 62 { FALSE, FALSE, FALSE }, // next
63 { FALSE, FALSE, FALSE }, // volUp 63 { FALSE, FALSE, FALSE }, // volUp
64 { FALSE, FALSE, FALSE }, // volDown 64 { FALSE, FALSE, FALSE }, // volDown
65 { TRUE, FALSE, FALSE } // fullscreen 65 { TRUE, FALSE, FALSE } // fullscreen
66}; 66};
67 67
68//static const int numButtons = (sizeof(videoButtons)/sizeof(MediaButton)); 68//static const int numButtons = (sizeof(videoButtons)/sizeof(MediaButton));
69 69
70const char *skinV_mask_file_names[7] = { 70const char *skinV_mask_file_names[7] = {
71 "stop","play","back","fwd","up","down","full" 71 "stop","play","back","fwd","up","down","full"
72}; 72};
73 73
74static const int numVButtons = (sizeof(videoButtons)/sizeof(MediaButton)); 74static const int numVButtons = (sizeof(videoButtons)/sizeof(MediaButton));
75 75
76VideoWidget::VideoWidget(QWidget* parent, const char* name, WFlags f) : 76VideoWidget::VideoWidget(QWidget* parent, const char* name, WFlags f) :
77 QWidget( parent, name, f ), scaledWidth( 0 ), scaledHeight( 0 ) 77 QWidget( parent, name, f ), scaledWidth( 0 ), scaledHeight( 0 )
78{ 78{
79 setCaption( tr("OpiePlayer") ); 79 setCaption( tr("OpiePlayer") );
80 Config cfg("OpiePlayer"); 80 Config cfg("OpiePlayer");
81 81
82 cfg.setGroup("Options"); 82 cfg.setGroup("Options");
83 skin = cfg.readEntry("Skin","default"); 83 skin = cfg.readEntry("Skin","default");
84 84
85 QString skinPath; 85 QString skinPath;
86 skinPath = "opieplayer2/skins/" + skin; 86 skinPath = "opieplayer2/skins/" + skin;
87 if(!QDir(QString(getenv("OPIEDIR")) +"/pics/"+skinPath).exists()) 87 if(!QDir(QString(getenv("OPIEDIR")) +"/pics/"+skinPath).exists())
88 skinPath = "opieplayer2/skins/default"; 88 skinPath = "opieplayer2/skins/default";
89 89
90 // odebug << "skin path " + skinPath << oendl;
91 90
92// QString skinPath = "opieplayer2/skins/" + skin; 91// QString skinPath = "opieplayer2/skins/" + skin;
93 92
94 pixBg = new QPixmap( Resource::loadPixmap( QString("%1/background").arg(skinPath) ) ); 93 pixBg = new QPixmap( Resource::loadPixmap( QString("%1/background").arg(skinPath) ) );
95 imgUp = new QImage( Resource::loadImage( QString("%1/skinV_up").arg(skinPath) ) ); 94 imgUp = new QImage( Resource::loadImage( QString("%1/skinV_up").arg(skinPath) ) );
96 imgDn = new QImage( Resource::loadImage( QString("%1/skinV_down").arg(skinPath) ) ); 95 imgDn = new QImage( Resource::loadImage( QString("%1/skinV_down").arg(skinPath) ) );
97 96
98 imgButtonMask = new QImage( imgUp->width(), imgUp->height(), 8, 255 ); 97 imgButtonMask = new QImage( imgUp->width(), imgUp->height(), 8, 255 );
99 imgButtonMask->fill( 0 ); 98 imgButtonMask->fill( 0 );
100 99
101 for ( int i = 0; i < 7; i++ ) { 100 for ( int i = 0; i < 7; i++ ) {
102 QString filename = QString( QPEApplication::qpeDir() + "/pics/" + skinPath + 101 QString filename = QString( QPEApplication::qpeDir() + "/pics/" + skinPath +
103 "/skinV_mask_" + skinV_mask_file_names[i] + ".png" ); 102 "/skinV_mask_" + skinV_mask_file_names[i] + ".png" );
104 // odebug << "loading "+filename << oendl; 103 // odebug << "loading "+filename << oendl;
105 masks[i] = new QBitmap( filename ); 104 masks[i] = new QBitmap( filename );
106 105
107 if ( !masks[i]->isNull() ) { 106 if ( !masks[i]->isNull() ) {
108 QImage imgMask = masks[i]->convertToImage(); 107 QImage imgMask = masks[i]->convertToImage();
109 uchar **dest = imgButtonMask->jumpTable(); 108 uchar **dest = imgButtonMask->jumpTable();
110 for ( int y = 0; y < imgUp->height(); y++ ) { 109 for ( int y = 0; y < imgUp->height(); y++ ) {
111 uchar *line = dest[y]; 110 uchar *line = dest[y];
112 for ( int x = 0; x < imgUp->width(); x++ ) { 111 for ( int x = 0; x < imgUp->width(); x++ ) {
113 if ( !qRed( imgMask.pixel( x, y ) ) ) 112 if ( !qRed( imgMask.pixel( x, y ) ) )
114 line[x] = i + 1; 113 line[x] = i + 1;
115 } 114 }
116 } 115 }
117 } 116 }
118 } 117 }
119 // odebug << "finished loading first pics" << oendl; 118 for ( int i = 0; i < 7; i++ ) {
120 for ( int i = 0; i < 7; i++ ) { 119 buttonPixUp[i] = NULL;
121 buttonPixUp[i] = NULL; 120 buttonPixDown[i] = NULL;
122 buttonPixDown[i] = NULL; 121 }
123 } 122
124 123 QWidget *d = QApplication::desktop();
125 124 int width = d->width();
126 QWidget *d = QApplication::desktop(); 125 int height = d->height();
127 int width = d->width(); 126
128 int height = d->height(); 127 if( (width != pixBg->width() ) || (height != pixBg->height() ) ) {
129 128 QImage img;
130 if( (width != pixBg->width() ) || (height != pixBg->height() ) ) { 129 img = pixBg->convertToImage();
131// odebug << "<<<<<<<< scale image >>>>>>>>>>>>" << oendl; 130 pixBg->convertFromImage( img.smoothScale( width, height));
132 QImage img; 131 }
133 img = pixBg->convertToImage(); 132
134 pixBg->convertFromImage( img.smoothScale( width, height)); 133 setBackgroundPixmap( *pixBg );
135 } 134 currentFrame = new QImage( 220 + 2, 160, (QPixmap::defaultDepth() == 16) ? 16 : 32 );
136 setBackgroundPixmap( *pixBg ); 135 slider = new QSlider( Qt::Horizontal, this );
137 136 slider->setMinValue( 0 );
138 currentFrame = new QImage( 220 + 2, 160, (QPixmap::defaultDepth() == 16) ? 16 : 32 ); 137 slider->setMaxValue( 1 );
139 138
140 slider = new QSlider( Qt::Horizontal, this ); 139 slider->setBackgroundPixmap( *pixBg );
141 slider->setMinValue( 0 ); 140 slider->setFocusPolicy( QWidget::NoFocus );
142 slider->setMaxValue( 1 );
143 slider->setBackgroundPixmap( Resource::loadPixmap( backgroundPix ) );
144 slider->setFocusPolicy( QWidget::NoFocus );
145// slider->setGeometry( QRect( 7, 250, 220, 20 ) ); 141// slider->setGeometry( QRect( 7, 250, 220, 20 ) );
146 142
147 connect( slider, SIGNAL( sliderPressed() ), this, SLOT( sliderPressed() ) ); 143 connect(slider,SIGNAL(sliderPressed()),this,SLOT(sliderPressed()));
148 connect( slider, SIGNAL( sliderReleased() ), this, SLOT( sliderReleased() ) ); 144 connect(slider,SIGNAL(sliderReleased()),this,SLOT(sliderReleased()));
149 145
150 connect( mediaPlayerState, SIGNAL( lengthChanged(long) ), this, SLOT( setLength(long) ) ); 146 connect(mediaPlayerState,SIGNAL(lengthChanged(long)),this,SLOT(setLength(long)));
151 connect( mediaPlayerState, SIGNAL( positionChanged(long) ),this, SLOT( setPosition(long) ) ); 147 connect(mediaPlayerState,SIGNAL(positionChanged(long)),this,SLOT(setPosition(long)));
152 connect( mediaPlayerState, SIGNAL( positionUpdated(long) ),this, SLOT( setPosition(long) ) ); 148 connect(mediaPlayerState,SIGNAL(positionUpdated(long)),this,SLOT(setPosition(long)));
153 connect( mediaPlayerState, SIGNAL( viewChanged(char) ), this, SLOT( setView(char) ) ); 149 connect(mediaPlayerState,SIGNAL(viewChanged(char)),this,SLOT(setView(char)));
154// connect( mediaPlayerState, SIGNAL( pausedToggled(bool) ), this, SLOT( setPaused(bool) ) ); 150// connect( mediaPlayerState, SIGNAL( pausedToggled(bool) ), this, SLOT( setPaused(bool) ) );
155 connect( mediaPlayerState, SIGNAL( playingToggled(bool) ), this, SLOT( setPlaying(bool) ) ); 151 connect(mediaPlayerState,SIGNAL(playingToggled(bool)),this,SLOT(setPlaying(bool)));
156 152
157 // Intialise state 153 // Intialise state
158 setLength( mediaPlayerState->length() ); 154 setLength( mediaPlayerState->length() );
159 setPosition( mediaPlayerState->position() ); 155 setPosition( mediaPlayerState->position() );
160 setFullscreen( mediaPlayerState->fullscreen() ); 156 setFullscreen( mediaPlayerState->fullscreen() );
161// setPaused( mediaPlayerState->paused() ); 157// setPlaying( mediaPlayerState->playing() );
162 setPlaying( mediaPlayerState->playing() ); 158 // if(this->x() < 0 || this->y() < 0)
159 // this->move(0,0);
163} 160}
164 161
165 162
166VideoWidget::~VideoWidget() { 163VideoWidget::~VideoWidget() {
167 164
168 for ( int i = 0; i < 7; i++ ) 165 for ( int i = 0; i < 7; i++ )
169 { 166 {
170 delete buttonPixUp[i]; 167 delete buttonPixUp[i];
171 delete buttonPixDown[i]; 168 delete buttonPixDown[i];
172 } 169 }
173 170
174 delete pixBg; 171 delete pixBg;
175 delete imgUp; 172 delete imgUp;
176 delete imgDn; 173 delete imgDn;
177 delete imgButtonMask; 174 delete imgButtonMask;
178 for ( int i = 0; i < 7; i++ ) 175 for ( int i = 0; i < 7; i++ )
179 { 176 {
180 delete masks[i]; 177 delete masks[i];
181 } 178 }
182 179
183// for ( int i = 0; i < 3; i++ ) 180// for ( int i = 0; i < 3; i++ )
184// delete pixmaps[i]; 181// delete pixmaps[i];
185// delete currentFrame; 182// delete currentFrame;
186} 183}
187 184
188 185
189static bool videoSliderBeingMoved = FALSE; 186static bool videoSliderBeingMoved = FALSE;
190 187
191QPixmap *combineVImageWithBackground( QImage img, QPixmap bg, QPoint offset ) { 188QPixmap *combineVImageWithBackground( QImage img, QPixmap bg, QPoint offset ) {
192 QPixmap pix( img.width(), img.height() ); 189 QPixmap pix( img.width(), img.height() );
193 QPainter p( &pix ); 190 QPainter p( &pix );
194 p.drawTiledPixmap( pix.rect(), bg, offset ); 191 p.drawTiledPixmap( pix.rect(), bg, offset );
195 p.drawImage( 0, 0, img ); 192 p.drawImage( 0, 0, img );
196 return new QPixmap( pix ); 193 return new QPixmap( pix );
197} 194}
198 195
199QPixmap *maskVPixToMask( QPixmap pix, QBitmap mask ) { 196QPixmap *maskVPixToMask( QPixmap pix, QBitmap mask ) {
200 QPixmap *pixmap = new QPixmap( pix ); 197 QPixmap *pixmap = new QPixmap( pix );
201 pixmap->setMask( mask ); 198 pixmap->setMask( mask );
202 return pixmap; 199 return pixmap;
203} 200}
204 201
205void VideoWidget::resizeEvent( QResizeEvent * ) { 202void VideoWidget::resizeEvent( QResizeEvent * ) {
206 int h = height(); 203 int h = height();
207 int w = width(); 204 int w = width();
208 //int Vh = 160; 205 //int Vh = 160;
209 //int Vw = 220; 206 //int Vw = 220;
210 207
@@ -427,152 +424,155 @@ void VideoWidget::makeVisible() {
427} 424}
428 425
429 426
430void VideoWidget::paintEvent( QPaintEvent * pe) { 427void VideoWidget::paintEvent( QPaintEvent * pe) {
431 QPainter p( this ); 428 QPainter p( this );
432 429
433 if ( mediaPlayerState->fullscreen() ) { 430 if ( mediaPlayerState->fullscreen() ) {
434 // Clear the background 431 // Clear the background
435 p.setBrush( QBrush( Qt::black ) ); 432 p.setBrush( QBrush( Qt::black ) );
436 p.drawRect( rect() ); 433 p.drawRect( rect() );
437 } else { 434 } else {
438 if ( !pe->erased() ) { 435 if ( !pe->erased() ) {
439 // Combine with background and double buffer 436 // Combine with background and double buffer
440 QPixmap pix( pe->rect().size() ); 437 QPixmap pix( pe->rect().size() );
441 QPainter p( &pix ); 438 QPainter p( &pix );
442 p.translate( -pe->rect().topLeft().x(), -pe->rect().topLeft().y() ); 439 p.translate( -pe->rect().topLeft().x(), -pe->rect().topLeft().y() );
443 p.drawTiledPixmap( pe->rect(), *pixBg, pe->rect().topLeft() ); 440 p.drawTiledPixmap( pe->rect(), *pixBg, pe->rect().topLeft() );
444 for ( int i = 0; i < numVButtons; i++ ) { 441 for ( int i = 0; i < numVButtons; i++ ) {
445 paintButton( &p, i ); 442 paintButton( &p, i );
446 } 443 }
447 QPainter p2( this ); 444 QPainter p2( this );
448 p2.drawPixmap( pe->rect().topLeft(), pix ); 445 p2.drawPixmap( pe->rect().topLeft(), pix );
449 } else { 446 } else {
450 QPainter p( this ); 447 QPainter p( this );
451 for ( int i = 0; i < numVButtons; i++ ) 448 for ( int i = 0; i < numVButtons; i++ )
452 paintButton( &p, i ); 449 paintButton( &p, i );
453 } 450 }
454 slider->repaint( TRUE ); 451 slider->repaint( TRUE );
455 } 452 }
456} 453}
457 454
458 455
459void VideoWidget::closeEvent( QCloseEvent* ) { 456void VideoWidget::closeEvent( QCloseEvent* ) {
460 mediaPlayerState->setList(); 457 mediaPlayerState->setList();
461} 458}
462 459
463 460
464bool VideoWidget::playVideo() { 461bool VideoWidget::playVideo() {
465 bool result = FALSE; 462 bool result = FALSE;
466// odebug << "<<<<<<<<<<<<<<<< play video" << oendl; 463// odebug << "<<<<<<<<<<<<<<<< play video" << oendl;
467 int stream = 0; 464 int stream = 0;
468 465
469 int sw = mediaPlayerState->curDecoder()->videoWidth( stream ); 466 int sw = mediaPlayerState->curDecoder()->videoWidth( stream );
470 int sh = mediaPlayerState->curDecoder()->videoHeight( stream ); 467 int sh = mediaPlayerState->curDecoder()->videoHeight( stream );
471 int dd = QPixmap::defaultDepth(); 468 int dd = QPixmap::defaultDepth();
472 int w = height(); 469 int w = height();
473 int h = width(); 470 int h = width();
474 471
472 QWidget *d = QApplication::desktop();
473 int d_width = d->width();
474 int d_height = d->height();
475
475 ColorFormat format = (dd == 16) ? RGB565 : BGRA8888; 476 ColorFormat format = (dd == 16) ? RGB565 : BGRA8888;
476 477
477 if ( mediaPlayerState->fullscreen() ) 478 if ( mediaPlayerState->fullscreen() )
478 { 479 {
479#ifdef USE_DIRECT_PAINTER 480#ifdef USE_DIRECT_PAINTER
480 QDirectPainter p(this); 481 QDirectPainter p(this);
481 482
482 if ( ( qt_screen->transformOrientation() == 3 ) && 483 if ( ( qt_screen->transformOrientation() == 3 ) &&
483 ( ( dd == 16 ) || ( dd == 32 ) ) && ( p.numRects() == 1 ) ) 484 ( ( dd == 16 ) || ( dd == 32 ) ) && ( p.numRects() == 1 ) )
484 { 485 {
485 486
486 w = 320; 487 w = d_width; //320;
487 h = 240; 488 h = d_height; //240;
488 489
489 if ( mediaPlayerState->scaled() ) 490 if ( mediaPlayerState->scaled() )
490 { 491 {
491 // maintain aspect ratio 492 // maintain aspect ratio
492 if ( w * sh > sw * h ) 493 if ( w * sh > sw * h )
493 w = sw * h / sh; 494 w = sw * h / sh;
494 else 495 else
495 h = sh * w / sw; 496 h = sh * w / sw;
496 } 497 }
497 else 498 else
498 { 499 {
499 w = sw; 500 w = sw;
500 h = sh; 501 h = sh;
501 } 502 }
502 503
503 w--; // we can't allow libmpeg to overwrite. 504 w--; // we can't allow libmpeg to overwrite.
504 QPoint roff = qt_screen->mapToDevice( p.offset(), QSize( qt_screen->width(), qt_screen->height() ) ); 505 QPoint roff = qt_screen->mapToDevice( p.offset(), QSize( qt_screen->width(), qt_screen->height() ) );
505 506
506 int ox = roff.x() - height() + 2 + (height() - w) / 2; 507 int ox = roff.x() - height() + 2 + (height() - w) / 2;
507 int oy = roff.y() + (width() - h) / 2; 508 int oy = roff.y() + (width() - h) / 2;
508 int sx = 0, sy = 0; 509 int sx = 0, sy = 0;
509 510
510 uchar* fp = p.frameBuffer() + p.lineStep() * oy; 511 uchar* fp = p.frameBuffer() + p.lineStep() * oy;
511 fp += dd * ox / 8; 512 fp += dd * ox / 8;
512 uchar **jt = new uchar*[h]; 513 uchar **jt = new uchar*[h];
513 514
514 for ( int i = h; i; i-- ) 515 for ( int i = h; i; i-- )
515 { 516 {
516 jt[h - i] = fp; 517 jt[h - i] = fp;
517 fp += p.lineStep(); 518 fp += p.lineStep();
518 } 519 }
519 520
520 result = mediaPlayerState->curDecoder()->videoReadScaledFrame( jt, sx, sy, sw, sh, w, h, format, 0) == 0; 521 result = mediaPlayerState->curDecoder()->videoReadScaledFrame( jt, sx, sy, sw, sh, w, h, format, 0) == 0;
521 522
522 delete [] jt; 523 delete [] jt;
523 } 524 }
524 else 525 else
525 { 526 {
526#endif 527#endif
527 QPainter p(this); 528 QPainter p(this);
528 529 w = d_width; //320;
529 w = 320; 530 h = d_height; //240;
530 h = 240;
531 531
532 if ( mediaPlayerState->scaled() ) 532 if ( mediaPlayerState->scaled() )
533 { 533 {
534 // maintain aspect ratio 534 // maintain aspect ratio
535 if ( w * sh > sw * h ) 535 if ( w * sh > sw * h )
536 w = sw * h / sh; 536 w = sw * h / sh;
537 else 537 else
538 h = sh * w / sw; 538 h = sh * w / sw;
539 } 539 }
540 else 540 else
541 { 541 {
542 w = sw; 542 w = sw;
543 h = sh; 543 h = sh;
544 } 544 }
545 545
546 int bytes = ( dd == 16 ) ? 2 : 4; 546 int bytes = ( dd == 16 ) ? 2 : 4;
547 QImage tempFrame( w, h, bytes << 3 ); 547 QImage tempFrame( w, h, bytes << 3 );
548 result = mediaPlayerState->curDecoder()->videoReadScaledFrame( tempFrame.jumpTable(), 548 result = mediaPlayerState->curDecoder()->videoReadScaledFrame( tempFrame.jumpTable(),
549 0, 0, sw, sh, w, h, format, 0) == 0; 549 0, 0, sw, sh, w, h, format, 0) == 0;
550 550
551 if ( result && mediaPlayerState->fullscreen() ) 551 if ( result && mediaPlayerState->fullscreen() )
552 { 552 {
553 553
554 int rw = h, rh = w; 554 int rw = h, rh = w;
555 QImage rotatedFrame( rw, rh, bytes << 3 ); 555 QImage rotatedFrame( rw, rh, bytes << 3 );
556 556
557 ushort* in = (ushort*)tempFrame.bits(); 557 ushort* in = (ushort*)tempFrame.bits();
558 ushort* out = (ushort*)rotatedFrame.bits(); 558 ushort* out = (ushort*)rotatedFrame.bits();
559 int spl = rotatedFrame.bytesPerLine() / bytes; 559 int spl = rotatedFrame.bytesPerLine() / bytes;
560 560
561 for (int x=0; x<h; x++) 561 for (int x=0; x<h; x++)
562 { 562 {
563 if ( bytes == 2 ) 563 if ( bytes == 2 )
564 { 564 {
565 ushort* lout = out++ + (w - 1)*spl; 565 ushort* lout = out++ + (w - 1)*spl;
566 for (int y=0; y<w; y++) { 566 for (int y=0; y<w; y++) {
567 *lout=*in++; 567 *lout=*in++;
568 lout-=spl; 568 lout-=spl;
569 } 569 }
570 } 570 }
571 else 571 else
572 { 572 {
573 ulong* _out = (ulong *)out; 573 ulong* _out = (ulong *)out;
574 ulong* lout = _out++ + (w - 1)*spl; 574 ulong* lout = _out++ + (w - 1)*spl;
575 for (int y=0; y<w; y++) 575 for (int y=0; y<w; y++)
576 { 576 {
577 ulong *_in = (ulong*)in; 577 ulong *_in = (ulong*)in;
578 *lout=*_in++; 578 *lout=*_in++;