From 2d2d57e3b7988f4246319cdfd0dc7fa90110db8e Mon Sep 17 00:00:00 2001 From: simon Date: Mon, 09 Dec 2002 20:02:52 +0000 Subject: - reworked the mouse event handling to be much simpler - fixed missing return in Play case in handleCommand, which accidentially broke pausing - accept the key events we receive in the audioWidget - commented out suspicious connect to pauseCheck in mediaplayer, which broke pausing via space bar --- (limited to 'noncore/multimedia/opieplayer2/mediawidget.cpp') diff --git a/noncore/multimedia/opieplayer2/mediawidget.cpp b/noncore/multimedia/opieplayer2/mediawidget.cpp index 439ba2e..4c4cead 100644 --- a/noncore/multimedia/opieplayer2/mediawidget.cpp +++ b/noncore/multimedia/opieplayer2/mediawidget.cpp @@ -69,58 +69,52 @@ void MediaWidget::paintEvent( QPaintEvent *pe ) } } -void MediaWidget::mouseMoveEvent( QMouseEvent *event ) -{ - for ( ButtonVector::iterator it = buttons.begin(); it != buttons.end(); ++it ) { - Button &button = *it; - Command command = button.command; - - if ( event->state() == QMouseEvent::LeftButton ) { - // The test to see if the mouse click is inside the button or not - bool isOnButton = isOverButton( event->pos() - upperLeftOfButtonMask, command ); - - if ( isOnButton && !button.isHeld ) { - button.isHeld = TRUE; - toggleButton( button ); - switch ( command ) { - case VolumeUp: - emit moreClicked(); - return; - case VolumeDown: - emit lessClicked(); - return; - case Forward: - emit forwardClicked(); - return; - case Back: - emit backClicked(); - return; - default: break; - } - } else if ( !isOnButton && button.isHeld ) { - button.isHeld = FALSE; - toggleButton( button ); - } - } else { - if ( button.isHeld ) { - button.isHeld = FALSE; - if ( button.type != ToggleButton ) { - setToggleButton( button, FALSE ); - } - handleCommand( command, button.isDown ); - } - } - } +MediaWidget::Button *MediaWidget::buttonAt( const QPoint &position ) +{ + if ( position.x() <= 0 || position.y() <= 0 || + position.x() >= buttonMask.width() || + position.y() >= buttonMask.height() ) + return 0; + + int pixelIdx = buttonMask.pixelIndex( position.x(), position.y() ); + for ( ButtonVector::iterator it = buttons.begin(); it != buttons.end(); ++it ) + if ( it->command + 1 == pixelIdx ) + return &( *it ); + + return 0; } void MediaWidget::mousePressEvent( QMouseEvent *event ) { - mouseMoveEvent( event ); + Button *button = buttonAt( event->pos() - upperLeftOfButtonMask ); + + if ( !button ) { + QWidget::mousePressEvent( event ); + return; + } + + switch ( button->command ) { + case VolumeUp: emit moreClicked(); return; + case VolumeDown: emit lessClicked(); return; + case Back: emit backClicked(); return; + case Forward: emit forwardClicked(); return; + default: break; + } } void MediaWidget::mouseReleaseEvent( QMouseEvent *event ) { - mouseMoveEvent( event ); + Button *button = buttonAt( event->pos() - upperLeftOfButtonMask ); + + if ( !button ) { + QWidget::mouseReleaseEvent( event ); + return; + } + + if ( button->type == ToggleButton ) + toggleButton( *button ); + + handleCommand( button->command, button->isDown ); } void MediaWidget::makeVisible() @@ -130,7 +124,7 @@ void MediaWidget::makeVisible() void MediaWidget::handleCommand( Command command, bool buttonDown ) { switch ( command ) { - case Play: mediaPlayerState.togglePaused(); + case Play: mediaPlayerState.togglePaused(); return; case Stop: mediaPlayerState.setPlaying(FALSE); return; case Next: if( playList.currentTab() == PlayListWidget::CurrentPlayList ) mediaPlayerState.setNext(); return; case Previous: if( playList.currentTab() == PlayListWidget::CurrentPlayList ) mediaPlayerState.setPrev(); return; -- cgit v0.9.0.2