-rw-r--r-- | noncore/multimedia/opieplayer2/audiowidget.cpp | 31 | ||||
-rw-r--r-- | noncore/multimedia/opieplayer2/audiowidget.h | 6 |
2 files changed, 23 insertions, 14 deletions
diff --git a/noncore/multimedia/opieplayer2/audiowidget.cpp b/noncore/multimedia/opieplayer2/audiowidget.cpp index 2cb1385..cc6187c 100644 --- a/noncore/multimedia/opieplayer2/audiowidget.cpp +++ b/noncore/multimedia/opieplayer2/audiowidget.cpp | |||
@@ -91,37 +91,36 @@ void Ticker::drawContents( QPainter *p ) { | |||
91 | } | 91 | } |
92 | p->drawPixmap( 0, 0, pm ); | 92 | p->drawPixmap( 0, 0, pm ); |
93 | } | 93 | } |
94 | 94 | ||
95 | struct MediaButton { | 95 | struct MediaButton { |
96 | bool isToggle, isHeld, isDown; | 96 | bool isToggle, isHeld, isDown; |
97 | }; | 97 | }; |
98 | 98 | ||
99 | //Layout information for the audioButtons (and if it is a toggle button or not) | 99 | //Layout information for the audioButtons (and if it is a toggle button or not) |
100 | MediaButton audioButtons[] = { | 100 | MediaButton audioButtons[] = { |
101 | { TRUE, FALSE, FALSE }, // play | 101 | { TRUE, FALSE, FALSE }, // play |
102 | { FALSE, FALSE, FALSE }, // stop | 102 | { FALSE, FALSE, FALSE }, // stop |
103 | { FALSE, FALSE, FALSE }, // pause | ||
104 | { FALSE, FALSE, FALSE }, // next | 103 | { FALSE, FALSE, FALSE }, // next |
105 | { FALSE, FALSE, FALSE }, // previous | 104 | { FALSE, FALSE, FALSE }, // previous |
106 | { FALSE, FALSE, FALSE }, // volume up | 105 | { FALSE, FALSE, FALSE }, // volume up |
107 | { FALSE, FALSE, FALSE }, // volume down | 106 | { FALSE, FALSE, FALSE }, // volume down |
108 | { TRUE, FALSE, FALSE }, // repeat/loop | 107 | { TRUE, FALSE, FALSE }, // repeat/loop |
109 | { FALSE, FALSE, FALSE }, // playlist | 108 | { FALSE, FALSE, FALSE }, // playlist |
110 | { FALSE, FALSE, FALSE }, // forward | 109 | { FALSE, FALSE, FALSE }, // forward |
111 | { FALSE, FALSE, FALSE } // back | 110 | { FALSE, FALSE, FALSE } // back |
112 | }; | 111 | }; |
113 | 112 | ||
114 | const char *skin_mask_file_names[11] = { | 113 | const char *skin_mask_file_names[10] = { |
115 | "play", "stop", "pause", "next", "prev", "up", | 114 | "play", "stop", "next", "prev", "up", |
116 | "down", "loop", "playlist", "forward", "back" | 115 | "down", "loop", "playlist", "forward", "back" |
117 | }; | 116 | }; |
118 | 117 | ||
119 | 118 | ||
120 | static void changeTextColor( QWidget *w ) { | 119 | static void changeTextColor( QWidget *w ) { |
121 | QPalette p = w->palette(); | 120 | QPalette p = w->palette(); |
122 | p.setBrush( QColorGroup::Background, QColor( 167, 212, 167 ) ); | 121 | p.setBrush( QColorGroup::Background, QColor( 167, 212, 167 ) ); |
123 | p.setBrush( QColorGroup::Base, QColor( 167, 212, 167 ) ); | 122 | p.setBrush( QColorGroup::Base, QColor( 167, 212, 167 ) ); |
124 | w->setPalette( p ); | 123 | w->setPalette( p ); |
125 | } | 124 | } |
126 | 125 | ||
127 | static const int numButtons = (sizeof(audioButtons)/sizeof(MediaButton)); | 126 | static const int numButtons = (sizeof(audioButtons)/sizeof(MediaButton)); |
@@ -136,42 +135,42 @@ AudioWidget::AudioWidget(QWidget* parent, const char* name, WFlags f) : | |||
136 | skin = cfg.readEntry("Skin","default"); | 135 | skin = cfg.readEntry("Skin","default"); |
137 | //skin = "scaleTest"; | 136 | //skin = "scaleTest"; |
138 | // color of background, frame, degree of transparency | 137 | // color of background, frame, degree of transparency |
139 | 138 | ||
140 | QString skinPath = "opieplayer2/skins/" + skin; | 139 | QString skinPath = "opieplayer2/skins/" + skin; |
141 | pixBg = new QPixmap( Resource::loadPixmap( QString("%1/background").arg(skinPath) ) ); | 140 | pixBg = new QPixmap( Resource::loadPixmap( QString("%1/background").arg(skinPath) ) ); |
142 | imgUp = new QImage( Resource::loadImage( QString("%1/skin_up").arg(skinPath) ) ); | 141 | imgUp = new QImage( Resource::loadImage( QString("%1/skin_up").arg(skinPath) ) ); |
143 | imgDn = new QImage( Resource::loadImage( QString("%1/skin_down").arg(skinPath) ) ); | 142 | imgDn = new QImage( Resource::loadImage( QString("%1/skin_down").arg(skinPath) ) ); |
144 | 143 | ||
145 | imgButtonMask = new QImage( imgUp->width(), imgUp->height(), 8, 255 ); | 144 | imgButtonMask = new QImage( imgUp->width(), imgUp->height(), 8, 255 ); |
146 | imgButtonMask->fill( 0 ); | 145 | imgButtonMask->fill( 0 ); |
147 | 146 | ||
148 | for ( int i = 0; i < 11; i++ ) { | 147 | for ( int i = 0; i < 10; i++ ) { |
149 | QString filename = QString(getenv("OPIEDIR")) + "/pics/" + skinPath + "/skin_mask_" + skin_mask_file_names[i] + ".png"; | 148 | QString filename = QString(getenv("OPIEDIR")) + "/pics/" + skinPath + "/skin_mask_" + skin_mask_file_names[i] + ".png"; |
150 | masks[i] = new QBitmap( filename ); | 149 | masks[i] = new QBitmap( filename ); |
151 | 150 | ||
152 | if ( !masks[i]->isNull() ) { | 151 | if ( !masks[i]->isNull() ) { |
153 | QImage imgMask = masks[i]->convertToImage(); | 152 | QImage imgMask = masks[i]->convertToImage(); |
154 | uchar **dest = imgButtonMask->jumpTable(); | 153 | uchar **dest = imgButtonMask->jumpTable(); |
155 | for ( int y = 0; y < imgUp->height(); y++ ) { | 154 | for ( int y = 0; y < imgUp->height(); y++ ) { |
156 | uchar *line = dest[y]; | 155 | uchar *line = dest[y]; |
157 | for ( int x = 0; x < imgUp->width(); x++ ) | 156 | for ( int x = 0; x < imgUp->width(); x++ ) |
158 | if ( !qRed( imgMask.pixel( x, y ) ) ) | 157 | if ( !qRed( imgMask.pixel( x, y ) ) ) |
159 | line[x] = i + 1; | 158 | line[x] = i + 1; |
160 | } | 159 | } |
161 | } | 160 | } |
162 | 161 | ||
163 | } | 162 | } |
164 | 163 | ||
165 | for ( int i = 0; i < 11; i++ ) { | 164 | for ( int i = 0; i < 10; i++ ) { |
166 | buttonPixUp[i] = NULL; | 165 | buttonPixUp[i] = NULL; |
167 | buttonPixDown[i] = NULL; | 166 | buttonPixDown[i] = NULL; |
168 | } | 167 | } |
169 | 168 | ||
170 | setBackgroundPixmap( *pixBg ); | 169 | setBackgroundPixmap( *pixBg ); |
171 | 170 | ||
172 | songInfo.setFocusPolicy( QWidget::NoFocus ); | 171 | songInfo.setFocusPolicy( QWidget::NoFocus ); |
173 | changeTextColor( &songInfo ); | 172 | changeTextColor( &songInfo ); |
174 | 173 | ||
175 | slider.setFixedHeight( 20 ); | 174 | slider.setFixedHeight( 20 ); |
176 | slider.setMinValue( 0 ); | 175 | slider.setMinValue( 0 ); |
177 | slider.setMaxValue( 1 ); | 176 | slider.setMaxValue( 1 ); |
@@ -203,33 +202,33 @@ AudioWidget::AudioWidget(QWidget* parent, const char* name, WFlags f) : | |||
203 | 202 | ||
204 | // Intialise state | 203 | // Intialise state |
205 | setLength( mediaPlayerState->length() ); | 204 | setLength( mediaPlayerState->length() ); |
206 | setPosition( mediaPlayerState->position() ); | 205 | setPosition( mediaPlayerState->position() ); |
207 | setLooping( mediaPlayerState->fullscreen() ); | 206 | setLooping( mediaPlayerState->fullscreen() ); |
208 | setPaused( mediaPlayerState->paused() ); | 207 | setPaused( mediaPlayerState->paused() ); |
209 | setPlaying( mediaPlayerState->playing() ); | 208 | setPlaying( mediaPlayerState->playing() ); |
210 | 209 | ||
211 | } | 210 | } |
212 | 211 | ||
213 | AudioWidget::~AudioWidget() { | 212 | AudioWidget::~AudioWidget() { |
214 | 213 | ||
215 | for ( int i = 0; i < 11; i++ ) { | 214 | for ( int i = 0; i < 10; i++ ) { |
216 | delete buttonPixUp[i]; | 215 | delete buttonPixUp[i]; |
217 | delete buttonPixDown[i]; | 216 | delete buttonPixDown[i]; |
218 | } | 217 | } |
219 | delete pixBg; | 218 | delete pixBg; |
220 | delete imgUp; | 219 | delete imgUp; |
221 | delete imgDn; | 220 | delete imgDn; |
222 | delete imgButtonMask; | 221 | delete imgButtonMask; |
223 | for ( int i = 0; i < 11; i++ ) { | 222 | for ( int i = 0; i < 10; i++ ) { |
224 | delete masks[i]; | 223 | delete masks[i]; |
225 | } | 224 | } |
226 | } | 225 | } |
227 | 226 | ||
228 | QPixmap *combineImageWithBackground( QImage img, QPixmap bg, QPoint offset ) { | 227 | QPixmap *combineImageWithBackground( QImage img, QPixmap bg, QPoint offset ) { |
229 | QPixmap pix( img.width(), img.height() ); | 228 | QPixmap pix( img.width(), img.height() ); |
230 | QPainter p( &pix ); | 229 | QPainter p( &pix ); |
231 | p.drawTiledPixmap( pix.rect(), bg, offset ); | 230 | p.drawTiledPixmap( pix.rect(), bg, offset ); |
232 | p.drawImage( 0, 0, img ); | 231 | p.drawImage( 0, 0, img ); |
233 | return new QPixmap( pix ); | 232 | return new QPixmap( pix ); |
234 | } | 233 | } |
235 | 234 | ||
@@ -251,25 +250,25 @@ void AudioWidget::resizeEvent( QResizeEvent * ) { | |||
251 | slider.setFixedWidth( w - 110 ); | 250 | slider.setFixedWidth( w - 110 ); |
252 | slider.setGeometry( QRect( 15, h - 30, w - 90, 20 ) ); | 251 | slider.setGeometry( QRect( 15, h - 30, w - 90, 20 ) ); |
253 | slider.setBackgroundOrigin( QWidget::ParentOrigin ); | 252 | slider.setBackgroundOrigin( QWidget::ParentOrigin ); |
254 | time.setGeometry( QRect( w - 85, h - 30, 70, 20 ) ); | 253 | time.setGeometry( QRect( w - 85, h - 30, 70, 20 ) ); |
255 | 254 | ||
256 | xoff = ( w - imgUp->width() ) / 2; | 255 | xoff = ( w - imgUp->width() ) / 2; |
257 | yoff = (( h - imgUp->height() ) / 2) - 10; | 256 | yoff = (( h - imgUp->height() ) / 2) - 10; |
258 | QPoint p( xoff, yoff ); | 257 | QPoint p( xoff, yoff ); |
259 | 258 | ||
260 | QPixmap *pixUp = combineImageWithBackground( *imgUp, *pixBg, p ); | 259 | QPixmap *pixUp = combineImageWithBackground( *imgUp, *pixBg, p ); |
261 | QPixmap *pixDn = combineImageWithBackground( *imgDn, *pixBg, p ); | 260 | QPixmap *pixDn = combineImageWithBackground( *imgDn, *pixBg, p ); |
262 | 261 | ||
263 | for ( int i = 0; i < 11; i++ ) { | 262 | for ( int i = 0; i < 10; i++ ) { |
264 | if ( !masks[i]->isNull() ) { | 263 | if ( !masks[i]->isNull() ) { |
265 | delete buttonPixUp[i]; | 264 | delete buttonPixUp[i]; |
266 | delete buttonPixDown[i]; | 265 | delete buttonPixDown[i]; |
267 | buttonPixUp[i] = maskPixToMask( *pixUp, *masks[i] ); | 266 | buttonPixUp[i] = maskPixToMask( *pixUp, *masks[i] ); |
268 | buttonPixDown[i] = maskPixToMask( *pixDn, *masks[i] ); | 267 | buttonPixDown[i] = maskPixToMask( *pixDn, *masks[i] ); |
269 | } | 268 | } |
270 | } | 269 | } |
271 | 270 | ||
272 | delete pixUp; | 271 | delete pixUp; |
273 | delete pixDn; | 272 | delete pixDn; |
274 | } | 273 | } |
275 | 274 | ||
@@ -418,52 +417,62 @@ void AudioWidget::mouseMoveEvent( QMouseEvent *event ) { | |||
418 | int y = event->pos().y() - yoff; | 417 | int y = event->pos().y() - yoff; |
419 | 418 | ||
420 | bool isOnButton = ( x > 0 && y > 0 && x < imgButtonMask->width() | 419 | bool isOnButton = ( x > 0 && y > 0 && x < imgButtonMask->width() |
421 | && y < imgButtonMask->height() | 420 | && y < imgButtonMask->height() |
422 | && imgButtonMask->pixelIndex( x, y ) == i + 1 ); | 421 | && imgButtonMask->pixelIndex( x, y ) == i + 1 ); |
423 | 422 | ||
424 | if ( isOnButton && !audioButtons[i].isHeld ) { | 423 | if ( isOnButton && !audioButtons[i].isHeld ) { |
425 | audioButtons[i].isHeld = TRUE; | 424 | audioButtons[i].isHeld = TRUE; |
426 | toggleButton(i); | 425 | toggleButton(i); |
427 | 426 | ||
428 | switch (i) { | 427 | switch (i) { |
429 | case AudioVolumeUp: | 428 | case AudioVolumeUp: |
430 | qDebug("more clicked"); | ||
431 | emit moreClicked(); | 429 | emit moreClicked(); |
432 | return; | 430 | return; |
433 | case AudioVolumeDown: | 431 | case AudioVolumeDown: |
434 | emit lessClicked(); | 432 | emit lessClicked(); |
435 | return; | 433 | return; |
436 | case AudioForward: | 434 | case AudioForward: |
437 | emit forwardClicked(); | 435 | emit forwardClicked(); |
438 | return; | 436 | return; |
439 | case AudioBack: | 437 | case AudioBack: |
440 | emit backClicked(); | 438 | emit backClicked(); |
441 | return; | 439 | return; |
442 | } | 440 | } |
443 | } else if ( !isOnButton && audioButtons[i].isHeld ) { | 441 | } else if ( !isOnButton && audioButtons[i].isHeld ) { |
444 | audioButtons[i].isHeld = FALSE; | 442 | audioButtons[i].isHeld = FALSE; |
445 | toggleButton(i); | 443 | toggleButton(i); |
446 | } | 444 | } |
447 | } else { | 445 | } else { |
448 | if ( audioButtons[i].isHeld ) { | 446 | if ( audioButtons[i].isHeld ) { |
449 | audioButtons[i].isHeld = FALSE; | 447 | audioButtons[i].isHeld = FALSE; |
450 | if ( !audioButtons[i].isToggle ) { | 448 | if ( !audioButtons[i].isToggle ) { |
451 | setToggleButton( i, FALSE ); | 449 | setToggleButton( i, FALSE ); |
452 | qDebug("button toggled3 %d",i); | 450 | qDebug("button toggled3 %d",i); |
453 | } | 451 | } |
454 | switch (i) { | 452 | switch (i) { |
455 | case AudioPlay: mediaPlayerState->setPlaying(audioButtons[i].isDown); return; | 453 | case AudioPlay: |
454 | if( mediaPlayerState->isPaused ) { | ||
455 | setToggleButton( i, FALSE ); | ||
456 | mediaPlayerState->setPaused( FALSE ); | ||
457 | return; | ||
458 | } else if( !mediaPlayerState->isPaused ) { | ||
459 | setToggleButton( i, TRUE ); | ||
460 | mediaPlayerState->setPaused( TRUE ); | ||
461 | return; | ||
462 | } else { | ||
463 | // setToggleButton( i, TRUE ); | ||
464 | // mediaPlayerState->setPlaying( videoButtons[i].isDown ); | ||
465 | } | ||
456 | case AudioStop: mediaPlayerState->setPlaying(FALSE); return; | 466 | case AudioStop: mediaPlayerState->setPlaying(FALSE); return; |
457 | case AudioPause: mediaPlayerState->setPaused( audioButtons[i].isDown); return; | ||
458 | case AudioNext: mediaPlayerState->setNext(); return; | 467 | case AudioNext: mediaPlayerState->setNext(); return; |
459 | case AudioPrevious: mediaPlayerState->setPrev(); return; | 468 | case AudioPrevious: mediaPlayerState->setPrev(); return; |
460 | case AudioLoop: mediaPlayerState->setLooping(audioButtons[i].isDown); return; | 469 | case AudioLoop: mediaPlayerState->setLooping(audioButtons[i].isDown); return; |
461 | case AudioVolumeUp: emit moreReleased(); return; | 470 | case AudioVolumeUp: emit moreReleased(); return; |
462 | case AudioVolumeDown: emit lessReleased(); return; | 471 | case AudioVolumeDown: emit lessReleased(); return; |
463 | case AudioPlayList: mediaPlayerState->setList(); return; | 472 | case AudioPlayList: mediaPlayerState->setList(); return; |
464 | case AudioForward: emit forwardReleased(); return; | 473 | case AudioForward: emit forwardReleased(); return; |
465 | case AudioBack: emit backReleased(); return; | 474 | case AudioBack: emit backReleased(); return; |
466 | } | 475 | } |
467 | } | 476 | } |
468 | } | 477 | } |
469 | } | 478 | } |
diff --git a/noncore/multimedia/opieplayer2/audiowidget.h b/noncore/multimedia/opieplayer2/audiowidget.h index e05188e..772d1d1 100644 --- a/noncore/multimedia/opieplayer2/audiowidget.h +++ b/noncore/multimedia/opieplayer2/audiowidget.h | |||
@@ -124,26 +124,26 @@ private slots: | |||
124 | void skipBack(); | 124 | void skipBack(); |
125 | void stopSkip(); | 125 | void stopSkip(); |
126 | private: | 126 | private: |
127 | void toggleButton( int ); | 127 | void toggleButton( int ); |
128 | void setToggleButton( int, bool ); | 128 | void setToggleButton( int, bool ); |
129 | void paintButton( QPainter *p, int i ); | 129 | void paintButton( QPainter *p, int i ); |
130 | int skipDirection; | 130 | int skipDirection; |
131 | QString skin; | 131 | QString skin; |
132 | QPixmap *pixBg; | 132 | QPixmap *pixBg; |
133 | QImage *imgUp; | 133 | QImage *imgUp; |
134 | QImage *imgDn; | 134 | QImage *imgDn; |
135 | QImage *imgButtonMask; | 135 | QImage *imgButtonMask; |
136 | QBitmap *masks[11]; | 136 | QBitmap *masks[10]; |
137 | QPixmap *buttonPixUp[11]; | 137 | QPixmap *buttonPixUp[10]; |
138 | QPixmap *buttonPixDown[11]; | 138 | QPixmap *buttonPixDown[10]; |
139 | 139 | ||
140 | QPixmap *pixmaps[4]; | 140 | QPixmap *pixmaps[4]; |
141 | Ticker songInfo; | 141 | Ticker songInfo; |
142 | QSlider slider; | 142 | QSlider slider; |
143 | QLineEdit time; | 143 | QLineEdit time; |
144 | int xoff, yoff; | 144 | int xoff, yoff; |
145 | }; | 145 | }; |
146 | 146 | ||
147 | 147 | ||
148 | #endif // AUDIO_WIDGET_H | 148 | #endif // AUDIO_WIDGET_H |
149 | 149 | ||