ModernPatternListPage.qml 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  1. import QtQuick 2.15
  2. import QtQuick.Controls 2.15
  3. import QtQuick.Layouts 1.15
  4. import "../components"
  5. import "../components" as Components
  6. Page {
  7. id: page
  8. property var patternModel
  9. property var backend
  10. property var stackView
  11. property bool searchExpanded: false
  12. Rectangle {
  13. anchors.fill: parent
  14. color: Components.ThemeManager.backgroundColor
  15. }
  16. ColumnLayout {
  17. anchors.fill: parent
  18. spacing: 0
  19. // Header with integrated search
  20. Rectangle {
  21. Layout.fillWidth: true
  22. Layout.preferredHeight: 50
  23. color: Components.ThemeManager.surfaceColor
  24. // Bottom border
  25. Rectangle {
  26. anchors.bottom: parent.bottom
  27. width: parent.width
  28. height: 1
  29. color: Components.ThemeManager.borderColor
  30. }
  31. RowLayout {
  32. anchors.fill: parent
  33. anchors.leftMargin: 15
  34. anchors.rightMargin: 10
  35. ConnectionStatus {
  36. backend: page.backend
  37. Layout.rightMargin: 8
  38. visible: !searchExpanded
  39. }
  40. Label {
  41. text: "Browse Patterns"
  42. font.pixelSize: 18
  43. font.bold: true
  44. color: Components.ThemeManager.textPrimary
  45. visible: !searchExpanded
  46. }
  47. // Pattern count
  48. Label {
  49. text: patternModel.rowCount() + " patterns"
  50. font.pixelSize: 12
  51. color: Components.ThemeManager.textTertiary
  52. visible: !searchExpanded
  53. }
  54. Item {
  55. Layout.fillWidth: true
  56. visible: !searchExpanded
  57. }
  58. // Expandable search
  59. Rectangle {
  60. Layout.fillWidth: searchExpanded
  61. Layout.preferredWidth: searchExpanded ? parent.width - 60 : 120
  62. Layout.preferredHeight: 32
  63. radius: 16
  64. color: searchExpanded ? Components.ThemeManager.surfaceColor : Components.ThemeManager.cardColor
  65. border.color: searchExpanded ? "#2563eb" : Components.ThemeManager.borderColor
  66. border.width: 1
  67. Behavior on Layout.preferredWidth {
  68. NumberAnimation { duration: 200 }
  69. }
  70. RowLayout {
  71. anchors.fill: parent
  72. anchors.leftMargin: 10
  73. anchors.rightMargin: 10
  74. spacing: 5
  75. Text {
  76. text: "⌕"
  77. font.pixelSize: 16
  78. font.family: "sans-serif"
  79. color: searchExpanded ? "#2563eb" : Components.ThemeManager.textSecondary
  80. }
  81. TextField {
  82. id: searchField
  83. Layout.fillWidth: true
  84. placeholderText: searchExpanded ? "Search patterns... (press Enter)" : "Search"
  85. font.pixelSize: 14
  86. visible: searchExpanded || text.length > 0
  87. property string lastSearchText: ""
  88. property bool hasUnappliedSearch: text !== lastSearchText && text.length > 0
  89. background: Rectangle {
  90. color: "transparent"
  91. border.color: searchField.hasUnappliedSearch ? "#f59e0b" : "transparent"
  92. border.width: searchField.hasUnappliedSearch ? 1 : 0
  93. radius: 4
  94. }
  95. // Remove automatic filtering on text change
  96. // onTextChanged: patternModel.filter(text)
  97. // Only filter when user presses Enter or field loses focus
  98. onAccepted: {
  99. patternModel.filter(text)
  100. lastSearchText = text
  101. Qt.inputMethod.hide()
  102. focus = false
  103. }
  104. // Enable virtual keyboard
  105. activeFocusOnPress: true
  106. selectByMouse: true
  107. inputMethodHints: Qt.ImhNoPredictiveText
  108. // Direct MouseArea for touch events
  109. MouseArea {
  110. anchors.fill: parent
  111. onPressed: {
  112. searchField.forceActiveFocus()
  113. Qt.inputMethod.show()
  114. mouse.accepted = false // Pass through to TextField
  115. }
  116. }
  117. onActiveFocusChanged: {
  118. if (activeFocus) {
  119. searchExpanded = true
  120. // Force virtual keyboard to show
  121. Qt.inputMethod.show()
  122. } else {
  123. // Apply search when focus is lost
  124. if (text !== lastSearchText) {
  125. patternModel.filter(text)
  126. lastSearchText = text
  127. }
  128. }
  129. }
  130. // Handle Enter key - triggers onAccepted
  131. Keys.onReturnPressed: {
  132. // onAccepted will be called automatically
  133. // Just hide keyboard and unfocus
  134. Qt.inputMethod.hide()
  135. focus = false
  136. }
  137. Keys.onEscapePressed: {
  138. // Clear search and hide keyboard
  139. text = ""
  140. lastSearchText = ""
  141. patternModel.filter("")
  142. Qt.inputMethod.hide()
  143. focus = false
  144. }
  145. }
  146. Text {
  147. text: searchExpanded || searchField.text.length > 0 ? "Search" : ""
  148. font.pixelSize: 12
  149. color: Components.ThemeManager.textTertiary
  150. visible: !searchExpanded && searchField.text.length === 0
  151. }
  152. }
  153. MouseArea {
  154. anchors.fill: parent
  155. enabled: !searchExpanded
  156. onClicked: {
  157. searchExpanded = true
  158. searchField.forceActiveFocus()
  159. Qt.inputMethod.show()
  160. }
  161. }
  162. }
  163. // Close button when expanded
  164. Button {
  165. text: "✕"
  166. font.pixelSize: 18
  167. flat: true
  168. visible: searchExpanded
  169. Layout.preferredWidth: 32
  170. Layout.preferredHeight: 32
  171. onClicked: {
  172. searchExpanded = false
  173. searchField.text = ""
  174. searchField.lastSearchText = ""
  175. searchField.focus = false
  176. // Clear the filter when closing search
  177. patternModel.filter("")
  178. }
  179. }
  180. }
  181. }
  182. // Content - Pattern Grid
  183. GridView {
  184. id: gridView
  185. Layout.fillWidth: true
  186. Layout.fillHeight: true
  187. cellWidth: 200
  188. cellHeight: 220
  189. model: patternModel
  190. clip: true
  191. // Add smooth scrolling
  192. ScrollBar.vertical: ScrollBar {
  193. active: true
  194. policy: ScrollBar.AsNeeded
  195. }
  196. delegate: ModernPatternCard {
  197. width: gridView.cellWidth - 10
  198. height: gridView.cellHeight - 10
  199. name: model.name
  200. preview: model.preview
  201. onClicked: {
  202. if (stackView && backend) {
  203. stackView.push("PatternDetailPage.qml", {
  204. patternName: model.name,
  205. patternPath: model.path,
  206. patternPreview: model.preview,
  207. backend: backend
  208. })
  209. }
  210. }
  211. }
  212. // Add scroll animations
  213. add: Transition {
  214. NumberAnimation { property: "opacity"; from: 0; to: 1; duration: 300 }
  215. NumberAnimation { property: "scale"; from: 0.8; to: 1; duration: 300 }
  216. }
  217. }
  218. // Empty state
  219. Item {
  220. Layout.fillWidth: true
  221. Layout.fillHeight: true
  222. visible: patternModel.rowCount() === 0 && searchField.text !== ""
  223. Column {
  224. anchors.centerIn: parent
  225. spacing: 20
  226. Text {
  227. text: "⌕"
  228. font.pixelSize: 48
  229. anchors.horizontalCenter: parent.horizontalCenter
  230. color: Components.ThemeManager.placeholderText
  231. }
  232. Label {
  233. text: "No patterns found"
  234. anchors.horizontalCenter: parent.horizontalCenter
  235. color: Components.ThemeManager.textSecondary
  236. font.pixelSize: 18
  237. }
  238. Label {
  239. text: "Try a different search term"
  240. anchors.horizontalCenter: parent.horizontalCenter
  241. color: Components.ThemeManager.textTertiary
  242. font.pixelSize: 14
  243. }
  244. }
  245. }
  246. }
  247. }