diff --git a/mandelbulber2/qt/animation_value_chart_widget.cpp b/mandelbulber2/qt/animation_value_chart_widget.cpp index f254e2073..88d27f860 100644 --- a/mandelbulber2/qt/animation_value_chart_widget.cpp +++ b/mandelbulber2/qt/animation_value_chart_widget.cpp @@ -143,6 +143,7 @@ void cAnimationValueChartWidget::paintEvent(QPaintEvent *event) painter.setPen(pen); painter.drawText(width() / 2, fontPixelSize, "Parameter: " + animationPath.parameterName); } + void cAnimationValueChartWidget::SetAnimationPath(const cAnimationPath &path) { animationPath = path; @@ -204,8 +205,14 @@ void cAnimationValueChartWidget::mouseMoveEvent(QMouseEvent *event) if (mouseDragStarted) { - qDebug() << pressedKeyIndex << event->x() << event->y(); emit update(); + + // calculate keyframe number and value when x and y coordinates in the widget are known + + double value = + max - (event->y() - margin * height()) / ((1.0 - 2.0 * margin) * height()) * (max - min); + + emit signalUpdateKey(pressedKeyIndex, value); } } } diff --git a/mandelbulber2/qt/animation_value_chart_widget.h b/mandelbulber2/qt/animation_value_chart_widget.h index 5fae86170..eb225beda 100644 --- a/mandelbulber2/qt/animation_value_chart_widget.h +++ b/mandelbulber2/qt/animation_value_chart_widget.h @@ -42,6 +42,9 @@ public slots: void slotZoomOut(); void slotSetCurrentFrame(int frame); +signals: + void signalUpdateKey(int key, double value); + private: void paintEvent(QPaintEvent *event) override; void mouseMoveEvent(QMouseEvent *event) override; diff --git a/mandelbulber2/src/animation_keyframes.cpp b/mandelbulber2/src/animation_keyframes.cpp index 4c4ce1a81..4d23ea698 100644 --- a/mandelbulber2/src/animation_keyframes.cpp +++ b/mandelbulber2/src/animation_keyframes.cpp @@ -178,6 +178,9 @@ cKeyframeAnimation::cKeyframeAnimation(cInterface *_interface, std::shared_ptrtoolButton_chartZoomOut, &QToolButton::clicked, ui->widgetValueChart, &cAnimationValueChartWidget::slotZoomOut); + connect(ui->widgetValueChart, &cAnimationValueChartWidget::signalUpdateKey, this, + &cKeyframeAnimation::slotUpdateKeyByChart); + table = ui->tableWidget_keyframe_animation; // add default parameters for animation @@ -2434,6 +2437,23 @@ void cKeyframeAnimation::slotClickedPrevFrame() } } +void cKeyframeAnimation::slotUpdateKeyByChart(int key, double value) +{ + if (table->currentRow() >= reservedRows) + { + cAnimationFrames::sAnimationFrame frame = keyframes->GetFrame(key); + cOneParameter parameter = + frame.parameters.GetAsOneParameter(GetParameterName(table->currentRow())); + parameter.Set(value, valueActual); + frame.parameters.SetFromOneParameter(GetParameterName(table->currentRow()), parameter); + keyframes->ModifyFrame(key, frame); + + const int parameterIndex = rowParameter.at(table->currentRow()); + const int vectorComponentIndex = table->currentRow() - parameterRows.at(parameterIndex); + UpdateAnimationPathSingleParameter(parameterIndex, vectorComponentIndex); + } +} + cKeyframeRenderThread::cKeyframeRenderThread(QString &_settingsText) : QThread() { settingsText = _settingsText; diff --git a/mandelbulber2/src/animation_keyframes.hpp b/mandelbulber2/src/animation_keyframes.hpp index c73d92390..f7e93edb1 100644 --- a/mandelbulber2/src/animation_keyframes.hpp +++ b/mandelbulber2/src/animation_keyframes.hpp @@ -151,6 +151,7 @@ private slots: void slotSliderMovedActualFrame(int); void slotClickedNextFrame(); void slotClickedPrevFrame(); + void slotUpdateKeyByChart(int key, double value); private: void PrepareTable();