author | simon <simon> | 2002-12-02 18:01:00 (UTC) |
---|---|---|
committer | simon <simon> | 2002-12-02 18:01:00 (UTC) |
commit | 41fe383fe8b840de6dc0bcd47cd29b0d68bf760a (patch) (unidiff) | |
tree | 238a6bc98e657ed32d4d71895265d8512013bb14 | |
parent | c31f9b59dba873739494fcd9916c7cb9120ce1d9 (diff) | |
download | opie-41fe383fe8b840de6dc0bcd47cd29b0d68bf760a.zip opie-41fe383fe8b840de6dc0bcd47cd29b0d68bf760a.tar.gz opie-41fe383fe8b840de6dc0bcd47cd29b0d68bf760a.tar.bz2 |
- added a missing const
- QImage and QPixmap are value based classes, so use them like that for
a couple of objects. simplifies the code and helps to avoid memory leaks
-rw-r--r-- | noncore/multimedia/opieplayer2/audiowidget.cpp | 53 | ||||
-rw-r--r-- | noncore/multimedia/opieplayer2/audiowidget.h | 9 |
2 files changed, 28 insertions, 34 deletions
diff --git a/noncore/multimedia/opieplayer2/audiowidget.cpp b/noncore/multimedia/opieplayer2/audiowidget.cpp index 5cdfbf2..46d374d 100644 --- a/noncore/multimedia/opieplayer2/audiowidget.cpp +++ b/noncore/multimedia/opieplayer2/audiowidget.cpp | |||
@@ -45,232 +45,225 @@ | |||
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 | extern MediaPlayerState *mediaPlayerState; | 53 | extern MediaPlayerState *mediaPlayerState; |
54 | extern PlayListWidget *playList; | 54 | extern PlayListWidget *playList; |
55 | 55 | ||
56 | static const int xo = -2; // movable x offset | 56 | static const int xo = -2; // movable x offset |
57 | static const int yo = 22; // movable y offset | 57 | static const int yo = 22; // movable y offset |
58 | 58 | ||
59 | struct MediaButton { | 59 | struct MediaButton { |
60 | bool isToggle, isHeld, isDown; | 60 | bool isToggle, isHeld, isDown; |
61 | }; | 61 | }; |
62 | 62 | ||
63 | //Layout information for the audioButtons (and if it is a toggle button or not) | 63 | //Layout information for the audioButtons (and if it is a toggle button or not) |
64 | MediaButton audioButtons[] = { | 64 | MediaButton audioButtons[] = { |
65 | { TRUE, FALSE, FALSE }, // play | 65 | { TRUE, FALSE, FALSE }, // play |
66 | { FALSE, FALSE, FALSE }, // stop | 66 | { FALSE, FALSE, FALSE }, // stop |
67 | { FALSE, FALSE, FALSE }, // next | 67 | { FALSE, FALSE, FALSE }, // next |
68 | { FALSE, FALSE, FALSE }, // previous | 68 | { FALSE, FALSE, FALSE }, // previous |
69 | { FALSE, FALSE, FALSE }, // volume up | 69 | { FALSE, FALSE, FALSE }, // volume up |
70 | { FALSE, FALSE, FALSE }, // volume down | 70 | { FALSE, FALSE, FALSE }, // volume down |
71 | { TRUE, FALSE, FALSE }, // repeat/loop | 71 | { TRUE, FALSE, FALSE }, // repeat/loop |
72 | { FALSE, FALSE, FALSE }, // playlist | 72 | { FALSE, FALSE, FALSE }, // playlist |
73 | { FALSE, FALSE, FALSE }, // forward | 73 | { FALSE, FALSE, FALSE }, // forward |
74 | { FALSE, FALSE, FALSE } // back | 74 | { FALSE, FALSE, FALSE } // back |
75 | }; | 75 | }; |
76 | 76 | ||
77 | const char *skin_mask_file_names[10] = { | 77 | const char * const skin_mask_file_names[10] = { |
78 | "play", "stop", "next", "prev", "up", | 78 | "play", "stop", "next", "prev", "up", |
79 | "down", "loop", "playlist", "forward", "back" | 79 | "down", "loop", "playlist", "forward", "back" |
80 | }; | 80 | }; |
81 | 81 | ||
82 | 82 | ||
83 | static void changeTextColor( QWidget *w ) { | 83 | static void changeTextColor( QWidget *w ) { |
84 | QPalette p = w->palette(); | 84 | QPalette p = w->palette(); |
85 | p.setBrush( QColorGroup::Background, QColor( 167, 212, 167 ) ); | 85 | p.setBrush( QColorGroup::Background, QColor( 167, 212, 167 ) ); |
86 | p.setBrush( QColorGroup::Base, QColor( 167, 212, 167 ) ); | 86 | p.setBrush( QColorGroup::Base, QColor( 167, 212, 167 ) ); |
87 | w->setPalette( p ); | 87 | w->setPalette( p ); |
88 | } | 88 | } |
89 | 89 | ||
90 | static const int numButtons = (sizeof(audioButtons)/sizeof(MediaButton)); | 90 | static const int numButtons = (sizeof(audioButtons)/sizeof(MediaButton)); |
91 | 91 | ||
92 | 92 | ||
93 | AudioWidget::AudioWidget(QWidget* parent, const char* name, WFlags f) : | 93 | AudioWidget::AudioWidget(QWidget* parent, const char* name, WFlags f) : |
94 | 94 | ||
95 | QWidget( parent, name, f ), songInfo( this ), slider( Qt::Horizontal, this ), time( this ) { | 95 | QWidget( parent, name, f ), songInfo( this ), slider( Qt::Horizontal, this ), time( this ) { |
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 = new QPixmap( Resource::loadPixmap( QString("%1/background").arg(skinPath) ) ); | 106 | pixBg = QPixmap( Resource::loadPixmap( QString("%1/background").arg(skinPath) ) ); |
107 | imgUp = new QImage( Resource::loadImage( QString("%1/skin_up").arg(skinPath) ) ); | 107 | imgUp = QImage( Resource::loadImage( QString("%1/skin_up").arg(skinPath) ) ); |
108 | imgDn = new QImage( Resource::loadImage( QString("%1/skin_down").arg(skinPath) ) ); | 108 | imgDn = QImage( Resource::loadImage( QString("%1/skin_down").arg(skinPath) ) ); |
109 | 109 | ||
110 | imgButtonMask = new QImage( imgUp->width(), imgUp->height(), 8, 255 ); | 110 | imgButtonMask = QImage( imgUp.width(), imgUp.height(), 8, 255 ); |
111 | imgButtonMask->fill( 0 ); | 111 | imgButtonMask.fill( 0 ); |
112 | 112 | ||
113 | for ( int i = 0; i < 10; i++ ) { | 113 | for ( int i = 0; i < 10; i++ ) { |
114 | QString filename = QString( QPEApplication::qpeDir() + "/pics/" + skinPath + "/skin_mask_" + skin_mask_file_names[i] + ".png" ); | 114 | QString filename = QString( QPEApplication::qpeDir() + "/pics/" + skinPath + "/skin_mask_" + skin_mask_file_names[i] + ".png" ); |
115 | masks[i] = new QBitmap( filename ); | 115 | masks[i] = new QBitmap( filename ); |
116 | 116 | ||
117 | if ( !masks[i]->isNull() ) { | 117 | if ( !masks[i]->isNull() ) { |
118 | QImage imgMask = masks[i]->convertToImage(); | 118 | QImage imgMask = masks[i]->convertToImage(); |
119 | uchar **dest = imgButtonMask->jumpTable(); | 119 | uchar **dest = imgButtonMask.jumpTable(); |
120 | for ( int y = 0; y < imgUp->height(); y++ ) { | 120 | for ( int y = 0; y < imgUp.height(); y++ ) { |
121 | uchar *line = dest[y]; | 121 | uchar *line = dest[y]; |
122 | for ( int x = 0; x < imgUp->width(); x++ ) | 122 | for ( int x = 0; x < imgUp.width(); x++ ) |
123 | if ( !qRed( imgMask.pixel( x, y ) ) ) | 123 | if ( !qRed( imgMask.pixel( x, y ) ) ) |
124 | line[x] = i + 1; | 124 | line[x] = i + 1; |
125 | } | 125 | } |
126 | } | 126 | } |
127 | 127 | ||
128 | } | 128 | } |
129 | 129 | ||
130 | for ( int i = 0; i < 10; i++ ) { | 130 | for ( int i = 0; i < 10; i++ ) { |
131 | buttonPixUp[i] = 0l; | 131 | buttonPixUp[i] = 0l; |
132 | buttonPixDown[i] = 0l; | 132 | buttonPixDown[i] = 0l; |
133 | } | 133 | } |
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( 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( playingToggled(bool) ), this, SLOT( setPlaying(bool) ) ); | 165 | connect( mediaPlayerState, SIGNAL( playingToggled(bool) ), this, SLOT( setPlaying(bool) ) ); |
166 | connect( mediaPlayerState, SIGNAL( isSeekableToggled( bool ) ), this, SLOT( setSeekable( bool ) ) ); | 166 | connect( mediaPlayerState, SIGNAL( isSeekableToggled( bool ) ), this, SLOT( setSeekable( bool ) ) ); |
167 | 167 | ||
168 | connect( this, SIGNAL( forwardClicked() ), this, SLOT( skipFor() ) ); | 168 | connect( this, SIGNAL( forwardClicked() ), this, SLOT( skipFor() ) ); |
169 | connect( this, SIGNAL( backClicked() ), this, SLOT( skipBack() ) ); | 169 | connect( this, SIGNAL( backClicked() ), this, SLOT( skipBack() ) ); |
170 | connect( this, SIGNAL( forwardReleased() ), this, SLOT( stopSkip() ) ); | 170 | connect( this, SIGNAL( forwardReleased() ), this, SLOT( stopSkip() ) ); |
171 | connect( this, SIGNAL( backReleased() ), this, SLOT( stopSkip() ) ); | 171 | connect( this, SIGNAL( backReleased() ), this, SLOT( stopSkip() ) ); |
172 | 172 | ||
173 | // Intialise state | 173 | // Intialise state |
174 | setLength( mediaPlayerState->length() ); | 174 | setLength( mediaPlayerState->length() ); |
175 | setPosition( mediaPlayerState->position() ); | 175 | setPosition( mediaPlayerState->position() ); |
176 | setLooping( mediaPlayerState->isFullscreen() ); | 176 | setLooping( mediaPlayerState->isFullscreen() ); |
177 | // setPaused( mediaPlayerState->paused() ); | 177 | // setPaused( mediaPlayerState->paused() ); |
178 | setPlaying( mediaPlayerState->isPlaying() ); | 178 | setPlaying( mediaPlayerState->isPlaying() ); |
179 | 179 | ||
180 | } | 180 | } |
181 | 181 | ||
182 | AudioWidget::~AudioWidget() { | 182 | AudioWidget::~AudioWidget() { |
183 | 183 | ||
184 | for ( int i = 0; i < 10; i++ ) { | 184 | for ( int i = 0; i < 10; i++ ) { |
185 | delete buttonPixUp[i]; | 185 | delete buttonPixUp[i]; |
186 | delete buttonPixDown[i]; | 186 | delete buttonPixDown[i]; |
187 | } | 187 | } |
188 | delete pixBg; | ||
189 | delete imgUp; | ||
190 | delete imgDn; | ||
191 | delete imgButtonMask; | ||
192 | for ( int i = 0; i < 10; i++ ) { | 188 | for ( int i = 0; i < 10; i++ ) { |
193 | delete masks[i]; | 189 | delete masks[i]; |
194 | } | 190 | } |
195 | // mediaPlayerState->setPlaying(false); | 191 | // mediaPlayerState->setPlaying(false); |
196 | } | 192 | } |
197 | 193 | ||
198 | namespace { | 194 | namespace { |
199 | 195 | ||
200 | QPixmap *combineImageWithBackground( QImage img, QPixmap bg, QPoint offset ) { | 196 | QPixmap combineImageWithBackground( QImage img, QPixmap bg, QPoint offset ) { |
201 | QPixmap pix( img.width(), img.height() ); | 197 | QPixmap pix( img.width(), img.height() ); |
202 | QPainter p( &pix ); | 198 | QPainter p( &pix ); |
203 | p.drawTiledPixmap( pix.rect(), bg, offset ); | 199 | p.drawTiledPixmap( pix.rect(), bg, offset ); |
204 | p.drawImage( 0, 0, img ); | 200 | p.drawImage( 0, 0, img ); |
205 | return new QPixmap( pix ); | 201 | return pix; |
206 | } | 202 | } |
207 | 203 | ||
208 | 204 | ||
209 | QPixmap *maskPixToMask( QPixmap pix, QBitmap mask ) { | 205 | QPixmap *maskPixToMask( QPixmap pix, QBitmap mask ) { |
210 | QPixmap *pixmap = new QPixmap( pix ); | 206 | QPixmap *pixmap = new QPixmap( pix ); |
211 | pixmap->setMask( mask ); | 207 | pixmap->setMask( mask ); |
212 | return pixmap; | 208 | return pixmap; |
213 | } | 209 | } |
214 | 210 | ||
215 | }; | 211 | }; |
216 | 212 | ||
217 | void AudioWidget::resizeEvent( QResizeEvent * ) { | 213 | void AudioWidget::resizeEvent( QResizeEvent * ) { |
218 | int h = height(); | 214 | int h = height(); |
219 | int w = width(); | 215 | int w = width(); |
220 | 216 | ||
221 | songInfo.setGeometry( QRect( 2, 2, w - 4, 20 ) ); | 217 | songInfo.setGeometry( QRect( 2, 2, w - 4, 20 ) ); |
222 | slider.setFixedWidth( w - 110 ); | 218 | slider.setFixedWidth( w - 110 ); |
223 | slider.setGeometry( QRect( 15, h - 22, w - 90, 20 ) ); | 219 | slider.setGeometry( QRect( 15, h - 22, w - 90, 20 ) ); |
224 | slider.setBackgroundOrigin( QWidget::ParentOrigin ); | 220 | slider.setBackgroundOrigin( QWidget::ParentOrigin ); |
225 | time.setGeometry( QRect( w - 85, h - 30, 70, 20 ) ); | 221 | time.setGeometry( QRect( w - 85, h - 30, 70, 20 ) ); |
226 | 222 | ||
227 | xoff = ( w - imgUp->width() ) / 2; | 223 | xoff = ( w - imgUp.width() ) / 2; |
228 | yoff = (( h - imgUp->height() ) / 2) - 10; | 224 | yoff = (( h - imgUp.height() ) / 2) - 10; |
229 | QPoint p( xoff, yoff ); | 225 | QPoint p( xoff, yoff ); |
230 | 226 | ||
231 | QPixmap *pixUp = combineImageWithBackground( *imgUp, *pixBg, p ); | 227 | QPixmap pixUp = combineImageWithBackground( imgUp, pixBg, p ); |
232 | QPixmap *pixDn = combineImageWithBackground( *imgDn, *pixBg, p ); | 228 | QPixmap pixDn = combineImageWithBackground( imgDn, pixBg, p ); |
233 | 229 | ||
234 | for ( int i = 0; i < 10; i++ ) { | 230 | for ( int i = 0; i < 10; i++ ) { |
235 | if ( !masks[i]->isNull() ) { | 231 | if ( !masks[i]->isNull() ) { |
236 | delete buttonPixUp[i]; | 232 | delete buttonPixUp[i]; |
237 | delete buttonPixDown[i]; | 233 | delete buttonPixDown[i]; |
238 | buttonPixUp[i] = maskPixToMask( *pixUp, *masks[i] ); | 234 | buttonPixUp[i] = maskPixToMask( pixUp, *masks[i] ); |
239 | buttonPixDown[i] = maskPixToMask( *pixDn, *masks[i] ); | 235 | buttonPixDown[i] = maskPixToMask( pixDn, *masks[i] ); |
240 | } | 236 | } |
241 | } | 237 | } |
242 | |||
243 | delete pixUp; | ||
244 | delete pixDn; | ||
245 | } | 238 | } |
246 | 239 | ||
247 | static bool audioSliderBeingMoved = FALSE; | 240 | static bool audioSliderBeingMoved = FALSE; |
248 | 241 | ||
249 | 242 | ||
250 | void AudioWidget::sliderPressed() { | 243 | void AudioWidget::sliderPressed() { |
251 | audioSliderBeingMoved = TRUE; | 244 | audioSliderBeingMoved = TRUE; |
252 | } | 245 | } |
253 | 246 | ||
254 | 247 | ||
255 | void AudioWidget::sliderReleased() { | 248 | void AudioWidget::sliderReleased() { |
256 | audioSliderBeingMoved = FALSE; | 249 | audioSliderBeingMoved = FALSE; |
257 | if ( slider.width() == 0 ) | 250 | if ( slider.width() == 0 ) |
258 | return; | 251 | return; |
259 | long val = long((double)slider.value() * mediaPlayerState->length() / slider.width()); | 252 | long val = long((double)slider.value() * mediaPlayerState->length() / slider.width()); |
260 | mediaPlayerState->setPosition( val ); | 253 | mediaPlayerState->setPosition( val ); |
261 | } | 254 | } |
262 | 255 | ||
263 | void AudioWidget::setPosition( long i ) { | 256 | void AudioWidget::setPosition( long i ) { |
264 | // qDebug("<<<<<<<<<<<<<<<<<<<<<<<<set position %d",i); | 257 | // qDebug("<<<<<<<<<<<<<<<<<<<<<<<<set position %d",i); |
265 | updateSlider( i, mediaPlayerState->length() ); | 258 | updateSlider( i, mediaPlayerState->length() ); |
266 | } | 259 | } |
267 | 260 | ||
268 | 261 | ||
269 | void AudioWidget::setLength( long max ) { | 262 | void AudioWidget::setLength( long max ) { |
270 | updateSlider( mediaPlayerState->position(), max ); | 263 | updateSlider( mediaPlayerState->position(), max ); |
271 | } | 264 | } |
272 | 265 | ||
273 | 266 | ||
274 | void AudioWidget::setView( char view ) { | 267 | void AudioWidget::setView( char view ) { |
275 | 268 | ||
276 | if ( view == 'a' ) { | 269 | if ( view == 'a' ) { |
@@ -368,67 +361,67 @@ void AudioWidget::skipFor() { | |||
368 | mediaPlayerState->setPosition( mediaPlayerState->position() + 2 ); | 361 | mediaPlayerState->setPosition( mediaPlayerState->position() + 2 ); |
369 | } | 362 | } |
370 | 363 | ||
371 | void AudioWidget::skipBack() { | 364 | void AudioWidget::skipBack() { |
372 | skipDirection = -1; | 365 | skipDirection = -1; |
373 | startTimer( 50 ); | 366 | startTimer( 50 ); |
374 | mediaPlayerState->setPosition( mediaPlayerState->position() - 2 ); | 367 | mediaPlayerState->setPosition( mediaPlayerState->position() - 2 ); |
375 | } | 368 | } |
376 | 369 | ||
377 | 370 | ||
378 | 371 | ||
379 | void AudioWidget::stopSkip() { | 372 | void AudioWidget::stopSkip() { |
380 | killTimers(); | 373 | killTimers(); |
381 | } | 374 | } |
382 | 375 | ||
383 | 376 | ||
384 | void AudioWidget::timerEvent( QTimerEvent * ) { | 377 | void AudioWidget::timerEvent( QTimerEvent * ) { |
385 | if ( skipDirection == +1 ) { | 378 | if ( skipDirection == +1 ) { |
386 | mediaPlayerState->setPosition( mediaPlayerState->position() + 2 ); | 379 | mediaPlayerState->setPosition( mediaPlayerState->position() + 2 ); |
387 | } else if ( skipDirection == -1 ) { | 380 | } else if ( skipDirection == -1 ) { |
388 | mediaPlayerState->setPosition( mediaPlayerState->position() - 2 ); | 381 | mediaPlayerState->setPosition( mediaPlayerState->position() - 2 ); |
389 | } | 382 | } |
390 | } | 383 | } |
391 | 384 | ||
392 | 385 | ||
393 | void AudioWidget::mouseMoveEvent( QMouseEvent *event ) { | 386 | void AudioWidget::mouseMoveEvent( QMouseEvent *event ) { |
394 | for ( int i = 0; i < numButtons; i++ ) { | 387 | for ( int i = 0; i < numButtons; i++ ) { |
395 | if ( event->state() == QMouseEvent::LeftButton ) { | 388 | if ( event->state() == QMouseEvent::LeftButton ) { |
396 | // The test to see if the mouse click is inside the button or not | 389 | // The test to see if the mouse click is inside the button or not |
397 | int x = event->pos().x() - xoff; | 390 | int x = event->pos().x() - xoff; |
398 | int y = event->pos().y() - yoff; | 391 | int y = event->pos().y() - yoff; |
399 | 392 | ||
400 | bool isOnButton = ( x > 0 && y > 0 && x < imgButtonMask->width() | 393 | bool isOnButton = ( x > 0 && y > 0 && x < imgButtonMask.width() |
401 | && y < imgButtonMask->height() | 394 | && y < imgButtonMask.height() |
402 | && imgButtonMask->pixelIndex( x, y ) == i + 1 ); | 395 | && imgButtonMask.pixelIndex( x, y ) == i + 1 ); |
403 | 396 | ||
404 | if ( isOnButton && !audioButtons[i].isHeld ) { | 397 | if ( isOnButton && !audioButtons[i].isHeld ) { |
405 | audioButtons[i].isHeld = TRUE; | 398 | audioButtons[i].isHeld = TRUE; |
406 | toggleButton(i); | 399 | toggleButton(i); |
407 | switch (i) { | 400 | switch (i) { |
408 | case AudioVolumeUp: | 401 | case AudioVolumeUp: |
409 | emit moreClicked(); | 402 | emit moreClicked(); |
410 | return; | 403 | return; |
411 | case AudioVolumeDown: | 404 | case AudioVolumeDown: |
412 | emit lessClicked(); | 405 | emit lessClicked(); |
413 | return; | 406 | return; |
414 | case AudioForward: | 407 | case AudioForward: |
415 | emit forwardClicked(); | 408 | emit forwardClicked(); |
416 | return; | 409 | return; |
417 | case AudioBack: | 410 | case AudioBack: |
418 | emit backClicked(); | 411 | emit backClicked(); |
419 | return; | 412 | return; |
420 | } | 413 | } |
421 | } else if ( !isOnButton && audioButtons[i].isHeld ) { | 414 | } else if ( !isOnButton && audioButtons[i].isHeld ) { |
422 | audioButtons[i].isHeld = FALSE; | 415 | audioButtons[i].isHeld = FALSE; |
423 | toggleButton(i); | 416 | toggleButton(i); |
424 | } | 417 | } |
425 | } else { | 418 | } else { |
426 | if ( audioButtons[i].isHeld ) { | 419 | if ( audioButtons[i].isHeld ) { |
427 | audioButtons[i].isHeld = FALSE; | 420 | audioButtons[i].isHeld = FALSE; |
428 | if ( !audioButtons[i].isToggle ) { | 421 | if ( !audioButtons[i].isToggle ) { |
429 | setToggleButton( i, FALSE ); | 422 | setToggleButton( i, FALSE ); |
430 | } | 423 | } |
431 | qDebug("mouseEvent %d", i); | 424 | qDebug("mouseEvent %d", i); |
432 | switch (i) { | 425 | switch (i) { |
433 | case AudioPlay: | 426 | case AudioPlay: |
434 | if( mediaPlayerState->isPaused() ) { | 427 | if( mediaPlayerState->isPaused() ) { |
@@ -452,65 +445,65 @@ void AudioWidget::mouseMoveEvent( QMouseEvent *event ) { | |||
452 | } | 445 | } |
453 | } | 446 | } |
454 | } | 447 | } |
455 | 448 | ||
456 | 449 | ||
457 | void AudioWidget::mousePressEvent( QMouseEvent *event ) { | 450 | void AudioWidget::mousePressEvent( QMouseEvent *event ) { |
458 | mouseMoveEvent( event ); | 451 | mouseMoveEvent( event ); |
459 | } | 452 | } |
460 | 453 | ||
461 | 454 | ||
462 | void AudioWidget::mouseReleaseEvent( QMouseEvent *event ) { | 455 | void AudioWidget::mouseReleaseEvent( QMouseEvent *event ) { |
463 | mouseMoveEvent( event ); | 456 | mouseMoveEvent( event ); |
464 | } | 457 | } |
465 | 458 | ||
466 | 459 | ||
467 | void AudioWidget::showEvent( QShowEvent* ) { | 460 | void AudioWidget::showEvent( QShowEvent* ) { |
468 | QMouseEvent event( QEvent::MouseMove, QPoint( 0, 0 ), 0, 0 ); | 461 | QMouseEvent event( QEvent::MouseMove, QPoint( 0, 0 ), 0, 0 ); |
469 | mouseMoveEvent( &event ); | 462 | mouseMoveEvent( &event ); |
470 | } | 463 | } |
471 | 464 | ||
472 | 465 | ||
473 | void AudioWidget::closeEvent( QCloseEvent* ) { | 466 | void AudioWidget::closeEvent( QCloseEvent* ) { |
474 | mediaPlayerState->setList(); | 467 | mediaPlayerState->setList(); |
475 | } | 468 | } |
476 | 469 | ||
477 | 470 | ||
478 | void AudioWidget::paintEvent( QPaintEvent * pe ) { | 471 | void AudioWidget::paintEvent( QPaintEvent * pe ) { |
479 | if ( !pe->erased() ) { | 472 | if ( !pe->erased() ) { |
480 | // Combine with background and double buffer | 473 | // Combine with background and double buffer |
481 | QPixmap pix( pe->rect().size() ); | 474 | QPixmap pix( pe->rect().size() ); |
482 | QPainter p( &pix ); | 475 | QPainter p( &pix ); |
483 | p.translate( -pe->rect().topLeft().x(), -pe->rect().topLeft().y() ); | 476 | p.translate( -pe->rect().topLeft().x(), -pe->rect().topLeft().y() ); |
484 | p.drawTiledPixmap( pe->rect(), *pixBg, pe->rect().topLeft() ); | 477 | p.drawTiledPixmap( pe->rect(), pixBg, pe->rect().topLeft() ); |
485 | for ( int i = 0; i < numButtons; i++ ) | 478 | for ( int i = 0; i < numButtons; i++ ) |
486 | paintButton( &p, i ); | 479 | paintButton( &p, i ); |
487 | QPainter p2( this ); | 480 | QPainter p2( this ); |
488 | p2.drawPixmap( pe->rect().topLeft(), pix ); | 481 | p2.drawPixmap( pe->rect().topLeft(), pix ); |
489 | } else { | 482 | } else { |
490 | QPainter p( this ); | 483 | QPainter p( this ); |
491 | for ( int i = 0; i < numButtons; i++ ) | 484 | for ( int i = 0; i < numButtons; i++ ) |
492 | paintButton( &p, i ); | 485 | paintButton( &p, i ); |
493 | } | 486 | } |
494 | } | 487 | } |
495 | 488 | ||
496 | void AudioWidget::keyReleaseEvent( QKeyEvent *e) { | 489 | void AudioWidget::keyReleaseEvent( QKeyEvent *e) { |
497 | switch ( e->key() ) { | 490 | switch ( e->key() ) { |
498 | ////////////////////////////// Zaurus keys | 491 | ////////////////////////////// Zaurus keys |
499 | case Key_Home: | 492 | case Key_Home: |
500 | break; | 493 | break; |
501 | case Key_F9: //activity | 494 | case Key_F9: //activity |
502 | hide(); | 495 | hide(); |
503 | // qDebug("Audio F9"); | 496 | // qDebug("Audio F9"); |
504 | break; | 497 | break; |
505 | case Key_F10: //contacts | 498 | case Key_F10: //contacts |
506 | break; | 499 | break; |
507 | case Key_F11: //menu | 500 | case Key_F11: //menu |
508 | mediaPlayerState->toggleBlank(); | 501 | mediaPlayerState->toggleBlank(); |
509 | break; | 502 | break; |
510 | case Key_F12: //home | 503 | case Key_F12: //home |
511 | break; | 504 | break; |
512 | case Key_F13: //mail | 505 | case Key_F13: //mail |
513 | mediaPlayerState->toggleBlank(); | 506 | mediaPlayerState->toggleBlank(); |
514 | break; | 507 | break; |
515 | case Key_Space: { | 508 | case Key_Space: { |
516 | if(mediaPlayerState->isPlaying()) { | 509 | if(mediaPlayerState->isPlaying()) { |
diff --git a/noncore/multimedia/opieplayer2/audiowidget.h b/noncore/multimedia/opieplayer2/audiowidget.h index 7cb1d79..54adb36 100644 --- a/noncore/multimedia/opieplayer2/audiowidget.h +++ b/noncore/multimedia/opieplayer2/audiowidget.h | |||
@@ -13,64 +13,65 @@ | |||
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 | #ifndef AUDIO_WIDGET_H | 34 | #ifndef AUDIO_WIDGET_H |
35 | #define AUDIO_WIDGET_H | 35 | #define AUDIO_WIDGET_H |
36 | 36 | ||
37 | #include <qwidget.h> | 37 | #include <qwidget.h> |
38 | #include <qpainter.h> | 38 | #include <qpainter.h> |
39 | #include <qdrawutil.h> | 39 | #include <qdrawutil.h> |
40 | #include <qpixmap.h> | 40 | #include <qpixmap.h> |
41 | #include <qstring.h> | 41 | #include <qstring.h> |
42 | #include <qslider.h> | 42 | #include <qslider.h> |
43 | #include <qframe.h> | 43 | #include <qframe.h> |
44 | #include <qlineedit.h> | 44 | #include <qlineedit.h> |
45 | #include <qimage.h> | ||
45 | 46 | ||
46 | #include <opie/oticker.h> | 47 | #include <opie/oticker.h> |
47 | 48 | ||
48 | class QPixmap; | 49 | class QPixmap; |
49 | 50 | ||
50 | namespace { | 51 | namespace { |
51 | 52 | ||
52 | enum AudioButtons { | 53 | enum AudioButtons { |
53 | AudioPlay=0, | 54 | AudioPlay=0, |
54 | AudioStop, | 55 | AudioStop, |
55 | AudioNext, | 56 | AudioNext, |
56 | AudioPrevious, | 57 | AudioPrevious, |
57 | AudioVolumeUp, | 58 | AudioVolumeUp, |
58 | AudioVolumeDown, | 59 | AudioVolumeDown, |
59 | AudioLoop, | 60 | AudioLoop, |
60 | AudioPlayList, | 61 | AudioPlayList, |
61 | AudioForward, | 62 | AudioForward, |
62 | AudioBack | 63 | AudioBack |
63 | }; | 64 | }; |
64 | }; | 65 | }; |
65 | 66 | ||
66 | class AudioWidget : public QWidget { | 67 | class AudioWidget : public QWidget { |
67 | Q_OBJECT | 68 | Q_OBJECT |
68 | public: | 69 | public: |
69 | AudioWidget( QWidget* parent=0, const char* name=0, WFlags f=0 ); | 70 | AudioWidget( QWidget* parent=0, const char* name=0, WFlags f=0 ); |
70 | ~AudioWidget(); | 71 | ~AudioWidget(); |
71 | void setTickerText( const QString &text ) { songInfo.setText( text ); } | 72 | void setTickerText( const QString &text ) { songInfo.setText( text ); } |
72 | public slots: | 73 | public slots: |
73 | void updateSlider( long, long ); | 74 | void updateSlider( long, long ); |
74 | void sliderPressed( ); | 75 | void sliderPressed( ); |
75 | void sliderReleased( ); | 76 | void sliderReleased( ); |
76 | void setLooping( bool b) { setToggleButton( AudioLoop, b ); } | 77 | void setLooping( bool b) { setToggleButton( AudioLoop, b ); } |
@@ -84,51 +85,51 @@ signals: | |||
84 | void moreClicked(); | 85 | void moreClicked(); |
85 | void lessClicked(); | 86 | void lessClicked(); |
86 | void moreReleased(); | 87 | void moreReleased(); |
87 | void lessReleased(); | 88 | void lessReleased(); |
88 | void forwardClicked(); | 89 | void forwardClicked(); |
89 | void backClicked(); | 90 | void backClicked(); |
90 | void forwardReleased(); | 91 | void forwardReleased(); |
91 | void backReleased(); | 92 | void backReleased(); |
92 | void sliderMoved(long); | 93 | void sliderMoved(long); |
93 | 94 | ||
94 | protected: | 95 | protected: |
95 | void doBlank(); | 96 | void doBlank(); |
96 | void doUnblank(); | 97 | void doUnblank(); |
97 | void paintEvent( QPaintEvent *pe ); | 98 | void paintEvent( QPaintEvent *pe ); |
98 | void showEvent( QShowEvent *se ); | 99 | void showEvent( QShowEvent *se ); |
99 | void resizeEvent( QResizeEvent *re ); | 100 | void resizeEvent( QResizeEvent *re ); |
100 | void mouseMoveEvent( QMouseEvent *event ); | 101 | void mouseMoveEvent( QMouseEvent *event ); |
101 | void mousePressEvent( QMouseEvent *event ); | 102 | void mousePressEvent( QMouseEvent *event ); |
102 | void mouseReleaseEvent( QMouseEvent *event ); | 103 | void mouseReleaseEvent( QMouseEvent *event ); |
103 | void timerEvent( QTimerEvent *event ); | 104 | void timerEvent( QTimerEvent *event ); |
104 | void closeEvent( QCloseEvent *event ); | 105 | void closeEvent( QCloseEvent *event ); |
105 | void keyReleaseEvent( QKeyEvent *e); | 106 | void keyReleaseEvent( QKeyEvent *e); |
106 | private slots: | 107 | private slots: |
107 | void skipFor(); | 108 | void skipFor(); |
108 | void skipBack(); | 109 | void skipBack(); |
109 | void stopSkip(); | 110 | void stopSkip(); |
110 | private: | 111 | private: |
111 | void toggleButton( int ); | 112 | void toggleButton( int ); |
112 | void setToggleButton( int, bool ); | 113 | void setToggleButton( int, bool ); |
113 | void paintButton( QPainter *p, int i ); | 114 | void paintButton( QPainter *p, int i ); |
114 | int skipDirection; | 115 | int skipDirection; |
115 | QString skin; | 116 | QString skin; |
116 | QPixmap *pixBg; | 117 | QPixmap pixBg; |
117 | QImage *imgUp; | 118 | QImage imgUp; |
118 | QImage *imgDn; | 119 | QImage imgDn; |
119 | QImage *imgButtonMask; | 120 | QImage imgButtonMask; |
120 | QBitmap *masks[10]; | 121 | QBitmap *masks[10]; |
121 | QPixmap *buttonPixUp[10]; | 122 | QPixmap *buttonPixUp[10]; |
122 | QPixmap *buttonPixDown[10]; | 123 | QPixmap *buttonPixDown[10]; |
123 | 124 | ||
124 | QPixmap *pixmaps[4]; | 125 | QPixmap *pixmaps[4]; |
125 | OTicker songInfo; | 126 | OTicker songInfo; |
126 | QSlider slider; | 127 | QSlider slider; |
127 | QLineEdit time; | 128 | QLineEdit time; |
128 | int xoff, yoff; | 129 | int xoff, yoff; |
129 | bool isStreaming : 1; | 130 | bool isStreaming : 1; |
130 | }; | 131 | }; |
131 | 132 | ||
132 | 133 | ||
133 | #endif // AUDIO_WIDGET_H | 134 | #endif // AUDIO_WIDGET_H |
134 | 135 | ||