summaryrefslogtreecommitdiff
authorsimon <simon>2002-12-08 22:47:39 (UTC)
committer simon <simon>2002-12-08 22:47:39 (UTC)
commit786bc677f61983414df8a4613cc525c4bcd2a054 (patch) (side-by-side diff)
treec39a2a1691ffc8d813a496cb47c00b8ede47ea30
parent8b72df0bb25ca5a0791756b2444fc6a1ce361082 (diff)
downloadopie-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
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/multimedia/opieplayer2/audiowidget.cpp7
-rw-r--r--noncore/multimedia/opieplayer2/mediawidget.cpp8
-rw-r--r--noncore/multimedia/opieplayer2/mediawidget.h2
-rw-r--r--noncore/multimedia/opieplayer2/videowidget.cpp7
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
@@ -372,30 +372,25 @@ 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:
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
@@ -51,14 +51,22 @@ void MediaWidget::handleCommand( Command command, bool buttonDown )
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
@@ -56,24 +56,26 @@ public slots:
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
@@ -273,30 +273,25 @@ 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;