From edb4d31b81f1690efa70f4084acc479a28a163c3 Mon Sep 17 00:00:00 2001 From: Massimo Callegari Date: Mon, 11 Nov 2024 19:25:16 +0100 Subject: [PATCH] qmlui: increase position tool precision to 0.01 degrees --- engine/src/fixture.cpp | 2 +- engine/src/fixture.h | 2 +- qmlui/contextmanager.cpp | 2 +- qmlui/contextmanager.h | 2 +- qmlui/qml/CustomDoubleSpinBox.qml | 6 +++ qmlui/qml/fixturesfunctions/PositionTool.qml | 40 +++++++++++--------- 6 files changed, 32 insertions(+), 22 deletions(-) diff --git a/engine/src/fixture.cpp b/engine/src/fixture.cpp index 79153f8c5b..5535b13c3a 100644 --- a/engine/src/fixture.cpp +++ b/engine/src/fixture.cpp @@ -310,7 +310,7 @@ QVector Fixture::cmyChannels(int head) const return m_fixtureMode->heads().at(head).cmyChannels(); } -QList Fixture::positionToValues(int type, int degrees, bool isRelative) +QList Fixture::positionToValues(int type, float degrees, bool isRelative) { QList posList; // cache a list of channels processed, to avoid duplicates diff --git a/engine/src/fixture.h b/engine/src/fixture.h index 8dc2a49a42..f360210020 100644 --- a/engine/src/fixture.h +++ b/engine/src/fixture.h @@ -277,7 +277,7 @@ class Fixture : public QObject /** Return a list of DMX values based on the given position degrees * and the provided type (Pan or Tilt) */ - QList positionToValues(int type, int degrees, bool isRelative = false); + QList positionToValues(int type, float degrees, bool isRelative = false); /** Return a list of DMX values based on the given zoom degrees */ QList zoomToValues(float degrees, bool isRelative); diff --git a/qmlui/contextmanager.cpp b/qmlui/contextmanager.cpp index 6cb8c07e7e..c17520441b 100644 --- a/qmlui/contextmanager.cpp +++ b/qmlui/contextmanager.cpp @@ -1478,7 +1478,7 @@ void ContextManager::setChannelValueByType(int type, int value, bool isRelative, } } -void ContextManager::setPositionValue(int type, int degrees, bool isRelative) +void ContextManager::setPositionValue(int type, float degrees, bool isRelative) { // list to keep track of the already processed Fixture IDs QListfxIDs; diff --git a/qmlui/contextmanager.h b/qmlui/contextmanager.h index e41495eb5b..d39f8fada6 100644 --- a/qmlui/contextmanager.h +++ b/qmlui/contextmanager.h @@ -238,7 +238,7 @@ public slots: Q_INVOKABLE void setColorValue(QColor col, QColor wauv); /** Set a Pan/Tilt position in degrees */ - Q_INVOKABLE void setPositionValue(int type, int degrees, bool isRelative); + Q_INVOKABLE void setPositionValue(int type, float degrees, bool isRelative); /** Set Pan/Tilt values at half position */ Q_INVOKABLE void setPositionCenter(); diff --git a/qmlui/qml/CustomDoubleSpinBox.qml b/qmlui/qml/CustomDoubleSpinBox.qml index f60fe2a02b..628403e1e0 100644 --- a/qmlui/qml/CustomDoubleSpinBox.qml +++ b/qmlui/qml/CustomDoubleSpinBox.qml @@ -50,4 +50,10 @@ CustomSpinBox } onValueModified: realValue = value / Math.pow(10, decimals) + + function setValue(newValue) + { + value = newValue + realValue = newValue / Math.pow(10, decimals) + } } diff --git a/qmlui/qml/fixturesfunctions/PositionTool.qml b/qmlui/qml/fixturesfunctions/PositionTool.qml index 8aa9f3f910..c17fd4e160 100644 --- a/qmlui/qml/fixturesfunctions/PositionTool.qml +++ b/qmlui/qml/fixturesfunctions/PositionTool.qml @@ -36,11 +36,11 @@ Rectangle property int panMaxDegrees: 360 property int tiltMaxDegrees: 270 - property alias panDegrees: panSpinBox.value + property alias panDegrees: panSpinBox.realValue property int previousPanDegrees: 0 property bool relativePanValue: false - property alias tiltDegrees: tiltSpinBox.value + property alias tiltDegrees: tiltSpinBox.realValue property int previousTiltDegrees: 0 property bool relativeTiltValue: false @@ -63,7 +63,7 @@ Rectangle else { relativePanValue = false - panDegrees = Math.round(pan) + panDegrees = pan * Math.pow(10, panSpinBox.decimals) } var tilt = contextManager.getCurrentValue(QLCChannel.Tilt, true) @@ -75,7 +75,7 @@ Rectangle else { relativeTiltValue = false - tiltDegrees = Math.round(tilt) + tiltDegrees = tilt * Math.pow(10, tiltSpinBox.decimals) } } @@ -361,12 +361,13 @@ Rectangle label: "Pan" } - CustomSpinBox + CustomDoubleSpinBox { id: panSpinBox Layout.fillWidth: true - from: relativePanValue ? -panMaxDegrees : 0 - to: panMaxDegrees + realFrom: relativePanValue ? -panMaxDegrees : 0 + realTo: panMaxDegrees + realStep: 0.1 value: 0 suffix: "°" @@ -381,9 +382,10 @@ Rectangle tooltip: qsTr("Snap to the previous value") onClicked: { - var prev = (parseInt(panSpinBox.value / 45) * 45) - 45 + var prev = (parseInt(panSpinBox.realValue / 45) * 45) - 45 + console.log("---- PREV PAN " + prev) if (prev >= 0) - panSpinBox.value = prev + panSpinBox.setValue(prev * 100) } } IconButton @@ -394,9 +396,10 @@ Rectangle tooltip: qsTr("Snap to the next value") onClicked: { - var next = (parseInt(panSpinBox.value / 45) * 45) + 45 + var next = (parseInt(panSpinBox.realValue / 45) * 45) + 45 + console.log("---- NEXT PAN " + next) if (next <= panMaxDegrees) - panSpinBox.value = next + panSpinBox.setValue(next * 100) } } @@ -407,12 +410,13 @@ Rectangle label: "Tilt" } - CustomSpinBox + CustomDoubleSpinBox { id: tiltSpinBox Layout.fillWidth: true - from: relativeTiltValue ? -tiltMaxDegrees : 0 - to: tiltMaxDegrees + realFrom: relativeTiltValue ? -tiltMaxDegrees : 0 + realTo: tiltMaxDegrees + realStep: 0.1 value: 0 suffix: "°" @@ -430,9 +434,9 @@ Rectangle var fixedPos = tiltPositionsArray() for (var i = fixedPos.length - 1; i >= 0; i--) { - if (parseInt(fixedPos[i]) < tiltSpinBox.value) + if (parseInt(fixedPos[i]) < tiltDegrees) { - tiltSpinBox.value = parseInt(fixedPos[i]) + tiltSpinBox.setValue(parseInt(fixedPos[i]) * 100) break; } } @@ -449,9 +453,9 @@ Rectangle var fixedPos = tiltPositionsArray() for (var i = 0; i < fixedPos.length; i++) { - if (tiltSpinBox.value < parseInt(fixedPos[i])) + if (tiltDegrees < parseInt(fixedPos[i])) { - tiltSpinBox.value = parseInt(fixedPos[i]) + tiltSpinBox.setValue(parseInt(fixedPos[i]) * 100) break; } }