1
0
mirror of https://gitlab.com/kelteseth/ScreenPlay.git synced 2024-11-07 03:22:33 +01:00

Videos working again!

This commit is contained in:
kelteseth 2017-07-10 15:09:43 +02:00
parent 831030cf89
commit 2ead9670ff
13 changed files with 167 additions and 96 deletions

View File

@ -12,7 +12,8 @@ SOURCES += main.cpp \
src/packagefilehandler.cpp \ src/packagefilehandler.cpp \
src/wallpaper.cpp \ src/wallpaper.cpp \
src/profilelistmodel.cpp \ src/profilelistmodel.cpp \
src/profile.cpp src/profile.cpp \
src/projectfile.cpp
RESOURCES += qml.qrc RESOURCES += qml.qrc
@ -25,7 +26,8 @@ HEADERS += \
src/packagefilehandler.h \ src/packagefilehandler.h \
src/wallpaper.h \ src/wallpaper.h \
src/profilelistmodel.h \ src/profilelistmodel.h \
src/profile.h src/profile.h \
src/projectfile.h
INCLUDEPATH += \ INCLUDEPATH += \
$$PWD/ThirdParty/ \ $$PWD/ThirdParty/ \

View File

@ -1,26 +1,29 @@
import QtQuick 2.0 import QtQuick 2.7
//import QtAV 1.07 import QtAV 1.07
Rectangle { Rectangle {
color: "orange" color: "gray"
visible: true
Video {
id: video
anchors.fill: parent
videoCodecPriority: ["CUDA", "D3D11", "DXVA", "VAAPI", "FFmpeg"]
onPlaybackStateChanged: {
}
Component.onCompleted: {
video.source = Qt.resolvedUrl("file:///" + wallpaper.absoluteFilePath.toString())
video.play()
}
onStopped: {
video.play()
}
// height: parent.height }
// width: parent.width
// Connections {
// target: installedListModel
// onSetScreenToVideo:{
// installedListModel.setScreenVisibleFromQml(true)
// video.stop()
// video.source = absolutePath;
// video.play();
// }
// }
// Video {
// id: video
// anchors.fill: parent
// }
} }

View File

@ -18,13 +18,13 @@ QVariant InstalledListModel::data(const QModelIndex& index, int role) const
if (index.row() < rowCount()) if (index.row() < rowCount())
switch (role) { switch (role) {
case TitleRole: case TitleRole:
return m_screenPlayFiles.at(index.row())._title; return m_screenPlayFiles.at(index.row()).m_title;
case PreviewRole: case PreviewRole:
return m_screenPlayFiles.at(index.row())._preview; return m_screenPlayFiles.at(index.row()).m_preview;
case FolderIdRole: case FolderIdRole:
return m_screenPlayFiles.at(index.row())._folderId; return m_screenPlayFiles.at(index.row()).m_folderId;
case FileIdRole: case FileIdRole:
return m_screenPlayFiles.at(index.row())._file; return m_screenPlayFiles.at(index.row()).m_file;
default: default:
return QVariant(); return QVariant();
} }
@ -42,13 +42,24 @@ QHash<int, QByteArray> InstalledListModel::roleNames() const
return roles; return roles;
} }
bool InstalledListModel::getProjectByName(QString profileName, ProjectFile *spf)
{
for (int i = 0; i < m_screenPlayFiles.size(); i++) {
if (m_screenPlayFiles.at(i).m_folderId == profileName) {
*spf = m_screenPlayFiles.at(i);
return true;
}
}
return false;
}
void InstalledListModel::append(const QJsonObject obj, const QString folderName) void InstalledListModel::append(const QJsonObject obj, const QString folderName)
{ {
int row = 0; int row = 0;
beginInsertRows(QModelIndex(), row, row); beginInsertRows(QModelIndex(), row, row);
ScreenPlayFile tmpFile(obj, folderName); ProjectFile tmpFile(obj, folderName);
m_screenPlayFiles.append(tmpFile); m_screenPlayFiles.append(tmpFile);
endInsertRows(); endInsertRows();
@ -89,39 +100,14 @@ QVariantMap InstalledListModel::get(QString folderId)
for (int i = 0; i < m_screenPlayFiles.count(); i++) { for (int i = 0; i < m_screenPlayFiles.count(); i++) {
if (m_screenPlayFiles[i]._folderId == folderId) { if (m_screenPlayFiles[i].m_folderId == folderId) {
map.insert("screenTitle", m_screenPlayFiles[i]._title); map.insert("screenTitle", m_screenPlayFiles[i].m_title);
map.insert("screenPreview", m_screenPlayFiles[i]._preview); map.insert("screenPreview", m_screenPlayFiles[i].m_preview);
map.insert("screenFile", m_screenPlayFiles[i]._file); map.insert("screenFile", m_screenPlayFiles[i].m_file);
} }
} }
return map; return map;
} }
void InstalledListModel::setScreenVisibleFromQml(bool visible)
{
emit setScreenVisible(visible);
}
void InstalledListModel::setScreenToVideoFromQml(QString absolutePath)
{
emit setScreenToVideo(absolutePath);
}
ScreenPlayFile::ScreenPlayFile(QJsonObject obj, QString folderName)
{
if (obj.contains("description"))
_description = obj.value("description");
if (obj.contains("file"))
_file = obj.value("file");
if (obj.contains("preview"))
_preview = obj.value("preview");
if (obj.contains("title"))
_title = obj.value("title");
_folderId = folderName;
}

View File

@ -15,8 +15,10 @@
#include <QString> #include <QString>
#include <QUrl> #include <QUrl>
#include <QtConcurrent/QtConcurrent> #include <QtConcurrent/QtConcurrent>
#include "profilelistmodel.h"
#include "projectfile.h"
class ScreenPlayFile;
class InstalledListModel : public QAbstractListModel { class InstalledListModel : public QAbstractListModel {
Q_OBJECT Q_OBJECT
@ -29,12 +31,13 @@ public:
QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override; QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
void append(const QJsonObject, const QString); void append(const QJsonObject, const QString);
QHash<int, QByteArray> roleNames() const override; QHash<int, QByteArray> roleNames() const override;
bool getProjectByName(QString profileName, ProjectFile* spf);
Q_INVOKABLE void loadScreens(); Q_INVOKABLE void loadScreens();
Q_INVOKABLE QVariantMap get(QString folderId); Q_INVOKABLE QVariantMap get(QString folderId);
Q_INVOKABLE void setScreenVisibleFromQml(bool visible);
Q_INVOKABLE void setScreenToVideoFromQml(QString absolutePath);
Q_PROPERTY(QUrl absoluteStoragePath READ absoluteStoragePath WRITE setabsoluteStoragePath NOTIFY absoluteStoragePathChanged) Q_PROPERTY(QUrl absoluteStoragePath READ absoluteStoragePath WRITE setabsoluteStoragePath NOTIFY absoluteStoragePathChanged)
enum InstalledRole { enum InstalledRole {
TitleRole, TitleRole,
PreviewRole, PreviewRole,
@ -66,24 +69,8 @@ signals:
void absoluteStoragePathChanged(QUrl absoluteStoragePath); void absoluteStoragePathChanged(QUrl absoluteStoragePath);
private: private:
QList<ScreenPlayFile> m_screenPlayFiles; QList<ProjectFile> m_screenPlayFiles;
QUrl m_absoluteStoragePath; QUrl m_absoluteStoragePath;
}; };
class ScreenPlayFile {
public:
ScreenPlayFile();
ScreenPlayFile(QJsonObject obj, QString folderName);
QVariant _description;
QVariant _file;
QVariant _preview;
QVariant _title;
QString _folderId;
QUrl _absolutePath;
QVariantList _tags; //TODO: Implement me!
};
#endif // INSTALLEDLISTMODEL_H #endif // INSTALLEDLISTMODEL_H

View File

@ -6,6 +6,7 @@ MonitorListModel::MonitorListModel(QObject *parent)
loadMonitors(); loadMonitors();
} }
QHash<int, QByteArray> MonitorListModel::roleNames() const QHash<int, QByteArray> MonitorListModel::roleNames() const
{ {
static const QHash<int, QByteArray> roles{ static const QHash<int, QByteArray> roles{

View File

@ -94,6 +94,8 @@ void ProfileListModel::loadProfiles()
if (profileObj.contains("isLooping")) if (profileObj.contains("isLooping"))
tmpProfile.m_isLooping = profileObj.value("isLooping").toBool(); tmpProfile.m_isLooping = profileObj.value("isLooping").toBool();
tmpProfile.m_absolutePath = m_absoluteStoragePath;
m_profileList.append(tmpProfile); m_profileList.append(tmpProfile);
} }

View File

@ -24,6 +24,7 @@ public:
NumberRole = Qt::UserRole + 2 NumberRole = Qt::UserRole + 2
}; };
int rowCount(const QModelIndex& parent = QModelIndex()) const override; int rowCount(const QModelIndex& parent = QModelIndex()) const override;
QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override; QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
virtual QHash<int, QByteArray> roleNames() const override; virtual QHash<int, QByteArray> roleNames() const override;

22
src/projectfile.cpp Normal file
View File

@ -0,0 +1,22 @@
#include "projectfile.h"
ProjectFile::ProjectFile()
{
}
ProjectFile::ProjectFile(QJsonObject obj, QString folderName)
{
if (obj.contains("description"))
m_description = obj.value("description");
if (obj.contains("file"))
m_file = obj.value("file");
if (obj.contains("preview"))
m_preview = obj.value("preview");
if (obj.contains("title"))
m_title = obj.value("title");
m_folderId = folderName;
}

25
src/projectfile.h Normal file
View File

@ -0,0 +1,25 @@
#ifndef PROJECTFILE_H
#define PROJECTFILE_H
#include <QJsonObject>
#include <QUrl>
#include <QVariant>
#include <QVariantList>
class ProjectFile
{
public:
ProjectFile();
ProjectFile(QJsonObject obj, QString folderName);
QVariant m_description;
QVariant m_file;
QVariant m_preview;
QVariant m_title;
QString m_folderId;
QUrl m_absolutePath;
QVariantList m_tags; //TODO: Implement me!
};
#endif // PROJECTFILE_H

View File

@ -8,7 +8,6 @@ Settings::Settings(ProfileListModel* plm, MonitorListModel* mlm, InstalledListMo
m_mlm = mlm; m_mlm = mlm;
m_ilm = ilm; m_ilm = ilm;
QFile configTmp; QFile configTmp;
QString appConfigLocation = QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation); QString appConfigLocation = QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation);
@ -27,7 +26,6 @@ Settings::Settings(ProfileListModel* plm, MonitorListModel* mlm, InstalledListMo
createDefaultConfig(); createDefaultConfig();
} }
QJsonDocument configJsonDocument; QJsonDocument configJsonDocument;
QJsonParseError parseError; QJsonParseError parseError;
QJsonObject configObj; QJsonObject configObj;
@ -55,8 +53,7 @@ Settings::Settings(ProfileListModel* plm, MonitorListModel* mlm, InstalledListMo
return; return;
} }
if (QString(configObj.value("absoluteStoragePath").toString()).isEmpty()) {
if(QString(configObj.value("absoluteStoragePath").toString()).isEmpty()){
m_absoluteStoragePath = appConfigLocation; m_absoluteStoragePath = appConfigLocation;
} else { } else {
m_absoluteStoragePath = configObj.value("absoluteStoragePath").toString(); m_absoluteStoragePath = configObj.value("absoluteStoragePath").toString();
@ -65,7 +62,6 @@ Settings::Settings(ProfileListModel* plm, MonitorListModel* mlm, InstalledListMo
m_ilm->setabsoluteStoragePath(m_absoluteStoragePath); m_ilm->setabsoluteStoragePath(m_absoluteStoragePath);
m_plm->m_absoluteStoragePath = m_absoluteStoragePath; m_plm->m_absoluteStoragePath = m_absoluteStoragePath;
//Create default folders //Create default folders
if (!QDir(m_absoluteStoragePath.toString() + "/ProfilePackages").exists()) { if (!QDir(m_absoluteStoragePath.toString() + "/ProfilePackages").exists()) {
if (!QDir().mkdir(appConfigLocation + "/ProfilePackages")) { if (!QDir().mkdir(appConfigLocation + "/ProfilePackages")) {
@ -96,16 +92,19 @@ Settings::Settings(ProfileListModel* plm, MonitorListModel* mlm, InstalledListMo
m_highPriorityStart = configObj.value("highPriorityStart").toBool(); m_highPriorityStart = configObj.value("highPriorityStart").toBool();
m_sendStatistics = configObj.value("sendStatistics").toBool(); m_sendStatistics = configObj.value("sendStatistics").toBool();
m_renderer = static_cast<Renderer>(configObj.value("renderer-value").toInt()); m_renderer = static_cast<Renderer>(configObj.value("renderer-value").toInt());
}
Settings::~Settings()
{
} }
void Settings::createNewProfile(int screenNumber) void Settings::createNewProfile(int screenNumber)
{ {
} }
void Settings::constructWallpaper(Profile profile, QString monitorID) void Settings::constructWallpaper(Profile profile, QString monitorID, ProjectFile pf)
{ {
m_wallpapers.append(QSharedPointer<Wallpaper>(new Wallpaper(profile))); m_wallpapers.append(QSharedPointer<Wallpaper>(new Wallpaper(profile,pf)));
} }
void Settings::loadActiveProfiles() void Settings::loadActiveProfiles()
@ -129,15 +128,27 @@ void Settings::loadActiveProfiles()
QString profileName = activeProfilesTmp.at(i).toObject().value("profile").toString(); QString profileName = activeProfilesTmp.at(i).toObject().value("profile").toString();
QString monitorID = activeProfilesTmp.at(i).toObject().value("monitorID").toString(); QString monitorID = activeProfilesTmp.at(i).toObject().value("monitorID").toString();
Profile profile; Profile profile;
ProjectFile spf;
if (!m_plm->getProfileByName(profileName, &profile)) if (!m_plm->getProfileByName(profileName, &profile))
continue; continue;
if (!m_ilm->getProjectByName(profile.m_wallpaperId, &spf))
continue;
constructWallpaper(profile, monitorID);
constructWallpaper(profile, monitorID, spf);
} }
} }
} }
void Settings::removeAll()
{
qDebug() << "destruct settings";
m_wallpapers.clear();
}
void Settings::createDefaultConfig() void Settings::createDefaultConfig()
{ {

View File

@ -7,7 +7,8 @@
#include <QJsonArray> #include <QJsonArray>
#include <QJsonDocument> #include <QJsonDocument>
#include <QJsonObject> #include <QJsonObject>
#include <QObject > #include <QObject>
#include <QThread>
#include <QPair> #include <QPair>
#include <QQmlPropertyMap> #include <QQmlPropertyMap>
#include <QStandardPaths> #include <QStandardPaths>
@ -18,6 +19,7 @@
#include <QVector> #include <QVector>
#include <QSharedPointer> #include <QSharedPointer>
#include "monitorlistmodel.h" #include "monitorlistmodel.h"
#include "installedlistmodel.h" #include "installedlistmodel.h"
#include "profilelistmodel.h" #include "profilelistmodel.h"
@ -30,7 +32,7 @@ class Settings : public QObject {
Q_OBJECT Q_OBJECT
public: public:
explicit Settings(ProfileListModel* plm, MonitorListModel* mlm, InstalledListModel* ilm, QObject* parent = nullptr); explicit Settings(ProfileListModel* plm, MonitorListModel* mlm, InstalledListModel* ilm, QObject* parent = nullptr);
~Settings();
Q_PROPERTY(bool autostart READ autostart WRITE setAutostart NOTIFY autostartChanged) Q_PROPERTY(bool autostart READ autostart WRITE setAutostart NOTIFY autostartChanged)
Q_PROPERTY(bool highPriorityStart READ highPriorityStart WRITE setHighPriorityStart NOTIFY highPriorityStartChanged) Q_PROPERTY(bool highPriorityStart READ highPriorityStart WRITE setHighPriorityStart NOTIFY highPriorityStartChanged)
Q_PROPERTY(Renderer renderer READ renderer WRITE setRenderer NOTIFY rendererChanged) Q_PROPERTY(Renderer renderer READ renderer WRITE setRenderer NOTIFY rendererChanged)
@ -38,8 +40,9 @@ public:
Q_PROPERTY(Version version READ version) Q_PROPERTY(Version version READ version)
Q_INVOKABLE void createNewProfile(int screenNumber); Q_INVOKABLE void createNewProfile(int screenNumber);
Q_INVOKABLE void constructWallpaper(Profile profile, QString monitorID); Q_INVOKABLE void constructWallpaper(Profile profile, QString monitorID, ProjectFile spf);
void loadActiveProfiles(); void loadActiveProfiles();
void removeAll();
enum Renderer { enum Renderer {
@ -151,6 +154,7 @@ private:
ProfileListModel* m_plm; ProfileListModel* m_plm;
InstalledListModel* m_ilm; InstalledListModel* m_ilm;
MonitorListModel* m_mlm; MonitorListModel* m_mlm;
QThread m_thread;
QVector<QSharedPointer<Wallpaper>> m_wallpapers; QVector<QSharedPointer<Wallpaper>> m_wallpapers;
QVector<QSharedPointer<ActiveProfiles>> m_activeProfiles; QVector<QSharedPointer<ActiveProfiles>> m_activeProfiles;

View File

@ -18,17 +18,21 @@ Wallpaper::Wallpaper(QWindow* parent)
{ {
} }
Wallpaper::Wallpaper(Profile profile) Wallpaper::Wallpaper(Profile profile, ProjectFile projf)
{ {
m_profile = profile; m_profile = profile;
m_project = projf;
QString tmp = profile.m_absolutePath.toString() + "/Wallpaper/" + profile.m_wallpaperId + "/" + projf.m_file.toString();
tmp.replace("/","\\\\");
setAbsoluteFilePath(tmp);
this->setX(m_profile.m_rect.x()); this->setX(m_profile.m_rect.x());
this->setY(m_profile.m_rect.y()); this->setY(m_profile.m_rect.y());
this->setWidth(m_profile.m_rect.width()); this->setWidth(m_profile.m_rect.width());
this->setHeight(m_profile.m_rect.height()); this->setHeight(m_profile.m_rect.height());
this->m_hwnd = (HWND)this->winId(); this->m_hwnd = (HWND)this->winId();
HWND progman_hwnd = FindWindowW(L"Progman", L"Program Manager"); HWND progman_hwnd = FindWindowW(L"Progman", L"Program Manager");
// Spawn new worker window below desktop (using some undocumented Win32 magic) // Spawn new worker window below desktop (using some undocumented Win32 magic)
@ -55,9 +59,9 @@ Wallpaper::Wallpaper(Profile profile)
m_quickRenderer = new QQuickView(this); m_quickRenderer = new QQuickView(this);
m_quickRenderer->setWidth(this->width()); m_quickRenderer->setWidth(this->width());
m_quickRenderer->setHeight(this->height()); m_quickRenderer->setHeight(this->height());
m_context = m_quickRenderer->rootContext();
m_context->setContextProperty("wallpaper", this);
m_quickRenderer->setResizeMode(QQuickView::ResizeMode::SizeRootObjectToView); m_quickRenderer->setResizeMode(QQuickView::ResizeMode::SizeRootObjectToView);
m_quickRenderer->setSource(QUrl("qrc:/qml/Components/Screens/ScreenVideo.qml")); m_quickRenderer->setSource(QUrl("qrc:/qml/Components/Screens/ScreenVideo.qml"));
m_context = m_quickRenderer->rootContext();
m_quickRenderer->show(); m_quickRenderer->show();
} }
}

View File

@ -8,25 +8,48 @@
#include <QWindow> #include <QWindow>
#include <qt_windows.h> #include <qt_windows.h>
#include <QUrl> #include <QUrl>
#include <QDir>
#include "profile.h" #include "profile.h"
#include "projectfile.h"
class Wallpaper : public QWindow { class Wallpaper : public QWindow {
Q_OBJECT Q_OBJECT
public: public:
explicit Wallpaper(QWindow* parent = 0); explicit Wallpaper(QWindow* parent = 0);
Wallpaper(Profile profile); Wallpaper(Profile profile, ProjectFile projf);
~Wallpaper(); Q_PROPERTY(QString absoluteFilePath READ absoluteFilePath WRITE setAbsoluteFilePath NOTIFY absoluteFilePathChanged)
QQmlContext* context() const;
QString absoluteFilePath() const
{
return m_absoluteFilePath;
}
public slots:
void setAbsoluteFilePath(QString absoluteFilePath)
{
if (m_absoluteFilePath == absoluteFilePath)
return;
m_absoluteFilePath = absoluteFilePath;
emit absoluteFilePathChanged(m_absoluteFilePath);
}
signals:
void absoluteFilePathChanged(QString absoluteFilePath);
private: private:
HWND m_hwnd = nullptr; HWND m_hwnd;
HWND m_worker_hwnd = nullptr; HWND m_worker_hwnd;
QQuickView* m_quickRenderer = nullptr; QQuickView* m_quickRenderer = nullptr;
QQmlContext* m_context = nullptr; QQmlContext* m_context = nullptr;
Profile m_profile; Profile m_profile;
ProjectFile m_project;
QString m_absoluteFilePath;
}; };
#endif // WALLPAPER_H #endif // WALLPAPER_H