]> cloud.milkyroute.net Git - dolphin.git/commitdiff
mediawidget: bind arrow keys to slide in media
authorMéven Car <meven@kde.org>
Sat, 3 May 2025 09:13:33 +0000 (11:13 +0200)
committerMéven Car <meven@kde.org>
Sat, 28 Jun 2025 09:55:38 +0000 (11:55 +0200)
src/panels/information/informationpanelcontent.cpp
src/panels/information/mediawidget.cpp

index 1ab57c0e78f7c46ad67fd87b7f3167b39653b988..134c5e0567e5aa8959d9602a46ac2fe310476afb 100644 (file)
@@ -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);
index 345cb0201c73a6ac441f5a3982d3ed9e38bca0c5..3ef046909a8ed90b5abc8436daf4eaf47c3179b1 100644 (file)
@@ -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()).
     }
 }