Canvas preview widget is immediately sized (so that render dialog don't resize later)

This commit is contained in:
Michaël Lemaire 2014-08-20 14:23:35 +02:00
parent 2b135eedac
commit 8ef8b0386c
8 changed files with 42 additions and 47 deletions

View file

@ -10,7 +10,6 @@ WidgetPreviewCanvas::WidgetPreviewCanvas(QWidget *parent) :
QWidget(parent), canvas(NULL) QWidget(parent), canvas(NULL)
{ {
pixbuf = new QImage(); pixbuf = new QImage();
inited = false;
startTimer(500); startTimer(500);
} }
@ -21,8 +20,12 @@ WidgetPreviewCanvas::~WidgetPreviewCanvas()
} }
void WidgetPreviewCanvas::setCanvas(const Canvas *canvas) void WidgetPreviewCanvas::setCanvas(const Canvas *canvas)
{
if (not this->canvas)
{ {
this->canvas = canvas; this->canvas = canvas;
canvas->getPreview()->initLive(this);
}
} }
void WidgetPreviewCanvas::paintEvent(QPaintEvent *) void WidgetPreviewCanvas::paintEvent(QPaintEvent *)
@ -58,12 +61,6 @@ void WidgetPreviewCanvas::timerEvent(QTimerEvent *)
{ {
if (canvas) if (canvas)
{ {
if (!inited)
{
canvas->getPreview()->initLive(this);
inited = true;
}
canvas->getPreview()->updateLive(this); canvas->getPreview()->updateLive(this);
update(); update();
} }

View file

@ -21,6 +21,8 @@ public:
/*! /*!
* \brief Set the canvas to watch and display, null to stop watching. * \brief Set the canvas to watch and display, null to stop watching.
*
* This function must be called from the graphics thread.
*/ */
void setCanvas(const Canvas *canvas); void setCanvas(const Canvas *canvas);
@ -35,7 +37,6 @@ protected:
private: private:
QImage* pixbuf; QImage* pixbuf;
const Canvas *canvas; const Canvas *canvas;
bool inited;
}; };
} }

View file

@ -247,16 +247,16 @@ void FreeFormHelper::processExploreClicked()
void FreeFormHelper::processRenderClicked() void FreeFormHelper::processRenderClicked()
{ {
RenderConfig params(400, 300, 1, 3);
SoftwareCanvasRenderer renderer; SoftwareCanvasRenderer renderer;
renderer.setConfig(params);
renderer.setScenery(DesktopScenery::getCurrent()); renderer.setScenery(DesktopScenery::getCurrent());
emit needAlterRenderer(&renderer); emit needAlterRenderer(&renderer);
DialogRender* dialog = new DialogRender(_form_widget, &renderer); DialogRender dialog(_form_widget, &renderer);
RenderConfig params(400, 300, 1, 3); dialog.startRender();
dialog->startRender(params);
delete dialog;
} }
void FreeFormHelper::processDecimalChange(double value) void FreeFormHelper::processDecimalChange(double value)

View file

@ -18,7 +18,6 @@
#include <QComboBox> #include <QComboBox>
#include "tools.h" #include "tools.h"
#include "RenderConfig.h"
#include "Scenery.h" #include "Scenery.h"
#include "ColorProfile.h" #include "ColorProfile.h"
#include "SoftwareCanvasRenderer.h" #include "SoftwareCanvasRenderer.h"
@ -27,22 +26,19 @@
class RenderThread:public QThread class RenderThread:public QThread
{ {
public: public:
RenderThread(DialogRender* dialog, SoftwareCanvasRenderer* renderer, const RenderConfig &params):QThread() RenderThread(DialogRender* dialog, SoftwareCanvasRenderer* renderer):QThread()
{ {
_dialog = dialog; _dialog = dialog;
_renderer = renderer; _renderer = renderer;
_params = params;
} }
void run() void run()
{ {
// FIXME Pass config to render
_renderer->render(); _renderer->render();
_dialog->tellRenderEnded(); _dialog->tellRenderEnded();
} }
private: private:
DialogRender* _dialog; DialogRender* _dialog;
SoftwareCanvasRenderer* _renderer; SoftwareCanvasRenderer* _renderer;
RenderConfig _params;
}; };
DialogRender::DialogRender(QWidget *parent, SoftwareCanvasRenderer* renderer): DialogRender::DialogRender(QWidget *parent, SoftwareCanvasRenderer* renderer):
@ -98,7 +94,6 @@ DialogRender::DialogRender(QWidget *parent, SoftwareCanvasRenderer* renderer):
_actions->layout()->addWidget(_save_button); _actions->layout()->addWidget(_save_button);
// Connections // Connections
//connect(this, SIGNAL(renderSizeChanged(int, int)), this, SLOT(applyRenderSize(int, int)));
connect(this, SIGNAL(progressChanged(double)), this, SLOT(applyProgress(double))); connect(this, SIGNAL(progressChanged(double)), this, SLOT(applyProgress(double)));
connect(this, SIGNAL(renderEnded()), this, SLOT(applyRenderEnded())); connect(this, SIGNAL(renderEnded()), this, SLOT(applyRenderEnded()));
connect(_save_button, SIGNAL(clicked()), this, SLOT(saveRender())); connect(_save_button, SIGNAL(clicked()), this, SLOT(saveRender()));
@ -119,11 +114,6 @@ DialogRender::~DialogRender()
delete pixbuf_lock; delete pixbuf_lock;
} }
void DialogRender::tellRenderSize(int width, int height)
{
emit renderSizeChanged(width, height);
}
void DialogRender::tellProgressChange(double value) void DialogRender::tellProgressChange(double value)
{ {
emit progressChanged(value); emit progressChanged(value);
@ -134,13 +124,11 @@ void DialogRender::tellRenderEnded()
emit renderEnded(); emit renderEnded();
} }
void DialogRender::startRender(const RenderConfig &params) void DialogRender::startRender()
{ {
_started = time(NULL); _started = time(NULL);
canvas_renderer->setSize(params.width, params.height, params.antialias); _render_thread = new RenderThread(this, canvas_renderer);
_render_thread = new RenderThread(this, canvas_renderer, params);
_render_thread->start(); _render_thread->start();
exec(); exec();

View file

@ -21,10 +21,9 @@ public:
explicit DialogRender(QWidget *parent, SoftwareCanvasRenderer* renderer); explicit DialogRender(QWidget *parent, SoftwareCanvasRenderer* renderer);
~DialogRender(); ~DialogRender();
void tellRenderSize(int width, int height);
void tellProgressChange(double value); void tellProgressChange(double value);
void tellRenderEnded(); void tellRenderEnded();
void startRender(const RenderConfig &params); void startRender();
void loadLastRender(); void loadLastRender();
QImage* pixbuf; QImage* pixbuf;
@ -37,7 +36,6 @@ private slots:
void toneMappingChanged(); void toneMappingChanged();
signals: signals:
void renderSizeChanged(int width, int height);
void progressChanged(double value); void progressChanged(double value);
void renderEnded(); void renderEnded();

View file

@ -103,15 +103,16 @@ void FormRender::startQuickRender()
{ {
delete _renderer; delete _renderer;
} }
RenderConfig config(400, 300, 1, 3);
_renderer = new SoftwareCanvasRenderer(); _renderer = new SoftwareCanvasRenderer();
_renderer->setScenery(DesktopScenery::getCurrent()); _renderer->setScenery(DesktopScenery::getCurrent());
_renderer->setConfig(config);
_renderer_inited = true; _renderer_inited = true;
DialogRender* dialog = new DialogRender(this, _renderer); DialogRender dialog(this, _renderer);
RenderConfig params(400, 300, 1, 3); dialog.startRender();
dialog->startRender(params);
delete dialog;
} }
void FormRender::startRender() void FormRender::startRender()
@ -122,21 +123,18 @@ void FormRender::startRender()
} }
_renderer = new SoftwareCanvasRenderer(); _renderer = new SoftwareCanvasRenderer();
_renderer->setScenery(DesktopScenery::getCurrent()); _renderer->setScenery(DesktopScenery::getCurrent());
_renderer->setConfig(_params);
_renderer_inited = true; _renderer_inited = true;
DialogRender* dialog = new DialogRender(this, _renderer); DialogRender dialog(this, _renderer);
dialog->startRender(_params); dialog.startRender();
delete dialog;
} }
void FormRender::showRender() void FormRender::showRender()
{ {
if (_renderer_inited) if (_renderer_inited)
{ {
DialogRender* dialog = new DialogRender(this, _renderer); DialogRender dialog(this, _renderer);
dialog->loadLastRender(); dialog.loadLastRender();
delete dialog;
} }
} }

View file

@ -10,6 +10,7 @@
#include "ParallelWork.h" #include "ParallelWork.h"
#include "CanvasPortion.h" #include "CanvasPortion.h"
#include "CanvasPixelShader.h" #include "CanvasPixelShader.h"
#include "RenderConfig.h"
SoftwareCanvasRenderer::SoftwareCanvasRenderer() SoftwareCanvasRenderer::SoftwareCanvasRenderer()
{ {
@ -34,6 +35,15 @@ SoftwareCanvasRenderer::~SoftwareCanvasRenderer()
} }
} }
void SoftwareCanvasRenderer::setConfig(const RenderConfig &config)
{
if (not started)
{
setSize(config.width, config.height, config.antialias);
render_quality = config.quality;
}
}
void SoftwareCanvasRenderer::setSize(int width, int height, int samples) void SoftwareCanvasRenderer::setSize(int width, int height, int samples)
{ {
if (not started) if (not started)
@ -44,9 +54,7 @@ void SoftwareCanvasRenderer::setSize(int width, int height, int samples)
void SoftwareCanvasRenderer::render() void SoftwareCanvasRenderer::render()
{ {
// TEMP
started = true; started = true;
render_quality = 3;
render_camera->setRenderSize(canvas->getWidth(), canvas->getHeight()); render_camera->setRenderSize(canvas->getWidth(), canvas->getHeight());

View file

@ -24,6 +24,11 @@ public:
inline const Canvas *getCanvas() const {return canvas;} inline const Canvas *getCanvas() const {return canvas;}
/**
* Set the renderer configuration.
*/
void setConfig(const RenderConfig &config);
/** /**
* @brief Set the rendering size in pixels. * @brief Set the rendering size in pixels.
* *