paysages3d/src/interface/modeler/quickapp/MainModelerWindow.cpp

161 lines
4.1 KiB
C++
Raw Normal View History

2014-08-28 08:29:12 +00:00
#include "MainModelerWindow.h"
#include "Logs.h"
2014-08-28 08:29:12 +00:00
#include "OpenGLView.h"
#include "Scenery.h"
#include "OpenGLRenderer.h"
2014-08-28 13:09:47 +00:00
#include "AtmosphereModeler.h"
#include "WaterModeler.h"
#include "ModelerCameras.h"
2014-09-09 15:56:52 +00:00
#include "RenderPreviewProvider.h"
#include "RenderProcess.h"
#include "RenderConfig.h"
#include "DiffManager.h"
2014-09-09 15:56:52 +00:00
#include <QQmlEngine>
2015-07-22 16:05:24 +00:00
#include <QGuiApplication>
2014-08-28 08:29:12 +00:00
MainModelerWindow::MainModelerWindow()
{
2015-08-18 20:29:18 +00:00
scenery = new Scenery();
scenery->autoPreset();
2015-08-18 20:29:18 +00:00
renderer = new OpenGLRenderer(scenery);
2014-08-28 08:29:12 +00:00
2014-09-09 15:56:52 +00:00
render_preview_provider = new RenderPreviewProvider();
2014-08-28 08:29:12 +00:00
qmlRegisterType<OpenGLView>("Paysages", 1, 0, "OpenGLView");
2014-09-09 15:56:52 +00:00
engine()->addImageProvider("renderpreviewprovider", render_preview_provider);
2014-08-28 08:29:12 +00:00
2014-09-09 15:56:52 +00:00
setMinimumSize(QSize(1000, 800));
2014-08-28 08:29:12 +00:00
setTitle(QObject::tr("Paysages 3D"));
setResizeMode(QQuickView::SizeRootObjectToView);
setSource(QUrl("qrc:///main.qml"));
2014-08-28 13:09:47 +00:00
cameras = new ModelerCameras(this);
2014-08-28 13:09:47 +00:00
atmosphere = new AtmosphereModeler(this);
water = new WaterModeler(this);
render_process = new RenderProcess(this, render_preview_provider);
2014-08-28 08:29:12 +00:00
}
MainModelerWindow::~MainModelerWindow()
{
2014-08-28 13:09:47 +00:00
delete atmosphere;
delete water;
delete cameras;
2014-08-28 13:09:47 +00:00
2014-09-09 15:56:52 +00:00
delete render_preview_provider;
delete render_process;
2014-08-28 08:29:12 +00:00
delete renderer;
2015-08-18 20:47:18 +00:00
delete scenery;
2014-08-28 08:29:12 +00:00
}
2014-08-28 13:09:47 +00:00
QObject *MainModelerWindow::findQmlObject(const QString &objectName)
{
return rootObject()->findChild<QObject *>(objectName);
}
2014-09-09 15:56:52 +00:00
void MainModelerWindow::setQmlProperty(const QString &objectName, const QString &propertyName, const QVariant &value)
{
QObject *item = findQmlObject(objectName);
if (item)
{
item->setProperty(propertyName.toLocal8Bit(), value);
}
}
QString MainModelerWindow::getState() const
{
return rootObject()->property("state").toString();
}
void MainModelerWindow::setState(const QString &stateName)
{
rootObject()->setProperty("state", stateName);
}
2014-09-09 15:56:52 +00:00
void MainModelerWindow::keyReleaseEvent(QKeyEvent *event)
{
if (getState() == "Render Dialog")
2014-09-09 15:56:52 +00:00
{
if (event->key() == Qt::Key_Escape)
2015-07-22 17:23:22 +00:00
{
render_process->stopRender();
2014-09-09 15:56:52 +00:00
setState("Init");
2015-07-22 16:05:24 +00:00
}
}
else
{
if (event->key() == Qt::Key_F5)
{
// Start render in a thread
if (event->modifiers() & Qt::ControlModifier)
{
render_process->startFinalRender();
}
else
{
render_process->startQuickRender();
}
}
else if (event->key() == Qt::Key_F6)
{
render_process->showPreviousRender();
}
else if (event->key() == Qt::Key_Q)
{
if (event->modifiers() & Qt::ControlModifier)
{
QGuiApplication::instance()->exit();
}
}
else if (event->key() == Qt::Key_N)
{
if (event->modifiers() & Qt::ControlModifier)
{
getScenery()->autoPreset();
renderer->reset();
}
}
else if (event->key() == Qt::Key_S)
{
if (event->modifiers() & Qt::ControlModifier)
{
getScenery()->saveGlobal("saved.p3d");
}
}
else if (event->key() == Qt::Key_L or event->key() == Qt::Key_O)
{
if (event->modifiers() & Qt::ControlModifier)
{
getScenery()->loadGlobal("saved.p3d");
renderer->reset();
}
}
else if (event->key() == Qt::Key_Z)
{
if (event->modifiers() & Qt::ControlModifier)
{
if (event->modifiers() & Qt::ShiftModifier)
{
getScenery()->getDiffManager()->redo();
}
else
{
getScenery()->getDiffManager()->undo();
}
}
}
else if (event->key() == Qt::Key_Y)
{
if (event->modifiers() & Qt::ControlModifier)
{
getScenery()->getDiffManager()->undo();
}
}
}
2014-09-09 15:56:52 +00:00
}