Skip to content

Commit

Permalink
feat: remember last used video player volume
Browse files Browse the repository at this point in the history
  • Loading branch information
Bionus committed Jan 17, 2024
1 parent 6e2fddd commit ee53ebb
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 11 deletions.
7 changes: 4 additions & 3 deletions src/gui/src/viewer/players/gif-player.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
#include "gif-player.h"
#include <QFileInfo>
#include <QMovie>
#include <QSettings>
#include <QStyle>
#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);

Expand All @@ -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);
Expand Down
4 changes: 3 additions & 1 deletion src/gui/src/viewer/players/gif-player.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@ namespace Ui
}


class QSettings;
class QWidget;

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;
Expand All @@ -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;
Expand Down
13 changes: 9 additions & 4 deletions src/gui/src/viewer/players/video-player.cpp
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
#include "video-player.h"
#include <QAudioOutput>
#include <QFileInfo>
#include <QMediaPlayer>
#include <QAudioOutput>
#include <QSettings>
#include <QStyle>
#include <QTime>
#include <QVideoWidget>
#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);

Expand All @@ -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));
Expand All @@ -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)
Expand Down
4 changes: 3 additions & 1 deletion src/gui/src/viewer/players/video-player.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ namespace Ui

class QAudioOutput;
class QMediaPlayer;
class QSettings;
class QVideoWidget;
class QWidget;

Expand All @@ -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;
Expand All @@ -37,6 +38,7 @@ class VideoPlayer : public Player

private:
Ui::VideoPlayer *ui;
QSettings *m_settings;
QStringList m_supportedFormats;
QVideoWidget *m_videoWidget;
QAudioOutput *m_audioOutput;
Expand Down
4 changes: 2 additions & 2 deletions src/gui/src/viewer/viewer-window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,12 +134,12 @@ ViewerWindow::ViewerWindow(QList<QSharedPointer<Image>> 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);
}

Expand Down

0 comments on commit ee53ebb

Please # to comment.