summaryrefslogtreecommitdiff
Side-by-side diff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/multimedia/opieplayer2/skin.cpp46
-rw-r--r--noncore/multimedia/opieplayer2/skin.h4
2 files changed, 25 insertions, 25 deletions
diff --git a/noncore/multimedia/opieplayer2/skin.cpp b/noncore/multimedia/opieplayer2/skin.cpp
index e9fb5a6..d6f4080 100644
--- a/noncore/multimedia/opieplayer2/skin.cpp
+++ b/noncore/multimedia/opieplayer2/skin.cpp
@@ -15,111 +15,111 @@
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 "singleton.h"
#include <qcache.h>
#include <qmap.h>
#include <qtimer.h>
#include <qpe/resource.h>
#include <qpe/config.h>
#include <assert.h>
struct SkinData
{
typedef QMap<QString, QImage> ButtonMaskImageMap;
- QImage backgroundImage;
+ QPixmap backgroundPixmap;
QImage buttonUpImage;
QImage buttonDownImage;
QImage buttonMask;
ButtonMaskImageMap buttonMasks;
};
class SkinCache : public Singleton<SkinCache>
{
public:
SkinCache();
SkinData *lookupAndTake( const QString &skinPath, const QString &fileNameInfix );
void store( const QString &skinPath, const QString &fileNameInfix, SkinData *data );
private:
typedef QCache<SkinData> DataCache;
- typedef QCache<QImage> BackgroundImageCache;
+ typedef QCache<QPixmap> BackgroundPixmapCache;
template <class CacheType>
void store( const QCache<CacheType> &cache, const QString &key, CacheType *data );
DataCache m_cache;
- BackgroundImageCache m_backgroundImageCache;
+ BackgroundPixmapCache m_backgroundPixmapCache;
};
Skin::Skin( const QString &name, const QString &fileNameInfix )
: m_fileNameInfix( fileNameInfix )
{
init( name );
}
Skin::Skin( const QString &fileNameInfix )
: m_fileNameInfix( fileNameInfix )
{
init( defaultSkinName() );
}
Skin::~Skin()
{
SkinCache::self().store( m_skinPath, m_fileNameInfix, d );
}
void Skin::init( const QString &name )
{
m_skinPath = "opieplayer2/skins/" + name;
d = SkinCache::self().lookupAndTake( m_skinPath, m_fileNameInfix );
}
void Skin::preload( const MediaWidget::SkinButtonInfo *skinButtonInfo, uint buttonCount )
{
- backgroundImage();
+ backgroundPixmap();
buttonUpImage();
buttonDownImage();
( void )buttonMask( skinButtonInfo, buttonCount );
}
-QImage Skin::backgroundImage() const
+QPixmap Skin::backgroundPixmap() const
{
- if ( d->backgroundImage.isNull() )
- d->backgroundImage = loadImage( QString( "%1/background" ).arg( m_skinPath ) );
- return d->backgroundImage;
+ if ( d->backgroundPixmap.isNull() )
+ d->backgroundPixmap = loadImage( QString( "%1/background" ).arg( m_skinPath ) );
+ return d->backgroundPixmap;
}
QImage Skin::buttonUpImage() const
{
if ( d->buttonUpImage.isNull() )
d->buttonUpImage = loadImage( QString( "%1/skin%2_up" ).arg( m_skinPath ).arg( m_fileNameInfix ) );
return d->buttonUpImage;
}
QImage Skin::buttonDownImage() const
{
if ( d->buttonDownImage.isNull() )
d->buttonDownImage = loadImage( QString( "%1/skin%2_down" ).arg( m_skinPath ).arg( m_fileNameInfix ) );
return d->buttonDownImage;
}
QImage Skin::buttonMask( const MediaWidget::SkinButtonInfo *skinButtonInfo, uint buttonCount ) const
{
if ( !d->buttonMask.isNull() )
return d->buttonMask;
QSize buttonAreaSize = buttonUpImage().size();
d->buttonMask = QImage( buttonAreaSize, 8, 255 );
@@ -152,101 +152,101 @@ QImage Skin::buttonMaskImage( const QString &fileName ) const
QString prefix = m_skinPath + QString::fromLatin1( "/skin%1_mask_" ).arg( m_fileNameInfix );
QString path = prefix + fileName + ".png";
it = d->buttonMasks.insert( fileName, loadImage( path ) );
}
return *it;
}
QString Skin::defaultSkinName()
{
Config cfg( "OpiePlayer" );
cfg.setGroup( "Options" );
return cfg.readEntry( "Skin", "default" );
}
QImage Skin::loadImage( const QString &fileName )
{
return QImage( Resource::findPixmap( fileName ) );
}
SkinCache::SkinCache()
{
// let's say we cache two skins (audio+video) at maximum
m_cache.setMaxCost( 2 );
// ... and one background pixmap
- m_backgroundImageCache.setMaxCost( 1 );
+ m_backgroundPixmapCache.setMaxCost( 1 );
}
SkinData *SkinCache::lookupAndTake( const QString &skinPath, const QString &fileNameInfix )
{
QString key = skinPath + fileNameInfix;
SkinData *data = m_cache.take( key );
if ( !data )
data = new SkinData;
else
qDebug( "SkinCache: hit" );
- QImage *bgImage = m_backgroundImageCache.find( skinPath );
- if ( bgImage ) {
- qDebug( "SkinCache: hit on bgimage" );
- data->backgroundImage = *bgImage;
+ QPixmap *bgPixmap = m_backgroundPixmapCache.find( skinPath );
+ if ( bgPixmap ) {
+ qDebug( "SkinCache: hit on bgpixmap" );
+ data->backgroundPixmap = *bgPixmap;
}
else
- data->backgroundImage = QImage();
+ data->backgroundPixmap = QPixmap();
return data;
}
void SkinCache::store( const QString &skinPath, const QString &fileNameInfix, SkinData *data )
{
- QImage *backgroundImage = new QImage( data->backgroundImage );
+ QPixmap *backgroundPixmap = new QPixmap( data->backgroundPixmap );
- data->backgroundImage = QImage();
+ data->backgroundPixmap = QPixmap();
QString key = skinPath + fileNameInfix;
if ( m_cache.find( key, false /*ref*/ ) != 0 ||
!m_cache.insert( key, data ) )
delete data;
- if ( m_backgroundImageCache.find( skinPath, false /*ref*/ ) != 0 ||
- !m_backgroundImageCache.insert( skinPath, backgroundImage ) )
- delete backgroundImage;
+ if ( m_backgroundPixmapCache.find( skinPath, false /*ref*/ ) != 0 ||
+ !m_backgroundPixmapCache.insert( skinPath, backgroundPixmap ) )
+ delete backgroundPixmap;
}
SkinLoader::IncrementalLoader::IncrementalLoader( const Info &info )
: m_skin( info.skinName, info.fileNameInfix ), m_info( info )
{
- m_currentState = LoadBackgroundImage;
+ m_currentState = LoadBackgroundPixmap;
}
SkinLoader::IncrementalLoader::LoaderResult SkinLoader::IncrementalLoader::loadStep()
{
switch ( m_currentState ) {
- case LoadBackgroundImage:
- qDebug( "load bgimage" );
- m_skin.backgroundImage();
+ case LoadBackgroundPixmap:
+ qDebug( "load bgpixmap" );
+ m_skin.backgroundPixmap();
m_currentState = LoadButtonUpImage;
break;
case LoadButtonUpImage:
qDebug( "load upimage" );
m_skin.buttonUpImage();
m_currentState = LoadButtonDownImage;
break;
case LoadButtonDownImage:
qDebug( "load downimage" );
m_skin.buttonDownImage();
m_currentState = LoadButtonMasks;
m_currentButton = 0;
break;
case LoadButtonMasks:
qDebug( "load button masks %i", m_currentButton );
m_skin.buttonMaskImage( m_info.buttonInfo[ m_currentButton ].fileName );
m_currentButton++;
if ( m_currentButton >= m_info.buttonCount )
m_currentState = LoadButtonMask;
break;
case LoadButtonMask:
qDebug( "load whole mask" );
diff --git a/noncore/multimedia/opieplayer2/skin.h b/noncore/multimedia/opieplayer2/skin.h
index a43a1d0..90062c2 100644
--- a/noncore/multimedia/opieplayer2/skin.h
+++ b/noncore/multimedia/opieplayer2/skin.h
@@ -19,49 +19,49 @@
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 <qobject.h>
#include "mediawidget.h"
struct SkinData;
class Skin
{
public:
Skin( const QString &name, const QString &fileNameInfix );
Skin( const QString &fileNameInfix );
~Skin();
void preload( const MediaWidget::SkinButtonInfo *skinButtonInfo, uint buttonCount );
- QImage backgroundImage() const;
+ QPixmap backgroundPixmap() 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;
static QImage loadImage( const QString &fileName );
QString m_fileNameInfix;
QString m_skinPath;
SkinData *d;
Skin( const Skin & );
Skin &operator=( const Skin & );
};
@@ -85,40 +85,40 @@ private slots:
void deleteMe();
private:
struct Info : public MediaWidget::GUIInfo
{
Info() {}
Info( const QString &_skinName, const MediaWidget::GUIInfo &guiInfo )
: MediaWidget::GUIInfo( guiInfo ), skinName( _skinName )
{}
QString skinName;
};
typedef QValueList<Info> InfoList;
class IncrementalLoader
{
public:
enum LoaderResult { LoadingCompleted, MoreToCome };
IncrementalLoader( const Info &info );
LoaderResult loadStep();
private:
- enum State { LoadBackgroundImage, LoadButtonUpImage, LoadButtonDownImage, LoadButtonMasks, LoadButtonMask };
+ enum State { LoadBackgroundPixmap, LoadButtonUpImage, LoadButtonDownImage, LoadButtonMasks, LoadButtonMask };
Skin m_skin;
Info m_info;
State m_currentState;
uint m_currentButton;
};
InfoList pendingSkins;
IncrementalLoader *m_currentLoader;
int m_timerId;
};
#endif // SKIN_H
/* vim: et sw=4 ts=4
*/