Skip to content

Commit

Permalink
For QUL masked images are drawns as a images
Browse files Browse the repository at this point in the history
  • Loading branch information
mmertama committed Feb 20, 2024
1 parent 842fb80 commit 47239b4
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 19 deletions.
4 changes: 3 additions & 1 deletion include/figmaparser.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ class FigmaParser {

std::optional<QString> 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;

Expand Down Expand Up @@ -212,6 +212,8 @@ class FigmaParser {
QByteArray parseQtComponent(const OrderedMap<QString, QByteArray>& children, int intendents);
QByteArray parseQulComponent(const OrderedMap<QString, QByteArray>& 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:
Expand Down
2 changes: 1 addition & 1 deletion qml/QtForMCUPopup.qml
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ Dialog {
footer: Row {
DialogButtonBox {
Button {
text: qsTr("Proceed...")
text: qsTr("Execute...")
DialogButtonBox.buttonRole: DialogButtonBox.AcceptRole
}

Expand Down
51 changes: 34 additions & 17 deletions src/figmaparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -737,17 +737,21 @@ std::optional<FigmaParser::Components> 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";
Expand All @@ -757,6 +761,8 @@ std::optional<FigmaParser::Components> 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";
Expand All @@ -770,9 +776,31 @@ std::optional<FigmaParser::Components> 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()) {
Expand Down Expand Up @@ -820,11 +848,7 @@ std::optional<FigmaParser::Components> 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";
Expand Down Expand Up @@ -915,17 +939,13 @@ std::optional<FigmaParser::Components> 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";
Expand Down Expand Up @@ -1080,16 +1100,13 @@ std::optional<FigmaParser::Components> 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";
Expand Down

0 comments on commit 47239b4

Please sign in to comment.