-rw-r--r-- | noncore/multimedia/opieplayer2/audiowidget.cpp | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/noncore/multimedia/opieplayer2/audiowidget.cpp b/noncore/multimedia/opieplayer2/audiowidget.cpp index 7c49733..45f301e 100644 --- a/noncore/multimedia/opieplayer2/audiowidget.cpp +++ b/noncore/multimedia/opieplayer2/audiowidget.cpp | |||
@@ -1,450 +1,450 @@ | |||
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 | 37 | ||
38 | #include <qwidget.h> | 38 | #include <qwidget.h> |
39 | #include <qpixmap.h> | 39 | #include <qpixmap.h> |
40 | #include <qbutton.h> | 40 | #include <qbutton.h> |
41 | #include <qpainter.h> | 41 | #include <qpainter.h> |
42 | #include <qframe.h> | 42 | #include <qframe.h> |
43 | #include <qlayout.h> | 43 | #include <qlayout.h> |
44 | 44 | #include <qdir.h> | |
45 | #include <stdlib.h> | 45 | #include <stdlib.h> |
46 | #include <stdio.h> | 46 | #include <stdio.h> |
47 | 47 | ||
48 | #include "audiowidget.h" | 48 | #include "audiowidget.h" |
49 | #include "mediaplayerstate.h" | 49 | #include "mediaplayerstate.h" |
50 | #include "playlistwidget.h" | 50 | #include "playlistwidget.h" |
51 | 51 | ||
52 | extern MediaPlayerState *mediaPlayerState; | 52 | extern MediaPlayerState *mediaPlayerState; |
53 | extern PlayListWidget *playList; | 53 | extern PlayListWidget *playList; |
54 | 54 | ||
55 | static const int xo = -2; // movable x offset | 55 | static const int xo = -2; // movable x offset |
56 | static const int yo = 22; // movable y offset | 56 | static const int yo = 22; // movable y offset |
57 | 57 | ||
58 | 58 | ||
59 | Ticker::Ticker( QWidget* parent=0 ) : QFrame( parent ) { | 59 | Ticker::Ticker( QWidget* parent=0 ) : QFrame( parent ) { |
60 | setFrameStyle( WinPanel | Sunken ); | 60 | setFrameStyle( WinPanel | Sunken ); |
61 | setText( "No Song" ); | 61 | setText( "No Song" ); |
62 | } | 62 | } |
63 | 63 | ||
64 | Ticker::~Ticker() { | 64 | Ticker::~Ticker() { |
65 | } | 65 | } |
66 | 66 | ||
67 | void Ticker::setText( const QString& text ) { | 67 | void Ticker::setText( const QString& text ) { |
68 | pos = 0; // reset it everytime the text is changed | 68 | pos = 0; // reset it everytime the text is changed |
69 | scrollText = text; | 69 | scrollText = text; |
70 | pixelLen = fontMetrics().width( scrollText ); | 70 | pixelLen = fontMetrics().width( scrollText ); |
71 | killTimers(); | 71 | killTimers(); |
72 | if ( pixelLen > width() ) { | 72 | if ( pixelLen > width() ) { |
73 | startTimer( 50 ); | 73 | startTimer( 50 ); |
74 | } | 74 | } |
75 | update(); | 75 | update(); |
76 | } | 76 | } |
77 | 77 | ||
78 | 78 | ||
79 | void Ticker::timerEvent( QTimerEvent * ) { | 79 | void Ticker::timerEvent( QTimerEvent * ) { |
80 | pos = ( pos + 1 > pixelLen ) ? 0 : pos + 1; | 80 | pos = ( pos + 1 > pixelLen ) ? 0 : pos + 1; |
81 | scroll( -1, 0, contentsRect() ); | 81 | scroll( -1, 0, contentsRect() ); |
82 | repaint( FALSE ); | 82 | repaint( FALSE ); |
83 | } | 83 | } |
84 | 84 | ||
85 | void Ticker::drawContents( QPainter *p ) { | 85 | void Ticker::drawContents( QPainter *p ) { |
86 | for ( int i = 0; i - pos < width() && (i < 1 || pixelLen > width()); i += pixelLen ) { | 86 | for ( int i = 0; i - pos < width() && (i < 1 || pixelLen > width()); i += pixelLen ) { |
87 | p->drawText( i - pos, 0, INT_MAX, height(), AlignVCenter, scrollText ); | 87 | p->drawText( i - pos, 0, INT_MAX, height(), AlignVCenter, scrollText ); |
88 | } | 88 | } |
89 | QPixmap pm( width(), height() ); | 89 | QPixmap pm( width(), height() ); |
90 | pm.fill( colorGroup().base() ); | 90 | pm.fill( colorGroup().base() ); |
91 | QPainter pmp( &pm ); | 91 | QPainter pmp( &pm ); |
92 | for ( int i = 0; i - pos < width() && (i < 1 || pixelLen > width()); i += pixelLen ) { | 92 | for ( int i = 0; i - pos < width() && (i < 1 || pixelLen > width()); i += pixelLen ) { |
93 | pmp.drawText( i - pos, 0, INT_MAX, height(), AlignVCenter, scrollText ); | 93 | pmp.drawText( i - pos, 0, INT_MAX, height(), AlignVCenter, scrollText ); |
94 | } | 94 | } |
95 | p->drawPixmap( 0, 0, pm ); | 95 | p->drawPixmap( 0, 0, pm ); |
96 | } | 96 | } |
97 | 97 | ||
98 | struct MediaButton { | 98 | struct MediaButton { |
99 | bool isToggle, isHeld, isDown; | 99 | bool isToggle, isHeld, isDown; |
100 | }; | 100 | }; |
101 | 101 | ||
102 | //Layout information for the audioButtons (and if it is a toggle button or not) | 102 | //Layout information for the audioButtons (and if it is a toggle button or not) |
103 | MediaButton audioButtons[] = { | 103 | MediaButton audioButtons[] = { |
104 | { TRUE, FALSE, FALSE }, // play | 104 | { TRUE, FALSE, FALSE }, // play |
105 | { FALSE, FALSE, FALSE }, // stop | 105 | { FALSE, FALSE, FALSE }, // stop |
106 | { FALSE, FALSE, FALSE }, // next | 106 | { FALSE, FALSE, FALSE }, // next |
107 | { FALSE, FALSE, FALSE }, // previous | 107 | { FALSE, FALSE, FALSE }, // previous |
108 | { FALSE, FALSE, FALSE }, // volume up | 108 | { FALSE, FALSE, FALSE }, // volume up |
109 | { FALSE, FALSE, FALSE }, // volume down | 109 | { FALSE, FALSE, FALSE }, // volume down |
110 | { TRUE, FALSE, FALSE }, // repeat/loop | 110 | { TRUE, FALSE, FALSE }, // repeat/loop |
111 | { FALSE, FALSE, FALSE }, // playlist | 111 | { FALSE, FALSE, FALSE }, // playlist |
112 | { FALSE, FALSE, FALSE }, // forward | 112 | { FALSE, FALSE, FALSE }, // forward |
113 | { FALSE, FALSE, FALSE } // back | 113 | { FALSE, FALSE, FALSE } // back |
114 | }; | 114 | }; |
115 | 115 | ||
116 | const char *skin_mask_file_names[10] = { | 116 | const char *skin_mask_file_names[10] = { |
117 | "play", "stop", "next", "prev", "up", | 117 | "play", "stop", "next", "prev", "up", |
118 | "down", "loop", "playlist", "forward", "back" | 118 | "down", "loop", "playlist", "forward", "back" |
119 | }; | 119 | }; |
120 | 120 | ||
121 | 121 | ||
122 | static void changeTextColor( QWidget *w ) { | 122 | static void changeTextColor( QWidget *w ) { |
123 | QPalette p = w->palette(); | 123 | QPalette p = w->palette(); |
124 | p.setBrush( QColorGroup::Background, QColor( 167, 212, 167 ) ); | 124 | p.setBrush( QColorGroup::Background, QColor( 167, 212, 167 ) ); |
125 | p.setBrush( QColorGroup::Base, QColor( 167, 212, 167 ) ); | 125 | p.setBrush( QColorGroup::Base, QColor( 167, 212, 167 ) ); |
126 | w->setPalette( p ); | 126 | w->setPalette( p ); |
127 | } | 127 | } |
128 | 128 | ||
129 | static const int numButtons = (sizeof(audioButtons)/sizeof(MediaButton)); | 129 | static const int numButtons = (sizeof(audioButtons)/sizeof(MediaButton)); |
130 | 130 | ||
131 | 131 | ||
132 | AudioWidget::AudioWidget(QWidget* parent, const char* name, WFlags f) : | 132 | AudioWidget::AudioWidget(QWidget* parent, const char* name, WFlags f) : |
133 | 133 | ||
134 | QWidget( parent, name, f ), songInfo( this ), slider( Qt::Horizontal, this ), time( this ) { | 134 | QWidget( parent, name, f ), songInfo( this ), slider( Qt::Horizontal, this ), time( this ) { |
135 | 135 | ||
136 | setCaption( tr("OpiePlayer") ); | 136 | setCaption( tr("OpiePlayer") ); |
137 | 137 | ||
138 | Config cfg("OpiePlayer"); | 138 | Config cfg("OpiePlayer"); |
139 | cfg.setGroup("Options"); | 139 | cfg.setGroup("Options"); |
140 | skin = cfg.readEntry("Skin","default"); | 140 | skin = cfg.readEntry("Skin","default"); |
141 | //skin = "scaleTest"; | 141 | //skin = "scaleTest"; |
142 | // color of background, frame, degree of transparency | 142 | // color of background, frame, degree of transparency |
143 | 143 | ||
144 | QString skinPath = "opieplayer2/skins/" + skin; | 144 | QString skinPath = "opieplayer2/skins/" + skin; |
145 | pixBg = new QPixmap( Resource::loadPixmap( QString("%1/background").arg(skinPath) ) ); | 145 | pixBg = new QPixmap( Resource::loadPixmap( QString("%1/background").arg(skinPath) ) ); |
146 | imgUp = new QImage( Resource::loadImage( QString("%1/skin_up").arg(skinPath) ) ); | 146 | imgUp = new QImage( Resource::loadImage( QString("%1/skin_up").arg(skinPath) ) ); |
147 | imgDn = new QImage( Resource::loadImage( QString("%1/skin_down").arg(skinPath) ) ); | 147 | imgDn = new QImage( Resource::loadImage( QString("%1/skin_down").arg(skinPath) ) ); |
148 | 148 | ||
149 | imgButtonMask = new QImage( imgUp->width(), imgUp->height(), 8, 255 ); | 149 | imgButtonMask = new QImage( imgUp->width(), imgUp->height(), 8, 255 ); |
150 | imgButtonMask->fill( 0 ); | 150 | imgButtonMask->fill( 0 ); |
151 | 151 | ||
152 | for ( int i = 0; i < 10; i++ ) { | 152 | for ( int i = 0; i < 10; i++ ) { |
153 | QString filename = QString( QPEApplication::qpeDir() + "/pics/" + skinPath + "/skin_mask_" + skin_mask_file_names[i] + ".png" ); | 153 | QString filename = QString( QPEApplication::qpeDir() + "/pics/" + skinPath + "/skin_mask_" + skin_mask_file_names[i] + ".png" ); |
154 | masks[i] = new QBitmap( filename ); | 154 | masks[i] = new QBitmap( filename ); |
155 | 155 | ||
156 | if ( !masks[i]->isNull() ) { | 156 | if ( !masks[i]->isNull() ) { |
157 | QImage imgMask = masks[i]->convertToImage(); | 157 | QImage imgMask = masks[i]->convertToImage(); |
158 | uchar **dest = imgButtonMask->jumpTable(); | 158 | uchar **dest = imgButtonMask->jumpTable(); |
159 | for ( int y = 0; y < imgUp->height(); y++ ) { | 159 | for ( int y = 0; y < imgUp->height(); y++ ) { |
160 | uchar *line = dest[y]; | 160 | uchar *line = dest[y]; |
161 | for ( int x = 0; x < imgUp->width(); x++ ) | 161 | for ( int x = 0; x < imgUp->width(); x++ ) |
162 | if ( !qRed( imgMask.pixel( x, y ) ) ) | 162 | if ( !qRed( imgMask.pixel( x, y ) ) ) |
163 | line[x] = i + 1; | 163 | line[x] = i + 1; |
164 | } | 164 | } |
165 | } | 165 | } |
166 | 166 | ||
167 | } | 167 | } |
168 | 168 | ||
169 | for ( int i = 0; i < 10; i++ ) { | 169 | for ( int i = 0; i < 10; i++ ) { |
170 | buttonPixUp[i] = 0l; | 170 | buttonPixUp[i] = 0l; |
171 | buttonPixDown[i] = 0l; | 171 | buttonPixDown[i] = 0l; |
172 | } | 172 | } |
173 | 173 | ||
174 | setBackgroundPixmap( *pixBg ); | 174 | setBackgroundPixmap( *pixBg ); |
175 | 175 | ||
176 | songInfo.setFocusPolicy( QWidget::NoFocus ); | 176 | songInfo.setFocusPolicy( QWidget::NoFocus ); |
177 | changeTextColor( &songInfo ); | 177 | changeTextColor( &songInfo ); |
178 | 178 | ||
179 | slider.setFixedHeight( 20 ); | 179 | slider.setFixedHeight( 20 ); |
180 | slider.setMinValue( 0 ); | 180 | slider.setMinValue( 0 ); |
181 | slider.setMaxValue( 1 ); | 181 | slider.setMaxValue( 1 ); |
182 | slider.setFocusPolicy( QWidget::NoFocus ); | 182 | slider.setFocusPolicy( QWidget::NoFocus ); |
183 | slider.setBackgroundPixmap( *pixBg ); | 183 | slider.setBackgroundPixmap( *pixBg ); |
184 | 184 | ||
185 | time.setFocusPolicy( QWidget::NoFocus ); | 185 | time.setFocusPolicy( QWidget::NoFocus ); |
186 | time.setAlignment( Qt::AlignCenter ); | 186 | time.setAlignment( Qt::AlignCenter ); |
187 | time.setFrame(FALSE); | 187 | time.setFrame(FALSE); |
188 | changeTextColor( &time ); | 188 | changeTextColor( &time ); |
189 | 189 | ||
190 | resizeEvent( NULL ); | 190 | resizeEvent( NULL ); |
191 | 191 | ||
192 | connect( &slider, SIGNAL( sliderPressed() ), this, SLOT( sliderPressed() ) ); | 192 | connect( &slider, SIGNAL( sliderPressed() ), this, SLOT( sliderPressed() ) ); |
193 | connect( &slider, SIGNAL( sliderReleased() ), this, SLOT( sliderReleased() ) ); | 193 | connect( &slider, SIGNAL( sliderReleased() ), this, SLOT( sliderReleased() ) ); |
194 | 194 | ||
195 | connect( mediaPlayerState, SIGNAL( lengthChanged(long) ), this, SLOT( setLength(long) ) ); | 195 | connect( mediaPlayerState, SIGNAL( lengthChanged(long) ), this, SLOT( setLength(long) ) ); |
196 | connect( mediaPlayerState, SIGNAL( viewChanged(char) ), this, SLOT( setView(char) ) ); | 196 | connect( mediaPlayerState, SIGNAL( viewChanged(char) ), this, SLOT( setView(char) ) ); |
197 | connect( mediaPlayerState, SIGNAL( loopingToggled(bool) ), this, SLOT( setLooping(bool) ) ); | 197 | connect( mediaPlayerState, SIGNAL( loopingToggled(bool) ), this, SLOT( setLooping(bool) ) ); |
198 | // connect( mediaPlayerState, SIGNAL( pausedToggled(bool) ), this, SLOT( setPaused(bool) ) ); | 198 | // connect( mediaPlayerState, SIGNAL( pausedToggled(bool) ), this, SLOT( setPaused(bool) ) ); |
199 | connect( mediaPlayerState, SIGNAL( playingToggled(bool) ), this, SLOT( setPlaying(bool) ) ); | 199 | connect( mediaPlayerState, SIGNAL( playingToggled(bool) ), this, SLOT( setPlaying(bool) ) ); |
200 | 200 | ||
201 | connect( this, SIGNAL( forwardClicked() ), this, SLOT( skipFor() ) ); | 201 | connect( this, SIGNAL( forwardClicked() ), this, SLOT( skipFor() ) ); |
202 | connect( this, SIGNAL( backClicked() ), this, SLOT( skipBack() ) ); | 202 | connect( this, SIGNAL( backClicked() ), this, SLOT( skipBack() ) ); |
203 | connect( this, SIGNAL( forwardReleased() ), this, SLOT( stopSkip() ) ); | 203 | connect( this, SIGNAL( forwardReleased() ), this, SLOT( stopSkip() ) ); |
204 | connect( this, SIGNAL( backReleased() ), this, SLOT( stopSkip() ) ); | 204 | connect( this, SIGNAL( backReleased() ), this, SLOT( stopSkip() ) ); |
205 | 205 | ||
206 | 206 | ||
207 | 207 | ||
208 | // Intialise state | 208 | // Intialise state |
209 | setLength( mediaPlayerState->length() ); | 209 | setLength( mediaPlayerState->length() ); |
210 | setPosition( mediaPlayerState->position() ); | 210 | setPosition( mediaPlayerState->position() ); |
211 | setLooping( mediaPlayerState->fullscreen() ); | 211 | setLooping( mediaPlayerState->fullscreen() ); |
212 | // setPaused( mediaPlayerState->paused() ); | 212 | // setPaused( mediaPlayerState->paused() ); |
213 | setPlaying( mediaPlayerState->playing() ); | 213 | setPlaying( mediaPlayerState->playing() ); |
214 | 214 | ||
215 | } | 215 | } |
216 | 216 | ||
217 | AudioWidget::~AudioWidget() { | 217 | AudioWidget::~AudioWidget() { |
218 | 218 | ||
219 | for ( int i = 0; i < 10; i++ ) { | 219 | for ( int i = 0; i < 10; i++ ) { |
220 | delete buttonPixUp[i]; | 220 | delete buttonPixUp[i]; |
221 | delete buttonPixDown[i]; | 221 | delete buttonPixDown[i]; |
222 | } | 222 | } |
223 | delete pixBg; | 223 | delete pixBg; |
224 | delete imgUp; | 224 | delete imgUp; |
225 | delete imgDn; | 225 | delete imgDn; |
226 | delete imgButtonMask; | 226 | delete imgButtonMask; |
227 | for ( int i = 0; i < 10; i++ ) { | 227 | for ( int i = 0; i < 10; i++ ) { |
228 | delete masks[i]; | 228 | delete masks[i]; |
229 | } | 229 | } |
230 | // mediaPlayerState->setPlaying(false); | 230 | // mediaPlayerState->setPlaying(false); |
231 | } | 231 | } |
232 | 232 | ||
233 | namespace { | 233 | namespace { |
234 | 234 | ||
235 | QPixmap *combineImageWithBackground( QImage img, QPixmap bg, QPoint offset ) { | 235 | QPixmap *combineImageWithBackground( QImage img, QPixmap bg, QPoint offset ) { |
236 | QPixmap pix( img.width(), img.height() ); | 236 | QPixmap pix( img.width(), img.height() ); |
237 | QPainter p( &pix ); | 237 | QPainter p( &pix ); |
238 | p.drawTiledPixmap( pix.rect(), bg, offset ); | 238 | p.drawTiledPixmap( pix.rect(), bg, offset ); |
239 | p.drawImage( 0, 0, img ); | 239 | p.drawImage( 0, 0, img ); |
240 | return new QPixmap( pix ); | 240 | return new QPixmap( pix ); |
241 | } | 241 | } |
242 | 242 | ||
243 | 243 | ||
244 | QPixmap *maskPixToMask( QPixmap pix, QBitmap mask ) { | 244 | QPixmap *maskPixToMask( QPixmap pix, QBitmap mask ) { |
245 | QPixmap *pixmap = new QPixmap( pix ); | 245 | QPixmap *pixmap = new QPixmap( pix ); |
246 | pixmap->setMask( mask ); | 246 | pixmap->setMask( mask ); |
247 | return pixmap; | 247 | return pixmap; |
248 | } | 248 | } |
249 | 249 | ||
250 | }; | 250 | }; |
251 | 251 | ||
252 | void AudioWidget::resizeEvent( QResizeEvent * ) { | 252 | void AudioWidget::resizeEvent( QResizeEvent * ) { |
253 | int h = height(); | 253 | int h = height(); |
254 | int w = width(); | 254 | int w = width(); |
255 | 255 | ||
256 | songInfo.setGeometry( QRect( 2, 10, w - 4, 20 ) ); | 256 | songInfo.setGeometry( QRect( 2, 2, w - 4, 20 ) ); |
257 | slider.setFixedWidth( w - 110 ); | 257 | slider.setFixedWidth( w - 110 ); |
258 | slider.setGeometry( QRect( 15, h - 30, w - 90, 20 ) ); | 258 | slider.setGeometry( QRect( 15, h - 22, w - 90, 20 ) ); |
259 | slider.setBackgroundOrigin( QWidget::ParentOrigin ); | 259 | slider.setBackgroundOrigin( QWidget::ParentOrigin ); |
260 | time.setGeometry( QRect( w - 85, h - 30, 70, 20 ) ); | 260 | time.setGeometry( QRect( w - 85, h - 30, 70, 20 ) ); |
261 | 261 | ||
262 | xoff = ( w - imgUp->width() ) / 2; | 262 | xoff = ( w - imgUp->width() ) / 2; |
263 | yoff = (( h - imgUp->height() ) / 2) - 10; | 263 | yoff = (( h - imgUp->height() ) / 2) - 10; |
264 | QPoint p( xoff, yoff ); | 264 | QPoint p( xoff, yoff ); |
265 | 265 | ||
266 | QPixmap *pixUp = combineImageWithBackground( *imgUp, *pixBg, p ); | 266 | QPixmap *pixUp = combineImageWithBackground( *imgUp, *pixBg, p ); |
267 | QPixmap *pixDn = combineImageWithBackground( *imgDn, *pixBg, p ); | 267 | QPixmap *pixDn = combineImageWithBackground( *imgDn, *pixBg, p ); |
268 | 268 | ||
269 | for ( int i = 0; i < 10; i++ ) { | 269 | for ( int i = 0; i < 10; i++ ) { |
270 | if ( !masks[i]->isNull() ) { | 270 | if ( !masks[i]->isNull() ) { |
271 | delete buttonPixUp[i]; | 271 | delete buttonPixUp[i]; |
272 | delete buttonPixDown[i]; | 272 | delete buttonPixDown[i]; |
273 | buttonPixUp[i] = maskPixToMask( *pixUp, *masks[i] ); | 273 | buttonPixUp[i] = maskPixToMask( *pixUp, *masks[i] ); |
274 | buttonPixDown[i] = maskPixToMask( *pixDn, *masks[i] ); | 274 | buttonPixDown[i] = maskPixToMask( *pixDn, *masks[i] ); |
275 | } | 275 | } |
276 | } | 276 | } |
277 | 277 | ||
278 | delete pixUp; | 278 | delete pixUp; |
279 | delete pixDn; | 279 | delete pixDn; |
280 | } | 280 | } |
281 | 281 | ||
282 | static bool audioSliderBeingMoved = FALSE; | 282 | static bool audioSliderBeingMoved = FALSE; |
283 | 283 | ||
284 | 284 | ||
285 | void AudioWidget::sliderPressed() { | 285 | void AudioWidget::sliderPressed() { |
286 | audioSliderBeingMoved = TRUE; | 286 | audioSliderBeingMoved = TRUE; |
287 | } | 287 | } |
288 | 288 | ||
289 | 289 | ||
290 | void AudioWidget::sliderReleased() { | 290 | void AudioWidget::sliderReleased() { |
291 | audioSliderBeingMoved = FALSE; | 291 | audioSliderBeingMoved = FALSE; |
292 | if ( slider.width() == 0 ) | 292 | if ( slider.width() == 0 ) |
293 | return; | 293 | return; |
294 | long val = long((double)slider.value() * mediaPlayerState->length() / slider.width()); | 294 | long val = long((double)slider.value() * mediaPlayerState->length() / slider.width()); |
295 | mediaPlayerState->setPosition( val ); | 295 | mediaPlayerState->setPosition( val ); |
296 | } | 296 | } |
297 | 297 | ||
298 | void AudioWidget::setPosition( long i ) { | 298 | void AudioWidget::setPosition( long i ) { |
299 | // qDebug("<<<<<<<<<<<<<<<<<<<<<<<<set position %d",i); | 299 | // qDebug("<<<<<<<<<<<<<<<<<<<<<<<<set position %d",i); |
300 | updateSlider( i, mediaPlayerState->length() ); | 300 | updateSlider( i, mediaPlayerState->length() ); |
301 | } | 301 | } |
302 | 302 | ||
303 | 303 | ||
304 | void AudioWidget::setLength( long max ) { | 304 | void AudioWidget::setLength( long max ) { |
305 | updateSlider( mediaPlayerState->position(), max ); | 305 | updateSlider( mediaPlayerState->position(), max ); |
306 | } | 306 | } |
307 | 307 | ||
308 | 308 | ||
309 | void AudioWidget::setView( char view ) { | 309 | void AudioWidget::setView( char view ) { |
310 | 310 | ||
311 | // this isnt working for some reason | 311 | // this isnt working for some reason |
312 | 312 | ||
313 | if ( mediaPlayerState->streaming() ) { | 313 | if ( mediaPlayerState->streaming() ) { |
314 | qDebug("<<<<<<<<<<<<<<file is STREAMING>>>>>>>>>>>>>>>>>>>"); | 314 | qDebug("<<<<<<<<<<<<<<file is STREAMING>>>>>>>>>>>>>>>>>>>"); |
315 | if( !slider.isHidden()) { | 315 | if( !slider.isHidden()) { |
316 | slider.hide(); | 316 | slider.hide(); |
317 | } | 317 | } |
318 | disconnect( mediaPlayerState, SIGNAL( positionChanged(long) ),this, SLOT( setPosition(long) ) ); | 318 | disconnect( mediaPlayerState, SIGNAL( positionChanged(long) ),this, SLOT( setPosition(long) ) ); |
319 | disconnect( mediaPlayerState, SIGNAL( positionUpdated(long) ),this, SLOT( setPosition(long) ) ); | 319 | disconnect( mediaPlayerState, SIGNAL( positionUpdated(long) ),this, SLOT( setPosition(long) ) ); |
320 | } else { | 320 | } else { |
321 | // this stops the slider from being moved, thus | 321 | // this stops the slider from being moved, thus |
322 | // does not stop stream when it reaches the end | 322 | // does not stop stream when it reaches the end |
323 | slider.show(); | 323 | slider.show(); |
324 | connect( mediaPlayerState, SIGNAL( positionChanged(long) ),this, SLOT( setPosition(long) ) ); | 324 | connect( mediaPlayerState, SIGNAL( positionChanged(long) ),this, SLOT( setPosition(long) ) ); |
325 | connect( mediaPlayerState, SIGNAL( positionUpdated(long) ),this, SLOT( setPosition(long) ) ); | 325 | connect( mediaPlayerState, SIGNAL( positionUpdated(long) ),this, SLOT( setPosition(long) ) ); |
326 | } | 326 | } |
327 | 327 | ||
328 | if ( view == 'a' ) { | 328 | if ( view == 'a' ) { |
329 | // startTimer( 150 ); | 329 | // startTimer( 150 ); |
330 | showMaximized(); | 330 | showMaximized(); |
331 | } else { | 331 | } else { |
332 | killTimers(); | 332 | killTimers(); |
333 | hide(); | 333 | hide(); |
334 | } | 334 | } |
335 | qApp->processEvents(); | 335 | qApp->processEvents(); |
336 | } | 336 | } |
337 | 337 | ||
338 | 338 | ||
339 | static QString timeAsString( long length ) { | 339 | static QString timeAsString( long length ) { |
340 | int minutes = length / 60; | 340 | int minutes = length / 60; |
341 | int seconds = length % 60; | 341 | int seconds = length % 60; |
342 | return QString("%1:%2%3").arg( minutes ).arg( seconds / 10 ).arg( seconds % 10 ); | 342 | return QString("%1:%2%3").arg( minutes ).arg( seconds / 10 ).arg( seconds % 10 ); |
343 | } | 343 | } |
344 | 344 | ||
345 | void AudioWidget::updateSlider( long i, long max ) { | 345 | void AudioWidget::updateSlider( long i, long max ) { |
346 | 346 | ||
347 | time.setText( timeAsString( i ) + " / " + timeAsString( max ) ); | 347 | time.setText( timeAsString( i ) + " / " + timeAsString( max ) ); |
348 | // qDebug( timeAsString( i ) + " / " + timeAsString( max ) ) ; | 348 | // qDebug( timeAsString( i ) + " / " + timeAsString( max ) ) ; |
349 | 349 | ||
350 | if ( max == 0 ) { | 350 | if ( max == 0 ) { |
351 | return; | 351 | return; |
352 | } | 352 | } |
353 | // Will flicker too much if we don't do this | 353 | // Will flicker too much if we don't do this |
354 | // Scale to something reasonable | 354 | // Scale to something reasonable |
355 | int width = slider.width(); | 355 | int width = slider.width(); |
356 | int val = int((double)i * width / max); | 356 | int val = int((double)i * width / max); |
357 | if ( !audioSliderBeingMoved ) { | 357 | if ( !audioSliderBeingMoved ) { |
358 | if ( slider.value() != val ) { | 358 | if ( slider.value() != val ) { |
359 | slider.setValue( val ); | 359 | slider.setValue( val ); |
360 | } | 360 | } |
361 | 361 | ||
362 | if ( slider.maxValue() != width ) { | 362 | if ( slider.maxValue() != width ) { |
363 | slider.setMaxValue( width ); | 363 | slider.setMaxValue( width ); |
364 | } | 364 | } |
365 | } | 365 | } |
366 | } | 366 | } |
367 | 367 | ||
368 | 368 | ||
369 | void AudioWidget::setToggleButton( int i, bool down ) { | 369 | void AudioWidget::setToggleButton( int i, bool down ) { |
370 | qDebug("setToggleButton %d", i); | 370 | qDebug("setToggleButton %d", i); |
371 | if ( down != audioButtons[i].isDown ) { | 371 | if ( down != audioButtons[i].isDown ) { |
372 | toggleButton( i ); | 372 | toggleButton( i ); |
373 | } | 373 | } |
374 | } | 374 | } |
375 | 375 | ||
376 | 376 | ||
377 | void AudioWidget::toggleButton( int i ) { | 377 | void AudioWidget::toggleButton( int i ) { |
378 | audioButtons[i].isDown = !audioButtons[i].isDown; | 378 | audioButtons[i].isDown = !audioButtons[i].isDown; |
379 | QPainter p(this); | 379 | QPainter p(this); |
380 | paintButton ( &p, i ); | 380 | paintButton ( &p, i ); |
381 | } | 381 | } |
382 | 382 | ||
383 | 383 | ||
384 | void AudioWidget::paintButton( QPainter *p, int i ) { | 384 | void AudioWidget::paintButton( QPainter *p, int i ) { |
385 | if ( audioButtons[i].isDown ) { | 385 | if ( audioButtons[i].isDown ) { |
386 | p->drawPixmap( xoff, yoff, *buttonPixDown[i] ); | 386 | p->drawPixmap( xoff, yoff, *buttonPixDown[i] ); |
387 | } else { | 387 | } else { |
388 | p->drawPixmap( xoff, yoff, *buttonPixUp[i] ); | 388 | p->drawPixmap( xoff, yoff, *buttonPixUp[i] ); |
389 | } | 389 | } |
390 | } | 390 | } |
391 | 391 | ||
392 | 392 | ||
393 | void AudioWidget::skipFor() { | 393 | void AudioWidget::skipFor() { |
394 | skipDirection = +1; | 394 | skipDirection = +1; |
395 | startTimer( 50 ); | 395 | startTimer( 50 ); |
396 | mediaPlayerState->setPosition( mediaPlayerState->position() + 2 ); | 396 | mediaPlayerState->setPosition( mediaPlayerState->position() + 2 ); |
397 | } | 397 | } |
398 | 398 | ||
399 | void AudioWidget::skipBack() { | 399 | void AudioWidget::skipBack() { |
400 | skipDirection = -1; | 400 | skipDirection = -1; |
401 | startTimer( 50 ); | 401 | startTimer( 50 ); |
402 | mediaPlayerState->setPosition( mediaPlayerState->position() - 2 ); | 402 | mediaPlayerState->setPosition( mediaPlayerState->position() - 2 ); |
403 | } | 403 | } |
404 | 404 | ||
405 | 405 | ||
406 | 406 | ||
407 | void AudioWidget::stopSkip() { | 407 | void AudioWidget::stopSkip() { |
408 | killTimers(); | 408 | killTimers(); |
409 | } | 409 | } |
410 | 410 | ||
411 | 411 | ||
412 | void AudioWidget::timerEvent( QTimerEvent * ) { | 412 | void AudioWidget::timerEvent( QTimerEvent * ) { |
413 | if ( skipDirection == +1 ) { | 413 | if ( skipDirection == +1 ) { |
414 | mediaPlayerState->setPosition( mediaPlayerState->position() + 2 ); | 414 | mediaPlayerState->setPosition( mediaPlayerState->position() + 2 ); |
415 | } else if ( skipDirection == -1 ) { | 415 | } else if ( skipDirection == -1 ) { |
416 | mediaPlayerState->setPosition( mediaPlayerState->position() - 2 ); | 416 | mediaPlayerState->setPosition( mediaPlayerState->position() - 2 ); |
417 | } | 417 | } |
418 | } | 418 | } |
419 | 419 | ||
420 | 420 | ||
421 | void AudioWidget::mouseMoveEvent( QMouseEvent *event ) { | 421 | void AudioWidget::mouseMoveEvent( QMouseEvent *event ) { |
422 | for ( int i = 0; i < numButtons; i++ ) { | 422 | for ( int i = 0; i < numButtons; i++ ) { |
423 | if ( event->state() == QMouseEvent::LeftButton ) { | 423 | if ( event->state() == QMouseEvent::LeftButton ) { |
424 | // The test to see if the mouse click is inside the button or not | 424 | // The test to see if the mouse click is inside the button or not |
425 | int x = event->pos().x() - xoff; | 425 | int x = event->pos().x() - xoff; |
426 | int y = event->pos().y() - yoff; | 426 | int y = event->pos().y() - yoff; |
427 | 427 | ||
428 | bool isOnButton = ( x > 0 && y > 0 && x < imgButtonMask->width() | 428 | bool isOnButton = ( x > 0 && y > 0 && x < imgButtonMask->width() |
429 | && y < imgButtonMask->height() | 429 | && y < imgButtonMask->height() |
430 | && imgButtonMask->pixelIndex( x, y ) == i + 1 ); | 430 | && imgButtonMask->pixelIndex( x, y ) == i + 1 ); |
431 | 431 | ||
432 | if ( isOnButton && !audioButtons[i].isHeld ) { | 432 | if ( isOnButton && !audioButtons[i].isHeld ) { |
433 | audioButtons[i].isHeld = TRUE; | 433 | audioButtons[i].isHeld = TRUE; |
434 | toggleButton(i); | 434 | toggleButton(i); |
435 | switch (i) { | 435 | switch (i) { |
436 | case AudioVolumeUp: | 436 | case AudioVolumeUp: |
437 | emit moreClicked(); | 437 | emit moreClicked(); |
438 | return; | 438 | return; |
439 | case AudioVolumeDown: | 439 | case AudioVolumeDown: |
440 | emit lessClicked(); | 440 | emit lessClicked(); |
441 | return; | 441 | return; |
442 | case AudioForward: | 442 | case AudioForward: |
443 | emit forwardClicked(); | 443 | emit forwardClicked(); |
444 | return; | 444 | return; |
445 | case AudioBack: | 445 | case AudioBack: |
446 | emit backClicked(); | 446 | emit backClicked(); |
447 | return; | 447 | return; |
448 | } | 448 | } |
449 | } else if ( !isOnButton && audioButtons[i].isHeld ) { | 449 | } else if ( !isOnButton && audioButtons[i].isHeld ) { |
450 | audioButtons[i].isHeld = FALSE; | 450 | audioButtons[i].isHeld = FALSE; |