add slider node
This commit is contained in:
parent
0ad7cfb52e
commit
0f2a6ef55c
@ -33,6 +33,7 @@
|
||||
<file alias="text.qml">../doric/resources/text.qml</file>
|
||||
<file alias="scroller.qml">../doric/resources/scroller.qml</file>
|
||||
<file alias="image.qml">../doric/resources/image.qml</file>
|
||||
<file alias="slider.qml">../doric/resources/slider.qml</file>
|
||||
|
||||
<file alias="toast.qml">../doric/resources/toast.qml</file>
|
||||
<file alias="alert.qml">../doric/resources/alert.qml</file>
|
||||
|
@ -8,50 +8,33 @@ ApplicationWindow {
|
||||
height: 800
|
||||
title: qsTr("Scroll")
|
||||
|
||||
ScrollView {
|
||||
property var wrapper
|
||||
SwipeView {
|
||||
id: view
|
||||
|
||||
width: 200
|
||||
height: 200
|
||||
|
||||
ScrollBar.horizontal.policy: ScrollBar.AlwaysOn
|
||||
ScrollBar.vertical.policy: ScrollBar.AlwaysOn
|
||||
|
||||
clip: true
|
||||
|
||||
// property var uuid: Util.uuidv4()
|
||||
|
||||
property var tag: "Scroller"
|
||||
|
||||
background: Rectangle {
|
||||
id: bg
|
||||
color: 'red'
|
||||
}
|
||||
|
||||
property var backgroundColor
|
||||
|
||||
onBackgroundColorChanged: {
|
||||
bg.color = backgroundColor
|
||||
}
|
||||
|
||||
onWidthChanged: {
|
||||
bg.implicitWidth = width
|
||||
console.log(tag, uuid + " onWidthChanged: " + this.width)
|
||||
}
|
||||
|
||||
onHeightChanged: {
|
||||
bg.implicitHeight = height
|
||||
console.log(tag, uuid + " onHeightChanged: " + this.height)
|
||||
}
|
||||
currentIndex: 0
|
||||
anchors.fill: parent
|
||||
|
||||
Rectangle {
|
||||
implicitWidth: 400
|
||||
implicitHeight: 400
|
||||
|
||||
Label {
|
||||
text: "ABC"
|
||||
font.pixelSize: 124
|
||||
}
|
||||
id: firstPage
|
||||
color: 'red'
|
||||
}
|
||||
Rectangle {
|
||||
id: secondPage
|
||||
color: 'green'
|
||||
}
|
||||
Rectangle {
|
||||
id: thirdPage
|
||||
color: 'blue'
|
||||
}
|
||||
}
|
||||
|
||||
PageIndicator {
|
||||
id: indicator
|
||||
|
||||
count: view.count
|
||||
currentIndex: view.currentIndex
|
||||
|
||||
anchors.bottom: view.bottom
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
}
|
||||
}
|
||||
|
@ -50,6 +50,7 @@ SOURCES += \
|
||||
shader/DoricTextNode.cpp \
|
||||
shader/DoricVLayoutNode.cpp \
|
||||
shader/DoricViewNode.cpp \
|
||||
shader/slider/DoricSliderNode.cpp \
|
||||
utils/DoricConstant.cpp \
|
||||
utils/DoricContextHolder.cpp \
|
||||
utils/DoricDialogBridge.cpp \
|
||||
@ -124,6 +125,7 @@ HEADERS += \
|
||||
shader/DoricTextNode.h \
|
||||
shader/DoricVLayoutNode.h \
|
||||
shader/DoricViewNode.h \
|
||||
shader/slider/DoricSliderNode.h \
|
||||
template/DoricSingleton.h \
|
||||
utils/DoricConstant.h \
|
||||
utils/DoricContextHolder.h \
|
||||
|
49
doric-Qt/example/doric/resources/slider.qml
Normal file
49
doric-Qt/example/doric/resources/slider.qml
Normal file
@ -0,0 +1,49 @@
|
||||
import QtQuick 2.12
|
||||
import QtQuick.Controls 2.5
|
||||
|
||||
SwipeView {
|
||||
property var wrapper
|
||||
|
||||
property var uuid: Util.uuidv4()
|
||||
|
||||
property var tag: "Slider"
|
||||
|
||||
background: Rectangle {
|
||||
id: bg
|
||||
color: 'transparent'
|
||||
}
|
||||
|
||||
property var backgroundColor
|
||||
|
||||
onBackgroundColorChanged: {
|
||||
bg.color = backgroundColor
|
||||
}
|
||||
|
||||
onWidthChanged: {
|
||||
bg.implicitWidth = width
|
||||
console.log(tag, uuid + " onWidthChanged: " + this.width)
|
||||
}
|
||||
|
||||
onHeightChanged: {
|
||||
bg.implicitHeight = height
|
||||
console.log(tag, uuid + " onHeightChanged: " + this.height)
|
||||
}
|
||||
|
||||
property var borderWidth: 0
|
||||
onBorderWidthChanged: {
|
||||
bg.border.width = borderWidth
|
||||
}
|
||||
|
||||
property var borderColor: ""
|
||||
onBorderColorChanged: {
|
||||
bg.border.color = borderColor
|
||||
}
|
||||
|
||||
MouseArea {
|
||||
anchors.fill: parent
|
||||
onClicked: {
|
||||
console.log(tag, uuid + " wrapper: " + wrapper)
|
||||
mouseAreaBridge.onClick(wrapper)
|
||||
}
|
||||
}
|
||||
}
|
@ -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