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