diff --git a/src/panels/information/informationpanelcontent.h b/src/panels/information/informationpanelcontent.h --- a/src/panels/information/informationpanelcontent.h +++ b/src/panels/information/informationpanelcontent.h @@ -154,6 +154,7 @@ QDialogButtonBox* m_configureButtons; PlacesItemModel* m_placesItemModel; + bool m_usePhonon; }; #endif // INFORMATIONPANELCONTENT_H diff --git a/src/panels/information/informationpanelcontent.cpp b/src/panels/information/informationpanelcontent.cpp --- a/src/panels/information/informationpanelcontent.cpp +++ b/src/panels/information/informationpanelcontent.cpp @@ -46,6 +46,8 @@ #include #include #include +#include +#include #include "dolphin_informationpanelsettings.h" #include "phononwidget.h" @@ -61,7 +63,8 @@ m_nameLabel(nullptr), m_metaDataWidget(nullptr), m_metaDataArea(nullptr), - m_placesItemModel(nullptr) + m_placesItemModel(nullptr), + m_usePhonon(false) { parent->installEventFilter(this); @@ -161,9 +164,9 @@ if (item != m_item) { m_item = item; - refreshPreview(); refreshMetaData(); } + refreshPreview(); } void InformationPanelContent::refreshPreview() @@ -174,6 +177,8 @@ m_previewJob->kill(); } + m_preview->setCursor(Qt::ArrowCursor); + m_usePhonon = false; setNameLabelText(m_item.text()); if (InformationPanelSettings::previewsShown()) { @@ -216,16 +221,19 @@ const QString mimeType = m_item.mimetype(); const bool isVideo = mimeType.startsWith(QLatin1String("video/")); - const bool usePhonon = mimeType.startsWith(QLatin1String("audio/")) || isVideo; + m_usePhonon = mimeType.startsWith(QLatin1String("audio/")) || isVideo; - if (usePhonon) { + if (m_usePhonon) { + // change the cursor + m_preview->setCursor(Qt::PointingHandCursor); 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_preview->installEventFilter(m_phononWidget); } m_phononWidget->show(); @@ -235,6 +243,7 @@ // When we don't need it, hide the phonon widget first to avoid flickering m_phononWidget->hide(); m_preview->show(); + m_preview->removeEventFilter(m_phononWidget); } } } else { @@ -323,6 +332,44 @@ QPixmap p = pixmap; KIconLoader::global()->drawOverlays(item.overlays(), p, KIconLoader::Desktop); + + if (m_usePhonon) { + // adds a play arrow + auto icon = QIcon::fromTheme(QStringLiteral("media-playback-start")); + + // inner arrow + auto pixicon = icon.pixmap(44, 44); + // border of the arrow + auto pixborder = icon.pixmap(48, 48); + + QImage img = pixborder.toImage(); + for(int i=0; i(pixborder.width() / 2 / p.devicePixelRatio()), + p.height() / 2 - static_cast(pixborder.height() / 2 / p.devicePixelRatio()), + pixborder); + + painter.drawPixmap(p.width() / 2 - static_cast(pixicon.width() / 2 / p.devicePixelRatio()), + p.height() / 2 - static_cast(pixicon.height() / 2 / p.devicePixelRatio()), + pixicon); + + } + m_preview->setPixmap(p); } diff --git a/src/panels/information/phononwidget.h b/src/panels/information/phononwidget.h --- a/src/panels/information/phononwidget.h +++ b/src/panels/information/phononwidget.h @@ -58,6 +58,7 @@ QSize videoSize() const; void setAutoPlay(bool autoPlay); + bool eventFilter(QObject *object, QEvent *event) override; signals: /** diff --git a/src/panels/information/phononwidget.cpp b/src/panels/information/phononwidget.cpp --- a/src/panels/information/phononwidget.cpp +++ b/src/panels/information/phononwidget.cpp @@ -95,6 +95,23 @@ return m_url; } +bool PhononWidget::eventFilter(QObject *object, QEvent *event) { + Q_UNUSED(object); + if (event->type() == QEvent::MouseButtonPress){ + const QMouseEvent *mouseEvent = static_cast(event); + if (mouseEvent->button() == Qt::LeftButton) { + // toggle playback + if (m_media && m_media->state() == Phonon::State::PlayingState) { + m_media->pause(); + } else { + play(); + } + return true; + } + } + return false; +} + void PhononWidget::setVideoSize(const QSize& size) { if (m_videoSize != size) { @@ -172,8 +189,8 @@ switch (newstate) { case Phonon::PlayingState: case Phonon::BufferingState: - m_stopButton->show(); m_playButton->hide(); + m_stopButton->show(); break; default: m_stopButton->hide(); @@ -196,6 +213,7 @@ if (!m_videoPlayer) { m_videoPlayer = new EmbeddedVideoPlayer(this); + m_videoPlayer->setCursor(Qt::PointingHandCursor); m_videoPlayer->installEventFilter(this); m_topLayout->insertWidget(0, m_videoPlayer); Phonon::createPath(m_media, m_videoPlayer);