-rw-r--r-- | noncore/multimedia/opieplayer2/videowidget.cpp | 16 |
1 files changed, 6 insertions, 10 deletions
diff --git a/noncore/multimedia/opieplayer2/videowidget.cpp b/noncore/multimedia/opieplayer2/videowidget.cpp index 8fe572f..238770b 100644 --- a/noncore/multimedia/opieplayer2/videowidget.cpp +++ b/noncore/multimedia/opieplayer2/videowidget.cpp | |||
@@ -56,190 +56,186 @@ extern MediaPlayerState *mediaPlayerState; | |||
56 | 56 | ||
57 | static const int xo = 2; // movable x offset | 57 | static const int xo = 2; // movable x offset |
58 | static const int yo = 0; // movable y offset | 58 | static const int yo = 0; // movable y offset |
59 | 59 | ||
60 | 60 | ||
61 | struct MediaButton { | 61 | struct MediaButton { |
62 | bool isToggle, isHeld, isDown; | 62 | bool isToggle, isHeld, isDown; |
63 | }; | 63 | }; |
64 | 64 | ||
65 | MediaButton videoButtons[] = { | 65 | MediaButton videoButtons[] = { |
66 | { FALSE, FALSE, FALSE }, // stop | 66 | { FALSE, FALSE, FALSE }, // stop |
67 | { TRUE, FALSE, FALSE }, // play | 67 | { TRUE, FALSE, FALSE }, // play |
68 | { FALSE, FALSE, FALSE }, // previous | 68 | { FALSE, FALSE, FALSE }, // previous |
69 | { FALSE, FALSE, FALSE }, // next | 69 | { FALSE, FALSE, FALSE }, // next |
70 | { FALSE, FALSE, FALSE }, // volUp | 70 | { FALSE, FALSE, FALSE }, // volUp |
71 | { FALSE, FALSE, FALSE }, // volDown | 71 | { FALSE, FALSE, FALSE }, // volDown |
72 | { TRUE, FALSE, FALSE } // fullscreen | 72 | { TRUE, FALSE, FALSE } // fullscreen |
73 | }; | 73 | }; |
74 | 74 | ||
75 | const char *skinV_mask_file_names[7] = { | 75 | const char *skinV_mask_file_names[7] = { |
76 | "stop","play","back","fwd","up","down","full" | 76 | "stop","play","back","fwd","up","down","full" |
77 | }; | 77 | }; |
78 | 78 | ||
79 | static const int numVButtons = (sizeof(videoButtons)/sizeof(MediaButton)); | 79 | static const int numVButtons = (sizeof(videoButtons)/sizeof(MediaButton)); |
80 | 80 | ||
81 | 81 | ||
82 | VideoWidget::VideoWidget(QWidget* parent, const char* name, WFlags f) : | 82 | VideoWidget::VideoWidget(QWidget* parent, const char* name, WFlags f) : |
83 | QWidget( parent, name, f ), scaledWidth( 0 ), scaledHeight( 0 ) { | 83 | QWidget( parent, name, f ), scaledWidth( 0 ), scaledHeight( 0 ) { |
84 | setCaption( tr("OpiePlayer - Video") ); | 84 | setCaption( tr("OpiePlayer - Video") ); |
85 | 85 | ||
86 | videoFrame = new XineVideoWidget ( this, "Video frame" ); | 86 | videoFrame = new XineVideoWidget ( this, "Video frame" ); |
87 | connect ( videoFrame, SIGNAL( videoResized ( const QSize & )), this, SIGNAL( videoResized ( const QSize & ))); | 87 | connect ( videoFrame, SIGNAL( videoResized ( const QSize & )), this, SIGNAL( videoResized ( const QSize & ))); |
88 | 88 | ||
89 | Config cfg("OpiePlayer"); | 89 | Config cfg("OpiePlayer"); |
90 | cfg.setGroup("Options"); | 90 | cfg.setGroup("Options"); |
91 | skin = cfg.readEntry("Skin","default"); | 91 | skin = cfg.readEntry("Skin","default"); |
92 | 92 | ||
93 | QString skinPath = "opieplayer2/skins/" + skin; | 93 | QString skinPath = "opieplayer2/skins/" + skin; |
94 | pixBg = new QPixmap( Resource::loadPixmap( QString("%1/background").arg(skinPath) ) ); | 94 | pixBg = new QPixmap( Resource::loadPixmap( QString("%1/background").arg(skinPath) ) ); |
95 | imgUp = new QImage( Resource::loadImage( QString("%1/skinV_up").arg(skinPath) ) ); | 95 | imgUp = new QImage( Resource::loadImage( QString("%1/skinV_up").arg(skinPath) ) ); |
96 | imgDn = new QImage( Resource::loadImage( QString("%1/skinV_down").arg(skinPath) ) ); | 96 | imgDn = new QImage( Resource::loadImage( QString("%1/skinV_down").arg(skinPath) ) ); |
97 | 97 | ||
98 | imgButtonMask = new QImage( imgUp->width(), imgUp->height(), 8, 255 ); | 98 | imgButtonMask = new QImage( imgUp->width(), imgUp->height(), 8, 255 ); |
99 | imgButtonMask->fill( 0 ); | 99 | imgButtonMask->fill( 0 ); |
100 | 100 | ||
101 | for ( int i = 0; i < 7; i++ ) { | 101 | for ( int i = 0; i < 7; i++ ) { |
102 | QString filename = QString(getenv("OPIEDIR")) + "/pics/" + skinPath + "/skinV_mask_" + skinV_mask_file_names[i] + ".png"; | 102 | QString filename = QString(getenv("OPIEDIR")) + "/pics/" + skinPath + "/skinV_mask_" + skinV_mask_file_names[i] + ".png"; |
103 | masks[i] = new QBitmap( filename ); | 103 | masks[i] = new QBitmap( filename ); |
104 | qDebug(filename); | 104 | |
105 | if ( !masks[i]->isNull() ) { | 105 | if ( !masks[i]->isNull() ) { |
106 | QImage imgMask = masks[i]->convertToImage(); | 106 | QImage imgMask = masks[i]->convertToImage(); |
107 | uchar **dest = imgButtonMask->jumpTable(); | 107 | uchar **dest = imgButtonMask->jumpTable(); |
108 | for ( int y = 0; y < imgUp->height(); y++ ) { | 108 | for ( int y = 0; y < imgUp->height(); y++ ) { |
109 | uchar *line = dest[y]; | 109 | uchar *line = dest[y]; |
110 | for ( int x = 0; x < imgUp->width(); x++ ) { | 110 | for ( int x = 0; x < imgUp->width(); x++ ) { |
111 | if ( !qRed( imgMask.pixel( x, y ) ) ) | 111 | if ( !qRed( imgMask.pixel( x, y ) ) ) |
112 | line[x] = i + 1; | 112 | line[x] = i + 1; |
113 | } | 113 | } |
114 | } | 114 | } |
115 | } | 115 | } |
116 | } | 116 | } |
117 | 117 | ||
118 | for ( int i = 0; i < 7; i++ ) { | 118 | for ( int i = 0; i < 7; i++ ) { |
119 | buttonPixUp[i] = NULL; | 119 | buttonPixUp[i] = NULL; |
120 | buttonPixDown[i] = NULL; | 120 | buttonPixDown[i] = NULL; |
121 | } | 121 | } |
122 | 122 | ||
123 | setBackgroundPixmap( *pixBg ); | 123 | setBackgroundPixmap( *pixBg ); |
124 | 124 | ||
125 | slider = new QSlider( Qt::Horizontal, this ); | 125 | slider = new QSlider( Qt::Horizontal, this ); |
126 | slider->setMinValue( 0 ); | 126 | slider->setMinValue( 0 ); |
127 | slider->setMaxValue( 1 ); | 127 | slider->setMaxValue( 1 ); |
128 | slider->setBackgroundPixmap( Resource::loadPixmap( backgroundPix ) ); | 128 | slider->setBackgroundPixmap( Resource::loadPixmap( backgroundPix ) ); |
129 | slider->setFocusPolicy( QWidget::NoFocus ); | 129 | slider->setFocusPolicy( QWidget::NoFocus ); |
130 | 130 | ||
131 | resizeEvent( NULL ); | 131 | resizeEvent( NULL ); |
132 | 132 | ||
133 | connect( slider, SIGNAL( sliderPressed() ), this, SLOT( sliderPressed() ) ); | 133 | connect( slider, SIGNAL( sliderPressed() ), this, SLOT( sliderPressed() ) ); |
134 | connect( slider, SIGNAL( sliderReleased() ), this, SLOT( sliderReleased() ) ); | 134 | connect( slider, SIGNAL( sliderReleased() ), this, SLOT( sliderReleased() ) ); |
135 | connect( mediaPlayerState, SIGNAL( lengthChanged(long) ), this, SLOT( setLength(long) ) ); | 135 | connect( mediaPlayerState, SIGNAL( lengthChanged(long) ), this, SLOT( setLength(long) ) ); |
136 | connect( mediaPlayerState, SIGNAL( viewChanged(char) ), this, SLOT( setView(char) ) ); | 136 | connect( mediaPlayerState, SIGNAL( viewChanged(char) ), this, SLOT( setView(char) ) ); |
137 | connect( mediaPlayerState, SIGNAL( playingToggled(bool) ), this, SLOT( setPlaying(bool) ) ); | 137 | connect( mediaPlayerState, SIGNAL( playingToggled(bool) ), this, SLOT( setPlaying(bool) ) ); |
138 | 138 | ||
139 | setLength( mediaPlayerState->length() ); | 139 | setLength( mediaPlayerState->length() ); |
140 | setPosition( mediaPlayerState->position() ); | 140 | setPosition( mediaPlayerState->position() ); |
141 | setFullscreen( mediaPlayerState->fullscreen() ); | 141 | setFullscreen( mediaPlayerState->fullscreen() ); |
142 | // setPaused( mediaPlayerState->paused() ); | 142 | // setPaused( mediaPlayerState->paused() ); |
143 | setPlaying( mediaPlayerState->playing() ); | 143 | setPlaying( mediaPlayerState->playing() ); |
144 | } | 144 | } |
145 | 145 | ||
146 | 146 | ||
147 | VideoWidget::~VideoWidget() { | 147 | VideoWidget::~VideoWidget() { |
148 | 148 | ||
149 | for ( int i = 0; i < 7; i++ ) { | 149 | for ( int i = 0; i < 7; i++ ) { |
150 | delete buttonPixUp[i]; | 150 | delete buttonPixUp[i]; |
151 | delete buttonPixDown[i]; | 151 | delete buttonPixDown[i]; |
152 | } | 152 | } |
153 | 153 | ||
154 | delete pixBg; | 154 | delete pixBg; |
155 | delete imgUp; | 155 | delete imgUp; |
156 | delete imgDn; | 156 | delete imgDn; |
157 | delete imgButtonMask; | 157 | delete imgButtonMask; |
158 | for ( int i = 0; i < 7; i++ ) { | 158 | for ( int i = 0; i < 7; i++ ) { |
159 | delete masks[i]; | 159 | delete masks[i]; |
160 | } | 160 | } |
161 | 161 | ||
162 | } | 162 | } |
163 | 163 | ||
164 | QPixmap *combineVImageWithBackground( QImage img, QPixmap bg, QPoint offset ) { | 164 | QPixmap *combineVImageWithBackground( QImage img, QPixmap bg, QPoint offset ) { |
165 | QPixmap pix( img.width(), img.height() ); | 165 | QPixmap pix( img.width(), img.height() ); |
166 | QPainter p( &pix ); | 166 | QPainter p( &pix ); |
167 | p.drawTiledPixmap( pix.rect(), bg, offset ); | 167 | p.drawTiledPixmap( pix.rect(), bg, offset ); |
168 | p.drawImage( 0, 0, img ); | 168 | p.drawImage( 0, 0, img ); |
169 | return new QPixmap( pix ); | 169 | return new QPixmap( pix ); |
170 | } | 170 | } |
171 | 171 | ||
172 | QPixmap *maskVPixToMask( QPixmap pix, QBitmap mask ) { | 172 | QPixmap *maskVPixToMask( QPixmap pix, QBitmap mask ) { |
173 | QPixmap *pixmap = new QPixmap( pix ); | 173 | QPixmap *pixmap = new QPixmap( pix ); |
174 | pixmap->setMask( mask ); | 174 | pixmap->setMask( mask ); |
175 | return pixmap; | 175 | return pixmap; |
176 | } | 176 | } |
177 | 177 | ||
178 | void VideoWidget::resizeEvent( QResizeEvent * ) { | 178 | void VideoWidget::resizeEvent( QResizeEvent * ) { |
179 | int h = height(); | 179 | int h = height(); |
180 | int w = width(); | 180 | int w = width(); |
181 | int Vh = 160; | 181 | int Vh = 160; |
182 | //videoFrame->height(); | ||
183 | int Vw = 220; | 182 | int Vw = 220; |
184 | //videoFrame->width(); | ||
185 | |||
186 | 183 | ||
187 | slider->setFixedWidth( w - 20 ); | 184 | slider->setFixedWidth( w - 20 ); |
188 | slider->setGeometry( QRect( 15, h - 30, w - 90, 20 ) ); | 185 | slider->setGeometry( QRect( 15, h - 30, w - 90, 20 ) ); |
189 | slider->setBackgroundOrigin( QWidget::ParentOrigin ); | 186 | slider->setBackgroundOrigin( QWidget::ParentOrigin ); |
190 | slider->setFocusPolicy( QWidget::NoFocus ); | 187 | slider->setFocusPolicy( QWidget::NoFocus ); |
191 | slider->setBackgroundPixmap( *pixBg ); | 188 | slider->setBackgroundPixmap( *pixBg ); |
192 | 189 | ||
193 | xoff = 0;// ( imgUp->width() ) / 2; | 190 | xoff = 0;// ( imgUp->width() ) / 2; |
194 | yoff = 180;//(( Vh - imgUp->height() ) / 2) - 10; | 191 | yoff = 185;//(( Vh - imgUp->height() ) / 2) - 10; |
195 | QPoint p( xoff, yoff ); | 192 | QPoint p( xoff, yoff ); |
196 | 193 | ||
197 | |||
198 | QPixmap *pixUp = combineVImageWithBackground( *imgUp, *pixBg, p ); | 194 | QPixmap *pixUp = combineVImageWithBackground( *imgUp, *pixBg, p ); |
199 | QPixmap *pixDn = combineVImageWithBackground( *imgDn, *pixBg, p ); | 195 | QPixmap *pixDn = combineVImageWithBackground( *imgDn, *pixBg, p ); |
200 | 196 | ||
201 | for ( int i = 0; i < 7; i++ ) { | 197 | for ( int i = 0; i < 7; i++ ) { |
202 | if ( !masks[i]->isNull() ) { | 198 | if ( !masks[i]->isNull() ) { |
203 | delete buttonPixUp[i]; | 199 | delete buttonPixUp[i]; |
204 | delete buttonPixDown[i]; | 200 | delete buttonPixDown[i]; |
205 | buttonPixUp[i] = maskVPixToMask( *pixUp, *masks[i] ); | 201 | buttonPixUp[i] = maskVPixToMask( *pixUp, *masks[i] ); |
206 | buttonPixDown[i] = maskVPixToMask( *pixDn, *masks[i] ); | 202 | buttonPixDown[i] = maskVPixToMask( *pixDn, *masks[i] ); |
207 | } | 203 | } |
208 | } | 204 | } |
209 | 205 | ||
210 | delete pixUp; | 206 | delete pixUp; |
211 | delete pixDn; | 207 | delete pixDn; |
212 | } | 208 | } |
213 | 209 | ||
214 | static bool videoSliderBeingMoved = FALSE; | 210 | static bool videoSliderBeingMoved = FALSE; |
215 | 211 | ||
216 | void VideoWidget::sliderPressed() { | 212 | void VideoWidget::sliderPressed() { |
217 | videoSliderBeingMoved = TRUE; | 213 | videoSliderBeingMoved = TRUE; |
218 | } | 214 | } |
219 | 215 | ||
220 | void VideoWidget::sliderReleased() { | 216 | void VideoWidget::sliderReleased() { |
221 | videoSliderBeingMoved = FALSE; | 217 | videoSliderBeingMoved = FALSE; |
222 | if ( slider->width() == 0 ) { | 218 | if ( slider->width() == 0 ) { |
223 | return; | 219 | return; |
224 | } | 220 | } |
225 | long val = long((double)slider->value() * mediaPlayerState->length() / slider->width()); | 221 | long val = long((double)slider->value() * mediaPlayerState->length() / slider->width()); |
226 | mediaPlayerState->setPosition( val ); | 222 | mediaPlayerState->setPosition( val ); |
227 | } | 223 | } |
228 | 224 | ||
229 | void VideoWidget::setPosition( long i ) { | 225 | void VideoWidget::setPosition( long i ) { |
230 | updateSlider( i, mediaPlayerState->length() ); | 226 | updateSlider( i, mediaPlayerState->length() ); |
231 | } | 227 | } |
232 | 228 | ||
233 | 229 | ||
234 | void VideoWidget::setLength( long max ) { | 230 | void VideoWidget::setLength( long max ) { |
235 | updateSlider( mediaPlayerState->position(), max ); | 231 | updateSlider( mediaPlayerState->position(), max ); |
236 | } | 232 | } |
237 | 233 | ||
238 | void VideoWidget::setView( char view ) { | 234 | void VideoWidget::setView( char view ) { |
239 | 235 | ||
240 | if ( mediaPlayerState->streaming() ) { | 236 | if ( mediaPlayerState->streaming() ) { |
241 | qDebug("<<<<<<<<<<<<<<file is STREAMING>>>>>>>>>>>>>>>>>>>"); | 237 | qDebug("<<<<<<<<<<<<<<file is STREAMING>>>>>>>>>>>>>>>>>>>"); |
242 | if( !slider->isHidden()) { | 238 | if( !slider->isHidden()) { |
243 | slider->hide(); | 239 | slider->hide(); |
244 | } | 240 | } |
245 | disconnect( mediaPlayerState, SIGNAL( positionChanged(long) ),this, SLOT( setPosition(long) ) ); | 241 | disconnect( mediaPlayerState, SIGNAL( positionChanged(long) ),this, SLOT( setPosition(long) ) ); |
@@ -414,84 +410,84 @@ void VideoWidget::paintEvent( QPaintEvent * pe) { | |||
414 | p.drawTiledPixmap( pe->rect(), *pixBg, pe->rect().topLeft() ); | 410 | p.drawTiledPixmap( pe->rect(), *pixBg, pe->rect().topLeft() ); |
415 | for ( int i = 0; i < numVButtons; i++ ) { | 411 | for ( int i = 0; i < numVButtons; i++ ) { |
416 | paintButton( &p, i ); | 412 | paintButton( &p, i ); |
417 | } | 413 | } |
418 | QPainter p2( this ); | 414 | QPainter p2( this ); |
419 | p2.drawPixmap( pe->rect().topLeft(), pix ); | 415 | p2.drawPixmap( pe->rect().topLeft(), pix ); |
420 | } else { | 416 | } else { |
421 | QPainter p( this ); | 417 | QPainter p( this ); |
422 | for ( int i = 0; i < numVButtons; i++ ) | 418 | for ( int i = 0; i < numVButtons; i++ ) |
423 | paintButton( &p, i ); | 419 | paintButton( &p, i ); |
424 | } | 420 | } |
425 | slider->repaint( TRUE ); | 421 | slider->repaint( TRUE ); |
426 | } | 422 | } |
427 | } | 423 | } |
428 | 424 | ||
429 | 425 | ||
430 | void VideoWidget::closeEvent( QCloseEvent* ) { | 426 | void VideoWidget::closeEvent( QCloseEvent* ) { |
431 | mediaPlayerState->setList(); | 427 | mediaPlayerState->setList(); |
432 | } | 428 | } |
433 | 429 | ||
434 | 430 | ||
435 | 431 | ||
436 | void VideoWidget::keyReleaseEvent( QKeyEvent *e) { | 432 | void VideoWidget::keyReleaseEvent( QKeyEvent *e) { |
437 | switch ( e->key() ) { | 433 | switch ( e->key() ) { |
438 | ////////////////////////////// Zaurus keys | 434 | ////////////////////////////// Zaurus keys |
439 | case Key_Home: | 435 | case Key_Home: |
440 | break; | 436 | break; |
441 | case Key_F9: //activity | 437 | case Key_F9: //activity |
442 | break; | 438 | break; |
443 | case Key_F10: //contacts | 439 | case Key_F10: //contacts |
444 | // hide(); | 440 | // hide(); |
445 | break; | 441 | break; |
446 | case Key_F11: //menu | 442 | case Key_F11: //menu |
447 | break; | 443 | break; |
448 | case Key_F12: //home | 444 | case Key_F12: //home |
449 | break; | 445 | break; |
450 | case Key_F13: //mail | 446 | case Key_F13: //mail |
451 | break; | 447 | break; |
452 | case Key_Space: { | 448 | case Key_Space: { |
453 | if(mediaPlayerState->playing()) { | 449 | if(mediaPlayerState->playing()) { |
454 | mediaPlayerState->setPlaying(FALSE); | 450 | mediaPlayerState->setPlaying(FALSE); |
455 | } else { | 451 | } else { |
456 | mediaPlayerState->setPlaying(TRUE); | 452 | mediaPlayerState->setPlaying(TRUE); |
457 | } | 453 | } |
458 | } | 454 | } |
459 | break; | 455 | break; |
460 | case Key_Down: | 456 | case Key_Down: |
461 | // toggleButton(6); | 457 | // toggleButton(6); |
462 | // emit lessClicked(); | 458 | emit lessClicked(); |
463 | // emit lessReleased(); | 459 | emit lessReleased(); |
464 | // toggleButton(6); | 460 | // toggleButton(6); |
465 | break; | 461 | break; |
466 | case Key_Up: | 462 | case Key_Up: |
467 | // toggleButton(5); | 463 | // toggleButton(5); |
468 | // emit moreClicked(); | 464 | emit moreClicked(); |
469 | // emit moreReleased(); | 465 | emit moreReleased(); |
470 | // toggleButton(5); | 466 | // toggleButton(5); |
471 | break; | 467 | break; |
472 | case Key_Right: | 468 | case Key_Right: |
473 | mediaPlayerState->setNext(); | 469 | mediaPlayerState->setNext(); |
474 | break; | 470 | break; |
475 | case Key_Left: | 471 | case Key_Left: |
476 | mediaPlayerState->setPrev(); | 472 | mediaPlayerState->setPrev(); |
477 | break; | 473 | break; |
478 | case Key_Escape: | 474 | case Key_Escape: |
479 | break; | 475 | break; |
480 | 476 | ||
481 | }; | 477 | }; |
482 | } | 478 | } |
483 | 479 | ||
484 | XineVideoWidget* VideoWidget::vidWidget() { | 480 | XineVideoWidget* VideoWidget::vidWidget() { |
485 | return videoFrame; | 481 | return videoFrame; |
486 | } | 482 | } |
487 | 483 | ||
488 | 484 | ||
489 | void VideoWidget::setFullscreen ( bool b ) { | 485 | void VideoWidget::setFullscreen ( bool b ) { |
490 | setToggleButton( VideoFullscreen, b ); | 486 | setToggleButton( VideoFullscreen, b ); |
491 | } | 487 | } |
492 | 488 | ||
493 | 489 | ||
494 | void VideoWidget::setPlaying( bool b) { | 490 | void VideoWidget::setPlaying( bool b) { |
495 | setToggleButton( VideoPlay, b ); | 491 | setToggleButton( VideoPlay, b ); |
496 | } | 492 | } |
497 | 493 | ||