13 #include <QDialogButtonBox>
14 #include <QDoubleValidator>
15 #include <QFormLayout>
16 #include <QGraphicsSceneMouseEvent>
17 #include <QHBoxLayout>
20 #include <QPushButton>
21 #include <QResizeEvent>
22 #include <QToolButton>
23 #include <QVBoxLayout>
36 emit
resizeSignal(event->size().width(), event->size().height());
43 , _interp(
T_CURVE::kMonotoneSpline)
61 setSceneRect(-9, -7, width, height);
71 for (
auto & _cv :
_cvs)
82 auto newIndex =
_cvs.size() - 1;
105 if (((event->key() == Qt::Key_Backspace) || (event->key() == Qt::Key_Delete)) && (
_selectedItem >= 0)) {
114 QPointF pos = mouseEvent->scenePos();
116 QList<QGraphicsItem *> itemList = items(pos);
117 if (itemList.empty()) {
121 }
else if (itemList[0]->zValue() == 2) {
124 for (
int i = 0; i < numCircle; i++) {
126 if (obj == itemList[0]) {
134 if (mouseEvent->buttons() == Qt::LeftButton) {
136 double myx = pos.x() /
_width;
152 auto *menu =
new QMenu(event->widget());
153 QAction *deleteAction = menu->addAction(tr(
"Delete Point"));
155 QAction *action = menu->exec(event->screenPos());
156 if (action == deleteAction)
164 QPointF point = mouseEvent->scenePos();
243 _curvePoly = addPolygon(QPolygonF(), QPen(Qt::black, 1.0), QBrush(Qt::darkGray));
247 poly.append(QPointF(
_width, 0));
248 poly.append(QPointF(0, 0));
249 for (
int i = 0; i < 1000; i++) {
250 double x = i / 1000.0;
253 poly.append(QPointF(
_width, 0));
265 int numCV =
_cvs.size();
266 for (
int i = 0; i < numCV; i++) {
270 pen = QPen(Qt::white, 1.0);
272 pen = QPen(Qt::black, 1.0);
276 circle->setFlag(QGraphicsItem::ItemIsMovable,
true);
277 circle->setZValue(2);
285 auto *mainLayout =
new QHBoxLayout();
286 mainLayout->setMargin(0);
288 auto *edits =
new QWidget;
289 auto *editsLayout =
new QFormLayout;
290 editsLayout->setMargin(0);
291 edits->setLayout(editsLayout);
294 auto *posValidator =
new QDoubleValidator(0.0, 1.0, 6,
_selPosEdit);
297 if (pLabel.isEmpty()) {
298 posLabel = tr(
"Selected Position:");
305 auto *valValidator =
new QDoubleValidator(0.0, 1.0, 6,
_selValEdit);
308 if (vLabel.isEmpty()) {
309 valLabel = tr(
"Selected Value:");
316 if (iLabel.isEmpty()) {
317 interpLabel = tr(
"Interp:");
319 interpLabel = iLabel;
331 curveView->setFrameShape(QFrame::StyledPanel);
332 curveView->setFrameShadow(QFrame::Sunken);
333 curveView->setLineWidth(1);
334 curveView->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
335 curveView->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
337 curveView->setScene(
_scene);
338 curveView->setTransform(QTransform().scale(1, -1));
339 curveView->setRenderHints(QPainter::Antialiasing);
341 mainLayout->addWidget(edits);
342 mainLayout->addWidget(curveView);
344 auto *expandButton =
new QToolButton(
this);
345 expandButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding);
346 QIcon expandIcon = QIcon::fromTheme(
"arrow-right", QIcon::fromTheme(
"go-next"));
347 auto *detailAction =
new QAction(expandIcon, tr(
"&Expand..."));
348 expandButton->setDefaultAction(detailAction);
349 mainLayout->addWidget(expandButton);
351 connect(expandButton, SIGNAL(triggered(QAction *)),
this, SLOT(
openDetail()));
353 mainLayout->setStretchFactor(curveView, 100);
354 setLayout(mainLayout);
369 connect(curveView, SIGNAL(resizeSignal(
int,
int)),
_scene, SLOT(resize(
int,
int)));
377 posStr.setNum(pos,
'f', 3);
381 valStr.setNum(val,
'f', 3);
389 double pos = QString(
_selPosEdit->text()).toDouble();
390 _selPosEdit->setText(QString(tr(
"%1")).arg(pos, 0,
'f', 3));
397 double val = QString(
_selValEdit->text()).toDouble();
399 _selValEdit->setText(QString(tr(
"%1")).arg(val, 0,
'f', 3));
405 auto *dialog =
new QDialog();
406 dialog->setMinimumWidth(1024);
407 dialog->setMinimumHeight(400);
408 auto *
curve =
new ExprCurve(
nullptr, QString(), QString(), QString(),
false);
411 const std::vector<T_CURVE::CV> &data =
_scene->
_cvs;
412 for (
const auto & i : data)
413 curve->addPoint(i._pos, i._val, i._interp);
415 auto *layout =
new QVBoxLayout();
416 dialog->setLayout(layout);
417 layout->addWidget(
curve);
418 auto *buttonbar =
new QDialogButtonBox();
419 buttonbar->setStandardButtons(QDialogButtonBox::Cancel | QDialogButtonBox::Ok);
420 connect(buttonbar, SIGNAL(accepted()), dialog, SLOT(accept()));
421 connect(buttonbar, SIGNAL(rejected()), dialog, SLOT(reject()));
422 layout->addWidget(buttonbar);
424 if (dialog->exec() == QDialog::Accepted) {
427 const auto &dataNew =
curve->_scene->_cvs;
428 for (
const auto & i : dataNew)
429 addPoint(i._pos, i._val, i._interp);
433 if (dialog->exec() == QDialog::Accepted) {
436 const auto &dataNew =
curve->_scene->_cvs;
437 for (
const auto & i : dataNew)
438 addPoint(i._pos, i._val, i._interp);
void resizeEvent(QResizeEvent *event) override
void resizeSignal(int width, int height)
void cvSelected(double x, double y, T_INTERP interp)
void mousePressEvent(QGraphicsSceneMouseEvent *mouseEvent) override
T_CURVE::InterpType T_INTERP
void removePoint(int index)
void mouseReleaseEvent(QGraphicsSceneMouseEvent *mouseEvent) override
QGraphicsRectItem * _baseRect
void resize(int width, int height)
void selValChanged(double val)
void mouseMoveEvent(QGraphicsSceneMouseEvent *mouseEvent) override
std::vector< QGraphicsEllipseItem * > _circleObjects
void addPoint(double x, double y, T_INTERP interp, bool select=true)
QGraphicsPolygonItem * _curvePoly
void contextMenuEvent(QGraphicsSceneContextMenuEvent *event) override
void interpChanged(int interp)
KSeExpr::Curve< double > T_CURVE
std::vector< T_CURVE::CV > _cvs
void selPosChanged(double pos)
void keyPressEvent(QKeyEvent *event) override
void cvSelectedSlot(double pos, double val, T_INTERP interp)
void addPoint(double x, double y, T_INTERP interp, bool select=false)
ExprCurve(QWidget *parent=nullptr, QString pLabel=QString(), QString vLabel=QString(), QString iLabel=QString(), bool expandable=true)
void selValChangedSignal(double val)
QComboBox * _interpComboBox
void selPosChangedSignal(double pos)
Interpolation curve class for double->double and double->Vec3D.
InterpType
Supported interpolation types.
void preparePoints()
Prepares points for evaluation (sorts and computes boundaries, clamps extrema)
T getValue(double param) const
Evaluates curve and returns full value.
void addPoint(double position, const T &val, InterpType type)
Adds a point to the curve.
CV getLowerBoundCV(double param) const
KSeExpr::CurveFuncX curve
double clamp(double x, double lo, double hi)