author | simon <simon> | 2002-12-09 20:02:52 (UTC) |
---|---|---|
committer | simon <simon> | 2002-12-09 20:02:52 (UTC) |
commit | 2d2d57e3b7988f4246319cdfd0dc7fa90110db8e (patch) (side-by-side diff) | |
tree | fb4dfb832e2630e7da1cc57e92ba6c62ead22dee | |
parent | 046f040efcb0f313818d1dbb1dc1db9021678175 (diff) | |
download | opie-2d2d57e3b7988f4246319cdfd0dc7fa90110db8e.zip opie-2d2d57e3b7988f4246319cdfd0dc7fa90110db8e.tar.gz opie-2d2d57e3b7988f4246319cdfd0dc7fa90110db8e.tar.bz2 |
- 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
-rw-r--r-- | noncore/multimedia/opieplayer2/audiowidget.cpp | 8 | ||||
-rw-r--r-- | noncore/multimedia/opieplayer2/mediaplayer.cpp | 3 | ||||
-rw-r--r-- | noncore/multimedia/opieplayer2/mediawidget.cpp | 84 | ||||
-rw-r--r-- | noncore/multimedia/opieplayer2/mediawidget.h | 3 |
4 files changed, 51 insertions, 47 deletions
diff --git a/noncore/multimedia/opieplayer2/audiowidget.cpp b/noncore/multimedia/opieplayer2/audiowidget.cpp index 5986a72..8e9bbf1 100644 --- a/noncore/multimedia/opieplayer2/audiowidget.cpp +++ b/noncore/multimedia/opieplayer2/audiowidget.cpp @@ -157,235 +157,243 @@ AudioWidget::AudioWidget( PlayListWidget &playList, MediaPlayerState &mediaPlaye connect( this, SIGNAL( forwardClicked() ), this, SLOT( skipFor() ) ); connect( this, SIGNAL( backClicked() ), this, SLOT( skipBack() ) ); connect( this, SIGNAL( forwardReleased() ), this, SLOT( stopSkip() ) ); connect( this, SIGNAL( backReleased() ), this, SLOT( stopSkip() ) ); // Intialise state setLength( mediaPlayerState.length() ); setPosition( mediaPlayerState.position() ); setLooping( mediaPlayerState.isFullscreen() ); // setPaused( mediaPlayerState->paused() ); setPlaying( mediaPlayerState.isPlaying() ); } AudioWidget::~AudioWidget() { // mediaPlayerState->setPlaying(false); } namespace { QPixmap combineImageWithBackground( QImage img, QPixmap bg, QPoint offset ) { QPixmap pix( img.width(), img.height() ); QPainter p( &pix ); p.drawTiledPixmap( pix.rect(), bg, offset ); p.drawImage( 0, 0, img ); return pix; } QPixmap maskPixToMask( QPixmap pix, QBitmap mask ) { QPixmap pixmap( pix ); pixmap.setMask( mask ); return pixmap; } }; void AudioWidget::resizeEvent( QResizeEvent * ) { int h = height(); int w = width(); songInfo.setGeometry( QRect( 2, 2, w - 4, 20 ) ); slider.setFixedWidth( w - 110 ); slider.setGeometry( QRect( 15, h - 22, w - 90, 20 ) ); slider.setBackgroundOrigin( QWidget::ParentOrigin ); time.setGeometry( QRect( w - 85, h - 30, 70, 20 ) ); upperLeftOfButtonMask.rx() = ( w - imgUp.width() ) / 2; upperLeftOfButtonMask.ry() = (( h - imgUp.height() ) / 2) - 10; QPoint p = upperLeftOfButtonMask; QPixmap pixUp = combineImageWithBackground( imgUp, backgroundPixmap, p ); QPixmap pixDn = combineImageWithBackground( imgDn, backgroundPixmap, p ); for ( uint i = 0; i < buttons.size(); i++ ) { if ( !buttons[i].mask.isNull() ) { buttons[i].pixUp = maskPixToMask( pixUp, buttons[i].mask ); buttons[i].pixDown = maskPixToMask( pixDn, buttons[i].mask ); } } } void AudioWidget::sliderPressed() { audioSliderBeingMoved = TRUE; } void AudioWidget::sliderReleased() { audioSliderBeingMoved = FALSE; if ( slider.width() == 0 ) return; long val = long((double)slider.value() * mediaPlayerState.length() / slider.width()); mediaPlayerState.setPosition( val ); } void AudioWidget::setPosition( long i ) { // qDebug("<<<<<<<<<<<<<<<<<<<<<<<<set position %d",i); updateSlider( i, mediaPlayerState.length() ); } void AudioWidget::setLength( long max ) { updateSlider( mediaPlayerState.position(), max ); } void AudioWidget::setDisplayType( MediaPlayerState::DisplayType mediaType ) { if ( mediaType == MediaPlayerState::Audio ) { // startTimer( 150 ); showMaximized(); return; } killTimers(); hide(); } void AudioWidget::setSeekable( bool isSeekable ) { if ( !isSeekable ) { qDebug("<<<<<<<<<<<<<<file is STREAMING>>>>>>>>>>>>>>>>>>>"); if( !slider.isHidden()) { slider.hide(); } disconnect( &mediaPlayerState, SIGNAL( positionChanged(long) ),this, SLOT( setPosition(long) ) ); disconnect( &mediaPlayerState, SIGNAL( positionUpdated(long) ),this, SLOT( setPosition(long) ) ); disconnect( &slider, SIGNAL( sliderPressed() ), this, SLOT( sliderPressed() ) ); disconnect( &slider, SIGNAL( sliderReleased() ), this, SLOT( sliderReleased() ) ); } else { // this stops the slider from being moved, thus // does not stop stream when it reaches the end slider.show(); qDebug( " CONNECT SET POSTION " ); connect( &mediaPlayerState, SIGNAL( positionChanged(long) ),this, SLOT( setPosition(long) ) ); connect( &mediaPlayerState, SIGNAL( positionUpdated(long) ),this, SLOT( setPosition(long) ) ); connect( &slider, SIGNAL( sliderPressed() ), this, SLOT( sliderPressed() ) ); connect( &slider, SIGNAL( sliderReleased() ), this, SLOT( sliderReleased() ) ); } } static QString timeAsString( long length ) { int minutes = length / 60; int seconds = length % 60; return QString("%1:%2%3").arg( minutes ).arg( seconds / 10 ).arg( seconds % 10 ); } void AudioWidget::updateSlider( long i, long max ) { time.setText( timeAsString( i ) + " / " + timeAsString( max ) ); // qDebug( timeAsString( i ) + " / " + timeAsString( max ) ) ; if ( max == 0 ) { return; } // Will flicker too much if we don't do this // Scale to something reasonable int width = slider.width(); int val = int((double)i * width / max); if ( !audioSliderBeingMoved ) { if ( slider.value() != val ) { slider.setValue( val ); } if ( slider.maxValue() != width ) { slider.setMaxValue( width ); } } } 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::showEvent( QShowEvent* ) { QMouseEvent event( QEvent::MouseMove, QPoint( 0, 0 ), 0, 0 ); mouseMoveEvent( &event ); } void AudioWidget::keyReleaseEvent( QKeyEvent *e) { switch ( e->key() ) { ////////////////////////////// Zaurus keys case Key_Home: break; case Key_F9: //activity hide(); // qDebug("Audio F9"); + e->accept(); break; case Key_F10: //contacts break; case Key_F11: //menu mediaPlayerState.toggleBlank(); + e->accept(); break; case Key_F12: //home break; case Key_F13: //mail mediaPlayerState.toggleBlank(); + e->accept(); break; case Key_Space: { + e->accept(); mediaPlayerState.togglePaused(); } break; case Key_Down: // toggleButton(6); emit lessClicked(); emit lessReleased(); // toggleButton(6); + e->accept(); break; case Key_Up: // toggleButton(5); emit moreClicked(); emit moreReleased(); // toggleButton(5); + e->accept(); break; case Key_Right: // toggleButton(3); mediaPlayerState.setNext(); // toggleButton(3); + e->accept(); break; case Key_Left: // toggleButton(4); mediaPlayerState.setPrev(); // toggleButton(4); + e->accept(); break; case Key_Escape: { } break; }; } diff --git a/noncore/multimedia/opieplayer2/mediaplayer.cpp b/noncore/multimedia/opieplayer2/mediaplayer.cpp index ed7e37f..e1bfc2d 100644 --- a/noncore/multimedia/opieplayer2/mediaplayer.cpp +++ b/noncore/multimedia/opieplayer2/mediaplayer.cpp @@ -1,240 +1,241 @@ #include <qpe/qpeapplication.h> #include <qpe/qlibrary.h> #include <qpe/resource.h> #include <qpe/config.h> #include <qpe/qcopenvelope_qws.h> #include <qfileinfo.h> #include <qmainwindow.h> #include <qmessagebox.h> #include <qwidgetstack.h> #include <qfile.h> #include "mediaplayer.h" #include "playlistwidget.h" #include "audiowidget.h" #include "videowidget.h" #include "volumecontrol.h" #include "mediaplayerstate.h" // for setBacklight() #include <linux/fb.h> #include <sys/file.h> #include <sys/ioctl.h> #define FBIOBLANK 0x4611 MediaPlayer::MediaPlayer( PlayListWidget &_playList, MediaPlayerState &_mediaPlayerState, QObject *parent, const char *name ) : QObject( parent, name ), volumeDirection( 0 ), mediaPlayerState( _mediaPlayerState ), playList( _playList ) { audioUI = 0; videoUI = 0; xineControl = 0; recreateAudioAndVideoWidgets(); fd=-1;fl=-1; playList.setCaption( tr( "OpiePlayer: Initializating" ) ); qApp->processEvents(); // QPEApplication::grabKeyboard(); // EVIL connect( qApp,SIGNAL( aboutToQuit()),SLOT( cleanUp()) ); connect( &mediaPlayerState, SIGNAL( playingToggled( bool ) ), this, SLOT( setPlaying( bool ) ) ); - connect( &mediaPlayerState, SIGNAL( pausedToggled( bool ) ), this, SLOT( pauseCheck( bool ) ) ); +// What is pauseCheck good for? (Simon) +// connect( &mediaPlayerState, SIGNAL( pausedToggled( bool ) ), this, SLOT( pauseCheck( bool ) ) ); connect( &mediaPlayerState, SIGNAL( next() ), this, SLOT( next() ) ); connect( &mediaPlayerState, SIGNAL( prev() ), this, SLOT( prev() ) ); connect( &mediaPlayerState, SIGNAL( blankToggled( bool ) ), this, SLOT ( blank( bool ) ) ); volControl = new VolumeControl; Config cfg( "OpiePlayer" ); cfg.setGroup("PlayList"); QString currentPlaylist = cfg.readEntry( "CurrentPlaylist", "default"); playList.setCaption( tr( "OpiePlayer: " ) + QFileInfo(currentPlaylist).baseName() ); } MediaPlayer::~MediaPlayer() { delete xineControl; delete audioUI; delete videoUI; delete volControl; } void MediaPlayer::pauseCheck( bool b ) { if ( b && !mediaPlayerState.isPlaying() ) { mediaPlayerState.setPaused( FALSE ); } } void MediaPlayer::play() { mediaPlayerState.setPlaying( FALSE ); mediaPlayerState.setPlaying( TRUE ); } void MediaPlayer::setPlaying( bool play ) { if ( !play ) { return; } if ( mediaPlayerState.isPaused() ) { mediaPlayerState.setPaused( FALSE ); return; } QString tickerText, time, fileName; if ( playList.currentTab() != PlayListWidget::CurrentPlayList ) { //if playing in file list.. play in a different way // random and looping settings enabled causes problems here, // since there is no selected file in the playlist, but a selected file in the file list, // so we remember and shutoff l = mediaPlayerState.isLooping(); if(l) { mediaPlayerState.setLooping( false ); } r = mediaPlayerState.isShuffled(); mediaPlayerState.setShuffled( false ); } PlayListWidget::Entry playListEntry = playList.currentEntry(); fileName = playListEntry.name; xineControl->play( playListEntry.file ); long seconds = mediaPlayerState.length(); time.sprintf("%li:%02i", seconds/60, (int)seconds%60 ); if( fileName.left(4) == "http" ) { fileName = QFileInfo( fileName ).baseName(); if ( xineControl->getMetaInfo().isEmpty() ) { tickerText = tr( " File: " ) + fileName; } else { tickerText = xineControl->getMetaInfo(); } } else { if ( xineControl->getMetaInfo().isEmpty() ) { tickerText = tr( " File: " ) + fileName + tr( ", Length: " ) + time + " "; } else { tickerText = xineControl->getMetaInfo() + " Length: " + time + " "; } } audioUI->setTickerText( tickerText ); } void MediaPlayer::prev() { if( playList.currentTab() == PlayListWidget::CurrentPlayList ) { //if using the playlist if ( playList.prev() ) { play(); } else if ( mediaPlayerState.isLooping() ) { if ( playList.last() ) { play(); } } else { mediaPlayerState.setList(); } } } void MediaPlayer::next() { if(playList.currentTab() == PlayListWidget::CurrentPlayList) { //if using the playlist if ( playList.next() ) { play(); } else if ( mediaPlayerState.isLooping() ) { if ( playList.first() ) { play(); } } else { mediaPlayerState.setList(); } } else { //if playing from file list, let's just stop qDebug("<<<<<<<<<<<<<<<<<stop for filelists"); mediaPlayerState.setPlaying(false); mediaPlayerState.setDisplayType( MediaPlayerState::MediaSelection ); if(l) mediaPlayerState.setLooping(l); if(r) mediaPlayerState.setShuffled(r); } qApp->processEvents(); } void MediaPlayer::startDecreasingVolume() { volumeDirection = -1; startTimer( 100 ); volControl->decVol(2); } void MediaPlayer::startIncreasingVolume() { volumeDirection = +1; startTimer( 100 ); volControl->incVol(2); } bool drawnOnScreenDisplay = FALSE; unsigned int onScreenDisplayVolume = 0; const int yoff = 110; void MediaPlayer::stopChangingVolume() { killTimers(); // Get rid of the on-screen display stuff drawnOnScreenDisplay = FALSE; onScreenDisplayVolume = 0; int w=0; int h=0; if( !xineControl->hasVideo() ) { w = audioUI->width(); h = audioUI->height(); audioUI->repaint( ( w - 200 ) / 2, h - yoff, 200 + 9, 70, FALSE ); } else { w = videoUI->width(); h = videoUI->height(); videoUI->repaint( ( w - 200 ) / 2, h - yoff, 200 + 9, 70, FALSE ); } } void MediaPlayer::timerEvent( QTimerEvent * ) { if ( volumeDirection == +1 ) { volControl->incVol( 2 ); } else if ( volumeDirection == -1 ) { volControl->decVol( 2 ); } // TODO FIXME // huh?? unsigned int v= 0; v = volControl->volume(); v = v / 10; if ( drawnOnScreenDisplay && onScreenDisplayVolume == v ) { return; } int w=0; int h=0; if( !xineControl->hasVideo() ) { w = audioUI->width(); h = audioUI->height(); if ( drawnOnScreenDisplay ) { if ( onScreenDisplayVolume > v ) { audioUI->repaint( ( w - 200 ) / 2 + v * 20 + 0, h - yoff + 40, ( onScreenDisplayVolume - v ) * 20 + 9, 30, FALSE ); } } drawnOnScreenDisplay = TRUE; onScreenDisplayVolume = v; QPainter p( audioUI ); p.setPen( QColor( 0x10, 0xD0, 0x10 ) ); p.setBrush( QColor( 0x10, 0xD0, 0x10 ) ); QFont f; f.setPixelSize( 20 ); f.setBold( TRUE ); p.setFont( f ); 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 @@ -1,200 +1,194 @@ /* Copyright (C) 2002 Simon Hausmann <hausmann@kde.org> (C) 2002 Max Reiss <harlekin@handhelds.org> (C) 2002 L. Potter <ljp@llornkcor.com> (C) 2002 Holger Freyther <zecke@handhelds.org> This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 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::paintEvent( QPaintEvent *pe ) { QPainter p( this ); if ( mediaPlayerState.isFullscreen() ) { // Clear the background p.setBrush( QBrush( Qt::black ) ); return; } if ( !pe->erased() ) { // Combine with background and double buffer QPixmap pix( pe->rect().size() ); QPainter p( &pix ); p.translate( -pe->rect().topLeft().x(), -pe->rect().topLeft().y() ); p.drawTiledPixmap( pe->rect(), backgroundPixmap, pe->rect().topLeft() ); paintAllButtons( p ); QPainter p2( this ); p2.drawPixmap( pe->rect().topLeft(), pix ); } else { QPainter p( this ); paintAllButtons( p ); } } -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() { } 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; 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; case FullScreen: mediaPlayerState.setFullscreen( true ); makeVisible(); return; default: assert( false ); } } 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 ); } void MediaWidget::paintAllButtons( QPainter &p ) { for ( ButtonVector::const_iterator it = buttons.begin(); it != buttons.end(); ++it ) paintButton( p, *it ); } void MediaWidget::paintButton( const Button &button ) { QPainter p( this ); paintButton( p, button ); } void MediaWidget::paintButton( QPainter &p, const Button &button ) { if ( button.isDown ) p.drawPixmap( upperLeftOfButtonMask, button.pixDown ); else p.drawPixmap( upperLeftOfButtonMask, button.pixUp ); } void MediaWidget::setToggleButton( Command command, bool down ) { for ( ButtonVector::iterator it = buttons.begin(); it != buttons.end(); ++it ) if ( it->command == command ) { setToggleButton( *it, down ); return; } } void MediaWidget::setToggleButton( Button &button, bool down ) { if ( down != button.isDown ) toggleButton( button ); } void MediaWidget::toggleButton( Button &button ) { button.isDown = !button.isDown; paintButton( button ); } /* vim: et sw=4 ts=4 */ diff --git a/noncore/multimedia/opieplayer2/mediawidget.h b/noncore/multimedia/opieplayer2/mediawidget.h index 9042d5b..8031371 100644 --- a/noncore/multimedia/opieplayer2/mediawidget.h +++ b/noncore/multimedia/opieplayer2/mediawidget.h @@ -1,122 +1,123 @@ /* Copyright (C) 2002 Simon Hausmann <hausmann@kde.org> (C) 2002 Max Reiss <harlekin@handhelds.org> (C) 2002 L. Potter <ljp@llornkcor.com> (C) 2002 Holger Freyther <zecke@handhelds.org> This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 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. */ #ifndef MEDIAWIDGET_H #define MEDIAWIDGET_H #include <qwidget.h> #include <qmap.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, FullScreen, Undefined }; enum ButtonType { NormalButton, ToggleButton }; struct Button { Button() : command( Undefined ), type( NormalButton ), isHeld( false ), isDown( false ) {} Command command; ButtonType type; // this should be part of the bitfield but gcc2 is too buggy to support this :-( bool isHeld : 1; bool isDown : 1; QBitmap mask; QPixmap pixUp; QPixmap pixDown; }; typedef std::vector<Button> ButtonVector; struct SkinButtonInfo { Command command; const char *fileName; ButtonType type; }; typedef std::vector<QBitmap> MaskVector; typedef std::vector<QPixmap> PixmapVector; 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(); void forwardClicked(); void backClicked(); void moreClicked(); void lessClicked(); protected: virtual void closeEvent( QCloseEvent * ); virtual void paintEvent( QPaintEvent *pe ); - virtual void mouseMoveEvent( QMouseEvent *event ); + Button *buttonAt( const QPoint &position ); + virtual void mousePressEvent( QMouseEvent *event ); virtual void mouseReleaseEvent( QMouseEvent *event ); virtual void makeVisible(); void handleCommand( Command command, bool buttonDown ); bool isOverButton( const QPoint &position, int buttonId ) const; void paintAllButtons( QPainter &p ); void paintButton( const Button &button ); void paintButton( QPainter &p, const Button &button ); void setToggleButton( Button &button, bool down ); void setToggleButton( Command command, bool down ); void toggleButton( Button &button ); MediaPlayerState &mediaPlayerState; PlayListWidget &playList; ButtonVector buttons; QImage buttonMask; QPoint upperLeftOfButtonMask; QPixmap backgroundPixmap; }; #endif // MEDIAWIDGET_H /* vim: et sw=4 ts=4 */ |