author | llornkcor <llornkcor> | 2002-02-25 05:10:32 (UTC) |
---|---|---|
committer | llornkcor <llornkcor> | 2002-02-25 05:10:32 (UTC) |
commit | 1bebd27631a6c9d1ab967cbb32dd4e796b3b0402 (patch) (unidiff) | |
tree | 8ce49800cba26f6f2c33de74a71d4efe0338843f /core/multimedia/opieplayer/audiowidget.cpp | |
parent | d948361c1b475fab4660b28fbf5ec21fd34d923f (diff) | |
download | opie-1bebd27631a6c9d1ab967cbb32dd4e796b3b0402.zip opie-1bebd27631a6c9d1ab967cbb32dd4e796b3b0402.tar.gz opie-1bebd27631a6c9d1ab967cbb32dd4e796b3b0402.tar.bz2 |
fixed 2
Diffstat (limited to 'core/multimedia/opieplayer/audiowidget.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | core/multimedia/opieplayer/audiowidget.cpp | 126 |
1 files changed, 63 insertions, 63 deletions
diff --git a/core/multimedia/opieplayer/audiowidget.cpp b/core/multimedia/opieplayer/audiowidget.cpp index 1e0757f..582660c 100644 --- a/core/multimedia/opieplayer/audiowidget.cpp +++ b/core/multimedia/opieplayer/audiowidget.cpp | |||
@@ -1,10 +1,10 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of the 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 | ** |
@@ -57,13 +57,13 @@ MediaButton audioButtons[] = { | |||
57 | static const int numButtons = (sizeof(audioButtons)/sizeof(MediaButton)); | 57 | static const int numButtons = (sizeof(audioButtons)/sizeof(MediaButton)); |
58 | 58 | ||
59 | 59 | ||
60 | AudioWidget::AudioWidget(QWidget* parent, const char* name, WFlags f) : | 60 | AudioWidget::AudioWidget(QWidget* parent, const char* name, WFlags f) : |
61 | QWidget( parent, name, f ) | 61 | QWidget( parent, name, f ) |
62 | { | 62 | { |
63 | setCaption( tr("MediaPlayer") ); | 63 | setCaption( tr("OpiePlayer") ); |
64 | setBackgroundPixmap( Resource::loadPixmap( "mpegplayer/metalFinish" ) ); | 64 | setBackgroundPixmap( Resource::loadPixmap( "mpegplayer/metalFinish" ) ); |
65 | pixmaps[0] = new QPixmap( Resource::loadPixmap( "mpegplayer/mediaButtonsAll" ) ); | 65 | pixmaps[0] = new QPixmap( Resource::loadPixmap( "mpegplayer/mediaButtonsAll" ) ); |
66 | pixmaps[1] = new QPixmap( Resource::loadPixmap( "mpegplayer/mediaButtonsBig" ) ); | 66 | pixmaps[1] = new QPixmap( Resource::loadPixmap( "mpegplayer/mediaButtonsBig" ) ); |
67 | pixmaps[2] = new QPixmap( Resource::loadPixmap( "mpegplayer/mediaControls" ) ); | 67 | pixmaps[2] = new QPixmap( Resource::loadPixmap( "mpegplayer/mediaControls" ) ); |
68 | pixmaps[3] = new QPixmap( Resource::loadPixmap( "mpegplayer/animatedButton" ) ); | 68 | pixmaps[3] = new QPixmap( Resource::loadPixmap( "mpegplayer/animatedButton" ) ); |
69 | 69 | ||
@@ -100,13 +100,13 @@ AudioWidget::AudioWidget(QWidget* parent, const char* name, WFlags f) : | |||
100 | 100 | ||
101 | } | 101 | } |
102 | 102 | ||
103 | 103 | ||
104 | AudioWidget::~AudioWidget() { | 104 | AudioWidget::~AudioWidget() { |
105 | for ( int i = 0; i < 4; i++ ) | 105 | for ( int i = 0; i < 4; i++ ) |
106 | delete pixmaps[i]; | 106 | delete pixmaps[i]; |
107 | } | 107 | } |
108 | 108 | ||
109 | 109 | ||
110 | static bool audioSliderBeingMoved = FALSE; | 110 | static bool audioSliderBeingMoved = FALSE; |
111 | 111 | ||
112 | 112 | ||
@@ -115,13 +115,13 @@ void AudioWidget::sliderPressed() { | |||
115 | } | 115 | } |
116 | 116 | ||
117 | 117 | ||
118 | void AudioWidget::sliderReleased() { | 118 | void AudioWidget::sliderReleased() { |
119 | audioSliderBeingMoved = FALSE; | 119 | audioSliderBeingMoved = FALSE; |
120 | if ( slider->width() == 0 ) | 120 | if ( slider->width() == 0 ) |
121 | return; | 121 | return; |
122 | long val = long((double)slider->value() * mediaPlayerState->length() / slider->width()); | 122 | long val = long((double)slider->value() * mediaPlayerState->length() / slider->width()); |
123 | mediaPlayerState->setPosition( val ); | 123 | mediaPlayerState->setPosition( val ); |
124 | } | 124 | } |
125 | 125 | ||
126 | 126 | ||
127 | void AudioWidget::setPosition( long i ) { | 127 | void AudioWidget::setPosition( long i ) { |
@@ -133,40 +133,40 @@ void AudioWidget::setLength( long max ) { | |||
133 | updateSlider( mediaPlayerState->position(), max ); | 133 | updateSlider( mediaPlayerState->position(), max ); |
134 | } | 134 | } |
135 | 135 | ||
136 | 136 | ||
137 | void AudioWidget::setView( char view ) { | 137 | void AudioWidget::setView( char view ) { |
138 | if ( view == 'a' ) { | 138 | if ( view == 'a' ) { |
139 | startTimer( 150 ); | 139 | startTimer( 150 ); |
140 | showMaximized(); | 140 | showMaximized(); |
141 | } else { | 141 | } else { |
142 | killTimers(); | 142 | killTimers(); |
143 | hide(); | 143 | hide(); |
144 | } | 144 | } |
145 | } | 145 | } |
146 | 146 | ||
147 | 147 | ||
148 | void AudioWidget::updateSlider( long i, long max ) { | 148 | void AudioWidget::updateSlider( long i, long max ) { |
149 | if ( max == 0 ) | 149 | if ( max == 0 ) |
150 | return; | 150 | return; |
151 | // Will flicker too much if we don't do this | 151 | // Will flicker too much if we don't do this |
152 | // Scale to something reasonable | 152 | // Scale to something reasonable |
153 | int width = slider->width(); | 153 | int width = slider->width(); |
154 | int val = int((double)i * width / max); | 154 | int val = int((double)i * width / max); |
155 | if ( !audioSliderBeingMoved ) { | 155 | if ( !audioSliderBeingMoved ) { |
156 | if ( slider->value() != val ) | 156 | if ( slider->value() != val ) |
157 | slider->setValue( val ); | 157 | slider->setValue( val ); |
158 | if ( slider->maxValue() != width ) | 158 | if ( slider->maxValue() != width ) |
159 | slider->setMaxValue( width ); | 159 | slider->setMaxValue( width ); |
160 | } | 160 | } |
161 | } | 161 | } |
162 | 162 | ||
163 | 163 | ||
164 | void AudioWidget::setToggleButton( int i, bool down ) { | 164 | void AudioWidget::setToggleButton( int i, bool down ) { |
165 | if ( down != audioButtons[i].isDown ) | 165 | if ( down != audioButtons[i].isDown ) |
166 | toggleButton( i ); | 166 | toggleButton( i ); |
167 | } | 167 | } |
168 | 168 | ||
169 | 169 | ||
170 | void AudioWidget::toggleButton( int i ) { | 170 | void AudioWidget::toggleButton( int i ) { |
171 | audioButtons[i].isDown = !audioButtons[i].isDown; | 171 | audioButtons[i].isDown = !audioButtons[i].isDown; |
172 | QPainter p(this); | 172 | QPainter p(this); |
@@ -184,67 +184,67 @@ void AudioWidget::paintButton( QPainter *p, int i ) { | |||
184 | } | 184 | } |
185 | 185 | ||
186 | 186 | ||
187 | void AudioWidget::timerEvent( QTimerEvent * ) { | 187 | void AudioWidget::timerEvent( QTimerEvent * ) { |
188 | static int frame = 0; | 188 | static int frame = 0; |
189 | if ( !mediaPlayerState->paused() && audioButtons[ AudioPlay ].isDown ) { | 189 | if ( !mediaPlayerState->paused() && audioButtons[ AudioPlay ].isDown ) { |
190 | frame = frame >= 7 ? 0 : frame + 1; | 190 | frame = frame >= 7 ? 0 : frame + 1; |
191 | int x = audioButtons[AudioPlay].xPos; | 191 | int x = audioButtons[AudioPlay].xPos; |
192 | int y = audioButtons[AudioPlay].yPos; | 192 | int y = audioButtons[AudioPlay].yPos; |
193 | QPainter p( this ); | 193 | QPainter p( this ); |
194 | // 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 |
195 | 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 ); |
196 | 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 ); |
197 | } | 197 | } |
198 | } | 198 | } |
199 | 199 | ||
200 | 200 | ||
201 | void AudioWidget::mouseMoveEvent( QMouseEvent *event ) { | 201 | void AudioWidget::mouseMoveEvent( QMouseEvent *event ) { |
202 | for ( int i = 0; i < numButtons; i++ ) { | 202 | for ( int i = 0; i < numButtons; i++ ) { |
203 | int size = audioButtons[i].isBig; | 203 | int size = audioButtons[i].isBig; |
204 | int x = audioButtons[i].xPos; | 204 | int x = audioButtons[i].xPos; |
205 | int y = audioButtons[i].yPos; | 205 | int y = audioButtons[i].yPos; |
206 | if ( event->state() == QMouseEvent::LeftButton ) { | 206 | if ( event->state() == QMouseEvent::LeftButton ) { |
207 | // 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 |
208 | // (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) |
209 | int radius = 32 + 13 * size; | 209 | int radius = 32 + 13 * size; |
210 | QPoint center = QPoint( x + radius, y + radius ); | 210 | QPoint center = QPoint( x + radius, y + radius ); |
211 | QPoint dXY = center - event->pos(); | 211 | QPoint dXY = center - event->pos(); |
212 | int dist = dXY.x() * dXY.x() + dXY.y() * dXY.y(); | 212 | int dist = dXY.x() * dXY.x() + dXY.y() * dXY.y(); |
213 | bool isOnButton = dist <= (radius * radius); | 213 | bool isOnButton = dist <= (radius * radius); |
214 | // QRect r( x, y, 64 + 22*size, 64 + 22*size ); | 214 | // QRect r( x, y, 64 + 22*size, 64 + 22*size ); |
215 | // bool isOnButton = r.contains( event->pos() ); // Rectangular Button code | 215 | // bool isOnButton = r.contains( event->pos() ); // Rectangular Button code |
216 | if ( isOnButton && !audioButtons[i].isHeld ) { | 216 | if ( isOnButton && !audioButtons[i].isHeld ) { |
217 | audioButtons[i].isHeld = TRUE; | 217 | audioButtons[i].isHeld = TRUE; |
218 | toggleButton(i); | 218 | toggleButton(i); |
219 | switch (i) { | 219 | switch (i) { |
220 | case AudioVolumeUp: emit moreClicked(); return; | 220 | case AudioVolumeUp: emit moreClicked(); return; |
221 | case AudioVolumeDown: emit lessClicked(); return; | 221 | case AudioVolumeDown: emit lessClicked(); return; |
222 | } | 222 | } |
223 | } else if ( !isOnButton && audioButtons[i].isHeld ) { | 223 | } else if ( !isOnButton && audioButtons[i].isHeld ) { |
224 | audioButtons[i].isHeld = FALSE; | 224 | audioButtons[i].isHeld = FALSE; |
225 | toggleButton(i); | 225 | toggleButton(i); |
226 | } | 226 | } |
227 | } else { | 227 | } else { |
228 | if ( audioButtons[i].isHeld ) { | 228 | if ( audioButtons[i].isHeld ) { |
229 | audioButtons[i].isHeld = FALSE; | 229 | audioButtons[i].isHeld = FALSE; |
230 | if ( !audioButtons[i].isToggle ) | 230 | if ( !audioButtons[i].isToggle ) |
231 | setToggleButton( i, FALSE ); | 231 | setToggleButton( i, FALSE ); |
232 | switch (i) { | 232 | switch (i) { |
233 | case AudioPlay: mediaPlayerState->setPlaying(audioButtons[i].isDown); return; | 233 | case AudioPlay: mediaPlayerState->setPlaying(audioButtons[i].isDown); return; |
234 | case AudioStop: mediaPlayerState->setPlaying(FALSE); return; | 234 | case AudioStop: mediaPlayerState->setPlaying(FALSE); return; |
235 | case AudioPause: mediaPlayerState->setPaused(audioButtons[i].isDown); return; | 235 | case AudioPause: mediaPlayerState->setPaused(audioButtons[i].isDown); return; |
236 | case AudioNext: mediaPlayerState->setNext(); return; | 236 | case AudioNext: mediaPlayerState->setNext(); return; |
237 | case AudioPrevious: mediaPlayerState->setPrev(); return; | 237 | case AudioPrevious: mediaPlayerState->setPrev(); return; |
238 | case AudioLoop: mediaPlayerState->setLooping(audioButtons[i].isDown); return; | 238 | case AudioLoop: mediaPlayerState->setLooping(audioButtons[i].isDown); return; |
239 | case AudioVolumeUp: emit moreReleased(); return; | 239 | case AudioVolumeUp: emit moreReleased(); return; |
240 | case AudioVolumeDown: emit lessReleased(); return; | 240 | case AudioVolumeDown: emit lessReleased(); return; |
241 | case AudioPlayList: mediaPlayerState->setList(); return; | 241 | case AudioPlayList: mediaPlayerState->setList(); return; |
242 | } | 242 | } |
243 | } | 243 | } |
244 | } | 244 | } |
245 | } | 245 | } |
246 | } | 246 | } |
247 | 247 | ||
248 | 248 | ||
249 | void AudioWidget::mousePressEvent( QMouseEvent *event ) { | 249 | void AudioWidget::mousePressEvent( QMouseEvent *event ) { |
250 | mouseMoveEvent( event ); | 250 | mouseMoveEvent( event ); |
@@ -267,10 +267,10 @@ void AudioWidget::closeEvent( QCloseEvent* ) { | |||
267 | } | 267 | } |
268 | 268 | ||
269 | 269 | ||
270 | void AudioWidget::paintEvent( QPaintEvent * ) { | 270 | void AudioWidget::paintEvent( QPaintEvent * ) { |
271 | QPainter p( this ); | 271 | QPainter p( this ); |
272 | for ( int i = 0; i < numButtons; i++ ) | 272 | for ( int i = 0; i < numButtons; i++ ) |
273 | paintButton( &p, i ); | 273 | paintButton( &p, i ); |
274 | } | 274 | } |
275 | 275 | ||
276 | 276 | ||