From 89e2611f322ddec3cd0a3e58684d49024b77fc18 Mon Sep 17 00:00:00 2001 From: Albert Astals Cid Date: Tue, 13 Dec 2011 19:50:46 +0100 Subject: [PATCH] Stop playing videos when they are no longer visible This mimics Adobe Reader behaviour BUGS: 286932 FIXED-IN: 4.8.0 --- ui/pageview.cpp | 5 +++++ ui/videowidget.cpp | 5 +++++ ui/videowidget.h | 2 ++ 3 files changed, 12 insertions(+) diff --git a/ui/pageview.cpp b/ui/pageview.cpp index 9aacc9677..898054c79 100644 --- a/ui/pageview.cpp +++ b/ui/pageview.cpp @@ -3832,6 +3832,7 @@ void PageView::slotRequestVisiblePixmaps( int newValue ) QRect viewportRect( horizontalScrollBar()->value(), verticalScrollBar()->value(), viewport()->width(), viewport()->height() ); + const QRect viewportRectAtZeroZero( 0, 0, viewport()->width(), viewport()->height() ); // some variables used to determine the viewport int nearPageNumber = -1; @@ -3862,6 +3863,10 @@ void PageView::slotRequestVisiblePixmaps( int newValue ) vw->move( qRound( i->uncroppedGeometry().left() + i->uncroppedWidth() * r.left ) + 1 - viewportRect.left(), qRound( i->uncroppedGeometry().top() + i->uncroppedHeight() * r.top ) + 1 - viewportRect.top() ); + + if ( vw->isPlaying() && viewportRectAtZeroZero.intersect( vw->geometry() ).isEmpty() ) { + vw->stop(); + } } if ( !i->isVisible() ) diff --git a/ui/videowidget.cpp b/ui/videowidget.cpp index c949e0527..2a48772ab 100644 --- a/ui/videowidget.cpp +++ b/ui/videowidget.cpp @@ -219,6 +219,11 @@ Okular::NormalizedRect VideoWidget::normGeometry() const return d->geom; } +bool VideoWidget::isPlaying() const +{ + return d->player->isPlaying(); +} + void VideoWidget::play() { d->load(); diff --git a/ui/videowidget.h b/ui/videowidget.h index 764eb588c..b3ca14e18 100644 --- a/ui/videowidget.h +++ b/ui/videowidget.h @@ -27,6 +27,8 @@ class VideoWidget : public QWidget void setNormGeometry( const Okular::NormalizedRect &rect ); Okular::NormalizedRect normGeometry() const; + + bool isPlaying() const; public slots: void play();