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