From ad1b1a979b3d2ea39abb3f952d19d7f785aa2eb4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=8A=B2=E9=B9=8F?= Date: Wed, 7 Apr 2021 22:43:21 +0800 Subject: [PATCH] add head & tail for h & v layout for fill --- doric-Qt/doric/resources/hlayout.qml | 30 ++++++++++++++++++---- doric-Qt/doric/resources/vlayout.qml | 30 ++++++++++++++++++---- doric-Qt/doric/shader/DoricGroupNode.cpp | 23 ++++++++++++++--- doric-Qt/doric/shader/DoricHLayoutNode.cpp | 5 ++-- doric-Qt/doric/shader/DoricVLayoutNode.cpp | 5 ++-- 5 files changed, 76 insertions(+), 17 deletions(-) diff --git a/doric-Qt/doric/resources/hlayout.qml b/doric-Qt/doric/resources/hlayout.qml index 9c9d51c6..ac147193 100644 --- a/doric-Qt/doric/resources/hlayout.qml +++ b/doric-Qt/doric/resources/hlayout.qml @@ -33,7 +33,7 @@ Rectangle { if (this.widthSpec === 2) { this.width = parent.width -// children[1].width = parent.width + children[1].width = parent.width } } @@ -77,15 +77,35 @@ Rectangle { spacing: 0 + Item { + id: head + objectName: "head" + } + onChildrenChanged: { console.log(tag, uuid + " gravity: " + gravity) for (var i = 0;i !== children.length;i++) { - switch(this.gravity) { - case Gravity.enumerate().CENTER_X: - children[i].Layout.alignment = Qt.AlignHCenter - break + if (children[i] !== head && children[i] !== tail) { + switch(this.gravity) { + case Gravity.enumerate().CENTER_X: + children[i].Layout.alignment = Qt.AlignHCenter + break + case Gravity.enumerate().CENTER: + children[i].Layout.alignment = Qt.AlignCenter + break + } } } + + if (gravity === Gravity.enumerate().CENTER || gravity === Gravity.enumerate().CENTER_X) { + head.Layout.fillWidth = true + } + } + + Item { + id: tail + objectName: "tail" + Layout.fillWidth: true } } } diff --git a/doric-Qt/doric/resources/vlayout.qml b/doric-Qt/doric/resources/vlayout.qml index 225557ab..ca18a124 100644 --- a/doric-Qt/doric/resources/vlayout.qml +++ b/doric-Qt/doric/resources/vlayout.qml @@ -43,7 +43,7 @@ Rectangle { if (this.heightSpec === 2) { this.height = parent.height -// children[1].height = parent.height + children[1].height = parent.height } } @@ -77,16 +77,36 @@ Rectangle { spacing: 0 + Item { + id: head + objectName: "head" + } + onChildrenChanged: { console.log(tag, uuid + " gravity: " + gravity) for (var i = 0;i !== children.length;i++) { - switch(this.gravity) { - case Gravity.enumerate().CENTER_X: - children[i].Layout.alignment = Qt.AlignHCenter - break + if (children[i] !== head && children[i] !== tail) { + switch(this.gravity) { + case Gravity.enumerate().CENTER_X: + children[i].Layout.alignment = Qt.AlignHCenter + break + case Gravity.enumerate().CENTER: + children[i].Layout.alignment = Qt.AlignCenter + break + } } } + + if (gravity === Gravity.enumerate().CENTER || gravity === Gravity.enumerate().CENTER_Y) { + head.Layout.fillHeight = true + } + } + + Item { + id: tail + objectName: "tail" + Layout.fillHeight: true } } } diff --git a/doric-Qt/doric/shader/DoricGroupNode.cpp b/doric-Qt/doric/shader/DoricGroupNode.cpp index d363cd3f..ca4742ca 100644 --- a/doric-Qt/doric/shader/DoricGroupNode.cpp +++ b/doric-Qt/doric/shader/DoricGroupNode.cpp @@ -25,10 +25,10 @@ void DoricGroupNode::blend(QJsonValue jsValue) { void DoricGroupNode::configChildNode() { QQuickItem *parent = nullptr; - if (mType.isEmpty() || mType == "Stack") { - parent = mView; - } else { + if (mType == "HLayout" || mType == "VLayout") { parent = mView->childItems().at(1); + } else { + parent = mView; } for (int idx = 0; idx < mChildViewIds.size(); idx++) { QString id = mChildViewIds.at(idx); @@ -140,6 +140,23 @@ 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) { diff --git a/doric-Qt/doric/shader/DoricHLayoutNode.cpp b/doric-Qt/doric/shader/DoricHLayoutNode.cpp index a4379bd8..8e0e48c3 100644 --- a/doric-Qt/doric/shader/DoricHLayoutNode.cpp +++ b/doric-Qt/doric/shader/DoricHLayoutNode.cpp @@ -16,10 +16,11 @@ QQuickItem *DoricHLayoutNode::build() { } void DoricHLayoutNode::blend(QQuickItem *view, QString name, QJsonValue prop) { + QQuickItem *container = view->childItems().at(1); if (name == "space") { - view->childItems().at(1)->setProperty("spacing", prop.toInt()); + container->setProperty("spacing", prop.toInt()); } else if (name == "gravity") { - view->childItems().at(1)->setProperty("gravity", prop.toInt()); + container->setProperty("gravity", prop.toInt()); } else { DoricGroupNode::blend(view, name, prop); } diff --git a/doric-Qt/doric/shader/DoricVLayoutNode.cpp b/doric-Qt/doric/shader/DoricVLayoutNode.cpp index dc0ba29e..6861cfeb 100644 --- a/doric-Qt/doric/shader/DoricVLayoutNode.cpp +++ b/doric-Qt/doric/shader/DoricVLayoutNode.cpp @@ -16,10 +16,11 @@ QQuickItem *DoricVLayoutNode::build() { } void DoricVLayoutNode::blend(QQuickItem *view, QString name, QJsonValue prop) { + QQuickItem *container = view->childItems().at(1); if (name == "space") { - view->childItems().at(1)->setProperty("spacing", prop.toInt()); + container->setProperty("spacing", prop.toInt()); } else if (name == "gravity") { - view->childItems().at(1)->setProperty("gravity", prop.toInt()); + container->setProperty("gravity", prop.toInt()); } else { DoricGroupNode::blend(view, name, prop); }