main.qml 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  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. // Rotation container for Pi 5 linuxfb
  91. Item {
  92. id: rotationContainer
  93. anchors.fill: parent
  94. rotation: typeof rotateDisplay !== 'undefined' && rotateDisplay ? 180 : 0
  95. transformOrigin: Item.Center
  96. StackView {
  97. id: stackView
  98. anchors.fill: parent
  99. initialItem: backend.backendConnected ? mainSwipeView : connectionSplash
  100. Component {
  101. id: connectionSplash
  102. ConnectionSplash {
  103. statusText: backend.reconnectStatus
  104. showRetryButton: backend.reconnectStatus === "Cannot connect to backend"
  105. onRetryConnection: {
  106. console.log("🔄 Manual retry requested")
  107. backend.retryConnection()
  108. }
  109. }
  110. }
  111. Component {
  112. id: mainSwipeView
  113. Item {
  114. // Main content area
  115. StackLayout {
  116. id: stackLayout
  117. anchors.top: parent.top
  118. anchors.left: parent.left
  119. anchors.right: parent.right
  120. anchors.bottom: bottomNav.top
  121. currentIndex: window.currentPageIndex
  122. Component.onCompleted: {
  123. console.log("📱 StackLayout created with currentIndex:", currentIndex, "bound to window.currentPageIndex:", window.currentPageIndex)
  124. }
  125. // Patterns Page
  126. Loader {
  127. source: "pages/ModernPatternListPage.qml"
  128. onLoaded: {
  129. item.patternModel = patternModel
  130. item.backend = backend
  131. item.stackView = stackView
  132. }
  133. }
  134. // Playlists Page
  135. Loader {
  136. source: "pages/ModernPlaylistPage.qml"
  137. onLoaded: {
  138. item.backend = backend
  139. item.stackView = stackView
  140. item.mainWindow = window
  141. }
  142. }
  143. // Control Page
  144. Loader {
  145. source: "pages/TableControlPage.qml"
  146. onLoaded: {
  147. item.backend = backend
  148. }
  149. }
  150. // LED Control Page (index 3)
  151. Loader {
  152. source: "pages/LedControlPage.qml"
  153. onLoaded: {
  154. item.backend = backend
  155. }
  156. }
  157. // Execution Page (index 4)
  158. Loader {
  159. source: "pages/ExecutionPage.qml"
  160. onLoaded: {
  161. item.backend = backend
  162. item.stackView = stackView
  163. item.patternName = Qt.binding(function() { return window.currentPatternName })
  164. item.patternPreview = Qt.binding(function() { return window.currentPatternPreview })
  165. }
  166. }
  167. }
  168. // Bottom Navigation
  169. BottomNavigation {
  170. id: bottomNav
  171. anchors.bottom: parent.bottom
  172. anchors.left: parent.left
  173. anchors.right: parent.right
  174. currentIndex: window.currentPageIndex
  175. onTabClicked: function(index) {
  176. console.log("📱 Tab clicked:", index)
  177. window.currentPageIndex = index
  178. }
  179. }
  180. }
  181. }
  182. }
  183. } // End rotationContainer
  184. // Virtual Keyboard Support - outside rotation container for proper positioning
  185. InputPanel {
  186. id: inputPanel
  187. z: 99999
  188. y: window.height
  189. anchors.left: parent.left
  190. anchors.right: parent.right
  191. // Rotate keyboard for Pi 5
  192. rotation: typeof rotateDisplay !== 'undefined' && rotateDisplay ? 180 : 0
  193. transformOrigin: Item.Center
  194. states: State {
  195. name: "visible"
  196. when: inputPanel.active
  197. PropertyChanges {
  198. target: inputPanel
  199. y: typeof rotateDisplay !== 'undefined' && rotateDisplay ? 0 : window.height - inputPanel.height
  200. }
  201. }
  202. transitions: Transition {
  203. from: ""
  204. to: "visible"
  205. reversible: true
  206. ParallelAnimation {
  207. NumberAnimation {
  208. target: inputPanel
  209. property: "y"
  210. duration: 250
  211. easing.type: Easing.InOutQuad
  212. }
  213. }
  214. }
  215. }
  216. MessageDialog {
  217. id: errorDialog
  218. title: "Error"
  219. buttons: MessageDialog.Ok
  220. }
  221. }