TableControlPage.qml 28 KB

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