add text color & text size

This commit is contained in:
王劲鹏 2021-03-16 16:01:38 +08:00 committed by osborn
parent ca1129d31e
commit c51b99a351
2 changed files with 10 additions and 2 deletions

View File

@ -23,10 +23,10 @@ Rectangle {
this.childrenRectWidth = childrenRect.width this.childrenRectWidth = childrenRect.width
this.childrenRectHeight = childrenRect.height this.childrenRectHeight = childrenRect.height
if (this.width === 0) { if (this.width < this.childrenRectWidth) {
this.width = this.childrenRectWidth this.width = this.childrenRectWidth
} }
if (this.height === 0) { if (this.height < this.childrenRectHeight) {
this.height = this.childrenRectHeight this.height = this.childrenRectHeight
} }
} }

View File

@ -1,4 +1,5 @@
#include "DoricTextNode.h" #include "DoricTextNode.h"
#include "../utils/DoricUtils.h"
QQuickItem *DoricTextNode::build() { QQuickItem *DoricTextNode::build() {
QQmlComponent component(getContext()->getQmlEngine()); QQmlComponent component(getContext()->getQmlEngine());
@ -17,6 +18,13 @@ QQuickItem *DoricTextNode::build() {
void DoricTextNode::blend(QQuickItem *view, QString name, QJSValue prop) { void DoricTextNode::blend(QQuickItem *view, QString name, QJSValue prop) {
if (name == "text") { if (name == "text") {
view->childItems().at(0)->setProperty("text", prop.toString()); view->childItems().at(0)->setProperty("text", prop.toString());
} else if (name == "textColor") {
QString color = DoricUtils::doricColor(prop.toNumber()).name();
view->childItems().at(0)->setProperty("color", color);
} else if (name == "textSize") {
QFont font = view->childItems().at(0)->property("font").value<QFont>();
font.setPixelSize(prop.toNumber());
view->childItems().at(0)->setProperty("font", QVariant(font));
} else { } else {
DoricViewNode::blend(view, name, prop); DoricViewNode::blend(view, name, prop);
} }