paysages: Qt GUI (WIP)

git-svn-id: https://subversion.assembla.com/svn/thunderk/paysages@217 b1fd45b6-86a6-48da-8261-f70d1f35bdcc
This commit is contained in:
Michaël Lemaire 2012-01-06 16:09:03 +00:00 committed by ThunderK
parent 4a155ba5d5
commit a5bc77e798
20 changed files with 321 additions and 33 deletions

View file

@ -1,6 +1,7 @@
#include "baseform.h"
#include "inputdouble.h"
#include "inputint.h"
#include "inputcolor.h"
#include <QVBoxLayout>
@ -11,8 +12,8 @@
BaseForm::BaseForm(QWidget* parent) :
QWidget(parent)
{
QPushButton* button;
QWidget* hwidget;
QWidget* buttons;
QVBoxLayout* vlayout;
QHBoxLayout* hlayout;
@ -28,6 +29,7 @@ BaseForm::BaseForm(QWidget* parent) :
form->setLayout(new QGridLayout());
buttons = new QWidget(this);
buttons->setLayout(new QHBoxLayout());
hlayout->addWidget(previews);
hlayout->addWidget(form);
@ -36,6 +38,11 @@ BaseForm::BaseForm(QWidget* parent) :
hwidget->setLayout(hlayout);
this->setLayout(vlayout);
button = addButton("Apply");
connect(button, SIGNAL(clicked()), this, SLOT(applyConfig()));
button = addButton("Revert");
connect(button, SIGNAL(clicked()), this, SLOT(revertConfig()));
}
void BaseForm::applyConfigPreview()
@ -49,22 +56,34 @@ void BaseForm::applyConfigPreview()
void BaseForm::revertConfig()
{
QList<InputDouble*> list_doubles = form->findChildren<InputDouble*>("_form_doubleslider_");
for (int i = 0; i < list_doubles.size(); i++)
QList<BaseInput*> inputs = form->findChildren<BaseInput*>("_form_input_");
for (int i = 0; i < inputs.size(); i++)
{
list_doubles[i]->revert();
inputs[i]->revert();
}
BaseForm::applyConfigPreview();
}
void BaseForm::applyConfig()
{
}
void BaseForm::addPreview(Preview* preview, QString label)
{
previews->layout()->addWidget(new QLabel(label, previews));
previews->layout()->addWidget(preview);
preview->setObjectName("_form_preview_");
}
QPushButton* BaseForm::addButton(QString label)
{
QPushButton* button = new QPushButton(label);
buttons->layout()->addWidget(button);
return button;
}
void BaseForm::addInput(BaseInput* input)
{
QGridLayout* layout = (QGridLayout*)form->layout();
@ -75,6 +94,13 @@ void BaseForm::addInput(BaseInput* input)
layout->addWidget(input->control(), row, 2);
connect(input, SIGNAL(valueChanged()), this, SLOT(applyConfigPreview()));
input->setObjectName("_form_input_");
}
void BaseForm::addInputInt(QString label, int* value, int min, int max, int small_step, int large_step)
{
addInput(new InputInt(form, label, value, min, max, small_step, large_step));
}
void BaseForm::addInputDouble(QString label, double* value, double min, double max, double small_step, double large_step)

View file

@ -1,7 +1,8 @@
#ifndef _GUI_QT_BASEFORM_H_
#define _GUI_QT_BASEFORM_H_
#ifndef _PAYSAGES_QT_BASEFORM_H_
#define _PAYSAGES_QT_BASEFORM_H_
#include <QWidget>
#include <QPushButton>
#include "preview.h"
#include "baseinput.h"
#include "../lib_paysages/shared/types.h"
@ -16,16 +17,20 @@ public:
public slots:
virtual void revertConfig();
virtual void applyConfigPreview();
virtual void applyConfig();
protected:
void addPreview(Preview* preview, QString label);
QPushButton* addButton(QString label);
void addInput(BaseInput* input);
void addInputInt(QString label, int* value, int min, int max, int small_step, int large_step);
void addInputDouble(QString label, double* value, double min, double max, double small_step, double large_step);
void addInputColor(QString label, Color* value);
private:
QWidget* previews;
QWidget* form;
QWidget* buttons;
};
#endif // _GUI_QT_BASEFORM_H_
#endif // _PAYSAGES_QT_BASEFORM_H_

View file

@ -1,5 +1,5 @@
#ifndef _GUI_QT_BASEINPUT_H_
#define _GUI_QT_BASEINPUT_H_
#ifndef _PAYSAGES_QT_BASEINPUT_H_
#define _PAYSAGES_QT_BASEINPUT_H_
#include <QWidget>
#include <QSlider>
@ -29,4 +29,4 @@ protected:
QWidget* _control;
};
#endif // _GUI_QT_BASEINPUT_H_
#endif // _PAYSAGES_QT_BASEINPUT_H_

95
gui_qt/dialogrender.cpp Normal file
View file

@ -0,0 +1,95 @@
#include "dialogrender.h"
#include <QVBoxLayout>
#include <QImage>
#include <QColor>
#include <QPainter>
#include <QScrollArea>
#include "../lib_paysages/shared/functions.h"
class RenderThread:public QThread
{
public:
void run()
{
autoRenderSceneTwoPass(0);
}
};
static DialogRender* _current_dialog;
static void _renderResize(int width, int height)
{
delete _current_dialog->pixbuf;
_current_dialog->pixbuf = new QImage(width, height, QImage::Format_ARGB32);
_current_dialog->area->setMinimumSize(width, height);
_current_dialog->area->setMaximumSize(width, height);
_current_dialog->area->resize(width, height);
}
static void _renderClear(Color col)
{
_current_dialog->pixbuf->fill(QColor(col.r * 255.0, col.g * 255.0, col.b * 255.0).rgb());
}
static void _renderDraw(int x, int y, Color col)
{
_current_dialog->pixbuf->setPixel(x, _current_dialog->pixbuf->height() - 1 - y, QColor(col.r * 255.0, col.g * 255.0, col.b * 255.0).rgb());
}
static void _renderUpdate(double progress)
{
_current_dialog->area->update();
_current_dialog->progress_value = progress * 1000.0;
}
class RenderArea:public QWidget
{
public:
RenderArea(QWidget* parent):
QWidget(parent)
{
setMinimumSize(800, 600);
}
void paintEvent(QPaintEvent* event)
{
QPainter painter(this);
painter.drawImage(0, 0, *_current_dialog->pixbuf);
_current_dialog->progress->setValue(_current_dialog->progress_value);
_current_dialog->progress->update();
}
};
DialogRender::DialogRender(QWidget *parent) :
QDialog(parent)
{
QScrollArea* scroll;
pixbuf = new QImage(1, 1, QImage::Format_ARGB32);
_current_dialog = this;
setModal(true);
setLayout(new QVBoxLayout());
scroll = new QScrollArea(this);
scroll->setMinimumSize(850, 650);
scroll->setAlignment(Qt::AlignCenter);
area = new RenderArea(scroll);
scroll->setWidget(area);
layout()->addWidget(scroll);
progress = new QProgressBar(this);
progress->setMinimum(0);
progress->setMaximum(1000);
layout()->addWidget(progress);
progress_value = 0;
renderSetSize(800, 600);
autoSetRenderQuality(5);
renderSetPreviewCallbacks(_renderResize, _renderClear, _renderDraw, _renderUpdate);
render_thread = new RenderThread();
render_thread->start();
}

26
gui_qt/dialogrender.h Normal file
View file

@ -0,0 +1,26 @@
#ifndef _PAYSAGES_QT_DIALOGRENDER_H_
#define _PAYSAGES_QT_DIALOGRENDER_H_
#include <QDialog>
#include <QThread>
#include <QProgressBar>
class DialogRender : public QDialog
{
Q_OBJECT
public:
explicit DialogRender(QWidget *parent = 0);
QImage* pixbuf;
QWidget* area;
QProgressBar* progress;
int progress_value;
signals:
public slots:
private:
QThread* render_thread;
};
#endif // _PAYSAGES_QT_DIALOGRENDER_H_

40
gui_qt/formrender.cpp Normal file
View file

@ -0,0 +1,40 @@
#include "formrender.h"
#include "dialogrender.h"
/**************** Form ****************/
FormRender::FormRender(QWidget *parent) :
BaseForm(parent),
_quality(5)
{
QPushButton* button;
addInputInt("Quality", &_quality, 1, 10, 1, 1);
button = addButton("Start new render");
connect(button, SIGNAL(clicked()), this, SLOT(startRender()));
button = addButton("Show last render");
connect(button, SIGNAL(clicked()), this, SLOT(showRender()));
button = addButton("Save last render");
connect(button, SIGNAL(clicked()), this, SLOT(saveRender()));
revertConfig();
}
void FormRender::startRender()
{
DialogRender* dialog = new DialogRender();
dialog->exec();
delete dialog;
}
void FormRender::showRender()
{
}
void FormRender::saveRender()
{
}

22
gui_qt/formrender.h Normal file
View file

@ -0,0 +1,22 @@
#ifndef _PAYSAGES_QT_FORMRENDER_H_
#define _PAYSAGES_QT_FORMRENDER_H_
#include "baseform.h"
class FormRender : public BaseForm
{
Q_OBJECT
public:
explicit FormRender(QWidget *parent = 0);
private slots:
void startRender();
void showRender();
void saveRender();
private:
int _quality;
};
#endif // _PAYSAGES_QT_FORMRENDER_H_

View file

@ -1,5 +1,5 @@
#ifndef _GUI_QT_FORMWATER_H_
#define _GUI_QT_FORMWATER_H_
#ifndef _PAYSAGES_QT_FORMWATER_H_
#define _PAYSAGES_QT_FORMWATER_H_
#include <QWidget>
#include "preview.h"
@ -20,4 +20,4 @@ private:
Preview* previewColor;
};
#endif // _GUI_QT_FORMWATER_H_
#endif // _PAYSAGES_QT_FORMWATER_H_

View file

@ -7,8 +7,6 @@ InputColor::InputColor(QWidget* form, QString label, Color* value):
BaseInput(form, label),
_value(value)
{
setObjectName("_inputcolor_");
_preview = new QWidget(form);
_control = new QPushButton("Edit", form);
}

View file

@ -1,5 +1,5 @@
#ifndef _GUI_QT_INPUTCOLOR_H_
#define _GUI_QT_INPUTCOLOR_H_
#ifndef _PAYSAGES_QT_INPUTCOLOR_H_
#define _PAYSAGES_QT_INPUTCOLOR_H_
#include <QWidget>
#include "baseinput.h"
@ -23,4 +23,4 @@ private:
Color* _value;
};
#endif // _GUI_QT_INPUTCOLOR_H_
#endif // _PAYSAGES_QT_INPUTCOLOR_H_

View file

@ -6,8 +6,6 @@ InputDouble::InputDouble(QWidget* form, QString label, double* value, double min
BaseInput(form, label),
value(value), min(min), max(max), small_step(small_step), large_step(large_step)
{
setObjectName("_form_doubleslider_");
slider = new QSlider(form);
slider->setOrientation(Qt::Horizontal);

View file

@ -1,5 +1,5 @@
#ifndef _GUI_QT_INPUTDOUBLE_H_
#define _GUI_QT_INPUTDOUBLE_H_
#ifndef _PAYSAGES_QT_INPUTDOUBLE_H_
#define _PAYSAGES_QT_INPUTDOUBLE_H_
#include <QWidget>
#include <QSlider>
@ -27,4 +27,4 @@ private:
double large_step;
};
#endif // _GUI_QT_INPUTDOUBLE_H_
#endif // _PAYSAGES_QT_INPUTDOUBLE_H_

39
gui_qt/inputint.cpp Normal file
View file

@ -0,0 +1,39 @@
#include "inputint.h"
#include <QLabel>
InputInt::InputInt(QWidget* form, QString label, int* value, int min, int max, int small_step, int large_step):
BaseInput(form, label),
value(value), min(min), max(max), small_step(small_step), large_step(large_step)
{
slider = new QSlider(form);
slider->setOrientation(Qt::Horizontal);
slider->setMinimumWidth(150);
slider->setMaximumWidth(400);
slider->setMinimum(min);
slider->setMaximum(max);
slider->setValue(*value);
slider->setTickInterval(large_step);
slider->setTickPosition(QSlider::TicksBelow);
connect(slider, SIGNAL(valueChanged(int)), this, SLOT(applyValue()));
_preview = new QLabel(form);
_control = slider;
}
void InputInt::applyValue()
{
*value = (int)slider->value();
((QLabel*)_preview)->setText(QString("%1").arg(*value));
BaseInput::applyValue();
}
void InputInt::revert()
{
slider->setValue(*value);
}

30
gui_qt/inputint.h Normal file
View file

@ -0,0 +1,30 @@
#ifndef _PAYSAGES_QT_INPUTINT_H_
#define _PAYSAGES_QT_INPUTINT_H_
#include <QWidget>
#include <QSlider>
#include "baseinput.h"
class InputInt:public BaseInput
{
Q_OBJECT
public:
InputInt(QWidget* form, QString label, int* value, int min, int max, int small_step, int large_step);
public slots:
virtual void revert();
protected slots:
virtual void applyValue();
private:
QSlider* slider;
int* value;
int min;
int max;
int small_step;
int large_step;
};
#endif // _PAYSAGES_QT_INPUTINT_H_

View file

@ -1,6 +1,7 @@
#include <QApplication>
#include "mainwindow.h"
#include "formwater.h"
#include "formrender.h"
#include "../lib_paysages/shared/functions.h"
@ -24,7 +25,9 @@ MainWindow::MainWindow(QWidget *parent) :
QTabWidget* tabs;
tabs = new QTabWidget(this);
tabs->addTab(new BaseForm(tabs), "Temp");
tabs->addTab(new FormWater(tabs), "Water");
tabs->addTab(new FormRender(tabs), "Render");
setCentralWidget(tabs);
}

View file

@ -1,5 +1,5 @@
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#ifndef _PAYSAGES_QT_MAINWINDOW_H_
#define _PAYSAGES_QT_MAINWINDOW_H_
#include <QMainWindow>
@ -15,4 +15,4 @@ public:
explicit MainWindow(QWidget *parent = 0);
};
#endif // MAINWINDOW_H
#endif // _PAYSAGES_QT_MAINWINDOW_H_

View file

@ -18,7 +18,10 @@ HEADERS += ../lib_paysages/shared/functions.h ../lib_paysages/shared/types.h \
baseform.h \
inputdouble.h \
baseinput.h \
inputcolor.h
inputcolor.h \
formrender.h \
inputint.h \
dialogrender.h
FORMS +=
SOURCES += \
mainwindow.cpp \
@ -27,4 +30,7 @@ SOURCES += \
baseform.cpp \
inputdouble.cpp \
baseinput.cpp \
inputcolor.cpp
inputcolor.cpp \
formrender.cpp \
inputint.cpp \
dialogrender.cpp

View file

@ -1,5 +1,5 @@
#ifndef _GUI_QT_PREVIEW_H_
#define _GUI_QT_PREVIEW_H_
#ifndef _PAYSAGES_QT_PREVIEW_H_
#define _PAYSAGES_QT_PREVIEW_H_
#include <QMutex>
#include <QImage>
@ -47,4 +47,4 @@ protected:
//SmallPreviewCallback renderer;
};
#endif // _GUI_QT_PREVIEW_H_
#endif // _PAYSAGES_QT_PREVIEW_H_

View file

@ -27,7 +27,7 @@ void autoSetDaytime(int hour, int minute);
void autoSetDaytimeFraction(double daytime);
void autoSetRenderQuality(int quality);
void autoGenRealisticLandscape(int seed);
void autoRenderSceneTwoPass();
void autoRenderSceneTwoPass(int postonly);
void autoRenderSceneRayTracing();
/* camera.c */