-rw-r--r-- | noncore/multimedia/opieplayer2/mediawidget.cpp | 24 | ||||
-rw-r--r-- | noncore/multimedia/opieplayer2/mediawidget.h | 1 | ||||
-rw-r--r-- | noncore/multimedia/opieplayer2/skin.cpp | 36 | ||||
-rw-r--r-- | noncore/multimedia/opieplayer2/skin.h | 7 |
4 files changed, 41 insertions, 27 deletions
diff --git a/noncore/multimedia/opieplayer2/mediawidget.cpp b/noncore/multimedia/opieplayer2/mediawidget.cpp index 4de7ea9..da0706e 100644 --- a/noncore/multimedia/opieplayer2/mediawidget.cpp +++ b/noncore/multimedia/opieplayer2/mediawidget.cpp | |||
@@ -46,8 +46,7 @@ MediaWidget::~MediaWidget() | |||
46 | void MediaWidget::setupButtons( const SkinButtonInfo *skinInfo, uint buttonCount, | 46 | void MediaWidget::setupButtons( const SkinButtonInfo *skinInfo, uint buttonCount, |
47 | const Skin &skin, const QSize &buttonAreaSize ) | 47 | const Skin &skin, const QSize &buttonAreaSize ) |
48 | { | 48 | { |
49 | buttonMask = QImage( buttonAreaSize, 8, 255 ); | 49 | buttonMask = skin.buttonMask( skinInfo, buttonCount, buttonAreaSize ); |
50 | buttonMask.fill( 0 ); | ||
51 | 50 | ||
52 | buttons.clear(); | 51 | buttons.clear(); |
53 | buttons.reserve( buttonCount ); | 52 | buttons.reserve( buttonCount ); |
@@ -63,30 +62,11 @@ MediaWidget::Button MediaWidget::setupButton( const SkinButtonInfo &buttonInfo, | |||
63 | Button button; | 62 | Button button; |
64 | button.command = buttonInfo.command; | 63 | button.command = buttonInfo.command; |
65 | button.type = buttonInfo.type; | 64 | button.type = buttonInfo.type; |
66 | 65 | button.mask = skin.buttonMaskImage( buttonInfo.fileName ); | |
67 | button.mask = setupButtonMask( button.command, skin.buttonMaskImage( buttonInfo.fileName ) ); | ||
68 | 66 | ||
69 | return button; | 67 | return button; |
70 | } | 68 | } |
71 | 69 | ||
72 | QBitmap MediaWidget::setupButtonMask( const Command &command, const QImage &maskImage ) | ||
73 | { | ||
74 | if ( maskImage.isNull() ) | ||
75 | return QBitmap(); | ||
76 | |||
77 | uchar **dest = buttonMask.jumpTable(); | ||
78 | for ( int y = 0; y < buttonMask.height(); y++ ) { | ||
79 | uchar *line = dest[y]; | ||
80 | for ( int x = 0; x < buttonMask.width(); x++ ) | ||
81 | if ( !qRed( maskImage.pixel( x, y ) ) ) | ||
82 | line[x] = command + 1; | ||
83 | } | ||
84 | |||
85 | // ### grmbl qt2. use constructor when switching to qt3. | ||
86 | QBitmap bm; bm = maskImage; | ||
87 | return bm; | ||
88 | } | ||
89 | |||
90 | void MediaWidget::loadDefaultSkin( const SkinButtonInfo *skinInfo, uint buttonCount, const QString &fileNameInfix ) | 70 | void MediaWidget::loadDefaultSkin( const SkinButtonInfo *skinInfo, uint buttonCount, const QString &fileNameInfix ) |
91 | { | 71 | { |
92 | Config cfg( "OpiePlayer" ); | 72 | Config cfg( "OpiePlayer" ); |
diff --git a/noncore/multimedia/opieplayer2/mediawidget.h b/noncore/multimedia/opieplayer2/mediawidget.h index 0d635aa..4bd8760 100644 --- a/noncore/multimedia/opieplayer2/mediawidget.h +++ b/noncore/multimedia/opieplayer2/mediawidget.h | |||
@@ -104,7 +104,6 @@ protected: | |||
104 | void setupButtons( const SkinButtonInfo *skinInfo, uint buttonCount, | 104 | void setupButtons( const SkinButtonInfo *skinInfo, uint buttonCount, |
105 | const Skin &skin, const QSize &buttonAreaSize ); | 105 | const Skin &skin, const QSize &buttonAreaSize ); |
106 | Button setupButton( const SkinButtonInfo &buttonInfo, const Skin &skin ); | 106 | Button setupButton( const SkinButtonInfo &buttonInfo, const Skin &skin ); |
107 | QBitmap setupButtonMask( const Command &command, const QImage &maskImage ); | ||
108 | 107 | ||
109 | void loadDefaultSkin( const SkinButtonInfo *skinInfo, uint buttonCount, const QString &fileNameInfix = QString::null ); | 108 | void loadDefaultSkin( const SkinButtonInfo *skinInfo, uint buttonCount, const QString &fileNameInfix = QString::null ); |
110 | void loadSkin( const SkinButtonInfo *skinInfo, uint buttonCount, const QString &name, const QString &fileNameInfix ); | 109 | void loadSkin( const SkinButtonInfo *skinInfo, uint buttonCount, const QString &name, const QString &fileNameInfix ); |
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 | |||
@@ -9,13 +9,12 @@ Skin::Skin( const QString &name, const QString &fileNameInfix ) | |||
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 |
@@ -39,6 +38,37 @@ QImage Skin::buttonDownImage() const | |||
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 ); |
diff --git a/noncore/multimedia/opieplayer2/skin.h b/noncore/multimedia/opieplayer2/skin.h index 9276a5b..14873e7 100644 --- a/noncore/multimedia/opieplayer2/skin.h +++ b/noncore/multimedia/opieplayer2/skin.h | |||
@@ -12,15 +12,19 @@ class Skin | |||
12 | public: | 12 | public: |
13 | Skin( const QString &name, const QString &fileNameInfix ); | 13 | Skin( const QString &name, const QString &fileNameInfix ); |
14 | 14 | ||
15 | void preload( const MediaWidget::SkinButtonInfo *skinButtonInfo, uint buttonCount ); | 15 | void preload( const MediaWidget::SkinButtonInfo *skinButtonInfo, uint buttonCount, const QSize &buttonAreaSize ); |
16 | 16 | ||
17 | QImage backgroundImage() const; | 17 | QImage backgroundImage() const; |
18 | QImage buttonUpImage() const; | 18 | QImage buttonUpImage() const; |
19 | QImage buttonDownImage() const; | 19 | QImage buttonDownImage() const; |
20 | 20 | ||
21 | QImage buttonMask( const MediaWidget::SkinButtonInfo *skinButtonInfo, uint buttonCount, const QSize &buttonAreaSize ) const; | ||
22 | |||
21 | QImage buttonMaskImage( const QString &fileName ) const; | 23 | QImage buttonMaskImage( const QString &fileName ) const; |
22 | 24 | ||
23 | private: | 25 | private: |
26 | void addButtonToMask( int tag, const QImage &maskImage ) const; | ||
27 | |||
24 | QString m_name; | 28 | QString m_name; |
25 | QString m_fileNameInfix; | 29 | QString m_fileNameInfix; |
26 | QString m_skinPath; | 30 | QString m_skinPath; |
@@ -30,6 +34,7 @@ private: | |||
30 | mutable QImage m_backgroundImage; | 34 | mutable QImage m_backgroundImage; |
31 | mutable QImage m_buttonUpImage; | 35 | mutable QImage m_buttonUpImage; |
32 | mutable QImage m_buttonDownImage; | 36 | mutable QImage m_buttonDownImage; |
37 | mutable QImage m_buttonMask; | ||
33 | mutable ButtonMaskImageMap m_buttonMasks; | 38 | mutable ButtonMaskImageMap m_buttonMasks; |
34 | 39 | ||
35 | Skin( const Skin & ); | 40 | Skin( const Skin & ); |