summaryrefslogtreecommitdiff
authorsimon <simon>2002-12-08 21:19:07 (UTC)
committer simon <simon>2002-12-08 21:19:07 (UTC)
commit6c0988792eed5cefcc7d1f0c179ccf5317b5baab (patch) (unidiff)
tree27349c3c72d2f623f92ae5ee4b6b871b068d1e55
parentb3ae76e6afdfd734789a85c5e80e8e846b15d6cf (diff)
downloadopie-6c0988792eed5cefcc7d1f0c179ccf5317b5baab.zip
opie-6c0988792eed5cefcc7d1f0c179ccf5317b5baab.tar.gz
opie-6c0988792eed5cefcc7d1f0c179ccf5317b5baab.tar.bz2
- made audioButtons a member variable here, too
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/multimedia/opieplayer2/audiowidget.cpp28
-rw-r--r--noncore/multimedia/opieplayer2/audiowidget.h2
2 files changed, 26 insertions, 4 deletions
diff --git a/noncore/multimedia/opieplayer2/audiowidget.cpp b/noncore/multimedia/opieplayer2/audiowidget.cpp
index 879d0b4..4172da0 100644
--- a/noncore/multimedia/opieplayer2/audiowidget.cpp
+++ b/noncore/multimedia/opieplayer2/audiowidget.cpp
@@ -32,97 +32,117 @@
32*/ 32*/
33 33
34#include <qpe/qpeapplication.h> 34#include <qpe/qpeapplication.h>
35#include <qpe/resource.h> 35#include <qpe/resource.h>
36#include <qpe/config.h> 36#include <qpe/config.h>
37#include <opie/oticker.h> 37#include <opie/oticker.h>
38 38
39#include <qwidget.h> 39#include <qwidget.h>
40#include <qpixmap.h> 40#include <qpixmap.h>
41#include <qbutton.h> 41#include <qbutton.h>
42#include <qpainter.h> 42#include <qpainter.h>
43#include <qframe.h> 43#include <qframe.h>
44#include <qlayout.h> 44#include <qlayout.h>
45#include <qdir.h> 45#include <qdir.h>
46#include <stdlib.h> 46#include <stdlib.h>
47#include <stdio.h> 47#include <stdio.h>
48 48
49#include "audiowidget.h" 49#include "audiowidget.h"
50#include "mediaplayerstate.h" 50#include "mediaplayerstate.h"
51#include "playlistwidget.h" 51#include "playlistwidget.h"
52 52
53namespace 53namespace
54{ 54{
55 55
56const int xo = -2; // movable x offset 56const int xo = -2; // movable x offset
57const int yo = 22; // movable y offset 57const int yo = 22; // movable y offset
58 58
59struct MediaButton { 59struct MediaButton {
60 bool isToggle, isHeld, isDown; 60 bool isToggle, isHeld, isDown;
61}; 61};
62 62
63//Layout information for the audioButtons (and if it is a toggle button or not) 63//Layout information for the audioButtons (and if it is a toggle button or not)
64/*
64MediaWidget::Button audioButtons[] = { 65MediaWidget::Button audioButtons[] = {
65 { TRUE, FALSE, FALSE }, // play 66 { TRUE, FALSE, FALSE }, // play
66 { FALSE, FALSE, FALSE }, // stop 67 { FALSE, FALSE, FALSE }, // stop
67 { FALSE, FALSE, FALSE }, // next 68 { FALSE, FALSE, FALSE }, // next
68 { FALSE, FALSE, FALSE }, // previous 69 { FALSE, FALSE, FALSE }, // previous
69 { FALSE, FALSE, FALSE }, // volume up 70 { FALSE, FALSE, FALSE }, // volume up
70 { FALSE, FALSE, FALSE }, // volume down 71 { FALSE, FALSE, FALSE }, // volume down
71 { TRUE, FALSE, FALSE }, // repeat/loop 72 { TRUE, FALSE, FALSE }, // repeat/loop
72 { FALSE, FALSE, FALSE }, // playlist 73 { FALSE, FALSE, FALSE }, // playlist
73 { FALSE, FALSE, FALSE }, // forward 74 { FALSE, FALSE, FALSE }, // forward
74 { FALSE, FALSE, FALSE } // back 75 { FALSE, FALSE, FALSE } // back
75}; 76};
77*/
76 78
77const char * const skin_mask_file_names[10] = { 79const char * const skin_mask_file_names[10] = {
78 "play", "stop", "next", "prev", "up", 80 "play", "stop", "next", "prev", "up",
79 "down", "loop", "playlist", "forward", "back" 81 "down", "loop", "playlist", "forward", "back"
80}; 82};
81 83
82void changeTextColor( QWidget * w) { 84void changeTextColor( QWidget * w) {
83 QPalette p = w->palette(); 85 QPalette p = w->palette();
84 p.setBrush( QColorGroup::Background, QColor( 167, 212, 167 ) ); 86 p.setBrush( QColorGroup::Background, QColor( 167, 212, 167 ) );
85 p.setBrush( QColorGroup::Base, QColor( 167, 212, 167 ) ); 87 p.setBrush( QColorGroup::Base, QColor( 167, 212, 167 ) );
86 w->setPalette( p ); 88 w->setPalette( p );
87} 89}
88 90
89const int numButtons = (sizeof(audioButtons)/sizeof(MediaWidget::Button)); 91//const int numButtons = (sizeof(audioButtons)/sizeof(MediaWidget::Button));
90 92
91} 93}
92 94
93AudioWidget::AudioWidget( PlayListWidget &playList, MediaPlayerState &mediaPlayerState, QWidget* parent, const char* name) : 95AudioWidget::AudioWidget( PlayListWidget &playList, MediaPlayerState &mediaPlayerState, QWidget* parent, const char* name) :
94 96
95 MediaWidget( playList, mediaPlayerState, parent, name ), songInfo( this ), slider( Qt::Horizontal, this ), time( this ) { 97 MediaWidget( playList, mediaPlayerState, parent, name ), songInfo( this ), slider( Qt::Horizontal, this ), time( this ) {
96 98
99 Button defaultButton;
100 defaultButton.isToggle = defaultButton.isHeld = defaultButton.isDown = false;
101 Button toggleButton;
102 toggleButton.isToggle = true;
103 toggleButton.isHeld = toggleButton.isDown = false;
104
105 audioButtons.reserve( 10 );
106 audioButtons.push_back( toggleButton ); // play
107 audioButtons.push_back( defaultButton ); // stop
108 audioButtons.push_back( defaultButton ); // next
109 audioButtons.push_back( defaultButton ); // previous
110 audioButtons.push_back( defaultButton ); // volume up
111 audioButtons.push_back( defaultButton ); // volume down
112 audioButtons.push_back( toggleButton ); // repeat/loop
113 audioButtons.push_back( defaultButton ); // playlist
114 audioButtons.push_back( defaultButton ); // forward
115 audioButtons.push_back( defaultButton ); // back
116
97 setCaption( tr("OpiePlayer") ); 117 setCaption( tr("OpiePlayer") );
98 118
99 Config cfg("OpiePlayer"); 119 Config cfg("OpiePlayer");
100 cfg.setGroup("Options"); 120 cfg.setGroup("Options");
101 skin = cfg.readEntry("Skin","default"); 121 skin = cfg.readEntry("Skin","default");
102 //skin = "scaleTest"; 122 //skin = "scaleTest";
103 // color of background, frame, degree of transparency 123 // color of background, frame, degree of transparency
104 124
105 QString skinPath = "opieplayer2/skins/" + skin; 125 QString skinPath = "opieplayer2/skins/" + skin;
106 pixBg = QPixmap( Resource::loadPixmap( QString("%1/background").arg(skinPath) ) ); 126 pixBg = QPixmap( Resource::loadPixmap( QString("%1/background").arg(skinPath) ) );
107 imgUp = QImage( Resource::loadImage( QString("%1/skin_up").arg(skinPath) ) ); 127 imgUp = QImage( Resource::loadImage( QString("%1/skin_up").arg(skinPath) ) );
108 imgDn = QImage( Resource::loadImage( QString("%1/skin_down").arg(skinPath) ) ); 128 imgDn = QImage( Resource::loadImage( QString("%1/skin_down").arg(skinPath) ) );
109 129
110 imgButtonMask = QImage( imgUp.width(), imgUp.height(), 8, 255 ); 130 imgButtonMask = QImage( imgUp.width(), imgUp.height(), 8, 255 );
111 imgButtonMask.fill( 0 ); 131 imgButtonMask.fill( 0 );
112 132
113 for ( int i = 0; i < 10; i++ ) { 133 for ( int i = 0; i < 10; i++ ) {
114 QString filename = QString( QPEApplication::qpeDir() + "/pics/" + skinPath + "/skin_mask_" + skin_mask_file_names[i] + ".png" ); 134 QString filename = QString( QPEApplication::qpeDir() + "/pics/" + skinPath + "/skin_mask_" + skin_mask_file_names[i] + ".png" );
115 masks[i] = new QBitmap( filename ); 135 masks[i] = new QBitmap( filename );
116 136
117 if ( !masks[i]->isNull() ) { 137 if ( !masks[i]->isNull() ) {
118 QImage imgMask = masks[i]->convertToImage(); 138 QImage imgMask = masks[i]->convertToImage();
119 uchar **dest = imgButtonMask.jumpTable(); 139 uchar **dest = imgButtonMask.jumpTable();
120 for ( int y = 0; y < imgUp.height(); y++ ) { 140 for ( int y = 0; y < imgUp.height(); y++ ) {
121 uchar *line = dest[y]; 141 uchar *line = dest[y];
122 for ( int x = 0; x < imgUp.width(); x++ ) 142 for ( int x = 0; x < imgUp.width(); x++ )
123 if ( !qRed( imgMask.pixel( x, y ) ) ) 143 if ( !qRed( imgMask.pixel( x, y ) ) )
124 line[x] = i + 1; 144 line[x] = i + 1;
125 } 145 }
126 } 146 }
127 147
128 } 148 }
@@ -351,65 +371,65 @@ void AudioWidget::paintButton( QPainter *p, int i ) {
351} 371}
352 372
353 373
354void AudioWidget::skipFor() { 374void AudioWidget::skipFor() {
355 skipDirection = +1; 375 skipDirection = +1;
356 startTimer( 50 ); 376 startTimer( 50 );
357 mediaPlayerState.setPosition( mediaPlayerState.position() + 2 ); 377 mediaPlayerState.setPosition( mediaPlayerState.position() + 2 );
358} 378}
359 379
360void AudioWidget::skipBack() { 380void AudioWidget::skipBack() {
361 skipDirection = -1; 381 skipDirection = -1;
362 startTimer( 50 ); 382 startTimer( 50 );
363 mediaPlayerState.setPosition( mediaPlayerState.position() - 2 ); 383 mediaPlayerState.setPosition( mediaPlayerState.position() - 2 );
364} 384}
365 385
366 386
367 387
368void AudioWidget::stopSkip() { 388void AudioWidget::stopSkip() {
369 killTimers(); 389 killTimers();
370} 390}
371 391
372 392
373void AudioWidget::timerEvent( QTimerEvent * ) { 393void AudioWidget::timerEvent( QTimerEvent * ) {
374 if ( skipDirection == +1 ) { 394 if ( skipDirection == +1 ) {
375 mediaPlayerState.setPosition( mediaPlayerState.position() + 2 ); 395 mediaPlayerState.setPosition( mediaPlayerState.position() + 2 );
376 } else if ( skipDirection == -1 ) { 396 } else if ( skipDirection == -1 ) {
377 mediaPlayerState.setPosition( mediaPlayerState.position() - 2 ); 397 mediaPlayerState.setPosition( mediaPlayerState.position() - 2 );
378 } 398 }
379} 399}
380 400
381 401
382void AudioWidget::mouseMoveEvent( QMouseEvent *event ) { 402void AudioWidget::mouseMoveEvent( QMouseEvent *event ) {
383 for ( int i = 0; i < numButtons; i++ ) { 403 for ( unsigned int i = 0; i < audioButtons.size(); i++ ) {
384 if ( event->state() == QMouseEvent::LeftButton ) { 404 if ( event->state() == QMouseEvent::LeftButton ) {
385 // The test to see if the mouse click is inside the button or not 405 // The test to see if the mouse click is inside the button or not
386 int x = event->pos().x() - xoff; 406 int x = event->pos().x() - xoff;
387 int y = event->pos().y() - yoff; 407 int y = event->pos().y() - yoff;
388 408
389 bool isOnButton = ( x > 0 && y > 0 && x < imgButtonMask.width() 409 bool isOnButton = ( x > 0 && y > 0 && x < imgButtonMask.width()
390 && y < imgButtonMask.height() 410 && y < imgButtonMask.height()
391 && imgButtonMask.pixelIndex( x, y ) == i + 1 ); 411 && imgButtonMask.pixelIndex( x, y ) == i + 1 );
392 412
393 if ( isOnButton && !audioButtons[i].isHeld ) { 413 if ( isOnButton && !audioButtons[i].isHeld ) {
394 audioButtons[i].isHeld = TRUE; 414 audioButtons[i].isHeld = TRUE;
395 toggleButton(i); 415 toggleButton(i);
396 switch (i) { 416 switch (i) {
397 case VolumeUp: 417 case VolumeUp:
398 emit moreClicked(); 418 emit moreClicked();
399 return; 419 return;
400 case VolumeDown: 420 case VolumeDown:
401 emit lessClicked(); 421 emit lessClicked();
402 return; 422 return;
403 case Forward: 423 case Forward:
404 emit forwardClicked(); 424 emit forwardClicked();
405 return; 425 return;
406 case Back: 426 case Back:
407 emit backClicked(); 427 emit backClicked();
408 return; 428 return;
409 } 429 }
410 } else if ( !isOnButton && audioButtons[i].isHeld ) { 430 } else if ( !isOnButton && audioButtons[i].isHeld ) {
411 audioButtons[i].isHeld = FALSE; 431 audioButtons[i].isHeld = FALSE;
412 toggleButton(i); 432 toggleButton(i);
413 } 433 }
414 } else { 434 } else {
415 if ( audioButtons[i].isHeld ) { 435 if ( audioButtons[i].isHeld ) {
@@ -419,71 +439,71 @@ void AudioWidget::mouseMoveEvent( QMouseEvent *event ) {
419 } 439 }
420 qDebug("mouseEvent %d", i); 440 qDebug("mouseEvent %d", i);
421 handleCommand( static_cast<Command>( i ), audioButtons[ i ].isDown ); 441 handleCommand( static_cast<Command>( i ), audioButtons[ i ].isDown );
422 } 442 }
423 } 443 }
424 } 444 }
425} 445}
426 446
427 447
428void AudioWidget::mousePressEvent( QMouseEvent *event ) { 448void AudioWidget::mousePressEvent( QMouseEvent *event ) {
429 mouseMoveEvent( event ); 449 mouseMoveEvent( event );
430} 450}
431 451
432 452
433void AudioWidget::mouseReleaseEvent( QMouseEvent *event ) { 453void AudioWidget::mouseReleaseEvent( QMouseEvent *event ) {
434 mouseMoveEvent( event ); 454 mouseMoveEvent( event );
435} 455}
436 456
437 457
438void AudioWidget::showEvent( QShowEvent* ) { 458void AudioWidget::showEvent( QShowEvent* ) {
439 QMouseEvent event( QEvent::MouseMove, QPoint( 0, 0 ), 0, 0 ); 459 QMouseEvent event( QEvent::MouseMove, QPoint( 0, 0 ), 0, 0 );
440 mouseMoveEvent( &event ); 460 mouseMoveEvent( &event );
441} 461}
442 462
443 463
444void AudioWidget::paintEvent( QPaintEvent * pe ) { 464void AudioWidget::paintEvent( QPaintEvent * pe ) {
445 if ( !pe->erased() ) { 465 if ( !pe->erased() ) {
446 // Combine with background and double buffer 466 // Combine with background and double buffer
447 QPixmap pix( pe->rect().size() ); 467 QPixmap pix( pe->rect().size() );
448 QPainter p( &pix ); 468 QPainter p( &pix );
449 p.translate( -pe->rect().topLeft().x(), -pe->rect().topLeft().y() ); 469 p.translate( -pe->rect().topLeft().x(), -pe->rect().topLeft().y() );
450 p.drawTiledPixmap( pe->rect(), pixBg, pe->rect().topLeft() ); 470 p.drawTiledPixmap( pe->rect(), pixBg, pe->rect().topLeft() );
451 for ( int i = 0; i < numButtons; i++ ) 471 for ( unsigned int i = 0; i < audioButtons.size(); i++ )
452 paintButton( &p, i ); 472 paintButton( &p, i );
453 QPainter p2( this ); 473 QPainter p2( this );
454 p2.drawPixmap( pe->rect().topLeft(), pix ); 474 p2.drawPixmap( pe->rect().topLeft(), pix );
455 } else { 475 } else {
456 QPainter p( this ); 476 QPainter p( this );
457 for ( int i = 0; i < numButtons; i++ ) 477 for ( unsigned int i = 0; i < audioButtons.size(); i++ )
458 paintButton( &p, i ); 478 paintButton( &p, i );
459 } 479 }
460} 480}
461 481
462void AudioWidget::keyReleaseEvent( QKeyEvent *e) { 482void AudioWidget::keyReleaseEvent( QKeyEvent *e) {
463 switch ( e->key() ) { 483 switch ( e->key() ) {
464 ////////////////////////////// Zaurus keys 484 ////////////////////////////// Zaurus keys
465 case Key_Home: 485 case Key_Home:
466 break; 486 break;
467 case Key_F9: //activity 487 case Key_F9: //activity
468 hide(); 488 hide();
469 // qDebug("Audio F9"); 489 // qDebug("Audio F9");
470 break; 490 break;
471 case Key_F10: //contacts 491 case Key_F10: //contacts
472 break; 492 break;
473 case Key_F11: //menu 493 case Key_F11: //menu
474 mediaPlayerState.toggleBlank(); 494 mediaPlayerState.toggleBlank();
475 break; 495 break;
476 case Key_F12: //home 496 case Key_F12: //home
477 break; 497 break;
478 case Key_F13: //mail 498 case Key_F13: //mail
479 mediaPlayerState.toggleBlank(); 499 mediaPlayerState.toggleBlank();
480 break; 500 break;
481 case Key_Space: { 501 case Key_Space: {
482 if(mediaPlayerState.isPlaying()) { 502 if(mediaPlayerState.isPlaying()) {
483 // toggleButton(1); 503 // toggleButton(1);
484 mediaPlayerState.setPlaying(FALSE); 504 mediaPlayerState.setPlaying(FALSE);
485 // toggleButton(1); 505 // toggleButton(1);
486 } else { 506 } else {
487 // toggleButton(0); 507 // toggleButton(0);
488 mediaPlayerState.setPlaying(TRUE); 508 mediaPlayerState.setPlaying(TRUE);
489 // toggleButton(0); 509 // toggleButton(0);
diff --git a/noncore/multimedia/opieplayer2/audiowidget.h b/noncore/multimedia/opieplayer2/audiowidget.h
index 52a358c..e09c5f8 100644
--- a/noncore/multimedia/opieplayer2/audiowidget.h
+++ b/noncore/multimedia/opieplayer2/audiowidget.h
@@ -81,37 +81,39 @@ protected:
81 void paintEvent( QPaintEvent *pe ); 81 void paintEvent( QPaintEvent *pe );
82 void showEvent( QShowEvent *se ); 82 void showEvent( QShowEvent *se );
83 void resizeEvent( QResizeEvent *re ); 83 void resizeEvent( QResizeEvent *re );
84 void mouseMoveEvent( QMouseEvent *event ); 84 void mouseMoveEvent( QMouseEvent *event );
85 void mousePressEvent( QMouseEvent *event ); 85 void mousePressEvent( QMouseEvent *event );
86 void mouseReleaseEvent( QMouseEvent *event ); 86 void mouseReleaseEvent( QMouseEvent *event );
87 void timerEvent( QTimerEvent *event ); 87 void timerEvent( QTimerEvent *event );
88 void keyReleaseEvent( QKeyEvent *e); 88 void keyReleaseEvent( QKeyEvent *e);
89private slots: 89private slots:
90 void skipFor(); 90 void skipFor();
91 void skipBack(); 91 void skipBack();
92 void stopSkip(); 92 void stopSkip();
93private: 93private:
94 void toggleButton( int ); 94 void toggleButton( int );
95 void setToggleButton( int, bool ); 95 void setToggleButton( int, bool );
96 void paintButton( QPainter *p, int i ); 96 void paintButton( QPainter *p, int i );
97 int skipDirection; 97 int skipDirection;
98 QString skin; 98 QString skin;
99 QPixmap pixBg; 99 QPixmap pixBg;
100 QImage imgUp; 100 QImage imgUp;
101 QImage imgDn; 101 QImage imgDn;
102 QImage imgButtonMask; 102 QImage imgButtonMask;
103 QBitmap *masks[10]; 103 QBitmap *masks[10];
104 QPixmap *buttonPixUp[10]; 104 QPixmap *buttonPixUp[10];
105 QPixmap *buttonPixDown[10]; 105 QPixmap *buttonPixDown[10];
106 106
107 QPixmap *pixmaps[4]; 107 QPixmap *pixmaps[4];
108 OTicker songInfo; 108 OTicker songInfo;
109 QSlider slider; 109 QSlider slider;
110 QLineEdit time; 110 QLineEdit time;
111 int xoff, yoff; 111 int xoff, yoff;
112 bool isStreaming : 1; 112 bool isStreaming : 1;
113
114 ButtonVector audioButtons;
113}; 115};
114 116
115 117
116#endif // AUDIO_WIDGET_H 118#endif // AUDIO_WIDGET_H
117 119