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
@@ -1,680 +1,680 @@
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 20
21#include "videowidget.h" 21#include "videowidget.h"
22#include "mediaplayerstate.h" 22#include "mediaplayerstate.h"
23 23
24/* OPIE */ 24/* OPIE */
25#include <qpe/resource.h> 25#include <qpe/resource.h>
26#include <qpe/mediaplayerplugininterface.h> 26#include <qpe/mediaplayerplugininterface.h>
27#include <qpe/config.h> 27#include <qpe/config.h>
28#include <qpe/qpeapplication.h> 28#include <qpe/qpeapplication.h>
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
211 slider->setFixedWidth( w - 20 ); 208 slider->setFixedWidth( w - 20 );
212 slider->setGeometry( QRect( 15, h - 22, w - 90, 20 ) ); 209 slider->setGeometry( QRect( 15, h - 22, w - 90, 20 ) );
213 slider->setBackgroundOrigin( QWidget::ParentOrigin ); 210 slider->setBackgroundOrigin( QWidget::ParentOrigin );
214 slider->setFocusPolicy( QWidget::NoFocus ); 211 slider->setFocusPolicy( QWidget::NoFocus );
215 slider->setBackgroundPixmap( *pixBg ); 212 slider->setBackgroundPixmap( *pixBg );
216 213
217 xoff = 0;// ( imgUp->width() ) / 2; 214 xoff = 0;// ( imgUp->width() ) / 2;
218 if(w>h) 215 if(w>h)
219 yoff = 0; 216 yoff = 0;
220 else 217 else
221 yoff = 185;//(( Vh - imgUp->height() ) / 2) - 10; 218 yoff = 185;//(( Vh - imgUp->height() ) / 2) - 10;
222 QPoint p( xoff, yoff ); 219 QPoint p( xoff, yoff );
223 220
224 QPixmap *pixUp = combineVImageWithBackground( *imgUp, *pixBg, p ); 221 QPixmap *pixUp = combineVImageWithBackground( *imgUp, *pixBg, p );
225 QPixmap *pixDn = combineVImageWithBackground( *imgDn, *pixBg, p ); 222 QPixmap *pixDn = combineVImageWithBackground( *imgDn, *pixBg, p );
226 223
227 for ( int i = 0; i < 7; i++ ) 224 for ( int i = 0; i < 7; i++ )
228 { 225 {
229 if ( !masks[i]->isNull() ) 226 if ( !masks[i]->isNull() )
230 { 227 {
231 delete buttonPixUp[i]; 228 delete buttonPixUp[i];
232 delete buttonPixDown[i]; 229 delete buttonPixDown[i];
233 buttonPixUp[i] = maskVPixToMask( *pixUp, *masks[i] ); 230 buttonPixUp[i] = maskVPixToMask( *pixUp, *masks[i] );
234 buttonPixDown[i] = maskVPixToMask( *pixDn, *masks[i] ); 231 buttonPixDown[i] = maskVPixToMask( *pixDn, *masks[i] );
235 } 232 }
236 } 233 }
237 234
238 delete pixUp; 235 delete pixUp;
239 delete pixDn; 236 delete pixDn;
240} 237}
241 238
242 239
243void VideoWidget::sliderPressed() { 240void VideoWidget::sliderPressed() {
244 videoSliderBeingMoved = TRUE; 241 videoSliderBeingMoved = TRUE;
245} 242}
246 243
247 244
248void VideoWidget::sliderReleased() { 245void VideoWidget::sliderReleased() {
249 videoSliderBeingMoved = FALSE; 246 videoSliderBeingMoved = FALSE;
250 if ( slider->width() == 0 ) 247 if ( slider->width() == 0 )
251 return; 248 return;
252 long val = long((double)slider->value() * mediaPlayerState->length() / slider->width()); 249 long val = long((double)slider->value() * mediaPlayerState->length() / slider->width());
253 mediaPlayerState->setPosition( val ); 250 mediaPlayerState->setPosition( val );
254} 251}
255 252
256 253
257void VideoWidget::setPosition( long i ) { 254void VideoWidget::setPosition( long i ) {
258 updateSlider( i, mediaPlayerState->length() ); 255 updateSlider( i, mediaPlayerState->length() );
259} 256}
260 257
261 258
262void VideoWidget::setLength( long max ) { 259void VideoWidget::setLength( long max ) {
263 updateSlider( mediaPlayerState->position(), max ); 260 updateSlider( mediaPlayerState->position(), max );
264} 261}
265 262
266 263
267void VideoWidget::setView( char view ) { 264void VideoWidget::setView( char view ) {
268 if ( view == 'v' ) 265 if ( view == 'v' )
269 { 266 {
270 makeVisible(); 267 makeVisible();
271 } 268 }
272 else 269 else
273 { 270 {
274 // Effectively blank the view next time we show it so it looks nicer 271 // Effectively blank the view next time we show it so it looks nicer
275 scaledWidth = 0; 272 scaledWidth = 0;
276 scaledHeight = 0; 273 scaledHeight = 0;
277 hide(); 274 hide();
278 } 275 }
279} 276}
280 277
281 278
282void VideoWidget::updateSlider( long i, long max ) { 279void VideoWidget::updateSlider( long i, long max ) {
283 // Will flicker too much if we don't do this 280 // Will flicker too much if we don't do this
284 if ( max == 0 ) 281 if ( max == 0 )
285 return; 282 return;
286 int width = slider->width(); 283 int width = slider->width();
287 int val = int((double)i * width / max); 284 int val = int((double)i * width / max);
288 if ( !mediaPlayerState->fullscreen() && !videoSliderBeingMoved ) 285 if ( !mediaPlayerState->fullscreen() && !videoSliderBeingMoved )
289 { 286 {
290 if ( slider->value() != val ) 287 if ( slider->value() != val )
291 slider->setValue( val ); 288 slider->setValue( val );
292 if ( slider->maxValue() != width ) 289 if ( slider->maxValue() != width )
293 slider->setMaxValue( width ); 290 slider->setMaxValue( width );
294 } 291 }
295} 292}
296 293
297 294
298void VideoWidget::setToggleButton( int i, bool down ) { 295void VideoWidget::setToggleButton( int i, bool down ) {
299 if ( down != videoButtons[i].isDown ) 296 if ( down != videoButtons[i].isDown )
300 toggleButton( i ); 297 toggleButton( i );
301} 298}
302 299
303 300
304void VideoWidget::toggleButton( int i ) { 301void VideoWidget::toggleButton( int i ) {
305 videoButtons[i].isDown = !videoButtons[i].isDown; 302 videoButtons[i].isDown = !videoButtons[i].isDown;
306 QPainter p(this); 303 QPainter p(this);
307 paintButton ( &p, i ); 304 paintButton ( &p, i );
308} 305}
309 306
310 307
311void VideoWidget::paintButton( QPainter *p, int i ) { 308void VideoWidget::paintButton( QPainter *p, int i ) {
312 if ( videoButtons[i].isDown ) 309 if ( videoButtons[i].isDown )
313 { 310 {
314 p->drawPixmap( xoff, yoff, *buttonPixDown[i] ); 311 p->drawPixmap( xoff, yoff, *buttonPixDown[i] );
315 } 312 }
316 else 313 else
317 { 314 {
318 p->drawPixmap( xoff, yoff, *buttonPixUp[i] ); 315 p->drawPixmap( xoff, yoff, *buttonPixUp[i] );
319 } 316 }
320} 317}
321 318
322 319
323void VideoWidget::mouseMoveEvent( QMouseEvent *event ) { 320void VideoWidget::mouseMoveEvent( QMouseEvent *event ) {
324 for ( int i = 0; i < numVButtons; i++ ) { 321 for ( int i = 0; i < numVButtons; i++ ) {
325 if ( event->state() == QMouseEvent::LeftButton ) { 322 if ( event->state() == QMouseEvent::LeftButton ) {
326 // The test to see if the mouse click is inside the button or not 323 // The test to see if the mouse click is inside the button or not
327 int x = event->pos().x() - xoff; 324 int x = event->pos().x() - xoff;
328 int y = event->pos().y() - yoff; 325 int y = event->pos().y() - yoff;
329 326
330 bool isOnButton = ( x > 0 && y > 0 && x < imgButtonMask->width() 327 bool isOnButton = ( x > 0 && y > 0 && x < imgButtonMask->width()
331 && y < imgButtonMask->height() 328 && y < imgButtonMask->height()
332 && imgButtonMask->pixelIndex( x, y ) == i + 1 ); 329 && imgButtonMask->pixelIndex( x, y ) == i + 1 );
333 330
334 if ( isOnButton && !videoButtons[i].isHeld ) { 331 if ( isOnButton && !videoButtons[i].isHeld ) {
335 videoButtons[i].isHeld = TRUE; 332 videoButtons[i].isHeld = TRUE;
336 toggleButton(i); 333 toggleButton(i);
337 334
338 switch (i) { 335 switch (i) {
339 case VideoVolUp: 336 case VideoVolUp:
340 emit moreClicked(); 337 emit moreClicked();
341 return; 338 return;
342 case VideoVolDown: 339 case VideoVolDown:
343 emit lessClicked(); 340 emit lessClicked();
344 return; 341 return;
345 } 342 }
346 } else if ( !isOnButton && videoButtons[i].isHeld ) { 343 } else if ( !isOnButton && videoButtons[i].isHeld ) {
347 videoButtons[i].isHeld = FALSE; 344 videoButtons[i].isHeld = FALSE;
348 toggleButton(i); 345 toggleButton(i);
349 } 346 }
350 } else { 347 } else {
351 348
352 if ( videoButtons[i].isHeld ) { 349 if ( videoButtons[i].isHeld ) {
353 videoButtons[i].isHeld = FALSE; 350 videoButtons[i].isHeld = FALSE;
354 if ( !videoButtons[i].isToggle ) { 351 if ( !videoButtons[i].isToggle ) {
355 setToggleButton( i, FALSE ); 352 setToggleButton( i, FALSE );
356 } 353 }
357 354
358 switch(i) { 355 switch(i) {
359 356
360 case VideoPlay: { 357 case VideoPlay: {
361 // odebug << "play" << oendl; 358 // odebug << "play" << oendl;
362 if( !mediaPlayerState->playing()) { 359 if( !mediaPlayerState->playing()) {
363 mediaPlayerState->setPlaying( true); 360 mediaPlayerState->setPlaying( true);
364 setToggleButton( i-1, false ); 361 setToggleButton( i-1, false );
365 setToggleButton( i, false ); 362 setToggleButton( i, false );
366 return; 363 return;
367 } 364 }
368 if( mediaPlayerState->isPaused ) { 365 if( mediaPlayerState->isPaused ) {
369 // odebug << "isPaused" << oendl; 366 // odebug << "isPaused" << oendl;
370 setToggleButton( i, FALSE ); 367 setToggleButton( i, FALSE );
371 mediaPlayerState->setPaused( FALSE ); 368 mediaPlayerState->setPaused( FALSE );
372 return; 369 return;
373 } else if( !mediaPlayerState->isPaused ) { 370 } else if( !mediaPlayerState->isPaused ) {
374 // odebug << "is not paused" << oendl; 371 // odebug << "is not paused" << oendl;
375 setToggleButton( i, TRUE ); 372 setToggleButton( i, TRUE );
376 mediaPlayerState->setPaused( TRUE ); 373 mediaPlayerState->setPaused( TRUE );
377 return; 374 return;
378 } else { 375 } else {
379 return; 376 return;
380 } 377 }
381 } 378 }
382 379
383 case VideoStop: mediaPlayerState->setPlaying( FALSE ); setToggleButton( i+1, true); setToggleButton( i, true ); return; 380 case VideoStop: mediaPlayerState->setPlaying( FALSE ); setToggleButton( i+1, true); setToggleButton( i, true ); return;
384 case VideoNext: mediaPlayerState->setNext(); return; 381 case VideoNext: mediaPlayerState->setNext(); return;
385 case VideoPrevious: mediaPlayerState->setPrev(); return; 382 case VideoPrevious: mediaPlayerState->setPrev(); return;
386 case VideoVolUp: emit moreReleased(); return; 383 case VideoVolUp: emit moreReleased(); return;
387 case VideoVolDown: emit lessReleased(); return; 384 case VideoVolDown: emit lessReleased(); return;
388 case VideoFullscreen: mediaPlayerState->setFullscreen( TRUE ); makeVisible(); return; 385 case VideoFullscreen: mediaPlayerState->setFullscreen( TRUE ); makeVisible(); return;
389 } 386 }
390 } 387 }
391 } 388 }
392 } 389 }
393} 390}
394 391
395 392
396void VideoWidget::mousePressEvent( QMouseEvent *event ) { 393void VideoWidget::mousePressEvent( QMouseEvent *event ) {
397 mouseMoveEvent( event ); 394 mouseMoveEvent( event );
398} 395}
399 396
400 397
401void VideoWidget::mouseReleaseEvent( QMouseEvent *event ) { 398void VideoWidget::mouseReleaseEvent( QMouseEvent *event ) {
402 if ( mediaPlayerState->fullscreen() ) 399 if ( mediaPlayerState->fullscreen() )
403 { 400 {
404 mediaPlayerState->setFullscreen( FALSE ); 401 mediaPlayerState->setFullscreen( FALSE );
405 makeVisible(); 402 makeVisible();
406 } 403 }
407 mouseMoveEvent( event ); 404 mouseMoveEvent( event );
408// } 405// }
409} 406}
410 407
411 408
412void VideoWidget::makeVisible() { 409void VideoWidget::makeVisible() {
413 if ( mediaPlayerState->fullscreen() ) 410 if ( mediaPlayerState->fullscreen() )
414 { 411 {
415 setBackgroundMode( QWidget::NoBackground ); 412 setBackgroundMode( QWidget::NoBackground );
416 showFullScreen(); 413 showFullScreen();
417 resize( qApp->desktop()->size() ); 414 resize( qApp->desktop()->size() );
418 slider->hide(); 415 slider->hide();
419 } 416 }
420 else 417 else
421 { 418 {
422 setBackgroundPixmap( *pixBg ); 419 setBackgroundPixmap( *pixBg );
423 showNormal(); 420 showNormal();
424 QPEApplication::showWidget( this ); 421 QPEApplication::showWidget( this );
425 slider->show(); 422 slider->show();
426 } 423 }
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++;
579 lout-=spl; 579 lout-=spl;
580 } 580 }
581 } 581 }
582 } 582 }
583 583
584 p.drawImage( (240 - rw) / 2, (320 - rh) / 2, rotatedFrame, 0, 0, rw, rh ); 584 p.drawImage( (240 - rw) / 2, (320 - rh) / 2, rotatedFrame, 0, 0, rw, rh );
585 } 585 }
586#ifdef USE_DIRECT_PAINTER 586#ifdef USE_DIRECT_PAINTER
587 } 587 }
588#endif 588#endif
589 } 589 }
590 else 590 else
591 { 591 {
592 592
593 w = 220; 593 w = 220;
594 h = 160; 594 h = 160;
595 595
596 // maintain aspect ratio 596 // maintain aspect ratio
597 if ( w * sh > sw * h ) 597 if ( w * sh > sw * h )
598 w = sw * h / sh; 598 w = sw * h / sh;
599 else 599 else
600 h = sh * w / sw; 600 h = sh * w / sw;
601 601
602 result = mediaPlayerState->curDecoder()->videoReadScaledFrame( currentFrame->jumpTable(), 0, 0, sw, sh, w, h, format, 0) == 0; 602 result = mediaPlayerState->curDecoder()->videoReadScaledFrame( currentFrame->jumpTable(), 0, 0, sw, sh, w, h, format, 0) == 0;
603 603
604 QPainter p( this ); 604 QPainter p( this );
605 int deskW = qApp->desktop()->width(); 605 int deskW = qApp->desktop()->width();
606 // Image changed size, therefore need to blank the possibly unpainted regions first 606 // Image changed size, therefore need to blank the possibly unpainted regions first
607 if ( scaledWidth != w || scaledHeight != h ) 607 if ( scaledWidth != w || scaledHeight != h )
608 { 608 {
609 p.setBrush( QBrush( Qt::black ) ); 609 p.setBrush( QBrush( Qt::black ) );
610 p.drawRect( ( deskW -scaledWidth)/2, 20, scaledWidth, 160 ); 610 p.drawRect( ( deskW -scaledWidth)/2, 20, scaledWidth, 160 );
611 } 611 }
612 612
613 scaledWidth = w; 613 scaledWidth = w;
614 scaledHeight = h; 614 scaledHeight = h;
615 615
616 if ( result ) 616 if ( result )
617 { 617 {
618 p.drawImage( (deskW - scaledWidth) / 2, 20 + (160 - scaledHeight) / 2, *currentFrame, 0, 0, scaledWidth, scaledHeight ); 618 p.drawImage( (deskW - scaledWidth) / 2, 20 + (160 - scaledHeight) / 2, *currentFrame, 0, 0, scaledWidth, scaledHeight );
619 } 619 }
620 620
621 } 621 }
622 622
623 return result; 623 return result;
624} 624}
625 625
626 626
627 627
628void VideoWidget::keyReleaseEvent( QKeyEvent *e) 628void VideoWidget::keyReleaseEvent( QKeyEvent *e)
629{ 629{
630 switch ( e->key() ) 630 switch ( e->key() )
631 { 631 {
632////////////////////////////// Zaurus keys 632////////////////////////////// Zaurus keys
633 case Key_Home: 633 case Key_Home:
634 break; 634 break;
635 case Key_F9: //activity 635 case Key_F9: //activity
636 break; 636 break;
637 case Key_F10: //contacts 637 case Key_F10: //contacts
638// hide(); 638// hide();
639 break; 639 break;
640 case Key_F11: //menu 640 case Key_F11: //menu
641 break; 641 break;
642 case Key_F12: //home 642 case Key_F12: //home
643 break; 643 break;
644 case Key_F13: //mail 644 case Key_F13: //mail
645 break; 645 break;
646 case Key_Space: 646 case Key_Space:
647 { 647 {
648 if(mediaPlayerState->playing()) 648 if(mediaPlayerState->playing())
649 { 649 {
650 mediaPlayerState->setPlaying(FALSE); 650 mediaPlayerState->setPlaying(FALSE);
651 } 651 }
652 else 652 else
653 { 653 {
654 mediaPlayerState->setPlaying(TRUE); 654 mediaPlayerState->setPlaying(TRUE);
655 } 655 }
656 } 656 }
657 break; 657 break;
658 case Key_Down: 658 case Key_Down:
659// toggleButton(6); 659// toggleButton(6);
660// emit lessClicked(); 660// emit lessClicked();
661// emit lessReleased(); 661// emit lessReleased();
662// toggleButton(6); 662// toggleButton(6);
663 break; 663 break;
664 case Key_Up: 664 case Key_Up:
665// toggleButton(5); 665// toggleButton(5);
666// emit moreClicked(); 666// emit moreClicked();
667// emit moreReleased(); 667// emit moreReleased();
668// toggleButton(5); 668// toggleButton(5);
669 break; 669 break;
670 case Key_Right: 670 case Key_Right:
671 mediaPlayerState->setNext(); 671 mediaPlayerState->setNext();
672 break; 672 break;
673 case Key_Left: 673 case Key_Left:
674 mediaPlayerState->setPrev(); 674 mediaPlayerState->setPrev();
675 break; 675 break;
676 case Key_Escape: 676 case Key_Escape:
677 break; 677 break;
678 678
679 }; 679 };
680} 680}