FluentUI/src/controls/FluTextBox.qml

121 lines
3.5 KiB
QML
Raw Normal View History

2023-03-30 21:52:55 +08:00
import QtQuick
import QtQuick.Controls
import FluentUI
2023-02-26 23:47:07 +08:00
2023-04-05 16:37:27 +08:00
FluTextFiled{
2023-03-09 23:11:59 +08:00
property int fontStyle: FluText.Body
property int pixelSize : FluTheme.textSize
2023-03-20 18:22:32 +08:00
property bool disabled: false
2023-04-02 14:05:54 +08:00
property int iconSource: 0
2023-04-01 21:01:46 +08:00
property color normalColor: FluTheme.dark ? Qt.rgba(255/255,255/255,255/255,1) : Qt.rgba(27/255,27/255,27/255,1)
property color disableColor: FluTheme.dark ? Qt.rgba(131/255,131/255,131/255,1) : Qt.rgba(160/255,160/255,160/255,1)
property color placeholderNormalColor: FluTheme.dark ? Qt.rgba(210/255,210/255,210/255,1) : Qt.rgba(96/255,96/255,96/255,1)
property color placeholderFocusColor: FluTheme.dark ? Qt.rgba(152/255,152/255,152/255,1) : Qt.rgba(141/255,141/255,141/255,1)
property color placeholderDisableColor: FluTheme.dark ? Qt.rgba(131/255,131/255,131/255,1) : Qt.rgba(160/255,160/255,160/255,1)
2023-03-09 23:11:59 +08:00
2023-04-01 21:01:46 +08:00
id:control
2023-03-02 12:20:16 +08:00
width: 300
2023-03-20 18:22:32 +08:00
enabled: !disabled
color: {
if(disabled){
2023-04-01 21:01:46 +08:00
return disableColor
2023-03-20 18:22:32 +08:00
}
2023-04-01 21:01:46 +08:00
return normalColor
2023-03-20 18:22:32 +08:00
}
2023-03-28 21:37:10 +08:00
renderType: FluTheme.nativeText ? Text.NativeRendering : Text.QtRendering
2023-03-30 18:23:33 +08:00
selectionColor: FluTheme.primaryColor.lightest
2023-03-09 23:11:59 +08:00
placeholderTextColor: {
2023-03-20 18:22:32 +08:00
if(disabled){
2023-04-01 21:01:46 +08:00
return placeholderDisableColor
2023-03-20 18:22:32 +08:00
}
2023-03-09 23:11:59 +08:00
if(focus){
2023-04-01 21:01:46 +08:00
return placeholderFocusColor
2023-03-09 23:11:59 +08:00
}
2023-04-01 21:01:46 +08:00
return placeholderNormalColor
2023-03-09 23:11:59 +08:00
}
font.bold: {
switch (fontStyle) {
case FluText.Display:
return true
case FluText.TitleLarge:
return true
case FluText.Title:
return true
2023-03-29 21:43:01 +08:00
case FluText.SubTitle:
2023-03-09 23:11:59 +08:00
return true
case FluText.BodyStrong:
return true
case FluText.Body:
return false
case FluText.Caption:
return false
default:
return false
}
}
font.pixelSize: {
switch (fontStyle) {
case FluText.Display:
2023-03-29 21:43:01 +08:00
return text.pixelSize * 4.857
2023-03-09 23:11:59 +08:00
case FluText.TitleLarge:
2023-03-29 21:43:01 +08:00
return text.pixelSize * 2.857
2023-03-09 23:11:59 +08:00
case FluText.Title:
2023-03-29 21:43:01 +08:00
return text.pixelSize * 2
case FluText.SubTitle:
return text.pixelSize * 1.428
2023-03-09 23:11:59 +08:00
case FluText.Body:
2023-03-29 21:43:01 +08:00
return text.pixelSize * 1.0
case FluText.BodyStrong:
return text.pixelSize * 1.0
2023-03-09 23:11:59 +08:00
case FluText.Caption:
2023-03-29 21:43:01 +08:00
return text.pixelSize * 0.857
2023-03-09 23:11:59 +08:00
default:
2023-03-29 21:43:01 +08:00
return text.pixelSize * 1.0
2023-03-09 23:11:59 +08:00
}
}
2023-03-02 12:20:16 +08:00
selectByMouse: true
2023-04-02 14:05:54 +08:00
rightPadding: icon_end.visible ? 50 : 30
background: FluTextBoxBackground{
inputItem: control
FluIcon{
id:icon_end
iconSource: control.iconSource
iconSize: 15
opacity: 0.5
visible: control.iconSource != 0
anchors{
verticalCenter: parent.verticalCenter
right: parent.right
rightMargin: 5
}
}
}
FluIconButton{
iconSource:FluentIcons.ChromeClose
iconSize: 10
width: 20
height: 20
opacity: 0.5
visible: control.text !== ""
anchors{
verticalCenter: parent.verticalCenter
right: parent.right
rightMargin: icon_end.visible ? 25 : 5
}
onClicked:{
control.text = ""
}
}
2023-03-30 18:23:33 +08:00
TapHandler {
acceptedButtons: Qt.RightButton
2023-04-01 21:01:46 +08:00
onTapped: control.echoMode !== TextInput.Password && menu.popup()
2023-03-30 18:23:33 +08:00
}
2023-04-01 21:01:46 +08:00
FluTextBoxMenu{
2023-03-30 18:23:33 +08:00
id:menu
2023-04-01 21:01:46 +08:00
inputItem: control
2023-03-30 18:23:33 +08:00
}
2023-02-26 23:47:07 +08:00
}
2023-03-02 12:20:16 +08:00