-rw-r--r-- | noncore/multimedia/opieplayer2/audiowidget.cpp | 7 | ||||
-rw-r--r-- | noncore/multimedia/opieplayer2/videowidget.cpp | 6 |
2 files changed, 9 insertions, 4 deletions
diff --git a/noncore/multimedia/opieplayer2/audiowidget.cpp b/noncore/multimedia/opieplayer2/audiowidget.cpp index 446fa45..7c49733 100644 --- a/noncore/multimedia/opieplayer2/audiowidget.cpp +++ b/noncore/multimedia/opieplayer2/audiowidget.cpp | |||
@@ -1,596 +1,599 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of the Opie Project | 2 | This file is part of the Opie Project |
3 | 3 | ||
4 | Copyright (c) 2002 Max Reiss <harlekin@handhelds.org> | 4 | Copyright (c) 2002 Max Reiss <harlekin@handhelds.org> |
5 | Copyright (c) 2002 L. Potter <ljp@llornkcor.com> | 5 | Copyright (c) 2002 L. Potter <ljp@llornkcor.com> |
6 | Copyright (c) 2002 Holger Freyther <zecke@handhelds.org> | 6 | Copyright (c) 2002 Holger Freyther <zecke@handhelds.org> |
7 | =. | 7 | =. |
8 | .=l. | 8 | .=l. |
9 | .>+-= | 9 | .>+-= |
10 | _;:, .> :=|. This program is free software; you can | 10 | _;:, .> :=|. This program is free software; you can |
11 | .> <`_, > . <= redistribute it and/or modify it under | 11 | .> <`_, > . <= redistribute it and/or modify it under |
12 | :`=1 )Y*s>-.-- : the terms of the GNU General Public | 12 | :`=1 )Y*s>-.-- : the terms of the GNU General Public |
13 | .="- .-=="i, .._ License as published by the Free Software | 13 | .="- .-=="i, .._ License as published by the Free Software |
14 | - . .-<_> .<> Foundation; either version 2 of the License, | 14 | - . .-<_> .<> Foundation; either version 2 of the License, |
15 | ._= =} : or (at your option) any later version. | 15 | ._= =} : or (at your option) any later version. |
16 | .%`+i> _;_. | 16 | .%`+i> _;_. |
17 | .i_,=:_. -<s. This program is distributed in the hope that | 17 | .i_,=:_. -<s. This program is distributed in the hope that |
18 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 18 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
19 | : .. .:, . . . without even the implied warranty of | 19 | : .. .:, . . . without even the implied warranty of |
20 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 20 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
21 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | 21 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU |
22 | ..}^=.= = ; Library General Public License for more | 22 | ..}^=.= = ; Library General Public License for more |
23 | ++= -. .` .: details. | 23 | ++= -. .` .: details. |
24 | : = ...= . :.=- | 24 | : = ...= . :.=- |
25 | -. .:....=;==+<; You should have received a copy of the GNU | 25 | -. .:....=;==+<; You should have received a copy of the GNU |
26 | -_. . . )=. = Library General Public License along with | 26 | -_. . . )=. = Library General Public License along with |
27 | -- :-=` this library; see the file COPYING.LIB. | 27 | -- :-=` this library; see the file COPYING.LIB. |
28 | If not, write to the Free Software Foundation, | 28 | If not, write to the Free Software Foundation, |
29 | Inc., 59 Temple Place - Suite 330, | 29 | Inc., 59 Temple Place - Suite 330, |
30 | Boston, MA 02111-1307, USA. | 30 | Boston, MA 02111-1307, USA. |
31 | 31 | ||
32 | */ | 32 | */ |
33 | 33 | ||
34 | #include <qpe/qpeapplication.h> | 34 | #include <qpe/qpeapplication.h> |
35 | #include <qpe/resource.h> | 35 | #include <qpe/resource.h> |
36 | #include <qpe/config.h> | 36 | #include <qpe/config.h> |
37 | 37 | ||
38 | #include <qwidget.h> | 38 | #include <qwidget.h> |
39 | #include <qpixmap.h> | 39 | #include <qpixmap.h> |
40 | #include <qbutton.h> | 40 | #include <qbutton.h> |
41 | #include <qpainter.h> | 41 | #include <qpainter.h> |
42 | #include <qframe.h> | 42 | #include <qframe.h> |
43 | #include <qlayout.h> | 43 | #include <qlayout.h> |
44 | 44 | ||
45 | #include <stdlib.h> | 45 | #include <stdlib.h> |
46 | #include <stdio.h> | 46 | #include <stdio.h> |
47 | 47 | ||
48 | #include "audiowidget.h" | 48 | #include "audiowidget.h" |
49 | #include "mediaplayerstate.h" | 49 | #include "mediaplayerstate.h" |
50 | #include "playlistwidget.h" | ||
50 | 51 | ||
51 | extern MediaPlayerState *mediaPlayerState; | 52 | extern MediaPlayerState *mediaPlayerState; |
53 | extern PlayListWidget *playList; | ||
52 | 54 | ||
53 | static const int xo = -2; // movable x offset | 55 | static const int xo = -2; // movable x offset |
54 | static const int yo = 22; // movable y offset | 56 | static const int yo = 22; // movable y offset |
55 | 57 | ||
56 | 58 | ||
57 | Ticker::Ticker( QWidget* parent=0 ) : QFrame( parent ) { | 59 | Ticker::Ticker( QWidget* parent=0 ) : QFrame( parent ) { |
58 | setFrameStyle( WinPanel | Sunken ); | 60 | setFrameStyle( WinPanel | Sunken ); |
59 | setText( "No Song" ); | 61 | setText( "No Song" ); |
60 | } | 62 | } |
61 | 63 | ||
62 | Ticker::~Ticker() { | 64 | Ticker::~Ticker() { |
63 | } | 65 | } |
64 | 66 | ||
65 | void Ticker::setText( const QString& text ) { | 67 | void Ticker::setText( const QString& text ) { |
66 | pos = 0; // reset it everytime the text is changed | 68 | pos = 0; // reset it everytime the text is changed |
67 | scrollText = text; | 69 | scrollText = text; |
68 | pixelLen = fontMetrics().width( scrollText ); | 70 | pixelLen = fontMetrics().width( scrollText ); |
69 | killTimers(); | 71 | killTimers(); |
70 | if ( pixelLen > width() ) { | 72 | if ( pixelLen > width() ) { |
71 | startTimer( 50 ); | 73 | startTimer( 50 ); |
72 | } | 74 | } |
73 | update(); | 75 | update(); |
74 | } | 76 | } |
75 | 77 | ||
76 | 78 | ||
77 | void Ticker::timerEvent( QTimerEvent * ) { | 79 | void Ticker::timerEvent( QTimerEvent * ) { |
78 | pos = ( pos + 1 > pixelLen ) ? 0 : pos + 1; | 80 | pos = ( pos + 1 > pixelLen ) ? 0 : pos + 1; |
79 | scroll( -1, 0, contentsRect() ); | 81 | scroll( -1, 0, contentsRect() ); |
80 | repaint( FALSE ); | 82 | repaint( FALSE ); |
81 | } | 83 | } |
82 | 84 | ||
83 | void Ticker::drawContents( QPainter *p ) { | 85 | void Ticker::drawContents( QPainter *p ) { |
84 | for ( int i = 0; i - pos < width() && (i < 1 || pixelLen > width()); i += pixelLen ) { | 86 | for ( int i = 0; i - pos < width() && (i < 1 || pixelLen > width()); i += pixelLen ) { |
85 | p->drawText( i - pos, 0, INT_MAX, height(), AlignVCenter, scrollText ); | 87 | p->drawText( i - pos, 0, INT_MAX, height(), AlignVCenter, scrollText ); |
86 | } | 88 | } |
87 | QPixmap pm( width(), height() ); | 89 | QPixmap pm( width(), height() ); |
88 | pm.fill( colorGroup().base() ); | 90 | pm.fill( colorGroup().base() ); |
89 | QPainter pmp( &pm ); | 91 | QPainter pmp( &pm ); |
90 | for ( int i = 0; i - pos < width() && (i < 1 || pixelLen > width()); i += pixelLen ) { | 92 | for ( int i = 0; i - pos < width() && (i < 1 || pixelLen > width()); i += pixelLen ) { |
91 | pmp.drawText( i - pos, 0, INT_MAX, height(), AlignVCenter, scrollText ); | 93 | pmp.drawText( i - pos, 0, INT_MAX, height(), AlignVCenter, scrollText ); |
92 | } | 94 | } |
93 | p->drawPixmap( 0, 0, pm ); | 95 | p->drawPixmap( 0, 0, pm ); |
94 | } | 96 | } |
95 | 97 | ||
96 | struct MediaButton { | 98 | struct MediaButton { |
97 | bool isToggle, isHeld, isDown; | 99 | bool isToggle, isHeld, isDown; |
98 | }; | 100 | }; |
99 | 101 | ||
100 | //Layout information for the audioButtons (and if it is a toggle button or not) | 102 | //Layout information for the audioButtons (and if it is a toggle button or not) |
101 | MediaButton audioButtons[] = { | 103 | MediaButton audioButtons[] = { |
102 | { TRUE, FALSE, FALSE }, // play | 104 | { TRUE, FALSE, FALSE }, // play |
103 | { FALSE, FALSE, FALSE }, // stop | 105 | { FALSE, FALSE, FALSE }, // stop |
104 | { FALSE, FALSE, FALSE }, // next | 106 | { FALSE, FALSE, FALSE }, // next |
105 | { FALSE, FALSE, FALSE }, // previous | 107 | { FALSE, FALSE, FALSE }, // previous |
106 | { FALSE, FALSE, FALSE }, // volume up | 108 | { FALSE, FALSE, FALSE }, // volume up |
107 | { FALSE, FALSE, FALSE }, // volume down | 109 | { FALSE, FALSE, FALSE }, // volume down |
108 | { TRUE, FALSE, FALSE }, // repeat/loop | 110 | { TRUE, FALSE, FALSE }, // repeat/loop |
109 | { FALSE, FALSE, FALSE }, // playlist | 111 | { FALSE, FALSE, FALSE }, // playlist |
110 | { FALSE, FALSE, FALSE }, // forward | 112 | { FALSE, FALSE, FALSE }, // forward |
111 | { FALSE, FALSE, FALSE } // back | 113 | { FALSE, FALSE, FALSE } // back |
112 | }; | 114 | }; |
113 | 115 | ||
114 | const char *skin_mask_file_names[10] = { | 116 | const char *skin_mask_file_names[10] = { |
115 | "play", "stop", "next", "prev", "up", | 117 | "play", "stop", "next", "prev", "up", |
116 | "down", "loop", "playlist", "forward", "back" | 118 | "down", "loop", "playlist", "forward", "back" |
117 | }; | 119 | }; |
118 | 120 | ||
119 | 121 | ||
120 | static void changeTextColor( QWidget *w ) { | 122 | static void changeTextColor( QWidget *w ) { |
121 | QPalette p = w->palette(); | 123 | QPalette p = w->palette(); |
122 | p.setBrush( QColorGroup::Background, QColor( 167, 212, 167 ) ); | 124 | p.setBrush( QColorGroup::Background, QColor( 167, 212, 167 ) ); |
123 | p.setBrush( QColorGroup::Base, QColor( 167, 212, 167 ) ); | 125 | p.setBrush( QColorGroup::Base, QColor( 167, 212, 167 ) ); |
124 | w->setPalette( p ); | 126 | w->setPalette( p ); |
125 | } | 127 | } |
126 | 128 | ||
127 | static const int numButtons = (sizeof(audioButtons)/sizeof(MediaButton)); | 129 | static const int numButtons = (sizeof(audioButtons)/sizeof(MediaButton)); |
128 | 130 | ||
129 | 131 | ||
130 | AudioWidget::AudioWidget(QWidget* parent, const char* name, WFlags f) : | 132 | AudioWidget::AudioWidget(QWidget* parent, const char* name, WFlags f) : |
131 | 133 | ||
132 | QWidget( parent, name, f ), songInfo( this ), slider( Qt::Horizontal, this ), time( this ) { | 134 | QWidget( parent, name, f ), songInfo( this ), slider( Qt::Horizontal, this ), time( this ) { |
133 | 135 | ||
134 | setCaption( tr("OpiePlayer") ); | 136 | setCaption( tr("OpiePlayer") ); |
135 | 137 | ||
136 | Config cfg("OpiePlayer"); | 138 | Config cfg("OpiePlayer"); |
137 | cfg.setGroup("Options"); | 139 | cfg.setGroup("Options"); |
138 | skin = cfg.readEntry("Skin","default"); | 140 | skin = cfg.readEntry("Skin","default"); |
139 | //skin = "scaleTest"; | 141 | //skin = "scaleTest"; |
140 | // color of background, frame, degree of transparency | 142 | // color of background, frame, degree of transparency |
141 | 143 | ||
142 | QString skinPath = "opieplayer2/skins/" + skin; | 144 | QString skinPath = "opieplayer2/skins/" + skin; |
143 | pixBg = new QPixmap( Resource::loadPixmap( QString("%1/background").arg(skinPath) ) ); | 145 | pixBg = new QPixmap( Resource::loadPixmap( QString("%1/background").arg(skinPath) ) ); |
144 | imgUp = new QImage( Resource::loadImage( QString("%1/skin_up").arg(skinPath) ) ); | 146 | imgUp = new QImage( Resource::loadImage( QString("%1/skin_up").arg(skinPath) ) ); |
145 | imgDn = new QImage( Resource::loadImage( QString("%1/skin_down").arg(skinPath) ) ); | 147 | imgDn = new QImage( Resource::loadImage( QString("%1/skin_down").arg(skinPath) ) ); |
146 | 148 | ||
147 | imgButtonMask = new QImage( imgUp->width(), imgUp->height(), 8, 255 ); | 149 | imgButtonMask = new QImage( imgUp->width(), imgUp->height(), 8, 255 ); |
148 | imgButtonMask->fill( 0 ); | 150 | imgButtonMask->fill( 0 ); |
149 | 151 | ||
150 | for ( int i = 0; i < 10; i++ ) { | 152 | for ( int i = 0; i < 10; i++ ) { |
151 | QString filename = QString( QPEApplication::qpeDir() + "/pics/" + skinPath + "/skin_mask_" + skin_mask_file_names[i] + ".png" ); | 153 | QString filename = QString( QPEApplication::qpeDir() + "/pics/" + skinPath + "/skin_mask_" + skin_mask_file_names[i] + ".png" ); |
152 | masks[i] = new QBitmap( filename ); | 154 | masks[i] = new QBitmap( filename ); |
153 | 155 | ||
154 | if ( !masks[i]->isNull() ) { | 156 | if ( !masks[i]->isNull() ) { |
155 | QImage imgMask = masks[i]->convertToImage(); | 157 | QImage imgMask = masks[i]->convertToImage(); |
156 | uchar **dest = imgButtonMask->jumpTable(); | 158 | uchar **dest = imgButtonMask->jumpTable(); |
157 | for ( int y = 0; y < imgUp->height(); y++ ) { | 159 | for ( int y = 0; y < imgUp->height(); y++ ) { |
158 | uchar *line = dest[y]; | 160 | uchar *line = dest[y]; |
159 | for ( int x = 0; x < imgUp->width(); x++ ) | 161 | for ( int x = 0; x < imgUp->width(); x++ ) |
160 | if ( !qRed( imgMask.pixel( x, y ) ) ) | 162 | if ( !qRed( imgMask.pixel( x, y ) ) ) |
161 | line[x] = i + 1; | 163 | line[x] = i + 1; |
162 | } | 164 | } |
163 | } | 165 | } |
164 | 166 | ||
165 | } | 167 | } |
166 | 168 | ||
167 | for ( int i = 0; i < 10; i++ ) { | 169 | for ( int i = 0; i < 10; i++ ) { |
168 | buttonPixUp[i] = 0l; | 170 | buttonPixUp[i] = 0l; |
169 | buttonPixDown[i] = 0l; | 171 | buttonPixDown[i] = 0l; |
170 | } | 172 | } |
171 | 173 | ||
172 | setBackgroundPixmap( *pixBg ); | 174 | setBackgroundPixmap( *pixBg ); |
173 | 175 | ||
174 | songInfo.setFocusPolicy( QWidget::NoFocus ); | 176 | songInfo.setFocusPolicy( QWidget::NoFocus ); |
175 | changeTextColor( &songInfo ); | 177 | changeTextColor( &songInfo ); |
176 | 178 | ||
177 | slider.setFixedHeight( 20 ); | 179 | slider.setFixedHeight( 20 ); |
178 | slider.setMinValue( 0 ); | 180 | slider.setMinValue( 0 ); |
179 | slider.setMaxValue( 1 ); | 181 | slider.setMaxValue( 1 ); |
180 | slider.setFocusPolicy( QWidget::NoFocus ); | 182 | slider.setFocusPolicy( QWidget::NoFocus ); |
181 | slider.setBackgroundPixmap( *pixBg ); | 183 | slider.setBackgroundPixmap( *pixBg ); |
182 | 184 | ||
183 | time.setFocusPolicy( QWidget::NoFocus ); | 185 | time.setFocusPolicy( QWidget::NoFocus ); |
184 | time.setAlignment( Qt::AlignCenter ); | 186 | time.setAlignment( Qt::AlignCenter ); |
185 | time.setFrame(FALSE); | 187 | time.setFrame(FALSE); |
186 | changeTextColor( &time ); | 188 | changeTextColor( &time ); |
187 | 189 | ||
188 | resizeEvent( NULL ); | 190 | resizeEvent( NULL ); |
189 | 191 | ||
190 | connect( &slider, SIGNAL( sliderPressed() ), this, SLOT( sliderPressed() ) ); | 192 | connect( &slider, SIGNAL( sliderPressed() ), this, SLOT( sliderPressed() ) ); |
191 | connect( &slider, SIGNAL( sliderReleased() ), this, SLOT( sliderReleased() ) ); | 193 | connect( &slider, SIGNAL( sliderReleased() ), this, SLOT( sliderReleased() ) ); |
192 | 194 | ||
193 | connect( mediaPlayerState, SIGNAL( lengthChanged(long) ), this, SLOT( setLength(long) ) ); | 195 | connect( mediaPlayerState, SIGNAL( lengthChanged(long) ), this, SLOT( setLength(long) ) ); |
194 | connect( mediaPlayerState, SIGNAL( viewChanged(char) ), this, SLOT( setView(char) ) ); | 196 | connect( mediaPlayerState, SIGNAL( viewChanged(char) ), this, SLOT( setView(char) ) ); |
195 | connect( mediaPlayerState, SIGNAL( loopingToggled(bool) ), this, SLOT( setLooping(bool) ) ); | 197 | connect( mediaPlayerState, SIGNAL( loopingToggled(bool) ), this, SLOT( setLooping(bool) ) ); |
196 | // connect( mediaPlayerState, SIGNAL( pausedToggled(bool) ), this, SLOT( setPaused(bool) ) ); | 198 | // connect( mediaPlayerState, SIGNAL( pausedToggled(bool) ), this, SLOT( setPaused(bool) ) ); |
197 | connect( mediaPlayerState, SIGNAL( playingToggled(bool) ), this, SLOT( setPlaying(bool) ) ); | 199 | connect( mediaPlayerState, SIGNAL( playingToggled(bool) ), this, SLOT( setPlaying(bool) ) ); |
198 | 200 | ||
199 | connect( this, SIGNAL( forwardClicked() ), this, SLOT( skipFor() ) ); | 201 | connect( this, SIGNAL( forwardClicked() ), this, SLOT( skipFor() ) ); |
200 | connect( this, SIGNAL( backClicked() ), this, SLOT( skipBack() ) ); | 202 | connect( this, SIGNAL( backClicked() ), this, SLOT( skipBack() ) ); |
201 | connect( this, SIGNAL( forwardReleased() ), this, SLOT( stopSkip() ) ); | 203 | connect( this, SIGNAL( forwardReleased() ), this, SLOT( stopSkip() ) ); |
202 | connect( this, SIGNAL( backReleased() ), this, SLOT( stopSkip() ) ); | 204 | connect( this, SIGNAL( backReleased() ), this, SLOT( stopSkip() ) ); |
203 | 205 | ||
204 | 206 | ||
205 | 207 | ||
206 | // Intialise state | 208 | // Intialise state |
207 | setLength( mediaPlayerState->length() ); | 209 | setLength( mediaPlayerState->length() ); |
208 | setPosition( mediaPlayerState->position() ); | 210 | setPosition( mediaPlayerState->position() ); |
209 | setLooping( mediaPlayerState->fullscreen() ); | 211 | setLooping( mediaPlayerState->fullscreen() ); |
210 | // setPaused( mediaPlayerState->paused() ); | 212 | // setPaused( mediaPlayerState->paused() ); |
211 | setPlaying( mediaPlayerState->playing() ); | 213 | setPlaying( mediaPlayerState->playing() ); |
212 | 214 | ||
213 | } | 215 | } |
214 | 216 | ||
215 | AudioWidget::~AudioWidget() { | 217 | AudioWidget::~AudioWidget() { |
216 | 218 | ||
217 | for ( int i = 0; i < 10; i++ ) { | 219 | for ( int i = 0; i < 10; i++ ) { |
218 | delete buttonPixUp[i]; | 220 | delete buttonPixUp[i]; |
219 | delete buttonPixDown[i]; | 221 | delete buttonPixDown[i]; |
220 | } | 222 | } |
221 | delete pixBg; | 223 | delete pixBg; |
222 | delete imgUp; | 224 | delete imgUp; |
223 | delete imgDn; | 225 | delete imgDn; |
224 | delete imgButtonMask; | 226 | delete imgButtonMask; |
225 | for ( int i = 0; i < 10; i++ ) { | 227 | for ( int i = 0; i < 10; i++ ) { |
226 | delete masks[i]; | 228 | delete masks[i]; |
227 | } | 229 | } |
230 | // mediaPlayerState->setPlaying(false); | ||
228 | } | 231 | } |
229 | 232 | ||
230 | namespace { | 233 | namespace { |
231 | 234 | ||
232 | QPixmap *combineImageWithBackground( QImage img, QPixmap bg, QPoint offset ) { | 235 | QPixmap *combineImageWithBackground( QImage img, QPixmap bg, QPoint offset ) { |
233 | QPixmap pix( img.width(), img.height() ); | 236 | QPixmap pix( img.width(), img.height() ); |
234 | QPainter p( &pix ); | 237 | QPainter p( &pix ); |
235 | p.drawTiledPixmap( pix.rect(), bg, offset ); | 238 | p.drawTiledPixmap( pix.rect(), bg, offset ); |
236 | p.drawImage( 0, 0, img ); | 239 | p.drawImage( 0, 0, img ); |
237 | return new QPixmap( pix ); | 240 | return new QPixmap( pix ); |
238 | } | 241 | } |
239 | 242 | ||
240 | 243 | ||
241 | QPixmap *maskPixToMask( QPixmap pix, QBitmap mask ) { | 244 | QPixmap *maskPixToMask( QPixmap pix, QBitmap mask ) { |
242 | QPixmap *pixmap = new QPixmap( pix ); | 245 | QPixmap *pixmap = new QPixmap( pix ); |
243 | pixmap->setMask( mask ); | 246 | pixmap->setMask( mask ); |
244 | return pixmap; | 247 | return pixmap; |
245 | } | 248 | } |
246 | 249 | ||
247 | }; | 250 | }; |
248 | 251 | ||
249 | void AudioWidget::resizeEvent( QResizeEvent * ) { | 252 | void AudioWidget::resizeEvent( QResizeEvent * ) { |
250 | int h = height(); | 253 | int h = height(); |
251 | int w = width(); | 254 | int w = width(); |
252 | 255 | ||
253 | songInfo.setGeometry( QRect( 2, 10, w - 4, 20 ) ); | 256 | songInfo.setGeometry( QRect( 2, 10, w - 4, 20 ) ); |
254 | slider.setFixedWidth( w - 110 ); | 257 | slider.setFixedWidth( w - 110 ); |
255 | slider.setGeometry( QRect( 15, h - 30, w - 90, 20 ) ); | 258 | slider.setGeometry( QRect( 15, h - 30, w - 90, 20 ) ); |
256 | slider.setBackgroundOrigin( QWidget::ParentOrigin ); | 259 | slider.setBackgroundOrigin( QWidget::ParentOrigin ); |
257 | time.setGeometry( QRect( w - 85, h - 30, 70, 20 ) ); | 260 | time.setGeometry( QRect( w - 85, h - 30, 70, 20 ) ); |
258 | 261 | ||
259 | xoff = ( w - imgUp->width() ) / 2; | 262 | xoff = ( w - imgUp->width() ) / 2; |
260 | yoff = (( h - imgUp->height() ) / 2) - 10; | 263 | yoff = (( h - imgUp->height() ) / 2) - 10; |
261 | QPoint p( xoff, yoff ); | 264 | QPoint p( xoff, yoff ); |
262 | 265 | ||
263 | QPixmap *pixUp = combineImageWithBackground( *imgUp, *pixBg, p ); | 266 | QPixmap *pixUp = combineImageWithBackground( *imgUp, *pixBg, p ); |
264 | QPixmap *pixDn = combineImageWithBackground( *imgDn, *pixBg, p ); | 267 | QPixmap *pixDn = combineImageWithBackground( *imgDn, *pixBg, p ); |
265 | 268 | ||
266 | for ( int i = 0; i < 10; i++ ) { | 269 | for ( int i = 0; i < 10; i++ ) { |
267 | if ( !masks[i]->isNull() ) { | 270 | if ( !masks[i]->isNull() ) { |
268 | delete buttonPixUp[i]; | 271 | delete buttonPixUp[i]; |
269 | delete buttonPixDown[i]; | 272 | delete buttonPixDown[i]; |
270 | buttonPixUp[i] = maskPixToMask( *pixUp, *masks[i] ); | 273 | buttonPixUp[i] = maskPixToMask( *pixUp, *masks[i] ); |
271 | buttonPixDown[i] = maskPixToMask( *pixDn, *masks[i] ); | 274 | buttonPixDown[i] = maskPixToMask( *pixDn, *masks[i] ); |
272 | } | 275 | } |
273 | } | 276 | } |
274 | 277 | ||
275 | delete pixUp; | 278 | delete pixUp; |
276 | delete pixDn; | 279 | delete pixDn; |
277 | } | 280 | } |
278 | 281 | ||
279 | static bool audioSliderBeingMoved = FALSE; | 282 | static bool audioSliderBeingMoved = FALSE; |
280 | 283 | ||
281 | 284 | ||
282 | void AudioWidget::sliderPressed() { | 285 | void AudioWidget::sliderPressed() { |
283 | audioSliderBeingMoved = TRUE; | 286 | audioSliderBeingMoved = TRUE; |
284 | } | 287 | } |
285 | 288 | ||
286 | 289 | ||
287 | void AudioWidget::sliderReleased() { | 290 | void AudioWidget::sliderReleased() { |
288 | audioSliderBeingMoved = FALSE; | 291 | audioSliderBeingMoved = FALSE; |
289 | if ( slider.width() == 0 ) | 292 | if ( slider.width() == 0 ) |
290 | return; | 293 | return; |
291 | long val = long((double)slider.value() * mediaPlayerState->length() / slider.width()); | 294 | long val = long((double)slider.value() * mediaPlayerState->length() / slider.width()); |
292 | mediaPlayerState->setPosition( val ); | 295 | mediaPlayerState->setPosition( val ); |
293 | } | 296 | } |
294 | 297 | ||
295 | void AudioWidget::setPosition( long i ) { | 298 | void AudioWidget::setPosition( long i ) { |
296 | // qDebug("<<<<<<<<<<<<<<<<<<<<<<<<set position %d",i); | 299 | // qDebug("<<<<<<<<<<<<<<<<<<<<<<<<set position %d",i); |
297 | updateSlider( i, mediaPlayerState->length() ); | 300 | updateSlider( i, mediaPlayerState->length() ); |
298 | } | 301 | } |
299 | 302 | ||
300 | 303 | ||
301 | void AudioWidget::setLength( long max ) { | 304 | void AudioWidget::setLength( long max ) { |
302 | updateSlider( mediaPlayerState->position(), max ); | 305 | updateSlider( mediaPlayerState->position(), max ); |
303 | } | 306 | } |
304 | 307 | ||
305 | 308 | ||
306 | void AudioWidget::setView( char view ) { | 309 | void AudioWidget::setView( char view ) { |
307 | 310 | ||
308 | // this isnt working for some reason | 311 | // this isnt working for some reason |
309 | 312 | ||
310 | if ( mediaPlayerState->streaming() ) { | 313 | if ( mediaPlayerState->streaming() ) { |
311 | qDebug("<<<<<<<<<<<<<<file is STREAMING>>>>>>>>>>>>>>>>>>>"); | 314 | qDebug("<<<<<<<<<<<<<<file is STREAMING>>>>>>>>>>>>>>>>>>>"); |
312 | if( !slider.isHidden()) { | 315 | if( !slider.isHidden()) { |
313 | slider.hide(); | 316 | slider.hide(); |
314 | } | 317 | } |
315 | disconnect( mediaPlayerState, SIGNAL( positionChanged(long) ),this, SLOT( setPosition(long) ) ); | 318 | disconnect( mediaPlayerState, SIGNAL( positionChanged(long) ),this, SLOT( setPosition(long) ) ); |
316 | disconnect( mediaPlayerState, SIGNAL( positionUpdated(long) ),this, SLOT( setPosition(long) ) ); | 319 | disconnect( mediaPlayerState, SIGNAL( positionUpdated(long) ),this, SLOT( setPosition(long) ) ); |
317 | } else { | 320 | } else { |
318 | // this stops the slider from being moved, thus | 321 | // this stops the slider from being moved, thus |
319 | // does not stop stream when it reaches the end | 322 | // does not stop stream when it reaches the end |
320 | slider.show(); | 323 | slider.show(); |
321 | connect( mediaPlayerState, SIGNAL( positionChanged(long) ),this, SLOT( setPosition(long) ) ); | 324 | connect( mediaPlayerState, SIGNAL( positionChanged(long) ),this, SLOT( setPosition(long) ) ); |
322 | connect( mediaPlayerState, SIGNAL( positionUpdated(long) ),this, SLOT( setPosition(long) ) ); | 325 | connect( mediaPlayerState, SIGNAL( positionUpdated(long) ),this, SLOT( setPosition(long) ) ); |
323 | } | 326 | } |
324 | 327 | ||
325 | if ( view == 'a' ) { | 328 | if ( view == 'a' ) { |
326 | // startTimer( 150 ); | 329 | // startTimer( 150 ); |
327 | showMaximized(); | 330 | showMaximized(); |
328 | } else { | 331 | } else { |
329 | killTimers(); | 332 | killTimers(); |
330 | hide(); | 333 | hide(); |
331 | } | 334 | } |
332 | qApp->processEvents(); | 335 | qApp->processEvents(); |
333 | } | 336 | } |
334 | 337 | ||
335 | 338 | ||
336 | static QString timeAsString( long length ) { | 339 | static QString timeAsString( long length ) { |
337 | int minutes = length / 60; | 340 | int minutes = length / 60; |
338 | int seconds = length % 60; | 341 | int seconds = length % 60; |
339 | return QString("%1:%2%3").arg( minutes ).arg( seconds / 10 ).arg( seconds % 10 ); | 342 | return QString("%1:%2%3").arg( minutes ).arg( seconds / 10 ).arg( seconds % 10 ); |
340 | } | 343 | } |
341 | 344 | ||
342 | void AudioWidget::updateSlider( long i, long max ) { | 345 | void AudioWidget::updateSlider( long i, long max ) { |
343 | 346 | ||
344 | time.setText( timeAsString( i ) + " / " + timeAsString( max ) ); | 347 | time.setText( timeAsString( i ) + " / " + timeAsString( max ) ); |
345 | // qDebug( timeAsString( i ) + " / " + timeAsString( max ) ) ; | 348 | // qDebug( timeAsString( i ) + " / " + timeAsString( max ) ) ; |
346 | 349 | ||
347 | if ( max == 0 ) { | 350 | if ( max == 0 ) { |
348 | return; | 351 | return; |
349 | } | 352 | } |
350 | // Will flicker too much if we don't do this | 353 | // Will flicker too much if we don't do this |
351 | // Scale to something reasonable | 354 | // Scale to something reasonable |
352 | int width = slider.width(); | 355 | int width = slider.width(); |
353 | int val = int((double)i * width / max); | 356 | int val = int((double)i * width / max); |
354 | if ( !audioSliderBeingMoved ) { | 357 | if ( !audioSliderBeingMoved ) { |
355 | if ( slider.value() != val ) { | 358 | if ( slider.value() != val ) { |
356 | slider.setValue( val ); | 359 | slider.setValue( val ); |
357 | } | 360 | } |
358 | 361 | ||
359 | if ( slider.maxValue() != width ) { | 362 | if ( slider.maxValue() != width ) { |
360 | slider.setMaxValue( width ); | 363 | slider.setMaxValue( width ); |
361 | } | 364 | } |
362 | } | 365 | } |
363 | } | 366 | } |
364 | 367 | ||
365 | 368 | ||
366 | void AudioWidget::setToggleButton( int i, bool down ) { | 369 | void AudioWidget::setToggleButton( int i, bool down ) { |
367 | qDebug("setToggleButton %d", i); | 370 | qDebug("setToggleButton %d", i); |
368 | if ( down != audioButtons[i].isDown ) { | 371 | if ( down != audioButtons[i].isDown ) { |
369 | toggleButton( i ); | 372 | toggleButton( i ); |
370 | } | 373 | } |
371 | } | 374 | } |
372 | 375 | ||
373 | 376 | ||
374 | void AudioWidget::toggleButton( int i ) { | 377 | void AudioWidget::toggleButton( int i ) { |
375 | audioButtons[i].isDown = !audioButtons[i].isDown; | 378 | audioButtons[i].isDown = !audioButtons[i].isDown; |
376 | QPainter p(this); | 379 | QPainter p(this); |
377 | paintButton ( &p, i ); | 380 | paintButton ( &p, i ); |
378 | } | 381 | } |
379 | 382 | ||
380 | 383 | ||
381 | void AudioWidget::paintButton( QPainter *p, int i ) { | 384 | void AudioWidget::paintButton( QPainter *p, int i ) { |
382 | if ( audioButtons[i].isDown ) { | 385 | if ( audioButtons[i].isDown ) { |
383 | p->drawPixmap( xoff, yoff, *buttonPixDown[i] ); | 386 | p->drawPixmap( xoff, yoff, *buttonPixDown[i] ); |
384 | } else { | 387 | } else { |
385 | p->drawPixmap( xoff, yoff, *buttonPixUp[i] ); | 388 | p->drawPixmap( xoff, yoff, *buttonPixUp[i] ); |
386 | } | 389 | } |
387 | } | 390 | } |
388 | 391 | ||
389 | 392 | ||
390 | void AudioWidget::skipFor() { | 393 | void AudioWidget::skipFor() { |
391 | skipDirection = +1; | 394 | skipDirection = +1; |
392 | startTimer( 50 ); | 395 | startTimer( 50 ); |
393 | mediaPlayerState->setPosition( mediaPlayerState->position() + 2 ); | 396 | mediaPlayerState->setPosition( mediaPlayerState->position() + 2 ); |
394 | } | 397 | } |
395 | 398 | ||
396 | void AudioWidget::skipBack() { | 399 | void AudioWidget::skipBack() { |
397 | skipDirection = -1; | 400 | skipDirection = -1; |
398 | startTimer( 50 ); | 401 | startTimer( 50 ); |
399 | mediaPlayerState->setPosition( mediaPlayerState->position() - 2 ); | 402 | mediaPlayerState->setPosition( mediaPlayerState->position() - 2 ); |
400 | } | 403 | } |
401 | 404 | ||
402 | 405 | ||
403 | 406 | ||
404 | void AudioWidget::stopSkip() { | 407 | void AudioWidget::stopSkip() { |
405 | killTimers(); | 408 | killTimers(); |
406 | } | 409 | } |
407 | 410 | ||
408 | 411 | ||
409 | void AudioWidget::timerEvent( QTimerEvent * ) { | 412 | void AudioWidget::timerEvent( QTimerEvent * ) { |
410 | if ( skipDirection == +1 ) { | 413 | if ( skipDirection == +1 ) { |
411 | mediaPlayerState->setPosition( mediaPlayerState->position() + 2 ); | 414 | mediaPlayerState->setPosition( mediaPlayerState->position() + 2 ); |
412 | } else if ( skipDirection == -1 ) { | 415 | } else if ( skipDirection == -1 ) { |
413 | mediaPlayerState->setPosition( mediaPlayerState->position() - 2 ); | 416 | mediaPlayerState->setPosition( mediaPlayerState->position() - 2 ); |
414 | } | 417 | } |
415 | } | 418 | } |
416 | 419 | ||
417 | 420 | ||
418 | void AudioWidget::mouseMoveEvent( QMouseEvent *event ) { | 421 | void AudioWidget::mouseMoveEvent( QMouseEvent *event ) { |
419 | for ( int i = 0; i < numButtons; i++ ) { | 422 | for ( int i = 0; i < numButtons; i++ ) { |
420 | if ( event->state() == QMouseEvent::LeftButton ) { | 423 | if ( event->state() == QMouseEvent::LeftButton ) { |
421 | // The test to see if the mouse click is inside the button or not | 424 | // The test to see if the mouse click is inside the button or not |
422 | int x = event->pos().x() - xoff; | 425 | int x = event->pos().x() - xoff; |
423 | int y = event->pos().y() - yoff; | 426 | int y = event->pos().y() - yoff; |
424 | 427 | ||
425 | bool isOnButton = ( x > 0 && y > 0 && x < imgButtonMask->width() | 428 | bool isOnButton = ( x > 0 && y > 0 && x < imgButtonMask->width() |
426 | && y < imgButtonMask->height() | 429 | && y < imgButtonMask->height() |
427 | && imgButtonMask->pixelIndex( x, y ) == i + 1 ); | 430 | && imgButtonMask->pixelIndex( x, y ) == i + 1 ); |
428 | 431 | ||
429 | if ( isOnButton && !audioButtons[i].isHeld ) { | 432 | if ( isOnButton && !audioButtons[i].isHeld ) { |
430 | audioButtons[i].isHeld = TRUE; | 433 | audioButtons[i].isHeld = TRUE; |
431 | toggleButton(i); | 434 | toggleButton(i); |
432 | switch (i) { | 435 | switch (i) { |
433 | case AudioVolumeUp: | 436 | case AudioVolumeUp: |
434 | emit moreClicked(); | 437 | emit moreClicked(); |
435 | return; | 438 | return; |
436 | case AudioVolumeDown: | 439 | case AudioVolumeDown: |
437 | emit lessClicked(); | 440 | emit lessClicked(); |
438 | return; | 441 | return; |
439 | case AudioForward: | 442 | case AudioForward: |
440 | emit forwardClicked(); | 443 | emit forwardClicked(); |
441 | return; | 444 | return; |
442 | case AudioBack: | 445 | case AudioBack: |
443 | emit backClicked(); | 446 | emit backClicked(); |
444 | return; | 447 | return; |
445 | } | 448 | } |
446 | } else if ( !isOnButton && audioButtons[i].isHeld ) { | 449 | } else if ( !isOnButton && audioButtons[i].isHeld ) { |
447 | audioButtons[i].isHeld = FALSE; | 450 | audioButtons[i].isHeld = FALSE; |
448 | toggleButton(i); | 451 | toggleButton(i); |
449 | } | 452 | } |
450 | } else { | 453 | } else { |
451 | if ( audioButtons[i].isHeld ) { | 454 | if ( audioButtons[i].isHeld ) { |
452 | audioButtons[i].isHeld = FALSE; | 455 | audioButtons[i].isHeld = FALSE; |
453 | if ( !audioButtons[i].isToggle ) { | 456 | if ( !audioButtons[i].isToggle ) { |
454 | setToggleButton( i, FALSE ); | 457 | setToggleButton( i, FALSE ); |
455 | } | 458 | } |
456 | qDebug("mouseEvent %d", i); | 459 | qDebug("mouseEvent %d", i); |
457 | switch (i) { | 460 | switch (i) { |
458 | case AudioPlay: | 461 | case AudioPlay: |
459 | if( mediaPlayerState->isPaused ) { | 462 | if( mediaPlayerState->isPaused ) { |
460 | // setToggleButton( i, FALSE ); | 463 | // setToggleButton( i, FALSE ); |
461 | mediaPlayerState->setPaused( FALSE ); | 464 | mediaPlayerState->setPaused( FALSE ); |
462 | return; | 465 | return; |
463 | } else if( !mediaPlayerState->isPaused ) { | 466 | } else if( !mediaPlayerState->isPaused ) { |
464 | // setToggleButton( i, TRUE ); | 467 | // setToggleButton( i, TRUE ); |
465 | mediaPlayerState->setPaused( TRUE ); | 468 | mediaPlayerState->setPaused( TRUE ); |
466 | return; | 469 | return; |
467 | } else { | 470 | } else { |
468 | // setToggleButton( i, TRUE ); | 471 | // setToggleButton( i, TRUE ); |
469 | // mediaPlayerState->setPlaying( videoButtons[i].isDown ); | 472 | // mediaPlayerState->setPlaying( videoButtons[i].isDown ); |
470 | } | 473 | } |
471 | case AudioStop: mediaPlayerState->setPlaying(FALSE); return; | 474 | case AudioStop: mediaPlayerState->setPlaying(FALSE); return; |
472 | case AudioNext: mediaPlayerState->setNext(); return; | 475 | case AudioNext: if(playList->whichList() ==0) mediaPlayerState->setNext(); return; |
473 | case AudioPrevious: mediaPlayerState->setPrev(); return; | 476 | case AudioPrevious: if(playList->whichList() ==0) mediaPlayerState->setPrev(); return; |
474 | case AudioLoop: mediaPlayerState->setLooping(audioButtons[i].isDown); return; | 477 | case AudioLoop: mediaPlayerState->setLooping(audioButtons[i].isDown); return; |
475 | case AudioVolumeUp: emit moreReleased(); return; | 478 | case AudioVolumeUp: emit moreReleased(); return; |
476 | case AudioVolumeDown: emit lessReleased(); return; | 479 | case AudioVolumeDown: emit lessReleased(); return; |
477 | case AudioPlayList: mediaPlayerState->setList(); return; | 480 | case AudioPlayList: mediaPlayerState->setList(); return; |
478 | case AudioForward: emit forwardReleased(); return; | 481 | case AudioForward: emit forwardReleased(); return; |
479 | case AudioBack: emit backReleased(); return; | 482 | case AudioBack: emit backReleased(); return; |
480 | } | 483 | } |
481 | } | 484 | } |
482 | } | 485 | } |
483 | } | 486 | } |
484 | } | 487 | } |
485 | 488 | ||
486 | 489 | ||
487 | void AudioWidget::mousePressEvent( QMouseEvent *event ) { | 490 | void AudioWidget::mousePressEvent( QMouseEvent *event ) { |
488 | mouseMoveEvent( event ); | 491 | mouseMoveEvent( event ); |
489 | } | 492 | } |
490 | 493 | ||
491 | 494 | ||
492 | void AudioWidget::mouseReleaseEvent( QMouseEvent *event ) { | 495 | void AudioWidget::mouseReleaseEvent( QMouseEvent *event ) { |
493 | mouseMoveEvent( event ); | 496 | mouseMoveEvent( event ); |
494 | } | 497 | } |
495 | 498 | ||
496 | 499 | ||
497 | void AudioWidget::showEvent( QShowEvent* ) { | 500 | void AudioWidget::showEvent( QShowEvent* ) { |
498 | QMouseEvent event( QEvent::MouseMove, QPoint( 0, 0 ), 0, 0 ); | 501 | QMouseEvent event( QEvent::MouseMove, QPoint( 0, 0 ), 0, 0 ); |
499 | mouseMoveEvent( &event ); | 502 | mouseMoveEvent( &event ); |
500 | } | 503 | } |
501 | 504 | ||
502 | 505 | ||
503 | void AudioWidget::closeEvent( QCloseEvent* ) { | 506 | void AudioWidget::closeEvent( QCloseEvent* ) { |
504 | mediaPlayerState->setList(); | 507 | mediaPlayerState->setList(); |
505 | } | 508 | } |
506 | 509 | ||
507 | 510 | ||
508 | void AudioWidget::paintEvent( QPaintEvent * pe) { | 511 | void AudioWidget::paintEvent( QPaintEvent * pe) { |
509 | if ( !pe->erased() ) { | 512 | if ( !pe->erased() ) { |
510 | // Combine with background and double buffer | 513 | // Combine with background and double buffer |
511 | QPixmap pix( pe->rect().size() ); | 514 | QPixmap pix( pe->rect().size() ); |
512 | QPainter p( &pix ); | 515 | QPainter p( &pix ); |
513 | p.translate( -pe->rect().topLeft().x(), -pe->rect().topLeft().y() ); | 516 | p.translate( -pe->rect().topLeft().x(), -pe->rect().topLeft().y() ); |
514 | p.drawTiledPixmap( pe->rect(), *pixBg, pe->rect().topLeft() ); | 517 | p.drawTiledPixmap( pe->rect(), *pixBg, pe->rect().topLeft() ); |
515 | for ( int i = 0; i < numButtons; i++ ) | 518 | for ( int i = 0; i < numButtons; i++ ) |
516 | paintButton( &p, i ); | 519 | paintButton( &p, i ); |
517 | QPainter p2( this ); | 520 | QPainter p2( this ); |
518 | p2.drawPixmap( pe->rect().topLeft(), pix ); | 521 | p2.drawPixmap( pe->rect().topLeft(), pix ); |
519 | } else { | 522 | } else { |
520 | QPainter p( this ); | 523 | QPainter p( this ); |
521 | for ( int i = 0; i < numButtons; i++ ) | 524 | for ( int i = 0; i < numButtons; i++ ) |
522 | paintButton( &p, i ); | 525 | paintButton( &p, i ); |
523 | } | 526 | } |
524 | } | 527 | } |
525 | 528 | ||
526 | void AudioWidget::keyReleaseEvent( QKeyEvent *e) { | 529 | void AudioWidget::keyReleaseEvent( QKeyEvent *e) { |
527 | switch ( e->key() ) { | 530 | switch ( e->key() ) { |
528 | ////////////////////////////// Zaurus keys | 531 | ////////////////////////////// Zaurus keys |
529 | case Key_Home: | 532 | case Key_Home: |
530 | break; | 533 | break; |
531 | case Key_F9: //activity | 534 | case Key_F9: //activity |
532 | hide(); | 535 | hide(); |
533 | // qDebug("Audio F9"); | 536 | // qDebug("Audio F9"); |
534 | break; | 537 | break; |
535 | case Key_F10: //contacts | 538 | case Key_F10: //contacts |
536 | break; | 539 | break; |
537 | case Key_F11: //menu | 540 | case Key_F11: //menu |
538 | mediaPlayerState->toggleBlank(); | 541 | mediaPlayerState->toggleBlank(); |
539 | break; | 542 | break; |
540 | case Key_F12: //home | 543 | case Key_F12: //home |
541 | break; | 544 | break; |
542 | case Key_F13: //mail | 545 | case Key_F13: //mail |
543 | mediaPlayerState->toggleBlank(); | 546 | mediaPlayerState->toggleBlank(); |
544 | break; | 547 | break; |
545 | case Key_Space: { | 548 | case Key_Space: { |
546 | if(mediaPlayerState->playing()) { | 549 | if(mediaPlayerState->playing()) { |
547 | // toggleButton(1); | 550 | // toggleButton(1); |
548 | mediaPlayerState->setPlaying(FALSE); | 551 | mediaPlayerState->setPlaying(FALSE); |
549 | // toggleButton(1); | 552 | // toggleButton(1); |
550 | } else { | 553 | } else { |
551 | // toggleButton(0); | 554 | // toggleButton(0); |
552 | mediaPlayerState->setPlaying(TRUE); | 555 | mediaPlayerState->setPlaying(TRUE); |
553 | // toggleButton(0); | 556 | // toggleButton(0); |
554 | } | 557 | } |
555 | } | 558 | } |
556 | break; | 559 | break; |
557 | case Key_Down: | 560 | case Key_Down: |
558 | // toggleButton(6); | 561 | // toggleButton(6); |
559 | emit lessClicked(); | 562 | emit lessClicked(); |
560 | emit lessReleased(); | 563 | emit lessReleased(); |
561 | // toggleButton(6); | 564 | // toggleButton(6); |
562 | break; | 565 | break; |
563 | case Key_Up: | 566 | case Key_Up: |
564 | // toggleButton(5); | 567 | // toggleButton(5); |
565 | emit moreClicked(); | 568 | emit moreClicked(); |
566 | emit moreReleased(); | 569 | emit moreReleased(); |
567 | // toggleButton(5); | 570 | // toggleButton(5); |
568 | break; | 571 | break; |
569 | case Key_Right: | 572 | case Key_Right: |
570 | // toggleButton(3); | 573 | // toggleButton(3); |
571 | mediaPlayerState->setNext(); | 574 | mediaPlayerState->setNext(); |
572 | // toggleButton(3); | 575 | // toggleButton(3); |
573 | break; | 576 | break; |
574 | case Key_Left: | 577 | case Key_Left: |
575 | // toggleButton(4); | 578 | // toggleButton(4); |
576 | mediaPlayerState->setPrev(); | 579 | mediaPlayerState->setPrev(); |
577 | // toggleButton(4); | 580 | // toggleButton(4); |
578 | break; | 581 | break; |
579 | case Key_Escape: { | 582 | case Key_Escape: { |
580 | /* | 583 | /* |
581 | * author pleas tell me where the i come from .-) | 584 | * author pleas tell me where the i come from .-) |
582 | #if defined(QT_QWS_IPAQ) | 585 | #if defined(QT_QWS_IPAQ) |
583 | if( mediaPlayerState->isPaused ) { | 586 | if( mediaPlayerState->isPaused ) { |
584 | setToggleButton( i, FALSE ); | 587 | setToggleButton( i, FALSE ); |
585 | mediaPlayerState->setPaused( FALSE ); | 588 | mediaPlayerState->setPaused( FALSE ); |
586 | } else if( !mediaPlayerState->isPaused ) { | 589 | } else if( !mediaPlayerState->isPaused ) { |
587 | setToggleButton( i, TRUE ); | 590 | setToggleButton( i, TRUE ); |
588 | mediaPlayerState->setPaused( TRUE ); | 591 | mediaPlayerState->setPaused( TRUE ); |
589 | } | 592 | } |
590 | #endif | 593 | #endif |
591 | */ | 594 | */ |
592 | } | 595 | } |
593 | break; | 596 | break; |
594 | 597 | ||
595 | }; | 598 | }; |
596 | } | 599 | } |
diff --git a/noncore/multimedia/opieplayer2/videowidget.cpp b/noncore/multimedia/opieplayer2/videowidget.cpp index ffda2e4..8e3a365 100644 --- a/noncore/multimedia/opieplayer2/videowidget.cpp +++ b/noncore/multimedia/opieplayer2/videowidget.cpp | |||
@@ -1,184 +1,186 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of the Opie Project | 2 | This file is part of the Opie Project |
3 | 3 | ||
4 | Copyright (c) 2002 Max Reiss <harlekin@handhelds.org> | 4 | Copyright (c) 2002 Max Reiss <harlekin@handhelds.org> |
5 | Copyright (c) 2002 L. Potter <ljp@llornkcor.com> | 5 | Copyright (c) 2002 L. Potter <ljp@llornkcor.com> |
6 | Copyright (c) 2002 Holger Freyther <zecke@handhelds.org> | 6 | Copyright (c) 2002 Holger Freyther <zecke@handhelds.org> |
7 | =. | 7 | =. |
8 | .=l. | 8 | .=l. |
9 | .>+-= | 9 | .>+-= |
10 | _;:, .> :=|. This program is free software; you can | 10 | _;:, .> :=|. This program is free software; you can |
11 | .> <`_, > . <= redistribute it and/or modify it under | 11 | .> <`_, > . <= redistribute it and/or modify it under |
12 | :`=1 )Y*s>-.-- : the terms of the GNU General Public | 12 | :`=1 )Y*s>-.-- : the terms of the GNU General Public |
13 | .="- .-=="i, .._ License as published by the Free Software | 13 | .="- .-=="i, .._ License as published by the Free Software |
14 | - . .-<_> .<> Foundation; either version 2 of the License, | 14 | - . .-<_> .<> Foundation; either version 2 of the License, |
15 | ._= =} : or (at your option) any later version. | 15 | ._= =} : or (at your option) any later version. |
16 | .%`+i> _;_. | 16 | .%`+i> _;_. |
17 | .i_,=:_. -<s. This program is distributed in the hope that | 17 | .i_,=:_. -<s. This program is distributed in the hope that |
18 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 18 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
19 | : .. .:, . . . without even the implied warranty of | 19 | : .. .:, . . . without even the implied warranty of |
20 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 20 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
21 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | 21 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU |
22 | ..}^=.= = ; Library General Public License for more | 22 | ..}^=.= = ; Library General Public License for more |
23 | ++= -. .` .: details. | 23 | ++= -. .` .: details. |
24 | : = ...= . :.=- | 24 | : = ...= . :.=- |
25 | -. .:....=;==+<; You should have received a copy of the GNU | 25 | -. .:....=;==+<; You should have received a copy of the GNU |
26 | -_. . . )=. = Library General Public License along with | 26 | -_. . . )=. = Library General Public License along with |
27 | -- :-=` this library; see the file COPYING.LIB. | 27 | -- :-=` this library; see the file COPYING.LIB. |
28 | If not, write to the Free Software Foundation, | 28 | If not, write to the Free Software Foundation, |
29 | Inc., 59 Temple Place - Suite 330, | 29 | Inc., 59 Temple Place - Suite 330, |
30 | Boston, MA 02111-1307, USA. | 30 | Boston, MA 02111-1307, USA. |
31 | 31 | ||
32 | */ | 32 | */ |
33 | 33 | ||
34 | #include <qpe/qpeapplication.h> | 34 | #include <qpe/qpeapplication.h> |
35 | #include <qpe/resource.h> | 35 | #include <qpe/resource.h> |
36 | #include <qpe/mediaplayerplugininterface.h> | 36 | #include <qpe/mediaplayerplugininterface.h> |
37 | #include <qpe/config.h> | 37 | #include <qpe/config.h> |
38 | 38 | ||
39 | 39 | ||
40 | #include <qwidget.h> | 40 | #include <qwidget.h> |
41 | #include <qpainter.h> | 41 | #include <qpainter.h> |
42 | #include <qpixmap.h> | 42 | #include <qpixmap.h> |
43 | #include <qslider.h> | 43 | #include <qslider.h> |
44 | #include <qdrawutil.h> | 44 | #include <qdrawutil.h> |
45 | #include "videowidget.h" | 45 | #include "videowidget.h" |
46 | #include "mediaplayerstate.h" | 46 | #include "mediaplayerstate.h" |
47 | #include "playlistwidget.h" | ||
47 | 48 | ||
48 | 49 | ||
49 | #ifdef Q_WS_QWS | 50 | #ifdef Q_WS_QWS |
50 | # define USE_DIRECT_PAINTER | 51 | # define USE_DIRECT_PAINTER |
51 | # include <qdirectpainter_qws.h> | 52 | # include <qdirectpainter_qws.h> |
52 | # include <qgfxraster_qws.h> | 53 | # include <qgfxraster_qws.h> |
53 | #endif | 54 | #endif |
54 | 55 | ||
55 | 56 | ||
56 | extern MediaPlayerState *mediaPlayerState; | 57 | extern MediaPlayerState *mediaPlayerState; |
58 | extern PlayListWidget *playList; | ||
57 | 59 | ||
58 | 60 | ||
59 | static const int xo = 2; // movable x offset | 61 | static const int xo = 2; // movable x offset |
60 | static const int yo = 0; // movable y offset | 62 | static const int yo = 0; // movable y offset |
61 | 63 | ||
62 | 64 | ||
63 | struct MediaButton { | 65 | struct MediaButton { |
64 | bool isToggle, isHeld, isDown; | 66 | bool isToggle, isHeld, isDown; |
65 | }; | 67 | }; |
66 | 68 | ||
67 | MediaButton videoButtons[] = { | 69 | MediaButton videoButtons[] = { |
68 | { FALSE, FALSE, FALSE }, // stop | 70 | { FALSE, FALSE, FALSE }, // stop |
69 | { TRUE, FALSE, FALSE }, // play | 71 | { TRUE, FALSE, FALSE }, // play |
70 | { FALSE, FALSE, FALSE }, // previous | 72 | { FALSE, FALSE, FALSE }, // previous |
71 | { FALSE, FALSE, FALSE }, // next | 73 | { FALSE, FALSE, FALSE }, // next |
72 | { FALSE, FALSE, FALSE }, // volUp | 74 | { FALSE, FALSE, FALSE }, // volUp |
73 | { FALSE, FALSE, FALSE }, // volDown | 75 | { FALSE, FALSE, FALSE }, // volDown |
74 | { TRUE, FALSE, FALSE } // fullscreen | 76 | { TRUE, FALSE, FALSE } // fullscreen |
75 | }; | 77 | }; |
76 | 78 | ||
77 | const char *skinV_mask_file_names[7] = { | 79 | const char *skinV_mask_file_names[7] = { |
78 | "stop","play","back","fwd","up","down","full" | 80 | "stop","play","back","fwd","up","down","full" |
79 | }; | 81 | }; |
80 | 82 | ||
81 | static const int numVButtons = (sizeof(videoButtons)/sizeof(MediaButton)); | 83 | static const int numVButtons = (sizeof(videoButtons)/sizeof(MediaButton)); |
82 | 84 | ||
83 | 85 | ||
84 | VideoWidget::VideoWidget(QWidget* parent, const char* name, WFlags f) : | 86 | VideoWidget::VideoWidget(QWidget* parent, const char* name, WFlags f) : |
85 | QWidget( parent, name, f ), scaledWidth( 0 ), scaledHeight( 0 ) { | 87 | QWidget( parent, name, f ), scaledWidth( 0 ), scaledHeight( 0 ) { |
86 | 88 | ||
87 | 89 | ||
88 | setCaption( tr("OpiePlayer - Video") ); | 90 | setCaption( tr("OpiePlayer - Video") ); |
89 | 91 | ||
90 | videoFrame = new XineVideoWidget ( this, "Video frame" ); | 92 | videoFrame = new XineVideoWidget ( this, "Video frame" ); |
91 | 93 | ||
92 | connect ( videoFrame, SIGNAL( videoResized ( const QSize & )), this, SIGNAL( videoResized ( const QSize & ))); | 94 | connect ( videoFrame, SIGNAL( videoResized ( const QSize & )), this, SIGNAL( videoResized ( const QSize & ))); |
93 | connect ( videoFrame, SIGNAL( clicked () ), this, SLOT ( backToNormal() ) ); | 95 | connect ( videoFrame, SIGNAL( clicked () ), this, SLOT ( backToNormal() ) ); |
94 | 96 | ||
95 | Config cfg("OpiePlayer"); | 97 | Config cfg("OpiePlayer"); |
96 | cfg.setGroup("Options"); | 98 | cfg.setGroup("Options"); |
97 | skin = cfg.readEntry("Skin","default"); | 99 | skin = cfg.readEntry("Skin","default"); |
98 | 100 | ||
99 | QString skinPath = "opieplayer2/skins/" + skin; | 101 | QString skinPath = "opieplayer2/skins/" + skin; |
100 | pixBg = new QPixmap( Resource::loadPixmap( QString("%1/background").arg(skinPath) ) ); | 102 | pixBg = new QPixmap( Resource::loadPixmap( QString("%1/background").arg(skinPath) ) ); |
101 | imgUp = new QImage( Resource::loadImage( QString("%1/skinV_up").arg(skinPath) ) ); | 103 | imgUp = new QImage( Resource::loadImage( QString("%1/skinV_up").arg(skinPath) ) ); |
102 | imgDn = new QImage( Resource::loadImage( QString("%1/skinV_down").arg(skinPath) ) ); | 104 | imgDn = new QImage( Resource::loadImage( QString("%1/skinV_down").arg(skinPath) ) ); |
103 | 105 | ||
104 | imgButtonMask = new QImage( imgUp->width(), imgUp->height(), 8, 255 ); | 106 | imgButtonMask = new QImage( imgUp->width(), imgUp->height(), 8, 255 ); |
105 | imgButtonMask->fill( 0 ); | 107 | imgButtonMask->fill( 0 ); |
106 | 108 | ||
107 | for ( int i = 0; i < 7; i++ ) { | 109 | for ( int i = 0; i < 7; i++ ) { |
108 | QString filename = QString( QPEApplication::qpeDir() + "/pics/" + skinPath + "/skinV_mask_" + skinV_mask_file_names[i] + ".png" ); | 110 | QString filename = QString( QPEApplication::qpeDir() + "/pics/" + skinPath + "/skinV_mask_" + skinV_mask_file_names[i] + ".png" ); |
109 | masks[i] = new QBitmap( filename ); | 111 | masks[i] = new QBitmap( filename ); |
110 | 112 | ||
111 | if ( !masks[i]->isNull() ) { | 113 | if ( !masks[i]->isNull() ) { |
112 | QImage imgMask = masks[i]->convertToImage(); | 114 | QImage imgMask = masks[i]->convertToImage(); |
113 | uchar **dest = imgButtonMask->jumpTable(); | 115 | uchar **dest = imgButtonMask->jumpTable(); |
114 | for ( int y = 0; y < imgUp->height(); y++ ) { | 116 | for ( int y = 0; y < imgUp->height(); y++ ) { |
115 | uchar *line = dest[y]; | 117 | uchar *line = dest[y]; |
116 | for ( int x = 0; x < imgUp->width(); x++ ) { | 118 | for ( int x = 0; x < imgUp->width(); x++ ) { |
117 | if ( !qRed( imgMask.pixel( x, y ) ) ) | 119 | if ( !qRed( imgMask.pixel( x, y ) ) ) |
118 | line[x] = i + 1; | 120 | line[x] = i + 1; |
119 | } | 121 | } |
120 | } | 122 | } |
121 | } | 123 | } |
122 | } | 124 | } |
123 | 125 | ||
124 | for ( int i = 0; i < 7; i++ ) { | 126 | for ( int i = 0; i < 7; i++ ) { |
125 | buttonPixUp[i] = NULL; | 127 | buttonPixUp[i] = NULL; |
126 | buttonPixDown[i] = NULL; | 128 | buttonPixDown[i] = NULL; |
127 | } | 129 | } |
128 | 130 | ||
129 | setBackgroundPixmap( *pixBg ); | 131 | setBackgroundPixmap( *pixBg ); |
130 | 132 | ||
131 | slider = new QSlider( Qt::Horizontal, this ); | 133 | slider = new QSlider( Qt::Horizontal, this ); |
132 | slider->setMinValue( 0 ); | 134 | slider->setMinValue( 0 ); |
133 | slider->setMaxValue( 1 ); | 135 | slider->setMaxValue( 1 ); |
134 | slider->setBackgroundPixmap( Resource::loadPixmap( backgroundPix ) ); | 136 | slider->setBackgroundPixmap( Resource::loadPixmap( backgroundPix ) ); |
135 | slider->setFocusPolicy( QWidget::NoFocus ); | 137 | slider->setFocusPolicy( QWidget::NoFocus ); |
136 | 138 | ||
137 | resizeEvent( NULL ); | 139 | resizeEvent( NULL ); |
138 | 140 | ||
139 | connect( slider, SIGNAL( sliderPressed() ), this, SLOT( sliderPressed() ) ); | 141 | connect( slider, SIGNAL( sliderPressed() ), this, SLOT( sliderPressed() ) ); |
140 | connect( slider, SIGNAL( sliderReleased() ), this, SLOT( sliderReleased() ) ); | 142 | connect( slider, SIGNAL( sliderReleased() ), this, SLOT( sliderReleased() ) ); |
141 | connect( mediaPlayerState, SIGNAL( lengthChanged(long) ), this, SLOT( setLength(long) ) ); | 143 | connect( mediaPlayerState, SIGNAL( lengthChanged(long) ), this, SLOT( setLength(long) ) ); |
142 | connect( mediaPlayerState, SIGNAL( viewChanged(char) ), this, SLOT( setView(char) ) ); | 144 | connect( mediaPlayerState, SIGNAL( viewChanged(char) ), this, SLOT( setView(char) ) ); |
143 | connect( mediaPlayerState, SIGNAL( playingToggled(bool) ), this, SLOT( setPlaying(bool) ) ); | 145 | connect( mediaPlayerState, SIGNAL( playingToggled(bool) ), this, SLOT( setPlaying(bool) ) ); |
144 | 146 | ||
145 | setLength( mediaPlayerState->length() ); | 147 | setLength( mediaPlayerState->length() ); |
146 | setPosition( mediaPlayerState->position() ); | 148 | setPosition( mediaPlayerState->position() ); |
147 | setFullscreen( mediaPlayerState->fullscreen() ); | 149 | setFullscreen( mediaPlayerState->fullscreen() ); |
148 | setPlaying( mediaPlayerState->playing() ); | 150 | setPlaying( mediaPlayerState->playing() ); |
149 | } | 151 | } |
150 | 152 | ||
151 | 153 | ||
152 | VideoWidget::~VideoWidget() { | 154 | VideoWidget::~VideoWidget() { |
153 | 155 | ||
154 | for ( int i = 0; i < 7; i++ ) { | 156 | for ( int i = 0; i < 7; i++ ) { |
155 | delete buttonPixUp[i]; | 157 | delete buttonPixUp[i]; |
156 | delete buttonPixDown[i]; | 158 | delete buttonPixDown[i]; |
157 | } | 159 | } |
158 | 160 | ||
159 | delete pixBg; | 161 | delete pixBg; |
160 | delete imgUp; | 162 | delete imgUp; |
161 | delete imgDn; | 163 | delete imgDn; |
162 | delete imgButtonMask; | 164 | delete imgButtonMask; |
163 | for ( int i = 0; i < 7; i++ ) { | 165 | for ( int i = 0; i < 7; i++ ) { |
164 | delete masks[i]; | 166 | delete masks[i]; |
165 | } | 167 | } |
166 | 168 | ||
167 | } | 169 | } |
168 | 170 | ||
169 | QPixmap *combineVImageWithBackground( QImage img, QPixmap bg, QPoint offset ) { | 171 | QPixmap *combineVImageWithBackground( QImage img, QPixmap bg, QPoint offset ) { |
170 | QPixmap pix( img.width(), img.height() ); | 172 | QPixmap pix( img.width(), img.height() ); |
171 | QPainter p( &pix ); | 173 | QPainter p( &pix ); |
172 | p.drawTiledPixmap( pix.rect(), bg, offset ); | 174 | p.drawTiledPixmap( pix.rect(), bg, offset ); |
173 | p.drawImage( 0, 0, img ); | 175 | p.drawImage( 0, 0, img ); |
174 | return new QPixmap( pix ); | 176 | return new QPixmap( pix ); |
175 | } | 177 | } |
176 | 178 | ||
177 | QPixmap *maskVPixToMask( QPixmap pix, QBitmap mask ) { | 179 | QPixmap *maskVPixToMask( QPixmap pix, QBitmap mask ) { |
178 | QPixmap *pixmap = new QPixmap( pix ); | 180 | QPixmap *pixmap = new QPixmap( pix ); |
179 | pixmap->setMask( mask ); | 181 | pixmap->setMask( mask ); |
180 | return pixmap; | 182 | return pixmap; |
181 | } | 183 | } |
182 | 184 | ||
183 | void VideoWidget::resizeEvent( QResizeEvent * ) { | 185 | void VideoWidget::resizeEvent( QResizeEvent * ) { |
184 | int h = height(); | 186 | int h = height(); |
@@ -213,258 +215,258 @@ void VideoWidget::resizeEvent( QResizeEvent * ) { | |||
213 | } | 215 | } |
214 | 216 | ||
215 | static bool videoSliderBeingMoved = FALSE; | 217 | static bool videoSliderBeingMoved = FALSE; |
216 | 218 | ||
217 | void VideoWidget::sliderPressed() { | 219 | void VideoWidget::sliderPressed() { |
218 | videoSliderBeingMoved = TRUE; | 220 | videoSliderBeingMoved = TRUE; |
219 | } | 221 | } |
220 | 222 | ||
221 | void VideoWidget::sliderReleased() { | 223 | void VideoWidget::sliderReleased() { |
222 | videoSliderBeingMoved = FALSE; | 224 | videoSliderBeingMoved = FALSE; |
223 | if ( slider->width() == 0 ) { | 225 | if ( slider->width() == 0 ) { |
224 | return; | 226 | return; |
225 | } | 227 | } |
226 | long val = long((double)slider->value() * mediaPlayerState->length() / slider->width()); | 228 | long val = long((double)slider->value() * mediaPlayerState->length() / slider->width()); |
227 | mediaPlayerState->setPosition( val ); | 229 | mediaPlayerState->setPosition( val ); |
228 | } | 230 | } |
229 | 231 | ||
230 | void VideoWidget::setPosition( long i ) { | 232 | void VideoWidget::setPosition( long i ) { |
231 | updateSlider( i, mediaPlayerState->length() ); | 233 | updateSlider( i, mediaPlayerState->length() ); |
232 | } | 234 | } |
233 | 235 | ||
234 | 236 | ||
235 | void VideoWidget::setLength( long max ) { | 237 | void VideoWidget::setLength( long max ) { |
236 | updateSlider( mediaPlayerState->position(), max ); | 238 | updateSlider( mediaPlayerState->position(), max ); |
237 | } | 239 | } |
238 | 240 | ||
239 | void VideoWidget::setView( char view ) { | 241 | void VideoWidget::setView( char view ) { |
240 | 242 | ||
241 | if ( view == 'v' ) { | 243 | if ( view == 'v' ) { |
242 | makeVisible(); | 244 | makeVisible(); |
243 | } else { | 245 | } else { |
244 | // Effectively blank the view next time we show it so it looks nicer | 246 | // Effectively blank the view next time we show it so it looks nicer |
245 | scaledWidth = 0; | 247 | scaledWidth = 0; |
246 | scaledHeight = 0; | 248 | scaledHeight = 0; |
247 | hide(); | 249 | hide(); |
248 | } | 250 | } |
249 | } | 251 | } |
250 | 252 | ||
251 | void VideoWidget::updateSlider( long i, long max ) { | 253 | void VideoWidget::updateSlider( long i, long max ) { |
252 | // Will flicker too much if we don't do this | 254 | // Will flicker too much if we don't do this |
253 | if ( max == 0 ) { | 255 | if ( max == 0 ) { |
254 | return; | 256 | return; |
255 | } | 257 | } |
256 | int width = slider->width(); | 258 | int width = slider->width(); |
257 | int val = int((double)i * width / max); | 259 | int val = int((double)i * width / max); |
258 | if ( !mediaPlayerState->fullscreen() && !videoSliderBeingMoved ) { | 260 | if ( !mediaPlayerState->fullscreen() && !videoSliderBeingMoved ) { |
259 | if ( slider->value() != val ) { | 261 | if ( slider->value() != val ) { |
260 | slider->setValue( val ); | 262 | slider->setValue( val ); |
261 | } | 263 | } |
262 | if ( slider->maxValue() != width ) { | 264 | if ( slider->maxValue() != width ) { |
263 | slider->setMaxValue( width ); | 265 | slider->setMaxValue( width ); |
264 | } | 266 | } |
265 | } | 267 | } |
266 | } | 268 | } |
267 | 269 | ||
268 | void VideoWidget::setToggleButton( int i, bool down ) { | 270 | void VideoWidget::setToggleButton( int i, bool down ) { |
269 | if ( down != videoButtons[i].isDown ) { | 271 | if ( down != videoButtons[i].isDown ) { |
270 | toggleButton( i ); | 272 | toggleButton( i ); |
271 | } | 273 | } |
272 | } | 274 | } |
273 | 275 | ||
274 | void VideoWidget::toggleButton( int i ) { | 276 | void VideoWidget::toggleButton( int i ) { |
275 | videoButtons[i].isDown = !videoButtons[i].isDown; | 277 | videoButtons[i].isDown = !videoButtons[i].isDown; |
276 | QPainter p(this); | 278 | QPainter p(this); |
277 | paintButton ( &p, i ); | 279 | paintButton ( &p, i ); |
278 | } | 280 | } |
279 | 281 | ||
280 | void VideoWidget::paintButton( QPainter *p, int i ) { | 282 | void VideoWidget::paintButton( QPainter *p, int i ) { |
281 | 283 | ||
282 | if ( videoButtons[i].isDown ) { | 284 | if ( videoButtons[i].isDown ) { |
283 | p->drawPixmap( xoff, yoff, *buttonPixDown[i] ); | 285 | p->drawPixmap( xoff, yoff, *buttonPixDown[i] ); |
284 | } else { | 286 | } else { |
285 | p->drawPixmap( xoff, yoff, *buttonPixUp[i] ); | 287 | p->drawPixmap( xoff, yoff, *buttonPixUp[i] ); |
286 | } | 288 | } |
287 | } | 289 | } |
288 | 290 | ||
289 | void VideoWidget::mouseMoveEvent( QMouseEvent *event ) { | 291 | void VideoWidget::mouseMoveEvent( QMouseEvent *event ) { |
290 | for ( int i = 0; i < numVButtons; i++ ) { | 292 | for ( int i = 0; i < numVButtons; i++ ) { |
291 | if ( event->state() == QMouseEvent::LeftButton ) { | 293 | if ( event->state() == QMouseEvent::LeftButton ) { |
292 | // The test to see if the mouse click is inside the button or not | 294 | // The test to see if the mouse click is inside the button or not |
293 | int x = event->pos().x() - xoff; | 295 | int x = event->pos().x() - xoff; |
294 | int y = event->pos().y() - yoff; | 296 | int y = event->pos().y() - yoff; |
295 | 297 | ||
296 | bool isOnButton = ( x > 0 && y > 0 && x < imgButtonMask->width() | 298 | bool isOnButton = ( x > 0 && y > 0 && x < imgButtonMask->width() |
297 | && y < imgButtonMask->height() | 299 | && y < imgButtonMask->height() |
298 | && imgButtonMask->pixelIndex( x, y ) == i + 1 ); | 300 | && imgButtonMask->pixelIndex( x, y ) == i + 1 ); |
299 | 301 | ||
300 | if ( isOnButton && !videoButtons[i].isHeld ) { | 302 | if ( isOnButton && !videoButtons[i].isHeld ) { |
301 | videoButtons[i].isHeld = TRUE; | 303 | videoButtons[i].isHeld = TRUE; |
302 | toggleButton(i); | 304 | toggleButton(i); |
303 | 305 | ||
304 | switch (i) { | 306 | switch (i) { |
305 | case VideoVolUp: | 307 | case VideoVolUp: |
306 | emit moreClicked(); | 308 | emit moreClicked(); |
307 | return; | 309 | return; |
308 | case VideoVolDown: | 310 | case VideoVolDown: |
309 | emit lessClicked(); | 311 | emit lessClicked(); |
310 | return; | 312 | return; |
311 | } | 313 | } |
312 | } else if ( !isOnButton && videoButtons[i].isHeld ) { | 314 | } else if ( !isOnButton && videoButtons[i].isHeld ) { |
313 | videoButtons[i].isHeld = FALSE; | 315 | videoButtons[i].isHeld = FALSE; |
314 | toggleButton(i); | 316 | toggleButton(i); |
315 | } | 317 | } |
316 | } else { | 318 | } else { |
317 | 319 | ||
318 | if ( videoButtons[i].isHeld ) { | 320 | if ( videoButtons[i].isHeld ) { |
319 | videoButtons[i].isHeld = FALSE; | 321 | videoButtons[i].isHeld = FALSE; |
320 | if ( !videoButtons[i].isToggle ) { | 322 | if ( !videoButtons[i].isToggle ) { |
321 | setToggleButton( i, FALSE ); | 323 | setToggleButton( i, FALSE ); |
322 | } | 324 | } |
323 | 325 | ||
324 | switch(i) { | 326 | switch(i) { |
325 | 327 | ||
326 | case VideoPlay: { | 328 | case VideoPlay: { |
327 | if( mediaPlayerState->isPaused ) { | 329 | if( mediaPlayerState->isPaused ) { |
328 | setToggleButton( i, FALSE ); | 330 | setToggleButton( i, FALSE ); |
329 | mediaPlayerState->setPaused( FALSE ); | 331 | mediaPlayerState->setPaused( FALSE ); |
330 | return; | 332 | return; |
331 | } else if( !mediaPlayerState->isPaused ) { | 333 | } else if( !mediaPlayerState->isPaused ) { |
332 | setToggleButton( i, TRUE ); | 334 | setToggleButton( i, TRUE ); |
333 | mediaPlayerState->setPaused( TRUE ); | 335 | mediaPlayerState->setPaused( TRUE ); |
334 | return; | 336 | return; |
335 | } else { | 337 | } else { |
336 | return; | 338 | return; |
337 | } | 339 | } |
338 | } | 340 | } |
339 | 341 | ||
340 | case VideoStop: mediaPlayerState->setPlaying( FALSE ); return; | 342 | case VideoStop: mediaPlayerState->setPlaying( FALSE ); return; |
341 | case VideoNext: mediaPlayerState->setNext(); return; | 343 | case VideoNext: if(playList->whichList() ==0) mediaPlayerState->setNext(); return; |
342 | case VideoPrevious: mediaPlayerState->setPrev(); return; | 344 | case VideoPrevious: if(playList->whichList() ==0) mediaPlayerState->setPrev(); return; |
343 | case VideoVolUp: emit moreReleased(); return; | 345 | case VideoVolUp: emit moreReleased(); return; |
344 | case VideoVolDown: emit lessReleased(); return; | 346 | case VideoVolDown: emit lessReleased(); return; |
345 | case VideoFullscreen: mediaPlayerState->setFullscreen( TRUE ); makeVisible(); return; | 347 | case VideoFullscreen: mediaPlayerState->setFullscreen( TRUE ); makeVisible(); return; |
346 | } | 348 | } |
347 | } | 349 | } |
348 | } | 350 | } |
349 | } | 351 | } |
350 | } | 352 | } |
351 | 353 | ||
352 | void VideoWidget::mousePressEvent( QMouseEvent *event ) { | 354 | void VideoWidget::mousePressEvent( QMouseEvent *event ) { |
353 | mouseMoveEvent( event ); | 355 | mouseMoveEvent( event ); |
354 | } | 356 | } |
355 | 357 | ||
356 | void VideoWidget::mouseReleaseEvent( QMouseEvent *event ) { | 358 | void VideoWidget::mouseReleaseEvent( QMouseEvent *event ) { |
357 | if ( mediaPlayerState->fullscreen() ) { | 359 | if ( mediaPlayerState->fullscreen() ) { |
358 | mediaPlayerState->setFullscreen( FALSE ); | 360 | mediaPlayerState->setFullscreen( FALSE ); |
359 | makeVisible(); | 361 | makeVisible(); |
360 | } | 362 | } |
361 | mouseMoveEvent( event ); | 363 | mouseMoveEvent( event ); |
362 | } | 364 | } |
363 | 365 | ||
364 | void VideoWidget::showEvent( QShowEvent* ) { | 366 | void VideoWidget::showEvent( QShowEvent* ) { |
365 | QMouseEvent event( QEvent::MouseMove, QPoint( 0, 0 ), 0, 0 ); | 367 | QMouseEvent event( QEvent::MouseMove, QPoint( 0, 0 ), 0, 0 ); |
366 | mouseMoveEvent( &event ); | 368 | mouseMoveEvent( &event ); |
367 | } | 369 | } |
368 | 370 | ||
369 | 371 | ||
370 | void VideoWidget::backToNormal() { | 372 | void VideoWidget::backToNormal() { |
371 | mediaPlayerState->setFullscreen( FALSE ); | 373 | mediaPlayerState->setFullscreen( FALSE ); |
372 | makeVisible(); | 374 | makeVisible(); |
373 | } | 375 | } |
374 | 376 | ||
375 | void VideoWidget::makeVisible() { | 377 | void VideoWidget::makeVisible() { |
376 | if ( mediaPlayerState->fullscreen() ) { | 378 | if ( mediaPlayerState->fullscreen() ) { |
377 | setBackgroundMode( QWidget::NoBackground ); | 379 | setBackgroundMode( QWidget::NoBackground ); |
378 | showFullScreen(); | 380 | showFullScreen(); |
379 | resize( qApp->desktop()->size() ); | 381 | resize( qApp->desktop()->size() ); |
380 | slider->hide(); | 382 | slider->hide(); |
381 | videoFrame-> setGeometry ( 0, 0, width ( ), height ( )); | 383 | videoFrame-> setGeometry ( 0, 0, width ( ), height ( )); |
382 | qApp->processEvents(); | 384 | qApp->processEvents(); |
383 | } else { | 385 | } else { |
384 | showNormal(); | 386 | showNormal(); |
385 | showMaximized(); | 387 | showMaximized(); |
386 | setBackgroundPixmap( *pixBg ); | 388 | setBackgroundPixmap( *pixBg ); |
387 | if ( mediaPlayerState->streaming() ) { | 389 | if ( mediaPlayerState->streaming() ) { |
388 | slider->hide(); | 390 | slider->hide(); |
389 | disconnect( mediaPlayerState, SIGNAL( positionChanged(long) ),this, SLOT( setPosition(long) ) ); | 391 | disconnect( mediaPlayerState, SIGNAL( positionChanged(long) ),this, SLOT( setPosition(long) ) ); |
390 | disconnect( mediaPlayerState, SIGNAL( positionUpdated(long) ),this, SLOT( setPosition(long) ) ); | 392 | disconnect( mediaPlayerState, SIGNAL( positionUpdated(long) ),this, SLOT( setPosition(long) ) ); |
391 | } else { | 393 | } else { |
392 | slider->show(); | 394 | slider->show(); |
393 | connect( mediaPlayerState, SIGNAL( positionChanged(long) ),this, SLOT( setPosition(long) ) ); | 395 | connect( mediaPlayerState, SIGNAL( positionChanged(long) ),this, SLOT( setPosition(long) ) ); |
394 | connect( mediaPlayerState, SIGNAL( positionUpdated(long) ),this, SLOT( setPosition(long) ) ); | 396 | connect( mediaPlayerState, SIGNAL( positionUpdated(long) ),this, SLOT( setPosition(long) ) ); |
395 | } | 397 | } |
396 | videoFrame->setGeometry( QRect( 0, 30, 240, 170 ) ); | 398 | videoFrame->setGeometry( QRect( 0, 30, 240, 170 ) ); |
397 | qApp->processEvents(); | 399 | qApp->processEvents(); |
398 | } | 400 | } |
399 | } | 401 | } |
400 | 402 | ||
401 | 403 | ||
402 | void VideoWidget::paintEvent( QPaintEvent * pe) { | 404 | void VideoWidget::paintEvent( QPaintEvent * pe) { |
403 | QPainter p( this ); | 405 | QPainter p( this ); |
404 | 406 | ||
405 | if ( mediaPlayerState->fullscreen() ) { | 407 | if ( mediaPlayerState->fullscreen() ) { |
406 | // Clear the background | 408 | // Clear the background |
407 | p.setBrush( QBrush( Qt::black ) ); | 409 | p.setBrush( QBrush( Qt::black ) ); |
408 | } else { | 410 | } else { |
409 | if ( !pe->erased() ) { | 411 | if ( !pe->erased() ) { |
410 | // Combine with background and double buffer | 412 | // Combine with background and double buffer |
411 | QPixmap pix( pe->rect().size() ); | 413 | QPixmap pix( pe->rect().size() ); |
412 | QPainter p( &pix ); | 414 | QPainter p( &pix ); |
413 | p.translate( -pe->rect().topLeft().x(), -pe->rect().topLeft().y() ); | 415 | p.translate( -pe->rect().topLeft().x(), -pe->rect().topLeft().y() ); |
414 | p.drawTiledPixmap( pe->rect(), *pixBg, pe->rect().topLeft() ); | 416 | p.drawTiledPixmap( pe->rect(), *pixBg, pe->rect().topLeft() ); |
415 | for ( int i = 0; i < numVButtons; i++ ) { | 417 | for ( int i = 0; i < numVButtons; i++ ) { |
416 | paintButton( &p, i ); | 418 | paintButton( &p, i ); |
417 | } | 419 | } |
418 | QPainter p2( this ); | 420 | QPainter p2( this ); |
419 | p2.drawPixmap( pe->rect().topLeft(), pix ); | 421 | p2.drawPixmap( pe->rect().topLeft(), pix ); |
420 | } else { | 422 | } else { |
421 | QPainter p( this ); | 423 | QPainter p( this ); |
422 | for ( int i = 0; i < numVButtons; i++ ) | 424 | for ( int i = 0; i < numVButtons; i++ ) |
423 | paintButton( &p, i ); | 425 | paintButton( &p, i ); |
424 | } | 426 | } |
425 | slider->repaint( TRUE ); | 427 | slider->repaint( TRUE ); |
426 | } | 428 | } |
427 | } | 429 | } |
428 | 430 | ||
429 | 431 | ||
430 | void VideoWidget::closeEvent( QCloseEvent* ) { | 432 | void VideoWidget::closeEvent( QCloseEvent* ) { |
431 | mediaPlayerState->setList(); | 433 | mediaPlayerState->setList(); |
432 | } | 434 | } |
433 | 435 | ||
434 | 436 | ||
435 | 437 | ||
436 | void VideoWidget::keyReleaseEvent( QKeyEvent *e) { | 438 | void VideoWidget::keyReleaseEvent( QKeyEvent *e) { |
437 | switch ( e->key() ) { | 439 | switch ( e->key() ) { |
438 | ////////////////////////////// Zaurus keys | 440 | ////////////////////////////// Zaurus keys |
439 | case Key_Home: | 441 | case Key_Home: |
440 | break; | 442 | break; |
441 | case Key_F9: //activity | 443 | case Key_F9: //activity |
442 | break; | 444 | break; |
443 | case Key_F10: //contacts | 445 | case Key_F10: //contacts |
444 | // hide(); | 446 | // hide(); |
445 | break; | 447 | break; |
446 | case Key_F11: //menu | 448 | case Key_F11: //menu |
447 | break; | 449 | break; |
448 | case Key_F12: //home | 450 | case Key_F12: //home |
449 | break; | 451 | break; |
450 | case Key_F13: //mail | 452 | case Key_F13: //mail |
451 | break; | 453 | break; |
452 | case Key_Space: { | 454 | case Key_Space: { |
453 | if(mediaPlayerState->playing()) { | 455 | if(mediaPlayerState->playing()) { |
454 | mediaPlayerState->setPlaying(FALSE); | 456 | mediaPlayerState->setPlaying(FALSE); |
455 | } else { | 457 | } else { |
456 | mediaPlayerState->setPlaying(TRUE); | 458 | mediaPlayerState->setPlaying(TRUE); |
457 | } | 459 | } |
458 | } | 460 | } |
459 | break; | 461 | break; |
460 | case Key_Down: | 462 | case Key_Down: |
461 | // toggleButton(6); | 463 | // toggleButton(6); |
462 | emit lessClicked(); | 464 | emit lessClicked(); |
463 | emit lessReleased(); | 465 | emit lessReleased(); |
464 | // toggleButton(6); | 466 | // toggleButton(6); |
465 | break; | 467 | break; |
466 | case Key_Up: | 468 | case Key_Up: |
467 | // toggleButton(5); | 469 | // toggleButton(5); |
468 | emit moreClicked(); | 470 | emit moreClicked(); |
469 | emit moreReleased(); | 471 | emit moreReleased(); |
470 | // toggleButton(5); | 472 | // toggleButton(5); |