Diffstat (limited to 'noncore/multimedia/opieplayer2/skin.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | noncore/multimedia/opieplayer2/skin.cpp | 58 |
1 files changed, 54 insertions, 4 deletions
diff --git a/noncore/multimedia/opieplayer2/skin.cpp b/noncore/multimedia/opieplayer2/skin.cpp index 8281b20..0de3023 100644 --- a/noncore/multimedia/opieplayer2/skin.cpp +++ b/noncore/multimedia/opieplayer2/skin.cpp | |||
@@ -1,18 +1,20 @@ | |||
1 | 1 | ||
2 | #include "skin.h" | 2 | #include "skin.h" |
3 | 3 | ||
4 | #include <qpe/resource.h> | 4 | #include <qpe/resource.h> |
5 | #include <qpe/config.h> | 5 | #include <qpe/config.h> |
6 | 6 | ||
7 | #include <assert.h> | ||
8 | |||
7 | Skin::Skin( const QString &name, const QString &fileNameInfix ) | 9 | Skin::Skin( const QString &name, const QString &fileNameInfix ) |
8 | : m_fileNameInfix( fileNameInfix ) | 10 | : m_fileNameInfix( fileNameInfix ) |
9 | { | 11 | { |
10 | init( name ); | 12 | init( name ); |
11 | } | 13 | } |
12 | 14 | ||
13 | Skin::Skin( const QString &fileNameInfix ) | 15 | Skin::Skin( const QString &fileNameInfix ) |
14 | : m_fileNameInfix( fileNameInfix ) | 16 | : m_fileNameInfix( fileNameInfix ) |
15 | { | 17 | { |
16 | init( defaultSkinName() ); | 18 | init( defaultSkinName() ); |
17 | } | 19 | } |
18 | 20 | ||
@@ -23,39 +25,39 @@ void Skin::init( const QString &name ) | |||
23 | 25 | ||
24 | void Skin::preload( const MediaWidget::SkinButtonInfo *skinButtonInfo, uint buttonCount ) | 26 | void Skin::preload( const MediaWidget::SkinButtonInfo *skinButtonInfo, uint buttonCount ) |
25 | { | 27 | { |
26 | backgroundImage(); | 28 | backgroundImage(); |
27 | buttonUpImage(); | 29 | buttonUpImage(); |
28 | buttonDownImage(); | 30 | buttonDownImage(); |
29 | ( void )buttonMask( skinButtonInfo, buttonCount ); | 31 | ( void )buttonMask( skinButtonInfo, buttonCount ); |
30 | } | 32 | } |
31 | 33 | ||
32 | QImage Skin::backgroundImage() const | 34 | QImage Skin::backgroundImage() const |
33 | { | 35 | { |
34 | if ( m_backgroundImage.isNull() ) | 36 | if ( m_backgroundImage.isNull() ) |
35 | m_backgroundImage = QImage( Resource::findPixmap( QString( "%1/background" ).arg( m_skinPath ) ) ); | 37 | m_backgroundImage = SkinCache::self().loadImage( QString( "%1/background" ).arg( m_skinPath ) ); |
36 | return m_backgroundImage; | 38 | return m_backgroundImage; |
37 | } | 39 | } |
38 | 40 | ||
39 | QImage Skin::buttonUpImage() const | 41 | QImage Skin::buttonUpImage() const |
40 | { | 42 | { |
41 | if ( m_buttonUpImage.isNull() ) | 43 | if ( m_buttonUpImage.isNull() ) |
42 | m_buttonUpImage = QImage( Resource::findPixmap( QString( "%1/skin%2_up" ).arg( m_skinPath ).arg( m_fileNameInfix ) ) ); | 44 | m_buttonUpImage = SkinCache::self().loadImage( QString( "%1/skin%2_up" ).arg( m_skinPath ).arg( m_fileNameInfix ) ); |
43 | return m_buttonUpImage; | 45 | return m_buttonUpImage; |
44 | } | 46 | } |
45 | 47 | ||
46 | QImage Skin::buttonDownImage() const | 48 | QImage Skin::buttonDownImage() const |
47 | { | 49 | { |
48 | if ( m_buttonDownImage.isNull() ) | 50 | if ( m_buttonDownImage.isNull() ) |
49 | m_buttonDownImage = QImage( Resource::findPixmap( QString( "%1/skin%2_down" ).arg( m_skinPath ).arg( m_fileNameInfix ) ) ); | 51 | m_buttonDownImage = SkinCache::self().loadImage( QString( "%1/skin%2_down" ).arg( m_skinPath ).arg( m_fileNameInfix ) ); |
50 | return m_buttonDownImage; | 52 | return m_buttonDownImage; |
51 | } | 53 | } |
52 | 54 | ||
53 | QImage Skin::buttonMask( const MediaWidget::SkinButtonInfo *skinButtonInfo, uint buttonCount ) const | 55 | QImage Skin::buttonMask( const MediaWidget::SkinButtonInfo *skinButtonInfo, uint buttonCount ) const |
54 | { | 56 | { |
55 | if ( !m_buttonMask.isNull() ) | 57 | if ( !m_buttonMask.isNull() ) |
56 | return m_buttonMask; | 58 | return m_buttonMask; |
57 | 59 | ||
58 | QSize buttonAreaSize = buttonUpImage().size(); | 60 | QSize buttonAreaSize = buttonUpImage().size(); |
59 | 61 | ||
60 | m_buttonMask = QImage( buttonAreaSize, 8, 255 ); | 62 | m_buttonMask = QImage( buttonAreaSize, 8, 255 ); |
61 | m_buttonMask.fill( 0 ); | 63 | m_buttonMask.fill( 0 ); |
@@ -77,26 +79,74 @@ void Skin::addButtonToMask( int tag, const QImage &maskImage ) const | |||
77 | for ( int x = 0; x < m_buttonMask.width(); x++ ) | 79 | for ( int x = 0; x < m_buttonMask.width(); x++ ) |
78 | if ( !qRed( maskImage.pixel( x, y ) ) ) | 80 | if ( !qRed( maskImage.pixel( x, y ) ) ) |
79 | line[x] = tag; | 81 | line[x] = tag; |
80 | } | 82 | } |
81 | } | 83 | } |
82 | 84 | ||
83 | QImage Skin::buttonMaskImage( const QString &fileName ) const | 85 | QImage Skin::buttonMaskImage( const QString &fileName ) const |
84 | { | 86 | { |
85 | ButtonMaskImageMap::Iterator it = m_buttonMasks.find( fileName ); | 87 | ButtonMaskImageMap::Iterator it = m_buttonMasks.find( fileName ); |
86 | if ( it == m_buttonMasks.end() ) { | 88 | if ( it == m_buttonMasks.end() ) { |
87 | QString prefix = m_skinPath + QString::fromLatin1( "/skin%1_mask_" ).arg( m_fileNameInfix ); | 89 | QString prefix = m_skinPath + QString::fromLatin1( "/skin%1_mask_" ).arg( m_fileNameInfix ); |
88 | QString path = prefix + fileName + ".png"; | 90 | QString path = prefix + fileName + ".png"; |
89 | it = m_buttonMasks.insert( fileName, QImage( Resource::findPixmap( path ) ) ); | 91 | it = m_buttonMasks.insert( fileName, SkinCache::self().loadImage( path ) ); |
90 | } | 92 | } |
91 | return *it; | 93 | return *it; |
92 | } | 94 | } |
93 | 95 | ||
94 | QString Skin::defaultSkinName() | 96 | QString Skin::defaultSkinName() |
95 | { | 97 | { |
96 | Config cfg( "OpiePlayer" ); | 98 | Config cfg( "OpiePlayer" ); |
97 | cfg.setGroup( "Options" ); | 99 | cfg.setGroup( "Options" ); |
98 | return cfg.readEntry( "Skin", "default" ); | 100 | return cfg.readEntry( "Skin", "default" ); |
99 | } | 101 | } |
100 | 102 | ||
103 | SkinCache::SkinCache() | ||
104 | { | ||
105 | m_cache.setAutoDelete( true ); | ||
106 | } | ||
107 | |||
108 | QImage SkinCache::loadImage( const QString &name ) | ||
109 | { | ||
110 | ThreadUtil::AutoLock lock( m_cacheGuard ); | ||
111 | |||
112 | QImage *image = m_cache.find( name ); | ||
113 | if ( image ) { | ||
114 | qDebug( "cache hit for %s", name.ascii() ); | ||
115 | return *image; | ||
116 | } | ||
117 | |||
118 | image = new QImage( Resource::findPixmap( name ) ); | ||
119 | m_cache.insert( name, image ); | ||
120 | return *image; | ||
121 | } | ||
122 | |||
123 | SkinLoader::SkinLoader() | ||
124 | { | ||
125 | } | ||
126 | |||
127 | void SkinLoader::schedule( const QString &skinName, const QString &fileNameInfix, | ||
128 | const MediaWidget::SkinButtonInfo *skinButtonInfo, const uint buttonCount ) | ||
129 | { | ||
130 | assert( isRunning() == false ); | ||
131 | |||
132 | pendingSkins << Info( skinName, fileNameInfix, skinButtonInfo, buttonCount ); | ||
133 | } | ||
134 | |||
135 | void SkinLoader::run() | ||
136 | { | ||
137 | qDebug( "SkinLoader::run()" ); | ||
138 | for ( InfoList::ConstIterator it = pendingSkins.begin(); it != pendingSkins.end(); ++it ) | ||
139 | load( *it ); | ||
140 | qDebug( "SkinLoader is done." ); | ||
141 | } | ||
142 | |||
143 | void SkinLoader::load( const Info &nfo ) | ||
144 | { | ||
145 | qDebug( "preloading %s with infix %s", nfo.skinName.ascii(), nfo.fileNameInfix.ascii() ); | ||
146 | |||
147 | Skin skin( nfo.skinName, nfo.fileNameInfix ); | ||
148 | skin.preload( nfo.skinButtonInfo, nfo.buttonCount ); | ||
149 | } | ||
150 | |||
101 | /* vim: et sw=4 ts=4 | 151 | /* vim: et sw=4 ts=4 |
102 | */ | 152 | */ |