summaryrefslogtreecommitdiff
authorharlekin <harlekin>2002-09-04 13:05:47 (UTC)
committer harlekin <harlekin>2002-09-04 13:05:47 (UTC)
commit41a5097ec65c57935aa4425e7e969be9ca591fba (patch) (unidiff)
tree0988e9b474e7ac50068e10f9c4ec3d85e4a75ef8
parent04da91b7a4451366cb005c1e2bb4f649283cc7f9 (diff)
downloadopie-41a5097ec65c57935aa4425e7e969be9ca591fba.zip
opie-41a5097ec65c57935aa4425e7e969be9ca591fba.tar.gz
opie-41a5097ec65c57935aa4425e7e969be9ca591fba.tar.bz2
test
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/multimedia/opieplayer2/audiowidget.cpp5
1 files changed, 4 insertions, 1 deletions
diff --git a/noncore/multimedia/opieplayer2/audiowidget.cpp b/noncore/multimedia/opieplayer2/audiowidget.cpp
index a718826..040e965 100644
--- a/noncore/multimedia/opieplayer2/audiowidget.cpp
+++ b/noncore/multimedia/opieplayer2/audiowidget.cpp
@@ -1,592 +1,595 @@
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 37
38#include <qwidget.h> 38#include <qwidget.h>
39#include <qpixmap.h> 39#include <qpixmap.h>
40#include <qbutton.h> 40#include <qbutton.h>
41#include <qpainter.h> 41#include <qpainter.h>
42#include <qframe.h> 42#include <qframe.h>
43#include <qlayout.h> 43#include <qlayout.h>
44 44
45#include <stdlib.h> 45#include <stdlib.h>
46#include <stdio.h> 46#include <stdio.h>
47 47
48#include "audiowidget.h" 48#include "audiowidget.h"
49#include "mediaplayerstate.h" 49#include "mediaplayerstate.h"
50 50
51extern MediaPlayerState *mediaPlayerState; 51extern MediaPlayerState *mediaPlayerState;
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
56 56
57Ticker::Ticker( QWidget* parent=0 ) : QFrame( parent ) { 57Ticker::Ticker( QWidget* parent=0 ) : QFrame( parent ) {
58 setFrameStyle( WinPanel | Sunken ); 58 setFrameStyle( WinPanel | Sunken );
59 setText( "No Song" ); 59 setText( "No Song" );
60} 60}
61 61
62Ticker::~Ticker() { 62Ticker::~Ticker() {
63} 63}
64 64
65void Ticker::setText( const QString& text ) { 65void Ticker::setText( const QString& text ) {
66 pos = 0; // reset it everytime the text is changed 66 pos = 0; // reset it everytime the text is changed
67 scrollText = text; 67 scrollText = text;
68 pixelLen = fontMetrics().width( scrollText ); 68 pixelLen = fontMetrics().width( scrollText );
69 killTimers(); 69 killTimers();
70 if ( pixelLen > width() ) { 70 if ( pixelLen > width() ) {
71 startTimer( 50 ); 71 startTimer( 50 );
72 } 72 }
73 update(); 73 update();
74} 74}
75 75
76 76
77void Ticker::timerEvent( QTimerEvent * ) { 77void Ticker::timerEvent( QTimerEvent * ) {
78 pos = ( pos + 1 > pixelLen ) ? 0 : pos + 1; 78 pos = ( pos + 1 > pixelLen ) ? 0 : pos + 1;
79 scroll( -1, 0, contentsRect() ); 79 scroll( -1, 0, contentsRect() );
80 repaint( FALSE ); 80 repaint( FALSE );
81} 81}
82 82
83void Ticker::drawContents( QPainter *p ) { 83void Ticker::drawContents( QPainter *p ) {
84 for ( int i = 0; i - pos < width() && (i < 1 || pixelLen > width()); i += pixelLen ) { 84 for ( int i = 0; i - pos < width() && (i < 1 || pixelLen > width()); i += pixelLen ) {
85 p->drawText( i - pos, 0, INT_MAX, height(), AlignVCenter, scrollText ); 85 p->drawText( i - pos, 0, INT_MAX, height(), AlignVCenter, scrollText );
86 } 86 }
87 QPixmap pm( width(), height() ); 87 QPixmap pm( width(), height() );
88 pm.fill( colorGroup().base() ); 88 pm.fill( colorGroup().base() );
89 QPainter pmp( &pm ); 89 QPainter pmp( &pm );
90 for ( int i = 0; i - pos < width() && (i < 1 || pixelLen > width()); i += pixelLen ) { 90 for ( int i = 0; i - pos < width() && (i < 1 || pixelLen > width()); i += pixelLen ) {
91 pmp.drawText( i - pos, 0, INT_MAX, height(), AlignVCenter, scrollText ); 91 pmp.drawText( i - pos, 0, INT_MAX, height(), AlignVCenter, scrollText );
92 } 92 }
93 p->drawPixmap( 0, 0, pm ); 93 p->drawPixmap( 0, 0, pm );
94} 94}
95 95
96struct MediaButton { 96struct MediaButton {
97 bool isToggle, isHeld, isDown; 97 bool isToggle, isHeld, isDown;
98}; 98};
99 99
100//Layout information for the audioButtons (and if it is a toggle button or not) 100//Layout information for the audioButtons (and if it is a toggle button or not)
101MediaButton audioButtons[] = { 101MediaButton audioButtons[] = {
102 { TRUE, FALSE, FALSE }, // play 102 { TRUE, FALSE, FALSE }, // play
103 { FALSE, FALSE, FALSE }, // stop 103 { FALSE, FALSE, FALSE }, // stop
104 { FALSE, FALSE, FALSE }, // next 104 { FALSE, FALSE, FALSE }, // next
105 { FALSE, FALSE, FALSE }, // previous 105 { FALSE, FALSE, FALSE }, // previous
106 { FALSE, FALSE, FALSE }, // volume up 106 { FALSE, FALSE, FALSE }, // volume up
107 { FALSE, FALSE, FALSE }, // volume down 107 { FALSE, FALSE, FALSE }, // volume down
108 { TRUE, FALSE, FALSE }, // repeat/loop 108 { TRUE, FALSE, FALSE }, // repeat/loop
109 { FALSE, FALSE, FALSE }, // playlist 109 { FALSE, FALSE, FALSE }, // playlist
110 { FALSE, FALSE, FALSE }, // forward 110 { FALSE, FALSE, FALSE }, // forward
111 { FALSE, FALSE, FALSE } // back 111 { FALSE, FALSE, FALSE } // back
112}; 112};
113 113
114const char *skin_mask_file_names[10] = { 114const char *skin_mask_file_names[10] = {
115 "play", "stop", "next", "prev", "up", 115 "play", "stop", "next", "prev", "up",
116 "down", "loop", "playlist", "forward", "back" 116 "down", "loop", "playlist", "forward", "back"
117}; 117};
118 118
119 119
120static void changeTextColor( QWidget *w ) { 120static void changeTextColor( QWidget *w ) {
121 QPalette p = w->palette(); 121 QPalette p = w->palette();
122 p.setBrush( QColorGroup::Background, QColor( 167, 212, 167 ) ); 122 p.setBrush( QColorGroup::Background, QColor( 167, 212, 167 ) );
123 p.setBrush( QColorGroup::Base, QColor( 167, 212, 167 ) ); 123 p.setBrush( QColorGroup::Base, QColor( 167, 212, 167 ) );
124 w->setPalette( p ); 124 w->setPalette( p );
125} 125}
126 126
127static const int numButtons = (sizeof(audioButtons)/sizeof(MediaButton)); 127static const int numButtons = (sizeof(audioButtons)/sizeof(MediaButton));
128 128
129 129
130AudioWidget::AudioWidget(QWidget* parent, const char* name, WFlags f) : 130AudioWidget::AudioWidget(QWidget* parent, const char* name, WFlags f) :
131 131
132 QWidget( parent, name, f ), songInfo( this ), slider( Qt::Horizontal, this ), time( this ) { 132 QWidget( parent, name, f ), songInfo( this ), slider( Qt::Horizontal, this ), time( this ) {
133 133
134 setCaption( tr("OpiePlayer") ); 134 setCaption( tr("OpiePlayer") );
135 135
136 Config cfg("OpiePlayer"); 136 Config cfg("OpiePlayer");
137 cfg.setGroup("Options"); 137 cfg.setGroup("Options");
138 skin = cfg.readEntry("Skin","default"); 138 skin = cfg.readEntry("Skin","default");
139 //skin = "scaleTest"; 139 //skin = "scaleTest";
140 // color of background, frame, degree of transparency 140 // color of background, frame, degree of transparency
141 141
142 QString skinPath = "opieplayer2/skins/" + skin; 142 QString skinPath = "opieplayer2/skins/" + skin;
143 pixBg = new QPixmap( Resource::loadPixmap( QString("%1/background").arg(skinPath) ) ); 143 pixBg = new QPixmap( Resource::loadPixmap( QString("%1/background").arg(skinPath) ) );
144 imgUp = new QImage( Resource::loadImage( QString("%1/skin_up").arg(skinPath) ) ); 144 imgUp = new QImage( Resource::loadImage( QString("%1/skin_up").arg(skinPath) ) );
145 imgDn = new QImage( Resource::loadImage( QString("%1/skin_down").arg(skinPath) ) ); 145 imgDn = new QImage( Resource::loadImage( QString("%1/skin_down").arg(skinPath) ) );
146 146
147 imgButtonMask = new QImage( imgUp->width(), imgUp->height(), 8, 255 ); 147 imgButtonMask = new QImage( imgUp->width(), imgUp->height(), 8, 255 );
148 imgButtonMask->fill( 0 ); 148 imgButtonMask->fill( 0 );
149 149
150 for ( int i = 0; i < 10; i++ ) { 150 for ( int i = 0; i < 10; i++ ) {
151 QString filename = QString( QPEApplication::qpeDir() + "/pics/" + skinPath + "/skin_mask_" + skin_mask_file_names[i] + ".png" ); 151 QString filename = QString( QPEApplication::qpeDir() + "/pics/" + skinPath + "/skin_mask_" + skin_mask_file_names[i] + ".png" );
152 masks[i] = new QBitmap( filename ); 152 masks[i] = new QBitmap( filename );
153 153
154 if ( !masks[i]->isNull() ) { 154 if ( !masks[i]->isNull() ) {
155 QImage imgMask = masks[i]->convertToImage(); 155 QImage imgMask = masks[i]->convertToImage();
156 uchar **dest = imgButtonMask->jumpTable(); 156 uchar **dest = imgButtonMask->jumpTable();
157 for ( int y = 0; y < imgUp->height(); y++ ) { 157 for ( int y = 0; y < imgUp->height(); y++ ) {
158 uchar *line = dest[y]; 158 uchar *line = dest[y];
159 for ( int x = 0; x < imgUp->width(); x++ ) 159 for ( int x = 0; x < imgUp->width(); x++ )
160 if ( !qRed( imgMask.pixel( x, y ) ) ) 160 if ( !qRed( imgMask.pixel( x, y ) ) )
161 line[x] = i + 1; 161 line[x] = i + 1;
162 } 162 }
163 } 163 }
164 164
165 } 165 }
166 166
167 for ( int i = 0; i < 10; i++ ) { 167 for ( int i = 0; i < 10; i++ ) {
168 buttonPixUp[i] = 0l; 168 buttonPixUp[i] = 0l;
169 buttonPixDown[i] = 0l; 169 buttonPixDown[i] = 0l;
170 } 170 }
171 171
172 setBackgroundPixmap( *pixBg ); 172 setBackgroundPixmap( *pixBg );
173 173
174 songInfo.setFocusPolicy( QWidget::NoFocus ); 174 songInfo.setFocusPolicy( QWidget::NoFocus );
175 changeTextColor( &songInfo ); 175 changeTextColor( &songInfo );
176 176
177 slider.setFixedHeight( 20 ); 177 slider.setFixedHeight( 20 );
178 slider.setMinValue( 0 ); 178 slider.setMinValue( 0 );
179 slider.setMaxValue( 1 ); 179 slider.setMaxValue( 1 );
180 slider.setFocusPolicy( QWidget::NoFocus ); 180 slider.setFocusPolicy( QWidget::NoFocus );
181 slider.setBackgroundPixmap( *pixBg ); 181 slider.setBackgroundPixmap( *pixBg );
182 182
183 time.setFocusPolicy( QWidget::NoFocus ); 183 time.setFocusPolicy( QWidget::NoFocus );
184 time.setAlignment( Qt::AlignCenter ); 184 time.setAlignment( Qt::AlignCenter );
185 time.setFrame(FALSE); 185 time.setFrame(FALSE);
186 changeTextColor( &time ); 186 changeTextColor( &time );
187 187
188 resizeEvent( NULL ); 188 resizeEvent( NULL );
189 189
190 connect( &slider, SIGNAL( sliderPressed() ), this, SLOT( sliderPressed() ) ); 190 connect( &slider, SIGNAL( sliderPressed() ), this, SLOT( sliderPressed() ) );
191 connect( &slider, SIGNAL( sliderReleased() ), this, SLOT( sliderReleased() ) ); 191 connect( &slider, SIGNAL( sliderReleased() ), this, SLOT( sliderReleased() ) );
192 192
193 connect( mediaPlayerState, SIGNAL( lengthChanged(long) ), this, SLOT( setLength(long) ) ); 193 connect( mediaPlayerState, SIGNAL( lengthChanged(long) ), this, SLOT( setLength(long) ) );
194 connect( mediaPlayerState, SIGNAL( viewChanged(char) ), this, SLOT( setView(char) ) ); 194 connect( mediaPlayerState, SIGNAL( viewChanged(char) ), this, SLOT( setView(char) ) );
195 connect( mediaPlayerState, SIGNAL( loopingToggled(bool) ), this, SLOT( setLooping(bool) ) ); 195 connect( mediaPlayerState, SIGNAL( loopingToggled(bool) ), this, SLOT( setLooping(bool) ) );
196 // connect( mediaPlayerState, SIGNAL( pausedToggled(bool) ), this, SLOT( setPaused(bool) ) ); 196 // connect( mediaPlayerState, SIGNAL( pausedToggled(bool) ), this, SLOT( setPaused(bool) ) );
197 connect( mediaPlayerState, SIGNAL( playingToggled(bool) ), this, SLOT( setPlaying(bool) ) ); 197 connect( mediaPlayerState, SIGNAL( playingToggled(bool) ), this, SLOT( setPlaying(bool) ) );
198 198
199 connect( this, SIGNAL( forwardClicked() ), this, SLOT( skipFor() ) ); 199 connect( this, SIGNAL( forwardClicked() ), this, SLOT( skipFor() ) );
200 connect( this, SIGNAL( backClicked() ), this, SLOT( skipBack() ) ); 200 connect( this, SIGNAL( backClicked() ), this, SLOT( skipBack() ) );
201 connect( this, SIGNAL( forwardReleased() ), this, SLOT( stopSkip() ) ); 201 connect( this, SIGNAL( forwardReleased() ), this, SLOT( stopSkip() ) );
202 connect( this, SIGNAL( backReleased() ), this, SLOT( stopSkip() ) ); 202 connect( this, SIGNAL( backReleased() ), this, SLOT( stopSkip() ) );
203 203
204 204
205 205
206 // Intialise state 206 // Intialise state
207 setLength( mediaPlayerState->length() ); 207 setLength( mediaPlayerState->length() );
208 setPosition( mediaPlayerState->position() ); 208 setPosition( mediaPlayerState->position() );
209 setLooping( mediaPlayerState->fullscreen() ); 209 setLooping( mediaPlayerState->fullscreen() );
210 // setPaused( mediaPlayerState->paused() ); 210 // setPaused( mediaPlayerState->paused() );
211 setPlaying( mediaPlayerState->playing() ); 211 setPlaying( mediaPlayerState->playing() );
212 212
213} 213}
214 214
215AudioWidget::~AudioWidget() { 215AudioWidget::~AudioWidget() {
216 216
217 for ( int i = 0; i < 10; i++ ) { 217 for ( int i = 0; i < 10; i++ ) {
218 delete buttonPixUp[i]; 218 delete buttonPixUp[i];
219 delete buttonPixDown[i]; 219 delete buttonPixDown[i];
220 } 220 }
221 delete pixBg; 221 delete pixBg;
222 delete imgUp; 222 delete imgUp;
223 delete imgDn; 223 delete imgDn;
224 delete imgButtonMask; 224 delete imgButtonMask;
225 for ( int i = 0; i < 10; i++ ) { 225 for ( int i = 0; i < 10; i++ ) {
226 delete masks[i]; 226 delete masks[i];
227 } 227 }
228} 228}
229 229
230namespace { 230namespace {
231 231
232QPixmap *combineImageWithBackground( QImage img, QPixmap bg, QPoint offset ) { 232QPixmap *combineImageWithBackground( QImage img, QPixmap bg, QPoint offset ) {
233 QPixmap pix( img.width(), img.height() ); 233 QPixmap pix( img.width(), img.height() );
234 QPainter p( &pix ); 234 QPainter p( &pix );
235 p.drawTiledPixmap( pix.rect(), bg, offset ); 235 p.drawTiledPixmap( pix.rect(), bg, offset );
236 p.drawImage( 0, 0, img ); 236 p.drawImage( 0, 0, img );
237 return new QPixmap( pix ); 237 return new QPixmap( pix );
238} 238}
239 239
240 240
241QPixmap *maskPixToMask( QPixmap pix, QBitmap mask ) { 241QPixmap *maskPixToMask( QPixmap pix, QBitmap mask ) {
242 QPixmap *pixmap = new QPixmap( pix ); 242 QPixmap *pixmap = new QPixmap( pix );
243 pixmap->setMask( mask ); 243 pixmap->setMask( mask );
244 return pixmap; 244 return pixmap;
245} 245}
246 246
247}; 247};
248 248
249void AudioWidget::resizeEvent( QResizeEvent * ) { 249void AudioWidget::resizeEvent( QResizeEvent * ) {
250 int h = height(); 250 int h = height();
251 int w = width(); 251 int w = width();
252 252
253 songInfo.setGeometry( QRect( 2, 10, w - 4, 20 ) ); 253 songInfo.setGeometry( QRect( 2, 10, w - 4, 20 ) );
254 slider.setFixedWidth( w - 110 ); 254 slider.setFixedWidth( w - 110 );
255 slider.setGeometry( QRect( 15, h - 30, w - 90, 20 ) ); 255 slider.setGeometry( QRect( 15, h - 30, w - 90, 20 ) );
256 slider.setBackgroundOrigin( QWidget::ParentOrigin ); 256 slider.setBackgroundOrigin( QWidget::ParentOrigin );
257 time.setGeometry( QRect( w - 85, h - 30, 70, 20 ) ); 257 time.setGeometry( QRect( w - 85, h - 30, 70, 20 ) );
258 258
259 xoff = ( w - imgUp->width() ) / 2; 259 xoff = ( w - imgUp->width() ) / 2;
260 yoff = (( h - imgUp->height() ) / 2) - 10; 260 yoff = (( h - imgUp->height() ) / 2) - 10;
261 QPoint p( xoff, yoff ); 261 QPoint p( xoff, yoff );
262 262
263 QPixmap *pixUp = combineImageWithBackground( *imgUp, *pixBg, p ); 263 QPixmap *pixUp = combineImageWithBackground( *imgUp, *pixBg, p );
264 QPixmap *pixDn = combineImageWithBackground( *imgDn, *pixBg, p ); 264 QPixmap *pixDn = combineImageWithBackground( *imgDn, *pixBg, p );
265 265
266 for ( int i = 0; i < 10; i++ ) { 266 for ( int i = 0; i < 10; i++ ) {
267 if ( !masks[i]->isNull() ) { 267 if ( !masks[i]->isNull() ) {
268 delete buttonPixUp[i]; 268 delete buttonPixUp[i];
269 delete buttonPixDown[i]; 269 delete buttonPixDown[i];
270 buttonPixUp[i] = maskPixToMask( *pixUp, *masks[i] ); 270 buttonPixUp[i] = maskPixToMask( *pixUp, *masks[i] );
271 buttonPixDown[i] = maskPixToMask( *pixDn, *masks[i] ); 271 buttonPixDown[i] = maskPixToMask( *pixDn, *masks[i] );
272 } 272 }
273 } 273 }
274 274
275 delete pixUp; 275 delete pixUp;
276 delete pixDn; 276 delete pixDn;
277} 277}
278 278
279static bool audioSliderBeingMoved = FALSE; 279static bool audioSliderBeingMoved = FALSE;
280 280
281 281
282void AudioWidget::sliderPressed() { 282void AudioWidget::sliderPressed() {
283 audioSliderBeingMoved = TRUE; 283 audioSliderBeingMoved = TRUE;
284} 284}
285 285
286 286
287void AudioWidget::sliderReleased() { 287void AudioWidget::sliderReleased() {
288 audioSliderBeingMoved = FALSE; 288 audioSliderBeingMoved = FALSE;
289 if ( slider.width() == 0 ) 289 if ( slider.width() == 0 )
290 return; 290 return;
291 long val = long((double)slider.value() * mediaPlayerState->length() / slider.width()); 291 long val = long((double)slider.value() * mediaPlayerState->length() / slider.width());
292 mediaPlayerState->setPosition( val ); 292 mediaPlayerState->setPosition( val );
293} 293}
294 294
295void AudioWidget::setPosition( long i ) { 295void AudioWidget::setPosition( long i ) {
296 // qDebug("<<<<<<<<<<<<<<<<<<<<<<<<set position %d",i); 296 // qDebug("<<<<<<<<<<<<<<<<<<<<<<<<set position %d",i);
297 updateSlider( i, mediaPlayerState->length() ); 297 updateSlider( i, mediaPlayerState->length() );
298} 298}
299 299
300 300
301void AudioWidget::setLength( long max ) { 301void AudioWidget::setLength( long max ) {
302 updateSlider( mediaPlayerState->position(), max ); 302 updateSlider( mediaPlayerState->position(), max );
303} 303}
304 304
305 305
306void AudioWidget::setView( char view ) { 306void AudioWidget::setView( char view ) {
307 307
308 // this isnt working for some reason 308 // this isnt working for some reason
309 309
310 if ( mediaPlayerState->streaming() ) { 310 if ( mediaPlayerState->streaming() ) {
311 qDebug("<<<<<<<<<<<<<<file is STREAMING>>>>>>>>>>>>>>>>>>>"); 311 qDebug("<<<<<<<<<<<<<<file is STREAMING>>>>>>>>>>>>>>>>>>>");
312 if( !slider.isHidden()) { 312 if( !slider.isHidden()) {
313 slider.hide(); 313 slider.hide();
314 } 314 }
315 disconnect( mediaPlayerState, SIGNAL( positionChanged(long) ),this, SLOT( setPosition(long) ) ); 315 disconnect( mediaPlayerState, SIGNAL( positionChanged(long) ),this, SLOT( setPosition(long) ) );
316 disconnect( mediaPlayerState, SIGNAL( positionUpdated(long) ),this, SLOT( setPosition(long) ) ); 316 disconnect( mediaPlayerState, SIGNAL( positionUpdated(long) ),this, SLOT( setPosition(long) ) );
317 } else { 317 } else {
318 // this stops the slider from being moved, thus 318 // this stops the slider from being moved, thus
319 // does not stop stream when it reaches the end 319 // does not stop stream when it reaches the end
320 slider.show(); 320 slider.show();
321 connect( mediaPlayerState, SIGNAL( positionChanged(long) ),this, SLOT( setPosition(long) ) ); 321 connect( mediaPlayerState, SIGNAL( positionChanged(long) ),this, SLOT( setPosition(long) ) );
322 connect( mediaPlayerState, SIGNAL( positionUpdated(long) ),this, SLOT( setPosition(long) ) ); 322 connect( mediaPlayerState, SIGNAL( positionUpdated(long) ),this, SLOT( setPosition(long) ) );
323 } 323 }
324 324
325 if ( view == 'a' ) { 325 if ( view == 'a' ) {
326 // startTimer( 150 ); 326 // startTimer( 150 );
327 showMaximized(); 327 showMaximized();
328 } else { 328 } else {
329 killTimers(); 329 killTimers();
330 hide(); 330 hide();
331 } 331 }
332 qApp->processEvents(); 332 qApp->processEvents();
333} 333}
334 334
335 335
336static QString timeAsString( long length ) { 336static QString timeAsString( long length ) {
337 int minutes = length / 60; 337 int minutes = length / 60;
338 int seconds = length % 60; 338 int seconds = length % 60;
339 return QString("%1:%2%3").arg( minutes ).arg( seconds / 10 ).arg( seconds % 10 ); 339 return QString("%1:%2%3").arg( minutes ).arg( seconds / 10 ).arg( seconds % 10 );
340} 340}
341 341
342void AudioWidget::updateSlider( long i, long max ) { 342void AudioWidget::updateSlider( long i, long max ) {
343 343
344 time.setText( timeAsString( i ) + " / " + timeAsString( max ) ); 344 time.setText( timeAsString( i ) + " / " + timeAsString( max ) );
345// qDebug( timeAsString( i ) + " / " + timeAsString( max ) ) ; 345// qDebug( timeAsString( i ) + " / " + timeAsString( max ) ) ;
346 346
347 if ( max == 0 ) { 347 if ( max == 0 ) {
348 return; 348 return;
349 } 349 }
350 // Will flicker too much if we don't do this 350 // Will flicker too much if we don't do this
351 // Scale to something reasonable 351 // Scale to something reasonable
352 int width = slider.width(); 352 int width = slider.width();
353 int val = int((double)i * width / max); 353 int val = int((double)i * width / max);
354 if ( !audioSliderBeingMoved ) { 354 if ( !audioSliderBeingMoved ) {
355 if ( slider.value() != val ) { 355 if ( slider.value() != val ) {
356 slider.setValue( val ); 356 slider.setValue( val );
357 } 357 }
358 358
359 if ( slider.maxValue() != width ) { 359 if ( slider.maxValue() != width ) {
360 slider.setMaxValue( width ); 360 slider.setMaxValue( width );
361 } 361 }
362 } 362 }
363} 363}
364 364
365 365
366void AudioWidget::setToggleButton( int i, bool down ) { 366void AudioWidget::setToggleButton( int i, bool down ) {
367 qDebug("setToggleButton %d", i); 367 qDebug("setToggleButton %d", i);
368 if ( down != audioButtons[i].isDown ) { 368 if ( down != audioButtons[i].isDown ) {
369 toggleButton( i ); 369 toggleButton( i );
370 } 370 }
371} 371}
372 372
373 373
374void AudioWidget::toggleButton( int i ) { 374void AudioWidget::toggleButton( int i ) {
375 audioButtons[i].isDown = !audioButtons[i].isDown; 375 audioButtons[i].isDown = !audioButtons[i].isDown;
376 QPainter p(this); 376 QPainter p(this);
377 paintButton ( &p, i ); 377 paintButton ( &p, i );
378} 378}
379 379
380 380
381void AudioWidget::paintButton( QPainter *p, int i ) { 381void AudioWidget::paintButton( QPainter *p, int i ) {
382 if ( audioButtons[i].isDown ) { 382 if ( audioButtons[i].isDown ) {
383 p->drawPixmap( xoff, yoff, *buttonPixDown[i] ); 383 p->drawPixmap( xoff, yoff, *buttonPixDown[i] );
384 } else { 384 } else {
385 p->drawPixmap( xoff, yoff, *buttonPixUp[i] ); 385 p->drawPixmap( xoff, yoff, *buttonPixUp[i] );
386 } 386 }
387} 387}
388 388
389 389
390void AudioWidget::skipFor() { 390void AudioWidget::skipFor() {
391 skipDirection = +1; 391 skipDirection = +1;
392 startTimer( 50 ); 392 startTimer( 50 );
393 mediaPlayerState->setPosition( mediaPlayerState->position() + 2 ); 393 mediaPlayerState->setPosition( mediaPlayerState->position() + 2 );
394} 394}
395 395
396void AudioWidget::skipBack() { 396void AudioWidget::skipBack() {
397 skipDirection = -1; 397 skipDirection = -1;
398 startTimer( 50 ); 398 startTimer( 50 );
399 mediaPlayerState->setPosition( mediaPlayerState->position() - 2 ); 399 mediaPlayerState->setPosition( mediaPlayerState->position() - 2 );
400} 400}
401 401
402 402
403 403
404void AudioWidget::stopSkip() { 404void AudioWidget::stopSkip() {
405 killTimers(); 405 killTimers();
406} 406}
407 407
408 408
409void AudioWidget::timerEvent( QTimerEvent * ) { 409void AudioWidget::timerEvent( QTimerEvent * ) {
410 if ( skipDirection == +1 ) { 410 if ( skipDirection == +1 ) {
411 mediaPlayerState->setPosition( mediaPlayerState->position() + 2 ); 411 mediaPlayerState->setPosition( mediaPlayerState->position() + 2 );
412 } else if ( skipDirection == -1 ) { 412 } else if ( skipDirection == -1 ) {
413 mediaPlayerState->setPosition( mediaPlayerState->position() - 2 ); 413 mediaPlayerState->setPosition( mediaPlayerState->position() - 2 );
414 } 414 }
415} 415}
416 416
417 417
418void AudioWidget::mouseMoveEvent( QMouseEvent *event ) { 418void AudioWidget::mouseMoveEvent( QMouseEvent *event ) {
419 for ( int i = 0; i < numButtons; i++ ) { 419 for ( int i = 0; i < numButtons; i++ ) {
420 if ( event->state() == QMouseEvent::LeftButton ) { 420 if ( event->state() == QMouseEvent::LeftButton ) {
421 // The test to see if the mouse click is inside the button or not 421 // The test to see if the mouse click is inside the button or not
422 int x = event->pos().x() - xoff; 422 int x = event->pos().x() - xoff;
423 int y = event->pos().y() - yoff; 423 int y = event->pos().y() - yoff;
424 424
425 bool isOnButton = ( x > 0 && y > 0 && x < imgButtonMask->width() 425 bool isOnButton = ( x > 0 && y > 0 && x < imgButtonMask->width()
426 && y < imgButtonMask->height() 426 && y < imgButtonMask->height()
427 && imgButtonMask->pixelIndex( x, y ) == i + 1 ); 427 && imgButtonMask->pixelIndex( x, y ) == i + 1 );
428 428
429 if ( isOnButton && !audioButtons[i].isHeld ) { 429 if ( isOnButton && !audioButtons[i].isHeld ) {
430 audioButtons[i].isHeld = TRUE; 430 audioButtons[i].isHeld = TRUE;
431 toggleButton(i); 431 toggleButton(i);
432 switch (i) { 432 switch (i) {
433 case AudioVolumeUp: 433 case AudioVolumeUp:
434 emit moreClicked(); 434 emit moreClicked();
435 return; 435 return;
436 case AudioVolumeDown: 436 case AudioVolumeDown:
437 emit lessClicked(); 437 emit lessClicked();
438 return; 438 return;
439 case AudioForward: 439 case AudioForward:
440 emit forwardClicked(); 440 emit forwardClicked();
441 return; 441 return;
442 case AudioBack: 442 case AudioBack:
443 emit backClicked(); 443 emit backClicked();
444 return; 444 return;
445 } 445 }
446 } else if ( !isOnButton && audioButtons[i].isHeld ) { 446 } else if ( !isOnButton && audioButtons[i].isHeld ) {
447 audioButtons[i].isHeld = FALSE; 447 audioButtons[i].isHeld = FALSE;
448 toggleButton(i); 448 toggleButton(i);
449 } 449 }
450 } else { 450 } else {
451 if ( audioButtons[i].isHeld ) { 451 if ( audioButtons[i].isHeld ) {
452 audioButtons[i].isHeld = FALSE; 452 audioButtons[i].isHeld = FALSE;
453 if ( !audioButtons[i].isToggle ) { 453 if ( !audioButtons[i].isToggle ) {
454 setToggleButton( i, FALSE ); 454 setToggleButton( i, FALSE );
455 } 455 }
456 switch (i) { 456 switch (i) {
457 case AudioPlay: 457 case AudioPlay:
458 if( mediaPlayerState->isPaused ) { 458 if( mediaPlayerState->isPaused ) {
459// setToggleButton( i, FALSE ); 459// setToggleButton( i, FALSE );
460 mediaPlayerState->setPaused( FALSE ); 460 mediaPlayerState->setPaused( FALSE );
461 return; 461 return;
462 } else if( !mediaPlayerState->isPaused ) { 462 } else if( !mediaPlayerState->isPaused ) {
463// setToggleButton( i, TRUE ); 463// setToggleButton( i, TRUE );
464 mediaPlayerState->setPaused( TRUE ); 464 mediaPlayerState->setPaused( TRUE );
465 return; 465 return;
466 } else { 466 } else {
467 // setToggleButton( i, TRUE ); 467 // setToggleButton( i, TRUE );
468 // mediaPlayerState->setPlaying( videoButtons[i].isDown ); 468 // mediaPlayerState->setPlaying( videoButtons[i].isDown );
469 } 469 }
470 case AudioStop: mediaPlayerState->setPlaying(FALSE); return; 470 case AudioStop: mediaPlayerState->setPlaying(FALSE); return;
471 case AudioNext: mediaPlayerState->setNext(); return; 471 case AudioNext: mediaPlayerState->setNext(); return;
472 case AudioPrevious: mediaPlayerState->setPrev(); return; 472 case AudioPrevious: mediaPlayerState->setPrev(); return;
473 case AudioLoop: mediaPlayerState->setLooping(audioButtons[i].isDown); return; 473 case AudioLoop: mediaPlayerState->setLooping(audioButtons[i].isDown); return;
474 case AudioVolumeUp: emit moreReleased(); return; 474 case AudioVolumeUp: emit moreReleased(); return;
475 case AudioVolumeDown: emit lessReleased(); return; 475 case AudioVolumeDown: emit lessReleased(); return;
476 case AudioPlayList: mediaPlayerState->setList(); return; 476 case AudioPlayList: mediaPlayerState->setList(); return;
477 case AudioForward: emit forwardReleased(); return; 477 case AudioForward: emit forwardReleased(); return;
478 case AudioBack: emit backReleased(); return; 478 case AudioBack: emit backReleased(); return;
479 } 479 }
480 } 480 }
481 } 481 }
482 } 482 }
483} 483}
484 484
485 485
486void AudioWidget::mousePressEvent( QMouseEvent *event ) { 486void AudioWidget::mousePressEvent( QMouseEvent *event ) {
487 mouseMoveEvent( event ); 487 mouseMoveEvent( event );
488} 488}
489 489
490 490
491void AudioWidget::mouseReleaseEvent( QMouseEvent *event ) { 491void AudioWidget::mouseReleaseEvent( QMouseEvent *event ) {
492 mouseMoveEvent( event ); 492 mouseMoveEvent( event );
493} 493}
494 494
495 495
496void AudioWidget::showEvent( QShowEvent* ) { 496void AudioWidget::showEvent( QShowEvent* ) {
497 QMouseEvent event( QEvent::MouseMove, QPoint( 0, 0 ), 0, 0 ); 497 QMouseEvent event( QEvent::MouseMove, QPoint( 0, 0 ), 0, 0 );
498 mouseMoveEvent( &event ); 498 mouseMoveEvent( &event );
499} 499}
500 500
501 501
502void AudioWidget::closeEvent( QCloseEvent* ) { 502void AudioWidget::closeEvent( QCloseEvent* ) {
503 mediaPlayerState->setList(); 503 mediaPlayerState->setList();
504} 504}
505 505
506 506
507void AudioWidget::paintEvent( QPaintEvent * pe) { 507void AudioWidget::paintEvent( QPaintEvent * pe) {
508 if ( !pe->erased() ) { 508 if ( !pe->erased() ) {
509 // Combine with background and double buffer 509 // Combine with background and double buffer
510 QPixmap pix( pe->rect().size() ); 510 QPixmap pix( pe->rect().size() );
511 QPainter p( &pix ); 511 QPainter p( &pix );
512 p.translate( -pe->rect().topLeft().x(), -pe->rect().topLeft().y() ); 512 p.translate( -pe->rect().topLeft().x(), -pe->rect().topLeft().y() );
513 p.drawTiledPixmap( pe->rect(), *pixBg, pe->rect().topLeft() ); 513 p.drawTiledPixmap( pe->rect(), *pixBg, pe->rect().topLeft() );
514 for ( int i = 0; i < numButtons; i++ ) 514 for ( int i = 0; i < numButtons; i++ )
515 paintButton( &p, i ); 515 paintButton( &p, i );
516 QPainter p2( this ); 516 QPainter p2( this );
517 p2.drawPixmap( pe->rect().topLeft(), pix ); 517 p2.drawPixmap( pe->rect().topLeft(), pix );
518 } else { 518 } else {
519 QPainter p( this ); 519 QPainter p( this );
520 for ( int i = 0; i < numButtons; i++ ) 520 for ( int i = 0; i < numButtons; i++ )
521 paintButton( &p, i ); 521 paintButton( &p, i );
522 } 522 }
523} 523}
524 524
525void AudioWidget::keyReleaseEvent( QKeyEvent *e) { 525void AudioWidget::keyReleaseEvent( QKeyEvent *e) {
526 switch ( e->key() ) { 526 switch ( e->key() ) {
527 ////////////////////////////// Zaurus keys 527 ////////////////////////////// Zaurus keys
528 case Key_Home: 528 case Key_Home:
529 break; 529 break;
530 case Key_F9: //activity 530 case Key_F9: //activity
531 hide(); 531 hide();
532 // qDebug("Audio F9"); 532 // qDebug("Audio F9");
533 break; 533 break;
534 case Key_F10: //contacts 534 case Key_F10: //contacts
535 break; 535 break;
536 case Key_F11: //menu 536 case Key_F11: //menu
537 mediaPlayerState->toggleBlank(); 537 mediaPlayerState->toggleBlank();
538 break; 538 break;
539 case Key_F12: //home 539 case Key_F12: //home
540 break; 540 break;
541 case Key_F13: //mail 541 case Key_F13: //mail
542 mediaPlayerState->toggleBlank(); 542 mediaPlayerState->toggleBlank();
543 break; 543 break;
544 case Key_Space: { 544 case Key_Space: {
545 if(mediaPlayerState->playing()) { 545 if(mediaPlayerState->playing()) {
546 // toggleButton(1); 546 // toggleButton(1);
547 mediaPlayerState->setPlaying(FALSE); 547 mediaPlayerState->setPlaying(FALSE);
548 // toggleButton(1); 548 // toggleButton(1);
549 } else { 549 } else {
550 // toggleButton(0); 550 // toggleButton(0);
551 mediaPlayerState->setPlaying(TRUE); 551 mediaPlayerState->setPlaying(TRUE);
552 // toggleButton(0); 552 // toggleButton(0);
553 } 553 }
554 } 554 }
555 break; 555 break;
556 case Key_Down: 556 case Key_Down:
557 // toggleButton(6); 557 // toggleButton(6);
558 emit lessClicked(); 558 emit lessClicked();
559 emit lessReleased(); 559 emit lessReleased();
560 // toggleButton(6); 560 // toggleButton(6);
561 break; 561 break;
562 case Key_Up: 562 case Key_Up:
563 // toggleButton(5); 563 // toggleButton(5);
564 emit moreClicked(); 564 emit moreClicked();
565 emit moreReleased(); 565 emit moreReleased();
566 // toggleButton(5); 566 // toggleButton(5);
567 break; 567 break;
568 case Key_Right: 568 case Key_Right:
569 // toggleButton(3); 569 // toggleButton(3);
570 mediaPlayerState->setNext(); 570 mediaPlayerState->setNext();
571 // toggleButton(3); 571 // toggleButton(3);
572 break; 572 break;
573 case Key_Left: 573 case Key_Left:
574 // toggleButton(4); 574 // toggleButton(4);
575 mediaPlayerState->setPrev(); 575 mediaPlayerState->setPrev();
576 // toggleButton(4); 576 // toggleButton(4);
577 break; 577 break;
578 case Key_Escape: { 578 case Key_Escape: {
579#if defined(QT_QWS_IPAQ) 579/*
580 * author pleas tell me where the i come from .-)
581 #if defined(QT_QWS_IPAQ)
580 if( mediaPlayerState->isPaused ) { 582 if( mediaPlayerState->isPaused ) {
581 setToggleButton( i, FALSE ); 583 setToggleButton( i, FALSE );
582 mediaPlayerState->setPaused( FALSE ); 584 mediaPlayerState->setPaused( FALSE );
583 } else if( !mediaPlayerState->isPaused ) { 585 } else if( !mediaPlayerState->isPaused ) {
584 setToggleButton( i, TRUE ); 586 setToggleButton( i, TRUE );
585 mediaPlayerState->setPaused( TRUE ); 587 mediaPlayerState->setPaused( TRUE );
586 } 588 }
587#endif 589#endif
590*/
588 } 591 }
589 break; 592 break;
590 593
591 }; 594 };
592} 595}