summaryrefslogtreecommitdiff
authorsimon <simon>2002-12-09 13:35:46 (UTC)
committer simon <simon>2002-12-09 13:35:46 (UTC)
commitd1324d850a3c8269bd6009de6fdf6c321954b371 (patch) (unidiff)
treef9effa74f69b06b8e9e7b89c3317c871c2bd81d6
parent235ef0e11bfd61c0debb530de8598ae38a396914 (diff)
downloadopie-d1324d850a3c8269bd6009de6fdf6c321954b371.zip
opie-d1324d850a3c8269bd6009de6fdf6c321954b371.tar.gz
opie-d1324d850a3c8269bd6009de6fdf6c321954b371.tar.bz2
- use a vector to store the masks
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/multimedia/opieplayer2/audiowidget.cpp19
-rw-r--r--noncore/multimedia/opieplayer2/audiowidget.h4
2 files changed, 12 insertions, 11 deletions
diff --git a/noncore/multimedia/opieplayer2/audiowidget.cpp b/noncore/multimedia/opieplayer2/audiowidget.cpp
index adef247..fe7ddc1 100644
--- a/noncore/multimedia/opieplayer2/audiowidget.cpp
+++ b/noncore/multimedia/opieplayer2/audiowidget.cpp
@@ -1,496 +1,495 @@
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 audioSliderBeingMoved( false ) 76 audioSliderBeingMoved( false )
77{ 77{
78 78
79 Button defaultButton; 79 Button defaultButton;
80 defaultButton.isToggle = defaultButton.isHeld = defaultButton.isDown = false; 80 defaultButton.isToggle = defaultButton.isHeld = defaultButton.isDown = false;
81 Button toggleButton; 81 Button toggleButton;
82 toggleButton.isToggle = true; 82 toggleButton.isToggle = true;
83 toggleButton.isHeld = toggleButton.isDown = false; 83 toggleButton.isHeld = toggleButton.isDown = false;
84 84
85 buttons.reserve( 10 ); 85 buttons.reserve( 10 );
86 buttons.push_back( toggleButton ); // play 86 buttons.push_back( toggleButton ); // play
87 buttons.push_back( defaultButton ); // stop 87 buttons.push_back( defaultButton ); // stop
88 buttons.push_back( defaultButton ); // next 88 buttons.push_back( defaultButton ); // next
89 buttons.push_back( defaultButton ); // previous 89 buttons.push_back( defaultButton ); // previous
90 buttons.push_back( defaultButton ); // volume up 90 buttons.push_back( defaultButton ); // volume up
91 buttons.push_back( defaultButton ); // volume down 91 buttons.push_back( defaultButton ); // volume down
92 buttons.push_back( toggleButton ); // repeat/loop 92 buttons.push_back( toggleButton ); // repeat/loop
93 buttons.push_back( defaultButton ); // playlist 93 buttons.push_back( defaultButton ); // playlist
94 buttons.push_back( defaultButton ); // forward 94 buttons.push_back( defaultButton ); // forward
95 buttons.push_back( defaultButton ); // back 95 buttons.push_back( defaultButton ); // back
96 96
97 setCaption( tr("OpiePlayer") ); 97 setCaption( tr("OpiePlayer") );
98 98
99 Config cfg("OpiePlayer"); 99 Config cfg("OpiePlayer");
100 cfg.setGroup("Options"); 100 cfg.setGroup("Options");
101 skin = cfg.readEntry("Skin","default"); 101 skin = cfg.readEntry("Skin","default");
102 //skin = "scaleTest"; 102 //skin = "scaleTest";
103 // color of background, frame, degree of transparency 103 // color of background, frame, degree of transparency
104 104
105 QString skinPath = "opieplayer2/skins/" + skin; 105 QString skinPath = "opieplayer2/skins/" + skin;
106 pixBg = QPixmap( Resource::loadPixmap( QString("%1/background").arg(skinPath) ) ); 106 pixBg = QPixmap( Resource::loadPixmap( QString("%1/background").arg(skinPath) ) );
107 imgUp = QImage( Resource::loadImage( QString("%1/skin_up").arg(skinPath) ) ); 107 imgUp = QImage( Resource::loadImage( QString("%1/skin_up").arg(skinPath) ) );
108 imgDn = QImage( Resource::loadImage( QString("%1/skin_down").arg(skinPath) ) ); 108 imgDn = QImage( Resource::loadImage( QString("%1/skin_down").arg(skinPath) ) );
109 109
110 buttonMask = QImage( imgUp.width(), imgUp.height(), 8, 255 ); 110 buttonMask = QImage( imgUp.width(), imgUp.height(), 8, 255 );
111 buttonMask.fill( 0 ); 111 buttonMask.fill( 0 );
112 112
113 for ( int i = 0; i < 10; i++ ) { 113 masks.reserve( 10 );
114
115 for ( uint i = 0; i < masks.capacity(); i++ ) {
114 QString filename = QString( QPEApplication::qpeDir() + "/pics/" + skinPath + "/skin_mask_" + skin_mask_file_names[i] + ".png" ); 116 QString filename = QString( QPEApplication::qpeDir() + "/pics/" + skinPath + "/skin_mask_" + skin_mask_file_names[i] + ".png" );
115 masks[i] = new QBitmap( filename ); 117 masks.push_back( QBitmap( filename ) );
116 118
117 if ( !masks[i]->isNull() ) { 119 if ( !masks[i].isNull() ) {
118 QImage imgMask = masks[i]->convertToImage(); 120 QImage imgMask = masks[i].convertToImage();
119 uchar **dest = buttonMask.jumpTable(); 121 uchar **dest = buttonMask.jumpTable();
120 for ( int y = 0; y < imgUp.height(); y++ ) { 122 for ( int y = 0; y < imgUp.height(); y++ ) {
121 uchar *line = dest[y]; 123 uchar *line = dest[y];
122 for ( int x = 0; x < imgUp.width(); x++ ) 124 for ( int x = 0; x < imgUp.width(); x++ )
123 if ( !qRed( imgMask.pixel( x, y ) ) ) 125 if ( !qRed( imgMask.pixel( x, y ) ) )
124 line[x] = i + 1; 126 line[x] = i + 1;
125 } 127 }
126 } 128 }
127 129
128 } 130 }
129 131
130 for ( int i = 0; i < 10; i++ ) { 132 for ( int i = 0; i < 10; i++ ) {
131 buttonPixUp[i] = 0l; 133 buttonPixUp[i] = 0l;
132 buttonPixDown[i] = 0l; 134 buttonPixDown[i] = 0l;
133 } 135 }
134 136
135 setBackgroundPixmap( pixBg ); 137 setBackgroundPixmap( pixBg );
136 138
137 songInfo.setFocusPolicy( QWidget::NoFocus ); 139 songInfo.setFocusPolicy( QWidget::NoFocus );
138// changeTextColor( &songInfo ); 140// changeTextColor( &songInfo );
139// songInfo.setBackgroundColor( QColor( 167, 212, 167 )); 141// songInfo.setBackgroundColor( QColor( 167, 212, 167 ));
140// songInfo.setFrameStyle( QFrame::NoFrame); 142// songInfo.setFrameStyle( QFrame::NoFrame);
141 songInfo.setFrameStyle( QFrame::WinPanel | QFrame::Sunken ); 143 songInfo.setFrameStyle( QFrame::WinPanel | QFrame::Sunken );
142// songInfo.setForegroundColor(Qt::white); 144// songInfo.setForegroundColor(Qt::white);
143 145
144 slider.setFixedHeight( 20 ); 146 slider.setFixedHeight( 20 );
145 slider.setMinValue( 0 ); 147 slider.setMinValue( 0 );
146 slider.setMaxValue( 1 ); 148 slider.setMaxValue( 1 );
147 slider.setFocusPolicy( QWidget::NoFocus ); 149 slider.setFocusPolicy( QWidget::NoFocus );
148 slider.setBackgroundPixmap( pixBg ); 150 slider.setBackgroundPixmap( pixBg );
149 151
150// Config cofg("qpe"); 152// Config cofg("qpe");
151// cofg.setGroup("Appearance"); 153// cofg.setGroup("Appearance");
152// QColor backgroundcolor = QColor( cofg.readEntry( "Background", "#E5E1D5" ) ); 154// QColor backgroundcolor = QColor( cofg.readEntry( "Background", "#E5E1D5" ) );
153 155
154 time.setFocusPolicy( QWidget::NoFocus ); 156 time.setFocusPolicy( QWidget::NoFocus );
155 time.setAlignment( Qt::AlignCenter ); 157 time.setAlignment( Qt::AlignCenter );
156 158
157// time.setFrame(FALSE); 159// time.setFrame(FALSE);
158// changeTextColor( &time ); 160// changeTextColor( &time );
159 161
160 resizeEvent( NULL ); 162 resizeEvent( NULL );
161 163
162 connect( &mediaPlayerState, SIGNAL( loopingToggled(bool) ), this, SLOT( setLooping(bool) ) ); 164 connect( &mediaPlayerState, SIGNAL( loopingToggled(bool) ), this, SLOT( setLooping(bool) ) );
163 connect( &mediaPlayerState, SIGNAL( isSeekableToggled( bool ) ), this, SLOT( setSeekable( bool ) ) ); 165 connect( &mediaPlayerState, SIGNAL( isSeekableToggled( bool ) ), this, SLOT( setSeekable( bool ) ) );
164 166
165 connect( this, SIGNAL( forwardClicked() ), this, SLOT( skipFor() ) ); 167 connect( this, SIGNAL( forwardClicked() ), this, SLOT( skipFor() ) );
166 connect( this, SIGNAL( backClicked() ), this, SLOT( skipBack() ) ); 168 connect( this, SIGNAL( backClicked() ), this, SLOT( skipBack() ) );
167 connect( this, SIGNAL( forwardReleased() ), this, SLOT( stopSkip() ) ); 169 connect( this, SIGNAL( forwardReleased() ), this, SLOT( stopSkip() ) );
168 connect( this, SIGNAL( backReleased() ), this, SLOT( stopSkip() ) ); 170 connect( this, SIGNAL( backReleased() ), this, SLOT( stopSkip() ) );
169 171
170 // Intialise state 172 // Intialise state
171 setLength( mediaPlayerState.length() ); 173 setLength( mediaPlayerState.length() );
172 setPosition( mediaPlayerState.position() ); 174 setPosition( mediaPlayerState.position() );
173 setLooping( mediaPlayerState.isFullscreen() ); 175 setLooping( mediaPlayerState.isFullscreen() );
174 // setPaused( mediaPlayerState->paused() ); 176 // setPaused( mediaPlayerState->paused() );
175 setPlaying( mediaPlayerState.isPlaying() ); 177 setPlaying( mediaPlayerState.isPlaying() );
176 178
177} 179}
178 180
179AudioWidget::~AudioWidget() { 181AudioWidget::~AudioWidget() {
180 182
181 for ( int i = 0; i < 10; i++ ) { 183 for ( int i = 0; i < 10; i++ ) {
182 delete buttonPixUp[i]; 184 delete buttonPixUp[i];
183 delete buttonPixDown[i]; 185 delete buttonPixDown[i];
184 } 186 }
185 for ( int i = 0; i < 10; i++ ) {
186 delete masks[i];
187 }
188// mediaPlayerState->setPlaying(false); 187// mediaPlayerState->setPlaying(false);
189} 188}
190 189
191namespace { 190namespace {
192 191
193QPixmap combineImageWithBackground( QImage img, QPixmap bg, QPoint offset ) { 192QPixmap combineImageWithBackground( QImage img, QPixmap bg, QPoint offset ) {
194 QPixmap pix( img.width(), img.height() ); 193 QPixmap pix( img.width(), img.height() );
195 QPainter p( &pix ); 194 QPainter p( &pix );
196 p.drawTiledPixmap( pix.rect(), bg, offset ); 195 p.drawTiledPixmap( pix.rect(), bg, offset );
197 p.drawImage( 0, 0, img ); 196 p.drawImage( 0, 0, img );
198 return pix; 197 return pix;
199} 198}
200 199
201 200
202QPixmap *maskPixToMask( QPixmap pix, QBitmap mask ) { 201QPixmap *maskPixToMask( QPixmap pix, QBitmap mask ) {
203 QPixmap *pixmap = new QPixmap( pix ); 202 QPixmap *pixmap = new QPixmap( pix );
204 pixmap->setMask( mask ); 203 pixmap->setMask( mask );
205 return pixmap; 204 return pixmap;
206} 205}
207 206
208}; 207};
209 208
210void AudioWidget::resizeEvent( QResizeEvent * ) { 209void AudioWidget::resizeEvent( QResizeEvent * ) {
211 int h = height(); 210 int h = height();
212 int w = width(); 211 int w = width();
213 212
214 songInfo.setGeometry( QRect( 2, 2, w - 4, 20 ) ); 213 songInfo.setGeometry( QRect( 2, 2, w - 4, 20 ) );
215 slider.setFixedWidth( w - 110 ); 214 slider.setFixedWidth( w - 110 );
216 slider.setGeometry( QRect( 15, h - 22, w - 90, 20 ) ); 215 slider.setGeometry( QRect( 15, h - 22, w - 90, 20 ) );
217 slider.setBackgroundOrigin( QWidget::ParentOrigin ); 216 slider.setBackgroundOrigin( QWidget::ParentOrigin );
218 time.setGeometry( QRect( w - 85, h - 30, 70, 20 ) ); 217 time.setGeometry( QRect( w - 85, h - 30, 70, 20 ) );
219 218
220 upperLeftOfButtonMask.rx() = ( w - imgUp.width() ) / 2; 219 upperLeftOfButtonMask.rx() = ( w - imgUp.width() ) / 2;
221 upperLeftOfButtonMask.ry() = (( h - imgUp.height() ) / 2) - 10; 220 upperLeftOfButtonMask.ry() = (( h - imgUp.height() ) / 2) - 10;
222 QPoint p = upperLeftOfButtonMask; 221 QPoint p = upperLeftOfButtonMask;
223 222
224 QPixmap pixUp = combineImageWithBackground( imgUp, pixBg, p ); 223 QPixmap pixUp = combineImageWithBackground( imgUp, pixBg, p );
225 QPixmap pixDn = combineImageWithBackground( imgDn, pixBg, p ); 224 QPixmap pixDn = combineImageWithBackground( imgDn, pixBg, p );
226 225
227 for ( int i = 0; i < 10; i++ ) { 226 for ( int i = 0; i < 10; i++ ) {
228 if ( !masks[i]->isNull() ) { 227 if ( !masks[i].isNull() ) {
229 delete buttonPixUp[i]; 228 delete buttonPixUp[i];
230 delete buttonPixDown[i]; 229 delete buttonPixDown[i];
231 buttonPixUp[i] = maskPixToMask( pixUp, *masks[i] ); 230 buttonPixUp[i] = maskPixToMask( pixUp, masks[i] );
232 buttonPixDown[i] = maskPixToMask( pixDn, *masks[i] ); 231 buttonPixDown[i] = maskPixToMask( pixDn, masks[i] );
233 } 232 }
234 } 233 }
235} 234}
236 235
237void AudioWidget::sliderPressed() { 236void AudioWidget::sliderPressed() {
238 audioSliderBeingMoved = TRUE; 237 audioSliderBeingMoved = TRUE;
239} 238}
240 239
241 240
242void AudioWidget::sliderReleased() { 241void AudioWidget::sliderReleased() {
243 audioSliderBeingMoved = FALSE; 242 audioSliderBeingMoved = FALSE;
244 if ( slider.width() == 0 ) 243 if ( slider.width() == 0 )
245 return; 244 return;
246 long val = long((double)slider.value() * mediaPlayerState.length() / slider.width()); 245 long val = long((double)slider.value() * mediaPlayerState.length() / slider.width());
247 mediaPlayerState.setPosition( val ); 246 mediaPlayerState.setPosition( val );
248} 247}
249 248
250void AudioWidget::setPosition( long i ) { 249void AudioWidget::setPosition( long i ) {
251 // qDebug("<<<<<<<<<<<<<<<<<<<<<<<<set position %d",i); 250 // qDebug("<<<<<<<<<<<<<<<<<<<<<<<<set position %d",i);
252 updateSlider( i, mediaPlayerState.length() ); 251 updateSlider( i, mediaPlayerState.length() );
253} 252}
254 253
255 254
256void AudioWidget::setLength( long max ) { 255void AudioWidget::setLength( long max ) {
257 updateSlider( mediaPlayerState.position(), max ); 256 updateSlider( mediaPlayerState.position(), max );
258} 257}
259 258
260 259
261void AudioWidget::setDisplayType( MediaPlayerState::DisplayType mediaType ) { 260void AudioWidget::setDisplayType( MediaPlayerState::DisplayType mediaType ) {
262 if ( mediaType == MediaPlayerState::Audio ) { 261 if ( mediaType == MediaPlayerState::Audio ) {
263 // startTimer( 150 ); 262 // startTimer( 150 );
264 showMaximized(); 263 showMaximized();
265 return; 264 return;
266 } 265 }
267 266
268 killTimers(); 267 killTimers();
269 hide(); 268 hide();
270} 269}
271 270
272 271
273void AudioWidget::setSeekable( bool isSeekable ) { 272void AudioWidget::setSeekable( bool isSeekable ) {
274 273
275 if ( !isSeekable ) { 274 if ( !isSeekable ) {
276 qDebug("<<<<<<<<<<<<<<file is STREAMING>>>>>>>>>>>>>>>>>>>"); 275 qDebug("<<<<<<<<<<<<<<file is STREAMING>>>>>>>>>>>>>>>>>>>");
277 if( !slider.isHidden()) { 276 if( !slider.isHidden()) {
278 slider.hide(); 277 slider.hide();
279 } 278 }
280 disconnect( &mediaPlayerState, SIGNAL( positionChanged(long) ),this, SLOT( setPosition(long) ) ); 279 disconnect( &mediaPlayerState, SIGNAL( positionChanged(long) ),this, SLOT( setPosition(long) ) );
281 disconnect( &mediaPlayerState, SIGNAL( positionUpdated(long) ),this, SLOT( setPosition(long) ) ); 280 disconnect( &mediaPlayerState, SIGNAL( positionUpdated(long) ),this, SLOT( setPosition(long) ) );
282 disconnect( &slider, SIGNAL( sliderPressed() ), this, SLOT( sliderPressed() ) ); 281 disconnect( &slider, SIGNAL( sliderPressed() ), this, SLOT( sliderPressed() ) );
283 disconnect( &slider, SIGNAL( sliderReleased() ), this, SLOT( sliderReleased() ) ); 282 disconnect( &slider, SIGNAL( sliderReleased() ), this, SLOT( sliderReleased() ) );
284 } else { 283 } else {
285 // this stops the slider from being moved, thus 284 // this stops the slider from being moved, thus
286 // does not stop stream when it reaches the end 285 // does not stop stream when it reaches the end
287 slider.show(); 286 slider.show();
288 qDebug( " CONNECT SET POSTION " ); 287 qDebug( " CONNECT SET POSTION " );
289 connect( &mediaPlayerState, SIGNAL( positionChanged(long) ),this, SLOT( setPosition(long) ) ); 288 connect( &mediaPlayerState, SIGNAL( positionChanged(long) ),this, SLOT( setPosition(long) ) );
290 connect( &mediaPlayerState, SIGNAL( positionUpdated(long) ),this, SLOT( setPosition(long) ) ); 289 connect( &mediaPlayerState, SIGNAL( positionUpdated(long) ),this, SLOT( setPosition(long) ) );
291 connect( &slider, SIGNAL( sliderPressed() ), this, SLOT( sliderPressed() ) ); 290 connect( &slider, SIGNAL( sliderPressed() ), this, SLOT( sliderPressed() ) );
292 connect( &slider, SIGNAL( sliderReleased() ), this, SLOT( sliderReleased() ) ); 291 connect( &slider, SIGNAL( sliderReleased() ), this, SLOT( sliderReleased() ) );
293 } 292 }
294} 293}
295 294
296 295
297static QString timeAsString( long length ) { 296static QString timeAsString( long length ) {
298 int minutes = length / 60; 297 int minutes = length / 60;
299 int seconds = length % 60; 298 int seconds = length % 60;
300 return QString("%1:%2%3").arg( minutes ).arg( seconds / 10 ).arg( seconds % 10 ); 299 return QString("%1:%2%3").arg( minutes ).arg( seconds / 10 ).arg( seconds % 10 );
301} 300}
302 301
303void AudioWidget::updateSlider( long i, long max ) { 302void AudioWidget::updateSlider( long i, long max ) {
304 303
305 time.setText( timeAsString( i ) + " / " + timeAsString( max ) ); 304 time.setText( timeAsString( i ) + " / " + timeAsString( max ) );
306// qDebug( timeAsString( i ) + " / " + timeAsString( max ) ) ; 305// qDebug( timeAsString( i ) + " / " + timeAsString( max ) ) ;
307 306
308 if ( max == 0 ) { 307 if ( max == 0 ) {
309 return; 308 return;
310 } 309 }
311 // Will flicker too much if we don't do this 310 // Will flicker too much if we don't do this
312 // Scale to something reasonable 311 // Scale to something reasonable
313 int width = slider.width(); 312 int width = slider.width();
314 int val = int((double)i * width / max); 313 int val = int((double)i * width / max);
315 if ( !audioSliderBeingMoved ) { 314 if ( !audioSliderBeingMoved ) {
316 if ( slider.value() != val ) { 315 if ( slider.value() != val ) {
317 slider.setValue( val ); 316 slider.setValue( val );
318 } 317 }
319 318
320 if ( slider.maxValue() != width ) { 319 if ( slider.maxValue() != width ) {
321 slider.setMaxValue( width ); 320 slider.setMaxValue( width );
322 } 321 }
323 } 322 }
324} 323}
325 324
326 325
327void AudioWidget::setToggleButton( int i, bool down ) { 326void AudioWidget::setToggleButton( int i, bool down ) {
328 qDebug("setToggleButton %d", i); 327 qDebug("setToggleButton %d", i);
329 if ( down != buttons[i].isDown ) { 328 if ( down != buttons[i].isDown ) {
330 toggleButton( i ); 329 toggleButton( i );
331 } 330 }
332} 331}
333 332
334void AudioWidget::paintButton( QPainter &p, int i ) { 333void AudioWidget::paintButton( QPainter &p, int i ) {
335 if ( buttons[i].isDown ) { 334 if ( buttons[i].isDown ) {
336 p.drawPixmap( upperLeftOfButtonMask, *buttonPixDown[i] ); 335 p.drawPixmap( upperLeftOfButtonMask, *buttonPixDown[i] );
337 } else { 336 } else {
338 p.drawPixmap( upperLeftOfButtonMask, *buttonPixUp[i] ); 337 p.drawPixmap( upperLeftOfButtonMask, *buttonPixUp[i] );
339 } 338 }
340} 339}
341 340
342 341
343void AudioWidget::skipFor() { 342void AudioWidget::skipFor() {
344 skipDirection = +1; 343 skipDirection = +1;
345 startTimer( 50 ); 344 startTimer( 50 );
346 mediaPlayerState.setPosition( mediaPlayerState.position() + 2 ); 345 mediaPlayerState.setPosition( mediaPlayerState.position() + 2 );
347} 346}
348 347
349void AudioWidget::skipBack() { 348void AudioWidget::skipBack() {
350 skipDirection = -1; 349 skipDirection = -1;
351 startTimer( 50 ); 350 startTimer( 50 );
352 mediaPlayerState.setPosition( mediaPlayerState.position() - 2 ); 351 mediaPlayerState.setPosition( mediaPlayerState.position() - 2 );
353} 352}
354 353
355 354
356 355
357void AudioWidget::stopSkip() { 356void AudioWidget::stopSkip() {
358 killTimers(); 357 killTimers();
359} 358}
360 359
361 360
362void AudioWidget::timerEvent( QTimerEvent * ) { 361void AudioWidget::timerEvent( QTimerEvent * ) {
363 if ( skipDirection == +1 ) { 362 if ( skipDirection == +1 ) {
364 mediaPlayerState.setPosition( mediaPlayerState.position() + 2 ); 363 mediaPlayerState.setPosition( mediaPlayerState.position() + 2 );
365 } else if ( skipDirection == -1 ) { 364 } else if ( skipDirection == -1 ) {
366 mediaPlayerState.setPosition( mediaPlayerState.position() - 2 ); 365 mediaPlayerState.setPosition( mediaPlayerState.position() - 2 );
367 } 366 }
368} 367}
369 368
370 369
371void AudioWidget::mouseMoveEvent( QMouseEvent *event ) { 370void AudioWidget::mouseMoveEvent( QMouseEvent *event ) {
372 for ( unsigned int i = 0; i < buttons.size(); i++ ) { 371 for ( unsigned int i = 0; i < buttons.size(); i++ ) {
373 if ( event->state() == QMouseEvent::LeftButton ) { 372 if ( event->state() == QMouseEvent::LeftButton ) {
374 // The test to see if the mouse click is inside the button or not 373 // The test to see if the mouse click is inside the button or not
375 bool isOnButton = isOverButton( event->pos() - upperLeftOfButtonMask, i ); 374 bool isOnButton = isOverButton( event->pos() - upperLeftOfButtonMask, i );
376 375
377 if ( isOnButton && !buttons[i].isHeld ) { 376 if ( isOnButton && !buttons[i].isHeld ) {
378 buttons[i].isHeld = TRUE; 377 buttons[i].isHeld = TRUE;
379 toggleButton(i); 378 toggleButton(i);
380 switch (i) { 379 switch (i) {
381 case VolumeUp: 380 case VolumeUp:
382 emit moreClicked(); 381 emit moreClicked();
383 return; 382 return;
384 case VolumeDown: 383 case VolumeDown:
385 emit lessClicked(); 384 emit lessClicked();
386 return; 385 return;
387 case Forward: 386 case Forward:
388 emit forwardClicked(); 387 emit forwardClicked();
389 return; 388 return;
390 case Back: 389 case Back:
391 emit backClicked(); 390 emit backClicked();
392 return; 391 return;
393 } 392 }
394 } else if ( !isOnButton && buttons[i].isHeld ) { 393 } else if ( !isOnButton && buttons[i].isHeld ) {
395 buttons[i].isHeld = FALSE; 394 buttons[i].isHeld = FALSE;
396 toggleButton(i); 395 toggleButton(i);
397 } 396 }
398 } else { 397 } else {
399 if ( buttons[i].isHeld ) { 398 if ( buttons[i].isHeld ) {
400 buttons[i].isHeld = FALSE; 399 buttons[i].isHeld = FALSE;
401 if ( !buttons[i].isToggle ) { 400 if ( !buttons[i].isToggle ) {
402 setToggleButton( i, FALSE ); 401 setToggleButton( i, FALSE );
403 } 402 }
404 qDebug("mouseEvent %d", i); 403 qDebug("mouseEvent %d", i);
405 handleCommand( static_cast<Command>( i ), buttons[ i ].isDown ); 404 handleCommand( static_cast<Command>( i ), buttons[ i ].isDown );
406 } 405 }
407 } 406 }
408 } 407 }
409} 408}
410 409
411 410
412void AudioWidget::mousePressEvent( QMouseEvent *event ) { 411void AudioWidget::mousePressEvent( QMouseEvent *event ) {
413 mouseMoveEvent( event ); 412 mouseMoveEvent( event );
414} 413}
415 414
416 415
417void AudioWidget::mouseReleaseEvent( QMouseEvent *event ) { 416void AudioWidget::mouseReleaseEvent( QMouseEvent *event ) {
418 mouseMoveEvent( event ); 417 mouseMoveEvent( event );
419} 418}
420 419
421 420
422void AudioWidget::showEvent( QShowEvent* ) { 421void AudioWidget::showEvent( QShowEvent* ) {
423 QMouseEvent event( QEvent::MouseMove, QPoint( 0, 0 ), 0, 0 ); 422 QMouseEvent event( QEvent::MouseMove, QPoint( 0, 0 ), 0, 0 );
424 mouseMoveEvent( &event ); 423 mouseMoveEvent( &event );
425} 424}
426 425
427 426
428void AudioWidget::paintEvent( QPaintEvent * pe ) { 427void AudioWidget::paintEvent( QPaintEvent * pe ) {
429 if ( !pe->erased() ) { 428 if ( !pe->erased() ) {
430 // Combine with background and double buffer 429 // Combine with background and double buffer
431 QPixmap pix( pe->rect().size() ); 430 QPixmap pix( pe->rect().size() );
432 QPainter p( &pix ); 431 QPainter p( &pix );
433 p.translate( -pe->rect().topLeft().x(), -pe->rect().topLeft().y() ); 432 p.translate( -pe->rect().topLeft().x(), -pe->rect().topLeft().y() );
434 p.drawTiledPixmap( pe->rect(), pixBg, pe->rect().topLeft() ); 433 p.drawTiledPixmap( pe->rect(), pixBg, pe->rect().topLeft() );
435 for ( unsigned int i = 0; i < buttons.size(); i++ ) 434 for ( unsigned int i = 0; i < buttons.size(); i++ )
436 paintButton( p, i ); 435 paintButton( p, i );
437 QPainter p2( this ); 436 QPainter p2( this );
438 p2.drawPixmap( pe->rect().topLeft(), pix ); 437 p2.drawPixmap( pe->rect().topLeft(), pix );
439 } else { 438 } else {
440 QPainter p( this ); 439 QPainter p( this );
441 for ( unsigned int i = 0; i < buttons.size(); i++ ) 440 for ( unsigned int i = 0; i < buttons.size(); i++ )
442 paintButton( p, i ); 441 paintButton( p, i );
443 } 442 }
444} 443}
445 444
446void AudioWidget::keyReleaseEvent( QKeyEvent *e) { 445void AudioWidget::keyReleaseEvent( QKeyEvent *e) {
447 switch ( e->key() ) { 446 switch ( e->key() ) {
448 ////////////////////////////// Zaurus keys 447 ////////////////////////////// Zaurus keys
449 case Key_Home: 448 case Key_Home:
450 break; 449 break;
451 case Key_F9: //activity 450 case Key_F9: //activity
452 hide(); 451 hide();
453 // qDebug("Audio F9"); 452 // qDebug("Audio F9");
454 break; 453 break;
455 case Key_F10: //contacts 454 case Key_F10: //contacts
456 break; 455 break;
457 case Key_F11: //menu 456 case Key_F11: //menu
458 mediaPlayerState.toggleBlank(); 457 mediaPlayerState.toggleBlank();
459 break; 458 break;
460 case Key_F12: //home 459 case Key_F12: //home
461 break; 460 break;
462 case Key_F13: //mail 461 case Key_F13: //mail
463 mediaPlayerState.toggleBlank(); 462 mediaPlayerState.toggleBlank();
464 break; 463 break;
465 case Key_Space: { 464 case Key_Space: {
466 mediaPlayerState.togglePaused(); 465 mediaPlayerState.togglePaused();
467 } 466 }
468 break; 467 break;
469 case Key_Down: 468 case Key_Down:
470 // toggleButton(6); 469 // toggleButton(6);
471 emit lessClicked(); 470 emit lessClicked();
472 emit lessReleased(); 471 emit lessReleased();
473 // toggleButton(6); 472 // toggleButton(6);
474 break; 473 break;
475 case Key_Up: 474 case Key_Up:
476 // toggleButton(5); 475 // toggleButton(5);
477 emit moreClicked(); 476 emit moreClicked();
478 emit moreReleased(); 477 emit moreReleased();
479 // toggleButton(5); 478 // toggleButton(5);
480 break; 479 break;
481 case Key_Right: 480 case Key_Right:
482 // toggleButton(3); 481 // toggleButton(3);
483 mediaPlayerState.setNext(); 482 mediaPlayerState.setNext();
484 // toggleButton(3); 483 // toggleButton(3);
485 break; 484 break;
486 case Key_Left: 485 case Key_Left:
487 // toggleButton(4); 486 // toggleButton(4);
488 mediaPlayerState.setPrev(); 487 mediaPlayerState.setPrev();
489 // toggleButton(4); 488 // toggleButton(4);
490 break; 489 break;
491 case Key_Escape: { 490 case Key_Escape: {
492 } 491 }
493 break; 492 break;
494 493
495 }; 494 };
496} 495}
diff --git a/noncore/multimedia/opieplayer2/audiowidget.h b/noncore/multimedia/opieplayer2/audiowidget.h
index 8426490..bc7262c 100644
--- a/noncore/multimedia/opieplayer2/audiowidget.h
+++ b/noncore/multimedia/opieplayer2/audiowidget.h
@@ -1,115 +1,117 @@
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 typedef std::vector<QBitmap> MaskVector;
95
94 void setToggleButton( int, bool ); 96 void setToggleButton( int, bool );
95 virtual void paintButton( QPainter &p, int i ); 97 virtual void paintButton( QPainter &p, int i );
96 int skipDirection; 98 int skipDirection;
97 QString skin; 99 QString skin;
98 QPixmap pixBg; 100 QPixmap pixBg;
99 QImage imgUp; 101 QImage imgUp;
100 QImage imgDn; 102 QImage imgDn;
101 QBitmap *masks[10]; 103 MaskVector masks;
102 QPixmap *buttonPixUp[10]; 104 QPixmap *buttonPixUp[10];
103 QPixmap *buttonPixDown[10]; 105 QPixmap *buttonPixDown[10];
104 106
105 QPixmap *pixmaps[4]; 107 QPixmap *pixmaps[4];
106 OTicker songInfo; 108 OTicker songInfo;
107 QSlider slider; 109 QSlider slider;
108 QLineEdit time; 110 QLineEdit time;
109 bool isStreaming : 1; 111 bool isStreaming : 1;
110 bool audioSliderBeingMoved : 1; 112 bool audioSliderBeingMoved : 1;
111}; 113};
112 114
113 115
114#endif // AUDIO_WIDGET_H 116#endif // AUDIO_WIDGET_H
115 117