From 7950416ba67d43ea8329690c04c7604770e13a55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=8A=B2=E9=B9=8F?= Date: Fri, 16 Apr 2021 16:44:08 +0800 Subject: [PATCH] fix scroll node cannot scroll --- doric-Qt/doric/resources/scroller.qml | 34 +++++++++++++++------ doric-Qt/doric/resources/test-layout.qml | 21 ++++++------- doric-Qt/doric/resources/text.qml | 5 +++ doric-Qt/doric/shader/DoricScrollerNode.cpp | 20 ++++++++++-- doric-Qt/doric/utils/DoricLayouts.cpp | 33 ++++++++++++-------- doric-Qt/doric/utils/DoricLayouts.h | 3 ++ 6 files changed, 79 insertions(+), 37 deletions(-) diff --git a/doric-Qt/doric/resources/scroller.qml b/doric-Qt/doric/resources/scroller.qml index fbdd96d9..0fa73808 100644 --- a/doric-Qt/doric/resources/scroller.qml +++ b/doric-Qt/doric/resources/scroller.qml @@ -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) + } + } } diff --git a/doric-Qt/doric/resources/test-layout.qml b/doric-Qt/doric/resources/test-layout.qml index 0c1b32b8..766aa4df 100644 --- a/doric-Qt/doric/resources/test-layout.qml +++ b/doric-Qt/doric/resources/test-layout.qml @@ -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 + } } } } diff --git a/doric-Qt/doric/resources/text.qml b/doric-Qt/doric/resources/text.qml index f423762e..24e92409 100644 --- a/doric-Qt/doric/resources/text.qml +++ b/doric-Qt/doric/resources/text.qml @@ -13,6 +13,11 @@ TextArea { readOnly: true + leftPadding: 0 + topPadding: 0 + rightPadding: 0 + bottomPadding: 0 + property int textAlignment: 0 background: Rectangle { diff --git a/doric-Qt/doric/shader/DoricScrollerNode.cpp b/doric-Qt/doric/shader/DoricScrollerNode.cpp index 11ef6510..0ddffd0d 100644 --- a/doric-Qt/doric/shader/DoricScrollerNode.cpp +++ b/doric-Qt/doric/shader/DoricScrollerNode.cpp @@ -72,7 +72,10 @@ void DoricScrollerNode::afterBlended(QJsonValue jsValue) { mChildNode->init(this); mChildNode->blend(props); - mChildNode->getNodeView()->setParentItem(parent); + QQmlListProperty contentChildren = + qvariant_cast>( + 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 contentChildren = + qvariant_cast>( + 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) { diff --git a/doric-Qt/doric/utils/DoricLayouts.cpp b/doric-Qt/doric/utils/DoricLayouts.cpp index c9cd46ee..394cbc65 100644 --- a/doric-Qt/doric/utils/DoricLayouts.cpp +++ b/doric-Qt/doric/utils/DoricLayouts.cpp @@ -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") diff --git a/doric-Qt/doric/utils/DoricLayouts.h b/doric-Qt/doric/utils/DoricLayouts.h index 56658f72..f1d9b588 100644 --- a/doric-Qt/doric/utils/DoricLayouts.h +++ b/doric-Qt/doric/utils/DoricLayouts.h @@ -84,6 +84,9 @@ public: void apply(); + qreal getMeasuredWidth(); + qreal getMeasuredHeight(); + private: QString tag;