-rw-r--r-- | noncore/multimedia/opieplayer2/audiowidget.cpp | 105 | ||||
-rw-r--r-- | noncore/multimedia/opieplayer2/audiowidget.h | 51 |
2 files changed, 134 insertions, 22 deletions
diff --git a/noncore/multimedia/opieplayer2/audiowidget.cpp b/noncore/multimedia/opieplayer2/audiowidget.cpp index 955169c..6b656ee 100644 --- a/noncore/multimedia/opieplayer2/audiowidget.cpp +++ b/noncore/multimedia/opieplayer2/audiowidget.cpp | |||
@@ -1,64 +1,96 @@ | |||
1 | /* | ||
2 | This file is part of the Opie Project | ||
3 | |||
4 | Copyright (c) 2002 Max Reiss <harlekin@handhelds.org> | ||
5 | Copyright (c) 2002 L. Potter <ljp@llornkcor.com> | ||
6 | Copyright (c) 2002 Holger Freyther <zecke@handhelds.org> | ||
7 | =. | ||
8 | .=l. | ||
9 | .>+-= | ||
10 | _;:, .> :=|. This program is free software; you can | ||
11 | .> <`_, > . <= redistribute it and/or modify it under | ||
12 | :`=1 )Y*s>-.-- : the terms of the GNU General Public | ||
13 | .="- .-=="i, .._ License as published by the Free Software | ||
14 | - . .-<_> .<> Foundation; either version 2 of the License, | ||
15 | ._= =} : or (at your option) any later version. | ||
16 | .%`+i> _;_. | ||
17 | .i_,=:_. -<s. This program is distributed in the hope that | ||
18 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | ||
19 | : .. .:, . . . without even the implied warranty of | ||
20 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | ||
21 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | ||
22 | ..}^=.= = ; Library General Public License for more | ||
23 | ++= -. .` .: details. | ||
24 | : = ...= . :.=- | ||
25 | -. .:....=;==+<; You should have received a copy of the GNU | ||
26 | -_. . . )=. = Library General Public License along with | ||
27 | -- :-=` this library; see the file COPYING.LIB. | ||
28 | If not, write to the Free Software Foundation, | ||
29 | Inc., 59 Temple Place - Suite 330, | ||
30 | Boston, MA 02111-1307, USA. | ||
31 | |||
32 | */ | ||
1 | 33 | ||
2 | #include <qpe/qpeapplication.h> | 34 | #include <qpe/qpeapplication.h> |
3 | #include <qpe/resource.h> | 35 | #include <qpe/resource.h> |
4 | #include <qpe/config.h> | 36 | #include <qpe/config.h> |
5 | 37 | ||
6 | #include <qwidget.h> | 38 | #include <qwidget.h> |
7 | #include <qpixmap.h> | 39 | #include <qpixmap.h> |
8 | #include <qbutton.h> | 40 | #include <qbutton.h> |
9 | #include <qpainter.h> | 41 | #include <qpainter.h> |
10 | #include <qframe.h> | 42 | #include <qframe.h> |
11 | #include <qlayout.h> | 43 | #include <qlayout.h> |
12 | 44 | ||
13 | #include <stdlib.h> | 45 | #include <stdlib.h> |
14 | #include <stdio.h> | 46 | #include <stdio.h> |
15 | 47 | ||
16 | #include "audiowidget.h" | 48 | #include "audiowidget.h" |
17 | #include "mediaplayerstate.h" | 49 | #include "mediaplayerstate.h" |
18 | 50 | ||
19 | extern MediaPlayerState *mediaPlayerState; | 51 | extern MediaPlayerState *mediaPlayerState; |
20 | 52 | ||
21 | static const int xo = -2; // movable x offset | 53 | static const int xo = -2; // movable x offset |
22 | static const int yo = 22; // movable y offset | 54 | static const int yo = 22; // movable y offset |
23 | 55 | ||
24 | 56 | ||
25 | Ticker::Ticker( QWidget* parent=0 ) : QFrame( parent ) { | 57 | Ticker::Ticker( QWidget* parent=0 ) : QFrame( parent ) { |
26 | setFrameStyle( WinPanel | Sunken ); | 58 | setFrameStyle( WinPanel | Sunken ); |
27 | setText( "No Song" ); | 59 | setText( "No Song" ); |
28 | } | 60 | } |
29 | 61 | ||
30 | Ticker::~Ticker() { | 62 | Ticker::~Ticker() { |
31 | } | 63 | } |
32 | 64 | ||
33 | void Ticker::setText( const QString& text ) { | 65 | void Ticker::setText( const QString& text ) { |
34 | pos = 0; // reset it everytime the text is changed | 66 | pos = 0; // reset it everytime the text is changed |
35 | scrollText = text; | 67 | scrollText = text; |
36 | pixelLen = fontMetrics().width( scrollText ); | 68 | pixelLen = fontMetrics().width( scrollText ); |
37 | killTimers(); | 69 | killTimers(); |
38 | if ( pixelLen > width() ) { | 70 | if ( pixelLen > width() ) { |
39 | startTimer( 50 ); | 71 | startTimer( 50 ); |
40 | } | 72 | } |
41 | update(); | 73 | update(); |
42 | } | 74 | } |
43 | 75 | ||
44 | 76 | ||
45 | void Ticker::timerEvent( QTimerEvent * ) { | 77 | void Ticker::timerEvent( QTimerEvent * ) { |
46 | pos = ( pos + 1 > pixelLen ) ? 0 : pos + 1; | 78 | pos = ( pos + 1 > pixelLen ) ? 0 : pos + 1; |
47 | scroll( -1, 0, contentsRect() ); | 79 | scroll( -1, 0, contentsRect() ); |
48 | repaint( FALSE ); | 80 | repaint( FALSE ); |
49 | } | 81 | } |
50 | 82 | ||
51 | void Ticker::drawContents( QPainter *p ) { | 83 | void Ticker::drawContents( QPainter *p ) { |
52 | for ( int i = 0; i - pos < width() && (i < 1 || pixelLen > width()); i += pixelLen ) | 84 | for ( int i = 0; i - pos < width() && (i < 1 || pixelLen > width()); i += pixelLen ) |
53 | p->drawText( i - pos, 0, INT_MAX, height(), AlignVCenter, scrollText ); | 85 | p->drawText( i - pos, 0, INT_MAX, height(), AlignVCenter, scrollText ); |
54 | QPixmap pm( width(), height() ); | 86 | QPixmap pm( width(), height() ); |
55 | pm.fill( colorGroup().base() ); | 87 | pm.fill( colorGroup().base() ); |
56 | QPainter pmp( &pm ); | 88 | QPainter pmp( &pm ); |
57 | for ( int i = 0; i - pos < width() && (i < 1 || pixelLen > width()); i += pixelLen ) { | 89 | for ( int i = 0; i - pos < width() && (i < 1 || pixelLen > width()); i += pixelLen ) { |
58 | pmp.drawText( i - pos, 0, INT_MAX, height(), AlignVCenter, scrollText ); | 90 | pmp.drawText( i - pos, 0, INT_MAX, height(), AlignVCenter, scrollText ); |
59 | } | 91 | } |
60 | p->drawPixmap( 0, 0, pm ); | 92 | p->drawPixmap( 0, 0, pm ); |
61 | } | 93 | } |
62 | 94 | ||
63 | struct MediaButton { | 95 | struct MediaButton { |
64 | bool isToggle, isHeld, isDown; | 96 | bool isToggle, isHeld, isDown; |
@@ -101,128 +133,135 @@ AudioWidget::AudioWidget(QWidget* parent, const char* name, WFlags f) : | |||
101 | 133 | ||
102 | Config cfg("OpiePlayer"); | 134 | Config cfg("OpiePlayer"); |
103 | cfg.setGroup("AudioWidget"); | 135 | cfg.setGroup("AudioWidget"); |
104 | skin = cfg.readEntry("Skin","default"); | 136 | skin = cfg.readEntry("Skin","default"); |
105 | //skin = "scaleTest"; | 137 | //skin = "scaleTest"; |
106 | // color of background, frame, degree of transparency | 138 | // color of background, frame, degree of transparency |
107 | 139 | ||
108 | QString skinPath = "opieplayer/skins/" + skin; | 140 | QString skinPath = "opieplayer/skins/" + skin; |
109 | pixBg = new QPixmap( Resource::loadPixmap( QString("%1/background").arg(skinPath) ) ); | 141 | pixBg = new QPixmap( Resource::loadPixmap( QString("%1/background").arg(skinPath) ) ); |
110 | imgUp = new QImage( Resource::loadImage( QString("%1/skin_up").arg(skinPath) ) ); | 142 | imgUp = new QImage( Resource::loadImage( QString("%1/skin_up").arg(skinPath) ) ); |
111 | imgDn = new QImage( Resource::loadImage( QString("%1/skin_down").arg(skinPath) ) ); | 143 | imgDn = new QImage( Resource::loadImage( QString("%1/skin_down").arg(skinPath) ) ); |
112 | 144 | ||
113 | imgButtonMask = new QImage( imgUp->width(), imgUp->height(), 8, 255 ); | 145 | imgButtonMask = new QImage( imgUp->width(), imgUp->height(), 8, 255 ); |
114 | imgButtonMask->fill( 0 ); | 146 | imgButtonMask->fill( 0 ); |
115 | 147 | ||
116 | for ( int i = 0; i < 11; i++ ) { | 148 | for ( int i = 0; i < 11; i++ ) { |
117 | QString filename = QString(getenv("OPIEDIR")) + "/pics/" + skinPath + "/skin_mask_" + skin_mask_file_names[i] + ".png"; | 149 | QString filename = QString(getenv("OPIEDIR")) + "/pics/" + skinPath + "/skin_mask_" + skin_mask_file_names[i] + ".png"; |
118 | masks[i] = new QBitmap( filename ); | 150 | masks[i] = new QBitmap( filename ); |
119 | 151 | ||
120 | if ( !masks[i]->isNull() ) { | 152 | if ( !masks[i]->isNull() ) { |
121 | QImage imgMask = masks[i]->convertToImage(); | 153 | QImage imgMask = masks[i]->convertToImage(); |
122 | uchar **dest = imgButtonMask->jumpTable(); | 154 | uchar **dest = imgButtonMask->jumpTable(); |
123 | for ( int y = 0; y < imgUp->height(); y++ ) { | 155 | for ( int y = 0; y < imgUp->height(); y++ ) { |
124 | uchar *line = dest[y]; | 156 | uchar *line = dest[y]; |
125 | for ( int x = 0; x < imgUp->width(); x++ ) | 157 | for ( int x = 0; x < imgUp->width(); x++ ) |
126 | if ( !qRed( imgMask.pixel( x, y ) ) ) | 158 | if ( !qRed( imgMask.pixel( x, y ) ) ) |
127 | line[x] = i + 1; | 159 | line[x] = i + 1; |
128 | } | 160 | } |
129 | } | 161 | } |
130 | 162 | ||
131 | } | 163 | } |
132 | 164 | ||
133 | for ( int i = 0; i < 11; i++ ) { | 165 | for ( int i = 0; i < 11; i++ ) { |
134 | buttonPixUp[i] = NULL; | 166 | buttonPixUp[i] = NULL; |
135 | buttonPixDown[i] = NULL; | 167 | buttonPixDown[i] = NULL; |
136 | } | 168 | } |
137 | 169 | ||
138 | setBackgroundPixmap( *pixBg ); | 170 | setBackgroundPixmap( *pixBg ); |
139 | 171 | ||
140 | songInfo.setFocusPolicy( QWidget::NoFocus ); | 172 | songInfo.setFocusPolicy( QWidget::NoFocus ); |
141 | changeTextColor( &songInfo ); | 173 | changeTextColor( &songInfo ); |
142 | 174 | ||
143 | slider.setFixedHeight( 20 ); | 175 | slider.setFixedHeight( 20 ); |
144 | slider.setMinValue( 0 ); | 176 | slider.setMinValue( 0 ); |
145 | slider.setMaxValue( 1 ); | 177 | slider.setMaxValue( 1 ); |
146 | slider.setFocusPolicy( QWidget::NoFocus ); | 178 | slider.setFocusPolicy( QWidget::NoFocus ); |
147 | slider.setBackgroundPixmap( *pixBg ); | 179 | slider.setBackgroundPixmap( *pixBg ); |
148 | 180 | ||
149 | time.setFocusPolicy( QWidget::NoFocus ); | 181 | time.setFocusPolicy( QWidget::NoFocus ); |
150 | time.setAlignment( Qt::AlignCenter ); | 182 | time.setAlignment( Qt::AlignCenter ); |
151 | time.setFrame(FALSE); | 183 | time.setFrame(FALSE); |
152 | changeTextColor( &time ); | 184 | changeTextColor( &time ); |
153 | 185 | ||
154 | resizeEvent( NULL ); | 186 | resizeEvent( NULL ); |
155 | 187 | ||
156 | connect( &slider, SIGNAL( sliderPressed() ), this, SLOT( sliderPressed() ) ); | 188 | connect( &slider, SIGNAL( sliderPressed() ), this, SLOT( sliderPressed() ) ); |
157 | connect( &slider, SIGNAL( sliderReleased() ), this, SLOT( sliderReleased() ) ); | 189 | connect( &slider, SIGNAL( sliderReleased() ), this, SLOT( sliderReleased() ) ); |
158 | 190 | ||
159 | connect( mediaPlayerState, SIGNAL( lengthChanged(long) ), this, SLOT( setLength(long) ) ); | 191 | connect( mediaPlayerState, SIGNAL( lengthChanged(long) ), this, SLOT( setLength(long) ) ); |
160 | connect( mediaPlayerState, SIGNAL( viewChanged(char) ), this, SLOT( setView(char) ) ); | 192 | connect( mediaPlayerState, SIGNAL( viewChanged(char) ), this, SLOT( setView(char) ) ); |
161 | connect( mediaPlayerState, SIGNAL( loopingToggled(bool) ), this, SLOT( setLooping(bool) ) ); | 193 | connect( mediaPlayerState, SIGNAL( loopingToggled(bool) ), this, SLOT( setLooping(bool) ) ); |
162 | connect( mediaPlayerState, SIGNAL( pausedToggled(bool) ), this, SLOT( setPaused(bool) ) ); | 194 | connect( mediaPlayerState, SIGNAL( pausedToggled(bool) ), this, SLOT( setPaused(bool) ) ); |
163 | connect( mediaPlayerState, SIGNAL( playingToggled(bool) ), this, SLOT( setPlaying(bool) ) ); | 195 | connect( mediaPlayerState, SIGNAL( playingToggled(bool) ), this, SLOT( setPlaying(bool) ) ); |
164 | 196 | ||
197 | connect( this, SIGNAL( forwardClicked() ), this, SLOT( skipFor() ) ); | ||
198 | connect( this, SIGNAL( backClicked() ), this, SLOT( skipBack() ) ); | ||
199 | connect( this, SIGNAL( forwardReleased() ), this, SLOT( stopSkip() ) ); | ||
200 | connect( this, SIGNAL( backReleased() ), this, SLOT( stopSkip() ) ); | ||
201 | |||
202 | |||
203 | |||
165 | // Intialise state | 204 | // Intialise state |
166 | setLength( mediaPlayerState->length() ); | 205 | setLength( mediaPlayerState->length() ); |
167 | setPosition( mediaPlayerState->position() ); | 206 | setPosition( mediaPlayerState->position() ); |
168 | setLooping( mediaPlayerState->fullscreen() ); | 207 | setLooping( mediaPlayerState->fullscreen() ); |
169 | setPaused( mediaPlayerState->paused() ); | 208 | setPaused( mediaPlayerState->paused() ); |
170 | setPlaying( mediaPlayerState->playing() ); | 209 | setPlaying( mediaPlayerState->playing() ); |
171 | 210 | ||
172 | } | 211 | } |
173 | 212 | ||
174 | AudioWidget::~AudioWidget() { | 213 | AudioWidget::~AudioWidget() { |
175 | 214 | ||
176 | for ( int i = 0; i < 11; i++ ) { | 215 | for ( int i = 0; i < 11; i++ ) { |
177 | delete buttonPixUp[i]; | 216 | delete buttonPixUp[i]; |
178 | delete buttonPixDown[i]; | 217 | delete buttonPixDown[i]; |
179 | } | 218 | } |
180 | delete pixBg; | 219 | delete pixBg; |
181 | delete imgUp; | 220 | delete imgUp; |
182 | delete imgDn; | 221 | delete imgDn; |
183 | delete imgButtonMask; | 222 | delete imgButtonMask; |
184 | for ( int i = 0; i < 11; i++ ) { | 223 | for ( int i = 0; i < 11; i++ ) { |
185 | delete masks[i]; | 224 | delete masks[i]; |
186 | } | 225 | } |
187 | } | 226 | } |
188 | 227 | ||
189 | QPixmap *combineImageWithBackground( QImage img, QPixmap bg, QPoint offset ) { | 228 | QPixmap *combineImageWithBackground( QImage img, QPixmap bg, QPoint offset ) { |
190 | QPixmap pix( img.width(), img.height() ); | 229 | QPixmap pix( img.width(), img.height() ); |
191 | QPainter p( &pix ); | 230 | QPainter p( &pix ); |
192 | p.drawTiledPixmap( pix.rect(), bg, offset ); | 231 | p.drawTiledPixmap( pix.rect(), bg, offset ); |
193 | p.drawImage( 0, 0, img ); | 232 | p.drawImage( 0, 0, img ); |
194 | return new QPixmap( pix ); | 233 | return new QPixmap( pix ); |
195 | } | 234 | } |
196 | 235 | ||
197 | 236 | ||
198 | QPixmap *maskPixToMask( QPixmap pix, QBitmap mask ) | 237 | QPixmap *maskPixToMask( QPixmap pix, QBitmap mask ) |
199 | { | 238 | { |
200 | QPixmap *pixmap = new QPixmap( pix ); | 239 | QPixmap *pixmap = new QPixmap( pix ); |
201 | pixmap->setMask( mask ); | 240 | pixmap->setMask( mask ); |
202 | return pixmap; | 241 | return pixmap; |
203 | } | 242 | } |
204 | 243 | ||
205 | 244 | ||
206 | 245 | ||
207 | void AudioWidget::resizeEvent( QResizeEvent * ) { | 246 | void AudioWidget::resizeEvent( QResizeEvent * ) { |
208 | int h = height(); | 247 | int h = height(); |
209 | int w = width(); | 248 | int w = width(); |
210 | 249 | ||
211 | songInfo.setGeometry( QRect( 2, 10, w - 4, 20 ) ); | 250 | songInfo.setGeometry( QRect( 2, 10, w - 4, 20 ) ); |
212 | slider.setFixedWidth( w - 110 ); | 251 | slider.setFixedWidth( w - 110 ); |
213 | slider.setGeometry( QRect( 15, h - 30, w - 90, 20 ) ); | 252 | slider.setGeometry( QRect( 15, h - 30, w - 90, 20 ) ); |
214 | slider.setBackgroundOrigin( QWidget::ParentOrigin ); | 253 | slider.setBackgroundOrigin( QWidget::ParentOrigin ); |
215 | time.setGeometry( QRect( w - 85, h - 30, 70, 20 ) ); | 254 | time.setGeometry( QRect( w - 85, h - 30, 70, 20 ) ); |
216 | 255 | ||
217 | xoff = ( w - imgUp->width() ) / 2; | 256 | xoff = ( w - imgUp->width() ) / 2; |
218 | yoff = (( h - imgUp->height() ) / 2) - 10; | 257 | yoff = (( h - imgUp->height() ) / 2) - 10; |
219 | QPoint p( xoff, yoff ); | 258 | QPoint p( xoff, yoff ); |
220 | 259 | ||
221 | QPixmap *pixUp = combineImageWithBackground( *imgUp, *pixBg, p ); | 260 | QPixmap *pixUp = combineImageWithBackground( *imgUp, *pixBg, p ); |
222 | QPixmap *pixDn = combineImageWithBackground( *imgDn, *pixBg, p ); | 261 | QPixmap *pixDn = combineImageWithBackground( *imgDn, *pixBg, p ); |
223 | 262 | ||
224 | for ( int i = 0; i < 11; i++ ) { | 263 | for ( int i = 0; i < 11; i++ ) { |
225 | if ( !masks[i]->isNull() ) { | 264 | if ( !masks[i]->isNull() ) { |
226 | delete buttonPixUp[i]; | 265 | delete buttonPixUp[i]; |
227 | delete buttonPixDown[i]; | 266 | delete buttonPixDown[i]; |
228 | buttonPixUp[i] = maskPixToMask( *pixUp, *masks[i] ); | 267 | buttonPixUp[i] = maskPixToMask( *pixUp, *masks[i] ); |
@@ -280,179 +319,211 @@ void AudioWidget::setView( char view ) { | |||
280 | // } | 319 | // } |
281 | 320 | ||
282 | if ( view == 'a' ) { | 321 | if ( view == 'a' ) { |
283 | startTimer( 150 ); | 322 | startTimer( 150 ); |
284 | showMaximized(); | 323 | showMaximized(); |
285 | } else { | 324 | } else { |
286 | killTimers(); | 325 | killTimers(); |
287 | hide(); | 326 | hide(); |
288 | } | 327 | } |
289 | } | 328 | } |
290 | 329 | ||
291 | 330 | ||
292 | static QString timeAsString( long length ) { | 331 | static QString timeAsString( long length ) { |
293 | int minutes = length / 60; | 332 | int minutes = length / 60; |
294 | int seconds = length % 60; | 333 | int seconds = length % 60; |
295 | return QString("%1:%2%3").arg( minutes ).arg( seconds / 10 ).arg( seconds % 10 ); | 334 | return QString("%1:%2%3").arg( minutes ).arg( seconds / 10 ).arg( seconds % 10 ); |
296 | } | 335 | } |
297 | 336 | ||
298 | void AudioWidget::updateSlider( long i, long max ) { | 337 | void AudioWidget::updateSlider( long i, long max ) { |
299 | 338 | ||
300 | time.setText( timeAsString( i ) + " / " + timeAsString( max ) ); | 339 | time.setText( timeAsString( i ) + " / " + timeAsString( max ) ); |
301 | // qDebug( timeAsString( i ) + " / " + timeAsString( max ) ) ; | 340 | // qDebug( timeAsString( i ) + " / " + timeAsString( max ) ) ; |
302 | 341 | ||
303 | if ( max == 0 ) { | 342 | if ( max == 0 ) { |
304 | return; | 343 | return; |
305 | } | 344 | } |
306 | // Will flicker too much if we don't do this | 345 | // Will flicker too much if we don't do this |
307 | // Scale to something reasonable | 346 | // Scale to something reasonable |
308 | int width = slider.width(); | 347 | int width = slider.width(); |
309 | int val = int((double)i * width / max); | 348 | int val = int((double)i * width / max); |
310 | if ( !audioSliderBeingMoved ) { | 349 | if ( !audioSliderBeingMoved ) { |
311 | if ( slider.value() != val ) { | 350 | if ( slider.value() != val ) { |
312 | slider.setValue( val ); | 351 | slider.setValue( val ); |
313 | } | 352 | } |
314 | 353 | ||
315 | if ( slider.maxValue() != width ) { | 354 | if ( slider.maxValue() != width ) { |
316 | slider.setMaxValue( width ); | 355 | slider.setMaxValue( width ); |
317 | } | 356 | } |
318 | } | 357 | } |
319 | } | 358 | } |
320 | 359 | ||
321 | 360 | ||
322 | void AudioWidget::setToggleButton( int i, bool down ) { | 361 | void AudioWidget::setToggleButton( int i, bool down ) { |
323 | if ( down != audioButtons[i].isDown ) { | 362 | if ( down != audioButtons[i].isDown ) { |
324 | toggleButton( i ); | 363 | toggleButton( i ); |
325 | } | 364 | } |
326 | } | 365 | } |
327 | 366 | ||
328 | 367 | ||
329 | void AudioWidget::toggleButton( int i ) { | 368 | void AudioWidget::toggleButton( int i ) { |
330 | audioButtons[i].isDown = !audioButtons[i].isDown; | 369 | audioButtons[i].isDown = !audioButtons[i].isDown; |
331 | QPainter p(this); | 370 | QPainter p(this); |
332 | paintButton ( &p, i ); | 371 | paintButton ( &p, i ); |
333 | } | 372 | } |
334 | 373 | ||
335 | 374 | ||
336 | void AudioWidget::paintButton( QPainter *p, int i ) { | 375 | void AudioWidget::paintButton( QPainter *p, int i ) { |
337 | if ( audioButtons[i].isDown ) | 376 | if ( audioButtons[i].isDown ) |
338 | p->drawPixmap( xoff, yoff, *buttonPixDown[i] ); | 377 | p->drawPixmap( xoff, yoff, *buttonPixDown[i] ); |
339 | else | 378 | else |
340 | p->drawPixmap( xoff, yoff, *buttonPixUp[i] ); | 379 | p->drawPixmap( xoff, yoff, *buttonPixUp[i] ); |
341 | } | 380 | } |
342 | 381 | ||
343 | 382 | ||
383 | void AudioWidget::skipFor() { | ||
384 | skipDirection = +1; | ||
385 | startTimer( 50 ); | ||
386 | mediaPlayerState->setPosition( mediaPlayerState->position() + 2 ); | ||
387 | } | ||
388 | |||
389 | void AudioWidget::skipBack() { | ||
390 | skipDirection = -1; | ||
391 | startTimer( 50 ); | ||
392 | mediaPlayerState->setPosition( mediaPlayerState->position() - 2 ); | ||
393 | } | ||
394 | |||
395 | |||
396 | |||
397 | void AudioWidget::stopSkip() { | ||
398 | killTimers(); | ||
399 | } | ||
400 | |||
401 | |||
344 | void AudioWidget::timerEvent( QTimerEvent * ) { | 402 | void AudioWidget::timerEvent( QTimerEvent * ) { |
403 | if ( skipDirection == +1 ) { | ||
404 | mediaPlayerState->setPosition( mediaPlayerState->position() + 2 ); | ||
405 | } else if ( skipDirection == -1 ) { | ||
406 | mediaPlayerState->setPosition( mediaPlayerState->position() - 2 ); | ||
407 | } | ||
345 | } | 408 | } |
346 | 409 | ||
347 | 410 | ||
348 | void AudioWidget::mouseMoveEvent( QMouseEvent *event ) { | 411 | void AudioWidget::mouseMoveEvent( QMouseEvent *event ) { |
349 | for ( int i = 0; i < numButtons; i++ ) { | 412 | for ( int i = 0; i < numButtons; i++ ) { |
350 | if ( event->state() == QMouseEvent::LeftButton ) { | 413 | if ( event->state() == QMouseEvent::LeftButton ) { |
351 | 414 | ||
352 | // The test to see if the mouse click is inside the button or not | 415 | // The test to see if the mouse click is inside the button or not |
353 | int x = event->pos().x() - xoff; | 416 | int x = event->pos().x() - xoff; |
354 | int y = event->pos().y() - yoff; | 417 | int y = event->pos().y() - yoff; |
355 | 418 | ||
356 | bool isOnButton = ( x > 0 && y > 0 && x < imgButtonMask->width() | 419 | bool isOnButton = ( x > 0 && y > 0 && x < imgButtonMask->width() |
357 | && y < imgButtonMask->height() && imgButtonMask->pixelIndex( x, y ) == i + 1 ); | 420 | && y < imgButtonMask->height() && imgButtonMask->pixelIndex( x, y ) == i + 1 ); |
358 | 421 | ||
359 | if ( isOnButton && i == AudioVolumeUp ) | 422 | if ( isOnButton && i == AudioVolumeUp ) |
360 | qDebug("on up"); | 423 | qDebug("on up"); |
361 | 424 | ||
362 | if ( isOnButton && !audioButtons[i].isHeld ) { | 425 | if ( isOnButton && !audioButtons[i].isHeld ) { |
363 | audioButtons[i].isHeld = TRUE; | 426 | audioButtons[i].isHeld = TRUE; |
364 | toggleButton(i); | 427 | toggleButton(i); |
365 | switch (i) { | 428 | switch (i) { |
366 | case AudioVolumeUp: | 429 | case AudioVolumeUp: |
367 | qDebug("more clicked"); | 430 | qDebug("more clicked"); |
368 | emit moreClicked(); | 431 | emit moreClicked(); |
369 | return; | 432 | return; |
370 | case AudioVolumeDown: | 433 | case AudioVolumeDown: |
371 | emit lessClicked(); | 434 | emit lessClicked(); |
372 | return; | 435 | return; |
436 | case AudioForward: | ||
437 | emit forwardClicked(); | ||
438 | return; | ||
439 | case AudioBack: | ||
440 | emit backClicked(); | ||
441 | return; | ||
373 | } | 442 | } |
374 | } else if ( !isOnButton && audioButtons[i].isHeld ) { | 443 | } else if ( !isOnButton && audioButtons[i].isHeld ) { |
375 | audioButtons[i].isHeld = FALSE; | 444 | audioButtons[i].isHeld = FALSE; |
376 | toggleButton(i); | 445 | toggleButton(i); |
377 | } | 446 | } |
378 | } else { | 447 | } else { |
379 | if ( audioButtons[i].isHeld ) { | 448 | if ( audioButtons[i].isHeld ) { |
380 | audioButtons[i].isHeld = FALSE; | 449 | audioButtons[i].isHeld = FALSE; |
381 | if ( !audioButtons[i].isToggle ) { | 450 | if ( !audioButtons[i].isToggle ) { |
382 | setToggleButton( i, FALSE ); | 451 | setToggleButton( i, FALSE ); |
383 | qDebug("button toggled3 %d",i); | 452 | qDebug("button toggled3 %d",i); |
384 | } | 453 | } |
385 | switch (i) { | 454 | switch (i) { |
386 | case AudioPlay: mediaPlayerState->setPlaying(audioButtons[i].isDown); return; | 455 | case AudioPlay: mediaPlayerState->setPlaying(audioButtons[i].isDown); return; |
387 | case AudioStop: mediaPlayerState->setPlaying(FALSE); return; | 456 | case AudioStop: mediaPlayerState->setPlaying(FALSE); return; |
388 | case AudioPause: mediaPlayerState->setPaused( audioButtons[i].isDown); return; | 457 | case AudioPause: mediaPlayerState->setPaused( audioButtons[i].isDown); return; |
389 | case AudioNext: mediaPlayerState->setNext(); return; | 458 | case AudioNext: mediaPlayerState->setNext(); return; |
390 | case AudioPrevious: mediaPlayerState->setPrev(); return; | 459 | case AudioPrevious: mediaPlayerState->setPrev(); return; |
391 | case AudioLoop: mediaPlayerState->setLooping(audioButtons[i].isDown); return; | 460 | case AudioLoop: mediaPlayerState->setLooping(audioButtons[i].isDown); return; |
392 | case AudioVolumeUp: emit moreReleased(); return; | 461 | case AudioVolumeUp: emit moreReleased(); return; |
393 | case AudioVolumeDown: emit lessReleased(); return; | 462 | case AudioVolumeDown: emit lessReleased(); return; |
394 | case AudioPlayList: mediaPlayerState->setList(); return; | 463 | case AudioPlayList: mediaPlayerState->setList(); return; |
464 | case AudioForward: emit forwardReleased(); return; | ||
465 | case AudioBack: emit backReleased(); return; | ||
395 | } | 466 | } |
396 | } | 467 | } |
397 | } | 468 | } |
398 | } | 469 | } |
399 | } | 470 | } |
400 | 471 | ||
401 | 472 | ||
402 | void AudioWidget::mousePressEvent( QMouseEvent *event ) { | 473 | void AudioWidget::mousePressEvent( QMouseEvent *event ) { |
403 | mouseMoveEvent( event ); | 474 | mouseMoveEvent( event ); |
404 | } | 475 | } |
405 | 476 | ||
406 | 477 | ||
407 | void AudioWidget::mouseReleaseEvent( QMouseEvent *event ) { | 478 | void AudioWidget::mouseReleaseEvent( QMouseEvent *event ) { |
408 | mouseMoveEvent( event ); | 479 | mouseMoveEvent( event ); |
409 | } | 480 | } |
410 | 481 | ||
411 | 482 | ||
412 | void AudioWidget::showEvent( QShowEvent* ) { | 483 | void AudioWidget::showEvent( QShowEvent* ) { |
413 | QMouseEvent event( QEvent::MouseMove, QPoint( 0, 0 ), 0, 0 ); | 484 | QMouseEvent event( QEvent::MouseMove, QPoint( 0, 0 ), 0, 0 ); |
414 | mouseMoveEvent( &event ); | 485 | mouseMoveEvent( &event ); |
415 | } | 486 | } |
416 | 487 | ||
417 | 488 | ||
418 | void AudioWidget::closeEvent( QCloseEvent* ) { | 489 | void AudioWidget::closeEvent( QCloseEvent* ) { |
419 | mediaPlayerState->setList(); | 490 | mediaPlayerState->setList(); |
420 | } | 491 | } |
421 | 492 | ||
422 | 493 | ||
423 | void AudioWidget::paintEvent( QPaintEvent * pe) { | 494 | void AudioWidget::paintEvent( QPaintEvent * pe) { |
424 | if ( !pe->erased() ) { | 495 | if ( !pe->erased() ) { |
425 | // Combine with background and double buffer | 496 | // Combine with background and double buffer |
426 | QPixmap pix( pe->rect().size() ); | 497 | QPixmap pix( pe->rect().size() ); |
427 | QPainter p( &pix ); | 498 | QPainter p( &pix ); |
428 | p.translate( -pe->rect().topLeft().x(), -pe->rect().topLeft().y() ); | 499 | p.translate( -pe->rect().topLeft().x(), -pe->rect().topLeft().y() ); |
429 | p.drawTiledPixmap( pe->rect(), *pixBg, pe->rect().topLeft() ); | 500 | p.drawTiledPixmap( pe->rect(), *pixBg, pe->rect().topLeft() ); |
430 | for ( int i = 0; i < numButtons; i++ ) | 501 | for ( int i = 0; i < numButtons; i++ ) |
431 | paintButton( &p, i ); | 502 | paintButton( &p, i ); |
432 | QPainter p2( this ); | 503 | QPainter p2( this ); |
433 | p2.drawPixmap( pe->rect().topLeft(), pix ); | 504 | p2.drawPixmap( pe->rect().topLeft(), pix ); |
434 | } else { | 505 | } else { |
435 | QPainter p( this ); | 506 | QPainter p( this ); |
436 | for ( int i = 0; i < numButtons; i++ ) | 507 | for ( int i = 0; i < numButtons; i++ ) |
437 | paintButton( &p, i ); | 508 | paintButton( &p, i ); |
438 | } | 509 | } |
439 | } | 510 | } |
440 | 511 | ||
441 | void AudioWidget::keyReleaseEvent( QKeyEvent *e) | 512 | void AudioWidget::keyReleaseEvent( QKeyEvent *e) |
442 | { | 513 | { |
443 | switch ( e->key() ) { | 514 | switch ( e->key() ) { |
444 | ////////////////////////////// Zaurus keys | 515 | ////////////////////////////// Zaurus keys |
445 | case Key_Home: | 516 | case Key_Home: |
446 | break; | 517 | break; |
447 | case Key_F9: //activity | 518 | case Key_F9: //activity |
448 | hide(); | 519 | hide(); |
449 | // qDebug("Audio F9"); | 520 | // qDebug("Audio F9"); |
450 | break; | 521 | break; |
451 | case Key_F10: //contacts | 522 | case Key_F10: //contacts |
452 | break; | 523 | break; |
453 | case Key_F11: //menu | 524 | case Key_F11: //menu |
454 | break; | 525 | break; |
455 | case Key_F12: //home | 526 | case Key_F12: //home |
456 | break; | 527 | break; |
457 | case Key_F13: //mail | 528 | case Key_F13: //mail |
458 | break; | 529 | break; |
diff --git a/noncore/multimedia/opieplayer2/audiowidget.h b/noncore/multimedia/opieplayer2/audiowidget.h index 2b892be..e05188e 100644 --- a/noncore/multimedia/opieplayer2/audiowidget.h +++ b/noncore/multimedia/opieplayer2/audiowidget.h | |||
@@ -1,108 +1,149 @@ | |||
1 | /* | ||
2 | This file is part of the Opie Project | ||
3 | |||
4 | Copyright (c) 2002 Max Reiss <harlekin@handhelds.org> | ||
5 | Copyright (c) 2002 L. Potter <ljp@llornkcor.com> | ||
6 | Copyright (c) 2002 Holger Freyther <zecke@handhelds.org> | ||
7 | =. | ||
8 | .=l. | ||
9 | .>+-= | ||
10 | _;:, .> :=|. This program is free software; you can | ||
11 | .> <`_, > . <= redistribute it and/or modify it under | ||
12 | :`=1 )Y*s>-.-- : the terms of the GNU General Public | ||
13 | .="- .-=="i, .._ License as published by the Free Software | ||
14 | - . .-<_> .<> Foundation; either version 2 of the License, | ||
15 | ._= =} : or (at your option) any later version. | ||
16 | .%`+i> _;_. | ||
17 | .i_,=:_. -<s. This program is distributed in the hope that | ||
18 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | ||
19 | : .. .:, . . . without even the implied warranty of | ||
20 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | ||
21 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | ||
22 | ..}^=.= = ; Library General Public License for more | ||
23 | ++= -. .` .: details. | ||
24 | : = ...= . :.=- | ||
25 | -. .:....=;==+<; You should have received a copy of the GNU | ||
26 | -_. . . )=. = Library General Public License along with | ||
27 | -- :-=` this library; see the file COPYING.LIB. | ||
28 | If not, write to the Free Software Foundation, | ||
29 | Inc., 59 Temple Place - Suite 330, | ||
30 | Boston, MA 02111-1307, USA. | ||
31 | |||
32 | */ | ||
33 | |||
1 | #ifndef AUDIO_WIDGET_H | 34 | #ifndef AUDIO_WIDGET_H |
2 | #define AUDIO_WIDGET_H | 35 | #define AUDIO_WIDGET_H |
3 | 36 | ||
4 | #include <qwidget.h> | 37 | #include <qwidget.h> |
5 | #include <qpainter.h> | 38 | #include <qpainter.h> |
6 | #include <qdrawutil.h> | 39 | #include <qdrawutil.h> |
7 | #include <qpixmap.h> | 40 | #include <qpixmap.h> |
8 | #include <qstring.h> | 41 | #include <qstring.h> |
9 | #include <qslider.h> | 42 | #include <qslider.h> |
10 | #include <qframe.h> | 43 | #include <qframe.h> |
11 | #include <qlineedit.h> | 44 | #include <qlineedit.h> |
12 | 45 | ||
13 | 46 | ||
14 | class QPixmap; | 47 | class QPixmap; |
15 | 48 | ||
16 | enum AudioButtons { | 49 | enum AudioButtons { |
17 | AudioPlay=0, | 50 | AudioPlay=0, |
18 | AudioStop, | 51 | AudioStop, |
19 | AudioPause, | 52 | AudioPause, |
20 | AudioNext, | 53 | AudioNext, |
21 | AudioPrevious, | 54 | AudioPrevious, |
22 | AudioVolumeUp, | 55 | AudioVolumeUp, |
23 | AudioVolumeDown, | 56 | AudioVolumeDown, |
24 | AudioLoop, | 57 | AudioLoop, |
25 | AudioPlayList | 58 | AudioPlayList, |
59 | AudioForward, | ||
60 | AudioBack | ||
26 | }; | 61 | }; |
27 | 62 | ||
28 | 63 | ||
29 | //#define USE_DBLBUF | ||
30 | |||
31 | |||
32 | class Ticker : public QFrame { | 64 | class Ticker : public QFrame { |
33 | Q_OBJECT | 65 | Q_OBJECT |
34 | 66 | ||
35 | public: | 67 | public: |
36 | Ticker( QWidget* parent=0 ); | 68 | Ticker( QWidget* parent=0 ); |
37 | ~Ticker(); | 69 | ~Ticker(); |
38 | void setText( const QString& text ) ; | 70 | void setText( const QString& text ) ; |
39 | 71 | ||
40 | protected: | 72 | protected: |
41 | void timerEvent( QTimerEvent * ); | 73 | void timerEvent( QTimerEvent * ); |
42 | void drawContents( QPainter *p ); | 74 | void drawContents( QPainter *p ); |
43 | private: | 75 | private: |
44 | QString scrollText; | 76 | QString scrollText; |
45 | int pos, pixelLen; | 77 | int pos, pixelLen; |
46 | }; | 78 | }; |
47 | 79 | ||
48 | 80 | ||
49 | class AudioWidget : public QWidget { | 81 | class AudioWidget : public QWidget { |
50 | Q_OBJECT | 82 | Q_OBJECT |
51 | public: | 83 | public: |
52 | AudioWidget( QWidget* parent=0, const char* name=0, WFlags f=0 ); | 84 | AudioWidget( QWidget* parent=0, const char* name=0, WFlags f=0 ); |
53 | ~AudioWidget(); | 85 | ~AudioWidget(); |
54 | void setTickerText( const QString &text ) { songInfo.setText( text ); } | 86 | void setTickerText( const QString &text ) { songInfo.setText( text ); } |
55 | bool isStreaming; | 87 | bool isStreaming; |
56 | public slots: | 88 | public slots: |
57 | void updateSlider( long, long ); | 89 | void updateSlider( long, long ); |
58 | void sliderPressed( ); | 90 | void sliderPressed( ); |
59 | void sliderReleased( ); | 91 | void sliderReleased( ); |
60 | void setPaused( bool b) { setToggleButton( AudioPause, b ); } | 92 | void setPaused( bool b) { setToggleButton( AudioPause, b ); } |
61 | void setLooping( bool b) { setToggleButton( AudioLoop, b ); } | 93 | void setLooping( bool b) { setToggleButton( AudioLoop, b ); } |
62 | void setPlaying( bool b) { setToggleButton( AudioPlay, b ); } | 94 | void setPlaying( bool b) { setToggleButton( AudioPlay, b ); } |
63 | void setPosition( long ); | 95 | void setPosition( long ); |
64 | void setLength( long ); | 96 | void setLength( long ); |
65 | void setView( char ); | 97 | void setView( char ); |
66 | 98 | ||
67 | signals: | 99 | signals: |
68 | void moreClicked(); | 100 | void moreClicked(); |
69 | void lessClicked(); | 101 | void lessClicked(); |
70 | void moreReleased(); | 102 | void moreReleased(); |
71 | void lessReleased(); | 103 | void lessReleased(); |
104 | void forwardClicked(); | ||
105 | void backClicked(); | ||
106 | void forwardReleased(); | ||
107 | void backReleased(); | ||
72 | void sliderMoved(long); | 108 | void sliderMoved(long); |
73 | 109 | ||
74 | protected: | 110 | protected: |
75 | void doBlank(); | 111 | void doBlank(); |
76 | void doUnblank(); | 112 | void doUnblank(); |
77 | void paintEvent( QPaintEvent *pe ); | 113 | void paintEvent( QPaintEvent *pe ); |
78 | void showEvent( QShowEvent *se ); | 114 | void showEvent( QShowEvent *se ); |
79 | void resizeEvent( QResizeEvent *re ); | 115 | void resizeEvent( QResizeEvent *re ); |
80 | void mouseMoveEvent( QMouseEvent *event ); | 116 | void mouseMoveEvent( QMouseEvent *event ); |
81 | void mousePressEvent( QMouseEvent *event ); | 117 | void mousePressEvent( QMouseEvent *event ); |
82 | void mouseReleaseEvent( QMouseEvent *event ); | 118 | void mouseReleaseEvent( QMouseEvent *event ); |
83 | void timerEvent( QTimerEvent *event ); | 119 | void timerEvent( QTimerEvent *event ); |
84 | void closeEvent( QCloseEvent *event ); | 120 | void closeEvent( QCloseEvent *event ); |
85 | void keyReleaseEvent( QKeyEvent *e); | 121 | void keyReleaseEvent( QKeyEvent *e); |
122 | private slots: | ||
123 | void skipFor(); | ||
124 | void skipBack(); | ||
125 | void stopSkip(); | ||
86 | private: | 126 | private: |
87 | void toggleButton( int ); | 127 | void toggleButton( int ); |
88 | void setToggleButton( int, bool ); | 128 | void setToggleButton( int, bool ); |
89 | void paintButton( QPainter *p, int i ); | 129 | void paintButton( QPainter *p, int i ); |
130 | int skipDirection; | ||
90 | QString skin; | 131 | QString skin; |
91 | QPixmap *pixBg; | 132 | QPixmap *pixBg; |
92 | QImage *imgUp; | 133 | QImage *imgUp; |
93 | QImage *imgDn; | 134 | QImage *imgDn; |
94 | QImage *imgButtonMask; | 135 | QImage *imgButtonMask; |
95 | QBitmap *masks[11]; | 136 | QBitmap *masks[11]; |
96 | QPixmap *buttonPixUp[11]; | 137 | QPixmap *buttonPixUp[11]; |
97 | QPixmap *buttonPixDown[11]; | 138 | QPixmap *buttonPixDown[11]; |
98 | 139 | ||
99 | QPixmap *pixmaps[4]; | 140 | QPixmap *pixmaps[4]; |
100 | Ticker songInfo; | 141 | Ticker songInfo; |
101 | QSlider slider; | 142 | QSlider slider; |
102 | QLineEdit time; | 143 | QLineEdit time; |
103 | int xoff, yoff; | 144 | int xoff, yoff; |
104 | }; | 145 | }; |
105 | 146 | ||
106 | 147 | ||
107 | #endif // AUDIO_WIDGET_H | 148 | #endif // AUDIO_WIDGET_H |
108 | 149 | ||