author | simon <simon> | 2002-12-09 14:29:48 (UTC) |
---|---|---|
committer | simon <simon> | 2002-12-09 14:29:48 (UTC) |
commit | 3f88070b9be5209cdd88caa0afd7f7294d3b1764 (patch) (unidiff) | |
tree | fe1c3c224e6d6930cef0756f4e23aded980d692f | |
parent | 8746877e7ed89fc4c227d5d79d63c35c69ceacd6 (diff) | |
download | opie-3f88070b9be5209cdd88caa0afd7f7294d3b1764.zip opie-3f88070b9be5209cdd88caa0afd7f7294d3b1764.tar.gz opie-3f88070b9be5209cdd88caa0afd7f7294d3b1764.tar.bz2 |
- merged the separate mask and pixmap arrays into the Button structure
and the buttons vector
-rw-r--r-- | noncore/multimedia/opieplayer2/audiowidget.cpp | 25 | ||||
-rw-r--r-- | noncore/multimedia/opieplayer2/mediawidget.h | 9 |
2 files changed, 15 insertions, 19 deletions
diff --git a/noncore/multimedia/opieplayer2/audiowidget.cpp b/noncore/multimedia/opieplayer2/audiowidget.cpp index 6e9c14a..87e06ee 100644 --- a/noncore/multimedia/opieplayer2/audiowidget.cpp +++ b/noncore/multimedia/opieplayer2/audiowidget.cpp | |||
@@ -95,54 +95,49 @@ AudioWidget::AudioWidget( PlayListWidget &playList, MediaPlayerState &mediaPlaye | |||
95 | setCaption( tr("OpiePlayer") ); | 95 | setCaption( tr("OpiePlayer") ); |
96 | 96 | ||
97 | Config cfg("OpiePlayer"); | 97 | Config cfg("OpiePlayer"); |
98 | cfg.setGroup("Options"); | 98 | cfg.setGroup("Options"); |
99 | skin = cfg.readEntry("Skin","default"); | 99 | skin = cfg.readEntry("Skin","default"); |
100 | //skin = "scaleTest"; | 100 | //skin = "scaleTest"; |
101 | // color of background, frame, degree of transparency | 101 | // color of background, frame, degree of transparency |
102 | 102 | ||
103 | QString skinPath = "opieplayer2/skins/" + skin; | 103 | QString skinPath = "opieplayer2/skins/" + skin; |
104 | pixBg = QPixmap( Resource::loadPixmap( QString("%1/background").arg(skinPath) ) ); | 104 | pixBg = QPixmap( Resource::loadPixmap( QString("%1/background").arg(skinPath) ) ); |
105 | imgUp = QImage( Resource::loadImage( QString("%1/skin_up").arg(skinPath) ) ); | 105 | imgUp = QImage( Resource::loadImage( QString("%1/skin_up").arg(skinPath) ) ); |
106 | imgDn = QImage( Resource::loadImage( QString("%1/skin_down").arg(skinPath) ) ); | 106 | imgDn = QImage( Resource::loadImage( QString("%1/skin_down").arg(skinPath) ) ); |
107 | 107 | ||
108 | buttonMask = QImage( imgUp.width(), imgUp.height(), 8, 255 ); | 108 | buttonMask = QImage( imgUp.width(), imgUp.height(), 8, 255 ); |
109 | buttonMask.fill( 0 ); | 109 | buttonMask.fill( 0 ); |
110 | 110 | ||
111 | masks.reserve( buttonCount ); | 111 | for ( uint i = 0; i < buttons.size(); i++ ) { |
112 | |||
113 | for ( uint i = 0; i < masks.capacity(); i++ ) { | ||
114 | QString filename = QString( QPEApplication::qpeDir() + "/pics/" + skinPath + "/skin_mask_" + skinInfo[i].fileName + ".png" ); | 112 | QString filename = QString( QPEApplication::qpeDir() + "/pics/" + skinPath + "/skin_mask_" + skinInfo[i].fileName + ".png" ); |
115 | masks.push_back( QBitmap( filename ) ); | 113 | buttons[ i ].mask =QBitmap( filename ); |
116 | 114 | ||
117 | if ( !masks[i].isNull() ) { | 115 | if ( !buttons[i].mask.isNull() ) { |
118 | QImage imgMask = masks[i].convertToImage(); | 116 | QImage imgMask = buttons[i].mask.convertToImage(); |
119 | uchar **dest = buttonMask.jumpTable(); | 117 | uchar **dest = buttonMask.jumpTable(); |
120 | for ( int y = 0; y < imgUp.height(); y++ ) { | 118 | for ( int y = 0; y < imgUp.height(); y++ ) { |
121 | uchar *line = dest[y]; | 119 | uchar *line = dest[y]; |
122 | for ( int x = 0; x < imgUp.width(); x++ ) | 120 | for ( int x = 0; x < imgUp.width(); x++ ) |
123 | if ( !qRed( imgMask.pixel( x, y ) ) ) | 121 | if ( !qRed( imgMask.pixel( x, y ) ) ) |
124 | line[x] = i + 1; | 122 | line[x] = i + 1; |
125 | } | 123 | } |
126 | } | 124 | } |
127 | 125 | ||
128 | } | 126 | } |
129 | 127 | ||
130 | buttonPixUp.resize( masks.size(), QPixmap() ); | ||
131 | buttonPixDown.resize( masks.size(), QPixmap() ); | ||
132 | |||
133 | setBackgroundPixmap( pixBg ); | 128 | setBackgroundPixmap( pixBg ); |
134 | 129 | ||
135 | songInfo.setFocusPolicy( QWidget::NoFocus ); | 130 | songInfo.setFocusPolicy( QWidget::NoFocus ); |
136 | // changeTextColor( &songInfo ); | 131 | // changeTextColor( &songInfo ); |
137 | // songInfo.setBackgroundColor( QColor( 167, 212, 167 )); | 132 | // songInfo.setBackgroundColor( QColor( 167, 212, 167 )); |
138 | // songInfo.setFrameStyle( QFrame::NoFrame); | 133 | // songInfo.setFrameStyle( QFrame::NoFrame); |
139 | songInfo.setFrameStyle( QFrame::WinPanel | QFrame::Sunken ); | 134 | songInfo.setFrameStyle( QFrame::WinPanel | QFrame::Sunken ); |
140 | // songInfo.setForegroundColor(Qt::white); | 135 | // songInfo.setForegroundColor(Qt::white); |
141 | 136 | ||
142 | slider.setFixedHeight( 20 ); | 137 | slider.setFixedHeight( 20 ); |
143 | slider.setMinValue( 0 ); | 138 | slider.setMinValue( 0 ); |
144 | slider.setMaxValue( 1 ); | 139 | slider.setMaxValue( 1 ); |
145 | slider.setFocusPolicy( QWidget::NoFocus ); | 140 | slider.setFocusPolicy( QWidget::NoFocus ); |
146 | slider.setBackgroundPixmap( pixBg ); | 141 | slider.setBackgroundPixmap( pixBg ); |
147 | 142 | ||
148 | // Config cofg("qpe"); | 143 | // Config cofg("qpe"); |
@@ -202,36 +197,36 @@ void AudioWidget::resizeEvent( QResizeEvent * ) { | |||
202 | int h = height(); | 197 | int h = height(); |
203 | int w = width(); | 198 | int w = width(); |
204 | 199 | ||
205 | songInfo.setGeometry( QRect( 2, 2, w - 4, 20 ) ); | 200 | songInfo.setGeometry( QRect( 2, 2, w - 4, 20 ) ); |
206 | slider.setFixedWidth( w - 110 ); | 201 | slider.setFixedWidth( w - 110 ); |
207 | slider.setGeometry( QRect( 15, h - 22, w - 90, 20 ) ); | 202 | slider.setGeometry( QRect( 15, h - 22, w - 90, 20 ) ); |
208 | slider.setBackgroundOrigin( QWidget::ParentOrigin ); | 203 | slider.setBackgroundOrigin( QWidget::ParentOrigin ); |
209 | time.setGeometry( QRect( w - 85, h - 30, 70, 20 ) ); | 204 | time.setGeometry( QRect( w - 85, h - 30, 70, 20 ) ); |
210 | 205 | ||
211 | upperLeftOfButtonMask.rx() = ( w - imgUp.width() ) / 2; | 206 | upperLeftOfButtonMask.rx() = ( w - imgUp.width() ) / 2; |
212 | upperLeftOfButtonMask.ry() = (( h - imgUp.height() ) / 2) - 10; | 207 | upperLeftOfButtonMask.ry() = (( h - imgUp.height() ) / 2) - 10; |
213 | QPoint p = upperLeftOfButtonMask; | 208 | QPoint p = upperLeftOfButtonMask; |
214 | 209 | ||
215 | QPixmap pixUp = combineImageWithBackground( imgUp, pixBg, p ); | 210 | QPixmap pixUp = combineImageWithBackground( imgUp, pixBg, p ); |
216 | QPixmap pixDn = combineImageWithBackground( imgDn, pixBg, p ); | 211 | QPixmap pixDn = combineImageWithBackground( imgDn, pixBg, p ); |
217 | 212 | ||
218 | for ( uint i = 0; i < masks.size(); i++ ) { | 213 | for ( uint i = 0; i < buttons.size(); i++ ) { |
219 | if ( !masks[i].isNull() ) { | 214 | if ( !buttons[i].mask.isNull() ) { |
220 | buttonPixUp[i] = maskPixToMask( pixUp, masks[i] ); | 215 | buttons[i].pixUp = maskPixToMask( pixUp, buttons[i].mask ); |
221 | buttonPixDown[i] = maskPixToMask( pixDn, masks[i] ); | 216 | buttons[i].pixDown = maskPixToMask( pixDn, buttons[i].mask ); |
222 | } | 217 | } |
223 | } | 218 | } |
224 | } | 219 | } |
225 | 220 | ||
226 | void AudioWidget::sliderPressed() { | 221 | void AudioWidget::sliderPressed() { |
227 | audioSliderBeingMoved = TRUE; | 222 | audioSliderBeingMoved = TRUE; |
228 | } | 223 | } |
229 | 224 | ||
230 | 225 | ||
231 | void AudioWidget::sliderReleased() { | 226 | void AudioWidget::sliderReleased() { |
232 | audioSliderBeingMoved = FALSE; | 227 | audioSliderBeingMoved = FALSE; |
233 | if ( slider.width() == 0 ) | 228 | if ( slider.width() == 0 ) |
234 | return; | 229 | return; |
235 | long val = long((double)slider.value() * mediaPlayerState.length() / slider.width()); | 230 | long val = long((double)slider.value() * mediaPlayerState.length() / slider.width()); |
236 | mediaPlayerState.setPosition( val ); | 231 | mediaPlayerState.setPosition( val ); |
237 | } | 232 | } |
@@ -309,35 +304,35 @@ void AudioWidget::updateSlider( long i, long max ) { | |||
309 | if ( slider.maxValue() != width ) { | 304 | if ( slider.maxValue() != width ) { |
310 | slider.setMaxValue( width ); | 305 | slider.setMaxValue( width ); |
311 | } | 306 | } |
312 | } | 307 | } |
313 | } | 308 | } |
314 | 309 | ||
315 | 310 | ||
316 | void AudioWidget::setToggleButton( int i, bool down ) { | 311 | void AudioWidget::setToggleButton( int i, bool down ) { |
317 | qDebug("setToggleButton %d", i); | 312 | qDebug("setToggleButton %d", i); |
318 | if ( down != buttons[i].isDown ) { | 313 | if ( down != buttons[i].isDown ) { |
319 | toggleButton( i ); | 314 | toggleButton( i ); |
320 | } | 315 | } |
321 | } | 316 | } |
322 | 317 | ||
323 | void AudioWidget::paintButton( QPainter &p, int i ) { | 318 | void AudioWidget::paintButton( QPainter &p, int i ) { |
324 | if ( buttons[i].isDown ) { | 319 | if ( buttons[i].isDown ) { |
325 | p.drawPixmap( upperLeftOfButtonMask, buttonPixDown[i] ); | 320 | p.drawPixmap( upperLeftOfButtonMask, buttons[i].pixDown ); |
326 | } else { | 321 | } else { |
327 | p.drawPixmap( upperLeftOfButtonMask, buttonPixUp[i] ); | 322 | p.drawPixmap( upperLeftOfButtonMask, buttons[i].pixUp ); |
328 | } | 323 | } |
329 | } | 324 | } |
330 | 325 | ||
331 | 326 | ||
332 | void AudioWidget::skipFor() { | 327 | void AudioWidget::skipFor() { |
333 | skipDirection = +1; | 328 | skipDirection = +1; |
334 | startTimer( 50 ); | 329 | startTimer( 50 ); |
335 | mediaPlayerState.setPosition( mediaPlayerState.position() + 2 ); | 330 | mediaPlayerState.setPosition( mediaPlayerState.position() + 2 ); |
336 | } | 331 | } |
337 | 332 | ||
338 | void AudioWidget::skipBack() { | 333 | void AudioWidget::skipBack() { |
339 | skipDirection = -1; | 334 | skipDirection = -1; |
340 | startTimer( 50 ); | 335 | startTimer( 50 ); |
341 | mediaPlayerState.setPosition( mediaPlayerState.position() - 2 ); | 336 | mediaPlayerState.setPosition( mediaPlayerState.position() - 2 ); |
342 | } | 337 | } |
343 | 338 | ||
diff --git a/noncore/multimedia/opieplayer2/mediawidget.h b/noncore/multimedia/opieplayer2/mediawidget.h index 2641df6..504b705 100644 --- a/noncore/multimedia/opieplayer2/mediawidget.h +++ b/noncore/multimedia/opieplayer2/mediawidget.h | |||
@@ -11,52 +11,57 @@ | |||
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 | 28 | ||
28 | #include "mediaplayerstate.h" | 29 | #include "mediaplayerstate.h" |
29 | #include "playlistwidget.h" | 30 | #include "playlistwidget.h" |
30 | 31 | ||
31 | #include <vector> | 32 | #include <vector> |
32 | 33 | ||
33 | class MediaWidget : public QWidget | 34 | class MediaWidget : public QWidget |
34 | { | 35 | { |
35 | Q_OBJECT | 36 | Q_OBJECT |
36 | public: | 37 | public: |
37 | enum Command { Play = 0, Stop, Next, Previous, VolumeUp, VolumeDown, Loop, PlayList, Forward, Back }; | 38 | enum Command { Play = 0, Stop, Next, Previous, VolumeUp, VolumeDown, Loop, PlayList, Forward, Back }; |
38 | enum ButtonType { NormalButton, ToggleButton }; | 39 | enum ButtonType { NormalButton, ToggleButton }; |
39 | 40 | ||
40 | struct Button | 41 | struct Button |
41 | { | 42 | { |
42 | Button() : type( NormalButton ), isHeld( false ), isDown( false ) {} | 43 | Button() : type( NormalButton ), isHeld( false ), isDown( false ) {} |
43 | 44 | ||
44 | ButtonType type : 1; | 45 | ButtonType type : 1; |
45 | bool isHeld : 1; | 46 | bool isHeld : 1; |
46 | bool isDown : 1; | 47 | bool isDown : 1; |
48 | |||
49 | QBitmap mask; | ||
50 | QPixmap pixUp; | ||
51 | QPixmap pixDown; | ||
47 | }; | 52 | }; |
48 | typedef std::vector<Button> ButtonVector; | 53 | typedef std::vector<Button> ButtonVector; |
49 | 54 | ||
50 | struct SkinButtonInfo | 55 | struct SkinButtonInfo |
51 | { | 56 | { |
52 | Command command; | 57 | Command command; |
53 | const char *fileName; | 58 | const char *fileName; |
54 | ButtonType type; | 59 | ButtonType type; |
55 | }; | 60 | }; |
56 | 61 | ||
57 | typedef std::vector<QBitmap> MaskVector; | 62 | typedef std::vector<QBitmap> MaskVector; |
58 | typedef std::vector<QPixmap> PixmapVector; | 63 | typedef std::vector<QPixmap> PixmapVector; |
59 | 64 | ||
60 | MediaWidget( PlayListWidget &_playList, MediaPlayerState &_mediaPlayerState, QWidget *parent = 0, const char *name = 0 ); | 65 | MediaWidget( PlayListWidget &_playList, MediaPlayerState &_mediaPlayerState, QWidget *parent = 0, const char *name = 0 ); |
61 | virtual ~MediaWidget(); | 66 | virtual ~MediaWidget(); |
62 | 67 | ||
@@ -77,26 +82,22 @@ protected: | |||
77 | void handleCommand( Command command, bool buttonDown ); | 82 | void handleCommand( Command command, bool buttonDown ); |
78 | 83 | ||
79 | bool isOverButton( const QPoint &position, int buttonId ) const; | 84 | bool isOverButton( const QPoint &position, int buttonId ) const; |
80 | 85 | ||
81 | void paintButton( int buttonId ); | 86 | void paintButton( int buttonId ); |
82 | virtual void paintButton( QPainter &p, int i ) = 0; | 87 | virtual void paintButton( QPainter &p, int i ) = 0; |
83 | 88 | ||
84 | void toggleButton( int buttonId ); | 89 | void toggleButton( int buttonId ); |
85 | 90 | ||
86 | MediaPlayerState &mediaPlayerState; | 91 | MediaPlayerState &mediaPlayerState; |
87 | PlayListWidget &playList; | 92 | PlayListWidget &playList; |
88 | 93 | ||
89 | ButtonVector buttons; | 94 | ButtonVector buttons; |
90 | 95 | ||
91 | QImage buttonMask; | 96 | QImage buttonMask; |
92 | 97 | ||
93 | MaskVector masks; | ||
94 | PixmapVector buttonPixUp; | ||
95 | PixmapVector buttonPixDown; | ||
96 | |||
97 | QPoint upperLeftOfButtonMask; | 98 | QPoint upperLeftOfButtonMask; |
98 | }; | 99 | }; |
99 | 100 | ||
100 | #endif // MEDIAWIDGET_H | 101 | #endif // MEDIAWIDGET_H |
101 | /* vim: et sw=4 ts=4 | 102 | /* vim: et sw=4 ts=4 |
102 | */ | 103 | */ |