2021-02-19 19:01:31 +08:00
|
|
|
#include <QJSValueIterator>
|
|
|
|
|
2021-02-19 15:43:09 +08:00
|
|
|
#include "../utils/DoricUtils.h"
|
|
|
|
#include "DoricSuperNode.h"
|
2021-02-19 19:01:31 +08:00
|
|
|
#include "DoricViewNode.h"
|
2021-02-09 15:54:22 +08:00
|
|
|
|
2021-03-02 17:18:23 +08:00
|
|
|
void DoricViewNode::blendLayoutConfig(QJSValue jsObject) {
|
2021-03-15 15:30:17 +08:00
|
|
|
this->mLayoutConfig = jsObject;
|
|
|
|
|
2021-03-02 17:18:23 +08:00
|
|
|
QJSValue margin = jsObject.property("margin");
|
|
|
|
QJSValue widthSpec = jsObject.property("widthSpec");
|
|
|
|
QJSValue heightSpec = jsObject.property("heightSpec");
|
2021-02-09 15:54:22 +08:00
|
|
|
|
2021-03-02 17:18:23 +08:00
|
|
|
if (widthSpec.isNumber()) {
|
|
|
|
switch (widthSpec.toInt()) {
|
2021-03-15 15:30:17 +08:00
|
|
|
case 0:
|
|
|
|
mView->setProperty("widthSpec", 0);
|
|
|
|
break;
|
2021-03-02 17:18:23 +08:00
|
|
|
case 1:
|
2021-03-15 15:30:17 +08:00
|
|
|
mView->setProperty("widthSpec", 1);
|
2021-03-02 17:18:23 +08:00
|
|
|
break;
|
|
|
|
case 2:
|
2021-03-15 15:30:17 +08:00
|
|
|
mView->setProperty("widthSpec", 2);
|
2021-03-04 17:44:54 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (heightSpec.isNumber()) {
|
|
|
|
switch (heightSpec.toInt()) {
|
2021-03-15 15:30:17 +08:00
|
|
|
case 0:
|
|
|
|
mView->setProperty("heightSpec", 0);
|
|
|
|
break;
|
2021-03-04 17:44:54 +08:00
|
|
|
case 1:
|
2021-03-15 15:30:17 +08:00
|
|
|
mView->setProperty("heightSpec", 1);
|
2021-03-02 17:18:23 +08:00
|
|
|
break;
|
2021-03-04 17:44:54 +08:00
|
|
|
case 2:
|
2021-03-15 15:30:17 +08:00
|
|
|
mView->setProperty("heightSpec", 2);
|
2021-03-02 17:18:23 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void DoricViewNode::setLayoutConfig(QJSValue layoutConfig) {
|
|
|
|
if (mSuperNode != nullptr) {
|
|
|
|
mSuperNode->blendSubLayoutConfig(this, layoutConfig);
|
|
|
|
} else {
|
|
|
|
blendLayoutConfig(layoutConfig);
|
|
|
|
}
|
|
|
|
}
|
2021-02-19 15:43:09 +08:00
|
|
|
|
|
|
|
void DoricViewNode::init(DoricSuperNode *superNode) {
|
|
|
|
if (DoricUtils:: instanceof <DoricSuperNode *>(this)) {
|
|
|
|
DoricSuperNode *thiz = dynamic_cast<DoricSuperNode *>(this);
|
|
|
|
thiz->mReusable = superNode->mReusable;
|
|
|
|
}
|
|
|
|
this->mSuperNode = superNode;
|
|
|
|
this->mView = build();
|
2021-02-09 15:54:22 +08:00
|
|
|
}
|
2021-02-19 15:43:09 +08:00
|
|
|
|
|
|
|
QString DoricViewNode::getId() { return mId; }
|
|
|
|
|
|
|
|
void DoricViewNode::setId(QString id) { mId = id; }
|
|
|
|
|
2021-02-22 16:42:19 +08:00
|
|
|
QString DoricViewNode::getType() { return mType; }
|
|
|
|
|
|
|
|
QQuickItem *DoricViewNode::getNodeView() { return mView; }
|
|
|
|
|
2021-02-19 19:01:31 +08:00
|
|
|
void DoricViewNode::blend(QJSValue jsValue) {
|
2021-03-02 17:18:23 +08:00
|
|
|
QJSValue value = jsValue.property("layoutConfig");
|
|
|
|
if (value.isObject()) {
|
|
|
|
setLayoutConfig(value);
|
|
|
|
}
|
2021-02-19 19:01:31 +08:00
|
|
|
QJSValueIterator it(jsValue);
|
|
|
|
while (it.hasNext()) {
|
|
|
|
it.next();
|
2021-02-22 16:42:19 +08:00
|
|
|
blend(mView, it.name(), it.value());
|
2021-02-19 19:01:31 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void DoricViewNode::blend(QQuickItem *view, QString name, QJSValue prop) {
|
|
|
|
if (name == "width") {
|
2021-02-23 18:26:00 +08:00
|
|
|
if (!prop.isNumber()) {
|
|
|
|
return;
|
|
|
|
}
|
2021-03-15 15:30:17 +08:00
|
|
|
if (this->mLayoutConfig.isUndefined()) {
|
|
|
|
view->setWidth(prop.toInt());
|
|
|
|
} else {
|
|
|
|
QJSValue widthSpec = this->mLayoutConfig.property("widthSpec");
|
|
|
|
if (widthSpec.isNumber()) {
|
|
|
|
if (widthSpec.toInt() == 0) {
|
|
|
|
view->setWidth(prop.toInt());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-02-19 19:01:31 +08:00
|
|
|
} else if (name == "height") {
|
2021-02-23 18:26:00 +08:00
|
|
|
if (!prop.isNumber()) {
|
|
|
|
return;
|
|
|
|
}
|
2021-03-15 15:30:17 +08:00
|
|
|
if (this->mLayoutConfig.isUndefined()) {
|
|
|
|
view->setHeight(prop.toInt());
|
|
|
|
} else {
|
|
|
|
QJSValue heightSpec = this->mLayoutConfig.property("heightSpec");
|
|
|
|
if (heightSpec.isNumber()) {
|
|
|
|
if (heightSpec.toInt() == 0) {
|
|
|
|
view->setHeight(prop.toInt());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-02-22 16:42:19 +08:00
|
|
|
} else if (name == "backgroundColor") {
|
2021-02-24 10:50:41 +08:00
|
|
|
QString color = DoricUtils::doricColor(prop.toNumber()).name();
|
|
|
|
view->setProperty("color", color);
|
2021-02-24 15:47:57 +08:00
|
|
|
} else if (name == "x") {
|
|
|
|
view->setProperty("x", prop.toInt());
|
|
|
|
} else if (name == "y") {
|
|
|
|
view->setProperty("y", prop.toInt());
|
2021-02-24 16:23:45 +08:00
|
|
|
} else if (name == "corners") {
|
|
|
|
view->setProperty("radius", prop.toInt());
|
2021-03-15 15:30:17 +08:00
|
|
|
} else if (name == "layoutConfig") {
|
|
|
|
|
2021-02-24 15:47:57 +08:00
|
|
|
} else {
|
|
|
|
qCritical() << name << ": " << prop.toString();
|
2021-02-19 19:01:31 +08:00
|
|
|
}
|
|
|
|
}
|