From 54ea8eab1d4cb9db6a85668d4a26b5f60f019b2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=8A=B2=E9=B9=8F?= Date: Tue, 27 Apr 2021 10:32:42 +0800 Subject: [PATCH] add drop shadow for hlayout, vlayout & stack --- doric-Qt/doric/resources/hlayout.qml | 25 +++++++++++++++++++++++++ doric-Qt/doric/resources/stack.qml | 25 +++++++++++++++++++++++++ doric-Qt/doric/resources/vlayout.qml | 25 +++++++++++++++++++++++++ doric-Qt/doric/shader/DoricViewNode.cpp | 7 +++++++ 4 files changed, 82 insertions(+) diff --git a/doric-Qt/doric/resources/hlayout.qml b/doric-Qt/doric/resources/hlayout.qml index 09ff8d66..21d48fa0 100644 --- a/doric-Qt/doric/resources/hlayout.qml +++ b/doric-Qt/doric/resources/hlayout.qml @@ -1,6 +1,7 @@ import QtQuick 2.12 import QtQuick.Controls 2.5 import QtQuick.Layouts 1.15 +import QtGraphicalEffects 1.12 import "util.mjs" as Util @@ -46,4 +47,28 @@ Rectangle { 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 + } } diff --git a/doric-Qt/doric/resources/stack.qml b/doric-Qt/doric/resources/stack.qml index 2e409614..60534b6e 100644 --- a/doric-Qt/doric/resources/stack.qml +++ b/doric-Qt/doric/resources/stack.qml @@ -1,6 +1,7 @@ import QtQuick 2.12 import QtQuick.Controls 2.5 import QtQuick.Layouts 1.15 +import QtGraphicalEffects 1.12 import "util.mjs" as Util @@ -46,4 +47,28 @@ Rectangle { 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 + } } diff --git a/doric-Qt/doric/resources/vlayout.qml b/doric-Qt/doric/resources/vlayout.qml index c588a72f..d642453f 100644 --- a/doric-Qt/doric/resources/vlayout.qml +++ b/doric-Qt/doric/resources/vlayout.qml @@ -1,6 +1,7 @@ import QtQuick 2.12 import QtQuick.Controls 2.5 import QtQuick.Layouts 1.15 +import QtGraphicalEffects 1.12 import "util.mjs" as Util @@ -46,4 +47,28 @@ Rectangle { 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 + } } diff --git a/doric-Qt/doric/shader/DoricViewNode.cpp b/doric-Qt/doric/shader/DoricViewNode.cpp index c70dc8b9..53cb9c83 100644 --- a/doric-Qt/doric/shader/DoricViewNode.cpp +++ b/doric-Qt/doric/shader/DoricViewNode.cpp @@ -129,6 +129,13 @@ void DoricViewNode::blend(QQuickItem *view, QString name, QJsonValue prop) { QString borderColor = DoricUtils::doricColor(prop["color"].toInt()).name(); view->setProperty("borderWidth", borderWidth); view->setProperty("borderColor", borderColor); + } else if (name == "shadow") { + view->setProperty("shadowColor", QVariant::fromValue(DoricUtils::doricColor( + prop["color"].toInt()))); + view->setProperty("shadowRadius", prop["radius"].toDouble()); + view->setProperty("shadowOffsetX", prop["offsetX"].toDouble()); + view->setProperty("shadowOffsetY", prop["offsetY"].toDouble()); + view->setProperty("shadowOpacity", prop["opacity"].toDouble()); } else if (name != "layoutConfig") { qCritical() << name << ": " << prop.toString(); }