Diffstat (limited to 'core/multimedia/opieplayer/audiowidget.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | core/multimedia/opieplayer/audiowidget.cpp | 32 |
1 files changed, 23 insertions, 9 deletions
diff --git a/core/multimedia/opieplayer/audiowidget.cpp b/core/multimedia/opieplayer/audiowidget.cpp index e2e3603..94b979f 100644 --- a/core/multimedia/opieplayer/audiowidget.cpp +++ b/core/multimedia/opieplayer/audiowidget.cpp | |||
@@ -4,178 +4,188 @@ | |||
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> | 20 | #include <qpe/qpeapplication.h> |
21 | #include <qpe/resource.h> | 21 | #include <qpe/resource.h> |
22 | 22 | ||
23 | #include <qwidget.h> | 23 | #include <qwidget.h> |
24 | #include <qpixmap.h> | 24 | #include <qpixmap.h> |
25 | #include <qbutton.h> | 25 | #include <qbutton.h> |
26 | #include <qpainter.h> | 26 | #include <qpainter.h> |
27 | #include <qframe.h> | 27 | #include <qframe.h> |
28 | #include <qlayout.h> | ||
28 | 29 | ||
29 | #include "audiowidget.h" | 30 | #include "audiowidget.h" |
30 | #include "mediaplayerstate.h" | 31 | #include "mediaplayerstate.h" |
31 | 32 | ||
32 | extern MediaPlayerState *mediaPlayerState; | 33 | extern MediaPlayerState *mediaPlayerState; |
33 | 34 | ||
34 | 35 | ||
35 | static const int xo = -2; // movable x offset | 36 | static const int xo = -2; // movable x offset |
36 | static const int yo = 22; // movable y offset | 37 | static const int yo = 22; // movable y offset |
37 | 38 | ||
38 | 39 | ||
39 | struct MediaButton { | 40 | struct MediaButton { |
40 | int xPos, yPos; | 41 | int xPos, yPos; |
41 | int color; | 42 | int color; |
42 | bool isToggle, isBig, isHeld, isDown; | 43 | bool isToggle, isBig, isHeld, isDown; |
43 | }; | 44 | }; |
44 | 45 | ||
45 | 46 | ||
46 | // Layout information for the audioButtons (and if it is a toggle button or not) | 47 | // Layout information for the audioButtons (and if it is a toggle button or not) |
47 | MediaButton audioButtons[] = { | 48 | MediaButton audioButtons[] = { |
48 | { 3*30-15+xo, 3*30-13+yo, 0, TRUE, TRUE, FALSE, FALSE }, // play | 49 | { 3*30-15+xo, 3*30-13+yo, 0, TRUE, TRUE, FALSE, FALSE }, // play |
49 | { 1*30+xo, 5*30+yo, 2, FALSE, FALSE, FALSE, FALSE }, // stop | 50 | { 1*30+xo, 5*30+yo, 2, FALSE, FALSE, FALSE, FALSE }, // stop |
50 | { 5*30+xo, 5*30+yo, 2, TRUE, FALSE, FALSE, FALSE }, // pause | 51 | { 5*30+xo, 5*30+yo, 2, TRUE, FALSE, FALSE, FALSE }, // pause |
51 | { 6*30-5+xo, 3*30+yo, 1, FALSE, FALSE, FALSE, FALSE }, // next | 52 | { 6*30-5+xo, 3*30+yo, 1, FALSE, FALSE, FALSE, FALSE }, // next |
52 | { 0*30+5+xo, 3*30+yo, 1, FALSE, FALSE, FALSE, FALSE }, // previous | 53 | { 0*30+5+xo, 3*30+yo, 1, FALSE, FALSE, FALSE, FALSE }, // previous |
53 | { 3*30+xo, 0*30+5+yo, 3, FALSE, FALSE, FALSE, FALSE }, // volume up | 54 | { 3*30+xo, 0*30+5+yo, 3, FALSE, FALSE, FALSE, FALSE }, // volume up |
54 | { 3*30+xo, 6*30-5+yo, 3, FALSE, FALSE, FALSE, FALSE }, // volume down | 55 | { 3*30+xo, 6*30-5+yo, 3, FALSE, FALSE, FALSE, FALSE }, // volume down |
55 | { 5*30+xo, 1*30+yo, 0, TRUE, FALSE, FALSE, FALSE }, // repeat/loop | 56 | { 5*30+xo, 1*30+yo, 0, TRUE, FALSE, FALSE, FALSE }, // repeat/loop |
56 | { 1*30+xo, 1*30+yo, 0, FALSE, FALSE, FALSE, FALSE } // playlist | 57 | { 1*30+xo, 1*30+yo, 0, FALSE, FALSE, FALSE, FALSE } // playlist |
57 | }; | 58 | }; |
58 | 59 | ||
59 | 60 | ||
60 | static const int numButtons = (sizeof(audioButtons)/sizeof(MediaButton)); | 61 | static const int numButtons = (sizeof(audioButtons)/sizeof(MediaButton)); |
61 | 62 | ||
62 | 63 | ||
63 | AudioWidget::AudioWidget(QWidget* parent, const char* name, WFlags f) : | 64 | AudioWidget::AudioWidget(QWidget* parent, const char* name, WFlags f) : |
64 | QWidget( parent, name, f ) | 65 | QWidget( parent, name, f ) |
65 | { | 66 | { |
66 | // QPEApplication::grabKeyboard(); | ||
67 | setCaption( tr("OpiePlayer") ); | 67 | setCaption( tr("OpiePlayer") ); |
68 | |||
69 | // QGridLayout *layout = new QGridLayout( this ); | ||
70 | // layout->setSpacing( 2); | ||
71 | // layout->setMargin( 2); | ||
72 | |||
68 | setBackgroundPixmap( Resource::loadPixmap( "opieplayer/metalFinish" ) ); | 73 | setBackgroundPixmap( Resource::loadPixmap( "opieplayer/metalFinish" ) ); |
69 | pixmaps[0] = new QPixmap( Resource::loadPixmap( "opieplayer/mediaButtonsAll" ) ); | 74 | pixmaps[0] = new QPixmap( Resource::loadPixmap( "opieplayer/mediaButtonsAll" ) ); |
70 | pixmaps[1] = new QPixmap( Resource::loadPixmap( "opieplayer/mediaButtonsBig" ) ); | 75 | pixmaps[1] = new QPixmap( Resource::loadPixmap( "opieplayer/mediaButtonsBig" ) ); |
71 | pixmaps[2] = new QPixmap( Resource::loadPixmap( "opieplayer/mediaControls" ) ); | 76 | pixmaps[2] = new QPixmap( Resource::loadPixmap( "opieplayer/mediaControls" ) ); |
72 | pixmaps[3] = new QPixmap( Resource::loadPixmap( "opieplayer/animatedButton" ) ); | 77 | pixmaps[3] = new QPixmap( Resource::loadPixmap( "opieplayer/animatedButton" ) ); |
73 | 78 | ||
74 | songInfo = new Ticker( this ); | 79 | songInfo = new Ticker( this ); |
75 | songInfo->setFocusPolicy( QWidget::NoFocus ); | 80 | songInfo->setFocusPolicy( QWidget::NoFocus ); |
76 | songInfo->setGeometry( QRect( 7, 3, 220, 20 ) ); | 81 | songInfo->setGeometry( QRect( 7, 3, 220, 20 ) ); |
77 | 82 | // layout->addMultiCellWidget( songInfo, 0, 0, 0, 2 ); | |
83 | |||
78 | slider = new QSlider( Qt::Horizontal, this ); | 84 | slider = new QSlider( Qt::Horizontal, this ); |
79 | slider->setFixedWidth( 220 ); | 85 | slider->setFixedWidth( 220 ); |
80 | slider->setFixedHeight( 20 ); | 86 | slider->setFixedHeight( 20 ); |
81 | slider->setMinValue( 0 ); | 87 | slider->setMinValue( 0 ); |
82 | slider->setMaxValue( 1 ); | 88 | slider->setMaxValue( 1 ); |
83 | slider->setBackgroundPixmap( Resource::loadPixmap( "opieplayer/metalFinish" ) ); | 89 | slider->setBackgroundPixmap( Resource::loadPixmap( "opieplayer/metalFinish" ) ); |
84 | slider->setFocusPolicy( QWidget::NoFocus ); | 90 | slider->setFocusPolicy( QWidget::NoFocus ); |
85 | slider->setGeometry( QRect( 7, 262, 220, 20 ) ); | 91 | slider->setGeometry( QRect( 7, 262, 220, 20 ) ); |
92 | // layout->addMultiCellWidget( slider, 4, 4, 0, 2 ); | ||
86 | 93 | ||
87 | connect( slider, SIGNAL( sliderPressed() ), this, SLOT( sliderPressed() ) ); | 94 | connect( slider, SIGNAL( sliderPressed() ), this, SLOT( sliderPressed() ) ); |
88 | connect( slider, SIGNAL( sliderReleased() ), this, SLOT( sliderReleased() ) ); | 95 | connect( slider, SIGNAL( sliderReleased() ), this, SLOT( sliderReleased() ) ); |
89 | 96 | ||
90 | connect( mediaPlayerState, SIGNAL( lengthChanged(long) ), this, SLOT( setLength(long) ) ); | 97 | connect( mediaPlayerState, SIGNAL( lengthChanged(long) ), this, SLOT( setLength(long) ) ); |
91 | connect( mediaPlayerState, SIGNAL( viewChanged(char) ), this, SLOT( setView(char) ) ); | 98 | connect( mediaPlayerState, SIGNAL( viewChanged(char) ), this, SLOT( setView(char) ) ); |
92 | connect( mediaPlayerState, SIGNAL( loopingToggled(bool) ), this, SLOT( setLooping(bool) ) ); | 99 | connect( mediaPlayerState, SIGNAL( loopingToggled(bool) ), this, SLOT( setLooping(bool) ) ); |
93 | connect( mediaPlayerState, SIGNAL( pausedToggled(bool) ), this, SLOT( setPaused(bool) ) ); | 100 | connect( mediaPlayerState, SIGNAL( pausedToggled(bool) ), this, SLOT( setPaused(bool) ) ); |
94 | connect( mediaPlayerState, SIGNAL( playingToggled(bool) ), this, SLOT( setPlaying(bool) ) ); | 101 | connect( mediaPlayerState, SIGNAL( playingToggled(bool) ), this, SLOT( setPlaying(bool) ) ); |
95 | 102 | ||
96 | // Intialise state | 103 | // Intialise state |
97 | setLength( mediaPlayerState->length() ); | 104 | setLength( mediaPlayerState->length() ); |
98 | setPosition( mediaPlayerState->position() ); | 105 | setPosition( mediaPlayerState->position() ); |
99 | setLooping( mediaPlayerState->fullscreen() ); | 106 | setLooping( mediaPlayerState->fullscreen() ); |
100 | setPaused( mediaPlayerState->paused() ); | 107 | setPaused( mediaPlayerState->paused() ); |
101 | setPlaying( mediaPlayerState->playing() ); | 108 | setPlaying( mediaPlayerState->playing() ); |
102 | 109 | ||
103 | } | 110 | } |
104 | 111 | ||
105 | 112 | ||
106 | AudioWidget::~AudioWidget() { | 113 | AudioWidget::~AudioWidget() { |
114 | mediaPlayerState->isStreaming = FALSE; | ||
107 | for ( int i = 0; i < 4; i++ ) | 115 | for ( int i = 0; i < 4; i++ ) |
108 | delete pixmaps[i]; | 116 | delete pixmaps[i]; |
109 | } | 117 | } |
110 | 118 | ||
111 | 119 | ||
112 | static bool audioSliderBeingMoved = FALSE; | 120 | static bool audioSliderBeingMoved = FALSE; |
113 | 121 | ||
114 | 122 | ||
115 | void AudioWidget::sliderPressed() { | 123 | void AudioWidget::sliderPressed() { |
116 | audioSliderBeingMoved = TRUE; | 124 | audioSliderBeingMoved = TRUE; |
117 | } | 125 | } |
118 | 126 | ||
119 | 127 | ||
120 | void AudioWidget::sliderReleased() { | 128 | void AudioWidget::sliderReleased() { |
121 | audioSliderBeingMoved = FALSE; | 129 | audioSliderBeingMoved = FALSE; |
122 | if ( slider->width() == 0 ) | 130 | if ( slider->width() == 0 ) |
123 | return; | 131 | return; |
124 | long val = long((double)slider->value() * mediaPlayerState->length() / slider->width()); | 132 | long val = long((double)slider->value() * mediaPlayerState->length() / slider->width()); |
125 | mediaPlayerState->setPosition( val ); | 133 | mediaPlayerState->setPosition( val ); |
126 | } | 134 | } |
127 | 135 | ||
128 | 136 | ||
129 | void AudioWidget::setPosition( long i ) { | 137 | void AudioWidget::setPosition( long i ) { |
130 | updateSlider( i, mediaPlayerState->length() ); | 138 | updateSlider( i, mediaPlayerState->length() ); |
131 | } | 139 | } |
132 | 140 | ||
133 | 141 | ||
134 | void AudioWidget::setLength( long max ) { | 142 | void AudioWidget::setLength( long max ) { |
135 | updateSlider( mediaPlayerState->position(), max ); | 143 | updateSlider( mediaPlayerState->position(), max ); |
136 | } | 144 | } |
137 | 145 | ||
138 | 146 | ||
139 | void AudioWidget::setView( char view ) { | 147 | void AudioWidget::setView( char view ) { |
148 | |||
140 | if (mediaPlayerState->isStreaming) { | 149 | if (mediaPlayerState->isStreaming) { |
141 | if( !slider->isHidden()) slider->hide(); | 150 | if( !slider->isHidden()) slider->hide(); |
142 | disconnect( mediaPlayerState, SIGNAL( positionChanged(long) ),this, SLOT( setPosition(long) ) ); | 151 | disconnect( mediaPlayerState, SIGNAL( positionChanged(long) ),this, SLOT( setPosition(long) ) ); |
143 | disconnect( mediaPlayerState, SIGNAL( positionUpdated(long) ),this, SLOT( setPosition(long) ) ); | 152 | disconnect( mediaPlayerState, SIGNAL( positionUpdated(long) ),this, SLOT( setPosition(long) ) ); |
144 | } else { | 153 | } else { |
145 | // this stops the slider from being moved, thus | 154 | // this stops the slider from being moved, thus |
146 | // does not stop stream when it reaches the end | 155 | // does not stop stream when it reaches the end |
147 | if( slider->isHidden()) slider->show(); | 156 | slider->show(); |
148 | connect( mediaPlayerState, SIGNAL( positionChanged(long) ),this, SLOT( setPosition(long) ) ); | 157 | connect( mediaPlayerState, SIGNAL( positionChanged(long) ),this, SLOT( setPosition(long) ) ); |
149 | connect( mediaPlayerState, SIGNAL( positionUpdated(long) ),this, SLOT( setPosition(long) ) ); | 158 | connect( mediaPlayerState, SIGNAL( positionUpdated(long) ),this, SLOT( setPosition(long) ) ); |
150 | } | 159 | } |
151 | 160 | ||
152 | if ( view == 'a' ) { | 161 | if ( view == 'a' ) { |
153 | startTimer( 150 ); | 162 | startTimer( 150 ); |
154 | showMaximized(); | 163 | // show(); |
164 | showMaximized(); | ||
155 | } else { | 165 | } else { |
156 | killTimers(); | 166 | killTimers(); |
157 | hide(); | 167 | hide(); |
158 | } | 168 | } |
159 | } | 169 | } |
160 | 170 | ||
161 | 171 | ||
162 | void AudioWidget::updateSlider( long i, long max ) { | 172 | void AudioWidget::updateSlider( long i, long max ) { |
163 | if ( max == 0 ) | 173 | if ( max == 0 ) |
164 | return; | 174 | return; |
165 | // Will flicker too much if we don't do this | 175 | // Will flicker too much if we don't do this |
166 | // Scale to something reasonable | 176 | // Scale to something reasonable |
167 | int width = slider->width(); | 177 | int width = slider->width(); |
168 | int val = int((double)i * width / max); | 178 | int val = int((double)i * width / max); |
169 | if ( !audioSliderBeingMoved ) { | 179 | if ( !audioSliderBeingMoved ) { |
170 | if ( slider->value() != val ) | 180 | if ( slider->value() != val ) |
171 | slider->setValue( val ); | 181 | slider->setValue( val ); |
172 | if ( slider->maxValue() != width ) | 182 | if ( slider->maxValue() != width ) |
173 | slider->setMaxValue( width ); | 183 | slider->setMaxValue( width ); |
174 | } | 184 | } |
175 | } | 185 | } |
176 | 186 | ||
177 | 187 | ||
178 | void AudioWidget::setToggleButton( int i, bool down ) { | 188 | void AudioWidget::setToggleButton( int i, bool down ) { |
179 | if ( down != audioButtons[i].isDown ) | 189 | if ( down != audioButtons[i].isDown ) |
180 | toggleButton( i ); | 190 | toggleButton( i ); |
181 | } | 191 | } |
@@ -269,56 +279,60 @@ void AudioWidget::mousePressEvent( QMouseEvent *event ) { | |||
269 | 279 | ||
270 | 280 | ||
271 | void AudioWidget::mouseReleaseEvent( QMouseEvent *event ) { | 281 | void AudioWidget::mouseReleaseEvent( QMouseEvent *event ) { |
272 | mouseMoveEvent( event ); | 282 | mouseMoveEvent( event ); |
273 | } | 283 | } |
274 | 284 | ||
275 | 285 | ||
276 | void AudioWidget::showEvent( QShowEvent* ) { | 286 | void AudioWidget::showEvent( QShowEvent* ) { |
277 | QMouseEvent event( QEvent::MouseMove, QPoint( 0, 0 ), 0, 0 ); | 287 | QMouseEvent event( QEvent::MouseMove, QPoint( 0, 0 ), 0, 0 ); |
278 | mouseMoveEvent( &event ); | 288 | mouseMoveEvent( &event ); |
279 | } | 289 | } |
280 | 290 | ||
281 | 291 | ||
282 | void AudioWidget::closeEvent( QCloseEvent* ) { | 292 | void AudioWidget::closeEvent( QCloseEvent* ) { |
283 | mediaPlayerState->setList(); | 293 | mediaPlayerState->setList(); |
284 | } | 294 | } |
285 | 295 | ||
286 | 296 | ||
287 | void AudioWidget::paintEvent( QPaintEvent * ) { | 297 | void AudioWidget::paintEvent( QPaintEvent * ) { |
288 | QPainter p( this ); | 298 | QPainter p( this ); |
289 | for ( int i = 0; i < numButtons; i++ ) | 299 | for ( int i = 0; i < numButtons; i++ ) |
290 | paintButton( &p, i ); | 300 | paintButton( &p, i ); |
291 | } | 301 | } |
292 | 302 | ||
293 | 303 | void AudioWidget::showMe() { | |
304 | show(); | ||
305 | } | ||
294 | void AudioWidget::keyReleaseEvent( QKeyEvent *e) | 306 | void AudioWidget::keyReleaseEvent( QKeyEvent *e) |
295 | { | 307 | { |
296 | switch ( e->key() ) { | 308 | switch ( e->key() ) { |
297 | ////////////////////////////// Zaurus keys | 309 | ////////////////////////////// Zaurus keys |
298 | case Key_Home: | 310 | case Key_Home: |
299 | break; | 311 | break; |
300 | case Key_F9: //activity | 312 | case Key_F9: //activity |
313 | hide(); | ||
314 | // qDebug("Audio F9"); | ||
301 | break; | 315 | break; |
302 | case Key_F10: //contacts | 316 | case Key_F10: //contacts |
303 | break; | 317 | break; |
304 | case Key_F11: //menu | 318 | case Key_F11: //menu |
305 | break; | 319 | break; |
306 | case Key_F12: //home | 320 | case Key_F12: //home |
307 | break; | 321 | break; |
308 | case Key_F13: //mail | 322 | case Key_F13: //mail |
309 | break; | 323 | break; |
310 | case Key_Space: { | 324 | case Key_Space: { |
311 | if(mediaPlayerState->playing()) { | 325 | if(mediaPlayerState->playing()) { |
312 | // toggleButton(1); | 326 | // toggleButton(1); |
313 | mediaPlayerState->setPlaying(FALSE); | 327 | mediaPlayerState->setPlaying(FALSE); |
314 | // toggleButton(1); | 328 | // toggleButton(1); |
315 | } else { | 329 | } else { |
316 | // toggleButton(0); | 330 | // toggleButton(0); |
317 | mediaPlayerState->setPlaying(TRUE); | 331 | mediaPlayerState->setPlaying(TRUE); |
318 | // toggleButton(0); | 332 | // toggleButton(0); |
319 | } | 333 | } |
320 | } | 334 | } |
321 | break; | 335 | break; |
322 | case Key_Down: | 336 | case Key_Down: |
323 | toggleButton(6); | 337 | toggleButton(6); |
324 | emit lessClicked(); | 338 | emit lessClicked(); |