朱子楚\zhuzi e25b944704 update
2023-06-27 21:14:20 +08:00

91 lines
2.7 KiB
QML

import QtQuick
import QtQuick.Controls
import QtQuick.Controls.Basic
import FluentUI
TextField{
signal commit
property bool disabled: false
property int iconSource: 0
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)
id:control
width: 300
enabled: !disabled
color: {
if(!enabled){
return disableColor
}
return normalColor
}
font:FluTextStyle.Body
renderType: FluTheme.nativeText ? Text.NativeRendering : Text.QtRendering
selectionColor: FluTheme.primaryColor.lightest
placeholderTextColor: {
if(!enabled){
return placeholderDisableColor
}
if(focus){
return placeholderFocusColor
}
return placeholderNormalColor
}
Keys.onEnterPressed: {
control.commit()
}
Keys.onReturnPressed: {
control.commit()
}
selectByMouse: true
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
}
}
}
MouseArea{
anchors.fill: parent
cursorShape: Qt.IBeamCursor
acceptedButtons: Qt.RightButton
onClicked: control.echoMode !== TextInput.Password && menu.popup()
}
FluIconButton{
iconSource:FluentIcons.ChromeClose
iconSize: 10
width: 20
height: 20
opacity: 0.5
visible: {
if(control.readOnly)
return false
return control.text !== ""
}
anchors{
verticalCenter: parent.verticalCenter
right: parent.right
rightMargin: icon_end.visible ? 25 : 5
}
onClicked:{
control.text = ""
}
}
FluTextBoxMenu{
id:menu
inputItem: control
}
}