SearchPanel.qml 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. import QtQuick 2.15
  2. import QtQuick.Layouts 1.15
  3. import DMusic 1.0
  4. import YandexMusic 1.0
  5. import "components"
  6. FloatingPanel {
  7. id: root
  8. height: _column.implicitHeight + (root.text == ""? 40 : 20)
  9. property string text
  10. signal changeText(string text)
  11. triangleCenter: horizontalCenter
  12. triangleTop: top
  13. triangleRotation: 180
  14. MouseArea {
  15. anchors.fill: parent
  16. hoverEnabled: true
  17. }
  18. onTextChanged: {
  19. SearchModel.search(root.text)
  20. }
  21. ColumnLayout {
  22. id: _column
  23. anchors.centerIn: parent
  24. width: root.width - 40
  25. spacing: 15
  26. DText {
  27. Layout.alignment: Qt.AlignHCenter
  28. color: Style.panel.text.color
  29. visible: SearchModel.nothingFound && root.text != ""
  30. text: qsTr("Nothing found")
  31. }
  32. Loader {
  33. sourceComponent: root.text == ""? _hisroty : _searchResults
  34. }
  35. Row {
  36. visible: false
  37. topPadding: 5
  38. leftPadding: spacing - 20
  39. rightPadding: spacing - 20
  40. spacing: Math.ceil((root.width - _tracks.width - _albums.width - _artists.width) / 4)
  41. SearchFilterToggle {
  42. id: _tracks
  43. text: qsTr("Tracks")
  44. icon: "qrc:/resources/search/track.svg"
  45. }
  46. SearchFilterToggle {
  47. id: _albums
  48. text: qsTr("Albums")
  49. icon: "qrc:/resources/search/album.svg"
  50. }
  51. SearchFilterToggle {
  52. id: _artists
  53. text: qsTr("Artists")
  54. icon: "qrc:/resources/search/artist.svg"
  55. }
  56. }
  57. }
  58. Component {
  59. id: _hisroty
  60. Column {
  61. spacing: 15
  62. width: root.width
  63. Repeater {
  64. enabled: root.text
  65. model: SearchHistory
  66. MouseArea {
  67. width: root.width - 40
  68. height: 14
  69. clip: true
  70. hoverEnabled: true
  71. cursorShape: Qt.PointingHandCursor
  72. onClicked: {
  73. root.changeText(element)
  74. SearchHistory.savePromit(element)
  75. }
  76. Icon {
  77. id: _icon
  78. width: 14
  79. height: 14
  80. src: "qrc:/resources/search/history.svg"
  81. color: parent.containsMouse? Style.panel.text.darkColor : Style.panel.text.color
  82. }
  83. DText {
  84. x: 24
  85. anchors.verticalCenter: parent.verticalCenter
  86. style: Style.panel.text
  87. font.pointSize: 9
  88. color: parent.containsMouse? Style.panel.text.darkColor : Style.panel.text.color
  89. text: element
  90. }
  91. }
  92. }
  93. }
  94. }
  95. Component {
  96. id: _searchResults
  97. Column {
  98. x: -10
  99. Repeater {
  100. model: SearchModel
  101. SearchResult {
  102. width: root.width - 20
  103. kind: objKind
  104. cover: objCover
  105. name: objName
  106. comment: objComment
  107. artist: objArtist
  108. onPlay: {
  109. SearchHistory.savePromit(root.text)
  110. AudioPlayer.playYmTrack(objId)
  111. _root.focus = true
  112. }
  113. }
  114. }
  115. }
  116. }
  117. }