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