summaryrefslogtreecommitdiff
authorsimon <simon>2002-12-09 14:41:19 (UTC)
committer simon <simon>2002-12-09 14:41:19 (UTC)
commit174c4a427750a3829ffd81a87454be8abf61ee30 (patch) (unidiff)
treee6b8d73afe4426707698396cc3c0086d712983f9
parent3f88070b9be5209cdd88caa0afd7f7294d3b1764 (diff)
downloadopie-174c4a427750a3829ffd81a87454be8abf61ee30.zip
opie-174c4a427750a3829ffd81a87454be8abf61ee30.tar.gz
opie-174c4a427750a3829ffd81a87454be8abf61ee30.tar.bz2
- merged the two button setup loops
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/multimedia/opieplayer2/audiowidget.cpp18
1 files changed, 8 insertions, 10 deletions
diff --git a/noncore/multimedia/opieplayer2/audiowidget.cpp b/noncore/multimedia/opieplayer2/audiowidget.cpp
index 87e06ee..c148820 100644
--- a/noncore/multimedia/opieplayer2/audiowidget.cpp
+++ b/noncore/multimedia/opieplayer2/audiowidget.cpp
@@ -1,381 +1,379 @@
1/* 1/*
2                This file is part of the Opie Project 2                This file is part of the Opie Project
3 3
4              Copyright (c) 2002 Max Reiss <harlekin@handhelds.org> 4              Copyright (c) 2002 Max Reiss <harlekin@handhelds.org>
5 Copyright (c) 2002 L. Potter <ljp@llornkcor.com> 5 Copyright (c) 2002 L. Potter <ljp@llornkcor.com>
6 Copyright (c) 2002 Holger Freyther <zecke@handhelds.org> 6 Copyright (c) 2002 Holger Freyther <zecke@handhelds.org>
7 =. 7 =.
8 .=l. 8 .=l.
9           .>+-= 9           .>+-=
10 _;:,     .>    :=|. This program is free software; you can 10 _;:,     .>    :=|. This program is free software; you can
11.> <`_,   >  .   <= redistribute it and/or modify it under 11.> <`_,   >  .   <= redistribute it and/or modify it under
12:`=1 )Y*s>-.--   : the terms of the GNU General Public 12:`=1 )Y*s>-.--   : the terms of the GNU General Public
13.="- .-=="i,     .._ License as published by the Free Software 13.="- .-=="i,     .._ License as published by the Free Software
14 - .   .-<_>     .<> Foundation; either version 2 of the License, 14 - .   .-<_>     .<> Foundation; either version 2 of the License,
15     ._= =}       : or (at your option) any later version. 15     ._= =}       : or (at your option) any later version.
16    .%`+i>       _;_. 16    .%`+i>       _;_.
17    .i_,=:_.      -<s. This program is distributed in the hope that 17    .i_,=:_.      -<s. This program is distributed in the hope that
18     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY; 18     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
19    : ..    .:,     . . . without even the implied warranty of 19    : ..    .:,     . . . without even the implied warranty of
20    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A 20    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
21  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU 21  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
22..}^=.=       =       ; Library General Public License for more 22..}^=.=       =       ; Library General Public License for more
23++=   -.     .`     .: details. 23++=   -.     .`     .: details.
24 :     =  ...= . :.=- 24 :     =  ...= . :.=-
25 -.   .:....=;==+<; You should have received a copy of the GNU 25 -.   .:....=;==+<; You should have received a copy of the GNU
26  -_. . .   )=.  = Library General Public License along with 26  -_. . .   )=.  = Library General Public License along with
27    --        :-=` this library; see the file COPYING.LIB. 27    --        :-=` this library; see the file COPYING.LIB.
28 If not, write to the Free Software Foundation, 28 If not, write to the Free Software Foundation,
29 Inc., 59 Temple Place - Suite 330, 29 Inc., 59 Temple Place - Suite 330,
30 Boston, MA 02111-1307, USA. 30 Boston, MA 02111-1307, USA.
31 31
32*/ 32*/
33 33
34#include <qpe/qpeapplication.h> 34#include <qpe/qpeapplication.h>
35#include <qpe/resource.h> 35#include <qpe/resource.h>
36#include <qpe/config.h> 36#include <qpe/config.h>
37#include <opie/oticker.h> 37#include <opie/oticker.h>
38 38
39#include <qwidget.h> 39#include <qwidget.h>
40#include <qpixmap.h> 40#include <qpixmap.h>
41#include <qbutton.h> 41#include <qbutton.h>
42#include <qpainter.h> 42#include <qpainter.h>
43#include <qframe.h> 43#include <qframe.h>
44#include <qlayout.h> 44#include <qlayout.h>
45#include <qdir.h> 45#include <qdir.h>
46#include <stdlib.h> 46#include <stdlib.h>
47#include <stdio.h> 47#include <stdio.h>
48 48
49#include "audiowidget.h" 49#include "audiowidget.h"
50#include "mediaplayerstate.h" 50#include "mediaplayerstate.h"
51#include "playlistwidget.h" 51#include "playlistwidget.h"
52 52
53namespace 53namespace
54{ 54{
55 55
56const int xo = -2; // movable x offset 56const int xo = -2; // movable x offset
57const int yo = 22; // movable y offset 57const int yo = 22; // movable y offset
58 58
59const MediaWidget::SkinButtonInfo skinInfo[] = 59const MediaWidget::SkinButtonInfo skinInfo[] =
60{ 60{
61 { MediaWidget::Play, "play", MediaWidget::ToggleButton }, 61 { MediaWidget::Play, "play", MediaWidget::ToggleButton },
62 { MediaWidget::Stop, "stop", MediaWidget::NormalButton }, 62 { MediaWidget::Stop, "stop", MediaWidget::NormalButton },
63 { MediaWidget::Next, "next", MediaWidget::NormalButton }, 63 { MediaWidget::Next, "next", MediaWidget::NormalButton },
64 { MediaWidget::Previous, "prev", MediaWidget::NormalButton }, 64 { MediaWidget::Previous, "prev", MediaWidget::NormalButton },
65 { MediaWidget::VolumeUp, "up", MediaWidget::NormalButton }, 65 { MediaWidget::VolumeUp, "up", MediaWidget::NormalButton },
66 { MediaWidget::VolumeDown, "down", MediaWidget::NormalButton }, 66 { MediaWidget::VolumeDown, "down", MediaWidget::NormalButton },
67 { MediaWidget::Loop, "loop", MediaWidget::ToggleButton }, 67 { MediaWidget::Loop, "loop", MediaWidget::ToggleButton },
68 { MediaWidget::PlayList, "playlist", MediaWidget::NormalButton }, 68 { MediaWidget::PlayList, "playlist", MediaWidget::NormalButton },
69 { MediaWidget::Forward, "forward", MediaWidget::NormalButton }, 69 { MediaWidget::Forward, "forward", MediaWidget::NormalButton },
70 { MediaWidget::Back, "back", MediaWidget::NormalButton } 70 { MediaWidget::Back, "back", MediaWidget::NormalButton }
71}; 71};
72 72
73const uint buttonCount = sizeof( skinInfo ) / sizeof( skinInfo[ 0 ] ); 73const uint buttonCount = sizeof( skinInfo ) / sizeof( skinInfo[ 0 ] );
74 74
75void changeTextColor( QWidget * w) { 75void changeTextColor( QWidget * w) {
76 QPalette p = w->palette(); 76 QPalette p = w->palette();
77 p.setBrush( QColorGroup::Background, QColor( 167, 212, 167 ) ); 77 p.setBrush( QColorGroup::Background, QColor( 167, 212, 167 ) );
78 p.setBrush( QColorGroup::Base, QColor( 167, 212, 167 ) ); 78 p.setBrush( QColorGroup::Base, QColor( 167, 212, 167 ) );
79 w->setPalette( p ); 79 w->setPalette( p );
80} 80}
81 81
82} 82}
83 83
84AudioWidget::AudioWidget( PlayListWidget &playList, MediaPlayerState &mediaPlayerState, QWidget* parent, const char* name) : 84AudioWidget::AudioWidget( PlayListWidget &playList, MediaPlayerState &mediaPlayerState, QWidget* parent, const char* name) :
85 85
86 MediaWidget( playList, mediaPlayerState, parent, name ), songInfo( this ), slider( Qt::Horizontal, this ), time( this ), 86 MediaWidget( playList, mediaPlayerState, parent, name ), songInfo( this ), slider( Qt::Horizontal, this ), time( this ),
87 audioSliderBeingMoved( false ) 87 audioSliderBeingMoved( false )
88{ 88{
89 for ( uint i = 0; i < buttonCount; ++i ) {
90 Button button;
91 button.type = skinInfo[ i ].type;
92 buttons.push_back( button );
93 }
94
95 setCaption( tr("OpiePlayer") ); 89 setCaption( tr("OpiePlayer") );
96 90
97 Config cfg("OpiePlayer"); 91 Config cfg("OpiePlayer");
98 cfg.setGroup("Options"); 92 cfg.setGroup("Options");
99 skin = cfg.readEntry("Skin","default"); 93 skin = cfg.readEntry("Skin","default");
100 //skin = "scaleTest"; 94 //skin = "scaleTest";
101 // color of background, frame, degree of transparency 95 // color of background, frame, degree of transparency
102 96
103 QString skinPath = "opieplayer2/skins/" + skin; 97 QString skinPath = "opieplayer2/skins/" + skin;
104 pixBg = QPixmap( Resource::loadPixmap( QString("%1/background").arg(skinPath) ) ); 98 pixBg = QPixmap( Resource::loadPixmap( QString("%1/background").arg(skinPath) ) );
105 imgUp = QImage( Resource::loadImage( QString("%1/skin_up").arg(skinPath) ) ); 99 imgUp = QImage( Resource::loadImage( QString("%1/skin_up").arg(skinPath) ) );
106 imgDn = QImage( Resource::loadImage( QString("%1/skin_down").arg(skinPath) ) ); 100 imgDn = QImage( Resource::loadImage( QString("%1/skin_down").arg(skinPath) ) );
107 101
108 buttonMask = QImage( imgUp.width(), imgUp.height(), 8, 255 ); 102 buttonMask = QImage( imgUp.width(), imgUp.height(), 8, 255 );
109 buttonMask.fill( 0 ); 103 buttonMask.fill( 0 );
110 104
111 for ( uint i = 0; i < buttons.size(); i++ ) { 105 for ( uint i = 0; i < buttonCount; i++ ) {
106 Button button;
107 button.type = skinInfo[ i ].type;
108
112 QString filename = QString( QPEApplication::qpeDir() + "/pics/" + skinPath + "/skin_mask_" + skinInfo[i].fileName + ".png" ); 109 QString filename = QString( QPEApplication::qpeDir() + "/pics/" + skinPath + "/skin_mask_" + skinInfo[i].fileName + ".png" );
113 buttons[ i ].mask =QBitmap( filename ); 110 button.mask =QBitmap( filename );
114 111
115 if ( !buttons[i].mask.isNull() ) { 112 if ( !button.mask.isNull() ) {
116 QImage imgMask = buttons[i].mask.convertToImage(); 113 QImage imgMask = button.mask.convertToImage();
117 uchar **dest = buttonMask.jumpTable(); 114 uchar **dest = buttonMask.jumpTable();
118 for ( int y = 0; y < imgUp.height(); y++ ) { 115 for ( int y = 0; y < imgUp.height(); y++ ) {
119 uchar *line = dest[y]; 116 uchar *line = dest[y];
120 for ( int x = 0; x < imgUp.width(); x++ ) 117 for ( int x = 0; x < imgUp.width(); x++ )
121 if ( !qRed( imgMask.pixel( x, y ) ) ) 118 if ( !qRed( imgMask.pixel( x, y ) ) )
122 line[x] = i + 1; 119 line[x] = i + 1;
123 } 120 }
124 } 121 }
125 122
123 buttons.push_back( button );
126 } 124 }
127 125
128 setBackgroundPixmap( pixBg ); 126 setBackgroundPixmap( pixBg );
129 127
130 songInfo.setFocusPolicy( QWidget::NoFocus ); 128 songInfo.setFocusPolicy( QWidget::NoFocus );
131// changeTextColor( &songInfo ); 129// changeTextColor( &songInfo );
132// songInfo.setBackgroundColor( QColor( 167, 212, 167 )); 130// songInfo.setBackgroundColor( QColor( 167, 212, 167 ));
133// songInfo.setFrameStyle( QFrame::NoFrame); 131// songInfo.setFrameStyle( QFrame::NoFrame);
134 songInfo.setFrameStyle( QFrame::WinPanel | QFrame::Sunken ); 132 songInfo.setFrameStyle( QFrame::WinPanel | QFrame::Sunken );
135// songInfo.setForegroundColor(Qt::white); 133// songInfo.setForegroundColor(Qt::white);
136 134
137 slider.setFixedHeight( 20 ); 135 slider.setFixedHeight( 20 );
138 slider.setMinValue( 0 ); 136 slider.setMinValue( 0 );
139 slider.setMaxValue( 1 ); 137 slider.setMaxValue( 1 );
140 slider.setFocusPolicy( QWidget::NoFocus ); 138 slider.setFocusPolicy( QWidget::NoFocus );
141 slider.setBackgroundPixmap( pixBg ); 139 slider.setBackgroundPixmap( pixBg );
142 140
143// Config cofg("qpe"); 141// Config cofg("qpe");
144// cofg.setGroup("Appearance"); 142// cofg.setGroup("Appearance");
145// QColor backgroundcolor = QColor( cofg.readEntry( "Background", "#E5E1D5" ) ); 143// QColor backgroundcolor = QColor( cofg.readEntry( "Background", "#E5E1D5" ) );
146 144
147 time.setFocusPolicy( QWidget::NoFocus ); 145 time.setFocusPolicy( QWidget::NoFocus );
148 time.setAlignment( Qt::AlignCenter ); 146 time.setAlignment( Qt::AlignCenter );
149 147
150// time.setFrame(FALSE); 148// time.setFrame(FALSE);
151// changeTextColor( &time ); 149// changeTextColor( &time );
152 150
153 resizeEvent( NULL ); 151 resizeEvent( NULL );
154 152
155 connect( &mediaPlayerState, SIGNAL( loopingToggled(bool) ), this, SLOT( setLooping(bool) ) ); 153 connect( &mediaPlayerState, SIGNAL( loopingToggled(bool) ), this, SLOT( setLooping(bool) ) );
156 connect( &mediaPlayerState, SIGNAL( isSeekableToggled( bool ) ), this, SLOT( setSeekable( bool ) ) ); 154 connect( &mediaPlayerState, SIGNAL( isSeekableToggled( bool ) ), this, SLOT( setSeekable( bool ) ) );
157 155
158 connect( this, SIGNAL( forwardClicked() ), this, SLOT( skipFor() ) ); 156 connect( this, SIGNAL( forwardClicked() ), this, SLOT( skipFor() ) );
159 connect( this, SIGNAL( backClicked() ), this, SLOT( skipBack() ) ); 157 connect( this, SIGNAL( backClicked() ), this, SLOT( skipBack() ) );
160 connect( this, SIGNAL( forwardReleased() ), this, SLOT( stopSkip() ) ); 158 connect( this, SIGNAL( forwardReleased() ), this, SLOT( stopSkip() ) );
161 connect( this, SIGNAL( backReleased() ), this, SLOT( stopSkip() ) ); 159 connect( this, SIGNAL( backReleased() ), this, SLOT( stopSkip() ) );
162 160
163 // Intialise state 161 // Intialise state
164 setLength( mediaPlayerState.length() ); 162 setLength( mediaPlayerState.length() );
165 setPosition( mediaPlayerState.position() ); 163 setPosition( mediaPlayerState.position() );
166 setLooping( mediaPlayerState.isFullscreen() ); 164 setLooping( mediaPlayerState.isFullscreen() );
167 // setPaused( mediaPlayerState->paused() ); 165 // setPaused( mediaPlayerState->paused() );
168 setPlaying( mediaPlayerState.isPlaying() ); 166 setPlaying( mediaPlayerState.isPlaying() );
169 167
170} 168}
171 169
172AudioWidget::~AudioWidget() { 170AudioWidget::~AudioWidget() {
173 171
174// mediaPlayerState->setPlaying(false); 172// mediaPlayerState->setPlaying(false);
175} 173}
176 174
177namespace { 175namespace {
178 176
179QPixmap combineImageWithBackground( QImage img, QPixmap bg, QPoint offset ) { 177QPixmap combineImageWithBackground( QImage img, QPixmap bg, QPoint offset ) {
180 QPixmap pix( img.width(), img.height() ); 178 QPixmap pix( img.width(), img.height() );
181 QPainter p( &pix ); 179 QPainter p( &pix );
182 p.drawTiledPixmap( pix.rect(), bg, offset ); 180 p.drawTiledPixmap( pix.rect(), bg, offset );
183 p.drawImage( 0, 0, img ); 181 p.drawImage( 0, 0, img );
184 return pix; 182 return pix;
185} 183}
186 184
187 185
188QPixmap maskPixToMask( QPixmap pix, QBitmap mask ) { 186QPixmap maskPixToMask( QPixmap pix, QBitmap mask ) {
189 QPixmap pixmap( pix ); 187 QPixmap pixmap( pix );
190 pixmap.setMask( mask ); 188 pixmap.setMask( mask );
191 return pixmap; 189 return pixmap;
192} 190}
193 191
194}; 192};
195 193
196void AudioWidget::resizeEvent( QResizeEvent * ) { 194void AudioWidget::resizeEvent( QResizeEvent * ) {
197 int h = height(); 195 int h = height();
198 int w = width(); 196 int w = width();
199 197
200 songInfo.setGeometry( QRect( 2, 2, w - 4, 20 ) ); 198 songInfo.setGeometry( QRect( 2, 2, w - 4, 20 ) );
201 slider.setFixedWidth( w - 110 ); 199 slider.setFixedWidth( w - 110 );
202 slider.setGeometry( QRect( 15, h - 22, w - 90, 20 ) ); 200 slider.setGeometry( QRect( 15, h - 22, w - 90, 20 ) );
203 slider.setBackgroundOrigin( QWidget::ParentOrigin ); 201 slider.setBackgroundOrigin( QWidget::ParentOrigin );
204 time.setGeometry( QRect( w - 85, h - 30, 70, 20 ) ); 202 time.setGeometry( QRect( w - 85, h - 30, 70, 20 ) );
205 203
206 upperLeftOfButtonMask.rx() = ( w - imgUp.width() ) / 2; 204 upperLeftOfButtonMask.rx() = ( w - imgUp.width() ) / 2;
207 upperLeftOfButtonMask.ry() = (( h - imgUp.height() ) / 2) - 10; 205 upperLeftOfButtonMask.ry() = (( h - imgUp.height() ) / 2) - 10;
208 QPoint p = upperLeftOfButtonMask; 206 QPoint p = upperLeftOfButtonMask;
209 207
210 QPixmap pixUp = combineImageWithBackground( imgUp, pixBg, p ); 208 QPixmap pixUp = combineImageWithBackground( imgUp, pixBg, p );
211 QPixmap pixDn = combineImageWithBackground( imgDn, pixBg, p ); 209 QPixmap pixDn = combineImageWithBackground( imgDn, pixBg, p );
212 210
213 for ( uint i = 0; i < buttons.size(); i++ ) { 211 for ( uint i = 0; i < buttons.size(); i++ ) {
214 if ( !buttons[i].mask.isNull() ) { 212 if ( !buttons[i].mask.isNull() ) {
215 buttons[i].pixUp = maskPixToMask( pixUp, buttons[i].mask ); 213 buttons[i].pixUp = maskPixToMask( pixUp, buttons[i].mask );
216 buttons[i].pixDown = maskPixToMask( pixDn, buttons[i].mask ); 214 buttons[i].pixDown = maskPixToMask( pixDn, buttons[i].mask );
217 } 215 }
218 } 216 }
219} 217}
220 218
221void AudioWidget::sliderPressed() { 219void AudioWidget::sliderPressed() {
222 audioSliderBeingMoved = TRUE; 220 audioSliderBeingMoved = TRUE;
223} 221}
224 222
225 223
226void AudioWidget::sliderReleased() { 224void AudioWidget::sliderReleased() {
227 audioSliderBeingMoved = FALSE; 225 audioSliderBeingMoved = FALSE;
228 if ( slider.width() == 0 ) 226 if ( slider.width() == 0 )
229 return; 227 return;
230 long val = long((double)slider.value() * mediaPlayerState.length() / slider.width()); 228 long val = long((double)slider.value() * mediaPlayerState.length() / slider.width());
231 mediaPlayerState.setPosition( val ); 229 mediaPlayerState.setPosition( val );
232} 230}
233 231
234void AudioWidget::setPosition( long i ) { 232void AudioWidget::setPosition( long i ) {
235 // qDebug("<<<<<<<<<<<<<<<<<<<<<<<<set position %d",i); 233 // qDebug("<<<<<<<<<<<<<<<<<<<<<<<<set position %d",i);
236 updateSlider( i, mediaPlayerState.length() ); 234 updateSlider( i, mediaPlayerState.length() );
237} 235}
238 236
239 237
240void AudioWidget::setLength( long max ) { 238void AudioWidget::setLength( long max ) {
241 updateSlider( mediaPlayerState.position(), max ); 239 updateSlider( mediaPlayerState.position(), max );
242} 240}
243 241
244 242
245void AudioWidget::setDisplayType( MediaPlayerState::DisplayType mediaType ) { 243void AudioWidget::setDisplayType( MediaPlayerState::DisplayType mediaType ) {
246 if ( mediaType == MediaPlayerState::Audio ) { 244 if ( mediaType == MediaPlayerState::Audio ) {
247 // startTimer( 150 ); 245 // startTimer( 150 );
248 showMaximized(); 246 showMaximized();
249 return; 247 return;
250 } 248 }
251 249
252 killTimers(); 250 killTimers();
253 hide(); 251 hide();
254} 252}
255 253
256 254
257void AudioWidget::setSeekable( bool isSeekable ) { 255void AudioWidget::setSeekable( bool isSeekable ) {
258 256
259 if ( !isSeekable ) { 257 if ( !isSeekable ) {
260 qDebug("<<<<<<<<<<<<<<file is STREAMING>>>>>>>>>>>>>>>>>>>"); 258 qDebug("<<<<<<<<<<<<<<file is STREAMING>>>>>>>>>>>>>>>>>>>");
261 if( !slider.isHidden()) { 259 if( !slider.isHidden()) {
262 slider.hide(); 260 slider.hide();
263 } 261 }
264 disconnect( &mediaPlayerState, SIGNAL( positionChanged(long) ),this, SLOT( setPosition(long) ) ); 262 disconnect( &mediaPlayerState, SIGNAL( positionChanged(long) ),this, SLOT( setPosition(long) ) );
265 disconnect( &mediaPlayerState, SIGNAL( positionUpdated(long) ),this, SLOT( setPosition(long) ) ); 263 disconnect( &mediaPlayerState, SIGNAL( positionUpdated(long) ),this, SLOT( setPosition(long) ) );
266 disconnect( &slider, SIGNAL( sliderPressed() ), this, SLOT( sliderPressed() ) ); 264 disconnect( &slider, SIGNAL( sliderPressed() ), this, SLOT( sliderPressed() ) );
267 disconnect( &slider, SIGNAL( sliderReleased() ), this, SLOT( sliderReleased() ) ); 265 disconnect( &slider, SIGNAL( sliderReleased() ), this, SLOT( sliderReleased() ) );
268 } else { 266 } else {
269 // this stops the slider from being moved, thus 267 // this stops the slider from being moved, thus
270 // does not stop stream when it reaches the end 268 // does not stop stream when it reaches the end
271 slider.show(); 269 slider.show();
272 qDebug( " CONNECT SET POSTION " ); 270 qDebug( " CONNECT SET POSTION " );
273 connect( &mediaPlayerState, SIGNAL( positionChanged(long) ),this, SLOT( setPosition(long) ) ); 271 connect( &mediaPlayerState, SIGNAL( positionChanged(long) ),this, SLOT( setPosition(long) ) );
274 connect( &mediaPlayerState, SIGNAL( positionUpdated(long) ),this, SLOT( setPosition(long) ) ); 272 connect( &mediaPlayerState, SIGNAL( positionUpdated(long) ),this, SLOT( setPosition(long) ) );
275 connect( &slider, SIGNAL( sliderPressed() ), this, SLOT( sliderPressed() ) ); 273 connect( &slider, SIGNAL( sliderPressed() ), this, SLOT( sliderPressed() ) );
276 connect( &slider, SIGNAL( sliderReleased() ), this, SLOT( sliderReleased() ) ); 274 connect( &slider, SIGNAL( sliderReleased() ), this, SLOT( sliderReleased() ) );
277 } 275 }
278} 276}
279 277
280 278
281static QString timeAsString( long length ) { 279static QString timeAsString( long length ) {
282 int minutes = length / 60; 280 int minutes = length / 60;
283 int seconds = length % 60; 281 int seconds = length % 60;
284 return QString("%1:%2%3").arg( minutes ).arg( seconds / 10 ).arg( seconds % 10 ); 282 return QString("%1:%2%3").arg( minutes ).arg( seconds / 10 ).arg( seconds % 10 );
285} 283}
286 284
287void AudioWidget::updateSlider( long i, long max ) { 285void AudioWidget::updateSlider( long i, long max ) {
288 286
289 time.setText( timeAsString( i ) + " / " + timeAsString( max ) ); 287 time.setText( timeAsString( i ) + " / " + timeAsString( max ) );
290// qDebug( timeAsString( i ) + " / " + timeAsString( max ) ) ; 288// qDebug( timeAsString( i ) + " / " + timeAsString( max ) ) ;
291 289
292 if ( max == 0 ) { 290 if ( max == 0 ) {
293 return; 291 return;
294 } 292 }
295 // Will flicker too much if we don't do this 293 // Will flicker too much if we don't do this
296 // Scale to something reasonable 294 // Scale to something reasonable
297 int width = slider.width(); 295 int width = slider.width();
298 int val = int((double)i * width / max); 296 int val = int((double)i * width / max);
299 if ( !audioSliderBeingMoved ) { 297 if ( !audioSliderBeingMoved ) {
300 if ( slider.value() != val ) { 298 if ( slider.value() != val ) {
301 slider.setValue( val ); 299 slider.setValue( val );
302 } 300 }
303 301
304 if ( slider.maxValue() != width ) { 302 if ( slider.maxValue() != width ) {
305 slider.setMaxValue( width ); 303 slider.setMaxValue( width );
306 } 304 }
307 } 305 }
308} 306}
309 307
310 308
311void AudioWidget::setToggleButton( int i, bool down ) { 309void AudioWidget::setToggleButton( int i, bool down ) {
312 qDebug("setToggleButton %d", i); 310 qDebug("setToggleButton %d", i);
313 if ( down != buttons[i].isDown ) { 311 if ( down != buttons[i].isDown ) {
314 toggleButton( i ); 312 toggleButton( i );
315 } 313 }
316} 314}
317 315
318void AudioWidget::paintButton( QPainter &p, int i ) { 316void AudioWidget::paintButton( QPainter &p, int i ) {
319 if ( buttons[i].isDown ) { 317 if ( buttons[i].isDown ) {
320 p.drawPixmap( upperLeftOfButtonMask, buttons[i].pixDown ); 318 p.drawPixmap( upperLeftOfButtonMask, buttons[i].pixDown );
321 } else { 319 } else {
322 p.drawPixmap( upperLeftOfButtonMask, buttons[i].pixUp ); 320 p.drawPixmap( upperLeftOfButtonMask, buttons[i].pixUp );
323 } 321 }
324} 322}
325 323
326 324
327void AudioWidget::skipFor() { 325void AudioWidget::skipFor() {
328 skipDirection = +1; 326 skipDirection = +1;
329 startTimer( 50 ); 327 startTimer( 50 );
330 mediaPlayerState.setPosition( mediaPlayerState.position() + 2 ); 328 mediaPlayerState.setPosition( mediaPlayerState.position() + 2 );
331} 329}
332 330
333void AudioWidget::skipBack() { 331void AudioWidget::skipBack() {
334 skipDirection = -1; 332 skipDirection = -1;
335 startTimer( 50 ); 333 startTimer( 50 );
336 mediaPlayerState.setPosition( mediaPlayerState.position() - 2 ); 334 mediaPlayerState.setPosition( mediaPlayerState.position() - 2 );
337} 335}
338 336
339 337
340 338
341void AudioWidget::stopSkip() { 339void AudioWidget::stopSkip() {
342 killTimers(); 340 killTimers();
343} 341}
344 342
345 343
346void AudioWidget::timerEvent( QTimerEvent * ) { 344void AudioWidget::timerEvent( QTimerEvent * ) {
347 if ( skipDirection == +1 ) { 345 if ( skipDirection == +1 ) {
348 mediaPlayerState.setPosition( mediaPlayerState.position() + 2 ); 346 mediaPlayerState.setPosition( mediaPlayerState.position() + 2 );
349 } else if ( skipDirection == -1 ) { 347 } else if ( skipDirection == -1 ) {
350 mediaPlayerState.setPosition( mediaPlayerState.position() - 2 ); 348 mediaPlayerState.setPosition( mediaPlayerState.position() - 2 );
351 } 349 }
352} 350}
353 351
354 352
355void AudioWidget::mouseMoveEvent( QMouseEvent *event ) { 353void AudioWidget::mouseMoveEvent( QMouseEvent *event ) {
356 for ( unsigned int i = 0; i < buttons.size(); i++ ) { 354 for ( unsigned int i = 0; i < buttons.size(); i++ ) {
357 if ( event->state() == QMouseEvent::LeftButton ) { 355 if ( event->state() == QMouseEvent::LeftButton ) {
358 // The test to see if the mouse click is inside the button or not 356 // The test to see if the mouse click is inside the button or not
359 bool isOnButton = isOverButton( event->pos() - upperLeftOfButtonMask, i ); 357 bool isOnButton = isOverButton( event->pos() - upperLeftOfButtonMask, i );
360 358
361 if ( isOnButton && !buttons[i].isHeld ) { 359 if ( isOnButton && !buttons[i].isHeld ) {
362 buttons[i].isHeld = TRUE; 360 buttons[i].isHeld = TRUE;
363 toggleButton(i); 361 toggleButton(i);
364 switch (i) { 362 switch (i) {
365 case VolumeUp: 363 case VolumeUp:
366 emit moreClicked(); 364 emit moreClicked();
367 return; 365 return;
368 case VolumeDown: 366 case VolumeDown:
369 emit lessClicked(); 367 emit lessClicked();
370 return; 368 return;
371 case Forward: 369 case Forward:
372 emit forwardClicked(); 370 emit forwardClicked();
373 return; 371 return;
374 case Back: 372 case Back:
375 emit backClicked(); 373 emit backClicked();
376 return; 374 return;
377 } 375 }
378 } else if ( !isOnButton && buttons[i].isHeld ) { 376 } else if ( !isOnButton && buttons[i].isHeld ) {
379 buttons[i].isHeld = FALSE; 377 buttons[i].isHeld = FALSE;
380 toggleButton(i); 378 toggleButton(i);
381 } 379 }