]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/panels/information/informationpanelcontent.cpp
Fix a regression preventing previews to be resized
[dolphin.git] / src / panels / information / informationpanelcontent.cpp
index c130ad37022733bc8909c1f19518a0c9bbe75c47..363ad818d3dcbc1c027cfa7d935987d41427757e 100644 (file)
@@ -40,6 +40,7 @@
 #include <Phonon/MediaObject>
 
 #include <QLabel>
+#include <QDialogButtonBox>
 #include <QScrollArea>
 #include <QTextLayout>
 #include <QTimer>
@@ -85,6 +86,7 @@ InformationPanelContent::InformationPanelContent(QWidget* parent) :
     m_phononWidget = new PhononWidget(parent);
     m_phononWidget->hide();
     m_phononWidget->setMinimumWidth(minPreviewWidth);
+    m_phononWidget->setAutoPlay(InformationPanelSettings::previewsAutoPlay());
     connect(m_phononWidget, &PhononWidget::hasVideoChanged,
             this, &InformationPanelContent::slotHasVideoChanged);
 
@@ -107,18 +109,31 @@ InformationPanelContent::InformationPanelContent(QWidget* parent) :
     m_metaDataWidget->setFont(QFontDatabase::systemFont(QFontDatabase::SmallestReadableFont));
     m_metaDataWidget->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Minimum);
 
-    // Encapsulate the MetaDataWidget inside a container that has a dummy widget
-    // at the bottom. This prevents that the meta data widget gets vertically stretched
-    // in the case where the height of m_metaDataArea > m_metaDataWidget.
-    QWidget* metaDataWidgetContainer = new QWidget(parent);
-    QVBoxLayout* containerLayout = new QVBoxLayout(metaDataWidgetContainer);
-    containerLayout->setContentsMargins(0, 0, 0, 0);
-    containerLayout->setSpacing(0);
-    containerLayout->addWidget(m_metaDataWidget);
-    containerLayout->addStretch();
+    // Configuration
+    m_configureLabel = new QLabel(i18nc("@label::textbox",
+                                        "Select which data should be shown:"), this);
+    m_configureLabel->setWordWrap(true);
+    m_configureLabel->setVisible(false);
+
+    m_configureButtons = new QDialogButtonBox(QDialogButtonBox::Save | QDialogButtonBox::Cancel);
+    m_configureButtons->setVisible(false);
+    connect(m_configureButtons, &QDialogButtonBox::accepted, this, [this]() {
+                m_metaDataWidget->setConfigurationMode(Baloo::ConfigurationMode::Accept);
+                m_configureButtons->setVisible(false);
+                m_configureLabel->setVisible(false);
+                emit configurationFinished();
+            }
+    );
+    connect(m_configureButtons, &QDialogButtonBox::rejected, this, [this]() {
+                m_metaDataWidget->setConfigurationMode(Baloo::ConfigurationMode::Cancel);
+                m_configureButtons->setVisible(false);
+                m_configureLabel->setVisible(false);
+                emit configurationFinished();
+            }
+    );
 
     m_metaDataArea = new QScrollArea(parent);
-    m_metaDataArea->setWidget(metaDataWidgetContainer);
+    m_metaDataArea->setWidget(m_metaDataWidget);
     m_metaDataArea->setWidgetResizable(true);
     m_metaDataArea->setFrameShape(QFrame::NoFrame);
 
@@ -129,7 +144,9 @@ InformationPanelContent::InformationPanelContent(QWidget* parent) :
     layout->addWidget(m_phononWidget);
     layout->addWidget(m_nameLabel);
     layout->addWidget(new KSeparator());
+    layout->addWidget(m_configureLabel);
     layout->addWidget(m_metaDataArea);
+    layout->addWidget(m_configureButtons);
 
     m_placesItemModel = new PlacesItemModel(this);
 }
@@ -141,13 +158,16 @@ InformationPanelContent::~InformationPanelContent()
 
 void InformationPanelContent::showItem(const KFileItem& item)
 {
-    m_item = item;
+    if (item != m_item) {
+        m_item = item;
 
+        refreshMetaData();
+    }
     refreshPreview();
-    refreshMetaData();
 }
 
-void InformationPanelContent::refreshPreview() {
+void InformationPanelContent::refreshPreview()
+{
     // If there is a preview job, kill it to prevent that we have jobs for
     // multiple items running, and thus a race condition (bug 250787).
     if (m_previewJob) {
@@ -156,11 +176,12 @@ void InformationPanelContent::refreshPreview() {
 
     setNameLabelText(m_item.text());
     if (InformationPanelSettings::previewsShown()) {
-        m_preview->show();
 
         const QUrl itemUrl = m_item.url();
         const bool isSearchUrl = itemUrl.scheme().contains(QStringLiteral("search")) && m_item.localPath().isEmpty();
         if (isSearchUrl) {
+            m_preview->show();
+
             // in the case of a search-URL the URL is not readable for humans
             // (at least not useful to show in the Information Panel)
             m_preview->setPixmap(
@@ -194,13 +215,26 @@ void InformationPanelContent::refreshPreview() {
                     this, &InformationPanelContent::showIcon);
 
             const QString mimeType = m_item.mimetype();
-            const bool usePhonon = mimeType.startsWith(QLatin1String("audio/")) || mimeType.startsWith(QLatin1String("video/"));
+            const bool isVideo = mimeType.startsWith(QLatin1String("video/"));
+            const bool usePhonon = mimeType.startsWith(QLatin1String("audio/")) || isVideo;
+
             if (usePhonon) {
+
+                if (InformationPanelSettings::previewsAutoPlay() && isVideo) {
+                    // hides the preview now to avoid flickering when the autoplay video starts
+                    m_preview->hide();
+                } else {
+                    // the video won't play before the preview is displayed
+                    m_preview->show();
+                }
+
                 m_phononWidget->show();
-                m_phononWidget->setUrl(m_item.targetUrl());
+                m_phononWidget->setUrl(m_item.targetUrl(), isVideo ? PhononWidget::MediaKind::Video : PhononWidget::MediaKind::Audio);
                 m_phononWidget->setVideoSize(m_preview->size());
             } else {
+                // When we don't need it, hide the phonon widget first to avoid flickering
                 m_phononWidget->hide();
+                m_preview->show();
             }
         }
     } else {
@@ -209,7 +243,15 @@ void InformationPanelContent::refreshPreview() {
     }
 }
 
-void InformationPanelContent::refreshMetaData() {
+void InformationPanelContent::configureShownProperties()
+{
+    m_configureLabel->setVisible(true);
+    m_configureButtons->setVisible(true);
+    m_metaDataWidget->setConfigurationMode(Baloo::ConfigurationMode::ReStart);
+}
+
+void InformationPanelContent::refreshMetaData()
+{
     m_metaDataWidget->setDateFormat(static_cast<Baloo::DateFormats>(InformationPanelSettings::dateFormat()));
     m_metaDataWidget->show();
     m_metaDataWidget->setItems(KFileItemList() << m_item);
@@ -293,7 +335,8 @@ void InformationPanelContent::markOutdatedPreview()
     m_preview->setPixmap(disabledPixmap);
 }
 
-KFileItemList InformationPanelContent::items() {
+KFileItemList InformationPanelContent::items()
+{
     return m_metaDataWidget->items();
 }
 
@@ -302,6 +345,10 @@ void InformationPanelContent::slotHasVideoChanged(bool hasVideo)
     m_preview->setVisible(InformationPanelSettings::previewsShown() && !hasVideo);
 }
 
+void InformationPanelContent::setPreviewAutoPlay(bool autoPlay) {
+    m_phononWidget->setAutoPlay(autoPlay);
+}
+
 void InformationPanelContent::setNameLabelText(const QString& text)
 {
     QTextOption textOption;