add doric layout
This commit is contained in:
@@ -20,16 +20,13 @@ void DoricGroupNode::blend(QQuickItem *view, QString name, QJsonValue prop) {
|
||||
|
||||
void DoricGroupNode::blend(QJsonValue jsValue) {
|
||||
DoricViewNode::blend(jsValue);
|
||||
configChildNode();
|
||||
}
|
||||
|
||||
void DoricGroupNode::afterBlended(QJsonValue props) { configChildNode(); }
|
||||
|
||||
void DoricGroupNode::configChildNode() {
|
||||
QQuickItem *parent = nullptr;
|
||||
if (mType == "HLayout" || mType == "VLayout") {
|
||||
parent = mView->childItems().at(1);
|
||||
} else {
|
||||
parent = mView;
|
||||
}
|
||||
QQuickItem *parent = mView;
|
||||
|
||||
for (int idx = 0; idx < mChildViewIds.size(); idx++) {
|
||||
QString id = mChildViewIds.at(idx);
|
||||
QJsonValue model = getSubModel(id);
|
||||
@@ -140,23 +137,6 @@ void DoricGroupNode::configChildNode() {
|
||||
viewNode->getNodeView()->setParentItem(nullptr);
|
||||
viewNode->getNodeView()->deleteLater();
|
||||
}
|
||||
|
||||
// handle tail
|
||||
if (mType == "VLayout" || mType == "HLayout") {
|
||||
int tailIndex = -1;
|
||||
for (int idx = 0; idx < parent->childItems().size(); idx++) {
|
||||
if (parent->childItems().at(idx)->objectName() == "tail") {
|
||||
tailIndex = idx;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (tailIndex != -1 && tailIndex != parent->childItems().size() - 1) {
|
||||
QQuickItem *tail = parent->childItems().at(tailIndex);
|
||||
tail->setParentItem(nullptr);
|
||||
tail->setParentItem(parent);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void DoricGroupNode::blendSubNode(QJsonValue subProperties) {
|
||||
@@ -168,3 +148,8 @@ void DoricGroupNode::blendSubNode(QJsonValue subProperties) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void DoricGroupNode::requestLayout() {
|
||||
DoricSuperNode::requestLayout();
|
||||
foreach (DoricViewNode *node, this->mChildNodes) { node->requestLayout(); }
|
||||
}
|
||||
|
@@ -19,6 +19,10 @@ protected:
|
||||
void configChildNode();
|
||||
|
||||
virtual void blendSubNode(QJsonValue subProperties) override;
|
||||
|
||||
virtual void afterBlended(QJsonValue props) override;
|
||||
|
||||
virtual void requestLayout() override;
|
||||
};
|
||||
|
||||
#endif // DORICGROUPNODE_H
|
||||
|
@@ -11,16 +11,20 @@ QQuickItem *DoricHLayoutNode::build() {
|
||||
}
|
||||
|
||||
QQuickItem *item = qobject_cast<QQuickItem *>(component.create());
|
||||
this->createLayouts(item);
|
||||
|
||||
getLayouts()->setLayoutType(DoricLayoutType::DoricHLayout);
|
||||
|
||||
item->setProperty("wrapper", QString::number((qint64)this));
|
||||
return item;
|
||||
}
|
||||
|
||||
void DoricHLayoutNode::blend(QQuickItem *view, QString name, QJsonValue prop) {
|
||||
QQuickItem *container = view->childItems().at(1);
|
||||
QQuickItem *container = view;
|
||||
if (name == "space") {
|
||||
container->setProperty("spacing", prop.toInt());
|
||||
getLayouts()->setSpacing(prop.toInt());
|
||||
} else if (name == "gravity") {
|
||||
container->setProperty("gravity", prop.toInt());
|
||||
getLayouts()->setGravity(prop.toInt());
|
||||
} else {
|
||||
DoricGroupNode::blend(view, name, prop);
|
||||
}
|
||||
|
@@ -2,4 +2,12 @@
|
||||
|
||||
void DoricRootNode::setRootView(QQuickItem *rootView) {
|
||||
this->mView = rootView;
|
||||
this->createLayouts(rootView);
|
||||
|
||||
this->getLayouts()->setLayoutType(DoricLayoutType::DoricStack);
|
||||
}
|
||||
|
||||
void DoricRootNode::requestLayout() {
|
||||
getLayouts()->apply();
|
||||
DoricStackNode::requestLayout();
|
||||
}
|
||||
|
@@ -10,6 +10,8 @@ public:
|
||||
using DoricStackNode::DoricStackNode;
|
||||
|
||||
void setRootView(QQuickItem *rootView);
|
||||
|
||||
virtual void requestLayout() override;
|
||||
};
|
||||
|
||||
#endif // ROOTNODE_H
|
||||
|
@@ -11,6 +11,10 @@ QQuickItem *DoricStackNode::build() {
|
||||
}
|
||||
|
||||
QQuickItem *item = qobject_cast<QQuickItem *>(component.create());
|
||||
this->createLayouts(item);
|
||||
|
||||
getLayouts()->setLayoutType(DoricLayoutType::DoricStack);
|
||||
|
||||
item->setProperty("wrapper", QString::number((qint64)this));
|
||||
return item;
|
||||
}
|
||||
|
@@ -54,10 +54,3 @@ void DoricSuperNode::blendSubLayoutConfig(DoricViewNode *viewNode,
|
||||
QJsonValue jsValue) {
|
||||
viewNode->blendLayoutConfig(jsValue);
|
||||
}
|
||||
|
||||
QJsonValue DoricSuperNode::generateDefaultLayoutConfig() {
|
||||
QJsonObject layoutConfig;
|
||||
layoutConfig.insert("widthSpec", SpecMode::JUST);
|
||||
layoutConfig.insert("heightSpec", SpecMode::JUST);
|
||||
return layoutConfig;
|
||||
}
|
||||
|
@@ -23,8 +23,6 @@ public:
|
||||
|
||||
void blendSubLayoutConfig(DoricViewNode *viewNode, QJsonValue jsValue);
|
||||
|
||||
QJsonValue generateDefaultLayoutConfig();
|
||||
|
||||
private:
|
||||
void mixinSubNode(QJsonValue subNode);
|
||||
|
||||
|
@@ -12,6 +12,7 @@ QQuickItem *DoricTextNode::build() {
|
||||
}
|
||||
|
||||
QQuickItem *item = qobject_cast<QQuickItem *>(component.create());
|
||||
this->createLayouts(item);
|
||||
|
||||
item->setProperty("wrapper", QString::number((qint64)this));
|
||||
return item;
|
||||
|
@@ -11,16 +11,20 @@ QQuickItem *DoricVLayoutNode::build() {
|
||||
}
|
||||
|
||||
QQuickItem *item = qobject_cast<QQuickItem *>(component.create());
|
||||
this->createLayouts(item);
|
||||
|
||||
getLayouts()->setLayoutType(DoricLayoutType::DoricVLayout);
|
||||
|
||||
item->setProperty("wrapper", QString::number((qint64)this));
|
||||
return item;
|
||||
}
|
||||
|
||||
void DoricVLayoutNode::blend(QQuickItem *view, QString name, QJsonValue prop) {
|
||||
QQuickItem *container = view->childItems().at(1);
|
||||
QQuickItem *container = view;
|
||||
if (name == "space") {
|
||||
container->setProperty("spacing", prop.toInt());
|
||||
getLayouts()->setSpacing(prop.toInt());
|
||||
} else if (name == "gravity") {
|
||||
container->setProperty("gravity", prop.toInt());
|
||||
getLayouts()->setGravity(prop.toInt());
|
||||
} else {
|
||||
DoricGroupNode::blend(view, name, prop);
|
||||
}
|
||||
|
@@ -3,42 +3,62 @@
|
||||
#include "../utils/DoricUtils.h"
|
||||
#include "DoricSuperNode.h"
|
||||
|
||||
void DoricViewNode::blendLayoutConfig(QJsonValue jsObject) {
|
||||
this->mLayoutConfig = jsObject;
|
||||
void DoricViewNode::blendLayoutConfig(QJsonValue jsValue) {
|
||||
QJsonObject jsObject = jsValue.toObject();
|
||||
if (jsObject.contains("widthSpec"))
|
||||
getLayouts()->setWidthSpec(jsObject["widthSpec"].toInt());
|
||||
|
||||
QJsonValue margin = jsObject["margin"];
|
||||
QJsonValue widthSpec = jsObject["widthSpec"];
|
||||
QJsonValue heightSpec = jsObject["heightSpec"];
|
||||
if (jsObject.contains("heightSpec"))
|
||||
getLayouts()->setHeightSpec(jsObject["heightSpec"].toInt());
|
||||
|
||||
if (widthSpec.isDouble()) {
|
||||
switch (widthSpec.toInt()) {
|
||||
case SpecMode::JUST:
|
||||
mView->setProperty("widthSpec", SpecMode::JUST);
|
||||
break;
|
||||
case SpecMode::FIT:
|
||||
mView->setProperty("widthSpec", SpecMode::FIT);
|
||||
break;
|
||||
case SpecMode::MOST:
|
||||
mView->setProperty("widthSpec", SpecMode::MOST);
|
||||
break;
|
||||
}
|
||||
if (jsObject.contains("margin")) {
|
||||
QJsonObject margin = jsObject["margin"].toObject();
|
||||
|
||||
if (margin.contains("left"))
|
||||
getLayouts()->setMarginLeft(margin["left"].toInt());
|
||||
|
||||
if (margin.contains("top"))
|
||||
getLayouts()->setMarginTop(margin["top"].toInt());
|
||||
|
||||
if (margin.contains("right"))
|
||||
getLayouts()->setMarginRight(margin["right"].toInt());
|
||||
|
||||
if (margin.contains("bottom"))
|
||||
getLayouts()->setMarginBottom(margin["bottom"].toInt());
|
||||
}
|
||||
|
||||
if (heightSpec.isDouble()) {
|
||||
switch (heightSpec.toInt()) {
|
||||
case SpecMode::JUST:
|
||||
mView->setProperty("heightSpec", SpecMode::JUST);
|
||||
break;
|
||||
case SpecMode::FIT:
|
||||
mView->setProperty("heightSpec", SpecMode::FIT);
|
||||
break;
|
||||
case SpecMode::MOST:
|
||||
mView->setProperty("heightSpec", SpecMode::MOST);
|
||||
break;
|
||||
}
|
||||
if (jsObject.contains("alignment"))
|
||||
getLayouts()->setAlignment(jsObject["alignment"].toInt());
|
||||
|
||||
if (jsObject.contains("weight"))
|
||||
getLayouts()->setWeight(jsObject["weight"].toInt());
|
||||
|
||||
if (jsObject.contains("maxWidth"))
|
||||
getLayouts()->setMaxWidth(jsObject["maxWidth"].toInt());
|
||||
|
||||
if (jsObject.contains("maxHeight"))
|
||||
getLayouts()->setMaxHeight(jsObject["maxHeight"].toInt());
|
||||
|
||||
if (jsObject.contains("minWidth"))
|
||||
getLayouts()->setMinWidth(jsObject["minWidth"].toInt());
|
||||
|
||||
if (jsObject.contains("minHeight"))
|
||||
getLayouts()->setMinHeight(jsObject["minHeight"].toInt());
|
||||
}
|
||||
|
||||
void DoricViewNode::createLayouts(QQuickItem *view) {
|
||||
if (mLayouts == nullptr) {
|
||||
mLayouts = new DoricLayouts();
|
||||
mLayouts->setWidth(view->width());
|
||||
mLayouts->setHeight(view->height());
|
||||
mLayouts->setView(view);
|
||||
|
||||
view->setProperty("doricLayout", QString::number((qint64)mLayouts));
|
||||
}
|
||||
}
|
||||
|
||||
DoricLayouts *DoricViewNode::getLayouts() { return mLayouts; }
|
||||
|
||||
void DoricViewNode::setLayoutConfig(QJsonValue layoutConfig) {
|
||||
if (mSuperNode != nullptr) {
|
||||
mSuperNode->blendSubLayoutConfig(this, layoutConfig);
|
||||
@@ -53,8 +73,8 @@ void DoricViewNode::init(DoricSuperNode *superNode) {
|
||||
thiz->mReusable = superNode->mReusable;
|
||||
}
|
||||
this->mSuperNode = superNode;
|
||||
this->mLayoutConfig = superNode->generateDefaultLayoutConfig();
|
||||
this->mView = build();
|
||||
getLayouts();
|
||||
}
|
||||
|
||||
QString DoricViewNode::getId() { return mId; }
|
||||
@@ -75,54 +95,41 @@ void DoricViewNode::blend(QJsonValue jsValue) {
|
||||
QJsonValue value = jsValue[key];
|
||||
blend(mView, key, value);
|
||||
}
|
||||
|
||||
this->afterBlended(jsValue);
|
||||
}
|
||||
|
||||
void DoricViewNode::blend(QQuickItem *view, QString name, QJsonValue prop) {
|
||||
if (name == "width") {
|
||||
if (!prop.isDouble()) {
|
||||
return;
|
||||
}
|
||||
if (this->mLayoutConfig.isUndefined()) {
|
||||
view->setWidth(prop.toInt());
|
||||
} else {
|
||||
QJsonValue widthSpec = this->mLayoutConfig["widthSpec"];
|
||||
if (widthSpec.isDouble()) {
|
||||
if (widthSpec.toInt() == SpecMode::JUST) {
|
||||
view->setWidth(prop.toInt());
|
||||
}
|
||||
}
|
||||
}
|
||||
getLayouts()->setWidth(prop.toInt());
|
||||
} else if (name == "height") {
|
||||
if (!prop.isDouble()) {
|
||||
return;
|
||||
}
|
||||
if (this->mLayoutConfig.isUndefined()) {
|
||||
view->setHeight(prop.toInt());
|
||||
} else {
|
||||
QJsonValue heightSpec = this->mLayoutConfig["heightSpec"];
|
||||
if (heightSpec.isDouble()) {
|
||||
if (heightSpec.toInt() == SpecMode::JUST) {
|
||||
view->setHeight(prop.toInt());
|
||||
}
|
||||
}
|
||||
}
|
||||
getLayouts()->setHeight(prop.toInt());
|
||||
} else if (name == "backgroundColor") {
|
||||
QString color = DoricUtils::doricColor(prop.toInt()).name();
|
||||
view->setProperty("backgroundColor", color);
|
||||
} else if (name == "x") {
|
||||
view->setProperty("x", prop.toInt());
|
||||
getLayouts()->setMarginLeft(prop.toInt());
|
||||
} else if (name == "y") {
|
||||
view->setProperty("y", prop.toInt());
|
||||
getLayouts()->setMarginRight(prop.toInt());
|
||||
} else if (name == "corners") {
|
||||
view->setProperty("radius", prop.toInt());
|
||||
} else if (name == "onClick") {
|
||||
if (prop.isString())
|
||||
clickFunction = prop.toString();
|
||||
} else if (name == "padding") {
|
||||
getLayouts()->setPaddingLeft(prop["left"].toInt());
|
||||
getLayouts()->setPaddingRight(prop["right"].toInt());
|
||||
getLayouts()->setPaddingTop(prop["top"].toInt());
|
||||
getLayouts()->setPaddingBottom(prop["bottom"].toInt());
|
||||
} else if (name == "hidden") {
|
||||
getLayouts()->setDisabled(prop.toBool());
|
||||
} else if (name != "layoutConfig") {
|
||||
qCritical() << name << ": " << prop.toString();
|
||||
}
|
||||
}
|
||||
|
||||
void DoricViewNode::afterBlended(QJsonValue prop) {}
|
||||
|
||||
QList<QString> DoricViewNode::getIdList() {
|
||||
QList<QString> ids;
|
||||
|
||||
@@ -135,6 +142,8 @@ QList<QString> DoricViewNode::getIdList() {
|
||||
return ids;
|
||||
}
|
||||
|
||||
void DoricViewNode::requestLayout() {}
|
||||
|
||||
void DoricViewNode::callJSResponse(QString funcId, QVariantList args) {
|
||||
QVariantList nArgs;
|
||||
QList<QString> idList = getIdList();
|
||||
|
@@ -6,13 +6,7 @@
|
||||
#include <QQuickItem>
|
||||
|
||||
#include "../utils/DoricContextHolder.h"
|
||||
|
||||
class SpecMode {
|
||||
public:
|
||||
const static int JUST = 0;
|
||||
const static int FIT = 1;
|
||||
const static int MOST = 2;
|
||||
};
|
||||
#include "../utils/DoricLayouts.h"
|
||||
|
||||
class DoricSuperNode;
|
||||
|
||||
@@ -21,17 +15,21 @@ class DoricViewNode : public DoricContextHolder {
|
||||
protected:
|
||||
QQuickItem *mView;
|
||||
|
||||
DoricLayouts *mLayouts = nullptr;
|
||||
|
||||
DoricSuperNode *mSuperNode = nullptr;
|
||||
|
||||
virtual QQuickItem *build() = 0;
|
||||
|
||||
void createLayouts(QQuickItem *view);
|
||||
|
||||
DoricLayouts *getLayouts();
|
||||
|
||||
void setLayoutConfig(QJsonValue layoutConfig);
|
||||
|
||||
private:
|
||||
QString mId;
|
||||
|
||||
QJsonValue mLayoutConfig;
|
||||
|
||||
QList<QString> getIdList();
|
||||
|
||||
QString clickFunction;
|
||||
@@ -70,8 +68,12 @@ public:
|
||||
|
||||
virtual void blend(QQuickItem *view, QString name, QJsonValue prop);
|
||||
|
||||
virtual void afterBlended(QJsonValue prop);
|
||||
|
||||
virtual void blendLayoutConfig(QJsonValue jsObject);
|
||||
|
||||
virtual void requestLayout();
|
||||
|
||||
void onClick();
|
||||
|
||||
void callJSResponse(QString funcId, QVariantList args);
|
||||
|
Reference in New Issue
Block a user