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