main.qml 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  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
  33. console.log("🎯 Setting currentPageIndex to 3")
  34. currentPageIndex = 3
  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. // Execution Page
  145. Loader {
  146. source: "pages/ExecutionPage.qml"
  147. onLoaded: {
  148. item.backend = backend
  149. item.stackView = stackView
  150. item.patternName = Qt.binding(function() { return window.currentPatternName })
  151. item.patternPreview = Qt.binding(function() { return window.currentPatternPreview })
  152. }
  153. }
  154. }
  155. // Bottom Navigation
  156. BottomNavigation {
  157. id: bottomNav
  158. anchors.bottom: parent.bottom
  159. anchors.left: parent.left
  160. anchors.right: parent.right
  161. currentIndex: window.currentPageIndex
  162. onTabClicked: function(index) {
  163. console.log("📱 Tab clicked:", index)
  164. window.currentPageIndex = index
  165. }
  166. }
  167. }
  168. }
  169. }
  170. MessageDialog {
  171. id: errorDialog
  172. title: "Error"
  173. buttons: MessageDialog.Ok
  174. }
  175. // Virtual Keyboard Support
  176. InputPanel {
  177. id: inputPanel
  178. z: 99999
  179. y: window.height
  180. anchors.left: parent.left
  181. anchors.right: parent.right
  182. states: State {
  183. name: "visible"
  184. when: inputPanel.active
  185. PropertyChanges {
  186. target: inputPanel
  187. y: window.height - inputPanel.height
  188. }
  189. }
  190. transitions: Transition {
  191. from: ""
  192. to: "visible"
  193. reversible: true
  194. ParallelAnimation {
  195. NumberAnimation {
  196. target: inputPanel
  197. property: "y"
  198. duration: 250
  199. easing.type: Easing.InOutQuad
  200. }
  201. }
  202. }
  203. }
  204. }