2012-05-29 13:32:23 +00:00
# include "dialogcurve.h"
# include <QGridLayout>
# include <QLabel>
# include <QPushButton>
2013-11-15 22:26:44 +00:00
# include "Curve.h"
2012-05-29 13:32:23 +00:00
# include "baseform.h"
# include "tools.h"
# include "widgetcurveeditor.h"
/**************** Dialog ****************/
2012-06-27 12:49:51 +00:00
DialogCurve : : DialogCurve ( QWidget * parent , Curve * curve , double xmin , double xmax , double ymin , double ymax , QString xlabel , QString ylabel ) : QDialog ( parent )
2012-05-29 13:32:23 +00:00
{
QWidget * buttons ;
QWidget * form ;
QGridLayout * form_layout ;
QLabel * label ;
2013-04-17 12:29:51 +00:00
2012-05-29 13:32:23 +00:00
_base = curve ;
2013-11-15 22:26:44 +00:00
_current = new Curve ;
_base - > copy ( _current ) ;
2012-05-29 13:32:23 +00:00
setLayout ( new QVBoxLayout ( ) ) ;
2013-04-17 12:29:51 +00:00
2012-05-29 13:32:23 +00:00
form = new QWidget ( this ) ;
form_layout = new QGridLayout ( ) ;
form - > setLayout ( form_layout ) ;
layout ( ) - > addWidget ( form ) ;
2013-04-17 12:29:51 +00:00
2012-05-29 13:32:23 +00:00
label = new QLabel ( tr ( " This is the curve editor. \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 ) ;
_curve_editor = new WidgetCurveEditor ( form , xmin , xmax , ymin , ymax ) ;
2012-06-27 12:49:51 +00:00
_curve_editor - > setAxisLabels ( xlabel , ylabel ) ;
2012-05-29 13:32:23 +00:00
_curve_editor - > setSizePolicy ( QSizePolicy : : MinimumExpanding , QSizePolicy : : MinimumExpanding ) ;
form_layout - > addWidget ( _curve_editor , 0 , 0 ) ;
buttons = new QWidget ( this ) ;
layout ( ) - > addWidget ( buttons ) ;
buttons - > setLayout ( new QHBoxLayout ( ) ) ;
2013-04-17 12:29:51 +00:00
2012-08-13 19:19:19 +00:00
_button_cancel = new QPushButton ( tr ( " Cancel " ) , buttons ) ;
2013-04-17 12:29:51 +00:00
_button_cancel - > setIcon ( QIcon ( getDataPath ( " images/cancel.png " ) ) ) ;
2012-08-13 19:19:19 +00:00
buttons - > layout ( ) - > addWidget ( _button_cancel ) ;
QObject : : connect ( _button_cancel , SIGNAL ( clicked ( ) ) , this , SLOT ( reject ( ) ) ) ;
2012-05-29 13:32:23 +00:00
_button_revert = new QPushButton ( tr ( " Revert " ) , buttons ) ;
2013-04-17 12:29:51 +00:00
_button_revert - > setIcon ( QIcon ( getDataPath ( " images/revert.png " ) ) ) ;
2012-05-29 13:32:23 +00:00
buttons - > layout ( ) - > addWidget ( _button_revert ) ;
QObject : : connect ( _button_revert , SIGNAL ( clicked ( ) ) , this , SLOT ( revert ( ) ) ) ;
2012-08-13 19:19:19 +00:00
_button_accept = new QPushButton ( tr ( " Validate " ) , buttons ) ;
2013-04-17 12:29:51 +00:00
_button_accept - > setIcon ( QIcon ( getDataPath ( " images/apply.png " ) ) ) ;
2012-08-13 19:19:19 +00:00
buttons - > layout ( ) - > addWidget ( _button_accept ) ;
QObject : : connect ( _button_accept , SIGNAL ( clicked ( ) ) , this , SLOT ( accept ( ) ) ) ;
2012-05-29 13:32:23 +00:00
setWindowTitle ( tr ( " Paysages 3D - Curve editor " ) ) ;
resize ( 900 , 600 ) ;
revert ( ) ;
}
DialogCurve : : ~ DialogCurve ( )
{
2013-11-15 22:26:44 +00:00
delete _current ;
2012-05-29 13:32:23 +00:00
}
2012-06-27 12:49:51 +00:00
bool DialogCurve : : getCurve ( QWidget * parent , Curve * curve , double xmin , double xmax , double ymin , double ymax , QString xlabel , QString ylabel )
2012-05-29 13:32:23 +00:00
{
int result ;
2012-06-27 12:49:51 +00:00
DialogCurve * dialog = new DialogCurve ( parent , curve , xmin , xmax , ymin , ymax , xlabel , ylabel ) ;
2012-05-29 13:32:23 +00:00
result = dialog - > exec ( ) ;
delete dialog ;
return ( result ! = 0 ) ? true : false ;
}
2012-08-08 13:30:40 +00:00
void DialogCurve : : closeEvent ( QCloseEvent * )
2012-05-29 13:32:23 +00:00
{
reject ( ) ;
}
void DialogCurve : : accept ( )
{
_curve_editor - > getCurve ( _current ) ;
2013-11-15 22:26:44 +00:00
_current - > copy ( _base ) ;
2012-05-29 13:32:23 +00:00
QDialog : : accept ( ) ;
}
void DialogCurve : : revert ( )
{
2013-11-15 22:26:44 +00:00
_base - > copy ( _current ) ;
2012-05-29 13:32:23 +00:00
revertToCurrent ( ) ;
}
void DialogCurve : : revertToCurrent ( )
{
_curve_editor - > setCurve ( _current ) ;
}