diff --git a/include/figmaparser.h b/include/figmaparser.h index a2810aa..3d507c6 100644 --- a/include/figmaparser.h +++ b/include/figmaparser.h @@ -149,7 +149,7 @@ class FigmaParser { std::optional imageFill(const QJsonObject& obj) const; - EByteArray makeImageMaskData(const QString& imageRef, const QJsonObject& obj, int intendents, const QString& sourceId, const QString& maskSourceId); + EByteArray makeImageMaskData(const QString& imageRef, const QJsonObject& obj, int intendents); QByteArray makeShapeFillData(const QJsonObject& obj, int shapeIntendents); QByteArray makeAntialising(int intendents) const; @@ -212,6 +212,8 @@ class FigmaParser { QByteArray parseQtComponent(const OrderedMap& children, int intendents); QByteArray parseQulComponent(const OrderedMap& children, int intendents); EByteArray makeChildMask(const QJsonObject& child, int intendents); + EByteArray makeImageMaskDataQul(const QString& imageRef, const QJsonObject& obj, int intendents); + EByteArray makeImageMaskDataQt(const QString& imageRef, const QJsonObject& obj, int intendents); ~FigmaParser(); private: diff --git a/qml/QtForMCUPopup.qml b/qml/QtForMCUPopup.qml index 20c683a..94a0311 100644 --- a/qml/QtForMCUPopup.qml +++ b/qml/QtForMCUPopup.qml @@ -128,7 +128,7 @@ Dialog { footer: Row { DialogButtonBox { Button { - text: qsTr("Proceed...") + text: qsTr("Execute...") DialogButtonBox.buttonRole: DialogButtonBox.AcceptRole } diff --git a/src/figmaparser.cpp b/src/figmaparser.cpp index 632d26e..183f04b 100644 --- a/src/figmaparser.cpp +++ b/src/figmaparser.cpp @@ -737,17 +737,21 @@ std::optional FigmaParser::components(const QJsonObject return std::nullopt; } - EByteArray FigmaParser::makeImageMaskData(const QString& imageRef, const QJsonObject& obj, int intendents, const QString& sourceId, const QString& maskSourceId) { - Q_ASSERT(!isQul()); + EByteArray FigmaParser::makeImageMaskDataQt(const QString& imageRef, const QJsonObject& obj, int intendents) { QByteArray out; const auto intendent = tabs(intendents); const auto intendent1 = tabs(intendents + 1); + const auto sourceId = "source_" + qmlId(obj["id"].toString()); + const auto maskSourceId = "maskSource_" + qmlId(obj["id"].toString()); + + out += intendent + "OpacityMask {\n"; out += intendent1 + "anchors.fill:parent\n"; out += intendent1 + "source: " + sourceId + "\n"; out += intendent1 + "maskSource: " + maskSourceId + "\n"; out += intendent + "}\n"; + out += intendent + "Image {\n"; out += intendent1 + "id: " + sourceId + "\n"; out += intendent1 + "layer.enabled: true\n"; @@ -757,6 +761,8 @@ std::optional FigmaParser::components(const QJsonObject out += intendent1 + "anchors.fill:parent\n"; APPENDERR(out, makeImageSource(imageRef, false, intendents + 1)); out += intendent + "}\n"; + + out += intendent + "Shape {\n"; out += intendent1 + "id: " + maskSourceId + "\n"; out += intendent1 + "anchors.fill: parent\n"; @@ -770,9 +776,31 @@ std::optional FigmaParser::components(const QJsonObject out += intendent1 + "}\n"; out += intendent + "}\n"; + + return out; + } + + + + EByteArray FigmaParser::makeImageMaskDataQul(const QString& imageRef, const QJsonObject& obj, int intendents) { + QByteArray out; + const auto intendent = tabs(intendents); + const auto intendent1 = tabs(intendents + 1); + const auto sourceId = "source_" + qmlId(obj["id"].toString()); + out += intendent + "Image {\n"; + out += intendent1 + "id: " + sourceId + "\n"; + out += intendent1 + "fillMode: Image.PreserveAspectCrop\n"; + out += intendent1 + "visible: true\n"; + out += intendent1 + "anchors.fill:parent\n"; + APPENDERR(out, makeImageSource(imageRef, false, intendents + 1)); + out += intendent + "}\n"; return out; } + EByteArray FigmaParser::makeImageMaskData(const QString& imageRef, const QJsonObject& obj, int intendents) { + return isQul() ? makeImageMaskDataQul(imageRef, obj, intendents) : makeImageMaskDataQt(imageRef, obj, intendents); + } + QByteArray FigmaParser::makeShapeFillData(const QJsonObject& obj, int shapeIntendents) { QByteArray out; if(!obj["fillGeometry"].toArray().isEmpty()) { @@ -820,11 +848,7 @@ std::optional FigmaParser::components(const QJsonObject out += makeItem("Item", obj, intendents); out += makeExtents(obj, intendents); - const auto sourceId = "source_" + qmlId(obj["id"].toString()); - const auto maskSourceId = "maskSource_" + qmlId(obj["id"].toString()); - - if(!isQul()) - APPENDERR(out, makeImageMaskData(image, obj, intendents, sourceId, maskSourceId)); + APPENDERR(out, makeImageMaskData(image, obj, intendents)); out += intendent + "Shape {\n"; out += intendent1 + "anchors.fill: parent\n"; @@ -915,17 +939,13 @@ std::optional FigmaParser::components(const QJsonObject const auto intendent1 = tabs(intendents + 1); const auto intendent2 = tabs(intendents + 2); - const auto sourceId = "source_" + qmlId(obj["id"].toString()); - const auto maskSourceId = "maskSource_" + qmlId(obj["id"].toString()); - out += intendent + "Item {\n"; out += intendent1 + "id:" + borderSourceId + "\n"; out += intendent1 + "anchors.fill: parent\n"; out += makeAntialising(intendents + 1); out += intendent1 + "visible: false\n"; - if(!isQul()) - APPENDERR(out, makeImageMaskData(image, obj, intendents + 1, sourceId, maskSourceId)); + APPENDERR(out, makeImageMaskData(image, obj, intendents + 1)); out += intendent1 + "Shape {\n"; out += intendent2 + "anchors.fill: parent\n"; @@ -1080,16 +1100,13 @@ std::optional FigmaParser::components(const QJsonObject const auto intendent2 = tabs(intendents + 2); const auto intendent3 = tabs(intendents + 3); - const auto sourceId = "source_" + qmlId(obj["id"].toString()); - const auto maskSourceId = "maskSource_" + qmlId(obj["id"].toString()); - out += intendent + "Item {\n"; out += intendent1 + "x: " + QString::number(borderWidth) + "\n"; out += intendent1 + "y: " + QString::number(borderWidth) + "\n"; out += makeSize(obj, intendents + 1); out += makeAntialising(intendents + 1); - if(!isQul()) - APPENDERR(out, makeImageMaskData(image, obj, intendents + 1, sourceId, maskSourceId)); + + APPENDERR(out, makeImageMaskData(image, obj, intendents + 1)); out += intendent1 + "Shape {\n"; out += intendent2 + "anchors.fill: parent\n";