author | llornkcor <llornkcor> | 2002-04-21 14:06:57 (UTC) |
---|---|---|
committer | llornkcor <llornkcor> | 2002-04-21 14:06:57 (UTC) |
commit | 05158fd95b12800666a7a0620a32390e61979385 (patch) (unidiff) | |
tree | 5b62d42fada3eda8a518389fc04d3aaf2f02aefd | |
parent | 2da038246124a92248add8195126ac7bd21512f6 (diff) | |
download | opie-05158fd95b12800666a7a0620a32390e61979385.zip opie-05158fd95b12800666a7a0620a32390e61979385.tar.gz opie-05158fd95b12800666a7a0620a32390e61979385.tar.bz2 |
really fixed slider
-rw-r--r-- | core/multimedia/opieplayer/audiowidget.cpp | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/core/multimedia/opieplayer/audiowidget.cpp b/core/multimedia/opieplayer/audiowidget.cpp index b9561d5..e2e3603 100644 --- a/core/multimedia/opieplayer/audiowidget.cpp +++ b/core/multimedia/opieplayer/audiowidget.cpp | |||
@@ -1,342 +1,348 @@ | |||
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> | 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 | 28 | ||
29 | #include "audiowidget.h" | 29 | #include "audiowidget.h" |
30 | #include "mediaplayerstate.h" | 30 | #include "mediaplayerstate.h" |
31 | 31 | ||
32 | extern MediaPlayerState *mediaPlayerState; | 32 | extern MediaPlayerState *mediaPlayerState; |
33 | 33 | ||
34 | 34 | ||
35 | static const int xo = -2; // movable x offset | 35 | static const int xo = -2; // movable x offset |
36 | static const int yo = 22; // movable y offset | 36 | static const int yo = 22; // movable y offset |
37 | 37 | ||
38 | 38 | ||
39 | struct MediaButton { | 39 | struct MediaButton { |
40 | int xPos, yPos; | 40 | int xPos, yPos; |
41 | int color; | 41 | int color; |
42 | bool isToggle, isBig, isHeld, isDown; | 42 | bool isToggle, isBig, isHeld, isDown; |
43 | }; | 43 | }; |
44 | 44 | ||
45 | 45 | ||
46 | // 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) |
47 | MediaButton audioButtons[] = { | 47 | MediaButton audioButtons[] = { |
48 | { 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 |
49 | { 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 |
50 | { 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 |
51 | { 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 |
52 | { 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 |
53 | { 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 |
54 | { 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 |
55 | { 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 |
56 | { 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 |
57 | }; | 57 | }; |
58 | 58 | ||
59 | 59 | ||
60 | static const int numButtons = (sizeof(audioButtons)/sizeof(MediaButton)); | 60 | static const int numButtons = (sizeof(audioButtons)/sizeof(MediaButton)); |
61 | 61 | ||
62 | 62 | ||
63 | AudioWidget::AudioWidget(QWidget* parent, const char* name, WFlags f) : | 63 | AudioWidget::AudioWidget(QWidget* parent, const char* name, WFlags f) : |
64 | QWidget( parent, name, f ) | 64 | QWidget( parent, name, f ) |
65 | { | 65 | { |
66 | // QPEApplication::grabKeyboard(); | 66 | // QPEApplication::grabKeyboard(); |
67 | setCaption( tr("OpiePlayer") ); | 67 | setCaption( tr("OpiePlayer") ); |
68 | setBackgroundPixmap( Resource::loadPixmap( "opieplayer/metalFinish" ) ); | 68 | setBackgroundPixmap( Resource::loadPixmap( "opieplayer/metalFinish" ) ); |
69 | pixmaps[0] = new QPixmap( Resource::loadPixmap( "opieplayer/mediaButtonsAll" ) ); | 69 | pixmaps[0] = new QPixmap( Resource::loadPixmap( "opieplayer/mediaButtonsAll" ) ); |
70 | pixmaps[1] = new QPixmap( Resource::loadPixmap( "opieplayer/mediaButtonsBig" ) ); | 70 | pixmaps[1] = new QPixmap( Resource::loadPixmap( "opieplayer/mediaButtonsBig" ) ); |
71 | pixmaps[2] = new QPixmap( Resource::loadPixmap( "opieplayer/mediaControls" ) ); | 71 | pixmaps[2] = new QPixmap( Resource::loadPixmap( "opieplayer/mediaControls" ) ); |
72 | pixmaps[3] = new QPixmap( Resource::loadPixmap( "opieplayer/animatedButton" ) ); | 72 | pixmaps[3] = new QPixmap( Resource::loadPixmap( "opieplayer/animatedButton" ) ); |
73 | 73 | ||
74 | songInfo = new Ticker( this ); | 74 | songInfo = new Ticker( this ); |
75 | songInfo->setFocusPolicy( QWidget::NoFocus ); | 75 | songInfo->setFocusPolicy( QWidget::NoFocus ); |
76 | songInfo->setGeometry( QRect( 7, 3, 220, 20 ) ); | 76 | songInfo->setGeometry( QRect( 7, 3, 220, 20 ) ); |
77 | 77 | ||
78 | slider = new QSlider( Qt::Horizontal, this ); | 78 | slider = new QSlider( Qt::Horizontal, this ); |
79 | slider->setFixedWidth( 220 ); | 79 | slider->setFixedWidth( 220 ); |
80 | slider->setFixedHeight( 20 ); | 80 | slider->setFixedHeight( 20 ); |
81 | slider->setMinValue( 0 ); | 81 | slider->setMinValue( 0 ); |
82 | slider->setMaxValue( 1 ); | 82 | slider->setMaxValue( 1 ); |
83 | slider->setBackgroundPixmap( Resource::loadPixmap( "opieplayer/metalFinish" ) ); | 83 | slider->setBackgroundPixmap( Resource::loadPixmap( "opieplayer/metalFinish" ) ); |
84 | slider->setFocusPolicy( QWidget::NoFocus ); | 84 | slider->setFocusPolicy( QWidget::NoFocus ); |
85 | slider->setGeometry( QRect( 7, 262, 220, 20 ) ); | 85 | slider->setGeometry( QRect( 7, 262, 220, 20 ) ); |
86 | 86 | ||
87 | connect( slider, SIGNAL( sliderPressed() ), this, SLOT( sliderPressed() ) ); | 87 | connect( slider, SIGNAL( sliderPressed() ), this, SLOT( sliderPressed() ) ); |
88 | connect( slider, SIGNAL( sliderReleased() ), this, SLOT( sliderReleased() ) ); | 88 | connect( slider, SIGNAL( sliderReleased() ), this, SLOT( sliderReleased() ) ); |
89 | 89 | ||
90 | connect( mediaPlayerState, SIGNAL( lengthChanged(long) ), this, SLOT( setLength(long) ) ); | 90 | connect( mediaPlayerState, SIGNAL( lengthChanged(long) ), this, SLOT( setLength(long) ) ); |
91 | connect( mediaPlayerState, SIGNAL( viewChanged(char) ), this, SLOT( setView(char) ) ); | 91 | connect( mediaPlayerState, SIGNAL( viewChanged(char) ), this, SLOT( setView(char) ) ); |
92 | connect( mediaPlayerState, SIGNAL( loopingToggled(bool) ), this, SLOT( setLooping(bool) ) ); | 92 | connect( mediaPlayerState, SIGNAL( loopingToggled(bool) ), this, SLOT( setLooping(bool) ) ); |
93 | connect( mediaPlayerState, SIGNAL( pausedToggled(bool) ), this, SLOT( setPaused(bool) ) ); | 93 | connect( mediaPlayerState, SIGNAL( pausedToggled(bool) ), this, SLOT( setPaused(bool) ) ); |
94 | connect( mediaPlayerState, SIGNAL( playingToggled(bool) ), this, SLOT( setPlaying(bool) ) ); | 94 | connect( mediaPlayerState, SIGNAL( playingToggled(bool) ), this, SLOT( setPlaying(bool) ) ); |
95 | 95 | ||
96 | if( !mediaPlayerState->isStreaming) { // this stops the slider from being moved, thus | ||
97 | // does not stop stream when it reaches the end | ||
98 | connect( mediaPlayerState, SIGNAL( positionChanged(long) ),this, SLOT( setPosition(long) ) ); | ||
99 | connect( mediaPlayerState, SIGNAL( positionUpdated(long) ),this, SLOT( setPosition(long) ) ); | ||
100 | } | ||
101 | // Intialise state | 96 | // Intialise state |
102 | setLength( mediaPlayerState->length() ); | 97 | setLength( mediaPlayerState->length() ); |
103 | setPosition( mediaPlayerState->position() ); | 98 | setPosition( mediaPlayerState->position() ); |
104 | setLooping( mediaPlayerState->fullscreen() ); | 99 | setLooping( mediaPlayerState->fullscreen() ); |
105 | setPaused( mediaPlayerState->paused() ); | 100 | setPaused( mediaPlayerState->paused() ); |
106 | setPlaying( mediaPlayerState->playing() ); | 101 | setPlaying( mediaPlayerState->playing() ); |
107 | if (mediaPlayerState->isStreaming) slider->hide(); | ||
108 | 102 | ||
109 | } | 103 | } |
110 | 104 | ||
111 | 105 | ||
112 | AudioWidget::~AudioWidget() { | 106 | AudioWidget::~AudioWidget() { |
113 | for ( int i = 0; i < 4; i++ ) | 107 | for ( int i = 0; i < 4; i++ ) |
114 | delete pixmaps[i]; | 108 | delete pixmaps[i]; |
115 | } | 109 | } |
116 | 110 | ||
117 | 111 | ||
118 | static bool audioSliderBeingMoved = FALSE; | 112 | static bool audioSliderBeingMoved = FALSE; |
119 | 113 | ||
120 | 114 | ||
121 | void AudioWidget::sliderPressed() { | 115 | void AudioWidget::sliderPressed() { |
122 | audioSliderBeingMoved = TRUE; | 116 | audioSliderBeingMoved = TRUE; |
123 | } | 117 | } |
124 | 118 | ||
125 | 119 | ||
126 | void AudioWidget::sliderReleased() { | 120 | void AudioWidget::sliderReleased() { |
127 | audioSliderBeingMoved = FALSE; | 121 | audioSliderBeingMoved = FALSE; |
128 | if ( slider->width() == 0 ) | 122 | if ( slider->width() == 0 ) |
129 | return; | 123 | return; |
130 | long val = long((double)slider->value() * mediaPlayerState->length() / slider->width()); | 124 | long val = long((double)slider->value() * mediaPlayerState->length() / slider->width()); |
131 | mediaPlayerState->setPosition( val ); | 125 | mediaPlayerState->setPosition( val ); |
132 | } | 126 | } |
133 | 127 | ||
134 | 128 | ||
135 | void AudioWidget::setPosition( long i ) { | 129 | void AudioWidget::setPosition( long i ) { |
136 | updateSlider( i, mediaPlayerState->length() ); | 130 | updateSlider( i, mediaPlayerState->length() ); |
137 | } | 131 | } |
138 | 132 | ||
139 | 133 | ||
140 | void AudioWidget::setLength( long max ) { | 134 | void AudioWidget::setLength( long max ) { |
141 | updateSlider( mediaPlayerState->position(), max ); | 135 | updateSlider( mediaPlayerState->position(), max ); |
142 | } | 136 | } |
143 | 137 | ||
144 | 138 | ||
145 | void AudioWidget::setView( char view ) { | 139 | void AudioWidget::setView( char view ) { |
140 | if (mediaPlayerState->isStreaming) { | ||
141 | if( !slider->isHidden()) slider->hide(); | ||
142 | disconnect( mediaPlayerState, SIGNAL( positionChanged(long) ),this, SLOT( setPosition(long) ) ); | ||
143 | disconnect( mediaPlayerState, SIGNAL( positionUpdated(long) ),this, SLOT( setPosition(long) ) ); | ||
144 | } else { | ||
145 | // this stops the slider from being moved, thus | ||
146 | // does not stop stream when it reaches the end | ||
147 | if( slider->isHidden()) slider->show(); | ||
148 | connect( mediaPlayerState, SIGNAL( positionChanged(long) ),this, SLOT( setPosition(long) ) ); | ||
149 | connect( mediaPlayerState, SIGNAL( positionUpdated(long) ),this, SLOT( setPosition(long) ) ); | ||
150 | } | ||
151 | |||
146 | if ( view == 'a' ) { | 152 | if ( view == 'a' ) { |
147 | startTimer( 150 ); | 153 | startTimer( 150 ); |
148 | showMaximized(); | 154 | showMaximized(); |
149 | } else { | 155 | } else { |
150 | killTimers(); | 156 | killTimers(); |
151 | hide(); | 157 | hide(); |
152 | } | 158 | } |
153 | } | 159 | } |
154 | 160 | ||
155 | 161 | ||
156 | void AudioWidget::updateSlider( long i, long max ) { | 162 | void AudioWidget::updateSlider( long i, long max ) { |
157 | if ( max == 0 ) | 163 | if ( max == 0 ) |
158 | return; | 164 | return; |
159 | // Will flicker too much if we don't do this | 165 | // Will flicker too much if we don't do this |
160 | // Scale to something reasonable | 166 | // Scale to something reasonable |
161 | int width = slider->width(); | 167 | int width = slider->width(); |
162 | int val = int((double)i * width / max); | 168 | int val = int((double)i * width / max); |
163 | if ( !audioSliderBeingMoved ) { | 169 | if ( !audioSliderBeingMoved ) { |
164 | if ( slider->value() != val ) | 170 | if ( slider->value() != val ) |
165 | slider->setValue( val ); | 171 | slider->setValue( val ); |
166 | if ( slider->maxValue() != width ) | 172 | if ( slider->maxValue() != width ) |
167 | slider->setMaxValue( width ); | 173 | slider->setMaxValue( width ); |
168 | } | 174 | } |
169 | } | 175 | } |
170 | 176 | ||
171 | 177 | ||
172 | void AudioWidget::setToggleButton( int i, bool down ) { | 178 | void AudioWidget::setToggleButton( int i, bool down ) { |
173 | if ( down != audioButtons[i].isDown ) | 179 | if ( down != audioButtons[i].isDown ) |
174 | toggleButton( i ); | 180 | toggleButton( i ); |
175 | } | 181 | } |
176 | 182 | ||
177 | 183 | ||
178 | void AudioWidget::toggleButton( int i ) { | 184 | void AudioWidget::toggleButton( int i ) { |
179 | audioButtons[i].isDown = !audioButtons[i].isDown; | 185 | audioButtons[i].isDown = !audioButtons[i].isDown; |
180 | QPainter p(this); | 186 | QPainter p(this); |
181 | paintButton ( &p, i ); | 187 | paintButton ( &p, i ); |
182 | } | 188 | } |
183 | 189 | ||
184 | 190 | ||
185 | void AudioWidget::paintButton( QPainter *p, int i ) { | 191 | void AudioWidget::paintButton( QPainter *p, int i ) { |
186 | int x = audioButtons[i].xPos; | 192 | int x = audioButtons[i].xPos; |
187 | int y = audioButtons[i].yPos; | 193 | int y = audioButtons[i].yPos; |
188 | int offset = 22 + 14 * audioButtons[i].isBig + audioButtons[i].isDown; | 194 | int offset = 22 + 14 * audioButtons[i].isBig + audioButtons[i].isDown; |
189 | int buttonSize = 64 + audioButtons[i].isBig * (90 - 64); | 195 | int buttonSize = 64 + audioButtons[i].isBig * (90 - 64); |
190 | p->drawPixmap( x, y, *pixmaps[audioButtons[i].isBig], buttonSize * (audioButtons[i].isDown + 2 * audioButtons[i].color), 0, buttonSize, buttonSize ); | 196 | p->drawPixmap( x, y, *pixmaps[audioButtons[i].isBig], buttonSize * (audioButtons[i].isDown + 2 * audioButtons[i].color), 0, buttonSize, buttonSize ); |
191 | p->drawPixmap( x + offset, y + offset, *pixmaps[2], 18 * i, 0, 18, 18 ); | 197 | p->drawPixmap( x + offset, y + offset, *pixmaps[2], 18 * i, 0, 18, 18 ); |
192 | } | 198 | } |
193 | 199 | ||
194 | 200 | ||
195 | void AudioWidget::timerEvent( QTimerEvent * ) { | 201 | void AudioWidget::timerEvent( QTimerEvent * ) { |
196 | static int frame = 0; | 202 | static int frame = 0; |
197 | if ( !mediaPlayerState->paused() && audioButtons[ AudioPlay ].isDown ) { | 203 | if ( !mediaPlayerState->paused() && audioButtons[ AudioPlay ].isDown ) { |
198 | frame = frame >= 7 ? 0 : frame + 1; | 204 | frame = frame >= 7 ? 0 : frame + 1; |
199 | int x = audioButtons[AudioPlay].xPos; | 205 | int x = audioButtons[AudioPlay].xPos; |
200 | int y = audioButtons[AudioPlay].yPos; | 206 | int y = audioButtons[AudioPlay].yPos; |
201 | QPainter p( this ); | 207 | QPainter p( this ); |
202 | // Optimize to only draw the little bit of the changing images which is different | 208 | // Optimize to only draw the little bit of the changing images which is different |
203 | p.drawPixmap( x + 14, y + 8, *pixmaps[3], 32 * frame, 0, 32, 32 ); | 209 | p.drawPixmap( x + 14, y + 8, *pixmaps[3], 32 * frame, 0, 32, 32 ); |
204 | p.drawPixmap( x + 37, y + 37, *pixmaps[2], 18 * AudioPlay, 0, 6, 3 ); | 210 | p.drawPixmap( x + 37, y + 37, *pixmaps[2], 18 * AudioPlay, 0, 6, 3 ); |
205 | } | 211 | } |
206 | } | 212 | } |
207 | 213 | ||
208 | 214 | ||
209 | void AudioWidget::mouseMoveEvent( QMouseEvent *event ) { | 215 | void AudioWidget::mouseMoveEvent( QMouseEvent *event ) { |
210 | for ( int i = 0; i < numButtons; i++ ) { | 216 | for ( int i = 0; i < numButtons; i++ ) { |
211 | int size = audioButtons[i].isBig; | 217 | int size = audioButtons[i].isBig; |
212 | int x = audioButtons[i].xPos; | 218 | int x = audioButtons[i].xPos; |
213 | int y = audioButtons[i].yPos; | 219 | int y = audioButtons[i].yPos; |
214 | if ( event->state() == QMouseEvent::LeftButton ) { | 220 | if ( event->state() == QMouseEvent::LeftButton ) { |
215 | // The test to see if the mouse click is inside the circular button or not | 221 | // The test to see if the mouse click is inside the circular button or not |
216 | // (compared with the radius squared to avoid a square-root of our distance) | 222 | // (compared with the radius squared to avoid a square-root of our distance) |
217 | int radius = 32 + 13 * size; | 223 | int radius = 32 + 13 * size; |
218 | QPoint center = QPoint( x + radius, y + radius ); | 224 | QPoint center = QPoint( x + radius, y + radius ); |
219 | QPoint dXY = center - event->pos(); | 225 | QPoint dXY = center - event->pos(); |
220 | int dist = dXY.x() * dXY.x() + dXY.y() * dXY.y(); | 226 | int dist = dXY.x() * dXY.x() + dXY.y() * dXY.y(); |
221 | bool isOnButton = dist <= (radius * radius); | 227 | bool isOnButton = dist <= (radius * radius); |
222 | // QRect r( x, y, 64 + 22*size, 64 + 22*size ); | 228 | // QRect r( x, y, 64 + 22*size, 64 + 22*size ); |
223 | // bool isOnButton = r.contains( event->pos() ); // Rectangular Button code | 229 | // bool isOnButton = r.contains( event->pos() ); // Rectangular Button code |
224 | if ( isOnButton && !audioButtons[i].isHeld ) { | 230 | if ( isOnButton && !audioButtons[i].isHeld ) { |
225 | audioButtons[i].isHeld = TRUE; | 231 | audioButtons[i].isHeld = TRUE; |
226 | toggleButton(i); | 232 | toggleButton(i); |
227 | qDebug("button toggled1 %d",i); | 233 | qDebug("button toggled1 %d",i); |
228 | switch (i) { | 234 | switch (i) { |
229 | case AudioVolumeUp: emit moreClicked(); return; | 235 | case AudioVolumeUp: emit moreClicked(); return; |
230 | case AudioVolumeDown: emit lessClicked(); return; | 236 | case AudioVolumeDown: emit lessClicked(); return; |
231 | } | 237 | } |
232 | } else if ( !isOnButton && audioButtons[i].isHeld ) { | 238 | } else if ( !isOnButton && audioButtons[i].isHeld ) { |
233 | audioButtons[i].isHeld = FALSE; | 239 | audioButtons[i].isHeld = FALSE; |
234 | toggleButton(i); | 240 | toggleButton(i); |
235 | qDebug("button toggled2 %d",i); | 241 | qDebug("button toggled2 %d",i); |
236 | } | 242 | } |
237 | } else { | 243 | } else { |
238 | if ( audioButtons[i].isHeld ) { | 244 | if ( audioButtons[i].isHeld ) { |
239 | audioButtons[i].isHeld = FALSE; | 245 | audioButtons[i].isHeld = FALSE; |
240 | if ( !audioButtons[i].isToggle ) | 246 | if ( !audioButtons[i].isToggle ) |
241 | setToggleButton( i, FALSE ); | 247 | setToggleButton( i, FALSE ); |
242 | qDebug("button toggled3 %d",i); | 248 | qDebug("button toggled3 %d",i); |
243 | switch (i) { | 249 | switch (i) { |
244 | case AudioPlay: mediaPlayerState->setPlaying(audioButtons[i].isDown); return; | 250 | case AudioPlay: mediaPlayerState->setPlaying(audioButtons[i].isDown); return; |
245 | case AudioStop: mediaPlayerState->setPlaying(FALSE); return; | 251 | case AudioStop: mediaPlayerState->setPlaying(FALSE); return; |
246 | case AudioPause: mediaPlayerState->setPaused(audioButtons[i].isDown); return; | 252 | case AudioPause: mediaPlayerState->setPaused(audioButtons[i].isDown); return; |
247 | case AudioNext: mediaPlayerState->setNext(); return; | 253 | case AudioNext: mediaPlayerState->setNext(); return; |
248 | case AudioPrevious: mediaPlayerState->setPrev(); return; | 254 | case AudioPrevious: mediaPlayerState->setPrev(); return; |
249 | case AudioLoop: mediaPlayerState->setLooping(audioButtons[i].isDown); return; | 255 | case AudioLoop: mediaPlayerState->setLooping(audioButtons[i].isDown); return; |
250 | case AudioVolumeUp: emit moreReleased(); return; | 256 | case AudioVolumeUp: emit moreReleased(); return; |
251 | case AudioVolumeDown: emit lessReleased(); return; | 257 | case AudioVolumeDown: emit lessReleased(); return; |
252 | case AudioPlayList: mediaPlayerState->setList(); return; | 258 | case AudioPlayList: mediaPlayerState->setList(); return; |
253 | } | 259 | } |
254 | } | 260 | } |
255 | } | 261 | } |
256 | } | 262 | } |
257 | } | 263 | } |
258 | 264 | ||
259 | 265 | ||
260 | void AudioWidget::mousePressEvent( QMouseEvent *event ) { | 266 | void AudioWidget::mousePressEvent( QMouseEvent *event ) { |
261 | mouseMoveEvent( event ); | 267 | mouseMoveEvent( event ); |
262 | } | 268 | } |
263 | 269 | ||
264 | 270 | ||
265 | void AudioWidget::mouseReleaseEvent( QMouseEvent *event ) { | 271 | void AudioWidget::mouseReleaseEvent( QMouseEvent *event ) { |
266 | mouseMoveEvent( event ); | 272 | mouseMoveEvent( event ); |
267 | } | 273 | } |
268 | 274 | ||
269 | 275 | ||
270 | void AudioWidget::showEvent( QShowEvent* ) { | 276 | void AudioWidget::showEvent( QShowEvent* ) { |
271 | QMouseEvent event( QEvent::MouseMove, QPoint( 0, 0 ), 0, 0 ); | 277 | QMouseEvent event( QEvent::MouseMove, QPoint( 0, 0 ), 0, 0 ); |
272 | mouseMoveEvent( &event ); | 278 | mouseMoveEvent( &event ); |
273 | } | 279 | } |
274 | 280 | ||
275 | 281 | ||
276 | void AudioWidget::closeEvent( QCloseEvent* ) { | 282 | void AudioWidget::closeEvent( QCloseEvent* ) { |
277 | mediaPlayerState->setList(); | 283 | mediaPlayerState->setList(); |
278 | } | 284 | } |
279 | 285 | ||
280 | 286 | ||
281 | void AudioWidget::paintEvent( QPaintEvent * ) { | 287 | void AudioWidget::paintEvent( QPaintEvent * ) { |
282 | QPainter p( this ); | 288 | QPainter p( this ); |
283 | for ( int i = 0; i < numButtons; i++ ) | 289 | for ( int i = 0; i < numButtons; i++ ) |
284 | paintButton( &p, i ); | 290 | paintButton( &p, i ); |
285 | } | 291 | } |
286 | 292 | ||
287 | 293 | ||
288 | void AudioWidget::keyReleaseEvent( QKeyEvent *e) | 294 | void AudioWidget::keyReleaseEvent( QKeyEvent *e) |
289 | { | 295 | { |
290 | switch ( e->key() ) { | 296 | switch ( e->key() ) { |
291 | ////////////////////////////// Zaurus keys | 297 | ////////////////////////////// Zaurus keys |
292 | case Key_Home: | 298 | case Key_Home: |
293 | break; | 299 | break; |
294 | case Key_F9: //activity | 300 | case Key_F9: //activity |
295 | break; | 301 | break; |
296 | case Key_F10: //contacts | 302 | case Key_F10: //contacts |
297 | break; | 303 | break; |
298 | case Key_F11: //menu | 304 | case Key_F11: //menu |
299 | break; | 305 | break; |
300 | case Key_F12: //home | 306 | case Key_F12: //home |
301 | break; | 307 | break; |
302 | case Key_F13: //mail | 308 | case Key_F13: //mail |
303 | break; | 309 | break; |
304 | case Key_Space: { | 310 | case Key_Space: { |
305 | if(mediaPlayerState->playing()) { | 311 | if(mediaPlayerState->playing()) { |
306 | // toggleButton(1); | 312 | // toggleButton(1); |
307 | mediaPlayerState->setPlaying(FALSE); | 313 | mediaPlayerState->setPlaying(FALSE); |
308 | // toggleButton(1); | 314 | // toggleButton(1); |
309 | } else { | 315 | } else { |
310 | // toggleButton(0); | 316 | // toggleButton(0); |
311 | mediaPlayerState->setPlaying(TRUE); | 317 | mediaPlayerState->setPlaying(TRUE); |
312 | // toggleButton(0); | 318 | // toggleButton(0); |
313 | } | 319 | } |
314 | } | 320 | } |
315 | break; | 321 | break; |
316 | case Key_Down: | 322 | case Key_Down: |
317 | toggleButton(6); | 323 | toggleButton(6); |
318 | emit lessClicked(); | 324 | emit lessClicked(); |
319 | emit lessReleased(); | 325 | emit lessReleased(); |
320 | toggleButton(6); | 326 | toggleButton(6); |
321 | break; | 327 | break; |
322 | case Key_Up: | 328 | case Key_Up: |
323 | toggleButton(5); | 329 | toggleButton(5); |
324 | emit moreClicked(); | 330 | emit moreClicked(); |
325 | emit moreReleased(); | 331 | emit moreReleased(); |
326 | toggleButton(5); | 332 | toggleButton(5); |
327 | break; | 333 | break; |
328 | case Key_Right: | 334 | case Key_Right: |
329 | // toggleButton(3); | 335 | // toggleButton(3); |
330 | mediaPlayerState->setNext(); | 336 | mediaPlayerState->setNext(); |
331 | // toggleButton(3); | 337 | // toggleButton(3); |
332 | break; | 338 | break; |
333 | case Key_Left: | 339 | case Key_Left: |
334 | // toggleButton(4); | 340 | // toggleButton(4); |
335 | mediaPlayerState->setPrev(); | 341 | mediaPlayerState->setPrev(); |
336 | // toggleButton(4); | 342 | // toggleButton(4); |
337 | break; | 343 | break; |
338 | case Key_Escape: | 344 | case Key_Escape: |
339 | break; | 345 | break; |
340 | 346 | ||
341 | }; | 347 | }; |
342 | } | 348 | } |