fix scroll node cannot scroll

This commit is contained in:
王劲鹏 2021-04-16 16:44:08 +08:00 committed by osborn
parent 3207cc2581
commit 7950416ba6
6 changed files with 79 additions and 37 deletions

View File

@ -11,8 +11,8 @@ ScrollView {
property var tag: "Scroller"
ScrollBar.horizontal.policy: ScrollBar.AlwaysOn
ScrollBar.vertical.policy: ScrollBar.AlwaysOn
ScrollBar.horizontal.policy: ScrollBar.AlwaysOff
ScrollBar.vertical.policy: ScrollBar.AlwaysOff
clip: true
@ -37,11 +37,27 @@ ScrollView {
console.log(tag, uuid + " onHeightChanged: " + this.height)
}
// MouseArea {
// anchors.fill: parent
// onClicked: {
// console.log(tag, uuid + " wrapper: " + wrapper)
// mouseAreaBridge.onClick(wrapper)
// }
// }
onImplicitWidthChanged: {
console.log(tag, uuid + " onImplicitWidthChanged: " + this.implicitWidth)
}
onImplicitHeightChanged: {
console.log(tag, uuid + " onImplicitHeightChanged: " + this.implicitHeight)
}
onContentWidthChanged: {
console.log(tag, uuid + " onContentWidthChanged: " + this.contentWidth)
}
onContentHeightChanged: {
console.log(tag, uuid + " onContentHeightChanged: " + this.contentHeight)
}
MouseArea {
anchors.fill: parent
onClicked: {
console.log(tag, uuid + " wrapper: " + wrapper)
mouseAreaBridge.onClick(wrapper)
}
}
}

View File

@ -14,8 +14,8 @@ ApplicationWindow {
width: 200
height: 200
ScrollBar.horizontal.policy: ScrollBar.AlwaysOff
ScrollBar.vertical.policy: ScrollBar.AlwaysOff
ScrollBar.horizontal.policy: ScrollBar.AlwaysOn
ScrollBar.vertical.policy: ScrollBar.AlwaysOn
clip: true
@ -44,17 +44,14 @@ ApplicationWindow {
console.log(tag, uuid + " onHeightChanged: " + this.height)
}
MouseArea {
anchors.fill: parent
onClicked: {
console.log(tag, uuid + " wrapper: " + wrapper)
mouseAreaBridge.onClick(wrapper)
}
}
Rectangle {
implicitWidth: 400
implicitHeight: 400
Label {
text: "ABC"
font.pixelSize: 224
Label {
text: "ABC"
font.pixelSize: 124
}
}
}
}

View File

@ -13,6 +13,11 @@ TextArea {
readOnly: true
leftPadding: 0
topPadding: 0
rightPadding: 0
bottomPadding: 0
property int textAlignment: 0
background: Rectangle {

View File

@ -72,7 +72,10 @@ void DoricScrollerNode::afterBlended(QJsonValue jsValue) {
mChildNode->init(this);
mChildNode->blend(props);
mChildNode->getNodeView()->setParentItem(parent);
QQmlListProperty<QQuickItem> contentChildren =
qvariant_cast<QQmlListProperty<QQuickItem>>(
parent->property("contentChildren"));
contentChildren.append(&contentChildren, mChildNode->getNodeView());
}
}
} else {
@ -81,13 +84,24 @@ void DoricScrollerNode::afterBlended(QJsonValue jsValue) {
mChildNode->init(this);
mChildNode->blend(props);
mChildNode->getNodeView()->setParentItem(parent);
QQmlListProperty<QQuickItem> contentChildren =
qvariant_cast<QQmlListProperty<QQuickItem>>(
parent->property("contentChildren"));
contentChildren.append(&contentChildren, mChildNode->getNodeView());
}
}
void DoricScrollerNode::requestLayout() {
this->mChildNode->requestLayout();
getLayouts()->apply(mView->width(), mView->height());
DoricLayouts *layout = (DoricLayouts *)(mChildNode->getNodeView()
->property("doricLayout")
.toULongLong());
if (layout != nullptr) {
layout->apply(mView->width(), mView->height());
mView->setProperty("contentWidth", layout->getMeasuredWidth());
mView->setProperty("contentHeight", layout->getMeasuredHeight());
}
}
void DoricScrollerNode::blendSubNode(QJsonValue subProperties) {

View File

@ -204,18 +204,20 @@ void DoricLayouts::measureContent(qreal targetWidth, qreal targetHeight) {
}
QQuickItem *parent = this->view->parentItem();
DoricLayouts *parentDoricLayout =
(DoricLayouts *)(parent->property("doricLayout").toULongLong());
if (parentDoricLayout != nullptr) {
if (parentDoricLayout->layoutType != DoricLayoutType::DoricUndefined &&
parentDoricLayout->widthSpec == DoricLayoutSpec::DoricLayoutFit &&
this->widthSpec == DoricLayoutSpec::DoricLayoutMost) {
setMeasuredWidth(0);
}
if (parentDoricLayout->layoutType != DoricLayoutType::DoricUndefined &&
parentDoricLayout->heightSpec == DoricLayoutSpec::DoricLayoutFit &&
this->heightSpec == DoricLayoutSpec::DoricLayoutMost) {
setMeasuredHeight(0);
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) {
setMeasuredWidth(0);
}
if (parentDoricLayout->layoutType != DoricLayoutType::DoricUndefined &&
parentDoricLayout->heightSpec == DoricLayoutSpec::DoricLayoutFit &&
this->heightSpec == DoricLayoutSpec::DoricLayoutMost) {
setMeasuredHeight(0);
}
}
}
}
@ -464,7 +466,8 @@ void DoricLayouts::setFrame() {
}
}
qCritical() << "DoricLayouts: " << tag << this->view->property("uuid")
qCritical() << "DoricLayouts setProperty: " << tag
<< this->view->property("uuid")
<< " measuredWidth: " << this->measuredWidth
<< " measuredHeight: " << this->measuredHeight
<< " width: " << this->view->width()
@ -707,12 +710,16 @@ void DoricLayouts::setMeasuredWidth(qreal measuredWidth) {
<< " measuredWidth: " << this->measuredWidth;
}
qreal DoricLayouts::getMeasuredWidth() { return this->measuredWidth; }
void DoricLayouts::setMeasuredHeight(qreal measuredHeight) {
this->measuredHeight = measuredHeight;
qCritical() << "DoricLayouts: " << tag << this->view->property("uuid")
<< " measuredHeight: " << this->measuredHeight;
}
qreal DoricLayouts::getMeasuredHeight() { return this->measuredHeight; }
void DoricLayouts::setMeasuredX(qreal measuredX) {
this->measuredX = measuredX;
qCritical() << "DoricLayouts: " << tag << this->view->property("uuid")

View File

@ -84,6 +84,9 @@ public:
void apply();
qreal getMeasuredWidth();
qreal getMeasuredHeight();
private:
QString tag;