Diffstat (limited to 'core/multimedia/opieplayer/videowidget.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | core/multimedia/opieplayer/videowidget.cpp | 39 |
1 files changed, 22 insertions, 17 deletions
diff --git a/core/multimedia/opieplayer/videowidget.cpp b/core/multimedia/opieplayer/videowidget.cpp index 164458b..e851044 100644 --- a/core/multimedia/opieplayer/videowidget.cpp +++ b/core/multimedia/opieplayer/videowidget.cpp | |||
@@ -1,52 +1,57 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of 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 |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | |||
21 | #include "videowidget.h" | ||
22 | #include "mediaplayerstate.h" | ||
23 | |||
24 | /* OPIE */ | ||
20 | #include <qpe/resource.h> | 25 | #include <qpe/resource.h> |
21 | #include <qpe/mediaplayerplugininterface.h> | 26 | #include <qpe/mediaplayerplugininterface.h> |
22 | #include <qpe/config.h> | 27 | #include <qpe/config.h> |
23 | #include <qpe/qpeapplication.h> | 28 | #include <qpe/qpeapplication.h> |
29 | #include <opie2/odebug.h> | ||
24 | 30 | ||
31 | /* QT */ | ||
25 | #include <qdir.h> | 32 | #include <qdir.h> |
26 | #include <qslider.h> | 33 | #include <qslider.h> |
27 | #include "videowidget.h" | ||
28 | #include "mediaplayerstate.h" | ||
29 | 34 | ||
30 | 35 | ||
31 | #ifdef Q_WS_QWS | 36 | #ifdef Q_WS_QWS |
32 | # define USE_DIRECT_PAINTER | 37 | # define USE_DIRECT_PAINTER |
33 | # include <qdirectpainter_qws.h> | 38 | # include <qdirectpainter_qws.h> |
34 | # include <qgfxraster_qws.h> | 39 | # include <qgfxraster_qws.h> |
35 | #endif | 40 | #endif |
36 | 41 | ||
37 | 42 | ||
38 | extern MediaPlayerState *mediaPlayerState; | 43 | extern MediaPlayerState *mediaPlayerState; |
39 | 44 | ||
40 | 45 | ||
41 | static const int xo = 2; // movable x offset | 46 | static const int xo = 2; // movable x offset |
42 | static const int yo = 0; // movable y offset | 47 | static const int yo = 0; // movable y offset |
43 | 48 | ||
44 | 49 | ||
45 | struct MediaButton { | 50 | struct MediaButton { |
46 | // int xPos, yPos; | 51 | // int xPos, yPos; |
47 | bool isToggle, isHeld, isDown; | 52 | bool isToggle, isHeld, isDown; |
48 | // int controlType; | 53 | // int controlType; |
49 | }; | 54 | }; |
50 | 55 | ||
51 | 56 | ||
52 | // 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) |
@@ -61,94 +66,94 @@ MediaButton videoButtons[] = { | |||
61 | }; | 66 | }; |
62 | 67 | ||
63 | //static const int numButtons = (sizeof(videoButtons)/sizeof(MediaButton)); | 68 | //static const int numButtons = (sizeof(videoButtons)/sizeof(MediaButton)); |
64 | 69 | ||
65 | const char *skinV_mask_file_names[7] = { | 70 | const char *skinV_mask_file_names[7] = { |
66 | "stop","play","back","fwd","up","down","full" | 71 | "stop","play","back","fwd","up","down","full" |
67 | }; | 72 | }; |
68 | 73 | ||
69 | static const int numVButtons = (sizeof(videoButtons)/sizeof(MediaButton)); | 74 | static const int numVButtons = (sizeof(videoButtons)/sizeof(MediaButton)); |
70 | 75 | ||
71 | VideoWidget::VideoWidget(QWidget* parent, const char* name, WFlags f) : | 76 | VideoWidget::VideoWidget(QWidget* parent, const char* name, WFlags f) : |
72 | QWidget( parent, name, f ), scaledWidth( 0 ), scaledHeight( 0 ) | 77 | QWidget( parent, name, f ), scaledWidth( 0 ), scaledHeight( 0 ) |
73 | { | 78 | { |
74 | setCaption( tr("OpiePlayer") ); | 79 | setCaption( tr("OpiePlayer") ); |
75 | Config cfg("OpiePlayer"); | 80 | Config cfg("OpiePlayer"); |
76 | 81 | ||
77 | cfg.setGroup("Options"); | 82 | cfg.setGroup("Options"); |
78 | skin = cfg.readEntry("Skin","default"); | 83 | skin = cfg.readEntry("Skin","default"); |
79 | 84 | ||
80 | QString skinPath; | 85 | QString skinPath; |
81 | skinPath = "opieplayer2/skins/" + skin; | 86 | skinPath = "opieplayer2/skins/" + skin; |
82 | if(!QDir(QString(getenv("OPIEDIR")) +"/pics/"+skinPath).exists()) | 87 | if(!QDir(QString(getenv("OPIEDIR")) +"/pics/"+skinPath).exists()) |
83 | skinPath = "opieplayer2/skins/default"; | 88 | skinPath = "opieplayer2/skins/default"; |
84 | 89 | ||
85 | // qDebug("skin path " + skinPath); | 90 | // odebug << "skin path " + skinPath << oendl; |
86 | 91 | ||
87 | // QString skinPath = "opieplayer2/skins/" + skin; | 92 | // QString skinPath = "opieplayer2/skins/" + skin; |
88 | 93 | ||
89 | pixBg = new QPixmap( Resource::loadPixmap( QString("%1/background").arg(skinPath) ) ); | 94 | pixBg = new QPixmap( Resource::loadPixmap( QString("%1/background").arg(skinPath) ) ); |
90 | imgUp = new QImage( Resource::loadImage( QString("%1/skinV_up").arg(skinPath) ) ); | 95 | imgUp = new QImage( Resource::loadImage( QString("%1/skinV_up").arg(skinPath) ) ); |
91 | imgDn = new QImage( Resource::loadImage( QString("%1/skinV_down").arg(skinPath) ) ); | 96 | imgDn = new QImage( Resource::loadImage( QString("%1/skinV_down").arg(skinPath) ) ); |
92 | 97 | ||
93 | imgButtonMask = new QImage( imgUp->width(), imgUp->height(), 8, 255 ); | 98 | imgButtonMask = new QImage( imgUp->width(), imgUp->height(), 8, 255 ); |
94 | imgButtonMask->fill( 0 ); | 99 | imgButtonMask->fill( 0 ); |
95 | 100 | ||
96 | for ( int i = 0; i < 7; i++ ) { | 101 | for ( int i = 0; i < 7; i++ ) { |
97 | QString filename = QString( QPEApplication::qpeDir() + "/pics/" + skinPath + | 102 | QString filename = QString( QPEApplication::qpeDir() + "/pics/" + skinPath + |
98 | "/skinV_mask_" + skinV_mask_file_names[i] + ".png" ); | 103 | "/skinV_mask_" + skinV_mask_file_names[i] + ".png" ); |
99 | // qDebug("loading "+filename); | 104 | // odebug << "loading "+filename << oendl; |
100 | masks[i] = new QBitmap( filename ); | 105 | masks[i] = new QBitmap( filename ); |
101 | 106 | ||
102 | if ( !masks[i]->isNull() ) { | 107 | if ( !masks[i]->isNull() ) { |
103 | QImage imgMask = masks[i]->convertToImage(); | 108 | QImage imgMask = masks[i]->convertToImage(); |
104 | uchar **dest = imgButtonMask->jumpTable(); | 109 | uchar **dest = imgButtonMask->jumpTable(); |
105 | for ( int y = 0; y < imgUp->height(); y++ ) { | 110 | for ( int y = 0; y < imgUp->height(); y++ ) { |
106 | uchar *line = dest[y]; | 111 | uchar *line = dest[y]; |
107 | for ( int x = 0; x < imgUp->width(); x++ ) { | 112 | for ( int x = 0; x < imgUp->width(); x++ ) { |
108 | if ( !qRed( imgMask.pixel( x, y ) ) ) | 113 | if ( !qRed( imgMask.pixel( x, y ) ) ) |
109 | line[x] = i + 1; | 114 | line[x] = i + 1; |
110 | } | 115 | } |
111 | } | 116 | } |
112 | } | 117 | } |
113 | } | 118 | } |
114 | // qDebug("finished loading first pics"); | 119 | // odebug << "finished loading first pics" << oendl; |
115 | for ( int i = 0; i < 7; i++ ) { | 120 | for ( int i = 0; i < 7; i++ ) { |
116 | buttonPixUp[i] = NULL; | 121 | buttonPixUp[i] = NULL; |
117 | buttonPixDown[i] = NULL; | 122 | buttonPixDown[i] = NULL; |
118 | } | 123 | } |
119 | 124 | ||
120 | 125 | ||
121 | QWidget *d = QApplication::desktop(); | 126 | QWidget *d = QApplication::desktop(); |
122 | int width = d->width(); | 127 | int width = d->width(); |
123 | int height = d->height(); | 128 | int height = d->height(); |
124 | 129 | ||
125 | if( (width != pixBg->width() ) || (height != pixBg->height() ) ) { | 130 | if( (width != pixBg->width() ) || (height != pixBg->height() ) ) { |
126 | // qDebug("<<<<<<<< scale image >>>>>>>>>>>>"); | 131 | // odebug << "<<<<<<<< scale image >>>>>>>>>>>>" << oendl; |
127 | QImage img; | 132 | QImage img; |
128 | img = pixBg->convertToImage(); | 133 | img = pixBg->convertToImage(); |
129 | pixBg->convertFromImage( img.smoothScale( width, height)); | 134 | pixBg->convertFromImage( img.smoothScale( width, height)); |
130 | } | 135 | } |
131 | setBackgroundPixmap( *pixBg ); | 136 | setBackgroundPixmap( *pixBg ); |
132 | 137 | ||
133 | currentFrame = new QImage( 220 + 2, 160, (QPixmap::defaultDepth() == 16) ? 16 : 32 ); | 138 | currentFrame = new QImage( 220 + 2, 160, (QPixmap::defaultDepth() == 16) ? 16 : 32 ); |
134 | 139 | ||
135 | slider = new QSlider( Qt::Horizontal, this ); | 140 | slider = new QSlider( Qt::Horizontal, this ); |
136 | slider->setMinValue( 0 ); | 141 | slider->setMinValue( 0 ); |
137 | slider->setMaxValue( 1 ); | 142 | slider->setMaxValue( 1 ); |
138 | slider->setBackgroundPixmap( Resource::loadPixmap( backgroundPix ) ); | 143 | slider->setBackgroundPixmap( Resource::loadPixmap( backgroundPix ) ); |
139 | slider->setFocusPolicy( QWidget::NoFocus ); | 144 | slider->setFocusPolicy( QWidget::NoFocus ); |
140 | // slider->setGeometry( QRect( 7, 250, 220, 20 ) ); | 145 | // slider->setGeometry( QRect( 7, 250, 220, 20 ) ); |
141 | 146 | ||
142 | connect( slider, SIGNAL( sliderPressed() ), this, SLOT( sliderPressed() ) ); | 147 | connect( slider, SIGNAL( sliderPressed() ), this, SLOT( sliderPressed() ) ); |
143 | connect( slider, SIGNAL( sliderReleased() ), this, SLOT( sliderReleased() ) ); | 148 | connect( slider, SIGNAL( sliderReleased() ), this, SLOT( sliderReleased() ) ); |
144 | 149 | ||
145 | connect( mediaPlayerState, SIGNAL( lengthChanged(long) ), this, SLOT( setLength(long) ) ); | 150 | connect( mediaPlayerState, SIGNAL( lengthChanged(long) ), this, SLOT( setLength(long) ) ); |
146 | connect( mediaPlayerState, SIGNAL( positionChanged(long) ),this, SLOT( setPosition(long) ) ); | 151 | connect( mediaPlayerState, SIGNAL( positionChanged(long) ),this, SLOT( setPosition(long) ) ); |
147 | connect( mediaPlayerState, SIGNAL( positionUpdated(long) ),this, SLOT( setPosition(long) ) ); | 152 | connect( mediaPlayerState, SIGNAL( positionUpdated(long) ),this, SLOT( setPosition(long) ) ); |
148 | connect( mediaPlayerState, SIGNAL( viewChanged(char) ), this, SLOT( setView(char) ) ); | 153 | connect( mediaPlayerState, SIGNAL( viewChanged(char) ), this, SLOT( setView(char) ) ); |
149 | // connect( mediaPlayerState, SIGNAL( pausedToggled(bool) ), this, SLOT( setPaused(bool) ) ); | 154 | // connect( mediaPlayerState, SIGNAL( pausedToggled(bool) ), this, SLOT( setPaused(bool) ) ); |
150 | connect( mediaPlayerState, SIGNAL( playingToggled(bool) ), this, SLOT( setPlaying(bool) ) ); | 155 | connect( mediaPlayerState, SIGNAL( playingToggled(bool) ), this, SLOT( setPlaying(bool) ) ); |
151 | 156 | ||
152 | // Intialise state | 157 | // Intialise state |
153 | setLength( mediaPlayerState->length() ); | 158 | setLength( mediaPlayerState->length() ); |
154 | setPosition( mediaPlayerState->position() ); | 159 | setPosition( mediaPlayerState->position() ); |
@@ -332,62 +337,62 @@ void VideoWidget::mouseMoveEvent( QMouseEvent *event ) { | |||
332 | 337 | ||
333 | switch (i) { | 338 | switch (i) { |
334 | case VideoVolUp: | 339 | case VideoVolUp: |
335 | emit moreClicked(); | 340 | emit moreClicked(); |
336 | return; | 341 | return; |
337 | case VideoVolDown: | 342 | case VideoVolDown: |
338 | emit lessClicked(); | 343 | emit lessClicked(); |
339 | return; | 344 | return; |
340 | } | 345 | } |
341 | } else if ( !isOnButton && videoButtons[i].isHeld ) { | 346 | } else if ( !isOnButton && videoButtons[i].isHeld ) { |
342 | videoButtons[i].isHeld = FALSE; | 347 | videoButtons[i].isHeld = FALSE; |
343 | toggleButton(i); | 348 | toggleButton(i); |
344 | } | 349 | } |
345 | } else { | 350 | } else { |
346 | 351 | ||
347 | if ( videoButtons[i].isHeld ) { | 352 | if ( videoButtons[i].isHeld ) { |
348 | videoButtons[i].isHeld = FALSE; | 353 | videoButtons[i].isHeld = FALSE; |
349 | if ( !videoButtons[i].isToggle ) { | 354 | if ( !videoButtons[i].isToggle ) { |
350 | setToggleButton( i, FALSE ); | 355 | setToggleButton( i, FALSE ); |
351 | } | 356 | } |
352 | 357 | ||
353 | switch(i) { | 358 | switch(i) { |
354 | 359 | ||
355 | case VideoPlay: { | 360 | case VideoPlay: { |
356 | // qDebug("play"); | 361 | // odebug << "play" << oendl; |
357 | if( !mediaPlayerState->playing()) { | 362 | if( !mediaPlayerState->playing()) { |
358 | mediaPlayerState->setPlaying( true); | 363 | mediaPlayerState->setPlaying( true); |
359 | setToggleButton( i-1, false ); | 364 | setToggleButton( i-1, false ); |
360 | setToggleButton( i, false ); | 365 | setToggleButton( i, false ); |
361 | return; | 366 | return; |
362 | } | 367 | } |
363 | if( mediaPlayerState->isPaused ) { | 368 | if( mediaPlayerState->isPaused ) { |
364 | // qDebug("isPaused"); | 369 | // odebug << "isPaused" << oendl; |
365 | setToggleButton( i, FALSE ); | 370 | setToggleButton( i, FALSE ); |
366 | mediaPlayerState->setPaused( FALSE ); | 371 | mediaPlayerState->setPaused( FALSE ); |
367 | return; | 372 | return; |
368 | } else if( !mediaPlayerState->isPaused ) { | 373 | } else if( !mediaPlayerState->isPaused ) { |
369 | // qDebug("is not paused"); | 374 | // odebug << "is not paused" << oendl; |
370 | setToggleButton( i, TRUE ); | 375 | setToggleButton( i, TRUE ); |
371 | mediaPlayerState->setPaused( TRUE ); | 376 | mediaPlayerState->setPaused( TRUE ); |
372 | return; | 377 | return; |
373 | } else { | 378 | } else { |
374 | return; | 379 | return; |
375 | } | 380 | } |
376 | } | 381 | } |
377 | 382 | ||
378 | case VideoStop: mediaPlayerState->setPlaying( FALSE ); setToggleButton( i+1, true); setToggleButton( i, true ); return; | 383 | case VideoStop: mediaPlayerState->setPlaying( FALSE ); setToggleButton( i+1, true); setToggleButton( i, true ); return; |
379 | case VideoNext: mediaPlayerState->setNext(); return; | 384 | case VideoNext: mediaPlayerState->setNext(); return; |
380 | case VideoPrevious: mediaPlayerState->setPrev(); return; | 385 | case VideoPrevious: mediaPlayerState->setPrev(); return; |
381 | case VideoVolUp: emit moreReleased(); return; | 386 | case VideoVolUp: emit moreReleased(); return; |
382 | case VideoVolDown: emit lessReleased(); return; | 387 | case VideoVolDown: emit lessReleased(); return; |
383 | case VideoFullscreen: mediaPlayerState->setFullscreen( TRUE ); makeVisible(); return; | 388 | case VideoFullscreen: mediaPlayerState->setFullscreen( TRUE ); makeVisible(); return; |
384 | } | 389 | } |
385 | } | 390 | } |
386 | } | 391 | } |
387 | } | 392 | } |
388 | } | 393 | } |
389 | 394 | ||
390 | 395 | ||
391 | void VideoWidget::mousePressEvent( QMouseEvent *event ) { | 396 | void VideoWidget::mousePressEvent( QMouseEvent *event ) { |
392 | mouseMoveEvent( event ); | 397 | mouseMoveEvent( event ); |
393 | } | 398 | } |
@@ -437,49 +442,49 @@ void VideoWidget::paintEvent( QPaintEvent * pe) { | |||
437 | p.translate( -pe->rect().topLeft().x(), -pe->rect().topLeft().y() ); | 442 | p.translate( -pe->rect().topLeft().x(), -pe->rect().topLeft().y() ); |
438 | p.drawTiledPixmap( pe->rect(), *pixBg, pe->rect().topLeft() ); | 443 | p.drawTiledPixmap( pe->rect(), *pixBg, pe->rect().topLeft() ); |
439 | for ( int i = 0; i < numVButtons; i++ ) { | 444 | for ( int i = 0; i < numVButtons; i++ ) { |
440 | paintButton( &p, i ); | 445 | paintButton( &p, i ); |
441 | } | 446 | } |
442 | QPainter p2( this ); | 447 | QPainter p2( this ); |
443 | p2.drawPixmap( pe->rect().topLeft(), pix ); | 448 | p2.drawPixmap( pe->rect().topLeft(), pix ); |
444 | } else { | 449 | } else { |
445 | QPainter p( this ); | 450 | QPainter p( this ); |
446 | for ( int i = 0; i < numVButtons; i++ ) | 451 | for ( int i = 0; i < numVButtons; i++ ) |
447 | paintButton( &p, i ); | 452 | paintButton( &p, i ); |
448 | } | 453 | } |
449 | slider->repaint( TRUE ); | 454 | slider->repaint( TRUE ); |
450 | } | 455 | } |
451 | } | 456 | } |
452 | 457 | ||
453 | 458 | ||
454 | void VideoWidget::closeEvent( QCloseEvent* ) { | 459 | void VideoWidget::closeEvent( QCloseEvent* ) { |
455 | mediaPlayerState->setList(); | 460 | mediaPlayerState->setList(); |
456 | } | 461 | } |
457 | 462 | ||
458 | 463 | ||
459 | bool VideoWidget::playVideo() { | 464 | bool VideoWidget::playVideo() { |
460 | bool result = FALSE; | 465 | bool result = FALSE; |
461 | // qDebug("<<<<<<<<<<<<<<<< play video"); | 466 | // odebug << "<<<<<<<<<<<<<<<< play video" << oendl; |
462 | int stream = 0; | 467 | int stream = 0; |
463 | 468 | ||
464 | int sw = mediaPlayerState->curDecoder()->videoWidth( stream ); | 469 | int sw = mediaPlayerState->curDecoder()->videoWidth( stream ); |
465 | int sh = mediaPlayerState->curDecoder()->videoHeight( stream ); | 470 | int sh = mediaPlayerState->curDecoder()->videoHeight( stream ); |
466 | int dd = QPixmap::defaultDepth(); | 471 | int dd = QPixmap::defaultDepth(); |
467 | int w = height(); | 472 | int w = height(); |
468 | int h = width(); | 473 | int h = width(); |
469 | 474 | ||
470 | ColorFormat format = (dd == 16) ? RGB565 : BGRA8888; | 475 | ColorFormat format = (dd == 16) ? RGB565 : BGRA8888; |
471 | 476 | ||
472 | if ( mediaPlayerState->fullscreen() ) | 477 | if ( mediaPlayerState->fullscreen() ) |
473 | { | 478 | { |
474 | #ifdef USE_DIRECT_PAINTER | 479 | #ifdef USE_DIRECT_PAINTER |
475 | QDirectPainter p(this); | 480 | QDirectPainter p(this); |
476 | 481 | ||
477 | if ( ( qt_screen->transformOrientation() == 3 ) && | 482 | if ( ( qt_screen->transformOrientation() == 3 ) && |
478 | ( ( dd == 16 ) || ( dd == 32 ) ) && ( p.numRects() == 1 ) ) | 483 | ( ( dd == 16 ) || ( dd == 32 ) ) && ( p.numRects() == 1 ) ) |
479 | { | 484 | { |
480 | 485 | ||
481 | w = 320; | 486 | w = 320; |
482 | h = 240; | 487 | h = 240; |
483 | 488 | ||
484 | if ( mediaPlayerState->scaled() ) | 489 | if ( mediaPlayerState->scaled() ) |
485 | { | 490 | { |