author | simon <simon> | 2002-12-11 17:38:55 (UTC) |
---|---|---|
committer | simon <simon> | 2002-12-11 17:38:55 (UTC) |
commit | 719acab56c57f283168b955582ab5b30b9809b02 (patch) (side-by-side diff) | |
tree | 370c9f8bae6741b0ee2303b6c04f9329757a8a3e | |
parent | aaac5c934e7053fa4323b03f7ea31c32c6388883 (diff) | |
download | opie-719acab56c57f283168b955582ab5b30b9809b02.zip opie-719acab56c57f283168b955582ab5b30b9809b02.tar.gz opie-719acab56c57f283168b955582ab5b30b9809b02.tar.bz2 |
- copyright notice fixlet
-rw-r--r-- | noncore/multimedia/opieplayer2/mediawidget.cpp | 15 | ||||
-rw-r--r-- | noncore/multimedia/opieplayer2/mediawidget.h | 14 | ||||
-rw-r--r-- | noncore/multimedia/opieplayer2/singleton.h | 19 | ||||
-rw-r--r-- | noncore/multimedia/opieplayer2/skin.cpp | 21 | ||||
-rw-r--r-- | noncore/multimedia/opieplayer2/skin.h | 22 |
5 files changed, 76 insertions, 15 deletions
diff --git a/noncore/multimedia/opieplayer2/mediawidget.cpp b/noncore/multimedia/opieplayer2/mediawidget.cpp index c0106d4..702e6d7 100644 --- a/noncore/multimedia/opieplayer2/mediawidget.cpp +++ b/noncore/multimedia/opieplayer2/mediawidget.cpp @@ -1,267 +1,266 @@ /* - Copyright (C) 2002 Simon Hausmann <hausmann@kde.org> + Copyright (C) 2002 Simon Hausmann <simon@lst.de> (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 + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU 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, + 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. + 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 + You should have received a copy of the GNU General Public License + along with this program; see the file COPYING. 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" #include "skin.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 Skin &skin ) { buttonMask = skin.buttonMask( skinInfo, buttonCount ); buttons.clear(); buttons.reserve( buttonCount ); for ( uint i = 0; i < buttonCount; ++i ) { Button button = setupButton( skinInfo[ i ], skin ); buttons.push_back( button ); } } MediaWidget::Button MediaWidget::setupButton( const SkinButtonInfo &buttonInfo, const Skin &skin ) { Button button; button.command = buttonInfo.command; button.type = buttonInfo.type; button.mask = skin.buttonMaskImage( buttonInfo.fileName ); return button; } void MediaWidget::loadDefaultSkin( const GUIInfo &guiInfo ) { Skin skin( guiInfo.fileNameInfix ); loadSkin( guiInfo.buttonInfo, guiInfo.buttonCount, skin ); } void MediaWidget::loadSkin( const SkinButtonInfo *skinInfo, uint buttonCount, const Skin &skin ) { backgroundPixmap = skin.backgroundImage(); buttonUpImage = skin.buttonUpImage(); buttonDownImage = skin.buttonDownImage(); setupButtons( skinInfo, buttonCount, skin ); } 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::resizeEvent( QResizeEvent *e ) { QPixmap pixUp = combineImageWithBackground( buttonUpImage, backgroundPixmap, upperLeftOfButtonMask ); QPixmap pixDn = combineImageWithBackground( buttonDownImage, backgroundPixmap, upperLeftOfButtonMask ); for ( ButtonVector::iterator it = buttons.begin(); it != buttons.end(); ++it ) { Button &button = *it; if ( button.mask.isNull() ) continue; button.pixUp = addMaskToPixmap( pixUp, button.mask ); button.pixDown = addMaskToPixmap( pixDn, button.mask ); } QWidget::resizeEvent( e ); } 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 ); 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 ) { 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(); 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 ); } QPixmap MediaWidget::combineImageWithBackground( const QImage &image, const QPixmap &background, const QPoint &offset ) { QPixmap pix( image.size() ); QPainter p( &pix ); p.drawTiledPixmap( pix.rect(), background, offset ); p.drawImage( 0, 0, image ); return pix; } QPixmap MediaWidget::addMaskToPixmap( const QPixmap &pix, const QBitmap &mask ) { QPixmap result( pix ); result.setMask( mask ); return result; } /* vim: et sw=4 ts=4 */ diff --git a/noncore/multimedia/opieplayer2/mediawidget.h b/noncore/multimedia/opieplayer2/mediawidget.h index 64483d8..40eb0af 100644 --- a/noncore/multimedia/opieplayer2/mediawidget.h +++ b/noncore/multimedia/opieplayer2/mediawidget.h @@ -1,167 +1,167 @@ /* - Copyright (C) 2002 Simon Hausmann <hausmann@kde.org> + Copyright (C) 2002 Simon Hausmann <simon@lst.de> (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 + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU 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, + 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. + 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 + You should have received a copy of the GNU General Public License + along with this program; see the file COPYING. 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> #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; #else typedef std::vector<Button> ButtonVector; #endif struct SkinButtonInfo { Command command; const char *fileName; ButtonType type; }; struct GUIInfo { GUIInfo() : buttonInfo( 0 ), buttonCount( 0 ) {} GUIInfo( const QString &_fileNameInfix, const SkinButtonInfo *_buttonInfo, const uint _buttonCount ) : fileNameInfix( _fileNameInfix ), buttonInfo( _buttonInfo ), buttonCount( _buttonCount ) {} QString fileNameInfix; const SkinButtonInfo *buttonInfo; const uint buttonCount; }; 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 Skin &skin ); Button setupButton( const SkinButtonInfo &buttonInfo, const Skin &skin ); void loadDefaultSkin( const GUIInfo &guiInfo ); void loadSkin( const SkinButtonInfo *skinInfo, uint buttonCount, const Skin &skin ); virtual void closeEvent( QCloseEvent * ); virtual void paintEvent( QPaintEvent *pe ); virtual void resizeEvent( QResizeEvent *e ); 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; QImage buttonUpImage; QImage buttonDownImage; static QPixmap combineImageWithBackground( const QImage &background, const QPixmap &pixmap, const QPoint &offset ); static QPixmap addMaskToPixmap( const QPixmap &pix, const QBitmap &mask ); }; #endif // MEDIAWIDGET_H /* vim: et sw=4 ts=4 */ diff --git a/noncore/multimedia/opieplayer2/singleton.h b/noncore/multimedia/opieplayer2/singleton.h index 35b3dff..83e228f 100644 --- a/noncore/multimedia/opieplayer2/singleton.h +++ b/noncore/multimedia/opieplayer2/singleton.h @@ -1,49 +1,68 @@ +/* + Copyright (C) 2002 Simon Hausmann <simon@lst.de> + + 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 SINGLETON_H #define SINGLETON_H template <class Product> struct DefaultSingletonCreator { static Product *create() { return new Product; } }; template <class Product> struct NullSingletonCreator { static Product *create() { return 0; } }; template < class T, template <class> class Creator = DefaultSingletonCreator > class Singleton { public: static T &self() { if ( !s_self ) s_self = Creator<T>::create(); return *s_self; } protected: Singleton() { s_self = static_cast<T *>( this ); } ~Singleton() { s_self = 0; } private: Singleton( const Singleton<T, Creator> &rhs ); Singleton<T, Creator> &operator=( const Singleton<T, Creator> &rhs ); static T *s_self; }; template <class T, template <class> class Creator> T *Singleton<T, Creator>::s_self = 0; #endif // SINGLETON_H /* vim: et sw=4 ts=4 */ diff --git a/noncore/multimedia/opieplayer2/skin.cpp b/noncore/multimedia/opieplayer2/skin.cpp index 0de3023..cef3259 100644 --- a/noncore/multimedia/opieplayer2/skin.cpp +++ b/noncore/multimedia/opieplayer2/skin.cpp @@ -1,152 +1,173 @@ +/* + Copyright (C) 2002 Simon Hausmann <simon@lst.de> + (C) 2002 Max Reiss <harlekin@handhelds.org> + (C) 2002 L. Potter <ljp@llornkcor.com> + (C) 2002 Holger Freyther <zecke@handhelds.org> + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + 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 + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; see the file COPYING. If not, write to + the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. +*/ #include "skin.h" #include <qpe/resource.h> #include <qpe/config.h> #include <assert.h> Skin::Skin( const QString &name, const QString &fileNameInfix ) : m_fileNameInfix( fileNameInfix ) { init( name ); } Skin::Skin( const QString &fileNameInfix ) : m_fileNameInfix( fileNameInfix ) { init( defaultSkinName() ); } void Skin::init( const QString &name ) { m_skinPath = "opieplayer2/skins/" + name; } void Skin::preload( const MediaWidget::SkinButtonInfo *skinButtonInfo, uint buttonCount ) { backgroundImage(); buttonUpImage(); buttonDownImage(); ( void )buttonMask( skinButtonInfo, buttonCount ); } QImage Skin::backgroundImage() const { if ( m_backgroundImage.isNull() ) m_backgroundImage = SkinCache::self().loadImage( QString( "%1/background" ).arg( m_skinPath ) ); return m_backgroundImage; } QImage Skin::buttonUpImage() const { if ( m_buttonUpImage.isNull() ) m_buttonUpImage = SkinCache::self().loadImage( QString( "%1/skin%2_up" ).arg( m_skinPath ).arg( m_fileNameInfix ) ); return m_buttonUpImage; } QImage Skin::buttonDownImage() const { if ( m_buttonDownImage.isNull() ) m_buttonDownImage = SkinCache::self().loadImage( QString( "%1/skin%2_down" ).arg( m_skinPath ).arg( m_fileNameInfix ) ); return m_buttonDownImage; } QImage Skin::buttonMask( const MediaWidget::SkinButtonInfo *skinButtonInfo, uint buttonCount ) const { if ( !m_buttonMask.isNull() ) return m_buttonMask; QSize buttonAreaSize = buttonUpImage().size(); m_buttonMask = QImage( buttonAreaSize, 8, 255 ); m_buttonMask.fill( 0 ); for ( uint i = 0; i < buttonCount; ++i ) addButtonToMask( skinButtonInfo[ i ].command + 1, buttonMaskImage( skinButtonInfo[ i ].fileName ) ); return m_buttonMask; } void Skin::addButtonToMask( int tag, const QImage &maskImage ) const { if ( maskImage.isNull() ) return; uchar **dest = m_buttonMask.jumpTable(); for ( int y = 0; y < m_buttonMask.height(); y++ ) { uchar *line = dest[y]; for ( int x = 0; x < m_buttonMask.width(); x++ ) if ( !qRed( maskImage.pixel( x, y ) ) ) line[x] = tag; } } QImage Skin::buttonMaskImage( const QString &fileName ) const { ButtonMaskImageMap::Iterator it = m_buttonMasks.find( fileName ); if ( it == m_buttonMasks.end() ) { QString prefix = m_skinPath + QString::fromLatin1( "/skin%1_mask_" ).arg( m_fileNameInfix ); QString path = prefix + fileName + ".png"; it = m_buttonMasks.insert( fileName, SkinCache::self().loadImage( path ) ); } return *it; } QString Skin::defaultSkinName() { Config cfg( "OpiePlayer" ); cfg.setGroup( "Options" ); return cfg.readEntry( "Skin", "default" ); } SkinCache::SkinCache() { m_cache.setAutoDelete( true ); } QImage SkinCache::loadImage( const QString &name ) { ThreadUtil::AutoLock lock( m_cacheGuard ); QImage *image = m_cache.find( name ); if ( image ) { qDebug( "cache hit for %s", name.ascii() ); return *image; } image = new QImage( Resource::findPixmap( name ) ); m_cache.insert( name, image ); return *image; } SkinLoader::SkinLoader() { } void SkinLoader::schedule( const QString &skinName, const QString &fileNameInfix, const MediaWidget::SkinButtonInfo *skinButtonInfo, const uint buttonCount ) { assert( isRunning() == false ); pendingSkins << Info( skinName, fileNameInfix, skinButtonInfo, buttonCount ); } void SkinLoader::run() { qDebug( "SkinLoader::run()" ); for ( InfoList::ConstIterator it = pendingSkins.begin(); it != pendingSkins.end(); ++it ) load( *it ); qDebug( "SkinLoader is done." ); } void SkinLoader::load( const Info &nfo ) { qDebug( "preloading %s with infix %s", nfo.skinName.ascii(), nfo.fileNameInfix.ascii() ); Skin skin( nfo.skinName, nfo.fileNameInfix ); skin.preload( nfo.skinButtonInfo, nfo.buttonCount ); } /* vim: et sw=4 ts=4 */ diff --git a/noncore/multimedia/opieplayer2/skin.h b/noncore/multimedia/opieplayer2/skin.h index c15d9dc..9f7326e 100644 --- a/noncore/multimedia/opieplayer2/skin.h +++ b/noncore/multimedia/opieplayer2/skin.h @@ -1,102 +1,124 @@ +/* + Copyright (C) 2002 Simon Hausmann <simon@lst.de> + (C) 2002 Max Reiss <harlekin@handhelds.org> + (C) 2002 L. Potter <ljp@llornkcor.com> + (C) 2002 Holger Freyther <zecke@handhelds.org> + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + 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 + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; see the file COPYING. If not, write to + the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. +*/ + #ifndef SKIN_H #define SKIN_H #include <qstring.h> #include <qimage.h> #include <qmap.h> #include <qdict.h> #include "mediawidget.h" #include "threadutil.h" #include "singleton.h" class Skin { public: Skin( const QString &name, const QString &fileNameInfix ); Skin( const QString &fileNameInfix ); void preload( const MediaWidget::SkinButtonInfo *skinButtonInfo, uint buttonCount ); QImage backgroundImage() const; QImage buttonUpImage() const; QImage buttonDownImage() const; QImage buttonMask( const MediaWidget::SkinButtonInfo *skinButtonInfo, uint buttonCount ) const; QImage buttonMaskImage( const QString &fileName ) const; static QString defaultSkinName(); private: void init( const QString &name ); void addButtonToMask( int tag, const QImage &maskImage ) const; QString m_fileNameInfix; QString m_skinPath; typedef QMap<QString, QImage> ButtonMaskImageMap; mutable QImage m_backgroundImage; mutable QImage m_buttonUpImage; mutable QImage m_buttonDownImage; mutable QImage m_buttonMask; mutable ButtonMaskImageMap m_buttonMasks; Skin( const Skin & ); Skin &operator=( const Skin & ); }; class SkinCache : public Singleton<SkinCache> { public: SkinCache(); QImage loadImage( const QString &name ); private: typedef QDict<QImage> ImageCache; ImageCache m_cache; ThreadUtil::Mutex m_cacheGuard; }; class SkinLoader : public ThreadUtil::Thread { public: SkinLoader(); void schedule( const QString &skinName, const QString &fileNameInfix, const MediaWidget::SkinButtonInfo *skinButtonInfo, const uint buttonCount ); protected: virtual void run(); private: struct Info { Info() : skinButtonInfo( 0 ), buttonCount( 0 ) {} Info( const QString &_skinName, const QString &_fileNameInfix, const MediaWidget::SkinButtonInfo *_skinButtonInfo, const uint _buttonCount ) : skinName( _skinName ), fileNameInfix( _fileNameInfix ), skinButtonInfo( _skinButtonInfo ), buttonCount( _buttonCount ) {} const QString skinName; const QString fileNameInfix; const MediaWidget::SkinButtonInfo *skinButtonInfo; const uint buttonCount; }; typedef QValueList<Info> InfoList; void load( const Info &nfo ); InfoList pendingSkins; ThreadUtil::Mutex guard; }; #endif // SKIN_H /* vim: et sw=4 ts=4 */ |