-rw-r--r-- | noncore/multimedia/opieplayer2/videowidget.cpp | 16 |
1 files changed, 6 insertions, 10 deletions
diff --git a/noncore/multimedia/opieplayer2/videowidget.cpp b/noncore/multimedia/opieplayer2/videowidget.cpp index 8fe572f..238770b 100644 --- a/noncore/multimedia/opieplayer2/videowidget.cpp +++ b/noncore/multimedia/opieplayer2/videowidget.cpp | |||
@@ -1,497 +1,493 @@ | |||
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/resource.h> | 34 | #include <qpe/resource.h> |
35 | #include <qpe/mediaplayerplugininterface.h> | 35 | #include <qpe/mediaplayerplugininterface.h> |
36 | #include <qpe/config.h> | 36 | #include <qpe/config.h> |
37 | 37 | ||
38 | #include <qwidget.h> | 38 | #include <qwidget.h> |
39 | #include <qpainter.h> | 39 | #include <qpainter.h> |
40 | #include <qpixmap.h> | 40 | #include <qpixmap.h> |
41 | #include <qslider.h> | 41 | #include <qslider.h> |
42 | #include <qdrawutil.h> | 42 | #include <qdrawutil.h> |
43 | #include "videowidget.h" | 43 | #include "videowidget.h" |
44 | #include "mediaplayerstate.h" | 44 | #include "mediaplayerstate.h" |
45 | 45 | ||
46 | 46 | ||
47 | #ifdef Q_WS_QWS | 47 | #ifdef Q_WS_QWS |
48 | # define USE_DIRECT_PAINTER | 48 | # define USE_DIRECT_PAINTER |
49 | # include <qdirectpainter_qws.h> | 49 | # include <qdirectpainter_qws.h> |
50 | # include <qgfxraster_qws.h> | 50 | # include <qgfxraster_qws.h> |
51 | #endif | 51 | #endif |
52 | 52 | ||
53 | 53 | ||
54 | extern MediaPlayerState *mediaPlayerState; | 54 | extern MediaPlayerState *mediaPlayerState; |
55 | 55 | ||
56 | 56 | ||
57 | static const int xo = 2; // movable x offset | 57 | static const int xo = 2; // movable x offset |
58 | static const int yo = 0; // movable y offset | 58 | static const int yo = 0; // movable y offset |
59 | 59 | ||
60 | 60 | ||
61 | struct MediaButton { | 61 | struct MediaButton { |
62 | bool isToggle, isHeld, isDown; | 62 | bool isToggle, isHeld, isDown; |
63 | }; | 63 | }; |
64 | 64 | ||
65 | MediaButton videoButtons[] = { | 65 | MediaButton videoButtons[] = { |
66 | { FALSE, FALSE, FALSE }, // stop | 66 | { FALSE, FALSE, FALSE }, // stop |
67 | { TRUE, FALSE, FALSE }, // play | 67 | { TRUE, FALSE, FALSE }, // play |
68 | { FALSE, FALSE, FALSE }, // previous | 68 | { FALSE, FALSE, FALSE }, // previous |
69 | { FALSE, FALSE, FALSE }, // next | 69 | { FALSE, FALSE, FALSE }, // next |
70 | { FALSE, FALSE, FALSE }, // volUp | 70 | { FALSE, FALSE, FALSE }, // volUp |
71 | { FALSE, FALSE, FALSE }, // volDown | 71 | { FALSE, FALSE, FALSE }, // volDown |
72 | { TRUE, FALSE, FALSE } // fullscreen | 72 | { TRUE, FALSE, FALSE } // fullscreen |
73 | }; | 73 | }; |
74 | 74 | ||
75 | const char *skinV_mask_file_names[7] = { | 75 | const char *skinV_mask_file_names[7] = { |
76 | "stop","play","back","fwd","up","down","full" | 76 | "stop","play","back","fwd","up","down","full" |
77 | }; | 77 | }; |
78 | 78 | ||
79 | static const int numVButtons = (sizeof(videoButtons)/sizeof(MediaButton)); | 79 | static const int numVButtons = (sizeof(videoButtons)/sizeof(MediaButton)); |
80 | 80 | ||
81 | 81 | ||
82 | VideoWidget::VideoWidget(QWidget* parent, const char* name, WFlags f) : | 82 | VideoWidget::VideoWidget(QWidget* parent, const char* name, WFlags f) : |
83 | QWidget( parent, name, f ), scaledWidth( 0 ), scaledHeight( 0 ) { | 83 | QWidget( parent, name, f ), scaledWidth( 0 ), scaledHeight( 0 ) { |
84 | setCaption( tr("OpiePlayer - Video") ); | 84 | setCaption( tr("OpiePlayer - Video") ); |
85 | 85 | ||
86 | videoFrame = new XineVideoWidget ( this, "Video frame" ); | 86 | videoFrame = new XineVideoWidget ( this, "Video frame" ); |
87 | connect ( videoFrame, SIGNAL( videoResized ( const QSize & )), this, SIGNAL( videoResized ( const QSize & ))); | 87 | connect ( videoFrame, SIGNAL( videoResized ( const QSize & )), this, SIGNAL( videoResized ( const QSize & ))); |
88 | 88 | ||
89 | Config cfg("OpiePlayer"); | 89 | Config cfg("OpiePlayer"); |
90 | cfg.setGroup("Options"); | 90 | cfg.setGroup("Options"); |
91 | skin = cfg.readEntry("Skin","default"); | 91 | skin = cfg.readEntry("Skin","default"); |
92 | 92 | ||
93 | QString skinPath = "opieplayer2/skins/" + skin; | 93 | QString skinPath = "opieplayer2/skins/" + skin; |
94 | pixBg = new QPixmap( Resource::loadPixmap( QString("%1/background").arg(skinPath) ) ); | 94 | pixBg = new QPixmap( Resource::loadPixmap( QString("%1/background").arg(skinPath) ) ); |
95 | imgUp = new QImage( Resource::loadImage( QString("%1/skinV_up").arg(skinPath) ) ); | 95 | imgUp = new QImage( Resource::loadImage( QString("%1/skinV_up").arg(skinPath) ) ); |
96 | imgDn = new QImage( Resource::loadImage( QString("%1/skinV_down").arg(skinPath) ) ); | 96 | imgDn = new QImage( Resource::loadImage( QString("%1/skinV_down").arg(skinPath) ) ); |
97 | 97 | ||
98 | imgButtonMask = new QImage( imgUp->width(), imgUp->height(), 8, 255 ); | 98 | imgButtonMask = new QImage( imgUp->width(), imgUp->height(), 8, 255 ); |
99 | imgButtonMask->fill( 0 ); | 99 | imgButtonMask->fill( 0 ); |
100 | 100 | ||
101 | for ( int i = 0; i < 7; i++ ) { | 101 | for ( int i = 0; i < 7; i++ ) { |
102 | QString filename = QString(getenv("OPIEDIR")) + "/pics/" + skinPath + "/skinV_mask_" + skinV_mask_file_names[i] + ".png"; | 102 | QString filename = QString(getenv("OPIEDIR")) + "/pics/" + skinPath + "/skinV_mask_" + skinV_mask_file_names[i] + ".png"; |
103 | masks[i] = new QBitmap( filename ); | 103 | masks[i] = new QBitmap( filename ); |
104 | qDebug(filename); | 104 | |
105 | if ( !masks[i]->isNull() ) { | 105 | if ( !masks[i]->isNull() ) { |
106 | QImage imgMask = masks[i]->convertToImage(); | 106 | QImage imgMask = masks[i]->convertToImage(); |
107 | uchar **dest = imgButtonMask->jumpTable(); | 107 | uchar **dest = imgButtonMask->jumpTable(); |
108 | for ( int y = 0; y < imgUp->height(); y++ ) { | 108 | for ( int y = 0; y < imgUp->height(); y++ ) { |
109 | uchar *line = dest[y]; | 109 | uchar *line = dest[y]; |
110 | for ( int x = 0; x < imgUp->width(); x++ ) { | 110 | for ( int x = 0; x < imgUp->width(); x++ ) { |
111 | if ( !qRed( imgMask.pixel( x, y ) ) ) | 111 | if ( !qRed( imgMask.pixel( x, y ) ) ) |
112 | line[x] = i + 1; | 112 | line[x] = i + 1; |
113 | } | 113 | } |
114 | } | 114 | } |
115 | } | 115 | } |
116 | } | 116 | } |
117 | 117 | ||
118 | for ( int i = 0; i < 7; i++ ) { | 118 | for ( int i = 0; i < 7; i++ ) { |
119 | buttonPixUp[i] = NULL; | 119 | buttonPixUp[i] = NULL; |
120 | buttonPixDown[i] = NULL; | 120 | buttonPixDown[i] = NULL; |
121 | } | 121 | } |
122 | 122 | ||
123 | setBackgroundPixmap( *pixBg ); | 123 | setBackgroundPixmap( *pixBg ); |
124 | 124 | ||
125 | slider = new QSlider( Qt::Horizontal, this ); | 125 | slider = new QSlider( Qt::Horizontal, this ); |
126 | slider->setMinValue( 0 ); | 126 | slider->setMinValue( 0 ); |
127 | slider->setMaxValue( 1 ); | 127 | slider->setMaxValue( 1 ); |
128 | slider->setBackgroundPixmap( Resource::loadPixmap( backgroundPix ) ); | 128 | slider->setBackgroundPixmap( Resource::loadPixmap( backgroundPix ) ); |
129 | slider->setFocusPolicy( QWidget::NoFocus ); | 129 | slider->setFocusPolicy( QWidget::NoFocus ); |
130 | 130 | ||
131 | resizeEvent( NULL ); | 131 | resizeEvent( NULL ); |
132 | 132 | ||
133 | connect( slider, SIGNAL( sliderPressed() ), this, SLOT( sliderPressed() ) ); | 133 | connect( slider, SIGNAL( sliderPressed() ), this, SLOT( sliderPressed() ) ); |
134 | connect( slider, SIGNAL( sliderReleased() ), this, SLOT( sliderReleased() ) ); | 134 | connect( slider, SIGNAL( sliderReleased() ), this, SLOT( sliderReleased() ) ); |
135 | connect( mediaPlayerState, SIGNAL( lengthChanged(long) ), this, SLOT( setLength(long) ) ); | 135 | connect( mediaPlayerState, SIGNAL( lengthChanged(long) ), this, SLOT( setLength(long) ) ); |
136 | connect( mediaPlayerState, SIGNAL( viewChanged(char) ), this, SLOT( setView(char) ) ); | 136 | connect( mediaPlayerState, SIGNAL( viewChanged(char) ), this, SLOT( setView(char) ) ); |
137 | connect( mediaPlayerState, SIGNAL( playingToggled(bool) ), this, SLOT( setPlaying(bool) ) ); | 137 | connect( mediaPlayerState, SIGNAL( playingToggled(bool) ), this, SLOT( setPlaying(bool) ) ); |
138 | 138 | ||
139 | setLength( mediaPlayerState->length() ); | 139 | setLength( mediaPlayerState->length() ); |
140 | setPosition( mediaPlayerState->position() ); | 140 | setPosition( mediaPlayerState->position() ); |
141 | setFullscreen( mediaPlayerState->fullscreen() ); | 141 | setFullscreen( mediaPlayerState->fullscreen() ); |
142 | // setPaused( mediaPlayerState->paused() ); | 142 | // setPaused( mediaPlayerState->paused() ); |
143 | setPlaying( mediaPlayerState->playing() ); | 143 | setPlaying( mediaPlayerState->playing() ); |
144 | } | 144 | } |
145 | 145 | ||
146 | 146 | ||
147 | VideoWidget::~VideoWidget() { | 147 | VideoWidget::~VideoWidget() { |
148 | 148 | ||
149 | for ( int i = 0; i < 7; i++ ) { | 149 | for ( int i = 0; i < 7; i++ ) { |
150 | delete buttonPixUp[i]; | 150 | delete buttonPixUp[i]; |
151 | delete buttonPixDown[i]; | 151 | delete buttonPixDown[i]; |
152 | } | 152 | } |
153 | 153 | ||
154 | delete pixBg; | 154 | delete pixBg; |
155 | delete imgUp; | 155 | delete imgUp; |
156 | delete imgDn; | 156 | delete imgDn; |
157 | delete imgButtonMask; | 157 | delete imgButtonMask; |
158 | for ( int i = 0; i < 7; i++ ) { | 158 | for ( int i = 0; i < 7; i++ ) { |
159 | delete masks[i]; | 159 | delete masks[i]; |
160 | } | 160 | } |
161 | 161 | ||
162 | } | 162 | } |
163 | 163 | ||
164 | QPixmap *combineVImageWithBackground( QImage img, QPixmap bg, QPoint offset ) { | 164 | QPixmap *combineVImageWithBackground( QImage img, QPixmap bg, QPoint offset ) { |
165 | QPixmap pix( img.width(), img.height() ); | 165 | QPixmap pix( img.width(), img.height() ); |
166 | QPainter p( &pix ); | 166 | QPainter p( &pix ); |
167 | p.drawTiledPixmap( pix.rect(), bg, offset ); | 167 | p.drawTiledPixmap( pix.rect(), bg, offset ); |
168 | p.drawImage( 0, 0, img ); | 168 | p.drawImage( 0, 0, img ); |
169 | return new QPixmap( pix ); | 169 | return new QPixmap( pix ); |
170 | } | 170 | } |
171 | 171 | ||
172 | QPixmap *maskVPixToMask( QPixmap pix, QBitmap mask ) { | 172 | QPixmap *maskVPixToMask( QPixmap pix, QBitmap mask ) { |
173 | QPixmap *pixmap = new QPixmap( pix ); | 173 | QPixmap *pixmap = new QPixmap( pix ); |
174 | pixmap->setMask( mask ); | 174 | pixmap->setMask( mask ); |
175 | return pixmap; | 175 | return pixmap; |
176 | } | 176 | } |
177 | 177 | ||
178 | void VideoWidget::resizeEvent( QResizeEvent * ) { | 178 | void VideoWidget::resizeEvent( QResizeEvent * ) { |
179 | int h = height(); | 179 | int h = height(); |
180 | int w = width(); | 180 | int w = width(); |
181 | int Vh = 160; | 181 | int Vh = 160; |
182 | //videoFrame->height(); | ||
183 | int Vw = 220; | 182 | int Vw = 220; |
184 | //videoFrame->width(); | ||
185 | |||
186 | 183 | ||
187 | slider->setFixedWidth( w - 20 ); | 184 | slider->setFixedWidth( w - 20 ); |
188 | slider->setGeometry( QRect( 15, h - 30, w - 90, 20 ) ); | 185 | slider->setGeometry( QRect( 15, h - 30, w - 90, 20 ) ); |
189 | slider->setBackgroundOrigin( QWidget::ParentOrigin ); | 186 | slider->setBackgroundOrigin( QWidget::ParentOrigin ); |
190 | slider->setFocusPolicy( QWidget::NoFocus ); | 187 | slider->setFocusPolicy( QWidget::NoFocus ); |
191 | slider->setBackgroundPixmap( *pixBg ); | 188 | slider->setBackgroundPixmap( *pixBg ); |
192 | 189 | ||
193 | xoff = 0;// ( imgUp->width() ) / 2; | 190 | xoff = 0;// ( imgUp->width() ) / 2; |
194 | yoff = 180;//(( Vh - imgUp->height() ) / 2) - 10; | 191 | yoff = 185;//(( Vh - imgUp->height() ) / 2) - 10; |
195 | QPoint p( xoff, yoff ); | 192 | QPoint p( xoff, yoff ); |
196 | 193 | ||
197 | |||
198 | QPixmap *pixUp = combineVImageWithBackground( *imgUp, *pixBg, p ); | 194 | QPixmap *pixUp = combineVImageWithBackground( *imgUp, *pixBg, p ); |
199 | QPixmap *pixDn = combineVImageWithBackground( *imgDn, *pixBg, p ); | 195 | QPixmap *pixDn = combineVImageWithBackground( *imgDn, *pixBg, p ); |
200 | 196 | ||
201 | for ( int i = 0; i < 7; i++ ) { | 197 | for ( int i = 0; i < 7; i++ ) { |
202 | if ( !masks[i]->isNull() ) { | 198 | if ( !masks[i]->isNull() ) { |
203 | delete buttonPixUp[i]; | 199 | delete buttonPixUp[i]; |
204 | delete buttonPixDown[i]; | 200 | delete buttonPixDown[i]; |
205 | buttonPixUp[i] = maskVPixToMask( *pixUp, *masks[i] ); | 201 | buttonPixUp[i] = maskVPixToMask( *pixUp, *masks[i] ); |
206 | buttonPixDown[i] = maskVPixToMask( *pixDn, *masks[i] ); | 202 | buttonPixDown[i] = maskVPixToMask( *pixDn, *masks[i] ); |
207 | } | 203 | } |
208 | } | 204 | } |
209 | 205 | ||
210 | delete pixUp; | 206 | delete pixUp; |
211 | delete pixDn; | 207 | delete pixDn; |
212 | } | 208 | } |
213 | 209 | ||
214 | static bool videoSliderBeingMoved = FALSE; | 210 | static bool videoSliderBeingMoved = FALSE; |
215 | 211 | ||
216 | void VideoWidget::sliderPressed() { | 212 | void VideoWidget::sliderPressed() { |
217 | videoSliderBeingMoved = TRUE; | 213 | videoSliderBeingMoved = TRUE; |
218 | } | 214 | } |
219 | 215 | ||
220 | void VideoWidget::sliderReleased() { | 216 | void VideoWidget::sliderReleased() { |
221 | videoSliderBeingMoved = FALSE; | 217 | videoSliderBeingMoved = FALSE; |
222 | if ( slider->width() == 0 ) { | 218 | if ( slider->width() == 0 ) { |
223 | return; | 219 | return; |
224 | } | 220 | } |
225 | long val = long((double)slider->value() * mediaPlayerState->length() / slider->width()); | 221 | long val = long((double)slider->value() * mediaPlayerState->length() / slider->width()); |
226 | mediaPlayerState->setPosition( val ); | 222 | mediaPlayerState->setPosition( val ); |
227 | } | 223 | } |
228 | 224 | ||
229 | void VideoWidget::setPosition( long i ) { | 225 | void VideoWidget::setPosition( long i ) { |
230 | updateSlider( i, mediaPlayerState->length() ); | 226 | updateSlider( i, mediaPlayerState->length() ); |
231 | } | 227 | } |
232 | 228 | ||
233 | 229 | ||
234 | void VideoWidget::setLength( long max ) { | 230 | void VideoWidget::setLength( long max ) { |
235 | updateSlider( mediaPlayerState->position(), max ); | 231 | updateSlider( mediaPlayerState->position(), max ); |
236 | } | 232 | } |
237 | 233 | ||
238 | void VideoWidget::setView( char view ) { | 234 | void VideoWidget::setView( char view ) { |
239 | 235 | ||
240 | if ( mediaPlayerState->streaming() ) { | 236 | if ( mediaPlayerState->streaming() ) { |
241 | qDebug("<<<<<<<<<<<<<<file is STREAMING>>>>>>>>>>>>>>>>>>>"); | 237 | qDebug("<<<<<<<<<<<<<<file is STREAMING>>>>>>>>>>>>>>>>>>>"); |
242 | if( !slider->isHidden()) { | 238 | if( !slider->isHidden()) { |
243 | slider->hide(); | 239 | slider->hide(); |
244 | } | 240 | } |
245 | disconnect( mediaPlayerState, SIGNAL( positionChanged(long) ),this, SLOT( setPosition(long) ) ); | 241 | disconnect( mediaPlayerState, SIGNAL( positionChanged(long) ),this, SLOT( setPosition(long) ) ); |
246 | disconnect( mediaPlayerState, SIGNAL( positionUpdated(long) ),this, SLOT( setPosition(long) ) ); | 242 | disconnect( mediaPlayerState, SIGNAL( positionUpdated(long) ),this, SLOT( setPosition(long) ) ); |
247 | } else { | 243 | } else { |
248 | // this stops the slider from being moved, thus | 244 | // this stops the slider from being moved, thus |
249 | // does not stop stream when it reaches the end | 245 | // does not stop stream when it reaches the end |
250 | slider->show(); | 246 | slider->show(); |
251 | connect( mediaPlayerState, SIGNAL( positionChanged(long) ),this, SLOT( setPosition(long) ) ); | 247 | connect( mediaPlayerState, SIGNAL( positionChanged(long) ),this, SLOT( setPosition(long) ) ); |
252 | connect( mediaPlayerState, SIGNAL( positionUpdated(long) ),this, SLOT( setPosition(long) ) ); | 248 | connect( mediaPlayerState, SIGNAL( positionUpdated(long) ),this, SLOT( setPosition(long) ) ); |
253 | } | 249 | } |
254 | 250 | ||
255 | if ( view == 'v' ) { | 251 | if ( view == 'v' ) { |
256 | makeVisible(); | 252 | makeVisible(); |
257 | } else { | 253 | } else { |
258 | // Effectively blank the view next time we show it so it looks nicer | 254 | // Effectively blank the view next time we show it so it looks nicer |
259 | scaledWidth = 0; | 255 | scaledWidth = 0; |
260 | scaledHeight = 0; | 256 | scaledHeight = 0; |
261 | hide(); | 257 | hide(); |
262 | } | 258 | } |
263 | } | 259 | } |
264 | 260 | ||
265 | void VideoWidget::updateSlider( long i, long max ) { | 261 | void VideoWidget::updateSlider( long i, long max ) { |
266 | // Will flicker too much if we don't do this | 262 | // Will flicker too much if we don't do this |
267 | if ( max == 0 ) { | 263 | if ( max == 0 ) { |
268 | return; | 264 | return; |
269 | } | 265 | } |
270 | int width = slider->width(); | 266 | int width = slider->width(); |
271 | int val = int((double)i * width / max); | 267 | int val = int((double)i * width / max); |
272 | if ( !mediaPlayerState->fullscreen() && !videoSliderBeingMoved ) { | 268 | if ( !mediaPlayerState->fullscreen() && !videoSliderBeingMoved ) { |
273 | if ( slider->value() != val ) { | 269 | if ( slider->value() != val ) { |
274 | slider->setValue( val ); | 270 | slider->setValue( val ); |
275 | } | 271 | } |
276 | if ( slider->maxValue() != width ) { | 272 | if ( slider->maxValue() != width ) { |
277 | slider->setMaxValue( width ); | 273 | slider->setMaxValue( width ); |
278 | } | 274 | } |
279 | } | 275 | } |
280 | } | 276 | } |
281 | 277 | ||
282 | void VideoWidget::setToggleButton( int i, bool down ) { | 278 | void VideoWidget::setToggleButton( int i, bool down ) { |
283 | if ( down != videoButtons[i].isDown ) { | 279 | if ( down != videoButtons[i].isDown ) { |
284 | toggleButton( i ); | 280 | toggleButton( i ); |
285 | } | 281 | } |
286 | } | 282 | } |
287 | 283 | ||
288 | void VideoWidget::toggleButton( int i ) { | 284 | void VideoWidget::toggleButton( int i ) { |
289 | videoButtons[i].isDown = !videoButtons[i].isDown; | 285 | videoButtons[i].isDown = !videoButtons[i].isDown; |
290 | QPainter p(this); | 286 | QPainter p(this); |
291 | paintButton ( &p, i ); | 287 | paintButton ( &p, i ); |
292 | } | 288 | } |
293 | 289 | ||
294 | void VideoWidget::paintButton( QPainter *p, int i ) { | 290 | void VideoWidget::paintButton( QPainter *p, int i ) { |
295 | 291 | ||
296 | if ( videoButtons[i].isDown ) { | 292 | if ( videoButtons[i].isDown ) { |
297 | p->drawPixmap( xoff, yoff, *buttonPixDown[i] ); | 293 | p->drawPixmap( xoff, yoff, *buttonPixDown[i] ); |
298 | } else { | 294 | } else { |
299 | p->drawPixmap( xoff, yoff, *buttonPixUp[i] ); | 295 | p->drawPixmap( xoff, yoff, *buttonPixUp[i] ); |
300 | } | 296 | } |
301 | } | 297 | } |
302 | 298 | ||
303 | void VideoWidget::mouseMoveEvent( QMouseEvent *event ) { | 299 | void VideoWidget::mouseMoveEvent( QMouseEvent *event ) { |
304 | for ( int i = 0; i < numVButtons; i++ ) { | 300 | for ( int i = 0; i < numVButtons; i++ ) { |
305 | if ( event->state() == QMouseEvent::LeftButton ) { | 301 | if ( event->state() == QMouseEvent::LeftButton ) { |
306 | // The test to see if the mouse click is inside the button or not | 302 | // The test to see if the mouse click is inside the button or not |
307 | int x = event->pos().x() - xoff; | 303 | int x = event->pos().x() - xoff; |
308 | int y = event->pos().y() - yoff; | 304 | int y = event->pos().y() - yoff; |
309 | 305 | ||
310 | bool isOnButton = ( x > 0 && y > 0 && x < imgButtonMask->width() | 306 | bool isOnButton = ( x > 0 && y > 0 && x < imgButtonMask->width() |
311 | && y < imgButtonMask->height() | 307 | && y < imgButtonMask->height() |
312 | && imgButtonMask->pixelIndex( x, y ) == i + 1 ); | 308 | && imgButtonMask->pixelIndex( x, y ) == i + 1 ); |
313 | 309 | ||
314 | if ( isOnButton && !videoButtons[i].isHeld ) { | 310 | if ( isOnButton && !videoButtons[i].isHeld ) { |
315 | videoButtons[i].isHeld = TRUE; | 311 | videoButtons[i].isHeld = TRUE; |
316 | toggleButton(i); | 312 | toggleButton(i); |
317 | 313 | ||
318 | switch (i) { | 314 | switch (i) { |
319 | case VideoVolUp: | 315 | case VideoVolUp: |
320 | emit moreClicked(); | 316 | emit moreClicked(); |
321 | return; | 317 | return; |
322 | case VideoVolDown: | 318 | case VideoVolDown: |
323 | emit lessClicked(); | 319 | emit lessClicked(); |
324 | return; | 320 | return; |
325 | } | 321 | } |
326 | } else if ( !isOnButton && videoButtons[i].isHeld ) { | 322 | } else if ( !isOnButton && videoButtons[i].isHeld ) { |
327 | videoButtons[i].isHeld = FALSE; | 323 | videoButtons[i].isHeld = FALSE; |
328 | toggleButton(i); | 324 | toggleButton(i); |
329 | } | 325 | } |
330 | } else { | 326 | } else { |
331 | 327 | ||
332 | if ( videoButtons[i].isHeld ) { | 328 | if ( videoButtons[i].isHeld ) { |
333 | videoButtons[i].isHeld = FALSE; | 329 | videoButtons[i].isHeld = FALSE; |
334 | if ( !videoButtons[i].isToggle ) { | 330 | if ( !videoButtons[i].isToggle ) { |
335 | setToggleButton( i, FALSE ); | 331 | setToggleButton( i, FALSE ); |
336 | } | 332 | } |
337 | 333 | ||
338 | switch(i) { | 334 | switch(i) { |
339 | 335 | ||
340 | case VideoPlay: { | 336 | case VideoPlay: { |
341 | if( mediaPlayerState->isPaused ) { | 337 | if( mediaPlayerState->isPaused ) { |
342 | setToggleButton( i, FALSE ); | 338 | setToggleButton( i, FALSE ); |
343 | mediaPlayerState->setPaused( FALSE ); | 339 | mediaPlayerState->setPaused( FALSE ); |
344 | return; | 340 | return; |
345 | } else if( !mediaPlayerState->isPaused ) { | 341 | } else if( !mediaPlayerState->isPaused ) { |
346 | setToggleButton( i, TRUE ); | 342 | setToggleButton( i, TRUE ); |
347 | mediaPlayerState->setPaused( TRUE ); | 343 | mediaPlayerState->setPaused( TRUE ); |
348 | return; | 344 | return; |
349 | } else { | 345 | } else { |
350 | // setToggleButton( i, TRUE ); | 346 | // setToggleButton( i, TRUE ); |
351 | // mediaPlayerState->setPlaying( videoButtons[i].isDown ); | 347 | // mediaPlayerState->setPlaying( videoButtons[i].isDown ); |
352 | } | 348 | } |
353 | } | 349 | } |
354 | 350 | ||
355 | case VideoStop: mediaPlayerState->setPlaying( FALSE ); return; | 351 | case VideoStop: mediaPlayerState->setPlaying( FALSE ); return; |
356 | case VideoNext: mediaPlayerState->setNext(); return; | 352 | case VideoNext: mediaPlayerState->setNext(); return; |
357 | case VideoPrevious: mediaPlayerState->setPrev(); return; | 353 | case VideoPrevious: mediaPlayerState->setPrev(); return; |
358 | case VideoVolUp: emit moreReleased(); return; | 354 | case VideoVolUp: emit moreReleased(); return; |
359 | case VideoVolDown: emit lessReleased(); return; | 355 | case VideoVolDown: emit lessReleased(); return; |
360 | case VideoFullscreen: mediaPlayerState->setFullscreen( TRUE ); makeVisible(); return; | 356 | case VideoFullscreen: mediaPlayerState->setFullscreen( TRUE ); makeVisible(); return; |
361 | } | 357 | } |
362 | } | 358 | } |
363 | } | 359 | } |
364 | } | 360 | } |
365 | } | 361 | } |
366 | 362 | ||
367 | void VideoWidget::mousePressEvent( QMouseEvent *event ) { | 363 | void VideoWidget::mousePressEvent( QMouseEvent *event ) { |
368 | mouseMoveEvent( event ); | 364 | mouseMoveEvent( event ); |
369 | } | 365 | } |
370 | 366 | ||
371 | void VideoWidget::mouseReleaseEvent( QMouseEvent *event ) { | 367 | void VideoWidget::mouseReleaseEvent( QMouseEvent *event ) { |
372 | if ( mediaPlayerState->fullscreen() ) { | 368 | if ( mediaPlayerState->fullscreen() ) { |
373 | mediaPlayerState->setFullscreen( FALSE ); | 369 | mediaPlayerState->setFullscreen( FALSE ); |
374 | makeVisible(); | 370 | makeVisible(); |
375 | } | 371 | } |
376 | mouseMoveEvent( event ); | 372 | mouseMoveEvent( event ); |
377 | } | 373 | } |
378 | 374 | ||
379 | void VideoWidget::showEvent( QShowEvent* ) { | 375 | void VideoWidget::showEvent( QShowEvent* ) { |
380 | QMouseEvent event( QEvent::MouseMove, QPoint( 0, 0 ), 0, 0 ); | 376 | QMouseEvent event( QEvent::MouseMove, QPoint( 0, 0 ), 0, 0 ); |
381 | mouseMoveEvent( &event ); | 377 | mouseMoveEvent( &event ); |
382 | } | 378 | } |
383 | 379 | ||
384 | 380 | ||
385 | void VideoWidget::makeVisible() { | 381 | void VideoWidget::makeVisible() { |
386 | if ( mediaPlayerState->fullscreen() ) { | 382 | if ( mediaPlayerState->fullscreen() ) { |
387 | setBackgroundMode( QWidget::NoBackground ); | 383 | setBackgroundMode( QWidget::NoBackground ); |
388 | showFullScreen(); | 384 | showFullScreen(); |
389 | resize( qApp->desktop()->size() ); | 385 | resize( qApp->desktop()->size() ); |
390 | slider->hide(); | 386 | slider->hide(); |
391 | videoFrame-> setGeometry ( 0, 0, width ( ), height ( )); | 387 | videoFrame-> setGeometry ( 0, 0, width ( ), height ( )); |
392 | } else { | 388 | } else { |
393 | showNormal(); | 389 | showNormal(); |
394 | showMaximized(); | 390 | showMaximized(); |
395 | slider->show(); | 391 | slider->show(); |
396 | videoFrame->setGeometry( QRect( 10, 20, 220, 160 ) ); | 392 | videoFrame->setGeometry( QRect( 10, 20, 220, 160 ) ); |
397 | qApp->processEvents(); | 393 | qApp->processEvents(); |
398 | } | 394 | } |
399 | } | 395 | } |
400 | 396 | ||
401 | 397 | ||
402 | void VideoWidget::paintEvent( QPaintEvent * pe) { | 398 | void VideoWidget::paintEvent( QPaintEvent * pe) { |
403 | QPainter p( this ); | 399 | QPainter p( this ); |
404 | 400 | ||
405 | if ( mediaPlayerState->fullscreen() ) { | 401 | if ( mediaPlayerState->fullscreen() ) { |
406 | // Clear the background | 402 | // Clear the background |
407 | p.setBrush( QBrush( Qt::black ) ); | 403 | p.setBrush( QBrush( Qt::black ) ); |
408 | } else { | 404 | } else { |
409 | if ( !pe->erased() ) { | 405 | if ( !pe->erased() ) { |
410 | // Combine with background and double buffer | 406 | // Combine with background and double buffer |
411 | QPixmap pix( pe->rect().size() ); | 407 | QPixmap pix( pe->rect().size() ); |
412 | QPainter p( &pix ); | 408 | QPainter p( &pix ); |
413 | p.translate( -pe->rect().topLeft().x(), -pe->rect().topLeft().y() ); | 409 | p.translate( -pe->rect().topLeft().x(), -pe->rect().topLeft().y() ); |
414 | p.drawTiledPixmap( pe->rect(), *pixBg, pe->rect().topLeft() ); | 410 | p.drawTiledPixmap( pe->rect(), *pixBg, pe->rect().topLeft() ); |
415 | for ( int i = 0; i < numVButtons; i++ ) { | 411 | for ( int i = 0; i < numVButtons; i++ ) { |
416 | paintButton( &p, i ); | 412 | paintButton( &p, i ); |
417 | } | 413 | } |
418 | QPainter p2( this ); | 414 | QPainter p2( this ); |
419 | p2.drawPixmap( pe->rect().topLeft(), pix ); | 415 | p2.drawPixmap( pe->rect().topLeft(), pix ); |
420 | } else { | 416 | } else { |
421 | QPainter p( this ); | 417 | QPainter p( this ); |
422 | for ( int i = 0; i < numVButtons; i++ ) | 418 | for ( int i = 0; i < numVButtons; i++ ) |
423 | paintButton( &p, i ); | 419 | paintButton( &p, i ); |
424 | } | 420 | } |
425 | slider->repaint( TRUE ); | 421 | slider->repaint( TRUE ); |
426 | } | 422 | } |
427 | } | 423 | } |
428 | 424 | ||
429 | 425 | ||
430 | void VideoWidget::closeEvent( QCloseEvent* ) { | 426 | void VideoWidget::closeEvent( QCloseEvent* ) { |
431 | mediaPlayerState->setList(); | 427 | mediaPlayerState->setList(); |
432 | } | 428 | } |
433 | 429 | ||
434 | 430 | ||
435 | 431 | ||
436 | void VideoWidget::keyReleaseEvent( QKeyEvent *e) { | 432 | void VideoWidget::keyReleaseEvent( QKeyEvent *e) { |
437 | switch ( e->key() ) { | 433 | switch ( e->key() ) { |
438 | ////////////////////////////// Zaurus keys | 434 | ////////////////////////////// Zaurus keys |
439 | case Key_Home: | 435 | case Key_Home: |
440 | break; | 436 | break; |
441 | case Key_F9: //activity | 437 | case Key_F9: //activity |
442 | break; | 438 | break; |
443 | case Key_F10: //contacts | 439 | case Key_F10: //contacts |
444 | // hide(); | 440 | // hide(); |
445 | break; | 441 | break; |
446 | case Key_F11: //menu | 442 | case Key_F11: //menu |
447 | break; | 443 | break; |
448 | case Key_F12: //home | 444 | case Key_F12: //home |
449 | break; | 445 | break; |
450 | case Key_F13: //mail | 446 | case Key_F13: //mail |
451 | break; | 447 | break; |
452 | case Key_Space: { | 448 | case Key_Space: { |
453 | if(mediaPlayerState->playing()) { | 449 | if(mediaPlayerState->playing()) { |
454 | mediaPlayerState->setPlaying(FALSE); | 450 | mediaPlayerState->setPlaying(FALSE); |
455 | } else { | 451 | } else { |
456 | mediaPlayerState->setPlaying(TRUE); | 452 | mediaPlayerState->setPlaying(TRUE); |
457 | } | 453 | } |
458 | } | 454 | } |
459 | break; | 455 | break; |
460 | case Key_Down: | 456 | case Key_Down: |
461 | // toggleButton(6); | 457 | // toggleButton(6); |
462 | // emit lessClicked(); | 458 | emit lessClicked(); |
463 | // emit lessReleased(); | 459 | emit lessReleased(); |
464 | // toggleButton(6); | 460 | // toggleButton(6); |
465 | break; | 461 | break; |
466 | case Key_Up: | 462 | case Key_Up: |
467 | // toggleButton(5); | 463 | // toggleButton(5); |
468 | // emit moreClicked(); | 464 | emit moreClicked(); |
469 | // emit moreReleased(); | 465 | emit moreReleased(); |
470 | // toggleButton(5); | 466 | // toggleButton(5); |
471 | break; | 467 | break; |
472 | case Key_Right: | 468 | case Key_Right: |
473 | mediaPlayerState->setNext(); | 469 | mediaPlayerState->setNext(); |
474 | break; | 470 | break; |
475 | case Key_Left: | 471 | case Key_Left: |
476 | mediaPlayerState->setPrev(); | 472 | mediaPlayerState->setPrev(); |
477 | break; | 473 | break; |
478 | case Key_Escape: | 474 | case Key_Escape: |
479 | break; | 475 | break; |
480 | 476 | ||
481 | }; | 477 | }; |
482 | } | 478 | } |
483 | 479 | ||
484 | XineVideoWidget* VideoWidget::vidWidget() { | 480 | XineVideoWidget* VideoWidget::vidWidget() { |
485 | return videoFrame; | 481 | return videoFrame; |
486 | } | 482 | } |
487 | 483 | ||
488 | 484 | ||
489 | void VideoWidget::setFullscreen ( bool b ) { | 485 | void VideoWidget::setFullscreen ( bool b ) { |
490 | setToggleButton( VideoFullscreen, b ); | 486 | setToggleButton( VideoFullscreen, b ); |
491 | } | 487 | } |
492 | 488 | ||
493 | 489 | ||
494 | void VideoWidget::setPlaying( bool b) { | 490 | void VideoWidget::setPlaying( bool b) { |
495 | setToggleButton( VideoPlay, b ); | 491 | setToggleButton( VideoPlay, b ); |
496 | } | 492 | } |
497 | 493 | ||