summaryrefslogtreecommitdiff
path: root/core/multimedia/opieplayer/audiowidget.cpp
Unidiff
Diffstat (limited to 'core/multimedia/opieplayer/audiowidget.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--core/multimedia/opieplayer/audiowidget.cpp142
1 files changed, 101 insertions, 41 deletions
diff --git a/core/multimedia/opieplayer/audiowidget.cpp b/core/multimedia/opieplayer/audiowidget.cpp
index 582660c..3901446 100644
--- a/core/multimedia/opieplayer/audiowidget.cpp
+++ b/core/multimedia/opieplayer/audiowidget.cpp
@@ -1,86 +1,90 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved. 2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of Qtopia Environment. 4** This file is part of Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20#include <qpe/qpeapplication.h>
21#include <qpe/resource.h>
22
20#include <qwidget.h> 23#include <qwidget.h>
21#include <qpixmap.h> 24#include <qpixmap.h>
22#include <qbutton.h> 25#include <qbutton.h>
23#include <qpainter.h> 26#include <qpainter.h>
24#include <qframe.h> 27#include <qframe.h>
25#include <qpe/resource.h> 28
26#include "audiowidget.h" 29#include "audiowidget.h"
27#include "mediaplayerstate.h" 30#include "mediaplayerstate.h"
28 31
29extern MediaPlayerState *mediaPlayerState; 32extern MediaPlayerState *mediaPlayerState;
30 33
31 34
32static const int xo = -2; // movable x offset 35static const int xo = -2; // movable x offset
33static const int yo = 22; // movable y offset 36static const int yo = 22; // movable y offset
34 37
35 38
36struct MediaButton { 39struct MediaButton {
37 int xPos, yPos; 40 int xPos, yPos;
38 int color; 41 int color;
39 bool isToggle, isBig, isHeld, isDown; 42 bool isToggle, isBig, isHeld, isDown;
40}; 43};
41 44
42 45
43// Layout information for the audioButtons (and if it is a toggle button or not) 46// Layout information for the audioButtons (and if it is a toggle button or not)
44MediaButton audioButtons[] = { 47MediaButton audioButtons[] = {
45 { 3*30-15+xo, 3*30-13+yo, 0, TRUE, TRUE, FALSE, FALSE }, // play 48 { 3*30-15+xo, 3*30-13+yo, 0, TRUE, TRUE, FALSE, FALSE }, // play
46 { 1*30+xo, 5*30+yo, 2, FALSE, FALSE, FALSE, FALSE }, // stop 49 { 1*30+xo, 5*30+yo, 2, FALSE, FALSE, FALSE, FALSE }, // stop
47 { 5*30+xo, 5*30+yo, 2, TRUE, FALSE, FALSE, FALSE }, // pause 50 { 5*30+xo, 5*30+yo, 2, TRUE, FALSE, FALSE, FALSE }, // pause
48 { 6*30-5+xo, 3*30+yo, 1, FALSE, FALSE, FALSE, FALSE }, // next 51 { 6*30-5+xo, 3*30+yo, 1, FALSE, FALSE, FALSE, FALSE }, // next
49 { 0*30+5+xo, 3*30+yo, 1, FALSE, FALSE, FALSE, FALSE }, // previous 52 { 0*30+5+xo, 3*30+yo, 1, FALSE, FALSE, FALSE, FALSE }, // previous
50 { 3*30+xo, 0*30+5+yo, 3, FALSE, FALSE, FALSE, FALSE }, // volume up 53 { 3*30+xo, 0*30+5+yo, 3, FALSE, FALSE, FALSE, FALSE }, // volume up
51 { 3*30+xo, 6*30-5+yo, 3, FALSE, FALSE, FALSE, FALSE }, // volume down 54 { 3*30+xo, 6*30-5+yo, 3, FALSE, FALSE, FALSE, FALSE }, // volume down
52 { 5*30+xo, 1*30+yo, 0, TRUE, FALSE, FALSE, FALSE }, // repeat/loop 55 { 5*30+xo, 1*30+yo, 0, TRUE, FALSE, FALSE, FALSE }, // repeat/loop
53 { 1*30+xo, 1*30+yo, 0, FALSE, FALSE, FALSE, FALSE } // playlist 56 { 1*30+xo, 1*30+yo, 0, FALSE, FALSE, FALSE, FALSE } // playlist
54}; 57};
55 58
56 59
57static const int numButtons = (sizeof(audioButtons)/sizeof(MediaButton)); 60static const int numButtons = (sizeof(audioButtons)/sizeof(MediaButton));
58 61
59 62
60AudioWidget::AudioWidget(QWidget* parent, const char* name, WFlags f) : 63AudioWidget::AudioWidget(QWidget* parent, const char* name, WFlags f) :
61 QWidget( parent, name, f ) 64 QWidget( parent, name, f )
62{ 65{
66// QPEApplication::grabKeyboard();
63 setCaption( tr("OpiePlayer") ); 67 setCaption( tr("OpiePlayer") );
64 setBackgroundPixmap( Resource::loadPixmap( "mpegplayer/metalFinish" ) ); 68 setBackgroundPixmap( Resource::loadPixmap( "mpegplayer/metalFinish" ) );
65 pixmaps[0] = new QPixmap( Resource::loadPixmap( "mpegplayer/mediaButtonsAll" ) ); 69 pixmaps[0] = new QPixmap( Resource::loadPixmap( "mpegplayer/mediaButtonsAll" ) );
66 pixmaps[1] = new QPixmap( Resource::loadPixmap( "mpegplayer/mediaButtonsBig" ) ); 70 pixmaps[1] = new QPixmap( Resource::loadPixmap( "mpegplayer/mediaButtonsBig" ) );
67 pixmaps[2] = new QPixmap( Resource::loadPixmap( "mpegplayer/mediaControls" ) ); 71 pixmaps[2] = new QPixmap( Resource::loadPixmap( "mpegplayer/mediaControls" ) );
68 pixmaps[3] = new QPixmap( Resource::loadPixmap( "mpegplayer/animatedButton" ) ); 72 pixmaps[3] = new QPixmap( Resource::loadPixmap( "mpegplayer/animatedButton" ) );
69 73
70 songInfo = new Ticker( this ); 74 songInfo = new Ticker( this );
71 songInfo->setFocusPolicy( QWidget::NoFocus ); 75 songInfo->setFocusPolicy( QWidget::NoFocus );
72 songInfo->setGeometry( QRect( 7, 3, 220, 20 ) ); 76 songInfo->setGeometry( QRect( 7, 3, 220, 20 ) );
73 77
74 slider = new QSlider( Qt::Horizontal, this ); 78 slider = new QSlider( Qt::Horizontal, this );
75 slider->setFixedWidth( 220 ); 79 slider->setFixedWidth( 220 );
76 slider->setFixedHeight( 20 ); 80 slider->setFixedHeight( 20 );
77 slider->setMinValue( 0 ); 81 slider->setMinValue( 0 );
78 slider->setMaxValue( 1 ); 82 slider->setMaxValue( 1 );
79 slider->setBackgroundPixmap( Resource::loadPixmap( "mpegplayer/metalFinish" ) ); 83 slider->setBackgroundPixmap( Resource::loadPixmap( "mpegplayer/metalFinish" ) );
80 slider->setFocusPolicy( QWidget::NoFocus ); 84 slider->setFocusPolicy( QWidget::NoFocus );
81 slider->setGeometry( QRect( 7, 262, 220, 20 ) ); 85 slider->setGeometry( QRect( 7, 262, 220, 20 ) );
82 86
83 connect( slider, SIGNAL( sliderPressed() ), this, SLOT( sliderPressed() ) ); 87 connect( slider, SIGNAL( sliderPressed() ), this, SLOT( sliderPressed() ) );
84 connect( slider, SIGNAL( sliderReleased() ), this, SLOT( sliderReleased() ) ); 88 connect( slider, SIGNAL( sliderReleased() ), this, SLOT( sliderReleased() ) );
85 89
86 connect( mediaPlayerState, SIGNAL( lengthChanged(long) ), this, SLOT( setLength(long) ) ); 90 connect( mediaPlayerState, SIGNAL( lengthChanged(long) ), this, SLOT( setLength(long) ) );
@@ -179,98 +183,154 @@ void AudioWidget::paintButton( QPainter *p, int i ) {
179 int y = audioButtons[i].yPos; 183 int y = audioButtons[i].yPos;
180 int offset = 22 + 14 * audioButtons[i].isBig + audioButtons[i].isDown; 184 int offset = 22 + 14 * audioButtons[i].isBig + audioButtons[i].isDown;
181 int buttonSize = 64 + audioButtons[i].isBig * (90 - 64); 185 int buttonSize = 64 + audioButtons[i].isBig * (90 - 64);
182 p->drawPixmap( x, y, *pixmaps[audioButtons[i].isBig], buttonSize * (audioButtons[i].isDown + 2 * audioButtons[i].color), 0, buttonSize, buttonSize ); 186 p->drawPixmap( x, y, *pixmaps[audioButtons[i].isBig], buttonSize * (audioButtons[i].isDown + 2 * audioButtons[i].color), 0, buttonSize, buttonSize );
183 p->drawPixmap( x + offset, y + offset, *pixmaps[2], 18 * i, 0, 18, 18 ); 187 p->drawPixmap( x + offset, y + offset, *pixmaps[2], 18 * i, 0, 18, 18 );
184} 188}
185 189
186 190
187void AudioWidget::timerEvent( QTimerEvent * ) { 191void AudioWidget::timerEvent( QTimerEvent * ) {
188 static int frame = 0; 192 static int frame = 0;
189 if ( !mediaPlayerState->paused() && audioButtons[ AudioPlay ].isDown ) { 193 if ( !mediaPlayerState->paused() && audioButtons[ AudioPlay ].isDown ) {
190 frame = frame >= 7 ? 0 : frame + 1; 194 frame = frame >= 7 ? 0 : frame + 1;
191 int x = audioButtons[AudioPlay].xPos; 195 int x = audioButtons[AudioPlay].xPos;
192 int y = audioButtons[AudioPlay].yPos; 196 int y = audioButtons[AudioPlay].yPos;
193 QPainter p( this ); 197 QPainter p( this );
194 // Optimize to only draw the little bit of the changing images which is different 198 // Optimize to only draw the little bit of the changing images which is different
195 p.drawPixmap( x + 14, y + 8, *pixmaps[3], 32 * frame, 0, 32, 32 ); 199 p.drawPixmap( x + 14, y + 8, *pixmaps[3], 32 * frame, 0, 32, 32 );
196 p.drawPixmap( x + 37, y + 37, *pixmaps[2], 18 * AudioPlay, 0, 6, 3 ); 200 p.drawPixmap( x + 37, y + 37, *pixmaps[2], 18 * AudioPlay, 0, 6, 3 );
197 } 201 }
198} 202}
199 203
200 204
201void AudioWidget::mouseMoveEvent( QMouseEvent *event ) { 205void AudioWidget::mouseMoveEvent( QMouseEvent *event ) {
202 for ( int i = 0; i < numButtons; i++ ) { 206 for ( int i = 0; i < numButtons; i++ ) {
203 int size = audioButtons[i].isBig; 207 int size = audioButtons[i].isBig;
204 int x = audioButtons[i].xPos; 208 int x = audioButtons[i].xPos;
205 int y = audioButtons[i].yPos; 209 int y = audioButtons[i].yPos;
206 if ( event->state() == QMouseEvent::LeftButton ) { 210 if ( event->state() == QMouseEvent::LeftButton ) {
207 // The test to see if the mouse click is inside the circular button or not 211 // The test to see if the mouse click is inside the circular button or not
208 // (compared with the radius squared to avoid a square-root of our distance) 212 // (compared with the radius squared to avoid a square-root of our distance)
209 int radius = 32 + 13 * size; 213 int radius = 32 + 13 * size;
210 QPoint center = QPoint( x + radius, y + radius ); 214 QPoint center = QPoint( x + radius, y + radius );
211 QPoint dXY = center - event->pos(); 215 QPoint dXY = center - event->pos();
212 int dist = dXY.x() * dXY.x() + dXY.y() * dXY.y(); 216 int dist = dXY.x() * dXY.x() + dXY.y() * dXY.y();
213 bool isOnButton = dist <= (radius * radius); 217 bool isOnButton = dist <= (radius * radius);
214// QRect r( x, y, 64 + 22*size, 64 + 22*size ); 218// QRect r( x, y, 64 + 22*size, 64 + 22*size );
215// bool isOnButton = r.contains( event->pos() ); // Rectangular Button code 219// bool isOnButton = r.contains( event->pos() ); // Rectangular Button code
216 if ( isOnButton && !audioButtons[i].isHeld ) { 220 if ( isOnButton && !audioButtons[i].isHeld ) {
217 audioButtons[i].isHeld = TRUE; 221 audioButtons[i].isHeld = TRUE;
218 toggleButton(i); 222 toggleButton(i);
219 switch (i) { 223 qDebug("button toggled %d",i);
220 case AudioVolumeUp: emit moreClicked(); return; 224 switch (i) {
221 case AudioVolumeDown: emit lessClicked(); return; 225 case AudioVolumeUp: emit moreClicked(); return;
222 } 226 case AudioVolumeDown: emit lessClicked(); return;
223 } else if ( !isOnButton && audioButtons[i].isHeld ) { 227 }
224 audioButtons[i].isHeld = FALSE; 228 } else if ( !isOnButton && audioButtons[i].isHeld ) {
225 toggleButton(i); 229 audioButtons[i].isHeld = FALSE;
226 } 230 toggleButton(i);
227 } else { 231 }
228 if ( audioButtons[i].isHeld ) { 232 } else {
229 audioButtons[i].isHeld = FALSE; 233 if ( audioButtons[i].isHeld ) {
230 if ( !audioButtons[i].isToggle ) 234 audioButtons[i].isHeld = FALSE;
231 setToggleButton( i, FALSE ); 235 if ( !audioButtons[i].isToggle )
232 switch (i) { 236 setToggleButton( i, FALSE );
233 case AudioPlay: mediaPlayerState->setPlaying(audioButtons[i].isDown); return; 237 switch (i) {
234 case AudioStop: mediaPlayerState->setPlaying(FALSE); return; 238 case AudioPlay: mediaPlayerState->setPlaying(audioButtons[i].isDown); return;
235 case AudioPause: mediaPlayerState->setPaused(audioButtons[i].isDown); return; 239 case AudioStop: mediaPlayerState->setPlaying(FALSE); return;
236 case AudioNext: mediaPlayerState->setNext(); return; 240 case AudioPause: mediaPlayerState->setPaused(audioButtons[i].isDown); return;
237 case AudioPrevious: mediaPlayerState->setPrev(); return; 241 case AudioNext: mediaPlayerState->setNext(); return;
238 case AudioLoop: mediaPlayerState->setLooping(audioButtons[i].isDown); return; 242 case AudioPrevious: mediaPlayerState->setPrev(); return;
239 case AudioVolumeUp: emit moreReleased(); return; 243 case AudioLoop: mediaPlayerState->setLooping(audioButtons[i].isDown); return;
240 case AudioVolumeDown: emit lessReleased(); return; 244 case AudioVolumeUp: emit moreReleased(); return;
241 case AudioPlayList: mediaPlayerState->setList(); return; 245 case AudioVolumeDown: emit lessReleased(); return;
242 } 246 case AudioPlayList: mediaPlayerState->setList(); return;
243 } 247 }
244 } 248 }
249 }
245 } 250 }
246} 251}
247 252
248 253
249void AudioWidget::mousePressEvent( QMouseEvent *event ) { 254void AudioWidget::mousePressEvent( QMouseEvent *event ) {
250 mouseMoveEvent( event ); 255 mouseMoveEvent( event );
251} 256}
252 257
253 258
254void AudioWidget::mouseReleaseEvent( QMouseEvent *event ) { 259void AudioWidget::mouseReleaseEvent( QMouseEvent *event ) {
255 mouseMoveEvent( event ); 260 mouseMoveEvent( event );
256} 261}
257 262
258 263
259void AudioWidget::showEvent( QShowEvent* ) { 264void AudioWidget::showEvent( QShowEvent* ) {
260 QMouseEvent event( QEvent::MouseMove, QPoint( 0, 0 ), 0, 0 ); 265 QMouseEvent event( QEvent::MouseMove, QPoint( 0, 0 ), 0, 0 );
261 mouseMoveEvent( &event ); 266 mouseMoveEvent( &event );
262} 267}
263 268
264 269
265void AudioWidget::closeEvent( QCloseEvent* ) { 270void AudioWidget::closeEvent( QCloseEvent* ) {
266 mediaPlayerState->setList(); 271 mediaPlayerState->setList();
267} 272}
268 273
269 274
270void AudioWidget::paintEvent( QPaintEvent * ) { 275void AudioWidget::paintEvent( QPaintEvent * ) {
271 QPainter p( this ); 276 QPainter p( this );
272 for ( int i = 0; i < numButtons; i++ ) 277 for ( int i = 0; i < numButtons; i++ )
273 paintButton( &p, i ); 278 paintButton( &p, i );
274} 279}
275 280
276 281
282void AudioWidget::keyReleaseEvent( QKeyEvent *e)
283{
284 switch ( e->key() ) {
285////////////////////////////// Zaurus keys
286 case Key_Home:
287 break;
288 case Key_F9: //activity
289 break;
290 case Key_F10: //contacts
291 break;
292 case Key_F11: //menu
293 break;
294 case Key_F12: //home
295 break;
296 case Key_F13: //mail
297 break;
298 case Key_Space: {
299 if(mediaPlayerState->playing()) {
300// toggleButton(1);
301 mediaPlayerState->setPlaying(FALSE);
302// toggleButton(1);
303 } else {
304// toggleButton(0);
305 mediaPlayerState->setPlaying(TRUE);
306// toggleButton(0);
307 }
308 }
309 break;
310 case Key_Down:
311 toggleButton(6);
312 emit lessClicked();
313 emit lessReleased();
314 toggleButton(6);
315 break;
316 case Key_Up:
317 toggleButton(5);
318 emit moreClicked();
319 emit moreReleased();
320 toggleButton(5);
321 break;
322 case Key_Right:
323// toggleButton(3);
324 mediaPlayerState->setNext();
325// toggleButton(3);
326 break;
327 case Key_Left:
328// toggleButton(4);
329 mediaPlayerState->setPrev();
330// toggleButton(4);
331 break;
332 case Key_Escape:
333 break;
334
335 };
336}