add image render

This commit is contained in:
王劲鹏
2021-04-23 17:56:08 +08:00
committed by osborn
parent 8ae5af13e9
commit 0a29cc2876
12 changed files with 254 additions and 9 deletions

View File

@@ -0,0 +1,75 @@
#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;
map.insert("width", 0);
map.insert("height", 0);
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);
}
}

View File

@@ -0,0 +1,30 @@
#ifndef DORICIMAGENODE_H
#define DORICIMAGENODE_H
#include "DoricViewNode.h"
class DoricImageNode : public DoricViewNode {
public:
using DoricViewNode::DoricViewNode;
QQuickItem *build() override;
virtual void blend(QJsonValue jsValue) override;
virtual void blend(QQuickItem *view, QString name, QJsonValue prop) override;
void onReady();
void onError();
private:
QString loadCallbackId = "";
int contentMode = 0;
int placeHolderColor = -1;
int errorColor = -1;
};
#endif // DORICIMAGENODE_H

View File

@@ -17,8 +17,6 @@ protected:
DoricLayouts *mLayouts = nullptr;
DoricSuperNode *mSuperNode = nullptr;
virtual QQuickItem *build() = 0;
void createLayouts(QQuickItem *view);
@@ -37,6 +35,8 @@ private:
public:
QString mType;
DoricSuperNode *mSuperNode = nullptr;
using DoricContextHolder::DoricContextHolder;
void init(DoricSuperNode *superNode);