author | llornkcor <llornkcor> | 2004-09-18 11:42:01 (UTC) |
---|---|---|
committer | llornkcor <llornkcor> | 2004-09-18 11:42:01 (UTC) |
commit | d4e33108b974aa802f10d30a6a082adf67681224 (patch) (unidiff) | |
tree | 2c172af340d9bd4f7b85d4e42c33f8d190ef63f2 | |
parent | 35d96e2215c765da2270589c059c717a858333ca (diff) | |
download | opie-d4e33108b974aa802f10d30a6a082adf67681224.zip opie-d4e33108b974aa802f10d30a6a082adf67681224.tar.gz opie-d4e33108b974aa802f10d30a6a082adf67681224.tar.bz2 |
fix crash #1408
-rw-r--r-- | core/multimedia/opieplayer/videowidget.cpp | 158 |
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,290 +1,287 @@ | |||
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 | ||
43 | extern MediaPlayerState *mediaPlayerState; | 43 | extern MediaPlayerState *mediaPlayerState; |
44 | 44 | ||
45 | 45 | ||
46 | static const int xo = 2; // movable x offset | 46 | static const int xo = 2; // movable x offset |
47 | static const int yo = 0; // movable y offset | 47 | static const int yo = 0; // movable y offset |
48 | 48 | ||
49 | 49 | ||
50 | struct MediaButton { | 50 | struct 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) |
58 | MediaButton videoButtons[] = { | 58 | MediaButton 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 | ||
70 | const char *skinV_mask_file_names[7] = { | 70 | const 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 | ||
74 | static const int numVButtons = (sizeof(videoButtons)/sizeof(MediaButton)); | 74 | static const int numVButtons = (sizeof(videoButtons)/sizeof(MediaButton)); |
75 | 75 | ||
76 | VideoWidget::VideoWidget(QWidget* parent, const char* name, WFlags f) : | 76 | VideoWidget::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 | ||
166 | VideoWidget::~VideoWidget() { | 163 | VideoWidget::~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 | ||
189 | static bool videoSliderBeingMoved = FALSE; | 186 | static bool videoSliderBeingMoved = FALSE; |
190 | 187 | ||
191 | QPixmap *combineVImageWithBackground( QImage img, QPixmap bg, QPoint offset ) { | 188 | QPixmap *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 | ||
199 | QPixmap *maskVPixToMask( QPixmap pix, QBitmap mask ) { | 196 | QPixmap *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 | ||
205 | void VideoWidget::resizeEvent( QResizeEvent * ) { | 202 | void 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 | ||
243 | void VideoWidget::sliderPressed() { | 240 | void VideoWidget::sliderPressed() { |
244 | videoSliderBeingMoved = TRUE; | 241 | videoSliderBeingMoved = TRUE; |
245 | } | 242 | } |
246 | 243 | ||
247 | 244 | ||
248 | void VideoWidget::sliderReleased() { | 245 | void 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 | ||
257 | void VideoWidget::setPosition( long i ) { | 254 | void VideoWidget::setPosition( long i ) { |
258 | updateSlider( i, mediaPlayerState->length() ); | 255 | updateSlider( i, mediaPlayerState->length() ); |
259 | } | 256 | } |
260 | 257 | ||
261 | 258 | ||
262 | void VideoWidget::setLength( long max ) { | 259 | void VideoWidget::setLength( long max ) { |
263 | updateSlider( mediaPlayerState->position(), max ); | 260 | updateSlider( mediaPlayerState->position(), max ); |
264 | } | 261 | } |
265 | 262 | ||
266 | 263 | ||
267 | void VideoWidget::setView( char view ) { | 264 | void 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 | ||
282 | void VideoWidget::updateSlider( long i, long max ) { | 279 | void 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 ) |
@@ -347,312 +344,315 @@ void VideoWidget::mouseMoveEvent( QMouseEvent *event ) { | |||
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 | ||
396 | void VideoWidget::mousePressEvent( QMouseEvent *event ) { | 393 | void VideoWidget::mousePressEvent( QMouseEvent *event ) { |
397 | mouseMoveEvent( event ); | 394 | mouseMoveEvent( event ); |
398 | } | 395 | } |
399 | 396 | ||
400 | 397 | ||
401 | void VideoWidget::mouseReleaseEvent( QMouseEvent *event ) { | 398 | void 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 | ||
412 | void VideoWidget::makeVisible() { | 409 | void 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 | ||
430 | void VideoWidget::paintEvent( QPaintEvent * pe) { | 427 | void 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 | ||
459 | void VideoWidget::closeEvent( QCloseEvent* ) { | 456 | void VideoWidget::closeEvent( QCloseEvent* ) { |
460 | mediaPlayerState->setList(); | 457 | mediaPlayerState->setList(); |
461 | } | 458 | } |
462 | 459 | ||
463 | 460 | ||
464 | bool VideoWidget::playVideo() { | 461 | bool 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 | ||
628 | void VideoWidget::keyReleaseEvent( QKeyEvent *e) | 628 | void 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: |