add head & tail for h & v layout for fill

This commit is contained in:
王劲鹏 2021-04-07 22:43:21 +08:00 committed by osborn
parent 5229e04752
commit ad1b1a979b
5 changed files with 76 additions and 17 deletions

View File

@ -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
}
}
}

View File

@ -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
}
}
}

View File

@ -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) {

View File

@ -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);
}

View File

@ -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);
}