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