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,11 +46,16 @@ #include #include #include +#include +#include #include "dolphin_informationpanelsettings.h" #include "phononwidget.h" #include "pixmapviewer.h" +const uint PLAY_ARROW_SIZE = 48; +const uint PLAY_ARROW_BORDER_SIZE = 4; + InformationPanelContent::InformationPanelContent(QWidget* parent) : QWidget(parent), m_item(), @@ -61,7 +66,8 @@ m_nameLabel(nullptr), m_metaDataWidget(nullptr), m_metaDataArea(nullptr), - m_placesItemModel(nullptr) + m_placesItemModel(nullptr), + m_usePhonon(false) { parent->installEventFilter(this); @@ -161,9 +167,9 @@ if (item != m_item) { m_item = item; - refreshPreview(); refreshMetaData(); } + refreshPreview(); } void InformationPanelContent::refreshPreview() @@ -174,6 +180,8 @@ m_previewJob->kill(); } + m_preview->setCursor(Qt::ArrowCursor); + m_usePhonon = false; setNameLabelText(m_item.text()); if (InformationPanelSettings::previewsShown()) { @@ -216,16 +224,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 +246,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 +335,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")); + + // border of the arrow + auto pixborder = icon.pixmap(PLAY_ARROW_SIZE, PLAY_ARROW_SIZE); + // inner arrow + auto pixicon = icon.pixmap(PLAY_ARROW_SIZE - PLAY_ARROW_BORDER_SIZE, PLAY_ARROW_SIZE - PLAY_ARROW_BORDER_SIZE); + + QImage img = pixborder.toImage(); + for (int i=0; i(p.width() / 2 - pixborder.width() / 2 / devicePixelRatio()), + static_cast(p.height() / 2 - pixborder.height() / 2 / devicePixelRatio()), + pixborder); + + painter.drawPixmap(static_cast(p.width() / 2 - pixicon.width() / 2 / devicePixelRatio()), + static_cast(p.height() / 2 - pixicon.height() / 2 / 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,24 @@ 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 +190,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 +214,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);