summaryrefslogtreecommitdiff
path: root/noncore/multimedia/opieplayer2/audiowidget.cpp
Unidiff
Diffstat (limited to 'noncore/multimedia/opieplayer2/audiowidget.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/multimedia/opieplayer2/audiowidget.cpp10
1 files changed, 1 insertions, 9 deletions
diff --git a/noncore/multimedia/opieplayer2/audiowidget.cpp b/noncore/multimedia/opieplayer2/audiowidget.cpp
index 1b0de5d..125fd72 100644
--- a/noncore/multimedia/opieplayer2/audiowidget.cpp
+++ b/noncore/multimedia/opieplayer2/audiowidget.cpp
@@ -1,255 +1,247 @@
1 1
2#include <qpe/qpeapplication.h> 2#include <qpe/qpeapplication.h>
3#include <qpe/resource.h> 3#include <qpe/resource.h>
4#include <qpe/config.h> 4#include <qpe/config.h>
5 5
6#include <qwidget.h> 6#include <qwidget.h>
7#include <qpixmap.h> 7#include <qpixmap.h>
8#include <qbutton.h> 8#include <qbutton.h>
9#include <qpainter.h> 9#include <qpainter.h>
10#include <qframe.h> 10#include <qframe.h>
11#include <qlayout.h> 11#include <qlayout.h>
12 12
13#include "audiowidget.h" 13#include "audiowidget.h"
14#include "mediaplayerstate.h" 14#include "mediaplayerstate.h"
15 15
16extern MediaPlayerState *mediaPlayerState; 16extern MediaPlayerState *mediaPlayerState;
17 17
18static const int xo = -2; // movable x offset 18static const int xo = -2; // movable x offset
19static const int yo = 22; // movable y offset 19static const int yo = 22; // movable y offset
20 20
21 21
22Ticker::Ticker( QWidget* parent=0 ) : QFrame( parent ) { 22Ticker::Ticker( QWidget* parent=0 ) : QFrame( parent ) {
23 setFrameStyle( WinPanel | Sunken ); 23 setFrameStyle( WinPanel | Sunken );
24 setText( "No Song" ); 24 setText( "No Song" );
25} 25}
26 26
27Ticker::~Ticker() { 27Ticker::~Ticker() {
28} 28}
29 29
30void Ticker::setText( const QString& text ) { 30void Ticker::setText( const QString& text ) {
31 pos = 0; // reset it everytime the text is changed 31 pos = 0; // reset it everytime the text is changed
32 scrollText = text; 32 scrollText = text;
33 pixelLen = fontMetrics().width( scrollText ); 33 pixelLen = fontMetrics().width( scrollText );
34 killTimers(); 34 killTimers();
35 if ( pixelLen > width() ) { 35 if ( pixelLen > width() ) {
36 startTimer( 50 ); 36 startTimer( 50 );
37 } 37 }
38 update(); 38 update();
39} 39}
40 40
41 41
42void Ticker::timerEvent( QTimerEvent * ) { 42void Ticker::timerEvent( QTimerEvent * ) {
43 pos = ( pos + 1 > pixelLen ) ? 0 : pos + 1; 43 pos = ( pos + 1 > pixelLen ) ? 0 : pos + 1;
44 repaint( FALSE ); 44 repaint( FALSE );
45} 45}
46 46
47void Ticker::drawContents( QPainter *p ) { 47void Ticker::drawContents( QPainter *p ) {
48 QPixmap pm( width(), height() ); 48 QPixmap pm( width(), height() );
49 pm.fill( colorGroup().base() ); 49 pm.fill( colorGroup().base() );
50 QPainter pmp( &pm ); 50 QPainter pmp( &pm );
51 for ( int i = 0; i - pos < width() && (i < 1 || pixelLen > width()); i += pixelLen ) { 51 for ( int i = 0; i - pos < width() && (i < 1 || pixelLen > width()); i += pixelLen ) {
52 pmp.drawText( i - pos, 0, INT_MAX, height(), AlignVCenter, scrollText ); 52 pmp.drawText( i - pos, 0, INT_MAX, height(), AlignVCenter, scrollText );
53 } 53 }
54 p->drawPixmap( 0, 0, pm ); 54 p->drawPixmap( 0, 0, pm );
55} 55}
56 56
57 57
58
59
60struct MediaButton { 58struct MediaButton {
61 int xPos, yPos; 59 int xPos, yPos;
62 int color; 60 int color;
63 bool isToggle, isBig, isHeld, isDown; 61 bool isToggle, isBig, isHeld, isDown;
64}; 62};
65 63
66 64
67
68
69// Layout information for the audioButtons (and if it is a toggle button or not) 65// Layout information for the audioButtons (and if it is a toggle button or not)
70MediaButton audioButtons[] = { 66MediaButton audioButtons[] = {
71 { 3*30-15+xo, 3*30-13+yo, 0, TRUE, TRUE, FALSE, FALSE }, // play 67 { 3*30-15+xo, 3*30-13+yo, 0, TRUE, TRUE, FALSE, FALSE }, // play
72 { 1*30+xo, 5*30+yo, 2, FALSE, FALSE, FALSE, FALSE }, // stop 68 { 1*30+xo, 5*30+yo, 2, FALSE, FALSE, FALSE, FALSE }, // stop
73 { 5*30+xo, 5*30+yo, 2, TRUE, FALSE, FALSE, FALSE }, // pause 69 { 5*30+xo, 5*30+yo, 2, TRUE, FALSE, FALSE, FALSE }, // pause
74 { 6*30-5+xo, 3*30+yo, 1, FALSE, FALSE, FALSE, FALSE }, // next 70 { 6*30-5+xo, 3*30+yo, 1, FALSE, FALSE, FALSE, FALSE }, // next
75 { 0*30+5+xo, 3*30+yo, 1, FALSE, FALSE, FALSE, FALSE }, // previous 71 { 0*30+5+xo, 3*30+yo, 1, FALSE, FALSE, FALSE, FALSE }, // previous
76 { 3*30+xo, 0*30+5+yo, 3, FALSE, FALSE, FALSE, FALSE }, // volume up 72 { 3*30+xo, 0*30+5+yo, 3, FALSE, FALSE, FALSE, FALSE }, // volume up
77 { 3*30+xo, 6*30-5+yo, 3, FALSE, FALSE, FALSE, FALSE }, // volume down 73 { 3*30+xo, 6*30-5+yo, 3, FALSE, FALSE, FALSE, FALSE }, // volume down
78 { 5*30+xo, 1*30+yo, 0, TRUE, FALSE, FALSE, FALSE }, // repeat/loop 74 { 5*30+xo, 1*30+yo, 0, TRUE, FALSE, FALSE, FALSE }, // repeat/loop
79 { 1*30+xo, 1*30+yo, 0, FALSE, FALSE, FALSE, FALSE } // playlist 75 { 1*30+xo, 1*30+yo, 0, FALSE, FALSE, FALSE, FALSE } // playlist
80}; 76};
81 77
82static const int numButtons = (sizeof(audioButtons)/sizeof(MediaButton)); 78static const int numButtons = (sizeof(audioButtons)/sizeof(MediaButton));
83 79
84 80
85AudioWidget::AudioWidget(QWidget* parent, const char* name, WFlags f) : 81AudioWidget::AudioWidget(QWidget* parent, const char* name, WFlags f) :
86 QWidget( parent, name, f ) 82 QWidget( parent, name, f ) {
87{
88 setCaption( tr("OpiePlayer - Audio") ); 83 setCaption( tr("OpiePlayer - Audio") );
89 Config cfg("OpiePlayer"); 84 Config cfg("OpiePlayer");
90 cfg.setGroup("AudioWidget"); 85 cfg.setGroup("AudioWidget");
91 86
92 QString backgroundPix, buttonsAllPix, buttonsBigPix, controlsPix, animatedPix; 87 QString backgroundPix, buttonsAllPix, buttonsBigPix, controlsPix, animatedPix;
93 backgroundPix=cfg.readEntry( " backgroundPix", "opieplayer/metalFinish"); 88 backgroundPix=cfg.readEntry( " backgroundPix", "opieplayer/metalFinish");
94 buttonsAllPix=cfg.readEntry( "buttonsAllPix","opieplayer/mediaButtonsAll"); 89 buttonsAllPix=cfg.readEntry( "buttonsAllPix","opieplayer/mediaButtonsAll");
95 buttonsBigPix=cfg.readEntry( "buttonsBigPix","opieplayer/mediaButtonsBig"); 90 buttonsBigPix=cfg.readEntry( "buttonsBigPix","opieplayer/mediaButtonsBig");
96 controlsPix=cfg.readEntry( "controlsPix","opieplayer/mediaControls"); 91 controlsPix=cfg.readEntry( "controlsPix","opieplayer/mediaControls");
97 92
98 setBackgroundPixmap( Resource::loadPixmap( backgroundPix) ); 93 setBackgroundPixmap( Resource::loadPixmap( backgroundPix) );
99 pixmaps[0] = new QPixmap( Resource::loadPixmap( buttonsAllPix ) ); 94 pixmaps[0] = new QPixmap( Resource::loadPixmap( buttonsAllPix ) );
100 pixmaps[1] = new QPixmap( Resource::loadPixmap( buttonsBigPix ) ); 95 pixmaps[1] = new QPixmap( Resource::loadPixmap( buttonsBigPix ) );
101 pixmaps[2] = new QPixmap( Resource::loadPixmap( controlsPix ) ); 96 pixmaps[2] = new QPixmap( Resource::loadPixmap( controlsPix ) );
102 97
103 songInfo = new Ticker( this ); 98 songInfo = new Ticker( this );
104 songInfo->setFocusPolicy( QWidget::NoFocus ); 99 songInfo->setFocusPolicy( QWidget::NoFocus );
105 songInfo->setGeometry( QRect( 7, 3, 220, 20 ) ); 100 songInfo->setGeometry( QRect( 7, 3, 220, 20 ) );
106 101
107 slider = new QSlider( Qt::Horizontal, this ); 102 slider = new QSlider( Qt::Horizontal, this );
108 slider->setFixedWidth( 220 ); 103 slider->setFixedWidth( 220 );
109 slider->setFixedHeight( 20 ); 104 slider->setFixedHeight( 20 );
110 slider->setMinValue( 0 ); 105 slider->setMinValue( 0 );
111 slider->setMaxValue( 1 ); 106 slider->setMaxValue( 1 );
112 slider->setBackgroundPixmap( Resource::loadPixmap( backgroundPix ) ); 107 slider->setBackgroundPixmap( Resource::loadPixmap( backgroundPix ) );
113 slider->setFocusPolicy( QWidget::NoFocus ); 108 slider->setFocusPolicy( QWidget::NoFocus );
114 slider->setGeometry( QRect( 7, 262, 220, 20 ) ); 109 slider->setGeometry( QRect( 7, 262, 220, 20 ) );
115 110
116 connect( slider, SIGNAL( sliderPressed() ), this, SLOT( sliderPressed() ) ); 111 connect( slider, SIGNAL( sliderPressed() ), this, SLOT( sliderPressed() ) );
117 connect( slider, SIGNAL( sliderReleased() ), this, SLOT( sliderReleased() ) ); 112 connect( slider, SIGNAL( sliderReleased() ), this, SLOT( sliderReleased() ) );
118 connect( mediaPlayerState, SIGNAL( lengthChanged(long) ), this, SLOT( setLength(long) ) ); 113 connect( mediaPlayerState, SIGNAL( lengthChanged(long) ), this, SLOT( setLength(long) ) );
119 connect( mediaPlayerState, SIGNAL( viewChanged(char) ), this, SLOT( setView(char) ) ); 114 connect( mediaPlayerState, SIGNAL( viewChanged(char) ), this, SLOT( setView(char) ) );
120 connect( mediaPlayerState, SIGNAL( loopingToggled(bool) ), this, SLOT( setLooping(bool) ) ); 115 connect( mediaPlayerState, SIGNAL( loopingToggled(bool) ), this, SLOT( setLooping(bool) ) );
121 connect( mediaPlayerState, SIGNAL( pausedToggled(bool) ), this, SLOT( setPaused(bool) ) ); 116 connect( mediaPlayerState, SIGNAL( pausedToggled(bool) ), this, SLOT( setPaused(bool) ) );
122 connect( mediaPlayerState, SIGNAL( playingToggled(bool) ), this, SLOT( setPlaying(bool) ) ); 117 connect( mediaPlayerState, SIGNAL( playingToggled(bool) ), this, SLOT( setPlaying(bool) ) );
123 118
124 // Intialise state 119 // Intialise state
125 setLength( mediaPlayerState->length() ); 120 setLength( mediaPlayerState->length() );
126 setPosition( mediaPlayerState->position() ); 121 setPosition( mediaPlayerState->position() );
127 setLooping( mediaPlayerState->fullscreen() ); 122 setLooping( mediaPlayerState->fullscreen() );
128 setPaused( mediaPlayerState->paused() ); 123 setPaused( mediaPlayerState->paused() );
129 setPlaying( mediaPlayerState->playing() ); 124 setPlaying( mediaPlayerState->playing() );
130
131} 125}
132 126
133
134AudioWidget::~AudioWidget() { 127AudioWidget::~AudioWidget() {
135 mediaPlayerState->isStreaming = FALSE; 128 mediaPlayerState->isStreaming = FALSE;
136 for ( int i = 0; i < 3; i++ ) { 129 for ( int i = 0; i < 3; i++ ) {
137 delete pixmaps[i]; 130 delete pixmaps[i];
138 } 131 }
139} 132}
140 133
141 134
142static bool audioSliderBeingMoved = FALSE; 135static bool audioSliderBeingMoved = FALSE;
143 136
144 137
145void AudioWidget::sliderPressed() { 138void AudioWidget::sliderPressed() {
146 audioSliderBeingMoved = TRUE; 139 audioSliderBeingMoved = TRUE;
147} 140}
148 141
149 142
150void AudioWidget::sliderReleased() { 143void AudioWidget::sliderReleased() {
151 audioSliderBeingMoved = FALSE; 144 audioSliderBeingMoved = FALSE;
152 if ( slider->width() == 0 ) { 145 if ( slider->width() == 0 ) {
153 return; 146 return;
154 } 147 }
155 long val = long((double)slider->value() * mediaPlayerState->length() / slider->width()); 148 long val = long((double)slider->value() * mediaPlayerState->length() / slider->width());
156 mediaPlayerState->setPosition( val ); 149 mediaPlayerState->setPosition( val );
157} 150}
158 151
159
160void AudioWidget::setPosition( long i ) { 152void AudioWidget::setPosition( long i ) {
161 // qDebug("set position %d",i); 153 // qDebug("set position %d",i);
162 updateSlider( i, mediaPlayerState->length() ); 154 updateSlider( i, mediaPlayerState->length() );
163} 155}
164 156
165 157
166void AudioWidget::setLength( long max ) { 158void AudioWidget::setLength( long max ) {
167 updateSlider( mediaPlayerState->position(), max ); 159 updateSlider( mediaPlayerState->position(), max );
168} 160}
169 161
170 162
171void AudioWidget::setView( char view ) { 163void AudioWidget::setView( char view ) {
172 if (mediaPlayerState->isStreaming) { 164 if (mediaPlayerState->isStreaming) {
173 if( !slider->isHidden()) slider->hide(); 165 if( !slider->isHidden()) slider->hide();
174 disconnect( mediaPlayerState, SIGNAL( positionChanged(long) ),this, SLOT( setPosition(long) ) ); 166 disconnect( mediaPlayerState, SIGNAL( positionChanged(long) ),this, SLOT( setPosition(long) ) );
175 disconnect( mediaPlayerState, SIGNAL( positionUpdated(long) ),this, SLOT( setPosition(long) ) ); 167 disconnect( mediaPlayerState, SIGNAL( positionUpdated(long) ),this, SLOT( setPosition(long) ) );
176 } else { 168 } else {
177 // this stops the slider from being moved, thus 169 // this stops the slider from being moved, thus
178 // does not stop stream when it reaches the end 170 // does not stop stream when it reaches the end
179 slider->show(); 171 slider->show();
180 connect( mediaPlayerState, SIGNAL( positionChanged(long) ),this, SLOT( setPosition(long) ) ); 172 connect( mediaPlayerState, SIGNAL( positionChanged(long) ),this, SLOT( setPosition(long) ) );
181 connect( mediaPlayerState, SIGNAL( positionUpdated(long) ),this, SLOT( setPosition(long) ) ); 173 connect( mediaPlayerState, SIGNAL( positionUpdated(long) ),this, SLOT( setPosition(long) ) );
182 } 174 }
183 175
184 if ( view == 'a' ) { 176 if ( view == 'a' ) {
185 startTimer( 150 ); 177 startTimer( 150 );
186 showMaximized(); 178 showMaximized();
187 } else { 179 } else {
188 killTimers(); 180 killTimers();
189 hide(); 181 hide();
190 } 182 }
191} 183}
192 184
193 185
194void AudioWidget::updateSlider( long i, long max ) { 186void AudioWidget::updateSlider( long i, long max ) {
195 if ( max == 0 ) { 187 if ( max == 0 ) {
196 return; 188 return;
197 } 189 }
198 // Will flicker too much if we don't do this 190 // Will flicker too much if we don't do this
199 // Scale to something reasonable 191 // Scale to something reasonable
200 int width = slider->width(); 192 int width = slider->width();
201 int val = int((double)i * width / max); 193 int val = int((double)i * width / max);
202 if ( !audioSliderBeingMoved ) { 194 if ( !audioSliderBeingMoved ) {
203 if ( slider->value() != val ) { 195 if ( slider->value() != val ) {
204 slider->setValue( val ); 196 slider->setValue( val );
205 } 197 }
206 198
207 if ( slider->maxValue() != width ) { 199 if ( slider->maxValue() != width ) {
208 slider->setMaxValue( width ); 200 slider->setMaxValue( width );
209 } 201 }
210 } 202 }
211} 203}
212 204
213 205
214void AudioWidget::setToggleButton( int i, bool down ) { 206void AudioWidget::setToggleButton( int i, bool down ) {
215 if ( down != audioButtons[i].isDown ) { 207 if ( down != audioButtons[i].isDown ) {
216 toggleButton( i ); 208 toggleButton( i );
217 } 209 }
218} 210}
219 211
220 212
221void AudioWidget::toggleButton( int i ) { 213void AudioWidget::toggleButton( int i ) {
222 audioButtons[i].isDown = !audioButtons[i].isDown; 214 audioButtons[i].isDown = !audioButtons[i].isDown;
223 QPainter p(this); 215 QPainter p(this);
224 paintButton ( &p, i ); 216 paintButton ( &p, i );
225} 217}
226 218
227 219
228void AudioWidget::paintButton( QPainter *p, int i ) { 220void AudioWidget::paintButton( QPainter *p, int i ) {
229 int x = audioButtons[i].xPos; 221 int x = audioButtons[i].xPos;
230 int y = audioButtons[i].yPos; 222 int y = audioButtons[i].yPos;
231 int offset = 22 + 14 * audioButtons[i].isBig + audioButtons[i].isDown; 223 int offset = 22 + 14 * audioButtons[i].isBig + audioButtons[i].isDown;
232 int buttonSize = 64 + audioButtons[i].isBig * (90 - 64); 224 int buttonSize = 64 + audioButtons[i].isBig * (90 - 64);
233 p->drawPixmap( x, y, *pixmaps[audioButtons[i].isBig], buttonSize * (audioButtons[i].isDown + 2 * audioButtons[i].color), 0, buttonSize, buttonSize ); 225 p->drawPixmap( x, y, *pixmaps[audioButtons[i].isBig], buttonSize * (audioButtons[i].isDown + 2 * audioButtons[i].color), 0, buttonSize, buttonSize );
234 p->drawPixmap( x + offset, y + offset, *pixmaps[2], 18 * i, 0, 18, 18 ); 226 p->drawPixmap( x + offset, y + offset, *pixmaps[2], 18 * i, 0, 18, 18 );
235} 227}
236 228
237 229
238void AudioWidget::timerEvent( QTimerEvent * ) { 230void AudioWidget::timerEvent( QTimerEvent * ) {
239 static int frame = 0; 231 static int frame = 0;
240 if ( !mediaPlayerState->paused() && audioButtons[ AudioPlay ].isDown ) { 232 if ( !mediaPlayerState->paused() && audioButtons[ AudioPlay ].isDown ) {
241 frame = frame >= 7 ? 0 : frame + 1; 233 frame = frame >= 7 ? 0 : frame + 1;
242 } 234 }
243} 235}
244 236
245 237
246void AudioWidget::mouseMoveEvent( QMouseEvent *event ) { 238void AudioWidget::mouseMoveEvent( QMouseEvent *event ) {
247 for ( int i = 0; i < numButtons; i++ ) { 239 for ( int i = 0; i < numButtons; i++ ) {
248 int size = audioButtons[i].isBig; 240 int size = audioButtons[i].isBig;
249 int x = audioButtons[i].xPos; 241 int x = audioButtons[i].xPos;
250 int y = audioButtons[i].yPos; 242 int y = audioButtons[i].yPos;
251 if ( event->state() == QMouseEvent::LeftButton ) { 243 if ( event->state() == QMouseEvent::LeftButton ) {
252 // The test to see if the mouse click is inside the circular button or not 244 // The test to see if the mouse click is inside the circular button or not
253 // (compared with the radius squared to avoid a square-root of our distance) 245 // (compared with the radius squared to avoid a square-root of our distance)
254 int radius = 32 + 13 * size; 246 int radius = 32 + 13 * size;
255 QPoint center = QPoint( x + radius, y + radius ); 247 QPoint center = QPoint( x + radius, y + radius );