1
0

TableControlPage.qml 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588
  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. 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. Repeater {
  159. model: serialPorts
  160. MenuItem {
  161. text: modelData
  162. onTriggered: {
  163. selectedPort = modelData
  164. }
  165. }
  166. }
  167. MenuSeparator {}
  168. MenuItem {
  169. text: "Refresh Ports"
  170. onTriggered: refreshSerialPorts()
  171. }
  172. }
  173. }
  174. ModernControlButton {
  175. Layout.preferredWidth: 150
  176. Layout.preferredHeight: 40
  177. text: isSerialConnected ? "Disconnect" : "Connect"
  178. icon: isSerialConnected ? "◉" : "○"
  179. buttonColor: isSerialConnected ? "#dc2626" : "#059669"
  180. fontSize: 11
  181. enabled: isSerialConnected || selectedPort !== ""
  182. onClicked: {
  183. if (backend) {
  184. if (isSerialConnected) {
  185. backend.disconnectSerial()
  186. } else {
  187. backend.connectSerial(selectedPort)
  188. }
  189. }
  190. }
  191. }
  192. }
  193. RowLayout {
  194. Layout.fillWidth: true
  195. spacing: 8
  196. visible: !isSerialConnected
  197. ModernControlButton {
  198. Layout.fillWidth: true
  199. Layout.preferredHeight: 35
  200. text: "Refresh Ports"
  201. icon: "↻"
  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. buttonColor: "#2563eb"
  237. fontSize: 12
  238. enabled: isSerialConnected
  239. onClicked: {
  240. if (backend) backend.sendHome()
  241. }
  242. }
  243. ModernControlButton {
  244. Layout.fillWidth: true
  245. Layout.preferredHeight: 45
  246. text: "Center"
  247. icon: "◎"
  248. buttonColor: "#2563eb"
  249. fontSize: 12
  250. enabled: isSerialConnected
  251. onClicked: {
  252. if (backend) backend.moveToCenter()
  253. }
  254. }
  255. ModernControlButton {
  256. Layout.fillWidth: true
  257. Layout.preferredHeight: 45
  258. text: "Perimeter"
  259. icon: "○"
  260. buttonColor: "#2563eb"
  261. fontSize: 12
  262. enabled: isSerialConnected
  263. onClicked: {
  264. if (backend) backend.moveToPerimeter()
  265. }
  266. }
  267. }
  268. }
  269. }
  270. // Auto Play on Boot Section
  271. Rectangle {
  272. Layout.fillWidth: true
  273. Layout.preferredHeight: 200 // Reduced from 280 for single row layout
  274. Layout.margins: 5
  275. radius: 8
  276. color: Components.ThemeManager.surfaceColor
  277. ColumnLayout {
  278. anchors.fill: parent
  279. anchors.margins: 15
  280. spacing: 10
  281. Label {
  282. text: "Auto Play Settings"
  283. font.pixelSize: 14
  284. font.bold: true
  285. color: Components.ThemeManager.textPrimary
  286. }
  287. RowLayout {
  288. Layout.fillWidth: true
  289. spacing: 10
  290. Label {
  291. text: "Auto play on boot:"
  292. font.pixelSize: 12
  293. color: Components.ThemeManager.textSecondary
  294. Layout.fillWidth: true
  295. }
  296. Switch {
  297. id: autoPlaySwitch
  298. checked: autoPlayOnBoot
  299. onToggled: {
  300. autoPlayOnBoot = checked
  301. if (backend) {
  302. backend.setAutoPlayOnBoot(checked)
  303. }
  304. }
  305. }
  306. }
  307. ColumnLayout {
  308. Layout.fillWidth: true
  309. spacing: 15
  310. Label {
  311. text: "Screen timeout:"
  312. font.pixelSize: 14
  313. font.bold: true
  314. color: Components.ThemeManager.textPrimary
  315. Layout.alignment: Qt.AlignLeft
  316. }
  317. // Touch-friendly button row for timeout options
  318. RowLayout {
  319. id: timeoutGrid
  320. Layout.fillWidth: true
  321. spacing: 8
  322. property string currentSelection: backend ? backend.getCurrentScreenTimeoutOption() : "5 minutes"
  323. // 30 seconds button
  324. Rectangle {
  325. Layout.preferredWidth: 100
  326. Layout.preferredHeight: 50
  327. color: timeoutGrid.currentSelection === "30 seconds" ? Components.ThemeManager.selectedBackground : Components.ThemeManager.buttonBackground
  328. border.color: timeoutGrid.currentSelection === "30 seconds" ? Components.ThemeManager.selectedBorder : Components.ThemeManager.buttonBorder
  329. border.width: 2
  330. radius: 8
  331. Label {
  332. anchors.centerIn: parent
  333. text: "30s"
  334. font.pixelSize: 14
  335. font.bold: true
  336. color: timeoutGrid.currentSelection === "30 seconds" ? "white" : Components.ThemeManager.textPrimary
  337. }
  338. MouseArea {
  339. anchors.fill: parent
  340. onClicked: {
  341. if (backend) {
  342. backend.setScreenTimeoutByOption("30 seconds")
  343. timeoutGrid.currentSelection = "30 seconds"
  344. }
  345. }
  346. }
  347. }
  348. // 1 minute button
  349. Rectangle {
  350. Layout.preferredWidth: 100
  351. Layout.preferredHeight: 50
  352. color: timeoutGrid.currentSelection === "1 minute" ? Components.ThemeManager.selectedBackground : Components.ThemeManager.buttonBackground
  353. border.color: timeoutGrid.currentSelection === "1 minute" ? Components.ThemeManager.selectedBorder : Components.ThemeManager.buttonBorder
  354. border.width: 2
  355. radius: 8
  356. Label {
  357. anchors.centerIn: parent
  358. text: "1min"
  359. font.pixelSize: 14
  360. font.bold: true
  361. color: timeoutGrid.currentSelection === "1 minute" ? "white" : Components.ThemeManager.textPrimary
  362. }
  363. MouseArea {
  364. anchors.fill: parent
  365. onClicked: {
  366. if (backend) {
  367. backend.setScreenTimeoutByOption("1 minute")
  368. timeoutGrid.currentSelection = "1 minute"
  369. }
  370. }
  371. }
  372. }
  373. // 5 minutes button
  374. Rectangle {
  375. Layout.preferredWidth: 100
  376. Layout.preferredHeight: 50
  377. color: timeoutGrid.currentSelection === "5 minutes" ? Components.ThemeManager.selectedBackground : Components.ThemeManager.buttonBackground
  378. border.color: timeoutGrid.currentSelection === "5 minutes" ? Components.ThemeManager.selectedBorder : Components.ThemeManager.buttonBorder
  379. border.width: 2
  380. radius: 8
  381. Label {
  382. anchors.centerIn: parent
  383. text: "5min"
  384. font.pixelSize: 14
  385. font.bold: true
  386. color: timeoutGrid.currentSelection === "5 minutes" ? "white" : Components.ThemeManager.textPrimary
  387. }
  388. MouseArea {
  389. anchors.fill: parent
  390. onClicked: {
  391. if (backend) {
  392. backend.setScreenTimeoutByOption("5 minutes")
  393. timeoutGrid.currentSelection = "5 minutes"
  394. }
  395. }
  396. }
  397. }
  398. // 10 minutes button
  399. Rectangle {
  400. Layout.preferredWidth: 100
  401. Layout.preferredHeight: 50
  402. color: timeoutGrid.currentSelection === "10 minutes" ? Components.ThemeManager.selectedBackground : Components.ThemeManager.buttonBackground
  403. border.color: timeoutGrid.currentSelection === "10 minutes" ? Components.ThemeManager.selectedBorder : Components.ThemeManager.buttonBorder
  404. border.width: 2
  405. radius: 8
  406. Label {
  407. anchors.centerIn: parent
  408. text: "10min"
  409. font.pixelSize: 14
  410. font.bold: true
  411. color: timeoutGrid.currentSelection === "10 minutes" ? "white" : Components.ThemeManager.textPrimary
  412. }
  413. MouseArea {
  414. anchors.fill: parent
  415. onClicked: {
  416. if (backend) {
  417. backend.setScreenTimeoutByOption("10 minutes")
  418. timeoutGrid.currentSelection = "10 minutes"
  419. }
  420. }
  421. }
  422. }
  423. // Never button
  424. Rectangle {
  425. Layout.preferredWidth: 100
  426. Layout.preferredHeight: 50
  427. color: timeoutGrid.currentSelection === "Never" ? "#FF9800" : "#f0f0f0"
  428. border.color: timeoutGrid.currentSelection === "Never" ? "#F57C00" : "#ccc"
  429. border.width: 2
  430. radius: 8
  431. Label {
  432. anchors.centerIn: parent
  433. text: "Never"
  434. font.pixelSize: 14
  435. font.bold: true
  436. color: timeoutGrid.currentSelection === "Never" ? "white" : "#333"
  437. }
  438. MouseArea {
  439. anchors.fill: parent
  440. onClicked: {
  441. if (backend) {
  442. backend.setScreenTimeoutByOption("Never")
  443. timeoutGrid.currentSelection = "Never"
  444. }
  445. }
  446. }
  447. }
  448. // Update selection when backend changes
  449. Connections {
  450. target: backend
  451. function onScreenTimeoutChanged() {
  452. if (backend) {
  453. timeoutGrid.currentSelection = backend.getCurrentScreenTimeoutOption()
  454. }
  455. }
  456. }
  457. }
  458. }
  459. }
  460. }
  461. // Theme Settings Section
  462. Rectangle {
  463. Layout.fillWidth: true
  464. Layout.preferredHeight: 100
  465. Layout.margins: 5
  466. radius: 8
  467. color: Components.ThemeManager.surfaceColor
  468. ColumnLayout {
  469. anchors.fill: parent
  470. anchors.margins: 15
  471. spacing: 10
  472. Label {
  473. text: "Appearance"
  474. font.pixelSize: 14
  475. font.bold: true
  476. color: Components.ThemeManager.textPrimary
  477. }
  478. RowLayout {
  479. Layout.fillWidth: true
  480. spacing: 10
  481. Label {
  482. text: "Dark mode:"
  483. font.pixelSize: 12
  484. color: Components.ThemeManager.textSecondary
  485. Layout.fillWidth: true
  486. }
  487. Switch {
  488. id: darkModeSwitch
  489. checked: Components.ThemeManager.darkMode
  490. onToggled: {
  491. Components.ThemeManager.darkMode = checked
  492. }
  493. }
  494. }
  495. }
  496. }
  497. // Add some bottom spacing for better scrolling
  498. Item {
  499. Layout.preferredHeight: 20
  500. }
  501. }
  502. }
  503. }
  504. }