author | harlekin <harlekin> | 2002-08-15 16:29:52 (UTC) |
---|---|---|
committer | harlekin <harlekin> | 2002-08-15 16:29:52 (UTC) |
commit | 320f73ae9a8ffc6daf009b3fefb9035506b0f684 (patch) (side-by-side diff) | |
tree | 52b4e54d1c73cdff58411a1da2485effb2aaa6bb | |
parent | 32ce744f58463ff11afb26ef5c4c8cf3f3d03fd3 (diff) | |
download | opie-320f73ae9a8ffc6daf009b3fefb9035506b0f684.zip opie-320f73ae9a8ffc6daf009b3fefb9035506b0f684.tar.gz opie-320f73ae9a8ffc6daf009b3fefb9035506b0f684.tar.bz2 |
more simular to audiowidget
-rw-r--r-- | noncore/multimedia/opieplayer2/videowidget.cpp | 136 | ||||
-rw-r--r-- | noncore/multimedia/opieplayer2/videowidget.h | 12 |
2 files changed, 74 insertions, 74 deletions
diff --git a/noncore/multimedia/opieplayer2/videowidget.cpp b/noncore/multimedia/opieplayer2/videowidget.cpp index fb375f0..fbcd775 100644 --- a/noncore/multimedia/opieplayer2/videowidget.cpp +++ b/noncore/multimedia/opieplayer2/videowidget.cpp @@ -68,439 +68,433 @@ MediaButton videoButtons[] = { { FALSE, FALSE, FALSE }, // previous { FALSE, FALSE, FALSE }, // next { FALSE, FALSE, FALSE }, // volUp { FALSE, FALSE, FALSE }, // volDown { TRUE, FALSE, FALSE } // fullscreen }; const char *skinV_mask_file_names[7] = { "stop","play","back","fwd","up","down","full" }; static const int numVButtons = (sizeof(videoButtons)/sizeof(MediaButton)); VideoWidget::VideoWidget(QWidget* parent, const char* name, WFlags f) : QWidget( parent, name, f ), scaledWidth( 0 ), scaledHeight( 0 ) { setCaption( tr("OpiePlayer - Video") ); videoFrame = new XineVideoWidget ( this, "Video frame" ); connect ( videoFrame, SIGNAL( videoResized ( const QSize & )), this, SIGNAL( videoResized ( const QSize & ))); Config cfg("OpiePlayer"); cfg.setGroup("Options"); skin = cfg.readEntry("Skin","default"); QString skinPath = "opieplayer2/skins/" + skin; pixBg = new QPixmap( Resource::loadPixmap( QString("%1/background").arg(skinPath) ) ); imgUp = new QImage( Resource::loadImage( QString("%1/skinV_up").arg(skinPath) ) ); imgDn = new QImage( Resource::loadImage( QString("%1/skinV_down").arg(skinPath) ) ); imgButtonMask = new QImage( imgUp->width(), imgUp->height(), 8, 255 ); imgButtonMask->fill( 0 ); for ( int i = 0; i < 7; i++ ) { QString filename = QString(getenv("OPIEDIR")) + "/pics/" + skinPath + "/skinV_mask_" + skinV_mask_file_names[i] + ".png"; masks[i] = new QBitmap( filename ); qDebug(filename); if ( !masks[i]->isNull() ) { QImage imgMask = masks[i]->convertToImage(); uchar **dest = imgButtonMask->jumpTable(); for ( int y = 0; y < imgUp->height(); y++ ) { uchar *line = dest[y]; for ( int x = 0; x < imgUp->width(); x++ ) { if ( !qRed( imgMask.pixel( x, y ) ) ) line[x] = i + 1; } } } - } for ( int i = 0; i < 7; i++ ) { buttonPixUp[i] = NULL; buttonPixDown[i] = NULL; } setBackgroundPixmap( *pixBg ); slider = new QSlider( Qt::Horizontal, this ); slider->setMinValue( 0 ); slider->setMaxValue( 1 ); slider->setBackgroundPixmap( Resource::loadPixmap( backgroundPix ) ); slider->setFocusPolicy( QWidget::NoFocus ); - slider->setGeometry( QRect( 7, 250, 220, 20 ) ); + + resizeEvent( NULL ); connect( slider, SIGNAL( sliderPressed() ), this, SLOT( sliderPressed() ) ); connect( slider, SIGNAL( sliderReleased() ), this, SLOT( sliderReleased() ) ); - connect( mediaPlayerState, SIGNAL( lengthChanged(long) ), this, SLOT( setLength(long) ) ); - connect( mediaPlayerState, SIGNAL( positionChanged(long) ),this, SLOT( setPosition(long) ) ); - connect( mediaPlayerState, SIGNAL( positionUpdated(long) ),this, SLOT( setPosition(long) ) ); connect( mediaPlayerState, SIGNAL( viewChanged(char) ), this, SLOT( setView(char) ) ); - connect( mediaPlayerState, SIGNAL( pausedToggled(bool) ), this, SLOT( setPaused(bool) ) ); connect( mediaPlayerState, SIGNAL( playingToggled(bool) ), this, SLOT( setPlaying(bool) ) ); setLength( mediaPlayerState->length() ); setPosition( mediaPlayerState->position() ); - - ////////////////////////// FIXME setFullscreen( mediaPlayerState->fullscreen() ); setPaused( mediaPlayerState->paused() ); setPlaying( mediaPlayerState->playing() ); - qDebug("finished videowidget"); } VideoWidget::~VideoWidget() { - mediaPlayerState->setPlaying( FALSE ); + for ( int i = 0; i < 7; i++ ) { delete buttonPixUp[i]; delete buttonPixDown[i]; } delete pixBg; delete imgUp; delete imgDn; delete imgButtonMask; for ( int i = 0; i < 7; i++ ) { delete masks[i]; } } QPixmap *combineVImageWithBackground( QImage img, QPixmap bg, QPoint offset ) { QPixmap pix( img.width(), img.height() ); QPainter p( &pix ); p.drawTiledPixmap( pix.rect(), bg, offset ); p.drawImage( 0, 0, img ); return new QPixmap( pix ); } QPixmap *maskVPixToMask( QPixmap pix, QBitmap mask ) { QPixmap *pixmap = new QPixmap( pix ); pixmap->setMask( mask ); return pixmap; } void VideoWidget::resizeEvent( QResizeEvent * ) { int h = height(); int w = width(); int Vh = 160; //videoFrame->height(); int Vw = 220; //videoFrame->width(); -// songInfo.setGeometry( QRect( 2, 10, w - 4, 20 ) ); - slider->setFixedWidth( w - 110 ); + + slider->setFixedWidth( w - 20 ); slider->setGeometry( QRect( 15, h - 30, w - 90, 20 ) ); slider->setBackgroundOrigin( QWidget::ParentOrigin ); slider->setFocusPolicy( QWidget::NoFocus ); slider->setBackgroundPixmap( *pixBg ); -// time.setGeometry( QRect( w - 85, h - 30, 70, 20 ) ); xoff = 0;// ( imgUp->width() ) / 2; yoff = 180;//(( Vh - imgUp->height() ) / 2) - 10; QPoint p( xoff, yoff ); QPixmap *pixUp = combineVImageWithBackground( *imgUp, *pixBg, p ); QPixmap *pixDn = combineVImageWithBackground( *imgDn, *pixBg, p ); for ( int i = 0; i < 7; i++ ) { if ( !masks[i]->isNull() ) { delete buttonPixUp[i]; delete buttonPixDown[i]; buttonPixUp[i] = maskVPixToMask( *pixUp, *masks[i] ); buttonPixDown[i] = maskVPixToMask( *pixDn, *masks[i] ); } } delete pixUp; delete pixDn; } static bool videoSliderBeingMoved = FALSE; void VideoWidget::sliderPressed() { videoSliderBeingMoved = TRUE; } void VideoWidget::sliderReleased() { videoSliderBeingMoved = FALSE; if ( slider->width() == 0 ) { return; } long val = long((double)slider->value() * mediaPlayerState->length() / slider->width()); mediaPlayerState->setPosition( val ); } void VideoWidget::setPosition( long i ) { updateSlider( i, mediaPlayerState->length() ); } void VideoWidget::setLength( long max ) { updateSlider( mediaPlayerState->position(), max ); } void VideoWidget::setView( char view ) { + + if ( mediaPlayerState->streaming() ) { + qDebug("<<<<<<<<<<<<<<file is STREAMING>>>>>>>>>>>>>>>>>>>"); + if( !slider->isHidden()) { + slider->hide(); + } + disconnect( mediaPlayerState, SIGNAL( positionChanged(long) ),this, SLOT( setPosition(long) ) ); + disconnect( mediaPlayerState, SIGNAL( positionUpdated(long) ),this, SLOT( setPosition(long) ) ); + } else { + // this stops the slider from being moved, thus + // does not stop stream when it reaches the end + slider->show(); + connect( mediaPlayerState, SIGNAL( positionChanged(long) ),this, SLOT( setPosition(long) ) ); + connect( mediaPlayerState, SIGNAL( positionUpdated(long) ),this, SLOT( setPosition(long) ) ); + } + if ( view == 'v' ) { makeVisible(); } else { // Effectively blank the view next time we show it so it looks nicer scaledWidth = 0; scaledHeight = 0; hide(); } } void VideoWidget::updateSlider( long i, long max ) { // Will flicker too much if we don't do this if ( max == 0 ) { return; } int width = slider->width(); int val = int((double)i * width / max); if ( !mediaPlayerState->fullscreen() && !videoSliderBeingMoved ) { if ( slider->value() != val ) { slider->setValue( val ); } if ( slider->maxValue() != width ) { slider->setMaxValue( width ); } } } void VideoWidget::setToggleButton( int i, bool down ) { if ( down != videoButtons[i].isDown ) { toggleButton( i ); } } void VideoWidget::toggleButton( int i ) { videoButtons[i].isDown = !videoButtons[i].isDown; QPainter p(this); paintButton ( &p, i ); } void VideoWidget::paintButton( QPainter *p, int i ) { - if ( videoButtons[i].isDown ) + if ( videoButtons[i].isDown ) { p->drawPixmap( xoff, yoff, *buttonPixDown[i] ); - else + } else { p->drawPixmap( xoff, yoff, *buttonPixUp[i] ); } +} void VideoWidget::mouseMoveEvent( QMouseEvent *event ) { for ( int i = 0; i < numVButtons; i++ ) { if ( event->state() == QMouseEvent::LeftButton ) { // The test to see if the mouse click is inside the button or not int x = event->pos().x() - xoff; int y = event->pos().y() - yoff; bool isOnButton = ( x > 0 && y > 0 && x < imgButtonMask->width() - && y < imgButtonMask->height() && imgButtonMask->pixelIndex( x, y ) == i + 1 ); - if ( isOnButton != videoButtons[i].isHeld ) { - videoButtons[i].isHeld = isOnButton; + && y < imgButtonMask->height() + && imgButtonMask->pixelIndex( x, y ) == i + 1 ); + + if ( isOnButton && !videoButtons[i].isHeld ) { + videoButtons[i].isHeld = TRUE; toggleButton(i); - } -// qDebug("mouseMove event switch1 %d", i); - if( isOnButton) switch (i) { - case VideoStop:{ - setToggleButton( i, FALSE ); - mediaPlayerState->setStop(TRUE); - mediaPlayerState->setPlaying(FALSE); + case VideoVolUp: + qDebug("more clicked"); + emit moreClicked(); return; - } - case VideoPlay: { - - if( mediaPlayerState->isPaused) { - setToggleButton( i, FALSE ); - mediaPlayerState->setPaused( FALSE); - return; - } - else if( mediaPlayerState->isPlaying) { - setToggleButton( i, TRUE ); - mediaPlayerState->setPaused( TRUE); - return; - } - else { - setToggleButton( i, FALSE ); - mediaPlayerState->setPlaying( videoButtons[i].isDown ); + case VideoVolDown: + qDebug("less clicked"); + emit lessClicked(); return; } + } else if ( !isOnButton && videoButtons[i].isHeld ) { + videoButtons[i].isHeld = FALSE; + toggleButton(i); } - case VideoNext: qDebug("next"); mediaPlayerState->setNext(); return; - case VideoPrevious: qDebug("previous"); mediaPlayerState->setPrev(); return; - case VideoVolUp: return; - case VideoVolDown: return; - case VideoFullscreen: mediaPlayerState->setFullscreen( TRUE ); makeVisible(); return; - - }; - } else { + if ( videoButtons[i].isHeld ) { videoButtons[i].isHeld = FALSE; if ( !videoButtons[i].isToggle ) { setToggleButton( i, FALSE ); + qDebug("button toggled3 %d",i); } -// qDebug("mouseMove event switch2 %d %d", i, VideoPlay); + switch (i) { + case VideoPlay: { if( mediaPlayerState->isPaused) { - mediaPlayerState->setPaused( FALSE); return; } - else if( mediaPlayerState->isPlaying) { - mediaPlayerState->setPaused( TRUE); return; } - else - mediaPlayerState->setPlaying( TRUE /*videoButtons[i].isDown*/ ); return; + qDebug("play again clicked"); + setToggleButton( i, FALSE ); + mediaPlayerState->setPaused( FALSE ); + return; + } else if( !mediaPlayerState->isPaused ) { + qDebug("pause now clicked"); + setToggleButton( i, TRUE ); + mediaPlayerState->setPaused( TRUE ); + return; + } else { + // setToggleButton( i, TRUE ); + // mediaPlayerState->setPlaying( videoButtons[i].isDown ); + } } + case VideoStop: mediaPlayerState->setPlaying(FALSE); return; // case VideoPause: mediaPlayerState->setPaused(videoButtons[i].isDown); return; case VideoNext: mediaPlayerState->setNext(); return; case VideoPrevious: mediaPlayerState->setPrev(); return; - case VideoVolUp: return; - case VideoVolDown: return; + case VideoVolUp: emit moreReleased(); return; + case VideoVolDown: emit lessReleased(); return; case VideoFullscreen: mediaPlayerState->setFullscreen( TRUE ); makeVisible(); return; } } } } } void VideoWidget::mousePressEvent( QMouseEvent *event ) { mouseMoveEvent( event ); } void VideoWidget::mouseReleaseEvent( QMouseEvent *event ) { if ( mediaPlayerState->fullscreen() ) { mediaPlayerState->setFullscreen( FALSE ); makeVisible(); mouseMoveEvent( event ); } } +void VideoWidget::showEvent( QShowEvent* ) { + QMouseEvent event( QEvent::MouseMove, QPoint( 0, 0 ), 0, 0 ); + mouseMoveEvent( &event ); +} + void VideoWidget::makeVisible() { if ( mediaPlayerState->fullscreen() ) { setBackgroundMode( QWidget::NoBackground ); showFullScreen(); resize( qApp->desktop()->size() ); slider->hide(); videoFrame-> setGeometry ( 0, 0, width ( ), height ( )); } else { showNormal(); showMaximized(); slider->show(); videoFrame->setGeometry( QRect( 10, 20, 220, 160 ) ); qApp->processEvents(); } } void VideoWidget::paintEvent( QPaintEvent * pe) { QPainter p( this ); if ( mediaPlayerState->fullscreen() ) { // Clear the background p.setBrush( QBrush( Qt::black ) ); // videoFrame->setGeometry( QRect( 0, 0 , 240 ,320 ) ); } else { // videoFrame->setGeometry( QRect( 0, 15 , 240 ,170 ) ); // draw the buttons if ( !pe->erased() ) { // Combine with background and double buffer QPixmap pix( pe->rect().size() ); QPainter p( &pix ); p.translate( -pe->rect().topLeft().x(), -pe->rect().topLeft().y() ); p.drawTiledPixmap( pe->rect(), *pixBg, pe->rect().topLeft() ); - for ( int i = 0; i < numVButtons; i++ ) + for ( int i = 0; i < numVButtons; i++ ) { paintButton( &p, i ); + } QPainter p2( this ); p2.drawPixmap( pe->rect().topLeft(), pix ); } else { QPainter p( this ); for ( int i = 0; i < numVButtons; i++ ) paintButton( &p, i ); } // for ( int i = 0; i < numButtons; i++ ) { // paintButton( &p, i ); // } // draw the slider slider->repaint( TRUE ); } } void VideoWidget::closeEvent( QCloseEvent* ) { mediaPlayerState->setList(); } -bool VideoWidget::playVideo() { - bool result = FALSE; - - int stream = 0; - - int sw = 240; - int sh = 320; - int dd = QPixmap::defaultDepth(); - int w = height(); - int h = width(); - - return true; -} void VideoWidget::keyReleaseEvent( QKeyEvent *e) { switch ( e->key() ) { ////////////////////////////// Zaurus keys case Key_Home: break; case Key_F9: //activity break; case Key_F10: //contacts // hide(); break; case Key_F11: //menu break; case Key_F12: //home break; case Key_F13: //mail break; case Key_Space: { if(mediaPlayerState->playing()) { mediaPlayerState->setPlaying(FALSE); } else { mediaPlayerState->setPlaying(TRUE); } } break; case Key_Down: // toggleButton(6); // emit lessClicked(); // emit lessReleased(); // toggleButton(6); break; case Key_Up: // toggleButton(5); // emit moreClicked(); // emit moreReleased(); // toggleButton(5); break; case Key_Right: mediaPlayerState->setNext(); break; case Key_Left: mediaPlayerState->setPrev(); break; case Key_Escape: break; }; } diff --git a/noncore/multimedia/opieplayer2/videowidget.h b/noncore/multimedia/opieplayer2/videowidget.h index 92193a4..710ba9e 100644 --- a/noncore/multimedia/opieplayer2/videowidget.h +++ b/noncore/multimedia/opieplayer2/videowidget.h @@ -1,117 +1,123 @@ /* This file is part of the Opie Project Copyright (c) 2002 Max Reiss <harlekin@handhelds.org> Copyright (c) 2002 L. Potter <ljp@llornkcor.com> Copyright (c) 2002 Holger Freyther <zecke@handhelds.org> =. .=l. .>+-= _;:, .> :=|. This program is free software; you can .> <`_, > . <= redistribute it and/or modify it under :`=1 )Y*s>-.-- : the terms of the GNU General Public .="- .-=="i, .._ License as published by the Free Software - . .-<_> .<> Foundation; either version 2 of the License, ._= =} : or (at your option) any later version. .%`+i> _;_. .i_,=:_. -<s. This program is distributed in the hope that + . -:. = it will be useful, but WITHOUT ANY WARRANTY; : .. .:, . . . without even the implied warranty of =_ + =;=|` MERCHANTABILITY or FITNESS FOR A _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU ..}^=.= = ; Library General Public License for more ++= -. .` .: details. : = ...= . :.=- -. .:....=;==+<; You should have received a copy of the GNU -_. . . )=. = Library General Public License along with -- :-=` this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #ifndef VIDEO_WIDGET_H #define VIDEO_WIDGET_H #include <qwidget.h> #include "xinevideowidget.h" class QPixmap; class QSlider; enum VideoButtons { - VideoStop, + VideoStop = 0, VideoPlay, // VideoPause, VideoPrevious, VideoNext, VideoVolUp, VideoVolDown, VideoFullscreen }; class VideoWidget : public QWidget { Q_OBJECT public: VideoWidget( QWidget* parent=0, const char* name=0, WFlags f=0 ); ~VideoWidget(); - bool playVideo(); + XineVideoWidget* vidWidget(); public slots: void updateSlider( long, long ); void sliderPressed( ); void sliderReleased( ); void setPaused( bool b); void setPlaying( bool b); void setFullscreen( bool b ); void makeVisible(); void setPosition( long ); void setLength( long ); void setView( char ); signals: + void moreClicked(); + void lessClicked(); + void moreReleased(); + void lessReleased(); void sliderMoved( long ); void videoResized ( const QSize &s ); protected: - QString skin; + void resizeEvent( QResizeEvent * ); void paintEvent( QPaintEvent *pe ); + void showEvent( QShowEvent *se ); void mouseMoveEvent( QMouseEvent *event ); void mousePressEvent( QMouseEvent *event ); void mouseReleaseEvent( QMouseEvent *event ); void closeEvent( QCloseEvent *event ); void keyReleaseEvent( QKeyEvent *e); private: // Ticker songInfo; QPixmap *pixBg; QImage *imgUp; QImage *imgDn; QImage *imgButtonMask; QBitmap *masks[7]; QPixmap *buttonPixUp[7]; QPixmap *buttonPixDown[7]; + QString skin; // QPixmap *pixmaps[4]; int xoff, yoff; void paintButton( QPainter *p, int i ); void toggleButton( int ); void setToggleButton( int, bool ); QString backgroundPix; QSlider *slider; QPixmap *pixmaps[3]; QImage *currentFrame; int scaledWidth; int scaledHeight; XineVideoWidget* videoFrame; }; #endif // VIDEO_WIDGET_H |