1
0

LedControlPage.qml 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603
  1. import QtQuick 2.15
  2. import QtQuick.Controls 2.15
  3. import QtQuick.Layouts 1.15
  4. import QtQuick.Dialogs
  5. import "../components"
  6. import "../components" as Components
  7. Page {
  8. id: page
  9. property var backend: null
  10. // Local state
  11. property bool ledPowerOn: false
  12. property int ledBrightness: 100
  13. property string ledProvider: "none"
  14. property bool ledConnected: false
  15. property int currentEffectIndex: 0
  16. property int currentPaletteIndex: 0
  17. property var effectsList: []
  18. property var palettesList: []
  19. // Predefined colors for quick selection (muted tones to fit dark UI)
  20. property var presetColors: [
  21. {"name": "White", "color": "#e8e8e8", "sendColor": "#ffffff"},
  22. {"name": "Warm", "color": "#d4a574", "sendColor": "#ffaa55"},
  23. {"name": "Red", "color": "#c45c5c", "sendColor": "#ff0000"},
  24. {"name": "Orange", "color": "#d4875c", "sendColor": "#ff8800"},
  25. {"name": "Yellow", "color": "#c9b95c", "sendColor": "#ffff00"},
  26. {"name": "Green", "color": "#5cb85c", "sendColor": "#00ff00"},
  27. {"name": "Cyan", "color": "#5cb8b8", "sendColor": "#00ffff"},
  28. {"name": "Blue", "color": "#5c7cc4", "sendColor": "#0000ff"},
  29. {"name": "Purple", "color": "#8b5cc4", "sendColor": "#8800ff"},
  30. {"name": "Pink", "color": "#c45c99", "sendColor": "#ff00ff"}
  31. ]
  32. // Backend signal connections
  33. Connections {
  34. target: backend
  35. function onLedStatusChanged() {
  36. if (backend) {
  37. ledPowerOn = backend.ledPowerOn
  38. ledBrightness = backend.ledBrightness
  39. ledProvider = backend.ledProvider
  40. ledConnected = backend.ledConnected
  41. currentEffectIndex = backend.ledCurrentEffect
  42. currentPaletteIndex = backend.ledCurrentPalette
  43. }
  44. }
  45. function onLedEffectsLoaded(effects) {
  46. effectsList = effects
  47. }
  48. function onLedPalettesLoaded(palettes) {
  49. palettesList = palettes
  50. }
  51. }
  52. // Load LED config on page load
  53. Component.onCompleted: {
  54. if (backend) {
  55. backend.loadLedConfig()
  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: "LED 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. // Screen Brightness Section (always visible, controls Pi LCD backlight)
  105. Rectangle {
  106. Layout.fillWidth: true
  107. Layout.preferredHeight: 60
  108. Layout.margins: 5
  109. radius: 8
  110. color: Components.ThemeManager.surfaceColor
  111. visible: backend && backend.lcdMaxBrightness > 0
  112. RowLayout {
  113. anchors.fill: parent
  114. anchors.leftMargin: 15
  115. anchors.rightMargin: 15
  116. anchors.topMargin: 10
  117. anchors.bottomMargin: 10
  118. spacing: 10
  119. Label {
  120. text: "\u2600"
  121. font.pixelSize: 20
  122. color: Components.ThemeManager.textSecondary
  123. }
  124. Slider {
  125. id: lcdBrightnessSlider
  126. Layout.fillWidth: true
  127. from: 0
  128. to: backend ? backend.lcdMaxBrightness : 255
  129. stepSize: 1
  130. value: backend ? backend.lcdBrightness : 255
  131. onMoved: {
  132. if (backend) {
  133. backend.setLcdBrightness(Math.round(value))
  134. }
  135. }
  136. }
  137. Label {
  138. text: {
  139. var max = backend ? backend.lcdMaxBrightness : 255
  140. if (max <= 0) return "0%"
  141. return Math.round(lcdBrightnessSlider.value / max * 100) + "%"
  142. }
  143. font.pixelSize: 12
  144. font.bold: true
  145. color: Components.ThemeManager.textPrimary
  146. Layout.preferredWidth: 35
  147. horizontalAlignment: Text.AlignRight
  148. }
  149. }
  150. }
  151. // Provider Info & Power/Brightness Section
  152. Rectangle {
  153. Layout.fillWidth: true
  154. Layout.preferredHeight: ledProvider === "none" ? 100 : (ledProvider === "wled" ? 90 : 110)
  155. Layout.margins: 5
  156. radius: 8
  157. color: Components.ThemeManager.surfaceColor
  158. ColumnLayout {
  159. anchors.fill: parent
  160. anchors.margins: 15
  161. spacing: 10
  162. // Not configured message
  163. ColumnLayout {
  164. visible: ledProvider === "none"
  165. Layout.fillWidth: true
  166. spacing: 8
  167. Label {
  168. text: "LED Not Configured"
  169. font.pixelSize: 14
  170. font.bold: true
  171. color: Components.ThemeManager.textPrimary
  172. }
  173. Label {
  174. text: "Configure LED settings in the main Dune Weaver web interface"
  175. font.pixelSize: 12
  176. color: Components.ThemeManager.textSecondary
  177. wrapMode: Text.WordWrap
  178. Layout.fillWidth: true
  179. }
  180. }
  181. // DW LEDs Controls - Power and Brightness in same section
  182. ColumnLayout {
  183. visible: ledProvider === "dw_leds"
  184. Layout.fillWidth: true
  185. spacing: 8
  186. // Power row with status and toggle
  187. RowLayout {
  188. Layout.fillWidth: true
  189. spacing: 12
  190. // Status indicator with label
  191. RowLayout {
  192. spacing: 6
  193. Rectangle {
  194. width: 12
  195. height: 12
  196. radius: 6
  197. color: ledPowerOn ? "#4CAF50" : "#6b7280"
  198. }
  199. Label {
  200. text: ledPowerOn ? "On" : "Off"
  201. font.pixelSize: 13
  202. font.bold: true
  203. color: Components.ThemeManager.textPrimary
  204. }
  205. }
  206. // Toggle button
  207. ModernControlButton {
  208. Layout.preferredWidth: 100
  209. Layout.preferredHeight: 36
  210. text: ledPowerOn ? "Turn Off" : "Turn On"
  211. icon: ""
  212. buttonColor: ledPowerOn ? "#6b7280" : "#4CAF50"
  213. fontSize: 11
  214. onClicked: {
  215. if (backend) {
  216. backend.toggleLedPower()
  217. }
  218. }
  219. }
  220. Item { Layout.fillWidth: true }
  221. // Connection status (smaller, secondary)
  222. RowLayout {
  223. spacing: 4
  224. Rectangle {
  225. width: 8
  226. height: 8
  227. radius: 4
  228. color: ledConnected ? "#4CAF50" : "#ef4444"
  229. }
  230. Label {
  231. text: ledConnected ? "Connected" : "Disconnected"
  232. font.pixelSize: 10
  233. color: Components.ThemeManager.textTertiary
  234. }
  235. }
  236. }
  237. // Brightness row
  238. RowLayout {
  239. Layout.fillWidth: true
  240. spacing: 10
  241. Label {
  242. text: "Brightness"
  243. font.pixelSize: 12
  244. color: Components.ThemeManager.textSecondary
  245. }
  246. Slider {
  247. id: brightnessSlider
  248. Layout.fillWidth: true
  249. from: 0
  250. to: 100
  251. stepSize: 5
  252. value: ledBrightness
  253. onMoved: {
  254. if (backend) {
  255. backend.setLedBrightness(Math.round(value))
  256. }
  257. }
  258. }
  259. Label {
  260. text: Math.round(brightnessSlider.value) + "%"
  261. font.pixelSize: 12
  262. font.bold: true
  263. color: Components.ThemeManager.textPrimary
  264. Layout.preferredWidth: 35
  265. horizontalAlignment: Text.AlignRight
  266. }
  267. }
  268. }
  269. // WLED Info
  270. ColumnLayout {
  271. visible: ledProvider === "wled"
  272. Layout.fillWidth: true
  273. spacing: 8
  274. Label {
  275. text: "WLED Mode"
  276. font.pixelSize: 14
  277. font.bold: true
  278. color: Components.ThemeManager.textPrimary
  279. }
  280. Label {
  281. text: "Use the main Dune Weaver web interface for WLED controls"
  282. font.pixelSize: 12
  283. color: Components.ThemeManager.textSecondary
  284. wrapMode: Text.WordWrap
  285. Layout.fillWidth: true
  286. }
  287. }
  288. }
  289. }
  290. // Effects Section (only for dw_leds)
  291. Rectangle {
  292. Layout.fillWidth: true
  293. Layout.preferredHeight: effectsList.length > 0 ? 180 : 80
  294. Layout.margins: 5
  295. radius: 8
  296. color: Components.ThemeManager.surfaceColor
  297. visible: ledProvider === "dw_leds"
  298. ColumnLayout {
  299. anchors.fill: parent
  300. anchors.margins: 15
  301. spacing: 10
  302. Label {
  303. text: "Effects"
  304. font.pixelSize: 14
  305. font.bold: true
  306. color: Components.ThemeManager.textPrimary
  307. }
  308. // Show loading or no effects message
  309. Label {
  310. visible: effectsList.length === 0
  311. text: "No effects available"
  312. font.pixelSize: 12
  313. color: Components.ThemeManager.textSecondary
  314. }
  315. // Effects grid
  316. GridLayout {
  317. Layout.fillWidth: true
  318. columns: 4
  319. rowSpacing: 6
  320. columnSpacing: 6
  321. visible: effectsList.length > 0
  322. Repeater {
  323. model: effectsList.slice(0, 12) // Show first 12 effects
  324. Rectangle {
  325. property int effectId: modelData.id !== undefined ? modelData.id : index
  326. property bool isSelected: effectId === currentEffectIndex
  327. Layout.fillWidth: true
  328. Layout.preferredHeight: 35
  329. radius: 6
  330. color: isSelected ?
  331. Components.ThemeManager.selectedBackground :
  332. Components.ThemeManager.buttonBackground
  333. border.color: isSelected ?
  334. Components.ThemeManager.selectedBorder :
  335. Components.ThemeManager.buttonBorder
  336. border.width: 1
  337. Label {
  338. anchors.centerIn: parent
  339. anchors.leftMargin: 4
  340. anchors.rightMargin: 4
  341. width: parent.width - 8
  342. text: modelData.name || ("Effect " + effectId)
  343. font.pixelSize: 10
  344. color: isSelected ? "white" : Components.ThemeManager.textPrimary
  345. elide: Text.ElideRight
  346. horizontalAlignment: Text.AlignHCenter
  347. }
  348. MouseArea {
  349. anchors.fill: parent
  350. onClicked: {
  351. if (backend) {
  352. backend.setLedEffect(effectId)
  353. currentEffectIndex = effectId
  354. }
  355. }
  356. }
  357. }
  358. }
  359. }
  360. }
  361. }
  362. // Palettes Section (only for dw_leds)
  363. Rectangle {
  364. Layout.fillWidth: true
  365. Layout.preferredHeight: palettesList.length > 0 ? 140 : 80
  366. Layout.margins: 5
  367. radius: 8
  368. color: Components.ThemeManager.surfaceColor
  369. visible: ledProvider === "dw_leds"
  370. ColumnLayout {
  371. anchors.fill: parent
  372. anchors.margins: 15
  373. spacing: 10
  374. Label {
  375. text: "Palettes"
  376. font.pixelSize: 14
  377. font.bold: true
  378. color: Components.ThemeManager.textPrimary
  379. }
  380. // Show loading or no palettes message
  381. Label {
  382. visible: palettesList.length === 0
  383. text: "No palettes available"
  384. font.pixelSize: 12
  385. color: Components.ThemeManager.textSecondary
  386. }
  387. // Palettes grid
  388. GridLayout {
  389. Layout.fillWidth: true
  390. columns: 4
  391. rowSpacing: 6
  392. columnSpacing: 6
  393. visible: palettesList.length > 0
  394. Repeater {
  395. model: palettesList.slice(0, 8) // Show first 8 palettes
  396. Rectangle {
  397. property int paletteId: modelData.id !== undefined ? modelData.id : index
  398. property bool isSelected: paletteId === currentPaletteIndex
  399. Layout.fillWidth: true
  400. Layout.preferredHeight: 35
  401. radius: 6
  402. color: isSelected ?
  403. Components.ThemeManager.selectedBackground :
  404. Components.ThemeManager.buttonBackground
  405. border.color: isSelected ?
  406. Components.ThemeManager.selectedBorder :
  407. Components.ThemeManager.buttonBorder
  408. border.width: 1
  409. Label {
  410. anchors.centerIn: parent
  411. anchors.leftMargin: 4
  412. anchors.rightMargin: 4
  413. width: parent.width - 8
  414. text: modelData.name || ("Palette " + paletteId)
  415. font.pixelSize: 10
  416. color: isSelected ? "white" : Components.ThemeManager.textPrimary
  417. elide: Text.ElideRight
  418. horizontalAlignment: Text.AlignHCenter
  419. }
  420. MouseArea {
  421. anchors.fill: parent
  422. onClicked: {
  423. if (backend) {
  424. backend.setLedPalette(paletteId)
  425. currentPaletteIndex = paletteId
  426. }
  427. }
  428. }
  429. }
  430. }
  431. }
  432. }
  433. }
  434. // Quick Colors Section - MOVED TO BOTTOM (only for dw_leds)
  435. Rectangle {
  436. Layout.fillWidth: true
  437. Layout.preferredHeight: 160
  438. Layout.margins: 5
  439. radius: 8
  440. color: Components.ThemeManager.surfaceColor
  441. visible: ledProvider === "dw_leds"
  442. ColumnLayout {
  443. anchors.fill: parent
  444. anchors.margins: 15
  445. spacing: 10
  446. Label {
  447. text: "Quick Colors"
  448. font.pixelSize: 14
  449. font.bold: true
  450. color: Components.ThemeManager.textPrimary
  451. }
  452. GridLayout {
  453. Layout.fillWidth: true
  454. Layout.fillHeight: true
  455. columns: 5
  456. rowSpacing: 8
  457. columnSpacing: 8
  458. Repeater {
  459. model: presetColors
  460. Rectangle {
  461. Layout.fillWidth: true
  462. Layout.fillHeight: true
  463. Layout.minimumHeight: 50
  464. radius: 6
  465. color: Components.ThemeManager.buttonBackground
  466. border.color: Components.ThemeManager.buttonBorder
  467. border.width: 1
  468. RowLayout {
  469. anchors.centerIn: parent
  470. spacing: 6
  471. // Color indicator circle
  472. Rectangle {
  473. width: 14
  474. height: 14
  475. radius: 7
  476. color: modelData.color
  477. border.color: Qt.darker(modelData.color, 1.2)
  478. border.width: 1
  479. }
  480. Label {
  481. text: modelData.name
  482. font.pixelSize: 11
  483. color: Components.ThemeManager.textPrimary
  484. }
  485. }
  486. MouseArea {
  487. anchors.fill: parent
  488. onClicked: {
  489. if (backend) {
  490. backend.setLedColorHex(modelData.sendColor)
  491. }
  492. }
  493. }
  494. // Touch feedback
  495. Rectangle {
  496. id: colorTouchFeedback
  497. anchors.fill: parent
  498. color: Components.ThemeManager.darkMode ? "#ffffff" : "#000000"
  499. opacity: 0
  500. radius: 6
  501. NumberAnimation {
  502. id: colorTouchAnimation
  503. target: colorTouchFeedback
  504. property: "opacity"
  505. from: 0.15
  506. to: 0
  507. duration: 200
  508. }
  509. }
  510. }
  511. }
  512. }
  513. }
  514. }
  515. // Add some bottom spacing for better scrolling
  516. Item {
  517. Layout.preferredHeight: 20
  518. }
  519. }
  520. }
  521. }
  522. }