-rw-r--r-- | noncore/multimedia/opieplayer2/audiowidget.cpp | 25 | ||||
-rw-r--r-- | noncore/multimedia/opieplayer2/mediawidget.cpp | 43 | ||||
-rw-r--r-- | noncore/multimedia/opieplayer2/mediawidget.h | 5 | ||||
-rw-r--r-- | noncore/multimedia/opieplayer2/videowidget.cpp | 25 |
4 files changed, 50 insertions, 48 deletions
diff --git a/noncore/multimedia/opieplayer2/audiowidget.cpp b/noncore/multimedia/opieplayer2/audiowidget.cpp index 23d12ec..fd18dbb 100644 --- a/noncore/multimedia/opieplayer2/audiowidget.cpp +++ b/noncore/multimedia/opieplayer2/audiowidget.cpp @@ -54,120 +54,97 @@ namespace { const int xo = -2; // movable x offset const int yo = 22; // movable y offset const MediaWidget::SkinButtonInfo skinInfo[] = { { MediaWidget::Play, "play", MediaWidget::ToggleButton }, { MediaWidget::Stop, "stop", MediaWidget::NormalButton }, { MediaWidget::Next, "next", MediaWidget::NormalButton }, { MediaWidget::Previous, "prev", MediaWidget::NormalButton }, { MediaWidget::VolumeUp, "up", MediaWidget::NormalButton }, { MediaWidget::VolumeDown, "down", MediaWidget::NormalButton }, { MediaWidget::Loop, "loop", MediaWidget::ToggleButton }, { MediaWidget::PlayList, "playlist", MediaWidget::NormalButton }, { MediaWidget::Forward, "forward", MediaWidget::NormalButton }, { MediaWidget::Back, "back", MediaWidget::NormalButton } }; const uint buttonCount = sizeof( skinInfo ) / sizeof( skinInfo[ 0 ] ); void changeTextColor( QWidget * w) { QPalette p = w->palette(); p.setBrush( QColorGroup::Background, QColor( 167, 212, 167 ) ); p.setBrush( QColorGroup::Base, QColor( 167, 212, 167 ) ); w->setPalette( p ); } } AudioWidget::AudioWidget( PlayListWidget &playList, MediaPlayerState &mediaPlayerState, QWidget* parent, const char* name) : MediaWidget( playList, mediaPlayerState, parent, name ), songInfo( this ), slider( Qt::Horizontal, this ), time( this ), audioSliderBeingMoved( false ) { setCaption( tr("OpiePlayer") ); Config cfg("OpiePlayer"); cfg.setGroup("Options"); skin = cfg.readEntry("Skin","default"); //skin = "scaleTest"; // color of background, frame, degree of transparency QString skinPath = "opieplayer2/skins/" + skin; backgroundPixmap = QPixmap( Resource::loadPixmap( QString("%1/background").arg(skinPath) ) ); imgUp = QImage( Resource::loadImage( QString("%1/skin_up").arg(skinPath) ) ); imgDn = QImage( Resource::loadImage( QString("%1/skin_down").arg(skinPath) ) ); - buttonMask = QImage( imgUp.width(), imgUp.height(), 8, 255 ); - buttonMask.fill( 0 ); - - for ( uint i = 0; i < buttonCount; i++ ) { - Button button; - button.command = skinInfo[ i ].command; - button.type = skinInfo[ i ].type; - - QString filename = QString( QPEApplication::qpeDir() + "/pics/" + skinPath + "/skin_mask_" + skinInfo[i].fileName + ".png" ); - button.mask =QBitmap( filename ); - - if ( !button.mask.isNull() ) { - QImage imgMask = button.mask.convertToImage(); - uchar **dest = buttonMask.jumpTable(); - for ( int y = 0; y < imgUp.height(); y++ ) { - uchar *line = dest[y]; - for ( int x = 0; x < imgUp.width(); x++ ) - if ( !qRed( imgMask.pixel( x, y ) ) ) - line[x] = button.command + 1; - } - } - - buttons.push_back( button ); - } + setupButtons( skinInfo, buttonCount, QPEApplication::qpeDir() + "/pics/" + skinPath + "/skin_mask_", imgUp.size() ); setBackgroundPixmap( backgroundPixmap ); songInfo.setFocusPolicy( QWidget::NoFocus ); // changeTextColor( &songInfo ); // songInfo.setBackgroundColor( QColor( 167, 212, 167 )); // songInfo.setFrameStyle( QFrame::NoFrame); songInfo.setFrameStyle( QFrame::WinPanel | QFrame::Sunken ); // songInfo.setForegroundColor(Qt::white); slider.setFixedHeight( 20 ); slider.setMinValue( 0 ); slider.setMaxValue( 1 ); slider.setFocusPolicy( QWidget::NoFocus ); slider.setBackgroundPixmap( backgroundPixmap ); // Config cofg("qpe"); // cofg.setGroup("Appearance"); // QColor backgroundcolor = QColor( cofg.readEntry( "Background", "#E5E1D5" ) ); time.setFocusPolicy( QWidget::NoFocus ); time.setAlignment( Qt::AlignCenter ); // time.setFrame(FALSE); // changeTextColor( &time ); resizeEvent( NULL ); connect( &mediaPlayerState, SIGNAL( loopingToggled(bool) ), this, SLOT( setLooping(bool) ) ); connect( &mediaPlayerState, SIGNAL( isSeekableToggled( bool ) ), this, SLOT( setSeekable( bool ) ) ); 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); diff --git a/noncore/multimedia/opieplayer2/mediawidget.cpp b/noncore/multimedia/opieplayer2/mediawidget.cpp index 4c4cead..db16b44 100644 --- a/noncore/multimedia/opieplayer2/mediawidget.cpp +++ b/noncore/multimedia/opieplayer2/mediawidget.cpp @@ -1,89 +1,132 @@ /* 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::setupButtons( const SkinButtonInfo *skinInfo, uint buttonCount, + const QString &imagePrefix, const QSize &buttonAreaSize ) +{ + buttonMask = QImage( buttonAreaSize, 8, 255 ); + buttonMask.fill( 0 ); + + for ( uint i = 0; i < buttonCount; ++i ) { + Button button = setupButton( skinInfo[ i ], imagePrefix ); + buttons.push_back( button ); + } +} + +MediaWidget::Button MediaWidget::setupButton( const SkinButtonInfo &buttonInfo, const QString &imagePrefix ) +{ + Button button; + button.command = buttonInfo.command; + button.type = buttonInfo.type; + + QString fileName = imagePrefix + buttonInfo.fileName + ".png"; + + button.mask = setupButtonMask( button.command, fileName ); + + return button; +} + +QBitmap MediaWidget::setupButtonMask( const Command &command, const QString &fileName ) +{ + QBitmap mask( fileName ); + if ( mask.isNull() ) + return mask; + + QImage imgMask = mask.convertToImage(); + uchar **dest = buttonMask.jumpTable(); + for ( int y = 0; y < buttonMask.height(); y++ ) { + uchar *line = dest[y]; + for ( int x = 0; x < buttonMask.width(); x++ ) + if ( !qRed( imgMask.pixel( x, y ) ) ) + line[x] = command + 1; + } + + return mask; +} + 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 ); } } 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 ) { Button *button = buttonAt( event->pos() - upperLeftOfButtonMask ); diff --git a/noncore/multimedia/opieplayer2/mediawidget.h b/noncore/multimedia/opieplayer2/mediawidget.h index 8031371..148948a 100644 --- a/noncore/multimedia/opieplayer2/mediawidget.h +++ b/noncore/multimedia/opieplayer2/mediawidget.h @@ -38,86 +38,91 @@ 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: + void setupButtons( const SkinButtonInfo *skinInfo, uint buttonCount, + const QString &imagePrefix, const QSize &buttonAreaSize ); + Button setupButton( const SkinButtonInfo &buttonInfo, const QString &imagePrefix ); + QBitmap setupButtonMask( const Command &command, const QString &fileName ); + virtual void closeEvent( QCloseEvent * ); virtual void paintEvent( QPaintEvent *pe ); 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 */ diff --git a/noncore/multimedia/opieplayer2/videowidget.cpp b/noncore/multimedia/opieplayer2/videowidget.cpp index 4901e47..d1efaad 100644 --- a/noncore/multimedia/opieplayer2/videowidget.cpp +++ b/noncore/multimedia/opieplayer2/videowidget.cpp @@ -49,120 +49,97 @@ #ifdef Q_WS_QWS # define USE_DIRECT_PAINTER # include <qdirectpainter_qws.h> # include <qgfxraster_qws.h> #endif namespace { const int xo = 2; // movable x offset const int yo = 0; // movable y offset const MediaWidget::SkinButtonInfo skinInfo[] = { { MediaWidget::Play, "play", MediaWidget::ToggleButton }, { MediaWidget::Stop, "stop", MediaWidget::NormalButton }, { MediaWidget::Next, "fwd", MediaWidget::NormalButton }, { MediaWidget::Previous, "back", MediaWidget::NormalButton }, { MediaWidget::VolumeUp, "up", MediaWidget::NormalButton }, { MediaWidget::VolumeDown, "down", MediaWidget::NormalButton }, { MediaWidget::FullScreen, "full", MediaWidget::ToggleButton } }; const uint buttonCount = sizeof( skinInfo ) / sizeof( skinInfo[ 0 ] ); } VideoWidget::VideoWidget( PlayListWidget &playList, MediaPlayerState &mediaPlayerState, QWidget* parent, const char* name ) : MediaWidget( playList, mediaPlayerState, parent, name ), scaledWidth( 0 ), scaledHeight( 0 ), videoSliderBeingMoved( false ) { setCaption( tr("OpiePlayer - Video") ); videoFrame = new XineVideoWidget ( this, "Video frame" ); connect ( videoFrame, SIGNAL( videoResized ( const QSize & )), this, SIGNAL( videoResized ( const QSize & ))); connect ( videoFrame, SIGNAL( clicked () ), this, SLOT ( backToNormal() ) ); Config cfg("OpiePlayer"); cfg.setGroup("Options"); skin = cfg.readEntry("Skin","default"); QString skinPath = "opieplayer2/skins/" + skin; backgroundPixmap = QPixmap( Resource::loadPixmap( QString("%1/background").arg(skinPath) ) ); imgUp = QImage( Resource::loadImage( QString("%1/skinV_up").arg(skinPath) ) ); imgDn = QImage( Resource::loadImage( QString("%1/skinV_down").arg(skinPath) ) ); - buttonMask = QImage( imgUp.width(), imgUp.height(), 8, 255 ); - buttonMask.fill( 0 ); - - for ( uint i = 0; i < buttonCount; i++ ) { - Button button; - button.command = skinInfo[ i ].command; - button.type = skinInfo[ i ].type; - - QString filename = QString( QPEApplication::qpeDir() + "/pics/" + skinPath + "/skinV_mask_" + skinInfo[i].fileName + ".png" ); - button.mask =QBitmap( filename ); - - if ( !button.mask.isNull() ) { - QImage imgMask = button.mask.convertToImage(); - uchar **dest = buttonMask.jumpTable(); - for ( int y = 0; y < imgUp.height(); y++ ) { - uchar *line = dest[y]; - for ( int x = 0; x < imgUp.width(); x++ ) - if ( !qRed( imgMask.pixel( x, y ) ) ) - line[x] = button.command + 1; - } - } - - buttons.push_back( button ); - } + setupButtons( skinInfo, buttonCount, QPEApplication::qpeDir() + "/pics/" + skinPath + "/skinV_mask_", imgUp.size() ); setBackgroundPixmap( backgroundPixmap ); slider = new QSlider( Qt::Horizontal, this ); slider->setMinValue( 0 ); slider->setMaxValue( 1 ); slider->setBackgroundPixmap( Resource::loadPixmap( backgroundPix ) ); //slider->setFocusPolicy( QWidget::NoFocus ); resizeEvent( NULL ); setLength( mediaPlayerState.length() ); setPosition( mediaPlayerState.position() ); setFullscreen( mediaPlayerState.isFullscreen() ); setPlaying( mediaPlayerState.isPlaying() ); } VideoWidget::~VideoWidget() { } QPixmap *combineVImageWithBackground( 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 new QPixmap( pix ); } QPixmap maskVPixToMask( QPixmap pix, QBitmap mask ) { QPixmap pixmap( pix ); pixmap.setMask( mask ); return pixmap; } void VideoWidget::resizeEvent( QResizeEvent * ) { int h = height(); int w = width(); //int Vh = 160; //int Vw = 220; slider->setFixedWidth( w - 20 ); slider->setGeometry( QRect( 15, h - 22, w - 90, 20 ) ); slider->setBackgroundOrigin( QWidget::ParentOrigin ); slider->setFocusPolicy( QWidget::NoFocus ); slider->setBackgroundPixmap( backgroundPixmap ); |