From e84698dbb30d6ca5ca5d24597b3e737648977909 Mon Sep 17 00:00:00 2001 From: Michael Lemaire Date: Thu, 23 Jul 2015 00:28:27 +0200 Subject: [PATCH] Added shortcut to show previous render again --- .../modeler/quickapp/MainModelerWindow.cpp | 33 +++++++++----- .../modeler/quickapp/MainModelerWindow.h | 4 +- .../modeler/quickapp/RenderProcess.cpp | 43 ++++++++++++++++--- .../modeler/quickapp/RenderProcess.h | 19 ++++++++ .../modeler/quickapp/qml/ToolbarButton.qml | 2 + src/interface/modeler/quickapp/qml/main.qml | 22 ++++++++++ 6 files changed, 106 insertions(+), 17 deletions(-) diff --git a/src/interface/modeler/quickapp/MainModelerWindow.cpp b/src/interface/modeler/quickapp/MainModelerWindow.cpp index 2d15232..924f13d 100644 --- a/src/interface/modeler/quickapp/MainModelerWindow.cpp +++ b/src/interface/modeler/quickapp/MainModelerWindow.cpp @@ -20,7 +20,6 @@ MainModelerWindow::MainModelerWindow() renderer = new OpenGLRenderer(scenery); render_preview_provider = new RenderPreviewProvider(); - render_process = new RenderProcess(this, render_preview_provider); qmlRegisterType("Paysages", 1, 0, "OpenGLView"); engine()->addImageProvider("renderpreviewprovider", render_preview_provider); @@ -33,6 +32,8 @@ MainModelerWindow::MainModelerWindow() cameras = new ModelerCameras(this); atmosphere = new AtmosphereModeler(this); water = new WaterModeler(this); + + render_process = new RenderProcess(this, render_preview_provider); } MainModelerWindow::~MainModelerWindow() @@ -53,6 +54,20 @@ QObject *MainModelerWindow::findQmlObject(const QString &objectName) return rootObject()->findChild(objectName); } +void MainModelerWindow::setQmlProperty(const QString &objectName, const QString &propertyName, const QVariant &value) +{ + QObject *item = findQmlObject(objectName); + if (item) + { + item->setProperty(propertyName.toLocal8Bit(), value); + } +} + +void MainModelerWindow::setState(const QString &stateName) +{ + rootObject()->setProperty("state", stateName); +} + void MainModelerWindow::keyReleaseEvent(QKeyEvent *event) { if (event->key() == Qt::Key_F5) @@ -60,20 +75,16 @@ void MainModelerWindow::keyReleaseEvent(QKeyEvent *event) // Start render in a thread if (event->modifiers() & Qt::ControlModifier) { - render_process->startRender(scenery, RenderConfig(1920, 1080, 4, 8)); + render_process->startFinalRender(); } else { - render_process->startRender(scenery, RenderConfig(400, 300, 1, 3)); + render_process->startQuickRender(); } - - // Resize preview - QSize preview_size = render_process->getPreviewSize(); - findQmlObject("preview_image")->setProperty("width", preview_size.width()); - findQmlObject("preview_image")->setProperty("height", preview_size.height()); - - // Show render dialog - rootObject()->setProperty("state", QString("Render Dialog")); + } + else if (event->key() == Qt::Key_F6) + { + render_process->showPreviousRender(); } else if (event->key() == Qt::Key_Escape) { diff --git a/src/interface/modeler/quickapp/MainModelerWindow.h b/src/interface/modeler/quickapp/MainModelerWindow.h index da676d9..7ce00ac 100644 --- a/src/interface/modeler/quickapp/MainModelerWindow.h +++ b/src/interface/modeler/quickapp/MainModelerWindow.h @@ -15,7 +15,9 @@ public: MainModelerWindow(); virtual ~MainModelerWindow(); - QObject *findQmlObject(const QString& objectName); + QObject *findQmlObject(const QString &objectName); + void setQmlProperty(const QString &objectName, const QString &propertyName, const QVariant &value); + void setState(const QString &stateName); inline Scenery *getScenery() const {return scenery;} inline OpenGLRenderer *getRenderer() const {return renderer;} diff --git a/src/interface/modeler/quickapp/RenderProcess.cpp b/src/interface/modeler/quickapp/RenderProcess.cpp index d0c0c0f..a8e687a 100644 --- a/src/interface/modeler/quickapp/RenderProcess.cpp +++ b/src/interface/modeler/quickapp/RenderProcess.cpp @@ -26,10 +26,16 @@ private: RenderProcess::RenderProcess(MainModelerWindow *window, RenderPreviewProvider *destination): window(window), destination(destination) { + has_render = false; rendering = false; renderer = NULL; render_thread = NULL; + QObject *button_quick = window->findQmlObject("tool_render_quick"); + if (button_quick) { + connect(button_quick, SIGNAL(clicked()), this, SLOT(startQuickRender())); + } + startTimer(100); } @@ -61,6 +67,7 @@ void RenderProcess::startRender(Scenery *scenery, const RenderConfig &config) return; } + has_render = true; rendering = true; if (renderer) @@ -74,8 +81,38 @@ void RenderProcess::startRender(Scenery *scenery, const RenderConfig &config) destination->setCanvas(renderer->getCanvas()); + // Resize preview + QSize preview_size = getPreviewSize(); + QObject *image = window->findQmlObject("preview_image"); + if (image) { + image->setProperty("width", preview_size.width()); + image->setProperty("height", preview_size.height()); + } + + // Start render thread render_thread = new RenderThread(renderer); render_thread->start(); + + // Show render dialog + window->setState("Render Dialog"); +} + +void RenderProcess::startQuickRender() +{ + startRender(window->getScenery(), RenderConfig(400, 300, 1, 3)); +} + +void RenderProcess::startFinalRender() +{ + startRender(window->getScenery(), RenderConfig(1920, 1080, 4, 8)); +} + +void RenderProcess::showPreviousRender() +{ + if (not rendering and has_render) + { + window->setState("Render Dialog"); + } } void RenderProcess::stopRender() @@ -112,10 +149,6 @@ void RenderProcess::timerEvent(QTimerEvent *) if (renderer) { - QObject *progress = window->findQmlObject("render_progress"); - if (progress) - { - progress->setProperty("value", renderer->getProgress()); - } + window->setQmlProperty("render_progress", "value", renderer->getProgress()); } } diff --git a/src/interface/modeler/quickapp/RenderProcess.h b/src/interface/modeler/quickapp/RenderProcess.h index cbb916a..32829a0 100644 --- a/src/interface/modeler/quickapp/RenderProcess.h +++ b/src/interface/modeler/quickapp/RenderProcess.h @@ -31,12 +31,31 @@ public: */ const QSize getPreviewSize(); + inline bool isRendering() const {return rendering;} + +public slots: + /** + * Start a quick render. + */ + void startQuickRender(); + + /** + * Start a final render. + */ + void startFinalRender(); + + /** + * Show the previous rendering. + */ + void showPreviousRender(); + protected: virtual void timerEvent(QTimerEvent *event) override; private: MainModelerWindow *window; RenderPreviewProvider *destination; + bool has_render; bool rendering; SoftwareCanvasRenderer *renderer; Thread *render_thread; diff --git a/src/interface/modeler/quickapp/qml/ToolbarButton.qml b/src/interface/modeler/quickapp/qml/ToolbarButton.qml index 727c408..ab7719f 100644 --- a/src/interface/modeler/quickapp/qml/ToolbarButton.qml +++ b/src/interface/modeler/quickapp/qml/ToolbarButton.qml @@ -7,6 +7,7 @@ Item { property bool hovered: false property string helptext property string hovertext + signal clicked width: image.width + 10 height: image.height + 10 @@ -82,6 +83,7 @@ Item { { tooltip_widget.helptext = ""; } + parent.clicked(); } } } diff --git a/src/interface/modeler/quickapp/qml/main.qml b/src/interface/modeler/quickapp/qml/main.qml index bc18a73..1bc2b03 100644 --- a/src/interface/modeler/quickapp/qml/main.qml +++ b/src/interface/modeler/quickapp/qml/main.qml @@ -91,6 +91,19 @@ OpenGLView { } } + Toolbar { + id: render_toolbar + opacity: 0 + anchors.left: primary_toolbar.right + + ToolbarButton { + id: tool_render_quick + objectName: "tool_render_quick" + picture: "images/tab_render.png" + hovertext: qsTr("Start a quick render") + } + } + CameraChoice { id: camera_choice anchors.bottom: main_ui.bottom @@ -140,6 +153,15 @@ OpenGLView { opacity: 1 } }, + State { + name: "Render Mode" + when: tool_render.selected + + PropertyChanges { + target: render_toolbar + opacity: 1 + } + }, State { name: "Render Dialog" when: tool_display.selected