author | simon <simon> | 2002-12-02 14:23:06 (UTC) |
---|---|---|
committer | simon <simon> | 2002-12-02 14:23:06 (UTC) |
commit | 6440dfbca27a1716456c081ff1b1756616afc518 (patch) (unidiff) | |
tree | 54c35f1acd1e3b06ba9b6cedbabc76dbc6a4783d | |
parent | 8179c80f459eeee815aeb279f73df754ba303198 (diff) | |
download | opie-6440dfbca27a1716456c081ff1b1756616afc518.zip opie-6440dfbca27a1716456c081ff1b1756616afc518.tar.gz opie-6440dfbca27a1716456c081ff1b1756616afc518.tar.bz2 |
- use currentTab() instead of whichList()
-rw-r--r-- | noncore/multimedia/opieplayer2/audiowidget.cpp | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/noncore/multimedia/opieplayer2/audiowidget.cpp b/noncore/multimedia/opieplayer2/audiowidget.cpp index 7c2b007..5cdfbf2 100644 --- a/noncore/multimedia/opieplayer2/audiowidget.cpp +++ b/noncore/multimedia/opieplayer2/audiowidget.cpp | |||
@@ -58,497 +58,497 @@ static const int yo = 22; // movable y offset | |||
58 | 58 | ||
59 | struct MediaButton { | 59 | struct 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 | MediaButton audioButtons[] = { | 64 | MediaButton audioButtons[] = { |
65 | { TRUE, FALSE, FALSE }, // play | 65 | { TRUE, FALSE, FALSE }, // play |
66 | { FALSE, FALSE, FALSE }, // stop | 66 | { FALSE, FALSE, FALSE }, // stop |
67 | { FALSE, FALSE, FALSE }, // next | 67 | { FALSE, FALSE, FALSE }, // next |
68 | { FALSE, FALSE, FALSE }, // previous | 68 | { FALSE, FALSE, FALSE }, // previous |
69 | { FALSE, FALSE, FALSE }, // volume up | 69 | { FALSE, FALSE, FALSE }, // volume up |
70 | { FALSE, FALSE, FALSE }, // volume down | 70 | { FALSE, FALSE, FALSE }, // volume down |
71 | { TRUE, FALSE, FALSE }, // repeat/loop | 71 | { TRUE, FALSE, FALSE }, // repeat/loop |
72 | { FALSE, FALSE, FALSE }, // playlist | 72 | { FALSE, FALSE, FALSE }, // playlist |
73 | { FALSE, FALSE, FALSE }, // forward | 73 | { FALSE, FALSE, FALSE }, // forward |
74 | { FALSE, FALSE, FALSE } // back | 74 | { FALSE, FALSE, FALSE } // back |
75 | }; | 75 | }; |
76 | 76 | ||
77 | const char *skin_mask_file_names[10] = { | 77 | const char *skin_mask_file_names[10] = { |
78 | "play", "stop", "next", "prev", "up", | 78 | "play", "stop", "next", "prev", "up", |
79 | "down", "loop", "playlist", "forward", "back" | 79 | "down", "loop", "playlist", "forward", "back" |
80 | }; | 80 | }; |
81 | 81 | ||
82 | 82 | ||
83 | static void changeTextColor( QWidget *w ) { | 83 | static void changeTextColor( QWidget *w ) { |
84 | QPalette p = w->palette(); | 84 | QPalette p = w->palette(); |
85 | p.setBrush( QColorGroup::Background, QColor( 167, 212, 167 ) ); | 85 | p.setBrush( QColorGroup::Background, QColor( 167, 212, 167 ) ); |
86 | p.setBrush( QColorGroup::Base, QColor( 167, 212, 167 ) ); | 86 | p.setBrush( QColorGroup::Base, QColor( 167, 212, 167 ) ); |
87 | w->setPalette( p ); | 87 | w->setPalette( p ); |
88 | } | 88 | } |
89 | 89 | ||
90 | static const int numButtons = (sizeof(audioButtons)/sizeof(MediaButton)); | 90 | static const int numButtons = (sizeof(audioButtons)/sizeof(MediaButton)); |
91 | 91 | ||
92 | 92 | ||
93 | AudioWidget::AudioWidget(QWidget* parent, const char* name, WFlags f) : | 93 | AudioWidget::AudioWidget(QWidget* parent, const char* name, WFlags f) : |
94 | 94 | ||
95 | QWidget( parent, name, f ), songInfo( this ), slider( Qt::Horizontal, this ), time( this ) { | 95 | QWidget( parent, name, f ), songInfo( this ), slider( Qt::Horizontal, this ), time( this ) { |
96 | 96 | ||
97 | setCaption( tr("OpiePlayer") ); | 97 | setCaption( tr("OpiePlayer") ); |
98 | 98 | ||
99 | Config cfg("OpiePlayer"); | 99 | Config cfg("OpiePlayer"); |
100 | cfg.setGroup("Options"); | 100 | cfg.setGroup("Options"); |
101 | skin = cfg.readEntry("Skin","default"); | 101 | skin = cfg.readEntry("Skin","default"); |
102 | //skin = "scaleTest"; | 102 | //skin = "scaleTest"; |
103 | // color of background, frame, degree of transparency | 103 | // color of background, frame, degree of transparency |
104 | 104 | ||
105 | QString skinPath = "opieplayer2/skins/" + skin; | 105 | QString skinPath = "opieplayer2/skins/" + skin; |
106 | pixBg = new QPixmap( Resource::loadPixmap( QString("%1/background").arg(skinPath) ) ); | 106 | pixBg = new QPixmap( Resource::loadPixmap( QString("%1/background").arg(skinPath) ) ); |
107 | imgUp = new QImage( Resource::loadImage( QString("%1/skin_up").arg(skinPath) ) ); | 107 | imgUp = new QImage( Resource::loadImage( QString("%1/skin_up").arg(skinPath) ) ); |
108 | imgDn = new QImage( Resource::loadImage( QString("%1/skin_down").arg(skinPath) ) ); | 108 | imgDn = new QImage( Resource::loadImage( QString("%1/skin_down").arg(skinPath) ) ); |
109 | 109 | ||
110 | imgButtonMask = new QImage( imgUp->width(), imgUp->height(), 8, 255 ); | 110 | imgButtonMask = new QImage( imgUp->width(), imgUp->height(), 8, 255 ); |
111 | imgButtonMask->fill( 0 ); | 111 | imgButtonMask->fill( 0 ); |
112 | 112 | ||
113 | for ( int i = 0; i < 10; i++ ) { | 113 | for ( int i = 0; i < 10; i++ ) { |
114 | QString filename = QString( QPEApplication::qpeDir() + "/pics/" + skinPath + "/skin_mask_" + skin_mask_file_names[i] + ".png" ); | 114 | QString filename = QString( QPEApplication::qpeDir() + "/pics/" + skinPath + "/skin_mask_" + skin_mask_file_names[i] + ".png" ); |
115 | masks[i] = new QBitmap( filename ); | 115 | masks[i] = new QBitmap( filename ); |
116 | 116 | ||
117 | if ( !masks[i]->isNull() ) { | 117 | if ( !masks[i]->isNull() ) { |
118 | QImage imgMask = masks[i]->convertToImage(); | 118 | QImage imgMask = masks[i]->convertToImage(); |
119 | uchar **dest = imgButtonMask->jumpTable(); | 119 | uchar **dest = imgButtonMask->jumpTable(); |
120 | for ( int y = 0; y < imgUp->height(); y++ ) { | 120 | for ( int y = 0; y < imgUp->height(); y++ ) { |
121 | uchar *line = dest[y]; | 121 | uchar *line = dest[y]; |
122 | for ( int x = 0; x < imgUp->width(); x++ ) | 122 | for ( int x = 0; x < imgUp->width(); x++ ) |
123 | if ( !qRed( imgMask.pixel( x, y ) ) ) | 123 | if ( !qRed( imgMask.pixel( x, y ) ) ) |
124 | line[x] = i + 1; | 124 | line[x] = i + 1; |
125 | } | 125 | } |
126 | } | 126 | } |
127 | 127 | ||
128 | } | 128 | } |
129 | 129 | ||
130 | for ( int i = 0; i < 10; i++ ) { | 130 | for ( int i = 0; i < 10; i++ ) { |
131 | buttonPixUp[i] = 0l; | 131 | buttonPixUp[i] = 0l; |
132 | buttonPixDown[i] = 0l; | 132 | buttonPixDown[i] = 0l; |
133 | } | 133 | } |
134 | 134 | ||
135 | setBackgroundPixmap( *pixBg ); | 135 | setBackgroundPixmap( *pixBg ); |
136 | 136 | ||
137 | songInfo.setFocusPolicy( QWidget::NoFocus ); | 137 | songInfo.setFocusPolicy( QWidget::NoFocus ); |
138 | // changeTextColor( &songInfo ); | 138 | // changeTextColor( &songInfo ); |
139 | // songInfo.setBackgroundColor( QColor( 167, 212, 167 )); | 139 | // songInfo.setBackgroundColor( QColor( 167, 212, 167 )); |
140 | // songInfo.setFrameStyle( QFrame::NoFrame); | 140 | // songInfo.setFrameStyle( QFrame::NoFrame); |
141 | songInfo.setFrameStyle( QFrame::WinPanel | QFrame::Sunken ); | 141 | songInfo.setFrameStyle( QFrame::WinPanel | QFrame::Sunken ); |
142 | // songInfo.setForegroundColor(Qt::white); | 142 | // songInfo.setForegroundColor(Qt::white); |
143 | 143 | ||
144 | slider.setFixedHeight( 20 ); | 144 | slider.setFixedHeight( 20 ); |
145 | slider.setMinValue( 0 ); | 145 | slider.setMinValue( 0 ); |
146 | slider.setMaxValue( 1 ); | 146 | slider.setMaxValue( 1 ); |
147 | slider.setFocusPolicy( QWidget::NoFocus ); | 147 | slider.setFocusPolicy( QWidget::NoFocus ); |
148 | slider.setBackgroundPixmap( *pixBg ); | 148 | slider.setBackgroundPixmap( *pixBg ); |
149 | 149 | ||
150 | // Config cofg("qpe"); | 150 | // Config cofg("qpe"); |
151 | // cofg.setGroup("Appearance"); | 151 | // cofg.setGroup("Appearance"); |
152 | // QColor backgroundcolor = QColor( cofg.readEntry( "Background", "#E5E1D5" ) ); | 152 | // QColor backgroundcolor = QColor( cofg.readEntry( "Background", "#E5E1D5" ) ); |
153 | 153 | ||
154 | time.setFocusPolicy( QWidget::NoFocus ); | 154 | time.setFocusPolicy( QWidget::NoFocus ); |
155 | time.setAlignment( Qt::AlignCenter ); | 155 | time.setAlignment( Qt::AlignCenter ); |
156 | 156 | ||
157 | // time.setFrame(FALSE); | 157 | // time.setFrame(FALSE); |
158 | // changeTextColor( &time ); | 158 | // changeTextColor( &time ); |
159 | 159 | ||
160 | resizeEvent( NULL ); | 160 | resizeEvent( NULL ); |
161 | 161 | ||
162 | connect( mediaPlayerState, SIGNAL( lengthChanged(long) ), this, SLOT( setLength(long) ) ); | 162 | connect( mediaPlayerState, SIGNAL( lengthChanged(long) ), this, SLOT( setLength(long) ) ); |
163 | connect( mediaPlayerState, SIGNAL( viewChanged(char) ), this, SLOT( setView(char) ) ); | 163 | connect( mediaPlayerState, SIGNAL( viewChanged(char) ), this, SLOT( setView(char) ) ); |
164 | connect( mediaPlayerState, SIGNAL( loopingToggled(bool) ), this, SLOT( setLooping(bool) ) ); | 164 | connect( mediaPlayerState, SIGNAL( loopingToggled(bool) ), this, SLOT( setLooping(bool) ) ); |
165 | connect( mediaPlayerState, SIGNAL( playingToggled(bool) ), this, SLOT( setPlaying(bool) ) ); | 165 | connect( mediaPlayerState, SIGNAL( playingToggled(bool) ), this, SLOT( setPlaying(bool) ) ); |
166 | connect( mediaPlayerState, SIGNAL( isSeekableToggled( bool ) ), this, SLOT( setSeekable( bool ) ) ); | 166 | connect( mediaPlayerState, SIGNAL( isSeekableToggled( bool ) ), this, SLOT( setSeekable( bool ) ) ); |
167 | 167 | ||
168 | connect( this, SIGNAL( forwardClicked() ), this, SLOT( skipFor() ) ); | 168 | connect( this, SIGNAL( forwardClicked() ), this, SLOT( skipFor() ) ); |
169 | connect( this, SIGNAL( backClicked() ), this, SLOT( skipBack() ) ); | 169 | connect( this, SIGNAL( backClicked() ), this, SLOT( skipBack() ) ); |
170 | connect( this, SIGNAL( forwardReleased() ), this, SLOT( stopSkip() ) ); | 170 | connect( this, SIGNAL( forwardReleased() ), this, SLOT( stopSkip() ) ); |
171 | connect( this, SIGNAL( backReleased() ), this, SLOT( stopSkip() ) ); | 171 | connect( this, SIGNAL( backReleased() ), this, SLOT( stopSkip() ) ); |
172 | 172 | ||
173 | // Intialise state | 173 | // Intialise state |
174 | setLength( mediaPlayerState->length() ); | 174 | setLength( mediaPlayerState->length() ); |
175 | setPosition( mediaPlayerState->position() ); | 175 | setPosition( mediaPlayerState->position() ); |
176 | setLooping( mediaPlayerState->isFullscreen() ); | 176 | setLooping( mediaPlayerState->isFullscreen() ); |
177 | // setPaused( mediaPlayerState->paused() ); | 177 | // setPaused( mediaPlayerState->paused() ); |
178 | setPlaying( mediaPlayerState->isPlaying() ); | 178 | setPlaying( mediaPlayerState->isPlaying() ); |
179 | 179 | ||
180 | } | 180 | } |
181 | 181 | ||
182 | AudioWidget::~AudioWidget() { | 182 | AudioWidget::~AudioWidget() { |
183 | 183 | ||
184 | for ( int i = 0; i < 10; i++ ) { | 184 | for ( int i = 0; i < 10; i++ ) { |
185 | delete buttonPixUp[i]; | 185 | delete buttonPixUp[i]; |
186 | delete buttonPixDown[i]; | 186 | delete buttonPixDown[i]; |
187 | } | 187 | } |
188 | delete pixBg; | 188 | delete pixBg; |
189 | delete imgUp; | 189 | delete imgUp; |
190 | delete imgDn; | 190 | delete imgDn; |
191 | delete imgButtonMask; | 191 | delete imgButtonMask; |
192 | for ( int i = 0; i < 10; i++ ) { | 192 | for ( int i = 0; i < 10; i++ ) { |
193 | delete masks[i]; | 193 | delete masks[i]; |
194 | } | 194 | } |
195 | // mediaPlayerState->setPlaying(false); | 195 | // mediaPlayerState->setPlaying(false); |
196 | } | 196 | } |
197 | 197 | ||
198 | namespace { | 198 | namespace { |
199 | 199 | ||
200 | QPixmap *combineImageWithBackground( QImage img, QPixmap bg, QPoint offset ) { | 200 | QPixmap *combineImageWithBackground( QImage img, QPixmap bg, QPoint offset ) { |
201 | QPixmap pix( img.width(), img.height() ); | 201 | QPixmap pix( img.width(), img.height() ); |
202 | QPainter p( &pix ); | 202 | QPainter p( &pix ); |
203 | p.drawTiledPixmap( pix.rect(), bg, offset ); | 203 | p.drawTiledPixmap( pix.rect(), bg, offset ); |
204 | p.drawImage( 0, 0, img ); | 204 | p.drawImage( 0, 0, img ); |
205 | return new QPixmap( pix ); | 205 | return new QPixmap( pix ); |
206 | } | 206 | } |
207 | 207 | ||
208 | 208 | ||
209 | QPixmap *maskPixToMask( QPixmap pix, QBitmap mask ) { | 209 | QPixmap *maskPixToMask( QPixmap pix, QBitmap mask ) { |
210 | QPixmap *pixmap = new QPixmap( pix ); | 210 | QPixmap *pixmap = new QPixmap( pix ); |
211 | pixmap->setMask( mask ); | 211 | pixmap->setMask( mask ); |
212 | return pixmap; | 212 | return pixmap; |
213 | } | 213 | } |
214 | 214 | ||
215 | }; | 215 | }; |
216 | 216 | ||
217 | void AudioWidget::resizeEvent( QResizeEvent * ) { | 217 | void AudioWidget::resizeEvent( QResizeEvent * ) { |
218 | int h = height(); | 218 | int h = height(); |
219 | int w = width(); | 219 | int w = width(); |
220 | 220 | ||
221 | songInfo.setGeometry( QRect( 2, 2, w - 4, 20 ) ); | 221 | songInfo.setGeometry( QRect( 2, 2, w - 4, 20 ) ); |
222 | slider.setFixedWidth( w - 110 ); | 222 | slider.setFixedWidth( w - 110 ); |
223 | slider.setGeometry( QRect( 15, h - 22, w - 90, 20 ) ); | 223 | slider.setGeometry( QRect( 15, h - 22, w - 90, 20 ) ); |
224 | slider.setBackgroundOrigin( QWidget::ParentOrigin ); | 224 | slider.setBackgroundOrigin( QWidget::ParentOrigin ); |
225 | time.setGeometry( QRect( w - 85, h - 30, 70, 20 ) ); | 225 | time.setGeometry( QRect( w - 85, h - 30, 70, 20 ) ); |
226 | 226 | ||
227 | xoff = ( w - imgUp->width() ) / 2; | 227 | xoff = ( w - imgUp->width() ) / 2; |
228 | yoff = (( h - imgUp->height() ) / 2) - 10; | 228 | yoff = (( h - imgUp->height() ) / 2) - 10; |
229 | QPoint p( xoff, yoff ); | 229 | QPoint p( xoff, yoff ); |
230 | 230 | ||
231 | QPixmap *pixUp = combineImageWithBackground( *imgUp, *pixBg, p ); | 231 | QPixmap *pixUp = combineImageWithBackground( *imgUp, *pixBg, p ); |
232 | QPixmap *pixDn = combineImageWithBackground( *imgDn, *pixBg, p ); | 232 | QPixmap *pixDn = combineImageWithBackground( *imgDn, *pixBg, p ); |
233 | 233 | ||
234 | for ( int i = 0; i < 10; i++ ) { | 234 | for ( int i = 0; i < 10; i++ ) { |
235 | if ( !masks[i]->isNull() ) { | 235 | if ( !masks[i]->isNull() ) { |
236 | delete buttonPixUp[i]; | 236 | delete buttonPixUp[i]; |
237 | delete buttonPixDown[i]; | 237 | delete buttonPixDown[i]; |
238 | buttonPixUp[i] = maskPixToMask( *pixUp, *masks[i] ); | 238 | buttonPixUp[i] = maskPixToMask( *pixUp, *masks[i] ); |
239 | buttonPixDown[i] = maskPixToMask( *pixDn, *masks[i] ); | 239 | buttonPixDown[i] = maskPixToMask( *pixDn, *masks[i] ); |
240 | } | 240 | } |
241 | } | 241 | } |
242 | 242 | ||
243 | delete pixUp; | 243 | delete pixUp; |
244 | delete pixDn; | 244 | delete pixDn; |
245 | } | 245 | } |
246 | 246 | ||
247 | static bool audioSliderBeingMoved = FALSE; | 247 | static bool audioSliderBeingMoved = FALSE; |
248 | 248 | ||
249 | 249 | ||
250 | void AudioWidget::sliderPressed() { | 250 | void AudioWidget::sliderPressed() { |
251 | audioSliderBeingMoved = TRUE; | 251 | audioSliderBeingMoved = TRUE; |
252 | } | 252 | } |
253 | 253 | ||
254 | 254 | ||
255 | void AudioWidget::sliderReleased() { | 255 | void AudioWidget::sliderReleased() { |
256 | audioSliderBeingMoved = FALSE; | 256 | audioSliderBeingMoved = FALSE; |
257 | if ( slider.width() == 0 ) | 257 | if ( slider.width() == 0 ) |
258 | return; | 258 | return; |
259 | long val = long((double)slider.value() * mediaPlayerState->length() / slider.width()); | 259 | long val = long((double)slider.value() * mediaPlayerState->length() / slider.width()); |
260 | mediaPlayerState->setPosition( val ); | 260 | mediaPlayerState->setPosition( val ); |
261 | } | 261 | } |
262 | 262 | ||
263 | void AudioWidget::setPosition( long i ) { | 263 | void AudioWidget::setPosition( long i ) { |
264 | // qDebug("<<<<<<<<<<<<<<<<<<<<<<<<set position %d",i); | 264 | // qDebug("<<<<<<<<<<<<<<<<<<<<<<<<set position %d",i); |
265 | updateSlider( i, mediaPlayerState->length() ); | 265 | updateSlider( i, mediaPlayerState->length() ); |
266 | } | 266 | } |
267 | 267 | ||
268 | 268 | ||
269 | void AudioWidget::setLength( long max ) { | 269 | void AudioWidget::setLength( long max ) { |
270 | updateSlider( mediaPlayerState->position(), max ); | 270 | updateSlider( mediaPlayerState->position(), max ); |
271 | } | 271 | } |
272 | 272 | ||
273 | 273 | ||
274 | void AudioWidget::setView( char view ) { | 274 | void AudioWidget::setView( char view ) { |
275 | 275 | ||
276 | if ( view == 'a' ) { | 276 | if ( view == 'a' ) { |
277 | // startTimer( 150 ); | 277 | // startTimer( 150 ); |
278 | showMaximized(); | 278 | showMaximized(); |
279 | } else { | 279 | } else { |
280 | killTimers(); | 280 | killTimers(); |
281 | hide(); | 281 | hide(); |
282 | } | 282 | } |
283 | // qApp->processEvents(); | 283 | // qApp->processEvents(); |
284 | } | 284 | } |
285 | 285 | ||
286 | 286 | ||
287 | void AudioWidget::setSeekable( bool isSeekable ) { | 287 | void AudioWidget::setSeekable( bool isSeekable ) { |
288 | 288 | ||
289 | if ( !isSeekable ) { | 289 | if ( !isSeekable ) { |
290 | qDebug("<<<<<<<<<<<<<<file is STREAMING>>>>>>>>>>>>>>>>>>>"); | 290 | qDebug("<<<<<<<<<<<<<<file is STREAMING>>>>>>>>>>>>>>>>>>>"); |
291 | if( !slider.isHidden()) { | 291 | if( !slider.isHidden()) { |
292 | slider.hide(); | 292 | slider.hide(); |
293 | } | 293 | } |
294 | disconnect( mediaPlayerState, SIGNAL( positionChanged(long) ),this, SLOT( setPosition(long) ) ); | 294 | disconnect( mediaPlayerState, SIGNAL( positionChanged(long) ),this, SLOT( setPosition(long) ) ); |
295 | disconnect( mediaPlayerState, SIGNAL( positionUpdated(long) ),this, SLOT( setPosition(long) ) ); | 295 | disconnect( mediaPlayerState, SIGNAL( positionUpdated(long) ),this, SLOT( setPosition(long) ) ); |
296 | disconnect( &slider, SIGNAL( sliderPressed() ), this, SLOT( sliderPressed() ) ); | 296 | disconnect( &slider, SIGNAL( sliderPressed() ), this, SLOT( sliderPressed() ) ); |
297 | disconnect( &slider, SIGNAL( sliderReleased() ), this, SLOT( sliderReleased() ) ); | 297 | disconnect( &slider, SIGNAL( sliderReleased() ), this, SLOT( sliderReleased() ) ); |
298 | } else { | 298 | } else { |
299 | // this stops the slider from being moved, thus | 299 | // this stops the slider from being moved, thus |
300 | // does not stop stream when it reaches the end | 300 | // does not stop stream when it reaches the end |
301 | slider.show(); | 301 | slider.show(); |
302 | qDebug( " CONNECT SET POSTION " ); | 302 | qDebug( " CONNECT SET POSTION " ); |
303 | connect( mediaPlayerState, SIGNAL( positionChanged(long) ),this, SLOT( setPosition(long) ) ); | 303 | connect( mediaPlayerState, SIGNAL( positionChanged(long) ),this, SLOT( setPosition(long) ) ); |
304 | connect( mediaPlayerState, SIGNAL( positionUpdated(long) ),this, SLOT( setPosition(long) ) ); | 304 | connect( mediaPlayerState, SIGNAL( positionUpdated(long) ),this, SLOT( setPosition(long) ) ); |
305 | connect( &slider, SIGNAL( sliderPressed() ), this, SLOT( sliderPressed() ) ); | 305 | connect( &slider, SIGNAL( sliderPressed() ), this, SLOT( sliderPressed() ) ); |
306 | connect( &slider, SIGNAL( sliderReleased() ), this, SLOT( sliderReleased() ) ); | 306 | connect( &slider, SIGNAL( sliderReleased() ), this, SLOT( sliderReleased() ) ); |
307 | } | 307 | } |
308 | } | 308 | } |
309 | 309 | ||
310 | 310 | ||
311 | static QString timeAsString( long length ) { | 311 | static QString timeAsString( long length ) { |
312 | int minutes = length / 60; | 312 | int minutes = length / 60; |
313 | int seconds = length % 60; | 313 | int seconds = length % 60; |
314 | return QString("%1:%2%3").arg( minutes ).arg( seconds / 10 ).arg( seconds % 10 ); | 314 | return QString("%1:%2%3").arg( minutes ).arg( seconds / 10 ).arg( seconds % 10 ); |
315 | } | 315 | } |
316 | 316 | ||
317 | void AudioWidget::updateSlider( long i, long max ) { | 317 | void AudioWidget::updateSlider( long i, long max ) { |
318 | 318 | ||
319 | time.setText( timeAsString( i ) + " / " + timeAsString( max ) ); | 319 | time.setText( timeAsString( i ) + " / " + timeAsString( max ) ); |
320 | // qDebug( timeAsString( i ) + " / " + timeAsString( max ) ) ; | 320 | // qDebug( timeAsString( i ) + " / " + timeAsString( max ) ) ; |
321 | 321 | ||
322 | if ( max == 0 ) { | 322 | if ( max == 0 ) { |
323 | return; | 323 | return; |
324 | } | 324 | } |
325 | // Will flicker too much if we don't do this | 325 | // Will flicker too much if we don't do this |
326 | // Scale to something reasonable | 326 | // Scale to something reasonable |
327 | int width = slider.width(); | 327 | int width = slider.width(); |
328 | int val = int((double)i * width / max); | 328 | int val = int((double)i * width / max); |
329 | if ( !audioSliderBeingMoved ) { | 329 | if ( !audioSliderBeingMoved ) { |
330 | if ( slider.value() != val ) { | 330 | if ( slider.value() != val ) { |
331 | slider.setValue( val ); | 331 | slider.setValue( val ); |
332 | } | 332 | } |
333 | 333 | ||
334 | if ( slider.maxValue() != width ) { | 334 | if ( slider.maxValue() != width ) { |
335 | slider.setMaxValue( width ); | 335 | slider.setMaxValue( width ); |
336 | } | 336 | } |
337 | } | 337 | } |
338 | } | 338 | } |
339 | 339 | ||
340 | 340 | ||
341 | void AudioWidget::setToggleButton( int i, bool down ) { | 341 | void AudioWidget::setToggleButton( int i, bool down ) { |
342 | qDebug("setToggleButton %d", i); | 342 | qDebug("setToggleButton %d", i); |
343 | if ( down != audioButtons[i].isDown ) { | 343 | if ( down != audioButtons[i].isDown ) { |
344 | toggleButton( i ); | 344 | toggleButton( i ); |
345 | } | 345 | } |
346 | } | 346 | } |
347 | 347 | ||
348 | 348 | ||
349 | void AudioWidget::toggleButton( int i ) { | 349 | void AudioWidget::toggleButton( int i ) { |
350 | audioButtons[i].isDown = !audioButtons[i].isDown; | 350 | audioButtons[i].isDown = !audioButtons[i].isDown; |
351 | QPainter p(this); | 351 | QPainter p(this); |
352 | paintButton ( &p, i ); | 352 | paintButton ( &p, i ); |
353 | } | 353 | } |
354 | 354 | ||
355 | 355 | ||
356 | void AudioWidget::paintButton( QPainter *p, int i ) { | 356 | void AudioWidget::paintButton( QPainter *p, int i ) { |
357 | if ( audioButtons[i].isDown ) { | 357 | if ( audioButtons[i].isDown ) { |
358 | p->drawPixmap( xoff, yoff, *buttonPixDown[i] ); | 358 | p->drawPixmap( xoff, yoff, *buttonPixDown[i] ); |
359 | } else { | 359 | } else { |
360 | p->drawPixmap( xoff, yoff, *buttonPixUp[i] ); | 360 | p->drawPixmap( xoff, yoff, *buttonPixUp[i] ); |
361 | } | 361 | } |
362 | } | 362 | } |
363 | 363 | ||
364 | 364 | ||
365 | void AudioWidget::skipFor() { | 365 | void AudioWidget::skipFor() { |
366 | skipDirection = +1; | 366 | skipDirection = +1; |
367 | startTimer( 50 ); | 367 | startTimer( 50 ); |
368 | mediaPlayerState->setPosition( mediaPlayerState->position() + 2 ); | 368 | mediaPlayerState->setPosition( mediaPlayerState->position() + 2 ); |
369 | } | 369 | } |
370 | 370 | ||
371 | void AudioWidget::skipBack() { | 371 | void AudioWidget::skipBack() { |
372 | skipDirection = -1; | 372 | skipDirection = -1; |
373 | startTimer( 50 ); | 373 | startTimer( 50 ); |
374 | mediaPlayerState->setPosition( mediaPlayerState->position() - 2 ); | 374 | mediaPlayerState->setPosition( mediaPlayerState->position() - 2 ); |
375 | } | 375 | } |
376 | 376 | ||
377 | 377 | ||
378 | 378 | ||
379 | void AudioWidget::stopSkip() { | 379 | void AudioWidget::stopSkip() { |
380 | killTimers(); | 380 | killTimers(); |
381 | } | 381 | } |
382 | 382 | ||
383 | 383 | ||
384 | void AudioWidget::timerEvent( QTimerEvent * ) { | 384 | void AudioWidget::timerEvent( QTimerEvent * ) { |
385 | if ( skipDirection == +1 ) { | 385 | if ( skipDirection == +1 ) { |
386 | mediaPlayerState->setPosition( mediaPlayerState->position() + 2 ); | 386 | mediaPlayerState->setPosition( mediaPlayerState->position() + 2 ); |
387 | } else if ( skipDirection == -1 ) { | 387 | } else if ( skipDirection == -1 ) { |
388 | mediaPlayerState->setPosition( mediaPlayerState->position() - 2 ); | 388 | mediaPlayerState->setPosition( mediaPlayerState->position() - 2 ); |
389 | } | 389 | } |
390 | } | 390 | } |
391 | 391 | ||
392 | 392 | ||
393 | void AudioWidget::mouseMoveEvent( QMouseEvent *event ) { | 393 | void AudioWidget::mouseMoveEvent( QMouseEvent *event ) { |
394 | for ( int i = 0; i < numButtons; i++ ) { | 394 | for ( int i = 0; i < numButtons; i++ ) { |
395 | if ( event->state() == QMouseEvent::LeftButton ) { | 395 | if ( event->state() == QMouseEvent::LeftButton ) { |
396 | // The test to see if the mouse click is inside the button or not | 396 | // The test to see if the mouse click is inside the button or not |
397 | int x = event->pos().x() - xoff; | 397 | int x = event->pos().x() - xoff; |
398 | int y = event->pos().y() - yoff; | 398 | int y = event->pos().y() - yoff; |
399 | 399 | ||
400 | bool isOnButton = ( x > 0 && y > 0 && x < imgButtonMask->width() | 400 | bool isOnButton = ( x > 0 && y > 0 && x < imgButtonMask->width() |
401 | && y < imgButtonMask->height() | 401 | && y < imgButtonMask->height() |
402 | && imgButtonMask->pixelIndex( x, y ) == i + 1 ); | 402 | && imgButtonMask->pixelIndex( x, y ) == i + 1 ); |
403 | 403 | ||
404 | if ( isOnButton && !audioButtons[i].isHeld ) { | 404 | if ( isOnButton && !audioButtons[i].isHeld ) { |
405 | audioButtons[i].isHeld = TRUE; | 405 | audioButtons[i].isHeld = TRUE; |
406 | toggleButton(i); | 406 | toggleButton(i); |
407 | switch (i) { | 407 | switch (i) { |
408 | case AudioVolumeUp: | 408 | case AudioVolumeUp: |
409 | emit moreClicked(); | 409 | emit moreClicked(); |
410 | return; | 410 | return; |
411 | case AudioVolumeDown: | 411 | case AudioVolumeDown: |
412 | emit lessClicked(); | 412 | emit lessClicked(); |
413 | return; | 413 | return; |
414 | case AudioForward: | 414 | case AudioForward: |
415 | emit forwardClicked(); | 415 | emit forwardClicked(); |
416 | return; | 416 | return; |
417 | case AudioBack: | 417 | case AudioBack: |
418 | emit backClicked(); | 418 | emit backClicked(); |
419 | return; | 419 | return; |
420 | } | 420 | } |
421 | } else if ( !isOnButton && audioButtons[i].isHeld ) { | 421 | } else if ( !isOnButton && audioButtons[i].isHeld ) { |
422 | audioButtons[i].isHeld = FALSE; | 422 | audioButtons[i].isHeld = FALSE; |
423 | toggleButton(i); | 423 | toggleButton(i); |
424 | } | 424 | } |
425 | } else { | 425 | } else { |
426 | if ( audioButtons[i].isHeld ) { | 426 | if ( audioButtons[i].isHeld ) { |
427 | audioButtons[i].isHeld = FALSE; | 427 | audioButtons[i].isHeld = FALSE; |
428 | if ( !audioButtons[i].isToggle ) { | 428 | if ( !audioButtons[i].isToggle ) { |
429 | setToggleButton( i, FALSE ); | 429 | setToggleButton( i, FALSE ); |
430 | } | 430 | } |
431 | qDebug("mouseEvent %d", i); | 431 | qDebug("mouseEvent %d", i); |
432 | switch (i) { | 432 | switch (i) { |
433 | case AudioPlay: | 433 | case AudioPlay: |
434 | if( mediaPlayerState->isPaused() ) { | 434 | if( mediaPlayerState->isPaused() ) { |
435 | mediaPlayerState->setPaused( FALSE ); | 435 | mediaPlayerState->setPaused( FALSE ); |
436 | return; | 436 | return; |
437 | } else if( !mediaPlayerState->isPaused() ) { | 437 | } else if( !mediaPlayerState->isPaused() ) { |
438 | mediaPlayerState->setPaused( TRUE ); | 438 | mediaPlayerState->setPaused( TRUE ); |
439 | return; | 439 | return; |
440 | } | 440 | } |
441 | case AudioStop: mediaPlayerState->setPlaying(FALSE); return; | 441 | case AudioStop: mediaPlayerState->setPlaying(FALSE); return; |
442 | case AudioNext: if( playList->whichList() ==0 ) mediaPlayerState->setNext(); return; | 442 | case AudioNext: if( playList->currentTab() == PlayListWidget::CurrentPlayList ) mediaPlayerState->setNext(); return; |
443 | case AudioPrevious: if( playList->whichList() ==0 ) mediaPlayerState->setPrev(); return; | 443 | case AudioPrevious: if( playList->currentTab() == PlayListWidget::CurrentPlayList ) mediaPlayerState->setPrev(); return; |
444 | case AudioLoop: mediaPlayerState->setLooping(audioButtons[i].isDown); return; | 444 | case AudioLoop: mediaPlayerState->setLooping(audioButtons[i].isDown); return; |
445 | case AudioVolumeUp: emit moreReleased(); return; | 445 | case AudioVolumeUp: emit moreReleased(); return; |
446 | case AudioVolumeDown: emit lessReleased(); return; | 446 | case AudioVolumeDown: emit lessReleased(); return; |
447 | case AudioPlayList: mediaPlayerState->setList(); return; | 447 | case AudioPlayList: mediaPlayerState->setList(); return; |
448 | case AudioForward: emit forwardReleased(); return; | 448 | case AudioForward: emit forwardReleased(); return; |
449 | case AudioBack: emit backReleased(); return; | 449 | case AudioBack: emit backReleased(); return; |
450 | } | 450 | } |
451 | } | 451 | } |
452 | } | 452 | } |
453 | } | 453 | } |
454 | } | 454 | } |
455 | 455 | ||
456 | 456 | ||
457 | void AudioWidget::mousePressEvent( QMouseEvent *event ) { | 457 | void AudioWidget::mousePressEvent( QMouseEvent *event ) { |
458 | mouseMoveEvent( event ); | 458 | mouseMoveEvent( event ); |
459 | } | 459 | } |
460 | 460 | ||
461 | 461 | ||
462 | void AudioWidget::mouseReleaseEvent( QMouseEvent *event ) { | 462 | void AudioWidget::mouseReleaseEvent( QMouseEvent *event ) { |
463 | mouseMoveEvent( event ); | 463 | mouseMoveEvent( event ); |
464 | } | 464 | } |
465 | 465 | ||
466 | 466 | ||
467 | void AudioWidget::showEvent( QShowEvent* ) { | 467 | void AudioWidget::showEvent( QShowEvent* ) { |
468 | QMouseEvent event( QEvent::MouseMove, QPoint( 0, 0 ), 0, 0 ); | 468 | QMouseEvent event( QEvent::MouseMove, QPoint( 0, 0 ), 0, 0 ); |
469 | mouseMoveEvent( &event ); | 469 | mouseMoveEvent( &event ); |
470 | } | 470 | } |
471 | 471 | ||
472 | 472 | ||
473 | void AudioWidget::closeEvent( QCloseEvent* ) { | 473 | void AudioWidget::closeEvent( QCloseEvent* ) { |
474 | mediaPlayerState->setList(); | 474 | mediaPlayerState->setList(); |
475 | } | 475 | } |
476 | 476 | ||
477 | 477 | ||
478 | void AudioWidget::paintEvent( QPaintEvent * pe ) { | 478 | void AudioWidget::paintEvent( QPaintEvent * pe ) { |
479 | if ( !pe->erased() ) { | 479 | if ( !pe->erased() ) { |
480 | // Combine with background and double buffer | 480 | // Combine with background and double buffer |
481 | QPixmap pix( pe->rect().size() ); | 481 | QPixmap pix( pe->rect().size() ); |
482 | QPainter p( &pix ); | 482 | QPainter p( &pix ); |
483 | p.translate( -pe->rect().topLeft().x(), -pe->rect().topLeft().y() ); | 483 | p.translate( -pe->rect().topLeft().x(), -pe->rect().topLeft().y() ); |
484 | p.drawTiledPixmap( pe->rect(), *pixBg, pe->rect().topLeft() ); | 484 | p.drawTiledPixmap( pe->rect(), *pixBg, pe->rect().topLeft() ); |
485 | for ( int i = 0; i < numButtons; i++ ) | 485 | for ( int i = 0; i < numButtons; i++ ) |
486 | paintButton( &p, i ); | 486 | paintButton( &p, i ); |
487 | QPainter p2( this ); | 487 | QPainter p2( this ); |
488 | p2.drawPixmap( pe->rect().topLeft(), pix ); | 488 | p2.drawPixmap( pe->rect().topLeft(), pix ); |
489 | } else { | 489 | } else { |
490 | QPainter p( this ); | 490 | QPainter p( this ); |
491 | for ( int i = 0; i < numButtons; i++ ) | 491 | for ( int i = 0; i < numButtons; i++ ) |
492 | paintButton( &p, i ); | 492 | paintButton( &p, i ); |
493 | } | 493 | } |
494 | } | 494 | } |
495 | 495 | ||
496 | void AudioWidget::keyReleaseEvent( QKeyEvent *e) { | 496 | void AudioWidget::keyReleaseEvent( QKeyEvent *e) { |
497 | switch ( e->key() ) { | 497 | switch ( e->key() ) { |
498 | ////////////////////////////// Zaurus keys | 498 | ////////////////////////////// Zaurus keys |
499 | case Key_Home: | 499 | case Key_Home: |
500 | break; | 500 | break; |
501 | case Key_F9: //activity | 501 | case Key_F9: //activity |
502 | hide(); | 502 | hide(); |
503 | // qDebug("Audio F9"); | 503 | // qDebug("Audio F9"); |
504 | break; | 504 | break; |
505 | case Key_F10: //contacts | 505 | case Key_F10: //contacts |
506 | break; | 506 | break; |
507 | case Key_F11: //menu | 507 | case Key_F11: //menu |
508 | mediaPlayerState->toggleBlank(); | 508 | mediaPlayerState->toggleBlank(); |
509 | break; | 509 | break; |
510 | case Key_F12: //home | 510 | case Key_F12: //home |
511 | break; | 511 | break; |
512 | case Key_F13: //mail | 512 | case Key_F13: //mail |
513 | mediaPlayerState->toggleBlank(); | 513 | mediaPlayerState->toggleBlank(); |
514 | break; | 514 | break; |
515 | case Key_Space: { | 515 | case Key_Space: { |
516 | if(mediaPlayerState->isPlaying()) { | 516 | if(mediaPlayerState->isPlaying()) { |
517 | // toggleButton(1); | 517 | // toggleButton(1); |
518 | mediaPlayerState->setPlaying(FALSE); | 518 | mediaPlayerState->setPlaying(FALSE); |
519 | // toggleButton(1); | 519 | // toggleButton(1); |
520 | } else { | 520 | } else { |
521 | // toggleButton(0); | 521 | // toggleButton(0); |
522 | mediaPlayerState->setPlaying(TRUE); | 522 | mediaPlayerState->setPlaying(TRUE); |
523 | // toggleButton(0); | 523 | // toggleButton(0); |
524 | } | 524 | } |
525 | } | 525 | } |
526 | break; | 526 | break; |
527 | case Key_Down: | 527 | case Key_Down: |
528 | // toggleButton(6); | 528 | // toggleButton(6); |
529 | emit lessClicked(); | 529 | emit lessClicked(); |
530 | emit lessReleased(); | 530 | emit lessReleased(); |
531 | // toggleButton(6); | 531 | // toggleButton(6); |
532 | break; | 532 | break; |
533 | case Key_Up: | 533 | case Key_Up: |
534 | // toggleButton(5); | 534 | // toggleButton(5); |
535 | emit moreClicked(); | 535 | emit moreClicked(); |
536 | emit moreReleased(); | 536 | emit moreReleased(); |
537 | // toggleButton(5); | 537 | // toggleButton(5); |
538 | break; | 538 | break; |
539 | case Key_Right: | 539 | case Key_Right: |
540 | // toggleButton(3); | 540 | // toggleButton(3); |
541 | mediaPlayerState->setNext(); | 541 | mediaPlayerState->setNext(); |
542 | // toggleButton(3); | 542 | // toggleButton(3); |
543 | break; | 543 | break; |
544 | case Key_Left: | 544 | case Key_Left: |
545 | // toggleButton(4); | 545 | // toggleButton(4); |
546 | mediaPlayerState->setPrev(); | 546 | mediaPlayerState->setPrev(); |
547 | // toggleButton(4); | 547 | // toggleButton(4); |
548 | break; | 548 | break; |
549 | case Key_Escape: { | 549 | case Key_Escape: { |
550 | } | 550 | } |
551 | break; | 551 | break; |
552 | 552 | ||
553 | }; | 553 | }; |
554 | } | 554 | } |