summaryrefslogtreecommitdiff
authorsimon <simon>2002-12-14 18:18:20 (UTC)
committer simon <simon>2002-12-14 18:18:20 (UTC)
commit7c854ad1b909f37c7314ef4ac2061500d02af16d (patch) (unidiff)
tree24528d72c0f2d36d6777090d7d93e2536ffb120d
parentae7a270c56fa0fff6d3f530c80532c54c51be596 (diff)
downloadopie-7c854ad1b909f37c7314ef4ac2061500d02af16d.zip
opie-7c854ad1b909f37c7314ef4ac2061500d02af16d.tar.gz
opie-7c854ad1b909f37c7314ef4ac2061500d02af16d.tar.bz2
- reduce memory usage a little bit by not storing the images after they
got converted to pixmaps
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/multimedia/opieplayer2/mediawidget.cpp1
-rw-r--r--noncore/multimedia/opieplayer2/skin.cpp6
-rw-r--r--noncore/multimedia/opieplayer2/skin.h4
3 files changed, 10 insertions, 1 deletions
diff --git a/noncore/multimedia/opieplayer2/mediawidget.cpp b/noncore/multimedia/opieplayer2/mediawidget.cpp
index edef2a7..46e7b6e 100644
--- a/noncore/multimedia/opieplayer2/mediawidget.cpp
+++ b/noncore/multimedia/opieplayer2/mediawidget.cpp
@@ -47,48 +47,49 @@ void MediaWidget::setupButtons( const SkinButtonInfo *skinInfo, uint buttonCount
47 buttonMask = skin.buttonMask( skinInfo, buttonCount ); 47 buttonMask = skin.buttonMask( skinInfo, buttonCount );
48 48
49 buttons.clear(); 49 buttons.clear();
50 buttons.reserve( buttonCount ); 50 buttons.reserve( buttonCount );
51 51
52 for ( uint i = 0; i < buttonCount; ++i ) { 52 for ( uint i = 0; i < buttonCount; ++i ) {
53 Button button = setupButton( skinInfo[ i ], skin ); 53 Button button = setupButton( skinInfo[ i ], skin );
54 buttons.push_back( button ); 54 buttons.push_back( button );
55 } 55 }
56} 56}
57 57
58MediaWidget::Button MediaWidget::setupButton( const SkinButtonInfo &buttonInfo, const Skin &skin ) 58MediaWidget::Button MediaWidget::setupButton( const SkinButtonInfo &buttonInfo, const Skin &skin )
59{ 59{
60 Button button; 60 Button button;
61 button.command = buttonInfo.command; 61 button.command = buttonInfo.command;
62 button.type = buttonInfo.type; 62 button.type = buttonInfo.type;
63 button.mask = skin.buttonMaskImage( buttonInfo.fileName ); 63 button.mask = skin.buttonMaskImage( buttonInfo.fileName );
64 64
65 return button; 65 return button;
66} 66}
67 67
68void MediaWidget::loadDefaultSkin( const GUIInfo &guiInfo ) 68void MediaWidget::loadDefaultSkin( const GUIInfo &guiInfo )
69{ 69{
70 Skin skin( guiInfo.fileNameInfix ); 70 Skin skin( guiInfo.fileNameInfix );
71 skin.setCachable( false );
71 loadSkin( guiInfo.buttonInfo, guiInfo.buttonCount, skin ); 72 loadSkin( guiInfo.buttonInfo, guiInfo.buttonCount, skin );
72} 73}
73 74
74void MediaWidget::loadSkin( const SkinButtonInfo *skinInfo, uint buttonCount, const Skin &skin ) 75void MediaWidget::loadSkin( const SkinButtonInfo *skinInfo, uint buttonCount, const Skin &skin )
75{ 76{
76 backgroundPixmap = skin.backgroundPixmap(); 77 backgroundPixmap = skin.backgroundPixmap();
77 buttonUpImage = skin.buttonUpImage(); 78 buttonUpImage = skin.buttonUpImage();
78 buttonDownImage = skin.buttonDownImage(); 79 buttonDownImage = skin.buttonDownImage();
79 80
80 setupButtons( skinInfo, buttonCount, skin ); 81 setupButtons( skinInfo, buttonCount, skin );
81} 82}
82 83
83void MediaWidget::closeEvent( QCloseEvent * ) 84void MediaWidget::closeEvent( QCloseEvent * )
84{ 85{
85 mediaPlayerState.setList(); 86 mediaPlayerState.setList();
86} 87}
87 88
88void MediaWidget::paintEvent( QPaintEvent *pe ) 89void MediaWidget::paintEvent( QPaintEvent *pe )
89{ 90{
90 QPainter p( this ); 91 QPainter p( this );
91 92
92 if ( mediaPlayerState.isFullscreen() ) { 93 if ( mediaPlayerState.isFullscreen() ) {
93 // Clear the background 94 // Clear the background
94 p.setBrush( QBrush( Qt::black ) ); 95 p.setBrush( QBrush( Qt::black ) );
diff --git a/noncore/multimedia/opieplayer2/skin.cpp b/noncore/multimedia/opieplayer2/skin.cpp
index a8f4ae9..44f5ca2 100644
--- a/noncore/multimedia/opieplayer2/skin.cpp
+++ b/noncore/multimedia/opieplayer2/skin.cpp
@@ -56,53 +56,57 @@ private:
56 typedef QCache<SkinData> DataCache; 56 typedef QCache<SkinData> DataCache;
57 typedef QCache<QPixmap> BackgroundPixmapCache; 57 typedef QCache<QPixmap> BackgroundPixmapCache;
58 58
59 template <class CacheType> 59 template <class CacheType>
60 void store( const QCache<CacheType> &cache, const QString &key, CacheType *data ); 60 void store( const QCache<CacheType> &cache, const QString &key, CacheType *data );
61 61
62 DataCache m_cache; 62 DataCache m_cache;
63 BackgroundPixmapCache m_backgroundPixmapCache; 63 BackgroundPixmapCache m_backgroundPixmapCache;
64}; 64};
65 65
66Skin::Skin( const QString &name, const QString &fileNameInfix ) 66Skin::Skin( const QString &name, const QString &fileNameInfix )
67 : m_fileNameInfix( fileNameInfix ) 67 : m_fileNameInfix( fileNameInfix )
68{ 68{
69 init( name ); 69 init( name );
70} 70}
71 71
72Skin::Skin( const QString &fileNameInfix ) 72Skin::Skin( const QString &fileNameInfix )
73 : m_fileNameInfix( fileNameInfix ) 73 : m_fileNameInfix( fileNameInfix )
74{ 74{
75 init( defaultSkinName() ); 75 init( defaultSkinName() );
76} 76}
77 77
78Skin::~Skin() 78Skin::~Skin()
79{ 79{
80 SkinCache::self().store( m_skinPath, m_fileNameInfix, d ); 80 if ( m_isCachable )
81 SkinCache::self().store( m_skinPath, m_fileNameInfix, d );
82 else
83 delete d;
81} 84}
82 85
83void Skin::init( const QString &name ) 86void Skin::init( const QString &name )
84{ 87{
88 m_isCachable = true;
85 m_skinPath = "opieplayer2/skins/" + name; 89 m_skinPath = "opieplayer2/skins/" + name;
86 d = SkinCache::self().lookupAndTake( m_skinPath, m_fileNameInfix ); 90 d = SkinCache::self().lookupAndTake( m_skinPath, m_fileNameInfix );
87} 91}
88 92
89QPixmap Skin::backgroundPixmap() const 93QPixmap Skin::backgroundPixmap() const
90{ 94{
91 if ( d->backgroundPixmap.isNull() ) 95 if ( d->backgroundPixmap.isNull() )
92 d->backgroundPixmap = loadImage( QString( "%1/background" ).arg( m_skinPath ) ); 96 d->backgroundPixmap = loadImage( QString( "%1/background" ).arg( m_skinPath ) );
93 return d->backgroundPixmap; 97 return d->backgroundPixmap;
94} 98}
95 99
96QImage Skin::buttonUpImage() const 100QImage Skin::buttonUpImage() const
97{ 101{
98 if ( d->buttonUpImage.isNull() ) 102 if ( d->buttonUpImage.isNull() )
99 d->buttonUpImage = loadImage( QString( "%1/skin%2_up" ).arg( m_skinPath ).arg( m_fileNameInfix ) ); 103 d->buttonUpImage = loadImage( QString( "%1/skin%2_up" ).arg( m_skinPath ).arg( m_fileNameInfix ) );
100 return d->buttonUpImage; 104 return d->buttonUpImage;
101} 105}
102 106
103QImage Skin::buttonDownImage() const 107QImage Skin::buttonDownImage() const
104{ 108{
105 if ( d->buttonDownImage.isNull() ) 109 if ( d->buttonDownImage.isNull() )
106 d->buttonDownImage = loadImage( QString( "%1/skin%2_down" ).arg( m_skinPath ).arg( m_fileNameInfix ) ); 110 d->buttonDownImage = loadImage( QString( "%1/skin%2_down" ).arg( m_skinPath ).arg( m_fileNameInfix ) );
107 return d->buttonDownImage; 111 return d->buttonDownImage;
108} 112}
diff --git a/noncore/multimedia/opieplayer2/skin.h b/noncore/multimedia/opieplayer2/skin.h
index bafebd3..067b6c4 100644
--- a/noncore/multimedia/opieplayer2/skin.h
+++ b/noncore/multimedia/opieplayer2/skin.h
@@ -17,67 +17,71 @@
17 You should have received a copy of the GNU General Public License 17 You should have received a copy of the GNU General Public License
18 along with this program; see the file COPYING. If not, write to 18 along with this program; see the file COPYING. If not, write to
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. 20 Boston, MA 02111-1307, USA.
21*/ 21*/
22 22
23#ifndef SKIN_H 23#ifndef SKIN_H
24#define SKIN_H 24#define SKIN_H
25 25
26#include <qstring.h> 26#include <qstring.h>
27#include <qimage.h> 27#include <qimage.h>
28#include <qobject.h> 28#include <qobject.h>
29 29
30#include "mediawidget.h" 30#include "mediawidget.h"
31 31
32struct SkinData; 32struct SkinData;
33 33
34class Skin 34class Skin
35{ 35{
36public: 36public:
37 Skin( const QString &name, const QString &fileNameInfix ); 37 Skin( const QString &name, const QString &fileNameInfix );
38 Skin( const QString &fileNameInfix ); 38 Skin( const QString &fileNameInfix );
39 ~Skin(); 39 ~Skin();
40 40
41 bool isCachable() const { return m_isCachable; }
42 void setCachable( bool cachable ) { m_isCachable = cachable; }
43
41 QPixmap backgroundPixmap() const; 44 QPixmap backgroundPixmap() const;
42 QImage buttonUpImage() const; 45 QImage buttonUpImage() const;
43 QImage buttonDownImage() const; 46 QImage buttonDownImage() const;
44 47
45 QImage buttonMask( const MediaWidget::SkinButtonInfo *skinButtonInfo, uint buttonCount ) const; 48 QImage buttonMask( const MediaWidget::SkinButtonInfo *skinButtonInfo, uint buttonCount ) const;
46 49
47 QImage buttonMaskImage( const QString &fileName ) const; 50 QImage buttonMaskImage( const QString &fileName ) const;
48 51
49 static QString defaultSkinName(); 52 static QString defaultSkinName();
50 53
51private: 54private:
52 void init( const QString &name ); 55 void init( const QString &name );
53 56
54 void addButtonToMask( int tag, const QImage &maskImage ) const; 57 void addButtonToMask( int tag, const QImage &maskImage ) const;
55 58
56 static QImage loadImage( const QString &fileName ); 59 static QImage loadImage( const QString &fileName );
57 60
58 QString m_fileNameInfix; 61 QString m_fileNameInfix;
59 QString m_skinPath; 62 QString m_skinPath;
63 bool m_isCachable : 1;
60 64
61 SkinData *d; 65 SkinData *d;
62 66
63 Skin( const Skin & ); 67 Skin( const Skin & );
64 Skin &operator=( const Skin & ); 68 Skin &operator=( const Skin & );
65}; 69};
66 70
67class SkinLoader : public QObject 71class SkinLoader : public QObject
68{ 72{
69 Q_OBJECT 73 Q_OBJECT
70public: 74public:
71 SkinLoader(); 75 SkinLoader();
72 virtual ~SkinLoader(); 76 virtual ~SkinLoader();
73 77
74 void schedule( const MediaWidget::GUIInfo &guiInfo ); 78 void schedule( const MediaWidget::GUIInfo &guiInfo );
75 void schedule( const QString &skinName, const MediaWidget::GUIInfo &guiInfo ); 79 void schedule( const QString &skinName, const MediaWidget::GUIInfo &guiInfo );
76 80
77 void start(); 81 void start();
78 82
79protected: 83protected:
80 virtual void timerEvent( QTimerEvent *ev ); 84 virtual void timerEvent( QTimerEvent *ev );
81 85
82private slots: 86private slots:
83 void deleteMe(); 87 void deleteMe();