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