author | simon <simon> | 2002-12-08 22:47:39 (UTC) |
---|---|---|
committer | simon <simon> | 2002-12-08 22:47:39 (UTC) |
commit | 786bc677f61983414df8a4613cc525c4bcd2a054 (patch) (unidiff) | |
tree | c39a2a1691ffc8d813a496cb47c00b8ede47ea30 | |
parent | 8b72df0bb25ca5a0791756b2444fc6a1ce361082 (diff) | |
download | opie-786bc677f61983414df8a4613cc525c4bcd2a054.zip opie-786bc677f61983414df8a4613cc525c4bcd2a054.tar.gz opie-786bc677f61983414df8a4613cc525c4bcd2a054.tar.bz2 |
- moved the duplicated code for checking whether the mouse is over a
button into a shared isOverButton method
-rw-r--r-- | noncore/multimedia/opieplayer2/audiowidget.cpp | 7 | ||||
-rw-r--r-- | noncore/multimedia/opieplayer2/mediawidget.cpp | 8 | ||||
-rw-r--r-- | noncore/multimedia/opieplayer2/mediawidget.h | 2 | ||||
-rw-r--r-- | noncore/multimedia/opieplayer2/videowidget.cpp | 7 |
4 files changed, 12 insertions, 12 deletions
diff --git a/noncore/multimedia/opieplayer2/audiowidget.cpp b/noncore/multimedia/opieplayer2/audiowidget.cpp index 4301a67..d083273 100644 --- a/noncore/multimedia/opieplayer2/audiowidget.cpp +++ b/noncore/multimedia/opieplayer2/audiowidget.cpp | |||
@@ -360,54 +360,49 @@ void AudioWidget::skipBack() { | |||
360 | startTimer( 50 ); | 360 | startTimer( 50 ); |
361 | mediaPlayerState.setPosition( mediaPlayerState.position() - 2 ); | 361 | mediaPlayerState.setPosition( mediaPlayerState.position() - 2 ); |
362 | } | 362 | } |
363 | 363 | ||
364 | 364 | ||
365 | 365 | ||
366 | void AudioWidget::stopSkip() { | 366 | void AudioWidget::stopSkip() { |
367 | killTimers(); | 367 | killTimers(); |
368 | } | 368 | } |
369 | 369 | ||
370 | 370 | ||
371 | void AudioWidget::timerEvent( QTimerEvent * ) { | 371 | void AudioWidget::timerEvent( QTimerEvent * ) { |
372 | if ( skipDirection == +1 ) { | 372 | if ( skipDirection == +1 ) { |
373 | mediaPlayerState.setPosition( mediaPlayerState.position() + 2 ); | 373 | mediaPlayerState.setPosition( mediaPlayerState.position() + 2 ); |
374 | } else if ( skipDirection == -1 ) { | 374 | } else if ( skipDirection == -1 ) { |
375 | mediaPlayerState.setPosition( mediaPlayerState.position() - 2 ); | 375 | mediaPlayerState.setPosition( mediaPlayerState.position() - 2 ); |
376 | } | 376 | } |
377 | } | 377 | } |
378 | 378 | ||
379 | 379 | ||
380 | void AudioWidget::mouseMoveEvent( QMouseEvent *event ) { | 380 | void AudioWidget::mouseMoveEvent( QMouseEvent *event ) { |
381 | for ( unsigned int i = 0; i < buttons.size(); i++ ) { | 381 | for ( unsigned int i = 0; i < buttons.size(); i++ ) { |
382 | if ( event->state() == QMouseEvent::LeftButton ) { | 382 | if ( event->state() == QMouseEvent::LeftButton ) { |
383 | // The test to see if the mouse click is inside the button or not | 383 | // The test to see if the mouse click is inside the button or not |
384 | int x = event->pos().x() - upperLeftOfButtonMask.x(); | 384 | bool isOnButton = isOverButton( event->pos() - upperLeftOfButtonMask, i ); |
385 | int y = event->pos().y() - upperLeftOfButtonMask.y(); | ||
386 | |||
387 | bool isOnButton = ( x > 0 && y > 0 && x < buttonMask.width() | ||
388 | && y < buttonMask.height() | ||
389 | && buttonMask.pixelIndex( x, y ) == i + 1 ); | ||
390 | 385 | ||
391 | if ( isOnButton && !buttons[i].isHeld ) { | 386 | if ( isOnButton && !buttons[i].isHeld ) { |
392 | buttons[i].isHeld = TRUE; | 387 | buttons[i].isHeld = TRUE; |
393 | toggleButton(i); | 388 | toggleButton(i); |
394 | switch (i) { | 389 | switch (i) { |
395 | case VolumeUp: | 390 | case VolumeUp: |
396 | emit moreClicked(); | 391 | emit moreClicked(); |
397 | return; | 392 | return; |
398 | case VolumeDown: | 393 | case VolumeDown: |
399 | emit lessClicked(); | 394 | emit lessClicked(); |
400 | return; | 395 | return; |
401 | case Forward: | 396 | case Forward: |
402 | emit forwardClicked(); | 397 | emit forwardClicked(); |
403 | return; | 398 | return; |
404 | case Back: | 399 | case Back: |
405 | emit backClicked(); | 400 | emit backClicked(); |
406 | return; | 401 | return; |
407 | } | 402 | } |
408 | } else if ( !isOnButton && buttons[i].isHeld ) { | 403 | } else if ( !isOnButton && buttons[i].isHeld ) { |
409 | buttons[i].isHeld = FALSE; | 404 | buttons[i].isHeld = FALSE; |
410 | toggleButton(i); | 405 | toggleButton(i); |
411 | } | 406 | } |
412 | } else { | 407 | } else { |
413 | if ( buttons[i].isHeld ) { | 408 | if ( buttons[i].isHeld ) { |
diff --git a/noncore/multimedia/opieplayer2/mediawidget.cpp b/noncore/multimedia/opieplayer2/mediawidget.cpp index a1b292e..1d18d6f 100644 --- a/noncore/multimedia/opieplayer2/mediawidget.cpp +++ b/noncore/multimedia/opieplayer2/mediawidget.cpp | |||
@@ -39,26 +39,34 @@ MediaWidget::~MediaWidget() | |||
39 | { | 39 | { |
40 | } | 40 | } |
41 | 41 | ||
42 | void MediaWidget::closeEvent( QCloseEvent * ) | 42 | void MediaWidget::closeEvent( QCloseEvent * ) |
43 | { | 43 | { |
44 | mediaPlayerState.setList(); | 44 | mediaPlayerState.setList(); |
45 | } | 45 | } |
46 | 46 | ||
47 | void MediaWidget::handleCommand( Command command, bool buttonDown ) | 47 | void MediaWidget::handleCommand( Command command, bool buttonDown ) |
48 | { | 48 | { |
49 | switch ( command ) { | 49 | switch ( command ) { |
50 | case Play: mediaPlayerState.togglePaused(); | 50 | case Play: mediaPlayerState.togglePaused(); |
51 | case Stop: mediaPlayerState.setPlaying(FALSE); return; | 51 | case Stop: mediaPlayerState.setPlaying(FALSE); return; |
52 | case Next: if( playList.currentTab() == PlayListWidget::CurrentPlayList ) mediaPlayerState.setNext(); return; | 52 | case Next: if( playList.currentTab() == PlayListWidget::CurrentPlayList ) mediaPlayerState.setNext(); return; |
53 | case Previous: if( playList.currentTab() == PlayListWidget::CurrentPlayList ) mediaPlayerState.setPrev(); return; | 53 | case Previous: if( playList.currentTab() == PlayListWidget::CurrentPlayList ) mediaPlayerState.setPrev(); return; |
54 | case Loop: mediaPlayerState.setLooping( buttonDown ); return; | 54 | case Loop: mediaPlayerState.setLooping( buttonDown ); return; |
55 | case VolumeUp: emit moreReleased(); return; | 55 | case VolumeUp: emit moreReleased(); return; |
56 | case VolumeDown: emit lessReleased(); return; | 56 | case VolumeDown: emit lessReleased(); return; |
57 | case PlayList: mediaPlayerState.setList(); return; | 57 | case PlayList: mediaPlayerState.setList(); return; |
58 | case Forward: emit forwardReleased(); return; | 58 | case Forward: emit forwardReleased(); return; |
59 | case Back: emit backReleased(); return; | 59 | case Back: emit backReleased(); return; |
60 | } | 60 | } |
61 | } | 61 | } |
62 | 62 | ||
63 | bool MediaWidget::isOverButton( const QPoint &position, int buttonId ) const | ||
64 | { | ||
65 | return ( position.x() > 0 && position.y() > 0 && | ||
66 | position.x() < buttonMask.width() && | ||
67 | position.y() < buttonMask.height() && | ||
68 | buttonMask.pixelIndex( position.x(), position.y() ) == buttonId + 1 ); | ||
69 | } | ||
70 | |||
63 | /* vim: et sw=4 ts=4 | 71 | /* vim: et sw=4 ts=4 |
64 | */ | 72 | */ |
diff --git a/noncore/multimedia/opieplayer2/mediawidget.h b/noncore/multimedia/opieplayer2/mediawidget.h index 7e6cb3b..6e12a3b 100644 --- a/noncore/multimedia/opieplayer2/mediawidget.h +++ b/noncore/multimedia/opieplayer2/mediawidget.h | |||
@@ -44,37 +44,39 @@ public: | |||
44 | bool isHeld : 1; | 44 | bool isHeld : 1; |
45 | bool isDown : 1; | 45 | bool isDown : 1; |
46 | }; | 46 | }; |
47 | typedef std::vector<Button> ButtonVector; | 47 | typedef std::vector<Button> ButtonVector; |
48 | 48 | ||
49 | MediaWidget( PlayListWidget &_playList, MediaPlayerState &_mediaPlayerState, QWidget *parent = 0, const char *name = 0 ); | 49 | MediaWidget( PlayListWidget &_playList, MediaPlayerState &_mediaPlayerState, QWidget *parent = 0, const char *name = 0 ); |
50 | virtual ~MediaWidget(); | 50 | virtual ~MediaWidget(); |
51 | 51 | ||
52 | public slots: | 52 | public slots: |
53 | virtual void setDisplayType( MediaPlayerState::DisplayType displayType ) = 0; | 53 | virtual void setDisplayType( MediaPlayerState::DisplayType displayType ) = 0; |
54 | virtual void setLength( long length ) = 0; | 54 | virtual void setLength( long length ) = 0; |
55 | virtual void setPlaying( bool playing ) = 0; | 55 | virtual void setPlaying( bool playing ) = 0; |
56 | 56 | ||
57 | signals: | 57 | signals: |
58 | void moreReleased(); | 58 | void moreReleased(); |
59 | void lessReleased(); | 59 | void lessReleased(); |
60 | void forwardReleased(); | 60 | void forwardReleased(); |
61 | void backReleased(); | 61 | void backReleased(); |
62 | 62 | ||
63 | protected: | 63 | protected: |
64 | virtual void closeEvent( QCloseEvent * ); | 64 | virtual void closeEvent( QCloseEvent * ); |
65 | 65 | ||
66 | void handleCommand( Command command, bool buttonDown ); | 66 | void handleCommand( Command command, bool buttonDown ); |
67 | 67 | ||
68 | bool isOverButton( const QPoint &position, int buttonId ) const; | ||
69 | |||
68 | MediaPlayerState &mediaPlayerState; | 70 | MediaPlayerState &mediaPlayerState; |
69 | PlayListWidget &playList; | 71 | PlayListWidget &playList; |
70 | 72 | ||
71 | ButtonVector buttons; | 73 | ButtonVector buttons; |
72 | 74 | ||
73 | QImage buttonMask; | 75 | QImage buttonMask; |
74 | 76 | ||
75 | QPoint upperLeftOfButtonMask; | 77 | QPoint upperLeftOfButtonMask; |
76 | }; | 78 | }; |
77 | 79 | ||
78 | #endif // MEDIAWIDGET_H | 80 | #endif // MEDIAWIDGET_H |
79 | /* vim: et sw=4 ts=4 | 81 | /* vim: et sw=4 ts=4 |
80 | */ | 82 | */ |
diff --git a/noncore/multimedia/opieplayer2/videowidget.cpp b/noncore/multimedia/opieplayer2/videowidget.cpp index 6ab6d7b..6451ac4 100644 --- a/noncore/multimedia/opieplayer2/videowidget.cpp +++ b/noncore/multimedia/opieplayer2/videowidget.cpp | |||
@@ -261,54 +261,49 @@ void VideoWidget::setToggleButton( int i, bool down ) { | |||
261 | if ( down != buttons[i].isDown ) { | 261 | if ( down != buttons[i].isDown ) { |
262 | toggleButton( i ); | 262 | toggleButton( i ); |
263 | } | 263 | } |
264 | } | 264 | } |
265 | 265 | ||
266 | void VideoWidget::toggleButton( int i ) { | 266 | void VideoWidget::toggleButton( int i ) { |
267 | buttons[i].isDown = !buttons[i].isDown; | 267 | buttons[i].isDown = !buttons[i].isDown; |
268 | QPainter p(this); | 268 | QPainter p(this); |
269 | paintButton ( &p, i ); | 269 | paintButton ( &p, i ); |
270 | } | 270 | } |
271 | 271 | ||
272 | void VideoWidget::paintButton( QPainter *p, int i ) { | 272 | void VideoWidget::paintButton( QPainter *p, int i ) { |
273 | 273 | ||
274 | if ( buttons[i].isDown ) { | 274 | if ( buttons[i].isDown ) { |
275 | p->drawPixmap( upperLeftOfButtonMask, *buttonPixDown[i] ); | 275 | p->drawPixmap( upperLeftOfButtonMask, *buttonPixDown[i] ); |
276 | } else { | 276 | } else { |
277 | p->drawPixmap( upperLeftOfButtonMask, *buttonPixUp[i] ); | 277 | p->drawPixmap( upperLeftOfButtonMask, *buttonPixUp[i] ); |
278 | } | 278 | } |
279 | } | 279 | } |
280 | 280 | ||
281 | void VideoWidget::mouseMoveEvent( QMouseEvent *event ) { | 281 | void VideoWidget::mouseMoveEvent( QMouseEvent *event ) { |
282 | for ( unsigned int i = 0; i < buttons.size(); i++ ) { | 282 | for ( unsigned int i = 0; i < buttons.size(); i++ ) { |
283 | if ( event->state() == QMouseEvent::LeftButton ) { | 283 | if ( event->state() == QMouseEvent::LeftButton ) { |
284 | // The test to see if the mouse click is inside the button or not | 284 | // The test to see if the mouse click is inside the button or not |
285 | int x = event->pos().x() - upperLeftOfButtonMask.x(); | 285 | bool isOnButton = isOverButton( event->pos() - upperLeftOfButtonMask, i ); |
286 | int y = event->pos().y() - upperLeftOfButtonMask.y(); | ||
287 | |||
288 | bool isOnButton = ( x > 0 && y > 0 && x < buttonMask.width() | ||
289 | && y < buttonMask.height() | ||
290 | && buttonMask.pixelIndex( x, y ) == i + 1 ); | ||
291 | 286 | ||
292 | if ( isOnButton && !buttons[i].isHeld ) { | 287 | if ( isOnButton && !buttons[i].isHeld ) { |
293 | buttons[i].isHeld = TRUE; | 288 | buttons[i].isHeld = TRUE; |
294 | toggleButton(i); | 289 | toggleButton(i); |
295 | 290 | ||
296 | switch (i) { | 291 | switch (i) { |
297 | case VideoVolUp: | 292 | case VideoVolUp: |
298 | emit moreClicked(); | 293 | emit moreClicked(); |
299 | return; | 294 | return; |
300 | case VideoVolDown: | 295 | case VideoVolDown: |
301 | emit lessClicked(); | 296 | emit lessClicked(); |
302 | return; | 297 | return; |
303 | } | 298 | } |
304 | } else if ( !isOnButton && buttons[i].isHeld ) { | 299 | } else if ( !isOnButton && buttons[i].isHeld ) { |
305 | buttons[i].isHeld = FALSE; | 300 | buttons[i].isHeld = FALSE; |
306 | toggleButton(i); | 301 | toggleButton(i); |
307 | } | 302 | } |
308 | } else { | 303 | } else { |
309 | 304 | ||
310 | if ( buttons[i].isHeld ) { | 305 | if ( buttons[i].isHeld ) { |
311 | buttons[i].isHeld = FALSE; | 306 | buttons[i].isHeld = FALSE; |
312 | if ( !buttons[i].isToggle ) { | 307 | if ( !buttons[i].isToggle ) { |
313 | setToggleButton( i, FALSE ); | 308 | setToggleButton( i, FALSE ); |
314 | } | 309 | } |