summaryrefslogtreecommitdiff
authorllornkcor <llornkcor>2004-06-16 09:37:59 (UTC)
committer llornkcor <llornkcor>2004-06-16 09:37:59 (UTC)
commit4386dec4cc1b5ef3272b9aba352dfa6fba6a4e06 (patch) (unidiff)
treebcfa76b6b25e8a341309545eb26cdcceae79d159
parent334da0ef825f861792a12f9b51201ed81b491cec (diff)
downloadopie-4386dec4cc1b5ef3272b9aba352dfa6fba6a4e06.zip
opie-4386dec4cc1b5ef3272b9aba352dfa6fba6a4e06.tar.gz
opie-4386dec4cc1b5ef3272b9aba352dfa6fba6a4e06.tar.bz2
fix position error
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/multimedia/opieplayer/audiowidget.cpp4
1 files changed, 3 insertions, 1 deletions
diff --git a/core/multimedia/opieplayer/audiowidget.cpp b/core/multimedia/opieplayer/audiowidget.cpp
index 376f8d3..d135647 100644
--- a/core/multimedia/opieplayer/audiowidget.cpp
+++ b/core/multimedia/opieplayer/audiowidget.cpp
@@ -1,430 +1,432 @@
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 "audiowidget.h" 20#include "audiowidget.h"
21#include "mediaplayerstate.h" 21#include "mediaplayerstate.h"
22 22
23/* OPIE */ 23/* OPIE */
24#include <qpe/qpeapplication.h> 24#include <qpe/qpeapplication.h>
25#include <qpe/resource.h> 25#include <qpe/resource.h>
26#include <qpe/config.h> 26#include <qpe/config.h>
27#include <opie2/odebug.h> 27#include <opie2/odebug.h>
28 28
29/* QT */ 29/* QT */
30#include <qdir.h> 30#include <qdir.h>
31 31
32/* STD */ 32/* STD */
33#include <stdlib.h> 33#include <stdlib.h>
34#include <stdio.h> 34#include <stdio.h>
35 35
36extern MediaPlayerState *mediaPlayerState; 36extern MediaPlayerState *mediaPlayerState;
37 37
38 38
39static const int xo = -2; // movable x offset 39static const int xo = -2; // movable x offset
40static const int yo = 22; // movable y offset 40static const int yo = 22; // movable y offset
41 41
42using namespace Opie::Ui; 42using namespace Opie::Ui;
43struct MediaButton { 43struct 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)
48MediaButton audioButtons[] = { 48MediaButton 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
61const char *skin_mask_file_names[10] = { 61const 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
66static void changeTextColor( QWidget *w ) { 66static 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
73static const int numButtons = (sizeof(audioButtons)/sizeof(MediaButton)); 73static const int numButtons = (sizeof(audioButtons)/sizeof(MediaButton));
74 74
75AudioWidget::AudioWidget(QWidget* parent, const char* name, WFlags f) : 75AudioWidget::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 // odebug << "<<<<<audioWidget" << oendl; 79 // odebug << "<<<<<audioWidget" << oendl;
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(QString(getenv("OPIEDIR")) +"/pics/"+skinPath).exists()) 90 if(!QDir(QString(getenv("OPIEDIR")) +"/pics/"+skinPath).exists())
91 skinPath = "opieplayer2/skins/default"; 91 skinPath = "opieplayer2/skins/default";
92 92
93 // odebug << "skin path " + skinPath << oendl; 93 // odebug << "skin path " + skinPath << oendl;
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 QWidget *d = QApplication::desktop(); 124 QWidget *d = QApplication::desktop();
125 int width = d->width(); 125 int width = d->width();
126 int height = d->height(); 126 int height = d->height();
127 127
128 if( (width != pixBg->width() ) || (height != pixBg->height() ) ) { 128 if( (width != pixBg->width() ) || (height != pixBg->height() ) ) {
129// odebug << "<<<<<<<< scale image >>>>>>>>>>>>" << oendl; 129// odebug << "<<<<<<<< scale image >>>>>>>>>>>>" << oendl;
130 QImage img; 130 QImage img;
131 img = pixBg->convertToImage(); 131 img = pixBg->convertToImage();
132 pixBg->convertFromImage( img.smoothScale( width, height)); 132 pixBg->convertFromImage( img.smoothScale( width, height));
133 } 133 }
134 setBackgroundPixmap( *pixBg); 134 setBackgroundPixmap( *pixBg);
135 135
136 songInfo.setFocusPolicy( QWidget::NoFocus ); 136 songInfo.setFocusPolicy( QWidget::NoFocus );
137 137
138// changeTextColor( &songInfo ); 138// changeTextColor( &songInfo );
139// songInfo.setBackgroundColor( QColor( 167, 212, 167 )); 139// songInfo.setBackgroundColor( QColor( 167, 212, 167 ));
140// songInfo.setFrameStyle( QFrame::NoFrame); 140// songInfo.setFrameStyle( QFrame::NoFrame);
141// songInfo.setFrameStyle( QFrame::WinPanel | QFrame::Sunken ); 141// songInfo.setFrameStyle( QFrame::WinPanel | QFrame::Sunken );
142 //NoFrame 142 //NoFrame
143// songInfo.setForegroundColor(Qt::white); 143// songInfo.setForegroundColor(Qt::white);
144 144
145 slider.setFixedHeight( 20 ); 145 slider.setFixedHeight( 20 );
146 slider.setMinValue( 0 ); 146 slider.setMinValue( 0 );
147 slider.setMaxValue( 1 ); 147 slider.setMaxValue( 1 );
148 slider.setFocusPolicy( QWidget::NoFocus ); 148 slider.setFocusPolicy( QWidget::NoFocus );
149 149
150 slider.setBackgroundPixmap( *pixBg ); 150 slider.setBackgroundPixmap( *pixBg );
151 151
152 time.setFocusPolicy( QWidget::NoFocus ); 152 time.setFocusPolicy( QWidget::NoFocus );
153 time.setAlignment( Qt::AlignCenter ); 153 time.setAlignment( Qt::AlignCenter );
154 time.setFrame(FALSE); 154 time.setFrame(FALSE);
155 changeTextColor( &time ); 155 changeTextColor( &time );
156 156
157 resizeEvent( NULL ); 157 resizeEvent( NULL );
158 158
159 connect( &slider, SIGNAL( sliderPressed() ), this, SLOT( sliderPressed() ) ); 159 connect( &slider, SIGNAL( sliderPressed() ), this, SLOT( sliderPressed() ) );
160 connect( &slider, SIGNAL( sliderReleased() ), this, SLOT( sliderReleased() ) ); 160 connect( &slider, SIGNAL( sliderReleased() ), this, SLOT( sliderReleased() ) );
161 161
162 connect( mediaPlayerState, SIGNAL( lengthChanged(long) ), this, SLOT( setLength(long) ) ); 162 connect( mediaPlayerState, SIGNAL( lengthChanged(long) ), this, SLOT( setLength(long) ) );
163 connect( mediaPlayerState, SIGNAL( viewChanged(char) ), this, SLOT( setView(char) ) ); 163 connect( mediaPlayerState, SIGNAL( viewChanged(char) ), this, SLOT( setView(char) ) );
164 connect( mediaPlayerState, SIGNAL( loopingToggled(bool) ), this, SLOT( setLooping(bool) ) ); 164 connect( mediaPlayerState, SIGNAL( loopingToggled(bool) ), this, SLOT( setLooping(bool) ) );
165// connect( mediaPlayerState, SIGNAL( pausedToggled(bool) ), this, SLOT( setPaused(bool) ) ); 165// connect( mediaPlayerState, SIGNAL( pausedToggled(bool) ), this, SLOT( setPaused(bool) ) );
166 connect( mediaPlayerState, SIGNAL( playingToggled(bool) ), this, SLOT( setPlaying(bool) ) ); 166 connect( mediaPlayerState, SIGNAL( playingToggled(bool) ), this, SLOT( setPlaying(bool) ) );
167 167
168 // Intialise state 168 // Intialise state
169 setLength( mediaPlayerState->length() ); 169 setLength( mediaPlayerState->length() );
170 setPosition( mediaPlayerState->position() ); 170 setPosition( mediaPlayerState->position() );
171 setLooping( mediaPlayerState->fullscreen() ); 171 setLooping( mediaPlayerState->fullscreen() );
172// setPaused( mediaPlayerState->paused() ); 172// setPaused( mediaPlayerState->paused() );
173 setPlaying( mediaPlayerState->playing() ); 173 setPlaying( mediaPlayerState->playing() );
174this->setFocus(); 174 this->setFocus();
175 if(this->x() < 0 || this->y() < 0)
176 this->move(0,0);
175} 177}
176 178
177 179
178AudioWidget::~AudioWidget() { 180AudioWidget::~AudioWidget() {
179 // setPlaying( false); 181 // setPlaying( false);
180 182
181 for ( int i = 0; i < 10; i++ ) { 183 for ( int i = 0; i < 10; i++ ) {
182 if(buttonPixUp[i]) delete buttonPixUp[i]; 184 if(buttonPixUp[i]) delete buttonPixUp[i];
183 if(buttonPixDown[i]) delete buttonPixDown[i]; 185 if(buttonPixDown[i]) delete buttonPixDown[i];
184 } 186 }
185 if(pixBg) delete pixBg; 187 if(pixBg) delete pixBg;
186 if(imgUp) delete imgUp; 188 if(imgUp) delete imgUp;
187 if(imgDn) delete imgDn; 189 if(imgDn) delete imgDn;
188 if(imgButtonMask) delete imgButtonMask; 190 if(imgButtonMask) delete imgButtonMask;
189 for ( int i = 0; i < 10; i++ ) { 191 for ( int i = 0; i < 10; i++ ) {
190 if(masks[i]) delete masks[i]; 192 if(masks[i]) delete masks[i];
191 } 193 }
192} 194}
193 195
194 196
195QPixmap *combineImageWithBackground( QImage img, QPixmap bg, QPoint offset ) { 197QPixmap *combineImageWithBackground( QImage img, QPixmap bg, QPoint offset ) {
196 QPixmap pix( img.width(), img.height() ); 198 QPixmap pix( img.width(), img.height() );
197 QPainter p( &pix ); 199 QPainter p( &pix );
198 p.drawTiledPixmap( pix.rect(), bg, offset ); 200 p.drawTiledPixmap( pix.rect(), bg, offset );
199 p.drawImage( 0, 0, img ); 201 p.drawImage( 0, 0, img );
200 return new QPixmap( pix ); 202 return new QPixmap( pix );
201} 203}
202 204
203 205
204QPixmap *maskPixToMask( QPixmap pix, QBitmap mask ) 206QPixmap *maskPixToMask( QPixmap pix, QBitmap mask )
205{ 207{
206 QPixmap *pixmap = new QPixmap( pix ); 208 QPixmap *pixmap = new QPixmap( pix );
207 pixmap->setMask( mask ); 209 pixmap->setMask( mask );
208 return pixmap; 210 return pixmap;
209} 211}
210 212
211 213
212 214
213void AudioWidget::resizeEvent( QResizeEvent * ) { 215void AudioWidget::resizeEvent( QResizeEvent * ) {
214 int h = height(); 216 int h = height();
215 int w = width(); 217 int w = width();
216 218
217 songInfo.setGeometry( QRect( 2, 10, w - 4, 20 ) ); 219 songInfo.setGeometry( QRect( 2, 10, w - 4, 20 ) );
218 slider.setFixedWidth( w - 110 ); 220 slider.setFixedWidth( w - 110 );
219 slider.setGeometry( QRect( 15, h - 30, w - 90, 20 ) ); 221 slider.setGeometry( QRect( 15, h - 30, w - 90, 20 ) );
220 slider.setBackgroundOrigin( QWidget::ParentOrigin ); 222 slider.setBackgroundOrigin( QWidget::ParentOrigin );
221 time.setGeometry( QRect( w - 85, h - 30, 70, 20 ) ); 223 time.setGeometry( QRect( w - 85, h - 30, 70, 20 ) );
222 224
223 xoff = ( w - imgUp->width() ) / 2; 225 xoff = ( w - imgUp->width() ) / 2;
224 yoff = (( h - imgUp->height() ) / 2) - 10; 226 yoff = (( h - imgUp->height() ) / 2) - 10;
225 QPoint p( xoff, yoff ); 227 QPoint p( xoff, yoff );
226 228
227 QPixmap *pixUp = combineImageWithBackground( *imgUp, *pixBg, p ); 229 QPixmap *pixUp = combineImageWithBackground( *imgUp, *pixBg, p );
228 QPixmap *pixDn = combineImageWithBackground( *imgDn, *pixBg, p ); 230 QPixmap *pixDn = combineImageWithBackground( *imgDn, *pixBg, p );
229 231
230 for ( int i = 0; i < 10; i++ ) { 232 for ( int i = 0; i < 10; i++ ) {
231 if ( !masks[i]->isNull() ) { 233 if ( !masks[i]->isNull() ) {
232 delete buttonPixUp[i]; 234 delete buttonPixUp[i];
233 delete buttonPixDown[i]; 235 delete buttonPixDown[i];
234 buttonPixUp[i] = maskPixToMask( *pixUp, *masks[i] ); 236 buttonPixUp[i] = maskPixToMask( *pixUp, *masks[i] );
235 buttonPixDown[i] = maskPixToMask( *pixDn, *masks[i] ); 237 buttonPixDown[i] = maskPixToMask( *pixDn, *masks[i] );
236 } 238 }
237 } 239 }
238 240
239 delete pixUp; 241 delete pixUp;
240 delete pixDn; 242 delete pixDn;
241} 243}
242 244
243 245
244static bool audioSliderBeingMoved = FALSE; 246static bool audioSliderBeingMoved = FALSE;
245 247
246void AudioWidget::sliderPressed() { 248void AudioWidget::sliderPressed() {
247 audioSliderBeingMoved = TRUE; 249 audioSliderBeingMoved = TRUE;
248} 250}
249 251
250 252
251void AudioWidget::sliderReleased() { 253void AudioWidget::sliderReleased() {
252 audioSliderBeingMoved = FALSE; 254 audioSliderBeingMoved = FALSE;
253 if ( slider.width() == 0 ) 255 if ( slider.width() == 0 )
254 return; 256 return;
255 long val = long((double)slider.value() * mediaPlayerState->length() / slider.width()); 257 long val = long((double)slider.value() * mediaPlayerState->length() / slider.width());
256 mediaPlayerState->setPosition( val ); 258 mediaPlayerState->setPosition( val );
257} 259}
258 260
259 261
260void AudioWidget::setPosition( long i ) { 262void AudioWidget::setPosition( long i ) {
261// odebug << "set position " << i << "" << oendl; 263// odebug << "set position " << i << "" << oendl;
262 long length = mediaPlayerState->length(); 264 long length = mediaPlayerState->length();
263 updateSlider( i, length ); 265 updateSlider( i, length );
264} 266}
265 267
266 268
267void AudioWidget::setLength( long max ) { 269void AudioWidget::setLength( long max ) {
268 updateSlider( mediaPlayerState->position(), max ); 270 updateSlider( mediaPlayerState->position(), max );
269} 271}
270 272
271 273
272void AudioWidget::setView( char view ) { 274void AudioWidget::setView( char view ) {
273 275
274 if (mediaPlayerState->isStreaming) { 276 if (mediaPlayerState->isStreaming) {
275 if( !slider.isHidden()) slider.hide(); 277 if( !slider.isHidden()) slider.hide();
276 disconnect( mediaPlayerState, SIGNAL( positionChanged(long) ),this, SLOT( setPosition(long) ) ); 278 disconnect( mediaPlayerState, SIGNAL( positionChanged(long) ),this, SLOT( setPosition(long) ) );
277 disconnect( mediaPlayerState, SIGNAL( positionUpdated(long) ),this, SLOT( setPosition(long) ) ); 279 disconnect( mediaPlayerState, SIGNAL( positionUpdated(long) ),this, SLOT( setPosition(long) ) );
278 } else { 280 } else {
279// this stops the slider from being moved, thus 281// this stops the slider from being moved, thus
280 // does not stop stream when it reaches the end 282 // does not stop stream when it reaches the end
281 slider.show(); 283 slider.show();
282 connect( mediaPlayerState, SIGNAL( positionChanged(long) ),this, SLOT( setPosition(long) ) ); 284 connect( mediaPlayerState, SIGNAL( positionChanged(long) ),this, SLOT( setPosition(long) ) );
283 connect( mediaPlayerState, SIGNAL( positionUpdated(long) ),this, SLOT( setPosition(long) ) ); 285 connect( mediaPlayerState, SIGNAL( positionUpdated(long) ),this, SLOT( setPosition(long) ) );
284 } 286 }
285 287
286 if ( view == 'a' ) { 288 if ( view == 'a' ) {
287 startTimer( 150 ); 289 startTimer( 150 );
288// show(); 290// show();
289 QPEApplication::showWidget( this ); 291 QPEApplication::showWidget( this );
290 } else { 292 } else {
291 killTimers(); 293 killTimers();
292 hide(); 294 hide();
293 } 295 }
294 296
295} 297}
296 298
297 299
298static QString timeAsString( long length ) { 300static QString timeAsString( long length ) {
299 length /= 44100; 301 length /= 44100;
300 int minutes = length / 60; 302 int minutes = length / 60;
301 int seconds = length % 60; 303 int seconds = length % 60;
302 return QString("%1:%2%3").arg( minutes ).arg( seconds / 10 ).arg( seconds % 10 ); 304 return QString("%1:%2%3").arg( minutes ).arg( seconds / 10 ).arg( seconds % 10 );
303} 305}
304 306
305void AudioWidget::updateSlider( long i, long max ) { 307void AudioWidget::updateSlider( long i, long max ) {
306this->setFocus(); 308this->setFocus();
307 time.setText( timeAsString( i ) + " / " + timeAsString( max ) ); 309 time.setText( timeAsString( i ) + " / " + timeAsString( max ) );
308 310
309 if ( max == 0 ) 311 if ( max == 0 )
310 return; 312 return;
311 // Will flicker too much if we don't do this 313 // Will flicker too much if we don't do this
312 // Scale to something reasonable 314 // Scale to something reasonable
313 int width = slider.width(); 315 int width = slider.width();
314 int val = int((double)i * width / max); 316 int val = int((double)i * width / max);
315 if ( !audioSliderBeingMoved ) { 317 if ( !audioSliderBeingMoved ) {
316 if ( slider.value() != val ) 318 if ( slider.value() != val )
317 slider.setValue( val ); 319 slider.setValue( val );
318 if ( slider.maxValue() != width ) 320 if ( slider.maxValue() != width )
319 slider.setMaxValue( width ); 321 slider.setMaxValue( width );
320 } 322 }
321} 323}
322 324
323 325
324void AudioWidget::setToggleButton( int i, bool down ) { 326void AudioWidget::setToggleButton( int i, bool down ) {
325 if ( down != audioButtons[i].isDown ) 327 if ( down != audioButtons[i].isDown )
326 toggleButton( i ); 328 toggleButton( i );
327} 329}
328 330
329 331
330void AudioWidget::toggleButton( int i ) { 332void AudioWidget::toggleButton( int i ) {
331 audioButtons[i].isDown = !audioButtons[i].isDown; 333 audioButtons[i].isDown = !audioButtons[i].isDown;
332 QPainter p(this); 334 QPainter p(this);
333 paintButton ( &p, i ); 335 paintButton ( &p, i );
334} 336}
335 337
336 338
337void AudioWidget::paintButton( QPainter *p, int i ) { 339void AudioWidget::paintButton( QPainter *p, int i ) {
338 if ( audioButtons[i].isDown ) 340 if ( audioButtons[i].isDown )
339 p->drawPixmap( xoff, yoff, *buttonPixDown[i] ); 341 p->drawPixmap( xoff, yoff, *buttonPixDown[i] );
340 else 342 else
341 p->drawPixmap( xoff, yoff, *buttonPixUp[i] ); 343 p->drawPixmap( xoff, yoff, *buttonPixUp[i] );
342} 344}
343 345
344 346
345void AudioWidget::timerEvent( QTimerEvent * ) { 347void AudioWidget::timerEvent( QTimerEvent * ) {
346/* 348/*
347 int x = audioButtons[AudioPlay].xPos; 349 int x = audioButtons[AudioPlay].xPos;
348 int y = audioButtons[AudioPlay].yPos; 350 int y = audioButtons[AudioPlay].yPos;
349 QPainter p( this ); 351 QPainter p( this );
350 // Optimize to only draw the little bit of the changing images which is different 352 // Optimize to only draw the little bit of the changing images which is different
351 p.drawPixmap( x + 14, y + 8, *pixmaps[3], 32 * frame, 0, 32, 32 ); 353 p.drawPixmap( x + 14, y + 8, *pixmaps[3], 32 * frame, 0, 32, 32 );
352 p.drawPixmap( x + 37, y + 37, *pixmaps[2], 18 * AudioPlay, 0, 6, 3 ); 354 p.drawPixmap( x + 37, y + 37, *pixmaps[2], 18 * AudioPlay, 0, 6, 3 );
353*/ 355*/
354/* 356/*
355 static int frame = 0; 357 static int frame = 0;
356 if ( !mediaPlayerState->paused() && audioButtons[ AudioPlay ].isDown ) { 358 if ( !mediaPlayerState->paused() && audioButtons[ AudioPlay ].isDown ) {
357 frame = frame >= 7 ? 0 : frame + 1; 359 frame = frame >= 7 ? 0 : frame + 1;
358 } 360 }
359 */ 361 */
360} 362}
361 363
362 364
363void AudioWidget::mouseMoveEvent( QMouseEvent *event ) { 365void AudioWidget::mouseMoveEvent( QMouseEvent *event ) {
364 for ( int i = 0; i < numButtons; i++ ) { 366 for ( int i = 0; i < numButtons; i++ ) {
365 if ( event->state() == QMouseEvent::LeftButton ) { 367 if ( event->state() == QMouseEvent::LeftButton ) {
366 368
367 // The test to see if the mouse click is inside the button or not 369 // The test to see if the mouse click is inside the button or not
368 int x = event->pos().x() - xoff; 370 int x = event->pos().x() - xoff;
369 int y = event->pos().y() - yoff; 371 int y = event->pos().y() - yoff;
370 372
371 bool isOnButton = ( x > 0 && y > 0 && x < imgButtonMask->width() 373 bool isOnButton = ( x > 0 && y > 0 && x < imgButtonMask->width()
372 && y < imgButtonMask->height() && imgButtonMask->pixelIndex( x, y ) == i + 1 ); 374 && y < imgButtonMask->height() && imgButtonMask->pixelIndex( x, y ) == i + 1 );
373 375
374// if ( isOnButton && i == AudioVolumeUp ) 376// if ( isOnButton && i == AudioVolumeUp )
375// odebug << "on up" << oendl; 377// odebug << "on up" << oendl;
376 378
377 if ( isOnButton && !audioButtons[i].isHeld ) { 379 if ( isOnButton && !audioButtons[i].isHeld ) {
378 audioButtons[i].isHeld = TRUE; 380 audioButtons[i].isHeld = TRUE;
379 toggleButton(i); 381 toggleButton(i);
380 switch (i) { 382 switch (i) {
381 case AudioVolumeUp: 383 case AudioVolumeUp:
382 // odebug << "more clicked" << oendl; 384 // odebug << "more clicked" << oendl;
383 emit moreClicked(); 385 emit moreClicked();
384 return; 386 return;
385 case AudioVolumeDown: 387 case AudioVolumeDown:
386 // odebug << "less clicked" << oendl; 388 // odebug << "less clicked" << oendl;
387 emit lessClicked(); 389 emit lessClicked();
388 return; 390 return;
389 case AudioForward: 391 case AudioForward:
390 emit forwardClicked(); 392 emit forwardClicked();
391 return; 393 return;
392 case AudioBack: 394 case AudioBack:
393 emit backClicked(); 395 emit backClicked();
394 return; 396 return;
395 } 397 }
396 } else if ( !isOnButton && audioButtons[i].isHeld ) { 398 } else if ( !isOnButton && audioButtons[i].isHeld ) {
397 audioButtons[i].isHeld = FALSE; 399 audioButtons[i].isHeld = FALSE;
398 toggleButton(i); 400 toggleButton(i);
399 } 401 }
400 } else { 402 } else {
401 if ( audioButtons[i].isHeld ) { 403 if ( audioButtons[i].isHeld ) {
402 audioButtons[i].isHeld = FALSE; 404 audioButtons[i].isHeld = FALSE;
403 if ( !audioButtons[i].isToggle ) 405 if ( !audioButtons[i].isToggle )
404 setToggleButton( i, FALSE ); 406 setToggleButton( i, FALSE );
405 switch (i) { 407 switch (i) {
406 case AudioPlay: 408 case AudioPlay:
407 if( mediaPlayerState->isPaused ) { 409 if( mediaPlayerState->isPaused ) {
408 mediaPlayerState->setPaused( FALSE ); 410 mediaPlayerState->setPaused( FALSE );
409 return; 411 return;
410 } else if( !mediaPlayerState->isPaused ) { 412 } else if( !mediaPlayerState->isPaused ) {
411 mediaPlayerState->setPaused( TRUE ); 413 mediaPlayerState->setPaused( TRUE );
412 return; 414 return;
413 } 415 }
414// case AudioPlay: mediaPlayerState->setPlaying(audioButtons[i].isDown); return; 416// case AudioPlay: mediaPlayerState->setPlaying(audioButtons[i].isDown); return;
415 case AudioStop: mediaPlayerState->setPlaying(FALSE); return; 417 case AudioStop: mediaPlayerState->setPlaying(FALSE); return;
416// case AudioPause: mediaPlayerState->setPaused(audioButtons[i].isDown); return; 418// case AudioPause: mediaPlayerState->setPaused(audioButtons[i].isDown); return;
417 case AudioNext: mediaPlayerState->setNext(); return; 419 case AudioNext: mediaPlayerState->setNext(); return;
418 case AudioPrevious: mediaPlayerState->setPrev(); return; 420 case AudioPrevious: mediaPlayerState->setPrev(); return;
419 case AudioLoop: mediaPlayerState->setLooping(audioButtons[i].isDown); return; 421 case AudioLoop: mediaPlayerState->setLooping(audioButtons[i].isDown); return;
420 case AudioVolumeUp: emit moreReleased(); return; 422 case AudioVolumeUp: emit moreReleased(); return;
421 case AudioVolumeDown: emit lessReleased(); return; 423 case AudioVolumeDown: emit lessReleased(); return;
422 case AudioPlayList: mediaPlayerState->setList(); return; 424 case AudioPlayList: mediaPlayerState->setList(); return;
423 } 425 }
424 } 426 }
425 } 427 }
426 } 428 }
427} 429}
428 430
429 431
430 432