add slider node

This commit is contained in:
王劲鹏 2021-05-07 18:17:07 +08:00 committed by osborn
parent 0ad7cfb52e
commit 0f2a6ef55c
12 changed files with 189 additions and 41 deletions

View File

@ -33,6 +33,7 @@
<file alias="text.qml">../doric/resources/text.qml</file> <file alias="text.qml">../doric/resources/text.qml</file>
<file alias="scroller.qml">../doric/resources/scroller.qml</file> <file alias="scroller.qml">../doric/resources/scroller.qml</file>
<file alias="image.qml">../doric/resources/image.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="toast.qml">../doric/resources/toast.qml</file>
<file alias="alert.qml">../doric/resources/alert.qml</file> <file alias="alert.qml">../doric/resources/alert.qml</file>

View File

@ -8,50 +8,33 @@ ApplicationWindow {
height: 800 height: 800
title: qsTr("Scroll") title: qsTr("Scroll")
ScrollView { SwipeView {
property var wrapper id: view
width: 200 currentIndex: 0
height: 200 anchors.fill: parent
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)
}
Rectangle { Rectangle {
implicitWidth: 400 id: firstPage
implicitHeight: 400 color: 'red'
}
Rectangle {
id: secondPage
color: 'green'
}
Rectangle {
id: thirdPage
color: 'blue'
}
}
Label { PageIndicator {
text: "ABC" id: indicator
font.pixelSize: 124
} count: view.count
} currentIndex: view.currentIndex
anchors.bottom: view.bottom
anchors.horizontalCenter: parent.horizontalCenter
} }
} }

View File

@ -50,6 +50,7 @@ SOURCES += \
shader/DoricTextNode.cpp \ shader/DoricTextNode.cpp \
shader/DoricVLayoutNode.cpp \ shader/DoricVLayoutNode.cpp \
shader/DoricViewNode.cpp \ shader/DoricViewNode.cpp \
shader/slider/DoricSliderNode.cpp \
utils/DoricConstant.cpp \ utils/DoricConstant.cpp \
utils/DoricContextHolder.cpp \ utils/DoricContextHolder.cpp \
utils/DoricDialogBridge.cpp \ utils/DoricDialogBridge.cpp \
@ -124,6 +125,7 @@ HEADERS += \
shader/DoricTextNode.h \ shader/DoricTextNode.h \
shader/DoricVLayoutNode.h \ shader/DoricVLayoutNode.h \
shader/DoricViewNode.h \ shader/DoricViewNode.h \
shader/slider/DoricSliderNode.h \
template/DoricSingleton.h \ template/DoricSingleton.h \
utils/DoricConstant.h \ utils/DoricConstant.h \
utils/DoricContextHolder.h \ utils/DoricContextHolder.h \

View 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)
}
}
}

View File

@ -153,3 +153,13 @@ void DoricGroupNode::requestLayout() {
DoricSuperNode::requestLayout(); DoricSuperNode::requestLayout();
foreach (DoricViewNode *node, this->mChildNodes) { node->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;
}

View File

@ -23,6 +23,8 @@ protected:
virtual void afterBlended(QJsonValue props) override; virtual void afterBlended(QJsonValue props) override;
virtual void requestLayout() override; virtual void requestLayout() override;
virtual DoricViewNode *getSubNodeById(QString id) override;
}; };
#endif // DORICGROUPNODE_H #endif // DORICGROUPNODE_H

View File

@ -117,3 +117,7 @@ QSizeF DoricScrollerNode::sizeThatFits(QSizeF size) {
return QSizeF(qMin(size.width(), layout->getMeasuredWidth()), return QSizeF(qMin(size.width(), layout->getMeasuredWidth()),
qMin(size.height(), layout->getMeasuredHeight())); qMin(size.height(), layout->getMeasuredHeight()));
} }
DoricViewNode *DoricScrollerNode::getSubNodeById(QString id) {
return id == mChildNode->getId() ? mChildNode : nullptr;
}

View File

@ -25,6 +25,8 @@ public:
virtual void requestLayout() override; virtual void requestLayout() override;
QSizeF sizeThatFits(QSizeF size); QSizeF sizeThatFits(QSizeF size);
virtual DoricViewNode *getSubNodeById(QString id) override;
}; };
#endif // DORICSCROLLERNODE_H #endif // DORICSCROLLERNODE_H

View File

@ -54,3 +54,33 @@ void DoricSuperNode::blendSubLayoutConfig(DoricViewNode *viewNode,
QJsonValue jsValue) { QJsonValue jsValue) {
viewNode->blendLayoutConfig(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);
}
}

View File

@ -14,6 +14,8 @@ protected:
virtual void blendSubNode(QJsonValue subProperties) = 0; virtual void blendSubNode(QJsonValue subProperties) = 0;
void recursiveMixin(QJsonValue src, QJsonValue target);
public: public:
using DoricViewNode::DoricViewNode; using DoricViewNode::DoricViewNode;
@ -23,10 +25,14 @@ public:
void blendSubLayoutConfig(DoricViewNode *viewNode, QJsonValue jsValue); void blendSubLayoutConfig(DoricViewNode *viewNode, QJsonValue jsValue);
virtual DoricViewNode *getSubNodeById(QString id) = 0;
private: private:
void mixinSubNode(QJsonValue subNode); void mixinSubNode(QJsonValue subNode);
void mixin(QJsonValue src, QJsonValue target); void mixin(QJsonValue src, QJsonValue target);
bool viewIdIsEqual(QJsonValue src, QJsonValue target);
}; };
#endif // DORICSUPERNODE_H #endif // DORICSUPERNODE_H

View 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) {}

View 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