From 4fb7078815686a639be98790bf52845acc058c46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Lemaire?= Date: Tue, 15 Sep 2015 01:26:05 +0200 Subject: [PATCH] Added rendered picture saving ui --- TODO | 1 + .../modeler/quickapp/MainModelerWindow.cpp | 2 +- .../modeler/quickapp/RenderProcess.cpp | 17 ++++++-- .../modeler/quickapp/RenderProcess.h | 5 +++ .../modeler/quickapp/qml/RenderDialog.qml | 40 +++++++++++++++++++ 5 files changed, 60 insertions(+), 5 deletions(-) diff --git a/TODO b/TODO index 019b19c..c2cbe1a 100644 --- a/TODO +++ b/TODO @@ -5,6 +5,7 @@ Technlology Preview 2 : - Add clouds to OpenGL with 3d textures. - Fix potential holes in land rendering (OpenGL and software). - Fix polygon culling near the camera in low-res renders (automatic tessellation ?). +- Fix OpenGL water renderer sometimes not initializing correctly (value error in OpenGL). Technology Preview 3 : - Alter aerial perspective using estimation of the amount of light left after cloud layers traversal. diff --git a/src/interface/modeler/quickapp/MainModelerWindow.cpp b/src/interface/modeler/quickapp/MainModelerWindow.cpp index b93a975..f6cfd75 100644 --- a/src/interface/modeler/quickapp/MainModelerWindow.cpp +++ b/src/interface/modeler/quickapp/MainModelerWindow.cpp @@ -27,7 +27,7 @@ MainModelerWindow::MainModelerWindow() qmlRegisterType("Paysages", 1, 0, "OpenGLView"); engine()->addImageProvider("renderpreviewprovider", render_preview_provider); - setMinimumSize(QSize(1000, 800)); + setMinimumSize(QSize(1280, 720)); setTitle(QObject::tr("Paysages 3D")); setResizeMode(QQuickView::SizeRootObjectToView); setSource(QUrl("qrc:///main.qml")); diff --git a/src/interface/modeler/quickapp/RenderProcess.cpp b/src/interface/modeler/quickapp/RenderProcess.cpp index c625ea7..a0fff7a 100644 --- a/src/interface/modeler/quickapp/RenderProcess.cpp +++ b/src/interface/modeler/quickapp/RenderProcess.cpp @@ -61,6 +61,11 @@ RenderProcess::RenderProcess(MainModelerWindow *window, RenderPreviewProvider *d connect(button_cancel, SIGNAL(clicked()), this, SLOT(stopRender())); } + QObject *dialog_save = window->findQmlObject("render_save_dialog"); + if (dialog_save) { + connect(dialog_save, SIGNAL(saveRequired(QString)), this, SLOT(savePicture(QString))); + } + startTimer(100); } @@ -93,10 +98,8 @@ void RenderProcess::startRender(Scenery *scenery, const RenderConfig &config) } // Enable "show last render" button - QObject *button_show = window->findQmlObject("tool_render_show"); - if (button_show) { - button_show->setProperty("enabled", true); - } + window->setQmlProperty("tool_render_show", "enabled", true); + window->setQmlProperty("render_dialog", "rendering", true); has_render = true; rendering = true; @@ -169,6 +172,11 @@ void RenderProcess::stopRender() } } +void RenderProcess::savePicture(QString path) +{ + renderer->saveToDisk(path.replace("file://", "").toStdString()); +} + const QSize RenderProcess::getPreviewSize() { if (renderer) @@ -192,6 +200,7 @@ void RenderProcess::timerEvent(QTimerEvent *) delete render_thread; render_thread = NULL; + window->setQmlProperty("render_dialog", "rendering", false); window->getRenderer()->resume(); } diff --git a/src/interface/modeler/quickapp/RenderProcess.h b/src/interface/modeler/quickapp/RenderProcess.h index e5dc0b7..b7d5349 100644 --- a/src/interface/modeler/quickapp/RenderProcess.h +++ b/src/interface/modeler/quickapp/RenderProcess.h @@ -54,6 +54,11 @@ public slots: */ void stopRender(); + /** + * Save the current picture to a given path on disk. + */ + void savePicture(QString path); + protected: virtual void timerEvent(QTimerEvent *event) override; diff --git a/src/interface/modeler/quickapp/qml/RenderDialog.qml b/src/interface/modeler/quickapp/qml/RenderDialog.qml index 5b088bd..d06c769 100644 --- a/src/interface/modeler/quickapp/qml/RenderDialog.qml +++ b/src/interface/modeler/quickapp/qml/RenderDialog.qml @@ -1,11 +1,15 @@ import QtQuick 2.2 import QtQuick.Controls 1.2 +import QtQuick.Dialogs 1.0 import QtGraphicalEffects 1.0 BaseRectangle { + id: render_dialog + objectName: "render_dialog" width: 400 height: 300 color: "#222429" + property bool rendering: false function refresh() { preview_image.source = ""; @@ -20,6 +24,41 @@ BaseRectangle { } } + Rectangle { + width: parent.width + height: 80 + anchors.top: parent.top + anchors.left: parent.left + color: "#667080" + } + + FileDialog { + id: render_save_dialog + objectName: "render_save_dialog" + title: "Choose a file to save the rendered image" + folder: shortcuts.documents + selectExisting: false + + signal saveRequired(string filepath); + + onAccepted: saveRequired(render_save_dialog.fileUrls[0].toString()) + } + + ToolbarButton { + id: render_save + objectName: "render_save" + picture: "images/icon_file_save.png" + anchors.top: parent.top + anchors.left: parent.left + anchors.margins: 10 + enabled: !render_dialog.rendering + checkable: false + image_width: 48 + image_height: 48 + + onClicked: render_save_dialog.open() + } + ToolbarButton { id: render_cancel objectName: "render_cancel" @@ -53,6 +92,7 @@ BaseRectangle { ProgressBar { id: render_progress objectName: "render_progress" + visible: render_dialog.rendering width: parent.width * 0.8 anchors.top: preview_image.bottom anchors.horizontalCenter: preview_image.horizontalCenter