sync layout change

This commit is contained in:
王劲鹏 2021-08-05 20:59:47 +08:00 committed by osborn
parent bfa865fe5d
commit 4579c4155d

View File

@ -340,6 +340,8 @@ void DoricLayouts::measureVLayoutContent(QSizeF targetSize) {
if (contentWeight > 0) { if (contentWeight > 0) {
qreal remaining = targetSize.height() - contentHeight; qreal remaining = targetSize.height() - contentHeight;
contentWidth = 0; contentWidth = 0;
contentHeight = 0;
had = false;
foreach (QQuickItem *subview, this->view->childItems()) { foreach (QQuickItem *subview, this->view->childItems()) {
DoricLayouts *layout = DoricLayouts *layout =
(DoricLayouts *)(subview->property("doricLayout").toULongLong()); (DoricLayouts *)(subview->property("doricLayout").toULongLong());
@ -350,6 +352,7 @@ void DoricLayouts::measureVLayoutContent(QSizeF targetSize) {
if (layout->disabled) { if (layout->disabled) {
continue; continue;
} }
had = true;
qreal measuredHeight = qreal measuredHeight =
layout->measuredHeight + remaining / contentWeight * layout->weight; layout->measuredHeight + remaining / contentWeight * layout->weight;
layout->measuredHeight = measuredHeight; layout->measuredHeight = measuredHeight;
@ -359,8 +362,11 @@ void DoricLayouts::measureVLayoutContent(QSizeF targetSize) {
measuredHeight - layout->paddingTop - layout->paddingBottom)); measuredHeight - layout->paddingTop - layout->paddingBottom));
layout->measuredHeight = measuredHeight; layout->measuredHeight = measuredHeight;
contentWidth = qMax(contentWidth, layout->takenWidth()); contentWidth = qMax(contentWidth, layout->takenWidth());
contentHeight += layout->takenHeight() + this->spacing;
}
if (had) {
contentHeight -= this->spacing;
} }
contentHeight = targetSize.height();
} }
if (this->widthSpec == DoricLayoutSpec::DoricLayoutFit) { if (this->widthSpec == DoricLayoutSpec::DoricLayoutFit) {
@ -374,6 +380,7 @@ void DoricLayouts::measureVLayoutContent(QSizeF targetSize) {
this->contentWidth = contentWidth; this->contentWidth = contentWidth;
this->contentHeight = contentHeight; this->contentHeight = contentHeight;
} }
void DoricLayouts::measureHLayoutContent(QSizeF targetSize) { void DoricLayouts::measureHLayoutContent(QSizeF targetSize) {
qreal contentWidth = 0, contentHeight = 0, contentWeight = 0; qreal contentWidth = 0, contentHeight = 0, contentWeight = 0;
bool had = false; bool had = false;
@ -402,7 +409,9 @@ void DoricLayouts::measureHLayoutContent(QSizeF targetSize) {
if (contentWeight > 0) { if (contentWeight > 0) {
qreal remaining = targetSize.width() - contentWidth; qreal remaining = targetSize.width() - contentWidth;
contentWidth = 0;
contentHeight = 0; contentHeight = 0;
had = false;
foreach (QQuickItem *subview, this->view->childItems()) { foreach (QQuickItem *subview, this->view->childItems()) {
DoricLayouts *layout = DoricLayouts *layout =
(DoricLayouts *)(subview->property("doricLayout").toULongLong()); (DoricLayouts *)(subview->property("doricLayout").toULongLong());
@ -413,6 +422,7 @@ void DoricLayouts::measureHLayoutContent(QSizeF targetSize) {
if (layout->disabled) { if (layout->disabled) {
continue; continue;
} }
had = true;
qreal measuredWidth = qreal measuredWidth =
layout->measuredWidth + remaining / contentWeight * layout->weight; layout->measuredWidth + remaining / contentWeight * layout->weight;
layout->measuredWidth = measuredWidth; layout->measuredWidth = measuredWidth;
@ -421,9 +431,12 @@ void DoricLayouts::measureHLayoutContent(QSizeF targetSize) {
measuredWidth - layout->paddingLeft - layout->paddingRight, measuredWidth - layout->paddingLeft - layout->paddingRight,
layout->measuredHeight - layout->paddingTop - layout->paddingBottom)); layout->measuredHeight - layout->paddingTop - layout->paddingBottom));
layout->measuredWidth = measuredWidth; layout->measuredWidth = measuredWidth;
contentWidth += layout->takenWidth() + this->spacing;
contentHeight = qMax(contentHeight, layout->takenHeight()); contentHeight = qMax(contentHeight, layout->takenHeight());
} }
contentWidth = targetSize.width(); if (had) {
contentWidth -= this->spacing;
}
} }
if (this->widthSpec == DoricLayoutSpec::DoricLayoutFit) { if (this->widthSpec == DoricLayoutSpec::DoricLayoutFit) {
@ -725,7 +738,8 @@ void DoricLayouts::layoutHLayout() {
// Private Section // Private Section
void DoricLayouts::setMeasuredWidth(qreal measuredWidth) { void DoricLayouts::setMeasuredWidth(qreal measuredWidth) {
this->measuredWidth = measuredWidth; qreal zero = 0;
this->measuredWidth = qMax(zero, measuredWidth);
qCritical() << "DoricLayouts: " << tag << this->view->property("uuid") qCritical() << "DoricLayouts: " << tag << this->view->property("uuid")
<< " measuredWidth: " << this->measuredWidth; << " measuredWidth: " << this->measuredWidth;
} }
@ -733,7 +747,8 @@ void DoricLayouts::setMeasuredWidth(qreal measuredWidth) {
qreal DoricLayouts::getMeasuredWidth() { return this->measuredWidth; } qreal DoricLayouts::getMeasuredWidth() { return this->measuredWidth; }
void DoricLayouts::setMeasuredHeight(qreal measuredHeight) { void DoricLayouts::setMeasuredHeight(qreal measuredHeight) {
this->measuredHeight = measuredHeight; qreal zero = 0;
this->measuredHeight = qMax(zero, measuredHeight);
qCritical() << "DoricLayouts: " << tag << this->view->property("uuid") qCritical() << "DoricLayouts: " << tag << this->view->property("uuid")
<< " measuredHeight: " << this->measuredHeight; << " measuredHeight: " << this->measuredHeight;
} }