author | simon <simon> | 2002-12-08 22:47:39 (UTC) |
---|---|---|
committer | simon <simon> | 2002-12-08 22:47:39 (UTC) |
commit | 786bc677f61983414df8a4613cc525c4bcd2a054 (patch) (side-by-side diff) | |
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 @@ -336,102 +336,97 @@ void AudioWidget::setToggleButton( int i, bool down ) { void AudioWidget::toggleButton( int i ) { buttons[i].isDown = !buttons[i].isDown; QPainter p(this); paintButton ( &p, i ); } void AudioWidget::paintButton( QPainter *p, int i ) { if ( buttons[i].isDown ) { p->drawPixmap( upperLeftOfButtonMask, *buttonPixDown[i] ); } else { p->drawPixmap( upperLeftOfButtonMask, *buttonPixUp[i] ); } } void AudioWidget::skipFor() { skipDirection = +1; startTimer( 50 ); mediaPlayerState.setPosition( mediaPlayerState.position() + 2 ); } void AudioWidget::skipBack() { skipDirection = -1; startTimer( 50 ); mediaPlayerState.setPosition( mediaPlayerState.position() - 2 ); } void AudioWidget::stopSkip() { killTimers(); } void AudioWidget::timerEvent( QTimerEvent * ) { if ( skipDirection == +1 ) { mediaPlayerState.setPosition( mediaPlayerState.position() + 2 ); } else if ( skipDirection == -1 ) { mediaPlayerState.setPosition( mediaPlayerState.position() - 2 ); } } void AudioWidget::mouseMoveEvent( QMouseEvent *event ) { for ( unsigned int i = 0; i < buttons.size(); i++ ) { if ( event->state() == QMouseEvent::LeftButton ) { // The test to see if the mouse click is inside the button or not - int x = event->pos().x() - upperLeftOfButtonMask.x(); - int y = event->pos().y() - upperLeftOfButtonMask.y(); - - bool isOnButton = ( x > 0 && y > 0 && x < buttonMask.width() - && y < buttonMask.height() - && buttonMask.pixelIndex( x, y ) == i + 1 ); + bool isOnButton = isOverButton( event->pos() - upperLeftOfButtonMask, i ); if ( isOnButton && !buttons[i].isHeld ) { buttons[i].isHeld = TRUE; toggleButton(i); switch (i) { case VolumeUp: emit moreClicked(); return; case VolumeDown: emit lessClicked(); return; case Forward: emit forwardClicked(); return; case Back: emit backClicked(); return; } } else if ( !isOnButton && buttons[i].isHeld ) { buttons[i].isHeld = FALSE; toggleButton(i); } } else { if ( buttons[i].isHeld ) { buttons[i].isHeld = FALSE; if ( !buttons[i].isToggle ) { setToggleButton( i, FALSE ); } qDebug("mouseEvent %d", i); handleCommand( static_cast<Command>( i ), buttons[ i ].isDown ); } } } } void AudioWidget::mousePressEvent( QMouseEvent *event ) { mouseMoveEvent( event ); } void AudioWidget::mouseReleaseEvent( QMouseEvent *event ) { mouseMoveEvent( event ); } void AudioWidget::showEvent( QShowEvent* ) { QMouseEvent event( QEvent::MouseMove, QPoint( 0, 0 ), 0, 0 ); 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 @@ -15,50 +15,58 @@ Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include "mediawidget.h" #include "playlistwidget.h" MediaWidget::MediaWidget( PlayListWidget &_playList, MediaPlayerState &_mediaPlayerState, QWidget *parent, const char *name ) : QWidget( parent, name ), mediaPlayerState( _mediaPlayerState ), playList( _playList ) { connect( &mediaPlayerState, SIGNAL( displayTypeChanged( MediaPlayerState::DisplayType ) ), this, SLOT( setDisplayType( MediaPlayerState::DisplayType ) ) ); connect( &mediaPlayerState, SIGNAL( lengthChanged( long ) ), this, SLOT( setLength( long ) ) ); connect( &mediaPlayerState, SIGNAL( playingToggled( bool ) ), this, SLOT( setPlaying( bool ) ) ); } MediaWidget::~MediaWidget() { } void MediaWidget::closeEvent( QCloseEvent * ) { mediaPlayerState.setList(); } void MediaWidget::handleCommand( Command command, bool buttonDown ) { switch ( command ) { case Play: mediaPlayerState.togglePaused(); 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; case Loop: mediaPlayerState.setLooping( buttonDown ); return; case VolumeUp: emit moreReleased(); return; case VolumeDown: emit lessReleased(); return; case PlayList: mediaPlayerState.setList(); return; case Forward: emit forwardReleased(); return; case Back: emit backReleased(); return; } } +bool MediaWidget::isOverButton( const QPoint &position, int buttonId ) const +{ + return ( position.x() > 0 && position.y() > 0 && + position.x() < buttonMask.width() && + position.y() < buttonMask.height() && + buttonMask.pixelIndex( position.x(), position.y() ) == buttonId + 1 ); +} + /* vim: et sw=4 ts=4 */ 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 @@ -20,61 +20,63 @@ Boston, MA 02111-1307, USA. */ #ifndef MEDIAWIDGET_H #define MEDIAWIDGET_H #include <qwidget.h> #include "mediaplayerstate.h" #include "playlistwidget.h" #include <vector> class MediaWidget : public QWidget { Q_OBJECT public: enum Command { Play = 0, Stop, Next, Previous, VolumeUp, VolumeDown, Loop, PlayList, Forward, Back }; struct Button { Button() : isToggle( false ), isHeld( false ), isDown( false ) {} bool isToggle : 1; bool isHeld : 1; bool isDown : 1; }; typedef std::vector<Button> ButtonVector; MediaWidget( PlayListWidget &_playList, MediaPlayerState &_mediaPlayerState, QWidget *parent = 0, const char *name = 0 ); virtual ~MediaWidget(); public slots: virtual void setDisplayType( MediaPlayerState::DisplayType displayType ) = 0; virtual void setLength( long length ) = 0; virtual void setPlaying( bool playing ) = 0; signals: void moreReleased(); void lessReleased(); void forwardReleased(); void backReleased(); protected: virtual void closeEvent( QCloseEvent * ); void handleCommand( Command command, bool buttonDown ); + bool isOverButton( const QPoint &position, int buttonId ) const; + MediaPlayerState &mediaPlayerState; PlayListWidget &playList; ButtonVector buttons; QImage buttonMask; QPoint upperLeftOfButtonMask; }; #endif // MEDIAWIDGET_H /* vim: et sw=4 ts=4 */ 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 @@ -237,102 +237,97 @@ void VideoWidget::setDisplayType( MediaPlayerState::DisplayType displayType ) // Effectively blank the view next time we show it so it looks nicer scaledWidth = 0; scaledHeight = 0; hide(); } void VideoWidget::updateSlider( long i, long max ) { // Will flicker too much if we don't do this if ( max == 0 ) { return; } int width = slider->width(); int val = int((double)i * width / max); if ( !mediaPlayerState.isFullscreen() && !videoSliderBeingMoved ) { if ( slider->value() != val ) { slider->setValue( val ); } if ( slider->maxValue() != width ) { slider->setMaxValue( width ); } } } void VideoWidget::setToggleButton( int i, bool down ) { if ( down != buttons[i].isDown ) { toggleButton( i ); } } void VideoWidget::toggleButton( int i ) { buttons[i].isDown = !buttons[i].isDown; QPainter p(this); paintButton ( &p, i ); } void VideoWidget::paintButton( QPainter *p, int i ) { if ( buttons[i].isDown ) { p->drawPixmap( upperLeftOfButtonMask, *buttonPixDown[i] ); } else { p->drawPixmap( upperLeftOfButtonMask, *buttonPixUp[i] ); } } void VideoWidget::mouseMoveEvent( QMouseEvent *event ) { for ( unsigned int i = 0; i < buttons.size(); i++ ) { if ( event->state() == QMouseEvent::LeftButton ) { // The test to see if the mouse click is inside the button or not - int x = event->pos().x() - upperLeftOfButtonMask.x(); - int y = event->pos().y() - upperLeftOfButtonMask.y(); - - bool isOnButton = ( x > 0 && y > 0 && x < buttonMask.width() - && y < buttonMask.height() - && buttonMask.pixelIndex( x, y ) == i + 1 ); + bool isOnButton = isOverButton( event->pos() - upperLeftOfButtonMask, i ); if ( isOnButton && !buttons[i].isHeld ) { buttons[i].isHeld = TRUE; toggleButton(i); switch (i) { case VideoVolUp: emit moreClicked(); return; case VideoVolDown: emit lessClicked(); return; } } else if ( !isOnButton && buttons[i].isHeld ) { buttons[i].isHeld = FALSE; toggleButton(i); } } else { if ( buttons[i].isHeld ) { buttons[i].isHeld = FALSE; if ( !buttons[i].isToggle ) { setToggleButton( i, FALSE ); } switch(i) { case VideoPlay: { if( mediaPlayerState.isPaused() ) { setToggleButton( i, FALSE ); mediaPlayerState.setPaused( FALSE ); return; } else if( !mediaPlayerState.isPaused() ) { setToggleButton( i, TRUE ); mediaPlayerState.setPaused( TRUE ); return; } else { return; } } case VideoStop: mediaPlayerState.setPlaying( FALSE ); return; case VideoNext: if( playList.currentTab() == PlayListWidget::CurrentPlayList ) mediaPlayerState.setNext(); return; case VideoPrevious: if( playList.currentTab() == PlayListWidget::CurrentPlayList ) mediaPlayerState.setPrev(); return; case VideoVolUp: emit moreReleased(); return; case VideoVolDown: emit lessReleased(); return; case VideoFullscreen: mediaPlayerState.setFullscreen( TRUE ); makeVisible(); return; } |