summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/multimedia/opieplayer2/audiowidget.cpp28
-rw-r--r--noncore/multimedia/opieplayer2/audiowidget.h2
2 files changed, 26 insertions, 4 deletions
diff --git a/noncore/multimedia/opieplayer2/audiowidget.cpp b/noncore/multimedia/opieplayer2/audiowidget.cpp
index 879d0b4..4172da0 100644
--- a/noncore/multimedia/opieplayer2/audiowidget.cpp
+++ b/noncore/multimedia/opieplayer2/audiowidget.cpp
@@ -1,224 +1,244 @@
1/* 1/*
2                This file is part of the Opie Project 2                This file is part of the Opie Project
3 3
4              Copyright (c) 2002 Max Reiss <harlekin@handhelds.org> 4              Copyright (c) 2002 Max Reiss <harlekin@handhelds.org>
5 Copyright (c) 2002 L. Potter <ljp@llornkcor.com> 5 Copyright (c) 2002 L. Potter <ljp@llornkcor.com>
6 Copyright (c) 2002 Holger Freyther <zecke@handhelds.org> 6 Copyright (c) 2002 Holger Freyther <zecke@handhelds.org>
7 =. 7 =.
8 .=l. 8 .=l.
9           .>+-= 9           .>+-=
10 _;:,     .>    :=|. This program is free software; you can 10 _;:,     .>    :=|. This program is free software; you can
11.> <`_,   >  .   <= redistribute it and/or modify it under 11.> <`_,   >  .   <= redistribute it and/or modify it under
12:`=1 )Y*s>-.--   : the terms of the GNU General Public 12:`=1 )Y*s>-.--   : the terms of the GNU General Public
13.="- .-=="i,     .._ License as published by the Free Software 13.="- .-=="i,     .._ License as published by the Free Software
14 - .   .-<_>     .<> Foundation; either version 2 of the License, 14 - .   .-<_>     .<> Foundation; either version 2 of the License,
15     ._= =}       : or (at your option) any later version. 15     ._= =}       : or (at your option) any later version.
16    .%`+i>       _;_. 16    .%`+i>       _;_.
17    .i_,=:_.      -<s. This program is distributed in the hope that 17    .i_,=:_.      -<s. This program is distributed in the hope that
18     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY; 18     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
19    : ..    .:,     . . . without even the implied warranty of 19    : ..    .:,     . . . without even the implied warranty of
20    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A 20    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
21  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU 21  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
22..}^=.=       =       ; Library General Public License for more 22..}^=.=       =       ; Library General Public License for more
23++=   -.     .`     .: details. 23++=   -.     .`     .: details.
24 :     =  ...= . :.=- 24 :     =  ...= . :.=-
25 -.   .:....=;==+<; You should have received a copy of the GNU 25 -.   .:....=;==+<; You should have received a copy of the GNU
26  -_. . .   )=.  = Library General Public License along with 26  -_. . .   )=.  = Library General Public License along with
27    --        :-=` this library; see the file COPYING.LIB. 27    --        :-=` this library; see the file COPYING.LIB.
28 If not, write to the Free Software Foundation, 28 If not, write to the Free Software Foundation,
29 Inc., 59 Temple Place - Suite 330, 29 Inc., 59 Temple Place - Suite 330,
30 Boston, MA 02111-1307, USA. 30 Boston, MA 02111-1307, USA.
31 31
32*/ 32*/
33 33
34#include <qpe/qpeapplication.h> 34#include <qpe/qpeapplication.h>
35#include <qpe/resource.h> 35#include <qpe/resource.h>
36#include <qpe/config.h> 36#include <qpe/config.h>
37#include <opie/oticker.h> 37#include <opie/oticker.h>
38 38
39#include <qwidget.h> 39#include <qwidget.h>
40#include <qpixmap.h> 40#include <qpixmap.h>
41#include <qbutton.h> 41#include <qbutton.h>
42#include <qpainter.h> 42#include <qpainter.h>
43#include <qframe.h> 43#include <qframe.h>
44#include <qlayout.h> 44#include <qlayout.h>
45#include <qdir.h> 45#include <qdir.h>
46#include <stdlib.h> 46#include <stdlib.h>
47#include <stdio.h> 47#include <stdio.h>
48 48
49#include "audiowidget.h" 49#include "audiowidget.h"
50#include "mediaplayerstate.h" 50#include "mediaplayerstate.h"
51#include "playlistwidget.h" 51#include "playlistwidget.h"
52 52
53namespace 53namespace
54{ 54{
55 55
56const int xo = -2; // movable x offset 56const int xo = -2; // movable x offset
57const int yo = 22; // movable y offset 57const int yo = 22; // movable y offset
58 58
59struct MediaButton { 59struct MediaButton {
60 bool isToggle, isHeld, isDown; 60 bool isToggle, isHeld, isDown;
61}; 61};
62 62
63//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)
64/*
64MediaWidget::Button audioButtons[] = { 65MediaWidget::Button audioButtons[] = {
65 { TRUE, FALSE, FALSE }, // play 66 { TRUE, FALSE, FALSE }, // play
66 { FALSE, FALSE, FALSE }, // stop 67 { FALSE, FALSE, FALSE }, // stop
67 { FALSE, FALSE, FALSE }, // next 68 { FALSE, FALSE, FALSE }, // next
68 { FALSE, FALSE, FALSE }, // previous 69 { FALSE, FALSE, FALSE }, // previous
69 { FALSE, FALSE, FALSE }, // volume up 70 { FALSE, FALSE, FALSE }, // volume up
70 { FALSE, FALSE, FALSE }, // volume down 71 { FALSE, FALSE, FALSE }, // volume down
71 { TRUE, FALSE, FALSE }, // repeat/loop 72 { TRUE, FALSE, FALSE }, // repeat/loop
72 { FALSE, FALSE, FALSE }, // playlist 73 { FALSE, FALSE, FALSE }, // playlist
73 { FALSE, FALSE, FALSE }, // forward 74 { FALSE, FALSE, FALSE }, // forward
74 { FALSE, FALSE, FALSE } // back 75 { FALSE, FALSE, FALSE } // back
75}; 76};
77*/
76 78
77const char * const skin_mask_file_names[10] = { 79const char * const skin_mask_file_names[10] = {
78 "play", "stop", "next", "prev", "up", 80 "play", "stop", "next", "prev", "up",
79 "down", "loop", "playlist", "forward", "back" 81 "down", "loop", "playlist", "forward", "back"
80}; 82};
81 83
82void changeTextColor( QWidget * w) { 84void changeTextColor( QWidget * w) {
83 QPalette p = w->palette(); 85 QPalette p = w->palette();
84 p.setBrush( QColorGroup::Background, QColor( 167, 212, 167 ) ); 86 p.setBrush( QColorGroup::Background, QColor( 167, 212, 167 ) );
85 p.setBrush( QColorGroup::Base, QColor( 167, 212, 167 ) ); 87 p.setBrush( QColorGroup::Base, QColor( 167, 212, 167 ) );
86 w->setPalette( p ); 88 w->setPalette( p );
87} 89}
88 90
89const int numButtons = (sizeof(audioButtons)/sizeof(MediaWidget::Button)); 91//const int numButtons = (sizeof(audioButtons)/sizeof(MediaWidget::Button));
90 92
91} 93}
92 94
93AudioWidget::AudioWidget( PlayListWidget &playList, MediaPlayerState &mediaPlayerState, QWidget* parent, const char* name) : 95AudioWidget::AudioWidget( PlayListWidget &playList, MediaPlayerState &mediaPlayerState, QWidget* parent, const char* name) :
94 96
95 MediaWidget( playList, mediaPlayerState, parent, name ), songInfo( this ), slider( Qt::Horizontal, this ), time( this ) { 97 MediaWidget( playList, mediaPlayerState, parent, name ), songInfo( this ), slider( Qt::Horizontal, this ), time( this ) {
96 98
99 Button defaultButton;
100 defaultButton.isToggle = defaultButton.isHeld = defaultButton.isDown = false;
101 Button toggleButton;
102 toggleButton.isToggle = true;
103 toggleButton.isHeld = toggleButton.isDown = false;
104
105 audioButtons.reserve( 10 );
106 audioButtons.push_back( toggleButton ); // play
107 audioButtons.push_back( defaultButton ); // stop
108 audioButtons.push_back( defaultButton ); // next
109 audioButtons.push_back( defaultButton ); // previous
110 audioButtons.push_back( defaultButton ); // volume up
111 audioButtons.push_back( defaultButton ); // volume down
112 audioButtons.push_back( toggleButton ); // repeat/loop
113 audioButtons.push_back( defaultButton ); // playlist
114 audioButtons.push_back( defaultButton ); // forward
115 audioButtons.push_back( defaultButton ); // back
116
97 setCaption( tr("OpiePlayer") ); 117 setCaption( tr("OpiePlayer") );
98 118
99 Config cfg("OpiePlayer"); 119 Config cfg("OpiePlayer");
100 cfg.setGroup("Options"); 120 cfg.setGroup("Options");
101 skin = cfg.readEntry("Skin","default"); 121 skin = cfg.readEntry("Skin","default");
102 //skin = "scaleTest"; 122 //skin = "scaleTest";
103 // color of background, frame, degree of transparency 123 // color of background, frame, degree of transparency
104 124
105 QString skinPath = "opieplayer2/skins/" + skin; 125 QString skinPath = "opieplayer2/skins/" + skin;
106 pixBg = QPixmap( Resource::loadPixmap( QString("%1/background").arg(skinPath) ) ); 126 pixBg = QPixmap( Resource::loadPixmap( QString("%1/background").arg(skinPath) ) );
107 imgUp = QImage( Resource::loadImage( QString("%1/skin_up").arg(skinPath) ) ); 127 imgUp = QImage( Resource::loadImage( QString("%1/skin_up").arg(skinPath) ) );
108 imgDn = QImage( Resource::loadImage( QString("%1/skin_down").arg(skinPath) ) ); 128 imgDn = QImage( Resource::loadImage( QString("%1/skin_down").arg(skinPath) ) );
109 129
110 imgButtonMask = QImage( imgUp.width(), imgUp.height(), 8, 255 ); 130 imgButtonMask = QImage( imgUp.width(), imgUp.height(), 8, 255 );
111 imgButtonMask.fill( 0 ); 131 imgButtonMask.fill( 0 );
112 132
113 for ( int i = 0; i < 10; i++ ) { 133 for ( int i = 0; i < 10; i++ ) {
114 QString filename = QString( QPEApplication::qpeDir() + "/pics/" + skinPath + "/skin_mask_" + skin_mask_file_names[i] + ".png" ); 134 QString filename = QString( QPEApplication::qpeDir() + "/pics/" + skinPath + "/skin_mask_" + skin_mask_file_names[i] + ".png" );
115 masks[i] = new QBitmap( filename ); 135 masks[i] = new QBitmap( filename );
116 136
117 if ( !masks[i]->isNull() ) { 137 if ( !masks[i]->isNull() ) {
118 QImage imgMask = masks[i]->convertToImage(); 138 QImage imgMask = masks[i]->convertToImage();
119 uchar **dest = imgButtonMask.jumpTable(); 139 uchar **dest = imgButtonMask.jumpTable();
120 for ( int y = 0; y < imgUp.height(); y++ ) { 140 for ( int y = 0; y < imgUp.height(); y++ ) {
121 uchar *line = dest[y]; 141 uchar *line = dest[y];
122 for ( int x = 0; x < imgUp.width(); x++ ) 142 for ( int x = 0; x < imgUp.width(); x++ )
123 if ( !qRed( imgMask.pixel( x, y ) ) ) 143 if ( !qRed( imgMask.pixel( x, y ) ) )
124 line[x] = i + 1; 144 line[x] = i + 1;
125 } 145 }
126 } 146 }
127 147
128 } 148 }
129 149
130 for ( int i = 0; i < 10; i++ ) { 150 for ( int i = 0; i < 10; i++ ) {
131 buttonPixUp[i] = 0l; 151 buttonPixUp[i] = 0l;
132 buttonPixDown[i] = 0l; 152 buttonPixDown[i] = 0l;
133 } 153 }
134 154
135 setBackgroundPixmap( pixBg ); 155 setBackgroundPixmap( pixBg );
136 156
137 songInfo.setFocusPolicy( QWidget::NoFocus ); 157 songInfo.setFocusPolicy( QWidget::NoFocus );
138// changeTextColor( &songInfo ); 158// changeTextColor( &songInfo );
139// songInfo.setBackgroundColor( QColor( 167, 212, 167 )); 159// songInfo.setBackgroundColor( QColor( 167, 212, 167 ));
140// songInfo.setFrameStyle( QFrame::NoFrame); 160// songInfo.setFrameStyle( QFrame::NoFrame);
141 songInfo.setFrameStyle( QFrame::WinPanel | QFrame::Sunken ); 161 songInfo.setFrameStyle( QFrame::WinPanel | QFrame::Sunken );
142// songInfo.setForegroundColor(Qt::white); 162// songInfo.setForegroundColor(Qt::white);
143 163
144 slider.setFixedHeight( 20 ); 164 slider.setFixedHeight( 20 );
145 slider.setMinValue( 0 ); 165 slider.setMinValue( 0 );
146 slider.setMaxValue( 1 ); 166 slider.setMaxValue( 1 );
147 slider.setFocusPolicy( QWidget::NoFocus ); 167 slider.setFocusPolicy( QWidget::NoFocus );
148 slider.setBackgroundPixmap( pixBg ); 168 slider.setBackgroundPixmap( pixBg );
149 169
150// Config cofg("qpe"); 170// Config cofg("qpe");
151// cofg.setGroup("Appearance"); 171// cofg.setGroup("Appearance");
152// QColor backgroundcolor = QColor( cofg.readEntry( "Background", "#E5E1D5" ) ); 172// QColor backgroundcolor = QColor( cofg.readEntry( "Background", "#E5E1D5" ) );
153 173
154 time.setFocusPolicy( QWidget::NoFocus ); 174 time.setFocusPolicy( QWidget::NoFocus );
155 time.setAlignment( Qt::AlignCenter ); 175 time.setAlignment( Qt::AlignCenter );
156 176
157// time.setFrame(FALSE); 177// time.setFrame(FALSE);
158// changeTextColor( &time ); 178// changeTextColor( &time );
159 179
160 resizeEvent( NULL ); 180 resizeEvent( NULL );
161 181
162 connect( &mediaPlayerState, SIGNAL( loopingToggled(bool) ), this, SLOT( setLooping(bool) ) ); 182 connect( &mediaPlayerState, SIGNAL( loopingToggled(bool) ), this, SLOT( setLooping(bool) ) );
163 connect( &mediaPlayerState, SIGNAL( isSeekableToggled( bool ) ), this, SLOT( setSeekable( bool ) ) ); 183 connect( &mediaPlayerState, SIGNAL( isSeekableToggled( bool ) ), this, SLOT( setSeekable( bool ) ) );
164 184
165 connect( this, SIGNAL( forwardClicked() ), this, SLOT( skipFor() ) ); 185 connect( this, SIGNAL( forwardClicked() ), this, SLOT( skipFor() ) );
166 connect( this, SIGNAL( backClicked() ), this, SLOT( skipBack() ) ); 186 connect( this, SIGNAL( backClicked() ), this, SLOT( skipBack() ) );
167 connect( this, SIGNAL( forwardReleased() ), this, SLOT( stopSkip() ) ); 187 connect( this, SIGNAL( forwardReleased() ), this, SLOT( stopSkip() ) );
168 connect( this, SIGNAL( backReleased() ), this, SLOT( stopSkip() ) ); 188 connect( this, SIGNAL( backReleased() ), this, SLOT( stopSkip() ) );
169 189
170 // Intialise state 190 // Intialise state
171 setLength( mediaPlayerState.length() ); 191 setLength( mediaPlayerState.length() );
172 setPosition( mediaPlayerState.position() ); 192 setPosition( mediaPlayerState.position() );
173 setLooping( mediaPlayerState.isFullscreen() ); 193 setLooping( mediaPlayerState.isFullscreen() );
174 // setPaused( mediaPlayerState->paused() ); 194 // setPaused( mediaPlayerState->paused() );
175 setPlaying( mediaPlayerState.isPlaying() ); 195 setPlaying( mediaPlayerState.isPlaying() );
176 196
177} 197}
178 198
179AudioWidget::~AudioWidget() { 199AudioWidget::~AudioWidget() {
180 200
181 for ( int i = 0; i < 10; i++ ) { 201 for ( int i = 0; i < 10; i++ ) {
182 delete buttonPixUp[i]; 202 delete buttonPixUp[i];
183 delete buttonPixDown[i]; 203 delete buttonPixDown[i];
184 } 204 }
185 for ( int i = 0; i < 10; i++ ) { 205 for ( int i = 0; i < 10; i++ ) {
186 delete masks[i]; 206 delete masks[i];
187 } 207 }
188// mediaPlayerState->setPlaying(false); 208// mediaPlayerState->setPlaying(false);
189} 209}
190 210
191namespace { 211namespace {
192 212
193QPixmap combineImageWithBackground( QImage img, QPixmap bg, QPoint offset ) { 213QPixmap combineImageWithBackground( QImage img, QPixmap bg, QPoint offset ) {
194 QPixmap pix( img.width(), img.height() ); 214 QPixmap pix( img.width(), img.height() );
195 QPainter p( &pix ); 215 QPainter p( &pix );
196 p.drawTiledPixmap( pix.rect(), bg, offset ); 216 p.drawTiledPixmap( pix.rect(), bg, offset );
197 p.drawImage( 0, 0, img ); 217 p.drawImage( 0, 0, img );
198 return pix; 218 return pix;
199} 219}
200 220
201 221
202QPixmap *maskPixToMask( QPixmap pix, QBitmap mask ) { 222QPixmap *maskPixToMask( QPixmap pix, QBitmap mask ) {
203 QPixmap *pixmap = new QPixmap( pix ); 223 QPixmap *pixmap = new QPixmap( pix );
204 pixmap->setMask( mask ); 224 pixmap->setMask( mask );
205 return pixmap; 225 return pixmap;
206} 226}
207 227
208}; 228};
209 229
210void AudioWidget::resizeEvent( QResizeEvent * ) { 230void AudioWidget::resizeEvent( QResizeEvent * ) {
211 int h = height(); 231 int h = height();
212 int w = width(); 232 int w = width();
213 233
214 songInfo.setGeometry( QRect( 2, 2, w - 4, 20 ) ); 234 songInfo.setGeometry( QRect( 2, 2, w - 4, 20 ) );
215 slider.setFixedWidth( w - 110 ); 235 slider.setFixedWidth( w - 110 );
216 slider.setGeometry( QRect( 15, h - 22, w - 90, 20 ) ); 236 slider.setGeometry( QRect( 15, h - 22, w - 90, 20 ) );
217 slider.setBackgroundOrigin( QWidget::ParentOrigin ); 237 slider.setBackgroundOrigin( QWidget::ParentOrigin );
218 time.setGeometry( QRect( w - 85, h - 30, 70, 20 ) ); 238 time.setGeometry( QRect( w - 85, h - 30, 70, 20 ) );
219 239
220 xoff = ( w - imgUp.width() ) / 2; 240 xoff = ( w - imgUp.width() ) / 2;
221 yoff = (( h - imgUp.height() ) / 2) - 10; 241 yoff = (( h - imgUp.height() ) / 2) - 10;
222 QPoint p( xoff, yoff ); 242 QPoint p( xoff, yoff );
223 243
224 QPixmap pixUp = combineImageWithBackground( imgUp, pixBg, p ); 244 QPixmap pixUp = combineImageWithBackground( imgUp, pixBg, p );
@@ -255,266 +275,266 @@ void AudioWidget::setPosition( long i ) {
255 updateSlider( i, mediaPlayerState.length() ); 275 updateSlider( i, mediaPlayerState.length() );
256} 276}
257 277
258 278
259void AudioWidget::setLength( long max ) { 279void AudioWidget::setLength( long max ) {
260 updateSlider( mediaPlayerState.position(), max ); 280 updateSlider( mediaPlayerState.position(), max );
261} 281}
262 282
263 283
264void AudioWidget::setDisplayType( MediaPlayerState::DisplayType mediaType ) { 284void AudioWidget::setDisplayType( MediaPlayerState::DisplayType mediaType ) {
265 if ( mediaType == MediaPlayerState::Audio ) { 285 if ( mediaType == MediaPlayerState::Audio ) {
266 // startTimer( 150 ); 286 // startTimer( 150 );
267 showMaximized(); 287 showMaximized();
268 return; 288 return;
269 } 289 }
270 290
271 killTimers(); 291 killTimers();
272 hide(); 292 hide();
273} 293}
274 294
275 295
276void AudioWidget::setSeekable( bool isSeekable ) { 296void AudioWidget::setSeekable( bool isSeekable ) {
277 297
278 if ( !isSeekable ) { 298 if ( !isSeekable ) {
279 qDebug("<<<<<<<<<<<<<<file is STREAMING>>>>>>>>>>>>>>>>>>>"); 299 qDebug("<<<<<<<<<<<<<<file is STREAMING>>>>>>>>>>>>>>>>>>>");
280 if( !slider.isHidden()) { 300 if( !slider.isHidden()) {
281 slider.hide(); 301 slider.hide();
282 } 302 }
283 disconnect( &mediaPlayerState, SIGNAL( positionChanged(long) ),this, SLOT( setPosition(long) ) ); 303 disconnect( &mediaPlayerState, SIGNAL( positionChanged(long) ),this, SLOT( setPosition(long) ) );
284 disconnect( &mediaPlayerState, SIGNAL( positionUpdated(long) ),this, SLOT( setPosition(long) ) ); 304 disconnect( &mediaPlayerState, SIGNAL( positionUpdated(long) ),this, SLOT( setPosition(long) ) );
285 disconnect( &slider, SIGNAL( sliderPressed() ), this, SLOT( sliderPressed() ) ); 305 disconnect( &slider, SIGNAL( sliderPressed() ), this, SLOT( sliderPressed() ) );
286 disconnect( &slider, SIGNAL( sliderReleased() ), this, SLOT( sliderReleased() ) ); 306 disconnect( &slider, SIGNAL( sliderReleased() ), this, SLOT( sliderReleased() ) );
287 } else { 307 } else {
288 // this stops the slider from being moved, thus 308 // this stops the slider from being moved, thus
289 // does not stop stream when it reaches the end 309 // does not stop stream when it reaches the end
290 slider.show(); 310 slider.show();
291 qDebug( " CONNECT SET POSTION " ); 311 qDebug( " CONNECT SET POSTION " );
292 connect( &mediaPlayerState, SIGNAL( positionChanged(long) ),this, SLOT( setPosition(long) ) ); 312 connect( &mediaPlayerState, SIGNAL( positionChanged(long) ),this, SLOT( setPosition(long) ) );
293 connect( &mediaPlayerState, SIGNAL( positionUpdated(long) ),this, SLOT( setPosition(long) ) ); 313 connect( &mediaPlayerState, SIGNAL( positionUpdated(long) ),this, SLOT( setPosition(long) ) );
294 connect( &slider, SIGNAL( sliderPressed() ), this, SLOT( sliderPressed() ) ); 314 connect( &slider, SIGNAL( sliderPressed() ), this, SLOT( sliderPressed() ) );
295 connect( &slider, SIGNAL( sliderReleased() ), this, SLOT( sliderReleased() ) ); 315 connect( &slider, SIGNAL( sliderReleased() ), this, SLOT( sliderReleased() ) );
296 } 316 }
297} 317}
298 318
299 319
300static QString timeAsString( long length ) { 320static QString timeAsString( long length ) {
301 int minutes = length / 60; 321 int minutes = length / 60;
302 int seconds = length % 60; 322 int seconds = length % 60;
303 return QString("%1:%2%3").arg( minutes ).arg( seconds / 10 ).arg( seconds % 10 ); 323 return QString("%1:%2%3").arg( minutes ).arg( seconds / 10 ).arg( seconds % 10 );
304} 324}
305 325
306void AudioWidget::updateSlider( long i, long max ) { 326void AudioWidget::updateSlider( long i, long max ) {
307 327
308 time.setText( timeAsString( i ) + " / " + timeAsString( max ) ); 328 time.setText( timeAsString( i ) + " / " + timeAsString( max ) );
309// qDebug( timeAsString( i ) + " / " + timeAsString( max ) ) ; 329// qDebug( timeAsString( i ) + " / " + timeAsString( max ) ) ;
310 330
311 if ( max == 0 ) { 331 if ( max == 0 ) {
312 return; 332 return;
313 } 333 }
314 // Will flicker too much if we don't do this 334 // Will flicker too much if we don't do this
315 // Scale to something reasonable 335 // Scale to something reasonable
316 int width = slider.width(); 336 int width = slider.width();
317 int val = int((double)i * width / max); 337 int val = int((double)i * width / max);
318 if ( !audioSliderBeingMoved ) { 338 if ( !audioSliderBeingMoved ) {
319 if ( slider.value() != val ) { 339 if ( slider.value() != val ) {
320 slider.setValue( val ); 340 slider.setValue( val );
321 } 341 }
322 342
323 if ( slider.maxValue() != width ) { 343 if ( slider.maxValue() != width ) {
324 slider.setMaxValue( width ); 344 slider.setMaxValue( width );
325 } 345 }
326 } 346 }
327} 347}
328 348
329 349
330void AudioWidget::setToggleButton( int i, bool down ) { 350void AudioWidget::setToggleButton( int i, bool down ) {
331 qDebug("setToggleButton %d", i); 351 qDebug("setToggleButton %d", i);
332 if ( down != audioButtons[i].isDown ) { 352 if ( down != audioButtons[i].isDown ) {
333 toggleButton( i ); 353 toggleButton( i );
334 } 354 }
335} 355}
336 356
337 357
338void AudioWidget::toggleButton( int i ) { 358void AudioWidget::toggleButton( int i ) {
339 audioButtons[i].isDown = !audioButtons[i].isDown; 359 audioButtons[i].isDown = !audioButtons[i].isDown;
340 QPainter p(this); 360 QPainter p(this);
341 paintButton ( &p, i ); 361 paintButton ( &p, i );
342} 362}
343 363
344 364
345void AudioWidget::paintButton( QPainter *p, int i ) { 365void AudioWidget::paintButton( QPainter *p, int i ) {
346 if ( audioButtons[i].isDown ) { 366 if ( audioButtons[i].isDown ) {
347 p->drawPixmap( xoff, yoff, *buttonPixDown[i] ); 367 p->drawPixmap( xoff, yoff, *buttonPixDown[i] );
348 } else { 368 } else {
349 p->drawPixmap( xoff, yoff, *buttonPixUp[i] ); 369 p->drawPixmap( xoff, yoff, *buttonPixUp[i] );
350 } 370 }
351} 371}
352 372
353 373
354void AudioWidget::skipFor() { 374void AudioWidget::skipFor() {
355 skipDirection = +1; 375 skipDirection = +1;
356 startTimer( 50 ); 376 startTimer( 50 );
357 mediaPlayerState.setPosition( mediaPlayerState.position() + 2 ); 377 mediaPlayerState.setPosition( mediaPlayerState.position() + 2 );
358} 378}
359 379
360void AudioWidget::skipBack() { 380void AudioWidget::skipBack() {
361 skipDirection = -1; 381 skipDirection = -1;
362 startTimer( 50 ); 382 startTimer( 50 );
363 mediaPlayerState.setPosition( mediaPlayerState.position() - 2 ); 383 mediaPlayerState.setPosition( mediaPlayerState.position() - 2 );
364} 384}
365 385
366 386
367 387
368void AudioWidget::stopSkip() { 388void AudioWidget::stopSkip() {
369 killTimers(); 389 killTimers();
370} 390}
371 391
372 392
373void AudioWidget::timerEvent( QTimerEvent * ) { 393void AudioWidget::timerEvent( QTimerEvent * ) {
374 if ( skipDirection == +1 ) { 394 if ( skipDirection == +1 ) {
375 mediaPlayerState.setPosition( mediaPlayerState.position() + 2 ); 395 mediaPlayerState.setPosition( mediaPlayerState.position() + 2 );
376 } else if ( skipDirection == -1 ) { 396 } else if ( skipDirection == -1 ) {
377 mediaPlayerState.setPosition( mediaPlayerState.position() - 2 ); 397 mediaPlayerState.setPosition( mediaPlayerState.position() - 2 );
378 } 398 }
379} 399}
380 400
381 401
382void AudioWidget::mouseMoveEvent( QMouseEvent *event ) { 402void AudioWidget::mouseMoveEvent( QMouseEvent *event ) {
383 for ( int i = 0; i < numButtons; i++ ) { 403 for ( unsigned int i = 0; i < audioButtons.size(); i++ ) {
384 if ( event->state() == QMouseEvent::LeftButton ) { 404 if ( event->state() == QMouseEvent::LeftButton ) {
385 // The test to see if the mouse click is inside the button or not 405 // The test to see if the mouse click is inside the button or not
386 int x = event->pos().x() - xoff; 406 int x = event->pos().x() - xoff;
387 int y = event->pos().y() - yoff; 407 int y = event->pos().y() - yoff;
388 408
389 bool isOnButton = ( x > 0 && y > 0 && x < imgButtonMask.width() 409 bool isOnButton = ( x > 0 && y > 0 && x < imgButtonMask.width()
390 && y < imgButtonMask.height() 410 && y < imgButtonMask.height()
391 && imgButtonMask.pixelIndex( x, y ) == i + 1 ); 411 && imgButtonMask.pixelIndex( x, y ) == i + 1 );
392 412
393 if ( isOnButton && !audioButtons[i].isHeld ) { 413 if ( isOnButton && !audioButtons[i].isHeld ) {
394 audioButtons[i].isHeld = TRUE; 414 audioButtons[i].isHeld = TRUE;
395 toggleButton(i); 415 toggleButton(i);
396 switch (i) { 416 switch (i) {
397 case VolumeUp: 417 case VolumeUp:
398 emit moreClicked(); 418 emit moreClicked();
399 return; 419 return;
400 case VolumeDown: 420 case VolumeDown:
401 emit lessClicked(); 421 emit lessClicked();
402 return; 422 return;
403 case Forward: 423 case Forward:
404 emit forwardClicked(); 424 emit forwardClicked();
405 return; 425 return;
406 case Back: 426 case Back:
407 emit backClicked(); 427 emit backClicked();
408 return; 428 return;
409 } 429 }
410 } else if ( !isOnButton && audioButtons[i].isHeld ) { 430 } else if ( !isOnButton && audioButtons[i].isHeld ) {
411 audioButtons[i].isHeld = FALSE; 431 audioButtons[i].isHeld = FALSE;
412 toggleButton(i); 432 toggleButton(i);
413 } 433 }
414 } else { 434 } else {
415 if ( audioButtons[i].isHeld ) { 435 if ( audioButtons[i].isHeld ) {
416 audioButtons[i].isHeld = FALSE; 436 audioButtons[i].isHeld = FALSE;
417 if ( !audioButtons[i].isToggle ) { 437 if ( !audioButtons[i].isToggle ) {
418 setToggleButton( i, FALSE ); 438 setToggleButton( i, FALSE );
419 } 439 }
420 qDebug("mouseEvent %d", i); 440 qDebug("mouseEvent %d", i);
421 handleCommand( static_cast<Command>( i ), audioButtons[ i ].isDown ); 441 handleCommand( static_cast<Command>( i ), audioButtons[ i ].isDown );
422 } 442 }
423 } 443 }
424 } 444 }
425} 445}
426 446
427 447
428void AudioWidget::mousePressEvent( QMouseEvent *event ) { 448void AudioWidget::mousePressEvent( QMouseEvent *event ) {
429 mouseMoveEvent( event ); 449 mouseMoveEvent( event );
430} 450}
431 451
432 452
433void AudioWidget::mouseReleaseEvent( QMouseEvent *event ) { 453void AudioWidget::mouseReleaseEvent( QMouseEvent *event ) {
434 mouseMoveEvent( event ); 454 mouseMoveEvent( event );
435} 455}
436 456
437 457
438void AudioWidget::showEvent( QShowEvent* ) { 458void AudioWidget::showEvent( QShowEvent* ) {
439 QMouseEvent event( QEvent::MouseMove, QPoint( 0, 0 ), 0, 0 ); 459 QMouseEvent event( QEvent::MouseMove, QPoint( 0, 0 ), 0, 0 );
440 mouseMoveEvent( &event ); 460 mouseMoveEvent( &event );
441} 461}
442 462
443 463
444void AudioWidget::paintEvent( QPaintEvent * pe ) { 464void AudioWidget::paintEvent( QPaintEvent * pe ) {
445 if ( !pe->erased() ) { 465 if ( !pe->erased() ) {
446 // Combine with background and double buffer 466 // Combine with background and double buffer
447 QPixmap pix( pe->rect().size() ); 467 QPixmap pix( pe->rect().size() );
448 QPainter p( &pix ); 468 QPainter p( &pix );
449 p.translate( -pe->rect().topLeft().x(), -pe->rect().topLeft().y() ); 469 p.translate( -pe->rect().topLeft().x(), -pe->rect().topLeft().y() );
450 p.drawTiledPixmap( pe->rect(), pixBg, pe->rect().topLeft() ); 470 p.drawTiledPixmap( pe->rect(), pixBg, pe->rect().topLeft() );
451 for ( int i = 0; i < numButtons; i++ ) 471 for ( unsigned int i = 0; i < audioButtons.size(); i++ )
452 paintButton( &p, i ); 472 paintButton( &p, i );
453 QPainter p2( this ); 473 QPainter p2( this );
454 p2.drawPixmap( pe->rect().topLeft(), pix ); 474 p2.drawPixmap( pe->rect().topLeft(), pix );
455 } else { 475 } else {
456 QPainter p( this ); 476 QPainter p( this );
457 for ( int i = 0; i < numButtons; i++ ) 477 for ( unsigned int i = 0; i < audioButtons.size(); i++ )
458 paintButton( &p, i ); 478 paintButton( &p, i );
459 } 479 }
460} 480}
461 481
462void AudioWidget::keyReleaseEvent( QKeyEvent *e) { 482void AudioWidget::keyReleaseEvent( QKeyEvent *e) {
463 switch ( e->key() ) { 483 switch ( e->key() ) {
464 ////////////////////////////// Zaurus keys 484 ////////////////////////////// Zaurus keys
465 case Key_Home: 485 case Key_Home:
466 break; 486 break;
467 case Key_F9: //activity 487 case Key_F9: //activity
468 hide(); 488 hide();
469 // qDebug("Audio F9"); 489 // qDebug("Audio F9");
470 break; 490 break;
471 case Key_F10: //contacts 491 case Key_F10: //contacts
472 break; 492 break;
473 case Key_F11: //menu 493 case Key_F11: //menu
474 mediaPlayerState.toggleBlank(); 494 mediaPlayerState.toggleBlank();
475 break; 495 break;
476 case Key_F12: //home 496 case Key_F12: //home
477 break; 497 break;
478 case Key_F13: //mail 498 case Key_F13: //mail
479 mediaPlayerState.toggleBlank(); 499 mediaPlayerState.toggleBlank();
480 break; 500 break;
481 case Key_Space: { 501 case Key_Space: {
482 if(mediaPlayerState.isPlaying()) { 502 if(mediaPlayerState.isPlaying()) {
483 // toggleButton(1); 503 // toggleButton(1);
484 mediaPlayerState.setPlaying(FALSE); 504 mediaPlayerState.setPlaying(FALSE);
485 // toggleButton(1); 505 // toggleButton(1);
486 } else { 506 } else {
487 // toggleButton(0); 507 // toggleButton(0);
488 mediaPlayerState.setPlaying(TRUE); 508 mediaPlayerState.setPlaying(TRUE);
489 // toggleButton(0); 509 // toggleButton(0);
490 } 510 }
491 } 511 }
492 break; 512 break;
493 case Key_Down: 513 case Key_Down:
494 // toggleButton(6); 514 // toggleButton(6);
495 emit lessClicked(); 515 emit lessClicked();
496 emit lessReleased(); 516 emit lessReleased();
497 // toggleButton(6); 517 // toggleButton(6);
498 break; 518 break;
499 case Key_Up: 519 case Key_Up:
500 // toggleButton(5); 520 // toggleButton(5);
501 emit moreClicked(); 521 emit moreClicked();
502 emit moreReleased(); 522 emit moreReleased();
503 // toggleButton(5); 523 // toggleButton(5);
504 break; 524 break;
505 case Key_Right: 525 case Key_Right:
506 // toggleButton(3); 526 // toggleButton(3);
507 mediaPlayerState.setNext(); 527 mediaPlayerState.setNext();
508 // toggleButton(3); 528 // toggleButton(3);
509 break; 529 break;
510 case Key_Left: 530 case Key_Left:
511 // toggleButton(4); 531 // toggleButton(4);
512 mediaPlayerState.setPrev(); 532 mediaPlayerState.setPrev();
513 // toggleButton(4); 533 // toggleButton(4);
514 break; 534 break;
515 case Key_Escape: { 535 case Key_Escape: {
516 } 536 }
517 break; 537 break;
518 538
519 }; 539 };
520} 540}
diff --git a/noncore/multimedia/opieplayer2/audiowidget.h b/noncore/multimedia/opieplayer2/audiowidget.h
index 52a358c..e09c5f8 100644
--- a/noncore/multimedia/opieplayer2/audiowidget.h
+++ b/noncore/multimedia/opieplayer2/audiowidget.h
@@ -1,117 +1,119 @@
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#ifndef AUDIO_WIDGET_H 34#ifndef AUDIO_WIDGET_H
35#define AUDIO_WIDGET_H 35#define AUDIO_WIDGET_H
36 36
37#include <qpainter.h> 37#include <qpainter.h>
38#include <qdrawutil.h> 38#include <qdrawutil.h>
39#include <qpixmap.h> 39#include <qpixmap.h>
40#include <qstring.h> 40#include <qstring.h>
41#include <qslider.h> 41#include <qslider.h>
42#include <qframe.h> 42#include <qframe.h>
43#include <qlineedit.h> 43#include <qlineedit.h>
44#include <qimage.h> 44#include <qimage.h>
45 45
46#include <opie/oticker.h> 46#include <opie/oticker.h>
47 47
48#include "mediawidget.h" 48#include "mediawidget.h"
49 49
50class QPixmap; 50class QPixmap;
51 51
52class AudioWidget : public MediaWidget { 52class AudioWidget : public MediaWidget {
53 Q_OBJECT 53 Q_OBJECT
54public: 54public:
55 AudioWidget( PlayListWidget &playList, MediaPlayerState &mediaPlayerState, QWidget* parent=0, const char* name=0 ); 55 AudioWidget( PlayListWidget &playList, MediaPlayerState &mediaPlayerState, QWidget* parent=0, const char* name=0 );
56 ~AudioWidget(); 56 ~AudioWidget();
57 void setTickerText( const QString &text ) { songInfo.setText( text ); } 57 void setTickerText( const QString &text ) { songInfo.setText( text ); }
58public slots: 58public slots:
59 void updateSlider( long, long ); 59 void updateSlider( long, long );
60 void sliderPressed( ); 60 void sliderPressed( );
61 void sliderReleased( ); 61 void sliderReleased( );
62 void setLooping( bool b) { setToggleButton( Loop, b ); } 62 void setLooping( bool b) { setToggleButton( Loop, b ); }
63 void setPosition( long ); 63 void setPosition( long );
64 void setSeekable( bool ); 64 void setSeekable( bool );
65 65
66public: 66public:
67 virtual void setLength( long ); 67 virtual void setLength( long );
68 virtual void setPlaying( bool b) { setToggleButton( Play, b ); } 68 virtual void setPlaying( bool b) { setToggleButton( Play, b ); }
69 virtual void setDisplayType( MediaPlayerState::DisplayType displayType ); 69 virtual void setDisplayType( MediaPlayerState::DisplayType displayType );
70 70
71signals: 71signals:
72 void moreClicked(); 72 void moreClicked();
73 void lessClicked(); 73 void lessClicked();
74 void forwardClicked(); 74 void forwardClicked();
75 void backClicked(); 75 void backClicked();
76 void sliderMoved(long); 76 void sliderMoved(long);
77 77
78protected: 78protected:
79 void doBlank(); 79 void doBlank();
80 void doUnblank(); 80 void doUnblank();
81 void paintEvent( QPaintEvent *pe ); 81 void paintEvent( QPaintEvent *pe );
82 void showEvent( QShowEvent *se ); 82 void showEvent( QShowEvent *se );
83 void resizeEvent( QResizeEvent *re ); 83 void resizeEvent( QResizeEvent *re );
84 void mouseMoveEvent( QMouseEvent *event ); 84 void mouseMoveEvent( QMouseEvent *event );
85 void mousePressEvent( QMouseEvent *event ); 85 void mousePressEvent( QMouseEvent *event );
86 void mouseReleaseEvent( QMouseEvent *event ); 86 void mouseReleaseEvent( QMouseEvent *event );
87 void timerEvent( QTimerEvent *event ); 87 void timerEvent( QTimerEvent *event );
88 void keyReleaseEvent( QKeyEvent *e); 88 void keyReleaseEvent( QKeyEvent *e);
89private slots: 89private slots:
90 void skipFor(); 90 void skipFor();
91 void skipBack(); 91 void skipBack();
92 void stopSkip(); 92 void stopSkip();
93private: 93private:
94 void toggleButton( int ); 94 void toggleButton( int );
95 void setToggleButton( int, bool ); 95 void setToggleButton( int, bool );
96 void paintButton( QPainter *p, int i ); 96 void paintButton( QPainter *p, int i );
97 int skipDirection; 97 int skipDirection;
98 QString skin; 98 QString skin;
99 QPixmap pixBg; 99 QPixmap pixBg;
100 QImage imgUp; 100 QImage imgUp;
101 QImage imgDn; 101 QImage imgDn;
102 QImage imgButtonMask; 102 QImage imgButtonMask;
103 QBitmap *masks[10]; 103 QBitmap *masks[10];
104 QPixmap *buttonPixUp[10]; 104 QPixmap *buttonPixUp[10];
105 QPixmap *buttonPixDown[10]; 105 QPixmap *buttonPixDown[10];
106 106
107 QPixmap *pixmaps[4]; 107 QPixmap *pixmaps[4];
108 OTicker songInfo; 108 OTicker songInfo;
109 QSlider slider; 109 QSlider slider;
110 QLineEdit time; 110 QLineEdit time;
111 int xoff, yoff; 111 int xoff, yoff;
112 bool isStreaming : 1; 112 bool isStreaming : 1;
113
114 ButtonVector audioButtons;
113}; 115};
114 116
115 117
116#endif // AUDIO_WIDGET_H 118#endif // AUDIO_WIDGET_H
117 119