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