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/DoricViewNode.cpp

102 lines
2.5 KiB
C++
Raw Normal View History

2021-02-19 19:01:31 +08:00
#include <QJSValueIterator>
#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) {
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()) {
case 1:
qCritical() << 1;
break;
case 2:
qCritical() << 2;
break;
default:
qCritical() << "default";
break;
}
}
if (heightSpec.isNumber()) {
switch (heightSpec.toInt()) {
case 1:
2021-03-02 17:18:23 +08:00
qCritical() << 1;
break;
case 2:
qCritical() << 2;
break;
2021-03-02 17:18:23 +08:00
default:
qCritical() << "default";
break;
}
}
}
void DoricViewNode::setLayoutConfig(QJSValue layoutConfig) {
if (mSuperNode != nullptr) {
mSuperNode->blendSubLayoutConfig(this, layoutConfig);
} else {
blendLayoutConfig(layoutConfig);
}
}
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
}
QString DoricViewNode::getId() { return mId; }
void DoricViewNode::setId(QString id) { mId = id; }
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();
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") {
if (!prop.isNumber()) {
return;
}
view->setWidth(prop.toInt());
2021-02-19 19:01:31 +08:00
} else if (name == "height") {
if (!prop.isNumber()) {
return;
}
view->setHeight(prop.toInt());
} else if (name == "backgroundColor") {
2021-02-24 10:50:41 +08:00
QString color = DoricUtils::doricColor(prop.toNumber()).name();
view->setProperty("color", color);
} else if (name == "x") {
view->setProperty("x", prop.toInt());
} else if (name == "y") {
view->setProperty("y", prop.toInt());
} else if (name == "corners") {
view->setProperty("radius", prop.toInt());
} else {
qCritical() << name << ": " << prop.toString();
2021-02-19 19:01:31 +08:00
}
}