-rw-r--r-- | core/multimedia/opieplayer/audiowidget.cpp | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/core/multimedia/opieplayer/audiowidget.cpp b/core/multimedia/opieplayer/audiowidget.cpp index b9561d5..e2e3603 100644 --- a/core/multimedia/opieplayer/audiowidget.cpp +++ b/core/multimedia/opieplayer/audiowidget.cpp | |||
@@ -48,146 +48,152 @@ MediaButton audioButtons[] = { | |||
48 | { 3*30-15+xo, 3*30-13+yo, 0, TRUE, TRUE, FALSE, FALSE }, // play | 48 | { 3*30-15+xo, 3*30-13+yo, 0, TRUE, TRUE, FALSE, FALSE }, // play |
49 | { 1*30+xo, 5*30+yo, 2, FALSE, FALSE, FALSE, FALSE }, // stop | 49 | { 1*30+xo, 5*30+yo, 2, FALSE, FALSE, FALSE, FALSE }, // stop |
50 | { 5*30+xo, 5*30+yo, 2, TRUE, FALSE, FALSE, FALSE }, // pause | 50 | { 5*30+xo, 5*30+yo, 2, TRUE, FALSE, FALSE, FALSE }, // pause |
51 | { 6*30-5+xo, 3*30+yo, 1, FALSE, FALSE, FALSE, FALSE }, // next | 51 | { 6*30-5+xo, 3*30+yo, 1, FALSE, FALSE, FALSE, FALSE }, // next |
52 | { 0*30+5+xo, 3*30+yo, 1, FALSE, FALSE, FALSE, FALSE }, // previous | 52 | { 0*30+5+xo, 3*30+yo, 1, FALSE, FALSE, FALSE, FALSE }, // previous |
53 | { 3*30+xo, 0*30+5+yo, 3, FALSE, FALSE, FALSE, FALSE }, // volume up | 53 | { 3*30+xo, 0*30+5+yo, 3, FALSE, FALSE, FALSE, FALSE }, // volume up |
54 | { 3*30+xo, 6*30-5+yo, 3, FALSE, FALSE, FALSE, FALSE }, // volume down | 54 | { 3*30+xo, 6*30-5+yo, 3, FALSE, FALSE, FALSE, FALSE }, // volume down |
55 | { 5*30+xo, 1*30+yo, 0, TRUE, FALSE, FALSE, FALSE }, // repeat/loop | 55 | { 5*30+xo, 1*30+yo, 0, TRUE, FALSE, FALSE, FALSE }, // repeat/loop |
56 | { 1*30+xo, 1*30+yo, 0, FALSE, FALSE, FALSE, FALSE } // playlist | 56 | { 1*30+xo, 1*30+yo, 0, FALSE, FALSE, FALSE, FALSE } // playlist |
57 | }; | 57 | }; |
58 | 58 | ||
59 | 59 | ||
60 | static const int numButtons = (sizeof(audioButtons)/sizeof(MediaButton)); | 60 | static const int numButtons = (sizeof(audioButtons)/sizeof(MediaButton)); |
61 | 61 | ||
62 | 62 | ||
63 | AudioWidget::AudioWidget(QWidget* parent, const char* name, WFlags f) : | 63 | AudioWidget::AudioWidget(QWidget* parent, const char* name, WFlags f) : |
64 | QWidget( parent, name, f ) | 64 | QWidget( parent, name, f ) |
65 | { | 65 | { |
66 | // QPEApplication::grabKeyboard(); | 66 | // QPEApplication::grabKeyboard(); |
67 | setCaption( tr("OpiePlayer") ); | 67 | setCaption( tr("OpiePlayer") ); |
68 | setBackgroundPixmap( Resource::loadPixmap( "opieplayer/metalFinish" ) ); | 68 | setBackgroundPixmap( Resource::loadPixmap( "opieplayer/metalFinish" ) ); |
69 | pixmaps[0] = new QPixmap( Resource::loadPixmap( "opieplayer/mediaButtonsAll" ) ); | 69 | pixmaps[0] = new QPixmap( Resource::loadPixmap( "opieplayer/mediaButtonsAll" ) ); |
70 | pixmaps[1] = new QPixmap( Resource::loadPixmap( "opieplayer/mediaButtonsBig" ) ); | 70 | pixmaps[1] = new QPixmap( Resource::loadPixmap( "opieplayer/mediaButtonsBig" ) ); |
71 | pixmaps[2] = new QPixmap( Resource::loadPixmap( "opieplayer/mediaControls" ) ); | 71 | pixmaps[2] = new QPixmap( Resource::loadPixmap( "opieplayer/mediaControls" ) ); |
72 | pixmaps[3] = new QPixmap( Resource::loadPixmap( "opieplayer/animatedButton" ) ); | 72 | pixmaps[3] = new QPixmap( Resource::loadPixmap( "opieplayer/animatedButton" ) ); |
73 | 73 | ||
74 | songInfo = new Ticker( this ); | 74 | songInfo = new Ticker( this ); |
75 | songInfo->setFocusPolicy( QWidget::NoFocus ); | 75 | songInfo->setFocusPolicy( QWidget::NoFocus ); |
76 | songInfo->setGeometry( QRect( 7, 3, 220, 20 ) ); | 76 | songInfo->setGeometry( QRect( 7, 3, 220, 20 ) ); |
77 | 77 | ||
78 | slider = new QSlider( Qt::Horizontal, this ); | 78 | slider = new QSlider( Qt::Horizontal, this ); |
79 | slider->setFixedWidth( 220 ); | 79 | slider->setFixedWidth( 220 ); |
80 | slider->setFixedHeight( 20 ); | 80 | slider->setFixedHeight( 20 ); |
81 | slider->setMinValue( 0 ); | 81 | slider->setMinValue( 0 ); |
82 | slider->setMaxValue( 1 ); | 82 | slider->setMaxValue( 1 ); |
83 | slider->setBackgroundPixmap( Resource::loadPixmap( "opieplayer/metalFinish" ) ); | 83 | slider->setBackgroundPixmap( Resource::loadPixmap( "opieplayer/metalFinish" ) ); |
84 | slider->setFocusPolicy( QWidget::NoFocus ); | 84 | slider->setFocusPolicy( QWidget::NoFocus ); |
85 | slider->setGeometry( QRect( 7, 262, 220, 20 ) ); | 85 | slider->setGeometry( QRect( 7, 262, 220, 20 ) ); |
86 | 86 | ||
87 | connect( slider, SIGNAL( sliderPressed() ), this, SLOT( sliderPressed() ) ); | 87 | connect( slider, SIGNAL( sliderPressed() ), this, SLOT( sliderPressed() ) ); |
88 | connect( slider, SIGNAL( sliderReleased() ), this, SLOT( sliderReleased() ) ); | 88 | connect( slider, SIGNAL( sliderReleased() ), this, SLOT( sliderReleased() ) ); |
89 | 89 | ||
90 | connect( mediaPlayerState, SIGNAL( lengthChanged(long) ), this, SLOT( setLength(long) ) ); | 90 | connect( mediaPlayerState, SIGNAL( lengthChanged(long) ), this, SLOT( setLength(long) ) ); |
91 | connect( mediaPlayerState, SIGNAL( viewChanged(char) ), this, SLOT( setView(char) ) ); | 91 | connect( mediaPlayerState, SIGNAL( viewChanged(char) ), this, SLOT( setView(char) ) ); |
92 | connect( mediaPlayerState, SIGNAL( loopingToggled(bool) ), this, SLOT( setLooping(bool) ) ); | 92 | connect( mediaPlayerState, SIGNAL( loopingToggled(bool) ), this, SLOT( setLooping(bool) ) ); |
93 | connect( mediaPlayerState, SIGNAL( pausedToggled(bool) ), this, SLOT( setPaused(bool) ) ); | 93 | connect( mediaPlayerState, SIGNAL( pausedToggled(bool) ), this, SLOT( setPaused(bool) ) ); |
94 | connect( mediaPlayerState, SIGNAL( playingToggled(bool) ), this, SLOT( setPlaying(bool) ) ); | 94 | connect( mediaPlayerState, SIGNAL( playingToggled(bool) ), this, SLOT( setPlaying(bool) ) ); |
95 | 95 | ||
96 | if( !mediaPlayerState->isStreaming) { // this stops the slider from being moved, thus | ||
97 | // does not stop stream when it reaches the end | ||
98 | connect( mediaPlayerState, SIGNAL( positionChanged(long) ),this, SLOT( setPosition(long) ) ); | ||
99 | connect( mediaPlayerState, SIGNAL( positionUpdated(long) ),this, SLOT( setPosition(long) ) ); | ||
100 | } | ||
101 | // Intialise state | 96 | // Intialise state |
102 | setLength( mediaPlayerState->length() ); | 97 | setLength( mediaPlayerState->length() ); |
103 | setPosition( mediaPlayerState->position() ); | 98 | setPosition( mediaPlayerState->position() ); |
104 | setLooping( mediaPlayerState->fullscreen() ); | 99 | setLooping( mediaPlayerState->fullscreen() ); |
105 | setPaused( mediaPlayerState->paused() ); | 100 | setPaused( mediaPlayerState->paused() ); |
106 | setPlaying( mediaPlayerState->playing() ); | 101 | setPlaying( mediaPlayerState->playing() ); |
107 | if (mediaPlayerState->isStreaming) slider->hide(); | ||
108 | 102 | ||
109 | } | 103 | } |
110 | 104 | ||
111 | 105 | ||
112 | AudioWidget::~AudioWidget() { | 106 | AudioWidget::~AudioWidget() { |
113 | for ( int i = 0; i < 4; i++ ) | 107 | for ( int i = 0; i < 4; i++ ) |
114 | delete pixmaps[i]; | 108 | delete pixmaps[i]; |
115 | } | 109 | } |
116 | 110 | ||
117 | 111 | ||
118 | static bool audioSliderBeingMoved = FALSE; | 112 | static bool audioSliderBeingMoved = FALSE; |
119 | 113 | ||
120 | 114 | ||
121 | void AudioWidget::sliderPressed() { | 115 | void AudioWidget::sliderPressed() { |
122 | audioSliderBeingMoved = TRUE; | 116 | audioSliderBeingMoved = TRUE; |
123 | } | 117 | } |
124 | 118 | ||
125 | 119 | ||
126 | void AudioWidget::sliderReleased() { | 120 | void AudioWidget::sliderReleased() { |
127 | audioSliderBeingMoved = FALSE; | 121 | audioSliderBeingMoved = FALSE; |
128 | if ( slider->width() == 0 ) | 122 | if ( slider->width() == 0 ) |
129 | return; | 123 | return; |
130 | long val = long((double)slider->value() * mediaPlayerState->length() / slider->width()); | 124 | long val = long((double)slider->value() * mediaPlayerState->length() / slider->width()); |
131 | mediaPlayerState->setPosition( val ); | 125 | mediaPlayerState->setPosition( val ); |
132 | } | 126 | } |
133 | 127 | ||
134 | 128 | ||
135 | void AudioWidget::setPosition( long i ) { | 129 | void AudioWidget::setPosition( long i ) { |
136 | updateSlider( i, mediaPlayerState->length() ); | 130 | updateSlider( i, mediaPlayerState->length() ); |
137 | } | 131 | } |
138 | 132 | ||
139 | 133 | ||
140 | void AudioWidget::setLength( long max ) { | 134 | void AudioWidget::setLength( long max ) { |
141 | updateSlider( mediaPlayerState->position(), max ); | 135 | updateSlider( mediaPlayerState->position(), max ); |
142 | } | 136 | } |
143 | 137 | ||
144 | 138 | ||
145 | void AudioWidget::setView( char view ) { | 139 | void AudioWidget::setView( char view ) { |
140 | if (mediaPlayerState->isStreaming) { | ||
141 | if( !slider->isHidden()) slider->hide(); | ||
142 | disconnect( mediaPlayerState, SIGNAL( positionChanged(long) ),this, SLOT( setPosition(long) ) ); | ||
143 | disconnect( mediaPlayerState, SIGNAL( positionUpdated(long) ),this, SLOT( setPosition(long) ) ); | ||
144 | } else { | ||
145 | // this stops the slider from being moved, thus | ||
146 | // does not stop stream when it reaches the end | ||
147 | if( slider->isHidden()) slider->show(); | ||
148 | connect( mediaPlayerState, SIGNAL( positionChanged(long) ),this, SLOT( setPosition(long) ) ); | ||
149 | connect( mediaPlayerState, SIGNAL( positionUpdated(long) ),this, SLOT( setPosition(long) ) ); | ||
150 | } | ||
151 | |||
146 | if ( view == 'a' ) { | 152 | if ( view == 'a' ) { |
147 | startTimer( 150 ); | 153 | startTimer( 150 ); |
148 | showMaximized(); | 154 | showMaximized(); |
149 | } else { | 155 | } else { |
150 | killTimers(); | 156 | killTimers(); |
151 | hide(); | 157 | hide(); |
152 | } | 158 | } |
153 | } | 159 | } |
154 | 160 | ||
155 | 161 | ||
156 | void AudioWidget::updateSlider( long i, long max ) { | 162 | void AudioWidget::updateSlider( long i, long max ) { |
157 | if ( max == 0 ) | 163 | if ( max == 0 ) |
158 | return; | 164 | return; |
159 | // Will flicker too much if we don't do this | 165 | // Will flicker too much if we don't do this |
160 | // Scale to something reasonable | 166 | // Scale to something reasonable |
161 | int width = slider->width(); | 167 | int width = slider->width(); |
162 | int val = int((double)i * width / max); | 168 | int val = int((double)i * width / max); |
163 | if ( !audioSliderBeingMoved ) { | 169 | if ( !audioSliderBeingMoved ) { |
164 | if ( slider->value() != val ) | 170 | if ( slider->value() != val ) |
165 | slider->setValue( val ); | 171 | slider->setValue( val ); |
166 | if ( slider->maxValue() != width ) | 172 | if ( slider->maxValue() != width ) |
167 | slider->setMaxValue( width ); | 173 | slider->setMaxValue( width ); |
168 | } | 174 | } |
169 | } | 175 | } |
170 | 176 | ||
171 | 177 | ||
172 | void AudioWidget::setToggleButton( int i, bool down ) { | 178 | void AudioWidget::setToggleButton( int i, bool down ) { |
173 | if ( down != audioButtons[i].isDown ) | 179 | if ( down != audioButtons[i].isDown ) |
174 | toggleButton( i ); | 180 | toggleButton( i ); |
175 | } | 181 | } |
176 | 182 | ||
177 | 183 | ||
178 | void AudioWidget::toggleButton( int i ) { | 184 | void AudioWidget::toggleButton( int i ) { |
179 | audioButtons[i].isDown = !audioButtons[i].isDown; | 185 | audioButtons[i].isDown = !audioButtons[i].isDown; |
180 | QPainter p(this); | 186 | QPainter p(this); |
181 | paintButton ( &p, i ); | 187 | paintButton ( &p, i ); |
182 | } | 188 | } |
183 | 189 | ||
184 | 190 | ||
185 | void AudioWidget::paintButton( QPainter *p, int i ) { | 191 | void AudioWidget::paintButton( QPainter *p, int i ) { |
186 | int x = audioButtons[i].xPos; | 192 | int x = audioButtons[i].xPos; |
187 | int y = audioButtons[i].yPos; | 193 | int y = audioButtons[i].yPos; |
188 | int offset = 22 + 14 * audioButtons[i].isBig + audioButtons[i].isDown; | 194 | int offset = 22 + 14 * audioButtons[i].isBig + audioButtons[i].isDown; |
189 | int buttonSize = 64 + audioButtons[i].isBig * (90 - 64); | 195 | int buttonSize = 64 + audioButtons[i].isBig * (90 - 64); |
190 | p->drawPixmap( x, y, *pixmaps[audioButtons[i].isBig], buttonSize * (audioButtons[i].isDown + 2 * audioButtons[i].color), 0, buttonSize, buttonSize ); | 196 | p->drawPixmap( x, y, *pixmaps[audioButtons[i].isBig], buttonSize * (audioButtons[i].isDown + 2 * audioButtons[i].color), 0, buttonSize, buttonSize ); |
191 | p->drawPixmap( x + offset, y + offset, *pixmaps[2], 18 * i, 0, 18, 18 ); | 197 | p->drawPixmap( x + offset, y + offset, *pixmaps[2], 18 * i, 0, 18, 18 ); |
192 | } | 198 | } |
193 | 199 | ||