author | simon <simon> | 2002-12-09 14:48:13 (UTC) |
---|---|---|
committer | simon <simon> | 2002-12-09 14:48:13 (UTC) |
commit | 9ab8a657b23fd1871c4a376fdd097732c14392e0 (patch) (unidiff) | |
tree | 5e507bf74fad84ae6da1ed1facc689fd89de167d | |
parent | 174c4a427750a3829ffd81a87454be8abf61ee30 (diff) | |
download | opie-9ab8a657b23fd1871c4a376fdd097732c14392e0.zip opie-9ab8a657b23fd1871c4a376fdd097732c14392e0.tar.gz opie-9ab8a657b23fd1871c4a376fdd097732c14392e0.tar.bz2 |
- migrating from a button vector to a button map
-rw-r--r-- | noncore/multimedia/opieplayer2/audiowidget.cpp | 10 | ||||
-rw-r--r-- | noncore/multimedia/opieplayer2/mediawidget.h | 4 | ||||
-rw-r--r-- | noncore/multimedia/opieplayer2/videowidget.cpp | 21 |
3 files changed, 18 insertions, 17 deletions
diff --git a/noncore/multimedia/opieplayer2/audiowidget.cpp b/noncore/multimedia/opieplayer2/audiowidget.cpp index c148820..12f91a9 100644 --- a/noncore/multimedia/opieplayer2/audiowidget.cpp +++ b/noncore/multimedia/opieplayer2/audiowidget.cpp | |||
@@ -1,478 +1,478 @@ | |||
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 | #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 | Config cfg("OpiePlayer"); | 91 | Config cfg("OpiePlayer"); |
92 | cfg.setGroup("Options"); | 92 | cfg.setGroup("Options"); |
93 | skin = cfg.readEntry("Skin","default"); | 93 | skin = cfg.readEntry("Skin","default"); |
94 | //skin = "scaleTest"; | 94 | //skin = "scaleTest"; |
95 | // color of background, frame, degree of transparency | 95 | // color of background, frame, degree of transparency |
96 | 96 | ||
97 | QString skinPath = "opieplayer2/skins/" + skin; | 97 | QString skinPath = "opieplayer2/skins/" + skin; |
98 | pixBg = QPixmap( Resource::loadPixmap( QString("%1/background").arg(skinPath) ) ); | 98 | pixBg = QPixmap( Resource::loadPixmap( QString("%1/background").arg(skinPath) ) ); |
99 | imgUp = QImage( Resource::loadImage( QString("%1/skin_up").arg(skinPath) ) ); | 99 | imgUp = QImage( Resource::loadImage( QString("%1/skin_up").arg(skinPath) ) ); |
100 | imgDn = QImage( Resource::loadImage( QString("%1/skin_down").arg(skinPath) ) ); | 100 | imgDn = QImage( Resource::loadImage( QString("%1/skin_down").arg(skinPath) ) ); |
101 | 101 | ||
102 | buttonMask = QImage( imgUp.width(), imgUp.height(), 8, 255 ); | 102 | buttonMask = QImage( imgUp.width(), imgUp.height(), 8, 255 ); |
103 | buttonMask.fill( 0 ); | 103 | buttonMask.fill( 0 ); |
104 | 104 | ||
105 | for ( uint i = 0; i < buttonCount; i++ ) { | 105 | for ( uint i = 0; i < buttonCount; i++ ) { |
106 | Button button; | 106 | Button button; |
107 | button.type = skinInfo[ i ].type; | 107 | button.type = skinInfo[ i ].type; |
108 | 108 | ||
109 | QString filename = QString( QPEApplication::qpeDir() + "/pics/" + skinPath + "/skin_mask_" + skinInfo[i].fileName + ".png" ); | 109 | QString filename = QString( QPEApplication::qpeDir() + "/pics/" + skinPath + "/skin_mask_" + skinInfo[i].fileName + ".png" ); |
110 | button.mask =QBitmap( filename ); | 110 | button.mask =QBitmap( filename ); |
111 | 111 | ||
112 | if ( !button.mask.isNull() ) { | 112 | if ( !button.mask.isNull() ) { |
113 | QImage imgMask = button.mask.convertToImage(); | 113 | QImage imgMask = button.mask.convertToImage(); |
114 | uchar **dest = buttonMask.jumpTable(); | 114 | uchar **dest = buttonMask.jumpTable(); |
115 | for ( int y = 0; y < imgUp.height(); y++ ) { | 115 | for ( int y = 0; y < imgUp.height(); y++ ) { |
116 | uchar *line = dest[y]; | 116 | uchar *line = dest[y]; |
117 | for ( int x = 0; x < imgUp.width(); x++ ) | 117 | for ( int x = 0; x < imgUp.width(); x++ ) |
118 | if ( !qRed( imgMask.pixel( x, y ) ) ) | 118 | if ( !qRed( imgMask.pixel( x, y ) ) ) |
119 | line[x] = i + 1; | 119 | line[x] = i + 1; |
120 | } | 120 | } |
121 | } | 121 | } |
122 | 122 | ||
123 | buttons.push_back( button ); | 123 | buttons.insert( i, button ); |
124 | } | 124 | } |
125 | 125 | ||
126 | setBackgroundPixmap( pixBg ); | 126 | setBackgroundPixmap( pixBg ); |
127 | 127 | ||
128 | songInfo.setFocusPolicy( QWidget::NoFocus ); | 128 | songInfo.setFocusPolicy( QWidget::NoFocus ); |
129 | // changeTextColor( &songInfo ); | 129 | // changeTextColor( &songInfo ); |
130 | // songInfo.setBackgroundColor( QColor( 167, 212, 167 )); | 130 | // songInfo.setBackgroundColor( QColor( 167, 212, 167 )); |
131 | // songInfo.setFrameStyle( QFrame::NoFrame); | 131 | // songInfo.setFrameStyle( QFrame::NoFrame); |
132 | songInfo.setFrameStyle( QFrame::WinPanel | QFrame::Sunken ); | 132 | songInfo.setFrameStyle( QFrame::WinPanel | QFrame::Sunken ); |
133 | // songInfo.setForegroundColor(Qt::white); | 133 | // songInfo.setForegroundColor(Qt::white); |
134 | 134 | ||
135 | slider.setFixedHeight( 20 ); | 135 | slider.setFixedHeight( 20 ); |
136 | slider.setMinValue( 0 ); | 136 | slider.setMinValue( 0 ); |
137 | slider.setMaxValue( 1 ); | 137 | slider.setMaxValue( 1 ); |
138 | slider.setFocusPolicy( QWidget::NoFocus ); | 138 | slider.setFocusPolicy( QWidget::NoFocus ); |
139 | slider.setBackgroundPixmap( pixBg ); | 139 | slider.setBackgroundPixmap( pixBg ); |
140 | 140 | ||
141 | // Config cofg("qpe"); | 141 | // Config cofg("qpe"); |
142 | // cofg.setGroup("Appearance"); | 142 | // cofg.setGroup("Appearance"); |
143 | // QColor backgroundcolor = QColor( cofg.readEntry( "Background", "#E5E1D5" ) ); | 143 | // QColor backgroundcolor = QColor( cofg.readEntry( "Background", "#E5E1D5" ) ); |
144 | 144 | ||
145 | time.setFocusPolicy( QWidget::NoFocus ); | 145 | time.setFocusPolicy( QWidget::NoFocus ); |
146 | time.setAlignment( Qt::AlignCenter ); | 146 | time.setAlignment( Qt::AlignCenter ); |
147 | 147 | ||
148 | // time.setFrame(FALSE); | 148 | // time.setFrame(FALSE); |
149 | // changeTextColor( &time ); | 149 | // changeTextColor( &time ); |
150 | 150 | ||
151 | resizeEvent( NULL ); | 151 | resizeEvent( NULL ); |
152 | 152 | ||
153 | connect( &mediaPlayerState, SIGNAL( loopingToggled(bool) ), this, SLOT( setLooping(bool) ) ); | 153 | connect( &mediaPlayerState, SIGNAL( loopingToggled(bool) ), this, SLOT( setLooping(bool) ) ); |
154 | connect( &mediaPlayerState, SIGNAL( isSeekableToggled( bool ) ), this, SLOT( setSeekable( bool ) ) ); | 154 | connect( &mediaPlayerState, SIGNAL( isSeekableToggled( bool ) ), this, SLOT( setSeekable( bool ) ) ); |
155 | 155 | ||
156 | connect( this, SIGNAL( forwardClicked() ), this, SLOT( skipFor() ) ); | 156 | connect( this, SIGNAL( forwardClicked() ), this, SLOT( skipFor() ) ); |
157 | connect( this, SIGNAL( backClicked() ), this, SLOT( skipBack() ) ); | 157 | connect( this, SIGNAL( backClicked() ), this, SLOT( skipBack() ) ); |
158 | connect( this, SIGNAL( forwardReleased() ), this, SLOT( stopSkip() ) ); | 158 | connect( this, SIGNAL( forwardReleased() ), this, SLOT( stopSkip() ) ); |
159 | connect( this, SIGNAL( backReleased() ), this, SLOT( stopSkip() ) ); | 159 | connect( this, SIGNAL( backReleased() ), this, SLOT( stopSkip() ) ); |
160 | 160 | ||
161 | // Intialise state | 161 | // Intialise state |
162 | setLength( mediaPlayerState.length() ); | 162 | setLength( mediaPlayerState.length() ); |
163 | setPosition( mediaPlayerState.position() ); | 163 | setPosition( mediaPlayerState.position() ); |
164 | setLooping( mediaPlayerState.isFullscreen() ); | 164 | setLooping( mediaPlayerState.isFullscreen() ); |
165 | // setPaused( mediaPlayerState->paused() ); | 165 | // setPaused( mediaPlayerState->paused() ); |
166 | setPlaying( mediaPlayerState.isPlaying() ); | 166 | setPlaying( mediaPlayerState.isPlaying() ); |
167 | 167 | ||
168 | } | 168 | } |
169 | 169 | ||
170 | AudioWidget::~AudioWidget() { | 170 | AudioWidget::~AudioWidget() { |
171 | 171 | ||
172 | // mediaPlayerState->setPlaying(false); | 172 | // mediaPlayerState->setPlaying(false); |
173 | } | 173 | } |
174 | 174 | ||
175 | namespace { | 175 | namespace { |
176 | 176 | ||
177 | QPixmap combineImageWithBackground( QImage img, QPixmap bg, QPoint offset ) { | 177 | QPixmap combineImageWithBackground( QImage img, QPixmap bg, QPoint offset ) { |
178 | QPixmap pix( img.width(), img.height() ); | 178 | QPixmap pix( img.width(), img.height() ); |
179 | QPainter p( &pix ); | 179 | QPainter p( &pix ); |
180 | p.drawTiledPixmap( pix.rect(), bg, offset ); | 180 | p.drawTiledPixmap( pix.rect(), bg, offset ); |
181 | p.drawImage( 0, 0, img ); | 181 | p.drawImage( 0, 0, img ); |
182 | return pix; | 182 | return pix; |
183 | } | 183 | } |
184 | 184 | ||
185 | 185 | ||
186 | QPixmap maskPixToMask( QPixmap pix, QBitmap mask ) { | 186 | QPixmap maskPixToMask( QPixmap pix, QBitmap mask ) { |
187 | QPixmap pixmap( pix ); | 187 | QPixmap pixmap( pix ); |
188 | pixmap.setMask( mask ); | 188 | pixmap.setMask( mask ); |
189 | return pixmap; | 189 | return pixmap; |
190 | } | 190 | } |
191 | 191 | ||
192 | }; | 192 | }; |
193 | 193 | ||
194 | void AudioWidget::resizeEvent( QResizeEvent * ) { | 194 | void AudioWidget::resizeEvent( QResizeEvent * ) { |
195 | int h = height(); | 195 | int h = height(); |
196 | int w = width(); | 196 | int w = width(); |
197 | 197 | ||
198 | songInfo.setGeometry( QRect( 2, 2, w - 4, 20 ) ); | 198 | songInfo.setGeometry( QRect( 2, 2, w - 4, 20 ) ); |
199 | slider.setFixedWidth( w - 110 ); | 199 | slider.setFixedWidth( w - 110 ); |
200 | slider.setGeometry( QRect( 15, h - 22, w - 90, 20 ) ); | 200 | slider.setGeometry( QRect( 15, h - 22, w - 90, 20 ) ); |
201 | slider.setBackgroundOrigin( QWidget::ParentOrigin ); | 201 | slider.setBackgroundOrigin( QWidget::ParentOrigin ); |
202 | time.setGeometry( QRect( w - 85, h - 30, 70, 20 ) ); | 202 | time.setGeometry( QRect( w - 85, h - 30, 70, 20 ) ); |
203 | 203 | ||
204 | upperLeftOfButtonMask.rx() = ( w - imgUp.width() ) / 2; | 204 | upperLeftOfButtonMask.rx() = ( w - imgUp.width() ) / 2; |
205 | upperLeftOfButtonMask.ry() = (( h - imgUp.height() ) / 2) - 10; | 205 | upperLeftOfButtonMask.ry() = (( h - imgUp.height() ) / 2) - 10; |
206 | QPoint p = upperLeftOfButtonMask; | 206 | QPoint p = upperLeftOfButtonMask; |
207 | 207 | ||
208 | QPixmap pixUp = combineImageWithBackground( imgUp, pixBg, p ); | 208 | QPixmap pixUp = combineImageWithBackground( imgUp, pixBg, p ); |
209 | QPixmap pixDn = combineImageWithBackground( imgDn, pixBg, p ); | 209 | QPixmap pixDn = combineImageWithBackground( imgDn, pixBg, p ); |
210 | 210 | ||
211 | for ( uint i = 0; i < buttons.size(); i++ ) { | 211 | for ( uint i = 0; i < buttons.count(); i++ ) { |
212 | if ( !buttons[i].mask.isNull() ) { | 212 | if ( !buttons[i].mask.isNull() ) { |
213 | buttons[i].pixUp = maskPixToMask( pixUp, buttons[i].mask ); | 213 | buttons[i].pixUp = maskPixToMask( pixUp, buttons[i].mask ); |
214 | buttons[i].pixDown = maskPixToMask( pixDn, buttons[i].mask ); | 214 | buttons[i].pixDown = maskPixToMask( pixDn, buttons[i].mask ); |
215 | } | 215 | } |
216 | } | 216 | } |
217 | } | 217 | } |
218 | 218 | ||
219 | void AudioWidget::sliderPressed() { | 219 | void AudioWidget::sliderPressed() { |
220 | audioSliderBeingMoved = TRUE; | 220 | audioSliderBeingMoved = TRUE; |
221 | } | 221 | } |
222 | 222 | ||
223 | 223 | ||
224 | void AudioWidget::sliderReleased() { | 224 | void AudioWidget::sliderReleased() { |
225 | audioSliderBeingMoved = FALSE; | 225 | audioSliderBeingMoved = FALSE; |
226 | if ( slider.width() == 0 ) | 226 | if ( slider.width() == 0 ) |
227 | return; | 227 | return; |
228 | long val = long((double)slider.value() * mediaPlayerState.length() / slider.width()); | 228 | long val = long((double)slider.value() * mediaPlayerState.length() / slider.width()); |
229 | mediaPlayerState.setPosition( val ); | 229 | mediaPlayerState.setPosition( val ); |
230 | } | 230 | } |
231 | 231 | ||
232 | void AudioWidget::setPosition( long i ) { | 232 | void AudioWidget::setPosition( long i ) { |
233 | // qDebug("<<<<<<<<<<<<<<<<<<<<<<<<set position %d",i); | 233 | // qDebug("<<<<<<<<<<<<<<<<<<<<<<<<set position %d",i); |
234 | updateSlider( i, mediaPlayerState.length() ); | 234 | updateSlider( i, mediaPlayerState.length() ); |
235 | } | 235 | } |
236 | 236 | ||
237 | 237 | ||
238 | void AudioWidget::setLength( long max ) { | 238 | void AudioWidget::setLength( long max ) { |
239 | updateSlider( mediaPlayerState.position(), max ); | 239 | updateSlider( mediaPlayerState.position(), max ); |
240 | } | 240 | } |
241 | 241 | ||
242 | 242 | ||
243 | void AudioWidget::setDisplayType( MediaPlayerState::DisplayType mediaType ) { | 243 | void AudioWidget::setDisplayType( MediaPlayerState::DisplayType mediaType ) { |
244 | if ( mediaType == MediaPlayerState::Audio ) { | 244 | if ( mediaType == MediaPlayerState::Audio ) { |
245 | // startTimer( 150 ); | 245 | // startTimer( 150 ); |
246 | showMaximized(); | 246 | showMaximized(); |
247 | return; | 247 | return; |
248 | } | 248 | } |
249 | 249 | ||
250 | killTimers(); | 250 | killTimers(); |
251 | hide(); | 251 | hide(); |
252 | } | 252 | } |
253 | 253 | ||
254 | 254 | ||
255 | void AudioWidget::setSeekable( bool isSeekable ) { | 255 | void AudioWidget::setSeekable( bool isSeekable ) { |
256 | 256 | ||
257 | if ( !isSeekable ) { | 257 | if ( !isSeekable ) { |
258 | qDebug("<<<<<<<<<<<<<<file is STREAMING>>>>>>>>>>>>>>>>>>>"); | 258 | qDebug("<<<<<<<<<<<<<<file is STREAMING>>>>>>>>>>>>>>>>>>>"); |
259 | if( !slider.isHidden()) { | 259 | if( !slider.isHidden()) { |
260 | slider.hide(); | 260 | slider.hide(); |
261 | } | 261 | } |
262 | disconnect( &mediaPlayerState, SIGNAL( positionChanged(long) ),this, SLOT( setPosition(long) ) ); | 262 | disconnect( &mediaPlayerState, SIGNAL( positionChanged(long) ),this, SLOT( setPosition(long) ) ); |
263 | disconnect( &mediaPlayerState, SIGNAL( positionUpdated(long) ),this, SLOT( setPosition(long) ) ); | 263 | disconnect( &mediaPlayerState, SIGNAL( positionUpdated(long) ),this, SLOT( setPosition(long) ) ); |
264 | disconnect( &slider, SIGNAL( sliderPressed() ), this, SLOT( sliderPressed() ) ); | 264 | disconnect( &slider, SIGNAL( sliderPressed() ), this, SLOT( sliderPressed() ) ); |
265 | disconnect( &slider, SIGNAL( sliderReleased() ), this, SLOT( sliderReleased() ) ); | 265 | disconnect( &slider, SIGNAL( sliderReleased() ), this, SLOT( sliderReleased() ) ); |
266 | } else { | 266 | } else { |
267 | // this stops the slider from being moved, thus | 267 | // this stops the slider from being moved, thus |
268 | // does not stop stream when it reaches the end | 268 | // does not stop stream when it reaches the end |
269 | slider.show(); | 269 | slider.show(); |
270 | qDebug( " CONNECT SET POSTION " ); | 270 | qDebug( " CONNECT SET POSTION " ); |
271 | connect( &mediaPlayerState, SIGNAL( positionChanged(long) ),this, SLOT( setPosition(long) ) ); | 271 | connect( &mediaPlayerState, SIGNAL( positionChanged(long) ),this, SLOT( setPosition(long) ) ); |
272 | connect( &mediaPlayerState, SIGNAL( positionUpdated(long) ),this, SLOT( setPosition(long) ) ); | 272 | connect( &mediaPlayerState, SIGNAL( positionUpdated(long) ),this, SLOT( setPosition(long) ) ); |
273 | connect( &slider, SIGNAL( sliderPressed() ), this, SLOT( sliderPressed() ) ); | 273 | connect( &slider, SIGNAL( sliderPressed() ), this, SLOT( sliderPressed() ) ); |
274 | connect( &slider, SIGNAL( sliderReleased() ), this, SLOT( sliderReleased() ) ); | 274 | connect( &slider, SIGNAL( sliderReleased() ), this, SLOT( sliderReleased() ) ); |
275 | } | 275 | } |
276 | } | 276 | } |
277 | 277 | ||
278 | 278 | ||
279 | static QString timeAsString( long length ) { | 279 | static QString timeAsString( long length ) { |
280 | int minutes = length / 60; | 280 | int minutes = length / 60; |
281 | int seconds = length % 60; | 281 | int seconds = length % 60; |
282 | return QString("%1:%2%3").arg( minutes ).arg( seconds / 10 ).arg( seconds % 10 ); | 282 | return QString("%1:%2%3").arg( minutes ).arg( seconds / 10 ).arg( seconds % 10 ); |
283 | } | 283 | } |
284 | 284 | ||
285 | void AudioWidget::updateSlider( long i, long max ) { | 285 | void AudioWidget::updateSlider( long i, long max ) { |
286 | 286 | ||
287 | time.setText( timeAsString( i ) + " / " + timeAsString( max ) ); | 287 | time.setText( timeAsString( i ) + " / " + timeAsString( max ) ); |
288 | // qDebug( timeAsString( i ) + " / " + timeAsString( max ) ) ; | 288 | // qDebug( timeAsString( i ) + " / " + timeAsString( max ) ) ; |
289 | 289 | ||
290 | if ( max == 0 ) { | 290 | if ( max == 0 ) { |
291 | return; | 291 | return; |
292 | } | 292 | } |
293 | // Will flicker too much if we don't do this | 293 | // Will flicker too much if we don't do this |
294 | // Scale to something reasonable | 294 | // Scale to something reasonable |
295 | int width = slider.width(); | 295 | int width = slider.width(); |
296 | int val = int((double)i * width / max); | 296 | int val = int((double)i * width / max); |
297 | if ( !audioSliderBeingMoved ) { | 297 | if ( !audioSliderBeingMoved ) { |
298 | if ( slider.value() != val ) { | 298 | if ( slider.value() != val ) { |
299 | slider.setValue( val ); | 299 | slider.setValue( val ); |
300 | } | 300 | } |
301 | 301 | ||
302 | if ( slider.maxValue() != width ) { | 302 | if ( slider.maxValue() != width ) { |
303 | slider.setMaxValue( width ); | 303 | slider.setMaxValue( width ); |
304 | } | 304 | } |
305 | } | 305 | } |
306 | } | 306 | } |
307 | 307 | ||
308 | 308 | ||
309 | void AudioWidget::setToggleButton( int i, bool down ) { | 309 | void AudioWidget::setToggleButton( int i, bool down ) { |
310 | qDebug("setToggleButton %d", i); | 310 | qDebug("setToggleButton %d", i); |
311 | if ( down != buttons[i].isDown ) { | 311 | if ( down != buttons[i].isDown ) { |
312 | toggleButton( i ); | 312 | toggleButton( i ); |
313 | } | 313 | } |
314 | } | 314 | } |
315 | 315 | ||
316 | void AudioWidget::paintButton( QPainter &p, int i ) { | 316 | void AudioWidget::paintButton( QPainter &p, int i ) { |
317 | if ( buttons[i].isDown ) { | 317 | if ( buttons[i].isDown ) { |
318 | p.drawPixmap( upperLeftOfButtonMask, buttons[i].pixDown ); | 318 | p.drawPixmap( upperLeftOfButtonMask, buttons[i].pixDown ); |
319 | } else { | 319 | } else { |
320 | p.drawPixmap( upperLeftOfButtonMask, buttons[i].pixUp ); | 320 | p.drawPixmap( upperLeftOfButtonMask, buttons[i].pixUp ); |
321 | } | 321 | } |
322 | } | 322 | } |
323 | 323 | ||
324 | 324 | ||
325 | void AudioWidget::skipFor() { | 325 | void AudioWidget::skipFor() { |
326 | skipDirection = +1; | 326 | skipDirection = +1; |
327 | startTimer( 50 ); | 327 | startTimer( 50 ); |
328 | mediaPlayerState.setPosition( mediaPlayerState.position() + 2 ); | 328 | mediaPlayerState.setPosition( mediaPlayerState.position() + 2 ); |
329 | } | 329 | } |
330 | 330 | ||
331 | void AudioWidget::skipBack() { | 331 | void AudioWidget::skipBack() { |
332 | skipDirection = -1; | 332 | skipDirection = -1; |
333 | startTimer( 50 ); | 333 | startTimer( 50 ); |
334 | mediaPlayerState.setPosition( mediaPlayerState.position() - 2 ); | 334 | mediaPlayerState.setPosition( mediaPlayerState.position() - 2 ); |
335 | } | 335 | } |
336 | 336 | ||
337 | 337 | ||
338 | 338 | ||
339 | void AudioWidget::stopSkip() { | 339 | void AudioWidget::stopSkip() { |
340 | killTimers(); | 340 | killTimers(); |
341 | } | 341 | } |
342 | 342 | ||
343 | 343 | ||
344 | void AudioWidget::timerEvent( QTimerEvent * ) { | 344 | void AudioWidget::timerEvent( QTimerEvent * ) { |
345 | if ( skipDirection == +1 ) { | 345 | if ( skipDirection == +1 ) { |
346 | mediaPlayerState.setPosition( mediaPlayerState.position() + 2 ); | 346 | mediaPlayerState.setPosition( mediaPlayerState.position() + 2 ); |
347 | } else if ( skipDirection == -1 ) { | 347 | } else if ( skipDirection == -1 ) { |
348 | mediaPlayerState.setPosition( mediaPlayerState.position() - 2 ); | 348 | mediaPlayerState.setPosition( mediaPlayerState.position() - 2 ); |
349 | } | 349 | } |
350 | } | 350 | } |
351 | 351 | ||
352 | 352 | ||
353 | void AudioWidget::mouseMoveEvent( QMouseEvent *event ) { | 353 | void AudioWidget::mouseMoveEvent( QMouseEvent *event ) { |
354 | for ( unsigned int i = 0; i < buttons.size(); i++ ) { | 354 | for ( unsigned int i = 0; i < buttons.count(); i++ ) { |
355 | if ( event->state() == QMouseEvent::LeftButton ) { | 355 | if ( event->state() == QMouseEvent::LeftButton ) { |
356 | // The test to see if the mouse click is inside the button or not | 356 | // The test to see if the mouse click is inside the button or not |
357 | bool isOnButton = isOverButton( event->pos() - upperLeftOfButtonMask, i ); | 357 | bool isOnButton = isOverButton( event->pos() - upperLeftOfButtonMask, i ); |
358 | 358 | ||
359 | if ( isOnButton && !buttons[i].isHeld ) { | 359 | if ( isOnButton && !buttons[i].isHeld ) { |
360 | buttons[i].isHeld = TRUE; | 360 | buttons[i].isHeld = TRUE; |
361 | toggleButton(i); | 361 | toggleButton(i); |
362 | switch (i) { | 362 | switch (i) { |
363 | case VolumeUp: | 363 | case VolumeUp: |
364 | emit moreClicked(); | 364 | emit moreClicked(); |
365 | return; | 365 | return; |
366 | case VolumeDown: | 366 | case VolumeDown: |
367 | emit lessClicked(); | 367 | emit lessClicked(); |
368 | return; | 368 | return; |
369 | case Forward: | 369 | case Forward: |
370 | emit forwardClicked(); | 370 | emit forwardClicked(); |
371 | return; | 371 | return; |
372 | case Back: | 372 | case Back: |
373 | emit backClicked(); | 373 | emit backClicked(); |
374 | return; | 374 | return; |
375 | } | 375 | } |
376 | } else if ( !isOnButton && buttons[i].isHeld ) { | 376 | } else if ( !isOnButton && buttons[i].isHeld ) { |
377 | buttons[i].isHeld = FALSE; | 377 | buttons[i].isHeld = FALSE; |
378 | toggleButton(i); | 378 | toggleButton(i); |
379 | } | 379 | } |
380 | } else { | 380 | } else { |
381 | if ( buttons[i].isHeld ) { | 381 | if ( buttons[i].isHeld ) { |
382 | buttons[i].isHeld = FALSE; | 382 | buttons[i].isHeld = FALSE; |
383 | if ( buttons[i].type != ToggleButton ) { | 383 | if ( buttons[i].type != ToggleButton ) { |
384 | setToggleButton( i, FALSE ); | 384 | setToggleButton( i, FALSE ); |
385 | } | 385 | } |
386 | qDebug("mouseEvent %d", i); | 386 | qDebug("mouseEvent %d", i); |
387 | handleCommand( static_cast<Command>( i ), buttons[ i ].isDown ); | 387 | handleCommand( static_cast<Command>( i ), buttons[ i ].isDown ); |
388 | } | 388 | } |
389 | } | 389 | } |
390 | } | 390 | } |
391 | } | 391 | } |
392 | 392 | ||
393 | 393 | ||
394 | void AudioWidget::mousePressEvent( QMouseEvent *event ) { | 394 | void AudioWidget::mousePressEvent( QMouseEvent *event ) { |
395 | mouseMoveEvent( event ); | 395 | mouseMoveEvent( event ); |
396 | } | 396 | } |
397 | 397 | ||
398 | 398 | ||
399 | void AudioWidget::mouseReleaseEvent( QMouseEvent *event ) { | 399 | void AudioWidget::mouseReleaseEvent( QMouseEvent *event ) { |
400 | mouseMoveEvent( event ); | 400 | mouseMoveEvent( event ); |
401 | } | 401 | } |
402 | 402 | ||
403 | 403 | ||
404 | void AudioWidget::showEvent( QShowEvent* ) { | 404 | void AudioWidget::showEvent( QShowEvent* ) { |
405 | QMouseEvent event( QEvent::MouseMove, QPoint( 0, 0 ), 0, 0 ); | 405 | QMouseEvent event( QEvent::MouseMove, QPoint( 0, 0 ), 0, 0 ); |
406 | mouseMoveEvent( &event ); | 406 | mouseMoveEvent( &event ); |
407 | } | 407 | } |
408 | 408 | ||
409 | 409 | ||
410 | void AudioWidget::paintEvent( QPaintEvent * pe ) { | 410 | void AudioWidget::paintEvent( QPaintEvent * pe ) { |
411 | if ( !pe->erased() ) { | 411 | if ( !pe->erased() ) { |
412 | // Combine with background and double buffer | 412 | // Combine with background and double buffer |
413 | QPixmap pix( pe->rect().size() ); | 413 | QPixmap pix( pe->rect().size() ); |
414 | QPainter p( &pix ); | 414 | QPainter p( &pix ); |
415 | p.translate( -pe->rect().topLeft().x(), -pe->rect().topLeft().y() ); | 415 | p.translate( -pe->rect().topLeft().x(), -pe->rect().topLeft().y() ); |
416 | p.drawTiledPixmap( pe->rect(), pixBg, pe->rect().topLeft() ); | 416 | p.drawTiledPixmap( pe->rect(), pixBg, pe->rect().topLeft() ); |
417 | for ( unsigned int i = 0; i < buttons.size(); i++ ) | 417 | for ( unsigned int i = 0; i < buttons.count(); i++ ) |
418 | paintButton( p, i ); | 418 | paintButton( p, i ); |
419 | QPainter p2( this ); | 419 | QPainter p2( this ); |
420 | p2.drawPixmap( pe->rect().topLeft(), pix ); | 420 | p2.drawPixmap( pe->rect().topLeft(), pix ); |
421 | } else { | 421 | } else { |
422 | QPainter p( this ); | 422 | QPainter p( this ); |
423 | for ( unsigned int i = 0; i < buttons.size(); i++ ) | 423 | for ( unsigned int i = 0; i < buttons.count(); i++ ) |
424 | paintButton( p, i ); | 424 | paintButton( p, i ); |
425 | } | 425 | } |
426 | } | 426 | } |
427 | 427 | ||
428 | void AudioWidget::keyReleaseEvent( QKeyEvent *e) { | 428 | void AudioWidget::keyReleaseEvent( QKeyEvent *e) { |
429 | switch ( e->key() ) { | 429 | switch ( e->key() ) { |
430 | ////////////////////////////// Zaurus keys | 430 | ////////////////////////////// Zaurus keys |
431 | case Key_Home: | 431 | case Key_Home: |
432 | break; | 432 | break; |
433 | case Key_F9: //activity | 433 | case Key_F9: //activity |
434 | hide(); | 434 | hide(); |
435 | // qDebug("Audio F9"); | 435 | // qDebug("Audio F9"); |
436 | break; | 436 | break; |
437 | case Key_F10: //contacts | 437 | case Key_F10: //contacts |
438 | break; | 438 | break; |
439 | case Key_F11: //menu | 439 | case Key_F11: //menu |
440 | mediaPlayerState.toggleBlank(); | 440 | mediaPlayerState.toggleBlank(); |
441 | break; | 441 | break; |
442 | case Key_F12: //home | 442 | case Key_F12: //home |
443 | break; | 443 | break; |
444 | case Key_F13: //mail | 444 | case Key_F13: //mail |
445 | mediaPlayerState.toggleBlank(); | 445 | mediaPlayerState.toggleBlank(); |
446 | break; | 446 | break; |
447 | case Key_Space: { | 447 | case Key_Space: { |
448 | mediaPlayerState.togglePaused(); | 448 | mediaPlayerState.togglePaused(); |
449 | } | 449 | } |
450 | break; | 450 | break; |
451 | case Key_Down: | 451 | case Key_Down: |
452 | // toggleButton(6); | 452 | // toggleButton(6); |
453 | emit lessClicked(); | 453 | emit lessClicked(); |
454 | emit lessReleased(); | 454 | emit lessReleased(); |
455 | // toggleButton(6); | 455 | // toggleButton(6); |
456 | break; | 456 | break; |
457 | case Key_Up: | 457 | case Key_Up: |
458 | // toggleButton(5); | 458 | // toggleButton(5); |
459 | emit moreClicked(); | 459 | emit moreClicked(); |
460 | emit moreReleased(); | 460 | emit moreReleased(); |
461 | // toggleButton(5); | 461 | // toggleButton(5); |
462 | break; | 462 | break; |
463 | case Key_Right: | 463 | case Key_Right: |
464 | // toggleButton(3); | 464 | // toggleButton(3); |
465 | mediaPlayerState.setNext(); | 465 | mediaPlayerState.setNext(); |
466 | // toggleButton(3); | 466 | // toggleButton(3); |
467 | break; | 467 | break; |
468 | case Key_Left: | 468 | case Key_Left: |
469 | // toggleButton(4); | 469 | // toggleButton(4); |
470 | mediaPlayerState.setPrev(); | 470 | mediaPlayerState.setPrev(); |
471 | // toggleButton(4); | 471 | // toggleButton(4); |
472 | break; | 472 | break; |
473 | case Key_Escape: { | 473 | case Key_Escape: { |
474 | } | 474 | } |
475 | break; | 475 | break; |
476 | 476 | ||
477 | }; | 477 | }; |
478 | } | 478 | } |
diff --git a/noncore/multimedia/opieplayer2/mediawidget.h b/noncore/multimedia/opieplayer2/mediawidget.h index 504b705..49bf024 100644 --- a/noncore/multimedia/opieplayer2/mediawidget.h +++ b/noncore/multimedia/opieplayer2/mediawidget.h | |||
@@ -1,103 +1,105 @@ | |||
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 | 33 | ||
34 | class MediaWidget : public QWidget | 34 | class MediaWidget : public QWidget |
35 | { | 35 | { |
36 | Q_OBJECT | 36 | Q_OBJECT |
37 | public: | 37 | public: |
38 | 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 }; |
39 | enum ButtonType { NormalButton, ToggleButton }; | 39 | enum ButtonType { NormalButton, ToggleButton }; |
40 | 40 | ||
41 | struct Button | 41 | struct Button |
42 | { | 42 | { |
43 | Button() : type( NormalButton ), isHeld( false ), isDown( false ) {} | 43 | Button() : type( NormalButton ), isHeld( false ), isDown( false ) {} |
44 | 44 | ||
45 | ButtonType type : 1; | 45 | ButtonType type : 1; |
46 | bool isHeld : 1; | 46 | bool isHeld : 1; |
47 | bool isDown : 1; | 47 | bool isDown : 1; |
48 | 48 | ||
49 | QBitmap mask; | 49 | QBitmap mask; |
50 | QPixmap pixUp; | 50 | QPixmap pixUp; |
51 | QPixmap pixDown; | 51 | QPixmap pixDown; |
52 | }; | 52 | }; |
53 | typedef std::vector<Button> ButtonVector; | 53 | typedef std::vector<Button> ButtonVector; |
54 | // when the transition is done this should be Command -> Button | ||
55 | typedef QMap<int, Button> ButtonMap; | ||
54 | 56 | ||
55 | struct SkinButtonInfo | 57 | struct SkinButtonInfo |
56 | { | 58 | { |
57 | Command command; | 59 | Command command; |
58 | const char *fileName; | 60 | const char *fileName; |
59 | ButtonType type; | 61 | ButtonType type; |
60 | }; | 62 | }; |
61 | 63 | ||
62 | typedef std::vector<QBitmap> MaskVector; | 64 | typedef std::vector<QBitmap> MaskVector; |
63 | typedef std::vector<QPixmap> PixmapVector; | 65 | typedef std::vector<QPixmap> PixmapVector; |
64 | 66 | ||
65 | MediaWidget( PlayListWidget &_playList, MediaPlayerState &_mediaPlayerState, QWidget *parent = 0, const char *name = 0 ); | 67 | MediaWidget( PlayListWidget &_playList, MediaPlayerState &_mediaPlayerState, QWidget *parent = 0, const char *name = 0 ); |
66 | virtual ~MediaWidget(); | 68 | virtual ~MediaWidget(); |
67 | 69 | ||
68 | public slots: | 70 | public slots: |
69 | virtual void setDisplayType( MediaPlayerState::DisplayType displayType ) = 0; | 71 | virtual void setDisplayType( MediaPlayerState::DisplayType displayType ) = 0; |
70 | virtual void setLength( long length ) = 0; | 72 | virtual void setLength( long length ) = 0; |
71 | virtual void setPlaying( bool playing ) = 0; | 73 | virtual void setPlaying( bool playing ) = 0; |
72 | 74 | ||
73 | signals: | 75 | signals: |
74 | void moreReleased(); | 76 | void moreReleased(); |
75 | void lessReleased(); | 77 | void lessReleased(); |
76 | void forwardReleased(); | 78 | void forwardReleased(); |
77 | void backReleased(); | 79 | void backReleased(); |
78 | 80 | ||
79 | protected: | 81 | protected: |
80 | virtual void closeEvent( QCloseEvent * ); | 82 | virtual void closeEvent( QCloseEvent * ); |
81 | 83 | ||
82 | void handleCommand( Command command, bool buttonDown ); | 84 | void handleCommand( Command command, bool buttonDown ); |
83 | 85 | ||
84 | bool isOverButton( const QPoint &position, int buttonId ) const; | 86 | bool isOverButton( const QPoint &position, int buttonId ) const; |
85 | 87 | ||
86 | void paintButton( int buttonId ); | 88 | void paintButton( int buttonId ); |
87 | virtual void paintButton( QPainter &p, int i ) = 0; | 89 | virtual void paintButton( QPainter &p, int i ) = 0; |
88 | 90 | ||
89 | void toggleButton( int buttonId ); | 91 | void toggleButton( int buttonId ); |
90 | 92 | ||
91 | MediaPlayerState &mediaPlayerState; | 93 | MediaPlayerState &mediaPlayerState; |
92 | PlayListWidget &playList; | 94 | PlayListWidget &playList; |
93 | 95 | ||
94 | ButtonVector buttons; | 96 | ButtonMap buttons; |
95 | 97 | ||
96 | QImage buttonMask; | 98 | QImage buttonMask; |
97 | 99 | ||
98 | QPoint upperLeftOfButtonMask; | 100 | QPoint upperLeftOfButtonMask; |
99 | }; | 101 | }; |
100 | 102 | ||
101 | #endif // MEDIAWIDGET_H | 103 | #endif // MEDIAWIDGET_H |
102 | /* vim: et sw=4 ts=4 | 104 | /* vim: et sw=4 ts=4 |
103 | */ | 105 | */ |
diff --git a/noncore/multimedia/opieplayer2/videowidget.cpp b/noncore/multimedia/opieplayer2/videowidget.cpp index 380c703..7d85d63 100644 --- a/noncore/multimedia/opieplayer2/videowidget.cpp +++ b/noncore/multimedia/opieplayer2/videowidget.cpp | |||
@@ -1,492 +1,491 @@ | |||
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 char * const skinV_mask_file_names[7] = { | 62 | const char * const skinV_mask_file_names[7] = { |
63 | "play","stop","fwd","back","up","down","full" | 63 | "play","stop","fwd","back","up","down","full" |
64 | }; | 64 | }; |
65 | 65 | ||
66 | } | 66 | } |
67 | 67 | ||
68 | VideoWidget::VideoWidget( PlayListWidget &playList, MediaPlayerState &mediaPlayerState, QWidget* parent, const char* name ) | 68 | VideoWidget::VideoWidget( PlayListWidget &playList, MediaPlayerState &mediaPlayerState, QWidget* parent, const char* name ) |
69 | : MediaWidget( playList, mediaPlayerState, parent, name ), scaledWidth( 0 ), scaledHeight( 0 ) | 69 | : MediaWidget( playList, mediaPlayerState, parent, name ), scaledWidth( 0 ), scaledHeight( 0 ) |
70 | { | 70 | { |
71 | setCaption( tr("OpiePlayer - Video") ); | 71 | setCaption( tr("OpiePlayer - Video") ); |
72 | 72 | ||
73 | Button defaultButton; | 73 | Button defaultButton; |
74 | Button toggleButton = defaultButton; | 74 | Button toggleButton = defaultButton; |
75 | toggleButton.type = ToggleButton; | 75 | toggleButton.type = ToggleButton; |
76 | 76 | ||
77 | buttons.reserve( 7 ); | 77 | buttons.insert( 0, toggleButton ); // play |
78 | buttons.push_back( toggleButton ); // play | 78 | buttons.insert( 1, toggleButton ); // stop |
79 | buttons.push_back( defaultButton ); // stop | 79 | buttons.insert( 2, toggleButton ); // next |
80 | buttons.push_back( defaultButton ); // next | 80 | buttons.insert( 3, toggleButton ); // previous |
81 | buttons.push_back( defaultButton ); // previous | 81 | buttons.insert( 4, toggleButton ); // volUp |
82 | buttons.push_back( defaultButton ); // volUp | 82 | buttons.insert( 5, toggleButton ); // volDown |
83 | buttons.push_back( defaultButton ); // volDown | 83 | buttons.insert( 6, toggleButton ); // fullscreen |
84 | buttons.push_back( toggleButton ); //fullscreen | ||
85 | 84 | ||
86 | videoFrame = new XineVideoWidget ( this, "Video frame" ); | 85 | videoFrame = new XineVideoWidget ( this, "Video frame" ); |
87 | 86 | ||
88 | connect ( videoFrame, SIGNAL( videoResized ( const QSize & )), this, SIGNAL( videoResized ( const QSize & ))); | 87 | connect ( videoFrame, SIGNAL( videoResized ( const QSize & )), this, SIGNAL( videoResized ( const QSize & ))); |
89 | connect ( videoFrame, SIGNAL( clicked () ), this, SLOT ( backToNormal() ) ); | 88 | connect ( videoFrame, SIGNAL( clicked () ), this, SLOT ( backToNormal() ) ); |
90 | 89 | ||
91 | Config cfg("OpiePlayer"); | 90 | Config cfg("OpiePlayer"); |
92 | cfg.setGroup("Options"); | 91 | cfg.setGroup("Options"); |
93 | skin = cfg.readEntry("Skin","default"); | 92 | skin = cfg.readEntry("Skin","default"); |
94 | 93 | ||
95 | QString skinPath = "opieplayer2/skins/" + skin; | 94 | QString skinPath = "opieplayer2/skins/" + skin; |
96 | pixBg = QPixmap( Resource::loadPixmap( QString("%1/background").arg(skinPath) ) ); | 95 | pixBg = QPixmap( Resource::loadPixmap( QString("%1/background").arg(skinPath) ) ); |
97 | imgUp = QImage( Resource::loadImage( QString("%1/skinV_up").arg(skinPath) ) ); | 96 | imgUp = QImage( Resource::loadImage( QString("%1/skinV_up").arg(skinPath) ) ); |
98 | imgDn = QImage( Resource::loadImage( QString("%1/skinV_down").arg(skinPath) ) ); | 97 | imgDn = QImage( Resource::loadImage( QString("%1/skinV_down").arg(skinPath) ) ); |
99 | 98 | ||
100 | buttonMask = QImage( imgUp.width(), imgUp.height(), 8, 255 ); | 99 | buttonMask = QImage( imgUp.width(), imgUp.height(), 8, 255 ); |
101 | buttonMask.fill( 0 ); | 100 | buttonMask.fill( 0 ); |
102 | 101 | ||
103 | for ( int i = 0; i < 7; i++ ) { | 102 | for ( int i = 0; i < 7; i++ ) { |
104 | QString filename = QString( QPEApplication::qpeDir() + "/pics/" + skinPath + "/skinV_mask_" + skinV_mask_file_names[i] + ".png" ); | 103 | QString filename = QString( QPEApplication::qpeDir() + "/pics/" + skinPath + "/skinV_mask_" + skinV_mask_file_names[i] + ".png" ); |
105 | masks[i] = new QBitmap( filename ); | 104 | masks[i] = new QBitmap( filename ); |
106 | 105 | ||
107 | if ( !masks[i]->isNull() ) { | 106 | if ( !masks[i]->isNull() ) { |
108 | QImage imgMask = masks[i]->convertToImage(); | 107 | QImage imgMask = masks[i]->convertToImage(); |
109 | uchar **dest = buttonMask.jumpTable(); | 108 | uchar **dest = buttonMask.jumpTable(); |
110 | for ( int y = 0; y < imgUp.height(); y++ ) { | 109 | for ( int y = 0; y < imgUp.height(); y++ ) { |
111 | uchar *line = dest[y]; | 110 | uchar *line = dest[y]; |
112 | for ( int x = 0; x < imgUp.width(); x++ ) { | 111 | for ( int x = 0; x < imgUp.width(); x++ ) { |
113 | if ( !qRed( imgMask.pixel( x, y ) ) ) | 112 | if ( !qRed( imgMask.pixel( x, y ) ) ) |
114 | line[x] = i + 1; | 113 | line[x] = i + 1; |
115 | } | 114 | } |
116 | } | 115 | } |
117 | } | 116 | } |
118 | } | 117 | } |
119 | 118 | ||
120 | for ( int i = 0; i < 7; i++ ) { | 119 | for ( int i = 0; i < 7; i++ ) { |
121 | buttonPixUp[i] = NULL; | 120 | buttonPixUp[i] = NULL; |
122 | buttonPixDown[i] = NULL; | 121 | buttonPixDown[i] = NULL; |
123 | } | 122 | } |
124 | 123 | ||
125 | setBackgroundPixmap( pixBg ); | 124 | setBackgroundPixmap( pixBg ); |
126 | 125 | ||
127 | slider = new QSlider( Qt::Horizontal, this ); | 126 | slider = new QSlider( Qt::Horizontal, this ); |
128 | slider->setMinValue( 0 ); | 127 | slider->setMinValue( 0 ); |
129 | slider->setMaxValue( 1 ); | 128 | slider->setMaxValue( 1 ); |
130 | slider->setBackgroundPixmap( Resource::loadPixmap( backgroundPix ) ); | 129 | slider->setBackgroundPixmap( Resource::loadPixmap( backgroundPix ) ); |
131 | //slider->setFocusPolicy( QWidget::NoFocus ); | 130 | //slider->setFocusPolicy( QWidget::NoFocus ); |
132 | 131 | ||
133 | resizeEvent( NULL ); | 132 | resizeEvent( NULL ); |
134 | 133 | ||
135 | setLength( mediaPlayerState.length() ); | 134 | setLength( mediaPlayerState.length() ); |
136 | setPosition( mediaPlayerState.position() ); | 135 | setPosition( mediaPlayerState.position() ); |
137 | setFullscreen( mediaPlayerState.isFullscreen() ); | 136 | setFullscreen( mediaPlayerState.isFullscreen() ); |
138 | setPlaying( mediaPlayerState.isPlaying() ); | 137 | setPlaying( mediaPlayerState.isPlaying() ); |
139 | } | 138 | } |
140 | 139 | ||
141 | 140 | ||
142 | VideoWidget::~VideoWidget() { | 141 | VideoWidget::~VideoWidget() { |
143 | 142 | ||
144 | for ( int i = 0; i < 7; i++ ) { | 143 | for ( int i = 0; i < 7; i++ ) { |
145 | delete buttonPixUp[i]; | 144 | delete buttonPixUp[i]; |
146 | delete buttonPixDown[i]; | 145 | delete buttonPixDown[i]; |
147 | } | 146 | } |
148 | 147 | ||
149 | for ( int i = 0; i < 7; i++ ) { | 148 | for ( int i = 0; i < 7; i++ ) { |
150 | delete masks[i]; | 149 | delete masks[i]; |
151 | } | 150 | } |
152 | 151 | ||
153 | } | 152 | } |
154 | 153 | ||
155 | QPixmap *combineVImageWithBackground( QImage img, QPixmap bg, QPoint offset ) { | 154 | QPixmap *combineVImageWithBackground( QImage img, QPixmap bg, QPoint offset ) { |
156 | QPixmap pix( img.width(), img.height() ); | 155 | QPixmap pix( img.width(), img.height() ); |
157 | QPainter p( &pix ); | 156 | QPainter p( &pix ); |
158 | p.drawTiledPixmap( pix.rect(), bg, offset ); | 157 | p.drawTiledPixmap( pix.rect(), bg, offset ); |
159 | p.drawImage( 0, 0, img ); | 158 | p.drawImage( 0, 0, img ); |
160 | return new QPixmap( pix ); | 159 | return new QPixmap( pix ); |
161 | } | 160 | } |
162 | 161 | ||
163 | QPixmap *maskVPixToMask( QPixmap pix, QBitmap mask ) { | 162 | QPixmap *maskVPixToMask( QPixmap pix, QBitmap mask ) { |
164 | QPixmap *pixmap = new QPixmap( pix ); | 163 | QPixmap *pixmap = new QPixmap( pix ); |
165 | pixmap->setMask( mask ); | 164 | pixmap->setMask( mask ); |
166 | return pixmap; | 165 | return pixmap; |
167 | } | 166 | } |
168 | 167 | ||
169 | void VideoWidget::resizeEvent( QResizeEvent * ) { | 168 | void VideoWidget::resizeEvent( QResizeEvent * ) { |
170 | int h = height(); | 169 | int h = height(); |
171 | int w = width(); | 170 | int w = width(); |
172 | //int Vh = 160; | 171 | //int Vh = 160; |
173 | //int Vw = 220; | 172 | //int Vw = 220; |
174 | 173 | ||
175 | slider->setFixedWidth( w - 20 ); | 174 | slider->setFixedWidth( w - 20 ); |
176 | slider->setGeometry( QRect( 15, h - 22, w - 90, 20 ) ); | 175 | slider->setGeometry( QRect( 15, h - 22, w - 90, 20 ) ); |
177 | slider->setBackgroundOrigin( QWidget::ParentOrigin ); | 176 | slider->setBackgroundOrigin( QWidget::ParentOrigin ); |
178 | slider->setFocusPolicy( QWidget::NoFocus ); | 177 | slider->setFocusPolicy( QWidget::NoFocus ); |
179 | slider->setBackgroundPixmap( pixBg ); | 178 | slider->setBackgroundPixmap( pixBg ); |
180 | 179 | ||
181 | upperLeftOfButtonMask.rx() = 0;// ( imgUp->width() ) / 2; | 180 | upperLeftOfButtonMask.rx() = 0;// ( imgUp->width() ) / 2; |
182 | if(w>h) | 181 | if(w>h) |
183 | upperLeftOfButtonMask.ry() = 0; | 182 | upperLeftOfButtonMask.ry() = 0; |
184 | else | 183 | else |
185 | upperLeftOfButtonMask.ry() = 185;//(( Vh - imgUp->height() ) / 2) - 10; | 184 | upperLeftOfButtonMask.ry() = 185;//(( Vh - imgUp->height() ) / 2) - 10; |
186 | QPoint p = upperLeftOfButtonMask; | 185 | QPoint p = upperLeftOfButtonMask; |
187 | 186 | ||
188 | QPixmap *pixUp = combineVImageWithBackground( imgUp, pixBg, p ); | 187 | QPixmap *pixUp = combineVImageWithBackground( imgUp, pixBg, p ); |
189 | QPixmap *pixDn = combineVImageWithBackground( imgDn, pixBg, p ); | 188 | QPixmap *pixDn = combineVImageWithBackground( imgDn, pixBg, p ); |
190 | 189 | ||
191 | for ( int i = 0; i < 7; i++ ) { | 190 | for ( int i = 0; i < 7; i++ ) { |
192 | if ( !masks[i]->isNull() ) { | 191 | if ( !masks[i]->isNull() ) { |
193 | delete buttonPixUp[i]; | 192 | delete buttonPixUp[i]; |
194 | delete buttonPixDown[i]; | 193 | delete buttonPixDown[i]; |
195 | buttonPixUp[i] = maskVPixToMask( *pixUp, *masks[i] ); | 194 | buttonPixUp[i] = maskVPixToMask( *pixUp, *masks[i] ); |
196 | buttonPixDown[i] = maskVPixToMask( *pixDn, *masks[i] ); | 195 | buttonPixDown[i] = maskVPixToMask( *pixDn, *masks[i] ); |
197 | } | 196 | } |
198 | } | 197 | } |
199 | 198 | ||
200 | delete pixUp; | 199 | delete pixUp; |
201 | delete pixDn; | 200 | delete pixDn; |
202 | } | 201 | } |
203 | 202 | ||
204 | static bool videoSliderBeingMoved = FALSE; | 203 | static bool videoSliderBeingMoved = FALSE; |
205 | 204 | ||
206 | void VideoWidget::sliderPressed() { | 205 | void VideoWidget::sliderPressed() { |
207 | videoSliderBeingMoved = TRUE; | 206 | videoSliderBeingMoved = TRUE; |
208 | } | 207 | } |
209 | 208 | ||
210 | void VideoWidget::sliderReleased() { | 209 | void VideoWidget::sliderReleased() { |
211 | videoSliderBeingMoved = FALSE; | 210 | videoSliderBeingMoved = FALSE; |
212 | if ( slider->width() == 0 ) { | 211 | if ( slider->width() == 0 ) { |
213 | return; | 212 | return; |
214 | } | 213 | } |
215 | long val = long((double)slider->value() * mediaPlayerState.length() / slider->width()); | 214 | long val = long((double)slider->value() * mediaPlayerState.length() / slider->width()); |
216 | mediaPlayerState.setPosition( val ); | 215 | mediaPlayerState.setPosition( val ); |
217 | } | 216 | } |
218 | 217 | ||
219 | void VideoWidget::setPosition( long i ) { | 218 | void VideoWidget::setPosition( long i ) { |
220 | updateSlider( i, mediaPlayerState.length() ); | 219 | updateSlider( i, mediaPlayerState.length() ); |
221 | } | 220 | } |
222 | 221 | ||
223 | 222 | ||
224 | void VideoWidget::setLength( long max ) { | 223 | void VideoWidget::setLength( long max ) { |
225 | updateSlider( mediaPlayerState.position(), max ); | 224 | updateSlider( mediaPlayerState.position(), max ); |
226 | } | 225 | } |
227 | 226 | ||
228 | void VideoWidget::setDisplayType( MediaPlayerState::DisplayType displayType ) | 227 | void VideoWidget::setDisplayType( MediaPlayerState::DisplayType displayType ) |
229 | { | 228 | { |
230 | if ( displayType == MediaPlayerState::Video ) { | 229 | if ( displayType == MediaPlayerState::Video ) { |
231 | makeVisible(); | 230 | makeVisible(); |
232 | return; | 231 | return; |
233 | } | 232 | } |
234 | 233 | ||
235 | // Effectively blank the view next time we show it so it looks nicer | 234 | // Effectively blank the view next time we show it so it looks nicer |
236 | scaledWidth = 0; | 235 | scaledWidth = 0; |
237 | scaledHeight = 0; | 236 | scaledHeight = 0; |
238 | hide(); | 237 | hide(); |
239 | } | 238 | } |
240 | 239 | ||
241 | void VideoWidget::updateSlider( long i, long max ) { | 240 | void VideoWidget::updateSlider( long i, long max ) { |
242 | // Will flicker too much if we don't do this | 241 | // Will flicker too much if we don't do this |
243 | if ( max == 0 ) { | 242 | if ( max == 0 ) { |
244 | return; | 243 | return; |
245 | } | 244 | } |
246 | int width = slider->width(); | 245 | int width = slider->width(); |
247 | int val = int((double)i * width / max); | 246 | int val = int((double)i * width / max); |
248 | if ( !mediaPlayerState.isFullscreen() && !videoSliderBeingMoved ) { | 247 | if ( !mediaPlayerState.isFullscreen() && !videoSliderBeingMoved ) { |
249 | if ( slider->value() != val ) { | 248 | if ( slider->value() != val ) { |
250 | slider->setValue( val ); | 249 | slider->setValue( val ); |
251 | } | 250 | } |
252 | if ( slider->maxValue() != width ) { | 251 | if ( slider->maxValue() != width ) { |
253 | slider->setMaxValue( width ); | 252 | slider->setMaxValue( width ); |
254 | } | 253 | } |
255 | } | 254 | } |
256 | } | 255 | } |
257 | 256 | ||
258 | void VideoWidget::setToggleButton( int i, bool down ) { | 257 | void VideoWidget::setToggleButton( int i, bool down ) { |
259 | if ( down != buttons[i].isDown ) { | 258 | if ( down != buttons[i].isDown ) { |
260 | toggleButton( i ); | 259 | toggleButton( i ); |
261 | } | 260 | } |
262 | } | 261 | } |
263 | 262 | ||
264 | void VideoWidget::paintButton( QPainter &p, int i ) { | 263 | void VideoWidget::paintButton( QPainter &p, int i ) { |
265 | 264 | ||
266 | if ( buttons[i].isDown ) { | 265 | if ( buttons[i].isDown ) { |
267 | p.drawPixmap( upperLeftOfButtonMask, *buttonPixDown[i] ); | 266 | p.drawPixmap( upperLeftOfButtonMask, *buttonPixDown[i] ); |
268 | } else { | 267 | } else { |
269 | p.drawPixmap( upperLeftOfButtonMask, *buttonPixUp[i] ); | 268 | p.drawPixmap( upperLeftOfButtonMask, *buttonPixUp[i] ); |
270 | } | 269 | } |
271 | } | 270 | } |
272 | 271 | ||
273 | void VideoWidget::mouseMoveEvent( QMouseEvent *event ) { | 272 | void VideoWidget::mouseMoveEvent( QMouseEvent *event ) { |
274 | for ( unsigned int i = 0; i < buttons.size(); i++ ) { | 273 | for ( unsigned int i = 0; i < buttons.count(); i++ ) { |
275 | if ( event->state() == QMouseEvent::LeftButton ) { | 274 | if ( event->state() == QMouseEvent::LeftButton ) { |
276 | // The test to see if the mouse click is inside the button or not | 275 | // The test to see if the mouse click is inside the button or not |
277 | bool isOnButton = isOverButton( event->pos() - upperLeftOfButtonMask, i ); | 276 | bool isOnButton = isOverButton( event->pos() - upperLeftOfButtonMask, i ); |
278 | 277 | ||
279 | if ( isOnButton && !buttons[i].isHeld ) { | 278 | if ( isOnButton && !buttons[i].isHeld ) { |
280 | buttons[i].isHeld = TRUE; | 279 | buttons[i].isHeld = TRUE; |
281 | toggleButton(i); | 280 | toggleButton(i); |
282 | 281 | ||
283 | switch (i) { | 282 | switch (i) { |
284 | case VideoVolUp: | 283 | case VideoVolUp: |
285 | emit moreClicked(); | 284 | emit moreClicked(); |
286 | return; | 285 | return; |
287 | case VideoVolDown: | 286 | case VideoVolDown: |
288 | emit lessClicked(); | 287 | emit lessClicked(); |
289 | return; | 288 | return; |
290 | } | 289 | } |
291 | } else if ( !isOnButton && buttons[i].isHeld ) { | 290 | } else if ( !isOnButton && buttons[i].isHeld ) { |
292 | buttons[i].isHeld = FALSE; | 291 | buttons[i].isHeld = FALSE; |
293 | toggleButton(i); | 292 | toggleButton(i); |
294 | } | 293 | } |
295 | } else { | 294 | } else { |
296 | 295 | ||
297 | if ( buttons[i].isHeld ) { | 296 | if ( buttons[i].isHeld ) { |
298 | buttons[i].isHeld = FALSE; | 297 | buttons[i].isHeld = FALSE; |
299 | if ( buttons[i].type != ToggleButton ) { | 298 | if ( buttons[i].type != ToggleButton ) { |
300 | setToggleButton( i, FALSE ); | 299 | setToggleButton( i, FALSE ); |
301 | } | 300 | } |
302 | 301 | ||
303 | switch(i) { | 302 | switch(i) { |
304 | 303 | ||
305 | case VideoPlay: { | 304 | case VideoPlay: { |
306 | if( mediaPlayerState.isPaused() ) { | 305 | if( mediaPlayerState.isPaused() ) { |
307 | setToggleButton( i, FALSE ); | 306 | setToggleButton( i, FALSE ); |
308 | mediaPlayerState.setPaused( FALSE ); | 307 | mediaPlayerState.setPaused( FALSE ); |
309 | return; | 308 | return; |
310 | } else if( !mediaPlayerState.isPaused() ) { | 309 | } else if( !mediaPlayerState.isPaused() ) { |
311 | setToggleButton( i, TRUE ); | 310 | setToggleButton( i, TRUE ); |
312 | mediaPlayerState.setPaused( TRUE ); | 311 | mediaPlayerState.setPaused( TRUE ); |
313 | return; | 312 | return; |
314 | } else { | 313 | } else { |
315 | return; | 314 | return; |
316 | } | 315 | } |
317 | } | 316 | } |
318 | 317 | ||
319 | case VideoStop: mediaPlayerState.setPlaying( FALSE ); return; | 318 | case VideoStop: mediaPlayerState.setPlaying( FALSE ); return; |
320 | case VideoNext: if( playList.currentTab() == PlayListWidget::CurrentPlayList ) mediaPlayerState.setNext(); return; | 319 | case VideoNext: if( playList.currentTab() == PlayListWidget::CurrentPlayList ) mediaPlayerState.setNext(); return; |
321 | case VideoPrevious: if( playList.currentTab() == PlayListWidget::CurrentPlayList ) mediaPlayerState.setPrev(); return; | 320 | case VideoPrevious: if( playList.currentTab() == PlayListWidget::CurrentPlayList ) mediaPlayerState.setPrev(); return; |
322 | case VideoVolUp: emit moreReleased(); return; | 321 | case VideoVolUp: emit moreReleased(); return; |
323 | case VideoVolDown: emit lessReleased(); return; | 322 | case VideoVolDown: emit lessReleased(); return; |
324 | case VideoFullscreen: mediaPlayerState.setFullscreen( TRUE ); makeVisible(); return; | 323 | case VideoFullscreen: mediaPlayerState.setFullscreen( TRUE ); makeVisible(); return; |
325 | } | 324 | } |
326 | } | 325 | } |
327 | } | 326 | } |
328 | } | 327 | } |
329 | } | 328 | } |
330 | 329 | ||
331 | void VideoWidget::mousePressEvent( QMouseEvent *event ) { | 330 | void VideoWidget::mousePressEvent( QMouseEvent *event ) { |
332 | mouseMoveEvent( event ); | 331 | mouseMoveEvent( event ); |
333 | } | 332 | } |
334 | 333 | ||
335 | void VideoWidget::mouseReleaseEvent( QMouseEvent *event ) { | 334 | void VideoWidget::mouseReleaseEvent( QMouseEvent *event ) { |
336 | if ( mediaPlayerState.isFullscreen() ) { | 335 | if ( mediaPlayerState.isFullscreen() ) { |
337 | mediaPlayerState.setFullscreen( FALSE ); | 336 | mediaPlayerState.setFullscreen( FALSE ); |
338 | makeVisible(); | 337 | makeVisible(); |
339 | } | 338 | } |
340 | mouseMoveEvent( event ); | 339 | mouseMoveEvent( event ); |
341 | } | 340 | } |
342 | 341 | ||
343 | void VideoWidget::showEvent( QShowEvent* ) { | 342 | void VideoWidget::showEvent( QShowEvent* ) { |
344 | QMouseEvent event( QEvent::MouseMove, QPoint( 0, 0 ), 0, 0 ); | 343 | QMouseEvent event( QEvent::MouseMove, QPoint( 0, 0 ), 0, 0 ); |
345 | mouseMoveEvent( &event ); | 344 | mouseMoveEvent( &event ); |
346 | } | 345 | } |
347 | 346 | ||
348 | 347 | ||
349 | void VideoWidget::backToNormal() { | 348 | void VideoWidget::backToNormal() { |
350 | mediaPlayerState.setFullscreen( FALSE ); | 349 | mediaPlayerState.setFullscreen( FALSE ); |
351 | makeVisible(); | 350 | makeVisible(); |
352 | } | 351 | } |
353 | 352 | ||
354 | void VideoWidget::makeVisible() { | 353 | void VideoWidget::makeVisible() { |
355 | if ( mediaPlayerState.isFullscreen() ) { | 354 | if ( mediaPlayerState.isFullscreen() ) { |
356 | setBackgroundMode( QWidget::NoBackground ); | 355 | setBackgroundMode( QWidget::NoBackground ); |
357 | showFullScreen(); | 356 | showFullScreen(); |
358 | resize( qApp->desktop()->size() ); | 357 | resize( qApp->desktop()->size() ); |
359 | videoFrame-> setGeometry ( 0, 0, width ( ), height ( )); | 358 | videoFrame-> setGeometry ( 0, 0, width ( ), height ( )); |
360 | 359 | ||
361 | slider->hide(); | 360 | slider->hide(); |
362 | disconnect( &mediaPlayerState, SIGNAL( positionChanged(long) ),this, SLOT( setPosition(long) ) ); | 361 | disconnect( &mediaPlayerState, SIGNAL( positionChanged(long) ),this, SLOT( setPosition(long) ) ); |
363 | disconnect( &mediaPlayerState, SIGNAL( positionUpdated(long) ),this, SLOT( setPosition(long) ) ); | 362 | disconnect( &mediaPlayerState, SIGNAL( positionUpdated(long) ),this, SLOT( setPosition(long) ) ); |
364 | disconnect( slider, SIGNAL( sliderPressed() ), this, SLOT( sliderPressed() ) ); | 363 | disconnect( slider, SIGNAL( sliderPressed() ), this, SLOT( sliderPressed() ) ); |
365 | disconnect( slider, SIGNAL( sliderReleased() ), this, SLOT( sliderReleased() ) ); | 364 | disconnect( slider, SIGNAL( sliderReleased() ), this, SLOT( sliderReleased() ) ); |
366 | 365 | ||
367 | } else { | 366 | } else { |
368 | showNormal(); | 367 | showNormal(); |
369 | showMaximized(); | 368 | showMaximized(); |
370 | setBackgroundPixmap( pixBg ); | 369 | setBackgroundPixmap( pixBg ); |
371 | QWidget *d = QApplication::desktop(); | 370 | QWidget *d = QApplication::desktop(); |
372 | int w = d->width(); | 371 | int w = d->width(); |
373 | int h = d->height(); | 372 | int h = d->height(); |
374 | 373 | ||
375 | if(w>h) { | 374 | if(w>h) { |
376 | int newW=(w/2)-(246/2); //this will only work with 320x240 | 375 | int newW=(w/2)-(246/2); //this will only work with 320x240 |
377 | videoFrame->setGeometry( QRect( newW, 4, 240, 170 ) ); | 376 | videoFrame->setGeometry( QRect( newW, 4, 240, 170 ) ); |
378 | } else { | 377 | } else { |
379 | videoFrame->setGeometry( QRect( 0, 30, 240, 170 ) ); | 378 | videoFrame->setGeometry( QRect( 0, 30, 240, 170 ) ); |
380 | } | 379 | } |
381 | 380 | ||
382 | if ( !mediaPlayerState.isSeekable() ) { | 381 | if ( !mediaPlayerState.isSeekable() ) { |
383 | if( !slider->isHidden()) { | 382 | if( !slider->isHidden()) { |
384 | slider->hide(); | 383 | slider->hide(); |
385 | } | 384 | } |
386 | disconnect( &mediaPlayerState, SIGNAL( positionChanged(long) ),this, SLOT( setPosition(long) ) ); | 385 | disconnect( &mediaPlayerState, SIGNAL( positionChanged(long) ),this, SLOT( setPosition(long) ) ); |
387 | disconnect( &mediaPlayerState, SIGNAL( positionUpdated(long) ),this, SLOT( setPosition(long) ) ); | 386 | disconnect( &mediaPlayerState, SIGNAL( positionUpdated(long) ),this, SLOT( setPosition(long) ) ); |
388 | disconnect( slider, SIGNAL( sliderPressed() ), this, SLOT( sliderPressed() ) ); | 387 | disconnect( slider, SIGNAL( sliderPressed() ), this, SLOT( sliderPressed() ) ); |
389 | disconnect( slider, SIGNAL( sliderReleased() ), this, SLOT( sliderReleased() ) ); | 388 | disconnect( slider, SIGNAL( sliderReleased() ), this, SLOT( sliderReleased() ) ); |
390 | } else { | 389 | } else { |
391 | slider->show(); | 390 | slider->show(); |
392 | connect( &mediaPlayerState, SIGNAL( positionChanged(long) ),this, SLOT( setPosition(long) ) ); | 391 | connect( &mediaPlayerState, SIGNAL( positionChanged(long) ),this, SLOT( setPosition(long) ) ); |
393 | connect( &mediaPlayerState, SIGNAL( positionUpdated(long) ),this, SLOT( setPosition(long) ) ); | 392 | connect( &mediaPlayerState, SIGNAL( positionUpdated(long) ),this, SLOT( setPosition(long) ) ); |
394 | connect( slider, SIGNAL( sliderPressed() ), this, SLOT( sliderPressed() ) ); | 393 | connect( slider, SIGNAL( sliderPressed() ), this, SLOT( sliderPressed() ) ); |
395 | connect( slider, SIGNAL( sliderReleased() ), this, SLOT( sliderReleased() ) ); | 394 | connect( slider, SIGNAL( sliderReleased() ), this, SLOT( sliderReleased() ) ); |
396 | } | 395 | } |
397 | } | 396 | } |
398 | } | 397 | } |
399 | 398 | ||
400 | 399 | ||
401 | 400 | ||
402 | 401 | ||
403 | void VideoWidget::paintEvent( QPaintEvent * pe) { | 402 | void VideoWidget::paintEvent( QPaintEvent * pe) { |
404 | QPainter p( this ); | 403 | QPainter p( this ); |
405 | 404 | ||
406 | if ( mediaPlayerState.isFullscreen() ) { | 405 | if ( mediaPlayerState.isFullscreen() ) { |
407 | // Clear the background | 406 | // Clear the background |
408 | p.setBrush( QBrush( Qt::black ) ); | 407 | p.setBrush( QBrush( Qt::black ) ); |
409 | } else { | 408 | } else { |
410 | if ( !pe->erased() ) { | 409 | if ( !pe->erased() ) { |
411 | // Combine with background and double buffer | 410 | // Combine with background and double buffer |
412 | QPixmap pix( pe->rect().size() ); | 411 | QPixmap pix( pe->rect().size() ); |
413 | QPainter p( &pix ); | 412 | QPainter p( &pix ); |
414 | p.translate( -pe->rect().topLeft().x(), -pe->rect().topLeft().y() ); | 413 | p.translate( -pe->rect().topLeft().x(), -pe->rect().topLeft().y() ); |
415 | p.drawTiledPixmap( pe->rect(), pixBg, pe->rect().topLeft() ); | 414 | p.drawTiledPixmap( pe->rect(), pixBg, pe->rect().topLeft() ); |
416 | for ( unsigned int i = 0; i < buttons.size(); i++ ) { | 415 | for ( unsigned int i = 0; i < buttons.count(); i++ ) { |
417 | paintButton( p, i ); | 416 | paintButton( p, i ); |
418 | } | 417 | } |
419 | QPainter p2( this ); | 418 | QPainter p2( this ); |
420 | p2.drawPixmap( pe->rect().topLeft(), pix ); | 419 | p2.drawPixmap( pe->rect().topLeft(), pix ); |
421 | } else { | 420 | } else { |
422 | QPainter p( this ); | 421 | QPainter p( this ); |
423 | for ( unsigned int i = 0; i < buttons.size(); i++ ) | 422 | for ( unsigned int i = 0; i < buttons.count(); i++ ) |
424 | paintButton( p, i ); | 423 | paintButton( p, i ); |
425 | } | 424 | } |
426 | //slider->repaint( TRUE ); | 425 | //slider->repaint( TRUE ); |
427 | } | 426 | } |
428 | } | 427 | } |
429 | 428 | ||
430 | 429 | ||
431 | void VideoWidget::keyReleaseEvent( QKeyEvent *e) { | 430 | void VideoWidget::keyReleaseEvent( QKeyEvent *e) { |
432 | switch ( e->key() ) { | 431 | switch ( e->key() ) { |
433 | ////////////////////////////// Zaurus keys | 432 | ////////////////////////////// Zaurus keys |
434 | case Key_Home: | 433 | case Key_Home: |
435 | break; | 434 | break; |
436 | case Key_F9: //activity | 435 | case Key_F9: //activity |
437 | break; | 436 | break; |
438 | case Key_F10: //contacts | 437 | case Key_F10: //contacts |
439 | // hide(); | 438 | // hide(); |
440 | break; | 439 | break; |
441 | case Key_F11: //menu | 440 | case Key_F11: //menu |
442 | break; | 441 | break; |
443 | case Key_F12: //home | 442 | case Key_F12: //home |
444 | break; | 443 | break; |
445 | case Key_F13: //mail | 444 | case Key_F13: //mail |
446 | break; | 445 | break; |
447 | case Key_Space: { | 446 | case Key_Space: { |
448 | if(mediaPlayerState.isPlaying()) { | 447 | if(mediaPlayerState.isPlaying()) { |
449 | mediaPlayerState.setPlaying(FALSE); | 448 | mediaPlayerState.setPlaying(FALSE); |
450 | } else { | 449 | } else { |
451 | mediaPlayerState.setPlaying(TRUE); | 450 | mediaPlayerState.setPlaying(TRUE); |
452 | } | 451 | } |
453 | } | 452 | } |
454 | break; | 453 | break; |
455 | case Key_Down: | 454 | case Key_Down: |
456 | // toggleButton(6); | 455 | // toggleButton(6); |
457 | emit lessClicked(); | 456 | emit lessClicked(); |
458 | emit lessReleased(); | 457 | emit lessReleased(); |
459 | // toggleButton(6); | 458 | // toggleButton(6); |
460 | break; | 459 | break; |
461 | case Key_Up: | 460 | case Key_Up: |
462 | // toggleButton(5); | 461 | // toggleButton(5); |
463 | emit moreClicked(); | 462 | emit moreClicked(); |
464 | emit moreReleased(); | 463 | emit moreReleased(); |
465 | // toggleButton(5); | 464 | // toggleButton(5); |
466 | break; | 465 | break; |
467 | case Key_Right: | 466 | case Key_Right: |
468 | mediaPlayerState.setNext(); | 467 | mediaPlayerState.setNext(); |
469 | break; | 468 | break; |
470 | case Key_Left: | 469 | case Key_Left: |
471 | mediaPlayerState.setPrev(); | 470 | mediaPlayerState.setPrev(); |
472 | break; | 471 | break; |
473 | case Key_Escape: | 472 | case Key_Escape: |
474 | break; | 473 | break; |
475 | 474 | ||
476 | }; | 475 | }; |
477 | } | 476 | } |
478 | 477 | ||
479 | XineVideoWidget* VideoWidget::vidWidget() { | 478 | XineVideoWidget* VideoWidget::vidWidget() { |
480 | return videoFrame; | 479 | return videoFrame; |
481 | } | 480 | } |
482 | 481 | ||
483 | 482 | ||
484 | void VideoWidget::setFullscreen ( bool b ) { | 483 | void VideoWidget::setFullscreen ( bool b ) { |
485 | setToggleButton( VideoFullscreen, b ); | 484 | setToggleButton( VideoFullscreen, b ); |
486 | } | 485 | } |
487 | 486 | ||
488 | 487 | ||
489 | void VideoWidget::setPlaying( bool b) { | 488 | void VideoWidget::setPlaying( bool b) { |
490 | setToggleButton( VideoPlay, b ); | 489 | setToggleButton( VideoPlay, b ); |
491 | } | 490 | } |
492 | 491 | ||