Diffstat (limited to 'noncore/multimedia/opieplayer2/audiowidget.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/multimedia/opieplayer2/audiowidget.cpp | 50 |
1 files changed, 25 insertions, 25 deletions
diff --git a/noncore/multimedia/opieplayer2/audiowidget.cpp b/noncore/multimedia/opieplayer2/audiowidget.cpp index 7fb3781..a9d5a88 100644 --- a/noncore/multimedia/opieplayer2/audiowidget.cpp +++ b/noncore/multimedia/opieplayer2/audiowidget.cpp | |||
@@ -59,59 +59,59 @@ const int yo = 22; // movable y offset | |||
59 | const char * const skin_mask_file_names[10] = { | 59 | const char * const skin_mask_file_names[10] = { |
60 | "play", "stop", "next", "prev", "up", | 60 | "play", "stop", "next", "prev", "up", |
61 | "down", "loop", "playlist", "forward", "back" | 61 | "down", "loop", "playlist", "forward", "back" |
62 | }; | 62 | }; |
63 | 63 | ||
64 | void changeTextColor( QWidget * w) { | 64 | void changeTextColor( QWidget * w) { |
65 | QPalette p = w->palette(); | 65 | QPalette p = w->palette(); |
66 | p.setBrush( QColorGroup::Background, QColor( 167, 212, 167 ) ); | 66 | p.setBrush( QColorGroup::Background, QColor( 167, 212, 167 ) ); |
67 | p.setBrush( QColorGroup::Base, QColor( 167, 212, 167 ) ); | 67 | p.setBrush( QColorGroup::Base, QColor( 167, 212, 167 ) ); |
68 | w->setPalette( p ); | 68 | w->setPalette( p ); |
69 | } | 69 | } |
70 | 70 | ||
71 | } | 71 | } |
72 | 72 | ||
73 | AudioWidget::AudioWidget( PlayListWidget &playList, MediaPlayerState &mediaPlayerState, QWidget* parent, const char* name) : | 73 | AudioWidget::AudioWidget( PlayListWidget &playList, MediaPlayerState &mediaPlayerState, QWidget* parent, const char* name) : |
74 | 74 | ||
75 | MediaWidget( playList, mediaPlayerState, parent, name ), songInfo( this ), slider( Qt::Horizontal, this ), time( this ) { | 75 | MediaWidget( playList, mediaPlayerState, parent, name ), songInfo( this ), slider( Qt::Horizontal, this ), time( this ) { |
76 | 76 | ||
77 | Button defaultButton; | 77 | Button defaultButton; |
78 | defaultButton.isToggle = defaultButton.isHeld = defaultButton.isDown = false; | 78 | defaultButton.isToggle = defaultButton.isHeld = defaultButton.isDown = false; |
79 | Button toggleButton; | 79 | Button toggleButton; |
80 | toggleButton.isToggle = true; | 80 | toggleButton.isToggle = true; |
81 | toggleButton.isHeld = toggleButton.isDown = false; | 81 | toggleButton.isHeld = toggleButton.isDown = false; |
82 | 82 | ||
83 | audioButtons.reserve( 10 ); | 83 | buttons.reserve( 10 ); |
84 | audioButtons.push_back( toggleButton ); // play | 84 | buttons.push_back( toggleButton ); // play |
85 | audioButtons.push_back( defaultButton ); // stop | 85 | buttons.push_back( defaultButton ); // stop |
86 | audioButtons.push_back( defaultButton ); // next | 86 | buttons.push_back( defaultButton ); // next |
87 | audioButtons.push_back( defaultButton ); // previous | 87 | buttons.push_back( defaultButton ); // previous |
88 | audioButtons.push_back( defaultButton ); // volume up | 88 | buttons.push_back( defaultButton ); // volume up |
89 | audioButtons.push_back( defaultButton ); // volume down | 89 | buttons.push_back( defaultButton ); // volume down |
90 | audioButtons.push_back( toggleButton ); // repeat/loop | 90 | buttons.push_back( toggleButton ); // repeat/loop |
91 | audioButtons.push_back( defaultButton ); // playlist | 91 | buttons.push_back( defaultButton ); // playlist |
92 | audioButtons.push_back( defaultButton ); // forward | 92 | buttons.push_back( defaultButton ); // forward |
93 | audioButtons.push_back( defaultButton ); // back | 93 | buttons.push_back( defaultButton ); // back |
94 | 94 | ||
95 | setCaption( tr("OpiePlayer") ); | 95 | setCaption( tr("OpiePlayer") ); |
96 | 96 | ||
97 | Config cfg("OpiePlayer"); | 97 | Config cfg("OpiePlayer"); |
98 | cfg.setGroup("Options"); | 98 | cfg.setGroup("Options"); |
99 | skin = cfg.readEntry("Skin","default"); | 99 | skin = cfg.readEntry("Skin","default"); |
100 | //skin = "scaleTest"; | 100 | //skin = "scaleTest"; |
101 | // color of background, frame, degree of transparency | 101 | // color of background, frame, degree of transparency |
102 | 102 | ||
103 | QString skinPath = "opieplayer2/skins/" + skin; | 103 | QString skinPath = "opieplayer2/skins/" + skin; |
104 | pixBg = QPixmap( Resource::loadPixmap( QString("%1/background").arg(skinPath) ) ); | 104 | pixBg = QPixmap( Resource::loadPixmap( QString("%1/background").arg(skinPath) ) ); |
105 | imgUp = QImage( Resource::loadImage( QString("%1/skin_up").arg(skinPath) ) ); | 105 | imgUp = QImage( Resource::loadImage( QString("%1/skin_up").arg(skinPath) ) ); |
106 | imgDn = QImage( Resource::loadImage( QString("%1/skin_down").arg(skinPath) ) ); | 106 | imgDn = QImage( Resource::loadImage( QString("%1/skin_down").arg(skinPath) ) ); |
107 | 107 | ||
108 | imgButtonMask = QImage( imgUp.width(), imgUp.height(), 8, 255 ); | 108 | imgButtonMask = QImage( imgUp.width(), imgUp.height(), 8, 255 ); |
109 | imgButtonMask.fill( 0 ); | 109 | imgButtonMask.fill( 0 ); |
110 | 110 | ||
111 | for ( int i = 0; i < 10; i++ ) { | 111 | for ( int i = 0; i < 10; i++ ) { |
112 | QString filename = QString( QPEApplication::qpeDir() + "/pics/" + skinPath + "/skin_mask_" + skin_mask_file_names[i] + ".png" ); | 112 | QString filename = QString( QPEApplication::qpeDir() + "/pics/" + skinPath + "/skin_mask_" + skin_mask_file_names[i] + ".png" ); |
113 | masks[i] = new QBitmap( filename ); | 113 | masks[i] = new QBitmap( filename ); |
114 | 114 | ||
115 | if ( !masks[i]->isNull() ) { | 115 | if ( !masks[i]->isNull() ) { |
116 | QImage imgMask = masks[i]->convertToImage(); | 116 | QImage imgMask = masks[i]->convertToImage(); |
117 | uchar **dest = imgButtonMask.jumpTable(); | 117 | uchar **dest = imgButtonMask.jumpTable(); |
@@ -306,174 +306,174 @@ void AudioWidget::updateSlider( long i, long max ) { | |||
306 | time.setText( timeAsString( i ) + " / " + timeAsString( max ) ); | 306 | time.setText( timeAsString( i ) + " / " + timeAsString( max ) ); |
307 | // qDebug( timeAsString( i ) + " / " + timeAsString( max ) ) ; | 307 | // qDebug( timeAsString( i ) + " / " + timeAsString( max ) ) ; |
308 | 308 | ||
309 | if ( max == 0 ) { | 309 | if ( max == 0 ) { |
310 | return; | 310 | return; |
311 | } | 311 | } |
312 | // Will flicker too much if we don't do this | 312 | // Will flicker too much if we don't do this |
313 | // Scale to something reasonable | 313 | // Scale to something reasonable |
314 | int width = slider.width(); | 314 | int width = slider.width(); |
315 | int val = int((double)i * width / max); | 315 | int val = int((double)i * width / max); |
316 | if ( !audioSliderBeingMoved ) { | 316 | if ( !audioSliderBeingMoved ) { |
317 | if ( slider.value() != val ) { | 317 | if ( slider.value() != val ) { |
318 | slider.setValue( val ); | 318 | slider.setValue( val ); |
319 | } | 319 | } |
320 | 320 | ||
321 | if ( slider.maxValue() != width ) { | 321 | if ( slider.maxValue() != width ) { |
322 | slider.setMaxValue( width ); | 322 | slider.setMaxValue( width ); |
323 | } | 323 | } |
324 | } | 324 | } |
325 | } | 325 | } |
326 | 326 | ||
327 | 327 | ||
328 | void AudioWidget::setToggleButton( int i, bool down ) { | 328 | void AudioWidget::setToggleButton( int i, bool down ) { |
329 | qDebug("setToggleButton %d", i); | 329 | qDebug("setToggleButton %d", i); |
330 | if ( down != audioButtons[i].isDown ) { | 330 | if ( down != buttons[i].isDown ) { |
331 | toggleButton( i ); | 331 | toggleButton( i ); |
332 | } | 332 | } |
333 | } | 333 | } |
334 | 334 | ||
335 | 335 | ||
336 | void AudioWidget::toggleButton( int i ) { | 336 | void AudioWidget::toggleButton( int i ) { |
337 | audioButtons[i].isDown = !audioButtons[i].isDown; | 337 | buttons[i].isDown = !buttons[i].isDown; |
338 | QPainter p(this); | 338 | QPainter p(this); |
339 | paintButton ( &p, i ); | 339 | paintButton ( &p, i ); |
340 | } | 340 | } |
341 | 341 | ||
342 | 342 | ||
343 | void AudioWidget::paintButton( QPainter *p, int i ) { | 343 | void AudioWidget::paintButton( QPainter *p, int i ) { |
344 | if ( audioButtons[i].isDown ) { | 344 | if ( buttons[i].isDown ) { |
345 | p->drawPixmap( xoff, yoff, *buttonPixDown[i] ); | 345 | p->drawPixmap( xoff, yoff, *buttonPixDown[i] ); |
346 | } else { | 346 | } else { |
347 | p->drawPixmap( xoff, yoff, *buttonPixUp[i] ); | 347 | p->drawPixmap( xoff, yoff, *buttonPixUp[i] ); |
348 | } | 348 | } |
349 | } | 349 | } |
350 | 350 | ||
351 | 351 | ||
352 | void AudioWidget::skipFor() { | 352 | void AudioWidget::skipFor() { |
353 | skipDirection = +1; | 353 | skipDirection = +1; |
354 | startTimer( 50 ); | 354 | startTimer( 50 ); |
355 | mediaPlayerState.setPosition( mediaPlayerState.position() + 2 ); | 355 | mediaPlayerState.setPosition( mediaPlayerState.position() + 2 ); |
356 | } | 356 | } |
357 | 357 | ||
358 | void AudioWidget::skipBack() { | 358 | void AudioWidget::skipBack() { |
359 | skipDirection = -1; | 359 | skipDirection = -1; |
360 | startTimer( 50 ); | 360 | startTimer( 50 ); |
361 | mediaPlayerState.setPosition( mediaPlayerState.position() - 2 ); | 361 | mediaPlayerState.setPosition( mediaPlayerState.position() - 2 ); |
362 | } | 362 | } |
363 | 363 | ||
364 | 364 | ||
365 | 365 | ||
366 | void AudioWidget::stopSkip() { | 366 | void AudioWidget::stopSkip() { |
367 | killTimers(); | 367 | killTimers(); |
368 | } | 368 | } |
369 | 369 | ||
370 | 370 | ||
371 | void AudioWidget::timerEvent( QTimerEvent * ) { | 371 | void AudioWidget::timerEvent( QTimerEvent * ) { |
372 | if ( skipDirection == +1 ) { | 372 | if ( skipDirection == +1 ) { |
373 | mediaPlayerState.setPosition( mediaPlayerState.position() + 2 ); | 373 | mediaPlayerState.setPosition( mediaPlayerState.position() + 2 ); |
374 | } else if ( skipDirection == -1 ) { | 374 | } else if ( skipDirection == -1 ) { |
375 | mediaPlayerState.setPosition( mediaPlayerState.position() - 2 ); | 375 | mediaPlayerState.setPosition( mediaPlayerState.position() - 2 ); |
376 | } | 376 | } |
377 | } | 377 | } |
378 | 378 | ||
379 | 379 | ||
380 | void AudioWidget::mouseMoveEvent( QMouseEvent *event ) { | 380 | void AudioWidget::mouseMoveEvent( QMouseEvent *event ) { |
381 | for ( unsigned int i = 0; i < audioButtons.size(); i++ ) { | 381 | for ( unsigned int i = 0; i < buttons.size(); i++ ) { |
382 | if ( event->state() == QMouseEvent::LeftButton ) { | 382 | if ( event->state() == QMouseEvent::LeftButton ) { |
383 | // The test to see if the mouse click is inside the button or not | 383 | // The test to see if the mouse click is inside the button or not |
384 | int x = event->pos().x() - xoff; | 384 | int x = event->pos().x() - xoff; |
385 | int y = event->pos().y() - yoff; | 385 | int y = event->pos().y() - yoff; |
386 | 386 | ||
387 | bool isOnButton = ( x > 0 && y > 0 && x < imgButtonMask.width() | 387 | bool isOnButton = ( x > 0 && y > 0 && x < imgButtonMask.width() |
388 | && y < imgButtonMask.height() | 388 | && y < imgButtonMask.height() |
389 | && imgButtonMask.pixelIndex( x, y ) == i + 1 ); | 389 | && imgButtonMask.pixelIndex( x, y ) == i + 1 ); |
390 | 390 | ||
391 | if ( isOnButton && !audioButtons[i].isHeld ) { | 391 | if ( isOnButton && !buttons[i].isHeld ) { |
392 | audioButtons[i].isHeld = TRUE; | 392 | buttons[i].isHeld = TRUE; |
393 | toggleButton(i); | 393 | toggleButton(i); |
394 | switch (i) { | 394 | switch (i) { |
395 | case VolumeUp: | 395 | case VolumeUp: |
396 | emit moreClicked(); | 396 | emit moreClicked(); |
397 | return; | 397 | return; |
398 | case VolumeDown: | 398 | case VolumeDown: |
399 | emit lessClicked(); | 399 | emit lessClicked(); |
400 | return; | 400 | return; |
401 | case Forward: | 401 | case Forward: |
402 | emit forwardClicked(); | 402 | emit forwardClicked(); |
403 | return; | 403 | return; |
404 | case Back: | 404 | case Back: |
405 | emit backClicked(); | 405 | emit backClicked(); |
406 | return; | 406 | return; |
407 | } | 407 | } |
408 | } else if ( !isOnButton && audioButtons[i].isHeld ) { | 408 | } else if ( !isOnButton && buttons[i].isHeld ) { |
409 | audioButtons[i].isHeld = FALSE; | 409 | buttons[i].isHeld = FALSE; |
410 | toggleButton(i); | 410 | toggleButton(i); |
411 | } | 411 | } |
412 | } else { | 412 | } else { |
413 | if ( audioButtons[i].isHeld ) { | 413 | if ( buttons[i].isHeld ) { |
414 | audioButtons[i].isHeld = FALSE; | 414 | buttons[i].isHeld = FALSE; |
415 | if ( !audioButtons[i].isToggle ) { | 415 | if ( !buttons[i].isToggle ) { |
416 | setToggleButton( i, FALSE ); | 416 | setToggleButton( i, FALSE ); |
417 | } | 417 | } |
418 | qDebug("mouseEvent %d", i); | 418 | qDebug("mouseEvent %d", i); |
419 | handleCommand( static_cast<Command>( i ), audioButtons[ i ].isDown ); | 419 | handleCommand( static_cast<Command>( i ), buttons[ i ].isDown ); |
420 | } | 420 | } |
421 | } | 421 | } |
422 | } | 422 | } |
423 | } | 423 | } |
424 | 424 | ||
425 | 425 | ||
426 | void AudioWidget::mousePressEvent( QMouseEvent *event ) { | 426 | void AudioWidget::mousePressEvent( QMouseEvent *event ) { |
427 | mouseMoveEvent( event ); | 427 | mouseMoveEvent( event ); |
428 | } | 428 | } |
429 | 429 | ||
430 | 430 | ||
431 | void AudioWidget::mouseReleaseEvent( QMouseEvent *event ) { | 431 | void AudioWidget::mouseReleaseEvent( QMouseEvent *event ) { |
432 | mouseMoveEvent( event ); | 432 | mouseMoveEvent( event ); |
433 | } | 433 | } |
434 | 434 | ||
435 | 435 | ||
436 | void AudioWidget::showEvent( QShowEvent* ) { | 436 | void AudioWidget::showEvent( QShowEvent* ) { |
437 | QMouseEvent event( QEvent::MouseMove, QPoint( 0, 0 ), 0, 0 ); | 437 | QMouseEvent event( QEvent::MouseMove, QPoint( 0, 0 ), 0, 0 ); |
438 | mouseMoveEvent( &event ); | 438 | mouseMoveEvent( &event ); |
439 | } | 439 | } |
440 | 440 | ||
441 | 441 | ||
442 | void AudioWidget::paintEvent( QPaintEvent * pe ) { | 442 | void AudioWidget::paintEvent( QPaintEvent * pe ) { |
443 | if ( !pe->erased() ) { | 443 | if ( !pe->erased() ) { |
444 | // Combine with background and double buffer | 444 | // Combine with background and double buffer |
445 | QPixmap pix( pe->rect().size() ); | 445 | QPixmap pix( pe->rect().size() ); |
446 | QPainter p( &pix ); | 446 | QPainter p( &pix ); |
447 | p.translate( -pe->rect().topLeft().x(), -pe->rect().topLeft().y() ); | 447 | p.translate( -pe->rect().topLeft().x(), -pe->rect().topLeft().y() ); |
448 | p.drawTiledPixmap( pe->rect(), pixBg, pe->rect().topLeft() ); | 448 | p.drawTiledPixmap( pe->rect(), pixBg, pe->rect().topLeft() ); |
449 | for ( unsigned int i = 0; i < audioButtons.size(); i++ ) | 449 | for ( unsigned int i = 0; i < buttons.size(); i++ ) |
450 | paintButton( &p, i ); | 450 | paintButton( &p, i ); |
451 | QPainter p2( this ); | 451 | QPainter p2( this ); |
452 | p2.drawPixmap( pe->rect().topLeft(), pix ); | 452 | p2.drawPixmap( pe->rect().topLeft(), pix ); |
453 | } else { | 453 | } else { |
454 | QPainter p( this ); | 454 | QPainter p( this ); |
455 | for ( unsigned int i = 0; i < audioButtons.size(); i++ ) | 455 | for ( unsigned int i = 0; i < buttons.size(); i++ ) |
456 | paintButton( &p, i ); | 456 | paintButton( &p, i ); |
457 | } | 457 | } |
458 | } | 458 | } |
459 | 459 | ||
460 | void AudioWidget::keyReleaseEvent( QKeyEvent *e) { | 460 | void AudioWidget::keyReleaseEvent( QKeyEvent *e) { |
461 | switch ( e->key() ) { | 461 | switch ( e->key() ) { |
462 | ////////////////////////////// Zaurus keys | 462 | ////////////////////////////// Zaurus keys |
463 | case Key_Home: | 463 | case Key_Home: |
464 | break; | 464 | break; |
465 | case Key_F9: //activity | 465 | case Key_F9: //activity |
466 | hide(); | 466 | hide(); |
467 | // qDebug("Audio F9"); | 467 | // qDebug("Audio F9"); |
468 | break; | 468 | break; |
469 | case Key_F10: //contacts | 469 | case Key_F10: //contacts |
470 | break; | 470 | break; |
471 | case Key_F11: //menu | 471 | case Key_F11: //menu |
472 | mediaPlayerState.toggleBlank(); | 472 | mediaPlayerState.toggleBlank(); |
473 | break; | 473 | break; |
474 | case Key_F12: //home | 474 | case Key_F12: //home |
475 | break; | 475 | break; |
476 | case Key_F13: //mail | 476 | case Key_F13: //mail |
477 | mediaPlayerState.toggleBlank(); | 477 | mediaPlayerState.toggleBlank(); |
478 | break; | 478 | break; |
479 | case Key_Space: { | 479 | case Key_Space: { |