Diffstat (limited to 'core/multimedia/opieplayer/videowidget.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | core/multimedia/opieplayer/videowidget.cpp | 363 |
1 files changed, 181 insertions, 182 deletions
diff --git a/core/multimedia/opieplayer/videowidget.cpp b/core/multimedia/opieplayer/videowidget.cpp index 12ae4fd..1f128a4 100644 --- a/core/multimedia/opieplayer/videowidget.cpp +++ b/core/multimedia/opieplayer/videowidget.cpp | |||
@@ -1,34 +1,33 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of the Qtopia Environment. | 4 | ** This file is part of Qtopia Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
7 | ** GNU General Public License version 2 as published by the Free Software | 7 | ** GNU General Public License version 2 as published by the Free Software |
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 <qpe/resource.h> | 20 | #include <qpe/resource.h> |
22 | #include <qpe/mediaplayerplugininterface.h> | 21 | #include "mediaplayerplugininterface.h" |
23 | #include <qwidget.h> | 22 | #include <qwidget.h> |
24 | #include <qpainter.h> | 23 | #include <qpainter.h> |
25 | #include <qpixmap.h> | 24 | #include <qpixmap.h> |
26 | #include <qslider.h> | 25 | #include <qslider.h> |
27 | #include <qdrawutil.h> | 26 | #include <qdrawutil.h> |
28 | #include "videowidget.h" | 27 | #include "videowidget.h" |
29 | #include "mediaplayerstate.h" | 28 | #include "mediaplayerstate.h" |
30 | 29 | ||
31 | 30 | ||
32 | #ifdef Q_WS_QWS | 31 | #ifdef Q_WS_QWS |
33 | # define USE_DIRECT_PAINTER | 32 | # define USE_DIRECT_PAINTER |
34 | # include <qdirectpainter_qws.h> | 33 | # include <qdirectpainter_qws.h> |
@@ -58,367 +57,367 @@ MediaButton videoButtons[] = { | |||
58 | { 5+3*32+xo, 200+yo, TRUE, FALSE, FALSE, 2 }, // pause | 57 | { 5+3*32+xo, 200+yo, TRUE, FALSE, FALSE, 2 }, // pause |
59 | { 5+4*32+xo, 200+yo, FALSE, FALSE, FALSE, 3 }, // next | 58 | { 5+4*32+xo, 200+yo, FALSE, FALSE, FALSE, 3 }, // next |
60 | { 5+5*32+xo, 200+yo, FALSE, FALSE, FALSE, 8 }, // playlist | 59 | { 5+5*32+xo, 200+yo, FALSE, FALSE, FALSE, 8 }, // playlist |
61 | { 5+6*32+xo, 200+yo, TRUE, FALSE, FALSE, 9 } // fullscreen | 60 | { 5+6*32+xo, 200+yo, TRUE, FALSE, FALSE, 9 } // fullscreen |
62 | }; | 61 | }; |
63 | 62 | ||
64 | 63 | ||
65 | static const int numButtons = (sizeof(videoButtons)/sizeof(MediaButton)); | 64 | static const int numButtons = (sizeof(videoButtons)/sizeof(MediaButton)); |
66 | 65 | ||
67 | 66 | ||
68 | VideoWidget::VideoWidget(QWidget* parent, const char* name, WFlags f) : | 67 | VideoWidget::VideoWidget(QWidget* parent, const char* name, WFlags f) : |
69 | QWidget( parent, name, f ), scaledWidth( 0 ), scaledHeight( 0 ) { | 68 | QWidget( parent, name, f ), scaledWidth( 0 ), scaledHeight( 0 ) { |
70 | setCaption( tr("MediaPlayer") ); | 69 | setCaption( tr("OpiePlayer") ); |
71 | setBackgroundPixmap( Resource::loadPixmap( "mpegplayer/metalFinish" ) ); | 70 | setBackgroundPixmap( Resource::loadPixmap( "mpegplayer/metalFinish" ) ); |
72 | pixmaps[0] = new QPixmap( Resource::loadPixmap( "mpegplayer/mediaButton0a" ) ); | 71 | pixmaps[0] = new QPixmap( Resource::loadPixmap( "mpegplayer/mediaButton0a" ) ); |
73 | pixmaps[1] = new QPixmap( Resource::loadPixmap( "mpegplayer/mediaButton0b" ) ); | 72 | pixmaps[1] = new QPixmap( Resource::loadPixmap( "mpegplayer/mediaButton0b" ) ); |
74 | pixmaps[2] = new QPixmap( Resource::loadPixmap( "mpegplayer/mediaControls0" ) ); | 73 | pixmaps[2] = new QPixmap( Resource::loadPixmap( "mpegplayer/mediaControls0" ) ); |
75 | currentFrame = new QImage( 220 + 2, 160, (QPixmap::defaultDepth() == 16) ? 16 : 32 ); | 74 | currentFrame = new QImage( 220 + 2, 160, (QPixmap::defaultDepth() == 16) ? 16 : 32 ); |
76 | 75 | ||
77 | slider = new QSlider( Qt::Horizontal, this ); | 76 | slider = new QSlider( Qt::Horizontal, this ); |
78 | slider->setMinValue( 0 ); | 77 | slider->setMinValue( 0 ); |
79 | slider->setMaxValue( 1 ); | 78 | slider->setMaxValue( 1 ); |
80 | slider->setBackgroundPixmap( Resource::loadPixmap( "mpegplayer/metalFinish" ) ); | 79 | slider->setBackgroundPixmap( Resource::loadPixmap( "mpegplayer/metalFinish" ) ); |
81 | slider->setFocusPolicy( QWidget::NoFocus ); | 80 | slider->setFocusPolicy( QWidget::NoFocus ); |
82 | slider->setGeometry( QRect( 7, 250, 220, 20 ) ); | 81 | slider->setGeometry( QRect( 7, 250, 220, 20 ) ); |
83 | 82 | ||
84 | connect( slider, SIGNAL( sliderPressed() ), this, SLOT( sliderPressed() ) ); | 83 | connect( slider, SIGNAL( sliderPressed() ), this, SLOT( sliderPressed() ) ); |
85 | connect( slider, SIGNAL( sliderReleased() ), this, SLOT( sliderReleased() ) ); | 84 | connect( slider, SIGNAL( sliderReleased() ), this, SLOT( sliderReleased() ) ); |
86 | 85 | ||
87 | connect( mediaPlayerState, SIGNAL( lengthChanged(long) ), this, SLOT( setLength(long) ) ); | 86 | connect( mediaPlayerState, SIGNAL( lengthChanged(long) ), this, SLOT( setLength(long) ) ); |
88 | connect( mediaPlayerState, SIGNAL( positionChanged(long) ),this, SLOT( setPosition(long) ) ); | 87 | connect( mediaPlayerState, SIGNAL( positionChanged(long) ),this, SLOT( setPosition(long) ) ); |
89 | connect( mediaPlayerState, SIGNAL( positionUpdated(long) ),this, SLOT( setPosition(long) ) ); | 88 | connect( mediaPlayerState, SIGNAL( positionUpdated(long) ),this, SLOT( setPosition(long) ) ); |
90 | connect( mediaPlayerState, SIGNAL( viewChanged(char) ), this, SLOT( setView(char) ) ); | 89 | connect( mediaPlayerState, SIGNAL( viewChanged(char) ), this, SLOT( setView(char) ) ); |
91 | connect( mediaPlayerState, SIGNAL( pausedToggled(bool) ), this, SLOT( setPaused(bool) ) ); | 90 | connect( mediaPlayerState, SIGNAL( pausedToggled(bool) ), this, SLOT( setPaused(bool) ) ); |
92 | connect( mediaPlayerState, SIGNAL( playingToggled(bool) ), this, SLOT( setPlaying(bool) ) ); | 91 | connect( mediaPlayerState, SIGNAL( playingToggled(bool) ), this, SLOT( setPlaying(bool) ) ); |
93 | 92 | ||
94 | // Intialise state | 93 | // Intialise state |
95 | setLength( mediaPlayerState->length() ); | 94 | setLength( mediaPlayerState->length() ); |
96 | setPosition( mediaPlayerState->position() ); | 95 | setPosition( mediaPlayerState->position() ); |
97 | setFullscreen( mediaPlayerState->fullscreen() ); | 96 | setFullscreen( mediaPlayerState->fullscreen() ); |
98 | setPaused( mediaPlayerState->paused() ); | 97 | setPaused( mediaPlayerState->paused() ); |
99 | setPlaying( mediaPlayerState->playing() ); | 98 | setPlaying( mediaPlayerState->playing() ); |
100 | } | 99 | } |
101 | 100 | ||
102 | 101 | ||
103 | VideoWidget::~VideoWidget() { | 102 | VideoWidget::~VideoWidget() { |
104 | for ( int i = 0; i < 3; i++ ) | 103 | for ( int i = 0; i < 3; i++ ) |
105 | delete pixmaps[i]; | 104 | delete pixmaps[i]; |
106 | delete currentFrame; | 105 | delete currentFrame; |
107 | } | 106 | } |
108 | 107 | ||
109 | 108 | ||
110 | static bool videoSliderBeingMoved = FALSE; | 109 | static bool videoSliderBeingMoved = FALSE; |
111 | 110 | ||
112 | 111 | ||
113 | void VideoWidget::sliderPressed() { | 112 | void VideoWidget::sliderPressed() { |
114 | videoSliderBeingMoved = TRUE; | 113 | videoSliderBeingMoved = TRUE; |
115 | } | 114 | } |
116 | 115 | ||
117 | 116 | ||
118 | void VideoWidget::sliderReleased() { | 117 | void VideoWidget::sliderReleased() { |
119 | videoSliderBeingMoved = FALSE; | 118 | videoSliderBeingMoved = FALSE; |
120 | if ( slider->width() == 0 ) | 119 | if ( slider->width() == 0 ) |
121 | return; | 120 | return; |
122 | long val = long((double)slider->value() * mediaPlayerState->length() / slider->width()); | 121 | long val = long((double)slider->value() * mediaPlayerState->length() / slider->width()); |
123 | mediaPlayerState->setPosition( val ); | 122 | mediaPlayerState->setPosition( val ); |
124 | } | 123 | } |
125 | 124 | ||
126 | 125 | ||
127 | void VideoWidget::setPosition( long i ) { | 126 | void VideoWidget::setPosition( long i ) { |
128 | updateSlider( i, mediaPlayerState->length() ); | 127 | updateSlider( i, mediaPlayerState->length() ); |
129 | } | 128 | } |
130 | 129 | ||
131 | 130 | ||
132 | void VideoWidget::setLength( long max ) { | 131 | void VideoWidget::setLength( long max ) { |
133 | updateSlider( mediaPlayerState->position(), max ); | 132 | updateSlider( mediaPlayerState->position(), max ); |
134 | } | 133 | } |
135 | 134 | ||
136 | 135 | ||
137 | void VideoWidget::setView( char view ) { | 136 | void VideoWidget::setView( char view ) { |
138 | if ( view == 'v' ) { | 137 | if ( view == 'v' ) { |
139 | makeVisible(); | 138 | makeVisible(); |
140 | } else { | 139 | } else { |
141 | // Effectively blank the view next time we show it so it looks nicer | 140 | // Effectively blank the view next time we show it so it looks nicer |
142 | scaledWidth = 0; | 141 | scaledWidth = 0; |
143 | scaledHeight = 0; | 142 | scaledHeight = 0; |
144 | hide(); | 143 | hide(); |
145 | } | 144 | } |
146 | } | 145 | } |
147 | 146 | ||
148 | 147 | ||
149 | void VideoWidget::updateSlider( long i, long max ) { | 148 | void VideoWidget::updateSlider( long i, long max ) { |
150 | // Will flicker too much if we don't do this | 149 | // Will flicker too much if we don't do this |
151 | if ( max == 0 ) | 150 | if ( max == 0 ) |
152 | return; | 151 | return; |
153 | int width = slider->width(); | 152 | int width = slider->width(); |
154 | int val = int((double)i * width / max); | 153 | int val = int((double)i * width / max); |
155 | if ( !mediaPlayerState->fullscreen() && !videoSliderBeingMoved ) { | 154 | if ( !mediaPlayerState->fullscreen() && !videoSliderBeingMoved ) { |
156 | if ( slider->value() != val ) | 155 | if ( slider->value() != val ) |
157 | slider->setValue( val ); | 156 | slider->setValue( val ); |
158 | if ( slider->maxValue() != width ) | 157 | if ( slider->maxValue() != width ) |
159 | slider->setMaxValue( width ); | 158 | slider->setMaxValue( width ); |
160 | } | 159 | } |
161 | } | 160 | } |
162 | 161 | ||
163 | 162 | ||
164 | void VideoWidget::setToggleButton( int i, bool down ) { | 163 | void VideoWidget::setToggleButton( int i, bool down ) { |
165 | if ( down != videoButtons[i].isDown ) | 164 | if ( down != videoButtons[i].isDown ) |
166 | toggleButton( i ); | 165 | toggleButton( i ); |
167 | } | 166 | } |
168 | 167 | ||
169 | 168 | ||
170 | void VideoWidget::toggleButton( int i ) { | 169 | void VideoWidget::toggleButton( int i ) { |
171 | videoButtons[i].isDown = !videoButtons[i].isDown; | 170 | videoButtons[i].isDown = !videoButtons[i].isDown; |
172 | QPainter p(this); | 171 | QPainter p(this); |
173 | paintButton ( &p, i ); | 172 | paintButton ( &p, i ); |
174 | } | 173 | } |
175 | 174 | ||
176 | 175 | ||
177 | void VideoWidget::paintButton( QPainter *p, int i ) { | 176 | void VideoWidget::paintButton( QPainter *p, int i ) { |
178 | int x = videoButtons[i].xPos; | 177 | int x = videoButtons[i].xPos; |
179 | int y = videoButtons[i].yPos; | 178 | int y = videoButtons[i].yPos; |
180 | int offset = 10 + videoButtons[i].isDown; | 179 | int offset = 10 + videoButtons[i].isDown; |
181 | p->drawPixmap( x, y, *pixmaps[videoButtons[i].isDown] ); | 180 | p->drawPixmap( x, y, *pixmaps[videoButtons[i].isDown] ); |
182 | p->drawPixmap( x + 1 + offset, y + offset, *pixmaps[2], 9 * videoButtons[i].controlType, 0, 9, 9 ); | 181 | p->drawPixmap( x + 1 + offset, y + offset, *pixmaps[2], 9 * videoButtons[i].controlType, 0, 9, 9 ); |
183 | } | 182 | } |
184 | 183 | ||
185 | 184 | ||
186 | void VideoWidget::mouseMoveEvent( QMouseEvent *event ) { | 185 | void VideoWidget::mouseMoveEvent( QMouseEvent *event ) { |
187 | for ( int i = 0; i < numButtons; i++ ) { | 186 | for ( int i = 0; i < numButtons; i++ ) { |
188 | int x = videoButtons[i].xPos; | 187 | int x = videoButtons[i].xPos; |
189 | int y = videoButtons[i].yPos; | 188 | int y = videoButtons[i].yPos; |
190 | if ( event->state() == QMouseEvent::LeftButton ) { | 189 | if ( event->state() == QMouseEvent::LeftButton ) { |
191 | // The test to see if the mouse click is inside the circular button or not | 190 | // The test to see if the mouse click is inside the circular button or not |
192 | // (compared with the radius squared to avoid a square-root of our distance) | 191 | // (compared with the radius squared to avoid a square-root of our distance) |
193 | int radius = 16; | 192 | int radius = 16; |
194 | QPoint center = QPoint( x + radius, y + radius ); | 193 | QPoint center = QPoint( x + radius, y + radius ); |
195 | QPoint dXY = center - event->pos(); | 194 | QPoint dXY = center - event->pos(); |
196 | int dist = dXY.x() * dXY.x() + dXY.y() * dXY.y(); | 195 | int dist = dXY.x() * dXY.x() + dXY.y() * dXY.y(); |
197 | bool isOnButton = dist <= (radius * radius); | 196 | bool isOnButton = dist <= (radius * radius); |
198 | if ( isOnButton != videoButtons[i].isHeld ) { | 197 | if ( isOnButton != videoButtons[i].isHeld ) { |
199 | videoButtons[i].isHeld = isOnButton; | 198 | videoButtons[i].isHeld = isOnButton; |
200 | toggleButton(i); | 199 | toggleButton(i); |
201 | } | 200 | } |
202 | } else { | 201 | } else { |
203 | if ( videoButtons[i].isHeld ) { | 202 | if ( videoButtons[i].isHeld ) { |
204 | videoButtons[i].isHeld = FALSE; | 203 | videoButtons[i].isHeld = FALSE; |
205 | if ( !videoButtons[i].isToggle ) | 204 | if ( !videoButtons[i].isToggle ) |
206 | setToggleButton( i, FALSE ); | 205 | setToggleButton( i, FALSE ); |
207 | switch (i) { | 206 | switch (i) { |
208 | case VideoPlay: mediaPlayerState->setPlaying(videoButtons[i].isDown); return; | 207 | case VideoPlay: mediaPlayerState->setPlaying(videoButtons[i].isDown); return; |
209 | case VideoStop: mediaPlayerState->setPlaying(FALSE); return; | 208 | case VideoStop: mediaPlayerState->setPlaying(FALSE); return; |
210 | case VideoPause: mediaPlayerState->setPaused(videoButtons[i].isDown); return; | 209 | case VideoPause: mediaPlayerState->setPaused(videoButtons[i].isDown); return; |
211 | case VideoNext: mediaPlayerState->setNext(); return; | 210 | case VideoNext: mediaPlayerState->setNext(); return; |
212 | case VideoPrevious: mediaPlayerState->setPrev(); return; | 211 | case VideoPrevious: mediaPlayerState->setPrev(); return; |
213 | case VideoPlayList: mediaPlayerState->setList(); return; | 212 | case VideoPlayList: mediaPlayerState->setList(); return; |
214 | case VideoFullscreen: mediaPlayerState->setFullscreen( TRUE ); makeVisible(); return; | 213 | case VideoFullscreen: mediaPlayerState->setFullscreen( TRUE ); makeVisible(); return; |
215 | } | 214 | } |
216 | } | 215 | } |
217 | } | 216 | } |
218 | } | 217 | } |
219 | } | 218 | } |
220 | 219 | ||
221 | 220 | ||
222 | void VideoWidget::mousePressEvent( QMouseEvent *event ) { | 221 | void VideoWidget::mousePressEvent( QMouseEvent *event ) { |
223 | mouseMoveEvent( event ); | 222 | mouseMoveEvent( event ); |
224 | } | 223 | } |
225 | 224 | ||
226 | 225 | ||
227 | void VideoWidget::mouseReleaseEvent( QMouseEvent *event ) { | 226 | void VideoWidget::mouseReleaseEvent( QMouseEvent *event ) { |
228 | if ( mediaPlayerState->fullscreen() ) { | 227 | if ( mediaPlayerState->fullscreen() ) { |
229 | mediaPlayerState->setFullscreen( FALSE ); | 228 | mediaPlayerState->setFullscreen( FALSE ); |
230 | makeVisible(); | 229 | makeVisible(); |
231 | } else { | 230 | } else { |
232 | mouseMoveEvent( event ); | 231 | mouseMoveEvent( event ); |
233 | } | 232 | } |
234 | } | 233 | } |
235 | 234 | ||
236 | 235 | ||
237 | void VideoWidget::makeVisible() { | 236 | void VideoWidget::makeVisible() { |
238 | if ( mediaPlayerState->fullscreen() ) { | 237 | if ( mediaPlayerState->fullscreen() ) { |
239 | setBackgroundMode( QWidget::NoBackground ); | 238 | setBackgroundMode( QWidget::NoBackground ); |
240 | showFullScreen(); | 239 | showFullScreen(); |
241 | resize( qApp->desktop()->size() ); | 240 | resize( qApp->desktop()->size() ); |
242 | slider->hide(); | 241 | slider->hide(); |
243 | } else { | 242 | } else { |
244 | setBackgroundPixmap( Resource::loadPixmap( "mpegplayer/metalFinish" ) ); | 243 | setBackgroundPixmap( Resource::loadPixmap( "mpegplayer/metalFinish" ) ); |
245 | showNormal(); | 244 | showNormal(); |
246 | showMaximized(); | 245 | showMaximized(); |
247 | slider->show(); | 246 | slider->show(); |
248 | } | 247 | } |
249 | } | 248 | } |
250 | 249 | ||
251 | 250 | ||
252 | void VideoWidget::paintEvent( QPaintEvent * ) { | 251 | void VideoWidget::paintEvent( QPaintEvent * ) { |
253 | QPainter p( this ); | 252 | QPainter p( this ); |
254 | 253 | ||
255 | if ( mediaPlayerState->fullscreen() ) { | 254 | if ( mediaPlayerState->fullscreen() ) { |
256 | // Clear the background | 255 | // Clear the background |
257 | p.setBrush( QBrush( Qt::black ) ); | 256 | p.setBrush( QBrush( Qt::black ) ); |
258 | p.drawRect( rect() ); | 257 | p.drawRect( rect() ); |
259 | 258 | ||
260 | // Draw the current frame | 259 | // Draw the current frame |
261 | //p.drawImage( ); // If using directpainter we won't have a copy except whats on the screen | 260 | //p.drawImage( ); // If using directpainter we won't have a copy except whats on the screen |
262 | } else { | 261 | } else { |
263 | // draw border | 262 | // draw border |
264 | qDrawShadePanel( &p, 4, 15, 230, 170, colorGroup(), TRUE, 5, NULL ); | 263 | qDrawShadePanel( &p, 4, 15, 230, 170, colorGroup(), TRUE, 5, NULL ); |
265 | 264 | ||
266 | // Clear the movie screen first | 265 | // Clear the movie screen first |
267 | p.setBrush( QBrush( Qt::black ) ); | 266 | p.setBrush( QBrush( Qt::black ) ); |
268 | p.drawRect( 9, 20, 220, 160 ); | 267 | p.drawRect( 9, 20, 220, 160 ); |
269 | 268 | ||
270 | // draw current frame (centrally positioned from scaling to maintain aspect ratio) | 269 | // draw current frame (centrally positioned from scaling to maintain aspect ratio) |
271 | p.drawImage( 9 + (220 - scaledWidth) / 2, 20 + (160 - scaledHeight) / 2, *currentFrame, 0, 0, scaledWidth, scaledHeight ); | 270 | p.drawImage( 9 + (220 - scaledWidth) / 2, 20 + (160 - scaledHeight) / 2, *currentFrame, 0, 0, scaledWidth, scaledHeight ); |
272 | 271 | ||
273 | // draw the buttons | 272 | // draw the buttons |
274 | for ( int i = 0; i < numButtons; i++ ) | 273 | for ( int i = 0; i < numButtons; i++ ) |
275 | paintButton( &p, i ); | 274 | paintButton( &p, i ); |
276 | 275 | ||
277 | // draw the slider | 276 | // draw the slider |
278 | slider->repaint( TRUE ); | 277 | slider->repaint( TRUE ); |
279 | } | 278 | } |
280 | } | 279 | } |
281 | 280 | ||
282 | 281 | ||
283 | void VideoWidget::closeEvent( QCloseEvent* ) { | 282 | void VideoWidget::closeEvent( QCloseEvent* ) { |
284 | mediaPlayerState->setList(); | 283 | mediaPlayerState->setList(); |
285 | } | 284 | } |
286 | 285 | ||
287 | 286 | ||
288 | bool VideoWidget::playVideo() { | 287 | bool VideoWidget::playVideo() { |
289 | bool result = FALSE; | 288 | bool result = FALSE; |
290 | 289 | ||
291 | int stream = 0; | 290 | int stream = 0; |
292 | 291 | ||
293 | int sw = mediaPlayerState->curDecoder()->videoWidth( stream ); | 292 | int sw = mediaPlayerState->curDecoder()->videoWidth( stream ); |
294 | int sh = mediaPlayerState->curDecoder()->videoHeight( stream ); | 293 | int sh = mediaPlayerState->curDecoder()->videoHeight( stream ); |
295 | int dd = QPixmap::defaultDepth(); | 294 | int dd = QPixmap::defaultDepth(); |
296 | int w = height(); | 295 | int w = height(); |
297 | int h = width(); | 296 | int h = width(); |
298 | 297 | ||
299 | ColorFormat format = (dd == 16) ? RGB565 : BGRA8888; | 298 | ColorFormat format = (dd == 16) ? RGB565 : BGRA8888; |
300 | 299 | ||
301 | if ( mediaPlayerState->fullscreen() ) { | 300 | if ( mediaPlayerState->fullscreen() ) { |
302 | #ifdef USE_DIRECT_PAINTER | 301 | #ifdef USE_DIRECT_PAINTER |
303 | QDirectPainter p(this); | 302 | QDirectPainter p(this); |
304 | 303 | ||
305 | if ( ( qt_screen->transformOrientation() == 3 ) && | 304 | if ( ( qt_screen->transformOrientation() == 3 ) && |
306 | ( ( dd == 16 ) || ( dd == 32 ) ) && ( p.numRects() == 1 ) ) { | 305 | ( ( dd == 16 ) || ( dd == 32 ) ) && ( p.numRects() == 1 ) ) { |
307 | 306 | ||
308 | w = 320; | 307 | w = 320; |
309 | h = 240; | 308 | h = 240; |
310 | 309 | ||
311 | if ( mediaPlayerState->scaled() ) { | 310 | if ( mediaPlayerState->scaled() ) { |
312 | // maintain aspect ratio | 311 | // maintain aspect ratio |
313 | if ( w * sh > sw * h ) | 312 | if ( w * sh > sw * h ) |
314 | w = sw * h / sh; | 313 | w = sw * h / sh; |
315 | else | 314 | else |
316 | h = sh * w / sw; | 315 | h = sh * w / sw; |
317 | } else { | 316 | } else { |
318 | w = sw; | 317 | w = sw; |
319 | h = sh; | 318 | h = sh; |
320 | } | 319 | } |
321 | 320 | ||
322 | w--; // we can't allow libmpeg to overwrite. | 321 | w--; // we can't allow libmpeg to overwrite. |
323 | QPoint roff = qt_screen->mapToDevice( p.offset(), QSize( qt_screen->width(), qt_screen->height() ) ); | 322 | QPoint roff = qt_screen->mapToDevice( p.offset(), QSize( qt_screen->width(), qt_screen->height() ) ); |
324 | 323 | ||
325 | int ox = roff.x() - height() + 2 + (height() - w) / 2; | 324 | int ox = roff.x() - height() + 2 + (height() - w) / 2; |
326 | int oy = roff.y() + (width() - h) / 2; | 325 | int oy = roff.y() + (width() - h) / 2; |
327 | int sx = 0, sy = 0; | 326 | int sx = 0, sy = 0; |
328 | 327 | ||
329 | uchar* fp = p.frameBuffer() + p.lineStep() * oy; | 328 | uchar* fp = p.frameBuffer() + p.lineStep() * oy; |
330 | fp += dd * ox / 8; | 329 | fp += dd * ox / 8; |
331 | uchar **jt = new uchar*[h]; | 330 | uchar **jt = new uchar*[h]; |
332 | for ( int i = h; i; i-- ) { | 331 | for ( int i = h; i; i-- ) { |
333 | jt[h - i] = fp; | 332 | jt[h - i] = fp; |
334 | fp += p.lineStep(); | 333 | fp += p.lineStep(); |
335 | } | 334 | } |
336 | 335 | ||
337 | result = mediaPlayerState->curDecoder()->videoReadScaledFrame( jt, sx, sy, sw, sh, w, h, format, 0) == 0; | 336 | result = mediaPlayerState->curDecoder()->videoReadScaledFrame( jt, sx, sy, sw, sh, w, h, format, 0) == 0; |
338 | 337 | ||
339 | delete [] jt; | 338 | delete [] jt; |
340 | } else { | 339 | } else { |
341 | #endif | 340 | #endif |
342 | QPainter p(this); | 341 | QPainter p(this); |
343 | 342 | ||
344 | w = 320; | 343 | w = 320; |
345 | h = 240; | 344 | h = 240; |
346 | 345 | ||
347 | if ( mediaPlayerState->scaled() ) { | 346 | if ( mediaPlayerState->scaled() ) { |
348 | // maintain aspect ratio | 347 | // maintain aspect ratio |
349 | if ( w * sh > sw * h ) | 348 | if ( w * sh > sw * h ) |
350 | w = sw * h / sh; | 349 | w = sw * h / sh; |
351 | else | 350 | else |
352 | h = sh * w / sw; | 351 | h = sh * w / sw; |
353 | } else { | 352 | } else { |
354 | w = sw; | 353 | w = sw; |
355 | h = sh; | 354 | h = sh; |
356 | } | 355 | } |
357 | 356 | ||
358 | int bytes = ( dd == 16 ) ? 2 : 4; | 357 | int bytes = ( dd == 16 ) ? 2 : 4; |
359 | QImage tempFrame( w, h, bytes << 3 ); | 358 | QImage tempFrame( w, h, bytes << 3 ); |
360 | result = mediaPlayerState->curDecoder()->videoReadScaledFrame( tempFrame.jumpTable(), | 359 | result = mediaPlayerState->curDecoder()->videoReadScaledFrame( tempFrame.jumpTable(), |
361 | 0, 0, sw, sh, w, h, format, 0) == 0; | 360 | 0, 0, sw, sh, w, h, format, 0) == 0; |
362 | if ( result && mediaPlayerState->fullscreen() ) { | 361 | if ( result && mediaPlayerState->fullscreen() ) { |
363 | 362 | ||
364 | int rw = h, rh = w; | 363 | int rw = h, rh = w; |
365 | QImage rotatedFrame( rw, rh, bytes << 3 ); | 364 | QImage rotatedFrame( rw, rh, bytes << 3 ); |
366 | 365 | ||
367 | ushort* in = (ushort*)tempFrame.bits(); | 366 | ushort* in = (ushort*)tempFrame.bits(); |
368 | ushort* out = (ushort*)rotatedFrame.bits(); | 367 | ushort* out = (ushort*)rotatedFrame.bits(); |
369 | int spl = rotatedFrame.bytesPerLine() / bytes; | 368 | int spl = rotatedFrame.bytesPerLine() / bytes; |
370 | for (int x=0; x<h; x++) { | 369 | for (int x=0; x<h; x++) { |
371 | if ( bytes == 2 ) { | 370 | if ( bytes == 2 ) { |
372 | ushort* lout = out++ + (w - 1)*spl; | 371 | ushort* lout = out++ + (w - 1)*spl; |
373 | for (int y=0; y<w; y++) { | 372 | for (int y=0; y<w; y++) { |
374 | *lout=*in++; | 373 | *lout=*in++; |
375 | lout-=spl; | 374 | lout-=spl; |
376 | } | 375 | } |
377 | } else { | 376 | } else { |
378 | ulong* lout = ((ulong *)out)++ + (w - 1)*spl; | 377 | ulong* lout = ((ulong *)out)++ + (w - 1)*spl; |
379 | for (int y=0; y<w; y++) { | 378 | for (int y=0; y<w; y++) { |
380 | *lout=*((ulong*)in)++; | 379 | *lout=*((ulong*)in)++; |
381 | lout-=spl; | 380 | lout-=spl; |
382 | } | 381 | } |
383 | } | 382 | } |
384 | } | 383 | } |
385 | 384 | ||
386 | p.drawImage( (240 - rw) / 2, (320 - rh) / 2, rotatedFrame, 0, 0, rw, rh ); | 385 | p.drawImage( (240 - rw) / 2, (320 - rh) / 2, rotatedFrame, 0, 0, rw, rh ); |
387 | } | 386 | } |
388 | #ifdef USE_DIRECT_PAINTER | 387 | #ifdef USE_DIRECT_PAINTER |
389 | } | 388 | } |
390 | #endif | 389 | #endif |
391 | } else { | 390 | } else { |
392 | 391 | ||
393 | w = 220; | 392 | w = 220; |
394 | h = 160; | 393 | h = 160; |
395 | 394 | ||
396 | // maintain aspect ratio | 395 | // maintain aspect ratio |
397 | if ( w * sh > sw * h ) | 396 | if ( w * sh > sw * h ) |
398 | w = sw * h / sh; | 397 | w = sw * h / sh; |
399 | else | 398 | else |
400 | h = sh * w / sw; | 399 | h = sh * w / sw; |
401 | 400 | ||
402 | result = mediaPlayerState->curDecoder()->videoReadScaledFrame( currentFrame->jumpTable(), 0, 0, sw, sh, w, h, format, 0) == 0; | 401 | result = mediaPlayerState->curDecoder()->videoReadScaledFrame( currentFrame->jumpTable(), 0, 0, sw, sh, w, h, format, 0) == 0; |
403 | 402 | ||
404 | QPainter p( this ); | 403 | QPainter p( this ); |
405 | 404 | ||
406 | // Image changed size, therefore need to blank the possibly unpainted regions first | 405 | // Image changed size, therefore need to blank the possibly unpainted regions first |
407 | if ( scaledWidth != w || scaledHeight != h ) { | 406 | if ( scaledWidth != w || scaledHeight != h ) { |
408 | p.setBrush( QBrush( Qt::black ) ); | 407 | p.setBrush( QBrush( Qt::black ) ); |
409 | p.drawRect( 9, 20, 220, 160 ); | 408 | p.drawRect( 9, 20, 220, 160 ); |
410 | } | 409 | } |
411 | 410 | ||
412 | scaledWidth = w; | 411 | scaledWidth = w; |
413 | scaledHeight = h; | 412 | scaledHeight = h; |
414 | 413 | ||
415 | if ( result ) { | 414 | if ( result ) { |
416 | p.drawImage( 9 + (220 - scaledWidth) / 2, 20 + (160 - scaledHeight) / 2, *currentFrame, 0, 0, scaledWidth, scaledHeight ); | 415 | p.drawImage( 9 + (220 - scaledWidth) / 2, 20 + (160 - scaledHeight) / 2, *currentFrame, 0, 0, scaledWidth, scaledHeight ); |
417 | } | 416 | } |
418 | 417 | ||
419 | } | 418 | } |
420 | 419 | ||
421 | return result; | 420 | return result; |
422 | } | 421 | } |
423 | 422 | ||
424 | 423 | ||