diff options
-rw-r--r-- | src/Viewer/Qt3DViewer/main.cpp | 44 | ||||
-rw-r--r-- | src/Viewer/Qt3DViewer/mainwindow.cpp | 53 | ||||
-rw-r--r-- | src/Viewer/Qt3DViewer/mainwindow.h | 2 | ||||
-rw-r--r-- | src/Viewer/studio3d/q3dsimagesequencegenerator_p.h | 2 | ||||
-rw-r--r-- | src/Viewer/studio3d/q3dsimagesequencegeneratorthread.cpp | 26 | ||||
-rw-r--r-- | src/Viewer/studio3d/q3dsimagesequencegeneratorthread_p.h | 2 |
6 files changed, 101 insertions, 28 deletions
diff --git a/src/Viewer/Qt3DViewer/main.cpp b/src/Viewer/Qt3DViewer/main.cpp index 0c672c2c..4eee9f3e 100644 --- a/src/Viewer/Qt3DViewer/main.cpp +++ b/src/Viewer/Qt3DViewer/main.cpp @@ -68,30 +68,51 @@ int main(int argc, char *argv[]) QCoreApplication::translate("main", "[file]")); parser.addOption({"sequence", - QCoreApplication::translate("main", "Generates an image sequence without showing the UI. The file argument must be specified. Specifying any of the seq-* arguments implies setting this option.")}); + QCoreApplication::translate("main", + "Generates an image sequence.\n" + "The file argument must be specified.\n""" + "Specifying any of the seq-* arguments\n" + "implies setting this option.")}); parser.addOption({"seq-start", - QCoreApplication::translate("main", "Start time of the sequence in milliseconds. The default value is 0."), + QCoreApplication::translate("main", + "Start time of the sequence in milliseconds.\n" + "The default value is 0."), QCoreApplication::translate("main", "ms"), QString::number(0)}); parser.addOption({"seq-end", - QCoreApplication::translate("main", "End time of the sequence in milliseconds. The default value is 10000."), + QCoreApplication::translate("main", + "End time of the sequence in milliseconds.\n" + "The default value is 10000."), QCoreApplication::translate("main", "ms"), QString::number(1000)}); parser.addOption({"seq-fps", - QCoreApplication::translate("main", "Frames per second for the sequence. The default value is 60."), + QCoreApplication::translate("main", + "Frames per second for the sequence.\n" + "The default value is 60."), QCoreApplication::translate("main", "fps"), QString::number(60)}); parser.addOption({"seq-interval", - QCoreApplication::translate("main", "Time interval between frames in the sequence in milliseconds. The seq-fps argument is ignored if this argument is used."), + QCoreApplication::translate("main", + "Time interval between frames in the sequence\n" + "in milliseconds. The seq-fps argument is ignored\n" + "if this argument is used."), QCoreApplication::translate("main", "ms"), QString::number(0)}); parser.addOption({"seq-width", - QCoreApplication::translate("main", "Width of the image sequence. The default value is 1920."), + QCoreApplication::translate("main", + "Width of the image sequence.\n" + "The default value is 1920."), QCoreApplication::translate("main", "pixels"), QString::number(1920)}); parser.addOption({"seq-height", - QCoreApplication::translate("main", "Height of the image sequence. The default value is 1080."), + QCoreApplication::translate("main", + "Height of the image sequence.\n" + "The default value is 1080."), QCoreApplication::translate("main", "pixels"), QString::number(1080)}); parser.addOption({"seq-outpath", - QCoreApplication::translate("main", "Output path of the image sequence. The default value is the current directory."), + QCoreApplication::translate("main", + "Output path of the image sequence.\n" + "The default value is the current directory."), QCoreApplication::translate("main", "path"), QStringLiteral(".")}); parser.addOption({"seq-outfile", - QCoreApplication::translate("main", "Output filename base for the image sequence. The default value is derived from the presentation filename."), + QCoreApplication::translate("main", + "Output filename base for the image sequence.\n" + "The default value is derived from the presentation filename."), QCoreApplication::translate("main", "file"), QStringLiteral("")}); parser.process(a); @@ -110,7 +131,6 @@ int main(int argc, char *argv[]) Q3DSImageSequenceGenerator *generator = nullptr; MainWindow w(generateSequence); - w.show(); if (generateSequence) { if (files.count() != 1) { @@ -120,6 +140,9 @@ int main(int argc, char *argv[]) generator = new Q3DSImageSequenceGenerator; QObject::connect(generator, &Q3DSImageSequenceGenerator::progress, &w, &MainWindow::generatorProgress); + QObject::connect(generator, &Q3DSImageSequenceGenerator::finished, + &w, &MainWindow::generatorFinished); + w.setGeneratorDetails(files.first()); generator->generateImageSequence( files.first(), parser.value("seq-start").toDouble(), @@ -134,6 +157,7 @@ int main(int argc, char *argv[]) w.loadFile(files.first()); } + w.show(); #ifndef Q_OS_ANDROID QFile styleFile(":/style.qss"); #else diff --git a/src/Viewer/Qt3DViewer/mainwindow.cpp b/src/Viewer/Qt3DViewer/mainwindow.cpp index e73a1f94..c9a43663 100644 --- a/src/Viewer/Qt3DViewer/mainwindow.cpp +++ b/src/Viewer/Qt3DViewer/mainwindow.cpp @@ -93,7 +93,7 @@ MainWindow::MainWindow(bool generatorMode, QWidget *parent) } else { ui->menuBar->clear(); ui->menuBar->addAction(ui->actionQuit); - resize(500, 100); + resize(700, 100); } // Set import paths so that standalone installation works @@ -397,13 +397,33 @@ void MainWindow::setupGeneratorUI() QByteArray qml = "import QtQuick 2.7\n" "import QtQuick.Controls 2.2\n" - "Label {\n" - " color: \"White\"\n" - " horizontalAlignment: Text.AlignHCenter\n" - " verticalAlignment: Text.AlignVCenter\n" + "Item {\n" + " property alias mainText: mainLabel.text\n" + " property alias detailsText: detailsLabel.text\n" " anchors.fill: parent\n" - " font.pixelSize: width / 30\n" - " text: \"Image sequence generation initializing...\"\n" + " Label {\n" + " id: mainLabel\n" + " color: \"White\"\n" + " horizontalAlignment: Text.AlignHCenter\n" + " verticalAlignment: Text.AlignVCenter\n" + " anchors.top: parent.top\n" + " anchors.left: parent.left\n" + " anchors.right: parent.right\n" + " height: parent.height / 2\n" + " font.pixelSize: width / 40\n" + " text: \"Image sequence generation initializing...\"\n" + " }\n" + " Label {\n" + " id: detailsLabel\n" + " color: \"White\"\n" + " horizontalAlignment: Text.AlignHCenter\n" + " verticalAlignment: Text.AlignTop\n" + " anchors.top: mainLabel.bottom\n" + " anchors.left: parent.left\n" + " anchors.right: parent.right\n" + " height: parent.height / 2\n" + " font.pixelSize: width / 50\n" + " }\n" "}"; QQmlComponent component(engine); @@ -553,7 +573,19 @@ void MainWindow::generatorProgress(int totalFrames, int frameCount) QCoreApplication::translate("main", "Image sequence generation progress: %1 / %2") .arg(frameCount).arg(totalFrames); } - m_generatorInfo->setProperty("text", progressString); + m_generatorInfo->setProperty("mainText", progressString); +} + +void MainWindow::generatorFinished(bool success, const QString &details) +{ + if (success) { + m_generatorInfo->setProperty("detailsText", details); + } else { + QString mainString = + QCoreApplication::translate("main", "Image sequence generation failed:"); + m_generatorInfo->setProperty("mainText", mainString); + m_generatorInfo->setProperty("detailsText", details); + } } void MainWindow::updateProgress(int percent) @@ -568,3 +600,8 @@ void MainWindow::updateProgress(int percent) m_connectionInfo->setProperty("text", progress); updateUI(true); } + +void MainWindow::setGeneratorDetails(const QString &filename) +{ + m_generatorInfo->setProperty("detailsText", filename); +} diff --git a/src/Viewer/Qt3DViewer/mainwindow.h b/src/Viewer/Qt3DViewer/mainwindow.h index e14036c7..beba8f81 100644 --- a/src/Viewer/Qt3DViewer/mainwindow.h +++ b/src/Viewer/Qt3DViewer/mainwindow.h @@ -55,6 +55,7 @@ public: void loadFile(const QString &filename); void loadProject(const QByteArray &data); void updateProgress(int percent); + void setGeneratorDetails(const QString &filename); protected: void dragEnterEvent(QDragEnterEvent *event) override; @@ -74,6 +75,7 @@ private: public Q_SLOTS: void generatorProgress(int totalFrames, int frameCount); + void generatorFinished(bool success, const QString &details); private Q_SLOTS: void on_actionToggle_Scale_Mode_triggered(); diff --git a/src/Viewer/studio3d/q3dsimagesequencegenerator_p.h b/src/Viewer/studio3d/q3dsimagesequencegenerator_p.h index fed94e26..97a72d2e 100644 --- a/src/Viewer/studio3d/q3dsimagesequencegenerator_p.h +++ b/src/Viewer/studio3d/q3dsimagesequencegenerator_p.h @@ -58,7 +58,7 @@ public: const QString &outPath, const QString &outFile); Q_SIGNALS: void progress(int totalFrames, int frameNumber); - void finished(bool success); + void finished(bool success, const QString &details); }; QT_END_NAMESPACE diff --git a/src/Viewer/studio3d/q3dsimagesequencegeneratorthread.cpp b/src/Viewer/studio3d/q3dsimagesequencegeneratorthread.cpp index b3fa8ae5..e5410aa1 100644 --- a/src/Viewer/studio3d/q3dsimagesequencegeneratorthread.cpp +++ b/src/Viewer/studio3d/q3dsimagesequencegeneratorthread.cpp @@ -36,6 +36,8 @@ #include <QtGui/qopenglfunctions.h> #include <QtGui/qoffscreensurface.h> #include <QtGui/qopenglframebufferobject.h> +#include <QtCore/qfileinfo.h> +#include <QtCore/qdir.h> bool Q3DSImageSequenceGeneratorThread::initialize( const QString &presentation, qreal start, qreal end, qreal fps, qreal frameInterval, @@ -93,8 +95,9 @@ Q3DSImageSequenceGeneratorThread::~Q3DSImageSequenceGeneratorThread() { void Q3DSImageSequenceGeneratorThread::run() { if (!m_context->makeCurrent(m_surface)) { - qWarning("Generating image sequence failed - Couldn't make context current"); - Q_EMIT generationFinished(false); + QString error = QObject::tr("Couldn't make context current."); + qWarning() << "Generating image sequence failed -" << error; + Q_EMIT generationFinished(false, error); cleanup(); return; } @@ -111,8 +114,9 @@ void Q3DSImageSequenceGeneratorThread::run() { viewer.setSize(size); if (!viewer.initialize(m_surface, m_context, fbo.handle())) { - qWarning("Generating image sequence failed - Viewer initialization failed."); - Q_EMIT generationFinished(false); + QString error = QObject::tr("Viewer initialization failed."); + qWarning() << "Generating image sequence failed -" << error; + Q_EMIT generationFinished(false, error); cleanup(); return; } @@ -131,6 +135,11 @@ void Q3DSImageSequenceGeneratorThread::run() { // Add a bit of time to the end time to ensure we don't lose the last frame to rounding errors m_end += m_frameInterval / 10000.0; + // Ensure directory exists + QFileInfo fi(m_outputFileName); + QDir dir = fi.absoluteDir(); + dir.mkpath("."); + int frameCount = 0; int totalFrames = qCeil((m_end - m_start) / m_frameInterval); for (qreal t = m_start; t <= m_end; t += m_frameInterval) { @@ -138,16 +147,17 @@ void Q3DSImageSequenceGeneratorThread::run() { viewer.presentation()->setGlobalAnimationTime(qRound64(t)); viewer.update(); if (!fbo.toImage().save(m_outputFileName.arg(frameCount))) { - qWarning().nospace() << "Generating image sequence failed - Failed to write file: '" - << m_outputFileName.arg(frameCount) << "'"; - Q_EMIT generationFinished(false); + QString error = QObject::tr("Failed to write output file: '%1'") + .arg(m_outputFileName.arg(frameCount)); + qWarning() << "Generating image sequence failed -" << error; + Q_EMIT generationFinished(false, error); cleanup(); return; } Q_EMIT progress(totalFrames, frameCount); } - Q_EMIT generationFinished(true); + Q_EMIT generationFinished(true, m_outputFileName.arg("*")); cleanup(); } diff --git a/src/Viewer/studio3d/q3dsimagesequencegeneratorthread_p.h b/src/Viewer/studio3d/q3dsimagesequencegeneratorthread_p.h index 18de5d67..dc0ae847 100644 --- a/src/Viewer/studio3d/q3dsimagesequencegeneratorthread_p.h +++ b/src/Viewer/studio3d/q3dsimagesequencegeneratorthread_p.h @@ -62,7 +62,7 @@ public: Q_SIGNALS: void progress(int totalFrames, int frameNumber); - void generationFinished(bool success); + void generationFinished(bool success, const QString &details); protected: void run() override; |