snake build on v8 success
This commit is contained in:
parent
7458d0f4c0
commit
7e59150831
@ -13,16 +13,16 @@ void DoricDemoBridge::navigate(QVariant route) {
|
|||||||
QString name;
|
QString name;
|
||||||
switch (route.toInt()) {
|
switch (route.toInt()) {
|
||||||
case 0:
|
case 0:
|
||||||
name = "Counter.es5.js";
|
name = "Counter.js";
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
name = "Gobang.es5.js";
|
name = "Gobang.js";
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
name = "SimpleDemo.es5.js";
|
name = "SimpleDemo.js";
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
name = "Snake.es5.js";
|
name = "Snake.js";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
QString script = DoricUtils::readAssetFile("/doric/bundles", name);
|
QString script = DoricUtils::readAssetFile("/doric/bundles", name);
|
||||||
|
@ -21,7 +21,7 @@ void DoricBridgeExtension::callNative(QString contextId, QString module,
|
|||||||
QObject *plugin = context->obtainPlugin(module);
|
QObject *plugin = context->obtainPlugin(module);
|
||||||
QMetaObject::invokeMethod(plugin, methodName.toUtf8(), Qt::DirectConnection,
|
QMetaObject::invokeMethod(plugin, methodName.toUtf8(), Qt::DirectConnection,
|
||||||
QGenericReturnArgument(),
|
QGenericReturnArgument(),
|
||||||
Q_ARG(QJsonObject, jsValue),
|
Q_ARG(QJsonObject *, &jsValue),
|
||||||
Q_ARG(QString, callbackId));
|
Q_ARG(QString, callbackId));
|
||||||
}
|
}
|
||||||
qDebug() << "contextId: " + contextId << "module: " + module
|
qDebug() << "contextId: " + contextId << "module: " + module
|
||||||
|
@ -1,23 +1,24 @@
|
|||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
#include <QJsonObject>
|
||||||
|
|
||||||
#include "../shader/DoricRootNode.h"
|
#include "../shader/DoricRootNode.h"
|
||||||
#include "DoricShaderPlugin.h"
|
#include "DoricShaderPlugin.h"
|
||||||
|
|
||||||
void DoricShaderPlugin::render(QJSValue jsValue, QString callbackId) {
|
void DoricShaderPlugin::render(QJsonObject *jsValue, QString callbackId) {
|
||||||
getContext()->getDriver()->asyncCall(
|
getContext()->getDriver()->asyncCall(
|
||||||
[this, jsValue] {
|
[this, jsValue] {
|
||||||
try {
|
try {
|
||||||
QString viewId = jsValue.property("id").toString();
|
QString viewId = jsValue->value("id").toString();
|
||||||
DoricRootNode *rootNode = getContext()->getRootNode();
|
DoricRootNode *rootNode = getContext()->getRootNode();
|
||||||
|
|
||||||
if (rootNode->getId().isEmpty() &&
|
if (rootNode->getId().isEmpty() &&
|
||||||
jsValue.property("type").toString() == "Root") {
|
jsValue->value("type").toString() == "Root") {
|
||||||
rootNode->setId(viewId);
|
rootNode->setId(viewId);
|
||||||
rootNode->blend(jsValue.property("props"));
|
rootNode->blend(jsValue->value("props"));
|
||||||
} else {
|
} else {
|
||||||
DoricViewNode *viewNode = getContext()->targetViewNode(viewId);
|
DoricViewNode *viewNode = getContext()->targetViewNode(viewId);
|
||||||
if (viewNode != nullptr) {
|
if (viewNode != nullptr) {
|
||||||
viewNode->blend(jsValue.property("props"));
|
viewNode->blend(jsValue->value("props"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
|
@ -11,7 +11,7 @@ class DoricShaderPlugin : public DoricNativePlugin {
|
|||||||
public:
|
public:
|
||||||
using DoricNativePlugin::DoricNativePlugin;
|
using DoricNativePlugin::DoricNativePlugin;
|
||||||
|
|
||||||
Q_INVOKABLE void render(QJSValue jsValue, QString callbackId);
|
Q_INVOKABLE void render(QJsonObject *jsValue, QString callbackId);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // SHADERPLUGIN_H
|
#endif // SHADERPLUGIN_H
|
||||||
|
@ -4,14 +4,14 @@
|
|||||||
<file alias="qtquickcontrols2.conf">resources/qtquickcontrols2.conf</file>
|
<file alias="qtquickcontrols2.conf">resources/qtquickcontrols2.conf</file>
|
||||||
</qresource>
|
</qresource>
|
||||||
<qresource prefix="/doric">
|
<qresource prefix="/doric">
|
||||||
<file alias="doric-sandbox.es5.js">../../doric-js/bundle/doric-sandbox.es5.js</file>
|
<file alias="doric-sandbox.js">../../doric-js/bundle/doric-sandbox.js</file>
|
||||||
<file alias="doric-lib.es5.js">../../doric-js/bundle/doric-lib.es5.js</file>
|
<file alias="doric-lib.js">../../doric-js/bundle/doric-lib.js</file>
|
||||||
</qresource>
|
</qresource>
|
||||||
<qresource prefix="/doric/bundles">
|
<qresource prefix="/doric/bundles">
|
||||||
<file alias="Counter.es5.js">../../doric-demo/bundle/src/Counter.es5.js</file>
|
<file alias="Counter.js">../../doric-demo/bundle/src/Counter.js</file>
|
||||||
<file alias="Gobang.es5.js">../../doric-demo/bundle/src/Gobang.es5.js</file>
|
<file alias="Gobang.js">../../doric-demo/bundle/src/Gobang.js</file>
|
||||||
<file alias="SimpleDemo.es5.js">../../doric-demo/bundle/src/SimpleDemo.es5.js</file>
|
<file alias="SimpleDemo.js">../../doric-demo/bundle/src/SimpleDemo.js</file>
|
||||||
<file alias="Snake.es5.js">../../doric-demo/bundle/src/Snake.es5.js</file>
|
<file alias="Snake.js">../../doric-demo/bundle/src/Snake.js</file>
|
||||||
</qresource>
|
</qresource>
|
||||||
<qresource prefix="/doric/qml">
|
<qresource prefix="/doric/qml">
|
||||||
<file alias="Flex.qml">resources/Flex.qml</file>
|
<file alias="Flex.qml">resources/Flex.qml</file>
|
||||||
|
@ -20,13 +20,13 @@ ApplicationWindow {
|
|||||||
text: {
|
text: {
|
||||||
switch (index) {
|
switch (index) {
|
||||||
case 0:
|
case 0:
|
||||||
return "Counter.es5.js"
|
return "Counter.js"
|
||||||
case 1:
|
case 1:
|
||||||
return "Gobang.es5.js"
|
return "Gobang.js"
|
||||||
case 2:
|
case 2:
|
||||||
return "SimpleDemo.es5.js"
|
return "SimpleDemo.js"
|
||||||
case 3:
|
case 3:
|
||||||
return "Snake.es5.js"
|
return "Snake.js"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,12 +1,13 @@
|
|||||||
#include "DoricGroupNode.h"
|
#include "DoricGroupNode.h"
|
||||||
|
|
||||||
void DoricGroupNode::blend(QQuickItem *view, QString name, QJSValue prop) {
|
void DoricGroupNode::blend(QQuickItem *view, QString name, QJsonValue prop) {
|
||||||
if (name == "children") {
|
if (name == "children") {
|
||||||
mChildViewIds.clear();
|
mChildViewIds.clear();
|
||||||
if (prop.isArray()) {
|
if (prop.isArray()) {
|
||||||
const int length = prop.property("length").toInt();
|
QJsonArray array = prop.toArray();
|
||||||
|
const int length = array.size();
|
||||||
for (int i = 0; i < length; ++i) {
|
for (int i = 0; i < length; ++i) {
|
||||||
QJSValue value = prop.property(i);
|
QJsonValue value = array.at(i);
|
||||||
if (value.isString()) {
|
if (value.isString()) {
|
||||||
mChildViewIds.append(value.toString());
|
mChildViewIds.append(value.toString());
|
||||||
}
|
}
|
||||||
@ -17,7 +18,7 @@ void DoricGroupNode::blend(QQuickItem *view, QString name, QJSValue prop) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DoricGroupNode::blend(QJSValue jsValue) {
|
void DoricGroupNode::blend(QJsonValue jsValue) {
|
||||||
DoricViewNode::blend(jsValue);
|
DoricViewNode::blend(jsValue);
|
||||||
configChildNode();
|
configChildNode();
|
||||||
}
|
}
|
||||||
@ -31,13 +32,13 @@ void DoricGroupNode::configChildNode() {
|
|||||||
}
|
}
|
||||||
for (int idx = 0; idx < mChildViewIds.size(); idx++) {
|
for (int idx = 0; idx < mChildViewIds.size(); idx++) {
|
||||||
QString id = mChildViewIds.at(idx);
|
QString id = mChildViewIds.at(idx);
|
||||||
QJSValue model = getSubModel(id);
|
QJsonValue model = getSubModel(id);
|
||||||
if (model.isUndefined()) {
|
if (model.isUndefined()) {
|
||||||
DoricRegistry *registry = getContext()->getDriver()->getRegistry();
|
DoricRegistry *registry = getContext()->getDriver()->getRegistry();
|
||||||
qCritical() << "model.isUndefined()";
|
qCritical() << "model.isUndefined()";
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
QString type = model.property("type").toString();
|
QString type = model["type"].toString();
|
||||||
if (idx < mChildNodes.size()) {
|
if (idx < mChildNodes.size()) {
|
||||||
DoricViewNode *oldNode = mChildNodes.at(idx);
|
DoricViewNode *oldNode = mChildNodes.at(idx);
|
||||||
if (id == oldNode->getId()) {
|
if (id == oldNode->getId()) {
|
||||||
@ -47,7 +48,7 @@ void DoricGroupNode::configChildNode() {
|
|||||||
if (oldNode->getType() == type) {
|
if (oldNode->getType() == type) {
|
||||||
// Same type,can be reused
|
// Same type,can be reused
|
||||||
oldNode->setId(id);
|
oldNode->setId(id);
|
||||||
oldNode->blend(model.property("props"));
|
oldNode->blend(model["props"]);
|
||||||
} else {
|
} else {
|
||||||
// Replace this view
|
// Replace this view
|
||||||
mChildNodes.remove(idx);
|
mChildNodes.remove(idx);
|
||||||
@ -70,7 +71,7 @@ void DoricGroupNode::configChildNode() {
|
|||||||
parent->childItems().at(idx));
|
parent->childItems().at(idx));
|
||||||
}
|
}
|
||||||
|
|
||||||
newNode->blend(model.property("props"));
|
newNode->blend(model["props"]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -105,7 +106,7 @@ void DoricGroupNode::configChildNode() {
|
|||||||
parent->childItems().at(idx));
|
parent->childItems().at(idx));
|
||||||
}
|
}
|
||||||
|
|
||||||
newNode->blend(model.property("props"));
|
newNode->blend(model["props"]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -126,7 +127,7 @@ void DoricGroupNode::configChildNode() {
|
|||||||
newNode->getNodeView()->stackBefore(parent->childItems().at(idx));
|
newNode->getNodeView()->stackBefore(parent->childItems().at(idx));
|
||||||
}
|
}
|
||||||
|
|
||||||
newNode->blend(model.property("props"));
|
newNode->blend(model["props"]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -141,11 +142,11 @@ void DoricGroupNode::configChildNode() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DoricGroupNode::blendSubNode(QJSValue subProperties) {
|
void DoricGroupNode::blendSubNode(QJsonValue subProperties) {
|
||||||
QString subNodeId = subProperties.property("id").toString();
|
QString subNodeId = subProperties["id"].toString();
|
||||||
for (DoricViewNode *node : mChildNodes) {
|
for (DoricViewNode *node : mChildNodes) {
|
||||||
if (subNodeId == node->getId()) {
|
if (subNodeId == node->getId()) {
|
||||||
node->blend(subProperties.property("props"));
|
node->blend(subProperties["props"]);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,9 +7,9 @@ class DoricGroupNode : public DoricSuperNode {
|
|||||||
public:
|
public:
|
||||||
using DoricSuperNode::DoricSuperNode;
|
using DoricSuperNode::DoricSuperNode;
|
||||||
|
|
||||||
virtual void blend(QQuickItem *view, QString name, QJSValue prop) override;
|
virtual void blend(QQuickItem *view, QString name, QJsonValue prop) override;
|
||||||
|
|
||||||
virtual void blend(QJSValue jsValue) override;
|
virtual void blend(QJsonValue jsValue) override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
QList<DoricViewNode *> mChildNodes;
|
QList<DoricViewNode *> mChildNodes;
|
||||||
@ -18,7 +18,7 @@ protected:
|
|||||||
|
|
||||||
void configChildNode();
|
void configChildNode();
|
||||||
|
|
||||||
virtual void blendSubNode(QJSValue subProperties) override;
|
virtual void blendSubNode(QJsonValue subProperties) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // DORICGROUPNODE_H
|
#endif // DORICGROUPNODE_H
|
||||||
|
@ -15,7 +15,7 @@ QQuickItem *DoricHLayoutNode::build() {
|
|||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DoricHLayoutNode::blend(QQuickItem *view, QString name, QJSValue prop) {
|
void DoricHLayoutNode::blend(QQuickItem *view, QString name, QJsonValue prop) {
|
||||||
if (name == "space") {
|
if (name == "space") {
|
||||||
view->childItems().at(1)->setProperty("spacing", prop.toInt());
|
view->childItems().at(1)->setProperty("spacing", prop.toInt());
|
||||||
} else if (name == "gravity") {
|
} else if (name == "gravity") {
|
||||||
|
@ -10,7 +10,7 @@ public:
|
|||||||
|
|
||||||
QQuickItem *build() override;
|
QQuickItem *build() override;
|
||||||
|
|
||||||
virtual void blend(QQuickItem *view, QString name, QJSValue prop) override;
|
virtual void blend(QQuickItem *view, QString name, QJsonValue prop) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // DORICHLAYOUTNODE_H
|
#endif // DORICHLAYOUTNODE_H
|
||||||
|
@ -15,12 +15,12 @@ QQuickItem *DoricStackNode::build() {
|
|||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DoricStackNode::blendLayoutConfig(QJSValue jsValue) {
|
void DoricStackNode::blendLayoutConfig(QJsonValue jsValue) {
|
||||||
DoricViewNode::blendLayoutConfig(jsValue);
|
DoricViewNode::blendLayoutConfig(jsValue);
|
||||||
QJSValue maxWidth = jsValue.property("maxWidth");
|
QJsonValue maxWidth = jsValue["maxWidth"];
|
||||||
if (maxWidth.isNumber()) {
|
if (maxWidth.isDouble()) {
|
||||||
}
|
}
|
||||||
QJSValue maxHeight = jsValue.property("maxHeight");
|
QJsonValue maxHeight = jsValue["maxHeight"];
|
||||||
if (maxHeight.isNumber()) {
|
if (maxHeight.isDouble()) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,7 @@ public:
|
|||||||
|
|
||||||
QQuickItem *build() override;
|
QQuickItem *build() override;
|
||||||
|
|
||||||
void blendLayoutConfig(QJSValue jsValue) override;
|
void blendLayoutConfig(QJsonValue jsValue) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // DORICSTACKNODE_H
|
#endif // DORICSTACKNODE_H
|
||||||
|
@ -2,12 +2,13 @@
|
|||||||
|
|
||||||
#include "DoricSuperNode.h"
|
#include "DoricSuperNode.h"
|
||||||
|
|
||||||
void DoricSuperNode::blend(QQuickItem *view, QString name, QJSValue prop) {
|
void DoricSuperNode::blend(QQuickItem *view, QString name, QJsonValue prop) {
|
||||||
if (name == "subviews") {
|
if (name == "subviews") {
|
||||||
if (prop.isArray()) {
|
if (prop.isArray()) {
|
||||||
const int length = prop.property("length").toInt();
|
QJsonArray array = prop.toArray();
|
||||||
|
const int length = array.size();
|
||||||
for (int i = 0; i < length; ++i) {
|
for (int i = 0; i < length; ++i) {
|
||||||
QJSValue subNode = prop.property(i);
|
QJsonValue subNode = array.at(i);
|
||||||
mixinSubNode(subNode);
|
mixinSubNode(subNode);
|
||||||
blendSubNode(subNode);
|
blendSubNode(subNode);
|
||||||
}
|
}
|
||||||
@ -17,8 +18,8 @@ void DoricSuperNode::blend(QQuickItem *view, QString name, QJSValue prop) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DoricSuperNode::mixinSubNode(QJSValue subNode) {
|
void DoricSuperNode::mixinSubNode(QJsonValue subNode) {
|
||||||
QString id = subNode.property("id").toString();
|
QString id = subNode["id"].toString();
|
||||||
QList<QString> keys = subNodes.keys();
|
QList<QString> keys = subNodes.keys();
|
||||||
if (!keys.contains(id)) {
|
if (!keys.contains(id)) {
|
||||||
subNodes.insert(id, subNode);
|
subNodes.insert(id, subNode);
|
||||||
@ -27,30 +28,36 @@ void DoricSuperNode::mixinSubNode(QJSValue subNode) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DoricSuperNode::mixin(QJSValue src, QJSValue target) {
|
void DoricSuperNode::mixin(QJsonValue src, QJsonValue target) {
|
||||||
QJSValue srcProps = src.property("props");
|
QJsonValue srcProps = src["props"];
|
||||||
QJSValue targetProps = target.property("props");
|
QJsonValue targetProps = target["props"];
|
||||||
QJSValueIterator it(srcProps);
|
|
||||||
while (it.hasNext()) {
|
|
||||||
it.next();
|
|
||||||
|
|
||||||
if (it.name() == "subviews" && it.value().isArray()) {
|
foreach (const QString &key, srcProps.toObject().keys()) {
|
||||||
|
QJsonValue value = srcProps[key];
|
||||||
|
if (key == "subviews" && value.isArray()) {
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
targetProps.setProperty(it.name(), it.value());
|
targetProps.toObject().insert(key, value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QJSValue DoricSuperNode::getSubModel(QString id) {
|
QJsonValue DoricSuperNode::getSubModel(QString id) {
|
||||||
if (subNodes.keys().contains(id)) {
|
if (subNodes.keys().contains(id)) {
|
||||||
return subNodes.value(id);
|
return subNodes.value(id);
|
||||||
} else {
|
} else {
|
||||||
return QJSValue::UndefinedValue;
|
return QJsonValue::Undefined;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DoricSuperNode::blendSubLayoutConfig(DoricViewNode *viewNode,
|
void DoricSuperNode::blendSubLayoutConfig(DoricViewNode *viewNode,
|
||||||
QJSValue jsValue) {
|
QJsonValue jsValue) {
|
||||||
viewNode->blendLayoutConfig(jsValue);
|
viewNode->blendLayoutConfig(jsValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QJsonValue DoricSuperNode::generateDefaultLayoutConfig() {
|
||||||
|
QJsonObject layoutConfig;
|
||||||
|
layoutConfig.insert("widthSpec", 0);
|
||||||
|
layoutConfig.insert("heightSpec", 0);
|
||||||
|
return layoutConfig;
|
||||||
|
}
|
||||||
|
@ -1,30 +1,34 @@
|
|||||||
#ifndef DORICSUPERNODE_H
|
#ifndef DORICSUPERNODE_H
|
||||||
#define DORICSUPERNODE_H
|
#define DORICSUPERNODE_H
|
||||||
|
|
||||||
|
#include <QJsonArray>
|
||||||
|
|
||||||
#include "DoricViewNode.h"
|
#include "DoricViewNode.h"
|
||||||
|
|
||||||
class DoricSuperNode : public DoricViewNode {
|
class DoricSuperNode : public DoricViewNode {
|
||||||
private:
|
private:
|
||||||
QMap<QString, QJSValue> subNodes;
|
QMap<QString, QJsonValue> subNodes;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void blend(QQuickItem *view, QString name, QJSValue prop) override;
|
virtual void blend(QQuickItem *view, QString name, QJsonValue prop) override;
|
||||||
|
|
||||||
virtual void blendSubNode(QJSValue subProperties) = 0;
|
virtual void blendSubNode(QJsonValue subProperties) = 0;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
using DoricViewNode::DoricViewNode;
|
using DoricViewNode::DoricViewNode;
|
||||||
|
|
||||||
bool mReusable = false;
|
bool mReusable = false;
|
||||||
|
|
||||||
QJSValue getSubModel(QString id);
|
QJsonValue getSubModel(QString id);
|
||||||
|
|
||||||
void blendSubLayoutConfig(DoricViewNode *viewNode, QJSValue jsValue);
|
void blendSubLayoutConfig(DoricViewNode *viewNode, QJsonValue jsValue);
|
||||||
|
|
||||||
|
QJsonValue generateDefaultLayoutConfig();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void mixinSubNode(QJSValue subNode);
|
void mixinSubNode(QJsonValue subNode);
|
||||||
|
|
||||||
void mixin(QJSValue src, QJSValue target);
|
void mixin(QJsonValue src, QJsonValue target);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // DORICSUPERNODE_H
|
#endif // DORICSUPERNODE_H
|
||||||
|
@ -16,15 +16,15 @@ QQuickItem *DoricTextNode::build() {
|
|||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DoricTextNode::blend(QQuickItem *view, QString name, QJSValue prop) {
|
void DoricTextNode::blend(QQuickItem *view, QString name, QJsonValue prop) {
|
||||||
if (name == "text") {
|
if (name == "text") {
|
||||||
view->childItems().at(0)->setProperty("text", prop.toString());
|
view->childItems().at(0)->setProperty("text", prop.toString());
|
||||||
} else if (name == "textColor") {
|
} else if (name == "textColor") {
|
||||||
QString color = DoricUtils::doricColor(prop.toNumber()).name();
|
QString color = DoricUtils::doricColor(prop.toInt()).name();
|
||||||
view->childItems().at(0)->setProperty("color", color);
|
view->childItems().at(0)->setProperty("color", color);
|
||||||
} else if (name == "textSize") {
|
} else if (name == "textSize") {
|
||||||
QFont font = view->childItems().at(0)->property("font").value<QFont>();
|
QFont font = view->childItems().at(0)->property("font").value<QFont>();
|
||||||
font.setPixelSize(prop.toNumber());
|
font.setPixelSize(prop.toInt());
|
||||||
view->childItems().at(0)->setProperty("font", QVariant(font));
|
view->childItems().at(0)->setProperty("font", QVariant(font));
|
||||||
} else if (name == "textAlignment") {
|
} else if (name == "textAlignment") {
|
||||||
view->childItems().at(0)->setProperty("textAlignment", prop.toInt());
|
view->childItems().at(0)->setProperty("textAlignment", prop.toInt());
|
||||||
|
@ -9,7 +9,7 @@ public:
|
|||||||
|
|
||||||
QQuickItem *build() override;
|
QQuickItem *build() override;
|
||||||
|
|
||||||
virtual void blend(QQuickItem *view, QString name, QJSValue prop) override;
|
virtual void blend(QQuickItem *view, QString name, QJsonValue prop) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // DORICTEXTNODE_H
|
#endif // DORICTEXTNODE_H
|
||||||
|
@ -15,7 +15,7 @@ QQuickItem *DoricVLayoutNode::build() {
|
|||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DoricVLayoutNode::blend(QQuickItem *view, QString name, QJSValue prop) {
|
void DoricVLayoutNode::blend(QQuickItem *view, QString name, QJsonValue prop) {
|
||||||
if (name == "space") {
|
if (name == "space") {
|
||||||
view->childItems().at(1)->setProperty("spacing", prop.toInt());
|
view->childItems().at(1)->setProperty("spacing", prop.toInt());
|
||||||
} else if (name == "gravity") {
|
} else if (name == "gravity") {
|
||||||
|
@ -9,7 +9,7 @@ public:
|
|||||||
|
|
||||||
QQuickItem *build() override;
|
QQuickItem *build() override;
|
||||||
|
|
||||||
virtual void blend(QQuickItem *view, QString name, QJSValue prop) override;
|
virtual void blend(QQuickItem *view, QString name, QJsonValue prop) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // DORICVLAYOUTNODE_H
|
#endif // DORICVLAYOUTNODE_H
|
||||||
|
@ -1,18 +1,16 @@
|
|||||||
#include <QJSValueIterator>
|
#include "DoricViewNode.h"
|
||||||
|
|
||||||
#include "../utils/DoricConstant.h"
|
#include "../utils/DoricConstant.h"
|
||||||
#include "../utils/DoricUtils.h"
|
#include "../utils/DoricUtils.h"
|
||||||
#include "DoricSuperNode.h"
|
#include "DoricSuperNode.h"
|
||||||
#include "DoricViewNode.h"
|
|
||||||
|
|
||||||
void DoricViewNode::blendLayoutConfig(QJSValue jsObject) {
|
void DoricViewNode::blendLayoutConfig(QJsonValue jsObject) {
|
||||||
this->mLayoutConfig = jsObject;
|
this->mLayoutConfig = jsObject;
|
||||||
|
|
||||||
QJSValue margin = jsObject.property("margin");
|
QJsonValue margin = jsObject["margin"];
|
||||||
QJSValue widthSpec = jsObject.property("widthSpec");
|
QJsonValue widthSpec = jsObject["widthSpec"];
|
||||||
QJSValue heightSpec = jsObject.property("heightSpec");
|
QJsonValue heightSpec = jsObject["heightSpec"];
|
||||||
|
|
||||||
if (widthSpec.isNumber()) {
|
if (widthSpec.isDouble()) {
|
||||||
switch (widthSpec.toInt()) {
|
switch (widthSpec.toInt()) {
|
||||||
case 0:
|
case 0:
|
||||||
mView->setProperty("widthSpec", 0);
|
mView->setProperty("widthSpec", 0);
|
||||||
@ -26,7 +24,7 @@ void DoricViewNode::blendLayoutConfig(QJSValue jsObject) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (heightSpec.isNumber()) {
|
if (heightSpec.isDouble()) {
|
||||||
switch (heightSpec.toInt()) {
|
switch (heightSpec.toInt()) {
|
||||||
case 0:
|
case 0:
|
||||||
mView->setProperty("heightSpec", 0);
|
mView->setProperty("heightSpec", 0);
|
||||||
@ -41,7 +39,7 @@ void DoricViewNode::blendLayoutConfig(QJSValue jsObject) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DoricViewNode::setLayoutConfig(QJSValue layoutConfig) {
|
void DoricViewNode::setLayoutConfig(QJsonValue layoutConfig) {
|
||||||
if (mSuperNode != nullptr) {
|
if (mSuperNode != nullptr) {
|
||||||
mSuperNode->blendSubLayoutConfig(this, layoutConfig);
|
mSuperNode->blendSubLayoutConfig(this, layoutConfig);
|
||||||
} else {
|
} else {
|
||||||
@ -55,6 +53,7 @@ void DoricViewNode::init(DoricSuperNode *superNode) {
|
|||||||
thiz->mReusable = superNode->mReusable;
|
thiz->mReusable = superNode->mReusable;
|
||||||
}
|
}
|
||||||
this->mSuperNode = superNode;
|
this->mSuperNode = superNode;
|
||||||
|
this->mLayoutConfig = superNode->generateDefaultLayoutConfig();
|
||||||
this->mView = build();
|
this->mView = build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -66,49 +65,49 @@ QString DoricViewNode::getType() { return mType; }
|
|||||||
|
|
||||||
QQuickItem *DoricViewNode::getNodeView() { return mView; }
|
QQuickItem *DoricViewNode::getNodeView() { return mView; }
|
||||||
|
|
||||||
void DoricViewNode::blend(QJSValue jsValue) {
|
void DoricViewNode::blend(QJsonValue jsValue) {
|
||||||
QJSValue value = jsValue.property("layoutConfig");
|
QJsonValue value = jsValue["layoutConfig"];
|
||||||
if (value.isObject()) {
|
if (value.isObject()) {
|
||||||
setLayoutConfig(value);
|
setLayoutConfig(value);
|
||||||
}
|
}
|
||||||
QJSValueIterator it(jsValue);
|
|
||||||
while (it.hasNext()) {
|
foreach (const QString &key, jsValue.toObject().keys()) {
|
||||||
it.next();
|
QJsonValue value = jsValue[key];
|
||||||
blend(mView, it.name(), it.value());
|
blend(mView, key, value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DoricViewNode::blend(QQuickItem *view, QString name, QJSValue prop) {
|
void DoricViewNode::blend(QQuickItem *view, QString name, QJsonValue prop) {
|
||||||
if (name == "width") {
|
if (name == "width") {
|
||||||
if (!prop.isNumber()) {
|
if (!prop.isDouble()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (this->mLayoutConfig.isUndefined()) {
|
if (this->mLayoutConfig.isUndefined()) {
|
||||||
view->setWidth(prop.toInt());
|
view->setWidth(prop.toInt());
|
||||||
} else {
|
} else {
|
||||||
QJSValue widthSpec = this->mLayoutConfig.property("widthSpec");
|
QJsonValue widthSpec = this->mLayoutConfig["widthSpec"];
|
||||||
if (widthSpec.isNumber()) {
|
if (widthSpec.isDouble()) {
|
||||||
if (widthSpec.toInt() == 0) {
|
if (widthSpec.toInt() == 0) {
|
||||||
view->setWidth(prop.toInt());
|
view->setWidth(prop.toInt());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (name == "height") {
|
} else if (name == "height") {
|
||||||
if (!prop.isNumber()) {
|
if (!prop.isDouble()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (this->mLayoutConfig.isUndefined()) {
|
if (this->mLayoutConfig.isUndefined()) {
|
||||||
view->setHeight(prop.toInt());
|
view->setHeight(prop.toInt());
|
||||||
} else {
|
} else {
|
||||||
QJSValue heightSpec = this->mLayoutConfig.property("heightSpec");
|
QJsonValue heightSpec = this->mLayoutConfig["heightSpec"];
|
||||||
if (heightSpec.isNumber()) {
|
if (heightSpec.isDouble()) {
|
||||||
if (heightSpec.toInt() == 0) {
|
if (heightSpec.toInt() == 0) {
|
||||||
view->setHeight(prop.toInt());
|
view->setHeight(prop.toInt());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (name == "backgroundColor") {
|
} else if (name == "backgroundColor") {
|
||||||
QString color = DoricUtils::doricColor(prop.toNumber()).name();
|
QString color = DoricUtils::doricColor(prop.toInt()).name();
|
||||||
view->setProperty("color", color);
|
view->setProperty("color", color);
|
||||||
} else if (name == "x") {
|
} else if (name == "x") {
|
||||||
view->setProperty("x", prop.toInt());
|
view->setProperty("x", prop.toInt());
|
||||||
|
@ -2,6 +2,8 @@
|
|||||||
#define DORICVIEWNODE_H
|
#define DORICVIEWNODE_H
|
||||||
|
|
||||||
#include <QQuickItem>
|
#include <QQuickItem>
|
||||||
|
#include <QJsonValue>
|
||||||
|
#include <QJsonObject>
|
||||||
|
|
||||||
#include "../utils/DoricContextHolder.h"
|
#include "../utils/DoricContextHolder.h"
|
||||||
|
|
||||||
@ -16,12 +18,12 @@ protected:
|
|||||||
|
|
||||||
virtual QQuickItem *build() = 0;
|
virtual QQuickItem *build() = 0;
|
||||||
|
|
||||||
void setLayoutConfig(QJSValue layoutConfig);
|
void setLayoutConfig(QJsonValue layoutConfig);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QString mId;
|
QString mId;
|
||||||
|
|
||||||
QJSValue mLayoutConfig;
|
QJsonValue mLayoutConfig;
|
||||||
|
|
||||||
QList<QString> getIdList();
|
QList<QString> getIdList();
|
||||||
|
|
||||||
@ -57,11 +59,11 @@ public:
|
|||||||
|
|
||||||
QQuickItem *getNodeView();
|
QQuickItem *getNodeView();
|
||||||
|
|
||||||
virtual void blend(QJSValue jsValue);
|
virtual void blend(QJsonValue jsValue);
|
||||||
|
|
||||||
virtual void blend(QQuickItem *view, QString name, QJSValue prop);
|
virtual void blend(QQuickItem *view, QString name, QJsonValue prop);
|
||||||
|
|
||||||
virtual void blendLayoutConfig(QJSValue jsObject);
|
virtual void blendLayoutConfig(QJsonValue jsObject);
|
||||||
|
|
||||||
void onClick();
|
void onClick();
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
#include "DoricConstant.h"
|
#include "DoricConstant.h"
|
||||||
|
|
||||||
const QString DoricConstant::DORIC_BUNDLE_SANDBOX = "doric-sandbox.es5.js";
|
const QString DoricConstant::DORIC_BUNDLE_SANDBOX = "doric-sandbox.js";
|
||||||
const QString DoricConstant::DORIC_BUNDLE_LIB = "doric-lib.es5.js";
|
const QString DoricConstant::DORIC_BUNDLE_LIB = "doric-lib.js";
|
||||||
const QString DoricConstant::DORIC_MODULE_LIB = "doric";
|
const QString DoricConstant::DORIC_MODULE_LIB = "doric";
|
||||||
|
|
||||||
const QString DoricConstant::INJECT_ENVIRONMENT = "Environment";
|
const QString DoricConstant::INJECT_ENVIRONMENT = "Environment";
|
||||||
|
Reference in New Issue
Block a user