]> cloud.milkyroute.net Git - dolphin.git/commitdiff
- Postpone the video player initialization until the play button has been pressed.
authorPeter Penz <peter.penz19@gmail.com>
Thu, 23 Apr 2009 19:46:08 +0000 (19:46 +0000)
committerPeter Penz <peter.penz19@gmail.com>
Thu, 23 Apr 2009 19:46:08 +0000 (19:46 +0000)
- Assure that the video player has the same size as the preview widget. Convincing the embedded video player to dynamically resize during playing a video seems to be impossible - I need to check the Phonon::VideoPlayer source code to get the root cause for the currently strange behavior :-(

svn path=/trunk/KDE/kdebase/apps/; revision=958332

src/panels/information/informationpanel.cpp
src/panels/information/phononwidget.cpp
src/panels/information/phononwidget.h

index 1af83dcccb1d3ce6df8a0f20b609a67939f25270..2349a6cffc635265124acc2c6e8d46913ad6ac6e 100644 (file)
@@ -206,6 +206,11 @@ void InformationPanel::resizeEvent(QResizeEvent* event)
         m_preview->setSizeHint(QSize(maxWidth, maxWidth));
         m_urlCandidate = m_shownUrl; // reset the URL candidate if a resizing is done
         m_infoTimer->start();
+
+        if (m_phononWidget->isVisible() && (m_phononWidget->mode() == PhononWidget::Video)) {
+            // assure that the size of the video player is the same as the preview size
+            m_phononWidget->setVideoSize(QSize(maxWidth, maxWidth));
+        }
     }
     Panel::resizeEvent(event);
 }
@@ -698,7 +703,7 @@ void InformationPanel::updatePhononWidget()
         const KFileItem item = fileItem();
         const QString mimeType = item.mimetype();
         const bool usePhonon = Phonon::BackendCapabilities::isMimeTypeAvailable(mimeType) &&
-                               (mimeType != "image/png"); // TODO: workaround, as Phonon
+                               (mimeType != "image/png");  // TODO: workaround, as Phonon
                                                            // thinks it supports PNG images
         if (usePhonon) {
             m_phononWidget->show();
@@ -707,6 +712,9 @@ void InformationPanel::updatePhononWidget()
                                       : PhononWidget::Audio;
             m_phononWidget->setMode(mode);
             m_phononWidget->setUrl(item.url());
+            if (mode == PhononWidget::Video) {
+                m_phononWidget->setVideoSize(m_preview->size());
+            }
         } else {
             m_phononWidget->hide();
             m_preview->setVisible(true);
@@ -716,8 +724,6 @@ void InformationPanel::updatePhononWidget()
 
 void InformationPanel::init()
 {
-    const int spacing = KDialog::spacingHint();
-
     m_infoTimer = new QTimer(this);
     m_infoTimer->setInterval(300);
     m_infoTimer->setSingleShot(true);
@@ -734,7 +740,7 @@ void InformationPanel::init()
             this, SLOT(markOutdatedPreview()));
 
     QVBoxLayout* layout = new QVBoxLayout;
-    layout->setSpacing(spacing);
+    layout->setSpacing(KDialog::spacingHint());
 
     // name
     m_nameLabel = new QLabel(this);
@@ -746,11 +752,14 @@ void InformationPanel::init()
     m_nameLabel->setMaximumWidth(KIconLoader::SizeEnormous);
 
     // preview
+    const int minPreviewWidth = KIconLoader::SizeEnormous + KIconLoader::SizeMedium;
+
     m_preview = new PixmapViewer(this);
-    m_preview->setMinimumWidth(KIconLoader::SizeEnormous + KIconLoader::SizeMedium);
+    m_preview->setMinimumWidth(minPreviewWidth);
     m_preview->setMinimumHeight(KIconLoader::SizeEnormous);
 
     m_phononWidget = new PhononWidget(this);
+    m_phononWidget->setMinimumWidth(minPreviewWidth);
     connect(m_phononWidget, SIGNAL(playingStarted()),
             this, SLOT(slotPlayingStarted()));
     connect(m_phononWidget, SIGNAL(playingStopped()),
index 405172b8d4301b38d5dfa073c2498c1ed7f9785a..798a4a35b22691c80cef643450cd51c48efb7db0 100644 (file)
 #include <Phonon/MediaObject>
 #include <Phonon/SeekSlider>
 #include <Phonon/VideoPlayer>
+
 #include <QtGui/QVBoxLayout>
 #include <QtGui/QHBoxLayout>
 #include <QtGui/QShowEvent>
 #include <QtGui/QToolButton>
+
+#include <kdialog.h>
 #include <kicon.h>
 #include <kurl.h>
 #include <klocale.h>
 
+class EmbeddedVideoPlayer : public Phonon::VideoPlayer
+{
+    public:
+        EmbeddedVideoPlayer(Phonon::Category category, QWidget *parent = 0) :
+            Phonon::VideoPlayer(category, parent)
+        {
+            setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
+        }
+
+        void setSizeHint(const QSize& size)
+        {
+            m_sizeHint = size;
+            setFixedHeight(size.height());
+            updateGeometry();
+        }
+
+        virtual QSize sizeHint() const
+        {
+            return m_sizeHint.isValid() ? m_sizeHint : Phonon::VideoPlayer::sizeHint();
+        }
+
+    private:
+        QSize m_sizeHint;
+};
+
 PhononWidget::PhononWidget(QWidget *parent)
     : QWidget(parent),
     m_mode(Audio),
     m_url(),
     m_playButton(0),
     m_stopButton(0),
+    m_topLayout(0),
     m_audioMedia(0),
     m_media(0),
     m_seekSlider(0),
@@ -71,6 +100,19 @@ PhononWidget::Mode PhononWidget::mode() const
     return m_mode;
 }
 
+void PhononWidget::setVideoSize(const QSize& size)
+{
+    if (m_videoSize != size) {
+        m_videoSize = size;
+        applyVideoSize();
+    }
+}
+
+QSize PhononWidget::videoSize() const
+{
+    return m_videoSize;
+}
+
 void PhononWidget::showEvent(QShowEvent *event)
 {
     if (event->spontaneous()) {
@@ -78,10 +120,10 @@ void PhononWidget::showEvent(QShowEvent *event)
         return;
     }
 
-    if (m_playButton == 0) {
-        QVBoxLayout *topLayout = new QVBoxLayout(this);
-        topLayout->setMargin(0);
-        topLayout->setSpacing(0);
+    if (m_topLayout == 0) {
+        m_topLayout = new QVBoxLayout(this);
+        m_topLayout->setMargin(0);
+        m_topLayout->setSpacing(KDialog::spacingHint());
         QHBoxLayout *controlsLayout = new QHBoxLayout(this);
         controlsLayout->setMargin(0);
         controlsLayout->setSpacing(0);
@@ -89,15 +131,12 @@ void PhononWidget::showEvent(QShowEvent *event)
         m_playButton = new QToolButton(this);
         m_stopButton = new QToolButton(this);
         m_seekSlider = new Phonon::SeekSlider(this);
-        m_videoPlayer = new Phonon::VideoPlayer(Phonon::VideoCategory, this);
-        m_videoPlayer->hide();
 
         controlsLayout->addWidget(m_playButton);
         controlsLayout->addWidget(m_stopButton);
         controlsLayout->addWidget(m_seekSlider);
 
-        topLayout->addWidget(m_videoPlayer);
-        topLayout->addLayout(controlsLayout);
+        m_topLayout->addLayout(controlsLayout);
 
         m_playButton->setToolTip(i18n("play"));
         m_playButton->setIconSize(QSize(16, 16));
@@ -111,6 +150,11 @@ void PhononWidget::showEvent(QShowEvent *event)
         connect(m_stopButton, SIGNAL(clicked()), this, SLOT(stop()));
 
         m_seekSlider->setIconVisible(false);
+
+        // Creating an audio player or video player instance might take up to
+        // 2 seconds when doing it the first time. To prevent that the user
+        // interface gets noticable blocked, the creation is delayed until
+        // the play button has been pressed (see PhononWidget::play()).
     }
 }
 
@@ -144,10 +188,6 @@ void PhononWidget::play()
     switch (m_mode) {
     case Audio:
         if (m_audioMedia == 0) {
-            // Creating an audio player might take up to 2 seconds when doing
-            // it the first time. To prevent that the user interface gets
-            // noticable blocked, the creation is delayed until the play button
-            // has been pressed.
             m_audioMedia = Phonon::createPlayer(Phonon::MusicCategory, m_url);
             m_audioMedia->setParent(this);
         }
@@ -156,6 +196,11 @@ void PhononWidget::play()
         break;
 
     case Video:
+        if (m_videoPlayer == 0) {
+            m_videoPlayer = new EmbeddedVideoPlayer(Phonon::VideoCategory, this);
+            m_topLayout->insertWidget(0, m_videoPlayer);
+        }
+        applyVideoSize();
         m_videoPlayer->show();
         m_videoPlayer->play(m_url);
         m_media = m_videoPlayer->mediaObject();
@@ -189,3 +234,10 @@ void PhononWidget::stop()
         m_videoPlayer->hide();
     }
 }
+
+void PhononWidget::applyVideoSize()
+{
+    if ((m_videoPlayer != 0) && m_videoSize.isValid()) {
+        m_videoPlayer->setSizeHint(m_videoSize);
+    }
+}
index daea8b1cc27f8bbd0e801241a69b0e11f59ef18c..196b87f879c6274c1d2f8f2002462f8998839343 100644 (file)
@@ -23,6 +23,7 @@
 
 #include <kurl.h>
 
+#include <QtCore/QSize>
 #include <QtGui/QWidget>
 
 #include <Phonon/Global>
@@ -34,7 +35,9 @@ namespace Phonon
     class VideoPlayer;
 } // namespace Phonon
 
+class EmbeddedVideoPlayer;
 class QToolButton;
+class QVBoxLayout;
 
 class PhononWidget : public QWidget
 {
@@ -54,6 +57,9 @@ class PhononWidget : public QWidget
         void setMode(Mode mode);
         Mode mode() const;
 
+        void setVideoSize(const QSize& size);
+        QSize videoSize() const;
+
     signals:
         void playingStarted();
         void playingStopped();
@@ -67,15 +73,22 @@ class PhononWidget : public QWidget
         void play();
         void stop();
 
+    private:
+        void applyVideoSize();
+
     private:
         Mode m_mode;
         KUrl m_url;
+        QSize m_videoSize;
+
         QToolButton *m_playButton;
         QToolButton *m_stopButton;
+
+        QVBoxLayout *m_topLayout;
         Phonon::MediaObject *m_audioMedia;
         Phonon::MediaObject *m_media;
         Phonon::SeekSlider *m_seekSlider;
-        Phonon::VideoPlayer *m_videoPlayer;
+        EmbeddedVideoPlayer *m_videoPlayer;
 };
 
 #endif // PHONONWIDGET_H