Skip to content

Commit

Permalink
qmlui: handle keypad +/- including percentage
Browse files Browse the repository at this point in the history
  • Loading branch information
mcallegari committed Nov 29, 2020
1 parent e13c9ff commit 54be73a
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 17 deletions.
52 changes: 41 additions & 11 deletions engine/src/keypadparser.cpp
Expand Up @@ -18,14 +18,14 @@
*/

#include "keypadparser.h"

#include "qlcmacros.h"

KeyPadParser::KeyPadParser()
{

}

QList<SceneValue> KeyPadParser::parseCommand(Doc *doc, QString command)
QList<SceneValue> KeyPadParser::parseCommand(Doc *doc, QString command, QByteArray &uniData)
{
QList<SceneValue> values;
if (doc == NULL)
Expand Down Expand Up @@ -57,12 +57,10 @@ QList<SceneValue> KeyPadParser::parseCommand(Doc *doc, QString command)
else if (token == "FULL")
{
lastCommand = CommandFULL;
fromValue = toValue = 255;
}
else if (token == "ZERO")
{
lastCommand = CommandZERO;
fromValue = toValue = 0;
}
else if (token == "BY")
{
Expand All @@ -76,6 +74,22 @@ QList<SceneValue> KeyPadParser::parseCommand(Doc *doc, QString command)
{
lastCommand = CommandMinus;
}
else if (token == "+%")
{
lastCommand = CommandPlusPercent;
}

else if (token == "-%")
{
lastCommand = CommandMinusPercent;
}
else if (token == "%")
{
if (lastCommand == CommandPlus)
lastCommand = CommandPlusPercent;
else if (lastCommand == CommandMinus)
lastCommand = CommandMinusPercent;
}
else
{
// most likely a number
Expand Down Expand Up @@ -104,19 +118,21 @@ QList<SceneValue> KeyPadParser::parseCommand(Doc *doc, QString command)
thruCount++;
break;
case CommandFULL:
// nothing to do?
fromValue = toValue = 255;
break;
case CommandZERO:
// nothing to do?
fromValue = toValue = 0;
break;
case CommandBY:
byChannel = number;
break;
case CommandPlus:
// TODO
break;
case CommandMinus:
// TODO
toValue = number;
break;
case CommandPlusPercent:
case CommandMinusPercent:
toValue = float(number) / 100.0;
break;
}
}
Expand All @@ -129,11 +145,25 @@ QList<SceneValue> KeyPadParser::parseCommand(Doc *doc, QString command)
valueDelta = (float(toValue) - float(fromValue)) / valueDelta;
}

for (quint32 i = fromChannel; i <= toChannel; i += byChannel)
for (quint32 i = fromChannel - 1; i <= toChannel - 1; i += byChannel)
{
uchar uniValue = 0;
SceneValue scv;

if (quint32(uniData.length()) >= i)
uniValue = uchar(uniData.at(i));

scv.channel = i;
scv.value = uchar(fromValue);
if (lastCommand == CommandPlus)
scv.value = CLAMP(uniValue + toValue, 0, 255);
else if (lastCommand == CommandMinus)
scv.value = CLAMP(uniValue - toValue, 0, 255);
else if (lastCommand == CommandPlusPercent)
scv.value = CLAMP(uniValue * (1.0 + toValue), 0, 255);
else if (lastCommand == CommandMinusPercent)
scv.value = CLAMP(uniValue - (float(uniValue) * toValue), 0, 255);
else
scv.value = uchar(fromValue);

values.append(scv);
fromValue += valueDelta;
Expand Down
6 changes: 4 additions & 2 deletions engine/src/keypadparser.h
Expand Up @@ -36,10 +36,12 @@ class KeyPadParser
CommandZERO,
CommandBY,
CommandPlus,
CommandMinus
CommandPlusPercent,
CommandMinus,
CommandMinusPercent
};

static QList<SceneValue> parseCommand(Doc *doc, QString command);
static QList<SceneValue> parseCommand(Doc *doc, QString command, QByteArray &uniData);
};

#endif // KEYPADPARSER_H
3 changes: 2 additions & 1 deletion qmlui/qml/RobotoText.qml
Expand Up @@ -23,7 +23,7 @@ import "."
Rectangle
{
id: rtRoot
width: wrapText ? 100 : textBox.paintedWidth
width: wrapText ? 100 : textBox.paintedWidth + rightMargin
height: UISettings.iconSizeDefault

color: "transparent"
Expand All @@ -37,6 +37,7 @@ Rectangle
property int textHAlign: Text.AlignLeft
property int textVAlign: wrapText ? Text.AlignVCenter : Text.AlignTop
property alias leftMargin: textBox.x
property real rightMargin: 0

Text
{
Expand Down
1 change: 1 addition & 0 deletions qmlui/qml/SimpleDesk.qml
Expand Up @@ -365,6 +365,7 @@ Rectangle
{
x: parent.width - width
height: UISettings.listItemHeight
rightMargin: 5
label: (fixtureObj.address + 1) + " - " + (fixtureObj.address + fixtureObj.channels + 1)
}
}
Expand Down
23 changes: 21 additions & 2 deletions qmlui/qml/fixturesfunctions/UniverseSummary.qml
Expand Up @@ -109,11 +109,13 @@ Rectangle
GridLayout
{
id: gridBox
columns: 4 + (manufCheck.checked ? 1 : 0) + (modelCheck.checked ? 1 : 0) +
columns: 5 + (manufCheck.checked ? 1 : 0) + (modelCheck.checked ? 1 : 0) +
(weightCheck.checked ? 1 : 0) + (powerCheck.checked ? 1 : 0) + (dipCheck.checked ? 1 : 0)
columnSpacing: 5
rowSpacing: 0


RobotoText { label: "ID"; labelColor: flickView.textColor }
Rectangle { width: UISettings.iconSizeDefault }
RobotoText { label: qsTr("Name"); labelColor: flickView.textColor }
RobotoText { visible: manufCheck.checked; label: qsTr("Manufacturer"); labelColor: flickView.textColor }
Expand Down Expand Up @@ -163,6 +165,7 @@ Rectangle
visible: powerCheck.checked
label: modelData.power + "W"
labelColor: flickView.textColor
rightMargin: 5
Layout.fillWidth: true

Rectangle { anchors.right: parent.right; height: parent.height; width: 1; color: "black" }
Expand All @@ -176,6 +179,7 @@ Rectangle
visible: weightCheck.checked
label: modelData.weight + "Kg"
labelColor: flickView.textColor
rightMargin: 5
Layout.fillWidth: true

Rectangle { anchors.right: parent.right; height: parent.height; width: 1; color: "black" }
Expand All @@ -188,20 +192,21 @@ Rectangle
parent: gridBox
label: cRef ? cRef.channels : 0
labelColor: flickView.textColor
rightMargin: 5
Layout.fillWidth: true

Rectangle { anchors.right: parent.right; height: parent.height; width: 1; color: "black" }

Component.onCompleted: flickView.totalChannels += cRef.channels
}


// address range
RobotoText
{
parent: gridBox
label: cRef ? "" + (cRef.address + 1) + "-" + (cRef.address + cRef.channels + 1) : ""
labelColor: flickView.textColor
rightMargin: 5
Layout.fillWidth: true

Rectangle { anchors.right: parent.right; height: parent.height; width: 1; color: "black" }
Expand All @@ -214,6 +219,7 @@ Rectangle
visible: modelCheck.checked
label: modelData.fmodel
labelColor: flickView.textColor
rightMargin: 5
Layout.fillWidth: true

Rectangle { anchors.right: parent.right; height: parent.height; width: 1; color: "black" }
Expand All @@ -226,6 +232,7 @@ Rectangle
visible: manufCheck.checked
label: modelData.manuf
labelColor: flickView.textColor
rightMargin: 5
Layout.fillWidth: true

Rectangle { anchors.right: parent.right; height: parent.height; width: 1; color: "black" }
Expand All @@ -237,6 +244,7 @@ Rectangle
parent: gridBox
label: cRef ? cRef.name : ""
labelColor: flickView.textColor
rightMargin: 5
Layout.fillWidth: true

Rectangle { anchors.right: parent.right; height: parent.height; width: 1; color: "black" }
Expand All @@ -251,6 +259,17 @@ Rectangle
height: width
sourceSize: Qt.size(width, height)
}

// ID
RobotoText
{
parent: gridBox
label: cRef ? cRef.id : ""
labelColor: flickView.textColor
Layout.fillWidth: true

Rectangle { anchors.right: parent.right; height: parent.height; width: 1; color: "black" }
}
} // delegate
} // Repeater
} // GridLayout
Expand Down
3 changes: 2 additions & 1 deletion qmlui/simpledesk.cpp
Expand Up @@ -307,7 +307,8 @@ void SimpleDesk::slotUniverseWritten(quint32 idx, const QByteArray& ua)

void SimpleDesk::sendKeypadCommand(QString command)
{
QList<SceneValue> scvList = KeyPadParser::parseCommand(m_doc, command);
QByteArray uniData = m_prevUniverseValues.value(m_universeFilter);
QList<SceneValue> scvList = KeyPadParser::parseCommand(m_doc, command, uniData);

for (SceneValue scv : scvList)
{
Expand Down

0 comments on commit 54be73a

Please sign in to comment.