From ee53ebb1978522bb6ae22d9e86c5b72092a28ed0 Mon Sep 17 00:00:00 2001 From: Bionus Date: Wed, 17 Jan 2024 22:58:12 +0100 Subject: [PATCH] feat: remember last used video player volume --- src/gui/src/viewer/players/gif-player.cpp | 7 ++++--- src/gui/src/viewer/players/gif-player.h | 4 +++- src/gui/src/viewer/players/video-player.cpp | 13 +++++++++---- src/gui/src/viewer/players/video-player.h | 4 +++- src/gui/src/viewer/viewer-window.cpp | 4 ++-- 5 files changed, 21 insertions(+), 11 deletions(-) diff --git a/src/gui/src/viewer/players/gif-player.cpp b/src/gui/src/viewer/players/gif-player.cpp index 562b6f833..c2fc62ce0 100644 --- a/src/gui/src/viewer/players/gif-player.cpp +++ b/src/gui/src/viewer/players/gif-player.cpp @@ -1,12 +1,13 @@ #include "gif-player.h" #include #include +#include #include #include "ui_gif-player.h" -GifPlayer::GifPlayer(bool showControls, Qt::Alignment alignment, QWidget *parent) - : Player(parent), ui(new Ui::GifPlayer) +GifPlayer::GifPlayer(QSettings *settings, Qt::Alignment alignment, QWidget *parent) + : Player(parent), ui(new Ui::GifPlayer), m_settings(settings) { ui->setupUi(this); @@ -17,7 +18,7 @@ GifPlayer::GifPlayer(bool showControls, Qt::Alignment alignment, QWidget *parent ui->label->setAlignment(alignment); - if (showControls) { + if (m_settings->value("Viewer/showGifPlayerControls", true).toBool()) { ui->buttonPlayPause->setIcon(style()->standardIcon(QStyle::SP_MediaPause)); connect(ui->buttonPlayPause, &QToolButton::clicked, this, &GifPlayer::playPause); connect(ui->sliderPosition, &QSlider::valueChanged, this, &GifPlayer::seek); diff --git a/src/gui/src/viewer/players/gif-player.h b/src/gui/src/viewer/players/gif-player.h index 1e7288c97..873513b0f 100644 --- a/src/gui/src/viewer/players/gif-player.h +++ b/src/gui/src/viewer/players/gif-player.h @@ -12,6 +12,7 @@ namespace Ui } +class QSettings; class QWidget; class GifPlayer : public Player @@ -19,7 +20,7 @@ class GifPlayer : public Player Q_OBJECT public: - explicit GifPlayer(bool showControls, Qt::Alignment alignment, QWidget *parent = nullptr); + explicit GifPlayer(QSettings *settings, Qt::Alignment alignment, QWidget *parent = nullptr); ~GifPlayer(); bool supports(const QString &file) override; @@ -34,6 +35,7 @@ class GifPlayer : public Player private: Ui::GifPlayer *ui; + QSettings *m_settings; QStringList m_supportedFormats; QMovie *m_movie = nullptr; bool m_noSeek = false; diff --git a/src/gui/src/viewer/players/video-player.cpp b/src/gui/src/viewer/players/video-player.cpp index 3bce864a5..6eeb945e3 100644 --- a/src/gui/src/viewer/players/video-player.cpp +++ b/src/gui/src/viewer/players/video-player.cpp @@ -1,15 +1,16 @@ #include "video-player.h" +#include #include #include -#include +#include #include #include #include #include "ui_video-player.h" -VideoPlayer::VideoPlayer(bool showControls, QWidget *parent) - : Player(parent), ui(new Ui::VideoPlayer) +VideoPlayer::VideoPlayer(QSettings *settings, QWidget *parent) + : Player(parent), ui(new Ui::VideoPlayer), m_settings(settings) { ui->setupUi(this); @@ -24,7 +25,7 @@ VideoPlayer::VideoPlayer(bool showControls, QWidget *parent) m_mediaPlayer->setAudioOutput(m_audioOutput); m_mediaPlayer->setLoops(QMediaPlayer::Infinite); - if (showControls) { + if (m_settings->value("Viewer/showVideoPlayerControls", true).toBool()) { // TODO QT6 m_mediaPlayer->setNotifyInterval(50); ui->buttonPlayPause->setIcon(style()->standardIcon(QStyle::SP_MediaPause)); @@ -34,10 +35,14 @@ VideoPlayer::VideoPlayer(bool showControls, QWidget *parent) } else { ui->controls->hide(); } + + ui->sliderVolume->setValue(m_settings->value("Viewer/Video/Volume", 100).toInt()); } VideoPlayer::~VideoPlayer() { + m_settings->setValue("Viewer/Video/Volume", ui->sliderVolume->value()); + unload(); // Fix for weird Linux crash (issue #2190) diff --git a/src/gui/src/viewer/players/video-player.h b/src/gui/src/viewer/players/video-player.h index 763911562..21fc8394f 100644 --- a/src/gui/src/viewer/players/video-player.h +++ b/src/gui/src/viewer/players/video-player.h @@ -13,6 +13,7 @@ namespace Ui class QAudioOutput; class QMediaPlayer; +class QSettings; class QVideoWidget; class QWidget; @@ -21,7 +22,7 @@ class VideoPlayer : public Player Q_OBJECT public: - explicit VideoPlayer(bool showControls, QWidget *parent = nullptr); + explicit VideoPlayer(QSettings *settings, QWidget *parent = nullptr); ~VideoPlayer(); bool supports(const QString &file) override; @@ -37,6 +38,7 @@ class VideoPlayer : public Player private: Ui::VideoPlayer *ui; + QSettings *m_settings; QStringList m_supportedFormats; QVideoWidget *m_videoWidget; QAudioOutput *m_audioOutput; diff --git a/src/gui/src/viewer/viewer-window.cpp b/src/gui/src/viewer/viewer-window.cpp index 98c17b13d..e331e9115 100644 --- a/src/gui/src/viewer/viewer-window.cpp +++ b/src/gui/src/viewer/viewer-window.cpp @@ -134,12 +134,12 @@ ViewerWindow::ViewerWindow(QList> images, const QSharedPoi connect(m_labelImage, SIGNAL(doubleClicked()), this, SLOT(openFile())); m_stackedWidget->addWidget(m_labelImage); - m_gifPlayer = new GifPlayer(m_settings->value("Viewer/showGifPlayerControls", true).toBool(), getAlignments("imagePositionAnimation"), this); + m_gifPlayer = new GifPlayer(m_settings, getAlignments("imagePositionAnimation"), this); m_stackedWidget->addWidget(m_gifPlayer); if (m_settings->value("Viewer/useVideoPlayer", true).toBool()) { // getAlignments("imagePositionVideo") - m_videoPlayer = new VideoPlayer(m_settings->value("Viewer/showVideoPlayerControls", true).toBool(), this); + m_videoPlayer = new VideoPlayer(m_settings, this); m_stackedWidget->addWidget(m_videoPlayer); }