summaryrefslogtreecommitdiff
path: root/noncore/multimedia/opieplayer2/audiowidget.cpp
Unidiff
Diffstat (limited to 'noncore/multimedia/opieplayer2/audiowidget.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/multimedia/opieplayer2/audiowidget.cpp2
1 files changed, 1 insertions, 1 deletions
diff --git a/noncore/multimedia/opieplayer2/audiowidget.cpp b/noncore/multimedia/opieplayer2/audiowidget.cpp
index 870b4f3..f3eafab 100644
--- a/noncore/multimedia/opieplayer2/audiowidget.cpp
+++ b/noncore/multimedia/opieplayer2/audiowidget.cpp
@@ -1,274 +1,274 @@
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 34
35#include "audiowidget.h" 35#include "audiowidget.h"
36#include "mediaplayerstate.h" 36#include "mediaplayerstate.h"
37#include "playlistwidget.h" 37#include "playlistwidget.h"
38 38
39#include <qpe/qpeapplication.h> 39#include <qpe/qpeapplication.h>
40 40
41namespace 41namespace
42{ 42{
43 43
44const int xo = -2; // movable x offset 44const int xo = -2; // movable x offset
45const int yo = 22; // movable y offset 45const int yo = 22; // movable y offset
46 46
47const MediaWidget::SkinButtonInfo skinInfo[] = 47const MediaWidget::SkinButtonInfo skinInfo[] =
48{ 48{
49 { MediaWidget::Play, "play", MediaWidget::ToggleButton }, 49 { MediaWidget::Play, "play", MediaWidget::ToggleButton },
50 { MediaWidget::Stop, "stop", MediaWidget::NormalButton }, 50 { MediaWidget::Stop, "stop", MediaWidget::NormalButton },
51 { MediaWidget::Next, "next", MediaWidget::NormalButton }, 51 { MediaWidget::Next, "next", MediaWidget::NormalButton },
52 { MediaWidget::Previous, "prev", MediaWidget::NormalButton }, 52 { MediaWidget::Previous, "prev", MediaWidget::NormalButton },
53 { MediaWidget::VolumeUp, "up", MediaWidget::NormalButton }, 53 { MediaWidget::VolumeUp, "up", MediaWidget::NormalButton },
54 { MediaWidget::VolumeDown, "down", MediaWidget::NormalButton }, 54 { MediaWidget::VolumeDown, "down", MediaWidget::NormalButton },
55 { MediaWidget::Loop, "loop", MediaWidget::ToggleButton }, 55 { MediaWidget::Loop, "loop", MediaWidget::ToggleButton },
56 { MediaWidget::PlayList, "playlist", MediaWidget::NormalButton }, 56 { MediaWidget::PlayList, "playlist", MediaWidget::NormalButton },
57 { MediaWidget::Forward, "forward", MediaWidget::NormalButton }, 57 { MediaWidget::Forward, "forward", MediaWidget::NormalButton },
58 { MediaWidget::Back, "back", MediaWidget::NormalButton } 58 { MediaWidget::Back, "back", MediaWidget::NormalButton }
59}; 59};
60 60
61const uint buttonCount = sizeof( skinInfo ) / sizeof( skinInfo[ 0 ] ); 61const uint buttonCount = sizeof( skinInfo ) / sizeof( skinInfo[ 0 ] );
62 62
63void changeTextColor( QWidget * w) { 63void changeTextColor( QWidget * w) {
64 QPalette p = w->palette(); 64 QPalette p = w->palette();
65 p.setBrush( QColorGroup::Background, QColor( 167, 212, 167 ) ); 65 p.setBrush( QColorGroup::Background, QColor( 167, 212, 167 ) );
66 p.setBrush( QColorGroup::Base, QColor( 167, 212, 167 ) ); 66 p.setBrush( QColorGroup::Base, QColor( 167, 212, 167 ) );
67 w->setPalette( p ); 67 w->setPalette( p );
68} 68}
69 69
70} 70}
71 71
72AudioWidget::AudioWidget( PlayListWidget &playList, MediaPlayerState &mediaPlayerState, QWidget* parent, const char* name) : 72AudioWidget::AudioWidget( PlayListWidget &playList, MediaPlayerState &mediaPlayerState, QWidget* parent, const char* name) :
73 73
74 MediaWidget( playList, mediaPlayerState, parent, name ), songInfo( this ), slider( Qt::Horizontal, this ), time( this ), 74 MediaWidget( playList, mediaPlayerState, parent, name ), songInfo( this ), slider( Qt::Horizontal, this ), time( this ),
75 audioSliderBeingMoved( false ) 75 audioSliderBeingMoved( false )
76{ 76{
77 setCaption( tr("OpiePlayer") ); 77 setCaption( tr("OpiePlayer") );
78 78
79 loadSkin(); 79 loadSkin();
80 80
81 connect( &mediaPlayerState, SIGNAL( loopingToggled(bool) ), this, SLOT( setLooping(bool) ) ); 81 connect( &mediaPlayerState, SIGNAL( loopingToggled(bool) ), this, SLOT( setLooping(bool) ) );
82 connect( &mediaPlayerState, SIGNAL( isSeekableToggled( bool ) ), this, SLOT( setSeekable( bool ) ) ); 82 connect( &mediaPlayerState, SIGNAL( isSeekableToggled(bool) ), this, SLOT( setSeekable(bool) ) );
83 83
84 connect( this, SIGNAL( forwardClicked() ), this, SLOT( skipFor() ) ); 84 connect( this, SIGNAL( forwardClicked() ), this, SLOT( skipFor() ) );
85 connect( this, SIGNAL( backClicked() ), this, SLOT( skipBack() ) ); 85 connect( this, SIGNAL( backClicked() ), this, SLOT( skipBack() ) );
86 connect( this, SIGNAL( forwardReleased() ), this, SLOT( stopSkip() ) ); 86 connect( this, SIGNAL( forwardReleased() ), this, SLOT( stopSkip() ) );
87 connect( this, SIGNAL( backReleased() ), this, SLOT( stopSkip() ) ); 87 connect( this, SIGNAL( backReleased() ), this, SLOT( stopSkip() ) );
88 88
89 // Intialise state 89 // Intialise state
90 setLength( mediaPlayerState.length() ); 90 setLength( mediaPlayerState.length() );
91 setPosition( mediaPlayerState.position() ); 91 setPosition( mediaPlayerState.position() );
92 setLooping( mediaPlayerState.isFullscreen() ); 92 setLooping( mediaPlayerState.isFullscreen() );
93 // setPaused( mediaPlayerState->paused() ); 93 // setPaused( mediaPlayerState->paused() );
94 setPlaying( mediaPlayerState.isPlaying() ); 94 setPlaying( mediaPlayerState.isPlaying() );
95} 95}
96 96
97AudioWidget::~AudioWidget() { 97AudioWidget::~AudioWidget() {
98 98
99// mediaPlayerState->setPlaying(false); 99// mediaPlayerState->setPlaying(false);
100} 100}
101 101
102MediaWidget::GUIInfo AudioWidget::guiInfo() 102MediaWidget::GUIInfo AudioWidget::guiInfo()
103{ 103{
104 return GUIInfo( QString::null /* infix */, ::skinInfo, ::buttonCount ); 104 return GUIInfo( QString::null /* infix */, ::skinInfo, ::buttonCount );
105} 105}
106 106
107void AudioWidget::resizeEvent( QResizeEvent *e ) { 107void AudioWidget::resizeEvent( QResizeEvent *e ) {
108 int h = height(); 108 int h = height();
109 int w = width(); 109 int w = width();
110 110
111 songInfo.setGeometry( QRect( 2, 2, w - 4, 20 ) ); 111 songInfo.setGeometry( QRect( 2, 2, w - 4, 20 ) );
112 slider.setFixedWidth( w - 110 ); 112 slider.setFixedWidth( w - 110 );
113 slider.setGeometry( QRect( 15, h - 22, w - 90, 20 ) ); 113 slider.setGeometry( QRect( 15, h - 22, w - 90, 20 ) );
114 slider.setBackgroundOrigin( QWidget::ParentOrigin ); 114 slider.setBackgroundOrigin( QWidget::ParentOrigin );
115 time.setGeometry( QRect( w - 85, h - 30, 70, 20 ) ); 115 time.setGeometry( QRect( w - 85, h - 30, 70, 20 ) );
116 116
117 upperLeftOfButtonMask.rx() = ( w - buttonUpImage.width() ) / 2; 117 upperLeftOfButtonMask.rx() = ( w - buttonUpImage.width() ) / 2;
118 upperLeftOfButtonMask.ry() = (( h - buttonUpImage.height() ) / 2) - 10; 118 upperLeftOfButtonMask.ry() = (( h - buttonUpImage.height() ) / 2) - 10;
119 119
120 MediaWidget::resizeEvent( e ); 120 MediaWidget::resizeEvent( e );
121} 121}
122 122
123void AudioWidget::sliderPressed() { 123void AudioWidget::sliderPressed() {
124 audioSliderBeingMoved = TRUE; 124 audioSliderBeingMoved = TRUE;
125} 125}
126 126
127 127
128void AudioWidget::sliderReleased() { 128void AudioWidget::sliderReleased() {
129 audioSliderBeingMoved = FALSE; 129 audioSliderBeingMoved = FALSE;
130 if ( slider.width() == 0 ) 130 if ( slider.width() == 0 )
131 return; 131 return;
132 long val = long((double)slider.value() * mediaPlayerState.length() / slider.width()); 132 long val = long((double)slider.value() * mediaPlayerState.length() / slider.width());
133 mediaPlayerState.setPosition( val ); 133 mediaPlayerState.setPosition( val );
134} 134}
135 135
136void AudioWidget::setPosition( long i ) { 136void AudioWidget::setPosition( long i ) {
137 // qDebug("<<<<<<<<<<<<<<<<<<<<<<<<set position %d",i); 137 // qDebug("<<<<<<<<<<<<<<<<<<<<<<<<set position %d",i);
138 updateSlider( i, mediaPlayerState.length() ); 138 updateSlider( i, mediaPlayerState.length() );
139} 139}
140 140
141 141
142void AudioWidget::setLength( long max ) { 142void AudioWidget::setLength( long max ) {
143 updateSlider( mediaPlayerState.position(), max ); 143 updateSlider( mediaPlayerState.position(), max );
144} 144}
145 145
146 146
147void AudioWidget::setDisplayType( MediaPlayerState::DisplayType mediaType ) { 147void AudioWidget::setDisplayType( MediaPlayerState::DisplayType mediaType ) {
148 if ( mediaType == MediaPlayerState::Audio ) { 148 if ( mediaType == MediaPlayerState::Audio ) {
149 // startTimer( 150 ); 149 // startTimer( 150 );
150 QPEApplication::showWidget( this ); 150 QPEApplication::showWidget( this );
151 return; 151 return;
152 } 152 }
153 153
154 killTimers(); 154 killTimers();
155 hide(); 155 hide();
156} 156}
157 157
158void AudioWidget::loadSkin() 158void AudioWidget::loadSkin()
159{ 159{
160 loadDefaultSkin( guiInfo() ); 160 loadDefaultSkin( guiInfo() );
161 161
162 songInfo.setFocusPolicy( QWidget::NoFocus ); 162 songInfo.setFocusPolicy( QWidget::NoFocus );
163// changeTextColor( &songInfo ); 163// changeTextColor( &songInfo );
164// songInfo.setBackgroundColor( QColor( 167, 212, 167 )); 164// songInfo.setBackgroundColor( QColor( 167, 212, 167 ));
165// songInfo.setFrameStyle( QFrame::NoFrame); 165// songInfo.setFrameStyle( QFrame::NoFrame);
166 songInfo.setFrameStyle( QFrame::WinPanel | QFrame::Sunken ); 166 songInfo.setFrameStyle( QFrame::WinPanel | QFrame::Sunken );
167// songInfo.setForegroundColor(Qt::white); 167// songInfo.setForegroundColor(Qt::white);
168 168
169 slider.setFixedHeight( 20 ); 169 slider.setFixedHeight( 20 );
170 slider.setMinValue( 0 ); 170 slider.setMinValue( 0 );
171 slider.setMaxValue( 1 ); 171 slider.setMaxValue( 1 );
172 slider.setFocusPolicy( QWidget::NoFocus ); 172 slider.setFocusPolicy( QWidget::NoFocus );
173 slider.setBackgroundPixmap( backgroundPixmap ); 173 slider.setBackgroundPixmap( backgroundPixmap );
174 174
175// Config cofg("qpe"); 175// Config cofg("qpe");
176// cofg.setGroup("Appearance"); 176// cofg.setGroup("Appearance");
177// QColor backgroundcolor = QColor( cofg.readEntry( "Background", "#E5E1D5" ) ); 177// QColor backgroundcolor = QColor( cofg.readEntry( "Background", "#E5E1D5" ) );
178 178
179 time.setFocusPolicy( QWidget::NoFocus ); 179 time.setFocusPolicy( QWidget::NoFocus );
180 time.setAlignment( Qt::AlignCenter ); 180 time.setAlignment( Qt::AlignCenter );
181 181
182// time.setFrame(FALSE); 182// time.setFrame(FALSE);
183// changeTextColor( &time ); 183// changeTextColor( &time );
184 184
185 resizeEvent( 0 ); 185 resizeEvent( 0 );
186} 186}
187 187
188void AudioWidget::setSeekable( bool isSeekable ) { 188void AudioWidget::setSeekable( bool isSeekable ) {
189 189
190 if ( !isSeekable ) { 190 if ( !isSeekable ) {
191 qDebug("<<<<<<<<<<<<<<file is STREAMING>>>>>>>>>>>>>>>>>>>"); 191 qDebug("<<<<<<<<<<<<<<file is STREAMING>>>>>>>>>>>>>>>>>>>");
192 if( !slider.isHidden()) { 192 if( !slider.isHidden()) {
193 slider.hide(); 193 slider.hide();
194 } 194 }
195 disconnect( &mediaPlayerState, SIGNAL( positionChanged(long) ),this, SLOT( setPosition(long) ) ); 195 disconnect( &mediaPlayerState, SIGNAL( positionChanged(long) ),this, SLOT( setPosition(long) ) );
196 disconnect( &mediaPlayerState, SIGNAL( positionUpdated(long) ),this, SLOT( setPosition(long) ) ); 196 disconnect( &mediaPlayerState, SIGNAL( positionUpdated(long) ),this, SLOT( setPosition(long) ) );
197 disconnect( &slider, SIGNAL( sliderPressed() ), this, SLOT( sliderPressed() ) ); 197 disconnect( &slider, SIGNAL( sliderPressed() ), this, SLOT( sliderPressed() ) );
198 disconnect( &slider, SIGNAL( sliderReleased() ), this, SLOT( sliderReleased() ) ); 198 disconnect( &slider, SIGNAL( sliderReleased() ), this, SLOT( sliderReleased() ) );
199 } else { 199 } else {
200 // this stops the slider from being moved, thus 200 // this stops the slider from being moved, thus
201 // does not stop stream when it reaches the end 201 // does not stop stream when it reaches the end
202 slider.show(); 202 slider.show();
203 qDebug( " CONNECT SET POSTION " ); 203 qDebug( " CONNECT SET POSTION " );
204 connect( &mediaPlayerState, SIGNAL( positionChanged(long) ),this, SLOT( setPosition(long) ) ); 204 connect( &mediaPlayerState, SIGNAL( positionChanged(long) ),this, SLOT( setPosition(long) ) );
205 connect( &mediaPlayerState, SIGNAL( positionUpdated(long) ),this, SLOT( setPosition(long) ) ); 205 connect( &mediaPlayerState, SIGNAL( positionUpdated(long) ),this, SLOT( setPosition(long) ) );
206 connect( &slider, SIGNAL( sliderPressed() ), this, SLOT( sliderPressed() ) ); 206 connect( &slider, SIGNAL( sliderPressed() ), this, SLOT( sliderPressed() ) );
207 connect( &slider, SIGNAL( sliderReleased() ), this, SLOT( sliderReleased() ) ); 207 connect( &slider, SIGNAL( sliderReleased() ), this, SLOT( sliderReleased() ) );
208 } 208 }
209} 209}
210 210
211 211
212static QString timeAsString( long length ) { 212static QString timeAsString( long length ) {
213 int minutes = length / 60; 213 int minutes = length / 60;
214 int seconds = length % 60; 214 int seconds = length % 60;
215 return QString("%1:%2%3").arg( minutes ).arg( seconds / 10 ).arg( seconds % 10 ); 215 return QString("%1:%2%3").arg( minutes ).arg( seconds / 10 ).arg( seconds % 10 );
216} 216}
217 217
218void AudioWidget::updateSlider( long i, long max ) { 218void AudioWidget::updateSlider( long i, long max ) {
219 219
220 time.setText( timeAsString( i ) + " / " + timeAsString( max ) ); 220 time.setText( timeAsString( i ) + " / " + timeAsString( max ) );
221// qDebug( timeAsString( i ) + " / " + timeAsString( max ) ) ; 221// qDebug( timeAsString( i ) + " / " + timeAsString( max ) ) ;
222 222
223 if ( max == 0 ) { 223 if ( max == 0 ) {
224 return; 224 return;
225 } 225 }
226 // Will flicker too much if we don't do this 226 // Will flicker too much if we don't do this
227 // Scale to something reasonable 227 // Scale to something reasonable
228 int width = slider.width(); 228 int width = slider.width();
229 int val = int((double)i * width / max); 229 int val = int((double)i * width / max);
230 if ( !audioSliderBeingMoved ) { 230 if ( !audioSliderBeingMoved ) {
231 if ( slider.value() != val ) { 231 if ( slider.value() != val ) {
232 slider.setValue( val ); 232 slider.setValue( val );
233 } 233 }
234 234
235 if ( slider.maxValue() != width ) { 235 if ( slider.maxValue() != width ) {
236 slider.setMaxValue( width ); 236 slider.setMaxValue( width );
237 } 237 }
238 } 238 }
239} 239}
240 240
241void AudioWidget::skipFor() { 241void AudioWidget::skipFor() {
242 skipDirection = +1; 242 skipDirection = +1;
243 startTimer( 50 ); 243 startTimer( 50 );
244 mediaPlayerState.setPosition( mediaPlayerState.position() + 2 ); 244 mediaPlayerState.setPosition( mediaPlayerState.position() + 2 );
245} 245}
246 246
247void AudioWidget::skipBack() { 247void AudioWidget::skipBack() {
248 skipDirection = -1; 248 skipDirection = -1;
249 startTimer( 50 ); 249 startTimer( 50 );
250 mediaPlayerState.setPosition( mediaPlayerState.position() - 2 ); 250 mediaPlayerState.setPosition( mediaPlayerState.position() - 2 );
251} 251}
252 252
253 253
254 254
255void AudioWidget::stopSkip() { 255void AudioWidget::stopSkip() {
256 killTimers(); 256 killTimers();
257} 257}
258 258
259 259
260void AudioWidget::timerEvent( QTimerEvent * ) { 260void AudioWidget::timerEvent( QTimerEvent * ) {
261 if ( skipDirection == +1 ) { 261 if ( skipDirection == +1 ) {
262 mediaPlayerState.setPosition( mediaPlayerState.position() + 2 ); 262 mediaPlayerState.setPosition( mediaPlayerState.position() + 2 );
263 } else if ( skipDirection == -1 ) { 263 } else if ( skipDirection == -1 ) {
264 mediaPlayerState.setPosition( mediaPlayerState.position() - 2 ); 264 mediaPlayerState.setPosition( mediaPlayerState.position() - 2 );
265 } 265 }
266} 266}
267 267
268void AudioWidget::keyReleaseEvent( QKeyEvent *e) { 268void AudioWidget::keyReleaseEvent( QKeyEvent *e) {
269 switch ( e->key() ) { 269 switch ( e->key() ) {
270 ////////////////////////////// Zaurus keys 270 ////////////////////////////// Zaurus keys
271 case Key_Home: 271 case Key_Home:
272 break; 272 break;
273 case Key_F9: //activity 273 case Key_F9: //activity
274 hide(); 274 hide();