mirror of
https://gitlab.com/kelteseth/ScreenPlay.git
synced 2024-09-02 08:39:49 +02:00
Add ImageSelector
Add project config creation Add more enum states Remove no longer used functions
This commit is contained in:
parent
5f491212de
commit
5c04b3074f
@ -127,7 +127,7 @@ Item {
|
||||
Material.foreground: "white"
|
||||
anchors {
|
||||
right: parent.right
|
||||
rightMargin: 20
|
||||
rightMargin: 10
|
||||
verticalCenter: parent.verticalCenter
|
||||
}
|
||||
|
||||
|
@ -14,6 +14,7 @@ Item {
|
||||
|
||||
property bool conversionFinishedSuccessful: false
|
||||
property bool canSave: false
|
||||
property string filePath
|
||||
onCanSaveChanged: wrapperContent.checkCanSave()
|
||||
signal save
|
||||
|
||||
@ -145,9 +146,9 @@ Item {
|
||||
}
|
||||
}
|
||||
}
|
||||
RowLayout {
|
||||
id: row
|
||||
height: 50
|
||||
ImageSelector {
|
||||
id: previewSelector
|
||||
|
||||
anchors {
|
||||
top: imgWrapper.bottom
|
||||
topMargin: 20
|
||||
@ -155,46 +156,6 @@ Item {
|
||||
rightMargin: 30
|
||||
left: parent.left
|
||||
}
|
||||
|
||||
Rectangle {
|
||||
height: 50
|
||||
color: "#eeeeee"
|
||||
Layout.preferredWidth: imgWrapper.width
|
||||
|
||||
Text {
|
||||
id: txtCustomPreviewPath
|
||||
color: "#333333"
|
||||
|
||||
text: qsTr("Add custom preview image")
|
||||
anchors {
|
||||
verticalCenter: parent.verticalCenter
|
||||
left: parent.left
|
||||
leftMargin: 20
|
||||
}
|
||||
}
|
||||
|
||||
Button {
|
||||
id: button
|
||||
Material.background: Material.Orange
|
||||
Material.foreground: "white"
|
||||
text: qsTr("Choose Image")
|
||||
anchors {
|
||||
right: parent.right
|
||||
rightMargin: 10
|
||||
}
|
||||
onClicked: fileDialogOpenFile.open()
|
||||
}
|
||||
|
||||
FileDialog {
|
||||
id: fileDialogOpenFile
|
||||
nameFilters: []
|
||||
onAccepted: {
|
||||
var file = fileDialogOpenFile.file.toString()
|
||||
|
||||
txtCustomPreviewPath.text = fileDialogOpenFile.file
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Item {
|
||||
@ -290,6 +251,8 @@ Item {
|
||||
screenPlayCreate.saveWallpaper(
|
||||
textFieldName.text,
|
||||
textFieldDescription.text,
|
||||
wrapperContent.filePath,
|
||||
previewSelector.imageSource,
|
||||
textFieldYoutubeURL.text,
|
||||
textFieldTags.getTags())
|
||||
savePopup.open()
|
||||
@ -329,8 +292,10 @@ Item {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/*##^## Designer {
|
||||
D{i:0;autoSize:true;height:480;width:950}
|
||||
}
|
||||
##^##*/
|
||||
|
||||
|
@ -18,8 +18,12 @@ Item {
|
||||
Component.onCompleted: {
|
||||
state = "in"
|
||||
utility.setNavigationActive(false)
|
||||
loader_wrapperContent.source
|
||||
= "qrc:/qml/Create/Wizards/CreateWallpaper/CreateWallpaperVideoImportConvert.qml"
|
||||
|
||||
loader_wrapperContent.setSource(
|
||||
"qrc:/qml/Create/Wizards/CreateWallpaper/CreateWallpaperVideoImportConvert.qml",
|
||||
{
|
||||
"filePath": createNew.filePath
|
||||
})
|
||||
}
|
||||
|
||||
//Blocks some MouseArea from create page
|
||||
@ -30,13 +34,14 @@ Item {
|
||||
Connections {
|
||||
target: screenPlayCreate
|
||||
onCreateWallpaperStateChanged: {
|
||||
if (state === CreateImportVideo.State.AnalyseVideoError
|
||||
|| state === CreateImportVideo.State.ConvertingPreviewVideoError
|
||||
|| state === CreateImportVideo.State.ConvertingPreviewGifError
|
||||
|| state === CreateImportVideo.State.ConvertingPreviewImageError
|
||||
|| state === CreateImportVideo.State.ConvertingAudioError
|
||||
|| state === CreateImportVideo.State.AbortCleanupError
|
||||
|| state === CreateImportVideo.State.ErrorUnknown) {
|
||||
if (state === CreateImportVideo.State.AnalyseVideoError || state
|
||||
=== CreateImportVideo.State.ConvertingPreviewGifError || state
|
||||
=== CreateImportVideo.State.ConvertingPreviewImageError || state
|
||||
=== CreateImportVideo.State.ConvertingAudioError || state
|
||||
=== CreateImportVideo.State.AbortCleanupError || state
|
||||
=== CreateImportVideo.State.CopyFilesError || state
|
||||
=== CreateImportVideo.State.CreateProjectFileError || state
|
||||
=== CreateImportVideo.State.CreateTmpFolderError) {
|
||||
createNew.state = "result"
|
||||
}
|
||||
}
|
||||
@ -88,7 +93,7 @@ Item {
|
||||
z: 10
|
||||
Connections {
|
||||
target: loader_wrapperContent.sourceComponent
|
||||
onSave:{
|
||||
onSave: {
|
||||
createNew.state = "result"
|
||||
}
|
||||
}
|
||||
|
@ -2,7 +2,10 @@ import QtQuick 2.12
|
||||
import QtQuick.Controls 2.2
|
||||
import QtQuick.Controls.Material 2.2
|
||||
|
||||
import "../Common"
|
||||
|
||||
Item {
|
||||
id: screen
|
||||
anchors.fill: parent
|
||||
|
||||
}
|
||||
|
@ -12,44 +12,6 @@ Create::Create(Settings* st, QMLUtilities* util, QObject* parent)
|
||||
qmlRegisterType<CreateImportVideo>("net.aimber.create", 1, 0, "CreateImportVideo");
|
||||
}
|
||||
|
||||
void Create::copyProject(QString relativeProjectPath, QString toPath)
|
||||
{
|
||||
if (toPath.contains("file:///")) {
|
||||
toPath.remove("file:///");
|
||||
}
|
||||
QString srcFilePath = m_settings->getScreenPlayBasePath().toString() + relativeProjectPath;
|
||||
|
||||
// Todo: UI Error handling
|
||||
if (copyRecursively(srcFilePath, toPath)) {
|
||||
emit m_utils->openFolderInExplorer(toPath);
|
||||
}
|
||||
}
|
||||
|
||||
bool Create::copyRecursively(const QString& srcFilePath, const QString& tgtFilePath)
|
||||
{
|
||||
QFileInfo srcFileInfo(srcFilePath);
|
||||
if (srcFileInfo.isDir()) {
|
||||
QDir targetDir(tgtFilePath);
|
||||
targetDir.cdUp();
|
||||
QDir sourceDir(srcFilePath);
|
||||
QStringList fileNames = sourceDir.entryList(QDir::Files | QDir::Dirs | QDir::NoDotAndDotDot | QDir::Hidden | QDir::System);
|
||||
Q_FOREACH (const QString& fileName, fileNames) {
|
||||
const QString newSrcFilePath
|
||||
= srcFilePath + QLatin1Char('/') + fileName;
|
||||
const QString newTgtFilePath
|
||||
= tgtFilePath + QLatin1Char('/') + fileName;
|
||||
if (!copyRecursively(newSrcFilePath, newTgtFilePath)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (!QFile::copy(srcFilePath, tgtFilePath)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void Create::createWallpaperStart(QString videoPath)
|
||||
{
|
||||
videoPath.remove("file:///");
|
||||
@ -67,11 +29,12 @@ void Create::createWallpaperStart(QString videoPath)
|
||||
}
|
||||
setWorkingDir(dir.path() + "/" + folderName);
|
||||
|
||||
m_createImportVideoThread = new QThread;
|
||||
m_createImportVideoThread = new QThread();
|
||||
m_createImportVideo = new CreateImportVideo(videoPath, workingDir());
|
||||
|
||||
connect(m_createImportVideo, &CreateImportVideo::createWallpaperStateChanged, this, &Create::createWallpaperStateChanged);
|
||||
connect(m_createImportVideoThread, &QThread::started, m_createImportVideo, &CreateImportVideo::process);
|
||||
connect(m_createImportVideo, &CreateImportVideo::canceled, this, &Create::abortAndCleanup);
|
||||
connect(m_createImportVideo, &CreateImportVideo::finished, m_createImportVideoThread, &QThread::quit);
|
||||
connect(m_createImportVideo, &CreateImportVideo::finished, m_createImportVideo, &QObject::deleteLater);
|
||||
connect(m_createImportVideoThread, &QThread::finished, m_createImportVideoThread, &QObject::deleteLater);
|
||||
@ -80,18 +43,38 @@ void Create::createWallpaperStart(QString videoPath)
|
||||
m_createImportVideoThread->start();
|
||||
}
|
||||
|
||||
void Create::saveWallpaper(QString title, QString description, QString youtube, QVector<QString> tags)
|
||||
void Create::saveWallpaper(QString title, QString description, QString filePath, QString previewImagePath, QString youtube, QVector<QString> tags)
|
||||
{
|
||||
qDebug() << tags;
|
||||
filePath.remove("file:///");
|
||||
previewImagePath.remove("file:///");
|
||||
|
||||
emit createWallpaperStateChanged(CreateImportVideo::State::CopyFiles);
|
||||
|
||||
QFileInfo previewImageFile(previewImagePath);
|
||||
if (!QFile::copy(previewImagePath, m_workingDir + "/" + previewImageFile.fileName())) {
|
||||
qDebug() << "Could not copy" << previewImagePath << " to " << m_workingDir + "/" + previewImageFile.fileName();
|
||||
emit createWallpaperStateChanged(CreateImportVideo::State::CopyFilesError);
|
||||
return;
|
||||
}
|
||||
|
||||
QFileInfo filePathFile(filePath);
|
||||
if (!QFile::copy(filePath, m_workingDir + "/" + filePathFile.fileName())) {
|
||||
qDebug() << "Could not copy" << filePath << " to " << m_workingDir + "/" + filePathFile.fileName();
|
||||
emit createWallpaperStateChanged(CreateImportVideo::State::CopyFilesError);
|
||||
return;
|
||||
}
|
||||
emit createWallpaperStateChanged(CreateImportVideo::State::CopyFilesFinished);
|
||||
emit createWallpaperStateChanged(CreateImportVideo::State::CreateProjectFile);
|
||||
QFile file(m_workingDir + "/project.json");
|
||||
|
||||
QJsonObject obj;
|
||||
obj.insert("description", description);
|
||||
obj.insert("title", title);
|
||||
obj.insert("youtube", youtube);
|
||||
obj.insert("file", "video.webm");
|
||||
obj.insert("previewGIF", "preview.gif");
|
||||
obj.insert("previewWEBM", "preview.webm");
|
||||
obj.insert("previewWEBM", filePathFile.fileName());
|
||||
obj.insert("preview", previewImageFile.fileName());
|
||||
obj.insert("type", "video");
|
||||
|
||||
QJsonArray arr;
|
||||
@ -102,6 +85,7 @@ void Create::saveWallpaper(QString title, QString description, QString youtube,
|
||||
|
||||
if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
|
||||
qDebug() << "Could not open /project.json";
|
||||
emit createWallpaperStateChanged(CreateImportVideo::State::CreateProjectFileError);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -111,6 +95,7 @@ void Create::saveWallpaper(QString title, QString description, QString youtube,
|
||||
out << doc.toJson();
|
||||
|
||||
file.close();
|
||||
emit createWallpaperStateChanged(CreateImportVideo::State::CreateProjectFileFinished);
|
||||
}
|
||||
|
||||
void Create::abortAndCleanup()
|
||||
@ -120,6 +105,9 @@ void Create::abortAndCleanup()
|
||||
return;
|
||||
}
|
||||
|
||||
disconnect(m_createImportVideo);
|
||||
disconnect(m_createImportVideoThread);
|
||||
|
||||
// Save to export path before aborting to be able to cleanup the tmp folder
|
||||
QString tmpExportPath = m_createImportVideo->m_exportPath;
|
||||
|
||||
|
@ -55,10 +55,8 @@ signals:
|
||||
void workingDirChanged(QString workingDir);
|
||||
|
||||
public slots:
|
||||
void copyProject(QString relativeProjectPath, QString toPath);
|
||||
bool copyRecursively(const QString& srcFilePath, const QString& tgtFilePath);
|
||||
void createWallpaperStart(QString videoPath);
|
||||
void saveWallpaper(QString title, QString description, QString youtube, QVector<QString> tags);
|
||||
void saveWallpaper(QString title, QString description, QString filePath, QString previewImagePath, QString youtube, QVector<QString> tags);
|
||||
void abortAndCleanup();
|
||||
|
||||
void setProgress(float progress)
|
||||
|
@ -1,4 +1,5 @@
|
||||
#include "createimportvideo.h"
|
||||
#include <QScopeGuard>
|
||||
|
||||
CreateImportVideo::CreateImportVideo(QObject* parent)
|
||||
: QObject(parent)
|
||||
@ -15,13 +16,26 @@ CreateImportVideo::CreateImportVideo(QString videoPath, QString exportPath, QObj
|
||||
void CreateImportVideo::process()
|
||||
{
|
||||
qDebug() << "start converting video in thread: " << QThread::currentThreadId();
|
||||
createWallpaperInfo();
|
||||
createWallpaperVideoPreview();
|
||||
createWallpaperGifPreview();
|
||||
extractWallpaperAudio();
|
||||
emit createWallpaperStateChanged(CreateImportVideo::State::Finished);
|
||||
|
||||
emit finished();
|
||||
auto cleanup = qScopeGuard([this] {
|
||||
qDebug() << "ABORT";
|
||||
this->requestInterruption();
|
||||
emit canceled();
|
||||
});
|
||||
|
||||
if (!createWallpaperInfo())
|
||||
return;
|
||||
|
||||
if (!createWallpaperVideoPreview())
|
||||
return;
|
||||
|
||||
if (!createWallpaperGifPreview())
|
||||
return;
|
||||
|
||||
if (!extractWallpaperAudio())
|
||||
return;
|
||||
|
||||
emit createWallpaperStateChanged(CreateImportVideo::State::Finished);
|
||||
}
|
||||
|
||||
bool CreateImportVideo::createWallpaperInfo()
|
||||
@ -345,32 +359,4 @@ bool CreateImportVideo::extractWallpaperAudio()
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CreateImportVideo::createWallpaperProjectFile(const QString title, const QString description)
|
||||
{
|
||||
//Copy Project File
|
||||
QFile configFile(m_exportPath + "/project.json");
|
||||
|
||||
if (!configFile.open(QIODevice::ReadWrite | QIODevice::Text)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
QTextStream out(&configFile);
|
||||
QJsonObject configObj;
|
||||
|
||||
configObj.insert("description", description);
|
||||
configObj.insert("title", title);
|
||||
|
||||
configObj.insert("file", "video.webm");
|
||||
configObj.insert("preview", "preview.png");
|
||||
configObj.insert("previewGIF", "preview.gif");
|
||||
configObj.insert("previewWebM", "preview.webm");
|
||||
configObj.insert("type", "video");
|
||||
|
||||
QJsonDocument configJsonDocument(configObj);
|
||||
out << configJsonDocument.toJson();
|
||||
configFile.close();
|
||||
|
||||
emit createWallpaperStateChanged(CreateImportVideo::State::Finished);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -44,14 +44,18 @@ public:
|
||||
// ConvertingVideo,
|
||||
// ConvertingVideoFinished,
|
||||
// ConvertingVideoError,
|
||||
CopyFiles,
|
||||
CopyFilesFinished,
|
||||
CopyFilesError,
|
||||
CreateProjectFile,
|
||||
CreateProjectFileFinished,
|
||||
CreateProjectFileError,
|
||||
AbortCleanupError,
|
||||
CreateTmpFolderError,
|
||||
Finished,
|
||||
ErrorUnknown,
|
||||
};
|
||||
Q_ENUM(State)
|
||||
|
||||
QProcess m_process;
|
||||
QString m_videoPath;
|
||||
QString m_exportPath;
|
||||
int m_length = 0;
|
||||
@ -61,17 +65,15 @@ signals:
|
||||
void createWallpaperStateChanged(CreateImportVideo::State state);
|
||||
void processOutput(QString text);
|
||||
void finished();
|
||||
void canceled();
|
||||
|
||||
public slots:
|
||||
void process();
|
||||
void requestInterruption()
|
||||
{
|
||||
}
|
||||
void requestInterruption() {}
|
||||
|
||||
bool createWallpaperInfo();
|
||||
bool createWallpaperVideoPreview();
|
||||
bool createWallpaperGifPreview();
|
||||
bool createWallpaperImagePreview();
|
||||
bool extractWallpaperAudio();
|
||||
bool createWallpaperProjectFile(const QString title, const QString description);
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user