author | simon <simon> | 2002-12-02 20:56:19 (UTC) |
---|---|---|
committer | simon <simon> | 2002-12-02 20:56:19 (UTC) |
commit | 649ea9e9586ce51847ebeb9c062290137c9248f4 (patch) (side-by-side diff) | |
tree | 334d6fe0fe91e29ed3600d96443ab104939c1eef | |
parent | 0090a335a7162f4b0d34f78850ebf9a8bd544c01 (diff) | |
download | opie-649ea9e9586ce51847ebeb9c062290137c9248f4.zip opie-649ea9e9586ce51847ebeb9c062290137c9248f4.tar.gz opie-649ea9e9586ce51847ebeb9c062290137c9248f4.tar.bz2 |
- centralized the button command handling into MediaWidget (as it is
duplicated between AudioWidget and VideoWidget -- the latter still to
come though)
-rw-r--r-- | noncore/multimedia/opieplayer2/audiowidget.cpp | 30 | ||||
-rw-r--r-- | noncore/multimedia/opieplayer2/audiowidget.h | 24 | ||||
-rw-r--r-- | noncore/multimedia/opieplayer2/mediawidget.cpp | 19 | ||||
-rw-r--r-- | noncore/multimedia/opieplayer2/mediawidget.h | 10 |
4 files changed, 35 insertions, 48 deletions
diff --git a/noncore/multimedia/opieplayer2/audiowidget.cpp b/noncore/multimedia/opieplayer2/audiowidget.cpp index d9beb90..3070bc3 100644 --- a/noncore/multimedia/opieplayer2/audiowidget.cpp +++ b/noncore/multimedia/opieplayer2/audiowidget.cpp @@ -29,50 +29,48 @@ Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include <qpe/qpeapplication.h> #include <qpe/resource.h> #include <qpe/config.h> #include <opie/oticker.h> #include <qwidget.h> #include <qpixmap.h> #include <qbutton.h> #include <qpainter.h> #include <qframe.h> #include <qlayout.h> #include <qdir.h> #include <stdlib.h> #include <stdio.h> #include "audiowidget.h" #include "mediaplayerstate.h" #include "playlistwidget.h" -extern PlayListWidget *playList; - static const int xo = -2; // movable x offset static const int yo = 22; // movable y offset struct MediaButton { bool isToggle, isHeld, isDown; }; //Layout information for the audioButtons (and if it is a toggle button or not) MediaButton audioButtons[] = { { TRUE, FALSE, FALSE }, // play { FALSE, FALSE, FALSE }, // stop { FALSE, FALSE, FALSE }, // next { FALSE, FALSE, FALSE }, // previous { FALSE, FALSE, FALSE }, // volume up { FALSE, FALSE, FALSE }, // volume down { TRUE, FALSE, FALSE }, // repeat/loop { FALSE, FALSE, FALSE }, // playlist { FALSE, FALSE, FALSE }, // forward { FALSE, FALSE, FALSE } // back }; const char * const skin_mask_file_names[10] = { "play", "stop", "next", "prev", "up", "down", "loop", "playlist", "forward", "back" @@ -372,91 +370,73 @@ void AudioWidget::stopSkip() { 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 ( int i = 0; i < numButtons; 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() - xoff; int y = event->pos().y() - yoff; bool isOnButton = ( x > 0 && y > 0 && x < imgButtonMask.width() && y < imgButtonMask.height() && imgButtonMask.pixelIndex( x, y ) == i + 1 ); if ( isOnButton && !audioButtons[i].isHeld ) { audioButtons[i].isHeld = TRUE; toggleButton(i); switch (i) { - case AudioVolumeUp: + case VolumeUp: emit moreClicked(); return; - case AudioVolumeDown: + case VolumeDown: emit lessClicked(); return; - case AudioForward: + case Forward: emit forwardClicked(); return; - case AudioBack: + case Back: emit backClicked(); return; } } else if ( !isOnButton && audioButtons[i].isHeld ) { audioButtons[i].isHeld = FALSE; toggleButton(i); } } else { if ( audioButtons[i].isHeld ) { audioButtons[i].isHeld = FALSE; if ( !audioButtons[i].isToggle ) { setToggleButton( i, FALSE ); } qDebug("mouseEvent %d", i); - switch (i) { - case AudioPlay: - if( mediaPlayerState.isPaused() ) { - mediaPlayerState.setPaused( FALSE ); - return; - } else if( !mediaPlayerState.isPaused() ) { - mediaPlayerState.setPaused( TRUE ); - return; - } - case AudioStop: mediaPlayerState.setPlaying(FALSE); return; - case AudioNext: if( playList->currentTab() == PlayListWidget::CurrentPlayList ) mediaPlayerState.setNext(); return; - case AudioPrevious: if( playList->currentTab() == PlayListWidget::CurrentPlayList ) mediaPlayerState.setPrev(); return; - case AudioLoop: mediaPlayerState.setLooping(audioButtons[i].isDown); return; - case AudioVolumeUp: emit moreReleased(); return; - case AudioVolumeDown: emit lessReleased(); return; - case AudioPlayList: mediaPlayerState.setList(); return; - case AudioForward: emit forwardReleased(); return; - case AudioBack: emit backReleased(); return; - } + handleCommand( static_cast<Command>( i ), audioButtons[ 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 ); mouseMoveEvent( &event ); } void AudioWidget::closeEvent( QCloseEvent* ) { mediaPlayerState.setList(); diff --git a/noncore/multimedia/opieplayer2/audiowidget.h b/noncore/multimedia/opieplayer2/audiowidget.h index 087d711..1778a30 100644 --- a/noncore/multimedia/opieplayer2/audiowidget.h +++ b/noncore/multimedia/opieplayer2/audiowidget.h @@ -28,92 +28,72 @@ If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #ifndef AUDIO_WIDGET_H #define AUDIO_WIDGET_H #include <qpainter.h> #include <qdrawutil.h> #include <qpixmap.h> #include <qstring.h> #include <qslider.h> #include <qframe.h> #include <qlineedit.h> #include <qimage.h> #include <opie/oticker.h> #include "mediawidget.h" class QPixmap; -namespace { - -enum AudioButtons { - AudioPlay=0, - AudioStop, - AudioNext, - AudioPrevious, - AudioVolumeUp, - AudioVolumeDown, - AudioLoop, - AudioPlayList, - AudioForward, - AudioBack -}; -}; - class AudioWidget : public MediaWidget { Q_OBJECT public: AudioWidget( MediaPlayerState &mediaPlayerState, QWidget* parent=0, const char* name=0 ); ~AudioWidget(); void setTickerText( const QString &text ) { songInfo.setText( text ); } public slots: void updateSlider( long, long ); void sliderPressed( ); void sliderReleased( ); - void setLooping( bool b) { setToggleButton( AudioLoop, b ); } + void setLooping( bool b) { setToggleButton( Loop, b ); } void setPosition( long ); void setSeekable( bool ); public: virtual void setLength( long ); - virtual void setPlaying( bool b) { setToggleButton( AudioPlay, b ); } + virtual void setPlaying( bool b) { setToggleButton( Play, b ); } virtual void setDisplayType( MediaPlayerState::DisplayType displayType ); signals: void moreClicked(); void lessClicked(); - void moreReleased(); - void lessReleased(); void forwardClicked(); void backClicked(); - void forwardReleased(); - void backReleased(); void sliderMoved(long); protected: void doBlank(); void doUnblank(); void paintEvent( QPaintEvent *pe ); void showEvent( QShowEvent *se ); void resizeEvent( QResizeEvent *re ); void mouseMoveEvent( QMouseEvent *event ); void mousePressEvent( QMouseEvent *event ); void mouseReleaseEvent( QMouseEvent *event ); void timerEvent( QTimerEvent *event ); void closeEvent( QCloseEvent *event ); void keyReleaseEvent( QKeyEvent *e); private slots: void skipFor(); void skipBack(); void stopSkip(); private: void toggleButton( int ); void setToggleButton( int, bool ); void paintButton( QPainter *p, int i ); int skipDirection; QString skin; diff --git a/noncore/multimedia/opieplayer2/mediawidget.cpp b/noncore/multimedia/opieplayer2/mediawidget.cpp index d58e87e..01a7295 100644 --- a/noncore/multimedia/opieplayer2/mediawidget.cpp +++ b/noncore/multimedia/opieplayer2/mediawidget.cpp @@ -1,41 +1,58 @@ /* Copyright (C) 2002 Simon Hausmann <hausmann@kde.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" -extern MediaPlayerState *mediaPlayerState; +extern PlayListWidget *playList; MediaWidget::MediaWidget( MediaPlayerState &_mediaPlayerState, QWidget *parent, const char *name ) : QWidget( parent, name ), mediaPlayerState( _mediaPlayerState ) { 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::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; + } +} + /* vim: et sw=4 ts=4 */ diff --git a/noncore/multimedia/opieplayer2/mediawidget.h b/noncore/multimedia/opieplayer2/mediawidget.h index 64adba9..550f0fc 100644 --- a/noncore/multimedia/opieplayer2/mediawidget.h +++ b/noncore/multimedia/opieplayer2/mediawidget.h @@ -7,39 +7,49 @@ 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 "mediaplayerstate.h" class MediaWidget : public QWidget { Q_OBJECT public: + enum Command { Play = 0, Stop, Next, Previous, VolumeUp, VolumeDown, Loop, PlayList, Forward, Back }; + MediaWidget( 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: + void handleCommand( Command command, bool buttonDown ); + MediaPlayerState &mediaPlayerState; }; #endif // MEDIAWIDGET_H /* vim: et sw=4 ts=4 */ |