From 6f5c201df3138fcf12682d7c89b682b92fd46b67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Lemaire?= Date: Sun, 18 Mar 2012 19:51:06 +0000 Subject: [PATCH] paysages: Added band previews to colorgradation editor. git-svn-id: https://subversion.assembla.com/svn/thunderk/paysages@278 b1fd45b6-86a6-48da-8261-f70d1f35bdcc --- TODO | 1 + gui_qt/dialogcolorgradation.cpp | 18 ++++++++- gui_qt/dialogcolorgradation.h | 5 +++ gui_qt/inputcolorgradation.cpp | 27 +------------ gui_qt/previewcolorgradation.cpp | 68 ++++++++++++++++++++++++++++++++ gui_qt/previewcolorgradation.h | 28 +++++++++++++ i18n/paysages_fr.ts | 22 +++++++---- 7 files changed, 135 insertions(+), 34 deletions(-) create mode 100644 gui_qt/previewcolorgradation.cpp create mode 100644 gui_qt/previewcolorgradation.h diff --git a/TODO b/TODO index 1a0682c..b1e840e 100644 --- a/TODO +++ b/TODO @@ -1,4 +1,5 @@ - Implement scaling and scrolling on previews. +- Improve color gradation dialog (with curve editor ?). - Replace FILE* by a custom type for Save and Load. - Water and terrain LOD moves with the camera, fix it like in the wanderer. - Restore render progress. diff --git a/gui_qt/dialogcolorgradation.cpp b/gui_qt/dialogcolorgradation.cpp index 54b694a..7c2f61b 100644 --- a/gui_qt/dialogcolorgradation.cpp +++ b/gui_qt/dialogcolorgradation.cpp @@ -20,11 +20,27 @@ DialogColorGradation::DialogColorGradation(QWidget *parent, ColorGradation* grad _current = colorGradationCreate(); colorGradationCopy(_base, _current); - setLayout(new QHBoxLayout()); + setLayout(new QVBoxLayout()); _curve_editor = new WidgetCurveEditor(this); layout()->addWidget(_curve_editor); + _preview_red = new PreviewColorGradation(this, gradation, COLORGRADATIONBAND_RED); + _preview_red->setMinimumHeight(50); + layout()->addWidget(_preview_red); + + _preview_green = new PreviewColorGradation(this, gradation, COLORGRADATIONBAND_GREEN); + _preview_green->setMinimumHeight(50); + layout()->addWidget(_preview_green); + + _preview_blue = new PreviewColorGradation(this, gradation, COLORGRADATIONBAND_BLUE); + _preview_blue->setMinimumHeight(50); + layout()->addWidget(_preview_blue); + + _preview_final = new PreviewColorGradation(this, gradation, COLORGRADATIONBAND_FINAL); + _preview_final->setMinimumHeight(50); + layout()->addWidget(_preview_final); + _curve = curveCreate(); /*QObject::connect(button, SIGNAL(clicked()), this, SLOT(accept())); diff --git a/gui_qt/dialogcolorgradation.h b/gui_qt/dialogcolorgradation.h index 87f27d8..65e5ae1 100644 --- a/gui_qt/dialogcolorgradation.h +++ b/gui_qt/dialogcolorgradation.h @@ -4,6 +4,7 @@ #include #include "baseform.h" #include "widgetcurveeditor.h" +#include "previewcolorgradation.h" #include "../lib_paysages/color.h" #include "../lib_paysages/curve.h" @@ -32,6 +33,10 @@ private: ColorGradation* _current; Curve* _curve; WidgetCurveEditor* _curve_editor; + PreviewColorGradation* _preview_red; + PreviewColorGradation* _preview_green; + PreviewColorGradation* _preview_blue; + PreviewColorGradation* _preview_final; }; #endif diff --git a/gui_qt/inputcolorgradation.cpp b/gui_qt/inputcolorgradation.cpp index 1a281b8..2480f3e 100644 --- a/gui_qt/inputcolorgradation.cpp +++ b/gui_qt/inputcolorgradation.cpp @@ -5,37 +5,14 @@ #include #include #include "dialogcolorgradation.h" +#include "previewcolorgradation.h" #include "tools.h" -class ColorGradationPreview:public QWidget -{ -public: - ColorGradationPreview(QWidget* parent, ColorGradation* gradation) : QWidget(parent) - { - this->gradation = gradation; - } - - void paintEvent(QPaintEvent* event) - { - QPainter painter(this); - int width = this->width(); - int height = this->height(); - - for (int x = 0; x < width; x++) - { - painter.setPen(colorToQColor(colorGradationGet(gradation, (double)x / (double)width))); - painter.drawLine(x, 0, x, height - 1); - } - } - - ColorGradation* gradation; -}; - InputColorGradation::InputColorGradation(QWidget* form, QString label, ColorGradation* value) : BaseInput(form, label) { _value = value; - _preview = new ColorGradationPreview(form, value); + _preview = new PreviewColorGradation(form, value, COLORGRADATIONBAND_FINAL); _preview->setMinimumSize(200, 20); _control = new QPushButton(tr("Edit"), form); diff --git a/gui_qt/previewcolorgradation.cpp b/gui_qt/previewcolorgradation.cpp new file mode 100644 index 0000000..975ccb9 --- /dev/null +++ b/gui_qt/previewcolorgradation.cpp @@ -0,0 +1,68 @@ +#include "previewcolorgradation.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include "baseform.h" +#include "tools.h" +#include "widgetcurveeditor.h" + +/**************** Preview ****************/ +PreviewColorGradation::PreviewColorGradation(QWidget* parent, ColorGradation* gradation, EnumColorGradationBand band) : QWidget(parent) +{ + this->gradation = gradation; + this->band = band; +} + +void PreviewColorGradation::paintEvent(QPaintEvent* event) +{ + Curve* curve; + + QPainter painter(this); + int width = this->width(); + int height = this->height(); + + curve = curveCreate(); + + switch (band) + { + case COLORGRADATIONBAND_RED: + colorGradationGetRedCurve(gradation, curve); + break; + case COLORGRADATIONBAND_GREEN: + colorGradationGetGreenCurve(gradation, curve); + break; + case COLORGRADATIONBAND_BLUE: + colorGradationGetBlueCurve(gradation, curve); + break; + default: + break; + } + + for (int x = 0; x < width; x++) + { + switch (band) + { + case COLORGRADATIONBAND_RED: + painter.setPen(QColor::fromRgbF(curveGetValue(curve, (double)x / (double)width), 0.0, 0.0)); + break; + case COLORGRADATIONBAND_GREEN: + painter.setPen(QColor::fromRgbF(0.0, curveGetValue(curve, (double)x / (double)width), 0.0)); + break; + case COLORGRADATIONBAND_BLUE: + painter.setPen(QColor::fromRgbF(0.0, 0.0, curveGetValue(curve, (double)x / (double)width))); + break; + case COLORGRADATIONBAND_FINAL: + painter.setPen(colorToQColor(colorGradationGet(gradation, (double)x / (double)width))); + break; + } + painter.drawLine(x, 0, x, height - 1); + } + + curveDelete(curve); +} diff --git a/gui_qt/previewcolorgradation.h b/gui_qt/previewcolorgradation.h new file mode 100644 index 0000000..04acb59 --- /dev/null +++ b/gui_qt/previewcolorgradation.h @@ -0,0 +1,28 @@ +#ifndef _PAYSAGES_QT_PREVIEWCOLORGRADATION_H_ +#define _PAYSAGES_QT_PREVIEWCOLORGRADATION_H_ + +#include + +#include "../lib_paysages/color.h" + +typedef enum +{ + COLORGRADATIONBAND_RED, + COLORGRADATIONBAND_GREEN, + COLORGRADATIONBAND_BLUE, + COLORGRADATIONBAND_FINAL +} EnumColorGradationBand; + +class PreviewColorGradation:public QWidget +{ + Q_OBJECT +public: + PreviewColorGradation(QWidget* parent, ColorGradation* gradation, EnumColorGradationBand band); + void paintEvent(QPaintEvent* event); + +private: + ColorGradation* gradation; + EnumColorGradationBand band; +}; + +#endif diff --git a/i18n/paysages_fr.ts b/i18n/paysages_fr.ts index 38f4515..86ab83f 100644 --- a/i18n/paysages_fr.ts +++ b/i18n/paysages_fr.ts @@ -4,34 +4,40 @@ BaseForm + Layers : - Niveaux : + Niveaux : + Add layer - Ajouter un niveau + Ajouter un niveau + Delete layer - Supprimer un niveau + Supprimer un niveau + Apply - Appliquer + Appliquer + Revert - Annuler les modifications + Annuler les modifications + Layer %1 - Niveau %1 + Niveau %1 DialogColorGradation - + Paysages 3D - Color gradation editor Paysages 3D - Editeur de gradients de couleur @@ -492,7 +498,7 @@ InputColorGradation - + Edit Editer