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