Diffstat (limited to 'noncore/multimedia/opieplayer2/skin.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/multimedia/opieplayer2/skin.cpp | 36 |
1 files changed, 33 insertions, 3 deletions
diff --git a/noncore/multimedia/opieplayer2/skin.cpp b/noncore/multimedia/opieplayer2/skin.cpp index 7d05d80..ef70957 100644 --- a/noncore/multimedia/opieplayer2/skin.cpp +++ b/noncore/multimedia/opieplayer2/skin.cpp | |||
@@ -1,53 +1,83 @@ | |||
1 | 1 | ||
2 | #include "skin.h" | 2 | #include "skin.h" |
3 | 3 | ||
4 | #include <qpe/resource.h> | 4 | #include <qpe/resource.h> |
5 | 5 | ||
6 | Skin::Skin( const QString &name, const QString &fileNameInfix ) | 6 | Skin::Skin( const QString &name, const QString &fileNameInfix ) |
7 | : m_name( name ), m_fileNameInfix( fileNameInfix ) | 7 | : m_name( name ), m_fileNameInfix( fileNameInfix ) |
8 | { | 8 | { |
9 | m_skinPath = "opieplayer2/skins/" + name; | 9 | m_skinPath = "opieplayer2/skins/" + name; |
10 | } | 10 | } |
11 | 11 | ||
12 | void Skin::preload( const MediaWidget::SkinButtonInfo *skinButtonInfo, uint buttonCount ) | 12 | void Skin::preload( const MediaWidget::SkinButtonInfo *skinButtonInfo, uint buttonCount, const QSize &buttonAreaSize ) |
13 | { | 13 | { |
14 | backgroundImage(); | 14 | backgroundImage(); |
15 | buttonUpImage(); | 15 | buttonUpImage(); |
16 | buttonDownImage(); | 16 | buttonDownImage(); |
17 | for ( uint i = 0; i < buttonCount; ++i ) | 17 | ( void )buttonMask( skinButtonInfo, buttonCount, buttonAreaSize ); |
18 | ( void )buttonMaskImage( skinButtonInfo[ i ].fileName ); | ||
19 | } | 18 | } |
20 | 19 | ||
21 | QImage Skin::backgroundImage() const | 20 | QImage Skin::backgroundImage() const |
22 | { | 21 | { |
23 | if ( m_backgroundImage.isNull() ) | 22 | if ( m_backgroundImage.isNull() ) |
24 | m_backgroundImage = QImage( Resource::findPixmap( QString( "%1/background" ).arg( m_skinPath ) ) ); | 23 | m_backgroundImage = QImage( Resource::findPixmap( QString( "%1/background" ).arg( m_skinPath ) ) ); |
25 | return m_backgroundImage; | 24 | return m_backgroundImage; |
26 | } | 25 | } |
27 | 26 | ||
28 | QImage Skin::buttonUpImage() const | 27 | QImage Skin::buttonUpImage() const |
29 | { | 28 | { |
30 | if ( m_buttonUpImage.isNull() ) | 29 | if ( m_buttonUpImage.isNull() ) |
31 | m_buttonUpImage = QImage( Resource::findPixmap( QString( "%1/skin%2_up" ).arg( m_skinPath ).arg( m_fileNameInfix ) ) ); | 30 | m_buttonUpImage = QImage( Resource::findPixmap( QString( "%1/skin%2_up" ).arg( m_skinPath ).arg( m_fileNameInfix ) ) ); |
32 | return m_buttonUpImage; | 31 | return m_buttonUpImage; |
33 | } | 32 | } |
34 | 33 | ||
35 | QImage Skin::buttonDownImage() const | 34 | QImage Skin::buttonDownImage() const |
36 | { | 35 | { |
37 | if ( m_buttonDownImage.isNull() ) | 36 | if ( m_buttonDownImage.isNull() ) |
38 | m_buttonDownImage = QImage( Resource::findPixmap( QString( "%1/skin%2_down" ).arg( m_skinPath ).arg( m_fileNameInfix ) ) ); | 37 | m_buttonDownImage = QImage( Resource::findPixmap( QString( "%1/skin%2_down" ).arg( m_skinPath ).arg( m_fileNameInfix ) ) ); |
39 | return m_buttonDownImage; | 38 | return m_buttonDownImage; |
40 | } | 39 | } |
41 | 40 | ||
41 | QImage Skin::buttonMask( const MediaWidget::SkinButtonInfo *skinButtonInfo, uint buttonCount, const QSize &buttonAreaSize ) const | ||
42 | { | ||
43 | if ( buttonAreaSize != m_buttonMask.size() ) | ||
44 | m_buttonMask = QImage(); | ||
45 | |||
46 | if ( !m_buttonMask.isNull() ) | ||
47 | return m_buttonMask; | ||
48 | |||
49 | m_buttonMask = QImage( buttonAreaSize, 8, 255 ); | ||
50 | m_buttonMask.fill( 0 ); | ||
51 | |||
52 | for ( uint i = 0; i < buttonCount; ++i ) | ||
53 | addButtonToMask( skinButtonInfo[ i ].command + 1, buttonMaskImage( skinButtonInfo[ i ].fileName ) ); | ||
54 | |||
55 | return m_buttonMask; | ||
56 | } | ||
57 | |||
58 | void Skin::addButtonToMask( int tag, const QImage &maskImage ) const | ||
59 | { | ||
60 | if ( maskImage.isNull() ) | ||
61 | return; | ||
62 | |||
63 | uchar **dest = m_buttonMask.jumpTable(); | ||
64 | for ( int y = 0; y < m_buttonMask.height(); y++ ) { | ||
65 | uchar *line = dest[y]; | ||
66 | for ( int x = 0; x < m_buttonMask.width(); x++ ) | ||
67 | if ( !qRed( maskImage.pixel( x, y ) ) ) | ||
68 | line[x] = tag; | ||
69 | } | ||
70 | } | ||
71 | |||
42 | QImage Skin::buttonMaskImage( const QString &fileName ) const | 72 | QImage Skin::buttonMaskImage( const QString &fileName ) const |
43 | { | 73 | { |
44 | ButtonMaskImageMap::Iterator it = m_buttonMasks.find( fileName ); | 74 | ButtonMaskImageMap::Iterator it = m_buttonMasks.find( fileName ); |
45 | if ( it == m_buttonMasks.end() ) { | 75 | if ( it == m_buttonMasks.end() ) { |
46 | QString prefix = m_skinPath + QString::fromLatin1( "/skin%1_mask_" ).arg( m_fileNameInfix ); | 76 | QString prefix = m_skinPath + QString::fromLatin1( "/skin%1_mask_" ).arg( m_fileNameInfix ); |
47 | QString path = prefix + fileName + ".png"; | 77 | QString path = prefix + fileName + ".png"; |
48 | it = m_buttonMasks.insert( fileName, QImage( Resource::findPixmap( path ) ) ); | 78 | it = m_buttonMasks.insert( fileName, QImage( Resource::findPixmap( path ) ) ); |
49 | } | 79 | } |
50 | return *it; | 80 | return *it; |
51 | } | 81 | } |
52 | 82 | ||
53 | /* vim: et sw=4 ts=4 | 83 | /* vim: et sw=4 ts=4 |