summaryrefslogtreecommitdiff
authorsimon <simon>2002-12-11 12:21:55 (UTC)
committer simon <simon>2002-12-11 12:21:55 (UTC)
commitd24ad11763335834718485f14e90d8dab2611fa2 (patch) (side-by-side diff)
treec2ad64ecd8f2e217a3816f57c3dec20aaac4e421
parent381de1a3cfcc32dd7c0350329413f55dd9de9bb8 (diff)
downloadopie-d24ad11763335834718485f14e90d8dab2611fa2.zip
opie-d24ad11763335834718485f14e90d8dab2611fa2.tar.gz
opie-d24ad11763335834718485f14e90d8dab2611fa2.tar.bz2
- moved the remaining pieces of image/pixmap loading to the Skin class
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/multimedia/opieplayer2/mediawidget.cpp22
-rw-r--r--noncore/multimedia/opieplayer2/mediawidget.h8
-rw-r--r--noncore/multimedia/opieplayer2/skin.cpp7
-rw-r--r--noncore/multimedia/opieplayer2/skin.h2
4 files changed, 23 insertions, 16 deletions
diff --git a/noncore/multimedia/opieplayer2/mediawidget.cpp b/noncore/multimedia/opieplayer2/mediawidget.cpp
index 2031b4d..4de7ea9 100644
--- a/noncore/multimedia/opieplayer2/mediawidget.cpp
+++ b/noncore/multimedia/opieplayer2/mediawidget.cpp
@@ -23,114 +23,110 @@
#include "mediawidget.h"
#include "playlistwidget.h"
#include "skin.h"
#include <qpe/config.h>
#include <qpe/qpeapplication.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 )
+ const Skin &skin, const QSize &buttonAreaSize )
{
buttonMask = QImage( buttonAreaSize, 8, 255 );
buttonMask.fill( 0 );
buttons.clear();
buttons.reserve( buttonCount );
for ( uint i = 0; i < buttonCount; ++i ) {
- Button button = setupButton( skinInfo[ i ], imagePrefix );
+ Button button = setupButton( skinInfo[ i ], skin );
buttons.push_back( button );
}
}
-MediaWidget::Button MediaWidget::setupButton( const SkinButtonInfo &buttonInfo, const QString &imagePrefix )
+MediaWidget::Button MediaWidget::setupButton( const SkinButtonInfo &buttonInfo, const Skin &skin )
{
Button button;
button.command = buttonInfo.command;
button.type = buttonInfo.type;
- QString fileName = imagePrefix + buttonInfo.fileName + ".png";
-
- button.mask = setupButtonMask( button.command, fileName );
+ button.mask = setupButtonMask( button.command, skin.buttonMaskImage( buttonInfo.fileName ) );
return button;
}
-QBitmap MediaWidget::setupButtonMask( const Command &command, const QString &fileName )
+QBitmap MediaWidget::setupButtonMask( const Command &command, const QImage &maskImage )
{
- QImage imgMask( Resource::findPixmap( fileName ) );
- if ( imgMask.isNull() )
+ if ( maskImage.isNull() )
return QBitmap();
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 ) ) )
+ if ( !qRed( maskImage.pixel( x, y ) ) )
line[x] = command + 1;
}
// ### grmbl qt2. use constructor when switching to qt3.
- QBitmap bm; bm = imgMask;
+ QBitmap bm; bm = maskImage;
return bm;
}
void MediaWidget::loadDefaultSkin( const SkinButtonInfo *skinInfo, uint buttonCount, const QString &fileNameInfix )
{
Config cfg( "OpiePlayer" );
cfg.setGroup( "Options" );
QString skin = cfg.readEntry( "Skin","default" );
loadSkin( skinInfo, buttonCount, skin, fileNameInfix );
}
void MediaWidget::loadSkin( const SkinButtonInfo *skinInfo, uint buttonCount, const QString &name, const QString &fileNameInfix )
{
Skin skin( name, fileNameInfix );
QString skinPath = "opieplayer2/skins/" + name;
backgroundPixmap = skin.backgroundImage();
buttonUpImage = skin.buttonUpImage();
buttonDownImage = skin.buttonDownImage();
- setupButtons( skinInfo, buttonCount,
- skinPath + QString::fromLatin1( "/skin%1_mask_" ).arg( fileNameInfix ), buttonUpImage.size() );
+ setupButtons( skinInfo, buttonCount, skin, buttonUpImage.size() );
}
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 );
diff --git a/noncore/multimedia/opieplayer2/mediawidget.h b/noncore/multimedia/opieplayer2/mediawidget.h
index 52b9fcb..0d635aa 100644
--- a/noncore/multimedia/opieplayer2/mediawidget.h
+++ b/noncore/multimedia/opieplayer2/mediawidget.h
@@ -22,48 +22,50 @@
#ifndef MEDIAWIDGET_H
#define MEDIAWIDGET_H
#include <qwidget.h>
#include <qmap.h>
#include "mediaplayerstate.h"
#include "playlistwidget.h"
#include <vector>
#include <memory>
namespace
{
struct simpleAndStupidAllocator
{
static void *allocate( size_t amount )
{ return ::operator new( amount ); }
static void deallocate( void *p, size_t )
{ ::operator delete( p ); }
};
}
+class Skin;
+
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 ), isDown( false ) {}
Command command;
ButtonType type; // this should be part of the bitfield but gcc2 is too buggy to support this :-(
bool isDown : 1;
QBitmap mask;
QPixmap pixUp;
QPixmap pixDown;
};
#if defined( _CC_GNU_ )
// use that allocator to avoid the default allocator that on gcc2 requires libstdc++ because
// in the BAD_ALLOC macro it uses std::cerr and friends :-(
typedef std::vector<Button, std::__allocator<Button, simpleAndStupidAllocator> > ButtonVector;
@@ -79,51 +81,51 @@ public:
};
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;
virtual void loadSkin() = 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 );
+ const Skin &skin, const QSize &buttonAreaSize );
+ Button setupButton( const SkinButtonInfo &buttonInfo, const Skin &skin );
+ QBitmap setupButtonMask( const Command &command, const QImage &maskImage );
void loadDefaultSkin( const SkinButtonInfo *skinInfo, uint buttonCount, const QString &fileNameInfix = QString::null );
void loadSkin( const SkinButtonInfo *skinInfo, uint buttonCount, const QString &name, const QString &fileNameInfix );
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 );
diff --git a/noncore/multimedia/opieplayer2/skin.cpp b/noncore/multimedia/opieplayer2/skin.cpp
index 352368f..fb1c9c4 100644
--- a/noncore/multimedia/opieplayer2/skin.cpp
+++ b/noncore/multimedia/opieplayer2/skin.cpp
@@ -3,26 +3,33 @@
#include <qpe/resource.h>
Skin::Skin( const QString &name, const QString &fileNameInfix )
: m_name( name ), m_fileNameInfix( fileNameInfix )
{
m_skinPath = "opieplayer2/skins/" + name;
}
QImage Skin::backgroundImage() const
{
return QImage( Resource::findPixmap( QString( "%1/background" ).arg( m_skinPath ) ) );
}
QImage Skin::buttonUpImage() const
{
return QImage( Resource::findPixmap( QString( "%1/skin%2_up" ).arg( m_skinPath ).arg( m_fileNameInfix ) ) );
}
QImage Skin::buttonDownImage() const
{
return QImage( Resource::findPixmap( QString( "%1/skin%2_down" ).arg( m_skinPath ).arg( m_fileNameInfix ) ) );
}
+QImage Skin::buttonMaskImage( const QString &fileName ) const
+{
+ QString prefix = m_skinPath + QString::fromLatin1( "/skin%1_mask_" ).arg( m_fileNameInfix );
+ QString path = prefix + fileName + ".png";
+ return QImage( Resource::findPixmap( path ) );
+}
+
/* vim: et sw=4 ts=4
*/
diff --git a/noncore/multimedia/opieplayer2/skin.h b/noncore/multimedia/opieplayer2/skin.h
index 85f9e57..f160b3c 100644
--- a/noncore/multimedia/opieplayer2/skin.h
+++ b/noncore/multimedia/opieplayer2/skin.h
@@ -1,27 +1,29 @@
#ifndef SKIN_H
#define SKIN_H
#include <qstring.h>
#include <qimage.h>
class Skin
{
public:
Skin( const QString &name, const QString &fileNameInfix );
QImage backgroundImage() const;
QImage buttonUpImage() const;
QImage buttonDownImage() const;
+ QImage buttonMaskImage( const QString &fileName ) const;
+
private:
QString m_name;
QString m_fileNameInfix;
QString m_skinPath;
Skin( const Skin & );
Skin &operator=( const Skin & );
};
#endif // SKIN_H
/* vim: et sw=4 ts=4
*/