-rw-r--r-- | noncore/multimedia/opieplayer2/audiowidget.cpp | 13 | ||||
-rw-r--r-- | noncore/multimedia/opieplayer2/mediawidget.cpp | 23 | ||||
-rw-r--r-- | noncore/multimedia/opieplayer2/mediawidget.h | 3 | ||||
-rw-r--r-- | noncore/multimedia/opieplayer2/videowidget.cpp | 11 |
4 files changed, 28 insertions, 22 deletions
diff --git a/noncore/multimedia/opieplayer2/audiowidget.cpp b/noncore/multimedia/opieplayer2/audiowidget.cpp index 0b7cc45..bb686f1 100644 --- a/noncore/multimedia/opieplayer2/audiowidget.cpp +++ b/noncore/multimedia/opieplayer2/audiowidget.cpp | |||
@@ -3,372 +3,361 @@ | |||
3 | 3 | ||
4 | Copyright (c) 2002 Max Reiss <harlekin@handhelds.org> | 4 | Copyright (c) 2002 Max Reiss <harlekin@handhelds.org> |
5 | Copyright (c) 2002 L. Potter <ljp@llornkcor.com> | 5 | Copyright (c) 2002 L. Potter <ljp@llornkcor.com> |
6 | Copyright (c) 2002 Holger Freyther <zecke@handhelds.org> | 6 | Copyright (c) 2002 Holger Freyther <zecke@handhelds.org> |
7 | =. | 7 | =. |
8 | .=l. | 8 | .=l. |
9 | .>+-= | 9 | .>+-= |
10 | _;:, .> :=|. This program is free software; you can | 10 | _;:, .> :=|. This program is free software; you can |
11 | .> <`_, > . <= redistribute it and/or modify it under | 11 | .> <`_, > . <= redistribute it and/or modify it under |
12 | :`=1 )Y*s>-.-- : the terms of the GNU General Public | 12 | :`=1 )Y*s>-.-- : the terms of the GNU General Public |
13 | .="- .-=="i, .._ License as published by the Free Software | 13 | .="- .-=="i, .._ License as published by the Free Software |
14 | - . .-<_> .<> Foundation; either version 2 of the License, | 14 | - . .-<_> .<> Foundation; either version 2 of the License, |
15 | ._= =} : or (at your option) any later version. | 15 | ._= =} : or (at your option) any later version. |
16 | .%`+i> _;_. | 16 | .%`+i> _;_. |
17 | .i_,=:_. -<s. This program is distributed in the hope that | 17 | .i_,=:_. -<s. This program is distributed in the hope that |
18 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 18 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
19 | : .. .:, . . . without even the implied warranty of | 19 | : .. .:, . . . without even the implied warranty of |
20 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 20 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
21 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | 21 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU |
22 | ..}^=.= = ; Library General Public License for more | 22 | ..}^=.= = ; Library General Public License for more |
23 | ++= -. .` .: details. | 23 | ++= -. .` .: details. |
24 | : = ...= . :.=- | 24 | : = ...= . :.=- |
25 | -. .:....=;==+<; You should have received a copy of the GNU | 25 | -. .:....=;==+<; You should have received a copy of the GNU |
26 | -_. . . )=. = Library General Public License along with | 26 | -_. . . )=. = Library General Public License along with |
27 | -- :-=` this library; see the file COPYING.LIB. | 27 | -- :-=` this library; see the file COPYING.LIB. |
28 | If not, write to the Free Software Foundation, | 28 | If not, write to the Free Software Foundation, |
29 | Inc., 59 Temple Place - Suite 330, | 29 | Inc., 59 Temple Place - Suite 330, |
30 | Boston, MA 02111-1307, USA. | 30 | Boston, MA 02111-1307, USA. |
31 | 31 | ||
32 | */ | 32 | */ |
33 | 33 | ||
34 | #include <qpe/qpeapplication.h> | 34 | #include <qpe/qpeapplication.h> |
35 | #include <qpe/resource.h> | 35 | #include <qpe/resource.h> |
36 | #include <qpe/config.h> | 36 | #include <qpe/config.h> |
37 | #include <opie/oticker.h> | 37 | #include <opie/oticker.h> |
38 | 38 | ||
39 | #include <qwidget.h> | 39 | #include <qwidget.h> |
40 | #include <qpixmap.h> | 40 | #include <qpixmap.h> |
41 | #include <qbutton.h> | 41 | #include <qbutton.h> |
42 | #include <qpainter.h> | 42 | #include <qpainter.h> |
43 | #include <qframe.h> | 43 | #include <qframe.h> |
44 | #include <qlayout.h> | 44 | #include <qlayout.h> |
45 | #include <qdir.h> | 45 | #include <qdir.h> |
46 | #include <stdlib.h> | 46 | #include <stdlib.h> |
47 | #include <stdio.h> | 47 | #include <stdio.h> |
48 | 48 | ||
49 | #include "audiowidget.h" | 49 | #include "audiowidget.h" |
50 | #include "mediaplayerstate.h" | 50 | #include "mediaplayerstate.h" |
51 | #include "playlistwidget.h" | 51 | #include "playlistwidget.h" |
52 | 52 | ||
53 | namespace | 53 | namespace |
54 | { | 54 | { |
55 | 55 | ||
56 | const int xo = -2; // movable x offset | 56 | const int xo = -2; // movable x offset |
57 | const int yo = 22; // movable y offset | 57 | const int yo = 22; // movable y offset |
58 | 58 | ||
59 | const MediaWidget::SkinButtonInfo skinInfo[] = | 59 | const MediaWidget::SkinButtonInfo skinInfo[] = |
60 | { | 60 | { |
61 | { MediaWidget::Play, "play", MediaWidget::ToggleButton }, | 61 | { MediaWidget::Play, "play", MediaWidget::ToggleButton }, |
62 | { MediaWidget::Stop, "stop", MediaWidget::NormalButton }, | 62 | { MediaWidget::Stop, "stop", MediaWidget::NormalButton }, |
63 | { MediaWidget::Next, "next", MediaWidget::NormalButton }, | 63 | { MediaWidget::Next, "next", MediaWidget::NormalButton }, |
64 | { MediaWidget::Previous, "prev", MediaWidget::NormalButton }, | 64 | { MediaWidget::Previous, "prev", MediaWidget::NormalButton }, |
65 | { MediaWidget::VolumeUp, "up", MediaWidget::NormalButton }, | 65 | { MediaWidget::VolumeUp, "up", MediaWidget::NormalButton }, |
66 | { MediaWidget::VolumeDown, "down", MediaWidget::NormalButton }, | 66 | { MediaWidget::VolumeDown, "down", MediaWidget::NormalButton }, |
67 | { MediaWidget::Loop, "loop", MediaWidget::ToggleButton }, | 67 | { MediaWidget::Loop, "loop", MediaWidget::ToggleButton }, |
68 | { MediaWidget::PlayList, "playlist", MediaWidget::NormalButton }, | 68 | { MediaWidget::PlayList, "playlist", MediaWidget::NormalButton }, |
69 | { MediaWidget::Forward, "forward", MediaWidget::NormalButton }, | 69 | { MediaWidget::Forward, "forward", MediaWidget::NormalButton }, |
70 | { MediaWidget::Back, "back", MediaWidget::NormalButton } | 70 | { MediaWidget::Back, "back", MediaWidget::NormalButton } |
71 | }; | 71 | }; |
72 | 72 | ||
73 | const uint buttonCount = sizeof( skinInfo ) / sizeof( skinInfo[ 0 ] ); | 73 | const uint buttonCount = sizeof( skinInfo ) / sizeof( skinInfo[ 0 ] ); |
74 | 74 | ||
75 | void changeTextColor( QWidget * w) { | 75 | void changeTextColor( QWidget * w) { |
76 | QPalette p = w->palette(); | 76 | QPalette p = w->palette(); |
77 | p.setBrush( QColorGroup::Background, QColor( 167, 212, 167 ) ); | 77 | p.setBrush( QColorGroup::Background, QColor( 167, 212, 167 ) ); |
78 | p.setBrush( QColorGroup::Base, QColor( 167, 212, 167 ) ); | 78 | p.setBrush( QColorGroup::Base, QColor( 167, 212, 167 ) ); |
79 | w->setPalette( p ); | 79 | w->setPalette( p ); |
80 | } | 80 | } |
81 | 81 | ||
82 | } | 82 | } |
83 | 83 | ||
84 | AudioWidget::AudioWidget( PlayListWidget &playList, MediaPlayerState &mediaPlayerState, QWidget* parent, const char* name) : | 84 | AudioWidget::AudioWidget( PlayListWidget &playList, MediaPlayerState &mediaPlayerState, QWidget* parent, const char* name) : |
85 | 85 | ||
86 | MediaWidget( playList, mediaPlayerState, parent, name ), songInfo( this ), slider( Qt::Horizontal, this ), time( this ), | 86 | MediaWidget( playList, mediaPlayerState, parent, name ), songInfo( this ), slider( Qt::Horizontal, this ), time( this ), |
87 | audioSliderBeingMoved( false ) | 87 | audioSliderBeingMoved( false ) |
88 | { | 88 | { |
89 | setCaption( tr("OpiePlayer") ); | 89 | setCaption( tr("OpiePlayer") ); |
90 | 90 | ||
91 | loadSkin(); | 91 | loadSkin(); |
92 | 92 | ||
93 | connect( &mediaPlayerState, SIGNAL( loopingToggled(bool) ), this, SLOT( setLooping(bool) ) ); | 93 | connect( &mediaPlayerState, SIGNAL( loopingToggled(bool) ), this, SLOT( setLooping(bool) ) ); |
94 | connect( &mediaPlayerState, SIGNAL( isSeekableToggled( bool ) ), this, SLOT( setSeekable( bool ) ) ); | 94 | connect( &mediaPlayerState, SIGNAL( isSeekableToggled( bool ) ), this, SLOT( setSeekable( bool ) ) ); |
95 | 95 | ||
96 | connect( this, SIGNAL( forwardClicked() ), this, SLOT( skipFor() ) ); | 96 | connect( this, SIGNAL( forwardClicked() ), this, SLOT( skipFor() ) ); |
97 | connect( this, SIGNAL( backClicked() ), this, SLOT( skipBack() ) ); | 97 | connect( this, SIGNAL( backClicked() ), this, SLOT( skipBack() ) ); |
98 | connect( this, SIGNAL( forwardReleased() ), this, SLOT( stopSkip() ) ); | 98 | connect( this, SIGNAL( forwardReleased() ), this, SLOT( stopSkip() ) ); |
99 | connect( this, SIGNAL( backReleased() ), this, SLOT( stopSkip() ) ); | 99 | connect( this, SIGNAL( backReleased() ), this, SLOT( stopSkip() ) ); |
100 | 100 | ||
101 | // Intialise state | 101 | // Intialise state |
102 | setLength( mediaPlayerState.length() ); | 102 | setLength( mediaPlayerState.length() ); |
103 | setPosition( mediaPlayerState.position() ); | 103 | setPosition( mediaPlayerState.position() ); |
104 | setLooping( mediaPlayerState.isFullscreen() ); | 104 | setLooping( mediaPlayerState.isFullscreen() ); |
105 | // setPaused( mediaPlayerState->paused() ); | 105 | // setPaused( mediaPlayerState->paused() ); |
106 | setPlaying( mediaPlayerState.isPlaying() ); | 106 | setPlaying( mediaPlayerState.isPlaying() ); |
107 | } | 107 | } |
108 | 108 | ||
109 | AudioWidget::~AudioWidget() { | 109 | AudioWidget::~AudioWidget() { |
110 | 110 | ||
111 | // mediaPlayerState->setPlaying(false); | 111 | // mediaPlayerState->setPlaying(false); |
112 | } | 112 | } |
113 | 113 | ||
114 | namespace { | 114 | namespace { |
115 | 115 | ||
116 | QPixmap combineImageWithBackground( QImage img, QPixmap bg, QPoint offset ) { | 116 | QPixmap combineImageWithBackground( QImage img, QPixmap bg, QPoint offset ) { |
117 | QPixmap pix( img.width(), img.height() ); | 117 | QPixmap pix( img.width(), img.height() ); |
118 | QPainter p( &pix ); | 118 | QPainter p( &pix ); |
119 | p.drawTiledPixmap( pix.rect(), bg, offset ); | 119 | p.drawTiledPixmap( pix.rect(), bg, offset ); |
120 | p.drawImage( 0, 0, img ); | 120 | p.drawImage( 0, 0, img ); |
121 | return pix; | 121 | return pix; |
122 | } | 122 | } |
123 | 123 | ||
124 | 124 | ||
125 | QPixmap maskPixToMask( QPixmap pix, QBitmap mask ) { | 125 | QPixmap maskPixToMask( QPixmap pix, QBitmap mask ) { |
126 | QPixmap pixmap( pix ); | 126 | QPixmap pixmap( pix ); |
127 | pixmap.setMask( mask ); | 127 | pixmap.setMask( mask ); |
128 | return pixmap; | 128 | return pixmap; |
129 | } | 129 | } |
130 | 130 | ||
131 | }; | 131 | }; |
132 | 132 | ||
133 | void AudioWidget::resizeEvent( QResizeEvent * ) { | 133 | void AudioWidget::resizeEvent( QResizeEvent * ) { |
134 | int h = height(); | 134 | int h = height(); |
135 | int w = width(); | 135 | int w = width(); |
136 | 136 | ||
137 | songInfo.setGeometry( QRect( 2, 2, w - 4, 20 ) ); | 137 | songInfo.setGeometry( QRect( 2, 2, w - 4, 20 ) ); |
138 | slider.setFixedWidth( w - 110 ); | 138 | slider.setFixedWidth( w - 110 ); |
139 | slider.setGeometry( QRect( 15, h - 22, w - 90, 20 ) ); | 139 | slider.setGeometry( QRect( 15, h - 22, w - 90, 20 ) ); |
140 | slider.setBackgroundOrigin( QWidget::ParentOrigin ); | 140 | slider.setBackgroundOrigin( QWidget::ParentOrigin ); |
141 | time.setGeometry( QRect( w - 85, h - 30, 70, 20 ) ); | 141 | time.setGeometry( QRect( w - 85, h - 30, 70, 20 ) ); |
142 | 142 | ||
143 | upperLeftOfButtonMask.rx() = ( w - buttonUpImage.width() ) / 2; | 143 | upperLeftOfButtonMask.rx() = ( w - buttonUpImage.width() ) / 2; |
144 | upperLeftOfButtonMask.ry() = (( h - buttonUpImage.height() ) / 2) - 10; | 144 | upperLeftOfButtonMask.ry() = (( h - buttonUpImage.height() ) / 2) - 10; |
145 | QPoint p = upperLeftOfButtonMask; | 145 | QPoint p = upperLeftOfButtonMask; |
146 | 146 | ||
147 | QPixmap pixUp = combineImageWithBackground( buttonUpImage, backgroundPixmap, p ); | 147 | QPixmap pixUp = combineImageWithBackground( buttonUpImage, backgroundPixmap, p ); |
148 | QPixmap pixDn = combineImageWithBackground( buttonDownImage, backgroundPixmap, p ); | 148 | QPixmap pixDn = combineImageWithBackground( buttonDownImage, backgroundPixmap, p ); |
149 | 149 | ||
150 | for ( uint i = 0; i < buttons.size(); i++ ) { | 150 | for ( uint i = 0; i < buttons.size(); i++ ) { |
151 | if ( !buttons[i].mask.isNull() ) { | 151 | if ( !buttons[i].mask.isNull() ) { |
152 | buttons[i].pixUp = maskPixToMask( pixUp, buttons[i].mask ); | 152 | buttons[i].pixUp = maskPixToMask( pixUp, buttons[i].mask ); |
153 | buttons[i].pixDown = maskPixToMask( pixDn, buttons[i].mask ); | 153 | buttons[i].pixDown = maskPixToMask( pixDn, buttons[i].mask ); |
154 | } | 154 | } |
155 | } | 155 | } |
156 | } | 156 | } |
157 | 157 | ||
158 | void AudioWidget::sliderPressed() { | 158 | void AudioWidget::sliderPressed() { |
159 | audioSliderBeingMoved = TRUE; | 159 | audioSliderBeingMoved = TRUE; |
160 | } | 160 | } |
161 | 161 | ||
162 | 162 | ||
163 | void AudioWidget::sliderReleased() { | 163 | void AudioWidget::sliderReleased() { |
164 | audioSliderBeingMoved = FALSE; | 164 | audioSliderBeingMoved = FALSE; |
165 | if ( slider.width() == 0 ) | 165 | if ( slider.width() == 0 ) |
166 | return; | 166 | return; |
167 | long val = long((double)slider.value() * mediaPlayerState.length() / slider.width()); | 167 | long val = long((double)slider.value() * mediaPlayerState.length() / slider.width()); |
168 | mediaPlayerState.setPosition( val ); | 168 | mediaPlayerState.setPosition( val ); |
169 | } | 169 | } |
170 | 170 | ||
171 | void AudioWidget::setPosition( long i ) { | 171 | void AudioWidget::setPosition( long i ) { |
172 | // qDebug("<<<<<<<<<<<<<<<<<<<<<<<<set position %d",i); | 172 | // qDebug("<<<<<<<<<<<<<<<<<<<<<<<<set position %d",i); |
173 | updateSlider( i, mediaPlayerState.length() ); | 173 | updateSlider( i, mediaPlayerState.length() ); |
174 | } | 174 | } |
175 | 175 | ||
176 | 176 | ||
177 | void AudioWidget::setLength( long max ) { | 177 | void AudioWidget::setLength( long max ) { |
178 | updateSlider( mediaPlayerState.position(), max ); | 178 | updateSlider( mediaPlayerState.position(), max ); |
179 | } | 179 | } |
180 | 180 | ||
181 | 181 | ||
182 | void AudioWidget::setDisplayType( MediaPlayerState::DisplayType mediaType ) { | 182 | void AudioWidget::setDisplayType( MediaPlayerState::DisplayType mediaType ) { |
183 | if ( mediaType == MediaPlayerState::Audio ) { | 183 | if ( mediaType == MediaPlayerState::Audio ) { |
184 | // startTimer( 150 ); | 184 | // startTimer( 150 ); |
185 | showMaximized(); | 185 | showMaximized(); |
186 | return; | 186 | return; |
187 | } | 187 | } |
188 | 188 | ||
189 | killTimers(); | 189 | killTimers(); |
190 | hide(); | 190 | hide(); |
191 | } | 191 | } |
192 | 192 | ||
193 | void AudioWidget::loadSkin() | 193 | void AudioWidget::loadSkin() |
194 | { | 194 | { |
195 | Config cfg("OpiePlayer"); | 195 | loadDefaultSkin( skinInfo, buttonCount ); |
196 | cfg.setGroup("Options"); | ||
197 | skin = cfg.readEntry("Skin","default"); | ||
198 | //skin = "scaleTest"; | ||
199 | // color of background, frame, degree of transparency | ||
200 | |||
201 | QString skinPath = "opieplayer2/skins/" + skin; | ||
202 | backgroundPixmap = QPixmap( Resource::loadPixmap( QString("%1/background").arg(skinPath) ) ); | ||
203 | buttonUpImage = QImage( Resource::loadImage( QString("%1/skin_up").arg(skinPath) ) ); | ||
204 | buttonDownImage = QImage( Resource::loadImage( QString("%1/skin_down").arg(skinPath) ) ); | ||
205 | |||
206 | setupButtons( skinInfo, buttonCount, QPEApplication::qpeDir() + "/pics/" + skinPath + "/skin_mask_", buttonUpImage.size() ); | ||
207 | 196 | ||
208 | setBackgroundPixmap( backgroundPixmap ); | 197 | setBackgroundPixmap( backgroundPixmap ); |
209 | 198 | ||
210 | songInfo.setFocusPolicy( QWidget::NoFocus ); | 199 | songInfo.setFocusPolicy( QWidget::NoFocus ); |
211 | // changeTextColor( &songInfo ); | 200 | // changeTextColor( &songInfo ); |
212 | // songInfo.setBackgroundColor( QColor( 167, 212, 167 )); | 201 | // songInfo.setBackgroundColor( QColor( 167, 212, 167 )); |
213 | // songInfo.setFrameStyle( QFrame::NoFrame); | 202 | // songInfo.setFrameStyle( QFrame::NoFrame); |
214 | songInfo.setFrameStyle( QFrame::WinPanel | QFrame::Sunken ); | 203 | songInfo.setFrameStyle( QFrame::WinPanel | QFrame::Sunken ); |
215 | // songInfo.setForegroundColor(Qt::white); | 204 | // songInfo.setForegroundColor(Qt::white); |
216 | 205 | ||
217 | slider.setFixedHeight( 20 ); | 206 | slider.setFixedHeight( 20 ); |
218 | slider.setMinValue( 0 ); | 207 | slider.setMinValue( 0 ); |
219 | slider.setMaxValue( 1 ); | 208 | slider.setMaxValue( 1 ); |
220 | slider.setFocusPolicy( QWidget::NoFocus ); | 209 | slider.setFocusPolicy( QWidget::NoFocus ); |
221 | slider.setBackgroundPixmap( backgroundPixmap ); | 210 | slider.setBackgroundPixmap( backgroundPixmap ); |
222 | 211 | ||
223 | // Config cofg("qpe"); | 212 | // Config cofg("qpe"); |
224 | // cofg.setGroup("Appearance"); | 213 | // cofg.setGroup("Appearance"); |
225 | // QColor backgroundcolor = QColor( cofg.readEntry( "Background", "#E5E1D5" ) ); | 214 | // QColor backgroundcolor = QColor( cofg.readEntry( "Background", "#E5E1D5" ) ); |
226 | 215 | ||
227 | time.setFocusPolicy( QWidget::NoFocus ); | 216 | time.setFocusPolicy( QWidget::NoFocus ); |
228 | time.setAlignment( Qt::AlignCenter ); | 217 | time.setAlignment( Qt::AlignCenter ); |
229 | 218 | ||
230 | // time.setFrame(FALSE); | 219 | // time.setFrame(FALSE); |
231 | // changeTextColor( &time ); | 220 | // changeTextColor( &time ); |
232 | 221 | ||
233 | resizeEvent( 0 ); | 222 | resizeEvent( 0 ); |
234 | } | 223 | } |
235 | 224 | ||
236 | void AudioWidget::setSeekable( bool isSeekable ) { | 225 | void AudioWidget::setSeekable( bool isSeekable ) { |
237 | 226 | ||
238 | if ( !isSeekable ) { | 227 | if ( !isSeekable ) { |
239 | qDebug("<<<<<<<<<<<<<<file is STREAMING>>>>>>>>>>>>>>>>>>>"); | 228 | qDebug("<<<<<<<<<<<<<<file is STREAMING>>>>>>>>>>>>>>>>>>>"); |
240 | if( !slider.isHidden()) { | 229 | if( !slider.isHidden()) { |
241 | slider.hide(); | 230 | slider.hide(); |
242 | } | 231 | } |
243 | disconnect( &mediaPlayerState, SIGNAL( positionChanged(long) ),this, SLOT( setPosition(long) ) ); | 232 | disconnect( &mediaPlayerState, SIGNAL( positionChanged(long) ),this, SLOT( setPosition(long) ) ); |
244 | disconnect( &mediaPlayerState, SIGNAL( positionUpdated(long) ),this, SLOT( setPosition(long) ) ); | 233 | disconnect( &mediaPlayerState, SIGNAL( positionUpdated(long) ),this, SLOT( setPosition(long) ) ); |
245 | disconnect( &slider, SIGNAL( sliderPressed() ), this, SLOT( sliderPressed() ) ); | 234 | disconnect( &slider, SIGNAL( sliderPressed() ), this, SLOT( sliderPressed() ) ); |
246 | disconnect( &slider, SIGNAL( sliderReleased() ), this, SLOT( sliderReleased() ) ); | 235 | disconnect( &slider, SIGNAL( sliderReleased() ), this, SLOT( sliderReleased() ) ); |
247 | } else { | 236 | } else { |
248 | // this stops the slider from being moved, thus | 237 | // this stops the slider from being moved, thus |
249 | // does not stop stream when it reaches the end | 238 | // does not stop stream when it reaches the end |
250 | slider.show(); | 239 | slider.show(); |
251 | qDebug( " CONNECT SET POSTION " ); | 240 | qDebug( " CONNECT SET POSTION " ); |
252 | connect( &mediaPlayerState, SIGNAL( positionChanged(long) ),this, SLOT( setPosition(long) ) ); | 241 | connect( &mediaPlayerState, SIGNAL( positionChanged(long) ),this, SLOT( setPosition(long) ) ); |
253 | connect( &mediaPlayerState, SIGNAL( positionUpdated(long) ),this, SLOT( setPosition(long) ) ); | 242 | connect( &mediaPlayerState, SIGNAL( positionUpdated(long) ),this, SLOT( setPosition(long) ) ); |
254 | connect( &slider, SIGNAL( sliderPressed() ), this, SLOT( sliderPressed() ) ); | 243 | connect( &slider, SIGNAL( sliderPressed() ), this, SLOT( sliderPressed() ) ); |
255 | connect( &slider, SIGNAL( sliderReleased() ), this, SLOT( sliderReleased() ) ); | 244 | connect( &slider, SIGNAL( sliderReleased() ), this, SLOT( sliderReleased() ) ); |
256 | } | 245 | } |
257 | } | 246 | } |
258 | 247 | ||
259 | 248 | ||
260 | static QString timeAsString( long length ) { | 249 | static QString timeAsString( long length ) { |
261 | int minutes = length / 60; | 250 | int minutes = length / 60; |
262 | int seconds = length % 60; | 251 | int seconds = length % 60; |
263 | return QString("%1:%2%3").arg( minutes ).arg( seconds / 10 ).arg( seconds % 10 ); | 252 | return QString("%1:%2%3").arg( minutes ).arg( seconds / 10 ).arg( seconds % 10 ); |
264 | } | 253 | } |
265 | 254 | ||
266 | void AudioWidget::updateSlider( long i, long max ) { | 255 | void AudioWidget::updateSlider( long i, long max ) { |
267 | 256 | ||
268 | time.setText( timeAsString( i ) + " / " + timeAsString( max ) ); | 257 | time.setText( timeAsString( i ) + " / " + timeAsString( max ) ); |
269 | // qDebug( timeAsString( i ) + " / " + timeAsString( max ) ) ; | 258 | // qDebug( timeAsString( i ) + " / " + timeAsString( max ) ) ; |
270 | 259 | ||
271 | if ( max == 0 ) { | 260 | if ( max == 0 ) { |
272 | return; | 261 | return; |
273 | } | 262 | } |
274 | // Will flicker too much if we don't do this | 263 | // Will flicker too much if we don't do this |
275 | // Scale to something reasonable | 264 | // Scale to something reasonable |
276 | int width = slider.width(); | 265 | int width = slider.width(); |
277 | int val = int((double)i * width / max); | 266 | int val = int((double)i * width / max); |
278 | if ( !audioSliderBeingMoved ) { | 267 | if ( !audioSliderBeingMoved ) { |
279 | if ( slider.value() != val ) { | 268 | if ( slider.value() != val ) { |
280 | slider.setValue( val ); | 269 | slider.setValue( val ); |
281 | } | 270 | } |
282 | 271 | ||
283 | if ( slider.maxValue() != width ) { | 272 | if ( slider.maxValue() != width ) { |
284 | slider.setMaxValue( width ); | 273 | slider.setMaxValue( width ); |
285 | } | 274 | } |
286 | } | 275 | } |
287 | } | 276 | } |
288 | 277 | ||
289 | void AudioWidget::skipFor() { | 278 | void AudioWidget::skipFor() { |
290 | skipDirection = +1; | 279 | skipDirection = +1; |
291 | startTimer( 50 ); | 280 | startTimer( 50 ); |
292 | mediaPlayerState.setPosition( mediaPlayerState.position() + 2 ); | 281 | mediaPlayerState.setPosition( mediaPlayerState.position() + 2 ); |
293 | } | 282 | } |
294 | 283 | ||
295 | void AudioWidget::skipBack() { | 284 | void AudioWidget::skipBack() { |
296 | skipDirection = -1; | 285 | skipDirection = -1; |
297 | startTimer( 50 ); | 286 | startTimer( 50 ); |
298 | mediaPlayerState.setPosition( mediaPlayerState.position() - 2 ); | 287 | mediaPlayerState.setPosition( mediaPlayerState.position() - 2 ); |
299 | } | 288 | } |
300 | 289 | ||
301 | 290 | ||
302 | 291 | ||
303 | void AudioWidget::stopSkip() { | 292 | void AudioWidget::stopSkip() { |
304 | killTimers(); | 293 | killTimers(); |
305 | } | 294 | } |
306 | 295 | ||
307 | 296 | ||
308 | void AudioWidget::timerEvent( QTimerEvent * ) { | 297 | void AudioWidget::timerEvent( QTimerEvent * ) { |
309 | if ( skipDirection == +1 ) { | 298 | if ( skipDirection == +1 ) { |
310 | mediaPlayerState.setPosition( mediaPlayerState.position() + 2 ); | 299 | mediaPlayerState.setPosition( mediaPlayerState.position() + 2 ); |
311 | } else if ( skipDirection == -1 ) { | 300 | } else if ( skipDirection == -1 ) { |
312 | mediaPlayerState.setPosition( mediaPlayerState.position() - 2 ); | 301 | mediaPlayerState.setPosition( mediaPlayerState.position() - 2 ); |
313 | } | 302 | } |
314 | } | 303 | } |
315 | 304 | ||
316 | void AudioWidget::keyReleaseEvent( QKeyEvent *e) { | 305 | void AudioWidget::keyReleaseEvent( QKeyEvent *e) { |
317 | switch ( e->key() ) { | 306 | switch ( e->key() ) { |
318 | ////////////////////////////// Zaurus keys | 307 | ////////////////////////////// Zaurus keys |
319 | case Key_Home: | 308 | case Key_Home: |
320 | break; | 309 | break; |
321 | case Key_F9: //activity | 310 | case Key_F9: //activity |
322 | hide(); | 311 | hide(); |
323 | // qDebug("Audio F9"); | 312 | // qDebug("Audio F9"); |
324 | e->accept(); | 313 | e->accept(); |
325 | break; | 314 | break; |
326 | case Key_F10: //contacts | 315 | case Key_F10: //contacts |
327 | break; | 316 | break; |
328 | case Key_F11: //menu | 317 | case Key_F11: //menu |
329 | mediaPlayerState.toggleBlank(); | 318 | mediaPlayerState.toggleBlank(); |
330 | e->accept(); | 319 | e->accept(); |
331 | break; | 320 | break; |
332 | case Key_F12: //home | 321 | case Key_F12: //home |
333 | break; | 322 | break; |
334 | case Key_F13: //mail | 323 | case Key_F13: //mail |
335 | mediaPlayerState.toggleBlank(); | 324 | mediaPlayerState.toggleBlank(); |
336 | e->accept(); | 325 | e->accept(); |
337 | break; | 326 | break; |
338 | case Key_Space: { | 327 | case Key_Space: { |
339 | e->accept(); | 328 | e->accept(); |
340 | mediaPlayerState.togglePaused(); | 329 | mediaPlayerState.togglePaused(); |
341 | } | 330 | } |
342 | break; | 331 | break; |
343 | case Key_Down: | 332 | case Key_Down: |
344 | // toggleButton(6); | 333 | // toggleButton(6); |
345 | emit lessClicked(); | 334 | emit lessClicked(); |
346 | emit lessReleased(); | 335 | emit lessReleased(); |
347 | // toggleButton(6); | 336 | // toggleButton(6); |
348 | e->accept(); | 337 | e->accept(); |
349 | break; | 338 | break; |
350 | case Key_Up: | 339 | case Key_Up: |
351 | // toggleButton(5); | 340 | // toggleButton(5); |
352 | emit moreClicked(); | 341 | emit moreClicked(); |
353 | emit moreReleased(); | 342 | emit moreReleased(); |
354 | // toggleButton(5); | 343 | // toggleButton(5); |
355 | e->accept(); | 344 | e->accept(); |
356 | break; | 345 | break; |
357 | case Key_Right: | 346 | case Key_Right: |
358 | // toggleButton(3); | 347 | // toggleButton(3); |
359 | mediaPlayerState.setNext(); | 348 | mediaPlayerState.setNext(); |
360 | // toggleButton(3); | 349 | // toggleButton(3); |
361 | e->accept(); | 350 | e->accept(); |
362 | break; | 351 | break; |
363 | case Key_Left: | 352 | case Key_Left: |
364 | // toggleButton(4); | 353 | // toggleButton(4); |
365 | mediaPlayerState.setPrev(); | 354 | mediaPlayerState.setPrev(); |
366 | // toggleButton(4); | 355 | // toggleButton(4); |
367 | e->accept(); | 356 | e->accept(); |
368 | break; | 357 | break; |
369 | case Key_Escape: { | 358 | case Key_Escape: { |
370 | } | 359 | } |
371 | break; | 360 | break; |
372 | 361 | ||
373 | }; | 362 | }; |
374 | } | 363 | } |
diff --git a/noncore/multimedia/opieplayer2/mediawidget.cpp b/noncore/multimedia/opieplayer2/mediawidget.cpp index d60dc0d..c9d7db8 100644 --- a/noncore/multimedia/opieplayer2/mediawidget.cpp +++ b/noncore/multimedia/opieplayer2/mediawidget.cpp | |||
@@ -1,240 +1,263 @@ | |||
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 | 26 | ||
27 | #include <qpe/config.h> | ||
28 | #include <qpe/qpeapplication.h> | ||
29 | |||
27 | MediaWidget::MediaWidget( PlayListWidget &_playList, MediaPlayerState &_mediaPlayerState, QWidget *parent, const char *name ) | 30 | MediaWidget::MediaWidget( PlayListWidget &_playList, MediaPlayerState &_mediaPlayerState, QWidget *parent, const char *name ) |
28 | : QWidget( parent, name ), mediaPlayerState( _mediaPlayerState ), playList( _playList ) | 31 | : QWidget( parent, name ), mediaPlayerState( _mediaPlayerState ), playList( _playList ) |
29 | { | 32 | { |
30 | connect( &mediaPlayerState, SIGNAL( displayTypeChanged( MediaPlayerState::DisplayType ) ), | 33 | connect( &mediaPlayerState, SIGNAL( displayTypeChanged( MediaPlayerState::DisplayType ) ), |
31 | this, SLOT( setDisplayType( MediaPlayerState::DisplayType ) ) ); | 34 | this, SLOT( setDisplayType( MediaPlayerState::DisplayType ) ) ); |
32 | connect( &mediaPlayerState, SIGNAL( lengthChanged( long ) ), | 35 | connect( &mediaPlayerState, SIGNAL( lengthChanged( long ) ), |
33 | this, SLOT( setLength( long ) ) ); | 36 | this, SLOT( setLength( long ) ) ); |
34 | connect( &mediaPlayerState, SIGNAL( playingToggled( bool ) ), | 37 | connect( &mediaPlayerState, SIGNAL( playingToggled( bool ) ), |
35 | this, SLOT( setPlaying( bool ) ) ); | 38 | this, SLOT( setPlaying( bool ) ) ); |
36 | } | 39 | } |
37 | 40 | ||
38 | MediaWidget::~MediaWidget() | 41 | MediaWidget::~MediaWidget() |
39 | { | 42 | { |
40 | } | 43 | } |
41 | 44 | ||
42 | void MediaWidget::setupButtons( const SkinButtonInfo *skinInfo, uint buttonCount, | 45 | void MediaWidget::setupButtons( const SkinButtonInfo *skinInfo, uint buttonCount, |
43 | const QString &imagePrefix, const QSize &buttonAreaSize ) | 46 | const QString &imagePrefix, const QSize &buttonAreaSize ) |
44 | { | 47 | { |
45 | buttonMask = QImage( buttonAreaSize, 8, 255 ); | 48 | buttonMask = QImage( buttonAreaSize, 8, 255 ); |
46 | buttonMask.fill( 0 ); | 49 | buttonMask.fill( 0 ); |
47 | 50 | ||
48 | buttons.clear(); | 51 | buttons.clear(); |
49 | buttons.reserve( buttonCount ); | 52 | buttons.reserve( buttonCount ); |
50 | 53 | ||
51 | for ( uint i = 0; i < buttonCount; ++i ) { | 54 | for ( uint i = 0; i < buttonCount; ++i ) { |
52 | Button button = setupButton( skinInfo[ i ], imagePrefix ); | 55 | Button button = setupButton( skinInfo[ i ], imagePrefix ); |
53 | buttons.push_back( button ); | 56 | buttons.push_back( button ); |
54 | } | 57 | } |
55 | } | 58 | } |
56 | 59 | ||
57 | MediaWidget::Button MediaWidget::setupButton( const SkinButtonInfo &buttonInfo, const QString &imagePrefix ) | 60 | MediaWidget::Button MediaWidget::setupButton( const SkinButtonInfo &buttonInfo, const QString &imagePrefix ) |
58 | { | 61 | { |
59 | Button button; | 62 | Button button; |
60 | button.command = buttonInfo.command; | 63 | button.command = buttonInfo.command; |
61 | button.type = buttonInfo.type; | 64 | button.type = buttonInfo.type; |
62 | 65 | ||
63 | QString fileName = imagePrefix + buttonInfo.fileName + ".png"; | 66 | QString fileName = imagePrefix + buttonInfo.fileName + ".png"; |
64 | 67 | ||
65 | button.mask = setupButtonMask( button.command, fileName ); | 68 | button.mask = setupButtonMask( button.command, fileName ); |
66 | 69 | ||
67 | return button; | 70 | return button; |
68 | } | 71 | } |
69 | 72 | ||
70 | QBitmap MediaWidget::setupButtonMask( const Command &command, const QString &fileName ) | 73 | QBitmap MediaWidget::setupButtonMask( const Command &command, const QString &fileName ) |
71 | { | 74 | { |
72 | QBitmap mask( fileName ); | 75 | QBitmap mask( fileName ); |
73 | if ( mask.isNull() ) | 76 | if ( mask.isNull() ) |
74 | return mask; | 77 | return mask; |
75 | 78 | ||
76 | QImage imgMask = mask.convertToImage(); | 79 | QImage imgMask = mask.convertToImage(); |
77 | uchar **dest = buttonMask.jumpTable(); | 80 | uchar **dest = buttonMask.jumpTable(); |
78 | for ( int y = 0; y < buttonMask.height(); y++ ) { | 81 | for ( int y = 0; y < buttonMask.height(); y++ ) { |
79 | uchar *line = dest[y]; | 82 | uchar *line = dest[y]; |
80 | for ( int x = 0; x < buttonMask.width(); x++ ) | 83 | for ( int x = 0; x < buttonMask.width(); x++ ) |
81 | if ( !qRed( imgMask.pixel( x, y ) ) ) | 84 | if ( !qRed( imgMask.pixel( x, y ) ) ) |
82 | line[x] = command + 1; | 85 | line[x] = command + 1; |
83 | } | 86 | } |
84 | 87 | ||
85 | return mask; | 88 | return mask; |
86 | } | 89 | } |
87 | 90 | ||
91 | void MediaWidget::loadDefaultSkin( const SkinButtonInfo *skinInfo, uint buttonCount, const QString &fileNameInfix ) | ||
92 | { | ||
93 | Config cfg( "OpiePlayer" ); | ||
94 | cfg.setGroup( "Options" ); | ||
95 | QString skin = cfg.readEntry( "Skin","default" ); | ||
96 | |||
97 | loadSkin( skinInfo, buttonCount, skin, fileNameInfix ); | ||
98 | } | ||
99 | |||
100 | void MediaWidget::loadSkin( const SkinButtonInfo *skinInfo, uint buttonCount, const QString &name, const QString &fileNameInfix ) | ||
101 | { | ||
102 | QString skinPath = "opieplayer2/skins/" + name; | ||
103 | backgroundPixmap = QPixmap( Resource::loadPixmap( QString( "%1/background" ).arg( skinPath ) ) ); | ||
104 | buttonUpImage = QImage( Resource::loadImage( QString( "%1/skin%2_up" ).arg( skinPath ).arg( fileNameInfix ) ) ); | ||
105 | buttonDownImage = QImage( Resource::loadImage( QString( "%1/skin%2_down" ).arg( skinPath ).arg( fileNameInfix ) ) ); | ||
106 | |||
107 | setupButtons( skinInfo, buttonCount, | ||
108 | QPEApplication::qpeDir() + "/pics/" + skinPath + QString::fromLatin1( "/skin%1_mask_" ).arg( fileNameInfix ), buttonUpImage.size() ); | ||
109 | } | ||
110 | |||
88 | void MediaWidget::closeEvent( QCloseEvent * ) | 111 | void MediaWidget::closeEvent( QCloseEvent * ) |
89 | { | 112 | { |
90 | mediaPlayerState.setList(); | 113 | mediaPlayerState.setList(); |
91 | } | 114 | } |
92 | 115 | ||
93 | void MediaWidget::paintEvent( QPaintEvent *pe ) | 116 | void MediaWidget::paintEvent( QPaintEvent *pe ) |
94 | { | 117 | { |
95 | QPainter p( this ); | 118 | QPainter p( this ); |
96 | 119 | ||
97 | if ( mediaPlayerState.isFullscreen() ) { | 120 | if ( mediaPlayerState.isFullscreen() ) { |
98 | // Clear the background | 121 | // Clear the background |
99 | p.setBrush( QBrush( Qt::black ) ); | 122 | p.setBrush( QBrush( Qt::black ) ); |
100 | return; | 123 | return; |
101 | } | 124 | } |
102 | 125 | ||
103 | if ( !pe->erased() ) { | 126 | if ( !pe->erased() ) { |
104 | // Combine with background and double buffer | 127 | // Combine with background and double buffer |
105 | QPixmap pix( pe->rect().size() ); | 128 | QPixmap pix( pe->rect().size() ); |
106 | QPainter p( &pix ); | 129 | QPainter p( &pix ); |
107 | p.translate( -pe->rect().topLeft().x(), -pe->rect().topLeft().y() ); | 130 | p.translate( -pe->rect().topLeft().x(), -pe->rect().topLeft().y() ); |
108 | p.drawTiledPixmap( pe->rect(), backgroundPixmap, pe->rect().topLeft() ); | 131 | p.drawTiledPixmap( pe->rect(), backgroundPixmap, pe->rect().topLeft() ); |
109 | paintAllButtons( p ); | 132 | paintAllButtons( p ); |
110 | QPainter p2( this ); | 133 | QPainter p2( this ); |
111 | p2.drawPixmap( pe->rect().topLeft(), pix ); | 134 | p2.drawPixmap( pe->rect().topLeft(), pix ); |
112 | } else { | 135 | } else { |
113 | QPainter p( this ); | 136 | QPainter p( this ); |
114 | paintAllButtons( p ); | 137 | paintAllButtons( p ); |
115 | } | 138 | } |
116 | } | 139 | } |
117 | 140 | ||
118 | MediaWidget::Button *MediaWidget::buttonAt( const QPoint &position ) | 141 | MediaWidget::Button *MediaWidget::buttonAt( const QPoint &position ) |
119 | { | 142 | { |
120 | if ( position.x() <= 0 || position.y() <= 0 || | 143 | if ( position.x() <= 0 || position.y() <= 0 || |
121 | position.x() >= buttonMask.width() || | 144 | position.x() >= buttonMask.width() || |
122 | position.y() >= buttonMask.height() ) | 145 | position.y() >= buttonMask.height() ) |
123 | return 0; | 146 | return 0; |
124 | 147 | ||
125 | int pixelIdx = buttonMask.pixelIndex( position.x(), position.y() ); | 148 | int pixelIdx = buttonMask.pixelIndex( position.x(), position.y() ); |
126 | for ( ButtonVector::iterator it = buttons.begin(); it != buttons.end(); ++it ) | 149 | for ( ButtonVector::iterator it = buttons.begin(); it != buttons.end(); ++it ) |
127 | if ( it->command + 1 == pixelIdx ) | 150 | if ( it->command + 1 == pixelIdx ) |
128 | return &( *it ); | 151 | return &( *it ); |
129 | 152 | ||
130 | return 0; | 153 | return 0; |
131 | } | 154 | } |
132 | 155 | ||
133 | void MediaWidget::mousePressEvent( QMouseEvent *event ) | 156 | void MediaWidget::mousePressEvent( QMouseEvent *event ) |
134 | { | 157 | { |
135 | Button *button = buttonAt( event->pos() - upperLeftOfButtonMask ); | 158 | Button *button = buttonAt( event->pos() - upperLeftOfButtonMask ); |
136 | 159 | ||
137 | if ( !button ) { | 160 | if ( !button ) { |
138 | QWidget::mousePressEvent( event ); | 161 | QWidget::mousePressEvent( event ); |
139 | return; | 162 | return; |
140 | } | 163 | } |
141 | 164 | ||
142 | switch ( button->command ) { | 165 | switch ( button->command ) { |
143 | case VolumeUp: emit moreClicked(); return; | 166 | case VolumeUp: emit moreClicked(); return; |
144 | case VolumeDown: emit lessClicked(); return; | 167 | case VolumeDown: emit lessClicked(); return; |
145 | case Back: emit backClicked(); return; | 168 | case Back: emit backClicked(); return; |
146 | case Forward: emit forwardClicked(); return; | 169 | case Forward: emit forwardClicked(); return; |
147 | default: break; | 170 | default: break; |
148 | } | 171 | } |
149 | } | 172 | } |
150 | 173 | ||
151 | void MediaWidget::mouseReleaseEvent( QMouseEvent *event ) | 174 | void MediaWidget::mouseReleaseEvent( QMouseEvent *event ) |
152 | { | 175 | { |
153 | Button *button = buttonAt( event->pos() - upperLeftOfButtonMask ); | 176 | Button *button = buttonAt( event->pos() - upperLeftOfButtonMask ); |
154 | 177 | ||
155 | if ( !button ) { | 178 | if ( !button ) { |
156 | QWidget::mouseReleaseEvent( event ); | 179 | QWidget::mouseReleaseEvent( event ); |
157 | return; | 180 | return; |
158 | } | 181 | } |
159 | 182 | ||
160 | if ( button->type == ToggleButton ) | 183 | if ( button->type == ToggleButton ) |
161 | toggleButton( *button ); | 184 | toggleButton( *button ); |
162 | 185 | ||
163 | handleCommand( button->command, button->isDown ); | 186 | handleCommand( button->command, button->isDown ); |
164 | } | 187 | } |
165 | 188 | ||
166 | void MediaWidget::makeVisible() | 189 | void MediaWidget::makeVisible() |
167 | { | 190 | { |
168 | } | 191 | } |
169 | 192 | ||
170 | void MediaWidget::handleCommand( Command command, bool buttonDown ) | 193 | void MediaWidget::handleCommand( Command command, bool buttonDown ) |
171 | { | 194 | { |
172 | switch ( command ) { | 195 | switch ( command ) { |
173 | case Play: mediaPlayerState.togglePaused(); return; | 196 | case Play: mediaPlayerState.togglePaused(); return; |
174 | case Stop: mediaPlayerState.setPlaying(FALSE); return; | 197 | case Stop: mediaPlayerState.setPlaying(FALSE); return; |
175 | case Next: if( playList.currentTab() == PlayListWidget::CurrentPlayList ) mediaPlayerState.setNext(); return; | 198 | case Next: if( playList.currentTab() == PlayListWidget::CurrentPlayList ) mediaPlayerState.setNext(); return; |
176 | case Previous: if( playList.currentTab() == PlayListWidget::CurrentPlayList ) mediaPlayerState.setPrev(); return; | 199 | case Previous: if( playList.currentTab() == PlayListWidget::CurrentPlayList ) mediaPlayerState.setPrev(); return; |
177 | case Loop: mediaPlayerState.setLooping( buttonDown ); return; | 200 | case Loop: mediaPlayerState.setLooping( buttonDown ); return; |
178 | case VolumeUp: emit moreReleased(); return; | 201 | case VolumeUp: emit moreReleased(); return; |
179 | case VolumeDown: emit lessReleased(); return; | 202 | case VolumeDown: emit lessReleased(); return; |
180 | case PlayList: mediaPlayerState.setList(); return; | 203 | case PlayList: mediaPlayerState.setList(); return; |
181 | case Forward: emit forwardReleased(); return; | 204 | case Forward: emit forwardReleased(); return; |
182 | case Back: emit backReleased(); return; | 205 | case Back: emit backReleased(); return; |
183 | case FullScreen: mediaPlayerState.setFullscreen( true ); makeVisible(); return; | 206 | case FullScreen: mediaPlayerState.setFullscreen( true ); makeVisible(); return; |
184 | default: assert( false ); | 207 | default: assert( false ); |
185 | } | 208 | } |
186 | } | 209 | } |
187 | 210 | ||
188 | bool MediaWidget::isOverButton( const QPoint &position, int buttonId ) const | 211 | bool MediaWidget::isOverButton( const QPoint &position, int buttonId ) const |
189 | { | 212 | { |
190 | return ( position.x() > 0 && position.y() > 0 && | 213 | return ( position.x() > 0 && position.y() > 0 && |
191 | position.x() < buttonMask.width() && | 214 | position.x() < buttonMask.width() && |
192 | position.y() < buttonMask.height() && | 215 | position.y() < buttonMask.height() && |
193 | buttonMask.pixelIndex( position.x(), position.y() ) == buttonId + 1 ); | 216 | buttonMask.pixelIndex( position.x(), position.y() ) == buttonId + 1 ); |
194 | } | 217 | } |
195 | 218 | ||
196 | void MediaWidget::paintAllButtons( QPainter &p ) | 219 | void MediaWidget::paintAllButtons( QPainter &p ) |
197 | { | 220 | { |
198 | for ( ButtonVector::const_iterator it = buttons.begin(); | 221 | for ( ButtonVector::const_iterator it = buttons.begin(); |
199 | it != buttons.end(); ++it ) | 222 | it != buttons.end(); ++it ) |
200 | paintButton( p, *it ); | 223 | paintButton( p, *it ); |
201 | } | 224 | } |
202 | 225 | ||
203 | void MediaWidget::paintButton( const Button &button ) | 226 | void MediaWidget::paintButton( const Button &button ) |
204 | { | 227 | { |
205 | QPainter p( this ); | 228 | QPainter p( this ); |
206 | paintButton( p, button ); | 229 | paintButton( p, button ); |
207 | } | 230 | } |
208 | 231 | ||
209 | void MediaWidget::paintButton( QPainter &p, const Button &button ) | 232 | void MediaWidget::paintButton( QPainter &p, const Button &button ) |
210 | { | 233 | { |
211 | if ( button.isDown ) | 234 | if ( button.isDown ) |
212 | p.drawPixmap( upperLeftOfButtonMask, button.pixDown ); | 235 | p.drawPixmap( upperLeftOfButtonMask, button.pixDown ); |
213 | else | 236 | else |
214 | p.drawPixmap( upperLeftOfButtonMask, button.pixUp ); | 237 | p.drawPixmap( upperLeftOfButtonMask, button.pixUp ); |
215 | } | 238 | } |
216 | 239 | ||
217 | void MediaWidget::setToggleButton( Command command, bool down ) | 240 | void MediaWidget::setToggleButton( Command command, bool down ) |
218 | { | 241 | { |
219 | for ( ButtonVector::iterator it = buttons.begin(); it != buttons.end(); ++it ) | 242 | for ( ButtonVector::iterator it = buttons.begin(); it != buttons.end(); ++it ) |
220 | if ( it->command == command ) { | 243 | if ( it->command == command ) { |
221 | setToggleButton( *it, down ); | 244 | setToggleButton( *it, down ); |
222 | return; | 245 | return; |
223 | } | 246 | } |
224 | } | 247 | } |
225 | 248 | ||
226 | void MediaWidget::setToggleButton( Button &button, bool down ) | 249 | void MediaWidget::setToggleButton( Button &button, bool down ) |
227 | { | 250 | { |
228 | if ( down != button.isDown ) | 251 | if ( down != button.isDown ) |
229 | toggleButton( button ); | 252 | toggleButton( button ); |
230 | } | 253 | } |
231 | 254 | ||
232 | void MediaWidget::toggleButton( Button &button ) | 255 | void MediaWidget::toggleButton( Button &button ) |
233 | { | 256 | { |
234 | button.isDown = !button.isDown; | 257 | button.isDown = !button.isDown; |
235 | 258 | ||
236 | paintButton( button ); | 259 | paintButton( button ); |
237 | } | 260 | } |
238 | 261 | ||
239 | /* vim: et sw=4 ts=4 | 262 | /* vim: et sw=4 ts=4 |
240 | */ | 263 | */ |
diff --git a/noncore/multimedia/opieplayer2/mediawidget.h b/noncore/multimedia/opieplayer2/mediawidget.h index 754228e..52b9fcb 100644 --- a/noncore/multimedia/opieplayer2/mediawidget.h +++ b/noncore/multimedia/opieplayer2/mediawidget.h | |||
@@ -1,146 +1,149 @@ | |||
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 | #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 MediaWidget : public QWidget | 46 | class MediaWidget : public QWidget |
47 | { | 47 | { |
48 | Q_OBJECT | 48 | Q_OBJECT |
49 | public: | 49 | public: |
50 | enum Command { Play = 0, Stop, Next, Previous, VolumeUp, VolumeDown, Loop, PlayList, Forward, Back, FullScreen, Undefined }; | 50 | enum Command { Play = 0, Stop, Next, Previous, VolumeUp, VolumeDown, Loop, PlayList, Forward, Back, FullScreen, Undefined }; |
51 | enum ButtonType { NormalButton, ToggleButton }; | 51 | enum ButtonType { NormalButton, ToggleButton }; |
52 | 52 | ||
53 | struct Button | 53 | struct Button |
54 | { | 54 | { |
55 | Button() : command( Undefined ), type( NormalButton ), isDown( false ) {} | 55 | Button() : command( Undefined ), type( NormalButton ), isDown( false ) {} |
56 | 56 | ||
57 | Command command; | 57 | Command command; |
58 | 58 | ||
59 | ButtonType type; // this should be part of the bitfield but gcc2 is too buggy to support this :-( | 59 | ButtonType type; // this should be part of the bitfield but gcc2 is too buggy to support this :-( |
60 | bool isDown : 1; | 60 | bool isDown : 1; |
61 | 61 | ||
62 | QBitmap mask; | 62 | QBitmap mask; |
63 | QPixmap pixUp; | 63 | QPixmap pixUp; |
64 | QPixmap pixDown; | 64 | QPixmap pixDown; |
65 | }; | 65 | }; |
66 | #if defined( _CC_GNU_ ) | 66 | #if defined( _CC_GNU_ ) |
67 | // use that allocator to avoid the default allocator that on gcc2 requires libstdc++ because | 67 | // use that allocator to avoid the default allocator that on gcc2 requires libstdc++ because |
68 | // in the BAD_ALLOC macro it uses std::cerr and friends :-( | 68 | // in the BAD_ALLOC macro it uses std::cerr and friends :-( |
69 | typedef std::vector<Button, std::__allocator<Button, simpleAndStupidAllocator> > ButtonVector; | 69 | typedef std::vector<Button, std::__allocator<Button, simpleAndStupidAllocator> > ButtonVector; |
70 | #else | 70 | #else |
71 | typedef std::vector<Button> ButtonVector; | 71 | typedef std::vector<Button> ButtonVector; |
72 | #endif | 72 | #endif |
73 | 73 | ||
74 | struct SkinButtonInfo | 74 | struct SkinButtonInfo |
75 | { | 75 | { |
76 | Command command; | 76 | Command command; |
77 | const char *fileName; | 77 | const char *fileName; |
78 | ButtonType type; | 78 | ButtonType type; |
79 | }; | 79 | }; |
80 | 80 | ||
81 | MediaWidget( PlayListWidget &_playList, MediaPlayerState &_mediaPlayerState, QWidget *parent = 0, const char *name = 0 ); | 81 | MediaWidget( PlayListWidget &_playList, MediaPlayerState &_mediaPlayerState, QWidget *parent = 0, const char *name = 0 ); |
82 | virtual ~MediaWidget(); | 82 | virtual ~MediaWidget(); |
83 | 83 | ||
84 | public slots: | 84 | public slots: |
85 | virtual void setDisplayType( MediaPlayerState::DisplayType displayType ) = 0; | 85 | virtual void setDisplayType( MediaPlayerState::DisplayType displayType ) = 0; |
86 | virtual void setLength( long length ) = 0; | 86 | virtual void setLength( long length ) = 0; |
87 | virtual void setPlaying( bool playing ) = 0; | 87 | virtual void setPlaying( bool playing ) = 0; |
88 | 88 | ||
89 | virtual void loadSkin() = 0; | 89 | virtual void loadSkin() = 0; |
90 | 90 | ||
91 | signals: | 91 | signals: |
92 | void moreReleased(); | 92 | void moreReleased(); |
93 | void lessReleased(); | 93 | void lessReleased(); |
94 | void forwardReleased(); | 94 | void forwardReleased(); |
95 | void backReleased(); | 95 | void backReleased(); |
96 | void forwardClicked(); | 96 | void forwardClicked(); |
97 | void backClicked(); | 97 | void backClicked(); |
98 | void moreClicked(); | 98 | void moreClicked(); |
99 | void lessClicked(); | 99 | void lessClicked(); |
100 | 100 | ||
101 | protected: | 101 | protected: |
102 | void setupButtons( const SkinButtonInfo *skinInfo, uint buttonCount, | 102 | void setupButtons( const SkinButtonInfo *skinInfo, uint buttonCount, |
103 | const QString &imagePrefix, const QSize &buttonAreaSize ); | 103 | const QString &imagePrefix, const QSize &buttonAreaSize ); |
104 | Button setupButton( const SkinButtonInfo &buttonInfo, const QString &imagePrefix ); | 104 | Button setupButton( const SkinButtonInfo &buttonInfo, const QString &imagePrefix ); |
105 | QBitmap setupButtonMask( const Command &command, const QString &fileName ); | 105 | QBitmap setupButtonMask( const Command &command, const QString &fileName ); |
106 | 106 | ||
107 | void loadDefaultSkin( const SkinButtonInfo *skinInfo, uint buttonCount, const QString &fileNameInfix = QString::null ); | ||
108 | void loadSkin( const SkinButtonInfo *skinInfo, uint buttonCount, const QString &name, const QString &fileNameInfix ); | ||
109 | |||
107 | virtual void closeEvent( QCloseEvent * ); | 110 | virtual void closeEvent( QCloseEvent * ); |
108 | 111 | ||
109 | virtual void paintEvent( QPaintEvent *pe ); | 112 | virtual void paintEvent( QPaintEvent *pe ); |
110 | 113 | ||
111 | Button *buttonAt( const QPoint &position ); | 114 | Button *buttonAt( const QPoint &position ); |
112 | 115 | ||
113 | virtual void mousePressEvent( QMouseEvent *event ); | 116 | virtual void mousePressEvent( QMouseEvent *event ); |
114 | virtual void mouseReleaseEvent( QMouseEvent *event ); | 117 | virtual void mouseReleaseEvent( QMouseEvent *event ); |
115 | 118 | ||
116 | virtual void makeVisible(); | 119 | virtual void makeVisible(); |
117 | 120 | ||
118 | void handleCommand( Command command, bool buttonDown ); | 121 | void handleCommand( Command command, bool buttonDown ); |
119 | 122 | ||
120 | bool isOverButton( const QPoint &position, int buttonId ) const; | 123 | bool isOverButton( const QPoint &position, int buttonId ) const; |
121 | 124 | ||
122 | void paintAllButtons( QPainter &p ); | 125 | void paintAllButtons( QPainter &p ); |
123 | void paintButton( const Button &button ); | 126 | void paintButton( const Button &button ); |
124 | void paintButton( QPainter &p, const Button &button ); | 127 | void paintButton( QPainter &p, const Button &button ); |
125 | 128 | ||
126 | void setToggleButton( Button &button, bool down ); | 129 | void setToggleButton( Button &button, bool down ); |
127 | void setToggleButton( Command command, bool down ); | 130 | void setToggleButton( Command command, bool down ); |
128 | void toggleButton( Button &button ); | 131 | void toggleButton( Button &button ); |
129 | 132 | ||
130 | MediaPlayerState &mediaPlayerState; | 133 | MediaPlayerState &mediaPlayerState; |
131 | PlayListWidget &playList; | 134 | PlayListWidget &playList; |
132 | 135 | ||
133 | ButtonVector buttons; | 136 | ButtonVector buttons; |
134 | 137 | ||
135 | QImage buttonMask; | 138 | QImage buttonMask; |
136 | 139 | ||
137 | QPoint upperLeftOfButtonMask; | 140 | QPoint upperLeftOfButtonMask; |
138 | 141 | ||
139 | QPixmap backgroundPixmap; | 142 | QPixmap backgroundPixmap; |
140 | QImage buttonUpImage; | 143 | QImage buttonUpImage; |
141 | QImage buttonDownImage; | 144 | QImage buttonDownImage; |
142 | }; | 145 | }; |
143 | 146 | ||
144 | #endif // MEDIAWIDGET_H | 147 | #endif // MEDIAWIDGET_H |
145 | /* vim: et sw=4 ts=4 | 148 | /* vim: et sw=4 ts=4 |
146 | */ | 149 | */ |
diff --git a/noncore/multimedia/opieplayer2/videowidget.cpp b/noncore/multimedia/opieplayer2/videowidget.cpp index 0047ac0..bc47717 100644 --- a/noncore/multimedia/opieplayer2/videowidget.cpp +++ b/noncore/multimedia/opieplayer2/videowidget.cpp | |||
@@ -1,348 +1,339 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of the Opie Project | 2 | This file is part of the Opie Project |
3 | 3 | ||
4 | Copyright (c) 2002 Max Reiss <harlekin@handhelds.org> | 4 | Copyright (c) 2002 Max Reiss <harlekin@handhelds.org> |
5 | Copyright (c) 2002 L. Potter <ljp@llornkcor.com> | 5 | Copyright (c) 2002 L. Potter <ljp@llornkcor.com> |
6 | Copyright (c) 2002 Holger Freyther <zecke@handhelds.org> | 6 | Copyright (c) 2002 Holger Freyther <zecke@handhelds.org> |
7 | =. | 7 | =. |
8 | .=l. | 8 | .=l. |
9 | .>+-= | 9 | .>+-= |
10 | _;:, .> :=|. This program is free software; you can | 10 | _;:, .> :=|. This program is free software; you can |
11 | .> <`_, > . <= redistribute it and/or modify it under | 11 | .> <`_, > . <= redistribute it and/or modify it under |
12 | :`=1 )Y*s>-.-- : the terms of the GNU General Public | 12 | :`=1 )Y*s>-.-- : the terms of the GNU General Public |
13 | .="- .-=="i, .._ License as published by the Free Software | 13 | .="- .-=="i, .._ License as published by the Free Software |
14 | - . .-<_> .<> Foundation; either version 2 of the License, | 14 | - . .-<_> .<> Foundation; either version 2 of the License, |
15 | ._= =} : or (at your option) any later version. | 15 | ._= =} : or (at your option) any later version. |
16 | .%`+i> _;_. | 16 | .%`+i> _;_. |
17 | .i_,=:_. -<s. This program is distributed in the hope that | 17 | .i_,=:_. -<s. This program is distributed in the hope that |
18 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 18 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
19 | : .. .:, . . . without even the implied warranty of | 19 | : .. .:, . . . without even the implied warranty of |
20 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 20 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
21 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | 21 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU |
22 | ..}^=.= = ; Library General Public License for more | 22 | ..}^=.= = ; Library General Public License for more |
23 | ++= -. .` .: details. | 23 | ++= -. .` .: details. |
24 | : = ...= . :.=- | 24 | : = ...= . :.=- |
25 | -. .:....=;==+<; You should have received a copy of the GNU | 25 | -. .:....=;==+<; You should have received a copy of the GNU |
26 | -_. . . )=. = Library General Public License along with | 26 | -_. . . )=. = Library General Public License along with |
27 | -- :-=` this library; see the file COPYING.LIB. | 27 | -- :-=` this library; see the file COPYING.LIB. |
28 | If not, write to the Free Software Foundation, | 28 | If not, write to the Free Software Foundation, |
29 | Inc., 59 Temple Place - Suite 330, | 29 | Inc., 59 Temple Place - Suite 330, |
30 | Boston, MA 02111-1307, USA. | 30 | Boston, MA 02111-1307, USA. |
31 | 31 | ||
32 | */ | 32 | */ |
33 | 33 | ||
34 | #include <qpe/qpeapplication.h> | 34 | #include <qpe/qpeapplication.h> |
35 | #include <qpe/resource.h> | 35 | #include <qpe/resource.h> |
36 | #include <qpe/config.h> | 36 | #include <qpe/config.h> |
37 | 37 | ||
38 | 38 | ||
39 | #include <qwidget.h> | 39 | #include <qwidget.h> |
40 | #include <qpainter.h> | 40 | #include <qpainter.h> |
41 | #include <qpixmap.h> | 41 | #include <qpixmap.h> |
42 | #include <qslider.h> | 42 | #include <qslider.h> |
43 | #include <qdrawutil.h> | 43 | #include <qdrawutil.h> |
44 | #include "videowidget.h" | 44 | #include "videowidget.h" |
45 | #include "mediaplayerstate.h" | 45 | #include "mediaplayerstate.h" |
46 | #include "playlistwidget.h" | 46 | #include "playlistwidget.h" |
47 | 47 | ||
48 | 48 | ||
49 | #ifdef Q_WS_QWS | 49 | #ifdef Q_WS_QWS |
50 | # define USE_DIRECT_PAINTER | 50 | # define USE_DIRECT_PAINTER |
51 | # include <qdirectpainter_qws.h> | 51 | # include <qdirectpainter_qws.h> |
52 | # include <qgfxraster_qws.h> | 52 | # include <qgfxraster_qws.h> |
53 | #endif | 53 | #endif |
54 | 54 | ||
55 | 55 | ||
56 | namespace | 56 | namespace |
57 | { | 57 | { |
58 | 58 | ||
59 | const int xo = 2; // movable x offset | 59 | const int xo = 2; // movable x offset |
60 | const int yo = 0; // movable y offset | 60 | const int yo = 0; // movable y offset |
61 | 61 | ||
62 | const MediaWidget::SkinButtonInfo skinInfo[] = | 62 | const MediaWidget::SkinButtonInfo skinInfo[] = |
63 | { | 63 | { |
64 | { MediaWidget::Play, "play", MediaWidget::ToggleButton }, | 64 | { MediaWidget::Play, "play", MediaWidget::ToggleButton }, |
65 | { MediaWidget::Stop, "stop", MediaWidget::NormalButton }, | 65 | { MediaWidget::Stop, "stop", MediaWidget::NormalButton }, |
66 | { MediaWidget::Next, "fwd", MediaWidget::NormalButton }, | 66 | { MediaWidget::Next, "fwd", MediaWidget::NormalButton }, |
67 | { MediaWidget::Previous, "back", MediaWidget::NormalButton }, | 67 | { MediaWidget::Previous, "back", MediaWidget::NormalButton }, |
68 | { MediaWidget::VolumeUp, "up", MediaWidget::NormalButton }, | 68 | { MediaWidget::VolumeUp, "up", MediaWidget::NormalButton }, |
69 | { MediaWidget::VolumeDown, "down", MediaWidget::NormalButton }, | 69 | { MediaWidget::VolumeDown, "down", MediaWidget::NormalButton }, |
70 | { MediaWidget::FullScreen, "full", MediaWidget::ToggleButton } | 70 | { MediaWidget::FullScreen, "full", MediaWidget::ToggleButton } |
71 | }; | 71 | }; |
72 | 72 | ||
73 | const uint buttonCount = sizeof( skinInfo ) / sizeof( skinInfo[ 0 ] ); | 73 | const uint buttonCount = sizeof( skinInfo ) / sizeof( skinInfo[ 0 ] ); |
74 | 74 | ||
75 | } | 75 | } |
76 | 76 | ||
77 | VideoWidget::VideoWidget( PlayListWidget &playList, MediaPlayerState &mediaPlayerState, QWidget* parent, const char* name ) | 77 | VideoWidget::VideoWidget( PlayListWidget &playList, MediaPlayerState &mediaPlayerState, QWidget* parent, const char* name ) |
78 | : MediaWidget( playList, mediaPlayerState, parent, name ), scaledWidth( 0 ), scaledHeight( 0 ), videoSliderBeingMoved( false ) | 78 | : MediaWidget( playList, mediaPlayerState, parent, name ), scaledWidth( 0 ), scaledHeight( 0 ), videoSliderBeingMoved( false ) |
79 | { | 79 | { |
80 | setCaption( tr("OpiePlayer - Video") ); | 80 | setCaption( tr("OpiePlayer - Video") ); |
81 | 81 | ||
82 | videoFrame = new XineVideoWidget ( this, "Video frame" ); | 82 | videoFrame = new XineVideoWidget ( this, "Video frame" ); |
83 | 83 | ||
84 | connect ( videoFrame, SIGNAL( videoResized ( const QSize & )), this, SIGNAL( videoResized ( const QSize & ))); | 84 | connect ( videoFrame, SIGNAL( videoResized ( const QSize & )), this, SIGNAL( videoResized ( const QSize & ))); |
85 | connect ( videoFrame, SIGNAL( clicked () ), this, SLOT ( backToNormal() ) ); | 85 | connect ( videoFrame, SIGNAL( clicked () ), this, SLOT ( backToNormal() ) ); |
86 | 86 | ||
87 | slider = 0; | 87 | slider = 0; |
88 | 88 | ||
89 | loadSkin(); | 89 | loadSkin(); |
90 | 90 | ||
91 | setLength( mediaPlayerState.length() ); | 91 | setLength( mediaPlayerState.length() ); |
92 | setPosition( mediaPlayerState.position() ); | 92 | setPosition( mediaPlayerState.position() ); |
93 | setFullscreen( mediaPlayerState.isFullscreen() ); | 93 | setFullscreen( mediaPlayerState.isFullscreen() ); |
94 | setPlaying( mediaPlayerState.isPlaying() ); | 94 | setPlaying( mediaPlayerState.isPlaying() ); |
95 | } | 95 | } |
96 | 96 | ||
97 | 97 | ||
98 | VideoWidget::~VideoWidget() | 98 | VideoWidget::~VideoWidget() |
99 | { | 99 | { |
100 | } | 100 | } |
101 | 101 | ||
102 | QPixmap *combineVImageWithBackground( QImage img, QPixmap bg, QPoint offset ) { | 102 | QPixmap *combineVImageWithBackground( QImage img, QPixmap bg, QPoint offset ) { |
103 | QPixmap pix( img.width(), img.height() ); | 103 | QPixmap pix( img.width(), img.height() ); |
104 | QPainter p( &pix ); | 104 | QPainter p( &pix ); |
105 | p.drawTiledPixmap( pix.rect(), bg, offset ); | 105 | p.drawTiledPixmap( pix.rect(), bg, offset ); |
106 | p.drawImage( 0, 0, img ); | 106 | p.drawImage( 0, 0, img ); |
107 | return new QPixmap( pix ); | 107 | return new QPixmap( pix ); |
108 | } | 108 | } |
109 | 109 | ||
110 | QPixmap maskVPixToMask( QPixmap pix, QBitmap mask ) { | 110 | QPixmap maskVPixToMask( QPixmap pix, QBitmap mask ) { |
111 | QPixmap pixmap( pix ); | 111 | QPixmap pixmap( pix ); |
112 | pixmap.setMask( mask ); | 112 | pixmap.setMask( mask ); |
113 | return pixmap; | 113 | return pixmap; |
114 | } | 114 | } |
115 | 115 | ||
116 | void VideoWidget::resizeEvent( QResizeEvent * ) { | 116 | void VideoWidget::resizeEvent( QResizeEvent * ) { |
117 | int h = height(); | 117 | int h = height(); |
118 | int w = width(); | 118 | int w = width(); |
119 | //int Vh = 160; | 119 | //int Vh = 160; |
120 | //int Vw = 220; | 120 | //int Vw = 220; |
121 | 121 | ||
122 | slider->setFixedWidth( w - 20 ); | 122 | slider->setFixedWidth( w - 20 ); |
123 | slider->setGeometry( QRect( 15, h - 22, w - 90, 20 ) ); | 123 | slider->setGeometry( QRect( 15, h - 22, w - 90, 20 ) ); |
124 | slider->setBackgroundOrigin( QWidget::ParentOrigin ); | 124 | slider->setBackgroundOrigin( QWidget::ParentOrigin ); |
125 | slider->setFocusPolicy( QWidget::NoFocus ); | 125 | slider->setFocusPolicy( QWidget::NoFocus ); |
126 | slider->setBackgroundPixmap( backgroundPixmap ); | 126 | slider->setBackgroundPixmap( backgroundPixmap ); |
127 | 127 | ||
128 | upperLeftOfButtonMask.rx() = 0;// ( imgUp->width() ) / 2; | 128 | upperLeftOfButtonMask.rx() = 0;// ( imgUp->width() ) / 2; |
129 | if(w>h) | 129 | if(w>h) |
130 | upperLeftOfButtonMask.ry() = 0; | 130 | upperLeftOfButtonMask.ry() = 0; |
131 | else | 131 | else |
132 | upperLeftOfButtonMask.ry() = 185;//(( Vh - imgUp->height() ) / 2) - 10; | 132 | upperLeftOfButtonMask.ry() = 185;//(( Vh - imgUp->height() ) / 2) - 10; |
133 | QPoint p = upperLeftOfButtonMask; | 133 | QPoint p = upperLeftOfButtonMask; |
134 | 134 | ||
135 | QPixmap *pixUp = combineVImageWithBackground( buttonUpImage, backgroundPixmap, p ); | 135 | QPixmap *pixUp = combineVImageWithBackground( buttonUpImage, backgroundPixmap, p ); |
136 | QPixmap *pixDn = combineVImageWithBackground( buttonDownImage, backgroundPixmap, p ); | 136 | QPixmap *pixDn = combineVImageWithBackground( buttonDownImage, backgroundPixmap, p ); |
137 | 137 | ||
138 | for ( ButtonVector::iterator it = buttons.begin(); it != buttons.end(); ++it ) { | 138 | for ( ButtonVector::iterator it = buttons.begin(); it != buttons.end(); ++it ) { |
139 | Button &button = *it; | 139 | Button &button = *it; |
140 | 140 | ||
141 | if ( !button.mask.isNull() ) { | 141 | if ( !button.mask.isNull() ) { |
142 | button.pixUp = maskVPixToMask( *pixUp, button.mask ); | 142 | button.pixUp = maskVPixToMask( *pixUp, button.mask ); |
143 | button.pixDown = maskVPixToMask( *pixDn, button.mask ); | 143 | button.pixDown = maskVPixToMask( *pixDn, button.mask ); |
144 | } | 144 | } |
145 | } | 145 | } |
146 | 146 | ||
147 | delete pixUp; | 147 | delete pixUp; |
148 | delete pixDn; | 148 | delete pixDn; |
149 | } | 149 | } |
150 | 150 | ||
151 | void VideoWidget::sliderPressed() { | 151 | void VideoWidget::sliderPressed() { |
152 | videoSliderBeingMoved = TRUE; | 152 | videoSliderBeingMoved = TRUE; |
153 | } | 153 | } |
154 | 154 | ||
155 | void VideoWidget::sliderReleased() { | 155 | void VideoWidget::sliderReleased() { |
156 | videoSliderBeingMoved = FALSE; | 156 | videoSliderBeingMoved = FALSE; |
157 | if ( slider->width() == 0 ) { | 157 | if ( slider->width() == 0 ) { |
158 | return; | 158 | return; |
159 | } | 159 | } |
160 | long val = long((double)slider->value() * mediaPlayerState.length() / slider->width()); | 160 | long val = long((double)slider->value() * mediaPlayerState.length() / slider->width()); |
161 | mediaPlayerState.setPosition( val ); | 161 | mediaPlayerState.setPosition( val ); |
162 | } | 162 | } |
163 | 163 | ||
164 | void VideoWidget::setPosition( long i ) { | 164 | void VideoWidget::setPosition( long i ) { |
165 | updateSlider( i, mediaPlayerState.length() ); | 165 | updateSlider( i, mediaPlayerState.length() ); |
166 | } | 166 | } |
167 | 167 | ||
168 | 168 | ||
169 | void VideoWidget::setLength( long max ) { | 169 | void VideoWidget::setLength( long max ) { |
170 | updateSlider( mediaPlayerState.position(), max ); | 170 | updateSlider( mediaPlayerState.position(), max ); |
171 | } | 171 | } |
172 | 172 | ||
173 | void VideoWidget::setDisplayType( MediaPlayerState::DisplayType displayType ) | 173 | void VideoWidget::setDisplayType( MediaPlayerState::DisplayType displayType ) |
174 | { | 174 | { |
175 | if ( displayType == MediaPlayerState::Video ) { | 175 | if ( displayType == MediaPlayerState::Video ) { |
176 | makeVisible(); | 176 | makeVisible(); |
177 | return; | 177 | return; |
178 | } | 178 | } |
179 | 179 | ||
180 | // Effectively blank the view next time we show it so it looks nicer | 180 | // Effectively blank the view next time we show it so it looks nicer |
181 | scaledWidth = 0; | 181 | scaledWidth = 0; |
182 | scaledHeight = 0; | 182 | scaledHeight = 0; |
183 | hide(); | 183 | hide(); |
184 | } | 184 | } |
185 | 185 | ||
186 | void VideoWidget::loadSkin() | 186 | void VideoWidget::loadSkin() |
187 | { | 187 | { |
188 | Config cfg("OpiePlayer"); | 188 | loadDefaultSkin( skinInfo, buttonCount, "V" ); |
189 | cfg.setGroup("Options"); | ||
190 | QString skin = cfg.readEntry("Skin","default"); | ||
191 | |||
192 | QString skinPath = "opieplayer2/skins/" + skin; | ||
193 | backgroundPixmap = QPixmap( Resource::loadPixmap( QString("%1/background").arg(skinPath) ) ); | ||
194 | buttonUpImage = QImage( Resource::loadImage( QString("%1/skinV_up").arg(skinPath) ) ); | ||
195 | buttonDownImage = QImage( Resource::loadImage( QString("%1/skinV_down").arg(skinPath) ) ); | ||
196 | |||
197 | setupButtons( skinInfo, buttonCount, QPEApplication::qpeDir() + "/pics/" + skinPath + "/skinV_mask_", buttonUpImage.size() ); | ||
198 | 189 | ||
199 | setBackgroundPixmap( backgroundPixmap ); | 190 | setBackgroundPixmap( backgroundPixmap ); |
200 | 191 | ||
201 | delete slider; | 192 | delete slider; |
202 | slider = new QSlider( Qt::Horizontal, this ); | 193 | slider = new QSlider( Qt::Horizontal, this ); |
203 | slider->setMinValue( 0 ); | 194 | slider->setMinValue( 0 ); |
204 | slider->setMaxValue( 1 ); | 195 | slider->setMaxValue( 1 ); |
205 | slider->setBackgroundPixmap( backgroundPixmap ); | 196 | slider->setBackgroundPixmap( backgroundPixmap ); |
206 | //slider->setFocusPolicy( QWidget::NoFocus ); | 197 | //slider->setFocusPolicy( QWidget::NoFocus ); |
207 | 198 | ||
208 | resizeEvent( 0 ); | 199 | resizeEvent( 0 ); |
209 | } | 200 | } |
210 | 201 | ||
211 | void VideoWidget::updateSlider( long i, long max ) { | 202 | void VideoWidget::updateSlider( long i, long max ) { |
212 | // Will flicker too much if we don't do this | 203 | // Will flicker too much if we don't do this |
213 | if ( max == 0 ) { | 204 | if ( max == 0 ) { |
214 | return; | 205 | return; |
215 | } | 206 | } |
216 | int width = slider->width(); | 207 | int width = slider->width(); |
217 | int val = int((double)i * width / max); | 208 | int val = int((double)i * width / max); |
218 | if ( !mediaPlayerState.isFullscreen() && !videoSliderBeingMoved ) { | 209 | if ( !mediaPlayerState.isFullscreen() && !videoSliderBeingMoved ) { |
219 | if ( slider->value() != val ) { | 210 | if ( slider->value() != val ) { |
220 | slider->setValue( val ); | 211 | slider->setValue( val ); |
221 | } | 212 | } |
222 | if ( slider->maxValue() != width ) { | 213 | if ( slider->maxValue() != width ) { |
223 | slider->setMaxValue( width ); | 214 | slider->setMaxValue( width ); |
224 | } | 215 | } |
225 | } | 216 | } |
226 | } | 217 | } |
227 | 218 | ||
228 | void VideoWidget::mouseReleaseEvent( QMouseEvent *event ) { | 219 | void VideoWidget::mouseReleaseEvent( QMouseEvent *event ) { |
229 | if ( mediaPlayerState.isFullscreen() ) { | 220 | if ( mediaPlayerState.isFullscreen() ) { |
230 | mediaPlayerState.setFullscreen( FALSE ); | 221 | mediaPlayerState.setFullscreen( FALSE ); |
231 | makeVisible(); | 222 | makeVisible(); |
232 | } | 223 | } |
233 | MediaWidget::mouseReleaseEvent( event ); | 224 | MediaWidget::mouseReleaseEvent( event ); |
234 | } | 225 | } |
235 | 226 | ||
236 | void VideoWidget::backToNormal() { | 227 | void VideoWidget::backToNormal() { |
237 | mediaPlayerState.setFullscreen( FALSE ); | 228 | mediaPlayerState.setFullscreen( FALSE ); |
238 | makeVisible(); | 229 | makeVisible(); |
239 | } | 230 | } |
240 | 231 | ||
241 | void VideoWidget::makeVisible() { | 232 | void VideoWidget::makeVisible() { |
242 | if ( mediaPlayerState.isFullscreen() ) { | 233 | if ( mediaPlayerState.isFullscreen() ) { |
243 | setBackgroundMode( QWidget::NoBackground ); | 234 | setBackgroundMode( QWidget::NoBackground ); |
244 | showFullScreen(); | 235 | showFullScreen(); |
245 | resize( qApp->desktop()->size() ); | 236 | resize( qApp->desktop()->size() ); |
246 | videoFrame-> setGeometry ( 0, 0, width ( ), height ( )); | 237 | videoFrame-> setGeometry ( 0, 0, width ( ), height ( )); |
247 | 238 | ||
248 | slider->hide(); | 239 | slider->hide(); |
249 | disconnect( &mediaPlayerState, SIGNAL( positionChanged(long) ),this, SLOT( setPosition(long) ) ); | 240 | disconnect( &mediaPlayerState, SIGNAL( positionChanged(long) ),this, SLOT( setPosition(long) ) ); |
250 | disconnect( &mediaPlayerState, SIGNAL( positionUpdated(long) ),this, SLOT( setPosition(long) ) ); | 241 | disconnect( &mediaPlayerState, SIGNAL( positionUpdated(long) ),this, SLOT( setPosition(long) ) ); |
251 | disconnect( slider, SIGNAL( sliderPressed() ), this, SLOT( sliderPressed() ) ); | 242 | disconnect( slider, SIGNAL( sliderPressed() ), this, SLOT( sliderPressed() ) ); |
252 | disconnect( slider, SIGNAL( sliderReleased() ), this, SLOT( sliderReleased() ) ); | 243 | disconnect( slider, SIGNAL( sliderReleased() ), this, SLOT( sliderReleased() ) ); |
253 | 244 | ||
254 | } else { | 245 | } else { |
255 | showNormal(); | 246 | showNormal(); |
256 | showMaximized(); | 247 | showMaximized(); |
257 | setBackgroundPixmap( backgroundPixmap ); | 248 | setBackgroundPixmap( backgroundPixmap ); |
258 | QWidget *d = QApplication::desktop(); | 249 | QWidget *d = QApplication::desktop(); |
259 | int w = d->width(); | 250 | int w = d->width(); |
260 | int h = d->height(); | 251 | int h = d->height(); |
261 | 252 | ||
262 | if(w>h) { | 253 | if(w>h) { |
263 | int newW=(w/2)-(246/2); //this will only work with 320x240 | 254 | int newW=(w/2)-(246/2); //this will only work with 320x240 |
264 | videoFrame->setGeometry( QRect( newW, 4, 240, 170 ) ); | 255 | videoFrame->setGeometry( QRect( newW, 4, 240, 170 ) ); |
265 | } else { | 256 | } else { |
266 | videoFrame->setGeometry( QRect( 0, 30, 240, 170 ) ); | 257 | videoFrame->setGeometry( QRect( 0, 30, 240, 170 ) ); |
267 | } | 258 | } |
268 | 259 | ||
269 | if ( !mediaPlayerState.isSeekable() ) { | 260 | if ( !mediaPlayerState.isSeekable() ) { |
270 | if( !slider->isHidden()) { | 261 | if( !slider->isHidden()) { |
271 | slider->hide(); | 262 | slider->hide(); |
272 | } | 263 | } |
273 | disconnect( &mediaPlayerState, SIGNAL( positionChanged(long) ),this, SLOT( setPosition(long) ) ); | 264 | disconnect( &mediaPlayerState, SIGNAL( positionChanged(long) ),this, SLOT( setPosition(long) ) ); |
274 | disconnect( &mediaPlayerState, SIGNAL( positionUpdated(long) ),this, SLOT( setPosition(long) ) ); | 265 | disconnect( &mediaPlayerState, SIGNAL( positionUpdated(long) ),this, SLOT( setPosition(long) ) ); |
275 | disconnect( slider, SIGNAL( sliderPressed() ), this, SLOT( sliderPressed() ) ); | 266 | disconnect( slider, SIGNAL( sliderPressed() ), this, SLOT( sliderPressed() ) ); |
276 | disconnect( slider, SIGNAL( sliderReleased() ), this, SLOT( sliderReleased() ) ); | 267 | disconnect( slider, SIGNAL( sliderReleased() ), this, SLOT( sliderReleased() ) ); |
277 | } else { | 268 | } else { |
278 | slider->show(); | 269 | slider->show(); |
279 | connect( &mediaPlayerState, SIGNAL( positionChanged(long) ),this, SLOT( setPosition(long) ) ); | 270 | connect( &mediaPlayerState, SIGNAL( positionChanged(long) ),this, SLOT( setPosition(long) ) ); |
280 | connect( &mediaPlayerState, SIGNAL( positionUpdated(long) ),this, SLOT( setPosition(long) ) ); | 271 | connect( &mediaPlayerState, SIGNAL( positionUpdated(long) ),this, SLOT( setPosition(long) ) ); |
281 | connect( slider, SIGNAL( sliderPressed() ), this, SLOT( sliderPressed() ) ); | 272 | connect( slider, SIGNAL( sliderPressed() ), this, SLOT( sliderPressed() ) ); |
282 | connect( slider, SIGNAL( sliderReleased() ), this, SLOT( sliderReleased() ) ); | 273 | connect( slider, SIGNAL( sliderReleased() ), this, SLOT( sliderReleased() ) ); |
283 | } | 274 | } |
284 | } | 275 | } |
285 | } | 276 | } |
286 | 277 | ||
287 | void VideoWidget::keyReleaseEvent( QKeyEvent *e) { | 278 | void VideoWidget::keyReleaseEvent( QKeyEvent *e) { |
288 | switch ( e->key() ) { | 279 | switch ( e->key() ) { |
289 | ////////////////////////////// Zaurus keys | 280 | ////////////////////////////// Zaurus keys |
290 | case Key_Home: | 281 | case Key_Home: |
291 | break; | 282 | break; |
292 | case Key_F9: //activity | 283 | case Key_F9: //activity |
293 | break; | 284 | break; |
294 | case Key_F10: //contacts | 285 | case Key_F10: //contacts |
295 | // hide(); | 286 | // hide(); |
296 | break; | 287 | break; |
297 | case Key_F11: //menu | 288 | case Key_F11: //menu |
298 | break; | 289 | break; |
299 | case Key_F12: //home | 290 | case Key_F12: //home |
300 | break; | 291 | break; |
301 | case Key_F13: //mail | 292 | case Key_F13: //mail |
302 | break; | 293 | break; |
303 | case Key_Space: { | 294 | case Key_Space: { |
304 | if(mediaPlayerState.isPlaying()) { | 295 | if(mediaPlayerState.isPlaying()) { |
305 | mediaPlayerState.setPlaying(FALSE); | 296 | mediaPlayerState.setPlaying(FALSE); |
306 | } else { | 297 | } else { |
307 | mediaPlayerState.setPlaying(TRUE); | 298 | mediaPlayerState.setPlaying(TRUE); |
308 | } | 299 | } |
309 | } | 300 | } |
310 | break; | 301 | break; |
311 | case Key_Down: | 302 | case Key_Down: |
312 | // toggleButton(6); | 303 | // toggleButton(6); |
313 | emit lessClicked(); | 304 | emit lessClicked(); |
314 | emit lessReleased(); | 305 | emit lessReleased(); |
315 | // toggleButton(6); | 306 | // toggleButton(6); |
316 | break; | 307 | break; |
317 | case Key_Up: | 308 | case Key_Up: |
318 | // toggleButton(5); | 309 | // toggleButton(5); |
319 | emit moreClicked(); | 310 | emit moreClicked(); |
320 | emit moreReleased(); | 311 | emit moreReleased(); |
321 | // toggleButton(5); | 312 | // toggleButton(5); |
322 | break; | 313 | break; |
323 | case Key_Right: | 314 | case Key_Right: |
324 | mediaPlayerState.setNext(); | 315 | mediaPlayerState.setNext(); |
325 | break; | 316 | break; |
326 | case Key_Left: | 317 | case Key_Left: |
327 | mediaPlayerState.setPrev(); | 318 | mediaPlayerState.setPrev(); |
328 | break; | 319 | break; |
329 | case Key_Escape: | 320 | case Key_Escape: |
330 | break; | 321 | break; |
331 | 322 | ||
332 | }; | 323 | }; |
333 | } | 324 | } |
334 | 325 | ||
335 | XineVideoWidget* VideoWidget::vidWidget() { | 326 | XineVideoWidget* VideoWidget::vidWidget() { |
336 | return videoFrame; | 327 | return videoFrame; |
337 | } | 328 | } |
338 | 329 | ||
339 | 330 | ||
340 | void VideoWidget::setFullscreen ( bool b ) { | 331 | void VideoWidget::setFullscreen ( bool b ) { |
341 | setToggleButton( FullScreen, b ); | 332 | setToggleButton( FullScreen, b ); |
342 | } | 333 | } |
343 | 334 | ||
344 | 335 | ||
345 | void VideoWidget::setPlaying( bool b) { | 336 | void VideoWidget::setPlaying( bool b) { |
346 | setToggleButton( Play, b ); | 337 | setToggleButton( Play, b ); |
347 | } | 338 | } |
348 | 339 | ||