Skip to content

Commit

Permalink
Add basic built-in video player (fix #1114)
Browse files Browse the repository at this point in the history
It can be disabled in the settings to restore the openable thumbnail.
  • Loading branch information
Bionus committed Nov 14, 2020
1 parent b29b11c commit 25d501f
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 19 deletions.
1 change: 1 addition & 0 deletions scripts/windows-setup/setup.iss
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ Source: "{#QtDir}\Qt5Concurrent.dll"; DestDir: "{app}"; Flags: ignorev
Source: "{#QtDir}\Qt5Core.dll"; DestDir: "{app}"; Flags: ignoreversion
Source: "{#QtDir}\Qt5Gui.dll"; DestDir: "{app}"; Flags: ignoreversion
Source: "{#QtDir}\Qt5Multimedia.dll"; DestDir: "{app}"; Flags: ignoreversion
Source: "{#QtDir}\Qt5MultimediaWidgets.dll"; DestDir: "{app}"; Flags: ignoreversion
Source: "{#QtDir}\Qt5Network.dll"; DestDir: "{app}"; Flags: ignoreversion
Source: "{#QtDir}\Qt5OpenGL.dll"; DestDir: "{app}"; Flags: ignoreversion
Source: "{#QtDir}\Qt5PrintSupport.dll"; DestDir: "{app}"; Flags: ignoreversion
Expand Down
3 changes: 2 additions & 1 deletion src/gui/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,11 @@ find_package(Qt5Concurrent REQUIRED)
find_package(Qt5Gui REQUIRED)
find_package(Qt5Network REQUIRED)
find_package(Qt5Multimedia REQUIRED)
find_package(Qt5MultimediaWidgets REQUIRED)
find_package(Qt5Sql REQUIRED)
find_package(Qt5Widgets REQUIRED)
find_package(Qt5Xml REQUIRED)
set(QT_LIBRARIES Qt5::Concurrent Qt5::Core Qt5::Gui Qt5::Multimedia Qt5::Network Qt5::Sql Qt5::Widgets Qt5::Xml)
set(QT_LIBRARIES Qt5::Concurrent Qt5::Core Qt5::Gui Qt5::Multimedia Qt5::MultimediaWidgets Qt5::Network Qt5::Sql Qt5::Widgets Qt5::Xml)

# Windows specials
if(WIN32)
Expand Down
2 changes: 2 additions & 0 deletions src/gui/src/settings/options-window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ OptionsWindow::OptionsWindow(Profile *profile, QWidget *parent)
ui->checkZoomShowTagCount->setChecked(settings->value("Zoom/showTagCount", false).toBool());
ui->checkZoomViewSamples->setChecked(settings->value("Zoom/viewSamples", false).toBool());
ui->checkImageScaleUp->setChecked(settings->value("Zoom/scaleUp", false).toBool());
ui->checkImageUseVideoPlayer->setChecked(settings->value("Zoom/useVideoPlayer", true).toBool());
const QStringList imageTagOrder { "type", "name", "count" };
ui->comboImageTagOrder->setCurrentIndex(imageTagOrder.indexOf(settings->value("Zoom/tagOrder", "type").toString()));
const QStringList positionsV { "top", "center", "bottom" };
Expand Down Expand Up @@ -1039,6 +1040,7 @@ void OptionsWindow::save()
settings->setValue("Zoom/showTagCount", ui->checkZoomShowTagCount->isChecked());
settings->setValue("Zoom/viewSamples", ui->checkZoomViewSamples->isChecked());
settings->setValue("Zoom/scaleUp", ui->checkImageScaleUp->isChecked());
settings->setValue("Zoom/useVideoPlayer", ui->checkImageUseVideoPlayer->isChecked());
const QStringList imageTagOrder { "type", "name", "count" };
settings->setValue("Zoom/tagOrder", imageTagOrder.at(ui->comboImageTagOrder->currentIndex()));
const QStringList positionsV { "top", "center", "bottom" };
Expand Down
10 changes: 10 additions & 0 deletions src/gui/src/settings/options-window.ui
Original file line number Diff line number Diff line change
Expand Up @@ -1848,6 +1848,16 @@
</property>
</widget>
</item>
<item row="14" column="0" colspan="2">
<widget class="QCheckBox" name="checkImageUseVideoPlayer">
<property name="text">
<string>Use built-in video player</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="pageInterfaceColoring">
Expand Down
69 changes: 51 additions & 18 deletions src/gui/src/viewer/zoom-window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#include <QFile>
#include <QFileDialog>
#include <QFileInfo>
#include <QMediaPlayer>
#include <QMediaPlaylist>
#include <QMenu>
#include <QMessageBox>
#include <QMouseEvent>
Expand All @@ -16,6 +18,7 @@
#include <QScrollBar>
#include <QShortcut>
#include <QUrl>
#include <QVideoWidget>
#include <QWheelEvent>
#include <ui_zoom-window.h>
#include "downloader/image-downloader.h"
Expand Down Expand Up @@ -102,6 +105,14 @@ ZoomWindow::ZoomWindow(QList<QSharedPointer<Image>> images, const QSharedPointer
connect(m_labelImage, SIGNAL(doubleClicked()), this, SLOT(openFile()));
m_stackedWidget->addWidget(m_labelImage);

if (m_settings->value("Zoom/useVideoPlayer", true).toBool()) {
m_videoWidget = new QVideoWidget(this);
m_stackedWidget->addWidget(m_videoWidget);

m_mediaPlayer = new QMediaPlayer(this, QMediaPlayer::VideoSurface);
m_mediaPlayer->setVideoOutput(m_videoWidget);
}

connect(ui->buttonDetails, &QPushButton::clicked, this, &ZoomWindow::showDetails);
connect(ui->buttonPlus, &QPushButton::toggled, this, &ZoomWindow::updateButtonPlus);

Expand Down Expand Up @@ -676,7 +687,7 @@ void ZoomWindow::pendingUpdate()
void ZoomWindow::draw()
{
// Videos don't get drawn
if (m_image->isVideo()) {
if (m_image->isVideo() && !m_settings->value("Zoom/useVideoPlayer", true).toBool()) {
return;
}

Expand All @@ -698,6 +709,18 @@ void ZoomWindow::draw()
m_fullScreen->setMovie(m_displayMovie);
}
}
// Videos (using a media player)
else if (m_image->isVideo()) {
QMediaPlaylist *playlist = new QMediaPlaylist(this);
playlist->addMedia(QUrl::fromLocalFile(m_imagePath));
playlist->setPlaybackMode(QMediaPlaylist::CurrentItemInLoop);

m_mediaPlayer->setPlaylist(playlist);
m_stackedWidget->setCurrentWidget(m_videoWidget);
m_mediaPlayer->play();

m_displayImage = QPixmap();
}
// Images
else {
m_displayImage = QPixmap();
Expand Down Expand Up @@ -959,19 +982,25 @@ void ZoomWindow::fullScreen()
return;
}

m_fullScreen = new QAffiche(QVariant(), 0, QColor(), this);
m_fullScreen->setStyleSheet("background-color: black");
m_fullScreen->setAlignment(Qt::AlignCenter);
if (!m_isAnimated.isEmpty()) {
m_fullScreen->setMovie(m_displayMovie);
QWidget *widget;
if (m_image->isVideo()) {
m_videoWidget->setFullScreen(true);
widget = m_videoWidget;
} else {
m_fullScreen->setImage(m_displayImage.scaled(QApplication::desktop()->screenGeometry().size(), Qt::KeepAspectRatio, Qt::SmoothTransformation));
}
m_fullScreen->setWindowFlags(Qt::Window);
m_fullScreen->showFullScreen();
m_fullScreen = new QAffiche(QVariant(), 0, QColor(), this);
m_fullScreen->setStyleSheet("background-color: black");
m_fullScreen->setAlignment(Qt::AlignCenter);
if (!m_isAnimated.isEmpty()) {
m_fullScreen->setMovie(m_displayMovie);
} else {
m_fullScreen->setImage(m_displayImage.scaled(QApplication::desktop()->screenGeometry().size(), Qt::KeepAspectRatio, Qt::SmoothTransformation));
}
m_fullScreen->setWindowFlags(Qt::Window);
m_fullScreen->showFullScreen();

connect(m_fullScreen, SIGNAL(doubleClicked()), this, SLOT(unfullScreen()));
QWidget *widget = m_fullScreen;
connect(m_fullScreen, SIGNAL(doubleClicked()), this, SLOT(unfullScreen()));
widget = m_fullScreen;
}

m_isFullscreen = true;
prepareNextSlide();
Expand All @@ -994,9 +1023,13 @@ void ZoomWindow::unfullScreen()
{
m_slideshow.stop();

m_fullScreen->close();
m_fullScreen->deleteLater();
m_fullScreen = nullptr;
if (m_image->isVideo()) {
m_videoWidget->setFullScreen(false);
} else if (m_fullScreen != nullptr) {
m_fullScreen->close();
m_fullScreen->deleteLater();
m_fullScreen = nullptr;
}

m_isFullscreen = false;
}
Expand All @@ -1017,7 +1050,7 @@ void ZoomWindow::prepareNextSlide()
// We make sure to wait to see the whole displayed item
const qint64 additionalInterval = !m_isAnimated.isEmpty()
? m_displayMovie->nextFrameDelay() * m_displayMovie->frameCount()
: 0;
: (m_image->isVideo() ? m_mediaPlayer->duration() : 0);

const qint64 totalInterval = interval * 1000 + additionalInterval;
m_slideshow.start(totalInterval);
Expand Down Expand Up @@ -1080,7 +1113,7 @@ void ZoomWindow::showThumbnail()
}

// Videos get a static resizable overlay
if (m_image->isVideo()) {
if (m_image->isVideo() && !m_settings->value("Zoom/useVideoPlayer", true).toBool()) {
// A video thumbnail should not be upscaled to more than three times its size
QSize maxSize = QSize(500, 500) * m_settings->value("thumbnailUpscale", 1.0).toDouble();
if (size.width() > maxSize.width() || size.height() > maxSize.height()) {
Expand All @@ -1100,7 +1133,7 @@ void ZoomWindow::showThumbnail()
update(false, true);
}
// Gifs get non-resizable thumbnails
else if (!m_isAnimated.isEmpty()) {
else if (!m_isAnimated.isEmpty() || m_image->isVideo()) {
m_labelImage->setPixmap(m_image->previewImage().scaled(size, Qt::IgnoreAspectRatio, Qt::FastTransformation));
}
// Other images get a resizable thumbnail
Expand Down
4 changes: 4 additions & 0 deletions src/gui/src/viewer/zoom-window.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ namespace Ui


class QAffiche;
class QMediaPlayer;
class QVideoWidget;
class Profile;
class MainWindow;
class DetailsWindow;
Expand Down Expand Up @@ -170,6 +172,8 @@ class ZoomWindow : public QWidget
QPixmap m_displayImage;
QMovie *m_displayMovie;
bool m_labelImageScaled;
QVideoWidget *m_videoWidget;
QMediaPlayer *m_mediaPlayer;

// Threads
QThread m_imageLoaderThread;
Expand Down

0 comments on commit 25d501f

Please sign in to comment.