-rw-r--r-- | noncore/multimedia/opieplayer2/audiowidget.cpp | 21 |
1 files changed, 11 insertions, 10 deletions
diff --git a/noncore/multimedia/opieplayer2/audiowidget.cpp b/noncore/multimedia/opieplayer2/audiowidget.cpp index 6b656ee..dc90a62 100644 --- a/noncore/multimedia/opieplayer2/audiowidget.cpp +++ b/noncore/multimedia/opieplayer2/audiowidget.cpp | |||
@@ -176,275 +176,276 @@ AudioWidget::AudioWidget(QWidget* parent, const char* name, WFlags f) : | |||
176 | slider.setMinValue( 0 ); | 176 | slider.setMinValue( 0 ); |
177 | slider.setMaxValue( 1 ); | 177 | slider.setMaxValue( 1 ); |
178 | slider.setFocusPolicy( QWidget::NoFocus ); | 178 | slider.setFocusPolicy( QWidget::NoFocus ); |
179 | slider.setBackgroundPixmap( *pixBg ); | 179 | slider.setBackgroundPixmap( *pixBg ); |
180 | 180 | ||
181 | time.setFocusPolicy( QWidget::NoFocus ); | 181 | time.setFocusPolicy( QWidget::NoFocus ); |
182 | time.setAlignment( Qt::AlignCenter ); | 182 | time.setAlignment( Qt::AlignCenter ); |
183 | time.setFrame(FALSE); | 183 | time.setFrame(FALSE); |
184 | changeTextColor( &time ); | 184 | changeTextColor( &time ); |
185 | 185 | ||
186 | resizeEvent( NULL ); | 186 | resizeEvent( NULL ); |
187 | 187 | ||
188 | connect( &slider, SIGNAL( sliderPressed() ), this, SLOT( sliderPressed() ) ); | 188 | connect( &slider, SIGNAL( sliderPressed() ), this, SLOT( sliderPressed() ) ); |
189 | connect( &slider, SIGNAL( sliderReleased() ), this, SLOT( sliderReleased() ) ); | 189 | connect( &slider, SIGNAL( sliderReleased() ), this, SLOT( sliderReleased() ) ); |
190 | 190 | ||
191 | connect( mediaPlayerState, SIGNAL( lengthChanged(long) ), this, SLOT( setLength(long) ) ); | 191 | connect( mediaPlayerState, SIGNAL( lengthChanged(long) ), this, SLOT( setLength(long) ) ); |
192 | connect( mediaPlayerState, SIGNAL( viewChanged(char) ), this, SLOT( setView(char) ) ); | 192 | connect( mediaPlayerState, SIGNAL( viewChanged(char) ), this, SLOT( setView(char) ) ); |
193 | connect( mediaPlayerState, SIGNAL( loopingToggled(bool) ), this, SLOT( setLooping(bool) ) ); | 193 | connect( mediaPlayerState, SIGNAL( loopingToggled(bool) ), this, SLOT( setLooping(bool) ) ); |
194 | connect( mediaPlayerState, SIGNAL( pausedToggled(bool) ), this, SLOT( setPaused(bool) ) ); | 194 | connect( mediaPlayerState, SIGNAL( pausedToggled(bool) ), this, SLOT( setPaused(bool) ) ); |
195 | connect( mediaPlayerState, SIGNAL( playingToggled(bool) ), this, SLOT( setPlaying(bool) ) ); | 195 | connect( mediaPlayerState, SIGNAL( playingToggled(bool) ), this, SLOT( setPlaying(bool) ) ); |
196 | 196 | ||
197 | connect( this, SIGNAL( forwardClicked() ), this, SLOT( skipFor() ) ); | 197 | connect( this, SIGNAL( forwardClicked() ), this, SLOT( skipFor() ) ); |
198 | connect( this, SIGNAL( backClicked() ), this, SLOT( skipBack() ) ); | 198 | connect( this, SIGNAL( backClicked() ), this, SLOT( skipBack() ) ); |
199 | connect( this, SIGNAL( forwardReleased() ), this, SLOT( stopSkip() ) ); | 199 | connect( this, SIGNAL( forwardReleased() ), this, SLOT( stopSkip() ) ); |
200 | connect( this, SIGNAL( backReleased() ), this, SLOT( stopSkip() ) ); | 200 | connect( this, SIGNAL( backReleased() ), this, SLOT( stopSkip() ) ); |
201 | 201 | ||
202 | 202 | ||
203 | 203 | ||
204 | // Intialise state | 204 | // Intialise state |
205 | setLength( mediaPlayerState->length() ); | 205 | setLength( mediaPlayerState->length() ); |
206 | setPosition( mediaPlayerState->position() ); | 206 | setPosition( mediaPlayerState->position() ); |
207 | setLooping( mediaPlayerState->fullscreen() ); | 207 | setLooping( mediaPlayerState->fullscreen() ); |
208 | setPaused( mediaPlayerState->paused() ); | 208 | setPaused( mediaPlayerState->paused() ); |
209 | setPlaying( mediaPlayerState->playing() ); | 209 | setPlaying( mediaPlayerState->playing() ); |
210 | 210 | ||
211 | } | 211 | } |
212 | 212 | ||
213 | AudioWidget::~AudioWidget() { | 213 | AudioWidget::~AudioWidget() { |
214 | 214 | ||
215 | for ( int i = 0; i < 11; i++ ) { | 215 | for ( int i = 0; i < 11; i++ ) { |
216 | delete buttonPixUp[i]; | 216 | delete buttonPixUp[i]; |
217 | delete buttonPixDown[i]; | 217 | delete buttonPixDown[i]; |
218 | } | 218 | } |
219 | delete pixBg; | 219 | delete pixBg; |
220 | delete imgUp; | 220 | delete imgUp; |
221 | delete imgDn; | 221 | delete imgDn; |
222 | delete imgButtonMask; | 222 | delete imgButtonMask; |
223 | for ( int i = 0; i < 11; i++ ) { | 223 | for ( int i = 0; i < 11; i++ ) { |
224 | delete masks[i]; | 224 | delete masks[i]; |
225 | } | 225 | } |
226 | } | 226 | } |
227 | 227 | ||
228 | QPixmap *combineImageWithBackground( QImage img, QPixmap bg, QPoint offset ) { | 228 | QPixmap *combineImageWithBackground( QImage img, QPixmap bg, QPoint offset ) { |
229 | QPixmap pix( img.width(), img.height() ); | 229 | QPixmap pix( img.width(), img.height() ); |
230 | QPainter p( &pix ); | 230 | QPainter p( &pix ); |
231 | p.drawTiledPixmap( pix.rect(), bg, offset ); | 231 | p.drawTiledPixmap( pix.rect(), bg, offset ); |
232 | p.drawImage( 0, 0, img ); | 232 | p.drawImage( 0, 0, img ); |
233 | return new QPixmap( pix ); | 233 | return new QPixmap( pix ); |
234 | } | 234 | } |
235 | 235 | ||
236 | 236 | ||
237 | QPixmap *maskPixToMask( QPixmap pix, QBitmap mask ) | 237 | QPixmap *maskPixToMask( QPixmap pix, QBitmap mask ) |
238 | { | 238 | { |
239 | QPixmap *pixmap = new QPixmap( pix ); | 239 | QPixmap *pixmap = new QPixmap( pix ); |
240 | pixmap->setMask( mask ); | 240 | pixmap->setMask( mask ); |
241 | return pixmap; | 241 | return pixmap; |
242 | } | 242 | } |
243 | 243 | ||
244 | 244 | ||
245 | 245 | ||
246 | void AudioWidget::resizeEvent( QResizeEvent * ) { | 246 | void AudioWidget::resizeEvent( QResizeEvent * ) { |
247 | int h = height(); | 247 | int h = height(); |
248 | int w = width(); | 248 | int w = width(); |
249 | 249 | ||
250 | songInfo.setGeometry( QRect( 2, 10, w - 4, 20 ) ); | 250 | songInfo.setGeometry( QRect( 2, 10, w - 4, 20 ) ); |
251 | slider.setFixedWidth( w - 110 ); | 251 | slider.setFixedWidth( w - 110 ); |
252 | slider.setGeometry( QRect( 15, h - 30, w - 90, 20 ) ); | 252 | slider.setGeometry( QRect( 15, h - 30, w - 90, 20 ) ); |
253 | slider.setBackgroundOrigin( QWidget::ParentOrigin ); | 253 | slider.setBackgroundOrigin( QWidget::ParentOrigin ); |
254 | time.setGeometry( QRect( w - 85, h - 30, 70, 20 ) ); | 254 | time.setGeometry( QRect( w - 85, h - 30, 70, 20 ) ); |
255 | 255 | ||
256 | xoff = ( w - imgUp->width() ) / 2; | 256 | xoff = ( w - imgUp->width() ) / 2; |
257 | yoff = (( h - imgUp->height() ) / 2) - 10; | 257 | yoff = (( h - imgUp->height() ) / 2) - 10; |
258 | QPoint p( xoff, yoff ); | 258 | QPoint p( xoff, yoff ); |
259 | 259 | ||
260 | QPixmap *pixUp = combineImageWithBackground( *imgUp, *pixBg, p ); | 260 | QPixmap *pixUp = combineImageWithBackground( *imgUp, *pixBg, p ); |
261 | QPixmap *pixDn = combineImageWithBackground( *imgDn, *pixBg, p ); | 261 | QPixmap *pixDn = combineImageWithBackground( *imgDn, *pixBg, p ); |
262 | 262 | ||
263 | for ( int i = 0; i < 11; i++ ) { | 263 | for ( int i = 0; i < 11; i++ ) { |
264 | if ( !masks[i]->isNull() ) { | 264 | if ( !masks[i]->isNull() ) { |
265 | delete buttonPixUp[i]; | 265 | delete buttonPixUp[i]; |
266 | delete buttonPixDown[i]; | 266 | delete buttonPixDown[i]; |
267 | buttonPixUp[i] = maskPixToMask( *pixUp, *masks[i] ); | 267 | buttonPixUp[i] = maskPixToMask( *pixUp, *masks[i] ); |
268 | buttonPixDown[i] = maskPixToMask( *pixDn, *masks[i] ); | 268 | buttonPixDown[i] = maskPixToMask( *pixDn, *masks[i] ); |
269 | } | 269 | } |
270 | } | 270 | } |
271 | 271 | ||
272 | delete pixUp; | 272 | delete pixUp; |
273 | delete pixDn; | 273 | delete pixDn; |
274 | } | 274 | } |
275 | 275 | ||
276 | static bool audioSliderBeingMoved = FALSE; | 276 | static bool audioSliderBeingMoved = FALSE; |
277 | 277 | ||
278 | 278 | ||
279 | void AudioWidget::sliderPressed() { | 279 | void AudioWidget::sliderPressed() { |
280 | audioSliderBeingMoved = TRUE; | 280 | audioSliderBeingMoved = TRUE; |
281 | } | 281 | } |
282 | 282 | ||
283 | 283 | ||
284 | void AudioWidget::sliderReleased() { | 284 | void AudioWidget::sliderReleased() { |
285 | audioSliderBeingMoved = FALSE; | 285 | audioSliderBeingMoved = FALSE; |
286 | if ( slider.width() == 0 ) | 286 | if ( slider.width() == 0 ) |
287 | return; | 287 | return; |
288 | long val = long((double)slider.value() * mediaPlayerState->length() / slider.width()); | 288 | long val = long((double)slider.value() * mediaPlayerState->length() / slider.width()); |
289 | mediaPlayerState->setPosition( val ); | 289 | mediaPlayerState->setPosition( val ); |
290 | } | 290 | } |
291 | 291 | ||
292 | void AudioWidget::setPosition( long i ) { | 292 | void AudioWidget::setPosition( long i ) { |
293 | // qDebug("<<<<<<<<<<<<<<<<<<<<<<<<set position %d",i); | 293 | // qDebug("<<<<<<<<<<<<<<<<<<<<<<<<set position %d",i); |
294 | updateSlider( i, mediaPlayerState->length() ); | 294 | updateSlider( i, mediaPlayerState->length() ); |
295 | } | 295 | } |
296 | 296 | ||
297 | 297 | ||
298 | void AudioWidget::setLength( long max ) { | 298 | void AudioWidget::setLength( long max ) { |
299 | updateSlider( mediaPlayerState->position(), max ); | 299 | updateSlider( mediaPlayerState->position(), max ); |
300 | } | 300 | } |
301 | 301 | ||
302 | 302 | ||
303 | void AudioWidget::setView( char view ) { | 303 | void AudioWidget::setView( char view ) { |
304 | slider.show(); | ||
305 | 304 | ||
306 | // this isnt working for some reason | 305 | // this isnt working for some reason |
307 | 306 | ||
308 | // if ( mediaPlayerState->streaming() ) { | 307 | if ( mediaPlayerState->streaming() ) { |
309 | // qDebug("<<<<<<<<<<<<<<file is STREAMING>>>>>>>>>>>>>>>>>>>"); | 308 | qDebug("<<<<<<<<<<<<<<file is STREAMING>>>>>>>>>>>>>>>>>>>"); |
310 | // if( !slider.isHidden()) slider.hide(); | 309 | if( !slider.isHidden()) { |
311 | // disconnect( mediaPlayerState, SIGNAL( positionChanged(long) ),this, SLOT( setPosition(long) ) ); | 310 | slider.hide(); |
312 | // disconnect( mediaPlayerState, SIGNAL( positionUpdated(long) ),this, SLOT( setPosition(long) ) ); | 311 | } |
313 | // } else { | 312 | disconnect( mediaPlayerState, SIGNAL( positionChanged(long) ),this, SLOT( setPosition(long) ) ); |
313 | disconnect( mediaPlayerState, SIGNAL( positionUpdated(long) ),this, SLOT( setPosition(long) ) ); | ||
314 | } else { | ||
314 | // this stops the slider from being moved, thus | 315 | // this stops the slider from being moved, thus |
315 | // does not stop stream when it reaches the end | 316 | // does not stop stream when it reaches the end |
316 | // slider.show(); | 317 | slider.show(); |
317 | connect( mediaPlayerState, SIGNAL( positionChanged(long) ),this, SLOT( setPosition(long) ) ); | 318 | connect( mediaPlayerState, SIGNAL( positionChanged(long) ),this, SLOT( setPosition(long) ) ); |
318 | connect( mediaPlayerState, SIGNAL( positionUpdated(long) ),this, SLOT( setPosition(long) ) ); | 319 | connect( mediaPlayerState, SIGNAL( positionUpdated(long) ),this, SLOT( setPosition(long) ) ); |
319 | // } | 320 | } |
320 | 321 | ||
321 | if ( view == 'a' ) { | 322 | if ( view == 'a' ) { |
322 | startTimer( 150 ); | 323 | // startTimer( 150 ); |
323 | showMaximized(); | 324 | showMaximized(); |
324 | } else { | 325 | } else { |
325 | killTimers(); | 326 | killTimers(); |
326 | hide(); | 327 | hide(); |
327 | } | 328 | } |
328 | } | 329 | } |
329 | 330 | ||
330 | 331 | ||
331 | static QString timeAsString( long length ) { | 332 | static QString timeAsString( long length ) { |
332 | int minutes = length / 60; | 333 | int minutes = length / 60; |
333 | int seconds = length % 60; | 334 | int seconds = length % 60; |
334 | return QString("%1:%2%3").arg( minutes ).arg( seconds / 10 ).arg( seconds % 10 ); | 335 | return QString("%1:%2%3").arg( minutes ).arg( seconds / 10 ).arg( seconds % 10 ); |
335 | } | 336 | } |
336 | 337 | ||
337 | void AudioWidget::updateSlider( long i, long max ) { | 338 | void AudioWidget::updateSlider( long i, long max ) { |
338 | 339 | ||
339 | time.setText( timeAsString( i ) + " / " + timeAsString( max ) ); | 340 | time.setText( timeAsString( i ) + " / " + timeAsString( max ) ); |
340 | // qDebug( timeAsString( i ) + " / " + timeAsString( max ) ) ; | 341 | // qDebug( timeAsString( i ) + " / " + timeAsString( max ) ) ; |
341 | 342 | ||
342 | if ( max == 0 ) { | 343 | if ( max == 0 ) { |
343 | return; | 344 | return; |
344 | } | 345 | } |
345 | // Will flicker too much if we don't do this | 346 | // Will flicker too much if we don't do this |
346 | // Scale to something reasonable | 347 | // Scale to something reasonable |
347 | int width = slider.width(); | 348 | int width = slider.width(); |
348 | int val = int((double)i * width / max); | 349 | int val = int((double)i * width / max); |
349 | if ( !audioSliderBeingMoved ) { | 350 | if ( !audioSliderBeingMoved ) { |
350 | if ( slider.value() != val ) { | 351 | if ( slider.value() != val ) { |
351 | slider.setValue( val ); | 352 | slider.setValue( val ); |
352 | } | 353 | } |
353 | 354 | ||
354 | if ( slider.maxValue() != width ) { | 355 | if ( slider.maxValue() != width ) { |
355 | slider.setMaxValue( width ); | 356 | slider.setMaxValue( width ); |
356 | } | 357 | } |
357 | } | 358 | } |
358 | } | 359 | } |
359 | 360 | ||
360 | 361 | ||
361 | void AudioWidget::setToggleButton( int i, bool down ) { | 362 | void AudioWidget::setToggleButton( int i, bool down ) { |
362 | if ( down != audioButtons[i].isDown ) { | 363 | if ( down != audioButtons[i].isDown ) { |
363 | toggleButton( i ); | 364 | toggleButton( i ); |
364 | } | 365 | } |
365 | } | 366 | } |
366 | 367 | ||
367 | 368 | ||
368 | void AudioWidget::toggleButton( int i ) { | 369 | void AudioWidget::toggleButton( int i ) { |
369 | audioButtons[i].isDown = !audioButtons[i].isDown; | 370 | audioButtons[i].isDown = !audioButtons[i].isDown; |
370 | QPainter p(this); | 371 | QPainter p(this); |
371 | paintButton ( &p, i ); | 372 | paintButton ( &p, i ); |
372 | } | 373 | } |
373 | 374 | ||
374 | 375 | ||
375 | void AudioWidget::paintButton( QPainter *p, int i ) { | 376 | void AudioWidget::paintButton( QPainter *p, int i ) { |
376 | if ( audioButtons[i].isDown ) | 377 | if ( audioButtons[i].isDown ) |
377 | p->drawPixmap( xoff, yoff, *buttonPixDown[i] ); | 378 | p->drawPixmap( xoff, yoff, *buttonPixDown[i] ); |
378 | else | 379 | else |
379 | p->drawPixmap( xoff, yoff, *buttonPixUp[i] ); | 380 | p->drawPixmap( xoff, yoff, *buttonPixUp[i] ); |
380 | } | 381 | } |
381 | 382 | ||
382 | 383 | ||
383 | void AudioWidget::skipFor() { | 384 | void AudioWidget::skipFor() { |
384 | skipDirection = +1; | 385 | skipDirection = +1; |
385 | startTimer( 50 ); | 386 | startTimer( 50 ); |
386 | mediaPlayerState->setPosition( mediaPlayerState->position() + 2 ); | 387 | mediaPlayerState->setPosition( mediaPlayerState->position() + 2 ); |
387 | } | 388 | } |
388 | 389 | ||
389 | void AudioWidget::skipBack() { | 390 | void AudioWidget::skipBack() { |
390 | skipDirection = -1; | 391 | skipDirection = -1; |
391 | startTimer( 50 ); | 392 | startTimer( 50 ); |
392 | mediaPlayerState->setPosition( mediaPlayerState->position() - 2 ); | 393 | mediaPlayerState->setPosition( mediaPlayerState->position() - 2 ); |
393 | } | 394 | } |
394 | 395 | ||
395 | 396 | ||
396 | 397 | ||
397 | void AudioWidget::stopSkip() { | 398 | void AudioWidget::stopSkip() { |
398 | killTimers(); | 399 | killTimers(); |
399 | } | 400 | } |
400 | 401 | ||
401 | 402 | ||
402 | void AudioWidget::timerEvent( QTimerEvent * ) { | 403 | void AudioWidget::timerEvent( QTimerEvent * ) { |
403 | if ( skipDirection == +1 ) { | 404 | if ( skipDirection == +1 ) { |
404 | mediaPlayerState->setPosition( mediaPlayerState->position() + 2 ); | 405 | mediaPlayerState->setPosition( mediaPlayerState->position() + 2 ); |
405 | } else if ( skipDirection == -1 ) { | 406 | } else if ( skipDirection == -1 ) { |
406 | mediaPlayerState->setPosition( mediaPlayerState->position() - 2 ); | 407 | mediaPlayerState->setPosition( mediaPlayerState->position() - 2 ); |
407 | } | 408 | } |
408 | } | 409 | } |
409 | 410 | ||
410 | 411 | ||
411 | void AudioWidget::mouseMoveEvent( QMouseEvent *event ) { | 412 | void AudioWidget::mouseMoveEvent( QMouseEvent *event ) { |
412 | for ( int i = 0; i < numButtons; i++ ) { | 413 | for ( int i = 0; i < numButtons; i++ ) { |
413 | if ( event->state() == QMouseEvent::LeftButton ) { | 414 | if ( event->state() == QMouseEvent::LeftButton ) { |
414 | 415 | ||
415 | // The test to see if the mouse click is inside the button or not | 416 | // The test to see if the mouse click is inside the button or not |
416 | int x = event->pos().x() - xoff; | 417 | int x = event->pos().x() - xoff; |
417 | int y = event->pos().y() - yoff; | 418 | int y = event->pos().y() - yoff; |
418 | 419 | ||
419 | bool isOnButton = ( x > 0 && y > 0 && x < imgButtonMask->width() | 420 | bool isOnButton = ( x > 0 && y > 0 && x < imgButtonMask->width() |
420 | && y < imgButtonMask->height() && imgButtonMask->pixelIndex( x, y ) == i + 1 ); | 421 | && y < imgButtonMask->height() && imgButtonMask->pixelIndex( x, y ) == i + 1 ); |
421 | 422 | ||
422 | if ( isOnButton && i == AudioVolumeUp ) | 423 | if ( isOnButton && i == AudioVolumeUp ) |
423 | qDebug("on up"); | 424 | qDebug("on up"); |
424 | 425 | ||
425 | if ( isOnButton && !audioButtons[i].isHeld ) { | 426 | if ( isOnButton && !audioButtons[i].isHeld ) { |
426 | audioButtons[i].isHeld = TRUE; | 427 | audioButtons[i].isHeld = TRUE; |
427 | toggleButton(i); | 428 | toggleButton(i); |
428 | switch (i) { | 429 | switch (i) { |
429 | case AudioVolumeUp: | 430 | case AudioVolumeUp: |
430 | qDebug("more clicked"); | 431 | qDebug("more clicked"); |
431 | emit moreClicked(); | 432 | emit moreClicked(); |
432 | return; | 433 | return; |
433 | case AudioVolumeDown: | 434 | case AudioVolumeDown: |
434 | emit lessClicked(); | 435 | emit lessClicked(); |
435 | return; | 436 | return; |
436 | case AudioForward: | 437 | case AudioForward: |
437 | emit forwardClicked(); | 438 | emit forwardClicked(); |
438 | return; | 439 | return; |
439 | case AudioBack: | 440 | case AudioBack: |
440 | emit backClicked(); | 441 | emit backClicked(); |
441 | return; | 442 | return; |
442 | } | 443 | } |
443 | } else if ( !isOnButton && audioButtons[i].isHeld ) { | 444 | } else if ( !isOnButton && audioButtons[i].isHeld ) { |
444 | audioButtons[i].isHeld = FALSE; | 445 | audioButtons[i].isHeld = FALSE; |
445 | toggleButton(i); | 446 | toggleButton(i); |
446 | } | 447 | } |
447 | } else { | 448 | } else { |
448 | if ( audioButtons[i].isHeld ) { | 449 | if ( audioButtons[i].isHeld ) { |
449 | audioButtons[i].isHeld = FALSE; | 450 | audioButtons[i].isHeld = FALSE; |
450 | if ( !audioButtons[i].isToggle ) { | 451 | if ( !audioButtons[i].isToggle ) { |