author | harlekin <harlekin> | 2002-08-09 21:06:15 (UTC) |
---|---|---|
committer | harlekin <harlekin> | 2002-08-09 21:06:15 (UTC) |
commit | 62f9bc4e906784d201d758b9c0bba05a294a31be (patch) (side-by-side diff) | |
tree | dfdb5b202046fdd87879fa0f8ccf75eec7369363 | |
parent | 46eb53b1fd042d2591933a7d89a0e65b79140f16 (diff) | |
download | opie-62f9bc4e906784d201d758b9c0bba05a294a31be.zip opie-62f9bc4e906784d201d758b9c0bba05a294a31be.tar.gz opie-62f9bc4e906784d201d758b9c0bba05a294a31be.tar.bz2 |
fix runnaway seek on media change
-rw-r--r-- | noncore/multimedia/opieplayer2/audiowidget.cpp | 21 |
1 files changed, 11 insertions, 10 deletions
diff --git a/noncore/multimedia/opieplayer2/audiowidget.cpp b/noncore/multimedia/opieplayer2/audiowidget.cpp index 6b656ee..dc90a62 100644 --- a/noncore/multimedia/opieplayer2/audiowidget.cpp +++ b/noncore/multimedia/opieplayer2/audiowidget.cpp @@ -112,403 +112,404 @@ MediaButton audioButtons[] = { }; const char *skin_mask_file_names[11] = { "play", "stop", "pause", "next", "prev", "up", "down", "loop", "playlist", "forward", "back" }; static void changeTextColor( QWidget *w ) { QPalette p = w->palette(); p.setBrush( QColorGroup::Background, QColor( 167, 212, 167 ) ); p.setBrush( QColorGroup::Base, QColor( 167, 212, 167 ) ); w->setPalette( p ); } static const int numButtons = (sizeof(audioButtons)/sizeof(MediaButton)); AudioWidget::AudioWidget(QWidget* parent, const char* name, WFlags f) : QWidget( parent, name, f ), songInfo( this ), slider( Qt::Horizontal, this ), time( this ) { setCaption( tr("OpiePlayer") ); Config cfg("OpiePlayer"); cfg.setGroup("AudioWidget"); skin = cfg.readEntry("Skin","default"); //skin = "scaleTest"; // color of background, frame, degree of transparency QString skinPath = "opieplayer/skins/" + skin; pixBg = new QPixmap( Resource::loadPixmap( QString("%1/background").arg(skinPath) ) ); imgUp = new QImage( Resource::loadImage( QString("%1/skin_up").arg(skinPath) ) ); imgDn = new QImage( Resource::loadImage( QString("%1/skin_down").arg(skinPath) ) ); imgButtonMask = new QImage( imgUp->width(), imgUp->height(), 8, 255 ); imgButtonMask->fill( 0 ); for ( int i = 0; i < 11; i++ ) { QString filename = QString(getenv("OPIEDIR")) + "/pics/" + skinPath + "/skin_mask_" + skin_mask_file_names[i] + ".png"; masks[i] = new QBitmap( 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 < 11; i++ ) { buttonPixUp[i] = NULL; buttonPixDown[i] = NULL; } setBackgroundPixmap( *pixBg ); songInfo.setFocusPolicy( QWidget::NoFocus ); changeTextColor( &songInfo ); slider.setFixedHeight( 20 ); slider.setMinValue( 0 ); slider.setMaxValue( 1 ); slider.setFocusPolicy( QWidget::NoFocus ); slider.setBackgroundPixmap( *pixBg ); time.setFocusPolicy( QWidget::NoFocus ); time.setAlignment( Qt::AlignCenter ); time.setFrame(FALSE); changeTextColor( &time ); 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( viewChanged(char) ), this, SLOT( setView(char) ) ); connect( mediaPlayerState, SIGNAL( loopingToggled(bool) ), this, SLOT( setLooping(bool) ) ); connect( mediaPlayerState, SIGNAL( pausedToggled(bool) ), this, SLOT( setPaused(bool) ) ); connect( mediaPlayerState, SIGNAL( playingToggled(bool) ), this, SLOT( setPlaying(bool) ) ); connect( this, SIGNAL( forwardClicked() ), this, SLOT( skipFor() ) ); connect( this, SIGNAL( backClicked() ), this, SLOT( skipBack() ) ); connect( this, SIGNAL( forwardReleased() ), this, SLOT( stopSkip() ) ); connect( this, SIGNAL( backReleased() ), this, SLOT( stopSkip() ) ); // Intialise state setLength( mediaPlayerState->length() ); setPosition( mediaPlayerState->position() ); setLooping( mediaPlayerState->fullscreen() ); setPaused( mediaPlayerState->paused() ); setPlaying( mediaPlayerState->playing() ); } AudioWidget::~AudioWidget() { for ( int i = 0; i < 11; i++ ) { delete buttonPixUp[i]; delete buttonPixDown[i]; } delete pixBg; delete imgUp; delete imgDn; delete imgButtonMask; for ( int i = 0; i < 11; i++ ) { delete masks[i]; } } QPixmap *combineImageWithBackground( 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 *maskPixToMask( QPixmap pix, QBitmap mask ) { QPixmap *pixmap = new QPixmap( pix ); pixmap->setMask( mask ); return pixmap; } void AudioWidget::resizeEvent( QResizeEvent * ) { int h = height(); int w = width(); songInfo.setGeometry( QRect( 2, 10, w - 4, 20 ) ); slider.setFixedWidth( w - 110 ); slider.setGeometry( QRect( 15, h - 30, w - 90, 20 ) ); slider.setBackgroundOrigin( QWidget::ParentOrigin ); time.setGeometry( QRect( w - 85, h - 30, 70, 20 ) ); xoff = ( w - imgUp->width() ) / 2; yoff = (( h - imgUp->height() ) / 2) - 10; QPoint p( xoff, yoff ); QPixmap *pixUp = combineImageWithBackground( *imgUp, *pixBg, p ); QPixmap *pixDn = combineImageWithBackground( *imgDn, *pixBg, p ); for ( int i = 0; i < 11; i++ ) { if ( !masks[i]->isNull() ) { delete buttonPixUp[i]; delete buttonPixDown[i]; buttonPixUp[i] = maskPixToMask( *pixUp, *masks[i] ); buttonPixDown[i] = maskPixToMask( *pixDn, *masks[i] ); } } delete pixUp; delete pixDn; } static bool audioSliderBeingMoved = FALSE; void AudioWidget::sliderPressed() { audioSliderBeingMoved = TRUE; } void AudioWidget::sliderReleased() { audioSliderBeingMoved = FALSE; if ( slider.width() == 0 ) return; long val = long((double)slider.value() * mediaPlayerState->length() / slider.width()); mediaPlayerState->setPosition( val ); } void AudioWidget::setPosition( long i ) { // qDebug("<<<<<<<<<<<<<<<<<<<<<<<<set position %d",i); updateSlider( i, mediaPlayerState->length() ); } void AudioWidget::setLength( long max ) { updateSlider( mediaPlayerState->position(), max ); } void AudioWidget::setView( char view ) { - slider.show(); // this isnt working for some reason -// 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 { + 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(); + slider.show(); connect( mediaPlayerState, SIGNAL( positionChanged(long) ),this, SLOT( setPosition(long) ) ); connect( mediaPlayerState, SIGNAL( positionUpdated(long) ),this, SLOT( setPosition(long) ) ); -// } + } if ( view == 'a' ) { - startTimer( 150 ); + // startTimer( 150 ); showMaximized(); } else { killTimers(); hide(); } } static QString timeAsString( long length ) { int minutes = length / 60; int seconds = length % 60; return QString("%1:%2%3").arg( minutes ).arg( seconds / 10 ).arg( seconds % 10 ); } void AudioWidget::updateSlider( long i, long max ) { time.setText( timeAsString( i ) + " / " + timeAsString( max ) ); // qDebug( timeAsString( i ) + " / " + timeAsString( max ) ) ; if ( max == 0 ) { return; } // Will flicker too much if we don't do this // Scale to something reasonable int width = slider.width(); int val = int((double)i * width / max); if ( !audioSliderBeingMoved ) { if ( slider.value() != val ) { slider.setValue( val ); } if ( slider.maxValue() != width ) { slider.setMaxValue( width ); } } } void AudioWidget::setToggleButton( int i, bool down ) { if ( down != audioButtons[i].isDown ) { toggleButton( i ); } } void AudioWidget::toggleButton( int i ) { audioButtons[i].isDown = !audioButtons[i].isDown; QPainter p(this); paintButton ( &p, i ); } void AudioWidget::paintButton( QPainter *p, int i ) { if ( audioButtons[i].isDown ) p->drawPixmap( xoff, yoff, *buttonPixDown[i] ); else p->drawPixmap( xoff, yoff, *buttonPixUp[i] ); } void AudioWidget::skipFor() { skipDirection = +1; startTimer( 50 ); mediaPlayerState->setPosition( mediaPlayerState->position() + 2 ); } void AudioWidget::skipBack() { skipDirection = -1; startTimer( 50 ); mediaPlayerState->setPosition( mediaPlayerState->position() - 2 ); } void AudioWidget::stopSkip() { killTimers(); } void AudioWidget::timerEvent( QTimerEvent * ) { if ( skipDirection == +1 ) { mediaPlayerState->setPosition( mediaPlayerState->position() + 2 ); } else if ( skipDirection == -1 ) { mediaPlayerState->setPosition( mediaPlayerState->position() - 2 ); } } void AudioWidget::mouseMoveEvent( QMouseEvent *event ) { for ( int i = 0; i < numButtons; 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 && i == AudioVolumeUp ) qDebug("on up"); if ( isOnButton && !audioButtons[i].isHeld ) { audioButtons[i].isHeld = TRUE; toggleButton(i); switch (i) { case AudioVolumeUp: qDebug("more clicked"); emit moreClicked(); return; case AudioVolumeDown: emit lessClicked(); return; case AudioForward: emit forwardClicked(); return; case AudioBack: emit backClicked(); return; } } else if ( !isOnButton && audioButtons[i].isHeld ) { audioButtons[i].isHeld = FALSE; toggleButton(i); } } else { if ( audioButtons[i].isHeld ) { audioButtons[i].isHeld = FALSE; if ( !audioButtons[i].isToggle ) { setToggleButton( i, FALSE ); qDebug("button toggled3 %d",i); } switch (i) { case AudioPlay: mediaPlayerState->setPlaying(audioButtons[i].isDown); return; case AudioStop: mediaPlayerState->setPlaying(FALSE); return; case AudioPause: mediaPlayerState->setPaused( audioButtons[i].isDown); return; case AudioNext: mediaPlayerState->setNext(); return; case AudioPrevious: mediaPlayerState->setPrev(); return; case AudioLoop: mediaPlayerState->setLooping(audioButtons[i].isDown); return; case AudioVolumeUp: emit moreReleased(); return; case AudioVolumeDown: emit lessReleased(); return; case AudioPlayList: mediaPlayerState->setList(); return; case AudioForward: emit forwardReleased(); return; case AudioBack: emit backReleased(); return; } } } } } void AudioWidget::mousePressEvent( QMouseEvent *event ) { mouseMoveEvent( event ); } void AudioWidget::mouseReleaseEvent( QMouseEvent *event ) { mouseMoveEvent( event ); } void AudioWidget::showEvent( QShowEvent* ) { QMouseEvent event( QEvent::MouseMove, QPoint( 0, 0 ), 0, 0 ); mouseMoveEvent( &event ); } void AudioWidget::closeEvent( QCloseEvent* ) { mediaPlayerState->setList(); } void AudioWidget::paintEvent( QPaintEvent * pe) { 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 < numButtons; i++ ) paintButton( &p, i ); QPainter p2( this ); p2.drawPixmap( pe->rect().topLeft(), pix ); } else { QPainter p( this ); for ( int i = 0; i < numButtons; i++ ) paintButton( &p, i ); } } void AudioWidget::keyReleaseEvent( QKeyEvent *e) { switch ( e->key() ) { |