main.qml 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. import QtQuick 2.15
  2. import QtQuick.Controls 2.15
  3. import QtQuick.Layouts 1.15
  4. import QtQuick.Dialogs
  5. import QtQuick.VirtualKeyboard 2.15
  6. import DuneWeaver 1.0
  7. import "components"
  8. ApplicationWindow {
  9. id: window
  10. visible: true
  11. width: 800
  12. height: 480
  13. title: "Dune Weaver Touch"
  14. property int currentPageIndex: 0
  15. property alias stackView: stackView
  16. property alias backend: backend
  17. property bool shouldNavigateToExecution: false
  18. property string currentPatternName: ""
  19. property string currentPatternPreview: ""
  20. onCurrentPageIndexChanged: {
  21. console.log("📱 currentPageIndex changed to:", currentPageIndex)
  22. }
  23. onShouldNavigateToExecutionChanged: {
  24. if (shouldNavigateToExecution) {
  25. console.log("🎯 Navigating to execution page")
  26. console.log("🎯 Current stack depth:", stackView.depth)
  27. // If we're in a sub-page (like PatternDetailPage), pop back to main view first
  28. if (stackView.depth > 1) {
  29. console.log("🎯 Popping back to main view first")
  30. stackView.pop()
  31. }
  32. // Then navigate to ExecutionPage tab (index 4)
  33. console.log("🎯 Setting currentPageIndex to 4")
  34. currentPageIndex = 4
  35. shouldNavigateToExecution = false
  36. }
  37. }
  38. Backend {
  39. id: backend
  40. onExecutionStarted: function(patternName, patternPreview) {
  41. console.log("🎯 QML: ExecutionStarted signal received! patternName='" + patternName + "', preview='" + patternPreview + "'")
  42. console.log("🎯 Setting shouldNavigateToExecution = true")
  43. // Store pattern info for ExecutionPage
  44. window.currentPatternName = patternName
  45. window.currentPatternPreview = patternPreview
  46. // Navigate to Execution tab (index 3) instead of pushing page
  47. shouldNavigateToExecution = true
  48. console.log("🎯 shouldNavigateToExecution set to:", shouldNavigateToExecution)
  49. }
  50. onErrorOccurred: function(error) {
  51. errorDialog.text = error
  52. errorDialog.open()
  53. }
  54. onScreenStateChanged: function(isOn) {
  55. console.log("🖥️ Screen state changed:", isOn ? "ON" : "OFF")
  56. }
  57. onBackendConnectionChanged: function(connected) {
  58. console.log("🔗 Backend connection changed:", connected)
  59. if (connected && stackView.currentItem.toString().indexOf("ConnectionSplash") !== -1) {
  60. console.log("✅ Backend connected, switching to main view")
  61. stackView.replace(mainSwipeView)
  62. } else if (!connected && stackView.currentItem.toString().indexOf("ConnectionSplash") === -1) {
  63. console.log("❌ Backend disconnected, switching to splash screen")
  64. stackView.replace(connectionSplash)
  65. }
  66. }
  67. }
  68. // Global touch/mouse handler for activity tracking
  69. MouseArea {
  70. anchors.fill: parent
  71. acceptedButtons: Qt.NoButton // Don't interfere with other mouse areas
  72. hoverEnabled: true
  73. propagateComposedEvents: true
  74. onPressed: {
  75. console.log("🖥️ QML: Touch/press detected - resetting activity timer")
  76. backend.resetActivityTimer()
  77. }
  78. onPositionChanged: {
  79. console.log("🖥️ QML: Mouse movement detected - resetting activity timer")
  80. backend.resetActivityTimer()
  81. }
  82. onClicked: {
  83. console.log("🖥️ QML: Click detected - resetting activity timer")
  84. backend.resetActivityTimer()
  85. }
  86. }
  87. PatternModel {
  88. id: patternModel
  89. }
  90. StackView {
  91. id: stackView
  92. anchors.fill: parent
  93. initialItem: backend.backendConnected ? mainSwipeView : connectionSplash
  94. Component {
  95. id: connectionSplash
  96. ConnectionSplash {
  97. statusText: backend.reconnectStatus
  98. showRetryButton: backend.reconnectStatus === "Cannot connect to backend"
  99. onRetryConnection: {
  100. console.log("🔄 Manual retry requested")
  101. backend.retryConnection()
  102. }
  103. }
  104. }
  105. Component {
  106. id: mainSwipeView
  107. Item {
  108. // Main content area
  109. StackLayout {
  110. id: stackLayout
  111. anchors.top: parent.top
  112. anchors.left: parent.left
  113. anchors.right: parent.right
  114. anchors.bottom: bottomNav.top
  115. currentIndex: window.currentPageIndex
  116. Component.onCompleted: {
  117. console.log("📱 StackLayout created with currentIndex:", currentIndex, "bound to window.currentPageIndex:", window.currentPageIndex)
  118. }
  119. // Patterns Page
  120. Loader {
  121. source: "pages/ModernPatternListPage.qml"
  122. onLoaded: {
  123. item.patternModel = patternModel
  124. item.backend = backend
  125. item.stackView = stackView
  126. }
  127. }
  128. // Playlists Page
  129. Loader {
  130. source: "pages/ModernPlaylistPage.qml"
  131. onLoaded: {
  132. item.backend = backend
  133. item.stackView = stackView
  134. item.mainWindow = window
  135. }
  136. }
  137. // Control Page
  138. Loader {
  139. source: "pages/TableControlPage.qml"
  140. onLoaded: {
  141. item.backend = backend
  142. }
  143. }
  144. // LED Control Page (index 3)
  145. Loader {
  146. source: "pages/LedControlPage.qml"
  147. onLoaded: {
  148. item.backend = backend
  149. }
  150. }
  151. // Execution Page (index 4)
  152. Loader {
  153. source: "pages/ExecutionPage.qml"
  154. onLoaded: {
  155. item.backend = backend
  156. item.stackView = stackView
  157. item.patternName = Qt.binding(function() { return window.currentPatternName })
  158. item.patternPreview = Qt.binding(function() { return window.currentPatternPreview })
  159. }
  160. }
  161. }
  162. // Bottom Navigation
  163. BottomNavigation {
  164. id: bottomNav
  165. anchors.bottom: parent.bottom
  166. anchors.left: parent.left
  167. anchors.right: parent.right
  168. currentIndex: window.currentPageIndex
  169. onTabClicked: function(index) {
  170. console.log("📱 Tab clicked:", index)
  171. window.currentPageIndex = index
  172. }
  173. }
  174. }
  175. }
  176. }
  177. // Virtual Keyboard Support
  178. InputPanel {
  179. id: inputPanel
  180. z: 99999
  181. y: window.height
  182. anchors.left: parent.left
  183. anchors.right: parent.right
  184. states: State {
  185. name: "visible"
  186. when: inputPanel.active
  187. PropertyChanges {
  188. target: inputPanel
  189. y: window.height - inputPanel.height
  190. }
  191. }
  192. transitions: Transition {
  193. from: ""
  194. to: "visible"
  195. reversible: true
  196. ParallelAnimation {
  197. NumberAnimation {
  198. target: inputPanel
  199. property: "y"
  200. duration: 250
  201. easing.type: Easing.InOutQuad
  202. }
  203. }
  204. }
  205. }
  206. MessageDialog {
  207. id: errorDialog
  208. title: "Error"
  209. buttons: MessageDialog.Ok
  210. }
  211. }