diff --git a/doric-Qt/example/app/qml.qrc b/doric-Qt/example/app/qml.qrc index 38d62c41..a2ed6dc4 100644 --- a/doric-Qt/example/app/qml.qrc +++ b/doric-Qt/example/app/qml.qrc @@ -44,6 +44,7 @@ ../doric/resources/scroller.qml ../doric/resources/image.qml ../doric/resources/slider.qml + ../doric/resources/slide-item.qml ../doric/resources/input.qml ../doric/resources/switch.qml diff --git a/doric-Qt/example/doric/resources/slide-item.qml b/doric-Qt/example/doric/resources/slide-item.qml new file mode 100644 index 00000000..cd6581e2 --- /dev/null +++ b/doric-Qt/example/doric/resources/slide-item.qml @@ -0,0 +1,180 @@ +import QtQuick 2.12 +import QtQuick.Controls 2.5 +import QtQuick.Layouts 1.15 +import QtGraphicalEffects 1.12 + +import "util.mjs" as Util + +Rectangle { + id: root + property var wrapper + + clip: true + + property var uuid: Util.uuidv4() + + property var tag: "SlideItem" + + onWidthChanged: { + console.log(tag, uuid + " onWidthChanged: " + this.width) + + updateGradient() + } + + onHeightChanged: { + console.log(tag, uuid + " onHeightChanged: " + this.height) + + updateGradient() + } + + color: 'transparent' + + property var backgroundColor + + onBackgroundColorChanged: { + color = backgroundColor + } + + property var borderWidth: 0 + onBorderWidthChanged: { + border.width = borderWidth + } + + property var borderColor: "" + onBorderColorChanged: { + border.color = borderColor + } + + MouseArea { + anchors.fill: parent + onClicked: { + console.log(tag, uuid + " wrapper: " + wrapper) + mouseAreaBridge.onClick(wrapper) + } + } + + property var shadowColor + property var shadowRadius + property var shadowOffsetX + property var shadowOffsetY + property var shadowOpacity + + onShadowOpacityChanged: { + if (shadowOpacity > 0) { + layer.enabled = true + } else { + layer.enabled = false + } + } + + layer.enabled: false + layer.effect: DropShadow { + horizontalOffset: shadowOffsetX + verticalOffset: shadowOffsetY + radius: shadowRadius + samples: 16 + color: shadowColor + transparentBorder: true + } + + + property var backgroundColorIsObject: false + onBackgroundColorIsObjectChanged: { + if (backgroundColorIsObject) { + lineGradient.anchors.fill = root + } else { + lineGradient.anchors.fill = null + } + } + + property variant gradientColors: [] + property variant gradientLocations: [] + + onGradientColorsChanged: { + console.log(tag, uuid + " onGradientColorsChanged: " + gradientColors) + if (gradientColors.length > 0) { + let stops = [] + + if (gradientLocations.length == 0) { + let unit = 1 / (gradientColors.length - 1) + for (let i = 0;i !== gradientColors.length;i++) { + let a = ((gradientColors[i] >> 24) & 0xff) / 255; + let r = ((gradientColors[i] >> 16) & 0xff) / 255; + let g = ((gradientColors[i] >> 8) & 0xff) / 255; + let b = ((gradientColors[i] >> 0) & 0xff) / 255; + let stop = stopComponent.createObject(root, {"position": unit * i, "color": Qt.rgba(r, g, b, a)}) + console.log(tag, uuid + " onGradientColorsChanged: " + "position: " + unit * i + " color: " + Qt.rgba(r, g, b, a)) + stops.push(stop) + } + } else { + for (let i = 0;i !== gradientColors.length;i++) { + let a = ((gradientColors[i] >> 24) & 0xff) / 255; + let r = ((gradientColors[i] >> 16) & 0xff) / 255; + let g = ((gradientColors[i] >> 8) & 0xff) / 255; + let b = ((gradientColors[i] >> 0) & 0xff) / 255; + let stop = stopComponent.createObject(root, {"position": gradientLocations[i], "color": Qt.rgba(r, g, b, a)}) + console.log(tag, uuid + " onGradientColorsChanged: " + "position: " + gradientLocations[i] + " color: " + Qt.rgba(r, g, b, a)) + stops.push(stop) + } + } + + innerGradient.stops = stops + } + } + + property var orientation: 0 + + function updateGradient() { + switch (orientation) { + case 0: + lineGradient.start = Qt.point(0, 0) + lineGradient.end = Qt.point(0, root.height) + break + case 1: + lineGradient.start = Qt.point(root.width, 0) + lineGradient.end = Qt.point(0, root.height) + break + case 2: + lineGradient.start = Qt.point(root.width, 0) + lineGradient.end = Qt.point(0, 0) + break + case 3: + lineGradient.start = Qt.point(root.width, root.height) + lineGradient.end = Qt.point(0, 0) + break + case 4: + lineGradient.start = Qt.point(0, root.height) + lineGradient.end = Qt.point(0, 0) + break + case 5: + lineGradient.start = Qt.point(0, root.height) + lineGradient.end = Qt.point(root.width, 0) + break + case 6: + lineGradient.start = Qt.point(0, 0) + lineGradient.end = Qt.point(root.width, 0) + break + case 7: + lineGradient.start = Qt.point(0, 0) + lineGradient.end = Qt.point(root.width, root.height) + break + } + } + onOrientationChanged: { + console.log(tag, uuid + " onOrientationChanged: " + orientation) + + updateGradient() + } + + LinearGradient { + Component { + id:stopComponent + GradientStop {} + } + + id: lineGradient + gradient: Gradient { + id: innerGradient + } + } +} diff --git a/doric-Qt/example/doric/shader/DoricViewNode.cpp b/doric-Qt/example/doric/shader/DoricViewNode.cpp index 713a7078..8856070a 100644 --- a/doric-Qt/example/doric/shader/DoricViewNode.cpp +++ b/doric-Qt/example/doric/shader/DoricViewNode.cpp @@ -189,7 +189,7 @@ void DoricViewNode::blend(QQuickItem *view, QString name, QJsonValue prop) { view->setProperty("shadowOffsetY", prop["offsetY"].toDouble()); view->setProperty("shadowOpacity", prop["opacity"].toDouble()); } else if (name != "layoutConfig") { - qCritical() << "unhandled prop: " << name << ": " << prop.toString(); + qCritical() << mType << " unhandled prop: " << name << ": " << prop.toString(); } } diff --git a/doric-Qt/example/doric/shader/slider/DoricSlideItemNode.cpp b/doric-Qt/example/doric/shader/slider/DoricSlideItemNode.cpp index 60ec7572..b1a1764c 100644 --- a/doric-Qt/example/doric/shader/slider/DoricSlideItemNode.cpp +++ b/doric-Qt/example/doric/shader/slider/DoricSlideItemNode.cpp @@ -1 +1,20 @@ #include "DoricSlideItemNode.h" + +QQuickItem *DoricSlideItemNode::build() { + QQmlComponent component(getContext()->getQmlEngine()); + + const QUrl url(QStringLiteral("qrc:/doric/qml/slide-item.qml")); + component.loadUrl(url); + + if (component.isError()) { + qCritical() << component.errorString(); + } + + QQuickItem *item = qobject_cast(component.create()); + this->createLayouts(item); + + getLayouts()->setLayoutType(DoricLayoutType::DoricStack); + + item->setProperty("wrapper", QString::number((qint64)this)); + return item; +} diff --git a/doric-Qt/example/doric/shader/slider/DoricSlideItemNode.h b/doric-Qt/example/doric/shader/slider/DoricSlideItemNode.h index c7dde437..628fe41f 100644 --- a/doric-Qt/example/doric/shader/slider/DoricSlideItemNode.h +++ b/doric-Qt/example/doric/shader/slider/DoricSlideItemNode.h @@ -8,6 +8,8 @@ class DORIC_EXPORT DoricSlideItemNode : public DoricStackNode { public: using DoricStackNode::DoricStackNode; + + QQuickItem *build() override; }; #endif // DORICSLIDEITEMNODE_H