FluTextBox.qml 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. import QtQuick
  2. import QtQuick.Controls
  3. import QtQuick.Controls.Basic
  4. import FluentUI
  5. TextField{
  6. property int fontStyle: FluText.Body
  7. property int pixelSize : FluTheme.textSize
  8. property bool disabled: false
  9. property int iconSource: 0
  10. property color normalColor: FluTheme.dark ? Qt.rgba(255/255,255/255,255/255,1) : Qt.rgba(27/255,27/255,27/255,1)
  11. property color disableColor: FluTheme.dark ? Qt.rgba(131/255,131/255,131/255,1) : Qt.rgba(160/255,160/255,160/255,1)
  12. property color placeholderNormalColor: FluTheme.dark ? Qt.rgba(210/255,210/255,210/255,1) : Qt.rgba(96/255,96/255,96/255,1)
  13. property color placeholderFocusColor: FluTheme.dark ? Qt.rgba(152/255,152/255,152/255,1) : Qt.rgba(141/255,141/255,141/255,1)
  14. property color placeholderDisableColor: FluTheme.dark ? Qt.rgba(131/255,131/255,131/255,1) : Qt.rgba(160/255,160/255,160/255,1)
  15. id:control
  16. width: 300
  17. enabled: !disabled
  18. color: {
  19. if(disabled){
  20. return disableColor
  21. }
  22. return normalColor
  23. }
  24. renderType: FluTheme.nativeText ? Text.NativeRendering : Text.QtRendering
  25. selectionColor: FluTheme.primaryColor.lightest
  26. placeholderTextColor: {
  27. if(disabled){
  28. return placeholderDisableColor
  29. }
  30. if(focus){
  31. return placeholderFocusColor
  32. }
  33. return placeholderNormalColor
  34. }
  35. font.bold: {
  36. switch (fontStyle) {
  37. case FluText.Display:
  38. return true
  39. case FluText.TitleLarge:
  40. return true
  41. case FluText.Title:
  42. return true
  43. case FluText.SubTitle:
  44. return true
  45. case FluText.BodyStrong:
  46. return true
  47. case FluText.Body:
  48. return false
  49. case FluText.Caption:
  50. return false
  51. default:
  52. return false
  53. }
  54. }
  55. font.pixelSize: {
  56. switch (fontStyle) {
  57. case FluText.Display:
  58. return text.pixelSize * 4.857
  59. case FluText.TitleLarge:
  60. return text.pixelSize * 2.857
  61. case FluText.Title:
  62. return text.pixelSize * 2
  63. case FluText.SubTitle:
  64. return text.pixelSize * 1.428
  65. case FluText.Body:
  66. return text.pixelSize * 1.0
  67. case FluText.BodyStrong:
  68. return text.pixelSize * 1.0
  69. case FluText.Caption:
  70. return text.pixelSize * 0.857
  71. default:
  72. return text.pixelSize * 1.0
  73. }
  74. }
  75. selectByMouse: true
  76. rightPadding: icon_end.visible ? 50 : 30
  77. background: FluTextBoxBackground{
  78. inputItem: control
  79. FluIcon{
  80. id:icon_end
  81. iconSource: control.iconSource
  82. iconSize: 15
  83. opacity: 0.5
  84. visible: control.iconSource != 0
  85. anchors{
  86. verticalCenter: parent.verticalCenter
  87. right: parent.right
  88. rightMargin: 5
  89. }
  90. }
  91. }
  92. FluIconButton{
  93. iconSource:FluentIcons.ChromeClose
  94. iconSize: 10
  95. width: 20
  96. height: 20
  97. opacity: 0.5
  98. visible: control.text !== ""
  99. anchors{
  100. verticalCenter: parent.verticalCenter
  101. right: parent.right
  102. rightMargin: icon_end.visible ? 25 : 5
  103. }
  104. onClicked:{
  105. control.text = ""
  106. }
  107. }
  108. TapHandler {
  109. acceptedButtons: Qt.RightButton
  110. onTapped: control.echoMode !== TextInput.Password && menu.popup()
  111. }
  112. FluTextBoxMenu{
  113. id:menu
  114. inputItem: control
  115. }
  116. }