FluentUI/src/controls/FluText.qml

75 lines
1.8 KiB
QML
Raw Normal View History

2023-02-26 23:47:07 +08:00
import QtQuick 2.15
Text {
id:text
enum FontStyle {
Display,
TitleLarge,
Title,
Subtitle,
BodyLarge,
BodyStrong,
Body,
Caption
}
2023-02-27 18:46:39 +08:00
property int fontStyle: FluText.Body
property color textColor: FluApp.isDark ? "#FFFFFF" : "#1A1A1A"
2023-02-26 23:47:07 +08:00
2023-02-27 18:46:39 +08:00
property int pixelSize : 14
2023-02-26 23:47:07 +08:00
color: textColor
Component.onCompleted: {
setFontStyle(fontStyle)
}
onStyleChanged: {
setFontStyle(fontStyle)
}
function setFontStyle(fontStyle) {
switch (fontStyle) {
case FluText.Display:
font.bold = true
font.pixelSize = text.pixelSize * 4
break
case FluText.TitleLarge:
font.bold = true
font.pixelSize = text.pixelSize * 2
break
case FluText.Title:
font.bold = true
font.pixelSize = text.pixelSize * 1.5
break
case FluText.Subtitle:
font.bold = true
font.pixelSize = text.pixelSize * 0.9
break
case FluText.BodyLarge:
font.bold = false
font.pixelSize = text.pixelSize * 1.1
break
case FluText.BodyStrong:
font.bold = true
font.pixelSize = text.pixelSize * 1.0
break
case FluText.Body:
font.bold = false
font.pixelSize = text.pixelSize
break
case FluText.Caption:
font.bold = false
font.pixelSize = text.pixelSize * 0.8
break
default:
2023-02-27 18:46:39 +08:00
font.pixelSize = text.pixelSize * 1.0
2023-02-26 23:47:07 +08:00
break
}
}
}