Skip to content

Commit

Permalink
qmlui: increase position tool precision to 0.01 degrees
Browse files Browse the repository at this point in the history
  • Loading branch information
mcallegari committed Nov 11, 2024
1 parent e8ecb67 commit edb4d31
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 22 deletions.
2 changes: 1 addition & 1 deletion engine/src/fixture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ QVector <quint32> Fixture::cmyChannels(int head) const
return m_fixtureMode->heads().at(head).cmyChannels();
}

QList<SceneValue> Fixture::positionToValues(int type, int degrees, bool isRelative)
QList<SceneValue> Fixture::positionToValues(int type, float degrees, bool isRelative)
{
QList<SceneValue> posList;
// cache a list of channels processed, to avoid duplicates
Expand Down
2 changes: 1 addition & 1 deletion engine/src/fixture.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<SceneValue> positionToValues(int type, int degrees, bool isRelative = false);
QList<SceneValue> positionToValues(int type, float degrees, bool isRelative = false);

/** Return a list of DMX values based on the given zoom degrees */
QList<SceneValue> zoomToValues(float degrees, bool isRelative);
Expand Down
2 changes: 1 addition & 1 deletion qmlui/contextmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
QList<quint32>fxIDs;
Expand Down
2 changes: 1 addition & 1 deletion qmlui/contextmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
6 changes: 6 additions & 0 deletions qmlui/qml/CustomDoubleSpinBox.qml
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,10 @@ CustomSpinBox
}

onValueModified: realValue = value / Math.pow(10, decimals)

function setValue(newValue)
{
value = newValue
realValue = newValue / Math.pow(10, decimals)
}
}
40 changes: 22 additions & 18 deletions qmlui/qml/fixturesfunctions/PositionTool.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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)
Expand All @@ -75,7 +75,7 @@ Rectangle
else
{
relativeTiltValue = false
tiltDegrees = Math.round(tilt)
tiltDegrees = tilt * Math.pow(10, tiltSpinBox.decimals)
}
}

Expand Down Expand Up @@ -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: "°"

Expand All @@ -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
Expand All @@ -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)
}
}

Expand All @@ -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: "°"

Expand All @@ -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;
}
}
Expand All @@ -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;
}
}
Expand Down

0 comments on commit edb4d31

Please sign in to comment.