add text shadow

This commit is contained in:
王劲鹏 2021-05-25 11:30:11 +08:00 committed by osborn
parent 2baa84a9ee
commit 8b9c14c827
2 changed files with 32 additions and 0 deletions

View File

@ -1,5 +1,6 @@
import QtQuick 2.12 import QtQuick 2.12
import QtQuick.Controls 2.5 import QtQuick.Controls 2.5
import QtGraphicalEffects 1.12
import "util.mjs" as Util import "util.mjs" as Util
import "gravity.mjs" as Gravity import "gravity.mjs" as Gravity
@ -98,4 +99,28 @@ TextArea {
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

@ -32,6 +32,13 @@ void DoricTextNode::blend(QQuickItem *view, QString name, QJsonValue prop) {
view->setProperty("textAlignment", prop.toInt()); view->setProperty("textAlignment", prop.toInt());
} else if (name == "fontStyle") { } else if (name == "fontStyle") {
view->setProperty("fontStyle", prop.toString()); view->setProperty("fontStyle", prop.toString());
} 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 { } else {
DoricViewNode::blend(view, name, prop); DoricViewNode::blend(view, name, prop);
} }