1
0

ModernPatternListPage.qml 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  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. color: Components.ThemeManager.textPrimary
  87. visible: searchExpanded || text.length > 0
  88. property string lastSearchText: ""
  89. property bool hasUnappliedSearch: text !== lastSearchText && text.length > 0
  90. background: Rectangle {
  91. color: "transparent"
  92. border.color: searchField.hasUnappliedSearch ? "#f59e0b" : "transparent"
  93. border.width: searchField.hasUnappliedSearch ? 1 : 0
  94. radius: 4
  95. }
  96. // Remove automatic filtering on text change
  97. // onTextChanged: patternModel.filter(text)
  98. // Only filter when user presses Enter or field loses focus
  99. onAccepted: {
  100. patternModel.filter(text)
  101. lastSearchText = text
  102. Qt.inputMethod.hide()
  103. focus = false
  104. }
  105. // Enable virtual keyboard
  106. activeFocusOnPress: true
  107. selectByMouse: true
  108. inputMethodHints: Qt.ImhNoPredictiveText
  109. // Direct MouseArea for touch events
  110. MouseArea {
  111. anchors.fill: parent
  112. onPressed: {
  113. searchField.forceActiveFocus()
  114. Qt.inputMethod.show()
  115. mouse.accepted = false // Pass through to TextField
  116. }
  117. }
  118. onActiveFocusChanged: {
  119. if (activeFocus) {
  120. searchExpanded = true
  121. // Force virtual keyboard to show
  122. Qt.inputMethod.show()
  123. } else {
  124. // Apply search when focus is lost
  125. if (text !== lastSearchText) {
  126. patternModel.filter(text)
  127. lastSearchText = text
  128. }
  129. }
  130. }
  131. // Handle Enter key - triggers onAccepted
  132. Keys.onReturnPressed: {
  133. // onAccepted will be called automatically
  134. // Just hide keyboard and unfocus
  135. Qt.inputMethod.hide()
  136. focus = false
  137. }
  138. Keys.onEscapePressed: {
  139. // Clear search and hide keyboard
  140. text = ""
  141. lastSearchText = ""
  142. patternModel.filter("")
  143. Qt.inputMethod.hide()
  144. focus = false
  145. }
  146. }
  147. Text {
  148. text: searchExpanded || searchField.text.length > 0 ? "Search" : ""
  149. font.pixelSize: 12
  150. color: Components.ThemeManager.textTertiary
  151. visible: !searchExpanded && searchField.text.length === 0
  152. }
  153. }
  154. MouseArea {
  155. anchors.fill: parent
  156. enabled: !searchExpanded
  157. onClicked: {
  158. searchExpanded = true
  159. searchField.forceActiveFocus()
  160. Qt.inputMethod.show()
  161. }
  162. }
  163. }
  164. // Close button when expanded
  165. Button {
  166. text: "✕"
  167. font.pixelSize: 18
  168. flat: true
  169. visible: searchExpanded
  170. Layout.preferredWidth: 32
  171. Layout.preferredHeight: 32
  172. onClicked: {
  173. searchExpanded = false
  174. searchField.text = ""
  175. searchField.lastSearchText = ""
  176. searchField.focus = false
  177. // Clear the filter when closing search
  178. patternModel.filter("")
  179. }
  180. }
  181. }
  182. }
  183. // Content - Pattern Grid
  184. GridView {
  185. id: gridView
  186. Layout.fillWidth: true
  187. Layout.fillHeight: true
  188. cellWidth: 200
  189. cellHeight: 220
  190. model: patternModel
  191. clip: true
  192. // Add smooth scrolling
  193. ScrollBar.vertical: ScrollBar {
  194. active: true
  195. policy: ScrollBar.AsNeeded
  196. }
  197. delegate: ModernPatternCard {
  198. width: gridView.cellWidth - 10
  199. height: gridView.cellHeight - 10
  200. name: model.name
  201. preview: model.preview
  202. onClicked: {
  203. if (stackView && backend) {
  204. stackView.push("PatternDetailPage.qml", {
  205. patternName: model.name,
  206. patternPath: model.path,
  207. patternPreview: model.preview,
  208. backend: backend
  209. })
  210. }
  211. }
  212. }
  213. // Add scroll animations
  214. add: Transition {
  215. NumberAnimation { property: "opacity"; from: 0; to: 1; duration: 300 }
  216. NumberAnimation { property: "scale"; from: 0.8; to: 1; duration: 300 }
  217. }
  218. }
  219. // Empty state
  220. Item {
  221. Layout.fillWidth: true
  222. Layout.fillHeight: true
  223. visible: patternModel.rowCount() === 0 && searchField.text !== ""
  224. Column {
  225. anchors.centerIn: parent
  226. spacing: 20
  227. Text {
  228. text: "⌕"
  229. font.pixelSize: 48
  230. anchors.horizontalCenter: parent.horizontalCenter
  231. color: Components.ThemeManager.placeholderText
  232. }
  233. Label {
  234. text: "No patterns found"
  235. anchors.horizontalCenter: parent.horizontalCenter
  236. color: Components.ThemeManager.textSecondary
  237. font.pixelSize: 18
  238. }
  239. Label {
  240. text: "Try a different search term"
  241. anchors.horizontalCenter: parent.horizontalCenter
  242. color: Components.ThemeManager.textTertiary
  243. font.pixelSize: 14
  244. }
  245. }
  246. }
  247. }
  248. }