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