2012-05-29 13:32:23 +00:00
# include "dialogcurve.h"
# include <QVBoxLayout>
# include <QHBoxLayout>
# include <QGridLayout>
# include <QImage>
# include <QLabel>
# include <QColor>
# include <QPainter>
# include <QSlider>
# include <QScrollArea>
# include <QPushButton>
# 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 ;
_base = curve ;
_current = curveCreate ( ) ;
curveCopy ( _base , _current ) ;
setLayout ( new QVBoxLayout ( ) ) ;
form = new QWidget ( this ) ;
form_layout = new QGridLayout ( ) ;
form - > setLayout ( form_layout ) ;
layout ( ) - > addWidget ( form ) ;
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 ( ) ) ;
_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 ( ) ) ) ;
setWindowTitle ( tr ( " Paysages 3D - Curve editor " ) ) ;
resize ( 900 , 600 ) ;
revert ( ) ;
}
DialogCurve : : ~ DialogCurve ( )
{
curveDelete ( _current ) ;
}
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 ) ;
curveCopy ( _current , _base ) ;
QDialog : : accept ( ) ;
}
void DialogCurve : : revert ( )
{
curveCopy ( _base , _current ) ;
revertToCurrent ( ) ;
}
void DialogCurve : : revertToCurrent ( )
{
_curve_editor - > setCurve ( _current ) ;
}