DTextBox.qml 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. import QtQuick 2.15
  2. import DMusic 1.0
  3. Rectangle {
  4. id: root
  5. height: style.height
  6. width: 200
  7. radius: style.radius
  8. color: style.background.normal
  9. border.width: style.border.width
  10. border.color: style.border.color.normal
  11. property string hint: ""
  12. property alias input: _input
  13. property alias text: _input.text
  14. property bool clearButton: false
  15. property real textRightPadding: 0
  16. property QtObject style: Style.panel.textBox
  17. MouseArea {
  18. anchors.fill: parent
  19. anchors.leftMargin: 5
  20. anchors.rightMargin: 5
  21. clip: true
  22. cursorShape: Qt.IBeamCursor
  23. TextInput {
  24. id: _input
  25. anchors.fill: parent
  26. anchors.rightMargin: ((clearButton && contentWidth > parent.width - _clear.width * 2)? _clear.width : 0) + root.textRightPadding
  27. verticalAlignment: Text.AlignVCenter
  28. horizontalAlignment: root.style.text.hAlign
  29. clip: true
  30. color: root.style.text.color
  31. font.family: root.style.text.font
  32. font.pointSize: root.height * 0.75 * root.style.textScale
  33. selectByMouse: true
  34. selectionColor: "#627FAA"
  35. }
  36. DText {
  37. anchors.fill: _input
  38. verticalAlignment: Text.AlignVCenter
  39. horizontalAlignment: root.style.text.hAlign
  40. anchors.rightMargin: root.textRightPadding
  41. visible: _input.text == ""
  42. font.family: root.style.text.font
  43. font.pointSize: root.height * 0.75 * root.style.hintScale
  44. text: root.hint
  45. color: root.style.text.darkColor
  46. }
  47. MouseArea {
  48. id: _clear
  49. anchors.right: parent.right
  50. anchors.rightMargin: root.textRightPadding
  51. visible: clearButton && root.text !== ""
  52. height: parent.height
  53. width: height
  54. hoverEnabled: true
  55. cursorShape: Qt.PointingHandCursor
  56. onClicked: root.text = ""
  57. Icon {
  58. anchors.centerIn: parent
  59. src: "qrc:/resources/title/clear.svg"
  60. color: root.style.text.color
  61. }
  62. }
  63. }
  64. states: [
  65. State {
  66. name: "input"
  67. when: _input.text != "" || _input.focus == true
  68. PropertyChanges {
  69. target: root
  70. color: root.style.background.input
  71. border.color: style.border.color.input
  72. }
  73. }
  74. ]
  75. transitions: Transition {
  76. ColorAnimation { properties: "color"; duration: 250; easing.type: Easing.OutCubic }
  77. }
  78. }