Diffstat (limited to 'core/multimedia/opieplayer/audiowidget.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | core/multimedia/opieplayer/audiowidget.cpp | 33 |
1 files changed, 18 insertions, 15 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 | |||
@@ -55,63 +55,63 @@ MediaButton audioButtons[] = { | |||
55 | { TRUE, FALSE, FALSE }, // repeat/loop | 55 | { TRUE, FALSE, FALSE }, // repeat/loop |
56 | { FALSE, FALSE, FALSE }, // playlist | 56 | { FALSE, FALSE, FALSE }, // playlist |
57 | { FALSE, FALSE, FALSE }, // forward | 57 | { FALSE, FALSE, FALSE }, // forward |
58 | { FALSE, FALSE, FALSE } // back | 58 | { FALSE, FALSE, FALSE } // back |
59 | }; | 59 | }; |
60 | 60 | ||
61 | const char *skin_mask_file_names[10] = { | 61 | const char *skin_mask_file_names[10] = { |
62 | "play", "stop", "next", "prev", "up", | 62 | "play", "stop", "next", "prev", "up", |
63 | "down", "loop", "playlist", "forward", "back" | 63 | "down", "loop", "playlist", "forward", "back" |
64 | }; | 64 | }; |
65 | 65 | ||
66 | static void changeTextColor( QWidget *w ) { | 66 | 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 | ||
106 | if ( !masks[i]->isNull() ) { | 106 | if ( !masks[i]->isNull() ) { |
107 | QImage imgMask = masks[i]->convertToImage(); | 107 | QImage imgMask = masks[i]->convertToImage(); |
108 | uchar **dest = imgButtonMask->jumpTable(); | 108 | uchar **dest = imgButtonMask->jumpTable(); |
109 | for ( int y = 0; y < imgUp->height(); y++ ) { | 109 | for ( int y = 0; y < imgUp->height(); y++ ) { |
110 | uchar *line = dest[y]; | 110 | uchar *line = dest[y]; |
111 | for ( int x = 0; x < imgUp->width(); x++ ) | 111 | for ( int x = 0; x < imgUp->width(); x++ ) |
112 | if ( !qRed( imgMask.pixel( x, y ) ) ) | 112 | if ( !qRed( imgMask.pixel( x, y ) ) ) |
113 | line[x] = i + 1; | 113 | line[x] = i + 1; |
114 | } | 114 | } |
115 | } | 115 | } |
116 | 116 | ||
117 | } | 117 | } |
@@ -139,64 +139,65 @@ AudioWidget::AudioWidget(QWidget* parent, const char* name, WFlags f) : | |||
139 | slider.setBackgroundPixmap( *pixBg ); | 139 | slider.setBackgroundPixmap( *pixBg ); |
140 | 140 | ||
141 | time.setFocusPolicy( QWidget::NoFocus ); | 141 | time.setFocusPolicy( QWidget::NoFocus ); |
142 | time.setAlignment( Qt::AlignCenter ); | 142 | time.setAlignment( Qt::AlignCenter ); |
143 | time.setFrame(FALSE); | 143 | time.setFrame(FALSE); |
144 | changeTextColor( &time ); | 144 | changeTextColor( &time ); |
145 | 145 | ||
146 | resizeEvent( NULL ); | 146 | resizeEvent( NULL ); |
147 | 147 | ||
148 | connect( &slider, SIGNAL( sliderPressed() ), this, SLOT( sliderPressed() ) ); | 148 | connect( &slider, SIGNAL( sliderPressed() ), this, SLOT( sliderPressed() ) ); |
149 | connect( &slider, SIGNAL( sliderReleased() ), this, SLOT( sliderReleased() ) ); | 149 | connect( &slider, SIGNAL( sliderReleased() ), this, SLOT( sliderReleased() ) ); |
150 | 150 | ||
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 | ||
191 | 192 | ||
192 | QPixmap *maskPixToMask( QPixmap pix, QBitmap mask ) | 193 | QPixmap *maskPixToMask( QPixmap pix, QBitmap mask ) |
193 | { | 194 | { |
194 | QPixmap *pixmap = new QPixmap( pix ); | 195 | QPixmap *pixmap = new QPixmap( pix ); |
195 | pixmap->setMask( mask ); | 196 | pixmap->setMask( mask ); |
196 | return pixmap; | 197 | return pixmap; |
197 | } | 198 | } |
198 | 199 | ||
199 | 200 | ||
200 | 201 | ||
201 | void AudioWidget::resizeEvent( QResizeEvent * ) { | 202 | void AudioWidget::resizeEvent( QResizeEvent * ) { |
202 | int h = height(); | 203 | int h = height(); |
@@ -258,60 +259,62 @@ void AudioWidget::setLength( long max ) { | |||
258 | 259 | ||
259 | 260 | ||
260 | void AudioWidget::setView( char view ) { | 261 | void AudioWidget::setView( char view ) { |
261 | 262 | ||
262 | if (mediaPlayerState->isStreaming) { | 263 | if (mediaPlayerState->isStreaming) { |
263 | if( !slider.isHidden()) slider.hide(); | 264 | if( !slider.isHidden()) slider.hide(); |
264 | disconnect( mediaPlayerState, SIGNAL( positionChanged(long) ),this, SLOT( setPosition(long) ) ); | 265 | disconnect( mediaPlayerState, SIGNAL( positionChanged(long) ),this, SLOT( setPosition(long) ) ); |
265 | disconnect( mediaPlayerState, SIGNAL( positionUpdated(long) ),this, SLOT( setPosition(long) ) ); | 266 | disconnect( mediaPlayerState, SIGNAL( positionUpdated(long) ),this, SLOT( setPosition(long) ) ); |
266 | } else { | 267 | } else { |
267 | // this stops the slider from being moved, thus | 268 | // this stops the slider from being moved, thus |
268 | // does not stop stream when it reaches the end | 269 | // does not stop stream when it reaches the end |
269 | slider.show(); | 270 | slider.show(); |
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 ) { |
293 | time.setText( timeAsString( i ) + " / " + timeAsString( max ) ); | 295 | this->setFocus(); |
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 ) |
305 | slider.setMaxValue( width ); | 308 | slider.setMaxValue( width ); |
306 | } | 309 | } |
307 | } | 310 | } |
308 | 311 | ||
309 | 312 | ||
310 | void AudioWidget::setToggleButton( int i, bool down ) { | 313 | void AudioWidget::setToggleButton( int i, bool down ) { |
311 | if ( down != audioButtons[i].isDown ) | 314 | if ( down != audioButtons[i].isDown ) |
312 | toggleButton( i ); | 315 | toggleButton( i ); |
313 | } | 316 | } |
314 | 317 | ||
315 | 318 | ||
316 | void AudioWidget::toggleButton( int i ) { | 319 | void AudioWidget::toggleButton( int i ) { |
317 | audioButtons[i].isDown = !audioButtons[i].isDown; | 320 | audioButtons[i].isDown = !audioButtons[i].isDown; |
@@ -336,61 +339,61 @@ void AudioWidget::timerEvent( QTimerEvent * ) { | |||
336 | // Optimize to only draw the little bit of the changing images which is different | 339 | // Optimize to only draw the little bit of the changing images which is different |
337 | p.drawPixmap( x + 14, y + 8, *pixmaps[3], 32 * frame, 0, 32, 32 ); | 340 | p.drawPixmap( x + 14, y + 8, *pixmaps[3], 32 * frame, 0, 32, 32 ); |
338 | p.drawPixmap( x + 37, y + 37, *pixmaps[2], 18 * AudioPlay, 0, 6, 3 ); | 341 | p.drawPixmap( x + 37, y + 37, *pixmaps[2], 18 * AudioPlay, 0, 6, 3 ); |
339 | */ | 342 | */ |
340 | /* | 343 | /* |
341 | static int frame = 0; | 344 | static int frame = 0; |
342 | if ( !mediaPlayerState->paused() && audioButtons[ AudioPlay ].isDown ) { | 345 | if ( !mediaPlayerState->paused() && audioButtons[ AudioPlay ].isDown ) { |
343 | frame = frame >= 7 ? 0 : frame + 1; | 346 | frame = frame >= 7 ? 0 : frame + 1; |
344 | } | 347 | } |
345 | */ | 348 | */ |
346 | } | 349 | } |
347 | 350 | ||
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); |
385 | } | 388 | } |
386 | } else { | 389 | } else { |
387 | if ( audioButtons[i].isHeld ) { | 390 | if ( audioButtons[i].isHeld ) { |
388 | audioButtons[i].isHeld = FALSE; | 391 | audioButtons[i].isHeld = FALSE; |
389 | if ( !audioButtons[i].isToggle ) | 392 | if ( !audioButtons[i].isToggle ) |
390 | setToggleButton( i, FALSE ); | 393 | setToggleButton( i, FALSE ); |
391 | switch (i) { | 394 | switch (i) { |
392 | case AudioPlay: | 395 | case AudioPlay: |
393 | if( mediaPlayerState->isPaused ) { | 396 | if( mediaPlayerState->isPaused ) { |
394 | mediaPlayerState->setPaused( FALSE ); | 397 | mediaPlayerState->setPaused( FALSE ); |
395 | return; | 398 | return; |
396 | } else if( !mediaPlayerState->isPaused ) { | 399 | } else if( !mediaPlayerState->isPaused ) { |