26#include <QDoubleValidator>
27#include <QGraphicsSceneMouseEvent>
32#include <QResizeEvent>
33#include <QDialogButtonBox>
44 emit
resizeSignal(event->size().width(), event->size().height());
48 : _curve(new
T_CURVE), _width(320), _height(170), _interp(
T_CURVE::kMonotoneSpline), _selectedItem(-1),
49 _curvePoly(0), _baseRect(0), _lmb(false) {
60 setSceneRect(-9, -7, width, height);
78 int newIndex =
_cvs.size() - 1;
98 if (((event->key() == Qt::Key_Backspace) || (event->key() == Qt::Key_Delete)) && (
_selectedItem >= 0)) {
106 QPointF pos = mouseEvent->scenePos();
108 QList<QGraphicsItem *> itemList = items(pos);
109 if (itemList.empty()) {
113 }
else if (itemList[0]->zValue() == 2) {
116 for (
int i = 0; i < numCircle; i++) {
118 if (obj == itemList[0]) {
126 if (mouseEvent->buttons() == Qt::LeftButton) {
128 double myx = pos.x() /
_width;
142 QMenu *menu =
new QMenu(event->widget());
143 QAction *deleteAction = menu->addAction(
"Delete Point");
145 QAction *action = menu->exec(event->screenPos());
152 QPointF
point = mouseEvent->scenePos();
169 Q_UNUSED(mouseEvent);
223 _curvePoly = addPolygon(QPolygonF(), QPen(Qt::black, 1.0), QBrush(Qt::darkGray));
227 poly.append(QPointF(
_width, 0));
228 poly.append(QPointF(0, 0));
229 for (
int i = 0; i < 1000; i++) {
230 double x = i / 1000.0;
233 poly.append(QPointF(
_width, 0));
244 const int numCV =
_cvs.size();
245 for (
int i = 0; i < numCV; i++) {
249 pen = QPen(Qt::white, 1.0);
251 pen = QPen(Qt::black, 1.0);
255 circle->setFlag(QGraphicsItem::ItemIsMovable,
true);
256 circle->setZValue(2);
261 : QWidget(parent), _scene(0), _selPosEdit(0), _selValEdit(0), _interpComboBox(0) {
263 QHBoxLayout *mainLayout =
new QHBoxLayout();
264 mainLayout->setSpacing(2);
265 mainLayout->setMargin(4);
267 QWidget *edits =
new QWidget;
268 QVBoxLayout *editsLayout =
new QVBoxLayout;
269 editsLayout->setAlignment(Qt::AlignTop);
270 editsLayout->setSpacing(0);
271 editsLayout->setMargin(0);
272 edits->setLayout(editsLayout);
274 QWidget *selPos =
new QWidget;
275 QHBoxLayout *selPosLayout =
new QHBoxLayout;
276 selPosLayout->setSpacing(1);
277 selPosLayout->setMargin(1);
278 selPos->setLayout(selPosLayout);
280 QDoubleValidator *posValidator =
new QDoubleValidator(0.0, 1.0, 6,
_selPosEdit);
282 int editwidth = QFontMetrics(font()).width(
"9.999") + 8;
285 selPosLayout->addStretch(50);
287 if (pLabel.isEmpty()) {
288 posLabel =
new QLabel(
"Selected Position: ");
290 posLabel =
new QLabel(pLabel);
292 selPosLayout->addWidget(posLabel);
295 QWidget *selVal =
new QWidget;
296 QBoxLayout *selValLayout =
new QHBoxLayout;
297 selValLayout->setSpacing(1);
298 selValLayout->setMargin(1);
299 selVal->setLayout(selValLayout);
301 QDoubleValidator *valValidator =
new QDoubleValidator(0.0, 1.0, 6,
_selValEdit);
305 selValLayout->addStretch(50);
307 if (vLabel.isEmpty()) {
308 valLabel =
new QLabel(
"Selected Value: ");
310 valLabel =
new QLabel(vLabel);
312 selValLayout->addWidget(valLabel);
325 editsLayout->addWidget(selPos);
326 editsLayout->addWidget(selVal);
329 QFrame *curveFrame =
new QFrame;
330 curveFrame->setFrameShape(QFrame::Panel);
331 curveFrame->setFrameShadow(QFrame::Sunken);
332 curveFrame->setLineWidth(1);
333 QHBoxLayout *curveFrameLayout =
new QHBoxLayout;
334 curveFrameLayout->setMargin(0);
336 curveView->setFrameShape(QFrame::Panel);
337 curveView->setFrameShadow(QFrame::Sunken);
338 curveView->setLineWidth(1);
339 curveView->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
340 curveView->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
342 curveView->setScene(
_scene);
343 curveView->setTransform(QTransform().scale(1, -1));
344 curveView->setRenderHints(QPainter::Antialiasing);
345 curveFrameLayout->addWidget(curveView);
346 curveFrame->setLayout(curveFrameLayout);
348 mainLayout->addWidget(edits);
349 mainLayout->addWidget(curveFrame);
351 QPushButton *expandButton =
new QPushButton(
">");
352 expandButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding);
353 expandButton->setFixedWidth(15);
354 mainLayout->addWidget(expandButton);
356 connect(expandButton, SIGNAL(clicked()),
this, SLOT(
openDetail()));
358 mainLayout->setStretchFactor(curveFrame, 100);
359 setLayout(mainLayout);
374 connect(curveView, SIGNAL(resizeSignal(
int,
int)),
_scene, SLOT(resize(
int,
int)));
380 if (pos >= 0.0) posStr.setNum(pos,
'f', 3);
383 if (val >= 0.0) valStr.setNum(val,
'f', 3);
390 double pos = QString(
_selPosEdit->text()).toDouble();
391 _selPosEdit->setText(QString(
"%1").arg(pos, 0,
'f', 3));
397 double val = QString(
_selValEdit->text()).toDouble();
399 _selValEdit->setText(QString(
"%1").arg(val, 0,
'f', 3));
404 QDialog *dialog =
new QDialog();
405 dialog->setMinimumWidth(1024);
406 dialog->setMinimumHeight(400);
410 const std::vector<T_CURVE::CV> &data =
_scene->
_cvs;
411 typedef std::vector<T_CURVE::CV>::const_iterator ITERATOR;
412 for (ITERATOR i = data.begin(); i != data.end(); ++i)
curve->addPoint(i->_pos, i->_val, i->_interp);
414 QVBoxLayout *layout =
new QVBoxLayout();
415 dialog->setLayout(layout);
416 layout->addWidget(
curve);
417 QDialogButtonBox *buttonbar =
new QDialogButtonBox();
418 buttonbar->setStandardButtons(QDialogButtonBox::Cancel | QDialogButtonBox::Ok);
419 connect(buttonbar, SIGNAL(accepted()), dialog, SLOT(accept()));
420 connect(buttonbar, SIGNAL(rejected()), dialog, SLOT(reject()));
421 layout->addWidget(buttonbar);
423 if (dialog->exec() == QDialog::Accepted) {
426 const std::vector<T_CURVE::CV> &dataNew =
curve->_scene->_cvs;
427 typedef std::vector<T_CURVE::CV>::const_iterator ITERATOR;
428 for (ITERATOR i = dataNew.begin(); i != dataNew.end(); ++i)
addPoint(i->_pos, i->_val, i->_interp);
432 if (dialog->exec() == QDialog::Accepted) {
435 const std::vector<T_CURVE::CV> &dataNew =
curve->_scene->_cvs;
436 typedef std::vector<T_CURVE::CV>::const_iterator ITERATOR;
437 for (ITERATOR i = dataNew.begin(); i != dataNew.end(); ++i)
addPoint(i->_pos, i->_val, i->_interp);
virtual void resizeEvent(QResizeEvent *event)
void resizeSignal(int width, int height)
void cvSelected(double x, double y, T_INTERP interp)
virtual void mousePressEvent(QGraphicsSceneMouseEvent *mouseEvent)
void resize(const int width, const int height)
virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *mouseEvent)
QGraphicsRectItem * _baseRect
void selValChanged(double val)
void removePoint(const int index)
T_CURVE::InterpType T_INTERP
std::vector< QGraphicsEllipseItem * > _circleObjects
virtual void keyPressEvent(QKeyEvent *event)
void addPoint(double x, double y, const T_INTERP interp, const bool select=true)
QGraphicsPolygonItem * _curvePoly
virtual void contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
std::vector< T_CURVE::CV > _cvs
SeExpr2::Curve< double > T_CURVE
void selPosChanged(double pos)
virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *mouseEvent)
void interpChanged(const int interp)
void addPoint(const double x, const double y, const T_INTERP interp, bool select=false)
void cvSelectedSlot(double pos, double val, T_INTERP interp)
void selValChangedSignal(double val)
QComboBox * _interpComboBox
void selPosChangedSignal(double pos)
ExprCurve(QWidget *parent=0, QString pLabel="", QString vLabel="", QString iLabel="", bool expandable=true)
Interpolation curve class for double->double and double->Vec3D.
CV getLowerBoundCV(const double param) const
InterpType
Supported interpolation types.
T getValue(const double param) const
Evaluates curve and returns full value.
void addPoint(double position, const T &val, InterpType type)
Adds a point to the curve.
void preparePoints()
Prepares points for evaluation (sorts and computes boundaries, clamps extrema)
double clamp(double x, double lo, double hi)
SeExpr2::CurveFuncX curve
</pre >< h3 > A simple variable reference</h3 > This is not a very interesting subclass of expression until we add some additional variables Variables on some applications may be very dynamic In this we only need x
This is the same as the prman cellnoise function< br ></div >< br > float< b > float y< br > float< b > float y
The result is computed int int< br >< div style="margin-left: 40px;"> Picks values randomly between loRange and hiRange based on supplied index(which is automatically hashed).