From 54be73aae79e8c362f09f69a3637ff5be41cb77b Mon Sep 17 00:00:00 2001 From: Massimo Callegari Date: Sun, 29 Nov 2020 11:14:31 +0100 Subject: [PATCH] qmlui: handle keypad +/- including percentage --- engine/src/keypadparser.cpp | 52 +++++++++++++++---- engine/src/keypadparser.h | 6 ++- qmlui/qml/RobotoText.qml | 3 +- qmlui/qml/SimpleDesk.qml | 1 + .../qml/fixturesfunctions/UniverseSummary.qml | 23 +++++++- qmlui/simpledesk.cpp | 3 +- 6 files changed, 71 insertions(+), 17 deletions(-) diff --git a/engine/src/keypadparser.cpp b/engine/src/keypadparser.cpp index 57a42354d8..2ab693cbc5 100644 --- a/engine/src/keypadparser.cpp +++ b/engine/src/keypadparser.cpp @@ -18,14 +18,14 @@ */ #include "keypadparser.h" - +#include "qlcmacros.h" KeyPadParser::KeyPadParser() { } -QList KeyPadParser::parseCommand(Doc *doc, QString command) +QList KeyPadParser::parseCommand(Doc *doc, QString command, QByteArray &uniData) { QList values; if (doc == NULL) @@ -57,12 +57,10 @@ QList 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") { @@ -76,6 +74,22 @@ QList 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 @@ -104,19 +118,21 @@ QList 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; } } @@ -129,11 +145,25 @@ QList 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; diff --git a/engine/src/keypadparser.h b/engine/src/keypadparser.h index 696274e8b6..4d609f9951 100644 --- a/engine/src/keypadparser.h +++ b/engine/src/keypadparser.h @@ -36,10 +36,12 @@ class KeyPadParser CommandZERO, CommandBY, CommandPlus, - CommandMinus + CommandPlusPercent, + CommandMinus, + CommandMinusPercent }; - static QList parseCommand(Doc *doc, QString command); + static QList parseCommand(Doc *doc, QString command, QByteArray &uniData); }; #endif // KEYPADPARSER_H diff --git a/qmlui/qml/RobotoText.qml b/qmlui/qml/RobotoText.qml index 77b066047a..972b1647ef 100644 --- a/qmlui/qml/RobotoText.qml +++ b/qmlui/qml/RobotoText.qml @@ -23,7 +23,7 @@ import "." Rectangle { id: rtRoot - width: wrapText ? 100 : textBox.paintedWidth + width: wrapText ? 100 : textBox.paintedWidth + rightMargin height: UISettings.iconSizeDefault color: "transparent" @@ -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 { diff --git a/qmlui/qml/SimpleDesk.qml b/qmlui/qml/SimpleDesk.qml index 6e6789db9d..059eafb36b 100644 --- a/qmlui/qml/SimpleDesk.qml +++ b/qmlui/qml/SimpleDesk.qml @@ -365,6 +365,7 @@ Rectangle { x: parent.width - width height: UISettings.listItemHeight + rightMargin: 5 label: (fixtureObj.address + 1) + " - " + (fixtureObj.address + fixtureObj.channels + 1) } } diff --git a/qmlui/qml/fixturesfunctions/UniverseSummary.qml b/qmlui/qml/fixturesfunctions/UniverseSummary.qml index 27c54acf1d..6c80a58521 100644 --- a/qmlui/qml/fixturesfunctions/UniverseSummary.qml +++ b/qmlui/qml/fixturesfunctions/UniverseSummary.qml @@ -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 } @@ -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" } @@ -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" } @@ -188,6 +192,7 @@ 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" } @@ -195,13 +200,13 @@ Rectangle 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" } @@ -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" } @@ -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" } @@ -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" } @@ -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 diff --git a/qmlui/simpledesk.cpp b/qmlui/simpledesk.cpp index cf86211687..ceba847ae9 100644 --- a/qmlui/simpledesk.cpp +++ b/qmlui/simpledesk.cpp @@ -307,7 +307,8 @@ void SimpleDesk::slotUniverseWritten(quint32 idx, const QByteArray& ua) void SimpleDesk::sendKeypadCommand(QString command) { - QList scvList = KeyPadParser::parseCommand(m_doc, command); + QByteArray uniData = m_prevUniverseValues.value(m_universeFilter); + QList scvList = KeyPadParser::parseCommand(m_doc, command, uniData); for (SceneValue scv : scvList) {