Diffstat (limited to 'core/multimedia/opieplayer/audiowidget.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | core/multimedia/opieplayer/audiowidget.cpp | 316 |
1 files changed, 220 insertions, 96 deletions
diff --git a/core/multimedia/opieplayer/audiowidget.cpp b/core/multimedia/opieplayer/audiowidget.cpp index b96b1ef..896da91 100644 --- a/core/multimedia/opieplayer/audiowidget.cpp +++ b/core/multimedia/opieplayer/audiowidget.cpp | |||
@@ -10,358 +10,482 @@ | |||
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | #include <qpe/qpeapplication.h> | 20 | #include <qpe/qpeapplication.h> |
21 | #include <qpe/resource.h> | 21 | #include <qpe/resource.h> |
22 | #include <qpe/config.h> | 22 | #include <qpe/config.h> |
23 | 23 | ||
24 | #include <qwidget.h> | 24 | #include <qwidget.h> |
25 | #include <qpixmap.h> | 25 | #include <qpixmap.h> |
26 | #include <qbutton.h> | 26 | #include <qbutton.h> |
27 | #include <qpainter.h> | 27 | #include <qpainter.h> |
28 | #include <qframe.h> | 28 | #include <qframe.h> |
29 | #include <qlayout.h> | 29 | #include <qlayout.h> |
30 | 30 | ||
31 | #include "audiowidget.h" | 31 | #include "audiowidget.h" |
32 | #include "mediaplayerstate.h" | 32 | #include "mediaplayerstate.h" |
33 | 33 | ||
34 | #include <stdlib.h> | ||
35 | #include <stdio.h> | ||
36 | |||
34 | extern MediaPlayerState *mediaPlayerState; | 37 | extern MediaPlayerState *mediaPlayerState; |
35 | 38 | ||
36 | 39 | ||
37 | static const int xo = -2; // movable x offset | 40 | static const int xo = -2; // movable x offset |
38 | static const int yo = 22; // movable y offset | 41 | static const int yo = 22; // movable y offset |
39 | 42 | ||
40 | |||
41 | struct MediaButton { | 43 | struct MediaButton { |
42 | int xPos, yPos; | 44 | bool isToggle, isHeld, isDown; |
43 | int color; | ||
44 | bool isToggle, isBig, isHeld, isDown; | ||
45 | }; | 45 | }; |
46 | 46 | ||
47 | |||
48 | // Layout information for the audioButtons (and if it is a toggle button or not) | 47 | // Layout information for the audioButtons (and if it is a toggle button or not) |
49 | MediaButton audioButtons[] = { | 48 | MediaButton audioButtons[] = { |
50 | { 3*30-15+xo, 3*30-13+yo, 0, TRUE, TRUE, FALSE, FALSE }, // play | 49 | { TRUE, FALSE, FALSE }, // play |
51 | { 1*30+xo, 5*30+yo, 2, FALSE, FALSE, FALSE, FALSE }, // stop | 50 | { FALSE, FALSE, FALSE }, // stop |
52 | { 5*30+xo, 5*30+yo, 2, TRUE, FALSE, FALSE, FALSE }, // pause | 51 | { TRUE, FALSE, FALSE }, // pause |
53 | { 6*30-5+xo, 3*30+yo, 1, FALSE, FALSE, FALSE, FALSE }, // next | 52 | { FALSE, FALSE, FALSE }, // next |
54 | { 0*30+5+xo, 3*30+yo, 1, FALSE, FALSE, FALSE, FALSE }, // previous | 53 | { FALSE, FALSE, FALSE }, // previous |
55 | { 3*30+xo, 0*30+5+yo, 3, FALSE, FALSE, FALSE, FALSE }, // volume up | 54 | { FALSE, FALSE, FALSE }, // volume up |
56 | { 3*30+xo, 6*30-5+yo, 3, FALSE, FALSE, FALSE, FALSE }, // volume down | 55 | { FALSE, FALSE, FALSE }, // volume down |
57 | { 5*30+xo, 1*30+yo, 0, TRUE, FALSE, FALSE, FALSE }, // repeat/loop | 56 | { TRUE, FALSE, FALSE }, // repeat/loop |
58 | { 1*30+xo, 1*30+yo, 0, FALSE, FALSE, FALSE, FALSE } // playlist | 57 | { FALSE, FALSE, FALSE }, // playlist |
58 | { FALSE, FALSE, FALSE }, // forward | ||
59 | { FALSE, FALSE, FALSE } // back | ||
60 | }; | ||
61 | |||
62 | const char *skin_mask_file_names[11] = { | ||
63 | "play", "stop", "pause", "next", "prev", "up", | ||
64 | "down", "loop", "playlist", "forward", "back" | ||
59 | }; | 65 | }; |
60 | 66 | ||
61 | 67 | ||
62 | static const int numButtons = (sizeof(audioButtons)/sizeof(MediaButton)); | 68 | static void changeTextColor( QWidget *w ) { |
69 | QPalette p = w->palette(); | ||
70 | p.setBrush( QColorGroup::Background, QColor( 167, 212, 167 ) ); | ||
71 | p.setBrush( QColorGroup::Base, QColor( 167, 212, 167 ) ); | ||
72 | w->setPalette( p ); | ||
73 | } | ||
63 | 74 | ||
75 | static const int numButtons = (sizeof(audioButtons)/sizeof(MediaButton)); | ||
64 | 76 | ||
65 | AudioWidget::AudioWidget(QWidget* parent, const char* name, WFlags f) : | 77 | AudioWidget::AudioWidget(QWidget* parent, const char* name, WFlags f) : |
66 | QWidget( parent, name, f ) | 78 | QWidget( parent, name, f ), songInfo( this ), slider( Qt::Horizontal, this ), time( this ) |
67 | { | 79 | { |
68 | setCaption( tr("OpiePlayer") ); | 80 | setCaption( tr("OpiePlayer") ); |
81 | qDebug("<<<<<audioWidget"); | ||
82 | |||
69 | Config cfg("OpiePlayer"); | 83 | Config cfg("OpiePlayer"); |
70 | cfg.setGroup("AudioWidget"); | 84 | cfg.setGroup("AudioWidget"); |
71 | // QGridLayout *layout = new QGridLayout( this ); | 85 | skin = cfg.readEntry("Skin","default"); |
72 | // layout->setSpacing( 2); | 86 | //skin = "scaleTest"; |
73 | // layout->setMargin( 2); | 87 | // color of background, frame, degree of transparency |
74 | QString backgroundPix, buttonsAllPix, buttonsBigPix, controlsPix, animatedPix; | 88 | |
75 | backgroundPix=cfg.readEntry( " backgroundPix", "opieplayer/metalFinish"); | 89 | QString skinPath = "opieplayer2/skins/" + skin; |
76 | buttonsAllPix=cfg.readEntry( "buttonsAllPix","opieplayer/mediaButtonsAll"); | 90 | pixBg = new QPixmap( Resource::loadPixmap( QString("%1/background").arg(skinPath) ) ); |
77 | buttonsBigPix=cfg.readEntry( "buttonsBigPix","opieplayer/mediaButtonsBig"); | 91 | imgUp = new QImage( Resource::loadImage( QString("%1/skin_up").arg(skinPath) ) ); |
78 | controlsPix=cfg.readEntry( "controlsPix","opieplayer/mediaControls"); | 92 | imgDn = new QImage( Resource::loadImage( QString("%1/skin_down").arg(skinPath) ) ); |
79 | // animatedPix=cfg.readEntry( "animatedPix", "opieplayer/animatedButton"); | 93 | |
80 | 94 | imgButtonMask = new QImage( imgUp->width(), imgUp->height(), 8, 255 ); | |
81 | setBackgroundPixmap( Resource::loadPixmap( backgroundPix) ); | 95 | imgButtonMask->fill( 0 ); |
82 | pixmaps[0] = new QPixmap( Resource::loadPixmap( buttonsAllPix ) ); | 96 | |
83 | pixmaps[1] = new QPixmap( Resource::loadPixmap( buttonsBigPix ) ); | 97 | for ( int i = 0; i < 11; i++ ) { |
84 | pixmaps[2] = new QPixmap( Resource::loadPixmap( controlsPix ) ); | 98 | QString filename = QString(getenv("OPIEDIR")) + "/pics/" + skinPath + "/skin_mask_" + skin_mask_file_names[i] + ".png"; |
85 | // pixmaps[3] = new QPixmap( Resource::loadPixmap( animatedPix) ); | 99 | masks[i] = new QBitmap( filename ); |
86 | 100 | ||
87 | songInfo = new Ticker( this ); | 101 | if ( !masks[i]->isNull() ) { |
88 | songInfo->setFocusPolicy( QWidget::NoFocus ); | 102 | QImage imgMask = masks[i]->convertToImage(); |
89 | songInfo->setGeometry( QRect( 7, 3, 220, 20 ) ); | 103 | uchar **dest = imgButtonMask->jumpTable(); |
90 | // layout->addMultiCellWidget( songInfo, 0, 0, 0, 2 ); | 104 | for ( int y = 0; y < imgUp->height(); y++ ) { |
91 | 105 | uchar *line = dest[y]; | |
92 | slider = new QSlider( Qt::Horizontal, this ); | 106 | for ( int x = 0; x < imgUp->width(); x++ ) |
93 | slider->setFixedWidth( 220 ); | 107 | if ( !qRed( imgMask.pixel( x, y ) ) ) |
94 | slider->setFixedHeight( 20 ); | 108 | line[x] = i + 1; |
95 | slider->setMinValue( 0 ); | 109 | } |
96 | slider->setMaxValue( 1 ); | 110 | } |
97 | slider->setBackgroundPixmap( Resource::loadPixmap( backgroundPix ) ); | 111 | |
98 | slider->setFocusPolicy( QWidget::NoFocus ); | 112 | } |
99 | slider->setGeometry( QRect( 7, 262, 220, 20 ) ); | 113 | |
100 | // layout->addMultiCellWidget( slider, 4, 4, 0, 2 ); | 114 | for ( int i = 0; i < 11; i++ ) { |
101 | 115 | buttonPixUp[i] = NULL; | |
102 | connect( slider, SIGNAL( sliderPressed() ), this, SLOT( sliderPressed() ) ); | 116 | buttonPixDown[i] = NULL; |
103 | connect( slider, SIGNAL( sliderReleased() ), this, SLOT( sliderReleased() ) ); | 117 | } |
118 | |||
119 | setBackgroundPixmap( *pixBg ); | ||
120 | |||
121 | songInfo.setFocusPolicy( QWidget::NoFocus ); | ||
122 | |||
123 | changeTextColor( &songInfo ); | ||
124 | songInfo.setBackgroundColor( QColor( 167, 212, 167 )); | ||
125 | songInfo.setFrameStyle( QFrame::NoFrame); | ||
126 | // songInfo.setFrameStyle( QFrame::WinPanel | QFrame::Sunken ); | ||
127 | //NoFrame | ||
128 | // songInfo.setForegroundColor(Qt::white); | ||
129 | |||
130 | slider.setFixedHeight( 20 ); | ||
131 | slider.setMinValue( 0 ); | ||
132 | slider.setMaxValue( 1 ); | ||
133 | slider.setFocusPolicy( QWidget::NoFocus ); | ||
134 | slider.setBackgroundPixmap( *pixBg ); | ||
135 | |||
136 | time.setFocusPolicy( QWidget::NoFocus ); | ||
137 | time.setAlignment( Qt::AlignCenter ); | ||
138 | time.setFrame(FALSE); | ||
139 | changeTextColor( &time ); | ||
140 | |||
141 | resizeEvent( NULL ); | ||
142 | |||
143 | connect( &slider, SIGNAL( sliderPressed() ), this, SLOT( sliderPressed() ) ); | ||
144 | connect( &slider, SIGNAL( sliderReleased() ), this, SLOT( sliderReleased() ) ); | ||
104 | 145 | ||
105 | connect( mediaPlayerState, SIGNAL( lengthChanged(long) ), this, SLOT( setLength(long) ) ); | 146 | connect( mediaPlayerState, SIGNAL( lengthChanged(long) ), this, SLOT( setLength(long) ) ); |
106 | connect( mediaPlayerState, SIGNAL( viewChanged(char) ), this, SLOT( setView(char) ) ); | 147 | connect( mediaPlayerState, SIGNAL( viewChanged(char) ), this, SLOT( setView(char) ) ); |
107 | connect( mediaPlayerState, SIGNAL( loopingToggled(bool) ), this, SLOT( setLooping(bool) ) ); | 148 | connect( mediaPlayerState, SIGNAL( loopingToggled(bool) ), this, SLOT( setLooping(bool) ) ); |
108 | connect( mediaPlayerState, SIGNAL( pausedToggled(bool) ), this, SLOT( setPaused(bool) ) ); | 149 | connect( mediaPlayerState, SIGNAL( pausedToggled(bool) ), this, SLOT( setPaused(bool) ) ); |
109 | connect( mediaPlayerState, SIGNAL( playingToggled(bool) ), this, SLOT( setPlaying(bool) ) ); | 150 | connect( mediaPlayerState, SIGNAL( playingToggled(bool) ), this, SLOT( setPlaying(bool) ) ); |
110 | 151 | ||
111 | // Intialise state | 152 | // Intialise state |
112 | setLength( mediaPlayerState->length() ); | 153 | setLength( mediaPlayerState->length() ); |
113 | setPosition( mediaPlayerState->position() ); | 154 | setPosition( mediaPlayerState->position() ); |
114 | setLooping( mediaPlayerState->fullscreen() ); | 155 | setLooping( mediaPlayerState->fullscreen() ); |
115 | setPaused( mediaPlayerState->paused() ); | 156 | setPaused( mediaPlayerState->paused() ); |
116 | setPlaying( mediaPlayerState->playing() ); | 157 | setPlaying( mediaPlayerState->playing() ); |
117 | 158 | ||
118 | } | 159 | } |
119 | 160 | ||
120 | 161 | ||
121 | AudioWidget::~AudioWidget() { | 162 | AudioWidget::~AudioWidget() { |
122 | mediaPlayerState->isStreaming = FALSE; | 163 | |
123 | for ( int i = 0; i < 3; i++ ) | 164 | for ( int i = 0; i < 11; i++ ) { |
124 | delete pixmaps[i]; | 165 | delete buttonPixUp[i]; |
166 | delete buttonPixDown[i]; | ||
167 | } | ||
168 | delete pixBg; | ||
169 | delete imgUp; | ||
170 | delete imgDn; | ||
171 | delete imgButtonMask; | ||
172 | for ( int i = 0; i < 11; i++ ) { | ||
173 | delete masks[i]; | ||
174 | } | ||
125 | } | 175 | } |
126 | 176 | ||
127 | 177 | ||
128 | static bool audioSliderBeingMoved = FALSE; | 178 | QPixmap *combineImageWithBackground( QImage img, QPixmap bg, QPoint offset ) { |
179 | QPixmap pix( img.width(), img.height() ); | ||
180 | QPainter p( &pix ); | ||
181 | p.drawTiledPixmap( pix.rect(), bg, offset ); | ||
182 | p.drawImage( 0, 0, img ); | ||
183 | return new QPixmap( pix ); | ||
184 | } | ||
185 | |||
186 | |||
187 | QPixmap *maskPixToMask( QPixmap pix, QBitmap mask ) | ||
188 | { | ||
189 | QPixmap *pixmap = new QPixmap( pix ); | ||
190 | pixmap->setMask( mask ); | ||
191 | return pixmap; | ||
192 | } | ||
129 | 193 | ||
130 | 194 | ||
195 | |||
196 | void AudioWidget::resizeEvent( QResizeEvent * ) { | ||
197 | int h = height(); | ||
198 | int w = width(); | ||
199 | |||
200 | songInfo.setGeometry( QRect( 2, 10, w - 4, 20 ) ); | ||
201 | slider.setFixedWidth( w - 110 ); | ||
202 | slider.setGeometry( QRect( 15, h - 30, w - 90, 20 ) ); | ||
203 | slider.setBackgroundOrigin( QWidget::ParentOrigin ); | ||
204 | time.setGeometry( QRect( w - 85, h - 30, 70, 20 ) ); | ||
205 | |||
206 | xoff = ( w - imgUp->width() ) / 2; | ||
207 | yoff = (( h - imgUp->height() ) / 2) - 10; | ||
208 | QPoint p( xoff, yoff ); | ||
209 | |||
210 | QPixmap *pixUp = combineImageWithBackground( *imgUp, *pixBg, p ); | ||
211 | QPixmap *pixDn = combineImageWithBackground( *imgDn, *pixBg, p ); | ||
212 | |||
213 | for ( int i = 0; i < 11; i++ ) { | ||
214 | if ( !masks[i]->isNull() ) { | ||
215 | delete buttonPixUp[i]; | ||
216 | delete buttonPixDown[i]; | ||
217 | buttonPixUp[i] = maskPixToMask( *pixUp, *masks[i] ); | ||
218 | buttonPixDown[i] = maskPixToMask( *pixDn, *masks[i] ); | ||
219 | } | ||
220 | } | ||
221 | |||
222 | delete pixUp; | ||
223 | delete pixDn; | ||
224 | } | ||
225 | |||
226 | |||
227 | static bool audioSliderBeingMoved = FALSE; | ||
228 | |||
131 | void AudioWidget::sliderPressed() { | 229 | void AudioWidget::sliderPressed() { |
132 | audioSliderBeingMoved = TRUE; | 230 | audioSliderBeingMoved = TRUE; |
133 | } | 231 | } |
134 | 232 | ||
135 | 233 | ||
136 | void AudioWidget::sliderReleased() { | 234 | void AudioWidget::sliderReleased() { |
137 | audioSliderBeingMoved = FALSE; | 235 | audioSliderBeingMoved = FALSE; |
138 | if ( slider->width() == 0 ) | 236 | if ( slider.width() == 0 ) |
139 | return; | 237 | return; |
140 | long val = long((double)slider->value() * mediaPlayerState->length() / slider->width()); | 238 | long val = long((double)slider.value() * mediaPlayerState->length() / slider.width()); |
141 | mediaPlayerState->setPosition( val ); | 239 | mediaPlayerState->setPosition( val ); |
142 | } | 240 | } |
143 | 241 | ||
144 | 242 | ||
145 | void AudioWidget::setPosition( long i ) { | 243 | void AudioWidget::setPosition( long i ) { |
146 | // qDebug("set position %d",i); | 244 | // qDebug("set position %d",i); |
147 | updateSlider( i, mediaPlayerState->length() ); | 245 | long length = mediaPlayerState->length(); |
246 | updateSlider( i, length ); | ||
148 | } | 247 | } |
149 | 248 | ||
150 | 249 | ||
151 | void AudioWidget::setLength( long max ) { | 250 | void AudioWidget::setLength( long max ) { |
152 | updateSlider( mediaPlayerState->position(), max ); | 251 | updateSlider( mediaPlayerState->position(), max ); |
153 | } | 252 | } |
154 | 253 | ||
155 | 254 | ||
156 | void AudioWidget::setView( char view ) { | 255 | void AudioWidget::setView( char view ) { |
256 | |||
157 | if (mediaPlayerState->isStreaming) { | 257 | if (mediaPlayerState->isStreaming) { |
158 | if( !slider->isHidden()) slider->hide(); | 258 | if( !slider.isHidden()) slider.hide(); |
159 | disconnect( mediaPlayerState, SIGNAL( positionChanged(long) ),this, SLOT( setPosition(long) ) ); | 259 | disconnect( mediaPlayerState, SIGNAL( positionChanged(long) ),this, SLOT( setPosition(long) ) ); |
160 | disconnect( mediaPlayerState, SIGNAL( positionUpdated(long) ),this, SLOT( setPosition(long) ) ); | 260 | disconnect( mediaPlayerState, SIGNAL( positionUpdated(long) ),this, SLOT( setPosition(long) ) ); |
161 | } else { | 261 | } else { |
162 | // this stops the slider from being moved, thus | 262 | // this stops the slider from being moved, thus |
163 | // does not stop stream when it reaches the end | 263 | // does not stop stream when it reaches the end |
164 | slider->show(); | 264 | slider.show(); |
165 | connect( mediaPlayerState, SIGNAL( positionChanged(long) ),this, SLOT( setPosition(long) ) ); | 265 | connect( mediaPlayerState, SIGNAL( positionChanged(long) ),this, SLOT( setPosition(long) ) ); |
166 | connect( mediaPlayerState, SIGNAL( positionUpdated(long) ),this, SLOT( setPosition(long) ) ); | 266 | connect( mediaPlayerState, SIGNAL( positionUpdated(long) ),this, SLOT( setPosition(long) ) ); |
167 | } | 267 | } |
168 | 268 | ||
169 | if ( view == 'a' ) { | 269 | if ( view == 'a' ) { |
170 | startTimer( 150 ); | 270 | startTimer( 150 ); |
171 | // show(); | 271 | // show(); |
172 | showMaximized(); | 272 | showMaximized(); |
173 | } else { | 273 | } else { |
174 | killTimers(); | 274 | killTimers(); |
175 | hide(); | 275 | hide(); |
176 | } | 276 | } |
177 | } | 277 | } |
178 | 278 | ||
179 | 279 | ||
280 | static QString timeAsString( long length ) { | ||
281 | length /= 44100; | ||
282 | int minutes = length / 60; | ||
283 | int seconds = length % 60; | ||
284 | return QString("%1:%2%3").arg( minutes ).arg( seconds / 10 ).arg( seconds % 10 ); | ||
285 | } | ||
286 | |||
180 | void AudioWidget::updateSlider( long i, long max ) { | 287 | void AudioWidget::updateSlider( long i, long max ) { |
288 | time.setText( timeAsString( i ) + " / " + timeAsString( max ) ); | ||
289 | |||
181 | if ( max == 0 ) | 290 | if ( max == 0 ) |
182 | return; | 291 | return; |
183 | // Will flicker too much if we don't do this | 292 | // Will flicker too much if we don't do this |
184 | // Scale to something reasonable | 293 | // Scale to something reasonable |
185 | int width = slider->width(); | 294 | int width = slider.width(); |
186 | int val = int((double)i * width / max); | 295 | int val = int((double)i * width / max); |
187 | if ( !audioSliderBeingMoved ) { | 296 | if ( !audioSliderBeingMoved ) { |
188 | if ( slider->value() != val ) | 297 | if ( slider.value() != val ) |
189 | slider->setValue( val ); | 298 | slider.setValue( val ); |
190 | if ( slider->maxValue() != width ) | 299 | if ( slider.maxValue() != width ) |
191 | slider->setMaxValue( width ); | 300 | slider.setMaxValue( width ); |
192 | } | 301 | } |
193 | } | 302 | } |
194 | 303 | ||
195 | 304 | ||
196 | void AudioWidget::setToggleButton( int i, bool down ) { | 305 | void AudioWidget::setToggleButton( int i, bool down ) { |
197 | if ( down != audioButtons[i].isDown ) | 306 | if ( down != audioButtons[i].isDown ) |
198 | toggleButton( i ); | 307 | toggleButton( i ); |
199 | } | 308 | } |
200 | 309 | ||
201 | 310 | ||
202 | void AudioWidget::toggleButton( int i ) { | 311 | void AudioWidget::toggleButton( int i ) { |
203 | audioButtons[i].isDown = !audioButtons[i].isDown; | 312 | audioButtons[i].isDown = !audioButtons[i].isDown; |
204 | QPainter p(this); | 313 | QPainter p(this); |
205 | paintButton ( &p, i ); | 314 | paintButton ( &p, i ); |
206 | } | 315 | } |
207 | 316 | ||
208 | 317 | ||
209 | void AudioWidget::paintButton( QPainter *p, int i ) { | 318 | void AudioWidget::paintButton( QPainter *p, int i ) { |
210 | int x = audioButtons[i].xPos; | 319 | if ( audioButtons[i].isDown ) |
211 | int y = audioButtons[i].yPos; | 320 | p->drawPixmap( xoff, yoff, *buttonPixDown[i] ); |
212 | int offset = 22 + 14 * audioButtons[i].isBig + audioButtons[i].isDown; | 321 | else |
213 | int buttonSize = 64 + audioButtons[i].isBig * (90 - 64); | 322 | p->drawPixmap( xoff, yoff, *buttonPixUp[i] ); |
214 | p->drawPixmap( x, y, *pixmaps[audioButtons[i].isBig], buttonSize * (audioButtons[i].isDown + 2 * audioButtons[i].color), 0, buttonSize, buttonSize ); | ||
215 | p->drawPixmap( x + offset, y + offset, *pixmaps[2], 18 * i, 0, 18, 18 ); | ||
216 | } | 323 | } |
217 | 324 | ||
218 | 325 | ||
219 | void AudioWidget::timerEvent( QTimerEvent * ) { | 326 | void AudioWidget::timerEvent( QTimerEvent * ) { |
327 | /* | ||
328 | int x = audioButtons[AudioPlay].xPos; | ||
329 | int y = audioButtons[AudioPlay].yPos; | ||
330 | QPainter p( this ); | ||
331 | // Optimize to only draw the little bit of the changing images which is different | ||
332 | p.drawPixmap( x + 14, y + 8, *pixmaps[3], 32 * frame, 0, 32, 32 ); | ||
333 | p.drawPixmap( x + 37, y + 37, *pixmaps[2], 18 * AudioPlay, 0, 6, 3 ); | ||
334 | */ | ||
335 | /* | ||
220 | static int frame = 0; | 336 | static int frame = 0; |
221 | if ( !mediaPlayerState->paused() && audioButtons[ AudioPlay ].isDown ) { | 337 | if ( !mediaPlayerState->paused() && audioButtons[ AudioPlay ].isDown ) { |
222 | frame = frame >= 7 ? 0 : frame + 1; | 338 | frame = frame >= 7 ? 0 : frame + 1; |
223 | // int x = audioButtons[AudioPlay].xPos; | ||
224 | // int y = audioButtons[AudioPlay].yPos; | ||
225 | // QPainter p( this ); | ||
226 | // // Optimize to only draw the little bit of the changing images which is different | ||
227 | // p.drawPixmap( x + 14, y + 8, *pixmaps[3], 32 * frame, 0, 32, 32 ); | ||
228 | // p.drawPixmap( x + 37, y + 37, *pixmaps[2], 18 * AudioPlay, 0, 6, 3 ); | ||
229 | } | 339 | } |
340 | */ | ||
230 | } | 341 | } |
231 | 342 | ||
232 | 343 | ||
233 | void AudioWidget::mouseMoveEvent( QMouseEvent *event ) { | 344 | void AudioWidget::mouseMoveEvent( QMouseEvent *event ) { |
234 | for ( int i = 0; i < numButtons; i++ ) { | 345 | for ( int i = 0; i < numButtons; i++ ) { |
235 | int size = audioButtons[i].isBig; | ||
236 | int x = audioButtons[i].xPos; | ||
237 | int y = audioButtons[i].yPos; | ||
238 | if ( event->state() == QMouseEvent::LeftButton ) { | 346 | if ( event->state() == QMouseEvent::LeftButton ) { |
239 | // The test to see if the mouse click is inside the circular button or not | 347 | |
240 | // (compared with the radius squared to avoid a square-root of our distance) | 348 | // The test to see if the mouse click is inside the button or not |
241 | int radius = 32 + 13 * size; | 349 | int x = event->pos().x() - xoff; |
242 | QPoint center = QPoint( x + radius, y + radius ); | 350 | int y = event->pos().y() - yoff; |
243 | QPoint dXY = center - event->pos(); | 351 | |
244 | int dist = dXY.x() * dXY.x() + dXY.y() * dXY.y(); | 352 | bool isOnButton = ( x > 0 && y > 0 && x < imgButtonMask->width() |
245 | bool isOnButton = dist <= (radius * radius); | 353 | && y < imgButtonMask->height() && imgButtonMask->pixelIndex( x, y ) == i + 1 ); |
246 | // QRect r( x, y, 64 + 22*size, 64 + 22*size ); | 354 | |
247 | // bool isOnButton = r.contains( event->pos() ); // Rectangular Button code | 355 | if ( isOnButton && i == AudioVolumeUp ) |
356 | qDebug("on up"); | ||
357 | |||
248 | if ( isOnButton && !audioButtons[i].isHeld ) { | 358 | if ( isOnButton && !audioButtons[i].isHeld ) { |
249 | audioButtons[i].isHeld = TRUE; | 359 | audioButtons[i].isHeld = TRUE; |
250 | toggleButton(i); | 360 | toggleButton(i); |
251 | qDebug("button toggled1 %d",i); | ||
252 | switch (i) { | 361 | switch (i) { |
253 | case AudioVolumeUp: emit moreClicked(); return; | 362 | case AudioVolumeUp: |
363 | qDebug("more clicked"); | ||
364 | emit moreClicked(); | ||
365 | return; | ||
254 | case AudioVolumeDown: emit lessClicked(); return; | 366 | case AudioVolumeDown: emit lessClicked(); return; |
255 | } | 367 | } |
256 | } else if ( !isOnButton && audioButtons[i].isHeld ) { | 368 | } else if ( !isOnButton && audioButtons[i].isHeld ) { |
257 | audioButtons[i].isHeld = FALSE; | 369 | audioButtons[i].isHeld = FALSE; |
258 | toggleButton(i); | 370 | toggleButton(i); |
259 | qDebug("button toggled2 %d",i); | ||
260 | } | 371 | } |
261 | } else { | 372 | } else { |
262 | if ( audioButtons[i].isHeld ) { | 373 | if ( audioButtons[i].isHeld ) { |
263 | audioButtons[i].isHeld = FALSE; | 374 | audioButtons[i].isHeld = FALSE; |
264 | if ( !audioButtons[i].isToggle ) | 375 | if ( !audioButtons[i].isToggle ) |
265 | setToggleButton( i, FALSE ); | 376 | setToggleButton( i, FALSE ); |
266 | qDebug("button toggled3 %d",i); | ||
267 | switch (i) { | 377 | switch (i) { |
268 | case AudioPlay: mediaPlayerState->setPlaying(audioButtons[i].isDown); return; | 378 | case AudioPlay: mediaPlayerState->setPlaying(audioButtons[i].isDown); return; |
269 | case AudioStop: mediaPlayerState->setPlaying(FALSE); return; | 379 | case AudioStop: mediaPlayerState->setPlaying(FALSE); return; |
270 | case AudioPause: mediaPlayerState->setPaused(audioButtons[i].isDown); return; | 380 | case AudioPause: mediaPlayerState->setPaused(audioButtons[i].isDown); return; |
271 | case AudioNext: mediaPlayerState->setNext(); return; | 381 | case AudioNext: mediaPlayerState->setNext(); return; |
272 | case AudioPrevious: mediaPlayerState->setPrev(); return; | 382 | case AudioPrevious: mediaPlayerState->setPrev(); return; |
273 | case AudioLoop: mediaPlayerState->setLooping(audioButtons[i].isDown); return; | 383 | case AudioLoop: mediaPlayerState->setLooping(audioButtons[i].isDown); return; |
274 | case AudioVolumeUp: emit moreReleased(); return; | 384 | case AudioVolumeUp: emit moreReleased(); return; |
275 | case AudioVolumeDown: emit lessReleased(); return; | 385 | case AudioVolumeDown: emit lessReleased(); return; |
276 | case AudioPlayList: mediaPlayerState->setList(); return; | 386 | case AudioPlayList: mediaPlayerState->setList(); return; |
277 | } | 387 | } |
278 | } | 388 | } |
279 | } | 389 | } |
280 | } | 390 | } |
281 | } | 391 | } |
282 | 392 | ||
283 | 393 | ||
394 | |||
284 | void AudioWidget::mousePressEvent( QMouseEvent *event ) { | 395 | void AudioWidget::mousePressEvent( QMouseEvent *event ) { |
285 | mouseMoveEvent( event ); | 396 | mouseMoveEvent( event ); |
286 | } | 397 | } |
287 | 398 | ||
288 | 399 | ||
289 | void AudioWidget::mouseReleaseEvent( QMouseEvent *event ) { | 400 | void AudioWidget::mouseReleaseEvent( QMouseEvent *event ) { |
290 | mouseMoveEvent( event ); | 401 | mouseMoveEvent( event ); |
291 | } | 402 | } |
292 | 403 | ||
293 | 404 | ||
294 | void AudioWidget::showEvent( QShowEvent* ) { | 405 | void AudioWidget::showEvent( QShowEvent* ) { |
295 | QMouseEvent event( QEvent::MouseMove, QPoint( 0, 0 ), 0, 0 ); | 406 | QMouseEvent event( QEvent::MouseMove, QPoint( 0, 0 ), 0, 0 ); |
296 | mouseMoveEvent( &event ); | 407 | mouseMoveEvent( &event ); |
297 | } | 408 | } |
298 | 409 | ||
299 | 410 | ||
300 | void AudioWidget::closeEvent( QCloseEvent* ) { | 411 | void AudioWidget::closeEvent( QCloseEvent* ) { |
301 | mediaPlayerState->setList(); | 412 | mediaPlayerState->setList(); |
302 | } | 413 | } |
303 | 414 | ||
304 | 415 | ||
305 | void AudioWidget::paintEvent( QPaintEvent * ) { | 416 | void AudioWidget::paintEvent( QPaintEvent * pe) { |
417 | if ( !pe->erased() ) { | ||
418 | // Combine with background and double buffer | ||
419 | QPixmap pix( pe->rect().size() ); | ||
420 | QPainter p( &pix ); | ||
421 | p.translate( -pe->rect().topLeft().x(), -pe->rect().topLeft().y() ); | ||
422 | p.drawTiledPixmap( pe->rect(), *pixBg, pe->rect().topLeft() ); | ||
423 | for ( int i = 0; i < numButtons; i++ ) | ||
424 | paintButton( &p, i ); | ||
425 | QPainter p2( this ); | ||
426 | p2.drawPixmap( pe->rect().topLeft(), pix ); | ||
427 | } else { | ||
306 | QPainter p( this ); | 428 | QPainter p( this ); |
307 | for ( int i = 0; i < numButtons; i++ ) | 429 | for ( int i = 0; i < numButtons; i++ ) |
308 | paintButton( &p, i ); | 430 | paintButton( &p, i ); |
309 | } | 431 | } |
432 | } | ||
310 | 433 | ||
311 | void AudioWidget::keyReleaseEvent( QKeyEvent *e) | 434 | void AudioWidget::keyReleaseEvent( QKeyEvent *e) |
312 | { | 435 | { |
313 | switch ( e->key() ) { | 436 | switch ( e->key() ) { |
314 | ////////////////////////////// Zaurus keys | 437 | ////////////////////////////// Zaurus keys |
315 | case Key_Home: | 438 | case Key_Home: |
316 | break; | 439 | break; |
317 | case Key_F9: //activity | 440 | case Key_F9: //activity |
318 | hide(); | 441 | hide(); |
319 | // qDebug("Audio F9"); | 442 | // qDebug("Audio F9"); |
320 | break; | 443 | break; |
321 | case Key_F10: //contacts | 444 | case Key_F10: //contacts |
322 | break; | 445 | break; |
323 | case Key_F11: //menu | 446 | case Key_F11: //menu |
324 | break; | 447 | break; |
325 | case Key_F12: //home | 448 | case Key_F12: //home |
326 | break; | 449 | break; |
327 | case Key_F13: //mail | 450 | case Key_F13: //mail |
328 | break; | 451 | break; |
329 | case Key_Space: { | 452 | case Key_Space: { |
453 | |||
330 | if(mediaPlayerState->playing()) { | 454 | if(mediaPlayerState->playing()) { |
331 | // toggleButton(1); | 455 | // toggleButton(1); |
332 | mediaPlayerState->setPlaying(FALSE); | 456 | mediaPlayerState->setPlaying(FALSE); |
333 | // toggleButton(1); | 457 | // toggleButton(1); |
334 | } else { | 458 | } else { |
335 | // toggleButton(0); | 459 | // toggleButton(0); |
336 | mediaPlayerState->setPlaying(TRUE); | 460 | mediaPlayerState->setPlaying(TRUE); |
337 | // toggleButton(0); | 461 | // toggleButton(0); |
338 | } | 462 | } |
339 | } | 463 | } |
340 | break; | 464 | break; |
341 | case Key_Down: | 465 | case Key_Down: //volume |
342 | toggleButton(6); | 466 | toggleButton(6); |
343 | emit lessClicked(); | 467 | emit lessClicked(); |
344 | emit lessReleased(); | 468 | emit lessReleased(); |
345 | toggleButton(6); | 469 | toggleButton(6); |
346 | break; | 470 | break; |
347 | case Key_Up: | 471 | case Key_Up: //volume |
348 | toggleButton(5); | 472 | toggleButton(5); |
349 | emit moreClicked(); | 473 | emit moreClicked(); |
350 | emit moreReleased(); | 474 | emit moreReleased(); |
351 | toggleButton(5); | 475 | toggleButton(5); |
352 | break; | 476 | break; |
353 | case Key_Right: | 477 | case Key_Right: //next in playlist |
354 | // toggleButton(3); | 478 | // toggleButton(3); |
355 | mediaPlayerState->setNext(); | 479 | mediaPlayerState->setNext(); |
356 | // toggleButton(3); | 480 | // toggleButton(3); |
357 | break; | 481 | break; |
358 | case Key_Left: | 482 | case Key_Left: // previous in playlist |
359 | // toggleButton(4); | 483 | // toggleButton(4); |
360 | mediaPlayerState->setPrev(); | 484 | mediaPlayerState->setPrev(); |
361 | // toggleButton(4); | 485 | // toggleButton(4); |
362 | break; | 486 | break; |
363 | case Key_Escape: | 487 | case Key_Escape: |
364 | break; | 488 | break; |
365 | 489 | ||
366 | }; | 490 | }; |
367 | } | 491 | } |