Automation Node fine tuning with double-click (Rewrites #5292) (#5923)

Co-authored-by: tecknixia <50790262+tecknixia@users.noreply.github.com>
This commit is contained in:
IanCaio
2021-03-27 23:32:51 -03:00
committed by GitHub
parent 372fe3bdcf
commit 3ab86fa381
2 changed files with 74 additions and 0 deletions

View File

@@ -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();

View File

@@ -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<float>(),
m_pattern->firstObject()->maxValue<float>(),
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;