-rw-r--r-- | core/multimedia/opieplayer/audiowidget.cpp | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/core/multimedia/opieplayer/audiowidget.cpp b/core/multimedia/opieplayer/audiowidget.cpp index 3dfe182..a1973e9 100644 --- a/core/multimedia/opieplayer/audiowidget.cpp +++ b/core/multimedia/opieplayer/audiowidget.cpp | |||
@@ -1,513 +1,513 @@ | |||
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 | #include <qpe/config.h> | 22 | #include <qpe/config.h> |
23 | 23 | ||
24 | #include <qwidget.h> | 24 | #include <qwidget.h> |
25 | #include <qpixmap.h> | 25 | #include <qpixmap.h> |
26 | #include <qbutton.h> | 26 | #include <qbutton.h> |
27 | #include <qpainter.h> | 27 | #include <qpainter.h> |
28 | #include <qframe.h> | 28 | #include <qframe.h> |
29 | #include <qlayout.h> | 29 | #include <qlayout.h> |
30 | #include <qdir.h> | 30 | #include <qdir.h> |
31 | #include "audiowidget.h" | 31 | #include "audiowidget.h" |
32 | #include "mediaplayerstate.h" | 32 | #include "mediaplayerstate.h" |
33 | 33 | ||
34 | #include <stdlib.h> | 34 | #include <stdlib.h> |
35 | #include <stdio.h> | 35 | #include <stdio.h> |
36 | 36 | ||
37 | extern MediaPlayerState *mediaPlayerState; | 37 | extern MediaPlayerState *mediaPlayerState; |
38 | 38 | ||
39 | 39 | ||
40 | static const int xo = -2; // movable x offset | 40 | static const int xo = -2; // movable x offset |
41 | static const int yo = 22; // movable y offset | 41 | static const int yo = 22; // movable y offset |
42 | 42 | ||
43 | struct MediaButton { | 43 | struct MediaButton { |
44 | bool isToggle, isHeld, isDown; | 44 | bool isToggle, isHeld, isDown; |
45 | }; | 45 | }; |
46 | 46 | ||
47 | //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) |
48 | MediaButton audioButtons[] = { | 48 | MediaButton audioButtons[] = { |
49 | { TRUE, FALSE, FALSE }, // play | 49 | { TRUE, FALSE, FALSE }, // play |
50 | { FALSE, FALSE, FALSE }, // stop | 50 | { FALSE, FALSE, FALSE }, // stop |
51 | { FALSE, FALSE, FALSE }, // next | 51 | { FALSE, FALSE, FALSE }, // next |
52 | { FALSE, FALSE, FALSE }, // previous | 52 | { FALSE, FALSE, FALSE }, // previous |
53 | { FALSE, FALSE, FALSE }, // volume up | 53 | { FALSE, FALSE, FALSE }, // volume up |
54 | { FALSE, FALSE, FALSE }, // volume down | 54 | { FALSE, FALSE, FALSE }, // volume down |
55 | { TRUE, FALSE, FALSE }, // repeat/loop | 55 | { TRUE, FALSE, FALSE }, // repeat/loop |
56 | { FALSE, FALSE, FALSE }, // playlist | 56 | { FALSE, FALSE, FALSE }, // playlist |
57 | { FALSE, FALSE, FALSE }, // forward | 57 | { FALSE, FALSE, FALSE }, // forward |
58 | { FALSE, FALSE, FALSE } // back | 58 | { FALSE, FALSE, FALSE } // back |
59 | }; | 59 | }; |
60 | 60 | ||
61 | const char *skin_mask_file_names[10] = { | 61 | const char *skin_mask_file_names[10] = { |
62 | "play", "stop", "next", "prev", "up", | 62 | "play", "stop", "next", "prev", "up", |
63 | "down", "loop", "playlist", "forward", "back" | 63 | "down", "loop", "playlist", "forward", "back" |
64 | }; | 64 | }; |
65 | 65 | ||
66 | static void changeTextColor( QWidget *w ) { | 66 | static void changeTextColor( QWidget *w ) { |
67 | QPalette p = w->palette(); | 67 | QPalette p = w->palette(); |
68 | p.setBrush( QColorGroup::Background, QColor( 167, 212, 167 ) ); | 68 | p.setBrush( QColorGroup::Background, QColor( 167, 212, 167 ) ); |
69 | p.setBrush( QColorGroup::Base, QColor( 167, 212, 167 ) ); | 69 | p.setBrush( QColorGroup::Base, QColor( 167, 212, 167 ) ); |
70 | w->setPalette( p ); | 70 | w->setPalette( p ); |
71 | } | 71 | } |
72 | 72 | ||
73 | static const int numButtons = (sizeof(audioButtons)/sizeof(MediaButton)); | 73 | static const int numButtons = (sizeof(audioButtons)/sizeof(MediaButton)); |
74 | 74 | ||
75 | AudioWidget::AudioWidget(QWidget* parent, const char* name, WFlags f) : | 75 | AudioWidget::AudioWidget(QWidget* parent, const char* name, WFlags f) : |
76 | QWidget( parent, name, f ), songInfo( this ), slider( Qt::Horizontal, this ), time( this ) | 76 | QWidget( parent, name, f ), songInfo( this ), slider( Qt::Horizontal, this ), time( this ) |
77 | { | 77 | { |
78 | setCaption( tr("OpiePlayer") ); | 78 | setCaption( tr("OpiePlayer") ); |
79 | qDebug("<<<<<audioWidget"); | 79 | qDebug("<<<<<audioWidget"); |
80 | 80 | ||
81 | Config cfg("OpiePlayer"); | 81 | Config cfg("OpiePlayer"); |
82 | cfg.setGroup("Options"); | 82 | cfg.setGroup("Options"); |
83 | skin = cfg.readEntry("Skin","default"); | 83 | skin = cfg.readEntry("Skin","default"); |
84 | //skin = "scaleTest"; | 84 | //skin = "scaleTest"; |
85 | // color of background, frame, degree of transparency | 85 | // color of background, frame, degree of transparency |
86 | 86 | ||
87 | // QString skinPath = "opieplayer/skins/" + skin; | 87 | // QString skinPath = "opieplayer/skins/" + skin; |
88 | QString skinPath; | 88 | QString skinPath; |
89 | skinPath = "opieplayer2/skins/" + skin; | 89 | skinPath = "opieplayer2/skins/" + skin; |
90 | if(!QDir(skinPath).exists()) | 90 | if(!QDir(QString(getenv("OPIEDIR")) +"/pics/"+skinPath).exists()) |
91 | skinPath = "opieplayer2/skins/default"; | 91 | skinPath = "opieplayer2/skins/default"; |
92 | 92 | ||
93 | qDebug("skin path " + skinPath); | 93 | qDebug("skin path " + skinPath); |
94 | 94 | ||
95 | pixBg = new QPixmap( Resource::loadPixmap( QString("%1/background").arg(skinPath) ) ); | 95 | pixBg = new QPixmap( Resource::loadPixmap( QString("%1/background").arg(skinPath) ) ); |
96 | imgUp = new QImage( Resource::loadImage( QString("%1/skin_up").arg(skinPath) ) ); | 96 | imgUp = new QImage( Resource::loadImage( QString("%1/skin_up").arg(skinPath) ) ); |
97 | imgDn = new QImage( Resource::loadImage( QString("%1/skin_down").arg(skinPath) ) ); | 97 | imgDn = new QImage( Resource::loadImage( QString("%1/skin_down").arg(skinPath) ) ); |
98 | 98 | ||
99 | imgButtonMask = new QImage( imgUp->width(), imgUp->height(), 8, 255 ); | 99 | imgButtonMask = new QImage( imgUp->width(), imgUp->height(), 8, 255 ); |
100 | imgButtonMask->fill( 0 ); | 100 | imgButtonMask->fill( 0 ); |
101 | 101 | ||
102 | for ( int i = 0; i < 10; i++ ) { | 102 | for ( int i = 0; i < 10; i++ ) { |
103 | QString filename = QString(getenv("OPIEDIR")) + "/pics/" + skinPath + "/skin_mask_" + skin_mask_file_names[i] + ".png"; | 103 | QString filename = QString(getenv("OPIEDIR")) + "/pics/" + skinPath + "/skin_mask_" + skin_mask_file_names[i] + ".png"; |
104 | masks[i] = new QBitmap( filename ); | 104 | masks[i] = new QBitmap( filename ); |
105 | 105 | ||
106 | if ( !masks[i]->isNull() ) { | 106 | if ( !masks[i]->isNull() ) { |
107 | QImage imgMask = masks[i]->convertToImage(); | 107 | QImage imgMask = masks[i]->convertToImage(); |
108 | uchar **dest = imgButtonMask->jumpTable(); | 108 | uchar **dest = imgButtonMask->jumpTable(); |
109 | for ( int y = 0; y < imgUp->height(); y++ ) { | 109 | for ( int y = 0; y < imgUp->height(); y++ ) { |
110 | uchar *line = dest[y]; | 110 | uchar *line = dest[y]; |
111 | for ( int x = 0; x < imgUp->width(); x++ ) | 111 | for ( int x = 0; x < imgUp->width(); x++ ) |
112 | if ( !qRed( imgMask.pixel( x, y ) ) ) | 112 | if ( !qRed( imgMask.pixel( x, y ) ) ) |
113 | line[x] = i + 1; | 113 | line[x] = i + 1; |
114 | } | 114 | } |
115 | } | 115 | } |
116 | 116 | ||
117 | } | 117 | } |
118 | 118 | ||
119 | for ( int i = 0; i < 11; i++ ) { | 119 | for ( int i = 0; i < 11; i++ ) { |
120 | buttonPixUp[i] = NULL; | 120 | buttonPixUp[i] = NULL; |
121 | buttonPixDown[i] = NULL; | 121 | buttonPixDown[i] = NULL; |
122 | } | 122 | } |
123 | 123 | ||
124 | setBackgroundPixmap( *pixBg ); | 124 | setBackgroundPixmap( *pixBg ); |
125 | 125 | ||
126 | songInfo.setFocusPolicy( QWidget::NoFocus ); | 126 | songInfo.setFocusPolicy( QWidget::NoFocus ); |
127 | 127 | ||
128 | // changeTextColor( &songInfo ); | 128 | // changeTextColor( &songInfo ); |
129 | // songInfo.setBackgroundColor( QColor( 167, 212, 167 )); | 129 | // songInfo.setBackgroundColor( QColor( 167, 212, 167 )); |
130 | // songInfo.setFrameStyle( QFrame::NoFrame); | 130 | // songInfo.setFrameStyle( QFrame::NoFrame); |
131 | // songInfo.setFrameStyle( QFrame::WinPanel | QFrame::Sunken ); | 131 | // songInfo.setFrameStyle( QFrame::WinPanel | QFrame::Sunken ); |
132 | //NoFrame | 132 | //NoFrame |
133 | // songInfo.setForegroundColor(Qt::white); | 133 | // songInfo.setForegroundColor(Qt::white); |
134 | 134 | ||
135 | slider.setFixedHeight( 20 ); | 135 | slider.setFixedHeight( 20 ); |
136 | slider.setMinValue( 0 ); | 136 | slider.setMinValue( 0 ); |
137 | slider.setMaxValue( 1 ); | 137 | slider.setMaxValue( 1 ); |
138 | slider.setFocusPolicy( QWidget::NoFocus ); | 138 | slider.setFocusPolicy( QWidget::NoFocus ); |
139 | slider.setBackgroundPixmap( *pixBg ); | 139 | slider.setBackgroundPixmap( *pixBg ); |
140 | 140 | ||
141 | time.setFocusPolicy( QWidget::NoFocus ); | 141 | time.setFocusPolicy( QWidget::NoFocus ); |
142 | time.setAlignment( Qt::AlignCenter ); | 142 | time.setAlignment( Qt::AlignCenter ); |
143 | time.setFrame(FALSE); | 143 | time.setFrame(FALSE); |
144 | changeTextColor( &time ); | 144 | changeTextColor( &time ); |
145 | 145 | ||
146 | resizeEvent( NULL ); | 146 | resizeEvent( NULL ); |
147 | 147 | ||
148 | connect( &slider, SIGNAL( sliderPressed() ), this, SLOT( sliderPressed() ) ); | 148 | connect( &slider, SIGNAL( sliderPressed() ), this, SLOT( sliderPressed() ) ); |
149 | connect( &slider, SIGNAL( sliderReleased() ), this, SLOT( sliderReleased() ) ); | 149 | connect( &slider, SIGNAL( sliderReleased() ), this, SLOT( sliderReleased() ) ); |
150 | 150 | ||
151 | connect( mediaPlayerState, SIGNAL( lengthChanged(long) ), this, SLOT( setLength(long) ) ); | 151 | connect( mediaPlayerState, SIGNAL( lengthChanged(long) ), this, SLOT( setLength(long) ) ); |
152 | connect( mediaPlayerState, SIGNAL( viewChanged(char) ), this, SLOT( setView(char) ) ); | 152 | connect( mediaPlayerState, SIGNAL( viewChanged(char) ), this, SLOT( setView(char) ) ); |
153 | connect( mediaPlayerState, SIGNAL( loopingToggled(bool) ), this, SLOT( setLooping(bool) ) ); | 153 | connect( mediaPlayerState, SIGNAL( loopingToggled(bool) ), this, SLOT( setLooping(bool) ) ); |
154 | // connect( mediaPlayerState, SIGNAL( pausedToggled(bool) ), this, SLOT( setPaused(bool) ) ); | 154 | // connect( mediaPlayerState, SIGNAL( pausedToggled(bool) ), this, SLOT( setPaused(bool) ) ); |
155 | connect( mediaPlayerState, SIGNAL( playingToggled(bool) ), this, SLOT( setPlaying(bool) ) ); | 155 | connect( mediaPlayerState, SIGNAL( playingToggled(bool) ), this, SLOT( setPlaying(bool) ) ); |
156 | 156 | ||
157 | // Intialise state | 157 | // Intialise state |
158 | setLength( mediaPlayerState->length() ); | 158 | setLength( mediaPlayerState->length() ); |
159 | setPosition( mediaPlayerState->position() ); | 159 | setPosition( mediaPlayerState->position() ); |
160 | setLooping( mediaPlayerState->fullscreen() ); | 160 | setLooping( mediaPlayerState->fullscreen() ); |
161 | // setPaused( mediaPlayerState->paused() ); | 161 | // setPaused( mediaPlayerState->paused() ); |
162 | setPlaying( mediaPlayerState->playing() ); | 162 | setPlaying( mediaPlayerState->playing() ); |
163 | 163 | ||
164 | } | 164 | } |
165 | 165 | ||
166 | 166 | ||
167 | AudioWidget::~AudioWidget() { | 167 | AudioWidget::~AudioWidget() { |
168 | 168 | ||
169 | for ( int i = 0; i < 10; i++ ) { | 169 | for ( int i = 0; i < 10; i++ ) { |
170 | delete buttonPixUp[i]; | 170 | delete buttonPixUp[i]; |
171 | delete buttonPixDown[i]; | 171 | delete buttonPixDown[i]; |
172 | } | 172 | } |
173 | delete pixBg; | 173 | delete pixBg; |
174 | delete imgUp; | 174 | delete imgUp; |
175 | delete imgDn; | 175 | delete imgDn; |
176 | delete imgButtonMask; | 176 | delete imgButtonMask; |
177 | for ( int i = 0; i < 10; i++ ) { | 177 | for ( int i = 0; i < 10; i++ ) { |
178 | delete masks[i]; | 178 | delete masks[i]; |
179 | } | 179 | } |
180 | } | 180 | } |
181 | 181 | ||
182 | 182 | ||
183 | QPixmap *combineImageWithBackground( QImage img, QPixmap bg, QPoint offset ) { | 183 | QPixmap *combineImageWithBackground( QImage img, QPixmap bg, QPoint offset ) { |
184 | QPixmap pix( img.width(), img.height() ); | 184 | QPixmap pix( img.width(), img.height() ); |
185 | QPainter p( &pix ); | 185 | QPainter p( &pix ); |
186 | p.drawTiledPixmap( pix.rect(), bg, offset ); | 186 | p.drawTiledPixmap( pix.rect(), bg, offset ); |
187 | p.drawImage( 0, 0, img ); | 187 | p.drawImage( 0, 0, img ); |
188 | return new QPixmap( pix ); | 188 | return new QPixmap( pix ); |
189 | } | 189 | } |
190 | 190 | ||
191 | 191 | ||
192 | QPixmap *maskPixToMask( QPixmap pix, QBitmap mask ) | 192 | QPixmap *maskPixToMask( QPixmap pix, QBitmap mask ) |
193 | { | 193 | { |
194 | QPixmap *pixmap = new QPixmap( pix ); | 194 | QPixmap *pixmap = new QPixmap( pix ); |
195 | pixmap->setMask( mask ); | 195 | pixmap->setMask( mask ); |
196 | return pixmap; | 196 | return pixmap; |
197 | } | 197 | } |
198 | 198 | ||
199 | 199 | ||
200 | 200 | ||
201 | void AudioWidget::resizeEvent( QResizeEvent * ) { | 201 | void AudioWidget::resizeEvent( QResizeEvent * ) { |
202 | int h = height(); | 202 | int h = height(); |
203 | int w = width(); | 203 | int w = width(); |
204 | 204 | ||
205 | songInfo.setGeometry( QRect( 2, 10, w - 4, 20 ) ); | 205 | songInfo.setGeometry( QRect( 2, 10, w - 4, 20 ) ); |
206 | slider.setFixedWidth( w - 110 ); | 206 | slider.setFixedWidth( w - 110 ); |
207 | slider.setGeometry( QRect( 15, h - 30, w - 90, 20 ) ); | 207 | slider.setGeometry( QRect( 15, h - 30, w - 90, 20 ) ); |
208 | slider.setBackgroundOrigin( QWidget::ParentOrigin ); | 208 | slider.setBackgroundOrigin( QWidget::ParentOrigin ); |
209 | time.setGeometry( QRect( w - 85, h - 30, 70, 20 ) ); | 209 | time.setGeometry( QRect( w - 85, h - 30, 70, 20 ) ); |
210 | 210 | ||
211 | xoff = ( w - imgUp->width() ) / 2; | 211 | xoff = ( w - imgUp->width() ) / 2; |
212 | yoff = (( h - imgUp->height() ) / 2) - 10; | 212 | yoff = (( h - imgUp->height() ) / 2) - 10; |
213 | QPoint p( xoff, yoff ); | 213 | QPoint p( xoff, yoff ); |
214 | 214 | ||
215 | QPixmap *pixUp = combineImageWithBackground( *imgUp, *pixBg, p ); | 215 | QPixmap *pixUp = combineImageWithBackground( *imgUp, *pixBg, p ); |
216 | QPixmap *pixDn = combineImageWithBackground( *imgDn, *pixBg, p ); | 216 | QPixmap *pixDn = combineImageWithBackground( *imgDn, *pixBg, p ); |
217 | 217 | ||
218 | for ( int i = 0; i < 10; i++ ) { | 218 | for ( int i = 0; i < 10; i++ ) { |
219 | if ( !masks[i]->isNull() ) { | 219 | if ( !masks[i]->isNull() ) { |
220 | delete buttonPixUp[i]; | 220 | delete buttonPixUp[i]; |
221 | delete buttonPixDown[i]; | 221 | delete buttonPixDown[i]; |
222 | buttonPixUp[i] = maskPixToMask( *pixUp, *masks[i] ); | 222 | buttonPixUp[i] = maskPixToMask( *pixUp, *masks[i] ); |
223 | buttonPixDown[i] = maskPixToMask( *pixDn, *masks[i] ); | 223 | buttonPixDown[i] = maskPixToMask( *pixDn, *masks[i] ); |
224 | } | 224 | } |
225 | } | 225 | } |
226 | 226 | ||
227 | delete pixUp; | 227 | delete pixUp; |
228 | delete pixDn; | 228 | delete pixDn; |
229 | } | 229 | } |
230 | 230 | ||
231 | 231 | ||
232 | static bool audioSliderBeingMoved = FALSE; | 232 | static bool audioSliderBeingMoved = FALSE; |
233 | 233 | ||
234 | void AudioWidget::sliderPressed() { | 234 | void AudioWidget::sliderPressed() { |
235 | audioSliderBeingMoved = TRUE; | 235 | audioSliderBeingMoved = TRUE; |
236 | } | 236 | } |
237 | 237 | ||
238 | 238 | ||
239 | void AudioWidget::sliderReleased() { | 239 | void AudioWidget::sliderReleased() { |
240 | audioSliderBeingMoved = FALSE; | 240 | audioSliderBeingMoved = FALSE; |
241 | if ( slider.width() == 0 ) | 241 | if ( slider.width() == 0 ) |
242 | return; | 242 | return; |
243 | long val = long((double)slider.value() * mediaPlayerState->length() / slider.width()); | 243 | long val = long((double)slider.value() * mediaPlayerState->length() / slider.width()); |
244 | mediaPlayerState->setPosition( val ); | 244 | mediaPlayerState->setPosition( val ); |
245 | } | 245 | } |
246 | 246 | ||
247 | 247 | ||
248 | void AudioWidget::setPosition( long i ) { | 248 | void AudioWidget::setPosition( long i ) { |
249 | // qDebug("set position %d",i); | 249 | // qDebug("set position %d",i); |
250 | long length = mediaPlayerState->length(); | 250 | long length = mediaPlayerState->length(); |
251 | updateSlider( i, length ); | 251 | updateSlider( i, length ); |
252 | } | 252 | } |
253 | 253 | ||
254 | 254 | ||
255 | void AudioWidget::setLength( long max ) { | 255 | void AudioWidget::setLength( long max ) { |
256 | updateSlider( mediaPlayerState->position(), max ); | 256 | updateSlider( mediaPlayerState->position(), max ); |
257 | } | 257 | } |
258 | 258 | ||
259 | 259 | ||
260 | void AudioWidget::setView( char view ) { | 260 | void AudioWidget::setView( char view ) { |
261 | 261 | ||
262 | if (mediaPlayerState->isStreaming) { | 262 | if (mediaPlayerState->isStreaming) { |
263 | if( !slider.isHidden()) slider.hide(); | 263 | if( !slider.isHidden()) slider.hide(); |
264 | disconnect( mediaPlayerState, SIGNAL( positionChanged(long) ),this, SLOT( setPosition(long) ) ); | 264 | disconnect( mediaPlayerState, SIGNAL( positionChanged(long) ),this, SLOT( setPosition(long) ) ); |
265 | disconnect( mediaPlayerState, SIGNAL( positionUpdated(long) ),this, SLOT( setPosition(long) ) ); | 265 | disconnect( mediaPlayerState, SIGNAL( positionUpdated(long) ),this, SLOT( setPosition(long) ) ); |
266 | } else { | 266 | } else { |
267 | // this stops the slider from being moved, thus | 267 | // this stops the slider from being moved, thus |
268 | // does not stop stream when it reaches the end | 268 | // does not stop stream when it reaches the end |
269 | slider.show(); | 269 | slider.show(); |
270 | connect( mediaPlayerState, SIGNAL( positionChanged(long) ),this, SLOT( setPosition(long) ) ); | 270 | connect( mediaPlayerState, SIGNAL( positionChanged(long) ),this, SLOT( setPosition(long) ) ); |
271 | connect( mediaPlayerState, SIGNAL( positionUpdated(long) ),this, SLOT( setPosition(long) ) ); | 271 | connect( mediaPlayerState, SIGNAL( positionUpdated(long) ),this, SLOT( setPosition(long) ) ); |
272 | } | 272 | } |
273 | 273 | ||
274 | if ( view == 'a' ) { | 274 | if ( view == 'a' ) { |
275 | startTimer( 150 ); | 275 | startTimer( 150 ); |
276 | // show(); | 276 | // show(); |
277 | showMaximized(); | 277 | showMaximized(); |
278 | } else { | 278 | } else { |
279 | killTimers(); | 279 | killTimers(); |
280 | hide(); | 280 | hide(); |
281 | } | 281 | } |
282 | } | 282 | } |
283 | 283 | ||
284 | 284 | ||
285 | static QString timeAsString( long length ) { | 285 | static QString timeAsString( long length ) { |
286 | length /= 44100; | 286 | length /= 44100; |
287 | int minutes = length / 60; | 287 | int minutes = length / 60; |
288 | int seconds = length % 60; | 288 | int seconds = length % 60; |
289 | return QString("%1:%2%3").arg( minutes ).arg( seconds / 10 ).arg( seconds % 10 ); | 289 | return QString("%1:%2%3").arg( minutes ).arg( seconds / 10 ).arg( seconds % 10 ); |
290 | } | 290 | } |
291 | 291 | ||
292 | void AudioWidget::updateSlider( long i, long max ) { | 292 | void AudioWidget::updateSlider( long i, long max ) { |
293 | time.setText( timeAsString( i ) + " / " + timeAsString( max ) ); | 293 | time.setText( timeAsString( i ) + " / " + timeAsString( max ) ); |
294 | 294 | ||
295 | if ( max == 0 ) | 295 | if ( max == 0 ) |
296 | return; | 296 | return; |
297 | // Will flicker too much if we don't do this | 297 | // Will flicker too much if we don't do this |
298 | // Scale to something reasonable | 298 | // Scale to something reasonable |
299 | int width = slider.width(); | 299 | int width = slider.width(); |
300 | int val = int((double)i * width / max); | 300 | int val = int((double)i * width / max); |
301 | if ( !audioSliderBeingMoved ) { | 301 | if ( !audioSliderBeingMoved ) { |
302 | if ( slider.value() != val ) | 302 | if ( slider.value() != val ) |
303 | slider.setValue( val ); | 303 | slider.setValue( val ); |
304 | if ( slider.maxValue() != width ) | 304 | if ( slider.maxValue() != width ) |
305 | slider.setMaxValue( width ); | 305 | slider.setMaxValue( width ); |
306 | } | 306 | } |
307 | } | 307 | } |
308 | 308 | ||
309 | 309 | ||
310 | void AudioWidget::setToggleButton( int i, bool down ) { | 310 | void AudioWidget::setToggleButton( int i, bool down ) { |
311 | if ( down != audioButtons[i].isDown ) | 311 | if ( down != audioButtons[i].isDown ) |
312 | toggleButton( i ); | 312 | toggleButton( i ); |
313 | } | 313 | } |
314 | 314 | ||
315 | 315 | ||
316 | void AudioWidget::toggleButton( int i ) { | 316 | void AudioWidget::toggleButton( int i ) { |
317 | audioButtons[i].isDown = !audioButtons[i].isDown; | 317 | audioButtons[i].isDown = !audioButtons[i].isDown; |
318 | QPainter p(this); | 318 | QPainter p(this); |
319 | paintButton ( &p, i ); | 319 | paintButton ( &p, i ); |
320 | } | 320 | } |
321 | 321 | ||
322 | 322 | ||
323 | void AudioWidget::paintButton( QPainter *p, int i ) { | 323 | void AudioWidget::paintButton( QPainter *p, int i ) { |
324 | if ( audioButtons[i].isDown ) | 324 | if ( audioButtons[i].isDown ) |
325 | p->drawPixmap( xoff, yoff, *buttonPixDown[i] ); | 325 | p->drawPixmap( xoff, yoff, *buttonPixDown[i] ); |
326 | else | 326 | else |
327 | p->drawPixmap( xoff, yoff, *buttonPixUp[i] ); | 327 | p->drawPixmap( xoff, yoff, *buttonPixUp[i] ); |
328 | } | 328 | } |
329 | 329 | ||
330 | 330 | ||
331 | void AudioWidget::timerEvent( QTimerEvent * ) { | 331 | void AudioWidget::timerEvent( QTimerEvent * ) { |
332 | /* | 332 | /* |
333 | int x = audioButtons[AudioPlay].xPos; | 333 | int x = audioButtons[AudioPlay].xPos; |
334 | int y = audioButtons[AudioPlay].yPos; | 334 | int y = audioButtons[AudioPlay].yPos; |
335 | QPainter p( this ); | 335 | QPainter p( this ); |
336 | // Optimize to only draw the little bit of the changing images which is different | 336 | // Optimize to only draw the little bit of the changing images which is different |
337 | p.drawPixmap( x + 14, y + 8, *pixmaps[3], 32 * frame, 0, 32, 32 ); | 337 | p.drawPixmap( x + 14, y + 8, *pixmaps[3], 32 * frame, 0, 32, 32 ); |
338 | p.drawPixmap( x + 37, y + 37, *pixmaps[2], 18 * AudioPlay, 0, 6, 3 ); | 338 | p.drawPixmap( x + 37, y + 37, *pixmaps[2], 18 * AudioPlay, 0, 6, 3 ); |
339 | */ | 339 | */ |
340 | /* | 340 | /* |
341 | static int frame = 0; | 341 | static int frame = 0; |
342 | if ( !mediaPlayerState->paused() && audioButtons[ AudioPlay ].isDown ) { | 342 | if ( !mediaPlayerState->paused() && audioButtons[ AudioPlay ].isDown ) { |
343 | frame = frame >= 7 ? 0 : frame + 1; | 343 | frame = frame >= 7 ? 0 : frame + 1; |
344 | } | 344 | } |
345 | */ | 345 | */ |
346 | } | 346 | } |
347 | 347 | ||
348 | 348 | ||
349 | void AudioWidget::mouseMoveEvent( QMouseEvent *event ) { | 349 | void AudioWidget::mouseMoveEvent( QMouseEvent *event ) { |
350 | for ( int i = 0; i < numButtons; i++ ) { | 350 | for ( int i = 0; i < numButtons; i++ ) { |
351 | if ( event->state() == QMouseEvent::LeftButton ) { | 351 | if ( event->state() == QMouseEvent::LeftButton ) { |
352 | 352 | ||
353 | // The test to see if the mouse click is inside the button or not | 353 | // The test to see if the mouse click is inside the button or not |
354 | int x = event->pos().x() - xoff; | 354 | int x = event->pos().x() - xoff; |
355 | int y = event->pos().y() - yoff; | 355 | int y = event->pos().y() - yoff; |
356 | 356 | ||
357 | bool isOnButton = ( x > 0 && y > 0 && x < imgButtonMask->width() | 357 | bool isOnButton = ( x > 0 && y > 0 && x < imgButtonMask->width() |
358 | && y < imgButtonMask->height() && imgButtonMask->pixelIndex( x, y ) == i + 1 ); | 358 | && y < imgButtonMask->height() && imgButtonMask->pixelIndex( x, y ) == i + 1 ); |
359 | 359 | ||
360 | if ( isOnButton && i == AudioVolumeUp ) | 360 | if ( isOnButton && i == AudioVolumeUp ) |
361 | qDebug("on up"); | 361 | qDebug("on up"); |
362 | 362 | ||
363 | if ( isOnButton && !audioButtons[i].isHeld ) { | 363 | if ( isOnButton && !audioButtons[i].isHeld ) { |
364 | audioButtons[i].isHeld = TRUE; | 364 | audioButtons[i].isHeld = TRUE; |
365 | toggleButton(i); | 365 | toggleButton(i); |
366 | switch (i) { | 366 | switch (i) { |
367 | case AudioVolumeUp: | 367 | case AudioVolumeUp: |
368 | qDebug("more clicked"); | 368 | qDebug("more clicked"); |
369 | emit moreClicked(); | 369 | emit moreClicked(); |
370 | return; | 370 | return; |
371 | case AudioVolumeDown: | 371 | case AudioVolumeDown: |
372 | qDebug("less clicked"); | 372 | qDebug("less clicked"); |
373 | emit lessClicked(); | 373 | emit lessClicked(); |
374 | return; | 374 | return; |
375 | case AudioForward: | 375 | case AudioForward: |
376 | emit forwardClicked(); | 376 | emit forwardClicked(); |
377 | return; | 377 | return; |
378 | case AudioBack: | 378 | case AudioBack: |
379 | emit backClicked(); | 379 | emit backClicked(); |
380 | return; | 380 | return; |
381 | } | 381 | } |
382 | } else if ( !isOnButton && audioButtons[i].isHeld ) { | 382 | } else if ( !isOnButton && audioButtons[i].isHeld ) { |
383 | audioButtons[i].isHeld = FALSE; | 383 | audioButtons[i].isHeld = FALSE; |
384 | toggleButton(i); | 384 | toggleButton(i); |
385 | } | 385 | } |
386 | } else { | 386 | } else { |
387 | if ( audioButtons[i].isHeld ) { | 387 | if ( audioButtons[i].isHeld ) { |
388 | audioButtons[i].isHeld = FALSE; | 388 | audioButtons[i].isHeld = FALSE; |
389 | if ( !audioButtons[i].isToggle ) | 389 | if ( !audioButtons[i].isToggle ) |
390 | setToggleButton( i, FALSE ); | 390 | setToggleButton( i, FALSE ); |
391 | switch (i) { | 391 | switch (i) { |
392 | case AudioPlay: | 392 | case AudioPlay: |
393 | if( mediaPlayerState->isPaused ) { | 393 | if( mediaPlayerState->isPaused ) { |
394 | mediaPlayerState->setPaused( FALSE ); | 394 | mediaPlayerState->setPaused( FALSE ); |
395 | return; | 395 | return; |
396 | } else if( !mediaPlayerState->isPaused ) { | 396 | } else if( !mediaPlayerState->isPaused ) { |
397 | mediaPlayerState->setPaused( TRUE ); | 397 | mediaPlayerState->setPaused( TRUE ); |
398 | return; | 398 | return; |
399 | } | 399 | } |
400 | // case AudioPlay: mediaPlayerState->setPlaying(audioButtons[i].isDown); return; | 400 | // case AudioPlay: mediaPlayerState->setPlaying(audioButtons[i].isDown); return; |
401 | case AudioStop: mediaPlayerState->setPlaying(FALSE); return; | 401 | case AudioStop: mediaPlayerState->setPlaying(FALSE); return; |
402 | // case AudioPause: mediaPlayerState->setPaused(audioButtons[i].isDown); return; | 402 | // case AudioPause: mediaPlayerState->setPaused(audioButtons[i].isDown); return; |
403 | case AudioNext: mediaPlayerState->setNext(); return; | 403 | case AudioNext: mediaPlayerState->setNext(); return; |
404 | case AudioPrevious: mediaPlayerState->setPrev(); return; | 404 | case AudioPrevious: mediaPlayerState->setPrev(); return; |
405 | case AudioLoop: mediaPlayerState->setLooping(audioButtons[i].isDown); return; | 405 | case AudioLoop: mediaPlayerState->setLooping(audioButtons[i].isDown); return; |
406 | case AudioVolumeUp: emit moreReleased(); return; | 406 | case AudioVolumeUp: emit moreReleased(); return; |
407 | case AudioVolumeDown: emit lessReleased(); return; | 407 | case AudioVolumeDown: emit lessReleased(); return; |
408 | case AudioPlayList: mediaPlayerState->setList(); return; | 408 | case AudioPlayList: mediaPlayerState->setList(); return; |
409 | } | 409 | } |
410 | } | 410 | } |
411 | } | 411 | } |
412 | } | 412 | } |
413 | } | 413 | } |
414 | 414 | ||
415 | 415 | ||
416 | 416 | ||
417 | void AudioWidget::mousePressEvent( QMouseEvent *event ) { | 417 | void AudioWidget::mousePressEvent( QMouseEvent *event ) { |
418 | mouseMoveEvent( event ); | 418 | mouseMoveEvent( event ); |
419 | } | 419 | } |
420 | 420 | ||
421 | 421 | ||
422 | void AudioWidget::mouseReleaseEvent( QMouseEvent *event ) { | 422 | void AudioWidget::mouseReleaseEvent( QMouseEvent *event ) { |
423 | mouseMoveEvent( event ); | 423 | mouseMoveEvent( event ); |
424 | } | 424 | } |
425 | 425 | ||
426 | 426 | ||
427 | void AudioWidget::showEvent( QShowEvent* ) { | 427 | void AudioWidget::showEvent( QShowEvent* ) { |
428 | QMouseEvent event( QEvent::MouseMove, QPoint( 0, 0 ), 0, 0 ); | 428 | QMouseEvent event( QEvent::MouseMove, QPoint( 0, 0 ), 0, 0 ); |
429 | mouseMoveEvent( &event ); | 429 | mouseMoveEvent( &event ); |
430 | } | 430 | } |
431 | 431 | ||
432 | 432 | ||
433 | void AudioWidget::closeEvent( QCloseEvent* ) { | 433 | void AudioWidget::closeEvent( QCloseEvent* ) { |
434 | mediaPlayerState->setList(); | 434 | mediaPlayerState->setList(); |
435 | } | 435 | } |
436 | 436 | ||
437 | 437 | ||
438 | void AudioWidget::paintEvent( QPaintEvent * pe) { | 438 | void AudioWidget::paintEvent( QPaintEvent * pe) { |
439 | if ( !pe->erased() ) { | 439 | if ( !pe->erased() ) { |
440 | // Combine with background and double buffer | 440 | // Combine with background and double buffer |
441 | QPixmap pix( pe->rect().size() ); | 441 | QPixmap pix( pe->rect().size() ); |
442 | QPainter p( &pix ); | 442 | QPainter p( &pix ); |
443 | p.translate( -pe->rect().topLeft().x(), -pe->rect().topLeft().y() ); | 443 | p.translate( -pe->rect().topLeft().x(), -pe->rect().topLeft().y() ); |
444 | p.drawTiledPixmap( pe->rect(), *pixBg, pe->rect().topLeft() ); | 444 | p.drawTiledPixmap( pe->rect(), *pixBg, pe->rect().topLeft() ); |
445 | for ( int i = 0; i < numButtons; i++ ) | 445 | for ( int i = 0; i < numButtons; i++ ) |
446 | paintButton( &p, i ); | 446 | paintButton( &p, i ); |
447 | QPainter p2( this ); | 447 | QPainter p2( this ); |
448 | p2.drawPixmap( pe->rect().topLeft(), pix ); | 448 | p2.drawPixmap( pe->rect().topLeft(), pix ); |
449 | } else { | 449 | } else { |
450 | QPainter p( this ); | 450 | QPainter p( this ); |
451 | for ( int i = 0; i < numButtons; i++ ) | 451 | for ( int i = 0; i < numButtons; i++ ) |
452 | paintButton( &p, i ); | 452 | paintButton( &p, i ); |
453 | } | 453 | } |
454 | } | 454 | } |
455 | 455 | ||
456 | void AudioWidget::keyReleaseEvent( QKeyEvent *e) | 456 | void AudioWidget::keyReleaseEvent( QKeyEvent *e) |
457 | { | 457 | { |
458 | switch ( e->key() ) { | 458 | switch ( e->key() ) { |
459 | ////////////////////////////// Zaurus keys | 459 | ////////////////////////////// Zaurus keys |
460 | case Key_Home: | 460 | case Key_Home: |
461 | break; | 461 | break; |
462 | case Key_F9: //activity | 462 | case Key_F9: //activity |
463 | hide(); | 463 | hide(); |
464 | // qDebug("Audio F9"); | 464 | // qDebug("Audio F9"); |
465 | break; | 465 | break; |
466 | case Key_F10: //contacts | 466 | case Key_F10: //contacts |
467 | break; | 467 | break; |
468 | case Key_F11: //menu | 468 | case Key_F11: //menu |
469 | break; | 469 | break; |
470 | case Key_F12: //home | 470 | case Key_F12: //home |
471 | break; | 471 | break; |
472 | case Key_F13: //mail | 472 | case Key_F13: //mail |
473 | break; | 473 | break; |
474 | case Key_Space: { | 474 | case Key_Space: { |
475 | 475 | ||
476 | if(mediaPlayerState->playing()) { | 476 | if(mediaPlayerState->playing()) { |
477 | // toggleButton(1); | 477 | // toggleButton(1); |
478 | mediaPlayerState->setPlaying(FALSE); | 478 | mediaPlayerState->setPlaying(FALSE); |
479 | // toggleButton(1); | 479 | // toggleButton(1); |
480 | } else { | 480 | } else { |
481 | // toggleButton(0); | 481 | // toggleButton(0); |
482 | mediaPlayerState->setPlaying(TRUE); | 482 | mediaPlayerState->setPlaying(TRUE); |
483 | // toggleButton(0); | 483 | // toggleButton(0); |
484 | } | 484 | } |
485 | } | 485 | } |
486 | break; | 486 | break; |
487 | case Key_Down: //volume | 487 | case Key_Down: //volume |
488 | // toggleButton(6); | 488 | // toggleButton(6); |
489 | emit lessClicked(); | 489 | emit lessClicked(); |
490 | emit lessReleased(); | 490 | emit lessReleased(); |
491 | // toggleButton(6); | 491 | // toggleButton(6); |
492 | break; | 492 | break; |
493 | case Key_Up: //volume | 493 | case Key_Up: //volume |
494 | // toggleButton(5); | 494 | // toggleButton(5); |
495 | emit moreClicked(); | 495 | emit moreClicked(); |
496 | emit moreReleased(); | 496 | emit moreReleased(); |
497 | // toggleButton(5); | 497 | // toggleButton(5); |
498 | break; | 498 | break; |
499 | case Key_Right: //next in playlist | 499 | case Key_Right: //next in playlist |
500 | // toggleButton(3); | 500 | // toggleButton(3); |
501 | mediaPlayerState->setNext(); | 501 | mediaPlayerState->setNext(); |
502 | // toggleButton(3); | 502 | // toggleButton(3); |
503 | break; | 503 | break; |
504 | case Key_Left: // previous in playlist | 504 | case Key_Left: // previous in playlist |
505 | // toggleButton(4); | 505 | // toggleButton(4); |
506 | mediaPlayerState->setPrev(); | 506 | mediaPlayerState->setPrev(); |
507 | // toggleButton(4); | 507 | // toggleButton(4); |
508 | break; | 508 | break; |
509 | case Key_Escape: | 509 | case Key_Escape: |
510 | break; | 510 | break; |
511 | 511 | ||
512 | }; | 512 | }; |
513 | } | 513 | } |