-rw-r--r-- | noncore/multimedia/opieplayer2/audiowidget.cpp | 19 |
1 files changed, 0 insertions, 19 deletions
diff --git a/noncore/multimedia/opieplayer2/audiowidget.cpp b/noncore/multimedia/opieplayer2/audiowidget.cpp index bb07882..78079dd 100644 --- a/noncore/multimedia/opieplayer2/audiowidget.cpp +++ b/noncore/multimedia/opieplayer2/audiowidget.cpp | |||
@@ -1,260 +1,241 @@ | |||
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 | ||
53 | namespace | 53 | namespace |
54 | { | 54 | { |
55 | 55 | ||
56 | const int xo = -2; // movable x offset | 56 | const int xo = -2; // movable x offset |
57 | const int yo = 22; // movable y offset | 57 | const int yo = 22; // movable y offset |
58 | 58 | ||
59 | const MediaWidget::SkinButtonInfo skinInfo[] = | 59 | const 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 | ||
73 | const uint buttonCount = sizeof( skinInfo ) / sizeof( skinInfo[ 0 ] ); | 73 | const uint buttonCount = sizeof( skinInfo ) / sizeof( skinInfo[ 0 ] ); |
74 | 74 | ||
75 | void changeTextColor( QWidget * w) { | 75 | void 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 | ||
84 | AudioWidget::AudioWidget( PlayListWidget &playList, MediaPlayerState &mediaPlayerState, QWidget* parent, const char* name) : | 84 | AudioWidget::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 | setCaption( tr("OpiePlayer") ); | 89 | setCaption( tr("OpiePlayer") ); |
90 | 90 | ||
91 | loadSkin(); | 91 | loadSkin(); |
92 | 92 | ||
93 | connect( &mediaPlayerState, SIGNAL( loopingToggled(bool) ), this, SLOT( setLooping(bool) ) ); | 93 | connect( &mediaPlayerState, SIGNAL( loopingToggled(bool) ), this, SLOT( setLooping(bool) ) ); |
94 | connect( &mediaPlayerState, SIGNAL( isSeekableToggled( bool ) ), this, SLOT( setSeekable( bool ) ) ); | 94 | connect( &mediaPlayerState, SIGNAL( isSeekableToggled( bool ) ), this, SLOT( setSeekable( bool ) ) ); |
95 | 95 | ||
96 | connect( this, SIGNAL( forwardClicked() ), this, SLOT( skipFor() ) ); | 96 | connect( this, SIGNAL( forwardClicked() ), this, SLOT( skipFor() ) ); |
97 | connect( this, SIGNAL( backClicked() ), this, SLOT( skipBack() ) ); | 97 | connect( this, SIGNAL( backClicked() ), this, SLOT( skipBack() ) ); |
98 | connect( this, SIGNAL( forwardReleased() ), this, SLOT( stopSkip() ) ); | 98 | connect( this, SIGNAL( forwardReleased() ), this, SLOT( stopSkip() ) ); |
99 | connect( this, SIGNAL( backReleased() ), this, SLOT( stopSkip() ) ); | 99 | connect( this, SIGNAL( backReleased() ), this, SLOT( stopSkip() ) ); |
100 | 100 | ||
101 | // Intialise state | 101 | // Intialise state |
102 | setLength( mediaPlayerState.length() ); | 102 | setLength( mediaPlayerState.length() ); |
103 | setPosition( mediaPlayerState.position() ); | 103 | setPosition( mediaPlayerState.position() ); |
104 | setLooping( mediaPlayerState.isFullscreen() ); | 104 | setLooping( mediaPlayerState.isFullscreen() ); |
105 | // setPaused( mediaPlayerState->paused() ); | 105 | // setPaused( mediaPlayerState->paused() ); |
106 | setPlaying( mediaPlayerState.isPlaying() ); | 106 | setPlaying( mediaPlayerState.isPlaying() ); |
107 | } | 107 | } |
108 | 108 | ||
109 | AudioWidget::~AudioWidget() { | 109 | AudioWidget::~AudioWidget() { |
110 | 110 | ||
111 | // mediaPlayerState->setPlaying(false); | 111 | // mediaPlayerState->setPlaying(false); |
112 | } | 112 | } |
113 | 113 | ||
114 | namespace { | ||
115 | |||
116 | QPixmap combineImageWithBackground( QImage img, QPixmap bg, QPoint offset ) { | ||
117 | QPixmap pix( img.width(), img.height() ); | ||
118 | QPainter p( &pix ); | ||
119 | p.drawTiledPixmap( pix.rect(), bg, offset ); | ||
120 | p.drawImage( 0, 0, img ); | ||
121 | return pix; | ||
122 | } | ||
123 | |||
124 | |||
125 | QPixmap maskPixToMask( QPixmap pix, QBitmap mask ) { | ||
126 | QPixmap pixmap( pix ); | ||
127 | pixmap.setMask( mask ); | ||
128 | return pixmap; | ||
129 | } | ||
130 | |||
131 | }; | ||
132 | |||
133 | void AudioWidget::resizeEvent( QResizeEvent *e ) { | 114 | void AudioWidget::resizeEvent( QResizeEvent *e ) { |
134 | int h = height(); | 115 | int h = height(); |
135 | int w = width(); | 116 | int w = width(); |
136 | 117 | ||
137 | songInfo.setGeometry( QRect( 2, 2, w - 4, 20 ) ); | 118 | songInfo.setGeometry( QRect( 2, 2, w - 4, 20 ) ); |
138 | slider.setFixedWidth( w - 110 ); | 119 | slider.setFixedWidth( w - 110 ); |
139 | slider.setGeometry( QRect( 15, h - 22, w - 90, 20 ) ); | 120 | slider.setGeometry( QRect( 15, h - 22, w - 90, 20 ) ); |
140 | slider.setBackgroundOrigin( QWidget::ParentOrigin ); | 121 | slider.setBackgroundOrigin( QWidget::ParentOrigin ); |
141 | time.setGeometry( QRect( w - 85, h - 30, 70, 20 ) ); | 122 | time.setGeometry( QRect( w - 85, h - 30, 70, 20 ) ); |
142 | 123 | ||
143 | upperLeftOfButtonMask.rx() = ( w - buttonUpImage.width() ) / 2; | 124 | upperLeftOfButtonMask.rx() = ( w - buttonUpImage.width() ) / 2; |
144 | upperLeftOfButtonMask.ry() = (( h - buttonUpImage.height() ) / 2) - 10; | 125 | upperLeftOfButtonMask.ry() = (( h - buttonUpImage.height() ) / 2) - 10; |
145 | 126 | ||
146 | MediaWidget::resizeEvent( e ); | 127 | MediaWidget::resizeEvent( e ); |
147 | } | 128 | } |
148 | 129 | ||
149 | void AudioWidget::sliderPressed() { | 130 | void AudioWidget::sliderPressed() { |
150 | audioSliderBeingMoved = TRUE; | 131 | audioSliderBeingMoved = TRUE; |
151 | } | 132 | } |
152 | 133 | ||
153 | 134 | ||
154 | void AudioWidget::sliderReleased() { | 135 | void AudioWidget::sliderReleased() { |
155 | audioSliderBeingMoved = FALSE; | 136 | audioSliderBeingMoved = FALSE; |
156 | if ( slider.width() == 0 ) | 137 | if ( slider.width() == 0 ) |
157 | return; | 138 | return; |
158 | long val = long((double)slider.value() * mediaPlayerState.length() / slider.width()); | 139 | long val = long((double)slider.value() * mediaPlayerState.length() / slider.width()); |
159 | mediaPlayerState.setPosition( val ); | 140 | mediaPlayerState.setPosition( val ); |
160 | } | 141 | } |
161 | 142 | ||
162 | void AudioWidget::setPosition( long i ) { | 143 | void AudioWidget::setPosition( long i ) { |
163 | // qDebug("<<<<<<<<<<<<<<<<<<<<<<<<set position %d",i); | 144 | // qDebug("<<<<<<<<<<<<<<<<<<<<<<<<set position %d",i); |
164 | updateSlider( i, mediaPlayerState.length() ); | 145 | updateSlider( i, mediaPlayerState.length() ); |
165 | } | 146 | } |
166 | 147 | ||
167 | 148 | ||
168 | void AudioWidget::setLength( long max ) { | 149 | void AudioWidget::setLength( long max ) { |
169 | updateSlider( mediaPlayerState.position(), max ); | 150 | updateSlider( mediaPlayerState.position(), max ); |
170 | } | 151 | } |
171 | 152 | ||
172 | 153 | ||
173 | void AudioWidget::setDisplayType( MediaPlayerState::DisplayType mediaType ) { | 154 | void AudioWidget::setDisplayType( MediaPlayerState::DisplayType mediaType ) { |
174 | if ( mediaType == MediaPlayerState::Audio ) { | 155 | if ( mediaType == MediaPlayerState::Audio ) { |
175 | // startTimer( 150 ); | 156 | // startTimer( 150 ); |
176 | showMaximized(); | 157 | showMaximized(); |
177 | return; | 158 | return; |
178 | } | 159 | } |
179 | 160 | ||
180 | killTimers(); | 161 | killTimers(); |
181 | hide(); | 162 | hide(); |
182 | } | 163 | } |
183 | 164 | ||
184 | void AudioWidget::loadSkin() | 165 | void AudioWidget::loadSkin() |
185 | { | 166 | { |
186 | loadDefaultSkin( skinInfo, buttonCount ); | 167 | loadDefaultSkin( skinInfo, buttonCount ); |
187 | 168 | ||
188 | setBackgroundPixmap( backgroundPixmap ); | 169 | setBackgroundPixmap( backgroundPixmap ); |
189 | 170 | ||
190 | songInfo.setFocusPolicy( QWidget::NoFocus ); | 171 | songInfo.setFocusPolicy( QWidget::NoFocus ); |
191 | // changeTextColor( &songInfo ); | 172 | // changeTextColor( &songInfo ); |
192 | // songInfo.setBackgroundColor( QColor( 167, 212, 167 )); | 173 | // songInfo.setBackgroundColor( QColor( 167, 212, 167 )); |
193 | // songInfo.setFrameStyle( QFrame::NoFrame); | 174 | // songInfo.setFrameStyle( QFrame::NoFrame); |
194 | songInfo.setFrameStyle( QFrame::WinPanel | QFrame::Sunken ); | 175 | songInfo.setFrameStyle( QFrame::WinPanel | QFrame::Sunken ); |
195 | // songInfo.setForegroundColor(Qt::white); | 176 | // songInfo.setForegroundColor(Qt::white); |
196 | 177 | ||
197 | slider.setFixedHeight( 20 ); | 178 | slider.setFixedHeight( 20 ); |
198 | slider.setMinValue( 0 ); | 179 | slider.setMinValue( 0 ); |
199 | slider.setMaxValue( 1 ); | 180 | slider.setMaxValue( 1 ); |
200 | slider.setFocusPolicy( QWidget::NoFocus ); | 181 | slider.setFocusPolicy( QWidget::NoFocus ); |
201 | slider.setBackgroundPixmap( backgroundPixmap ); | 182 | slider.setBackgroundPixmap( backgroundPixmap ); |
202 | 183 | ||
203 | // Config cofg("qpe"); | 184 | // Config cofg("qpe"); |
204 | // cofg.setGroup("Appearance"); | 185 | // cofg.setGroup("Appearance"); |
205 | // QColor backgroundcolor = QColor( cofg.readEntry( "Background", "#E5E1D5" ) ); | 186 | // QColor backgroundcolor = QColor( cofg.readEntry( "Background", "#E5E1D5" ) ); |
206 | 187 | ||
207 | time.setFocusPolicy( QWidget::NoFocus ); | 188 | time.setFocusPolicy( QWidget::NoFocus ); |
208 | time.setAlignment( Qt::AlignCenter ); | 189 | time.setAlignment( Qt::AlignCenter ); |
209 | 190 | ||
210 | // time.setFrame(FALSE); | 191 | // time.setFrame(FALSE); |
211 | // changeTextColor( &time ); | 192 | // changeTextColor( &time ); |
212 | 193 | ||
213 | resizeEvent( 0 ); | 194 | resizeEvent( 0 ); |
214 | } | 195 | } |
215 | 196 | ||
216 | void AudioWidget::setSeekable( bool isSeekable ) { | 197 | void AudioWidget::setSeekable( bool isSeekable ) { |
217 | 198 | ||
218 | if ( !isSeekable ) { | 199 | if ( !isSeekable ) { |
219 | qDebug("<<<<<<<<<<<<<<file is STREAMING>>>>>>>>>>>>>>>>>>>"); | 200 | qDebug("<<<<<<<<<<<<<<file is STREAMING>>>>>>>>>>>>>>>>>>>"); |
220 | if( !slider.isHidden()) { | 201 | if( !slider.isHidden()) { |
221 | slider.hide(); | 202 | slider.hide(); |
222 | } | 203 | } |
223 | disconnect( &mediaPlayerState, SIGNAL( positionChanged(long) ),this, SLOT( setPosition(long) ) ); | 204 | disconnect( &mediaPlayerState, SIGNAL( positionChanged(long) ),this, SLOT( setPosition(long) ) ); |
224 | disconnect( &mediaPlayerState, SIGNAL( positionUpdated(long) ),this, SLOT( setPosition(long) ) ); | 205 | disconnect( &mediaPlayerState, SIGNAL( positionUpdated(long) ),this, SLOT( setPosition(long) ) ); |
225 | disconnect( &slider, SIGNAL( sliderPressed() ), this, SLOT( sliderPressed() ) ); | 206 | disconnect( &slider, SIGNAL( sliderPressed() ), this, SLOT( sliderPressed() ) ); |
226 | disconnect( &slider, SIGNAL( sliderReleased() ), this, SLOT( sliderReleased() ) ); | 207 | disconnect( &slider, SIGNAL( sliderReleased() ), this, SLOT( sliderReleased() ) ); |
227 | } else { | 208 | } else { |
228 | // this stops the slider from being moved, thus | 209 | // this stops the slider from being moved, thus |
229 | // does not stop stream when it reaches the end | 210 | // does not stop stream when it reaches the end |
230 | slider.show(); | 211 | slider.show(); |
231 | qDebug( " CONNECT SET POSTION " ); | 212 | qDebug( " CONNECT SET POSTION " ); |
232 | connect( &mediaPlayerState, SIGNAL( positionChanged(long) ),this, SLOT( setPosition(long) ) ); | 213 | connect( &mediaPlayerState, SIGNAL( positionChanged(long) ),this, SLOT( setPosition(long) ) ); |
233 | connect( &mediaPlayerState, SIGNAL( positionUpdated(long) ),this, SLOT( setPosition(long) ) ); | 214 | connect( &mediaPlayerState, SIGNAL( positionUpdated(long) ),this, SLOT( setPosition(long) ) ); |
234 | connect( &slider, SIGNAL( sliderPressed() ), this, SLOT( sliderPressed() ) ); | 215 | connect( &slider, SIGNAL( sliderPressed() ), this, SLOT( sliderPressed() ) ); |
235 | connect( &slider, SIGNAL( sliderReleased() ), this, SLOT( sliderReleased() ) ); | 216 | connect( &slider, SIGNAL( sliderReleased() ), this, SLOT( sliderReleased() ) ); |
236 | } | 217 | } |
237 | } | 218 | } |
238 | 219 | ||
239 | 220 | ||
240 | static QString timeAsString( long length ) { | 221 | static QString timeAsString( long length ) { |
241 | int minutes = length / 60; | 222 | int minutes = length / 60; |
242 | int seconds = length % 60; | 223 | int seconds = length % 60; |
243 | return QString("%1:%2%3").arg( minutes ).arg( seconds / 10 ).arg( seconds % 10 ); | 224 | return QString("%1:%2%3").arg( minutes ).arg( seconds / 10 ).arg( seconds % 10 ); |
244 | } | 225 | } |
245 | 226 | ||
246 | void AudioWidget::updateSlider( long i, long max ) { | 227 | void AudioWidget::updateSlider( long i, long max ) { |
247 | 228 | ||
248 | time.setText( timeAsString( i ) + " / " + timeAsString( max ) ); | 229 | time.setText( timeAsString( i ) + " / " + timeAsString( max ) ); |
249 | // qDebug( timeAsString( i ) + " / " + timeAsString( max ) ) ; | 230 | // qDebug( timeAsString( i ) + " / " + timeAsString( max ) ) ; |
250 | 231 | ||
251 | if ( max == 0 ) { | 232 | if ( max == 0 ) { |
252 | return; | 233 | return; |
253 | } | 234 | } |
254 | // Will flicker too much if we don't do this | 235 | // Will flicker too much if we don't do this |
255 | // Scale to something reasonable | 236 | // Scale to something reasonable |
256 | int width = slider.width(); | 237 | int width = slider.width(); |
257 | int val = int((double)i * width / max); | 238 | int val = int((double)i * width / max); |
258 | if ( !audioSliderBeingMoved ) { | 239 | if ( !audioSliderBeingMoved ) { |
259 | if ( slider.value() != val ) { | 240 | if ( slider.value() != val ) { |
260 | slider.setValue( val ); | 241 | slider.setValue( val ); |