TableControlPage.qml 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644
  1. import QtQuick 2.15
  2. import QtQuick.Controls 2.15
  3. import QtQuick.Layouts 1.15
  4. // import QtQuick.Effects // Disabled - causes issues on linuxfb
  5. import "../components"
  6. import "../components" as Components
  7. Page {
  8. id: page
  9. property var backend: null
  10. property var serialPorts: []
  11. property string selectedPort: ""
  12. property bool isSerialConnected: false
  13. property bool autoPlayOnBoot: false
  14. // Backend signal connections
  15. Connections {
  16. target: backend
  17. function onSerialPortsUpdated(ports) {
  18. console.log("Serial ports updated:", ports)
  19. serialPorts = ports
  20. }
  21. function onSerialConnectionChanged(connected) {
  22. console.log("Serial connection changed:", connected)
  23. isSerialConnected = connected
  24. }
  25. function onCurrentPortChanged(port) {
  26. console.log("Current port changed:", port)
  27. if (port) {
  28. selectedPort = port
  29. }
  30. }
  31. function onSettingsLoaded() {
  32. console.log("Settings loaded")
  33. if (backend) {
  34. autoPlayOnBoot = backend.autoPlayOnBoot
  35. isSerialConnected = backend.serialConnected
  36. // Screen timeout is now managed by button selection, no need to convert
  37. if (backend.currentPort) {
  38. selectedPort = backend.currentPort
  39. }
  40. }
  41. }
  42. }
  43. // Refresh serial ports on page load
  44. Component.onCompleted: {
  45. refreshSerialPorts()
  46. loadSettings()
  47. }
  48. function refreshSerialPorts() {
  49. if (backend) {
  50. backend.refreshSerialPorts()
  51. }
  52. }
  53. function loadSettings() {
  54. if (backend) {
  55. backend.loadControlSettings()
  56. }
  57. }
  58. Rectangle {
  59. anchors.fill: parent
  60. color: Components.ThemeManager.backgroundColor
  61. }
  62. ColumnLayout {
  63. anchors.fill: parent
  64. spacing: 0
  65. // Header
  66. Rectangle {
  67. Layout.fillWidth: true
  68. Layout.preferredHeight: 50
  69. color: Components.ThemeManager.surfaceColor
  70. Rectangle {
  71. anchors.bottom: parent.bottom
  72. width: parent.width
  73. height: 1
  74. color: Components.ThemeManager.borderColor
  75. }
  76. RowLayout {
  77. anchors.fill: parent
  78. anchors.leftMargin: 15
  79. anchors.rightMargin: 10
  80. ConnectionStatus {
  81. backend: page.backend
  82. Layout.rightMargin: 8
  83. }
  84. Label {
  85. text: "Table Control"
  86. font.pixelSize: 18
  87. font.bold: true
  88. color: Components.ThemeManager.textPrimary
  89. }
  90. Item {
  91. Layout.fillWidth: true
  92. }
  93. }
  94. }
  95. // Main Content
  96. ScrollView {
  97. Layout.fillWidth: true
  98. Layout.fillHeight: true
  99. contentWidth: availableWidth
  100. ColumnLayout {
  101. width: parent.width
  102. anchors.margins: 5
  103. spacing: 2
  104. // Serial Connection Section
  105. Rectangle {
  106. Layout.fillWidth: true
  107. Layout.preferredHeight: 160
  108. Layout.margins: 5
  109. radius: 8
  110. color: Components.ThemeManager.surfaceColor
  111. ColumnLayout {
  112. anchors.fill: parent
  113. anchors.margins: 15
  114. spacing: 10
  115. Label {
  116. text: "Serial Connection"
  117. font.pixelSize: 14
  118. font.bold: true
  119. color: Components.ThemeManager.textPrimary
  120. }
  121. RowLayout {
  122. Layout.fillWidth: true
  123. spacing: 10
  124. Rectangle {
  125. Layout.fillWidth: true
  126. Layout.preferredHeight: 40
  127. radius: 6
  128. color: isSerialConnected ? (Components.ThemeManager.darkMode ? "#1b4332" : "#e8f5e8") : Components.ThemeManager.cardColor
  129. border.color: isSerialConnected ? "#4CAF50" : Components.ThemeManager.borderColor
  130. border.width: 1
  131. RowLayout {
  132. anchors.fill: parent
  133. anchors.margins: 8
  134. Label {
  135. text: isSerialConnected ?
  136. (selectedPort ? `Connected: ${selectedPort}` : "Connected") :
  137. (selectedPort || "No port selected")
  138. color: isSerialConnected ? "#4CAF50" : (selectedPort ? Components.ThemeManager.textPrimary : Components.ThemeManager.textTertiary)
  139. font.pixelSize: 12
  140. font.bold: isSerialConnected
  141. Layout.fillWidth: true
  142. }
  143. Text {
  144. text: "▼"
  145. color: Components.ThemeManager.textSecondary
  146. font.pixelSize: 10
  147. visible: !isSerialConnected
  148. }
  149. }
  150. MouseArea {
  151. anchors.fill: parent
  152. enabled: !isSerialConnected
  153. onClicked: portMenu.open()
  154. }
  155. Menu {
  156. id: portMenu
  157. y: parent.height
  158. // Note: Menu rotation for Pi 5 handled differently
  159. // transform property not well supported on Menu
  160. Repeater {
  161. model: serialPorts
  162. MenuItem {
  163. text: modelData
  164. onTriggered: {
  165. selectedPort = modelData
  166. }
  167. }
  168. }
  169. MenuSeparator {}
  170. MenuItem {
  171. text: "Refresh Ports"
  172. onTriggered: refreshSerialPorts()
  173. }
  174. }
  175. }
  176. ModernControlButton {
  177. Layout.preferredWidth: 150
  178. Layout.preferredHeight: 40
  179. text: isSerialConnected ? "Disconnect" : "Connect"
  180. icon: isSerialConnected ? "◉" : "○"
  181. buttonColor: isSerialConnected ? "#dc2626" : "#059669"
  182. fontSize: 11
  183. enabled: isSerialConnected || selectedPort !== ""
  184. onClicked: {
  185. if (backend) {
  186. if (isSerialConnected) {
  187. backend.disconnectSerial()
  188. } else {
  189. backend.connectSerial(selectedPort)
  190. }
  191. }
  192. }
  193. }
  194. }
  195. RowLayout {
  196. Layout.fillWidth: true
  197. spacing: 8
  198. visible: !isSerialConnected
  199. ModernControlButton {
  200. Layout.fillWidth: true
  201. Layout.preferredHeight: 35
  202. text: "Refresh Ports"
  203. icon: "↻"
  204. buttonColor: "#6b7280"
  205. fontSize: 10
  206. onClicked: refreshSerialPorts()
  207. }
  208. }
  209. }
  210. }
  211. // Hardware Movement Section
  212. Rectangle {
  213. Layout.fillWidth: true
  214. Layout.preferredHeight: 100
  215. Layout.margins: 5
  216. radius: 8
  217. color: Components.ThemeManager.surfaceColor
  218. ColumnLayout {
  219. anchors.fill: parent
  220. anchors.margins: 15
  221. spacing: 10
  222. Label {
  223. text: "Table Movement"
  224. font.pixelSize: 14
  225. font.bold: true
  226. color: Components.ThemeManager.textPrimary
  227. }
  228. GridLayout {
  229. Layout.fillWidth: true
  230. columns: 3
  231. rowSpacing: 8
  232. columnSpacing: 8
  233. ModernControlButton {
  234. Layout.fillWidth: true
  235. Layout.preferredHeight: 45
  236. text: "Home"
  237. icon: "⌂"
  238. buttonColor: "#2563eb"
  239. fontSize: 12
  240. enabled: isSerialConnected
  241. onClicked: {
  242. if (backend) backend.sendHome()
  243. }
  244. }
  245. ModernControlButton {
  246. Layout.fillWidth: true
  247. Layout.preferredHeight: 45
  248. text: "Center"
  249. icon: "◎"
  250. buttonColor: "#2563eb"
  251. fontSize: 12
  252. enabled: isSerialConnected
  253. onClicked: {
  254. if (backend) backend.moveToCenter()
  255. }
  256. }
  257. ModernControlButton {
  258. Layout.fillWidth: true
  259. Layout.preferredHeight: 45
  260. text: "Perimeter"
  261. icon: "○"
  262. buttonColor: "#2563eb"
  263. fontSize: 12
  264. enabled: isSerialConnected
  265. onClicked: {
  266. if (backend) backend.moveToPerimeter()
  267. }
  268. }
  269. }
  270. }
  271. }
  272. // Auto Play on Boot Section
  273. Rectangle {
  274. Layout.fillWidth: true
  275. Layout.preferredHeight: 200 // Reduced from 280 for single row layout
  276. Layout.margins: 5
  277. radius: 8
  278. color: Components.ThemeManager.surfaceColor
  279. ColumnLayout {
  280. anchors.fill: parent
  281. anchors.margins: 15
  282. spacing: 10
  283. Label {
  284. text: "Auto Play Settings"
  285. font.pixelSize: 14
  286. font.bold: true
  287. color: Components.ThemeManager.textPrimary
  288. }
  289. RowLayout {
  290. Layout.fillWidth: true
  291. spacing: 10
  292. Label {
  293. text: "Auto play on boot:"
  294. font.pixelSize: 12
  295. color: Components.ThemeManager.textSecondary
  296. Layout.fillWidth: true
  297. }
  298. Switch {
  299. id: autoPlaySwitch
  300. checked: autoPlayOnBoot
  301. onToggled: {
  302. autoPlayOnBoot = checked
  303. if (backend) {
  304. backend.setAutoPlayOnBoot(checked)
  305. }
  306. }
  307. }
  308. }
  309. ColumnLayout {
  310. Layout.fillWidth: true
  311. spacing: 15
  312. Label {
  313. text: "Screen timeout:"
  314. font.pixelSize: 14
  315. font.bold: true
  316. color: Components.ThemeManager.textPrimary
  317. Layout.alignment: Qt.AlignLeft
  318. }
  319. // Touch-friendly button row for timeout options
  320. RowLayout {
  321. id: timeoutGrid
  322. Layout.fillWidth: true
  323. spacing: 8
  324. property string currentSelection: backend ? backend.getCurrentScreenTimeoutOption() : "5 minutes"
  325. // 30 seconds button
  326. Rectangle {
  327. Layout.preferredWidth: 100
  328. Layout.preferredHeight: 50
  329. color: timeoutGrid.currentSelection === "30 seconds" ? Components.ThemeManager.selectedBackground : Components.ThemeManager.buttonBackground
  330. border.color: timeoutGrid.currentSelection === "30 seconds" ? Components.ThemeManager.selectedBorder : Components.ThemeManager.buttonBorder
  331. border.width: 2
  332. radius: 8
  333. Label {
  334. anchors.centerIn: parent
  335. text: "30s"
  336. font.pixelSize: 14
  337. font.bold: true
  338. color: timeoutGrid.currentSelection === "30 seconds" ? "white" : Components.ThemeManager.textPrimary
  339. }
  340. MouseArea {
  341. anchors.fill: parent
  342. onClicked: {
  343. if (backend) {
  344. backend.setScreenTimeoutByOption("30 seconds")
  345. timeoutGrid.currentSelection = "30 seconds"
  346. }
  347. }
  348. }
  349. }
  350. // 1 minute button
  351. Rectangle {
  352. Layout.preferredWidth: 100
  353. Layout.preferredHeight: 50
  354. color: timeoutGrid.currentSelection === "1 minute" ? Components.ThemeManager.selectedBackground : Components.ThemeManager.buttonBackground
  355. border.color: timeoutGrid.currentSelection === "1 minute" ? Components.ThemeManager.selectedBorder : Components.ThemeManager.buttonBorder
  356. border.width: 2
  357. radius: 8
  358. Label {
  359. anchors.centerIn: parent
  360. text: "1min"
  361. font.pixelSize: 14
  362. font.bold: true
  363. color: timeoutGrid.currentSelection === "1 minute" ? "white" : Components.ThemeManager.textPrimary
  364. }
  365. MouseArea {
  366. anchors.fill: parent
  367. onClicked: {
  368. if (backend) {
  369. backend.setScreenTimeoutByOption("1 minute")
  370. timeoutGrid.currentSelection = "1 minute"
  371. }
  372. }
  373. }
  374. }
  375. // 5 minutes button
  376. Rectangle {
  377. Layout.preferredWidth: 100
  378. Layout.preferredHeight: 50
  379. color: timeoutGrid.currentSelection === "5 minutes" ? Components.ThemeManager.selectedBackground : Components.ThemeManager.buttonBackground
  380. border.color: timeoutGrid.currentSelection === "5 minutes" ? Components.ThemeManager.selectedBorder : Components.ThemeManager.buttonBorder
  381. border.width: 2
  382. radius: 8
  383. Label {
  384. anchors.centerIn: parent
  385. text: "5min"
  386. font.pixelSize: 14
  387. font.bold: true
  388. color: timeoutGrid.currentSelection === "5 minutes" ? "white" : Components.ThemeManager.textPrimary
  389. }
  390. MouseArea {
  391. anchors.fill: parent
  392. onClicked: {
  393. if (backend) {
  394. backend.setScreenTimeoutByOption("5 minutes")
  395. timeoutGrid.currentSelection = "5 minutes"
  396. }
  397. }
  398. }
  399. }
  400. // 10 minutes button
  401. Rectangle {
  402. Layout.preferredWidth: 100
  403. Layout.preferredHeight: 50
  404. color: timeoutGrid.currentSelection === "10 minutes" ? Components.ThemeManager.selectedBackground : Components.ThemeManager.buttonBackground
  405. border.color: timeoutGrid.currentSelection === "10 minutes" ? Components.ThemeManager.selectedBorder : Components.ThemeManager.buttonBorder
  406. border.width: 2
  407. radius: 8
  408. Label {
  409. anchors.centerIn: parent
  410. text: "10min"
  411. font.pixelSize: 14
  412. font.bold: true
  413. color: timeoutGrid.currentSelection === "10 minutes" ? "white" : Components.ThemeManager.textPrimary
  414. }
  415. MouseArea {
  416. anchors.fill: parent
  417. onClicked: {
  418. if (backend) {
  419. backend.setScreenTimeoutByOption("10 minutes")
  420. timeoutGrid.currentSelection = "10 minutes"
  421. }
  422. }
  423. }
  424. }
  425. // Never button
  426. Rectangle {
  427. Layout.preferredWidth: 100
  428. Layout.preferredHeight: 50
  429. color: timeoutGrid.currentSelection === "Never" ? "#FF9800" : "#f0f0f0"
  430. border.color: timeoutGrid.currentSelection === "Never" ? "#F57C00" : "#ccc"
  431. border.width: 2
  432. radius: 8
  433. Label {
  434. anchors.centerIn: parent
  435. text: "Never"
  436. font.pixelSize: 14
  437. font.bold: true
  438. color: timeoutGrid.currentSelection === "Never" ? "white" : "#333"
  439. }
  440. MouseArea {
  441. anchors.fill: parent
  442. onClicked: {
  443. if (backend) {
  444. backend.setScreenTimeoutByOption("Never")
  445. timeoutGrid.currentSelection = "Never"
  446. }
  447. }
  448. }
  449. }
  450. // Update selection when backend changes
  451. Connections {
  452. target: backend
  453. function onScreenTimeoutChanged() {
  454. if (backend) {
  455. timeoutGrid.currentSelection = backend.getCurrentScreenTimeoutOption()
  456. }
  457. }
  458. }
  459. }
  460. }
  461. }
  462. }
  463. // Theme Settings Section
  464. Rectangle {
  465. Layout.fillWidth: true
  466. Layout.preferredHeight: 100
  467. Layout.margins: 5
  468. radius: 8
  469. color: Components.ThemeManager.surfaceColor
  470. ColumnLayout {
  471. anchors.fill: parent
  472. anchors.margins: 15
  473. spacing: 10
  474. Label {
  475. text: "Appearance"
  476. font.pixelSize: 14
  477. font.bold: true
  478. color: Components.ThemeManager.textPrimary
  479. }
  480. RowLayout {
  481. Layout.fillWidth: true
  482. spacing: 10
  483. Label {
  484. text: "Dark mode:"
  485. font.pixelSize: 12
  486. color: Components.ThemeManager.textSecondary
  487. Layout.fillWidth: true
  488. }
  489. Switch {
  490. id: darkModeSwitch
  491. checked: Components.ThemeManager.darkMode
  492. onToggled: {
  493. Components.ThemeManager.darkMode = checked
  494. }
  495. }
  496. }
  497. }
  498. }
  499. // System Controls Section
  500. Rectangle {
  501. Layout.fillWidth: true
  502. Layout.preferredHeight: 100
  503. Layout.margins: 5
  504. radius: 8
  505. color: Components.ThemeManager.surfaceColor
  506. ColumnLayout {
  507. anchors.fill: parent
  508. anchors.margins: 15
  509. spacing: 10
  510. Label {
  511. text: "System Controls"
  512. font.pixelSize: 14
  513. font.bold: true
  514. color: Components.ThemeManager.textPrimary
  515. }
  516. RowLayout {
  517. Layout.fillWidth: true
  518. spacing: 8
  519. ModernControlButton {
  520. Layout.fillWidth: true
  521. Layout.preferredHeight: 45
  522. text: "Restart Backend"
  523. icon: "↻"
  524. buttonColor: "#f59e0b"
  525. fontSize: 11
  526. onClicked: {
  527. if (backend) backend.restartBackend()
  528. }
  529. }
  530. ModernControlButton {
  531. Layout.fillWidth: true
  532. Layout.preferredHeight: 45
  533. text: "Shutdown Pi"
  534. icon: "⏻"
  535. buttonColor: "#dc2626"
  536. fontSize: 11
  537. onClicked: {
  538. if (backend) backend.shutdownPi()
  539. }
  540. }
  541. }
  542. }
  543. }
  544. // Add some bottom spacing for better scrolling
  545. Item {
  546. Layout.preferredHeight: 20
  547. }
  548. }
  549. }
  550. }
  551. }