add scroller node
This commit is contained in:
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