author | llornkcor <llornkcor> | 2002-02-25 01:35:47 (UTC) |
---|---|---|
committer | llornkcor <llornkcor> | 2002-02-25 01:35:47 (UTC) |
commit | f180c1a5e8fc889ff1fb390d5cc94cdbc5085046 (patch) (unidiff) | |
tree | 5e9ea6f1313f4c33d57fb266523c1cfbe0826756 /core/multimedia/opieplayer/audiowidget.cpp | |
parent | c0446b55fc32b7fdea9f58db06e40da703f5e8ff (diff) | |
download | opie-f180c1a5e8fc889ff1fb390d5cc94cdbc5085046.zip opie-f180c1a5e8fc889ff1fb390d5cc94cdbc5085046.tar.gz opie-f180c1a5e8fc889ff1fb390d5cc94cdbc5085046.tar.bz2 |
fucked up- no workie.. back out
Diffstat (limited to 'core/multimedia/opieplayer/audiowidget.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | core/multimedia/opieplayer/audiowidget.cpp | 127 |
1 files changed, 63 insertions, 64 deletions
diff --git a/core/multimedia/opieplayer/audiowidget.cpp b/core/multimedia/opieplayer/audiowidget.cpp index 0d88591..1e0757f 100644 --- a/core/multimedia/opieplayer/audiowidget.cpp +++ b/core/multimedia/opieplayer/audiowidget.cpp | |||
@@ -1,41 +1,40 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of Qtopia Environment. | 4 | ** This file is part of the 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 <qwidget.h> | 20 | #include <qwidget.h> |
21 | #include <qpixmap.h> | 21 | #include <qpixmap.h> |
22 | #include <qbutton.h> | 22 | #include <qbutton.h> |
23 | #include <qpainter.h> | 23 | #include <qpainter.h> |
24 | #include <qframe.h> | 24 | #include <qframe.h> |
25 | #include <qpe/resource.h> | 25 | #include <qpe/resource.h> |
26 | #include "audiowidget.h" | 26 | #include "audiowidget.h" |
27 | #include "mediaplayerstate.h" | 27 | #include "mediaplayerstate.h" |
28 | 28 | ||
29 | |||
30 | extern MediaPlayerState *mediaPlayerState; | 29 | extern MediaPlayerState *mediaPlayerState; |
31 | 30 | ||
32 | 31 | ||
33 | static const int xo = -2; // movable x offset | 32 | static const int xo = -2; // movable x offset |
34 | static const int yo = 22; // movable y offset | 33 | static const int yo = 22; // movable y offset |
35 | 34 | ||
36 | 35 | ||
37 | struct MediaButton { | 36 | struct MediaButton { |
38 | int xPos, yPos; | 37 | int xPos, yPos; |
39 | int color; | 38 | int color; |
40 | bool isToggle, isBig, isHeld, isDown; | 39 | bool isToggle, isBig, isHeld, isDown; |
41 | }; | 40 | }; |
@@ -52,25 +51,25 @@ MediaButton audioButtons[] = { | |||
52 | { 3*30+xo, 6*30-5+yo, 3, FALSE, FALSE, FALSE, FALSE }, // volume down | 51 | { 3*30+xo, 6*30-5+yo, 3, FALSE, FALSE, FALSE, FALSE }, // volume down |
53 | { 5*30+xo, 1*30+yo, 0, TRUE, FALSE, FALSE, FALSE }, // repeat/loop | 52 | { 5*30+xo, 1*30+yo, 0, TRUE, FALSE, FALSE, FALSE }, // repeat/loop |
54 | { 1*30+xo, 1*30+yo, 0, FALSE, FALSE, FALSE, FALSE } // playlist | 53 | { 1*30+xo, 1*30+yo, 0, FALSE, FALSE, FALSE, FALSE } // playlist |
55 | }; | 54 | }; |
56 | 55 | ||
57 | 56 | ||
58 | static const int numButtons = (sizeof(audioButtons)/sizeof(MediaButton)); | 57 | static const int numButtons = (sizeof(audioButtons)/sizeof(MediaButton)); |
59 | 58 | ||
60 | 59 | ||
61 | AudioWidget::AudioWidget(QWidget* parent, const char* name, WFlags f) : | 60 | AudioWidget::AudioWidget(QWidget* parent, const char* name, WFlags f) : |
62 | QWidget( parent, name, f ) | 61 | QWidget( parent, name, f ) |
63 | { | 62 | { |
64 | setCaption( tr("OpiePlayer") ); | 63 | setCaption( tr("MediaPlayer") ); |
65 | setBackgroundPixmap( Resource::loadPixmap( "mpegplayer/metalFinish" ) ); | 64 | setBackgroundPixmap( Resource::loadPixmap( "mpegplayer/metalFinish" ) ); |
66 | pixmaps[0] = new QPixmap( Resource::loadPixmap( "mpegplayer/mediaButtonsAll" ) ); | 65 | pixmaps[0] = new QPixmap( Resource::loadPixmap( "mpegplayer/mediaButtonsAll" ) ); |
67 | pixmaps[1] = new QPixmap( Resource::loadPixmap( "mpegplayer/mediaButtonsBig" ) ); | 66 | pixmaps[1] = new QPixmap( Resource::loadPixmap( "mpegplayer/mediaButtonsBig" ) ); |
68 | pixmaps[2] = new QPixmap( Resource::loadPixmap( "mpegplayer/mediaControls" ) ); | 67 | pixmaps[2] = new QPixmap( Resource::loadPixmap( "mpegplayer/mediaControls" ) ); |
69 | pixmaps[3] = new QPixmap( Resource::loadPixmap( "mpegplayer/animatedButton" ) ); | 68 | pixmaps[3] = new QPixmap( Resource::loadPixmap( "mpegplayer/animatedButton" ) ); |
70 | 69 | ||
71 | songInfo = new Ticker( this ); | 70 | songInfo = new Ticker( this ); |
72 | songInfo->setFocusPolicy( QWidget::NoFocus ); | 71 | songInfo->setFocusPolicy( QWidget::NoFocus ); |
73 | songInfo->setGeometry( QRect( 7, 3, 220, 20 ) ); | 72 | songInfo->setGeometry( QRect( 7, 3, 220, 20 ) ); |
74 | 73 | ||
75 | slider = new QSlider( Qt::Horizontal, this ); | 74 | slider = new QSlider( Qt::Horizontal, this ); |
76 | slider->setFixedWidth( 220 ); | 75 | slider->setFixedWidth( 220 ); |
@@ -95,163 +94,163 @@ AudioWidget::AudioWidget(QWidget* parent, const char* name, WFlags f) : | |||
95 | // Intialise state | 94 | // Intialise state |
96 | setLength( mediaPlayerState->length() ); | 95 | setLength( mediaPlayerState->length() ); |
97 | setPosition( mediaPlayerState->position() ); | 96 | setPosition( mediaPlayerState->position() ); |
98 | setLooping( mediaPlayerState->fullscreen() ); | 97 | setLooping( mediaPlayerState->fullscreen() ); |
99 | setPaused( mediaPlayerState->paused() ); | 98 | setPaused( mediaPlayerState->paused() ); |
100 | setPlaying( mediaPlayerState->playing() ); | 99 | setPlaying( mediaPlayerState->playing() ); |
101 | 100 | ||
102 | } | 101 | } |
103 | 102 | ||
104 | 103 | ||
105 | AudioWidget::~AudioWidget() { | 104 | AudioWidget::~AudioWidget() { |
106 | for ( int i = 0; i < 4; i++ ) | 105 | for ( int i = 0; i < 4; i++ ) |
107 | delete pixmaps[i]; | 106 | delete pixmaps[i]; |
108 | } | 107 | } |
109 | 108 | ||
110 | 109 | ||
111 | static bool audioSliderBeingMoved = FALSE; | 110 | static bool audioSliderBeingMoved = FALSE; |
112 | 111 | ||
113 | 112 | ||
114 | void AudioWidget::sliderPressed() { | 113 | void AudioWidget::sliderPressed() { |
115 | audioSliderBeingMoved = TRUE; | 114 | audioSliderBeingMoved = TRUE; |
116 | } | 115 | } |
117 | 116 | ||
118 | 117 | ||
119 | void AudioWidget::sliderReleased() { | 118 | void AudioWidget::sliderReleased() { |
120 | audioSliderBeingMoved = FALSE; | 119 | audioSliderBeingMoved = FALSE; |
121 | if ( slider->width() == 0 ) | 120 | if ( slider->width() == 0 ) |
122 | return; | 121 | return; |
123 | long val = long((double)slider->value() * mediaPlayerState->length() / slider->width()); | 122 | long val = long((double)slider->value() * mediaPlayerState->length() / slider->width()); |
124 | mediaPlayerState->setPosition( val ); | 123 | mediaPlayerState->setPosition( val ); |
125 | } | 124 | } |
126 | 125 | ||
127 | 126 | ||
128 | void AudioWidget::setPosition( long i ) { | 127 | void AudioWidget::setPosition( long i ) { |
129 | updateSlider( i, mediaPlayerState->length() ); | 128 | updateSlider( i, mediaPlayerState->length() ); |
130 | } | 129 | } |
131 | 130 | ||
132 | 131 | ||
133 | void AudioWidget::setLength( long max ) { | 132 | void AudioWidget::setLength( long max ) { |
134 | updateSlider( mediaPlayerState->position(), max ); | 133 | updateSlider( mediaPlayerState->position(), max ); |
135 | } | 134 | } |
136 | 135 | ||
137 | 136 | ||
138 | void AudioWidget::setView( char view ) { | 137 | void AudioWidget::setView( char view ) { |
139 | if ( view == 'a' ) { | 138 | if ( view == 'a' ) { |
140 | startTimer( 150 ); | 139 | startTimer( 150 ); |
141 | showMaximized(); | 140 | showMaximized(); |
142 | } else { | 141 | } else { |
143 | killTimers(); | 142 | killTimers(); |
144 | hide(); | 143 | hide(); |
145 | } | 144 | } |
146 | } | 145 | } |
147 | 146 | ||
148 | 147 | ||
149 | void AudioWidget::updateSlider( long i, long max ) { | 148 | void AudioWidget::updateSlider( long i, long max ) { |
150 | if ( max == 0 ) | 149 | if ( max == 0 ) |
151 | return; | 150 | return; |
152 | // Will flicker too much if we don't do this | 151 | // Will flicker too much if we don't do this |
153 | // Scale to something reasonable | 152 | // Scale to something reasonable |
154 | int width = slider->width(); | 153 | int width = slider->width(); |
155 | int val = int((double)i * width / max); | 154 | int val = int((double)i * width / max); |
156 | if ( !audioSliderBeingMoved ) { | 155 | if ( !audioSliderBeingMoved ) { |
157 | if ( slider->value() != val ) | 156 | if ( slider->value() != val ) |
158 | slider->setValue( val ); | 157 | slider->setValue( val ); |
159 | if ( slider->maxValue() != width ) | 158 | if ( slider->maxValue() != width ) |
160 | slider->setMaxValue( width ); | 159 | slider->setMaxValue( width ); |
161 | } | 160 | } |
162 | } | 161 | } |
163 | 162 | ||
164 | 163 | ||
165 | void AudioWidget::setToggleButton( int i, bool down ) { | 164 | void AudioWidget::setToggleButton( int i, bool down ) { |
166 | if ( down != audioButtons[i].isDown ) | 165 | if ( down != audioButtons[i].isDown ) |
167 | toggleButton( i ); | 166 | toggleButton( i ); |
168 | } | 167 | } |
169 | 168 | ||
170 | 169 | ||
171 | void AudioWidget::toggleButton( int i ) { | 170 | void AudioWidget::toggleButton( int i ) { |
172 | audioButtons[i].isDown = !audioButtons[i].isDown; | 171 | audioButtons[i].isDown = !audioButtons[i].isDown; |
173 | QPainter p(this); | 172 | QPainter p(this); |
174 | paintButton ( &p, i ); | 173 | paintButton ( &p, i ); |
175 | } | 174 | } |
176 | 175 | ||
177 | 176 | ||
178 | void AudioWidget::paintButton( QPainter *p, int i ) { | 177 | void AudioWidget::paintButton( QPainter *p, int i ) { |
179 | int x = audioButtons[i].xPos; | 178 | int x = audioButtons[i].xPos; |
180 | int y = audioButtons[i].yPos; | 179 | int y = audioButtons[i].yPos; |
181 | int offset = 22 + 14 * audioButtons[i].isBig + audioButtons[i].isDown; | 180 | int offset = 22 + 14 * audioButtons[i].isBig + audioButtons[i].isDown; |
182 | int buttonSize = 64 + audioButtons[i].isBig * (90 - 64); | 181 | int buttonSize = 64 + audioButtons[i].isBig * (90 - 64); |
183 | p->drawPixmap( x, y, *pixmaps[audioButtons[i].isBig], buttonSize * (audioButtons[i].isDown + 2 * audioButtons[i].color), 0, buttonSize, buttonSize ); | 182 | p->drawPixmap( x, y, *pixmaps[audioButtons[i].isBig], buttonSize * (audioButtons[i].isDown + 2 * audioButtons[i].color), 0, buttonSize, buttonSize ); |
184 | p->drawPixmap( x + offset, y + offset, *pixmaps[2], 18 * i, 0, 18, 18 ); | 183 | p->drawPixmap( x + offset, y + offset, *pixmaps[2], 18 * i, 0, 18, 18 ); |
185 | } | 184 | } |
186 | 185 | ||
187 | 186 | ||
188 | void AudioWidget::timerEvent( QTimerEvent * ) { | 187 | void AudioWidget::timerEvent( QTimerEvent * ) { |
189 | static int frame = 0; | 188 | static int frame = 0; |
190 | if ( !mediaPlayerState->paused() && audioButtons[ AudioPlay ].isDown ) { | 189 | if ( !mediaPlayerState->paused() && audioButtons[ AudioPlay ].isDown ) { |
191 | frame = frame >= 7 ? 0 : frame + 1; | 190 | frame = frame >= 7 ? 0 : frame + 1; |
192 | int x = audioButtons[AudioPlay].xPos; | 191 | int x = audioButtons[AudioPlay].xPos; |
193 | int y = audioButtons[AudioPlay].yPos; | 192 | int y = audioButtons[AudioPlay].yPos; |
194 | QPainter p( this ); | 193 | QPainter p( this ); |
195 | // Optimize to only draw the little bit of the changing images which is different | 194 | // Optimize to only draw the little bit of the changing images which is different |
196 | p.drawPixmap( x + 14, y + 8, *pixmaps[3], 32 * frame, 0, 32, 32 ); | 195 | p.drawPixmap( x + 14, y + 8, *pixmaps[3], 32 * frame, 0, 32, 32 ); |
197 | p.drawPixmap( x + 37, y + 37, *pixmaps[2], 18 * AudioPlay, 0, 6, 3 ); | 196 | p.drawPixmap( x + 37, y + 37, *pixmaps[2], 18 * AudioPlay, 0, 6, 3 ); |
198 | } | 197 | } |
199 | } | 198 | } |
200 | 199 | ||
201 | 200 | ||
202 | void AudioWidget::mouseMoveEvent( QMouseEvent *event ) { | 201 | void AudioWidget::mouseMoveEvent( QMouseEvent *event ) { |
203 | for ( int i = 0; i < numButtons; i++ ) { | 202 | for ( int i = 0; i < numButtons; i++ ) { |
204 | int size = audioButtons[i].isBig; | 203 | int size = audioButtons[i].isBig; |
205 | int x = audioButtons[i].xPos; | 204 | int x = audioButtons[i].xPos; |
206 | int y = audioButtons[i].yPos; | 205 | int y = audioButtons[i].yPos; |
207 | if ( event->state() == QMouseEvent::LeftButton ) { | 206 | if ( event->state() == QMouseEvent::LeftButton ) { |
208 | // The test to see if the mouse click is inside the circular button or not | 207 | // The test to see if the mouse click is inside the circular button or not |
209 | // (compared with the radius squared to avoid a square-root of our distance) | 208 | // (compared with the radius squared to avoid a square-root of our distance) |
210 | int radius = 32 + 13 * size; | 209 | int radius = 32 + 13 * size; |
211 | QPoint center = QPoint( x + radius, y + radius ); | 210 | QPoint center = QPoint( x + radius, y + radius ); |
212 | QPoint dXY = center - event->pos(); | 211 | QPoint dXY = center - event->pos(); |
213 | int dist = dXY.x() * dXY.x() + dXY.y() * dXY.y(); | 212 | int dist = dXY.x() * dXY.x() + dXY.y() * dXY.y(); |
214 | bool isOnButton = dist <= (radius * radius); | 213 | bool isOnButton = dist <= (radius * radius); |
215 | // QRect r( x, y, 64 + 22*size, 64 + 22*size ); | 214 | // QRect r( x, y, 64 + 22*size, 64 + 22*size ); |
216 | // bool isOnButton = r.contains( event->pos() ); // Rectangular Button code | 215 | // bool isOnButton = r.contains( event->pos() ); // Rectangular Button code |
217 | if ( isOnButton && !audioButtons[i].isHeld ) { | 216 | if ( isOnButton && !audioButtons[i].isHeld ) { |
218 | audioButtons[i].isHeld = TRUE; | 217 | audioButtons[i].isHeld = TRUE; |
219 | toggleButton(i); | 218 | toggleButton(i); |
220 | switch (i) { | 219 | switch (i) { |
221 | case AudioVolumeUp: emit moreClicked(); return; | 220 | case AudioVolumeUp: emit moreClicked(); return; |
222 | case AudioVolumeDown: emit lessClicked(); return; | 221 | case AudioVolumeDown: emit lessClicked(); return; |
223 | } | 222 | } |
224 | } else if ( !isOnButton && audioButtons[i].isHeld ) { | 223 | } else if ( !isOnButton && audioButtons[i].isHeld ) { |
225 | audioButtons[i].isHeld = FALSE; | 224 | audioButtons[i].isHeld = FALSE; |
226 | toggleButton(i); | 225 | toggleButton(i); |
227 | } | 226 | } |
228 | } else { | 227 | } else { |
229 | if ( audioButtons[i].isHeld ) { | 228 | if ( audioButtons[i].isHeld ) { |
230 | audioButtons[i].isHeld = FALSE; | 229 | audioButtons[i].isHeld = FALSE; |
231 | if ( !audioButtons[i].isToggle ) | 230 | if ( !audioButtons[i].isToggle ) |
232 | setToggleButton( i, FALSE ); | 231 | setToggleButton( i, FALSE ); |
233 | switch (i) { | 232 | switch (i) { |
234 | case AudioPlay: mediaPlayerState->setPlaying(audioButtons[i].isDown); return; | 233 | case AudioPlay: mediaPlayerState->setPlaying(audioButtons[i].isDown); return; |
235 | case AudioStop: mediaPlayerState->setPlaying(FALSE); return; | 234 | case AudioStop: mediaPlayerState->setPlaying(FALSE); return; |
236 | case AudioPause: mediaPlayerState->setPaused(audioButtons[i].isDown); return; | 235 | case AudioPause: mediaPlayerState->setPaused(audioButtons[i].isDown); return; |
237 | case AudioNext: mediaPlayerState->setNext(); return; | 236 | case AudioNext: mediaPlayerState->setNext(); return; |
238 | case AudioPrevious: mediaPlayerState->setPrev(); return; | 237 | case AudioPrevious: mediaPlayerState->setPrev(); return; |
239 | case AudioLoop: mediaPlayerState->setLooping(audioButtons[i].isDown); return; | 238 | case AudioLoop: mediaPlayerState->setLooping(audioButtons[i].isDown); return; |
240 | case AudioVolumeUp: emit moreReleased(); return; | 239 | case AudioVolumeUp: emit moreReleased(); return; |
241 | case AudioVolumeDown: emit lessReleased(); return; | 240 | case AudioVolumeDown: emit lessReleased(); return; |
242 | case AudioPlayList: mediaPlayerState->setList(); return; | 241 | case AudioPlayList: mediaPlayerState->setList(); return; |
243 | } | 242 | } |
244 | } | 243 | } |
245 | } | 244 | } |
246 | } | 245 | } |
247 | } | 246 | } |
248 | 247 | ||
249 | 248 | ||
250 | void AudioWidget::mousePressEvent( QMouseEvent *event ) { | 249 | void AudioWidget::mousePressEvent( QMouseEvent *event ) { |
251 | mouseMoveEvent( event ); | 250 | mouseMoveEvent( event ); |
252 | } | 251 | } |
253 | 252 | ||
254 | 253 | ||
255 | void AudioWidget::mouseReleaseEvent( QMouseEvent *event ) { | 254 | void AudioWidget::mouseReleaseEvent( QMouseEvent *event ) { |
256 | mouseMoveEvent( event ); | 255 | mouseMoveEvent( event ); |
257 | } | 256 | } |
@@ -262,16 +261,16 @@ void AudioWidget::showEvent( QShowEvent* ) { | |||
262 | mouseMoveEvent( &event ); | 261 | mouseMoveEvent( &event ); |
263 | } | 262 | } |
264 | 263 | ||
265 | 264 | ||
266 | void AudioWidget::closeEvent( QCloseEvent* ) { | 265 | void AudioWidget::closeEvent( QCloseEvent* ) { |
267 | mediaPlayerState->setList(); | 266 | mediaPlayerState->setList(); |
268 | } | 267 | } |
269 | 268 | ||
270 | 269 | ||
271 | void AudioWidget::paintEvent( QPaintEvent * ) { | 270 | void AudioWidget::paintEvent( QPaintEvent * ) { |
272 | QPainter p( this ); | 271 | QPainter p( this ); |
273 | for ( int i = 0; i < numButtons; i++ ) | 272 | for ( int i = 0; i < numButtons; i++ ) |
274 | paintButton( &p, i ); | 273 | paintButton( &p, i ); |
275 | } | 274 | } |
276 | 275 | ||
277 | 276 | ||