FluPasswordBox.qml 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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. echoMode:btn_reveal.pressed ? TextField.Normal : TextField.Password
  25. renderType: FluTheme.nativeText ? Text.NativeRendering : Text.QtRendering
  26. selectionColor: FluTheme.primaryColor.lightest
  27. placeholderTextColor: {
  28. if(disabled){
  29. return placeholderDisableColor
  30. }
  31. if(focus){
  32. return placeholderFocusColor
  33. }
  34. return placeholderNormalColor
  35. }
  36. font.bold: {
  37. switch (fontStyle) {
  38. case FluText.Display:
  39. return true
  40. case FluText.TitleLarge:
  41. return true
  42. case FluText.Title:
  43. return true
  44. case FluText.SubTitle:
  45. return true
  46. case FluText.BodyStrong:
  47. return true
  48. case FluText.Body:
  49. return false
  50. case FluText.Caption:
  51. return false
  52. default:
  53. return false
  54. }
  55. }
  56. font.pixelSize: {
  57. switch (fontStyle) {
  58. case FluText.Display:
  59. return text.pixelSize * 4.857
  60. case FluText.TitleLarge:
  61. return text.pixelSize * 2.857
  62. case FluText.Title:
  63. return text.pixelSize * 2
  64. case FluText.SubTitle:
  65. return text.pixelSize * 1.428
  66. case FluText.Body:
  67. return text.pixelSize * 1.0
  68. case FluText.BodyStrong:
  69. return text.pixelSize * 1.0
  70. case FluText.Caption:
  71. return text.pixelSize * 0.857
  72. default:
  73. return text.pixelSize * 1.0
  74. }
  75. }
  76. selectByMouse: true
  77. rightPadding: icon_end.visible ? 50 : 30
  78. background: FluTextBoxBackground{
  79. inputItem: control
  80. FluIcon{
  81. id:icon_end
  82. iconSource: control.iconSource
  83. iconSize: 15
  84. opacity: 0.5
  85. visible: control.iconSource != 0
  86. anchors{
  87. verticalCenter: parent.verticalCenter
  88. right: parent.right
  89. rightMargin: 5
  90. }
  91. }
  92. }
  93. FluIconButton{
  94. id:btn_reveal
  95. iconSource:FluentIcons.RevealPasswordMedium
  96. iconSize: 10
  97. width: 20
  98. height: 20
  99. opacity: 0.5
  100. visible: control.text !== ""
  101. anchors{
  102. verticalCenter: parent.verticalCenter
  103. right: parent.right
  104. rightMargin: icon_end.visible ? 25 : 5
  105. }
  106. }
  107. TapHandler {
  108. acceptedButtons: Qt.RightButton
  109. onTapped: control.echoMode !== TextInput.Password && menu.popup()
  110. }
  111. FluTextBoxMenu{
  112. id:menu
  113. inputItem: control
  114. }
  115. }