author | llornkcor <llornkcor> | 2004-01-18 05:58:46 (UTC) |
---|---|---|
committer | llornkcor <llornkcor> | 2004-01-18 05:58:46 (UTC) |
commit | a2a3aabf21655cc9c7df8e2ed0d420d2b208fd3d (patch) (unidiff) | |
tree | 6cb2840a838d24cd1500e5c86c54393234999f08 | |
parent | a5a10ccc4b39e9ec21b1774713745b31f47a5133 (diff) | |
download | opie-a2a3aabf21655cc9c7df8e2ed0d420d2b208fd3d.zip opie-a2a3aabf21655cc9c7df8e2ed0d420d2b208fd3d.tar.gz opie-a2a3aabf21655cc9c7df8e2ed0d420d2b208fd3d.tar.bz2 |
scale background image if needed
-rw-r--r-- | core/multimedia/opieplayer/audiowidget.cpp | 13 | ||||
-rw-r--r-- | core/multimedia/opieplayer/videowidget.cpp | 26 |
2 files changed, 28 insertions, 11 deletions
diff --git a/core/multimedia/opieplayer/audiowidget.cpp b/core/multimedia/opieplayer/audiowidget.cpp index b187cb4..44fbe48 100644 --- a/core/multimedia/opieplayer/audiowidget.cpp +++ b/core/multimedia/opieplayer/audiowidget.cpp | |||
@@ -1,516 +1,527 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of Qtopia Environment. | 4 | ** This file is part of Qtopia Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
7 | ** GNU General Public License version 2 as published by the Free Software | 7 | ** GNU General Public License version 2 as published by the Free Software |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | #include <qpe/qpeapplication.h> | 20 | #include <qpe/qpeapplication.h> |
21 | #include <qpe/resource.h> | 21 | #include <qpe/resource.h> |
22 | #include <qpe/config.h> | 22 | #include <qpe/config.h> |
23 | 23 | ||
24 | #include <qwidget.h> | 24 | #include <qwidget.h> |
25 | #include <qpixmap.h> | 25 | #include <qpixmap.h> |
26 | #include <qbutton.h> | 26 | #include <qbutton.h> |
27 | #include <qpainter.h> | 27 | #include <qpainter.h> |
28 | #include <qframe.h> | 28 | #include <qframe.h> |
29 | #include <qlayout.h> | 29 | #include <qlayout.h> |
30 | #include <qdir.h> | 30 | #include <qdir.h> |
31 | #include "audiowidget.h" | 31 | #include "audiowidget.h" |
32 | #include "mediaplayerstate.h" | 32 | #include "mediaplayerstate.h" |
33 | 33 | ||
34 | #include <stdlib.h> | 34 | #include <stdlib.h> |
35 | #include <stdio.h> | 35 | #include <stdio.h> |
36 | 36 | ||
37 | extern MediaPlayerState *mediaPlayerState; | 37 | extern MediaPlayerState *mediaPlayerState; |
38 | 38 | ||
39 | 39 | ||
40 | static const int xo = -2; // movable x offset | 40 | static const int xo = -2; // movable x offset |
41 | static const int yo = 22; // movable y offset | 41 | static const int yo = 22; // movable y offset |
42 | 42 | ||
43 | struct MediaButton { | 43 | struct MediaButton { |
44 | bool isToggle, isHeld, isDown; | 44 | bool isToggle, isHeld, isDown; |
45 | }; | 45 | }; |
46 | 46 | ||
47 | //Layout information for the audioButtons (and if it is a toggle button or not) | 47 | //Layout information for the audioButtons (and if it is a toggle button or not) |
48 | MediaButton audioButtons[] = { | 48 | MediaButton audioButtons[] = { |
49 | { TRUE, FALSE, FALSE }, // play | 49 | { TRUE, FALSE, FALSE }, // play |
50 | { FALSE, FALSE, FALSE }, // stop | 50 | { FALSE, FALSE, FALSE }, // stop |
51 | { FALSE, FALSE, FALSE }, // next | 51 | { FALSE, FALSE, FALSE }, // next |
52 | { FALSE, FALSE, FALSE }, // previous | 52 | { FALSE, FALSE, FALSE }, // previous |
53 | { FALSE, FALSE, FALSE }, // volume up | 53 | { FALSE, FALSE, FALSE }, // volume up |
54 | { FALSE, FALSE, FALSE }, // volume down | 54 | { FALSE, FALSE, FALSE }, // volume down |
55 | { TRUE, FALSE, FALSE }, // repeat/loop | 55 | { TRUE, FALSE, FALSE }, // repeat/loop |
56 | { FALSE, FALSE, FALSE }, // playlist | 56 | { FALSE, FALSE, FALSE }, // playlist |
57 | { FALSE, FALSE, FALSE }, // forward | 57 | { FALSE, FALSE, FALSE }, // forward |
58 | { FALSE, FALSE, FALSE } // back | 58 | { FALSE, FALSE, FALSE } // back |
59 | }; | 59 | }; |
60 | 60 | ||
61 | const char *skin_mask_file_names[10] = { | 61 | const char *skin_mask_file_names[10] = { |
62 | "play", "stop", "next", "prev", "up", | 62 | "play", "stop", "next", "prev", "up", |
63 | "down", "loop", "playlist", "forward", "back" | 63 | "down", "loop", "playlist", "forward", "back" |
64 | }; | 64 | }; |
65 | 65 | ||
66 | static void changeTextColor( QWidget *w ) { | 66 | static void changeTextColor( QWidget *w ) { |
67 | QPalette p = w->palette(); | 67 | QPalette p = w->palette(); |
68 | p.setBrush( QColorGroup::Background, QColor( 167, 212, 167 ) ); | 68 | p.setBrush( QColorGroup::Background, QColor( 167, 212, 167 ) ); |
69 | p.setBrush( QColorGroup::Base, QColor( 167, 212, 167 ) ); | 69 | p.setBrush( QColorGroup::Base, QColor( 167, 212, 167 ) ); |
70 | w->setPalette( p ); | 70 | w->setPalette( p ); |
71 | } | 71 | } |
72 | 72 | ||
73 | static const int numButtons = (sizeof(audioButtons)/sizeof(MediaButton)); | 73 | static const int numButtons = (sizeof(audioButtons)/sizeof(MediaButton)); |
74 | 74 | ||
75 | AudioWidget::AudioWidget(QWidget* parent, const char* name, WFlags f) : | 75 | AudioWidget::AudioWidget(QWidget* parent, const char* name, WFlags f) : |
76 | QWidget( parent, name, f ), songInfo( this ), slider( Qt::Horizontal, this ), time( this ) | 76 | QWidget( parent, name, f ), songInfo( this ), slider( Qt::Horizontal, this ), time( this ) |
77 | { | 77 | { |
78 | setCaption( tr("OpiePlayer") ); | 78 | setCaption( tr("OpiePlayer") ); |
79 | // qDebug("<<<<<audioWidget"); | 79 | // qDebug("<<<<<audioWidget"); |
80 | 80 | ||
81 | Config cfg("OpiePlayer"); | 81 | Config cfg("OpiePlayer"); |
82 | cfg.setGroup("Options"); | 82 | cfg.setGroup("Options"); |
83 | skin = cfg.readEntry("Skin","default"); | 83 | skin = cfg.readEntry("Skin","default"); |
84 | //skin = "scaleTest"; | 84 | //skin = "scaleTest"; |
85 | // color of background, frame, degree of transparency | 85 | // color of background, frame, degree of transparency |
86 | 86 | ||
87 | // QString skinPath = "opieplayer/skins/" + skin; | 87 | // QString skinPath = "opieplayer/skins/" + skin; |
88 | QString skinPath; | 88 | QString skinPath; |
89 | skinPath = "opieplayer2/skins/" + skin; | 89 | skinPath = "opieplayer2/skins/" + skin; |
90 | if(!QDir(QString(getenv("OPIEDIR")) +"/pics/"+skinPath).exists()) | 90 | if(!QDir(QString(getenv("OPIEDIR")) +"/pics/"+skinPath).exists()) |
91 | skinPath = "opieplayer2/skins/default"; | 91 | skinPath = "opieplayer2/skins/default"; |
92 | 92 | ||
93 | // qDebug("skin path " + skinPath); | 93 | // qDebug("skin path " + skinPath); |
94 | 94 | ||
95 | pixBg = new QPixmap( Resource::loadPixmap( QString("%1/background").arg(skinPath) ) ); | 95 | pixBg = new QPixmap( Resource::loadPixmap( QString("%1/background").arg(skinPath) ) ); |
96 | imgUp = new QImage( Resource::loadImage( QString("%1/skin_up").arg(skinPath) ) ); | 96 | imgUp = new QImage( Resource::loadImage( QString("%1/skin_up").arg(skinPath) ) ); |
97 | imgDn = new QImage( Resource::loadImage( QString("%1/skin_down").arg(skinPath) ) ); | 97 | imgDn = new QImage( Resource::loadImage( QString("%1/skin_down").arg(skinPath) ) ); |
98 | 98 | ||
99 | imgButtonMask = new QImage( imgUp->width(), imgUp->height(), 8, 255 ); | 99 | imgButtonMask = new QImage( imgUp->width(), imgUp->height(), 8, 255 ); |
100 | imgButtonMask->fill( 0 ); | 100 | imgButtonMask->fill( 0 ); |
101 | 101 | ||
102 | for ( int i = 0; i < 10; i++ ) { | 102 | for ( int i = 0; i < 10; i++ ) { |
103 | QString filename = QString(getenv("OPIEDIR")) + "/pics/" + skinPath + "/skin_mask_" + skin_mask_file_names[i] + ".png"; | 103 | QString filename = QString(getenv("OPIEDIR")) + "/pics/" + skinPath + "/skin_mask_" + skin_mask_file_names[i] + ".png"; |
104 | masks[i] = new QBitmap( filename ); | 104 | masks[i] = new QBitmap( filename ); |
105 | 105 | ||
106 | if ( !masks[i]->isNull() ) { | 106 | if ( !masks[i]->isNull() ) { |
107 | QImage imgMask = masks[i]->convertToImage(); | 107 | QImage imgMask = masks[i]->convertToImage(); |
108 | uchar **dest = imgButtonMask->jumpTable(); | 108 | uchar **dest = imgButtonMask->jumpTable(); |
109 | for ( int y = 0; y < imgUp->height(); y++ ) { | 109 | for ( int y = 0; y < imgUp->height(); y++ ) { |
110 | uchar *line = dest[y]; | 110 | uchar *line = dest[y]; |
111 | for ( int x = 0; x < imgUp->width(); x++ ) | 111 | for ( int x = 0; x < imgUp->width(); x++ ) |
112 | if ( !qRed( imgMask.pixel( x, y ) ) ) | 112 | if ( !qRed( imgMask.pixel( x, y ) ) ) |
113 | line[x] = i + 1; | 113 | line[x] = i + 1; |
114 | } | 114 | } |
115 | } | 115 | } |
116 | 116 | ||
117 | } | 117 | } |
118 | 118 | ||
119 | for ( int i = 0; i < 11; i++ ) { | 119 | for ( int i = 0; i < 11; i++ ) { |
120 | buttonPixUp[i] = NULL; | 120 | buttonPixUp[i] = NULL; |
121 | buttonPixDown[i] = NULL; | 121 | buttonPixDown[i] = NULL; |
122 | } | 122 | } |
123 | 123 | ||
124 | setBackgroundPixmap( *pixBg ); | 124 | QWidget *d = QApplication::desktop(); |
125 | int width = d->width(); | ||
126 | int height = d->height(); | ||
127 | |||
128 | if( (width != pixBg->width() ) || (height != pixBg->height() ) ) { | ||
129 | // qDebug("<<<<<<<< scale image >>>>>>>>>>>>"); | ||
130 | QImage img; | ||
131 | img = pixBg->convertToImage(); | ||
132 | pixBg->convertFromImage( img.smoothScale( width, height)); | ||
133 | } | ||
134 | setBackgroundPixmap( *pixBg); | ||
125 | 135 | ||
126 | songInfo.setFocusPolicy( QWidget::NoFocus ); | 136 | songInfo.setFocusPolicy( QWidget::NoFocus ); |
127 | 137 | ||
128 | // changeTextColor( &songInfo ); | 138 | // changeTextColor( &songInfo ); |
129 | // songInfo.setBackgroundColor( QColor( 167, 212, 167 )); | 139 | // songInfo.setBackgroundColor( QColor( 167, 212, 167 )); |
130 | // songInfo.setFrameStyle( QFrame::NoFrame); | 140 | // songInfo.setFrameStyle( QFrame::NoFrame); |
131 | // songInfo.setFrameStyle( QFrame::WinPanel | QFrame::Sunken ); | 141 | // songInfo.setFrameStyle( QFrame::WinPanel | QFrame::Sunken ); |
132 | //NoFrame | 142 | //NoFrame |
133 | // songInfo.setForegroundColor(Qt::white); | 143 | // songInfo.setForegroundColor(Qt::white); |
134 | 144 | ||
135 | slider.setFixedHeight( 20 ); | 145 | slider.setFixedHeight( 20 ); |
136 | slider.setMinValue( 0 ); | 146 | slider.setMinValue( 0 ); |
137 | slider.setMaxValue( 1 ); | 147 | slider.setMaxValue( 1 ); |
138 | slider.setFocusPolicy( QWidget::NoFocus ); | 148 | slider.setFocusPolicy( QWidget::NoFocus ); |
149 | |||
139 | slider.setBackgroundPixmap( *pixBg ); | 150 | slider.setBackgroundPixmap( *pixBg ); |
140 | 151 | ||
141 | time.setFocusPolicy( QWidget::NoFocus ); | 152 | time.setFocusPolicy( QWidget::NoFocus ); |
142 | time.setAlignment( Qt::AlignCenter ); | 153 | time.setAlignment( Qt::AlignCenter ); |
143 | time.setFrame(FALSE); | 154 | time.setFrame(FALSE); |
144 | changeTextColor( &time ); | 155 | changeTextColor( &time ); |
145 | 156 | ||
146 | resizeEvent( NULL ); | 157 | resizeEvent( NULL ); |
147 | 158 | ||
148 | connect( &slider, SIGNAL( sliderPressed() ), this, SLOT( sliderPressed() ) ); | 159 | connect( &slider, SIGNAL( sliderPressed() ), this, SLOT( sliderPressed() ) ); |
149 | connect( &slider, SIGNAL( sliderReleased() ), this, SLOT( sliderReleased() ) ); | 160 | connect( &slider, SIGNAL( sliderReleased() ), this, SLOT( sliderReleased() ) ); |
150 | 161 | ||
151 | connect( mediaPlayerState, SIGNAL( lengthChanged(long) ), this, SLOT( setLength(long) ) ); | 162 | connect( mediaPlayerState, SIGNAL( lengthChanged(long) ), this, SLOT( setLength(long) ) ); |
152 | connect( mediaPlayerState, SIGNAL( viewChanged(char) ), this, SLOT( setView(char) ) ); | 163 | connect( mediaPlayerState, SIGNAL( viewChanged(char) ), this, SLOT( setView(char) ) ); |
153 | connect( mediaPlayerState, SIGNAL( loopingToggled(bool) ), this, SLOT( setLooping(bool) ) ); | 164 | connect( mediaPlayerState, SIGNAL( loopingToggled(bool) ), this, SLOT( setLooping(bool) ) ); |
154 | // connect( mediaPlayerState, SIGNAL( pausedToggled(bool) ), this, SLOT( setPaused(bool) ) ); | 165 | // connect( mediaPlayerState, SIGNAL( pausedToggled(bool) ), this, SLOT( setPaused(bool) ) ); |
155 | connect( mediaPlayerState, SIGNAL( playingToggled(bool) ), this, SLOT( setPlaying(bool) ) ); | 166 | connect( mediaPlayerState, SIGNAL( playingToggled(bool) ), this, SLOT( setPlaying(bool) ) ); |
156 | 167 | ||
157 | // Intialise state | 168 | // Intialise state |
158 | setLength( mediaPlayerState->length() ); | 169 | setLength( mediaPlayerState->length() ); |
159 | setPosition( mediaPlayerState->position() ); | 170 | setPosition( mediaPlayerState->position() ); |
160 | setLooping( mediaPlayerState->fullscreen() ); | 171 | setLooping( mediaPlayerState->fullscreen() ); |
161 | // setPaused( mediaPlayerState->paused() ); | 172 | // setPaused( mediaPlayerState->paused() ); |
162 | setPlaying( mediaPlayerState->playing() ); | 173 | setPlaying( mediaPlayerState->playing() ); |
163 | this->setFocus(); | 174 | this->setFocus(); |
164 | } | 175 | } |
165 | 176 | ||
166 | 177 | ||
167 | AudioWidget::~AudioWidget() { | 178 | AudioWidget::~AudioWidget() { |
168 | // setPlaying( false); | 179 | // setPlaying( false); |
169 | 180 | ||
170 | for ( int i = 0; i < 10; i++ ) { | 181 | for ( int i = 0; i < 10; i++ ) { |
171 | if(buttonPixUp[i]) delete buttonPixUp[i]; | 182 | if(buttonPixUp[i]) delete buttonPixUp[i]; |
172 | if(buttonPixDown[i]) delete buttonPixDown[i]; | 183 | if(buttonPixDown[i]) delete buttonPixDown[i]; |
173 | } | 184 | } |
174 | if(pixBg) delete pixBg; | 185 | if(pixBg) delete pixBg; |
175 | if(imgUp) delete imgUp; | 186 | if(imgUp) delete imgUp; |
176 | if(imgDn) delete imgDn; | 187 | if(imgDn) delete imgDn; |
177 | if(imgButtonMask) delete imgButtonMask; | 188 | if(imgButtonMask) delete imgButtonMask; |
178 | for ( int i = 0; i < 10; i++ ) { | 189 | for ( int i = 0; i < 10; i++ ) { |
179 | if(masks[i]) delete masks[i]; | 190 | if(masks[i]) delete masks[i]; |
180 | } | 191 | } |
181 | } | 192 | } |
182 | 193 | ||
183 | 194 | ||
184 | QPixmap *combineImageWithBackground( QImage img, QPixmap bg, QPoint offset ) { | 195 | QPixmap *combineImageWithBackground( QImage img, QPixmap bg, QPoint offset ) { |
185 | QPixmap pix( img.width(), img.height() ); | 196 | QPixmap pix( img.width(), img.height() ); |
186 | QPainter p( &pix ); | 197 | QPainter p( &pix ); |
187 | p.drawTiledPixmap( pix.rect(), bg, offset ); | 198 | p.drawTiledPixmap( pix.rect(), bg, offset ); |
188 | p.drawImage( 0, 0, img ); | 199 | p.drawImage( 0, 0, img ); |
189 | return new QPixmap( pix ); | 200 | return new QPixmap( pix ); |
190 | } | 201 | } |
191 | 202 | ||
192 | 203 | ||
193 | QPixmap *maskPixToMask( QPixmap pix, QBitmap mask ) | 204 | QPixmap *maskPixToMask( QPixmap pix, QBitmap mask ) |
194 | { | 205 | { |
195 | QPixmap *pixmap = new QPixmap( pix ); | 206 | QPixmap *pixmap = new QPixmap( pix ); |
196 | pixmap->setMask( mask ); | 207 | pixmap->setMask( mask ); |
197 | return pixmap; | 208 | return pixmap; |
198 | } | 209 | } |
199 | 210 | ||
200 | 211 | ||
201 | 212 | ||
202 | void AudioWidget::resizeEvent( QResizeEvent * ) { | 213 | void AudioWidget::resizeEvent( QResizeEvent * ) { |
203 | int h = height(); | 214 | int h = height(); |
204 | int w = width(); | 215 | int w = width(); |
205 | 216 | ||
206 | songInfo.setGeometry( QRect( 2, 10, w - 4, 20 ) ); | 217 | songInfo.setGeometry( QRect( 2, 10, w - 4, 20 ) ); |
207 | slider.setFixedWidth( w - 110 ); | 218 | slider.setFixedWidth( w - 110 ); |
208 | slider.setGeometry( QRect( 15, h - 30, w - 90, 20 ) ); | 219 | slider.setGeometry( QRect( 15, h - 30, w - 90, 20 ) ); |
209 | slider.setBackgroundOrigin( QWidget::ParentOrigin ); | 220 | slider.setBackgroundOrigin( QWidget::ParentOrigin ); |
210 | time.setGeometry( QRect( w - 85, h - 30, 70, 20 ) ); | 221 | time.setGeometry( QRect( w - 85, h - 30, 70, 20 ) ); |
211 | 222 | ||
212 | xoff = ( w - imgUp->width() ) / 2; | 223 | xoff = ( w - imgUp->width() ) / 2; |
213 | yoff = (( h - imgUp->height() ) / 2) - 10; | 224 | yoff = (( h - imgUp->height() ) / 2) - 10; |
214 | QPoint p( xoff, yoff ); | 225 | QPoint p( xoff, yoff ); |
215 | 226 | ||
216 | QPixmap *pixUp = combineImageWithBackground( *imgUp, *pixBg, p ); | 227 | QPixmap *pixUp = combineImageWithBackground( *imgUp, *pixBg, p ); |
217 | QPixmap *pixDn = combineImageWithBackground( *imgDn, *pixBg, p ); | 228 | QPixmap *pixDn = combineImageWithBackground( *imgDn, *pixBg, p ); |
218 | 229 | ||
219 | for ( int i = 0; i < 10; i++ ) { | 230 | for ( int i = 0; i < 10; i++ ) { |
220 | if ( !masks[i]->isNull() ) { | 231 | if ( !masks[i]->isNull() ) { |
221 | delete buttonPixUp[i]; | 232 | delete buttonPixUp[i]; |
222 | delete buttonPixDown[i]; | 233 | delete buttonPixDown[i]; |
223 | buttonPixUp[i] = maskPixToMask( *pixUp, *masks[i] ); | 234 | buttonPixUp[i] = maskPixToMask( *pixUp, *masks[i] ); |
224 | buttonPixDown[i] = maskPixToMask( *pixDn, *masks[i] ); | 235 | buttonPixDown[i] = maskPixToMask( *pixDn, *masks[i] ); |
225 | } | 236 | } |
226 | } | 237 | } |
227 | 238 | ||
228 | delete pixUp; | 239 | delete pixUp; |
229 | delete pixDn; | 240 | delete pixDn; |
230 | } | 241 | } |
231 | 242 | ||
232 | 243 | ||
233 | static bool audioSliderBeingMoved = FALSE; | 244 | static bool audioSliderBeingMoved = FALSE; |
234 | 245 | ||
235 | void AudioWidget::sliderPressed() { | 246 | void AudioWidget::sliderPressed() { |
236 | audioSliderBeingMoved = TRUE; | 247 | audioSliderBeingMoved = TRUE; |
237 | } | 248 | } |
238 | 249 | ||
239 | 250 | ||
240 | void AudioWidget::sliderReleased() { | 251 | void AudioWidget::sliderReleased() { |
241 | audioSliderBeingMoved = FALSE; | 252 | audioSliderBeingMoved = FALSE; |
242 | if ( slider.width() == 0 ) | 253 | if ( slider.width() == 0 ) |
243 | return; | 254 | return; |
244 | long val = long((double)slider.value() * mediaPlayerState->length() / slider.width()); | 255 | long val = long((double)slider.value() * mediaPlayerState->length() / slider.width()); |
245 | mediaPlayerState->setPosition( val ); | 256 | mediaPlayerState->setPosition( val ); |
246 | } | 257 | } |
247 | 258 | ||
248 | 259 | ||
249 | void AudioWidget::setPosition( long i ) { | 260 | void AudioWidget::setPosition( long i ) { |
250 | // qDebug("set position %d",i); | 261 | // qDebug("set position %d",i); |
251 | long length = mediaPlayerState->length(); | 262 | long length = mediaPlayerState->length(); |
252 | updateSlider( i, length ); | 263 | updateSlider( i, length ); |
253 | } | 264 | } |
254 | 265 | ||
255 | 266 | ||
256 | void AudioWidget::setLength( long max ) { | 267 | void AudioWidget::setLength( long max ) { |
257 | updateSlider( mediaPlayerState->position(), max ); | 268 | updateSlider( mediaPlayerState->position(), max ); |
258 | } | 269 | } |
259 | 270 | ||
260 | 271 | ||
261 | void AudioWidget::setView( char view ) { | 272 | void AudioWidget::setView( char view ) { |
262 | 273 | ||
263 | if (mediaPlayerState->isStreaming) { | 274 | if (mediaPlayerState->isStreaming) { |
264 | if( !slider.isHidden()) slider.hide(); | 275 | if( !slider.isHidden()) slider.hide(); |
265 | disconnect( mediaPlayerState, SIGNAL( positionChanged(long) ),this, SLOT( setPosition(long) ) ); | 276 | disconnect( mediaPlayerState, SIGNAL( positionChanged(long) ),this, SLOT( setPosition(long) ) ); |
266 | disconnect( mediaPlayerState, SIGNAL( positionUpdated(long) ),this, SLOT( setPosition(long) ) ); | 277 | disconnect( mediaPlayerState, SIGNAL( positionUpdated(long) ),this, SLOT( setPosition(long) ) ); |
267 | } else { | 278 | } else { |
268 | // this stops the slider from being moved, thus | 279 | // this stops the slider from being moved, thus |
269 | // does not stop stream when it reaches the end | 280 | // does not stop stream when it reaches the end |
270 | slider.show(); | 281 | slider.show(); |
271 | connect( mediaPlayerState, SIGNAL( positionChanged(long) ),this, SLOT( setPosition(long) ) ); | 282 | connect( mediaPlayerState, SIGNAL( positionChanged(long) ),this, SLOT( setPosition(long) ) ); |
272 | connect( mediaPlayerState, SIGNAL( positionUpdated(long) ),this, SLOT( setPosition(long) ) ); | 283 | connect( mediaPlayerState, SIGNAL( positionUpdated(long) ),this, SLOT( setPosition(long) ) ); |
273 | } | 284 | } |
274 | 285 | ||
275 | if ( view == 'a' ) { | 286 | if ( view == 'a' ) { |
276 | startTimer( 150 ); | 287 | startTimer( 150 ); |
277 | // show(); | 288 | // show(); |
278 | showMaximized(); | 289 | showMaximized(); |
279 | } else { | 290 | } else { |
280 | killTimers(); | 291 | killTimers(); |
281 | hide(); | 292 | hide(); |
282 | } | 293 | } |
283 | 294 | ||
284 | } | 295 | } |
285 | 296 | ||
286 | 297 | ||
287 | static QString timeAsString( long length ) { | 298 | static QString timeAsString( long length ) { |
288 | length /= 44100; | 299 | length /= 44100; |
289 | int minutes = length / 60; | 300 | int minutes = length / 60; |
290 | int seconds = length % 60; | 301 | int seconds = length % 60; |
291 | return QString("%1:%2%3").arg( minutes ).arg( seconds / 10 ).arg( seconds % 10 ); | 302 | return QString("%1:%2%3").arg( minutes ).arg( seconds / 10 ).arg( seconds % 10 ); |
292 | } | 303 | } |
293 | 304 | ||
294 | void AudioWidget::updateSlider( long i, long max ) { | 305 | void AudioWidget::updateSlider( long i, long max ) { |
295 | this->setFocus(); | 306 | this->setFocus(); |
296 | time.setText( timeAsString( i ) + " / " + timeAsString( max ) ); | 307 | time.setText( timeAsString( i ) + " / " + timeAsString( max ) ); |
297 | 308 | ||
298 | if ( max == 0 ) | 309 | if ( max == 0 ) |
299 | return; | 310 | return; |
300 | // Will flicker too much if we don't do this | 311 | // Will flicker too much if we don't do this |
301 | // Scale to something reasonable | 312 | // Scale to something reasonable |
302 | int width = slider.width(); | 313 | int width = slider.width(); |
303 | int val = int((double)i * width / max); | 314 | int val = int((double)i * width / max); |
304 | if ( !audioSliderBeingMoved ) { | 315 | if ( !audioSliderBeingMoved ) { |
305 | if ( slider.value() != val ) | 316 | if ( slider.value() != val ) |
306 | slider.setValue( val ); | 317 | slider.setValue( val ); |
307 | if ( slider.maxValue() != width ) | 318 | if ( slider.maxValue() != width ) |
308 | slider.setMaxValue( width ); | 319 | slider.setMaxValue( width ); |
309 | } | 320 | } |
310 | } | 321 | } |
311 | 322 | ||
312 | 323 | ||
313 | void AudioWidget::setToggleButton( int i, bool down ) { | 324 | void AudioWidget::setToggleButton( int i, bool down ) { |
314 | if ( down != audioButtons[i].isDown ) | 325 | if ( down != audioButtons[i].isDown ) |
315 | toggleButton( i ); | 326 | toggleButton( i ); |
316 | } | 327 | } |
317 | 328 | ||
318 | 329 | ||
319 | void AudioWidget::toggleButton( int i ) { | 330 | void AudioWidget::toggleButton( int i ) { |
320 | audioButtons[i].isDown = !audioButtons[i].isDown; | 331 | audioButtons[i].isDown = !audioButtons[i].isDown; |
321 | QPainter p(this); | 332 | QPainter p(this); |
322 | paintButton ( &p, i ); | 333 | paintButton ( &p, i ); |
323 | } | 334 | } |
324 | 335 | ||
325 | 336 | ||
326 | void AudioWidget::paintButton( QPainter *p, int i ) { | 337 | void AudioWidget::paintButton( QPainter *p, int i ) { |
327 | if ( audioButtons[i].isDown ) | 338 | if ( audioButtons[i].isDown ) |
328 | p->drawPixmap( xoff, yoff, *buttonPixDown[i] ); | 339 | p->drawPixmap( xoff, yoff, *buttonPixDown[i] ); |
329 | else | 340 | else |
330 | p->drawPixmap( xoff, yoff, *buttonPixUp[i] ); | 341 | p->drawPixmap( xoff, yoff, *buttonPixUp[i] ); |
331 | } | 342 | } |
332 | 343 | ||
333 | 344 | ||
334 | void AudioWidget::timerEvent( QTimerEvent * ) { | 345 | void AudioWidget::timerEvent( QTimerEvent * ) { |
335 | /* | 346 | /* |
336 | int x = audioButtons[AudioPlay].xPos; | 347 | int x = audioButtons[AudioPlay].xPos; |
337 | int y = audioButtons[AudioPlay].yPos; | 348 | int y = audioButtons[AudioPlay].yPos; |
338 | QPainter p( this ); | 349 | QPainter p( this ); |
339 | // Optimize to only draw the little bit of the changing images which is different | 350 | // Optimize to only draw the little bit of the changing images which is different |
340 | p.drawPixmap( x + 14, y + 8, *pixmaps[3], 32 * frame, 0, 32, 32 ); | 351 | p.drawPixmap( x + 14, y + 8, *pixmaps[3], 32 * frame, 0, 32, 32 ); |
341 | p.drawPixmap( x + 37, y + 37, *pixmaps[2], 18 * AudioPlay, 0, 6, 3 ); | 352 | p.drawPixmap( x + 37, y + 37, *pixmaps[2], 18 * AudioPlay, 0, 6, 3 ); |
342 | */ | 353 | */ |
343 | /* | 354 | /* |
344 | static int frame = 0; | 355 | static int frame = 0; |
345 | if ( !mediaPlayerState->paused() && audioButtons[ AudioPlay ].isDown ) { | 356 | if ( !mediaPlayerState->paused() && audioButtons[ AudioPlay ].isDown ) { |
346 | frame = frame >= 7 ? 0 : frame + 1; | 357 | frame = frame >= 7 ? 0 : frame + 1; |
347 | } | 358 | } |
348 | */ | 359 | */ |
349 | } | 360 | } |
350 | 361 | ||
351 | 362 | ||
352 | void AudioWidget::mouseMoveEvent( QMouseEvent *event ) { | 363 | void AudioWidget::mouseMoveEvent( QMouseEvent *event ) { |
353 | for ( int i = 0; i < numButtons; i++ ) { | 364 | for ( int i = 0; i < numButtons; i++ ) { |
354 | if ( event->state() == QMouseEvent::LeftButton ) { | 365 | if ( event->state() == QMouseEvent::LeftButton ) { |
355 | 366 | ||
356 | // The test to see if the mouse click is inside the button or not | 367 | // The test to see if the mouse click is inside the button or not |
357 | int x = event->pos().x() - xoff; | 368 | int x = event->pos().x() - xoff; |
358 | int y = event->pos().y() - yoff; | 369 | int y = event->pos().y() - yoff; |
359 | 370 | ||
360 | bool isOnButton = ( x > 0 && y > 0 && x < imgButtonMask->width() | 371 | bool isOnButton = ( x > 0 && y > 0 && x < imgButtonMask->width() |
361 | && y < imgButtonMask->height() && imgButtonMask->pixelIndex( x, y ) == i + 1 ); | 372 | && y < imgButtonMask->height() && imgButtonMask->pixelIndex( x, y ) == i + 1 ); |
362 | 373 | ||
363 | // if ( isOnButton && i == AudioVolumeUp ) | 374 | // if ( isOnButton && i == AudioVolumeUp ) |
364 | // qDebug("on up"); | 375 | // qDebug("on up"); |
365 | 376 | ||
366 | if ( isOnButton && !audioButtons[i].isHeld ) { | 377 | if ( isOnButton && !audioButtons[i].isHeld ) { |
367 | audioButtons[i].isHeld = TRUE; | 378 | audioButtons[i].isHeld = TRUE; |
368 | toggleButton(i); | 379 | toggleButton(i); |
369 | switch (i) { | 380 | switch (i) { |
370 | case AudioVolumeUp: | 381 | case AudioVolumeUp: |
371 | // qDebug("more clicked"); | 382 | // qDebug("more clicked"); |
372 | emit moreClicked(); | 383 | emit moreClicked(); |
373 | return; | 384 | return; |
374 | case AudioVolumeDown: | 385 | case AudioVolumeDown: |
375 | // qDebug("less clicked"); | 386 | // qDebug("less clicked"); |
376 | emit lessClicked(); | 387 | emit lessClicked(); |
377 | return; | 388 | return; |
378 | case AudioForward: | 389 | case AudioForward: |
379 | emit forwardClicked(); | 390 | emit forwardClicked(); |
380 | return; | 391 | return; |
381 | case AudioBack: | 392 | case AudioBack: |
382 | emit backClicked(); | 393 | emit backClicked(); |
383 | return; | 394 | return; |
384 | } | 395 | } |
385 | } else if ( !isOnButton && audioButtons[i].isHeld ) { | 396 | } else if ( !isOnButton && audioButtons[i].isHeld ) { |
386 | audioButtons[i].isHeld = FALSE; | 397 | audioButtons[i].isHeld = FALSE; |
387 | toggleButton(i); | 398 | toggleButton(i); |
388 | } | 399 | } |
389 | } else { | 400 | } else { |
390 | if ( audioButtons[i].isHeld ) { | 401 | if ( audioButtons[i].isHeld ) { |
391 | audioButtons[i].isHeld = FALSE; | 402 | audioButtons[i].isHeld = FALSE; |
392 | if ( !audioButtons[i].isToggle ) | 403 | if ( !audioButtons[i].isToggle ) |
393 | setToggleButton( i, FALSE ); | 404 | setToggleButton( i, FALSE ); |
394 | switch (i) { | 405 | switch (i) { |
395 | case AudioPlay: | 406 | case AudioPlay: |
396 | if( mediaPlayerState->isPaused ) { | 407 | if( mediaPlayerState->isPaused ) { |
397 | mediaPlayerState->setPaused( FALSE ); | 408 | mediaPlayerState->setPaused( FALSE ); |
398 | return; | 409 | return; |
399 | } else if( !mediaPlayerState->isPaused ) { | 410 | } else if( !mediaPlayerState->isPaused ) { |
400 | mediaPlayerState->setPaused( TRUE ); | 411 | mediaPlayerState->setPaused( TRUE ); |
401 | return; | 412 | return; |
402 | } | 413 | } |
403 | // case AudioPlay: mediaPlayerState->setPlaying(audioButtons[i].isDown); return; | 414 | // case AudioPlay: mediaPlayerState->setPlaying(audioButtons[i].isDown); return; |
404 | case AudioStop: mediaPlayerState->setPlaying(FALSE); return; | 415 | case AudioStop: mediaPlayerState->setPlaying(FALSE); return; |
405 | // case AudioPause: mediaPlayerState->setPaused(audioButtons[i].isDown); return; | 416 | // case AudioPause: mediaPlayerState->setPaused(audioButtons[i].isDown); return; |
406 | case AudioNext: mediaPlayerState->setNext(); return; | 417 | case AudioNext: mediaPlayerState->setNext(); return; |
407 | case AudioPrevious: mediaPlayerState->setPrev(); return; | 418 | case AudioPrevious: mediaPlayerState->setPrev(); return; |
408 | case AudioLoop: mediaPlayerState->setLooping(audioButtons[i].isDown); return; | 419 | case AudioLoop: mediaPlayerState->setLooping(audioButtons[i].isDown); return; |
409 | case AudioVolumeUp: emit moreReleased(); return; | 420 | case AudioVolumeUp: emit moreReleased(); return; |
410 | case AudioVolumeDown: emit lessReleased(); return; | 421 | case AudioVolumeDown: emit lessReleased(); return; |
411 | case AudioPlayList: mediaPlayerState->setList(); return; | 422 | case AudioPlayList: mediaPlayerState->setList(); return; |
412 | } | 423 | } |
413 | } | 424 | } |
414 | } | 425 | } |
415 | } | 426 | } |
416 | } | 427 | } |
417 | 428 | ||
418 | 429 | ||
419 | 430 | ||
420 | void AudioWidget::mousePressEvent( QMouseEvent *event ) { | 431 | void AudioWidget::mousePressEvent( QMouseEvent *event ) { |
421 | mouseMoveEvent( event ); | 432 | mouseMoveEvent( event ); |
422 | } | 433 | } |
423 | 434 | ||
424 | 435 | ||
425 | void AudioWidget::mouseReleaseEvent( QMouseEvent *event ) { | 436 | void AudioWidget::mouseReleaseEvent( QMouseEvent *event ) { |
426 | mouseMoveEvent( event ); | 437 | mouseMoveEvent( event ); |
427 | } | 438 | } |
428 | 439 | ||
429 | 440 | ||
430 | void AudioWidget::showEvent( QShowEvent* ) { | 441 | void AudioWidget::showEvent( QShowEvent* ) { |
431 | QMouseEvent event( QEvent::MouseMove, QPoint( 0, 0 ), 0, 0 ); | 442 | QMouseEvent event( QEvent::MouseMove, QPoint( 0, 0 ), 0, 0 ); |
432 | mouseMoveEvent( &event ); | 443 | mouseMoveEvent( &event ); |
433 | } | 444 | } |
434 | 445 | ||
435 | 446 | ||
436 | void AudioWidget::closeEvent( QCloseEvent* ) { | 447 | void AudioWidget::closeEvent( QCloseEvent* ) { |
437 | mediaPlayerState->setList(); | 448 | mediaPlayerState->setList(); |
438 | } | 449 | } |
439 | 450 | ||
440 | 451 | ||
441 | void AudioWidget::paintEvent( QPaintEvent * pe) { | 452 | void AudioWidget::paintEvent( QPaintEvent * pe) { |
442 | if ( !pe->erased() ) { | 453 | if ( !pe->erased() ) { |
443 | // Combine with background and double buffer | 454 | // Combine with background and double buffer |
444 | QPixmap pix( pe->rect().size() ); | 455 | QPixmap pix( pe->rect().size() ); |
445 | QPainter p( &pix ); | 456 | QPainter p( &pix ); |
446 | p.translate( -pe->rect().topLeft().x(), -pe->rect().topLeft().y() ); | 457 | p.translate( -pe->rect().topLeft().x(), -pe->rect().topLeft().y() ); |
447 | p.drawTiledPixmap( pe->rect(), *pixBg, pe->rect().topLeft() ); | 458 | p.drawTiledPixmap( pe->rect(), *pixBg, pe->rect().topLeft() ); |
448 | for ( int i = 0; i < numButtons; i++ ) | 459 | for ( int i = 0; i < numButtons; i++ ) |
449 | paintButton( &p, i ); | 460 | paintButton( &p, i ); |
450 | QPainter p2( this ); | 461 | QPainter p2( this ); |
451 | p2.drawPixmap( pe->rect().topLeft(), pix ); | 462 | p2.drawPixmap( pe->rect().topLeft(), pix ); |
452 | } else { | 463 | } else { |
453 | QPainter p( this ); | 464 | QPainter p( this ); |
454 | for ( int i = 0; i < numButtons; i++ ) | 465 | for ( int i = 0; i < numButtons; i++ ) |
455 | paintButton( &p, i ); | 466 | paintButton( &p, i ); |
456 | } | 467 | } |
457 | } | 468 | } |
458 | 469 | ||
459 | void AudioWidget::keyReleaseEvent( QKeyEvent *e) | 470 | void AudioWidget::keyReleaseEvent( QKeyEvent *e) |
460 | { | 471 | { |
461 | switch ( e->key() ) { | 472 | switch ( e->key() ) { |
462 | ////////////////////////////// Zaurus keys | 473 | ////////////////////////////// Zaurus keys |
463 | case Key_Home: | 474 | case Key_Home: |
464 | break; | 475 | break; |
465 | case Key_F9: //activity | 476 | case Key_F9: //activity |
466 | hide(); | 477 | hide(); |
467 | // qDebug("Audio F9"); | 478 | // qDebug("Audio F9"); |
468 | break; | 479 | break; |
469 | case Key_F10: //contacts | 480 | case Key_F10: //contacts |
470 | break; | 481 | break; |
471 | case Key_F11: //menu | 482 | case Key_F11: //menu |
472 | break; | 483 | break; |
473 | case Key_F12: //home | 484 | case Key_F12: //home |
474 | break; | 485 | break; |
475 | case Key_F13: //mail | 486 | case Key_F13: //mail |
476 | break; | 487 | break; |
477 | case Key_Space: { | 488 | case Key_Space: { |
478 | 489 | ||
479 | if(mediaPlayerState->playing()) { | 490 | if(mediaPlayerState->playing()) { |
480 | // toggleButton(1); | 491 | // toggleButton(1); |
481 | mediaPlayerState->setPlaying(FALSE); | 492 | mediaPlayerState->setPlaying(FALSE); |
482 | // toggleButton(1); | 493 | // toggleButton(1); |
483 | } else { | 494 | } else { |
484 | // toggleButton(0); | 495 | // toggleButton(0); |
485 | mediaPlayerState->setPlaying(TRUE); | 496 | mediaPlayerState->setPlaying(TRUE); |
486 | // toggleButton(0); | 497 | // toggleButton(0); |
487 | } | 498 | } |
488 | } | 499 | } |
489 | break; | 500 | break; |
490 | case Key_Down: //volume | 501 | case Key_Down: //volume |
491 | // toggleButton(6); | 502 | // toggleButton(6); |
492 | emit lessClicked(); | 503 | emit lessClicked(); |
493 | emit lessReleased(); | 504 | emit lessReleased(); |
494 | // toggleButton(6); | 505 | // toggleButton(6); |
495 | break; | 506 | break; |
496 | case Key_Up: //volume | 507 | case Key_Up: //volume |
497 | // toggleButton(5); | 508 | // toggleButton(5); |
498 | emit moreClicked(); | 509 | emit moreClicked(); |
499 | emit moreReleased(); | 510 | emit moreReleased(); |
500 | // toggleButton(5); | 511 | // toggleButton(5); |
501 | break; | 512 | break; |
502 | case Key_Right: //next in playlist | 513 | case Key_Right: //next in playlist |
503 | // toggleButton(3); | 514 | // toggleButton(3); |
504 | mediaPlayerState->setNext(); | 515 | mediaPlayerState->setNext(); |
505 | // toggleButton(3); | 516 | // toggleButton(3); |
506 | break; | 517 | break; |
507 | case Key_Left: // previous in playlist | 518 | case Key_Left: // previous in playlist |
508 | // toggleButton(4); | 519 | // toggleButton(4); |
509 | mediaPlayerState->setPrev(); | 520 | mediaPlayerState->setPrev(); |
510 | // toggleButton(4); | 521 | // toggleButton(4); |
511 | break; | 522 | break; |
512 | case Key_Escape: | 523 | case Key_Escape: |
513 | break; | 524 | break; |
514 | 525 | ||
515 | }; | 526 | }; |
516 | } | 527 | } |
diff --git a/core/multimedia/opieplayer/videowidget.cpp b/core/multimedia/opieplayer/videowidget.cpp index 02c8568..d9a9478 100644 --- a/core/multimedia/opieplayer/videowidget.cpp +++ b/core/multimedia/opieplayer/videowidget.cpp | |||
@@ -1,640 +1,646 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of Qtopia Environment. | 4 | ** This file is part of Qtopia Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
7 | ** GNU General Public License version 2 as published by the Free Software | 7 | ** GNU General Public License version 2 as published by the Free Software |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | #include <qpe/resource.h> | 20 | #include <qpe/resource.h> |
21 | #include <qpe/mediaplayerplugininterface.h> | 21 | #include <qpe/mediaplayerplugininterface.h> |
22 | #include <qpe/config.h> | 22 | #include <qpe/config.h> |
23 | #include <qpe/qpeapplication.h> | 23 | #include <qpe/qpeapplication.h> |
24 | 24 | ||
25 | #include <qdir.h> | 25 | #include <qdir.h> |
26 | #include <qwidget.h> | 26 | #include <qwidget.h> |
27 | #include <qpainter.h> | 27 | #include <qpainter.h> |
28 | #include <qpixmap.h> | 28 | #include <qpixmap.h> |
29 | #include <qslider.h> | 29 | #include <qslider.h> |
30 | #include <qdrawutil.h> | 30 | #include <qdrawutil.h> |
31 | #include "videowidget.h" | 31 | #include "videowidget.h" |
32 | #include "mediaplayerstate.h" | 32 | #include "mediaplayerstate.h" |
33 | 33 | ||
34 | 34 | ||
35 | #ifdef Q_WS_QWS | 35 | #ifdef Q_WS_QWS |
36 | # define USE_DIRECT_PAINTER | 36 | # define USE_DIRECT_PAINTER |
37 | # include <qdirectpainter_qws.h> | 37 | # include <qdirectpainter_qws.h> |
38 | # include <qgfxraster_qws.h> | 38 | # include <qgfxraster_qws.h> |
39 | #endif | 39 | #endif |
40 | 40 | ||
41 | 41 | ||
42 | extern MediaPlayerState *mediaPlayerState; | 42 | extern MediaPlayerState *mediaPlayerState; |
43 | 43 | ||
44 | 44 | ||
45 | static const int xo = 2; // movable x offset | 45 | static const int xo = 2; // movable x offset |
46 | static const int yo = 0; // movable y offset | 46 | static const int yo = 0; // movable y offset |
47 | 47 | ||
48 | 48 | ||
49 | struct MediaButton { | 49 | struct MediaButton { |
50 | // int xPos, yPos; | 50 | // int xPos, yPos; |
51 | bool isToggle, isHeld, isDown; | 51 | bool isToggle, isHeld, isDown; |
52 | // int controlType; | 52 | // int controlType; |
53 | }; | 53 | }; |
54 | 54 | ||
55 | 55 | ||
56 | // Layout information for the videoButtons (and if it is a toggle button or not) | 56 | // Layout information for the videoButtons (and if it is a toggle button or not) |
57 | MediaButton videoButtons[] = { | 57 | MediaButton videoButtons[] = { |
58 | { FALSE, FALSE, FALSE }, // stop | 58 | { FALSE, FALSE, FALSE }, // stop |
59 | { FALSE, FALSE, FALSE }, // play | 59 | { FALSE, FALSE, FALSE }, // play |
60 | { FALSE, FALSE, FALSE }, // previous | 60 | { FALSE, FALSE, FALSE }, // previous |
61 | { FALSE, FALSE, FALSE }, // next | 61 | { FALSE, FALSE, FALSE }, // next |
62 | { FALSE, FALSE, FALSE }, // volUp | 62 | { FALSE, FALSE, FALSE }, // volUp |
63 | { FALSE, FALSE, FALSE }, // volDown | 63 | { FALSE, FALSE, FALSE }, // volDown |
64 | { TRUE, FALSE, FALSE } // fullscreen | 64 | { TRUE, FALSE, FALSE } // fullscreen |
65 | }; | 65 | }; |
66 | 66 | ||
67 | //static const int numButtons = (sizeof(videoButtons)/sizeof(MediaButton)); | 67 | //static const int numButtons = (sizeof(videoButtons)/sizeof(MediaButton)); |
68 | 68 | ||
69 | const char *skinV_mask_file_names[7] = { | 69 | const char *skinV_mask_file_names[7] = { |
70 | "stop","play","back","fwd","up","down","full" | 70 | "stop","play","back","fwd","up","down","full" |
71 | }; | 71 | }; |
72 | 72 | ||
73 | static const int numVButtons = (sizeof(videoButtons)/sizeof(MediaButton)); | 73 | static const int numVButtons = (sizeof(videoButtons)/sizeof(MediaButton)); |
74 | 74 | ||
75 | VideoWidget::VideoWidget(QWidget* parent, const char* name, WFlags f) : | 75 | VideoWidget::VideoWidget(QWidget* parent, const char* name, WFlags f) : |
76 | QWidget( parent, name, f ), scaledWidth( 0 ), scaledHeight( 0 ) | 76 | QWidget( parent, name, f ), scaledWidth( 0 ), scaledHeight( 0 ) |
77 | { | 77 | { |
78 | setCaption( tr("OpiePlayer") ); | 78 | setCaption( tr("OpiePlayer") ); |
79 | Config cfg("OpiePlayer"); | 79 | Config cfg("OpiePlayer"); |
80 | 80 | ||
81 | cfg.setGroup("Options"); | 81 | cfg.setGroup("Options"); |
82 | skin = cfg.readEntry("Skin","default"); | 82 | skin = cfg.readEntry("Skin","default"); |
83 | 83 | ||
84 | QString skinPath; | 84 | QString skinPath; |
85 | skinPath = "opieplayer2/skins/" + skin; | 85 | skinPath = "opieplayer2/skins/" + skin; |
86 | if(!QDir(QString(getenv("OPIEDIR")) +"/pics/"+skinPath).exists()) | 86 | if(!QDir(QString(getenv("OPIEDIR")) +"/pics/"+skinPath).exists()) |
87 | skinPath = "opieplayer2/skins/default"; | 87 | skinPath = "opieplayer2/skins/default"; |
88 | 88 | ||
89 | // qDebug("skin path " + skinPath); | 89 | // qDebug("skin path " + skinPath); |
90 | 90 | ||
91 | // QString skinPath = "opieplayer2/skins/" + skin; | 91 | // QString skinPath = "opieplayer2/skins/" + skin; |
92 | 92 | ||
93 | pixBg = new QPixmap( Resource::loadPixmap( QString("%1/background").arg(skinPath) ) ); | 93 | pixBg = new QPixmap( Resource::loadPixmap( QString("%1/background").arg(skinPath) ) ); |
94 | imgUp = new QImage( Resource::loadImage( QString("%1/skinV_up").arg(skinPath) ) ); | 94 | imgUp = new QImage( Resource::loadImage( QString("%1/skinV_up").arg(skinPath) ) ); |
95 | imgDn = new QImage( Resource::loadImage( QString("%1/skinV_down").arg(skinPath) ) ); | 95 | imgDn = new QImage( Resource::loadImage( QString("%1/skinV_down").arg(skinPath) ) ); |
96 | 96 | ||
97 | imgButtonMask = new QImage( imgUp->width(), imgUp->height(), 8, 255 ); | 97 | imgButtonMask = new QImage( imgUp->width(), imgUp->height(), 8, 255 ); |
98 | imgButtonMask->fill( 0 ); | 98 | imgButtonMask->fill( 0 ); |
99 | 99 | ||
100 | for ( int i = 0; i < 7; i++ ) | 100 | for ( int i = 0; i < 7; i++ ) { |
101 | { | ||
102 | QString filename = QString( QPEApplication::qpeDir() + "/pics/" + skinPath + | 101 | QString filename = QString( QPEApplication::qpeDir() + "/pics/" + skinPath + |
103 | "/skinV_mask_" + skinV_mask_file_names[i] + ".png" ); | 102 | "/skinV_mask_" + skinV_mask_file_names[i] + ".png" ); |
104 | // qDebug("loading "+filename); | 103 | // qDebug("loading "+filename); |
105 | masks[i] = new QBitmap( filename ); | 104 | masks[i] = new QBitmap( filename ); |
106 | 105 | ||
107 | if ( !masks[i]->isNull() ) | 106 | if ( !masks[i]->isNull() ) { |
108 | { | ||
109 | QImage imgMask = masks[i]->convertToImage(); | 107 | QImage imgMask = masks[i]->convertToImage(); |
110 | uchar **dest = imgButtonMask->jumpTable(); | 108 | uchar **dest = imgButtonMask->jumpTable(); |
111 | for ( int y = 0; y < imgUp->height(); y++ ) | 109 | for ( int y = 0; y < imgUp->height(); y++ ) { |
112 | { | ||
113 | uchar *line = dest[y]; | 110 | uchar *line = dest[y]; |
114 | for ( int x = 0; x < imgUp->width(); x++ ) | 111 | for ( int x = 0; x < imgUp->width(); x++ ) { |
115 | { | ||
116 | if ( !qRed( imgMask.pixel( x, y ) ) ) | 112 | if ( !qRed( imgMask.pixel( x, y ) ) ) |
117 | line[x] = i + 1; | 113 | line[x] = i + 1; |
118 | } | 114 | } |
119 | } | 115 | } |
120 | } | 116 | } |
121 | } | 117 | } |
122 | // qDebug("finished loading first pics"); | 118 | // qDebug("finished loading first pics"); |
123 | for ( int i = 0; i < 7; i++ ) | 119 | for ( int i = 0; i < 7; i++ ) { |
124 | { | ||
125 | buttonPixUp[i] = NULL; | 120 | buttonPixUp[i] = NULL; |
126 | buttonPixDown[i] = NULL; | 121 | buttonPixDown[i] = NULL; |
127 | } | 122 | } |
128 | 123 | ||
124 | |||
125 | QWidget *d = QApplication::desktop(); | ||
126 | int width = d->width(); | ||
127 | int height = d->height(); | ||
128 | |||
129 | if( (width != pixBg->width() ) || (height != pixBg->height() ) ) { | ||
130 | // qDebug("<<<<<<<< scale image >>>>>>>>>>>>"); | ||
131 | QImage img; | ||
132 | img = pixBg->convertToImage(); | ||
133 | pixBg->convertFromImage( img.smoothScale( width, height)); | ||
134 | } | ||
129 | setBackgroundPixmap( *pixBg ); | 135 | setBackgroundPixmap( *pixBg ); |
130 | 136 | ||
131 | currentFrame = new QImage( 220 + 2, 160, (QPixmap::defaultDepth() == 16) ? 16 : 32 ); | 137 | currentFrame = new QImage( 220 + 2, 160, (QPixmap::defaultDepth() == 16) ? 16 : 32 ); |
132 | 138 | ||
133 | slider = new QSlider( Qt::Horizontal, this ); | 139 | slider = new QSlider( Qt::Horizontal, this ); |
134 | slider->setMinValue( 0 ); | 140 | slider->setMinValue( 0 ); |
135 | slider->setMaxValue( 1 ); | 141 | slider->setMaxValue( 1 ); |
136 | slider->setBackgroundPixmap( Resource::loadPixmap( backgroundPix ) ); | 142 | slider->setBackgroundPixmap( Resource::loadPixmap( backgroundPix ) ); |
137 | slider->setFocusPolicy( QWidget::NoFocus ); | 143 | slider->setFocusPolicy( QWidget::NoFocus ); |
138 | // slider->setGeometry( QRect( 7, 250, 220, 20 ) ); | 144 | // slider->setGeometry( QRect( 7, 250, 220, 20 ) ); |
139 | 145 | ||
140 | connect( slider, SIGNAL( sliderPressed() ), this, SLOT( sliderPressed() ) ); | 146 | connect( slider, SIGNAL( sliderPressed() ), this, SLOT( sliderPressed() ) ); |
141 | connect( slider, SIGNAL( sliderReleased() ), this, SLOT( sliderReleased() ) ); | 147 | connect( slider, SIGNAL( sliderReleased() ), this, SLOT( sliderReleased() ) ); |
142 | 148 | ||
143 | connect( mediaPlayerState, SIGNAL( lengthChanged(long) ), this, SLOT( setLength(long) ) ); | 149 | connect( mediaPlayerState, SIGNAL( lengthChanged(long) ), this, SLOT( setLength(long) ) ); |
144 | connect( mediaPlayerState, SIGNAL( positionChanged(long) ),this, SLOT( setPosition(long) ) ); | 150 | connect( mediaPlayerState, SIGNAL( positionChanged(long) ),this, SLOT( setPosition(long) ) ); |
145 | connect( mediaPlayerState, SIGNAL( positionUpdated(long) ),this, SLOT( setPosition(long) ) ); | 151 | connect( mediaPlayerState, SIGNAL( positionUpdated(long) ),this, SLOT( setPosition(long) ) ); |
146 | connect( mediaPlayerState, SIGNAL( viewChanged(char) ), this, SLOT( setView(char) ) ); | 152 | connect( mediaPlayerState, SIGNAL( viewChanged(char) ), this, SLOT( setView(char) ) ); |
147 | // connect( mediaPlayerState, SIGNAL( pausedToggled(bool) ), this, SLOT( setPaused(bool) ) ); | 153 | // connect( mediaPlayerState, SIGNAL( pausedToggled(bool) ), this, SLOT( setPaused(bool) ) ); |
148 | connect( mediaPlayerState, SIGNAL( playingToggled(bool) ), this, SLOT( setPlaying(bool) ) ); | 154 | connect( mediaPlayerState, SIGNAL( playingToggled(bool) ), this, SLOT( setPlaying(bool) ) ); |
149 | 155 | ||
150 | // Intialise state | 156 | // Intialise state |
151 | setLength( mediaPlayerState->length() ); | 157 | setLength( mediaPlayerState->length() ); |
152 | setPosition( mediaPlayerState->position() ); | 158 | setPosition( mediaPlayerState->position() ); |
153 | setFullscreen( mediaPlayerState->fullscreen() ); | 159 | setFullscreen( mediaPlayerState->fullscreen() ); |
154 | // setPaused( mediaPlayerState->paused() ); | 160 | // setPaused( mediaPlayerState->paused() ); |
155 | setPlaying( mediaPlayerState->playing() ); | 161 | setPlaying( mediaPlayerState->playing() ); |
156 | } | 162 | } |
157 | 163 | ||
158 | 164 | ||
159 | VideoWidget::~VideoWidget() { | 165 | VideoWidget::~VideoWidget() { |
160 | 166 | ||
161 | for ( int i = 0; i < 7; i++ ) | 167 | for ( int i = 0; i < 7; i++ ) |
162 | { | 168 | { |
163 | delete buttonPixUp[i]; | 169 | delete buttonPixUp[i]; |
164 | delete buttonPixDown[i]; | 170 | delete buttonPixDown[i]; |
165 | } | 171 | } |
166 | 172 | ||
167 | delete pixBg; | 173 | delete pixBg; |
168 | delete imgUp; | 174 | delete imgUp; |
169 | delete imgDn; | 175 | delete imgDn; |
170 | delete imgButtonMask; | 176 | delete imgButtonMask; |
171 | for ( int i = 0; i < 7; i++ ) | 177 | for ( int i = 0; i < 7; i++ ) |
172 | { | 178 | { |
173 | delete masks[i]; | 179 | delete masks[i]; |
174 | } | 180 | } |
175 | 181 | ||
176 | // for ( int i = 0; i < 3; i++ ) | 182 | // for ( int i = 0; i < 3; i++ ) |
177 | // delete pixmaps[i]; | 183 | // delete pixmaps[i]; |
178 | // delete currentFrame; | 184 | // delete currentFrame; |
179 | } | 185 | } |
180 | 186 | ||
181 | 187 | ||
182 | static bool videoSliderBeingMoved = FALSE; | 188 | static bool videoSliderBeingMoved = FALSE; |
183 | 189 | ||
184 | QPixmap *combineVImageWithBackground( QImage img, QPixmap bg, QPoint offset ) { | 190 | QPixmap *combineVImageWithBackground( QImage img, QPixmap bg, QPoint offset ) { |
185 | QPixmap pix( img.width(), img.height() ); | 191 | QPixmap pix( img.width(), img.height() ); |
186 | QPainter p( &pix ); | 192 | QPainter p( &pix ); |
187 | p.drawTiledPixmap( pix.rect(), bg, offset ); | 193 | p.drawTiledPixmap( pix.rect(), bg, offset ); |
188 | p.drawImage( 0, 0, img ); | 194 | p.drawImage( 0, 0, img ); |
189 | return new QPixmap( pix ); | 195 | return new QPixmap( pix ); |
190 | } | 196 | } |
191 | 197 | ||
192 | QPixmap *maskVPixToMask( QPixmap pix, QBitmap mask ) { | 198 | QPixmap *maskVPixToMask( QPixmap pix, QBitmap mask ) { |
193 | QPixmap *pixmap = new QPixmap( pix ); | 199 | QPixmap *pixmap = new QPixmap( pix ); |
194 | pixmap->setMask( mask ); | 200 | pixmap->setMask( mask ); |
195 | return pixmap; | 201 | return pixmap; |
196 | } | 202 | } |
197 | 203 | ||
198 | void VideoWidget::resizeEvent( QResizeEvent * ) { | 204 | void VideoWidget::resizeEvent( QResizeEvent * ) { |
199 | int h = height(); | 205 | int h = height(); |
200 | int w = width(); | 206 | int w = width(); |
201 | //int Vh = 160; | 207 | //int Vh = 160; |
202 | //int Vw = 220; | 208 | //int Vw = 220; |
203 | 209 | ||
204 | slider->setFixedWidth( w - 20 ); | 210 | slider->setFixedWidth( w - 20 ); |
205 | slider->setGeometry( QRect( 15, h - 22, w - 90, 20 ) ); | 211 | slider->setGeometry( QRect( 15, h - 22, w - 90, 20 ) ); |
206 | slider->setBackgroundOrigin( QWidget::ParentOrigin ); | 212 | slider->setBackgroundOrigin( QWidget::ParentOrigin ); |
207 | slider->setFocusPolicy( QWidget::NoFocus ); | 213 | slider->setFocusPolicy( QWidget::NoFocus ); |
208 | slider->setBackgroundPixmap( *pixBg ); | 214 | slider->setBackgroundPixmap( *pixBg ); |
209 | 215 | ||
210 | xoff = 0;// ( imgUp->width() ) / 2; | 216 | xoff = 0;// ( imgUp->width() ) / 2; |
211 | if(w>h) | 217 | if(w>h) |
212 | yoff = 0; | 218 | yoff = 0; |
213 | else | 219 | else |
214 | yoff = 185;//(( Vh - imgUp->height() ) / 2) - 10; | 220 | yoff = 185;//(( Vh - imgUp->height() ) / 2) - 10; |
215 | QPoint p( xoff, yoff ); | 221 | QPoint p( xoff, yoff ); |
216 | 222 | ||
217 | QPixmap *pixUp = combineVImageWithBackground( *imgUp, *pixBg, p ); | 223 | QPixmap *pixUp = combineVImageWithBackground( *imgUp, *pixBg, p ); |
218 | QPixmap *pixDn = combineVImageWithBackground( *imgDn, *pixBg, p ); | 224 | QPixmap *pixDn = combineVImageWithBackground( *imgDn, *pixBg, p ); |
219 | 225 | ||
220 | for ( int i = 0; i < 7; i++ ) | 226 | for ( int i = 0; i < 7; i++ ) |
221 | { | 227 | { |
222 | if ( !masks[i]->isNull() ) | 228 | if ( !masks[i]->isNull() ) |
223 | { | 229 | { |
224 | delete buttonPixUp[i]; | 230 | delete buttonPixUp[i]; |
225 | delete buttonPixDown[i]; | 231 | delete buttonPixDown[i]; |
226 | buttonPixUp[i] = maskVPixToMask( *pixUp, *masks[i] ); | 232 | buttonPixUp[i] = maskVPixToMask( *pixUp, *masks[i] ); |
227 | buttonPixDown[i] = maskVPixToMask( *pixDn, *masks[i] ); | 233 | buttonPixDown[i] = maskVPixToMask( *pixDn, *masks[i] ); |
228 | } | 234 | } |
229 | } | 235 | } |
230 | 236 | ||
231 | delete pixUp; | 237 | delete pixUp; |
232 | delete pixDn; | 238 | delete pixDn; |
233 | } | 239 | } |
234 | 240 | ||
235 | 241 | ||
236 | void VideoWidget::sliderPressed() { | 242 | void VideoWidget::sliderPressed() { |
237 | videoSliderBeingMoved = TRUE; | 243 | videoSliderBeingMoved = TRUE; |
238 | } | 244 | } |
239 | 245 | ||
240 | 246 | ||
241 | void VideoWidget::sliderReleased() { | 247 | void VideoWidget::sliderReleased() { |
242 | videoSliderBeingMoved = FALSE; | 248 | videoSliderBeingMoved = FALSE; |
243 | if ( slider->width() == 0 ) | 249 | if ( slider->width() == 0 ) |
244 | return; | 250 | return; |
245 | long val = long((double)slider->value() * mediaPlayerState->length() / slider->width()); | 251 | long val = long((double)slider->value() * mediaPlayerState->length() / slider->width()); |
246 | mediaPlayerState->setPosition( val ); | 252 | mediaPlayerState->setPosition( val ); |
247 | } | 253 | } |
248 | 254 | ||
249 | 255 | ||
250 | void VideoWidget::setPosition( long i ) { | 256 | void VideoWidget::setPosition( long i ) { |
251 | updateSlider( i, mediaPlayerState->length() ); | 257 | updateSlider( i, mediaPlayerState->length() ); |
252 | } | 258 | } |
253 | 259 | ||
254 | 260 | ||
255 | void VideoWidget::setLength( long max ) { | 261 | void VideoWidget::setLength( long max ) { |
256 | updateSlider( mediaPlayerState->position(), max ); | 262 | updateSlider( mediaPlayerState->position(), max ); |
257 | } | 263 | } |
258 | 264 | ||
259 | 265 | ||
260 | void VideoWidget::setView( char view ) { | 266 | void VideoWidget::setView( char view ) { |
261 | if ( view == 'v' ) | 267 | if ( view == 'v' ) |
262 | { | 268 | { |
263 | makeVisible(); | 269 | makeVisible(); |
264 | } | 270 | } |
265 | else | 271 | else |
266 | { | 272 | { |
267 | // Effectively blank the view next time we show it so it looks nicer | 273 | // Effectively blank the view next time we show it so it looks nicer |
268 | scaledWidth = 0; | 274 | scaledWidth = 0; |
269 | scaledHeight = 0; | 275 | scaledHeight = 0; |
270 | hide(); | 276 | hide(); |
271 | } | 277 | } |
272 | } | 278 | } |
273 | 279 | ||
274 | 280 | ||
275 | void VideoWidget::updateSlider( long i, long max ) { | 281 | void VideoWidget::updateSlider( long i, long max ) { |
276 | // Will flicker too much if we don't do this | 282 | // Will flicker too much if we don't do this |
277 | if ( max == 0 ) | 283 | if ( max == 0 ) |
278 | return; | 284 | return; |
279 | int width = slider->width(); | 285 | int width = slider->width(); |
280 | int val = int((double)i * width / max); | 286 | int val = int((double)i * width / max); |
281 | if ( !mediaPlayerState->fullscreen() && !videoSliderBeingMoved ) | 287 | if ( !mediaPlayerState->fullscreen() && !videoSliderBeingMoved ) |
282 | { | 288 | { |
283 | if ( slider->value() != val ) | 289 | if ( slider->value() != val ) |
284 | slider->setValue( val ); | 290 | slider->setValue( val ); |
285 | if ( slider->maxValue() != width ) | 291 | if ( slider->maxValue() != width ) |
286 | slider->setMaxValue( width ); | 292 | slider->setMaxValue( width ); |
287 | } | 293 | } |
288 | } | 294 | } |
289 | 295 | ||
290 | 296 | ||
291 | void VideoWidget::setToggleButton( int i, bool down ) { | 297 | void VideoWidget::setToggleButton( int i, bool down ) { |
292 | if ( down != videoButtons[i].isDown ) | 298 | if ( down != videoButtons[i].isDown ) |
293 | toggleButton( i ); | 299 | toggleButton( i ); |
294 | } | 300 | } |
295 | 301 | ||
296 | 302 | ||
297 | void VideoWidget::toggleButton( int i ) { | 303 | void VideoWidget::toggleButton( int i ) { |
298 | videoButtons[i].isDown = !videoButtons[i].isDown; | 304 | videoButtons[i].isDown = !videoButtons[i].isDown; |
299 | QPainter p(this); | 305 | QPainter p(this); |
300 | paintButton ( &p, i ); | 306 | paintButton ( &p, i ); |
301 | } | 307 | } |
302 | 308 | ||
303 | 309 | ||
304 | void VideoWidget::paintButton( QPainter *p, int i ) { | 310 | void VideoWidget::paintButton( QPainter *p, int i ) { |
305 | if ( videoButtons[i].isDown ) | 311 | if ( videoButtons[i].isDown ) |
306 | { | 312 | { |
307 | p->drawPixmap( xoff, yoff, *buttonPixDown[i] ); | 313 | p->drawPixmap( xoff, yoff, *buttonPixDown[i] ); |
308 | } | 314 | } |
309 | else | 315 | else |
310 | { | 316 | { |
311 | p->drawPixmap( xoff, yoff, *buttonPixUp[i] ); | 317 | p->drawPixmap( xoff, yoff, *buttonPixUp[i] ); |
312 | } | 318 | } |
313 | } | 319 | } |
314 | 320 | ||
315 | 321 | ||
316 | void VideoWidget::mouseMoveEvent( QMouseEvent *event ) { | 322 | void VideoWidget::mouseMoveEvent( QMouseEvent *event ) { |
317 | for ( int i = 0; i < numVButtons; i++ ) { | 323 | for ( int i = 0; i < numVButtons; i++ ) { |
318 | if ( event->state() == QMouseEvent::LeftButton ) { | 324 | if ( event->state() == QMouseEvent::LeftButton ) { |
319 | // The test to see if the mouse click is inside the button or not | 325 | // The test to see if the mouse click is inside the button or not |
320 | int x = event->pos().x() - xoff; | 326 | int x = event->pos().x() - xoff; |
321 | int y = event->pos().y() - yoff; | 327 | int y = event->pos().y() - yoff; |
322 | 328 | ||
323 | bool isOnButton = ( x > 0 && y > 0 && x < imgButtonMask->width() | 329 | bool isOnButton = ( x > 0 && y > 0 && x < imgButtonMask->width() |
324 | && y < imgButtonMask->height() | 330 | && y < imgButtonMask->height() |
325 | && imgButtonMask->pixelIndex( x, y ) == i + 1 ); | 331 | && imgButtonMask->pixelIndex( x, y ) == i + 1 ); |
326 | 332 | ||
327 | if ( isOnButton && !videoButtons[i].isHeld ) { | 333 | if ( isOnButton && !videoButtons[i].isHeld ) { |
328 | videoButtons[i].isHeld = TRUE; | 334 | videoButtons[i].isHeld = TRUE; |
329 | toggleButton(i); | 335 | toggleButton(i); |
330 | 336 | ||
331 | switch (i) { | 337 | switch (i) { |
332 | case VideoVolUp: | 338 | case VideoVolUp: |
333 | emit moreClicked(); | 339 | emit moreClicked(); |
334 | return; | 340 | return; |
335 | case VideoVolDown: | 341 | case VideoVolDown: |
336 | emit lessClicked(); | 342 | emit lessClicked(); |
337 | return; | 343 | return; |
338 | } | 344 | } |
339 | } else if ( !isOnButton && videoButtons[i].isHeld ) { | 345 | } else if ( !isOnButton && videoButtons[i].isHeld ) { |
340 | videoButtons[i].isHeld = FALSE; | 346 | videoButtons[i].isHeld = FALSE; |
341 | toggleButton(i); | 347 | toggleButton(i); |
342 | } | 348 | } |
343 | } else { | 349 | } else { |
344 | 350 | ||
345 | if ( videoButtons[i].isHeld ) { | 351 | if ( videoButtons[i].isHeld ) { |
346 | videoButtons[i].isHeld = FALSE; | 352 | videoButtons[i].isHeld = FALSE; |
347 | if ( !videoButtons[i].isToggle ) { | 353 | if ( !videoButtons[i].isToggle ) { |
348 | setToggleButton( i, FALSE ); | 354 | setToggleButton( i, FALSE ); |
349 | } | 355 | } |
350 | 356 | ||
351 | switch(i) { | 357 | switch(i) { |
352 | 358 | ||
353 | case VideoPlay: { | 359 | case VideoPlay: { |
354 | // qDebug("play"); | 360 | // qDebug("play"); |
355 | if( !mediaPlayerState->playing()) { | 361 | if( !mediaPlayerState->playing()) { |
356 | mediaPlayerState->setPlaying( true); | 362 | mediaPlayerState->setPlaying( true); |
357 | setToggleButton( i-1, false ); | 363 | setToggleButton( i-1, false ); |
358 | setToggleButton( i, false ); | 364 | setToggleButton( i, false ); |
359 | return; | 365 | return; |
360 | } | 366 | } |
361 | if( mediaPlayerState->isPaused ) { | 367 | if( mediaPlayerState->isPaused ) { |
362 | // qDebug("isPaused"); | 368 | // qDebug("isPaused"); |
363 | setToggleButton( i, FALSE ); | 369 | setToggleButton( i, FALSE ); |
364 | mediaPlayerState->setPaused( FALSE ); | 370 | mediaPlayerState->setPaused( FALSE ); |
365 | return; | 371 | return; |
366 | } else if( !mediaPlayerState->isPaused ) { | 372 | } else if( !mediaPlayerState->isPaused ) { |
367 | // qDebug("is not paused"); | 373 | // qDebug("is not paused"); |
368 | setToggleButton( i, TRUE ); | 374 | setToggleButton( i, TRUE ); |
369 | mediaPlayerState->setPaused( TRUE ); | 375 | mediaPlayerState->setPaused( TRUE ); |
370 | return; | 376 | return; |
371 | } else { | 377 | } else { |
372 | return; | 378 | return; |
373 | } | 379 | } |
374 | } | 380 | } |
375 | 381 | ||
376 | case VideoStop: mediaPlayerState->setPlaying( FALSE ); setToggleButton( i+1, true); setToggleButton( i, true ); return; | 382 | case VideoStop: mediaPlayerState->setPlaying( FALSE ); setToggleButton( i+1, true); setToggleButton( i, true ); return; |
377 | case VideoNext: mediaPlayerState->setNext(); return; | 383 | case VideoNext: mediaPlayerState->setNext(); return; |
378 | case VideoPrevious: mediaPlayerState->setPrev(); return; | 384 | case VideoPrevious: mediaPlayerState->setPrev(); return; |
379 | case VideoVolUp: emit moreReleased(); return; | 385 | case VideoVolUp: emit moreReleased(); return; |
380 | case VideoVolDown: emit lessReleased(); return; | 386 | case VideoVolDown: emit lessReleased(); return; |
381 | case VideoFullscreen: mediaPlayerState->setFullscreen( TRUE ); makeVisible(); return; | 387 | case VideoFullscreen: mediaPlayerState->setFullscreen( TRUE ); makeVisible(); return; |
382 | } | 388 | } |
383 | } | 389 | } |
384 | } | 390 | } |
385 | } | 391 | } |
386 | } | 392 | } |
387 | 393 | ||
388 | 394 | ||
389 | void VideoWidget::mousePressEvent( QMouseEvent *event ) { | 395 | void VideoWidget::mousePressEvent( QMouseEvent *event ) { |
390 | mouseMoveEvent( event ); | 396 | mouseMoveEvent( event ); |
391 | } | 397 | } |
392 | 398 | ||
393 | 399 | ||
394 | void VideoWidget::mouseReleaseEvent( QMouseEvent *event ) { | 400 | void VideoWidget::mouseReleaseEvent( QMouseEvent *event ) { |
395 | if ( mediaPlayerState->fullscreen() ) | 401 | if ( mediaPlayerState->fullscreen() ) |
396 | { | 402 | { |
397 | mediaPlayerState->setFullscreen( FALSE ); | 403 | mediaPlayerState->setFullscreen( FALSE ); |
398 | makeVisible(); | 404 | makeVisible(); |
399 | } | 405 | } |
400 | mouseMoveEvent( event ); | 406 | mouseMoveEvent( event ); |
401 | // } | 407 | // } |
402 | } | 408 | } |
403 | 409 | ||
404 | 410 | ||
405 | void VideoWidget::makeVisible() { | 411 | void VideoWidget::makeVisible() { |
406 | if ( mediaPlayerState->fullscreen() ) | 412 | if ( mediaPlayerState->fullscreen() ) |
407 | { | 413 | { |
408 | setBackgroundMode( QWidget::NoBackground ); | 414 | setBackgroundMode( QWidget::NoBackground ); |
409 | showFullScreen(); | 415 | showFullScreen(); |
410 | resize( qApp->desktop()->size() ); | 416 | resize( qApp->desktop()->size() ); |
411 | slider->hide(); | 417 | slider->hide(); |
412 | } | 418 | } |
413 | else | 419 | else |
414 | { | 420 | { |
415 | setBackgroundPixmap( *pixBg ); | 421 | setBackgroundPixmap( *pixBg ); |
416 | showNormal(); | 422 | showNormal(); |
417 | showMaximized(); | 423 | showMaximized(); |
418 | slider->show(); | 424 | slider->show(); |
419 | } | 425 | } |
420 | } | 426 | } |
421 | 427 | ||
422 | 428 | ||
423 | void VideoWidget::paintEvent( QPaintEvent * pe) { | 429 | void VideoWidget::paintEvent( QPaintEvent * pe) { |
424 | QPainter p( this ); | 430 | QPainter p( this ); |
425 | 431 | ||
426 | if ( mediaPlayerState->fullscreen() ) { | 432 | if ( mediaPlayerState->fullscreen() ) { |
427 | // Clear the background | 433 | // Clear the background |
428 | p.setBrush( QBrush( Qt::black ) ); | 434 | p.setBrush( QBrush( Qt::black ) ); |
429 | p.drawRect( rect() ); | 435 | p.drawRect( rect() ); |
430 | } else { | 436 | } else { |
431 | if ( !pe->erased() ) { | 437 | if ( !pe->erased() ) { |
432 | // Combine with background and double buffer | 438 | // Combine with background and double buffer |
433 | QPixmap pix( pe->rect().size() ); | 439 | QPixmap pix( pe->rect().size() ); |
434 | QPainter p( &pix ); | 440 | QPainter p( &pix ); |
435 | p.translate( -pe->rect().topLeft().x(), -pe->rect().topLeft().y() ); | 441 | p.translate( -pe->rect().topLeft().x(), -pe->rect().topLeft().y() ); |
436 | p.drawTiledPixmap( pe->rect(), *pixBg, pe->rect().topLeft() ); | 442 | p.drawTiledPixmap( pe->rect(), *pixBg, pe->rect().topLeft() ); |
437 | for ( int i = 0; i < numVButtons; i++ ) { | 443 | for ( int i = 0; i < numVButtons; i++ ) { |
438 | paintButton( &p, i ); | 444 | paintButton( &p, i ); |
439 | } | 445 | } |
440 | QPainter p2( this ); | 446 | QPainter p2( this ); |
441 | p2.drawPixmap( pe->rect().topLeft(), pix ); | 447 | p2.drawPixmap( pe->rect().topLeft(), pix ); |
442 | } else { | 448 | } else { |
443 | QPainter p( this ); | 449 | QPainter p( this ); |
444 | for ( int i = 0; i < numVButtons; i++ ) | 450 | for ( int i = 0; i < numVButtons; i++ ) |
445 | paintButton( &p, i ); | 451 | paintButton( &p, i ); |
446 | } | 452 | } |
447 | slider->repaint( TRUE ); | 453 | slider->repaint( TRUE ); |
448 | } | 454 | } |
449 | } | 455 | } |
450 | 456 | ||
451 | 457 | ||
452 | void VideoWidget::closeEvent( QCloseEvent* ) { | 458 | void VideoWidget::closeEvent( QCloseEvent* ) { |
453 | mediaPlayerState->setList(); | 459 | mediaPlayerState->setList(); |
454 | } | 460 | } |
455 | 461 | ||
456 | 462 | ||
457 | bool VideoWidget::playVideo() { | 463 | bool VideoWidget::playVideo() { |
458 | bool result = FALSE; | 464 | bool result = FALSE; |
459 | // qDebug("<<<<<<<<<<<<<<<< play video"); | 465 | // qDebug("<<<<<<<<<<<<<<<< play video"); |
460 | int stream = 0; | 466 | int stream = 0; |
461 | 467 | ||
462 | int sw = mediaPlayerState->curDecoder()->videoWidth( stream ); | 468 | int sw = mediaPlayerState->curDecoder()->videoWidth( stream ); |
463 | int sh = mediaPlayerState->curDecoder()->videoHeight( stream ); | 469 | int sh = mediaPlayerState->curDecoder()->videoHeight( stream ); |
464 | int dd = QPixmap::defaultDepth(); | 470 | int dd = QPixmap::defaultDepth(); |
465 | int w = height(); | 471 | int w = height(); |
466 | int h = width(); | 472 | int h = width(); |
467 | 473 | ||
468 | ColorFormat format = (dd == 16) ? RGB565 : BGRA8888; | 474 | ColorFormat format = (dd == 16) ? RGB565 : BGRA8888; |
469 | 475 | ||
470 | if ( mediaPlayerState->fullscreen() ) | 476 | if ( mediaPlayerState->fullscreen() ) |
471 | { | 477 | { |
472 | #ifdef USE_DIRECT_PAINTER | 478 | #ifdef USE_DIRECT_PAINTER |
473 | QDirectPainter p(this); | 479 | QDirectPainter p(this); |
474 | 480 | ||
475 | if ( ( qt_screen->transformOrientation() == 3 ) && | 481 | if ( ( qt_screen->transformOrientation() == 3 ) && |
476 | ( ( dd == 16 ) || ( dd == 32 ) ) && ( p.numRects() == 1 ) ) | 482 | ( ( dd == 16 ) || ( dd == 32 ) ) && ( p.numRects() == 1 ) ) |
477 | { | 483 | { |
478 | 484 | ||
479 | w = 320; | 485 | w = 320; |
480 | h = 240; | 486 | h = 240; |
481 | 487 | ||
482 | if ( mediaPlayerState->scaled() ) | 488 | if ( mediaPlayerState->scaled() ) |
483 | { | 489 | { |
484 | // maintain aspect ratio | 490 | // maintain aspect ratio |
485 | if ( w * sh > sw * h ) | 491 | if ( w * sh > sw * h ) |
486 | w = sw * h / sh; | 492 | w = sw * h / sh; |
487 | else | 493 | else |
488 | h = sh * w / sw; | 494 | h = sh * w / sw; |
489 | } | 495 | } |
490 | else | 496 | else |
491 | { | 497 | { |
492 | w = sw; | 498 | w = sw; |
493 | h = sh; | 499 | h = sh; |
494 | } | 500 | } |
495 | 501 | ||
496 | w--; // we can't allow libmpeg to overwrite. | 502 | w--; // we can't allow libmpeg to overwrite. |
497 | QPoint roff = qt_screen->mapToDevice( p.offset(), QSize( qt_screen->width(), qt_screen->height() ) ); | 503 | QPoint roff = qt_screen->mapToDevice( p.offset(), QSize( qt_screen->width(), qt_screen->height() ) ); |
498 | 504 | ||
499 | int ox = roff.x() - height() + 2 + (height() - w) / 2; | 505 | int ox = roff.x() - height() + 2 + (height() - w) / 2; |
500 | int oy = roff.y() + (width() - h) / 2; | 506 | int oy = roff.y() + (width() - h) / 2; |
501 | int sx = 0, sy = 0; | 507 | int sx = 0, sy = 0; |
502 | 508 | ||
503 | uchar* fp = p.frameBuffer() + p.lineStep() * oy; | 509 | uchar* fp = p.frameBuffer() + p.lineStep() * oy; |
504 | fp += dd * ox / 8; | 510 | fp += dd * ox / 8; |
505 | uchar **jt = new uchar*[h]; | 511 | uchar **jt = new uchar*[h]; |
506 | 512 | ||
507 | for ( int i = h; i; i-- ) | 513 | for ( int i = h; i; i-- ) |
508 | { | 514 | { |
509 | jt[h - i] = fp; | 515 | jt[h - i] = fp; |
510 | fp += p.lineStep(); | 516 | fp += p.lineStep(); |
511 | } | 517 | } |
512 | 518 | ||
513 | result = mediaPlayerState->curDecoder()->videoReadScaledFrame( jt, sx, sy, sw, sh, w, h, format, 0) == 0; | 519 | result = mediaPlayerState->curDecoder()->videoReadScaledFrame( jt, sx, sy, sw, sh, w, h, format, 0) == 0; |
514 | 520 | ||
515 | delete [] jt; | 521 | delete [] jt; |
516 | } | 522 | } |
517 | else | 523 | else |
518 | { | 524 | { |
519 | #endif | 525 | #endif |
520 | QPainter p(this); | 526 | QPainter p(this); |
521 | 527 | ||
522 | w = 320; | 528 | w = 320; |
523 | h = 240; | 529 | h = 240; |
524 | 530 | ||
525 | if ( mediaPlayerState->scaled() ) | 531 | if ( mediaPlayerState->scaled() ) |
526 | { | 532 | { |
527 | // maintain aspect ratio | 533 | // maintain aspect ratio |
528 | if ( w * sh > sw * h ) | 534 | if ( w * sh > sw * h ) |
529 | w = sw * h / sh; | 535 | w = sw * h / sh; |
530 | else | 536 | else |
531 | h = sh * w / sw; | 537 | h = sh * w / sw; |
532 | } | 538 | } |
533 | else | 539 | else |
534 | { | 540 | { |
535 | w = sw; | 541 | w = sw; |
536 | h = sh; | 542 | h = sh; |
537 | } | 543 | } |
538 | 544 | ||
539 | int bytes = ( dd == 16 ) ? 2 : 4; | 545 | int bytes = ( dd == 16 ) ? 2 : 4; |
540 | QImage tempFrame( w, h, bytes << 3 ); | 546 | QImage tempFrame( w, h, bytes << 3 ); |
541 | result = mediaPlayerState->curDecoder()->videoReadScaledFrame( tempFrame.jumpTable(), | 547 | result = mediaPlayerState->curDecoder()->videoReadScaledFrame( tempFrame.jumpTable(), |
542 | 0, 0, sw, sh, w, h, format, 0) == 0; | 548 | 0, 0, sw, sh, w, h, format, 0) == 0; |
543 | 549 | ||
544 | if ( result && mediaPlayerState->fullscreen() ) | 550 | if ( result && mediaPlayerState->fullscreen() ) |
545 | { | 551 | { |
546 | 552 | ||
547 | int rw = h, rh = w; | 553 | int rw = h, rh = w; |
548 | QImage rotatedFrame( rw, rh, bytes << 3 ); | 554 | QImage rotatedFrame( rw, rh, bytes << 3 ); |
549 | 555 | ||
550 | ushort* in = (ushort*)tempFrame.bits(); | 556 | ushort* in = (ushort*)tempFrame.bits(); |
551 | ushort* out = (ushort*)rotatedFrame.bits(); | 557 | ushort* out = (ushort*)rotatedFrame.bits(); |
552 | int spl = rotatedFrame.bytesPerLine() / bytes; | 558 | int spl = rotatedFrame.bytesPerLine() / bytes; |
553 | 559 | ||
554 | for (int x=0; x<h; x++) | 560 | for (int x=0; x<h; x++) |
555 | { | 561 | { |
556 | if ( bytes == 2 ) | 562 | if ( bytes == 2 ) |
557 | { | 563 | { |
558 | ushort* lout = out++ + (w - 1)*spl; | 564 | ushort* lout = out++ + (w - 1)*spl; |
559 | for (int y=0; y<w; y++) { | 565 | for (int y=0; y<w; y++) { |
560 | *lout=*in++; | 566 | *lout=*in++; |
561 | lout-=spl; | 567 | lout-=spl; |
562 | } | 568 | } |
563 | } | 569 | } |
564 | else | 570 | else |
565 | { | 571 | { |
566 | ulong* lout = ((ulong *)out)++ + (w - 1)*spl; | 572 | ulong* lout = ((ulong *)out)++ + (w - 1)*spl; |
567 | for (int y=0; y<w; y++) | 573 | for (int y=0; y<w; y++) |
568 | { | 574 | { |
569 | *lout=*((ulong*)in)++; | 575 | *lout=*((ulong*)in)++; |
570 | lout-=spl; | 576 | lout-=spl; |
571 | } | 577 | } |
572 | } | 578 | } |
573 | } | 579 | } |
574 | 580 | ||
575 | p.drawImage( (240 - rw) / 2, (320 - rh) / 2, rotatedFrame, 0, 0, rw, rh ); | 581 | p.drawImage( (240 - rw) / 2, (320 - rh) / 2, rotatedFrame, 0, 0, rw, rh ); |
576 | } | 582 | } |
577 | #ifdef USE_DIRECT_PAINTER | 583 | #ifdef USE_DIRECT_PAINTER |
578 | } | 584 | } |
579 | #endif | 585 | #endif |
580 | } | 586 | } |
581 | else | 587 | else |
582 | { | 588 | { |
583 | 589 | ||
584 | w = 220; | 590 | w = 220; |
585 | h = 160; | 591 | h = 160; |
586 | 592 | ||
587 | // maintain aspect ratio | 593 | // maintain aspect ratio |
588 | if ( w * sh > sw * h ) | 594 | if ( w * sh > sw * h ) |
589 | w = sw * h / sh; | 595 | w = sw * h / sh; |
590 | else | 596 | else |
591 | h = sh * w / sw; | 597 | h = sh * w / sw; |
592 | 598 | ||
593 | result = mediaPlayerState->curDecoder()->videoReadScaledFrame( currentFrame->jumpTable(), 0, 0, sw, sh, w, h, format, 0) == 0; | 599 | result = mediaPlayerState->curDecoder()->videoReadScaledFrame( currentFrame->jumpTable(), 0, 0, sw, sh, w, h, format, 0) == 0; |
594 | 600 | ||
595 | QPainter p( this ); | 601 | QPainter p( this ); |
596 | int deskW = qApp->desktop()->width(); | 602 | int deskW = qApp->desktop()->width(); |
597 | // Image changed size, therefore need to blank the possibly unpainted regions first | 603 | // Image changed size, therefore need to blank the possibly unpainted regions first |
598 | if ( scaledWidth != w || scaledHeight != h ) | 604 | if ( scaledWidth != w || scaledHeight != h ) |
599 | { | 605 | { |
600 | p.setBrush( QBrush( Qt::black ) ); | 606 | p.setBrush( QBrush( Qt::black ) ); |
601 | p.drawRect( ( deskW -scaledWidth)/2, 20, scaledWidth, 160 ); | 607 | p.drawRect( ( deskW -scaledWidth)/2, 20, scaledWidth, 160 ); |
602 | } | 608 | } |
603 | 609 | ||
604 | scaledWidth = w; | 610 | scaledWidth = w; |
605 | scaledHeight = h; | 611 | scaledHeight = h; |
606 | 612 | ||
607 | if ( result ) | 613 | if ( result ) |
608 | { | 614 | { |
609 | p.drawImage( (deskW - scaledWidth) / 2, 20 + (160 - scaledHeight) / 2, *currentFrame, 0, 0, scaledWidth, scaledHeight ); | 615 | p.drawImage( (deskW - scaledWidth) / 2, 20 + (160 - scaledHeight) / 2, *currentFrame, 0, 0, scaledWidth, scaledHeight ); |
610 | } | 616 | } |
611 | 617 | ||
612 | } | 618 | } |
613 | 619 | ||
614 | return result; | 620 | return result; |
615 | } | 621 | } |
616 | 622 | ||
617 | 623 | ||
618 | 624 | ||
619 | void VideoWidget::keyReleaseEvent( QKeyEvent *e) | 625 | void VideoWidget::keyReleaseEvent( QKeyEvent *e) |
620 | { | 626 | { |
621 | switch ( e->key() ) | 627 | switch ( e->key() ) |
622 | { | 628 | { |
623 | ////////////////////////////// Zaurus keys | 629 | ////////////////////////////// Zaurus keys |
624 | case Key_Home: | 630 | case Key_Home: |
625 | break; | 631 | break; |
626 | case Key_F9: //activity | 632 | case Key_F9: //activity |
627 | break; | 633 | break; |
628 | case Key_F10: //contacts | 634 | case Key_F10: //contacts |
629 | // hide(); | 635 | // hide(); |
630 | break; | 636 | break; |
631 | case Key_F11: //menu | 637 | case Key_F11: //menu |
632 | break; | 638 | break; |
633 | case Key_F12: //home | 639 | case Key_F12: //home |
634 | break; | 640 | break; |
635 | case Key_F13: //mail | 641 | case Key_F13: //mail |
636 | break; | 642 | break; |
637 | case Key_Space: | 643 | case Key_Space: |
638 | { | 644 | { |
639 | if(mediaPlayerState->playing()) | 645 | if(mediaPlayerState->playing()) |
640 | { | 646 | { |