author | llornkcor <llornkcor> | 2002-07-16 12:33:22 (UTC) |
---|---|---|
committer | llornkcor <llornkcor> | 2002-07-16 12:33:22 (UTC) |
commit | 4d5c003d4602e5e5bdc42deba7587fc0b838c7fb (patch) (unidiff) | |
tree | 7b20d18733555591dc11a557629a4cf94f727242 /noncore/multimedia | |
parent | 5e9626775709fdf1815e3ff4584aede3ceaa4d58 (diff) | |
download | opie-4d5c003d4602e5e5bdc42deba7587fc0b838c7fb.zip opie-4d5c003d4602e5e5bdc42deba7587fc0b838c7fb.tar.gz opie-4d5c003d4602e5e5bdc42deba7587fc0b838c7fb.tar.bz2 |
added new audiowidget skinable from qtopia 1.6 graphics later
-rw-r--r-- | noncore/multimedia/opieplayer2/audiowidget.cpp | 276 | ||||
-rw-r--r-- | noncore/multimedia/opieplayer2/audiowidget.h | 18 | ||||
-rw-r--r-- | noncore/multimedia/opieplayer2/mediaplayer.cpp | 47 |
3 files changed, 260 insertions, 81 deletions
diff --git a/noncore/multimedia/opieplayer2/audiowidget.cpp b/noncore/multimedia/opieplayer2/audiowidget.cpp index 303e56e..9f384cc 100644 --- a/noncore/multimedia/opieplayer2/audiowidget.cpp +++ b/noncore/multimedia/opieplayer2/audiowidget.cpp | |||
@@ -7,12 +7,15 @@ | |||
7 | #include <qpixmap.h> | 7 | #include <qpixmap.h> |
8 | #include <qbutton.h> | 8 | #include <qbutton.h> |
9 | #include <qpainter.h> | 9 | #include <qpainter.h> |
10 | #include <qframe.h> | 10 | #include <qframe.h> |
11 | #include <qlayout.h> | 11 | #include <qlayout.h> |
12 | 12 | ||
13 | #include <stdlib.h> | ||
14 | #include <stdio.h> | ||
15 | |||
13 | #include "audiowidget.h" | 16 | #include "audiowidget.h" |
14 | #include "mediaplayerstate.h" | 17 | #include "mediaplayerstate.h" |
15 | 18 | ||
16 | extern MediaPlayerState *mediaPlayerState; | 19 | extern MediaPlayerState *mediaPlayerState; |
17 | 20 | ||
18 | static const int xo = -2; // movable x offset | 21 | static const int xo = -2; // movable x offset |
@@ -38,117 +41,215 @@ void Ticker::setText( const QString& text ) { | |||
38 | update(); | 41 | update(); |
39 | } | 42 | } |
40 | 43 | ||
41 | 44 | ||
42 | void Ticker::timerEvent( QTimerEvent * ) { | 45 | void Ticker::timerEvent( QTimerEvent * ) { |
43 | pos = ( pos + 1 > pixelLen ) ? 0 : pos + 1; | 46 | pos = ( pos + 1 > pixelLen ) ? 0 : pos + 1; |
47 | scroll( -1, 0, contentsRect() ); | ||
44 | repaint( FALSE ); | 48 | repaint( FALSE ); |
45 | } | 49 | } |
46 | 50 | ||
47 | void Ticker::drawContents( QPainter *p ) { | 51 | void Ticker::drawContents( QPainter *p ) { |
52 | for ( int i = 0; i - pos < width() && (i < 1 || pixelLen > width()); i += pixelLen ) | ||
53 | p->drawText( i - pos, 0, INT_MAX, height(), AlignVCenter, scrollText ); | ||
48 | QPixmap pm( width(), height() ); | 54 | QPixmap pm( width(), height() ); |
49 | pm.fill( colorGroup().base() ); | 55 | pm.fill( colorGroup().base() ); |
50 | QPainter pmp( &pm ); | 56 | QPainter pmp( &pm ); |
51 | for ( int i = 0; i - pos < width() && (i < 1 || pixelLen > width()); i += pixelLen ) { | 57 | for ( int i = 0; i - pos < width() && (i < 1 || pixelLen > width()); i += pixelLen ) { |
52 | pmp.drawText( i - pos, 0, INT_MAX, height(), AlignVCenter, scrollText ); | 58 | pmp.drawText( i - pos, 0, INT_MAX, height(), AlignVCenter, scrollText ); |
53 | } | 59 | } |
54 | p->drawPixmap( 0, 0, pm ); | 60 | p->drawPixmap( 0, 0, pm ); |
55 | } | 61 | } |
56 | 62 | ||
57 | |||
58 | struct MediaButton { | 63 | struct MediaButton { |
59 | int xPos, yPos; | 64 | bool isToggle, isHeld, isDown; |
60 | int color; | ||
61 | bool isToggle, isBig, isHeld, isDown; | ||
62 | }; | 65 | }; |
63 | 66 | ||
64 | 67 | //Layout information for the audioButtons (and if it is a toggle button or not) | |
65 | // Layout information for the audioButtons (and if it is a toggle button or not) | ||
66 | MediaButton audioButtons[] = { | 68 | MediaButton audioButtons[] = { |
67 | { 3*30-15+xo, 3*30-13+yo, 0, TRUE, TRUE, FALSE, FALSE }, // play | 69 | { TRUE, FALSE, FALSE }, // play |
68 | { 1*30+xo, 5*30+yo, 2, FALSE, FALSE, FALSE, FALSE }, // stop | 70 | { FALSE, FALSE, FALSE }, // stop |
69 | { 5*30+xo, 5*30+yo, 2, TRUE, FALSE, FALSE, FALSE }, // pause | 71 | { TRUE, FALSE, FALSE }, // pause |
70 | { 6*30-5+xo, 3*30+yo, 1, FALSE, FALSE, FALSE, FALSE }, // next | 72 | { FALSE, FALSE, FALSE }, // next |
71 | { 0*30+5+xo, 3*30+yo, 1, FALSE, FALSE, FALSE, FALSE }, // previous | 73 | { FALSE, FALSE, FALSE }, // previous |
72 | { 3*30+xo, 0*30+5+yo, 3, FALSE, FALSE, FALSE, FALSE }, // volume up | 74 | { FALSE, FALSE, FALSE }, // volume up |
73 | { 3*30+xo, 6*30-5+yo, 3, FALSE, FALSE, FALSE, FALSE }, // volume down | 75 | { FALSE, FALSE, FALSE }, // volume down |
74 | { 5*30+xo, 1*30+yo, 0, TRUE, FALSE, FALSE, FALSE }, // repeat/loop | 76 | { TRUE, FALSE, FALSE }, // repeat/loop |
75 | { 1*30+xo, 1*30+yo, 0, FALSE, FALSE, FALSE, FALSE } // playlist | 77 | { FALSE, FALSE, FALSE }, // playlist |
78 | { FALSE, FALSE, FALSE }, // forward | ||
79 | { FALSE, FALSE, FALSE } // back | ||
76 | }; | 80 | }; |
77 | 81 | ||
82 | const char *skin_mask_file_names[11] = { | ||
83 | "play", "stop", "pause", "next", "prev", "up", | ||
84 | "down", "loop", "playlist", "forward", "back" | ||
85 | }; | ||
86 | |||
87 | |||
88 | static void changeTextColor( QWidget *w ) { | ||
89 | QPalette p = w->palette(); | ||
90 | p.setBrush( QColorGroup::Background, QColor( 167, 212, 167 ) ); | ||
91 | p.setBrush( QColorGroup::Base, QColor( 167, 212, 167 ) ); | ||
92 | w->setPalette( p ); | ||
93 | } | ||
94 | |||
78 | static const int numButtons = (sizeof(audioButtons)/sizeof(MediaButton)); | 95 | static const int numButtons = (sizeof(audioButtons)/sizeof(MediaButton)); |
79 | 96 | ||
80 | 97 | ||
81 | AudioWidget::AudioWidget(QWidget* parent, const char* name, WFlags f) : | 98 | AudioWidget::AudioWidget(QWidget* parent, const char* name, WFlags f) : |
82 | QWidget( parent, name, f ) { | 99 | QWidget( parent, name, f ), songInfo( this ), slider( Qt::Horizontal, this ), time( this ) |
83 | setCaption( tr("OpiePlayer - Audio") ); | 100 | setCaption( tr("OpiePlayer") ); |
101 | |||
84 | Config cfg("OpiePlayer"); | 102 | Config cfg("OpiePlayer"); |
85 | cfg.setGroup("AudioWidget"); | 103 | cfg.setGroup("AudioWidget"); |
104 | skin = cfg.readEntry("Skin","default"); | ||
105 | //skin = "scaleTest"; | ||
106 | // color of background, frame, degree of transparency | ||
107 | |||
108 | QString skinPath = "mediaplayer/skins/" + skin; | ||
109 | pixBg = new QPixmap( Resource::loadPixmap( QString("%1/background").arg(skinPath) ) ); | ||
110 | imgUp = new QImage( Resource::loadImage( QString("%1/skin_up").arg(skinPath) ) ); | ||
111 | imgDn = new QImage( Resource::loadImage( QString("%1/skin_down").arg(skinPath) ) ); | ||
112 | |||
113 | imgButtonMask = new QImage( imgUp->width(), imgUp->height(), 8, 255 ); | ||
114 | imgButtonMask->fill( 0 ); | ||
115 | |||
116 | for ( int i = 0; i < 11; i++ ) { | ||
117 | QString filename = QString(getenv("OPIEDIR")) + "/pics/" + skinPath + "/skin_mask_" + skin_mask_file_names[i] + ".png"; | ||
118 | masks[i] = new QBitmap( filename ); | ||
119 | |||
120 | if ( !masks[i]->isNull() ) { | ||
121 | QImage imgMask = masks[i]->convertToImage(); | ||
122 | uchar **dest = imgButtonMask->jumpTable(); | ||
123 | for ( int y = 0; y < imgUp->height(); y++ ) { | ||
124 | uchar *line = dest[y]; | ||
125 | for ( int x = 0; x < imgUp->width(); x++ ) | ||
126 | if ( !qRed( imgMask.pixel( x, y ) ) ) | ||
127 | line[x] = i + 1; | ||
128 | } | ||
129 | } | ||
130 | |||
131 | } | ||
132 | |||
133 | for ( int i = 0; i < 11; i++ ) { | ||
134 | buttonPixUp[i] = NULL; | ||
135 | buttonPixDown[i] = NULL; | ||
136 | } | ||
137 | |||
138 | setBackgroundPixmap( *pixBg ); | ||
139 | |||
140 | songInfo.setFocusPolicy( QWidget::NoFocus ); | ||
141 | changeTextColor( &songInfo ); | ||
142 | |||
143 | slider.setFixedHeight( 20 ); | ||
144 | slider.setMinValue( 0 ); | ||
145 | slider.setMaxValue( 1 ); | ||
146 | slider.setFocusPolicy( QWidget::NoFocus ); | ||
147 | slider.setBackgroundPixmap( *pixBg ); | ||
148 | |||
149 | time.setFocusPolicy( QWidget::NoFocus ); | ||
150 | time.setAlignment( Qt::AlignCenter ); | ||
151 | time.setFrame(FALSE); | ||
152 | changeTextColor( &time ); | ||
153 | |||
154 | resizeEvent( NULL ); | ||
155 | |||
156 | connect( &slider, SIGNAL( sliderPressed() ), this, SLOT( sliderPressed() ) ); | ||
157 | connect( &slider, SIGNAL( sliderReleased() ), this, SLOT( sliderReleased() ) ); | ||
86 | 158 | ||
87 | QString backgroundPix, buttonsAllPix, buttonsBigPix, controlsPix, animatedPix; | ||
88 | backgroundPix=cfg.readEntry( " backgroundPix", "opieplayer/metalFinish"); | ||
89 | buttonsAllPix=cfg.readEntry( "buttonsAllPix","opieplayer/mediaButtonsAll"); | ||
90 | buttonsBigPix=cfg.readEntry( "buttonsBigPix","opieplayer/mediaButtonsBig"); | ||
91 | controlsPix=cfg.readEntry( "controlsPix","opieplayer/mediaControls"); | ||
92 | |||
93 | setBackgroundPixmap( Resource::loadPixmap( backgroundPix) ); | ||
94 | pixmaps[0] = new QPixmap( Resource::loadPixmap( buttonsAllPix ) ); | ||
95 | pixmaps[1] = new QPixmap( Resource::loadPixmap( buttonsBigPix ) ); | ||
96 | pixmaps[2] = new QPixmap( Resource::loadPixmap( controlsPix ) ); | ||
97 | |||
98 | songInfo = new Ticker( this ); | ||
99 | songInfo->setFocusPolicy( QWidget::NoFocus ); | ||
100 | songInfo->setGeometry( QRect( 7, 3, 220, 20 ) ); | ||
101 | |||
102 | slider = new QSlider( Qt::Horizontal, this ); | ||
103 | slider->setFixedWidth( 220 ); | ||
104 | slider->setFixedHeight( 20 ); | ||
105 | slider->setMinValue( 0 ); | ||
106 | slider->setMaxValue( 1 ); | ||
107 | slider->setBackgroundPixmap( Resource::loadPixmap( backgroundPix ) ); | ||
108 | slider->setFocusPolicy( QWidget::NoFocus ); | ||
109 | slider->setGeometry( QRect( 7, 262, 220, 20 ) ); | ||
110 | |||
111 | connect( slider, SIGNAL( sliderPressed() ), this, SLOT( sliderPressed() ) ); | ||
112 | connect( slider, SIGNAL( sliderReleased() ), this, SLOT( sliderReleased() ) ); | ||
113 | connect( mediaPlayerState, SIGNAL( lengthChanged(long) ), this, SLOT( setLength(long) ) ); | 159 | connect( mediaPlayerState, SIGNAL( lengthChanged(long) ), this, SLOT( setLength(long) ) ); |
114 | connect( mediaPlayerState, SIGNAL( viewChanged(char) ), this, SLOT( setView(char) ) ); | 160 | connect( mediaPlayerState, SIGNAL( viewChanged(char) ), this, SLOT( setView(char) ) ); |
115 | connect( mediaPlayerState, SIGNAL( loopingToggled(bool) ), this, SLOT( setLooping(bool) ) ); | 161 | connect( mediaPlayerState, SIGNAL( loopingToggled(bool) ), this, SLOT( setLooping(bool) ) ); |
116 | connect( mediaPlayerState, SIGNAL( pausedToggled(bool) ), this, SLOT( setPaused(bool) ) ); | 162 | connect( mediaPlayerState, SIGNAL( pausedToggled(bool) ), this, SLOT( setPaused(bool) ) ); |
117 | connect( mediaPlayerState, SIGNAL( playingToggled(bool) ), this, SLOT( setPlaying(bool) ) ); | 163 | connect( mediaPlayerState, SIGNAL( playingToggled(bool) ), this, SLOT( setPlaying(bool) ) ); |
118 | 164 | ||
119 | // Intialise state | 165 | // Intialise state |
120 | setLength( mediaPlayerState->length() ); | 166 | setLength( mediaPlayerState->length() ); |
121 | setPosition( mediaPlayerState->position() ); | 167 | setPosition( mediaPlayerState->position() ); |
122 | setLooping( mediaPlayerState->fullscreen() ); | 168 | setLooping( mediaPlayerState->fullscreen() ); |
123 | setPaused( mediaPlayerState->paused() ); | 169 | setPaused( mediaPlayerState->paused() ); |
124 | setPlaying( mediaPlayerState->playing() ); | 170 | setPlaying( mediaPlayerState->playing() ); |
171 | |||
125 | } | 172 | } |
126 | 173 | ||
127 | AudioWidget::~AudioWidget() { | 174 | AudioWidget::~AudioWidget() { |
128 | mediaPlayerState->setIsStreaming( FALSE ); | 175 | |
129 | for ( int i = 0; i < 3; i++ ) { | 176 | for ( int i = 0; i < 11; i++ ) { |
130 | delete pixmaps[i]; | 177 | delete buttonPixUp[i]; |
178 | delete buttonPixDown[i]; | ||
131 | } | 179 | } |
180 | delete pixBg; | ||
181 | delete imgUp; | ||
182 | delete imgDn; | ||
183 | delete imgButtonMask; | ||
184 | for ( int i = 0; i < 11; i++ ) { | ||
185 | delete masks[i]; | ||
186 | } | ||
187 | } | ||
188 | |||
189 | QPixmap *combineImageWithBackground( QImage img, QPixmap bg, QPoint offset ) { | ||
190 | QPixmap pix( img.width(), img.height() ); | ||
191 | QPainter p( &pix ); | ||
192 | p.drawTiledPixmap( pix.rect(), bg, offset ); | ||
193 | p.drawImage( 0, 0, img ); | ||
194 | return new QPixmap( pix ); | ||
132 | } | 195 | } |
133 | 196 | ||
134 | 197 | ||
198 | QPixmap *maskPixToMask( QPixmap pix, QBitmap mask ) | ||
199 | { | ||
200 | QPixmap *pixmap = new QPixmap( pix ); | ||
201 | pixmap->setMask( mask ); | ||
202 | return pixmap; | ||
203 | } | ||
204 | |||
205 | |||
206 | |||
207 | void AudioWidget::resizeEvent( QResizeEvent * ) { | ||
208 | int h = height(); | ||
209 | int w = width(); | ||
210 | |||
211 | songInfo.setGeometry( QRect( 2, 10, w - 4, 20 ) ); | ||
212 | slider.setFixedWidth( w - 110 ); | ||
213 | slider.setGeometry( QRect( 15, h - 30, w - 90, 20 ) ); | ||
214 | slider.setBackgroundOrigin( QWidget::ParentOrigin ); | ||
215 | time.setGeometry( QRect( w - 85, h - 30, 70, 20 ) ); | ||
216 | |||
217 | xoff = ( w - imgUp->width() ) / 2; | ||
218 | yoff = (( h - imgUp->height() ) / 2) - 10; | ||
219 | QPoint p( xoff, yoff ); | ||
220 | |||
221 | QPixmap *pixUp = combineImageWithBackground( *imgUp, *pixBg, p ); | ||
222 | QPixmap *pixDn = combineImageWithBackground( *imgDn, *pixBg, p ); | ||
223 | |||
224 | for ( int i = 0; i < 11; i++ ) { | ||
225 | if ( !masks[i]->isNull() ) { | ||
226 | delete buttonPixUp[i]; | ||
227 | delete buttonPixDown[i]; | ||
228 | buttonPixUp[i] = maskPixToMask( *pixUp, *masks[i] ); | ||
229 | buttonPixDown[i] = maskPixToMask( *pixDn, *masks[i] ); | ||
230 | } | ||
231 | } | ||
232 | |||
233 | delete pixUp; | ||
234 | delete pixDn; | ||
235 | } | ||
236 | |||
135 | static bool audioSliderBeingMoved = FALSE; | 237 | static bool audioSliderBeingMoved = FALSE; |
136 | 238 | ||
137 | 239 | ||
138 | void AudioWidget::sliderPressed() { | 240 | void AudioWidget::sliderPressed() { |
139 | audioSliderBeingMoved = TRUE; | 241 | audioSliderBeingMoved = TRUE; |
140 | } | 242 | } |
141 | 243 | ||
142 | 244 | ||
143 | void AudioWidget::sliderReleased() { | 245 | void AudioWidget::sliderReleased() { |
144 | audioSliderBeingMoved = FALSE; | 246 | audioSliderBeingMoved = FALSE; |
145 | if ( slider->width() == 0 ) { | 247 | if ( slider.width() == 0 ) |
146 | return; | 248 | return; |
147 | } | 249 | long val = long((double)slider.value() * mediaPlayerState->length() / slider.width()); |
148 | long val = long((double)slider->value() * mediaPlayerState->length() / slider->width()); | ||
149 | mediaPlayerState->setPosition( val ); | 250 | mediaPlayerState->setPosition( val ); |
150 | } | 251 | } |
151 | 252 | ||
152 | void AudioWidget::setPosition( long i ) { | 253 | void AudioWidget::setPosition( long i ) { |
153 | // qDebug("set position %d",i); | 254 | // qDebug("set position %d",i); |
154 | updateSlider( i, mediaPlayerState->length() ); | 255 | updateSlider( i, mediaPlayerState->length() ); |
@@ -159,13 +260,13 @@ void AudioWidget::setLength( long max ) { | |||
159 | updateSlider( mediaPlayerState->position(), max ); | 260 | updateSlider( mediaPlayerState->position(), max ); |
160 | } | 261 | } |
161 | 262 | ||
162 | 263 | ||
163 | void AudioWidget::setView( char view ) { | 264 | void AudioWidget::setView( char view ) { |
164 | if (mediaPlayerState->streaming() ) { | 265 | if (mediaPlayerState->streaming() ) { |
165 | if( !slider->isHidden()) slider->hide(); | 266 | if( !slider.isHidden()) slider.hide(); |
166 | disconnect( mediaPlayerState, SIGNAL( positionChanged(long) ),this, SLOT( setPosition(long) ) ); | 267 | disconnect( mediaPlayerState, SIGNAL( positionChanged(long) ),this, SLOT( setPosition(long) ) ); |
167 | disconnect( mediaPlayerState, SIGNAL( positionUpdated(long) ),this, SLOT( setPosition(long) ) ); | 268 | disconnect( mediaPlayerState, SIGNAL( positionUpdated(long) ),this, SLOT( setPosition(long) ) ); |
168 | } else { | 269 | } else { |
169 | // this stops the slider from being moved, thus | 270 | // this stops the slider from being moved, thus |
170 | // does not stop stream when it reaches the end | 271 | // does not stop stream when it reaches the end |
171 | slider->show(); | 272 | slider->show(); |
@@ -180,13 +281,21 @@ void AudioWidget::setView( char view ) { | |||
180 | killTimers(); | 281 | killTimers(); |
181 | hide(); | 282 | hide(); |
182 | } | 283 | } |
183 | } | 284 | } |
184 | 285 | ||
185 | 286 | ||
287 | static QString timeAsString( long length ) { | ||
288 | length /= 44100; | ||
289 | int minutes = length / 60; | ||
290 | int seconds = length % 60; | ||
291 | return QString("%1:%2%3").arg( minutes ).arg( seconds / 10 ).arg( seconds % 10 ); | ||
292 | } | ||
293 | |||
186 | void AudioWidget::updateSlider( long i, long max ) { | 294 | void AudioWidget::updateSlider( long i, long max ) { |
295 | time.setText( timeAsString( i ) + " / " + timeAsString( max ) ); | ||
187 | if ( max == 0 ) { | 296 | if ( max == 0 ) { |
188 | return; | 297 | return; |
189 | } | 298 | } |
190 | // Will flicker too much if we don't do this | 299 | // Will flicker too much if we don't do this |
191 | // Scale to something reasonable | 300 | // Scale to something reasonable |
192 | int width = slider->width(); | 301 | int width = slider->width(); |
@@ -215,61 +324,60 @@ void AudioWidget::toggleButton( int i ) { | |||
215 | QPainter p(this); | 324 | QPainter p(this); |
216 | paintButton ( &p, i ); | 325 | paintButton ( &p, i ); |
217 | } | 326 | } |
218 | 327 | ||
219 | 328 | ||
220 | void AudioWidget::paintButton( QPainter *p, int i ) { | 329 | void AudioWidget::paintButton( QPainter *p, int i ) { |
221 | int x = audioButtons[i].xPos; | 330 | if ( audioButtons[i].isDown ) |
222 | int y = audioButtons[i].yPos; | 331 | p->drawPixmap( xoff, yoff, *buttonPixDown[i] ); |
223 | int offset = 22 + 14 * audioButtons[i].isBig + audioButtons[i].isDown; | 332 | else |
224 | int buttonSize = 64 + audioButtons[i].isBig * (90 - 64); | 333 | p->drawPixmap( xoff, yoff, *buttonPixUp[i] ); |
225 | p->drawPixmap( x, y, *pixmaps[audioButtons[i].isBig], buttonSize * (audioButtons[i].isDown + 2 * audioButtons[i].color), 0, buttonSize, buttonSize ); | ||
226 | p->drawPixmap( x + offset, y + offset, *pixmaps[2], 18 * i, 0, 18, 18 ); | ||
227 | } | 334 | } |
228 | 335 | ||
229 | 336 | ||
230 | void AudioWidget::timerEvent( QTimerEvent * ) { | 337 | void AudioWidget::timerEvent( QTimerEvent * ) { |
231 | static int frame = 0; | 338 | // static int frame = 0; |
232 | if ( !mediaPlayerState->paused() && audioButtons[ AudioPlay ].isDown ) { | 339 | // if ( !mediaPlayerState->paused() && audioButtons[ AudioPlay ].isDown ) { |
233 | frame = frame >= 7 ? 0 : frame + 1; | 340 | // frame = frame >= 7 ? 0 : frame + 1; |
234 | } | 341 | // } |
235 | } | 342 | } |
236 | 343 | ||
237 | 344 | ||
238 | void AudioWidget::mouseMoveEvent( QMouseEvent *event ) { | 345 | void AudioWidget::mouseMoveEvent( QMouseEvent *event ) { |
239 | for ( int i = 0; i < numButtons; i++ ) { | 346 | for ( int i = 0; i < numButtons; i++ ) { |
240 | int size = audioButtons[i].isBig; | ||
241 | int x = audioButtons[i].xPos; | ||
242 | int y = audioButtons[i].yPos; | ||
243 | if ( event->state() == QMouseEvent::LeftButton ) { | 347 | if ( event->state() == QMouseEvent::LeftButton ) { |
244 | // The test to see if the mouse click is inside the circular button or not | 348 | |
245 | // (compared with the radius squared to avoid a square-root of our distance) | 349 | // The test to see if the mouse click is inside the button or not |
246 | int radius = 32 + 13 * size; | 350 | int x = event->pos().x() - xoff; |
247 | QPoint center = QPoint( x + radius, y + radius ); | 351 | int y = event->pos().y() - yoff; |
248 | QPoint dXY = center - event->pos(); | 352 | |
249 | int dist = dXY.x() * dXY.x() + dXY.y() * dXY.y(); | 353 | bool isOnButton = ( x > 0 && y > 0 && x < imgButtonMask->width() |
250 | bool isOnButton = dist <= (radius * radius); | 354 | && y < imgButtonMask->height() && imgButtonMask->pixelIndex( x, y ) == i + 1 ); |
355 | |||
356 | if ( isOnButton && i == AudioVolumeUp ) | ||
357 | qDebug("on up"); | ||
358 | |||
251 | if ( isOnButton && !audioButtons[i].isHeld ) { | 359 | if ( isOnButton && !audioButtons[i].isHeld ) { |
252 | audioButtons[i].isHeld = TRUE; | 360 | audioButtons[i].isHeld = TRUE; |
253 | toggleButton(i); | 361 | toggleButton(i); |
254 | qDebug("button toggled1 %d",i); | ||
255 | switch (i) { | 362 | switch (i) { |
256 | case AudioVolumeUp: emit moreClicked(); return; | 363 | case AudioVolumeUp: |
364 | qDebug("more clicked"); | ||
365 | emit moreClicked(); | ||
366 | return; | ||
257 | case AudioVolumeDown: emit lessClicked(); return; | 367 | case AudioVolumeDown: emit lessClicked(); return; |
258 | } | 368 | } |
259 | } else if ( !isOnButton && audioButtons[i].isHeld ) { | 369 | } else if ( !isOnButton && audioButtons[i].isHeld ) { |
260 | audioButtons[i].isHeld = FALSE; | 370 | audioButtons[i].isHeld = FALSE; |
261 | toggleButton(i); | 371 | toggleButton(i); |
262 | qDebug("button toggled2 %d",i); | ||
263 | } | 372 | } |
264 | } else { | 373 | } else { |
265 | if ( audioButtons[i].isHeld ) { | 374 | if ( audioButtons[i].isHeld ) { |
266 | audioButtons[i].isHeld = FALSE; | 375 | audioButtons[i].isHeld = FALSE; |
267 | if ( !audioButtons[i].isToggle ) | 376 | if ( !audioButtons[i].isToggle ) |
268 | setToggleButton( i, FALSE ); | 377 | setToggleButton( i, FALSE ); |
269 | qDebug("button toggled3 %d",i); | ||
270 | switch (i) { | 378 | switch (i) { |
271 | case AudioPlay: mediaPlayerState->setPlaying(audioButtons[i].isDown); return; | 379 | case AudioPlay: mediaPlayerState->setPlaying(audioButtons[i].isDown); return; |
272 | case AudioStop: mediaPlayerState->setPlaying(FALSE); return; | 380 | case AudioStop: mediaPlayerState->setPlaying(FALSE); return; |
273 | case AudioPause: mediaPlayerState->setPaused(audioButtons[i].isDown); return; | 381 | case AudioPause: mediaPlayerState->setPaused(audioButtons[i].isDown); return; |
274 | case AudioNext: mediaPlayerState->setNext(); return; | 382 | case AudioNext: mediaPlayerState->setNext(); return; |
275 | case AudioPrevious: mediaPlayerState->setPrev(); return; | 383 | case AudioPrevious: mediaPlayerState->setPrev(); return; |
@@ -303,15 +411,27 @@ void AudioWidget::showEvent( QShowEvent* ) { | |||
303 | void AudioWidget::closeEvent( QCloseEvent* ) { | 411 | void AudioWidget::closeEvent( QCloseEvent* ) { |
304 | mediaPlayerState->setList(); | 412 | mediaPlayerState->setList(); |
305 | } | 413 | } |
306 | 414 | ||
307 | 415 | ||
308 | void AudioWidget::paintEvent( QPaintEvent * ) { | 416 | void AudioWidget::paintEvent( QPaintEvent * ) { |
309 | QPainter p( this ); | 417 | if ( !pe->erased() ) { |
310 | for ( int i = 0; i < numButtons; i++ ) | 418 | // Combine with background and double buffer |
311 | paintButton( &p, i ); | 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 { | ||
428 | QPainter p( this ); | ||
429 | for ( int i = 0; i < numButtons; i++ ) | ||
430 | paintButton( &p, i ); | ||
431 | } | ||
312 | } | 432 | } |
313 | 433 | ||
314 | void AudioWidget::keyReleaseEvent( QKeyEvent *e) | 434 | void AudioWidget::keyReleaseEvent( QKeyEvent *e) |
315 | { | 435 | { |
316 | switch ( e->key() ) { | 436 | switch ( e->key() ) { |
317 | ////////////////////////////// Zaurus keys | 437 | ////////////////////////////// Zaurus keys |
diff --git a/noncore/multimedia/opieplayer2/audiowidget.h b/noncore/multimedia/opieplayer2/audiowidget.h index ce8604a..3ebec5b 100644 --- a/noncore/multimedia/opieplayer2/audiowidget.h +++ b/noncore/multimedia/opieplayer2/audiowidget.h | |||
@@ -22,13 +22,13 @@ enum AudioButtons { | |||
22 | AudioVolumeDown, | 22 | AudioVolumeDown, |
23 | AudioLoop, | 23 | AudioLoop, |
24 | AudioPlayList | 24 | AudioPlayList |
25 | }; | 25 | }; |
26 | 26 | ||
27 | 27 | ||
28 | #define USE_DBLBUF | 28 | //#define USE_DBLBUF |
29 | 29 | ||
30 | 30 | ||
31 | class Ticker : public QFrame { | 31 | class Ticker : public QFrame { |
32 | Q_OBJECT | 32 | Q_OBJECT |
33 | 33 | ||
34 | public: | 34 | public: |
@@ -72,24 +72,36 @@ signals: | |||
72 | 72 | ||
73 | protected: | 73 | protected: |
74 | void doBlank(); | 74 | void doBlank(); |
75 | void doUnblank(); | 75 | void doUnblank(); |
76 | void paintEvent( QPaintEvent *pe ); | 76 | void paintEvent( QPaintEvent *pe ); |
77 | void showEvent( QShowEvent *se ); | 77 | void showEvent( QShowEvent *se ); |
78 | void resizeEvent( QResizeEvent *re ); | ||
78 | void mouseMoveEvent( QMouseEvent *event ); | 79 | void mouseMoveEvent( QMouseEvent *event ); |
79 | void mousePressEvent( QMouseEvent *event ); | 80 | void mousePressEvent( QMouseEvent *event ); |
80 | void mouseReleaseEvent( QMouseEvent *event ); | 81 | void mouseReleaseEvent( QMouseEvent *event ); |
81 | void timerEvent( QTimerEvent *event ); | 82 | void timerEvent( QTimerEvent *event ); |
82 | void closeEvent( QCloseEvent *event ); | 83 | void closeEvent( QCloseEvent *event ); |
83 | void keyReleaseEvent( QKeyEvent *e); | 84 | void keyReleaseEvent( QKeyEvent *e); |
84 | private: | 85 | private: |
85 | void toggleButton( int ); | 86 | void toggleButton( int ); |
86 | void setToggleButton( int, bool ); | 87 | void setToggleButton( int, bool ); |
87 | void paintButton( QPainter *p, int i ); | 88 | void paintButton( QPainter *p, int i ); |
89 | QString skin; | ||
90 | QPixmap *pixBg; | ||
91 | QImage *imgUp; | ||
92 | QImage *imgDn; | ||
93 | QImage *imgButtonMask; | ||
94 | QBitmap *masks[11]; | ||
95 | QPixmap *buttonPixUp[11]; | ||
96 | QPixmap *buttonPixDown[11]; | ||
97 | |||
88 | QPixmap *pixmaps[4]; | 98 | QPixmap *pixmaps[4]; |
89 | Ticker *songInfo; | 99 | Ticker songInfo; |
90 | QSlider *slider; | 100 | QSlider slider; |
101 | QLineEdit time; | ||
102 | int xoff, yoff; | ||
91 | }; | 103 | }; |
92 | 104 | ||
93 | 105 | ||
94 | #endif // AUDIO_WIDGET_H | 106 | #endif // AUDIO_WIDGET_H |
95 | 107 | ||
diff --git a/noncore/multimedia/opieplayer2/mediaplayer.cpp b/noncore/multimedia/opieplayer2/mediaplayer.cpp index 38ba08f..43e3133 100644 --- a/noncore/multimedia/opieplayer2/mediaplayer.cpp +++ b/noncore/multimedia/opieplayer2/mediaplayer.cpp | |||
@@ -105,33 +105,80 @@ void MediaPlayer::next() { | |||
105 | 105 | ||
106 | 106 | ||
107 | void MediaPlayer::startDecreasingVolume() { | 107 | void MediaPlayer::startDecreasingVolume() { |
108 | volumeDirection = -1; | 108 | volumeDirection = -1; |
109 | startTimer( 100 ); | 109 | startTimer( 100 ); |
110 | // da kommt demnächst osound denk ich mal | 110 | // da kommt demnächst osound denk ich mal |
111 | /////////////////////////// lets just move those change volume here | ||
111 | // AudioDevice::decreaseVolume(); | 112 | // AudioDevice::decreaseVolume(); |
112 | } | 113 | } |
113 | 114 | ||
114 | 115 | ||
115 | void MediaPlayer::startIncreasingVolume() { | 116 | void MediaPlayer::startIncreasingVolume() { |
116 | volumeDirection = +1; | 117 | volumeDirection = +1; |
117 | startTimer( 100 ); | 118 | startTimer( 100 ); |
118 | // AudioDevice::increaseVolume(); | 119 | // AudioDevice::increaseVolume(); |
119 | } | 120 | } |
120 | 121 | ||
121 | 122 | ||
123 | bool drawnOnScreenDisplay = FALSE; | ||
124 | unsigned int onScreenDisplayVolume = 0; | ||
125 | const int yoff = 110; | ||
126 | |||
122 | void MediaPlayer::stopChangingVolume() { | 127 | void MediaPlayer::stopChangingVolume() { |
123 | killTimers(); | 128 | killTimers(); |
129 | // Get rid of the on-screen display stuff | ||
130 | drawnOnScreenDisplay = FALSE; | ||
131 | onScreenDisplayVolume = 0; | ||
132 | int w = audioUI->width(); | ||
133 | int h = audioUI->height(); | ||
134 | audioUI->repaint( (w - 200) / 2, h - yoff, 200 + 9, 70, FALSE ); | ||
124 | } | 135 | } |
125 | 136 | ||
126 | 137 | ||
127 | void MediaPlayer::timerEvent( QTimerEvent * ) { | 138 | void MediaPlayer::timerEvent( QTimerEvent * ) { |
128 | // if ( volumeDirection == +1 ) | 139 | // if ( volumeDirection == +1 ) |
129 | // AudioDevice::increaseVolume(); | 140 | // AudioDevice::increaseVolume(); |
130 | // else if ( volumeDirection == -1 ) | 141 | // else if ( volumeDirection == -1 ) |
131 | // AudioDevice::decreaseVolume(); | 142 | // AudioDevice::decreaseVolume(); |
143 | |||
144 | // Display an on-screen display volume | ||
145 | unsigned int l, r, v; bool m; | ||
146 | AudioDevice::getVolume( l, r, m ); | ||
147 | v = ((l + r) * 11) / (2*0xFFFF); | ||
148 | |||
149 | if ( drawnOnScreenDisplay && onScreenDisplayVolume == v ) | ||
150 | return; | ||
151 | |||
152 | int w = audioUI->width(); | ||
153 | int h = audioUI->height(); | ||
154 | |||
155 | if ( drawnOnScreenDisplay ) { | ||
156 | if ( onScreenDisplayVolume > v ) | ||
157 | audioUI->repaint( (w - 200) / 2 + v * 20 + 0, h - yoff + 40, (onScreenDisplayVolume - v) * 20 + 9, 30, FALSE ); | ||
158 | } | ||
159 | |||
160 | drawnOnScreenDisplay = TRUE; | ||
161 | onScreenDisplayVolume = v; | ||
162 | |||
163 | QPainter p( audioUI ); | ||
164 | p.setPen( QColor( 0x10, 0xD0, 0x10 ) ); | ||
165 | p.setBrush( QColor( 0x10, 0xD0, 0x10 ) ); | ||
166 | |||
167 | QFont f; | ||
168 | f.setPixelSize( 20 ); | ||
169 | f.setBold( TRUE ); | ||
170 | p.setFont( f ); | ||
171 | p.drawText( (w - 200) / 2, h - yoff + 20, tr("Volume") ); | ||
172 | |||
173 | for ( unsigned int i = 0; i < 10; i++ ) { | ||
174 | if ( v > i ) | ||
175 | p.drawRect( (w - 200) / 2 + i * 20 + 0, h - yoff + 40, 9, 30 ); | ||
176 | else | ||
177 | p.drawRect( (w - 200) / 2 + i * 20 + 3, h - yoff + 50, 3, 10 ); | ||
178 | } | ||
132 | } | 179 | } |
133 | 180 | ||
134 | void MediaPlayer::keyReleaseEvent( QKeyEvent *e) { | 181 | void MediaPlayer::keyReleaseEvent( QKeyEvent *e) { |
135 | switch ( e->key() ) { | 182 | switch ( e->key() ) { |
136 | ////////////////////////////// Zaurus keys | 183 | ////////////////////////////// Zaurus keys |
137 | case Key_Home: | 184 | case Key_Home: |