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