This repository has been archived on 2024-07-22. You can view files and clone it, but cannot push or open issues or pull requests.
Doric/doric-Qt/doric/shader/DoricImageNode.cpp

76 lines
2.1 KiB
C++
Raw Normal View History

2021-04-23 17:56:08 +08:00
#include "DoricImageNode.h"
#include "DoricSuperNode.h"
#include "../utils/DoricUtils.h"
#include <QQuickItem>
QQuickItem *DoricImageNode::build() {
QQmlComponent component(getContext()->getQmlEngine());
const QUrl url(QStringLiteral("qrc:/doric/qml/image.qml"));
component.loadUrl(url);
if (component.isError()) {
qCritical() << component.errorString();
}
QQuickItem *item = qobject_cast<QQuickItem *>(component.create());
this->createLayouts(item);
item->setProperty("wrapper", QString::number((qint64)this));
return item;
}
void DoricImageNode::blend(QJsonValue jsValue) {
if (jsValue.toObject().contains("scaleType"))
this->contentMode = jsValue["scaleType"].toInt();
if (jsValue.toObject().contains("placeHolderColor"))
this->placeHolderColor = jsValue["placeHolderColor"].toInt();
if (jsValue.toObject().contains("errorColor"))
this->errorColor = jsValue["errorColor"].toInt();
if (jsValue.toObject().contains("loadCallback"))
this->loadCallbackId = jsValue["loadCallback"].toString();
DoricViewNode::blend(jsValue);
}
void DoricImageNode::blend(QQuickItem *view, QString name, QJsonValue prop) {
QQuickItem *container = view;
if (name == "imageUrl") {
container->setProperty("fillMode", this->contentMode);
container->setProperty("source", prop.toString());
} else if (name == "imageBase64") {
container->setProperty("fillMode", this->contentMode);
container->setProperty("source", prop.toString());
} else {
DoricViewNode::blend(view, name, prop);
}
}
void DoricImageNode::onReady() {
if (!this->loadCallbackId.isEmpty()) {
QVariantList args;
QMap<QString, QVariant> map;
2021-04-26 10:24:02 +08:00
map.insert("width", mView->width());
map.insert("height", mView->height());
2021-04-23 17:56:08 +08:00
args.append(QVariant::fromValue(map));
this->callJSResponse(this->loadCallbackId, args);
}
DoricSuperNode *node = this->mSuperNode;
while (node->mSuperNode != nullptr) {
node = node->mSuperNode;
}
node->requestLayout();
}
void DoricImageNode::onError() {
if (!this->loadCallbackId.isEmpty()) {
QVariantList args;
this->callJSResponse(this->loadCallbackId, args);
}
}