TableControlPage.qml 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544
  1. import QtQuick 2.15
  2. import QtQuick.Controls 2.15
  3. import QtQuick.Layouts 1.15
  4. import QtQuick.Effects
  5. import "../components"
  6. Page {
  7. id: page
  8. property var backend: null
  9. property var serialPorts: []
  10. property string selectedPort: ""
  11. property bool isSerialConnected: false
  12. property bool autoPlayOnBoot: false
  13. // Backend signal connections
  14. Connections {
  15. target: backend
  16. function onSerialPortsUpdated(ports) {
  17. console.log("Serial ports updated:", ports)
  18. serialPorts = ports
  19. }
  20. function onSerialConnectionChanged(connected) {
  21. console.log("Serial connection changed:", connected)
  22. isSerialConnected = connected
  23. }
  24. function onCurrentPortChanged(port) {
  25. console.log("Current port changed:", port)
  26. if (port) {
  27. selectedPort = port
  28. }
  29. }
  30. function onSettingsLoaded() {
  31. console.log("Settings loaded")
  32. if (backend) {
  33. autoPlayOnBoot = backend.autoPlayOnBoot
  34. isSerialConnected = backend.serialConnected
  35. // Screen timeout is now managed by button selection, no need to convert
  36. if (backend.currentPort) {
  37. selectedPort = backend.currentPort
  38. }
  39. }
  40. }
  41. }
  42. // Refresh serial ports on page load
  43. Component.onCompleted: {
  44. refreshSerialPorts()
  45. loadSettings()
  46. }
  47. function refreshSerialPorts() {
  48. if (backend) {
  49. backend.refreshSerialPorts()
  50. }
  51. }
  52. function loadSettings() {
  53. if (backend) {
  54. backend.loadControlSettings()
  55. }
  56. }
  57. Rectangle {
  58. anchors.fill: parent
  59. color: "#f5f5f5"
  60. }
  61. ColumnLayout {
  62. anchors.fill: parent
  63. spacing: 0
  64. // Header
  65. Rectangle {
  66. Layout.fillWidth: true
  67. Layout.preferredHeight: 50
  68. color: "white"
  69. Rectangle {
  70. anchors.bottom: parent.bottom
  71. width: parent.width
  72. height: 1
  73. color: "#e5e7eb"
  74. }
  75. RowLayout {
  76. anchors.fill: parent
  77. anchors.leftMargin: 15
  78. anchors.rightMargin: 10
  79. ConnectionStatus {
  80. backend: page.backend
  81. Layout.rightMargin: 8
  82. }
  83. Label {
  84. text: "Table Control"
  85. font.pixelSize: 18
  86. font.bold: true
  87. color: "#333"
  88. }
  89. Item {
  90. Layout.fillWidth: true
  91. }
  92. }
  93. }
  94. // Main Content
  95. ScrollView {
  96. Layout.fillWidth: true
  97. Layout.fillHeight: true
  98. contentWidth: availableWidth
  99. ColumnLayout {
  100. width: parent.width
  101. anchors.margins: 5
  102. spacing: 2
  103. // Serial Connection Section
  104. Rectangle {
  105. Layout.fillWidth: true
  106. Layout.preferredHeight: 160
  107. Layout.margins: 5
  108. radius: 8
  109. color: "white"
  110. ColumnLayout {
  111. anchors.fill: parent
  112. anchors.margins: 15
  113. spacing: 10
  114. Label {
  115. text: "Serial Connection"
  116. font.pixelSize: 14
  117. font.bold: true
  118. color: "#333"
  119. }
  120. RowLayout {
  121. Layout.fillWidth: true
  122. spacing: 10
  123. Rectangle {
  124. Layout.fillWidth: true
  125. Layout.preferredHeight: 40
  126. radius: 6
  127. color: isSerialConnected ? "#e8f5e8" : "#f8f9fa"
  128. border.color: isSerialConnected ? "#4CAF50" : "#e5e7eb"
  129. border.width: 1
  130. RowLayout {
  131. anchors.fill: parent
  132. anchors.margins: 8
  133. Label {
  134. text: isSerialConnected ?
  135. (selectedPort ? `Connected: ${selectedPort}` : "Connected") :
  136. (selectedPort || "No port selected")
  137. color: isSerialConnected ? "#2e7d32" : (selectedPort ? "#333" : "#999")
  138. font.pixelSize: 12
  139. font.bold: isSerialConnected
  140. Layout.fillWidth: true
  141. }
  142. Text {
  143. text: "▼"
  144. color: "#666"
  145. font.pixelSize: 10
  146. visible: !isSerialConnected
  147. }
  148. }
  149. MouseArea {
  150. anchors.fill: parent
  151. enabled: !isSerialConnected
  152. onClicked: portMenu.open()
  153. }
  154. Menu {
  155. id: portMenu
  156. y: parent.height
  157. Repeater {
  158. model: serialPorts
  159. MenuItem {
  160. text: modelData
  161. onTriggered: {
  162. selectedPort = modelData
  163. }
  164. }
  165. }
  166. MenuSeparator {}
  167. MenuItem {
  168. text: "Refresh Ports"
  169. onTriggered: refreshSerialPorts()
  170. }
  171. }
  172. }
  173. ModernControlButton {
  174. Layout.preferredWidth: 150
  175. Layout.preferredHeight: 40
  176. text: isSerialConnected ? "Disconnect" : "Connect"
  177. icon: isSerialConnected ? "◉" : "○"
  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. buttonColor: "#6b7280"
  202. fontSize: 10
  203. onClicked: refreshSerialPorts()
  204. }
  205. }
  206. }
  207. }
  208. // Hardware Movement Section
  209. Rectangle {
  210. Layout.fillWidth: true
  211. Layout.preferredHeight: 100
  212. Layout.margins: 5
  213. radius: 8
  214. color: "white"
  215. ColumnLayout {
  216. anchors.fill: parent
  217. anchors.margins: 15
  218. spacing: 10
  219. Label {
  220. text: "Table Movement"
  221. font.pixelSize: 14
  222. font.bold: true
  223. color: "#333"
  224. }
  225. GridLayout {
  226. Layout.fillWidth: true
  227. columns: 3
  228. rowSpacing: 8
  229. columnSpacing: 8
  230. ModernControlButton {
  231. Layout.fillWidth: true
  232. Layout.preferredHeight: 45
  233. text: "Home"
  234. icon: "⌂"
  235. buttonColor: "#2563eb"
  236. fontSize: 12
  237. enabled: isSerialConnected
  238. onClicked: {
  239. if (backend) backend.sendHome()
  240. }
  241. }
  242. ModernControlButton {
  243. Layout.fillWidth: true
  244. Layout.preferredHeight: 45
  245. text: "Center"
  246. icon: "◎"
  247. buttonColor: "#2563eb"
  248. fontSize: 12
  249. enabled: isSerialConnected
  250. onClicked: {
  251. if (backend) backend.moveToCenter()
  252. }
  253. }
  254. ModernControlButton {
  255. Layout.fillWidth: true
  256. Layout.preferredHeight: 45
  257. text: "Perimeter"
  258. icon: "○"
  259. buttonColor: "#2563eb"
  260. fontSize: 12
  261. enabled: isSerialConnected
  262. onClicked: {
  263. if (backend) backend.moveToPerimeter()
  264. }
  265. }
  266. }
  267. }
  268. }
  269. // Auto Play on Boot Section
  270. Rectangle {
  271. Layout.fillWidth: true
  272. Layout.preferredHeight: 200 // Reduced from 280 for single row layout
  273. Layout.margins: 5
  274. radius: 8
  275. color: "white"
  276. ColumnLayout {
  277. anchors.fill: parent
  278. anchors.margins: 15
  279. spacing: 10
  280. Label {
  281. text: "Auto Play Settings"
  282. font.pixelSize: 14
  283. font.bold: true
  284. color: "#333"
  285. }
  286. RowLayout {
  287. Layout.fillWidth: true
  288. spacing: 10
  289. Label {
  290. text: "Auto play on boot:"
  291. font.pixelSize: 12
  292. color: "#666"
  293. Layout.fillWidth: true
  294. }
  295. Switch {
  296. id: autoPlaySwitch
  297. checked: autoPlayOnBoot
  298. onToggled: {
  299. autoPlayOnBoot = checked
  300. if (backend) {
  301. backend.setAutoPlayOnBoot(checked)
  302. }
  303. }
  304. }
  305. }
  306. ColumnLayout {
  307. Layout.fillWidth: true
  308. spacing: 15
  309. Label {
  310. text: "Screen timeout:"
  311. font.pixelSize: 14
  312. font.bold: true
  313. color: "#333"
  314. Layout.alignment: Qt.AlignLeft
  315. }
  316. // Touch-friendly button row for timeout options
  317. RowLayout {
  318. id: timeoutGrid
  319. Layout.fillWidth: true
  320. spacing: 8
  321. property string currentSelection: backend ? backend.getCurrentScreenTimeoutOption() : "5 minutes"
  322. // 30 seconds button
  323. Rectangle {
  324. Layout.preferredWidth: 100
  325. Layout.preferredHeight: 50
  326. color: timeoutGrid.currentSelection === "30 seconds" ? "#2196F3" : "#f0f0f0"
  327. border.color: timeoutGrid.currentSelection === "30 seconds" ? "#1976D2" : "#ccc"
  328. border.width: 2
  329. radius: 8
  330. Label {
  331. anchors.centerIn: parent
  332. text: "30s"
  333. font.pixelSize: 14
  334. font.bold: true
  335. color: timeoutGrid.currentSelection === "30 seconds" ? "white" : "#333"
  336. }
  337. MouseArea {
  338. anchors.fill: parent
  339. onClicked: {
  340. if (backend) {
  341. backend.setScreenTimeoutByOption("30 seconds")
  342. timeoutGrid.currentSelection = "30 seconds"
  343. }
  344. }
  345. }
  346. }
  347. // 1 minute button
  348. Rectangle {
  349. Layout.preferredWidth: 100
  350. Layout.preferredHeight: 50
  351. color: timeoutGrid.currentSelection === "1 minute" ? "#2196F3" : "#f0f0f0"
  352. border.color: timeoutGrid.currentSelection === "1 minute" ? "#1976D2" : "#ccc"
  353. border.width: 2
  354. radius: 8
  355. Label {
  356. anchors.centerIn: parent
  357. text: "1min"
  358. font.pixelSize: 14
  359. font.bold: true
  360. color: timeoutGrid.currentSelection === "1 minute" ? "white" : "#333"
  361. }
  362. MouseArea {
  363. anchors.fill: parent
  364. onClicked: {
  365. if (backend) {
  366. backend.setScreenTimeoutByOption("1 minute")
  367. timeoutGrid.currentSelection = "1 minute"
  368. }
  369. }
  370. }
  371. }
  372. // 5 minutes button
  373. Rectangle {
  374. Layout.preferredWidth: 100
  375. Layout.preferredHeight: 50
  376. color: timeoutGrid.currentSelection === "5 minutes" ? "#2196F3" : "#f0f0f0"
  377. border.color: timeoutGrid.currentSelection === "5 minutes" ? "#1976D2" : "#ccc"
  378. border.width: 2
  379. radius: 8
  380. Label {
  381. anchors.centerIn: parent
  382. text: "5min"
  383. font.pixelSize: 14
  384. font.bold: true
  385. color: timeoutGrid.currentSelection === "5 minutes" ? "white" : "#333"
  386. }
  387. MouseArea {
  388. anchors.fill: parent
  389. onClicked: {
  390. if (backend) {
  391. backend.setScreenTimeoutByOption("5 minutes")
  392. timeoutGrid.currentSelection = "5 minutes"
  393. }
  394. }
  395. }
  396. }
  397. // 10 minutes button
  398. Rectangle {
  399. Layout.preferredWidth: 100
  400. Layout.preferredHeight: 50
  401. color: timeoutGrid.currentSelection === "10 minutes" ? "#2196F3" : "#f0f0f0"
  402. border.color: timeoutGrid.currentSelection === "10 minutes" ? "#1976D2" : "#ccc"
  403. border.width: 2
  404. radius: 8
  405. Label {
  406. anchors.centerIn: parent
  407. text: "10min"
  408. font.pixelSize: 14
  409. font.bold: true
  410. color: timeoutGrid.currentSelection === "10 minutes" ? "white" : "#333"
  411. }
  412. MouseArea {
  413. anchors.fill: parent
  414. onClicked: {
  415. if (backend) {
  416. backend.setScreenTimeoutByOption("10 minutes")
  417. timeoutGrid.currentSelection = "10 minutes"
  418. }
  419. }
  420. }
  421. }
  422. // Never button
  423. Rectangle {
  424. Layout.preferredWidth: 100
  425. Layout.preferredHeight: 50
  426. color: timeoutGrid.currentSelection === "Never" ? "#FF9800" : "#f0f0f0"
  427. border.color: timeoutGrid.currentSelection === "Never" ? "#F57C00" : "#ccc"
  428. border.width: 2
  429. radius: 8
  430. Label {
  431. anchors.centerIn: parent
  432. text: "Never"
  433. font.pixelSize: 14
  434. font.bold: true
  435. color: timeoutGrid.currentSelection === "Never" ? "white" : "#333"
  436. }
  437. MouseArea {
  438. anchors.fill: parent
  439. onClicked: {
  440. if (backend) {
  441. backend.setScreenTimeoutByOption("Never")
  442. timeoutGrid.currentSelection = "Never"
  443. }
  444. }
  445. }
  446. }
  447. // Update selection when backend changes
  448. Connections {
  449. target: backend
  450. function onScreenTimeoutChanged() {
  451. if (backend) {
  452. timeoutGrid.currentSelection = backend.getCurrentScreenTimeoutOption()
  453. }
  454. }
  455. }
  456. }
  457. }
  458. }
  459. }
  460. // Add some bottom spacing for better scrolling
  461. Item {
  462. Layout.preferredHeight: 20
  463. }
  464. }
  465. }
  466. }
  467. }