Diffstat (limited to 'core/multimedia/opieplayer/audiowidget.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | core/multimedia/opieplayer/audiowidget.cpp | 31 |
1 files changed, 17 insertions, 14 deletions
diff --git a/core/multimedia/opieplayer/audiowidget.cpp b/core/multimedia/opieplayer/audiowidget.cpp index a1973e9..b187cb4 100644 --- a/core/multimedia/opieplayer/audiowidget.cpp +++ b/core/multimedia/opieplayer/audiowidget.cpp | |||
@@ -67,39 +67,39 @@ static void changeTextColor( QWidget *w ) { | |||
67 | QPalette p = w->palette(); | 67 | QPalette p = w->palette(); |
68 | p.setBrush( QColorGroup::Background, QColor( 167, 212, 167 ) ); | 68 | p.setBrush( QColorGroup::Background, QColor( 167, 212, 167 ) ); |
69 | p.setBrush( QColorGroup::Base, QColor( 167, 212, 167 ) ); | 69 | p.setBrush( QColorGroup::Base, QColor( 167, 212, 167 ) ); |
70 | w->setPalette( p ); | 70 | w->setPalette( p ); |
71 | } | 71 | } |
72 | 72 | ||
73 | static const int numButtons = (sizeof(audioButtons)/sizeof(MediaButton)); | 73 | static const int numButtons = (sizeof(audioButtons)/sizeof(MediaButton)); |
74 | 74 | ||
75 | AudioWidget::AudioWidget(QWidget* parent, const char* name, WFlags f) : | 75 | AudioWidget::AudioWidget(QWidget* parent, const char* name, WFlags f) : |
76 | QWidget( parent, name, f ), songInfo( this ), slider( Qt::Horizontal, this ), time( this ) | 76 | QWidget( parent, name, f ), songInfo( this ), slider( Qt::Horizontal, this ), time( this ) |
77 | { | 77 | { |
78 | setCaption( tr("OpiePlayer") ); | 78 | setCaption( tr("OpiePlayer") ); |
79 | qDebug("<<<<<audioWidget"); | 79 | // qDebug("<<<<<audioWidget"); |
80 | 80 | ||
81 | Config cfg("OpiePlayer"); | 81 | Config cfg("OpiePlayer"); |
82 | cfg.setGroup("Options"); | 82 | cfg.setGroup("Options"); |
83 | skin = cfg.readEntry("Skin","default"); | 83 | skin = cfg.readEntry("Skin","default"); |
84 | //skin = "scaleTest"; | 84 | //skin = "scaleTest"; |
85 | // color of background, frame, degree of transparency | 85 | // color of background, frame, degree of transparency |
86 | 86 | ||
87 | // QString skinPath = "opieplayer/skins/" + skin; | 87 | // QString skinPath = "opieplayer/skins/" + skin; |
88 | QString skinPath; | 88 | QString skinPath; |
89 | skinPath = "opieplayer2/skins/" + skin; | 89 | skinPath = "opieplayer2/skins/" + skin; |
90 | if(!QDir(QString(getenv("OPIEDIR")) +"/pics/"+skinPath).exists()) | 90 | if(!QDir(QString(getenv("OPIEDIR")) +"/pics/"+skinPath).exists()) |
91 | skinPath = "opieplayer2/skins/default"; | 91 | skinPath = "opieplayer2/skins/default"; |
92 | 92 | ||
93 | qDebug("skin path " + skinPath); | 93 | // qDebug("skin path " + skinPath); |
94 | 94 | ||
95 | pixBg = new QPixmap( Resource::loadPixmap( QString("%1/background").arg(skinPath) ) ); | 95 | pixBg = new QPixmap( Resource::loadPixmap( QString("%1/background").arg(skinPath) ) ); |
96 | imgUp = new QImage( Resource::loadImage( QString("%1/skin_up").arg(skinPath) ) ); | 96 | imgUp = new QImage( Resource::loadImage( QString("%1/skin_up").arg(skinPath) ) ); |
97 | imgDn = new QImage( Resource::loadImage( QString("%1/skin_down").arg(skinPath) ) ); | 97 | imgDn = new QImage( Resource::loadImage( QString("%1/skin_down").arg(skinPath) ) ); |
98 | 98 | ||
99 | imgButtonMask = new QImage( imgUp->width(), imgUp->height(), 8, 255 ); | 99 | imgButtonMask = new QImage( imgUp->width(), imgUp->height(), 8, 255 ); |
100 | imgButtonMask->fill( 0 ); | 100 | imgButtonMask->fill( 0 ); |
101 | 101 | ||
102 | for ( int i = 0; i < 10; i++ ) { | 102 | for ( int i = 0; i < 10; i++ ) { |
103 | QString filename = QString(getenv("OPIEDIR")) + "/pics/" + skinPath + "/skin_mask_" + skin_mask_file_names[i] + ".png"; | 103 | QString filename = QString(getenv("OPIEDIR")) + "/pics/" + skinPath + "/skin_mask_" + skin_mask_file_names[i] + ".png"; |
104 | masks[i] = new QBitmap( filename ); | 104 | masks[i] = new QBitmap( filename ); |
105 | 105 | ||
@@ -151,40 +151,41 @@ AudioWidget::AudioWidget(QWidget* parent, const char* name, WFlags f) : | |||
151 | connect( mediaPlayerState, SIGNAL( lengthChanged(long) ), this, SLOT( setLength(long) ) ); | 151 | connect( mediaPlayerState, SIGNAL( lengthChanged(long) ), this, SLOT( setLength(long) ) ); |
152 | connect( mediaPlayerState, SIGNAL( viewChanged(char) ), this, SLOT( setView(char) ) ); | 152 | connect( mediaPlayerState, SIGNAL( viewChanged(char) ), this, SLOT( setView(char) ) ); |
153 | connect( mediaPlayerState, SIGNAL( loopingToggled(bool) ), this, SLOT( setLooping(bool) ) ); | 153 | connect( mediaPlayerState, SIGNAL( loopingToggled(bool) ), this, SLOT( setLooping(bool) ) ); |
154 | // connect( mediaPlayerState, SIGNAL( pausedToggled(bool) ), this, SLOT( setPaused(bool) ) ); | 154 | // connect( mediaPlayerState, SIGNAL( pausedToggled(bool) ), this, SLOT( setPaused(bool) ) ); |
155 | connect( mediaPlayerState, SIGNAL( playingToggled(bool) ), this, SLOT( setPlaying(bool) ) ); | 155 | connect( mediaPlayerState, SIGNAL( playingToggled(bool) ), this, SLOT( setPlaying(bool) ) ); |
156 | 156 | ||
157 | // Intialise state | 157 | // Intialise state |
158 | setLength( mediaPlayerState->length() ); | 158 | setLength( mediaPlayerState->length() ); |
159 | setPosition( mediaPlayerState->position() ); | 159 | setPosition( mediaPlayerState->position() ); |
160 | setLooping( mediaPlayerState->fullscreen() ); | 160 | setLooping( mediaPlayerState->fullscreen() ); |
161 | // setPaused( mediaPlayerState->paused() ); | 161 | // setPaused( mediaPlayerState->paused() ); |
162 | setPlaying( mediaPlayerState->playing() ); | 162 | setPlaying( mediaPlayerState->playing() ); |
163 | 163 | this->setFocus(); | |
164 | } | 164 | } |
165 | 165 | ||
166 | 166 | ||
167 | AudioWidget::~AudioWidget() { | 167 | AudioWidget::~AudioWidget() { |
168 | // setPlaying( false); | ||
168 | 169 | ||
169 | for ( int i = 0; i < 10; i++ ) { | 170 | for ( int i = 0; i < 10; i++ ) { |
170 | delete buttonPixUp[i]; | 171 | if(buttonPixUp[i]) delete buttonPixUp[i]; |
171 | delete buttonPixDown[i]; | 172 | if(buttonPixDown[i]) delete buttonPixDown[i]; |
172 | } | 173 | } |
173 | delete pixBg; | 174 | if(pixBg) delete pixBg; |
174 | delete imgUp; | 175 | if(imgUp) delete imgUp; |
175 | delete imgDn; | 176 | if(imgDn) delete imgDn; |
176 | delete imgButtonMask; | 177 | if(imgButtonMask) delete imgButtonMask; |
177 | for ( int i = 0; i < 10; i++ ) { | 178 | for ( int i = 0; i < 10; i++ ) { |
178 | delete masks[i]; | 179 | if(masks[i]) delete masks[i]; |
179 | } | 180 | } |
180 | } | 181 | } |
181 | 182 | ||
182 | 183 | ||
183 | QPixmap *combineImageWithBackground( QImage img, QPixmap bg, QPoint offset ) { | 184 | QPixmap *combineImageWithBackground( QImage img, QPixmap bg, QPoint offset ) { |
184 | QPixmap pix( img.width(), img.height() ); | 185 | QPixmap pix( img.width(), img.height() ); |
185 | QPainter p( &pix ); | 186 | QPainter p( &pix ); |
186 | p.drawTiledPixmap( pix.rect(), bg, offset ); | 187 | p.drawTiledPixmap( pix.rect(), bg, offset ); |
187 | p.drawImage( 0, 0, img ); | 188 | p.drawImage( 0, 0, img ); |
188 | return new QPixmap( pix ); | 189 | return new QPixmap( pix ); |
189 | } | 190 | } |
190 | 191 | ||
@@ -270,35 +271,37 @@ void AudioWidget::setView( char view ) { | |||
270 | connect( mediaPlayerState, SIGNAL( positionChanged(long) ),this, SLOT( setPosition(long) ) ); | 271 | connect( mediaPlayerState, SIGNAL( positionChanged(long) ),this, SLOT( setPosition(long) ) ); |
271 | connect( mediaPlayerState, SIGNAL( positionUpdated(long) ),this, SLOT( setPosition(long) ) ); | 272 | connect( mediaPlayerState, SIGNAL( positionUpdated(long) ),this, SLOT( setPosition(long) ) ); |
272 | } | 273 | } |
273 | 274 | ||
274 | if ( view == 'a' ) { | 275 | if ( view == 'a' ) { |
275 | startTimer( 150 ); | 276 | startTimer( 150 ); |
276 | // show(); | 277 | // show(); |
277 | showMaximized(); | 278 | showMaximized(); |
278 | } else { | 279 | } else { |
279 | killTimers(); | 280 | killTimers(); |
280 | hide(); | 281 | hide(); |
281 | } | 282 | } |
283 | |||
282 | } | 284 | } |
283 | 285 | ||
284 | 286 | ||
285 | static QString timeAsString( long length ) { | 287 | static QString timeAsString( long length ) { |
286 | length /= 44100; | 288 | length /= 44100; |
287 | int minutes = length / 60; | 289 | int minutes = length / 60; |
288 | int seconds = length % 60; | 290 | int seconds = length % 60; |
289 | return QString("%1:%2%3").arg( minutes ).arg( seconds / 10 ).arg( seconds % 10 ); | 291 | return QString("%1:%2%3").arg( minutes ).arg( seconds / 10 ).arg( seconds % 10 ); |
290 | } | 292 | } |
291 | 293 | ||
292 | void AudioWidget::updateSlider( long i, long max ) { | 294 | void AudioWidget::updateSlider( long i, long max ) { |
295 | this->setFocus(); | ||
293 | time.setText( timeAsString( i ) + " / " + timeAsString( max ) ); | 296 | time.setText( timeAsString( i ) + " / " + timeAsString( max ) ); |
294 | 297 | ||
295 | if ( max == 0 ) | 298 | if ( max == 0 ) |
296 | return; | 299 | return; |
297 | // Will flicker too much if we don't do this | 300 | // Will flicker too much if we don't do this |
298 | // Scale to something reasonable | 301 | // Scale to something reasonable |
299 | int width = slider.width(); | 302 | int width = slider.width(); |
300 | int val = int((double)i * width / max); | 303 | int val = int((double)i * width / max); |
301 | if ( !audioSliderBeingMoved ) { | 304 | if ( !audioSliderBeingMoved ) { |
302 | if ( slider.value() != val ) | 305 | if ( slider.value() != val ) |
303 | slider.setValue( val ); | 306 | slider.setValue( val ); |
304 | if ( slider.maxValue() != width ) | 307 | if ( slider.maxValue() != width ) |
@@ -348,37 +351,37 @@ void AudioWidget::timerEvent( QTimerEvent * ) { | |||
348 | 351 | ||
349 | void AudioWidget::mouseMoveEvent( QMouseEvent *event ) { | 352 | void AudioWidget::mouseMoveEvent( QMouseEvent *event ) { |
350 | for ( int i = 0; i < numButtons; i++ ) { | 353 | for ( int i = 0; i < numButtons; i++ ) { |
351 | if ( event->state() == QMouseEvent::LeftButton ) { | 354 | if ( event->state() == QMouseEvent::LeftButton ) { |
352 | 355 | ||
353 | // The test to see if the mouse click is inside the button or not | 356 | // The test to see if the mouse click is inside the button or not |
354 | int x = event->pos().x() - xoff; | 357 | int x = event->pos().x() - xoff; |
355 | int y = event->pos().y() - yoff; | 358 | int y = event->pos().y() - yoff; |
356 | 359 | ||
357 | bool isOnButton = ( x > 0 && y > 0 && x < imgButtonMask->width() | 360 | bool isOnButton = ( x > 0 && y > 0 && x < imgButtonMask->width() |
358 | && y < imgButtonMask->height() && imgButtonMask->pixelIndex( x, y ) == i + 1 ); | 361 | && y < imgButtonMask->height() && imgButtonMask->pixelIndex( x, y ) == i + 1 ); |
359 | 362 | ||
360 | if ( isOnButton && i == AudioVolumeUp ) | 363 | // if ( isOnButton && i == AudioVolumeUp ) |
361 | qDebug("on up"); | 364 | // qDebug("on up"); |
362 | 365 | ||
363 | if ( isOnButton && !audioButtons[i].isHeld ) { | 366 | if ( isOnButton && !audioButtons[i].isHeld ) { |
364 | audioButtons[i].isHeld = TRUE; | 367 | audioButtons[i].isHeld = TRUE; |
365 | toggleButton(i); | 368 | toggleButton(i); |
366 | switch (i) { | 369 | switch (i) { |
367 | case AudioVolumeUp: | 370 | case AudioVolumeUp: |
368 | qDebug("more clicked"); | 371 | // qDebug("more clicked"); |
369 | emit moreClicked(); | 372 | emit moreClicked(); |
370 | return; | 373 | return; |
371 | case AudioVolumeDown: | 374 | case AudioVolumeDown: |
372 | qDebug("less clicked"); | 375 | // qDebug("less clicked"); |
373 | emit lessClicked(); | 376 | emit lessClicked(); |
374 | return; | 377 | return; |
375 | case AudioForward: | 378 | case AudioForward: |
376 | emit forwardClicked(); | 379 | emit forwardClicked(); |
377 | return; | 380 | return; |
378 | case AudioBack: | 381 | case AudioBack: |
379 | emit backClicked(); | 382 | emit backClicked(); |
380 | return; | 383 | return; |
381 | } | 384 | } |
382 | } else if ( !isOnButton && audioButtons[i].isHeld ) { | 385 | } else if ( !isOnButton && audioButtons[i].isHeld ) { |
383 | audioButtons[i].isHeld = FALSE; | 386 | audioButtons[i].isHeld = FALSE; |
384 | toggleButton(i); | 387 | toggleButton(i); |