This repository has been archived on 2024-07-22. You can view files and clone it, but cannot push or open issues or pull requests.
Doric/doric-Qt/example/doric/resources/text.qml

156 lines
3.4 KiB
QML
Raw Normal View History

2021-02-25 19:04:14 +08:00
import QtQuick 2.12
import QtQuick.Controls 2.5
2021-05-25 11:30:11 +08:00
import QtGraphicalEffects 1.12
2021-03-18 11:27:26 +08:00
2021-03-16 15:20:46 +08:00
import "util.mjs" as Util
2021-03-18 11:27:26 +08:00
import "gravity.mjs" as Gravity
2021-02-25 19:04:14 +08:00
2021-05-27 16:07:09 +08:00
Text {
Rectangle {
id: bg
color: 'transparent'
z: -1
}
2021-05-26 15:47:44 +08:00
FontLoader { id: webFont }
2021-04-06 16:14:43 +08:00
property var wrapper
2021-03-16 15:20:46 +08:00
property var uuid: Util.uuidv4()
2021-03-16 15:20:46 +08:00
property var tag: "Text"
2021-04-16 16:44:08 +08:00
leftPadding: 0
topPadding: 0
rightPadding: 0
bottomPadding: 0
property int textAlignment: 0
2021-05-26 15:47:44 +08:00
property var fontSource: ""
onFontSourceChanged: {
webFont.source = fontSource
font.family = webFont.name
}
2021-05-19 14:27:44 +08:00
property var fontStyle: ""
onFontStyleChanged: {
if (fontStyle === "bold") {
font.weight = Font.Bold
} else if (fontStyle === "italic") {
font.italic = true
} else if (fontStyle === "bold_italic") {
font.weight = Font.Bold
font.italic = true
}
}
property var backgroundColor
2021-03-16 15:20:46 +08:00
onBackgroundColorChanged: {
bg.color = backgroundColor
2021-03-16 15:20:46 +08:00
}
2021-04-16 18:40:52 +08:00
horizontalAlignment: TextInput.AlignHCenter
verticalAlignment: TextInput.AlignVCenter
onTextAlignmentChanged: {
let gravity = Gravity.enumerate()
let result = this.textAlignment | gravity.CENTER_Y
console.log(tag, uuid + " onTextAlignmentChanged: " + this.textAlignment)
switch(result) {
case gravity.CENTER:
this.horizontalAlignment = TextInput.AlignHCenter
this.verticalAlignment = TextInput.AlignVCenter
break
2021-03-18 11:27:26 +08:00
}
}
2021-03-18 11:49:52 +08:00
onWidthChanged: {
2021-04-14 12:42:03 +08:00
bg.implicitWidth = width
2021-04-13 21:14:17 +08:00
console.log(tag, uuid + " onWidthChanged: " + this.width)
}
onHeightChanged: {
2021-04-14 12:42:03 +08:00
bg.implicitHeight = height
2021-04-13 21:14:17 +08:00
console.log(tag, uuid + " onHeightChanged: " + this.height)
}
onTextChanged: {
console.log(tag, uuid + " onTextChanged: " + this.text)
}
property var borderWidth: 0
onBorderWidthChanged: {
bg.border.width = borderWidth
}
property var borderColor: ""
onBorderColorChanged: {
bg.border.color = borderColor
}
2021-03-18 11:49:52 +08:00
MouseArea {
anchors.fill: parent
onClicked: {
2021-04-07 10:41:34 +08:00
console.log(tag, uuid + " wrapper: " + wrapper)
mouseAreaBridge.onClick(wrapper)
2021-03-18 11:49:52 +08:00
}
}
2021-05-25 11:30:11 +08:00
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
}
2021-05-25 12:42:14 +08:00
2021-05-27 16:18:44 +08:00
property var htmlText: false
onHtmlTextChanged: {
if (htmlText) {
textFormat = TextEdit.RichText
}
}
2021-05-25 14:44:42 +08:00
property var strikethrough: false
onStrikethroughChanged: {
font.strikeout = strikethrough
}
property var underline: false
onUnderlineChanged: {
font.underline = underline
}
2021-05-27 16:07:09 +08:00
property var lineSpacing: -1
onLineSpacingChanged: {
if (lineSpacing > 0) {
lineHeightMode = Text.FixedHeight
lineHeight = lineSpacing
}
}
2021-02-25 19:04:14 +08:00
}