From 3ab86fa381305bbcd197f0ad641e950c7ef255d3 Mon Sep 17 00:00:00 2001 From: IanCaio Date: Sat, 27 Mar 2021 23:32:51 -0300 Subject: [PATCH] Automation Node fine tuning with double-click (Rewrites #5292) (#5923) Co-authored-by: tecknixia <50790262+tecknixia@users.noreply.github.com> --- include/AutomationEditor.h | 2 + src/gui/editors/AutomationEditor.cpp | 72 ++++++++++++++++++++++++++++ 2 files changed, 74 insertions(+) diff --git a/include/AutomationEditor.h b/include/AutomationEditor.h index e66ab665b..d52f3bc24 100644 --- a/include/AutomationEditor.h +++ b/include/AutomationEditor.h @@ -98,6 +98,7 @@ protected: void keyPressEvent(QKeyEvent * ke) override; void leaveEvent(QEvent * e) override; void mousePressEvent(QMouseEvent * mouseEvent) override; + void mouseDoubleClickEvent(QMouseEvent * mouseEvent) override; void mouseReleaseEvent(QMouseEvent * mouseEvent) override; void mouseMoveEvent(QMouseEvent * mouseEvent) override; void paintEvent(QPaintEvent * pe) override; @@ -112,6 +113,7 @@ protected: timeMap::iterator getNodeAt(int x, int y, bool outValue = false, int r = 5); void drawLine( int x0, float y0, int x1, float y1 ); + bool fineTuneValue(timeMap::iterator node, bool editingOutValue); protected slots: void play(); diff --git a/src/gui/editors/AutomationEditor.cpp b/src/gui/editors/AutomationEditor.cpp index c50c1ca05..ede66760c 100644 --- a/src/gui/editors/AutomationEditor.cpp +++ b/src/gui/editors/AutomationEditor.cpp @@ -398,6 +398,53 @@ void AutomationEditor::drawLine( int x0In, float y0, int x1In, float y1 ) +bool AutomationEditor::fineTuneValue(timeMap::iterator node, bool editingOutValue) +{ + if (node == m_pattern->getTimeMap().end()) { return false; } + + // Display dialog to edit the value + bool ok; + double value = QInputDialog::getDouble( + this, + tr("Edit Value"), + editingOutValue + ? tr("New outValue") + : tr("New inValue"), + editingOutValue + ? OUTVAL(node) + : INVAL(node), + m_pattern->firstObject()->minValue(), + m_pattern->firstObject()->maxValue(), + 3, + &ok + ); + + // If dialog failed return false + if (!ok) { return false; } + + // Set the new inValue/outValue + if (editingOutValue) + { + node.value().setOutValue(value); + } + else + { + // If the outValue is equal to the inValue we + // set both to the given value + if (OFFSET(node) == 0) + { + node.value().setOutValue(value); + } + node.value().setInValue(value); + } + + Engine::getSong()->setModified(); + return true; +} + + + + void AutomationEditor::mousePressEvent( QMouseEvent* mouseEvent ) { if( !validPattern() ) @@ -615,6 +662,31 @@ void AutomationEditor::mousePressEvent( QMouseEvent* mouseEvent ) +void AutomationEditor::mouseDoubleClickEvent(QMouseEvent * mouseEvent) +{ + if (!validPattern()) { return; } + + // If we double clicked outside the AutomationEditor viewport return + if (mouseEvent->y() <= TOP_MARGIN || mouseEvent->x() < VALUES_WIDTH) { return; } + + // Are we fine tuning the inValue or outValue? + const bool isOutVal = (m_editMode == DRAW_OUTVALUES); + timeMap::iterator clickedNode = getNodeAt(mouseEvent->x(), mouseEvent->y(), isOutVal); + + switch (m_editMode) + { + case DRAW: + case DRAW_OUTVALUES: + if (fineTuneValue(clickedNode, isOutVal)) { update(); } + break; + default: + break; + } +} + + + + void AutomationEditor::mouseReleaseEvent(QMouseEvent * mouseEvent ) { bool mustRepaint = false;