2012-02-20 21:17:13 +00:00
# include "dialogcolorgradation.h"
# include <QVBoxLayout>
2012-03-29 20:19:50 +00:00
# include <QHBoxLayout>
2012-03-31 11:32:03 +00:00
# include <QGridLayout>
2012-02-20 21:17:13 +00:00
# include <QImage>
# include <QLabel>
# include <QColor>
# include <QPainter>
# include <QSlider>
# include <QScrollArea>
# include <QPushButton>
2012-02-21 13:41:02 +00:00
# include "tools.h"
2012-03-08 15:10:25 +00:00
# include "widgetcurveeditor.h"
2012-02-20 21:17:13 +00:00
/**************** Dialog ****************/
DialogColorGradation : : DialogColorGradation ( QWidget * parent , ColorGradation * gradation ) :
QDialog ( parent )
{
2012-03-29 20:19:50 +00:00
QWidget * buttons ;
2012-03-31 11:32:03 +00:00
QWidget * form ;
QGridLayout * form_layout ;
2012-04-14 13:05:03 +00:00
QLabel * label ;
2012-12-24 14:13:19 +00:00
2012-02-20 21:17:13 +00:00
_base = gradation ;
_current = colorGradationCreate ( ) ;
2012-03-08 15:10:25 +00:00
colorGradationCopy ( _base , _current ) ;
2012-02-20 21:17:13 +00:00
2012-03-18 19:51:06 +00:00
setLayout ( new QVBoxLayout ( ) ) ;
2012-12-24 14:13:19 +00:00
2012-03-31 11:32:03 +00:00
form = new QWidget ( this ) ;
form_layout = new QGridLayout ( ) ;
form - > setLayout ( form_layout ) ;
layout ( ) - > addWidget ( form ) ;
2012-12-24 14:13:19 +00:00
2012-04-14 13:05:03 +00:00
label = new QLabel ( tr ( " This is the curve editor for color components. \n Click on a component preview below to edit it. \n Click on points and drag them to move them. \n Double click to add a new point. \n Right click on a point to delete it. " ) , form ) ;
label - > setSizePolicy ( QSizePolicy : : MinimumExpanding , QSizePolicy : : Minimum ) ;
label - > setMinimumWidth ( 150 ) ;
label - > setMaximumWidth ( 200 ) ;
label - > setWordWrap ( true ) ;
form_layout - > addWidget ( label , 0 , 1 ) ;
2012-05-29 13:32:23 +00:00
_curve_editor = new WidgetCurveEditor ( form , 0.0 , 1.0 , 0.0 , 1.0 ) ;
2012-04-14 13:05:03 +00:00
_curve_editor - > setSizePolicy ( QSizePolicy : : MinimumExpanding , QSizePolicy : : MinimumExpanding ) ;
form_layout - > addWidget ( _curve_editor , 0 , 0 ) ;
2012-03-29 20:19:50 +00:00
connect ( _curve_editor , SIGNAL ( liveChanged ( ) ) , this , SLOT ( updateColors ( ) ) ) ;
2012-04-14 13:05:03 +00:00
label = new QLabel ( tr ( " Red preview, click to edit " ) , form ) ;
label - > setSizePolicy ( QSizePolicy : : MinimumExpanding , QSizePolicy : : Minimum ) ;
label - > setMinimumWidth ( 150 ) ;
label - > setMaximumWidth ( 200 ) ;
label - > setWordWrap ( true ) ;
form_layout - > addWidget ( label , 1 , 1 ) ;
2012-03-31 11:32:03 +00:00
_preview_red = new PreviewColorGradation ( form , _current , COLORGRADATIONBAND_RED ) ;
2012-04-14 13:05:03 +00:00
_preview_red - > setMinimumHeight ( 30 ) ;
_preview_red - > setMaximumHeight ( 60 ) ;
_preview_red - > setSizePolicy ( QSizePolicy : : MinimumExpanding , QSizePolicy : : MinimumExpanding ) ;
2012-03-18 21:00:50 +00:00
connect ( _preview_red , SIGNAL ( clicked ( ) ) , this , SLOT ( selectRed ( ) ) ) ;
2012-04-14 13:05:03 +00:00
form_layout - > addWidget ( _preview_red , 1 , 0 ) ;
2012-03-18 19:51:06 +00:00
2012-04-14 13:05:03 +00:00
label = new QLabel ( tr ( " Green preview, click to edit " ) , form ) ;
label - > setSizePolicy ( QSizePolicy : : MinimumExpanding , QSizePolicy : : Minimum ) ;
label - > setMinimumWidth ( 150 ) ;
label - > setMaximumWidth ( 200 ) ;
label - > setWordWrap ( true ) ;
form_layout - > addWidget ( label , 2 , 1 ) ;
2012-03-31 11:32:03 +00:00
_preview_green = new PreviewColorGradation ( form , _current , COLORGRADATIONBAND_GREEN ) ;
2012-04-14 13:05:03 +00:00
_preview_green - > setMinimumHeight ( 30 ) ;
_preview_green - > setMaximumHeight ( 60 ) ;
_preview_green - > setSizePolicy ( QSizePolicy : : MinimumExpanding , QSizePolicy : : MinimumExpanding ) ;
2012-03-18 21:00:50 +00:00
connect ( _preview_green , SIGNAL ( clicked ( ) ) , this , SLOT ( selectGreen ( ) ) ) ;
2012-04-14 13:05:03 +00:00
form_layout - > addWidget ( _preview_green , 2 , 0 ) ;
2012-03-18 19:51:06 +00:00
2012-04-14 13:05:03 +00:00
label = new QLabel ( tr ( " Blue preview, click to edit " ) , form ) ;
label - > setSizePolicy ( QSizePolicy : : MinimumExpanding , QSizePolicy : : Minimum ) ;
label - > setMinimumWidth ( 150 ) ;
label - > setMaximumWidth ( 200 ) ;
label - > setWordWrap ( true ) ;
form_layout - > addWidget ( label , 3 , 1 ) ;
2012-03-31 11:32:03 +00:00
_preview_blue = new PreviewColorGradation ( form , _current , COLORGRADATIONBAND_BLUE ) ;
2012-04-14 13:05:03 +00:00
_preview_blue - > setMinimumHeight ( 30 ) ;
_preview_blue - > setMaximumHeight ( 60 ) ;
_preview_blue - > setSizePolicy ( QSizePolicy : : MinimumExpanding , QSizePolicy : : MinimumExpanding ) ;
2012-03-18 21:00:50 +00:00
connect ( _preview_blue , SIGNAL ( clicked ( ) ) , this , SLOT ( selectBlue ( ) ) ) ;
2012-04-14 13:05:03 +00:00
form_layout - > addWidget ( _preview_blue , 3 , 0 ) ;
2012-03-18 19:51:06 +00:00
2012-04-14 13:05:03 +00:00
label = new QLabel ( tr ( " Final preview " ) , form ) ;
label - > setSizePolicy ( QSizePolicy : : MinimumExpanding , QSizePolicy : : Minimum ) ;
label - > setMinimumWidth ( 150 ) ;
label - > setMaximumWidth ( 200 ) ;
label - > setWordWrap ( true ) ;
form_layout - > addWidget ( label , 4 , 1 ) ;
2012-03-31 11:32:03 +00:00
_preview_final = new PreviewColorGradation ( form , _current , COLORGRADATIONBAND_FINAL ) ;
2012-04-14 13:05:03 +00:00
_preview_final - > setMinimumHeight ( 30 ) ;
_preview_final - > setMaximumHeight ( 60 ) ;
_preview_final - > setSizePolicy ( QSizePolicy : : MinimumExpanding , QSizePolicy : : MinimumExpanding ) ;
form_layout - > addWidget ( _preview_final , 4 , 0 ) ;
2012-12-24 14:13:19 +00:00
2012-03-29 20:19:50 +00:00
buttons = new QWidget ( this ) ;
layout ( ) - > addWidget ( buttons ) ;
buttons - > setLayout ( new QHBoxLayout ( ) ) ;
2012-12-24 14:13:19 +00:00
2012-03-29 20:19:50 +00:00
_button_accept = new QPushButton ( tr ( " Validate " ) , buttons ) ;
buttons - > layout ( ) - > addWidget ( _button_accept ) ;
QObject : : connect ( _button_accept , SIGNAL ( clicked ( ) ) , this , SLOT ( accept ( ) ) ) ;
_button_revert = new QPushButton ( tr ( " Revert " ) , buttons ) ;
buttons - > layout ( ) - > addWidget ( _button_revert ) ;
QObject : : connect ( _button_revert , SIGNAL ( clicked ( ) ) , this , SLOT ( revert ( ) ) ) ;
_button_cancel = new QPushButton ( tr ( " Cancel " ) , buttons ) ;
buttons - > layout ( ) - > addWidget ( _button_cancel ) ;
QObject : : connect ( _button_cancel , SIGNAL ( clicked ( ) ) , this , SLOT ( reject ( ) ) ) ;
_curve = curveCreate ( ) ;
2012-02-20 21:17:13 +00:00
2012-02-28 13:45:11 +00:00
setWindowTitle ( tr ( " Paysages 3D - Color gradation editor " ) ) ;
2012-04-14 13:05:03 +00:00
resize ( 900 , 600 ) ;
2012-02-20 21:17:13 +00:00
revert ( ) ;
}
DialogColorGradation : : ~ DialogColorGradation ( )
{
2012-03-08 15:10:25 +00:00
colorGradationDelete ( _current ) ;
2012-03-08 15:56:44 +00:00
curveDelete ( _curve ) ;
2012-02-20 21:17:13 +00:00
}
bool DialogColorGradation : : getGradation ( QWidget * parent , ColorGradation * gradation )
{
int result ;
DialogColorGradation * dialog = new DialogColorGradation ( parent , gradation ) ;
result = dialog - > exec ( ) ;
delete dialog ;
return ( result ! = 0 ) ? true : false ;
}
2012-12-24 14:13:19 +00:00
void DialogColorGradation : : closeEvent ( QCloseEvent * )
2012-02-20 21:17:13 +00:00
{
reject ( ) ;
}
void DialogColorGradation : : accept ( )
{
2012-03-08 15:10:25 +00:00
colorGradationCopy ( _current , _base ) ;
2012-02-20 21:17:13 +00:00
QDialog : : accept ( ) ;
}
void DialogColorGradation : : revert ( )
{
2012-03-29 20:19:50 +00:00
_selected = 0 ;
2012-03-08 15:10:25 +00:00
colorGradationCopy ( _base , _current ) ;
2012-02-20 21:17:13 +00:00
revertToCurrent ( ) ;
}
2012-03-18 21:00:50 +00:00
void DialogColorGradation : : selectRed ( )
2012-02-20 21:17:13 +00:00
{
2012-03-08 15:56:44 +00:00
colorGradationGetRedCurve ( _current , _curve ) ;
_curve_editor - > setCurve ( _curve ) ;
2012-03-31 11:32:03 +00:00
_curve_editor - > setPenColor ( QColor ( 255 , 0 , 0 ) ) ;
2012-03-29 20:19:50 +00:00
_selected = 1 ;
2012-02-20 21:17:13 +00:00
}
2012-03-18 21:00:50 +00:00
void DialogColorGradation : : selectGreen ( )
{
colorGradationGetGreenCurve ( _current , _curve ) ;
_curve_editor - > setCurve ( _curve ) ;
2012-03-31 11:32:03 +00:00
_curve_editor - > setPenColor ( QColor ( 0 , 200 , 0 ) ) ;
2012-03-29 20:19:50 +00:00
_selected = 2 ;
2012-03-18 21:00:50 +00:00
}
void DialogColorGradation : : selectBlue ( )
{
colorGradationGetBlueCurve ( _current , _curve ) ;
_curve_editor - > setCurve ( _curve ) ;
2012-03-31 11:32:03 +00:00
_curve_editor - > setPenColor ( QColor ( 0 , 0 , 255 ) ) ;
2012-03-29 20:19:50 +00:00
_selected = 3 ;
}
void DialogColorGradation : : updateColors ( )
{
Curve * curve ;
2012-12-24 14:13:19 +00:00
2012-03-29 20:19:50 +00:00
curve = curveCreate ( ) ;
_curve_editor - > getCurve ( curve ) ;
2012-12-24 14:13:19 +00:00
2012-03-29 20:19:50 +00:00
switch ( _selected )
{
case 0 :
_preview_red - > update ( ) ;
_preview_green - > update ( ) ;
_preview_blue - > update ( ) ;
break ;
case 1 :
colorGradationSetRedCurve ( _current , curve ) ;
_preview_red - > update ( ) ;
break ;
case 2 :
colorGradationSetGreenCurve ( _current , curve ) ;
_preview_green - > update ( ) ;
break ;
case 3 :
colorGradationSetBlueCurve ( _current , curve ) ;
_preview_blue - > update ( ) ;
break ;
default :
;
}
_preview_final - > update ( ) ;
2012-12-24 14:13:19 +00:00
2012-03-29 20:19:50 +00:00
curveDelete ( curve ) ;
2012-03-18 21:00:50 +00:00
}
void DialogColorGradation : : revertToCurrent ( )
{
2012-03-29 20:19:50 +00:00
updateColors ( ) ;
2012-03-18 21:00:50 +00:00
selectRed ( ) ;
}