paysages: Qt GUI (WIP)

git-svn-id: https://subversion.assembla.com/svn/thunderk/paysages@214 b1fd45b6-86a6-48da-8261-f70d1f35bdcc
This commit is contained in:
Michaël Lemaire 2012-01-05 18:39:17 +00:00 committed by ThunderK
parent deeadf33ca
commit 1fcbb37f17
17 changed files with 245 additions and 229 deletions

View file

@ -136,12 +136,12 @@ static void _cbTransparencyDepthChanged(GtkRange* range, gpointer data)
static void _cbColorChanged(GtkColorButton* colorbutton, gpointer data)
{
GdkRGBA col;
GdkColor col;
gtk_color_button_get_rgba(colorbutton, &col);
_definition.main_color.r = col.red;
_definition.main_color.g = col.green;
_definition.main_color.b = col.blue;
gtk_color_button_get_color(colorbutton, &col);
_definition.main_color.r = (double)col.red / 65535.0;
_definition.main_color.g = (double)col.green / 65535.0;
_definition.main_color.b = (double)col.blue / 65535.0;
_definition.main_color.a = 1.0;
guiPreviewRedraw(_preview_render);
@ -150,12 +150,12 @@ static void _cbColorChanged(GtkColorButton* colorbutton, gpointer data)
static void _cbColorDepthChanged(GtkColorButton* colorbutton, gpointer data)
{
GdkRGBA col;
GdkColor col;
gtk_color_button_get_rgba(colorbutton, &col);
_definition.depth_color.r = col.red;
_definition.depth_color.g = col.green;
_definition.depth_color.b = col.blue;
gtk_color_button_get_color(colorbutton, &col);
_definition.depth_color.r = (double)col.red / 65535.0;
_definition.depth_color.g = (double)col.green / 65535.0;
_definition.depth_color.b = (double)col.blue / 65535.0;
_definition.depth_color.a = 1.0;
guiPreviewRedraw(_preview_render);
@ -164,7 +164,7 @@ static void _cbColorDepthChanged(GtkColorButton* colorbutton, gpointer data)
static void _cbRevertConfig(GtkWidget* widget, gpointer data)
{
GdkRGBA col;
GdkColor col;
waterCopyDefinition(waterGetDefinition(), &_definition);
@ -172,16 +172,14 @@ static void _cbRevertConfig(GtkWidget* widget, gpointer data)
gtk_range_set_value(GTK_RANGE(GET_WIDGET("water_transparency")), _definition.transparency);
gtk_range_set_value(GTK_RANGE(GET_WIDGET("water_reflection")), _definition.reflection);
gtk_range_set_value(GTK_RANGE(GET_WIDGET("water_transparency_depth")), _definition.transparency_depth);
col.red = _definition.main_color.r;
col.green = _definition.main_color.g;
col.blue = _definition.main_color.b;
col.alpha = 1.0;
gtk_color_button_set_rgba(GTK_COLOR_BUTTON(GET_WIDGET("water_color")), &col);
col.red = _definition.depth_color.r;
col.green = _definition.depth_color.g;
col.blue = _definition.depth_color.b;
col.alpha = 1.0;
gtk_color_button_set_rgba(GTK_COLOR_BUTTON(GET_WIDGET("water_color_depth")), &col);
col.red = _definition.main_color.r * 65535.0;
col.green = _definition.main_color.g * 65535.0;
col.blue = _definition.main_color.b * 65535.0;
gtk_color_button_set_color(GTK_COLOR_BUTTON(GET_WIDGET("water_color")), &col);
col.red = _definition.depth_color.r * 65535.0;
col.green = _definition.depth_color.g * 65535.0;
col.blue = _definition.depth_color.b * 65535.0;
gtk_color_button_set_color(GTK_COLOR_BUTTON(GET_WIDGET("water_color_depth")), &col);
guiPreviewRedraw(_preview_render);
guiPreviewRedraw(_preview_coverage);

View file

@ -1,46 +1,10 @@
#include "baseform.h"
#include "inputdouble.h"
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QGridLayout>
#include <QLabel>
#include <QSlider>
class DoubleSliderWidget:public QWidget
{
public:
DoubleSliderWidget(QWidget* parent, double* value, double min, double max, double small_step, double large_step):
QWidget(parent),
value(value), min(min), max(max), small_step(small_step), large_step(large_step)
{
setObjectName("_form_doubleslider_");
setLayout(new QHBoxLayout());
slider = new QSlider(this);
slider->setOrientation(Qt::Horizontal);
slider->setMinimum(min / small_step);
slider->setMaximum(max / small_step);
slider->setValue(*value / small_step);
slider->setTickInterval(large_step / small_step);
slider->setTickPosition(QSlider::TicksBelow);
layout()->addWidget(slider);
}
void revert()
{
slider->setValue(*value / small_step);
}
private:
QSlider* slider;
double* value;
double min;
double max;
double small_step;
double large_step;
};
BaseForm::BaseForm(QWidget* parent) :
QWidget(parent)
@ -72,19 +36,24 @@ BaseForm::BaseForm(QWidget* parent) :
this->setLayout(vlayout);
}
void BaseForm::revertConfig()
void BaseForm::applyConfigPreview()
{
QList<Preview*> list_previews = previews->findChildren<Preview*>("_form_preview_");
for (int i = 0; i < list_previews.size(); i++)
{
list_previews[i]->redraw();
}
}
QList<DoubleSliderWidget*> list_doubles = form->findChildren<DoubleSliderWidget*>("_form_doubleslider_");
void BaseForm::revertConfig()
{
QList<InputDouble*> list_doubles = form->findChildren<InputDouble*>("_form_doubleslider_");
for (int i = 0; i < list_doubles.size(); i++)
{
list_doubles[i]->revert();
}
BaseForm::applyConfigPreview();
}
void BaseForm::addPreview(Preview* preview, QString label)
@ -94,11 +63,19 @@ void BaseForm::addPreview(Preview* preview, QString label)
preview->setObjectName("_form_preview_");
}
void BaseForm::addDoubleSlider(QString label, double* value, double min, double max, double small_step, double large_step)
void BaseForm::addInput(BaseInput* input)
{
QGridLayout* layout = (QGridLayout*)form->layout();
int row = layout->rowCount();
layout->addWidget(new QLabel(label, form), row, 0);
layout->addWidget(new DoubleSliderWidget(form, value, min, max, small_step, large_step), row, 1);
layout->addWidget(input->label(), row, 0);
layout->addWidget(input->preview(), row, 1);
layout->addWidget(input->control(), row, 2);
connect(input, SIGNAL(valueChanged()), this, SLOT(applyConfigPreview()));
}
void BaseForm::addInputDouble(QString label, double* value, double min, double max, double small_step, double large_step)
{
addInput(new InputDouble(form, label, value, min, max, small_step, large_step));
}

View file

@ -3,18 +3,23 @@
#include <QWidget>
#include "preview.h"
#include "baseinput.h"
class BaseForm:public QWidget
{
Q_OBJECT
public:
BaseForm(QWidget* parent);
public slots:
virtual void revertConfig();
virtual void applyConfigPreview();
protected:
void addPreview(Preview* preview, QString label);
void addDoubleSlider(QString label, double* value, double min, double max, double small_step, double large_step);
void addInput(BaseInput* input);
void addInputDouble(QString label, double* value, double min, double max, double small_step, double large_step);
private:
QWidget* previews;

9
gui_qt/baseinput.cpp Normal file
View file

@ -0,0 +1,9 @@
#include "baseinput.h"
#include <QLabel>
BaseInput::BaseInput(QWidget* form, QString label):
QObject(form)
{
_label = new QLabel(label);
}

32
gui_qt/baseinput.h Normal file
View file

@ -0,0 +1,32 @@
#ifndef _GUI_QT_BASEINPUT_H_
#define _GUI_QT_BASEINPUT_H_
#include <QWidget>
#include <QSlider>
class BaseInput:public QObject
{
Q_OBJECT
public:
BaseInput(QWidget* form, QString label);
inline QWidget* label() {return _label;}
inline QWidget* preview() {return _preview;}
inline QWidget* control() {return _control;}
public slots:
virtual void revert() = 0;
protected slots:
virtual void applyValue() = 0;
signals:
void valueChanged();
protected:
QWidget* _label;
QWidget* _preview;
QWidget* _control;
};
#endif // _GUI_QT_BASEINPUT_H_

View file

@ -131,33 +131,22 @@ FormWater::FormWater(QWidget *parent) :
addPreview(previewCoverage, QString("Coverage preview"));
addPreview(previewColor, QString("Color preview"));
addDoubleSlider("Height", &_definition.height, -20.0, 20.0, 0.1, 1.0);
addDoubleSlider("Transparency", &_definition.transparency, 0.0, 1.0, 0.001, 0.1);
addDoubleSlider("Reflection", &_definition.reflection, 0.0, 1.0, 0.001, 0.1);
addDoubleSlider("Depth filtering", &_definition.transparency_depth, 0.0, 100.0, 0.5, 5.0);
addInputDouble("Height", &_definition.height, -20.0, 20.0, 0.1, 1.0);
addInputDouble("Transparency", &_definition.transparency, 0.0, 1.0, 0.001, 0.1);
addInputDouble("Reflection", &_definition.reflection, 0.0, 1.0, 0.001, 0.1);
addInputDouble("Depth filtering", &_definition.transparency_depth, 0.0, 100.0, 0.5, 5.0);
revertConfig();
}
void FormWater::configChange()
{
/*_definition.height = (double)findChild<QSlider*>("water_height")->value() / 10.0;
_definition.transparency = (double)findChild<QSlider*>("water_transparency")->value() / 1000.0;
_definition.reflection = (double)findChild<QSlider*>("water_reflection")->value() / 1000.0;
_definition.transparency_depth = (double)findChild<QSlider*>("water_depth_limit")->value() / 10.0;
previewCoverage->redraw();
previewColor->redraw();*/
}
void FormWater::applyConfig()
{
waterSetDefinition(_definition);
//guiUpdate();
}
void FormWater::revertConfig()
{
waterCopyDefinition(waterGetDefinition(), &_definition);
BaseForm::revertConfig();
}
/*void FormWater::applyConfig()
{
waterSetDefinition(_definition);
//guiUpdate();
}*/

View file

@ -14,8 +14,6 @@ public:
public slots:
virtual void revertConfig();
void configChange();
void applyConfig();
private:
Preview* previewCoverage;

22
gui_qt/inputcolor.cpp Normal file
View file

@ -0,0 +1,22 @@
#include "inputcolor.h"
#include <QLabel>
InputColor::InputColor(QWidget* form, QString label, Color color):
BaseInput(form, label),
_color(color)
{
setObjectName("_inputcolor_");
_preview = new QLabel(form);
_control = new QLabel(form);
}
void InputColor::applyValue()
{
emit(valueChanged());
}
void InputColor::revert()
{
}

26
gui_qt/inputcolor.h Normal file
View file

@ -0,0 +1,26 @@
#ifndef _GUI_QT_INPUTCOLOR_H_
#define _GUI_QT_INPUTCOLOR_H_
#include <QWidget>
#include "baseinput.h"
#include "../lib_paysages/shared/types.h"
class InputColor:public BaseInput
{
Q_OBJECT
public:
InputColor(QWidget* form, QString label, Color value);
public slots:
virtual void revert();
protected slots:
virtual void applyValue();
private:
Color _color;
};
#endif // _GUI_QT_INPUTCOLOR_H_

40
gui_qt/inputdouble.cpp Normal file
View file

@ -0,0 +1,40 @@
#include "inputdouble.h"
#include <QLabel>
InputDouble::InputDouble(QWidget* form, QString label, double* value, double min, double max, double small_step, double large_step):
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);
slider->setMinimumWidth(150);
slider->setMaximumWidth(400);
slider->setMinimum(min / small_step);
slider->setMaximum(max / small_step);
slider->setValue(*value / small_step);
slider->setTickInterval(large_step / small_step);
slider->setTickPosition(QSlider::TicksBelow);
connect(slider, SIGNAL(valueChanged(int)), this, SLOT(applyValue()));
_preview = new QLabel(form);
_control = slider;
}
void InputDouble::applyValue()
{
*value = ((double)slider->value()) * small_step;
((QLabel*)_preview)->setText(QString("%1").arg(*value));
emit(valueChanged());
}
void InputDouble::revert()
{
slider->setValue(*value / small_step);
}

30
gui_qt/inputdouble.h Normal file
View file

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

View file

@ -1,19 +0,0 @@
#include <QApplication>
#include "mainwindow.h"
#include "preview.h"
#include "../lib_paysages/shared/functions.h"
int main(int argc, char** argv)
{
paysagesInit();
QApplication app(argc, argv);
MainWindow window;
window.show();
Preview::startUpdater();
return app.exec();
}

View file

@ -1,20 +1,30 @@
#include <QApplication>
#include "mainwindow.h"
#include "formwater.h"
#include "ui_mainwindow.h"
#include "../lib_paysages/shared/functions.h"
int main(int argc, char** argv)
{
paysagesInit();
QApplication app(argc, argv);
MainWindow window;
window.show();
Preview::startUpdater();
return app.exec();
}
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
QMainWindow(parent)
{
QTabWidget* tabs;
ui->setupUi(this);
tabs = this->findChild<QTabWidget*>("tabWidget");
tabs = new QTabWidget(this);
tabs->addTab(new FormWater(tabs), "Water");
}
MainWindow::~MainWindow()
{
delete ui;
setCentralWidget(tabs);
}

View file

@ -13,10 +13,6 @@ class MainWindow : public QMainWindow
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
private:
Ui::MainWindow *ui;
};
#endif // MAINWINDOW_H

View file

@ -1,105 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MainWindow</class>
<widget class="QMainWindow" name="MainWindow">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>744</width>
<height>673</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>744</width>
<height>673</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>744</width>
<height>673</height>
</size>
</property>
<property name="baseSize">
<size>
<width>744</width>
<height>673</height>
</size>
</property>
<property name="windowTitle">
<string>Paysages</string>
</property>
<widget class="QWidget" name="centralwidget">
<widget class="QTabWidget" name="tabWidget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>741</width>
<height>621</height>
</rect>
</property>
<property name="currentIndex">
<number>-1</number>
</property>
</widget>
</widget>
<widget class="QMenuBar" name="menubar">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>744</width>
<height>25</height>
</rect>
</property>
<widget class="QMenu" name="menuFichier">
<property name="title">
<string>File</string>
</property>
<addaction name="actionNewx"/>
<addaction name="actionSave"/>
<addaction name="actionLoad"/>
<addaction name="actionQuit"/>
</widget>
<widget class="QMenu" name="menuAbout">
<property name="title">
<string>About...</string>
</property>
</widget>
<addaction name="menuFichier"/>
<addaction name="menuAbout"/>
</widget>
<widget class="QStatusBar" name="statusbar"/>
<action name="actionNewx">
<property name="text">
<string>New</string>
</property>
</action>
<action name="actionSave">
<property name="text">
<string>Save</string>
</property>
</action>
<action name="actionLoad">
<property name="text">
<string>Load</string>
</property>
</action>
<action name="actionQuit">
<property name="text">
<string>Quit</string>
</property>
</action>
</widget>
<resources/>
<connections/>
</ui>

View file

@ -15,10 +15,16 @@ HEADERS += ../lib_paysages/shared/functions.h ../lib_paysages/shared/types.h \
mainwindow.h \
formwater.h \
preview.h \
baseform.h
FORMS += mainwindow.ui
SOURCES += main.cc \
baseform.h \
inputdouble.h \
baseinput.h \
inputcolor.h
FORMS +=
SOURCES += \
mainwindow.cpp \
formwater.cpp \
preview.cpp \
baseform.cpp
baseform.cpp \
inputdouble.cpp \
baseinput.cpp \
inputcolor.cpp

View file

@ -7,6 +7,8 @@
class Preview:public QWidget
{
Q_OBJECT
public:
Preview(QWidget* parent);
static void startUpdater();