add slider node
This commit is contained in:
@@ -153,3 +153,13 @@ void DoricGroupNode::requestLayout() {
|
||||
DoricSuperNode::requestLayout();
|
||||
foreach (DoricViewNode *node, this->mChildNodes) { node->requestLayout(); }
|
||||
}
|
||||
|
||||
DoricViewNode *DoricGroupNode::getSubNodeById(QString id) {
|
||||
DoricSuperNode::requestLayout();
|
||||
foreach (DoricViewNode *node, this->mChildNodes) {
|
||||
if (id == node->getId()) {
|
||||
return node;
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
@@ -23,6 +23,8 @@ protected:
|
||||
virtual void afterBlended(QJsonValue props) override;
|
||||
|
||||
virtual void requestLayout() override;
|
||||
|
||||
virtual DoricViewNode *getSubNodeById(QString id) override;
|
||||
};
|
||||
|
||||
#endif // DORICGROUPNODE_H
|
||||
|
@@ -117,3 +117,7 @@ QSizeF DoricScrollerNode::sizeThatFits(QSizeF size) {
|
||||
return QSizeF(qMin(size.width(), layout->getMeasuredWidth()),
|
||||
qMin(size.height(), layout->getMeasuredHeight()));
|
||||
}
|
||||
|
||||
DoricViewNode *DoricScrollerNode::getSubNodeById(QString id) {
|
||||
return id == mChildNode->getId() ? mChildNode : nullptr;
|
||||
}
|
||||
|
@@ -25,6 +25,8 @@ public:
|
||||
virtual void requestLayout() override;
|
||||
|
||||
QSizeF sizeThatFits(QSizeF size);
|
||||
|
||||
virtual DoricViewNode *getSubNodeById(QString id) override;
|
||||
};
|
||||
|
||||
#endif // DORICSCROLLERNODE_H
|
||||
|
@@ -54,3 +54,33 @@ void DoricSuperNode::blendSubLayoutConfig(DoricViewNode *viewNode,
|
||||
QJsonValue jsValue) {
|
||||
viewNode->blendLayoutConfig(jsValue);
|
||||
}
|
||||
|
||||
bool DoricSuperNode::viewIdIsEqual(QJsonValue src, QJsonValue target) {
|
||||
QString srcId = src["id"].toString();
|
||||
QString targetId = target["id"].toString();
|
||||
return srcId == targetId;
|
||||
}
|
||||
|
||||
void DoricSuperNode::recursiveMixin(QJsonValue src, QJsonValue target) {
|
||||
QJsonObject srcProps = src["props"].toObject();
|
||||
QJsonObject targetProps = target["props"].toObject();
|
||||
QJsonValue oriSubviews = targetProps["subviews"];
|
||||
for (QString key : srcProps.keys()) {
|
||||
QJsonValue jsValue = srcProps[key];
|
||||
if ("subviews" == key && jsValue.isArray()) {
|
||||
QJsonArray subviews = jsValue.toArray();
|
||||
for (QJsonValue subview : subviews) {
|
||||
if (oriSubviews.isArray()) {
|
||||
for (QJsonValue targetSubview : oriSubviews.toArray()) {
|
||||
if (viewIdIsEqual(subview, targetSubview)) {
|
||||
recursiveMixin(subview, targetSubview);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
continue;
|
||||
}
|
||||
targetProps.insert(key, jsValue);
|
||||
}
|
||||
}
|
||||
|
@@ -14,6 +14,8 @@ protected:
|
||||
|
||||
virtual void blendSubNode(QJsonValue subProperties) = 0;
|
||||
|
||||
void recursiveMixin(QJsonValue src, QJsonValue target);
|
||||
|
||||
public:
|
||||
using DoricViewNode::DoricViewNode;
|
||||
|
||||
@@ -23,10 +25,14 @@ public:
|
||||
|
||||
void blendSubLayoutConfig(DoricViewNode *viewNode, QJsonValue jsValue);
|
||||
|
||||
virtual DoricViewNode *getSubNodeById(QString id) = 0;
|
||||
|
||||
private:
|
||||
void mixinSubNode(QJsonValue subNode);
|
||||
|
||||
void mixin(QJsonValue src, QJsonValue target);
|
||||
|
||||
bool viewIdIsEqual(QJsonValue src, QJsonValue target);
|
||||
};
|
||||
|
||||
#endif // DORICSUPERNODE_H
|
||||
|
37
doric-Qt/example/doric/shader/slider/DoricSliderNode.cpp
Normal file
37
doric-Qt/example/doric/shader/slider/DoricSliderNode.cpp
Normal file
@@ -0,0 +1,37 @@
|
||||
#include "DoricSliderNode.h"
|
||||
|
||||
QQuickItem *DoricSliderNode::build() {
|
||||
QQmlComponent component(getContext()->getQmlEngine());
|
||||
|
||||
const QUrl url(QStringLiteral("qrc:/doric/qml/slider.qml"));
|
||||
component.loadUrl(url);
|
||||
|
||||
if (component.isError()) {
|
||||
qCritical() << component.errorString();
|
||||
}
|
||||
|
||||
QQuickItem *item = qobject_cast<QQuickItem *>(component.create());
|
||||
this->createLayouts(item);
|
||||
|
||||
item->setProperty("wrapper", QString::number((qint64)this));
|
||||
return item;
|
||||
}
|
||||
|
||||
DoricViewNode *DoricSliderNode::getSubNodeById(QString id) {}
|
||||
|
||||
void DoricSliderNode::blendSubNode(QJsonValue subProperties) {
|
||||
QString viewId = subProperties["id"].toString();
|
||||
DoricViewNode *node = getSubNodeById(viewId);
|
||||
if (node != nullptr) {
|
||||
node->blend(subProperties["props"]);
|
||||
} else {
|
||||
QJsonValue oldModel = getSubModel(viewId);
|
||||
if (oldModel != QJsonValue::Undefined) {
|
||||
DoricSuperNode::recursiveMixin(subProperties, oldModel);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void DoricSliderNode::blend(QJsonValue jsValue) {}
|
||||
|
||||
void DoricSliderNode::blend(QQuickItem *view, QString name, QJsonValue prop) {}
|
22
doric-Qt/example/doric/shader/slider/DoricSliderNode.h
Normal file
22
doric-Qt/example/doric/shader/slider/DoricSliderNode.h
Normal file
@@ -0,0 +1,22 @@
|
||||
#ifndef DORICSLIDERNODE_H
|
||||
#define DORICSLIDERNODE_H
|
||||
|
||||
#include "shader/DoricSuperNode.h"
|
||||
|
||||
class DoricSliderNode : public DoricSuperNode {
|
||||
|
||||
public:
|
||||
using DoricSuperNode::DoricSuperNode;
|
||||
|
||||
QQuickItem *build() override;
|
||||
|
||||
virtual DoricViewNode *getSubNodeById(QString id) override;
|
||||
|
||||
virtual void blendSubNode(QJsonValue subProperties) override;
|
||||
|
||||
virtual void blend(QJsonValue jsValue) override;
|
||||
|
||||
virtual void blend(QQuickItem *view, QString name, QJsonValue prop) override;
|
||||
};
|
||||
|
||||
#endif // DORICSLIDERNODE_H
|
Reference in New Issue
Block a user