-rw-r--r-- | core/multimedia/opieplayer/audiowidget.cpp | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/core/multimedia/opieplayer/audiowidget.cpp b/core/multimedia/opieplayer/audiowidget.cpp index 376f8d3..d135647 100644 --- a/core/multimedia/opieplayer/audiowidget.cpp +++ b/core/multimedia/opieplayer/audiowidget.cpp | |||
@@ -78,193 +78,195 @@ AudioWidget::AudioWidget(QWidget* parent, const char* name, WFlags f) : | |||
78 | setCaption( tr("OpiePlayer") ); | 78 | setCaption( tr("OpiePlayer") ); |
79 | // odebug << "<<<<<audioWidget" << oendl; | 79 | // odebug << "<<<<<audioWidget" << oendl; |
80 | 80 | ||
81 | Config cfg("OpiePlayer"); | 81 | Config cfg("OpiePlayer"); |
82 | cfg.setGroup("Options"); | 82 | cfg.setGroup("Options"); |
83 | skin = cfg.readEntry("Skin","default"); | 83 | skin = cfg.readEntry("Skin","default"); |
84 | //skin = "scaleTest"; | 84 | //skin = "scaleTest"; |
85 | // color of background, frame, degree of transparency | 85 | // color of background, frame, degree of transparency |
86 | 86 | ||
87 | // QString skinPath = "opieplayer/skins/" + skin; | 87 | // QString skinPath = "opieplayer/skins/" + skin; |
88 | QString skinPath; | 88 | QString skinPath; |
89 | skinPath = "opieplayer2/skins/" + skin; | 89 | skinPath = "opieplayer2/skins/" + skin; |
90 | if(!QDir(QString(getenv("OPIEDIR")) +"/pics/"+skinPath).exists()) | 90 | if(!QDir(QString(getenv("OPIEDIR")) +"/pics/"+skinPath).exists()) |
91 | skinPath = "opieplayer2/skins/default"; | 91 | skinPath = "opieplayer2/skins/default"; |
92 | 92 | ||
93 | // odebug << "skin path " + skinPath << oendl; | 93 | // odebug << "skin path " + skinPath << oendl; |
94 | 94 | ||
95 | pixBg = new QPixmap( Resource::loadPixmap( QString("%1/background").arg(skinPath) ) ); | 95 | pixBg = new QPixmap( Resource::loadPixmap( QString("%1/background").arg(skinPath) ) ); |
96 | imgUp = new QImage( Resource::loadImage( QString("%1/skin_up").arg(skinPath) ) ); | 96 | imgUp = new QImage( Resource::loadImage( QString("%1/skin_up").arg(skinPath) ) ); |
97 | imgDn = new QImage( Resource::loadImage( QString("%1/skin_down").arg(skinPath) ) ); | 97 | imgDn = new QImage( Resource::loadImage( QString("%1/skin_down").arg(skinPath) ) ); |
98 | 98 | ||
99 | imgButtonMask = new QImage( imgUp->width(), imgUp->height(), 8, 255 ); | 99 | imgButtonMask = new QImage( imgUp->width(), imgUp->height(), 8, 255 ); |
100 | imgButtonMask->fill( 0 ); | 100 | imgButtonMask->fill( 0 ); |
101 | 101 | ||
102 | for ( int i = 0; i < 10; i++ ) { | 102 | for ( int i = 0; i < 10; i++ ) { |
103 | QString filename = QString(getenv("OPIEDIR")) + "/pics/" + skinPath + "/skin_mask_" + skin_mask_file_names[i] + ".png"; | 103 | QString filename = QString(getenv("OPIEDIR")) + "/pics/" + skinPath + "/skin_mask_" + skin_mask_file_names[i] + ".png"; |
104 | masks[i] = new QBitmap( filename ); | 104 | masks[i] = new QBitmap( filename ); |
105 | 105 | ||
106 | if ( !masks[i]->isNull() ) { | 106 | if ( !masks[i]->isNull() ) { |
107 | QImage imgMask = masks[i]->convertToImage(); | 107 | QImage imgMask = masks[i]->convertToImage(); |
108 | uchar **dest = imgButtonMask->jumpTable(); | 108 | uchar **dest = imgButtonMask->jumpTable(); |
109 | for ( int y = 0; y < imgUp->height(); y++ ) { | 109 | for ( int y = 0; y < imgUp->height(); y++ ) { |
110 | uchar *line = dest[y]; | 110 | uchar *line = dest[y]; |
111 | for ( int x = 0; x < imgUp->width(); x++ ) | 111 | for ( int x = 0; x < imgUp->width(); x++ ) |
112 | if ( !qRed( imgMask.pixel( x, y ) ) ) | 112 | if ( !qRed( imgMask.pixel( x, y ) ) ) |
113 | line[x] = i + 1; | 113 | line[x] = i + 1; |
114 | } | 114 | } |
115 | } | 115 | } |
116 | 116 | ||
117 | } | 117 | } |
118 | 118 | ||
119 | for ( int i = 0; i < 11; i++ ) { | 119 | for ( int i = 0; i < 11; i++ ) { |
120 | buttonPixUp[i] = NULL; | 120 | buttonPixUp[i] = NULL; |
121 | buttonPixDown[i] = NULL; | 121 | buttonPixDown[i] = NULL; |
122 | } | 122 | } |
123 | 123 | ||
124 | QWidget *d = QApplication::desktop(); | 124 | QWidget *d = QApplication::desktop(); |
125 | int width = d->width(); | 125 | int width = d->width(); |
126 | int height = d->height(); | 126 | int height = d->height(); |
127 | 127 | ||
128 | if( (width != pixBg->width() ) || (height != pixBg->height() ) ) { | 128 | if( (width != pixBg->width() ) || (height != pixBg->height() ) ) { |
129 | // odebug << "<<<<<<<< scale image >>>>>>>>>>>>" << oendl; | 129 | // odebug << "<<<<<<<< scale image >>>>>>>>>>>>" << oendl; |
130 | QImage img; | 130 | QImage img; |
131 | img = pixBg->convertToImage(); | 131 | img = pixBg->convertToImage(); |
132 | pixBg->convertFromImage( img.smoothScale( width, height)); | 132 | pixBg->convertFromImage( img.smoothScale( width, height)); |
133 | } | 133 | } |
134 | setBackgroundPixmap( *pixBg); | 134 | setBackgroundPixmap( *pixBg); |
135 | 135 | ||
136 | songInfo.setFocusPolicy( QWidget::NoFocus ); | 136 | songInfo.setFocusPolicy( QWidget::NoFocus ); |
137 | 137 | ||
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 | //NoFrame | 142 | //NoFrame |
143 | // songInfo.setForegroundColor(Qt::white); | 143 | // songInfo.setForegroundColor(Qt::white); |
144 | 144 | ||
145 | slider.setFixedHeight( 20 ); | 145 | slider.setFixedHeight( 20 ); |
146 | slider.setMinValue( 0 ); | 146 | slider.setMinValue( 0 ); |
147 | slider.setMaxValue( 1 ); | 147 | slider.setMaxValue( 1 ); |
148 | slider.setFocusPolicy( QWidget::NoFocus ); | 148 | slider.setFocusPolicy( QWidget::NoFocus ); |
149 | 149 | ||
150 | slider.setBackgroundPixmap( *pixBg ); | 150 | slider.setBackgroundPixmap( *pixBg ); |
151 | 151 | ||
152 | time.setFocusPolicy( QWidget::NoFocus ); | 152 | time.setFocusPolicy( QWidget::NoFocus ); |
153 | time.setAlignment( Qt::AlignCenter ); | 153 | time.setAlignment( Qt::AlignCenter ); |
154 | time.setFrame(FALSE); | 154 | time.setFrame(FALSE); |
155 | changeTextColor( &time ); | 155 | changeTextColor( &time ); |
156 | 156 | ||
157 | resizeEvent( NULL ); | 157 | resizeEvent( NULL ); |
158 | 158 | ||
159 | connect( &slider, SIGNAL( sliderPressed() ), this, SLOT( sliderPressed() ) ); | 159 | connect( &slider, SIGNAL( sliderPressed() ), this, SLOT( sliderPressed() ) ); |
160 | connect( &slider, SIGNAL( sliderReleased() ), this, SLOT( sliderReleased() ) ); | 160 | connect( &slider, SIGNAL( sliderReleased() ), this, SLOT( sliderReleased() ) ); |
161 | 161 | ||
162 | connect( mediaPlayerState, SIGNAL( lengthChanged(long) ), this, SLOT( setLength(long) ) ); | 162 | connect( mediaPlayerState, SIGNAL( lengthChanged(long) ), this, SLOT( setLength(long) ) ); |
163 | connect( mediaPlayerState, SIGNAL( viewChanged(char) ), this, SLOT( setView(char) ) ); | 163 | connect( mediaPlayerState, SIGNAL( viewChanged(char) ), this, SLOT( setView(char) ) ); |
164 | connect( mediaPlayerState, SIGNAL( loopingToggled(bool) ), this, SLOT( setLooping(bool) ) ); | 164 | connect( mediaPlayerState, SIGNAL( loopingToggled(bool) ), this, SLOT( setLooping(bool) ) ); |
165 | // connect( mediaPlayerState, SIGNAL( pausedToggled(bool) ), this, SLOT( setPaused(bool) ) ); | 165 | // connect( mediaPlayerState, SIGNAL( pausedToggled(bool) ), this, SLOT( setPaused(bool) ) ); |
166 | connect( mediaPlayerState, SIGNAL( playingToggled(bool) ), this, SLOT( setPlaying(bool) ) ); | 166 | connect( mediaPlayerState, SIGNAL( playingToggled(bool) ), this, SLOT( setPlaying(bool) ) ); |
167 | 167 | ||
168 | // Intialise state | 168 | // Intialise state |
169 | setLength( mediaPlayerState->length() ); | 169 | setLength( mediaPlayerState->length() ); |
170 | setPosition( mediaPlayerState->position() ); | 170 | setPosition( mediaPlayerState->position() ); |
171 | setLooping( mediaPlayerState->fullscreen() ); | 171 | setLooping( mediaPlayerState->fullscreen() ); |
172 | // setPaused( mediaPlayerState->paused() ); | 172 | // setPaused( mediaPlayerState->paused() ); |
173 | setPlaying( mediaPlayerState->playing() ); | 173 | setPlaying( mediaPlayerState->playing() ); |
174 | this->setFocus(); | 174 | this->setFocus(); |
175 | if(this->x() < 0 || this->y() < 0) | ||
176 | this->move(0,0); | ||
175 | } | 177 | } |
176 | 178 | ||
177 | 179 | ||
178 | AudioWidget::~AudioWidget() { | 180 | AudioWidget::~AudioWidget() { |
179 | // setPlaying( false); | 181 | // setPlaying( false); |
180 | 182 | ||
181 | for ( int i = 0; i < 10; i++ ) { | 183 | for ( int i = 0; i < 10; i++ ) { |
182 | if(buttonPixUp[i]) delete buttonPixUp[i]; | 184 | if(buttonPixUp[i]) delete buttonPixUp[i]; |
183 | if(buttonPixDown[i]) delete buttonPixDown[i]; | 185 | if(buttonPixDown[i]) delete buttonPixDown[i]; |
184 | } | 186 | } |
185 | if(pixBg) delete pixBg; | 187 | if(pixBg) delete pixBg; |
186 | if(imgUp) delete imgUp; | 188 | if(imgUp) delete imgUp; |
187 | if(imgDn) delete imgDn; | 189 | if(imgDn) delete imgDn; |
188 | if(imgButtonMask) delete imgButtonMask; | 190 | if(imgButtonMask) delete imgButtonMask; |
189 | for ( int i = 0; i < 10; i++ ) { | 191 | for ( int i = 0; i < 10; i++ ) { |
190 | if(masks[i]) delete masks[i]; | 192 | if(masks[i]) delete masks[i]; |
191 | } | 193 | } |
192 | } | 194 | } |
193 | 195 | ||
194 | 196 | ||
195 | QPixmap *combineImageWithBackground( QImage img, QPixmap bg, QPoint offset ) { | 197 | QPixmap *combineImageWithBackground( QImage img, QPixmap bg, QPoint offset ) { |
196 | QPixmap pix( img.width(), img.height() ); | 198 | QPixmap pix( img.width(), img.height() ); |
197 | QPainter p( &pix ); | 199 | QPainter p( &pix ); |
198 | p.drawTiledPixmap( pix.rect(), bg, offset ); | 200 | p.drawTiledPixmap( pix.rect(), bg, offset ); |
199 | p.drawImage( 0, 0, img ); | 201 | p.drawImage( 0, 0, img ); |
200 | return new QPixmap( pix ); | 202 | return new QPixmap( pix ); |
201 | } | 203 | } |
202 | 204 | ||
203 | 205 | ||
204 | QPixmap *maskPixToMask( QPixmap pix, QBitmap mask ) | 206 | QPixmap *maskPixToMask( QPixmap pix, QBitmap mask ) |
205 | { | 207 | { |
206 | QPixmap *pixmap = new QPixmap( pix ); | 208 | QPixmap *pixmap = new QPixmap( pix ); |
207 | pixmap->setMask( mask ); | 209 | pixmap->setMask( mask ); |
208 | return pixmap; | 210 | return pixmap; |
209 | } | 211 | } |
210 | 212 | ||
211 | 213 | ||
212 | 214 | ||
213 | void AudioWidget::resizeEvent( QResizeEvent * ) { | 215 | void AudioWidget::resizeEvent( QResizeEvent * ) { |
214 | int h = height(); | 216 | int h = height(); |
215 | int w = width(); | 217 | int w = width(); |
216 | 218 | ||
217 | songInfo.setGeometry( QRect( 2, 10, w - 4, 20 ) ); | 219 | songInfo.setGeometry( QRect( 2, 10, w - 4, 20 ) ); |
218 | slider.setFixedWidth( w - 110 ); | 220 | slider.setFixedWidth( w - 110 ); |
219 | slider.setGeometry( QRect( 15, h - 30, w - 90, 20 ) ); | 221 | slider.setGeometry( QRect( 15, h - 30, w - 90, 20 ) ); |
220 | slider.setBackgroundOrigin( QWidget::ParentOrigin ); | 222 | slider.setBackgroundOrigin( QWidget::ParentOrigin ); |
221 | time.setGeometry( QRect( w - 85, h - 30, 70, 20 ) ); | 223 | time.setGeometry( QRect( w - 85, h - 30, 70, 20 ) ); |
222 | 224 | ||
223 | xoff = ( w - imgUp->width() ) / 2; | 225 | xoff = ( w - imgUp->width() ) / 2; |
224 | yoff = (( h - imgUp->height() ) / 2) - 10; | 226 | yoff = (( h - imgUp->height() ) / 2) - 10; |
225 | QPoint p( xoff, yoff ); | 227 | QPoint p( xoff, yoff ); |
226 | 228 | ||
227 | QPixmap *pixUp = combineImageWithBackground( *imgUp, *pixBg, p ); | 229 | QPixmap *pixUp = combineImageWithBackground( *imgUp, *pixBg, p ); |
228 | QPixmap *pixDn = combineImageWithBackground( *imgDn, *pixBg, p ); | 230 | QPixmap *pixDn = combineImageWithBackground( *imgDn, *pixBg, p ); |
229 | 231 | ||
230 | for ( int i = 0; i < 10; i++ ) { | 232 | for ( int i = 0; i < 10; i++ ) { |
231 | if ( !masks[i]->isNull() ) { | 233 | if ( !masks[i]->isNull() ) { |
232 | delete buttonPixUp[i]; | 234 | delete buttonPixUp[i]; |
233 | delete buttonPixDown[i]; | 235 | delete buttonPixDown[i]; |
234 | buttonPixUp[i] = maskPixToMask( *pixUp, *masks[i] ); | 236 | buttonPixUp[i] = maskPixToMask( *pixUp, *masks[i] ); |
235 | buttonPixDown[i] = maskPixToMask( *pixDn, *masks[i] ); | 237 | buttonPixDown[i] = maskPixToMask( *pixDn, *masks[i] ); |
236 | } | 238 | } |
237 | } | 239 | } |
238 | 240 | ||
239 | delete pixUp; | 241 | delete pixUp; |
240 | delete pixDn; | 242 | delete pixDn; |
241 | } | 243 | } |
242 | 244 | ||
243 | 245 | ||
244 | static bool audioSliderBeingMoved = FALSE; | 246 | static bool audioSliderBeingMoved = FALSE; |
245 | 247 | ||
246 | void AudioWidget::sliderPressed() { | 248 | void AudioWidget::sliderPressed() { |
247 | audioSliderBeingMoved = TRUE; | 249 | audioSliderBeingMoved = TRUE; |
248 | } | 250 | } |
249 | 251 | ||
250 | 252 | ||
251 | void AudioWidget::sliderReleased() { | 253 | void AudioWidget::sliderReleased() { |
252 | audioSliderBeingMoved = FALSE; | 254 | audioSliderBeingMoved = FALSE; |
253 | if ( slider.width() == 0 ) | 255 | if ( slider.width() == 0 ) |
254 | return; | 256 | return; |
255 | long val = long((double)slider.value() * mediaPlayerState->length() / slider.width()); | 257 | long val = long((double)slider.value() * mediaPlayerState->length() / slider.width()); |
256 | mediaPlayerState->setPosition( val ); | 258 | mediaPlayerState->setPosition( val ); |
257 | } | 259 | } |
258 | 260 | ||
259 | 261 | ||
260 | void AudioWidget::setPosition( long i ) { | 262 | void AudioWidget::setPosition( long i ) { |
261 | // odebug << "set position " << i << "" << oendl; | 263 | // odebug << "set position " << i << "" << oendl; |
262 | long length = mediaPlayerState->length(); | 264 | long length = mediaPlayerState->length(); |
263 | updateSlider( i, length ); | 265 | updateSlider( i, length ); |
264 | } | 266 | } |
265 | 267 | ||
266 | 268 | ||
267 | void AudioWidget::setLength( long max ) { | 269 | void AudioWidget::setLength( long max ) { |
268 | updateSlider( mediaPlayerState->position(), max ); | 270 | updateSlider( mediaPlayerState->position(), max ); |
269 | } | 271 | } |
270 | 272 | ||