diff options
| author | Méven Car <[email protected]> | 2025-05-03 11:13:33 +0200 |
|---|---|---|
| committer | Méven Car <[email protected]> | 2025-06-28 11:55:38 +0200 |
| commit | 58c48052c38e5bb4f6cf8047dc71e40cfbf04403 (patch) | |
| tree | 155f7ae706eef26fe31f6f9b69ac0d3c6f3dbb5c /src/panels | |
| parent | 8216a67d58af0fd709bb3bfb8d0b6073b11cdfed (diff) | |
mediawidget: bind arrow keys to slide in media
Diffstat (limited to 'src/panels')
| -rw-r--r-- | src/panels/information/informationpanelcontent.cpp | 8 | ||||
| -rw-r--r-- | src/panels/information/mediawidget.cpp | 33 |
2 files changed, 32 insertions, 9 deletions
diff --git a/src/panels/information/informationpanelcontent.cpp b/src/panels/information/informationpanelcontent.cpp index 1ab57c0e7..134c5e056 100644 --- a/src/panels/information/informationpanelcontent.cpp +++ b/src/panels/information/informationpanelcontent.cpp @@ -211,9 +211,9 @@ void InformationPanelContent::refreshPreview() const QString mimeType = m_item.mimetype(); const bool isAnimatedImage = m_preview->isAnimatedMimeType(mimeType); m_isVideo = !isAnimatedImage && mimeType.startsWith(QLatin1String("video/")); - bool usePhonon = m_isVideo || mimeType.startsWith(QLatin1String("audio/")); + bool useMedia = m_isVideo || mimeType.startsWith(QLatin1String("audio/")); - if (usePhonon) { + if (useMedia) { // change the cursor of the preview m_preview->setCursor(Qt::PointingHandCursor); m_preview->installEventFilter(m_mediaWidget); @@ -221,7 +221,7 @@ void InformationPanelContent::refreshPreview() m_mediaWidget->show(); // if the video is playing, has been paused or stopped - // we don't need to update the preview/phonon widget states + // we don't need to update the preview/media widget states // unless the previewed file has changed, // or the setting previewshown has changed if ((m_mediaWidget->state() != QMediaPlayer::PlayingState && m_mediaWidget->state() != QMediaPlayer::PausedState @@ -242,7 +242,7 @@ void InformationPanelContent::refreshPreview() if (isAnimatedImage) { m_preview->setAnimatedImageFileName(itemUrl.toLocalFile()); } - // When we don't need it, hide the phonon widget first to avoid flickering + // When we don't need it, hide the media widget first to avoid flickering m_mediaWidget->hide(); m_preview->show(); m_preview->removeEventFilter(m_mediaWidget); diff --git a/src/panels/information/mediawidget.cpp b/src/panels/information/mediawidget.cpp index 345cb0201..3ef046909 100644 --- a/src/panels/information/mediawidget.cpp +++ b/src/panels/information/mediawidget.cpp @@ -18,6 +18,8 @@ #include <QStyleOptionSlider> #include <QToolButton> #include <QVBoxLayout> +#include <qnamespace.h> +#include <qwidget.h> class EmbeddedVideoPlayer : public QVideoWidget { @@ -108,6 +110,32 @@ protected: QSlider::mousePressEvent(event); } } + + void keyPressEvent(QKeyEvent *event) override + { + int newPosition = -1; + if (event->key() == Qt::Key_Right) { + // slide right 1% + newPosition = std::min(maximum(), sliderPosition() + maximum() / 100); + } else if (event->key() == Qt::Key_Left) { + // slide left 1% + newPosition = std::max(0, sliderPosition() - maximum() / 100); + } + + if (newPosition != -1) { + event->accept(); + + if (newPosition != sliderPosition()) { + setSliderPosition(newPosition); + triggerAction(SliderMove); + setRepeatAction(SliderNoAction); + + Q_EMIT sliderMoved(newPosition); + } + } else { + QSlider::keyPressEvent(event); + } + } }; MediaWidget::MediaWidget(QWidget *parent) @@ -231,11 +259,6 @@ void MediaWidget::showEvent(QShowEvent *event) m_pauseButton->setAutoRaise(true); m_pauseButton->hide(); connect(m_pauseButton, &QToolButton::clicked, this, &MediaWidget::togglePlayback); - - // 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 noticeable blocked, the creation is delayed until - // the play button has been pressed (see PhononWidget::play()). } } |
