author | simon <simon> | 2002-12-11 12:47:06 (UTC) |
---|---|---|
committer | simon <simon> | 2002-12-11 12:47:06 (UTC) |
commit | dd6a6d5345e191ffa6da3e015c4e024bd8ca67b7 (patch) (unidiff) | |
tree | 565797ef0522be6d3cff893d8bc04c4378306c16 | |
parent | 6f5e269efd9d6a5910251ce26750134e841f7b14 (diff) | |
download | opie-dd6a6d5345e191ffa6da3e015c4e024bd8ca67b7.zip opie-dd6a6d5345e191ffa6da3e015c4e024bd8ca67b7.tar.gz opie-dd6a6d5345e191ffa6da3e015c4e024bd8ca67b7.tar.bz2 |
- button mask composing moved to Skin class
-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 | |||
@@ -1,185 +1,165 @@ | |||
1 | /* | 1 | /* |
2 | Copyright (C) 2002 Simon Hausmann <hausmann@kde.org> | 2 | Copyright (C) 2002 Simon Hausmann <hausmann@kde.org> |
3 | (C) 2002 Max Reiss <harlekin@handhelds.org> | 3 | (C) 2002 Max Reiss <harlekin@handhelds.org> |
4 | (C) 2002 L. Potter <ljp@llornkcor.com> | 4 | (C) 2002 L. Potter <ljp@llornkcor.com> |
5 | (C) 2002 Holger Freyther <zecke@handhelds.org> | 5 | (C) 2002 Holger Freyther <zecke@handhelds.org> |
6 | 6 | ||
7 | This library is free software; you can redistribute it and/or | 7 | This library is free software; you can redistribute it and/or |
8 | modify it under the terms of the GNU Library General Public | 8 | modify it under the terms of the GNU Library General Public |
9 | License as published by the Free Software Foundation; either | 9 | License as published by the Free Software Foundation; either |
10 | version 2 of the License, or (at your option) any later version. | 10 | version 2 of the License, or (at your option) any later version. |
11 | 11 | ||
12 | This library is distributed in the hope that it will be useful, | 12 | This library is distributed in the hope that it will be useful, |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
15 | Library General Public License for more details. | 15 | Library General Public License for more details. |
16 | 16 | ||
17 | You should have received a copy of the GNU Library General Public License | 17 | You should have received a copy of the GNU Library General Public License |
18 | along with this library; see the file COPYING.LIB. If not, write to | 18 | along with this library; see the file COPYING.LIB. 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 | 23 | ||
24 | #include "mediawidget.h" | 24 | #include "mediawidget.h" |
25 | #include "playlistwidget.h" | 25 | #include "playlistwidget.h" |
26 | #include "skin.h" | 26 | #include "skin.h" |
27 | 27 | ||
28 | #include <qpe/config.h> | 28 | #include <qpe/config.h> |
29 | #include <qpe/qpeapplication.h> | 29 | #include <qpe/qpeapplication.h> |
30 | 30 | ||
31 | MediaWidget::MediaWidget( PlayListWidget &_playList, MediaPlayerState &_mediaPlayerState, QWidget *parent, const char *name ) | 31 | MediaWidget::MediaWidget( PlayListWidget &_playList, MediaPlayerState &_mediaPlayerState, QWidget *parent, const char *name ) |
32 | : QWidget( parent, name ), mediaPlayerState( _mediaPlayerState ), playList( _playList ) | 32 | : QWidget( parent, name ), mediaPlayerState( _mediaPlayerState ), playList( _playList ) |
33 | { | 33 | { |
34 | connect( &mediaPlayerState, SIGNAL( displayTypeChanged( MediaPlayerState::DisplayType ) ), | 34 | connect( &mediaPlayerState, SIGNAL( displayTypeChanged( MediaPlayerState::DisplayType ) ), |
35 | this, SLOT( setDisplayType( MediaPlayerState::DisplayType ) ) ); | 35 | this, SLOT( setDisplayType( MediaPlayerState::DisplayType ) ) ); |
36 | connect( &mediaPlayerState, SIGNAL( lengthChanged( long ) ), | 36 | connect( &mediaPlayerState, SIGNAL( lengthChanged( long ) ), |
37 | this, SLOT( setLength( long ) ) ); | 37 | this, SLOT( setLength( long ) ) ); |
38 | connect( &mediaPlayerState, SIGNAL( playingToggled( bool ) ), | 38 | connect( &mediaPlayerState, SIGNAL( playingToggled( bool ) ), |
39 | this, SLOT( setPlaying( bool ) ) ); | 39 | this, SLOT( setPlaying( bool ) ) ); |
40 | } | 40 | } |
41 | 41 | ||
42 | MediaWidget::~MediaWidget() | 42 | MediaWidget::~MediaWidget() |
43 | { | 43 | { |
44 | } | 44 | } |
45 | 45 | ||
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 ); |
54 | 53 | ||
55 | for ( uint i = 0; i < buttonCount; ++i ) { | 54 | for ( uint i = 0; i < buttonCount; ++i ) { |
56 | Button button = setupButton( skinInfo[ i ], skin ); | 55 | Button button = setupButton( skinInfo[ i ], skin ); |
57 | buttons.push_back( button ); | 56 | buttons.push_back( button ); |
58 | } | 57 | } |
59 | } | 58 | } |
60 | 59 | ||
61 | MediaWidget::Button MediaWidget::setupButton( const SkinButtonInfo &buttonInfo, const Skin &skin ) | 60 | MediaWidget::Button MediaWidget::setupButton( const SkinButtonInfo &buttonInfo, const Skin &skin ) |
62 | { | 61 | { |
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" ); |
93 | cfg.setGroup( "Options" ); | 73 | cfg.setGroup( "Options" ); |
94 | QString skin = cfg.readEntry( "Skin","default" ); | 74 | QString skin = cfg.readEntry( "Skin","default" ); |
95 | 75 | ||
96 | loadSkin( skinInfo, buttonCount, skin, fileNameInfix ); | 76 | loadSkin( skinInfo, buttonCount, skin, fileNameInfix ); |
97 | } | 77 | } |
98 | 78 | ||
99 | void MediaWidget::loadSkin( const SkinButtonInfo *skinInfo, uint buttonCount, const QString &name, const QString &fileNameInfix ) | 79 | void MediaWidget::loadSkin( const SkinButtonInfo *skinInfo, uint buttonCount, const QString &name, const QString &fileNameInfix ) |
100 | { | 80 | { |
101 | Skin skin( name, fileNameInfix ); | 81 | Skin skin( name, fileNameInfix ); |
102 | 82 | ||
103 | QString skinPath = "opieplayer2/skins/" + name; | 83 | QString skinPath = "opieplayer2/skins/" + name; |
104 | backgroundPixmap = skin.backgroundImage(); | 84 | backgroundPixmap = skin.backgroundImage(); |
105 | buttonUpImage = skin.buttonUpImage(); | 85 | buttonUpImage = skin.buttonUpImage(); |
106 | buttonDownImage = skin.buttonDownImage(); | 86 | buttonDownImage = skin.buttonDownImage(); |
107 | 87 | ||
108 | setupButtons( skinInfo, buttonCount, skin, buttonUpImage.size() ); | 88 | setupButtons( skinInfo, buttonCount, skin, buttonUpImage.size() ); |
109 | } | 89 | } |
110 | 90 | ||
111 | void MediaWidget::closeEvent( QCloseEvent * ) | 91 | void MediaWidget::closeEvent( QCloseEvent * ) |
112 | { | 92 | { |
113 | mediaPlayerState.setList(); | 93 | mediaPlayerState.setList(); |
114 | } | 94 | } |
115 | 95 | ||
116 | void MediaWidget::paintEvent( QPaintEvent *pe ) | 96 | void MediaWidget::paintEvent( QPaintEvent *pe ) |
117 | { | 97 | { |
118 | QPainter p( this ); | 98 | QPainter p( this ); |
119 | 99 | ||
120 | if ( mediaPlayerState.isFullscreen() ) { | 100 | if ( mediaPlayerState.isFullscreen() ) { |
121 | // Clear the background | 101 | // Clear the background |
122 | p.setBrush( QBrush( Qt::black ) ); | 102 | p.setBrush( QBrush( Qt::black ) ); |
123 | return; | 103 | return; |
124 | } | 104 | } |
125 | 105 | ||
126 | if ( !pe->erased() ) { | 106 | if ( !pe->erased() ) { |
127 | // Combine with background and double buffer | 107 | // Combine with background and double buffer |
128 | QPixmap pix( pe->rect().size() ); | 108 | QPixmap pix( pe->rect().size() ); |
129 | QPainter p( &pix ); | 109 | QPainter p( &pix ); |
130 | p.translate( -pe->rect().topLeft().x(), -pe->rect().topLeft().y() ); | 110 | p.translate( -pe->rect().topLeft().x(), -pe->rect().topLeft().y() ); |
131 | p.drawTiledPixmap( pe->rect(), backgroundPixmap, pe->rect().topLeft() ); | 111 | p.drawTiledPixmap( pe->rect(), backgroundPixmap, pe->rect().topLeft() ); |
132 | paintAllButtons( p ); | 112 | paintAllButtons( p ); |
133 | QPainter p2( this ); | 113 | QPainter p2( this ); |
134 | p2.drawPixmap( pe->rect().topLeft(), pix ); | 114 | p2.drawPixmap( pe->rect().topLeft(), pix ); |
135 | } else { | 115 | } else { |
136 | QPainter p( this ); | 116 | QPainter p( this ); |
137 | paintAllButtons( p ); | 117 | paintAllButtons( p ); |
138 | } | 118 | } |
139 | } | 119 | } |
140 | 120 | ||
141 | MediaWidget::Button *MediaWidget::buttonAt( const QPoint &position ) | 121 | MediaWidget::Button *MediaWidget::buttonAt( const QPoint &position ) |
142 | { | 122 | { |
143 | if ( position.x() <= 0 || position.y() <= 0 || | 123 | if ( position.x() <= 0 || position.y() <= 0 || |
144 | position.x() >= buttonMask.width() || | 124 | position.x() >= buttonMask.width() || |
145 | position.y() >= buttonMask.height() ) | 125 | position.y() >= buttonMask.height() ) |
146 | return 0; | 126 | return 0; |
147 | 127 | ||
148 | int pixelIdx = buttonMask.pixelIndex( position.x(), position.y() ); | 128 | int pixelIdx = buttonMask.pixelIndex( position.x(), position.y() ); |
149 | for ( ButtonVector::iterator it = buttons.begin(); it != buttons.end(); ++it ) | 129 | for ( ButtonVector::iterator it = buttons.begin(); it != buttons.end(); ++it ) |
150 | if ( it->command + 1 == pixelIdx ) | 130 | if ( it->command + 1 == pixelIdx ) |
151 | return &( *it ); | 131 | return &( *it ); |
152 | 132 | ||
153 | return 0; | 133 | return 0; |
154 | } | 134 | } |
155 | 135 | ||
156 | void MediaWidget::mousePressEvent( QMouseEvent *event ) | 136 | void MediaWidget::mousePressEvent( QMouseEvent *event ) |
157 | { | 137 | { |
158 | Button *button = buttonAt( event->pos() - upperLeftOfButtonMask ); | 138 | Button *button = buttonAt( event->pos() - upperLeftOfButtonMask ); |
159 | 139 | ||
160 | if ( !button ) { | 140 | if ( !button ) { |
161 | QWidget::mousePressEvent( event ); | 141 | QWidget::mousePressEvent( event ); |
162 | return; | 142 | return; |
163 | } | 143 | } |
164 | 144 | ||
165 | switch ( button->command ) { | 145 | switch ( button->command ) { |
166 | case VolumeUp: emit moreClicked(); return; | 146 | case VolumeUp: emit moreClicked(); return; |
167 | case VolumeDown: emit lessClicked(); return; | 147 | case VolumeDown: emit lessClicked(); return; |
168 | case Back: emit backClicked(); return; | 148 | case Back: emit backClicked(); return; |
169 | case Forward: emit forwardClicked(); return; | 149 | case Forward: emit forwardClicked(); return; |
170 | default: break; | 150 | default: break; |
171 | } | 151 | } |
172 | } | 152 | } |
173 | 153 | ||
174 | void MediaWidget::mouseReleaseEvent( QMouseEvent *event ) | 154 | void MediaWidget::mouseReleaseEvent( QMouseEvent *event ) |
175 | { | 155 | { |
176 | Button *button = buttonAt( event->pos() - upperLeftOfButtonMask ); | 156 | Button *button = buttonAt( event->pos() - upperLeftOfButtonMask ); |
177 | 157 | ||
178 | if ( !button ) { | 158 | if ( !button ) { |
179 | QWidget::mouseReleaseEvent( event ); | 159 | QWidget::mouseReleaseEvent( event ); |
180 | return; | 160 | return; |
181 | } | 161 | } |
182 | 162 | ||
183 | if ( button->type == ToggleButton ) | 163 | if ( button->type == ToggleButton ) |
184 | toggleButton( *button ); | 164 | toggleButton( *button ); |
185 | 165 | ||
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 | |||
@@ -11,141 +11,140 @@ | |||
11 | 11 | ||
12 | This library is distributed in the hope that it will be useful, | 12 | This library is distributed in the hope that it will be useful, |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
15 | Library General Public License for more details. | 15 | Library General Public License for more details. |
16 | 16 | ||
17 | You should have received a copy of the GNU Library General Public License | 17 | You should have received a copy of the GNU Library General Public License |
18 | along with this library; see the file COPYING.LIB. If not, write to | 18 | along with this library; see the file COPYING.LIB. 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 MEDIAWIDGET_H | 23 | #ifndef MEDIAWIDGET_H |
24 | #define MEDIAWIDGET_H | 24 | #define MEDIAWIDGET_H |
25 | 25 | ||
26 | #include <qwidget.h> | 26 | #include <qwidget.h> |
27 | #include <qmap.h> | 27 | #include <qmap.h> |
28 | 28 | ||
29 | #include "mediaplayerstate.h" | 29 | #include "mediaplayerstate.h" |
30 | #include "playlistwidget.h" | 30 | #include "playlistwidget.h" |
31 | 31 | ||
32 | #include <vector> | 32 | #include <vector> |
33 | #include <memory> | 33 | #include <memory> |
34 | 34 | ||
35 | namespace | 35 | namespace |
36 | { | 36 | { |
37 | struct simpleAndStupidAllocator | 37 | struct simpleAndStupidAllocator |
38 | { | 38 | { |
39 | static void *allocate( size_t amount ) | 39 | static void *allocate( size_t amount ) |
40 | { return ::operator new( amount ); } | 40 | { return ::operator new( amount ); } |
41 | static void deallocate( void *p, size_t ) | 41 | static void deallocate( void *p, size_t ) |
42 | { ::operator delete( p ); } | 42 | { ::operator delete( p ); } |
43 | }; | 43 | }; |
44 | } | 44 | } |
45 | 45 | ||
46 | class Skin; | 46 | class Skin; |
47 | 47 | ||
48 | class MediaWidget : public QWidget | 48 | class MediaWidget : public QWidget |
49 | { | 49 | { |
50 | Q_OBJECT | 50 | Q_OBJECT |
51 | public: | 51 | public: |
52 | enum Command { Play = 0, Stop, Next, Previous, VolumeUp, VolumeDown, Loop, PlayList, Forward, Back, FullScreen, Undefined }; | 52 | enum Command { Play = 0, Stop, Next, Previous, VolumeUp, VolumeDown, Loop, PlayList, Forward, Back, FullScreen, Undefined }; |
53 | enum ButtonType { NormalButton, ToggleButton }; | 53 | enum ButtonType { NormalButton, ToggleButton }; |
54 | 54 | ||
55 | struct Button | 55 | struct Button |
56 | { | 56 | { |
57 | Button() : command( Undefined ), type( NormalButton ), isDown( false ) {} | 57 | Button() : command( Undefined ), type( NormalButton ), isDown( false ) {} |
58 | 58 | ||
59 | Command command; | 59 | Command command; |
60 | 60 | ||
61 | ButtonType type; // this should be part of the bitfield but gcc2 is too buggy to support this :-( | 61 | ButtonType type; // this should be part of the bitfield but gcc2 is too buggy to support this :-( |
62 | bool isDown : 1; | 62 | bool isDown : 1; |
63 | 63 | ||
64 | QBitmap mask; | 64 | QBitmap mask; |
65 | QPixmap pixUp; | 65 | QPixmap pixUp; |
66 | QPixmap pixDown; | 66 | QPixmap pixDown; |
67 | }; | 67 | }; |
68 | #if defined( _CC_GNU_ ) | 68 | #if defined( _CC_GNU_ ) |
69 | // use that allocator to avoid the default allocator that on gcc2 requires libstdc++ because | 69 | // use that allocator to avoid the default allocator that on gcc2 requires libstdc++ because |
70 | // in the BAD_ALLOC macro it uses std::cerr and friends :-( | 70 | // in the BAD_ALLOC macro it uses std::cerr and friends :-( |
71 | typedef std::vector<Button, std::__allocator<Button, simpleAndStupidAllocator> > ButtonVector; | 71 | typedef std::vector<Button, std::__allocator<Button, simpleAndStupidAllocator> > ButtonVector; |
72 | #else | 72 | #else |
73 | typedef std::vector<Button> ButtonVector; | 73 | typedef std::vector<Button> ButtonVector; |
74 | #endif | 74 | #endif |
75 | 75 | ||
76 | struct SkinButtonInfo | 76 | struct SkinButtonInfo |
77 | { | 77 | { |
78 | Command command; | 78 | Command command; |
79 | const char *fileName; | 79 | const char *fileName; |
80 | ButtonType type; | 80 | ButtonType type; |
81 | }; | 81 | }; |
82 | 82 | ||
83 | MediaWidget( PlayListWidget &_playList, MediaPlayerState &_mediaPlayerState, QWidget *parent = 0, const char *name = 0 ); | 83 | MediaWidget( PlayListWidget &_playList, MediaPlayerState &_mediaPlayerState, QWidget *parent = 0, const char *name = 0 ); |
84 | virtual ~MediaWidget(); | 84 | virtual ~MediaWidget(); |
85 | 85 | ||
86 | public slots: | 86 | public slots: |
87 | virtual void setDisplayType( MediaPlayerState::DisplayType displayType ) = 0; | 87 | virtual void setDisplayType( MediaPlayerState::DisplayType displayType ) = 0; |
88 | virtual void setLength( long length ) = 0; | 88 | virtual void setLength( long length ) = 0; |
89 | virtual void setPlaying( bool playing ) = 0; | 89 | virtual void setPlaying( bool playing ) = 0; |
90 | 90 | ||
91 | virtual void loadSkin() = 0; | 91 | virtual void loadSkin() = 0; |
92 | 92 | ||
93 | signals: | 93 | signals: |
94 | void moreReleased(); | 94 | void moreReleased(); |
95 | void lessReleased(); | 95 | void lessReleased(); |
96 | void forwardReleased(); | 96 | void forwardReleased(); |
97 | void backReleased(); | 97 | void backReleased(); |
98 | void forwardClicked(); | 98 | void forwardClicked(); |
99 | void backClicked(); | 99 | void backClicked(); |
100 | void moreClicked(); | 100 | void moreClicked(); |
101 | void lessClicked(); | 101 | void lessClicked(); |
102 | 102 | ||
103 | protected: | 103 | 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 ); |
111 | 110 | ||
112 | virtual void closeEvent( QCloseEvent * ); | 111 | virtual void closeEvent( QCloseEvent * ); |
113 | 112 | ||
114 | virtual void paintEvent( QPaintEvent *pe ); | 113 | virtual void paintEvent( QPaintEvent *pe ); |
115 | 114 | ||
116 | Button *buttonAt( const QPoint &position ); | 115 | Button *buttonAt( const QPoint &position ); |
117 | 116 | ||
118 | virtual void mousePressEvent( QMouseEvent *event ); | 117 | virtual void mousePressEvent( QMouseEvent *event ); |
119 | virtual void mouseReleaseEvent( QMouseEvent *event ); | 118 | virtual void mouseReleaseEvent( QMouseEvent *event ); |
120 | 119 | ||
121 | virtual void makeVisible(); | 120 | virtual void makeVisible(); |
122 | 121 | ||
123 | void handleCommand( Command command, bool buttonDown ); | 122 | void handleCommand( Command command, bool buttonDown ); |
124 | 123 | ||
125 | bool isOverButton( const QPoint &position, int buttonId ) const; | 124 | bool isOverButton( const QPoint &position, int buttonId ) const; |
126 | 125 | ||
127 | void paintAllButtons( QPainter &p ); | 126 | void paintAllButtons( QPainter &p ); |
128 | void paintButton( const Button &button ); | 127 | void paintButton( const Button &button ); |
129 | void paintButton( QPainter &p, const Button &button ); | 128 | void paintButton( QPainter &p, const Button &button ); |
130 | 129 | ||
131 | void setToggleButton( Button &button, bool down ); | 130 | void setToggleButton( Button &button, bool down ); |
132 | void setToggleButton( Command command, bool down ); | 131 | void setToggleButton( Command command, bool down ); |
133 | void toggleButton( Button &button ); | 132 | void toggleButton( Button &button ); |
134 | 133 | ||
135 | MediaPlayerState &mediaPlayerState; | 134 | MediaPlayerState &mediaPlayerState; |
136 | PlayListWidget &playList; | 135 | PlayListWidget &playList; |
137 | 136 | ||
138 | ButtonVector buttons; | 137 | ButtonVector buttons; |
139 | 138 | ||
140 | QImage buttonMask; | 139 | QImage buttonMask; |
141 | 140 | ||
142 | QPoint upperLeftOfButtonMask; | 141 | QPoint upperLeftOfButtonMask; |
143 | 142 | ||
144 | QPixmap backgroundPixmap; | 143 | QPixmap backgroundPixmap; |
145 | QImage buttonUpImage; | 144 | QImage buttonUpImage; |
146 | QImage buttonDownImage; | 145 | QImage buttonDownImage; |
147 | }; | 146 | }; |
148 | 147 | ||
149 | #endif // MEDIAWIDGET_H | 148 | #endif // MEDIAWIDGET_H |
150 | /* vim: et sw=4 ts=4 | 149 | /* vim: et sw=4 ts=4 |
151 | */ | 150 | */ |
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,54 +1,84 @@ | |||
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 |
54 | */ | 84 | */ |
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 | |||
@@ -1,41 +1,46 @@ | |||
1 | #ifndef SKIN_H | 1 | #ifndef SKIN_H |
2 | #define SKIN_H | 2 | #define SKIN_H |
3 | 3 | ||
4 | #include <qstring.h> | 4 | #include <qstring.h> |
5 | #include <qimage.h> | 5 | #include <qimage.h> |
6 | #include <qmap.h> | 6 | #include <qmap.h> |
7 | 7 | ||
8 | #include "mediawidget.h" | 8 | #include "mediawidget.h" |
9 | 9 | ||
10 | class Skin | 10 | class Skin |
11 | { | 11 | { |
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; |
27 | 31 | ||
28 | typedef QMap<QString, QImage> ButtonMaskImageMap; | 32 | typedef QMap<QString, QImage> ButtonMaskImageMap; |
29 | 33 | ||
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 & ); |
36 | Skin &operator=( const Skin & ); | 41 | Skin &operator=( const Skin & ); |
37 | }; | 42 | }; |
38 | 43 | ||
39 | #endif // SKIN_H | 44 | #endif // SKIN_H |
40 | /* vim: et sw=4 ts=4 | 45 | /* vim: et sw=4 ts=4 |
41 | */ | 46 | */ |