add drop shadow for hlayout, vlayout & stack

This commit is contained in:
王劲鹏 2021-04-27 10:32:42 +08:00 committed by osborn
parent 358f0f0589
commit 54ea8eab1d
4 changed files with 82 additions and 0 deletions

View File

@ -1,6 +1,7 @@
import QtQuick 2.12 import QtQuick 2.12
import QtQuick.Controls 2.5 import QtQuick.Controls 2.5
import QtQuick.Layouts 1.15 import QtQuick.Layouts 1.15
import QtGraphicalEffects 1.12
import "util.mjs" as Util import "util.mjs" as Util
@ -46,4 +47,28 @@ Rectangle {
mouseAreaBridge.onClick(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
}
} }

View File

@ -1,6 +1,7 @@
import QtQuick 2.12 import QtQuick 2.12
import QtQuick.Controls 2.5 import QtQuick.Controls 2.5
import QtQuick.Layouts 1.15 import QtQuick.Layouts 1.15
import QtGraphicalEffects 1.12
import "util.mjs" as Util import "util.mjs" as Util
@ -46,4 +47,28 @@ Rectangle {
mouseAreaBridge.onClick(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
}
} }

View File

@ -1,6 +1,7 @@
import QtQuick 2.12 import QtQuick 2.12
import QtQuick.Controls 2.5 import QtQuick.Controls 2.5
import QtQuick.Layouts 1.15 import QtQuick.Layouts 1.15
import QtGraphicalEffects 1.12
import "util.mjs" as Util import "util.mjs" as Util
@ -46,4 +47,28 @@ Rectangle {
mouseAreaBridge.onClick(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
}
} }

View File

@ -129,6 +129,13 @@ void DoricViewNode::blend(QQuickItem *view, QString name, QJsonValue prop) {
QString borderColor = DoricUtils::doricColor(prop["color"].toInt()).name(); QString borderColor = DoricUtils::doricColor(prop["color"].toInt()).name();
view->setProperty("borderWidth", borderWidth); view->setProperty("borderWidth", borderWidth);
view->setProperty("borderColor", borderColor); 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") { } else if (name != "layoutConfig") {
qCritical() << name << ": " << prop.toString(); qCritical() << name << ": " << prop.toString();
} }