2021-04-13 21:14:17 +08:00
|
|
|
#include "DoricLayouts.h"
|
2021-04-19 21:17:40 +08:00
|
|
|
#include "shader/DoricScrollerNode.h"
|
2021-04-13 21:14:17 +08:00
|
|
|
|
2021-04-14 12:42:03 +08:00
|
|
|
DoricLayouts::DoricLayouts(QObject *parent) : QObject(parent) {
|
2021-04-13 21:14:17 +08:00
|
|
|
this->widthSpec = DoricLayoutSpec::DoricLayoutJust;
|
|
|
|
this->heightSpec = DoricLayoutSpec::DoricLayoutJust;
|
2021-04-14 12:42:03 +08:00
|
|
|
|
|
|
|
this->alignment = 0;
|
|
|
|
this->gravity = 0;
|
|
|
|
|
|
|
|
this->width = 0;
|
|
|
|
this->height = 0;
|
|
|
|
|
|
|
|
this->spacing = 0;
|
|
|
|
|
|
|
|
this->marginBottom = 0;
|
|
|
|
this->marginTop = 0;
|
|
|
|
this->marginLeft = 0;
|
|
|
|
this->marginRight = 0;
|
|
|
|
|
|
|
|
this->paddingLeft = 0;
|
|
|
|
this->paddingRight = 0;
|
|
|
|
this->paddingBottom = 0;
|
|
|
|
this->paddingTop = 0;
|
|
|
|
|
|
|
|
this->weight = 0;
|
|
|
|
|
|
|
|
this->layoutType = DoricLayoutType::DoricUndefined;
|
|
|
|
|
|
|
|
this->disabled = false;
|
|
|
|
|
|
|
|
this->maxWidth = INT_MAX;
|
|
|
|
this->maxHeight = INT_MAX;
|
2021-04-13 21:14:17 +08:00
|
|
|
this->minWidth = 0;
|
|
|
|
this->minHeight = 0;
|
2021-04-14 12:42:03 +08:00
|
|
|
|
|
|
|
this->measuredWidth = 0;
|
|
|
|
this->measuredHeight = 0;
|
|
|
|
|
|
|
|
this->measuredX = 0;
|
|
|
|
this->measuredY = 0;
|
|
|
|
|
|
|
|
this->undefined = false;
|
|
|
|
|
|
|
|
this->contentWidth = 0;
|
|
|
|
this->contentHeight = 0;
|
2021-04-13 21:14:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void DoricLayouts::setWidthSpec(int widthSpec) { this->widthSpec = widthSpec; }
|
|
|
|
void DoricLayouts::setHeightSpec(int heightSpec) {
|
|
|
|
this->heightSpec = heightSpec;
|
|
|
|
}
|
|
|
|
|
|
|
|
void DoricLayouts::setAlignment(int alignment) { this->alignment = alignment; }
|
|
|
|
|
|
|
|
void DoricLayouts::setGravity(int gravity) { this->gravity = gravity; }
|
|
|
|
|
2021-04-15 10:20:55 +08:00
|
|
|
void DoricLayouts::setWidth(qreal width) { this->width = width; }
|
|
|
|
void DoricLayouts::setHeight(qreal height) { this->height = height; }
|
2021-04-13 21:14:17 +08:00
|
|
|
|
2021-04-15 10:20:55 +08:00
|
|
|
void DoricLayouts::setSpacing(qreal spacing) { this->spacing = spacing; }
|
2021-04-13 21:14:17 +08:00
|
|
|
|
2021-04-15 10:20:55 +08:00
|
|
|
void DoricLayouts::setMarginLeft(qreal marginLeft) {
|
2021-04-13 21:14:17 +08:00
|
|
|
this->marginLeft = marginLeft;
|
|
|
|
}
|
2021-04-15 10:20:55 +08:00
|
|
|
void DoricLayouts::setMarginTop(qreal marginTop) {
|
|
|
|
this->marginTop = marginTop;
|
|
|
|
}
|
|
|
|
void DoricLayouts::setMarginRight(qreal marginRight) {
|
2021-04-13 21:14:17 +08:00
|
|
|
this->marginRight = marginRight;
|
|
|
|
}
|
2021-04-15 10:20:55 +08:00
|
|
|
void DoricLayouts::setMarginBottom(qreal marginBottom) {
|
2021-04-13 21:14:17 +08:00
|
|
|
this->marginBottom = marginBottom;
|
|
|
|
}
|
|
|
|
|
2021-04-15 10:20:55 +08:00
|
|
|
void DoricLayouts::setPaddingLeft(qreal paddingLeft) {
|
2021-04-13 21:14:17 +08:00
|
|
|
this->paddingLeft = paddingLeft;
|
|
|
|
}
|
2021-04-15 10:20:55 +08:00
|
|
|
void DoricLayouts::setPaddingTop(qreal paddingTop) {
|
2021-04-13 21:14:17 +08:00
|
|
|
this->paddingTop = paddingTop;
|
|
|
|
}
|
2021-04-15 10:20:55 +08:00
|
|
|
void DoricLayouts::setPaddingRight(qreal paddingRight) {
|
2021-04-13 21:14:17 +08:00
|
|
|
this->paddingRight = paddingRight;
|
|
|
|
}
|
2021-04-15 10:20:55 +08:00
|
|
|
void DoricLayouts::setPaddingBottom(qreal paddingBottom) {
|
2021-04-13 21:14:17 +08:00
|
|
|
this->paddingBottom = paddingBottom;
|
|
|
|
}
|
|
|
|
|
|
|
|
void DoricLayouts::setWeight(int weight) { this->weight = weight; }
|
|
|
|
|
|
|
|
void DoricLayouts::setView(QQuickItem *view) {
|
|
|
|
this->view = view;
|
2021-04-14 12:42:03 +08:00
|
|
|
this->setParent(view);
|
2021-04-13 21:14:17 +08:00
|
|
|
this->tag = view->property("tag").toString();
|
|
|
|
}
|
|
|
|
|
|
|
|
void DoricLayouts::setLayoutType(int layoutType) {
|
|
|
|
this->layoutType = layoutType;
|
|
|
|
}
|
|
|
|
|
|
|
|
void DoricLayouts::setDisabled(bool disabled) { this->disabled = disabled; }
|
|
|
|
|
2021-04-15 10:20:55 +08:00
|
|
|
void DoricLayouts::setMaxWidth(qreal maxWidth) { this->maxWidth = maxWidth; }
|
|
|
|
void DoricLayouts::setMaxHeight(qreal maxHeight) {
|
|
|
|
this->maxHeight = maxHeight;
|
|
|
|
}
|
|
|
|
void DoricLayouts::setMinWidth(qreal minWidth) { this->minWidth = minWidth; }
|
|
|
|
void DoricLayouts::setMinHeight(qreal minHeight) {
|
|
|
|
this->minHeight = minHeight;
|
|
|
|
}
|
2021-04-13 21:14:17 +08:00
|
|
|
|
2021-04-19 19:22:10 +08:00
|
|
|
void DoricLayouts::apply(QSizeF frameSize) {
|
2021-04-13 21:14:17 +08:00
|
|
|
this->resolved = false;
|
|
|
|
|
2021-04-19 19:22:10 +08:00
|
|
|
this->measure(frameSize);
|
2021-04-13 21:14:17 +08:00
|
|
|
this->setFrame();
|
|
|
|
|
|
|
|
this->resolved = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void DoricLayouts::apply() {
|
2021-04-19 19:22:10 +08:00
|
|
|
this->apply(QSizeF(this->view->width(), this->view->height()));
|
2021-04-13 21:14:17 +08:00
|
|
|
}
|
|
|
|
|
2021-04-19 19:22:10 +08:00
|
|
|
void DoricLayouts::measure(QSizeF targetSize) {
|
|
|
|
this->measureSelf(targetSize);
|
2021-04-13 21:14:17 +08:00
|
|
|
this->layout();
|
|
|
|
}
|
|
|
|
|
2021-04-19 19:22:10 +08:00
|
|
|
void DoricLayouts::measureSelf(QSizeF targetSize) {
|
2021-04-13 21:14:17 +08:00
|
|
|
// measure width
|
2021-04-15 10:20:55 +08:00
|
|
|
qreal width;
|
2021-04-13 21:14:17 +08:00
|
|
|
if (this->widthSpec == DoricLayoutSpec::DoricLayoutMost) {
|
|
|
|
QQuickItem *parent = this->view->parentItem();
|
2021-04-25 14:36:42 +08:00
|
|
|
if (parent == nullptr) {
|
|
|
|
// incase parent is scroller
|
2021-04-19 19:22:10 +08:00
|
|
|
width = targetSize.width();
|
|
|
|
setMeasuredWidth(targetSize.width());
|
2021-04-25 14:36:42 +08:00
|
|
|
} else {
|
|
|
|
DoricLayouts *parentDoricLayout =
|
|
|
|
(DoricLayouts *)(parent->property("doricLayout").toULongLong());
|
|
|
|
if (parentDoricLayout != nullptr &&
|
|
|
|
parentDoricLayout->layoutType == DoricLayoutType::DoricHLayout &&
|
|
|
|
this->weight > 0) {
|
|
|
|
width = 0;
|
|
|
|
setMeasuredWidth(0);
|
|
|
|
} else {
|
|
|
|
width = targetSize.width();
|
|
|
|
setMeasuredWidth(targetSize.width());
|
|
|
|
}
|
2021-04-13 21:14:17 +08:00
|
|
|
}
|
|
|
|
} else if (this->widthSpec == DoricLayoutSpec::DoricLayoutJust) {
|
2021-04-14 12:42:03 +08:00
|
|
|
width = this->width;
|
|
|
|
setMeasuredWidth(this->width);
|
2021-04-13 21:14:17 +08:00
|
|
|
} else {
|
2021-04-19 19:22:10 +08:00
|
|
|
width = targetSize.width();
|
2021-04-13 21:14:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// measure height
|
2021-04-15 10:20:55 +08:00
|
|
|
qreal height;
|
2021-04-13 21:14:17 +08:00
|
|
|
if (this->heightSpec == DoricLayoutSpec::DoricLayoutMost) {
|
|
|
|
QQuickItem *parent = this->view->parentItem();
|
2021-04-25 14:36:42 +08:00
|
|
|
if (parent == nullptr) {
|
|
|
|
// incase parent is scroller
|
2021-04-19 19:22:10 +08:00
|
|
|
height = targetSize.height();
|
|
|
|
setMeasuredHeight(targetSize.height());
|
2021-04-25 14:36:42 +08:00
|
|
|
} else {
|
|
|
|
DoricLayouts *parentDoricLayout =
|
|
|
|
(DoricLayouts *)(parent->property("doricLayout").toULongLong());
|
|
|
|
if (parentDoricLayout != nullptr &&
|
|
|
|
parentDoricLayout->layoutType == DoricLayoutType::DoricVLayout &&
|
|
|
|
this->weight > 0) {
|
|
|
|
height = 0;
|
|
|
|
setMeasuredHeight(0);
|
|
|
|
} else {
|
|
|
|
height = targetSize.height();
|
|
|
|
setMeasuredHeight(targetSize.height());
|
|
|
|
}
|
2021-04-13 21:14:17 +08:00
|
|
|
}
|
2021-04-25 14:36:42 +08:00
|
|
|
|
2021-04-13 21:14:17 +08:00
|
|
|
} else if (this->heightSpec == DoricLayoutSpec::DoricLayoutJust) {
|
2021-04-14 12:42:03 +08:00
|
|
|
height = this->height;
|
|
|
|
setMeasuredHeight(this->height);
|
2021-04-13 21:14:17 +08:00
|
|
|
} else {
|
2021-04-19 19:22:10 +08:00
|
|
|
height = targetSize.height();
|
2021-04-13 21:14:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// measure content
|
2021-04-19 19:22:10 +08:00
|
|
|
this->measureContent(QSizeF(width - this->paddingLeft - this->paddingRight,
|
|
|
|
height - this->paddingTop - this->paddingBottom));
|
2021-04-13 21:14:17 +08:00
|
|
|
|
|
|
|
if (this->restrainSize()) {
|
|
|
|
this->measureContent(
|
2021-04-19 19:22:10 +08:00
|
|
|
QSizeF(this->measuredWidth - this->paddingLeft - this->paddingRight,
|
|
|
|
this->measuredHeight - this->paddingTop - this->paddingBottom));
|
2021-04-13 21:14:17 +08:00
|
|
|
}
|
|
|
|
this->restrainSize();
|
|
|
|
}
|
|
|
|
|
2021-04-19 19:22:10 +08:00
|
|
|
void DoricLayouts::measureContent(QSizeF targetSize) {
|
2021-04-14 12:42:03 +08:00
|
|
|
qCritical() << "measureContent: " << tag << this->view->property("uuid");
|
2021-04-13 21:14:17 +08:00
|
|
|
switch (this->layoutType) {
|
|
|
|
case DoricLayoutType::DoricStack: {
|
2021-04-19 19:22:10 +08:00
|
|
|
this->measureStackContent(targetSize);
|
2021-04-13 21:14:17 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case DoricLayoutType::DoricVLayout: {
|
2021-04-19 19:22:10 +08:00
|
|
|
this->measureVLayoutContent(targetSize);
|
2021-04-13 21:14:17 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case DoricLayoutType::DoricHLayout: {
|
2021-04-19 19:22:10 +08:00
|
|
|
this->measureHLayoutContent(targetSize);
|
2021-04-13 21:14:17 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
default: {
|
2021-04-19 19:22:10 +08:00
|
|
|
this->measureUndefinedContent(targetSize);
|
2021-04-13 21:14:17 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
QQuickItem *parent = this->view->parentItem();
|
2021-04-16 16:44:08 +08:00
|
|
|
if (parent != nullptr) {
|
|
|
|
DoricLayouts *parentDoricLayout =
|
|
|
|
(DoricLayouts *)(parent->property("doricLayout").toULongLong());
|
|
|
|
if (parentDoricLayout != nullptr) {
|
|
|
|
if (parentDoricLayout->layoutType != DoricLayoutType::DoricUndefined &&
|
|
|
|
parentDoricLayout->widthSpec == DoricLayoutSpec::DoricLayoutFit &&
|
|
|
|
this->widthSpec == DoricLayoutSpec::DoricLayoutMost) {
|
2021-04-19 19:22:10 +08:00
|
|
|
setMeasuredWidth(targetSize.width());
|
2021-04-16 16:44:08 +08:00
|
|
|
}
|
|
|
|
if (parentDoricLayout->layoutType != DoricLayoutType::DoricUndefined &&
|
|
|
|
parentDoricLayout->heightSpec == DoricLayoutSpec::DoricLayoutFit &&
|
|
|
|
this->heightSpec == DoricLayoutSpec::DoricLayoutMost) {
|
2021-04-19 19:22:10 +08:00
|
|
|
setMeasuredHeight(targetSize.height());
|
2021-04-16 16:44:08 +08:00
|
|
|
}
|
2021-04-13 21:14:17 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-19 19:22:10 +08:00
|
|
|
void DoricLayouts::measureUndefinedContent(QSizeF targetSize) {
|
2021-04-19 21:17:40 +08:00
|
|
|
// begin size that fits
|
2021-04-20 11:46:56 +08:00
|
|
|
QSizeF measuredSize;
|
2021-04-13 21:14:17 +08:00
|
|
|
|
2021-04-19 21:17:40 +08:00
|
|
|
if (tag == "Scroller") {
|
|
|
|
QObject *object =
|
|
|
|
(QObject *)(this->view->property("wrapper").toULongLong());
|
|
|
|
DoricScrollerNode *viewNode = dynamic_cast<DoricScrollerNode *>(object);
|
2021-04-20 11:46:56 +08:00
|
|
|
measuredSize = viewNode->sizeThatFits(targetSize);
|
2021-04-19 21:17:40 +08:00
|
|
|
} else {
|
2021-04-20 11:46:56 +08:00
|
|
|
qreal actualWidth = this->view->width();
|
|
|
|
qreal actualHeight = this->view->height();
|
|
|
|
|
|
|
|
measuredSize = QSizeF(actualWidth, actualHeight);
|
2021-04-13 21:14:17 +08:00
|
|
|
}
|
2021-04-19 21:17:40 +08:00
|
|
|
// end size that fits
|
|
|
|
|
2021-04-13 21:14:17 +08:00
|
|
|
if (this->widthSpec == DoricLayoutSpec::DoricLayoutFit) {
|
2021-04-20 11:46:56 +08:00
|
|
|
setMeasuredWidth(measuredSize.width() + this->paddingLeft +
|
|
|
|
this->paddingRight);
|
2021-04-13 21:14:17 +08:00
|
|
|
}
|
|
|
|
if (this->heightSpec == DoricLayoutSpec::DoricLayoutFit) {
|
2021-04-20 11:46:56 +08:00
|
|
|
setMeasuredHeight(measuredSize.height() + this->paddingTop +
|
|
|
|
this->paddingBottom);
|
2021-04-13 21:14:17 +08:00
|
|
|
}
|
|
|
|
}
|
2021-04-19 19:22:10 +08:00
|
|
|
void DoricLayouts::measureStackContent(QSizeF targetSize) {
|
2021-04-15 10:20:55 +08:00
|
|
|
qreal contentWidth = 0, contentHeight = 0;
|
2021-04-13 21:14:17 +08:00
|
|
|
foreach (QQuickItem *subview, this->view->childItems()) {
|
|
|
|
DoricLayouts *layout =
|
|
|
|
(DoricLayouts *)(subview->property("doricLayout").toULongLong());
|
|
|
|
if (layout == nullptr) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (layout->disabled) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2021-04-19 19:22:10 +08:00
|
|
|
layout->measure(layout->removeMargin(targetSize));
|
2021-04-13 21:14:17 +08:00
|
|
|
contentWidth = qMax(contentWidth, layout->takenWidth());
|
|
|
|
contentHeight = qMax(contentHeight, layout->takenHeight());
|
|
|
|
}
|
|
|
|
if (this->widthSpec == DoricLayoutSpec::DoricLayoutFit) {
|
2021-04-14 12:42:03 +08:00
|
|
|
setMeasuredWidth(contentWidth + this->paddingLeft + this->paddingRight);
|
2021-04-13 21:14:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (this->heightSpec == DoricLayoutSpec::DoricLayoutFit) {
|
2021-04-14 12:42:03 +08:00
|
|
|
setMeasuredHeight(contentHeight + this->paddingTop + this->paddingBottom);
|
2021-04-13 21:14:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
this->contentWidth = contentWidth;
|
|
|
|
this->contentHeight = contentHeight;
|
|
|
|
}
|
2021-04-19 19:22:10 +08:00
|
|
|
void DoricLayouts::measureVLayoutContent(QSizeF targetSize) {
|
2021-04-15 10:20:55 +08:00
|
|
|
qreal contentWidth = 0, contentHeight = 0, contentWeight = 0;
|
2021-04-13 21:14:17 +08:00
|
|
|
bool had = false;
|
|
|
|
foreach (QQuickItem *subview, this->view->childItems()) {
|
|
|
|
DoricLayouts *layout =
|
|
|
|
(DoricLayouts *)(subview->property("doricLayout").toULongLong());
|
|
|
|
if (layout == nullptr) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (layout->disabled) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
had = true;
|
|
|
|
|
2021-04-19 19:22:10 +08:00
|
|
|
layout->measure(layout->removeMargin(
|
|
|
|
QSizeF(targetSize.width(), targetSize.height() - contentHeight)));
|
2021-04-13 21:14:17 +08:00
|
|
|
contentWidth = qMax(contentWidth, layout->takenWidth());
|
|
|
|
contentHeight += layout->takenHeight() + this->spacing;
|
|
|
|
contentWeight += layout->weight;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (had) {
|
|
|
|
contentHeight -= this->spacing;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (contentWeight > 0) {
|
2021-04-19 19:22:10 +08:00
|
|
|
qreal remaining = targetSize.height() - contentHeight;
|
2021-04-13 21:14:17 +08:00
|
|
|
contentWidth = 0;
|
|
|
|
foreach (QQuickItem *subview, this->view->childItems()) {
|
|
|
|
DoricLayouts *layout =
|
|
|
|
(DoricLayouts *)(subview->property("doricLayout").toULongLong());
|
|
|
|
if (layout == nullptr) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (layout->disabled) {
|
|
|
|
continue;
|
|
|
|
}
|
2021-04-15 10:20:55 +08:00
|
|
|
qreal measuredHeight =
|
2021-04-13 21:14:17 +08:00
|
|
|
layout->measuredHeight + remaining / contentWeight * layout->weight;
|
|
|
|
layout->measuredHeight = measuredHeight;
|
|
|
|
// Need Remeasure
|
2021-04-19 19:22:10 +08:00
|
|
|
layout->measureContent(QSizeF(
|
2021-04-13 21:14:17 +08:00
|
|
|
layout->measuredWidth - layout->paddingLeft - layout->paddingRight,
|
2021-04-19 19:22:10 +08:00
|
|
|
measuredHeight - layout->paddingTop - layout->paddingBottom));
|
2021-04-13 21:14:17 +08:00
|
|
|
layout->measuredHeight = measuredHeight;
|
|
|
|
contentWidth = qMax(contentWidth, layout->takenWidth());
|
|
|
|
}
|
2021-04-19 19:22:10 +08:00
|
|
|
contentHeight = targetSize.height();
|
2021-04-13 21:14:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (this->widthSpec == DoricLayoutSpec::DoricLayoutFit) {
|
2021-04-14 12:42:03 +08:00
|
|
|
setMeasuredWidth(contentWidth + this->paddingLeft + this->paddingRight);
|
2021-04-13 21:14:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (this->heightSpec == DoricLayoutSpec::DoricLayoutFit) {
|
2021-04-14 12:42:03 +08:00
|
|
|
setMeasuredHeight(contentHeight + this->paddingTop + this->paddingBottom);
|
2021-04-13 21:14:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
this->contentWidth = contentWidth;
|
|
|
|
this->contentHeight = contentHeight;
|
|
|
|
}
|
2021-04-19 19:22:10 +08:00
|
|
|
void DoricLayouts::measureHLayoutContent(QSizeF targetSize) {
|
2021-04-15 10:20:55 +08:00
|
|
|
qreal contentWidth = 0, contentHeight = 0, contentWeight = 0;
|
2021-04-13 21:14:17 +08:00
|
|
|
bool had = false;
|
|
|
|
foreach (QQuickItem *subview, this->view->childItems()) {
|
|
|
|
DoricLayouts *layout =
|
|
|
|
(DoricLayouts *)(subview->property("doricLayout").toULongLong());
|
|
|
|
if (layout == nullptr) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (layout->disabled) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
had = true;
|
2021-04-19 19:22:10 +08:00
|
|
|
|
|
|
|
layout->measure(layout->removeMargin(
|
|
|
|
QSizeF(targetSize.width() - contentWidth, targetSize.height())));
|
2021-04-13 21:14:17 +08:00
|
|
|
contentWidth += layout->takenWidth() + this->spacing;
|
|
|
|
contentHeight = qMax(contentHeight, layout->takenHeight());
|
|
|
|
contentWeight += layout->weight;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (had) {
|
|
|
|
contentWidth -= this->spacing;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (contentWeight > 0) {
|
2021-04-19 19:22:10 +08:00
|
|
|
qreal remaining = targetSize.width() - contentWidth;
|
2021-04-13 21:14:17 +08:00
|
|
|
contentHeight = 0;
|
|
|
|
foreach (QQuickItem *subview, this->view->childItems()) {
|
|
|
|
DoricLayouts *layout =
|
|
|
|
(DoricLayouts *)(subview->property("doricLayout").toULongLong());
|
|
|
|
if (layout == nullptr) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (layout->disabled) {
|
|
|
|
continue;
|
|
|
|
}
|
2021-04-15 10:20:55 +08:00
|
|
|
qreal measuredWidth =
|
2021-04-13 21:14:17 +08:00
|
|
|
layout->measuredWidth + remaining / contentWeight * layout->weight;
|
|
|
|
layout->measuredWidth = measuredWidth;
|
|
|
|
// Need Remeasure
|
2021-04-19 19:22:10 +08:00
|
|
|
layout->measureContent(QSizeF(
|
2021-04-13 21:14:17 +08:00
|
|
|
measuredWidth - layout->paddingLeft - layout->paddingRight,
|
2021-04-19 19:22:10 +08:00
|
|
|
layout->measuredHeight - layout->paddingTop - layout->paddingBottom));
|
2021-04-13 21:14:17 +08:00
|
|
|
layout->measuredWidth = measuredWidth;
|
|
|
|
contentHeight = qMax(contentHeight, layout->takenHeight());
|
|
|
|
}
|
2021-04-19 19:22:10 +08:00
|
|
|
contentWidth = targetSize.width();
|
2021-04-13 21:14:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (this->widthSpec == DoricLayoutSpec::DoricLayoutFit) {
|
2021-04-14 12:42:03 +08:00
|
|
|
setMeasuredWidth(contentWidth + this->paddingLeft + this->paddingRight);
|
2021-04-13 21:14:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (this->heightSpec == DoricLayoutSpec::DoricLayoutFit) {
|
2021-04-14 12:42:03 +08:00
|
|
|
setMeasuredHeight(contentHeight + this->paddingTop + this->paddingBottom);
|
2021-04-13 21:14:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
this->contentWidth = contentWidth;
|
|
|
|
this->contentHeight = contentHeight;
|
|
|
|
}
|
|
|
|
|
2021-04-15 10:20:55 +08:00
|
|
|
qreal DoricLayouts::takenWidth() {
|
2021-04-13 21:14:17 +08:00
|
|
|
return this->measuredWidth + this->marginLeft + this->marginRight;
|
|
|
|
}
|
2021-04-15 10:20:55 +08:00
|
|
|
qreal DoricLayouts::takenHeight() {
|
2021-04-13 21:14:17 +08:00
|
|
|
return this->measuredHeight + this->marginTop + this->marginBottom;
|
|
|
|
}
|
2021-04-19 19:22:10 +08:00
|
|
|
QSizeF DoricLayouts::removeMargin(QSizeF targetSize) {
|
|
|
|
return QSizeF(targetSize.width() - this->marginLeft - this->marginRight,
|
|
|
|
targetSize.height() - this->marginTop - this->marginBottom);
|
2021-04-13 21:14:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool DoricLayouts::restrainSize() {
|
|
|
|
bool needRemeasure = false;
|
|
|
|
if (this->measuredWidth > this->maxWidth) {
|
2021-04-14 12:42:03 +08:00
|
|
|
setMeasuredWidth(this->maxWidth);
|
2021-04-13 21:14:17 +08:00
|
|
|
needRemeasure = true;
|
|
|
|
}
|
|
|
|
if (this->measuredHeight > this->maxHeight) {
|
2021-04-14 12:42:03 +08:00
|
|
|
setMeasuredHeight(this->maxHeight);
|
2021-04-13 21:14:17 +08:00
|
|
|
needRemeasure = true;
|
|
|
|
}
|
|
|
|
if (this->measuredWidth < this->minWidth) {
|
2021-04-14 12:42:03 +08:00
|
|
|
setMeasuredWidth(this->minWidth);
|
2021-04-13 21:14:17 +08:00
|
|
|
needRemeasure = true;
|
|
|
|
}
|
|
|
|
if (this->measuredHeight < this->minHeight) {
|
2021-04-14 12:42:03 +08:00
|
|
|
setMeasuredHeight(this->minHeight);
|
2021-04-13 21:14:17 +08:00
|
|
|
needRemeasure = true;
|
|
|
|
}
|
|
|
|
return needRemeasure;
|
|
|
|
}
|
|
|
|
|
|
|
|
void DoricLayouts::layout() {
|
|
|
|
switch (this->layoutType) {
|
|
|
|
case DoricLayoutType::DoricStack: {
|
|
|
|
this->layoutStack();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case DoricLayoutType::DoricVLayout: {
|
|
|
|
this->layoutVLayout();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case DoricLayoutType::DoricHLayout: {
|
|
|
|
this->layoutHLayout();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default: {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void DoricLayouts::setFrame() {
|
|
|
|
if (this->layoutType != DoricLayoutType::DoricUndefined) {
|
|
|
|
foreach (QQuickItem *subview, this->view->childItems()) {
|
|
|
|
DoricLayouts *layout =
|
|
|
|
(DoricLayouts *)(subview->property("doricLayout").toULongLong());
|
|
|
|
if (layout == nullptr) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
layout->setFrame();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-16 16:44:08 +08:00
|
|
|
qCritical() << "DoricLayouts setProperty: " << tag
|
|
|
|
<< this->view->property("uuid")
|
2021-04-14 14:25:55 +08:00
|
|
|
<< " measuredWidth: " << this->measuredWidth
|
2021-04-14 12:42:03 +08:00
|
|
|
<< " measuredHeight: " << this->measuredHeight
|
2021-04-15 10:20:55 +08:00
|
|
|
<< " width: " << this->view->width()
|
|
|
|
<< " height: " << this->view->height()
|
2021-04-14 12:42:03 +08:00
|
|
|
<< " measuredX: " << this->measuredX
|
|
|
|
<< " measuredY: " << this->measuredY;
|
|
|
|
|
2021-04-15 10:20:55 +08:00
|
|
|
if (qFabs(this->measuredWidth - this->view->width() >= 0.00001f))
|
|
|
|
this->view->setProperty("width", this->measuredWidth);
|
|
|
|
if (qFabs(this->measuredHeight - this->view->height() >= 0.00001f))
|
|
|
|
this->view->setProperty("height", this->measuredHeight);
|
|
|
|
|
2021-04-13 21:14:17 +08:00
|
|
|
this->view->setProperty("x", this->measuredX);
|
|
|
|
this->view->setProperty("y", this->measuredY);
|
|
|
|
}
|
|
|
|
|
|
|
|
void DoricLayouts::layoutStack() {
|
|
|
|
foreach (QQuickItem *subview, this->view->childItems()) {
|
|
|
|
DoricLayouts *layout =
|
|
|
|
(DoricLayouts *)(subview->property("doricLayout").toULongLong());
|
|
|
|
if (layout == nullptr) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (layout->disabled) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (this->widthSpec == DoricLayoutSpec::DoricLayoutFit &&
|
|
|
|
layout->widthSpec == DoricLayoutSpec::DoricLayoutMost) {
|
|
|
|
layout->measuredWidth =
|
|
|
|
this->measuredWidth - layout->marginLeft - layout->marginRight;
|
|
|
|
}
|
|
|
|
if (this->heightSpec == DoricLayoutSpec::DoricLayoutFit &&
|
|
|
|
layout->heightSpec == DoricLayoutSpec::DoricLayoutMost) {
|
|
|
|
layout->measuredHeight =
|
|
|
|
this->measuredHeight - layout->marginTop - layout->marginBottom;
|
|
|
|
}
|
|
|
|
layout->layout();
|
|
|
|
|
|
|
|
int gravity = layout->alignment;
|
|
|
|
if ((gravity & DoricGravity::DoricGravityLeft) ==
|
|
|
|
DoricGravity::DoricGravityLeft) {
|
2021-04-15 10:20:55 +08:00
|
|
|
layout->setMeasuredX(this->paddingLeft);
|
2021-04-13 21:14:17 +08:00
|
|
|
} else if ((gravity & DoricGravity::DoricGravityRight) ==
|
|
|
|
DoricGravity::DoricGravityRight) {
|
2021-04-15 10:20:55 +08:00
|
|
|
layout->setMeasuredX(this->measuredWidth - this->paddingRight -
|
|
|
|
layout->measuredWidth);
|
2021-04-13 21:14:17 +08:00
|
|
|
} else if ((gravity & DoricGravity::DoricGravityCenterX) ==
|
|
|
|
DoricGravity::DoricGravityCenterX) {
|
2021-04-15 10:20:55 +08:00
|
|
|
layout->setMeasuredX(this->measuredWidth / 2 - layout->measuredWidth / 2);
|
2021-04-13 21:14:17 +08:00
|
|
|
} else {
|
|
|
|
if (layout->marginLeft || layout->marginRight) {
|
2021-04-15 10:20:55 +08:00
|
|
|
layout->setMeasuredX(this->paddingLeft);
|
2021-04-13 21:14:17 +08:00
|
|
|
} else {
|
2021-04-15 10:20:55 +08:00
|
|
|
layout->setMeasuredX(0);
|
2021-04-13 21:14:17 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((gravity & DoricGravity::DoricGravityTop) ==
|
|
|
|
DoricGravity::DoricGravityTop) {
|
2021-04-16 19:09:25 +08:00
|
|
|
layout->setMeasuredY(this->paddingTop);
|
2021-04-13 21:14:17 +08:00
|
|
|
} else if ((gravity & DoricGravity::DoricGravityBottom) ==
|
|
|
|
DoricGravity::DoricGravityBottom) {
|
2021-04-16 19:09:25 +08:00
|
|
|
layout->setMeasuredY(this->measuredHeight - this->paddingBottom -
|
|
|
|
layout->measuredHeight);
|
2021-04-13 21:14:17 +08:00
|
|
|
} else if ((gravity & DoricGravity::DoricGravityCenterY) ==
|
|
|
|
DoricGravity::DoricGravityCenterY) {
|
2021-04-16 19:09:25 +08:00
|
|
|
layout->setMeasuredY(this->measuredHeight / 2 -
|
|
|
|
layout->measuredHeight / 2);
|
2021-04-13 21:14:17 +08:00
|
|
|
} else {
|
|
|
|
if (layout->marginTop || layout->marginBottom) {
|
2021-04-16 19:09:25 +08:00
|
|
|
layout->setMeasuredY(this->paddingTop);
|
2021-04-13 21:14:17 +08:00
|
|
|
} else {
|
2021-04-16 19:09:25 +08:00
|
|
|
layout->setMeasuredY(0);
|
2021-04-13 21:14:17 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!gravity) {
|
|
|
|
gravity = DoricGravity::DoricGravityLeft | DoricGravity::DoricGravityTop;
|
|
|
|
}
|
|
|
|
if (layout->marginLeft && !((gravity & DoricGravity::DoricGravityRight) ==
|
|
|
|
DoricGravity::DoricGravityRight)) {
|
|
|
|
layout->measuredX += layout->marginLeft;
|
|
|
|
}
|
|
|
|
if (layout->marginRight && !((gravity & DoricGravity::DoricGravityLeft) ==
|
|
|
|
DoricGravity::DoricGravityLeft)) {
|
|
|
|
layout->measuredX -= layout->marginRight;
|
|
|
|
}
|
|
|
|
if (layout->marginTop && !((gravity & DoricGravity::DoricGravityBottom) ==
|
|
|
|
DoricGravity::DoricGravityBottom)) {
|
|
|
|
layout->measuredY += layout->marginTop;
|
|
|
|
}
|
|
|
|
if (layout->marginBottom && !((gravity & DoricGravity::DoricGravityTop) ==
|
|
|
|
DoricGravity::DoricGravityTop)) {
|
|
|
|
layout->measuredY -= layout->marginBottom;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void DoricLayouts::layoutVLayout() {
|
2021-04-15 10:20:55 +08:00
|
|
|
qreal yStart = this->paddingTop;
|
2021-04-13 21:14:17 +08:00
|
|
|
if ((this->gravity & DoricGravity::DoricGravityTop) ==
|
|
|
|
DoricGravity::DoricGravityTop) {
|
|
|
|
yStart = this->paddingTop;
|
|
|
|
} else if ((this->gravity & DoricGravity::DoricGravityBottom) ==
|
|
|
|
DoricGravity::DoricGravityBottom) {
|
|
|
|
yStart = this->measuredHeight - this->contentHeight - this->paddingBottom;
|
|
|
|
} else if ((this->gravity & DoricGravity::DoricGravityCenterY) ==
|
|
|
|
DoricGravity::DoricGravityCenterY) {
|
|
|
|
yStart = (this->measuredHeight - this->contentHeight - this->paddingTop -
|
|
|
|
this->paddingBottom) /
|
|
|
|
2 +
|
|
|
|
this->paddingTop;
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach (QQuickItem *subview, this->view->childItems()) {
|
|
|
|
DoricLayouts *layout =
|
|
|
|
(DoricLayouts *)(subview->property("doricLayout").toULongLong());
|
|
|
|
if (layout == nullptr) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (layout->disabled) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (this->widthSpec == DoricLayoutSpec::DoricLayoutFit &&
|
|
|
|
layout->widthSpec == DoricLayoutSpec::DoricLayoutMost) {
|
|
|
|
layout->measuredWidth =
|
|
|
|
this->measuredWidth - layout->marginLeft - layout->marginRight;
|
|
|
|
}
|
|
|
|
if (this->heightSpec == DoricLayoutSpec::DoricLayoutFit &&
|
|
|
|
layout->heightSpec == DoricLayoutSpec::DoricLayoutMost) {
|
|
|
|
layout->measuredHeight = this->measuredHeight - yStart -
|
|
|
|
layout->marginTop - layout->marginBottom;
|
|
|
|
}
|
|
|
|
layout->layout();
|
|
|
|
int gravity = layout->alignment | this->gravity;
|
|
|
|
if ((gravity & DoricGravity::DoricGravityLeft) ==
|
|
|
|
DoricGravity::DoricGravityLeft) {
|
2021-04-15 10:20:55 +08:00
|
|
|
layout->setMeasuredX(this->paddingLeft);
|
2021-04-13 21:14:17 +08:00
|
|
|
} else if ((gravity & DoricGravity::DoricGravityRight) ==
|
|
|
|
DoricGravity::DoricGravityRight) {
|
2021-04-15 10:20:55 +08:00
|
|
|
layout->setMeasuredX(this->measuredWidth - this->paddingRight -
|
|
|
|
layout->measuredWidth);
|
2021-04-13 21:14:17 +08:00
|
|
|
} else if ((gravity & DoricGravity::DoricGravityCenterX) ==
|
|
|
|
DoricGravity::DoricGravityCenterX) {
|
2021-04-15 10:20:55 +08:00
|
|
|
layout->setMeasuredX(this->measuredWidth / 2 - layout->measuredWidth / 2);
|
2021-04-13 21:14:17 +08:00
|
|
|
} else {
|
2021-04-15 10:20:55 +08:00
|
|
|
layout->setMeasuredX(this->paddingLeft);
|
2021-04-13 21:14:17 +08:00
|
|
|
}
|
|
|
|
if (!gravity) {
|
|
|
|
gravity = DoricGravity::DoricGravityLeft;
|
|
|
|
}
|
|
|
|
if (layout->marginLeft && !((gravity & DoricGravity::DoricGravityRight) ==
|
|
|
|
DoricGravity::DoricGravityRight)) {
|
|
|
|
layout->measuredX += layout->marginLeft;
|
|
|
|
}
|
|
|
|
if (layout->marginRight && !((gravity & DoricGravity::DoricGravityLeft) ==
|
|
|
|
DoricGravity::DoricGravityLeft)) {
|
|
|
|
layout->measuredX -= layout->marginRight;
|
|
|
|
}
|
2021-04-16 19:09:25 +08:00
|
|
|
layout->setMeasuredY(yStart + layout->marginTop);
|
2021-04-13 21:14:17 +08:00
|
|
|
yStart += this->spacing + layout->takenHeight();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void DoricLayouts::layoutHLayout() {
|
2021-04-15 10:20:55 +08:00
|
|
|
qreal xStart = this->paddingLeft;
|
2021-04-13 21:14:17 +08:00
|
|
|
if ((this->gravity & DoricGravity::DoricGravityLeft) ==
|
|
|
|
DoricGravity::DoricGravityLeft) {
|
|
|
|
xStart = this->paddingLeft;
|
|
|
|
} else if ((this->gravity & DoricGravity::DoricGravityRight) ==
|
|
|
|
DoricGravity::DoricGravityRight) {
|
|
|
|
xStart = this->measuredWidth - this->contentWidth - this->paddingRight;
|
|
|
|
} else if ((this->gravity & DoricGravity::DoricGravityCenterX) ==
|
|
|
|
DoricGravity::DoricGravityCenterX) {
|
|
|
|
xStart = (this->measuredWidth - this->contentWidth - this->paddingLeft -
|
|
|
|
this->paddingRight) /
|
|
|
|
2 +
|
|
|
|
this->paddingLeft;
|
|
|
|
}
|
|
|
|
foreach (QQuickItem *subview, this->view->childItems()) {
|
|
|
|
DoricLayouts *layout =
|
|
|
|
(DoricLayouts *)(subview->property("doricLayout").toULongLong());
|
|
|
|
if (layout == nullptr) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (layout->disabled) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this->widthSpec == DoricLayoutSpec::DoricLayoutFit &&
|
|
|
|
layout->widthSpec == DoricLayoutSpec::DoricLayoutMost) {
|
|
|
|
layout->measuredWidth = this->measuredWidth - xStart -
|
|
|
|
layout->marginLeft - layout->marginRight;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this->heightSpec == DoricLayoutSpec::DoricLayoutFit &&
|
|
|
|
layout->heightSpec == DoricLayoutSpec::DoricLayoutMost) {
|
|
|
|
layout->measuredHeight =
|
|
|
|
this->measuredHeight - layout->marginTop - layout->marginBottom;
|
|
|
|
}
|
|
|
|
|
|
|
|
layout->layout();
|
|
|
|
|
|
|
|
int gravity = layout->alignment | this->gravity;
|
|
|
|
if ((gravity & DoricGravity::DoricGravityTop) ==
|
|
|
|
DoricGravity::DoricGravityTop) {
|
2021-04-16 19:09:25 +08:00
|
|
|
layout->setMeasuredY(this->paddingTop);
|
2021-04-13 21:14:17 +08:00
|
|
|
} else if ((gravity & DoricGravity::DoricGravityBottom) ==
|
|
|
|
DoricGravity::DoricGravityBottom) {
|
2021-04-16 19:09:25 +08:00
|
|
|
layout->setMeasuredY(this->measuredHeight - this->paddingBottom -
|
|
|
|
layout->measuredHeight);
|
2021-04-13 21:14:17 +08:00
|
|
|
} else if ((gravity & DoricGravity::DoricGravityCenterY) ==
|
|
|
|
DoricGravity::DoricGravityCenterY) {
|
2021-04-16 19:09:25 +08:00
|
|
|
layout->setMeasuredY(this->measuredHeight / 2 -
|
|
|
|
layout->measuredHeight / 2);
|
2021-04-13 21:14:17 +08:00
|
|
|
} else {
|
2021-04-16 19:09:25 +08:00
|
|
|
layout->setMeasuredY(this->paddingTop);
|
2021-04-13 21:14:17 +08:00
|
|
|
}
|
|
|
|
if (!gravity) {
|
|
|
|
gravity = DoricGravity::DoricGravityTop;
|
|
|
|
}
|
|
|
|
if (layout->marginTop && !((gravity & DoricGravity::DoricGravityBottom) ==
|
|
|
|
DoricGravity::DoricGravityBottom)) {
|
|
|
|
layout->measuredY += layout->marginTop;
|
|
|
|
}
|
|
|
|
if (layout->marginBottom && !((gravity & DoricGravity::DoricGravityTop) ==
|
|
|
|
DoricGravity::DoricGravityTop)) {
|
|
|
|
layout->measuredY -= layout->marginBottom;
|
|
|
|
}
|
2021-04-15 10:20:55 +08:00
|
|
|
layout->setMeasuredX(xStart + layout->marginLeft);
|
2021-04-13 21:14:17 +08:00
|
|
|
xStart += this->spacing + layout->takenWidth();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Private Section
|
2021-04-15 10:20:55 +08:00
|
|
|
void DoricLayouts::setMeasuredWidth(qreal measuredWidth) {
|
2021-04-14 12:42:03 +08:00
|
|
|
this->measuredWidth = measuredWidth;
|
2021-04-13 21:14:17 +08:00
|
|
|
qCritical() << "DoricLayouts: " << tag << this->view->property("uuid")
|
|
|
|
<< " measuredWidth: " << this->measuredWidth;
|
|
|
|
}
|
|
|
|
|
2021-04-16 16:44:08 +08:00
|
|
|
qreal DoricLayouts::getMeasuredWidth() { return this->measuredWidth; }
|
|
|
|
|
2021-04-15 10:20:55 +08:00
|
|
|
void DoricLayouts::setMeasuredHeight(qreal measuredHeight) {
|
2021-04-14 12:42:03 +08:00
|
|
|
this->measuredHeight = measuredHeight;
|
|
|
|
qCritical() << "DoricLayouts: " << tag << this->view->property("uuid")
|
2021-04-13 21:14:17 +08:00
|
|
|
<< " measuredHeight: " << this->measuredHeight;
|
2021-04-15 10:20:55 +08:00
|
|
|
}
|
|
|
|
|
2021-04-16 16:44:08 +08:00
|
|
|
qreal DoricLayouts::getMeasuredHeight() { return this->measuredHeight; }
|
|
|
|
|
2021-04-15 10:20:55 +08:00
|
|
|
void DoricLayouts::setMeasuredX(qreal measuredX) {
|
|
|
|
this->measuredX = measuredX;
|
|
|
|
qCritical() << "DoricLayouts: " << tag << this->view->property("uuid")
|
|
|
|
<< " measuredX: " << this->measuredX;
|
|
|
|
}
|
|
|
|
|
|
|
|
void DoricLayouts::setMeasuredY(qreal measuredY) {
|
|
|
|
this->measuredY = measuredY;
|
|
|
|
qCritical() << "DoricLayouts: " << tag << this->view->property("uuid")
|
|
|
|
<< " measuredY: " << this->measuredY;
|
2021-04-13 21:14:17 +08:00
|
|
|
}
|