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