add scroller node
This commit is contained in:
parent
b8440d9fb7
commit
7402fc2c0c
@ -3,6 +3,7 @@
|
|||||||
#include "plugin/DoricShaderPlugin.h"
|
#include "plugin/DoricShaderPlugin.h"
|
||||||
#include "shader/DoricHLayoutNode.h"
|
#include "shader/DoricHLayoutNode.h"
|
||||||
#include "shader/DoricRootNode.h"
|
#include "shader/DoricRootNode.h"
|
||||||
|
#include "shader/DoricScrollerNode.h"
|
||||||
#include "shader/DoricStackNode.h"
|
#include "shader/DoricStackNode.h"
|
||||||
#include "shader/DoricTextNode.h"
|
#include "shader/DoricTextNode.h"
|
||||||
#include "shader/DoricVLayoutNode.h"
|
#include "shader/DoricVLayoutNode.h"
|
||||||
@ -15,6 +16,7 @@ DoricRegistry::DoricRegistry() {
|
|||||||
registerViewNode<DoricVLayoutNode>("VLayout");
|
registerViewNode<DoricVLayoutNode>("VLayout");
|
||||||
registerViewNode<DoricHLayoutNode>("HLayout");
|
registerViewNode<DoricHLayoutNode>("HLayout");
|
||||||
registerViewNode<DoricTextNode>("Text");
|
registerViewNode<DoricTextNode>("Text");
|
||||||
|
registerViewNode<DoricScrollerNode>("Scroller");
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DoricRegistry::acquirePluginInfo(QString name) {
|
bool DoricRegistry::acquirePluginInfo(QString name) {
|
||||||
|
@ -38,6 +38,7 @@ SOURCES += \
|
|||||||
shader/DoricGroupNode.cpp \
|
shader/DoricGroupNode.cpp \
|
||||||
shader/DoricHLayoutNode.cpp \
|
shader/DoricHLayoutNode.cpp \
|
||||||
shader/DoricRootNode.cpp \
|
shader/DoricRootNode.cpp \
|
||||||
|
shader/DoricScrollerNode.cpp \
|
||||||
shader/DoricStackNode.cpp \
|
shader/DoricStackNode.cpp \
|
||||||
shader/DoricSuperNode.cpp \
|
shader/DoricSuperNode.cpp \
|
||||||
shader/DoricTextNode.cpp \
|
shader/DoricTextNode.cpp \
|
||||||
@ -103,6 +104,7 @@ HEADERS += \
|
|||||||
shader/DoricGroupNode.h \
|
shader/DoricGroupNode.h \
|
||||||
shader/DoricHLayoutNode.h \
|
shader/DoricHLayoutNode.h \
|
||||||
shader/DoricRootNode.h \
|
shader/DoricRootNode.h \
|
||||||
|
shader/DoricScrollerNode.h \
|
||||||
shader/DoricStackNode.h \
|
shader/DoricStackNode.h \
|
||||||
shader/DoricSuperNode.h \
|
shader/DoricSuperNode.h \
|
||||||
shader/DoricTextNode.h \
|
shader/DoricTextNode.h \
|
||||||
|
@ -21,6 +21,8 @@
|
|||||||
<file alias="vlayout.qml">resources/vlayout.qml</file>
|
<file alias="vlayout.qml">resources/vlayout.qml</file>
|
||||||
<file alias="hlayout.qml">resources/hlayout.qml</file>
|
<file alias="hlayout.qml">resources/hlayout.qml</file>
|
||||||
<file alias="text.qml">resources/text.qml</file>
|
<file alias="text.qml">resources/text.qml</file>
|
||||||
|
<file alias="scroller.qml">resources/scroller.qml</file>
|
||||||
|
|
||||||
<file alias="util.mjs">resources/util.mjs</file>
|
<file alias="util.mjs">resources/util.mjs</file>
|
||||||
<file alias="gravity.mjs">resources/gravity.mjs</file>
|
<file alias="gravity.mjs">resources/gravity.mjs</file>
|
||||||
<file alias="test-layout.qml">resources/test-layout.qml</file>
|
<file alias="test-layout.qml">resources/test-layout.qml</file>
|
||||||
|
77
doric-Qt/doric/resources/scroller.qml
Normal file
77
doric-Qt/doric/resources/scroller.qml
Normal file
@ -0,0 +1,77 @@
|
|||||||
|
import QtQuick 2.12
|
||||||
|
import QtQuick.Controls 2.5
|
||||||
|
import QtQuick.Layouts 1.15
|
||||||
|
|
||||||
|
import "util.mjs" as Util
|
||||||
|
|
||||||
|
Rectangle {
|
||||||
|
property var wrapper
|
||||||
|
|
||||||
|
clip: true
|
||||||
|
|
||||||
|
property var tag: "Scroller"
|
||||||
|
|
||||||
|
property var uuid: Util.uuidv4()
|
||||||
|
|
||||||
|
property int widthSpec: 0
|
||||||
|
property int heightSpec: 0
|
||||||
|
property int childrenRectWidth: childrenRect.width
|
||||||
|
property int childrenRectHeight: childrenRect.height
|
||||||
|
|
||||||
|
onWidthChanged: {
|
||||||
|
console.log(tag, uuid + " onWidthChanged: " + this.width)
|
||||||
|
}
|
||||||
|
|
||||||
|
onHeightChanged: {
|
||||||
|
console.log(tag, uuid + " onHeightChanged: " + this.height)
|
||||||
|
}
|
||||||
|
|
||||||
|
onWidthSpecChanged: {
|
||||||
|
console.log(tag, uuid + " onWidthSpecChanged: " + this.widthSpec)
|
||||||
|
console.log(tag, uuid + " parent width: " + parent.width)
|
||||||
|
|
||||||
|
if (this.widthSpec === 2) {
|
||||||
|
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 {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
90
doric-Qt/doric/shader/DoricScrollerNode.cpp
Normal file
90
doric-Qt/doric/shader/DoricScrollerNode.cpp
Normal file
@ -0,0 +1,90 @@
|
|||||||
|
#include "DoricScrollerNode.h"
|
||||||
|
|
||||||
|
QQuickItem *DoricScrollerNode::build() {
|
||||||
|
QQmlComponent component(getContext()->getQmlEngine());
|
||||||
|
|
||||||
|
const QUrl url(QStringLiteral("qrc:/doric/qml/scroller.qml"));
|
||||||
|
component.loadUrl(url);
|
||||||
|
|
||||||
|
if (component.isError()) {
|
||||||
|
qCritical() << component.errorString();
|
||||||
|
}
|
||||||
|
|
||||||
|
QQuickItem *item = qobject_cast<QQuickItem *>(component.create());
|
||||||
|
|
||||||
|
item->setProperty("wrapper", QString::number((qint64)this));
|
||||||
|
return item;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DoricScrollerNode::blendSubNode(QJsonValue subProperties) {
|
||||||
|
if (mChildNode != nullptr) {
|
||||||
|
mChildNode->blend(subProperties["props"]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void DoricScrollerNode::blend(QQuickItem *view, QString name, QJsonValue prop) {
|
||||||
|
if (name == "content") {
|
||||||
|
if (!prop.isString()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
mChildViewId = prop.toString();
|
||||||
|
} else if (name == "onScroll") {
|
||||||
|
if (!prop.isString()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
onScrollFuncId = prop.toString();
|
||||||
|
} else if (name == "onScrollEnd") {
|
||||||
|
if (!prop.isString()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
onScrollEndFuncId = prop.toString();
|
||||||
|
} else {
|
||||||
|
DoricSuperNode::blend(view, name, prop);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void DoricScrollerNode::blend(QJsonValue jsValue) {
|
||||||
|
DoricViewNode::blend(jsValue);
|
||||||
|
QJsonValue contentModel = getSubModel(mChildViewId);
|
||||||
|
if (contentModel == QJsonValue::Undefined) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString viewId = contentModel["id"].toString();
|
||||||
|
QString type = contentModel["type"].toString();
|
||||||
|
QJsonValue props = contentModel["props"];
|
||||||
|
|
||||||
|
QQuickItem *parent = mView->childItems().at(1);
|
||||||
|
|
||||||
|
if (mChildNode != nullptr) {
|
||||||
|
if (viewId == mChildNode->getId()) {
|
||||||
|
// skip
|
||||||
|
} else {
|
||||||
|
if (mReusable && mChildNode->getType() == type) {
|
||||||
|
mChildNode->setId(viewId);
|
||||||
|
mChildNode->blend(props);
|
||||||
|
} else {
|
||||||
|
// remove all views
|
||||||
|
for (int i = 0; i != parent->childItems().size(); i++) {
|
||||||
|
parent->childItems().at(i)->setParent(nullptr);
|
||||||
|
parent->childItems().at(i)->setParentItem(nullptr);
|
||||||
|
parent->childItems().at(i)->deleteLater();
|
||||||
|
}
|
||||||
|
|
||||||
|
mChildNode = DoricViewNode::create(getContext(), type);
|
||||||
|
mChildNode->setId(viewId);
|
||||||
|
mChildNode->init(this);
|
||||||
|
mChildNode->blend(props);
|
||||||
|
|
||||||
|
mChildNode->getNodeView()->setParentItem(parent);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
mChildNode = DoricViewNode::create(getContext(), type);
|
||||||
|
mChildNode->setId(viewId);
|
||||||
|
mChildNode->init(this);
|
||||||
|
mChildNode->blend(props);
|
||||||
|
|
||||||
|
mChildNode->getNodeView()->setParentItem(parent);
|
||||||
|
}
|
||||||
|
}
|
26
doric-Qt/doric/shader/DoricScrollerNode.h
Normal file
26
doric-Qt/doric/shader/DoricScrollerNode.h
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
#ifndef DORICSCROLLERNODE_H
|
||||||
|
#define DORICSCROLLERNODE_H
|
||||||
|
|
||||||
|
#include "DoricSuperNode.h"
|
||||||
|
|
||||||
|
class DoricScrollerNode : public DoricSuperNode {
|
||||||
|
private:
|
||||||
|
DoricViewNode *mChildNode = nullptr;
|
||||||
|
|
||||||
|
QString mChildViewId;
|
||||||
|
QString onScrollFuncId;
|
||||||
|
QString onScrollEndFuncId;
|
||||||
|
|
||||||
|
public:
|
||||||
|
using DoricSuperNode::DoricSuperNode;
|
||||||
|
|
||||||
|
QQuickItem *build() override;
|
||||||
|
|
||||||
|
virtual void blend(QQuickItem *view, QString name, QJsonValue prop) override;
|
||||||
|
|
||||||
|
virtual void blend(QJsonValue jsValue) override;
|
||||||
|
|
||||||
|
virtual void blendSubNode(QJsonValue subProperties) override;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // DORICSCROLLERNODE_H
|
Reference in New Issue
Block a user