From a5bc77e798d25d5d345e37393e9f02dd5628316c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Lemaire?= Date: Fri, 6 Jan 2012 16:09:03 +0000 Subject: [PATCH] paysages: Qt GUI (WIP) git-svn-id: https://subversion.assembla.com/svn/thunderk/paysages@217 b1fd45b6-86a6-48da-8261-f70d1f35bdcc --- gui_qt/baseform.cpp | 34 ++++++++++-- gui_qt/baseform.h | 11 ++-- gui_qt/baseinput.h | 6 +-- gui_qt/dialogrender.cpp | 95 +++++++++++++++++++++++++++++++++ gui_qt/dialogrender.h | 26 +++++++++ gui_qt/formrender.cpp | 40 ++++++++++++++ gui_qt/formrender.h | 22 ++++++++ gui_qt/formwater.cpp | 2 +- gui_qt/formwater.h | 6 +-- gui_qt/inputcolor.cpp | 2 - gui_qt/inputcolor.h | 6 +-- gui_qt/inputdouble.cpp | 2 - gui_qt/inputdouble.h | 6 +-- gui_qt/inputint.cpp | 39 ++++++++++++++ gui_qt/inputint.h | 30 +++++++++++ gui_qt/mainwindow.cpp | 3 ++ gui_qt/mainwindow.h | 6 +-- gui_qt/paysages-qt.pro | 10 +++- gui_qt/preview.h | 6 +-- lib_paysages/shared/functions.h | 2 +- 20 files changed, 321 insertions(+), 33 deletions(-) create mode 100644 gui_qt/dialogrender.cpp create mode 100644 gui_qt/dialogrender.h create mode 100644 gui_qt/formrender.cpp create mode 100644 gui_qt/formrender.h create mode 100644 gui_qt/inputint.cpp create mode 100644 gui_qt/inputint.h diff --git a/gui_qt/baseform.cpp b/gui_qt/baseform.cpp index 1a55164..84649fa 100644 --- a/gui_qt/baseform.cpp +++ b/gui_qt/baseform.cpp @@ -1,6 +1,7 @@ #include "baseform.h" #include "inputdouble.h" +#include "inputint.h" #include "inputcolor.h" #include @@ -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 list_doubles = form->findChildren("_form_doubleslider_"); - for (int i = 0; i < list_doubles.size(); i++) + QList inputs = form->findChildren("_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) diff --git a/gui_qt/baseform.h b/gui_qt/baseform.h index 6348dfc..1922dd2 100644 --- a/gui_qt/baseform.h +++ b/gui_qt/baseform.h @@ -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 +#include #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_ diff --git a/gui_qt/baseinput.h b/gui_qt/baseinput.h index cfebde1..e128b59 100644 --- a/gui_qt/baseinput.h +++ b/gui_qt/baseinput.h @@ -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 #include @@ -29,4 +29,4 @@ protected: QWidget* _control; }; -#endif // _GUI_QT_BASEINPUT_H_ +#endif // _PAYSAGES_QT_BASEINPUT_H_ diff --git a/gui_qt/dialogrender.cpp b/gui_qt/dialogrender.cpp new file mode 100644 index 0000000..ee96bd0 --- /dev/null +++ b/gui_qt/dialogrender.cpp @@ -0,0 +1,95 @@ +#include "dialogrender.h" + +#include +#include +#include +#include +#include + +#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(); +} diff --git a/gui_qt/dialogrender.h b/gui_qt/dialogrender.h new file mode 100644 index 0000000..4a0c821 --- /dev/null +++ b/gui_qt/dialogrender.h @@ -0,0 +1,26 @@ +#ifndef _PAYSAGES_QT_DIALOGRENDER_H_ +#define _PAYSAGES_QT_DIALOGRENDER_H_ + +#include +#include +#include + +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_ diff --git a/gui_qt/formrender.cpp b/gui_qt/formrender.cpp new file mode 100644 index 0000000..2a4ac33 --- /dev/null +++ b/gui_qt/formrender.cpp @@ -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() +{ + +} diff --git a/gui_qt/formrender.h b/gui_qt/formrender.h new file mode 100644 index 0000000..fd87b87 --- /dev/null +++ b/gui_qt/formrender.h @@ -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_ diff --git a/gui_qt/formwater.cpp b/gui_qt/formwater.cpp index 03c08c1..65b7b41 100644 --- a/gui_qt/formwater.cpp +++ b/gui_qt/formwater.cpp @@ -121,7 +121,7 @@ private: }; /**************** Form ****************/ -FormWater::FormWater(QWidget *parent) : +FormWater::FormWater(QWidget *parent): BaseForm(parent) { _definition = waterCreateDefinition(); diff --git a/gui_qt/formwater.h b/gui_qt/formwater.h index e40c408..283bab2 100644 --- a/gui_qt/formwater.h +++ b/gui_qt/formwater.h @@ -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 #include "preview.h" @@ -20,4 +20,4 @@ private: Preview* previewColor; }; -#endif // _GUI_QT_FORMWATER_H_ +#endif // _PAYSAGES_QT_FORMWATER_H_ diff --git a/gui_qt/inputcolor.cpp b/gui_qt/inputcolor.cpp index a80279a..593e1d8 100644 --- a/gui_qt/inputcolor.cpp +++ b/gui_qt/inputcolor.cpp @@ -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); } diff --git a/gui_qt/inputcolor.h b/gui_qt/inputcolor.h index 33090a6..96acca6 100644 --- a/gui_qt/inputcolor.h +++ b/gui_qt/inputcolor.h @@ -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 #include "baseinput.h" @@ -23,4 +23,4 @@ private: Color* _value; }; -#endif // _GUI_QT_INPUTCOLOR_H_ +#endif // _PAYSAGES_QT_INPUTCOLOR_H_ diff --git a/gui_qt/inputdouble.cpp b/gui_qt/inputdouble.cpp index 73e5864..1bc5dc6 100644 --- a/gui_qt/inputdouble.cpp +++ b/gui_qt/inputdouble.cpp @@ -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); diff --git a/gui_qt/inputdouble.h b/gui_qt/inputdouble.h index b706609..faa0bbf 100644 --- a/gui_qt/inputdouble.h +++ b/gui_qt/inputdouble.h @@ -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 #include @@ -27,4 +27,4 @@ private: double large_step; }; -#endif // _GUI_QT_INPUTDOUBLE_H_ +#endif // _PAYSAGES_QT_INPUTDOUBLE_H_ diff --git a/gui_qt/inputint.cpp b/gui_qt/inputint.cpp new file mode 100644 index 0000000..4ef0aac --- /dev/null +++ b/gui_qt/inputint.cpp @@ -0,0 +1,39 @@ +#include "inputint.h" + +#include + +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); +} diff --git a/gui_qt/inputint.h b/gui_qt/inputint.h new file mode 100644 index 0000000..69a44df --- /dev/null +++ b/gui_qt/inputint.h @@ -0,0 +1,30 @@ +#ifndef _PAYSAGES_QT_INPUTINT_H_ +#define _PAYSAGES_QT_INPUTINT_H_ + +#include +#include +#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_ diff --git a/gui_qt/mainwindow.cpp b/gui_qt/mainwindow.cpp index 606ab59..79f2de1 100644 --- a/gui_qt/mainwindow.cpp +++ b/gui_qt/mainwindow.cpp @@ -1,6 +1,7 @@ #include #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); } diff --git a/gui_qt/mainwindow.h b/gui_qt/mainwindow.h index fb5c048..9bbfb63 100644 --- a/gui_qt/mainwindow.h +++ b/gui_qt/mainwindow.h @@ -1,5 +1,5 @@ -#ifndef MAINWINDOW_H -#define MAINWINDOW_H +#ifndef _PAYSAGES_QT_MAINWINDOW_H_ +#define _PAYSAGES_QT_MAINWINDOW_H_ #include @@ -15,4 +15,4 @@ public: explicit MainWindow(QWidget *parent = 0); }; -#endif // MAINWINDOW_H +#endif // _PAYSAGES_QT_MAINWINDOW_H_ diff --git a/gui_qt/paysages-qt.pro b/gui_qt/paysages-qt.pro index 105f403..930ec32 100644 --- a/gui_qt/paysages-qt.pro +++ b/gui_qt/paysages-qt.pro @@ -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 diff --git a/gui_qt/preview.h b/gui_qt/preview.h index c1439e2..288dc96 100644 --- a/gui_qt/preview.h +++ b/gui_qt/preview.h @@ -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 #include @@ -47,4 +47,4 @@ protected: //SmallPreviewCallback renderer; }; -#endif // _GUI_QT_PREVIEW_H_ +#endif // _PAYSAGES_QT_PREVIEW_H_ diff --git a/lib_paysages/shared/functions.h b/lib_paysages/shared/functions.h index f55ae0d..d031ae7 100644 --- a/lib_paysages/shared/functions.h +++ b/lib_paysages/shared/functions.h @@ -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 */