summaryrefslogtreecommitdiff
Unidiff
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,480 +1,478 @@
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 }
382 } else { 380 } else {
383 if ( buttons[i].isHeld ) { 381 if ( buttons[i].isHeld ) {
384 buttons[i].isHeld = FALSE; 382 buttons[i].isHeld = FALSE;
385 if ( buttons[i].type != ToggleButton ) { 383 if ( buttons[i].type != ToggleButton ) {
386 setToggleButton( i, FALSE ); 384 setToggleButton( i, FALSE );
387 } 385 }
388 qDebug("mouseEvent %d", i); 386 qDebug("mouseEvent %d", i);
389 handleCommand( static_cast<Command>( i ), buttons[ i ].isDown ); 387 handleCommand( static_cast<Command>( i ), buttons[ i ].isDown );
390 } 388 }
391 } 389 }
392 } 390 }
393} 391}
394 392
395 393
396void AudioWidget::mousePressEvent( QMouseEvent *event ) { 394void AudioWidget::mousePressEvent( QMouseEvent *event ) {
397 mouseMoveEvent( event ); 395 mouseMoveEvent( event );
398} 396}
399 397
400 398
401void AudioWidget::mouseReleaseEvent( QMouseEvent *event ) { 399void AudioWidget::mouseReleaseEvent( QMouseEvent *event ) {
402 mouseMoveEvent( event ); 400 mouseMoveEvent( event );
403} 401}
404 402
405 403
406void AudioWidget::showEvent( QShowEvent* ) { 404void AudioWidget::showEvent( QShowEvent* ) {
407 QMouseEvent event( QEvent::MouseMove, QPoint( 0, 0 ), 0, 0 ); 405 QMouseEvent event( QEvent::MouseMove, QPoint( 0, 0 ), 0, 0 );
408 mouseMoveEvent( &event ); 406 mouseMoveEvent( &event );
409} 407}
410 408
411 409
412void AudioWidget::paintEvent( QPaintEvent * pe ) { 410void AudioWidget::paintEvent( QPaintEvent * pe ) {
413 if ( !pe->erased() ) { 411 if ( !pe->erased() ) {
414 // Combine with background and double buffer 412 // Combine with background and double buffer
415 QPixmap pix( pe->rect().size() ); 413 QPixmap pix( pe->rect().size() );
416 QPainter p( &pix ); 414 QPainter p( &pix );
417 p.translate( -pe->rect().topLeft().x(), -pe->rect().topLeft().y() ); 415 p.translate( -pe->rect().topLeft().x(), -pe->rect().topLeft().y() );
418 p.drawTiledPixmap( pe->rect(), pixBg, pe->rect().topLeft() ); 416 p.drawTiledPixmap( pe->rect(), pixBg, pe->rect().topLeft() );
419 for ( unsigned int i = 0; i < buttons.size(); i++ ) 417 for ( unsigned int i = 0; i < buttons.size(); i++ )
420 paintButton( p, i ); 418 paintButton( p, i );
421 QPainter p2( this ); 419 QPainter p2( this );
422 p2.drawPixmap( pe->rect().topLeft(), pix ); 420 p2.drawPixmap( pe->rect().topLeft(), pix );
423 } else { 421 } else {
424 QPainter p( this ); 422 QPainter p( this );
425 for ( unsigned int i = 0; i < buttons.size(); i++ ) 423 for ( unsigned int i = 0; i < buttons.size(); i++ )
426 paintButton( p, i ); 424 paintButton( p, i );
427 } 425 }
428} 426}
429 427
430void AudioWidget::keyReleaseEvent( QKeyEvent *e) { 428void AudioWidget::keyReleaseEvent( QKeyEvent *e) {
431 switch ( e->key() ) { 429 switch ( e->key() ) {
432 ////////////////////////////// Zaurus keys 430 ////////////////////////////// Zaurus keys
433 case Key_Home: 431 case Key_Home:
434 break; 432 break;
435 case Key_F9: //activity 433 case Key_F9: //activity
436 hide(); 434 hide();
437 // qDebug("Audio F9"); 435 // qDebug("Audio F9");
438 break; 436 break;
439 case Key_F10: //contacts 437 case Key_F10: //contacts
440 break; 438 break;
441 case Key_F11: //menu 439 case Key_F11: //menu
442 mediaPlayerState.toggleBlank(); 440 mediaPlayerState.toggleBlank();
443 break; 441 break;
444 case Key_F12: //home 442 case Key_F12: //home
445 break; 443 break;
446 case Key_F13: //mail 444 case Key_F13: //mail
447 mediaPlayerState.toggleBlank(); 445 mediaPlayerState.toggleBlank();
448 break; 446 break;
449 case Key_Space: { 447 case Key_Space: {
450 mediaPlayerState.togglePaused(); 448 mediaPlayerState.togglePaused();
451 } 449 }
452 break; 450 break;
453 case Key_Down: 451 case Key_Down:
454 // toggleButton(6); 452 // toggleButton(6);
455 emit lessClicked(); 453 emit lessClicked();
456 emit lessReleased(); 454 emit lessReleased();
457 // toggleButton(6); 455 // toggleButton(6);
458 break; 456 break;
459 case Key_Up: 457 case Key_Up:
460 // toggleButton(5); 458 // toggleButton(5);
461 emit moreClicked(); 459 emit moreClicked();
462 emit moreReleased(); 460 emit moreReleased();
463 // toggleButton(5); 461 // toggleButton(5);
464 break; 462 break;
465 case Key_Right: 463 case Key_Right:
466 // toggleButton(3); 464 // toggleButton(3);
467 mediaPlayerState.setNext(); 465 mediaPlayerState.setNext();
468 // toggleButton(3); 466 // toggleButton(3);
469 break; 467 break;
470 case Key_Left: 468 case Key_Left:
471 // toggleButton(4); 469 // toggleButton(4);
472 mediaPlayerState.setPrev(); 470 mediaPlayerState.setPrev();
473 // toggleButton(4); 471 // toggleButton(4);
474 break; 472 break;
475 case Key_Escape: { 473 case Key_Escape: {
476 } 474 }
477 break; 475 break;
478 476
479 }; 477 };
480} 478}