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