scroller implements
This commit is contained in:
parent
5e72a97a41
commit
3207cc2581
@ -19,9 +19,12 @@ void DoricDemoBridge::navigate(QVariant route) {
|
|||||||
name = "Gobang.js";
|
name = "Gobang.js";
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
name = "SimpleDemo.js";
|
name = "LayoutDemo.js";
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
|
name = "SimpleDemo.js";
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
name = "Snake.js";
|
name = "Snake.js";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -10,6 +10,7 @@
|
|||||||
<qresource prefix="/doric/bundles">
|
<qresource prefix="/doric/bundles">
|
||||||
<file alias="Counter.js">../../doric-demo/bundle/src/Counter.js</file>
|
<file alias="Counter.js">../../doric-demo/bundle/src/Counter.js</file>
|
||||||
<file alias="Gobang.js">../../doric-demo/bundle/src/Gobang.js</file>
|
<file alias="Gobang.js">../../doric-demo/bundle/src/Gobang.js</file>
|
||||||
|
<file alias="LayoutDemo.js">../../doric-demo/bundle/src/LayoutDemo.js</file>
|
||||||
<file alias="SimpleDemo.js">../../doric-demo/bundle/src/SimpleDemo.js</file>
|
<file alias="SimpleDemo.js">../../doric-demo/bundle/src/SimpleDemo.js</file>
|
||||||
<file alias="Snake.js">../../doric-demo/bundle/src/Snake.js</file>
|
<file alias="Snake.js">../../doric-demo/bundle/src/Snake.js</file>
|
||||||
</qresource>
|
</qresource>
|
||||||
|
@ -12,7 +12,7 @@ ApplicationWindow {
|
|||||||
|
|
||||||
ListView {
|
ListView {
|
||||||
width: parent.width
|
width: parent.width
|
||||||
model: 4
|
model: 5
|
||||||
delegate: Rectangle {
|
delegate: Rectangle {
|
||||||
Column {
|
Column {
|
||||||
anchors.centerIn: parent
|
anchors.centerIn: parent
|
||||||
@ -24,8 +24,10 @@ ApplicationWindow {
|
|||||||
case 1:
|
case 1:
|
||||||
return "Gobang.js"
|
return "Gobang.js"
|
||||||
case 2:
|
case 2:
|
||||||
return "SimpleDemo.js"
|
return "LayoutDemo.js"
|
||||||
case 3:
|
case 3:
|
||||||
|
return "SimpleDemo.js"
|
||||||
|
case 4:
|
||||||
return "Snake.js"
|
return "Snake.js"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,74 +4,44 @@ import QtQuick.Layouts 1.15
|
|||||||
|
|
||||||
import "util.mjs" as Util
|
import "util.mjs" as Util
|
||||||
|
|
||||||
Rectangle {
|
ScrollView {
|
||||||
property var wrapper
|
property var wrapper
|
||||||
|
|
||||||
clip: true
|
|
||||||
|
|
||||||
property var tag: "Scroller"
|
|
||||||
|
|
||||||
property var uuid: Util.uuidv4()
|
property var uuid: Util.uuidv4()
|
||||||
|
|
||||||
property int widthSpec: 0
|
property var tag: "Scroller"
|
||||||
property int heightSpec: 0
|
|
||||||
property int childrenRectWidth: childrenRect.width
|
ScrollBar.horizontal.policy: ScrollBar.AlwaysOn
|
||||||
property int childrenRectHeight: childrenRect.height
|
ScrollBar.vertical.policy: ScrollBar.AlwaysOn
|
||||||
|
|
||||||
|
clip: true
|
||||||
|
|
||||||
|
background: Rectangle {
|
||||||
|
id: bg
|
||||||
|
color: 'transparent'
|
||||||
|
}
|
||||||
|
|
||||||
|
property var backgroundColor
|
||||||
|
|
||||||
|
onBackgroundColorChanged: {
|
||||||
|
bg.color = backgroundColor
|
||||||
|
}
|
||||||
|
|
||||||
onWidthChanged: {
|
onWidthChanged: {
|
||||||
|
bg.implicitWidth = width
|
||||||
console.log(tag, uuid + " onWidthChanged: " + this.width)
|
console.log(tag, uuid + " onWidthChanged: " + this.width)
|
||||||
}
|
}
|
||||||
|
|
||||||
onHeightChanged: {
|
onHeightChanged: {
|
||||||
|
bg.implicitHeight = height
|
||||||
console.log(tag, uuid + " onHeightChanged: " + this.height)
|
console.log(tag, uuid + " onHeightChanged: " + this.height)
|
||||||
}
|
}
|
||||||
|
|
||||||
onWidthSpecChanged: {
|
// MouseArea {
|
||||||
console.log(tag, uuid + " onWidthSpecChanged: " + this.widthSpec)
|
// anchors.fill: parent
|
||||||
console.log(tag, uuid + " parent width: " + parent.width)
|
// onClicked: {
|
||||||
|
// console.log(tag, uuid + " wrapper: " + wrapper)
|
||||||
if (this.widthSpec === 2) {
|
// mouseAreaBridge.onClick(wrapper)
|
||||||
this.width = parent.width
|
// }
|
||||||
children[1].width = parent.width
|
// }
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
onHeightSpecChanged: {
|
|
||||||
console.log(tag, uuid + " onHeightSpecChanged: " + this.heightSpec)
|
|
||||||
console.log(tag, uuid + " parent height: " + parent.height)
|
|
||||||
|
|
||||||
if (this.heightSpec === 2) {
|
|
||||||
this.height = parent.height
|
|
||||||
children[1].height = parent.height
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
onChildrenRectChanged: {
|
|
||||||
console.log(tag, uuid + " widthSpec: " + widthSpec + " heightSpec: " + heightSpec)
|
|
||||||
console.log(tag, uuid + " onChildrenRectChanged: " + childrenRect)
|
|
||||||
this.childrenRectWidth = childrenRect.width
|
|
||||||
this.childrenRectHeight = childrenRect.height
|
|
||||||
|
|
||||||
if (this.widthSpec === 1) {
|
|
||||||
this.width = childrenRectWidth
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.heightSpec === 1) {
|
|
||||||
this.height = childrenRectHeight
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
color: 'transparent'
|
|
||||||
|
|
||||||
MouseArea {
|
|
||||||
anchors.fill: parent
|
|
||||||
onClicked: {
|
|
||||||
console.log(tag, uuid + " wrapper: " + wrapper)
|
|
||||||
mouseAreaBridge.onClick(wrapper)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ScrollView {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -8,32 +8,53 @@ ApplicationWindow {
|
|||||||
height: 800
|
height: 800
|
||||||
title: qsTr("Scroll")
|
title: qsTr("Scroll")
|
||||||
|
|
||||||
Rectangle {
|
ScrollView {
|
||||||
|
property var wrapper
|
||||||
|
|
||||||
|
width: 200
|
||||||
|
height: 200
|
||||||
|
|
||||||
|
ScrollBar.horizontal.policy: ScrollBar.AlwaysOff
|
||||||
|
ScrollBar.vertical.policy: ScrollBar.AlwaysOff
|
||||||
|
|
||||||
|
clip: true
|
||||||
|
|
||||||
|
// property var uuid: Util.uuidv4()
|
||||||
|
|
||||||
|
property var tag: "Scroller"
|
||||||
|
|
||||||
|
background: Rectangle {
|
||||||
|
id: bg
|
||||||
color: 'red'
|
color: 'red'
|
||||||
width: childrenRect.width
|
|
||||||
height: childrenRect.height
|
|
||||||
|
|
||||||
ColumnLayout {
|
|
||||||
property int gravity: 0
|
|
||||||
onGravityChanged: {
|
|
||||||
console.log(children[0].Layout.alignment)
|
|
||||||
children[0].Layout.alignment = 1
|
|
||||||
}
|
}
|
||||||
|
|
||||||
spacing: 0
|
property var backgroundColor
|
||||||
height: 600
|
|
||||||
|
|
||||||
Rectangle {
|
onBackgroundColorChanged: {
|
||||||
width: 100
|
bg.color = backgroundColor
|
||||||
height: 100
|
|
||||||
color: 'black'
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Rectangle {
|
onWidthChanged: {
|
||||||
width: 100
|
bg.implicitWidth = width
|
||||||
height: 100
|
console.log(tag, uuid + " onWidthChanged: " + this.width)
|
||||||
color: 'yellow'
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onHeightChanged: {
|
||||||
|
bg.implicitHeight = height
|
||||||
|
console.log(tag, uuid + " onHeightChanged: " + this.height)
|
||||||
|
}
|
||||||
|
|
||||||
|
MouseArea {
|
||||||
|
anchors.fill: parent
|
||||||
|
onClicked: {
|
||||||
|
console.log(tag, uuid + " wrapper: " + wrapper)
|
||||||
|
mouseAreaBridge.onClick(wrapper)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Label {
|
||||||
|
text: "ABC"
|
||||||
|
font.pixelSize: 224
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,17 +11,14 @@ QQuickItem *DoricScrollerNode::build() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
QQuickItem *item = qobject_cast<QQuickItem *>(component.create());
|
QQuickItem *item = qobject_cast<QQuickItem *>(component.create());
|
||||||
|
this->createLayouts(item);
|
||||||
|
|
||||||
|
getLayouts()->setLayoutType(DoricLayoutType::DoricStack);
|
||||||
|
|
||||||
item->setProperty("wrapper", QString::number((qint64)this));
|
item->setProperty("wrapper", QString::number((qint64)this));
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DoricScrollerNode::blendSubNode(QJsonValue subProperties) {
|
|
||||||
if (mChildNode != nullptr) {
|
|
||||||
mChildNode->blend(subProperties["props"]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void DoricScrollerNode::blend(QQuickItem *view, QString name, QJsonValue prop) {
|
void DoricScrollerNode::blend(QQuickItem *view, QString name, QJsonValue prop) {
|
||||||
if (name == "content") {
|
if (name == "content") {
|
||||||
if (!prop.isString()) {
|
if (!prop.isString()) {
|
||||||
@ -43,8 +40,7 @@ void DoricScrollerNode::blend(QQuickItem *view, QString name, QJsonValue prop) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DoricScrollerNode::blend(QJsonValue jsValue) {
|
void DoricScrollerNode::afterBlended(QJsonValue jsValue) {
|
||||||
DoricViewNode::blend(jsValue);
|
|
||||||
QJsonValue contentModel = getSubModel(mChildViewId);
|
QJsonValue contentModel = getSubModel(mChildViewId);
|
||||||
if (contentModel == QJsonValue::Undefined) {
|
if (contentModel == QJsonValue::Undefined) {
|
||||||
return;
|
return;
|
||||||
@ -54,7 +50,7 @@ void DoricScrollerNode::blend(QJsonValue jsValue) {
|
|||||||
QString type = contentModel["type"].toString();
|
QString type = contentModel["type"].toString();
|
||||||
QJsonValue props = contentModel["props"];
|
QJsonValue props = contentModel["props"];
|
||||||
|
|
||||||
QQuickItem *parent = mView->childItems().at(1);
|
QQuickItem *parent = mView;
|
||||||
|
|
||||||
if (mChildNode != nullptr) {
|
if (mChildNode != nullptr) {
|
||||||
if (viewId == mChildNode->getId()) {
|
if (viewId == mChildNode->getId()) {
|
||||||
@ -88,3 +84,14 @@ void DoricScrollerNode::blend(QJsonValue jsValue) {
|
|||||||
mChildNode->getNodeView()->setParentItem(parent);
|
mChildNode->getNodeView()->setParentItem(parent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DoricScrollerNode::requestLayout() {
|
||||||
|
this->mChildNode->requestLayout();
|
||||||
|
getLayouts()->apply(mView->width(), mView->height());
|
||||||
|
}
|
||||||
|
|
||||||
|
void DoricScrollerNode::blendSubNode(QJsonValue subProperties) {
|
||||||
|
if (mChildNode != nullptr) {
|
||||||
|
mChildNode->blend(subProperties["props"]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -18,9 +18,11 @@ public:
|
|||||||
|
|
||||||
virtual void blend(QQuickItem *view, QString name, QJsonValue prop) override;
|
virtual void blend(QQuickItem *view, QString name, QJsonValue prop) override;
|
||||||
|
|
||||||
virtual void blend(QJsonValue jsValue) override;
|
|
||||||
|
|
||||||
virtual void blendSubNode(QJsonValue subProperties) override;
|
virtual void blendSubNode(QJsonValue subProperties) override;
|
||||||
|
|
||||||
|
virtual void afterBlended(QJsonValue jsValue) override;
|
||||||
|
|
||||||
|
virtual void requestLayout() override;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // DORICSCROLLERNODE_H
|
#endif // DORICSCROLLERNODE_H
|
||||||
|
Reference in New Issue
Block a user