From efe89e54c5052afbf6542308571ccccb3dbafffb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=8A=B2=E9=B9=8F?= Date: Wed, 21 Apr 2021 11:14:21 +0800 Subject: [PATCH] init set x & y; update x & y --- doric-Qt/doric/plugin/DoricModalPlugin.cpp | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/doric-Qt/doric/plugin/DoricModalPlugin.cpp b/doric-Qt/doric/plugin/DoricModalPlugin.cpp index 23c02527..74262aad 100644 --- a/doric-Qt/doric/plugin/DoricModalPlugin.cpp +++ b/doric-Qt/doric/plugin/DoricModalPlugin.cpp @@ -30,12 +30,27 @@ void DoricModalPlugin::toast(QString jsValueString, QString callbackId) { item->setParentItem(rootObject); item->childItems().at(0)->childItems().at(0)->setProperty("text", msg); - item->setProperty("y", rootObject->height() - item->height() - 20); + // init set x + item->setProperty("x", (rootObject->width() - item->width()) / 2.f); + // init set y + if ((gravity & DoricGravity::DoricGravityBottom) == + DoricGravity::DoricGravityBottom) { + item->setProperty("y", rootObject->height() - item->height() - 20); + } else if ((gravity & DoricGravity::DoricGravityTop) == + DoricGravity::DoricGravityTop) { + item->setProperty("y", 20); + } else { + item->setProperty("y", + (rootObject->height() - item->height() - 88) / 2); + } + + // update x connect(item, &QQuickItem::widthChanged, [rootObject, item]() { item->setProperty("x", (rootObject->width() - item->width()) / 2.f); }); + // update y connect(item, &QQuickItem::heightChanged, [rootObject, item, gravity]() { if ((gravity & DoricGravity::DoricGravityBottom) ==