Skip to content

Commit

Permalink
Partially implemented dragging of valus on the chart
Browse files Browse the repository at this point in the history
It works not correct when zoom is used
  • Loading branch information
buddhi1980 committed Nov 15, 2024
1 parent ef3398d commit ce71668
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 1 deletion.
9 changes: 8 additions & 1 deletion mandelbulber2/qt/animation_value_chart_widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions mandelbulber2/qt/animation_value_chart_widget.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
20 changes: 20 additions & 0 deletions mandelbulber2/src/animation_keyframes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,9 @@ cKeyframeAnimation::cKeyframeAnimation(cInterface *_interface, std::shared_ptr<c
connect(ui->toolButton_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
Expand Down Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions mandelbulber2/src/animation_keyframes.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ private slots:
void slotSliderMovedActualFrame(int);
void slotClickedNextFrame();
void slotClickedPrevFrame();
void slotUpdateKeyByChart(int key, double value);

private:
void PrepareTable();
Expand Down

0 comments on commit ce71668

Please sign in to comment.