summaryrefslogtreecommitdiff
authorsimon <simon>2002-12-09 16:39:32 (UTC)
committer simon <simon>2002-12-09 16:39:32 (UTC)
commit1bb6aa52f2db85f65f75278310c328218caeae65 (patch) (side-by-side diff)
tree1983547bac0da80bde93554038a57713feb715c1
parent1ae041fba55e218a2523de441bec6ec3a1eecf02 (diff)
downloadopie-1bb6aa52f2db85f65f75278310c328218caeae65.zip
opie-1bb6aa52f2db85f65f75278310c328218caeae65.tar.gz
opie-1bb6aa52f2db85f65f75278310c328218caeae65.tar.bz2
- removing duplicated code in VideoWidget
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/multimedia/opieplayer2/mediawidget.cpp5
-rw-r--r--noncore/multimedia/opieplayer2/mediawidget.h2
-rw-r--r--noncore/multimedia/opieplayer2/videowidget.cpp25
-rw-r--r--noncore/multimedia/opieplayer2/videowidget.h4
4 files changed, 9 insertions, 27 deletions
diff --git a/noncore/multimedia/opieplayer2/mediawidget.cpp b/noncore/multimedia/opieplayer2/mediawidget.cpp
index c0ebd63..7eb75e6 100644
--- a/noncore/multimedia/opieplayer2/mediawidget.cpp
+++ b/noncore/multimedia/opieplayer2/mediawidget.cpp
@@ -24,109 +24,114 @@
#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::makeVisible()
+{
+}
+
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;
+ 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 );
}
diff --git a/noncore/multimedia/opieplayer2/mediawidget.h b/noncore/multimedia/opieplayer2/mediawidget.h
index caae0a7..3f4c45d 100644
--- a/noncore/multimedia/opieplayer2/mediawidget.h
+++ b/noncore/multimedia/opieplayer2/mediawidget.h
@@ -38,75 +38,77 @@ 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 : 1;
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();
protected:
virtual void closeEvent( QCloseEvent * );
virtual void paintEvent( QPaintEvent *pe );
+ 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
*/
diff --git a/noncore/multimedia/opieplayer2/videowidget.cpp b/noncore/multimedia/opieplayer2/videowidget.cpp
index 12316f8..cc586cc 100644
--- a/noncore/multimedia/opieplayer2/videowidget.cpp
+++ b/noncore/multimedia/opieplayer2/videowidget.cpp
@@ -232,120 +232,97 @@ void VideoWidget::updateSlider( long i, long max ) {
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::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;
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 );
}
- switch( command ) {
-
- case Play: {
- if( mediaPlayerState.isPaused() ) {
- setToggleButton( button, FALSE );
- mediaPlayerState.setPaused( FALSE );
- return;
- } else if( !mediaPlayerState.isPaused() ) {
- setToggleButton( button, TRUE );
- mediaPlayerState.setPaused( TRUE );
- return;
- } else {
- 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 VolumeUp: emit moreReleased(); return;
- case VolumeDown: emit lessReleased(); return;
- case FullScreen: mediaPlayerState.setFullscreen( TRUE ); makeVisible(); return;
- default: break;
- }
+ handleCommand( command, button.isDown );
}
}
}
}
void VideoWidget::mousePressEvent( QMouseEvent *event ) {
mouseMoveEvent( event );
}
void VideoWidget::mouseReleaseEvent( QMouseEvent *event ) {
if ( mediaPlayerState.isFullscreen() ) {
mediaPlayerState.setFullscreen( FALSE );
makeVisible();
}
mouseMoveEvent( event );
}
void VideoWidget::showEvent( QShowEvent* ) {
QMouseEvent event( QEvent::MouseMove, QPoint( 0, 0 ), 0, 0 );
mouseMoveEvent( &event );
}
void VideoWidget::backToNormal() {
mediaPlayerState.setFullscreen( FALSE );
makeVisible();
}
void VideoWidget::makeVisible() {
if ( mediaPlayerState.isFullscreen() ) {
setBackgroundMode( QWidget::NoBackground );
showFullScreen();
resize( qApp->desktop()->size() );
videoFrame-> setGeometry ( 0, 0, width ( ), height ( ));
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 {
showNormal();
showMaximized();
setBackgroundPixmap( backgroundPixmap );
QWidget *d = QApplication::desktop();
int w = d->width();
int h = d->height();
diff --git a/noncore/multimedia/opieplayer2/videowidget.h b/noncore/multimedia/opieplayer2/videowidget.h
index c3bc131..ef88186 100644
--- a/noncore/multimedia/opieplayer2/videowidget.h
+++ b/noncore/multimedia/opieplayer2/videowidget.h
@@ -12,94 +12,92 @@
:`=1 )Y*s>-.--   : the terms of the GNU General Public
.="- .-=="i,     .._ License as published by the Free Software
 - .   .-<_>     .<> Foundation; either version 2 of the License,
     ._= =}       : or (at your option) any later version.
    .%`+i>       _;_.
    .i_,=:_.      -<s. This program 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 VIDEO_WIDGET_H
#define VIDEO_WIDGET_H
#include <qwidget.h>
#include <qimage.h>
#include <qpixmap.h>
#include "xinevideowidget.h"
#include "mediawidget.h"
class QPixmap;
class QSlider;
class VideoWidget : public MediaWidget {
Q_OBJECT
public:
VideoWidget( PlayListWidget &playList, MediaPlayerState &mediaPlayerState, QWidget* parent=0, const char* name=0 );
~VideoWidget();
XineVideoWidget* vidWidget();
public slots:
void updateSlider( long, long );
void sliderPressed( );
void sliderReleased( );
void setFullscreen( bool b );
- void makeVisible();
+ virtual void makeVisible();
void backToNormal();
void setPosition( long );
public:
virtual void setPlaying( bool b);
virtual void setLength( long );
virtual void setDisplayType( MediaPlayerState::DisplayType displayType );
signals:
void moreClicked();
void lessClicked();
- void moreReleased();
- void lessReleased();
void sliderMoved( long );
void videoResized ( const QSize &s );
protected:
void resizeEvent( QResizeEvent * );
void showEvent( QShowEvent *se );
void mouseMoveEvent( QMouseEvent *event );
void mousePressEvent( QMouseEvent *event );
void mouseReleaseEvent( QMouseEvent *event );
void keyReleaseEvent( QKeyEvent *e);
private:
// Ticker songInfo;
QImage imgUp;
QImage imgDn;
QString skin;
QString backgroundPix;
QSlider *slider;
QImage *currentFrame;
int scaledWidth;
int scaledHeight;
XineVideoWidget* videoFrame;
};
#endif // VIDEO_WIDGET_H