ModernPlaylistPage.qml 72 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426
  1. import QtQuick 2.15
  2. import QtQuick.Controls 2.15
  3. import QtQuick.Layouts 1.15
  4. import DuneWeaver 1.0
  5. import "../components"
  6. import "../components" as Components
  7. Page {
  8. id: page
  9. property var backend: null
  10. property var stackView: null
  11. property var mainWindow: null
  12. // State management for navigation
  13. property bool showingPlaylistDetail: false
  14. property string selectedPlaylist: ""
  15. property var selectedPlaylistData: null
  16. property var currentPlaylistPatterns: []
  17. property var currentPlaylistRawPatterns: [] // Raw patterns with full paths for API calls
  18. // Playlist execution settings (loaded from backend/persisted settings)
  19. property real pauseTime: backend ? backend.pauseBetweenPatterns : 10800
  20. property string clearPattern: backend ? backend.playlistClearPattern : "adaptive"
  21. property string runMode: backend ? backend.playlistRunMode : "loop"
  22. property bool shuffle: backend ? backend.playlistShuffle : true
  23. PlaylistModel {
  24. id: playlistModel
  25. }
  26. // Update patterns when playlist selection changes
  27. onSelectedPlaylistChanged: {
  28. if (selectedPlaylist) {
  29. currentPlaylistPatterns = playlistModel.getPatternsForPlaylist(selectedPlaylist)
  30. currentPlaylistRawPatterns = playlistModel.getRawPatternsForPlaylist(selectedPlaylist)
  31. } else {
  32. currentPlaylistPatterns = []
  33. currentPlaylistRawPatterns = []
  34. }
  35. }
  36. // Function to remove a pattern from the current playlist
  37. function removePatternAtIndex(index) {
  38. if (index >= 0 && index < currentPlaylistRawPatterns.length && backend) {
  39. var updatedPatterns = currentPlaylistRawPatterns.slice() // Create a copy
  40. updatedPatterns.splice(index, 1) // Remove the pattern at index
  41. backend.updatePlaylistPatterns(selectedPlaylist, updatedPatterns)
  42. }
  43. }
  44. // Debug playlist loading
  45. Component.onCompleted: {
  46. }
  47. // Function to navigate to playlist detail
  48. function showPlaylistDetail(playlistName, playlistData) {
  49. selectedPlaylist = playlistName
  50. selectedPlaylistData = playlistData
  51. showingPlaylistDetail = true
  52. }
  53. // Function to go back to playlist list
  54. function showPlaylistList() {
  55. showingPlaylistDetail = false
  56. selectedPlaylist = ""
  57. selectedPlaylistData = null
  58. }
  59. Rectangle {
  60. anchors.fill: parent
  61. color: Components.ThemeManager.backgroundColor
  62. }
  63. // Playlist List View (shown by default)
  64. Rectangle {
  65. id: playlistListView
  66. anchors.fill: parent
  67. color: Components.ThemeManager.backgroundColor
  68. visible: !showingPlaylistDetail
  69. ColumnLayout {
  70. anchors.fill: parent
  71. spacing: 0
  72. // Header
  73. Rectangle {
  74. Layout.fillWidth: true
  75. Layout.preferredHeight: 50
  76. color: Components.ThemeManager.surfaceColor
  77. // Bottom border
  78. Rectangle {
  79. anchors.bottom: parent.bottom
  80. width: parent.width
  81. height: 1
  82. color: Components.ThemeManager.borderColor
  83. }
  84. RowLayout {
  85. anchors.fill: parent
  86. anchors.leftMargin: 15
  87. anchors.rightMargin: 10
  88. ConnectionStatus {
  89. backend: page.backend
  90. Layout.rightMargin: 8
  91. }
  92. Label {
  93. text: "Playlists"
  94. font.pixelSize: 18
  95. font.bold: true
  96. color: Components.ThemeManager.textPrimary
  97. }
  98. Label {
  99. text: playlistModel.rowCount() + " playlists"
  100. font.pixelSize: 12
  101. color: Components.ThemeManager.textTertiary
  102. }
  103. Item {
  104. Layout.fillWidth: true
  105. }
  106. // Create new playlist button
  107. Text {
  108. text: "+"
  109. font.pixelSize: 32
  110. font.bold: true
  111. color: createPlaylistMouseArea.pressed ? "#1e40af" : "#2563eb"
  112. MouseArea {
  113. id: createPlaylistMouseArea
  114. anchors.fill: parent
  115. anchors.margins: -8 // Increase touch area
  116. onClicked: createPlaylistDialog.open()
  117. }
  118. }
  119. }
  120. }
  121. // Playlist List
  122. ListView {
  123. Layout.fillWidth: true
  124. Layout.fillHeight: true
  125. Layout.margins: 15
  126. model: playlistModel
  127. spacing: 12
  128. clip: true
  129. ScrollBar.vertical: ScrollBar {
  130. active: true
  131. policy: ScrollBar.AsNeeded
  132. }
  133. delegate: Rectangle {
  134. width: ListView.view.width
  135. height: 80
  136. color: Components.ThemeManager.surfaceColor
  137. radius: 12
  138. border.color: Components.ThemeManager.borderColor
  139. border.width: 1
  140. // Press animation
  141. scale: mouseArea.pressed ? 0.98 : 1.0
  142. Behavior on scale {
  143. NumberAnimation { duration: 100; easing.type: Easing.OutQuad }
  144. }
  145. RowLayout {
  146. anchors.fill: parent
  147. anchors.margins: 20
  148. spacing: 15
  149. // Icon
  150. Rectangle {
  151. Layout.preferredWidth: 40
  152. Layout.preferredHeight: 40
  153. radius: 20
  154. color: Components.ThemeManager.darkMode ? "#1e3a5f" : "#e3f2fd"
  155. Text {
  156. anchors.centerIn: parent
  157. text: "♪"
  158. font.pixelSize: 18
  159. color: "#2196F3"
  160. }
  161. }
  162. // Playlist info
  163. Column {
  164. Layout.fillWidth: true
  165. spacing: 4
  166. Label {
  167. text: model.name
  168. font.pixelSize: 16
  169. font.bold: true
  170. color: Components.ThemeManager.textPrimary
  171. elide: Text.ElideRight
  172. width: parent.width
  173. }
  174. Label {
  175. text: model.itemCount + " patterns"
  176. color: Components.ThemeManager.textSecondary
  177. font.pixelSize: 12
  178. }
  179. }
  180. // Arrow
  181. Text {
  182. text: "▶"
  183. font.pixelSize: 16
  184. color: Components.ThemeManager.textTertiary
  185. }
  186. }
  187. MouseArea {
  188. id: mouseArea
  189. anchors.fill: parent
  190. onClicked: {
  191. showPlaylistDetail(model.name, model)
  192. }
  193. }
  194. }
  195. // Empty state
  196. Rectangle {
  197. anchors.fill: parent
  198. color: "transparent"
  199. visible: playlistModel.rowCount() === 0
  200. Column {
  201. anchors.centerIn: parent
  202. spacing: 15
  203. Text {
  204. text: "♪"
  205. color: Components.ThemeManager.placeholderText
  206. font.pixelSize: 64
  207. anchors.horizontalCenter: parent.horizontalCenter
  208. }
  209. Label {
  210. text: "No playlists found"
  211. anchors.horizontalCenter: parent.horizontalCenter
  212. color: Components.ThemeManager.textSecondary
  213. font.pixelSize: 18
  214. }
  215. Label {
  216. text: "Create playlists to organize\\nyour pattern collections"
  217. anchors.horizontalCenter: parent.horizontalCenter
  218. color: Components.ThemeManager.textTertiary
  219. font.pixelSize: 14
  220. horizontalAlignment: Text.AlignHCenter
  221. }
  222. }
  223. }
  224. }
  225. }
  226. }
  227. // Playlist Detail View (shown when a playlist is selected)
  228. Rectangle {
  229. id: playlistDetailView
  230. anchors.fill: parent
  231. color: Components.ThemeManager.backgroundColor
  232. visible: showingPlaylistDetail
  233. ColumnLayout {
  234. anchors.fill: parent
  235. spacing: 0
  236. // Header with back button
  237. Rectangle {
  238. Layout.fillWidth: true
  239. Layout.preferredHeight: 50
  240. color: Components.ThemeManager.surfaceColor
  241. // Bottom border
  242. Rectangle {
  243. anchors.bottom: parent.bottom
  244. width: parent.width
  245. height: 1
  246. color: Components.ThemeManager.borderColor
  247. }
  248. RowLayout {
  249. anchors.fill: parent
  250. anchors.leftMargin: 15
  251. anchors.rightMargin: 10
  252. spacing: 10
  253. ConnectionStatus {
  254. backend: page.backend
  255. Layout.rightMargin: 8
  256. }
  257. Button {
  258. text: "← Back"
  259. font.pixelSize: 14
  260. flat: true
  261. onClicked: showPlaylistList()
  262. contentItem: Text {
  263. text: parent.text
  264. font: parent.font
  265. color: Components.ThemeManager.textPrimary
  266. horizontalAlignment: Text.AlignHCenter
  267. verticalAlignment: Text.AlignVCenter
  268. }
  269. }
  270. Label {
  271. text: selectedPlaylist
  272. font.pixelSize: 18
  273. font.bold: true
  274. color: Components.ThemeManager.textPrimary
  275. Layout.fillWidth: true
  276. elide: Text.ElideRight
  277. }
  278. Label {
  279. text: currentPlaylistPatterns.length + " patterns"
  280. font.pixelSize: 12
  281. color: Components.ThemeManager.textTertiary
  282. }
  283. // Delete playlist button
  284. Text {
  285. text: "✕"
  286. font.pixelSize: 20
  287. color: deletePlaylistMouseArea.pressed ? "#991b1b" : "#dc2626"
  288. MouseArea {
  289. id: deletePlaylistMouseArea
  290. anchors.fill: parent
  291. anchors.margins: -8
  292. onClicked: deletePlaylistDialog.open()
  293. }
  294. }
  295. }
  296. }
  297. // Content - Pattern list on left, controls on right
  298. Item {
  299. Layout.fillWidth: true
  300. Layout.fillHeight: true
  301. Row {
  302. anchors.fill: parent
  303. spacing: 0
  304. // Left side - Pattern List (40% of width)
  305. Rectangle {
  306. width: parent.width * 0.4
  307. height: parent.height
  308. color: Components.ThemeManager.surfaceColor
  309. ColumnLayout {
  310. anchors.fill: parent
  311. anchors.margins: 15
  312. spacing: 10
  313. RowLayout {
  314. Layout.fillWidth: true
  315. spacing: 10
  316. Label {
  317. text: "Patterns"
  318. font.pixelSize: 14
  319. font.bold: true
  320. color: Components.ThemeManager.textPrimary
  321. Layout.fillWidth: true
  322. }
  323. // Add pattern button
  324. Text {
  325. text: "+"
  326. font.pixelSize: 24
  327. font.bold: true
  328. color: addPatternMouseArea.pressed ? "#1e40af" : "#2563eb"
  329. MouseArea {
  330. id: addPatternMouseArea
  331. anchors.fill: parent
  332. anchors.margins: -8
  333. onClicked: {
  334. // Navigate to full-page pattern selector
  335. stackView.push("PatternSelectorPage.qml", {
  336. backend: backend,
  337. stackView: stackView,
  338. playlistName: selectedPlaylist,
  339. existingPatterns: currentPlaylistRawPatterns
  340. })
  341. }
  342. }
  343. }
  344. }
  345. ScrollView {
  346. Layout.fillWidth: true
  347. Layout.fillHeight: true
  348. clip: true
  349. ListView {
  350. id: patternListView
  351. width: parent.width
  352. model: currentPlaylistPatterns
  353. spacing: 6
  354. delegate: Rectangle {
  355. width: patternListView.width
  356. height: 40
  357. color: index % 2 === 0 ? Components.ThemeManager.cardColor : Components.ThemeManager.surfaceColor
  358. radius: 6
  359. border.color: Components.ThemeManager.borderColor
  360. border.width: 1
  361. RowLayout {
  362. anchors.fill: parent
  363. anchors.leftMargin: 10
  364. anchors.rightMargin: 5
  365. anchors.topMargin: 4
  366. anchors.bottomMargin: 4
  367. spacing: 6
  368. Label {
  369. text: (index + 1) + "."
  370. font.pixelSize: 11
  371. color: Components.ThemeManager.textSecondary
  372. Layout.preferredWidth: 22
  373. }
  374. Label {
  375. text: modelData
  376. font.pixelSize: 11
  377. color: Components.ThemeManager.textPrimary
  378. Layout.fillWidth: true
  379. elide: Text.ElideRight
  380. }
  381. // Remove pattern button - aligned right
  382. Text {
  383. text: "✕"
  384. font.pixelSize: 16
  385. color: removePatternArea.pressed ? "#ef4444" : Components.ThemeManager.textTertiary
  386. Layout.alignment: Qt.AlignRight | Qt.AlignVCenter
  387. MouseArea {
  388. id: removePatternArea
  389. anchors.fill: parent
  390. anchors.margins: -8 // Increase touch area
  391. onClicked: {
  392. removePatternAtIndex(index)
  393. }
  394. }
  395. }
  396. }
  397. }
  398. }
  399. }
  400. // Empty playlist message
  401. Rectangle {
  402. Layout.fillWidth: true
  403. Layout.fillHeight: true
  404. color: "transparent"
  405. visible: currentPlaylistPatterns.length === 0
  406. Column {
  407. anchors.centerIn: parent
  408. spacing: 10
  409. Text {
  410. text: "♪"
  411. font.pixelSize: 32
  412. color: Components.ThemeManager.placeholderText
  413. anchors.horizontalCenter: parent.horizontalCenter
  414. }
  415. Label {
  416. text: "Empty playlist"
  417. anchors.horizontalCenter: parent.horizontalCenter
  418. color: Components.ThemeManager.textSecondary
  419. font.pixelSize: 14
  420. }
  421. }
  422. }
  423. }
  424. }
  425. // Divider
  426. Rectangle {
  427. width: 1
  428. height: parent.height
  429. color: Components.ThemeManager.borderColor
  430. }
  431. // Right side - Full height controls (60% of width)
  432. Rectangle {
  433. width: parent.width * 0.6 - 1
  434. height: parent.height
  435. color: Components.ThemeManager.surfaceColor
  436. ColumnLayout {
  437. anchors.fill: parent
  438. anchors.margins: 15
  439. spacing: 15
  440. Label {
  441. text: "Playlist Controls"
  442. font.pixelSize: 16
  443. font.bold: true
  444. color: Components.ThemeManager.textPrimary
  445. }
  446. // Main execution buttons
  447. RowLayout {
  448. Layout.fillWidth: true
  449. spacing: 10
  450. // Play Playlist button
  451. Rectangle {
  452. Layout.fillWidth: true
  453. Layout.preferredHeight: 45
  454. radius: 8
  455. color: playMouseArea.pressed ? "#1e40af" : "#2563eb"
  456. Text {
  457. anchors.centerIn: parent
  458. text: "Play Playlist"
  459. color: "white"
  460. font.pixelSize: 14
  461. font.bold: true
  462. }
  463. MouseArea {
  464. id: playMouseArea
  465. anchors.fill: parent
  466. onClicked: {
  467. if (backend) {
  468. backend.executePlaylist(selectedPlaylist, pauseTime, clearPattern, runMode, shuffle)
  469. // Navigate to execution page
  470. if (mainWindow) {
  471. mainWindow.shouldNavigateToExecution = true
  472. }
  473. }
  474. }
  475. }
  476. }
  477. // Shuffle toggle button
  478. Rectangle {
  479. Layout.preferredWidth: 60
  480. Layout.preferredHeight: 45
  481. radius: 8
  482. color: shuffle ? "#2563eb" : "#6b7280"
  483. Text {
  484. anchors.centerIn: parent
  485. text: "⇄"
  486. color: "white"
  487. font.pixelSize: 16
  488. }
  489. MouseArea {
  490. id: shuffleMouseArea
  491. anchors.fill: parent
  492. onClicked: {
  493. // Don't assign directly to shuffle - that breaks the binding
  494. // Just update backend and let the binding propagate the change
  495. if (backend) backend.setPlaylistShuffle(!backend.playlistShuffle)
  496. }
  497. }
  498. }
  499. }
  500. // Settings section
  501. Rectangle {
  502. Layout.fillWidth: true
  503. Layout.fillHeight: true
  504. Layout.minimumHeight: 250
  505. radius: 10
  506. color: Components.ThemeManager.cardColor
  507. border.color: Components.ThemeManager.borderColor
  508. border.width: 1
  509. ColumnLayout {
  510. anchors.fill: parent
  511. anchors.margins: 15
  512. spacing: 15
  513. Label {
  514. text: "Settings"
  515. font.pixelSize: 14
  516. font.bold: true
  517. color: Components.ThemeManager.textPrimary
  518. }
  519. // Scrollable settings content
  520. ScrollView {
  521. Layout.fillWidth: true
  522. Layout.fillHeight: true
  523. clip: true
  524. ScrollBar.vertical.policy: ScrollBar.AsNeeded
  525. ColumnLayout {
  526. width: parent.width
  527. spacing: 15
  528. // Run mode
  529. Column {
  530. Layout.fillWidth: true
  531. spacing: 8
  532. Label {
  533. text: "Run Mode:"
  534. font.pixelSize: 12
  535. color: Components.ThemeManager.textSecondary
  536. font.bold: true
  537. }
  538. RowLayout {
  539. width: parent.width
  540. spacing: 15
  541. RadioButton {
  542. id: singleModeRadio
  543. text: "Single"
  544. font.pixelSize: 11
  545. checked: runMode === "single"
  546. onClicked: {
  547. runMode = "single"
  548. if (backend) backend.setPlaylistRunMode("single")
  549. }
  550. contentItem: Text {
  551. text: parent.text
  552. font: parent.font
  553. color: Components.ThemeManager.textPrimary
  554. verticalAlignment: Text.AlignVCenter
  555. leftPadding: parent.indicator.width + parent.spacing
  556. }
  557. }
  558. RadioButton {
  559. id: loopModeRadio
  560. text: "Loop"
  561. font.pixelSize: 11
  562. checked: runMode === "loop"
  563. onClicked: {
  564. runMode = "loop"
  565. if (backend) backend.setPlaylistRunMode("loop")
  566. }
  567. contentItem: Text {
  568. text: parent.text
  569. font: parent.font
  570. color: Components.ThemeManager.textPrimary
  571. verticalAlignment: Text.AlignVCenter
  572. leftPadding: parent.indicator.width + parent.spacing
  573. }
  574. }
  575. }
  576. }
  577. // Pause Between Patterns
  578. Column {
  579. Layout.fillWidth: true
  580. spacing: 15
  581. Label {
  582. text: "Pause between patterns:"
  583. font.pixelSize: 12
  584. color: Components.ThemeManager.textSecondary
  585. font.bold: true
  586. }
  587. // Touch-friendly button row for pause options
  588. RowLayout {
  589. id: pauseGrid
  590. Layout.fillWidth: true
  591. spacing: 8
  592. property string currentSelection: backend ? backend.getCurrentPauseOption() : "0s"
  593. // 0s button
  594. Rectangle {
  595. Layout.preferredWidth: 60
  596. Layout.preferredHeight: 40
  597. color: pauseGrid.currentSelection === "0s" ? Components.ThemeManager.selectedBackground : Components.ThemeManager.buttonBackground
  598. border.color: pauseGrid.currentSelection === "0s" ? Components.ThemeManager.selectedBorder : Components.ThemeManager.buttonBorder
  599. border.width: 2
  600. radius: 8
  601. Label {
  602. anchors.centerIn: parent
  603. text: "0s"
  604. font.pixelSize: 12
  605. font.bold: true
  606. color: pauseGrid.currentSelection === "0s" ? "white" : Components.ThemeManager.textPrimary
  607. }
  608. MouseArea {
  609. anchors.fill: parent
  610. onClicked: {
  611. if (backend) {
  612. backend.setPauseByOption("0s")
  613. pauseGrid.currentSelection = "0s"
  614. pauseTime = 0
  615. }
  616. }
  617. }
  618. }
  619. // 1 min button
  620. Rectangle {
  621. Layout.preferredWidth: 60
  622. Layout.preferredHeight: 40
  623. color: pauseGrid.currentSelection === "1 min" ? Components.ThemeManager.selectedBackground : Components.ThemeManager.buttonBackground
  624. border.color: pauseGrid.currentSelection === "1 min" ? Components.ThemeManager.selectedBorder : Components.ThemeManager.buttonBorder
  625. border.width: 2
  626. radius: 8
  627. Label {
  628. anchors.centerIn: parent
  629. text: "1m"
  630. font.pixelSize: 12
  631. font.bold: true
  632. color: pauseGrid.currentSelection === "1 min" ? "white" : Components.ThemeManager.textPrimary
  633. }
  634. MouseArea {
  635. anchors.fill: parent
  636. onClicked: {
  637. if (backend) {
  638. backend.setPauseByOption("1 min")
  639. pauseGrid.currentSelection = "1 min"
  640. pauseTime = 60
  641. }
  642. }
  643. }
  644. }
  645. // 5 min button
  646. Rectangle {
  647. Layout.preferredWidth: 60
  648. Layout.preferredHeight: 40
  649. color: pauseGrid.currentSelection === "5 min" ? Components.ThemeManager.selectedBackground : Components.ThemeManager.buttonBackground
  650. border.color: pauseGrid.currentSelection === "5 min" ? Components.ThemeManager.selectedBorder : Components.ThemeManager.buttonBorder
  651. border.width: 2
  652. radius: 8
  653. Label {
  654. anchors.centerIn: parent
  655. text: "5m"
  656. font.pixelSize: 12
  657. font.bold: true
  658. color: pauseGrid.currentSelection === "5 min" ? "white" : Components.ThemeManager.textPrimary
  659. }
  660. MouseArea {
  661. anchors.fill: parent
  662. onClicked: {
  663. if (backend) {
  664. backend.setPauseByOption("5 min")
  665. pauseGrid.currentSelection = "5 min"
  666. pauseTime = 300
  667. }
  668. }
  669. }
  670. }
  671. // 15 min button
  672. Rectangle {
  673. Layout.preferredWidth: 60
  674. Layout.preferredHeight: 40
  675. color: pauseGrid.currentSelection === "15 min" ? Components.ThemeManager.selectedBackground : Components.ThemeManager.buttonBackground
  676. border.color: pauseGrid.currentSelection === "15 min" ? Components.ThemeManager.selectedBorder : Components.ThemeManager.buttonBorder
  677. border.width: 2
  678. radius: 8
  679. Label {
  680. anchors.centerIn: parent
  681. text: "15m"
  682. font.pixelSize: 12
  683. font.bold: true
  684. color: pauseGrid.currentSelection === "15 min" ? "white" : Components.ThemeManager.textPrimary
  685. }
  686. MouseArea {
  687. anchors.fill: parent
  688. onClicked: {
  689. if (backend) {
  690. backend.setPauseByOption("15 min")
  691. pauseGrid.currentSelection = "15 min"
  692. pauseTime = 900
  693. }
  694. }
  695. }
  696. }
  697. // 30 min button
  698. Rectangle {
  699. Layout.preferredWidth: 60
  700. Layout.preferredHeight: 40
  701. color: pauseGrid.currentSelection === "30 min" ? Components.ThemeManager.selectedBackground : Components.ThemeManager.buttonBackground
  702. border.color: pauseGrid.currentSelection === "30 min" ? Components.ThemeManager.selectedBorder : Components.ThemeManager.buttonBorder
  703. border.width: 2
  704. radius: 8
  705. Label {
  706. anchors.centerIn: parent
  707. text: "30m"
  708. font.pixelSize: 12
  709. font.bold: true
  710. color: pauseGrid.currentSelection === "30 min" ? "white" : Components.ThemeManager.textPrimary
  711. }
  712. MouseArea {
  713. anchors.fill: parent
  714. onClicked: {
  715. if (backend) {
  716. backend.setPauseByOption("30 min")
  717. pauseGrid.currentSelection = "30 min"
  718. pauseTime = 1800
  719. }
  720. }
  721. }
  722. }
  723. // 1 hour button
  724. Rectangle {
  725. Layout.preferredWidth: 60
  726. Layout.preferredHeight: 40
  727. color: pauseGrid.currentSelection === "1 hour" ? Components.ThemeManager.selectedBackground : Components.ThemeManager.buttonBackground
  728. border.color: pauseGrid.currentSelection === "1 hour" ? Components.ThemeManager.selectedBorder : Components.ThemeManager.buttonBorder
  729. border.width: 2
  730. radius: 8
  731. Label {
  732. anchors.centerIn: parent
  733. text: "1h"
  734. font.pixelSize: 12
  735. font.bold: true
  736. color: pauseGrid.currentSelection === "1 hour" ? "white" : Components.ThemeManager.textPrimary
  737. }
  738. MouseArea {
  739. anchors.fill: parent
  740. onClicked: {
  741. if (backend) {
  742. backend.setPauseByOption("1 hour")
  743. pauseGrid.currentSelection = "1 hour"
  744. pauseTime = 3600
  745. }
  746. }
  747. }
  748. }
  749. }
  750. // Second row for longer hour options
  751. RowLayout {
  752. Layout.fillWidth: true
  753. spacing: 8
  754. // 2h button
  755. Rectangle {
  756. Layout.preferredWidth: 60
  757. Layout.preferredHeight: 40
  758. color: pauseGrid.currentSelection === "2 hour" ? Components.ThemeManager.selectedBackground : Components.ThemeManager.buttonBackground
  759. border.color: pauseGrid.currentSelection === "2 hour" ? Components.ThemeManager.selectedBorder : Components.ThemeManager.buttonBorder
  760. border.width: 2
  761. radius: 8
  762. Label {
  763. anchors.centerIn: parent
  764. text: "2h"
  765. font.pixelSize: 12
  766. font.bold: true
  767. color: pauseGrid.currentSelection === "2 hour" ? "white" : Components.ThemeManager.textPrimary
  768. }
  769. MouseArea {
  770. anchors.fill: parent
  771. onClicked: {
  772. if (backend) {
  773. backend.setPauseByOption("2 hour")
  774. pauseGrid.currentSelection = "2 hour"
  775. pauseTime = 7200
  776. }
  777. }
  778. }
  779. }
  780. // 3h button
  781. Rectangle {
  782. Layout.preferredWidth: 60
  783. Layout.preferredHeight: 40
  784. color: pauseGrid.currentSelection === "3 hour" ? Components.ThemeManager.selectedBackground : Components.ThemeManager.buttonBackground
  785. border.color: pauseGrid.currentSelection === "3 hour" ? Components.ThemeManager.selectedBorder : Components.ThemeManager.buttonBorder
  786. border.width: 2
  787. radius: 8
  788. Label {
  789. anchors.centerIn: parent
  790. text: "3h"
  791. font.pixelSize: 12
  792. font.bold: true
  793. color: pauseGrid.currentSelection === "3 hour" ? "white" : Components.ThemeManager.textPrimary
  794. }
  795. MouseArea {
  796. anchors.fill: parent
  797. onClicked: {
  798. if (backend) {
  799. backend.setPauseByOption("3 hour")
  800. pauseGrid.currentSelection = "3 hour"
  801. pauseTime = 10800
  802. }
  803. }
  804. }
  805. }
  806. // 4h button
  807. Rectangle {
  808. Layout.preferredWidth: 60
  809. Layout.preferredHeight: 40
  810. color: pauseGrid.currentSelection === "4 hour" ? Components.ThemeManager.selectedBackground : Components.ThemeManager.buttonBackground
  811. border.color: pauseGrid.currentSelection === "4 hour" ? Components.ThemeManager.selectedBorder : Components.ThemeManager.buttonBorder
  812. border.width: 2
  813. radius: 8
  814. Label {
  815. anchors.centerIn: parent
  816. text: "4h"
  817. font.pixelSize: 12
  818. font.bold: true
  819. color: pauseGrid.currentSelection === "4 hour" ? "white" : Components.ThemeManager.textPrimary
  820. }
  821. MouseArea {
  822. anchors.fill: parent
  823. onClicked: {
  824. if (backend) {
  825. backend.setPauseByOption("4 hour")
  826. pauseGrid.currentSelection = "4 hour"
  827. pauseTime = 14400
  828. }
  829. }
  830. }
  831. }
  832. // 5h button
  833. Rectangle {
  834. Layout.preferredWidth: 60
  835. Layout.preferredHeight: 40
  836. color: pauseGrid.currentSelection === "5 hour" ? Components.ThemeManager.selectedBackground : Components.ThemeManager.buttonBackground
  837. border.color: pauseGrid.currentSelection === "5 hour" ? Components.ThemeManager.selectedBorder : Components.ThemeManager.buttonBorder
  838. border.width: 2
  839. radius: 8
  840. Label {
  841. anchors.centerIn: parent
  842. text: "5h"
  843. font.pixelSize: 12
  844. font.bold: true
  845. color: pauseGrid.currentSelection === "5 hour" ? "white" : Components.ThemeManager.textPrimary
  846. }
  847. MouseArea {
  848. anchors.fill: parent
  849. onClicked: {
  850. if (backend) {
  851. backend.setPauseByOption("5 hour")
  852. pauseGrid.currentSelection = "5 hour"
  853. pauseTime = 18000
  854. }
  855. }
  856. }
  857. }
  858. // 6h button
  859. Rectangle {
  860. Layout.preferredWidth: 60
  861. Layout.preferredHeight: 40
  862. color: pauseGrid.currentSelection === "6 hour" ? Components.ThemeManager.selectedBackground : Components.ThemeManager.buttonBackground
  863. border.color: pauseGrid.currentSelection === "6 hour" ? Components.ThemeManager.selectedBorder : Components.ThemeManager.buttonBorder
  864. border.width: 2
  865. radius: 8
  866. Label {
  867. anchors.centerIn: parent
  868. text: "6h"
  869. font.pixelSize: 12
  870. font.bold: true
  871. color: pauseGrid.currentSelection === "6 hour" ? "white" : Components.ThemeManager.textPrimary
  872. }
  873. MouseArea {
  874. anchors.fill: parent
  875. onClicked: {
  876. if (backend) {
  877. backend.setPauseByOption("6 hour")
  878. pauseGrid.currentSelection = "6 hour"
  879. pauseTime = 21600
  880. }
  881. }
  882. }
  883. }
  884. // 12h button
  885. Rectangle {
  886. Layout.preferredWidth: 60
  887. Layout.preferredHeight: 40
  888. color: pauseGrid.currentSelection === "12 hour" ? Components.ThemeManager.selectedBackground : Components.ThemeManager.buttonBackground
  889. border.color: pauseGrid.currentSelection === "12 hour" ? Components.ThemeManager.selectedBorder : Components.ThemeManager.buttonBorder
  890. border.width: 2
  891. radius: 8
  892. Label {
  893. anchors.centerIn: parent
  894. text: "12h"
  895. font.pixelSize: 12
  896. font.bold: true
  897. color: pauseGrid.currentSelection === "12 hour" ? "white" : Components.ThemeManager.textPrimary
  898. }
  899. MouseArea {
  900. anchors.fill: parent
  901. onClicked: {
  902. if (backend) {
  903. backend.setPauseByOption("12 hour")
  904. pauseGrid.currentSelection = "12 hour"
  905. pauseTime = 43200
  906. }
  907. }
  908. }
  909. }
  910. // Update selection when backend changes
  911. Connections {
  912. target: backend
  913. function onPauseBetweenPatternsChanged(pause) {
  914. if (backend) {
  915. pauseGrid.currentSelection = backend.getCurrentPauseOption()
  916. pauseTime = backend.pauseBetweenPatterns
  917. }
  918. }
  919. }
  920. }
  921. }
  922. // Clear pattern
  923. Column {
  924. Layout.fillWidth: true
  925. spacing: 8
  926. Label {
  927. text: "Clear Pattern:"
  928. font.pixelSize: 12
  929. color: Components.ThemeManager.textSecondary
  930. font.bold: true
  931. }
  932. GridLayout {
  933. width: parent.width
  934. columns: 2
  935. columnSpacing: 10
  936. rowSpacing: 5
  937. RadioButton {
  938. id: adaptiveRadio
  939. text: "Adaptive"
  940. font.pixelSize: 11
  941. checked: clearPattern === "adaptive"
  942. onClicked: {
  943. clearPattern = "adaptive"
  944. if (backend) backend.setPlaylistClearPattern("adaptive")
  945. }
  946. contentItem: Text {
  947. text: parent.text
  948. font: parent.font
  949. color: Components.ThemeManager.textPrimary
  950. verticalAlignment: Text.AlignVCenter
  951. leftPadding: parent.indicator.width + parent.spacing
  952. }
  953. }
  954. RadioButton {
  955. id: clearCenterRadio
  956. text: "Clear Center"
  957. font.pixelSize: 11
  958. checked: clearPattern === "clear_center"
  959. onClicked: {
  960. clearPattern = "clear_center"
  961. if (backend) backend.setPlaylistClearPattern("clear_center")
  962. }
  963. contentItem: Text {
  964. text: parent.text
  965. font: parent.font
  966. color: Components.ThemeManager.textPrimary
  967. verticalAlignment: Text.AlignVCenter
  968. leftPadding: parent.indicator.width + parent.spacing
  969. }
  970. }
  971. RadioButton {
  972. id: clearEdgeRadio
  973. text: "Clear Edge"
  974. font.pixelSize: 11
  975. checked: clearPattern === "clear_perimeter"
  976. onClicked: {
  977. clearPattern = "clear_perimeter"
  978. if (backend) backend.setPlaylistClearPattern("clear_perimeter")
  979. }
  980. contentItem: Text {
  981. text: parent.text
  982. font: parent.font
  983. color: Components.ThemeManager.textPrimary
  984. verticalAlignment: Text.AlignVCenter
  985. leftPadding: parent.indicator.width + parent.spacing
  986. }
  987. }
  988. RadioButton {
  989. id: noneRadio
  990. text: "None"
  991. font.pixelSize: 11
  992. checked: clearPattern === "none"
  993. onClicked: {
  994. clearPattern = "none"
  995. if (backend) backend.setPlaylistClearPattern("none")
  996. }
  997. contentItem: Text {
  998. text: parent.text
  999. font: parent.font
  1000. color: Components.ThemeManager.textPrimary
  1001. verticalAlignment: Text.AlignVCenter
  1002. leftPadding: parent.indicator.width + parent.spacing
  1003. }
  1004. }
  1005. }
  1006. }
  1007. }
  1008. }
  1009. }
  1010. }
  1011. }
  1012. }
  1013. }
  1014. }
  1015. }
  1016. }
  1017. // ==================== Dialogs ====================
  1018. // Create Playlist Dialog
  1019. Popup {
  1020. id: createPlaylistDialog
  1021. modal: true
  1022. x: (parent.width - width) / 2
  1023. y: (parent.height - height) / 2
  1024. width: 320
  1025. height: 200
  1026. closePolicy: Popup.CloseOnEscape | Popup.CloseOnPressOutside
  1027. background: Rectangle {
  1028. color: Components.ThemeManager.surfaceColor
  1029. radius: 16
  1030. border.color: Components.ThemeManager.borderColor
  1031. border.width: 1
  1032. }
  1033. contentItem: ColumnLayout {
  1034. anchors.fill: parent
  1035. anchors.margins: 20
  1036. spacing: 15
  1037. Label {
  1038. text: "Create New Playlist"
  1039. font.pixelSize: 18
  1040. font.bold: true
  1041. color: Components.ThemeManager.textPrimary
  1042. Layout.alignment: Qt.AlignHCenter
  1043. }
  1044. TextField {
  1045. id: newPlaylistNameField
  1046. Layout.fillWidth: true
  1047. Layout.preferredHeight: 45
  1048. placeholderText: "Enter playlist name..."
  1049. placeholderTextColor: Components.ThemeManager.textTertiary
  1050. font.pixelSize: 14
  1051. color: Components.ThemeManager.textPrimary
  1052. background: Rectangle {
  1053. color: Components.ThemeManager.backgroundColor
  1054. radius: 8
  1055. border.color: newPlaylistNameField.activeFocus ? "#2563eb" : Components.ThemeManager.borderColor
  1056. border.width: 1
  1057. }
  1058. onAccepted: {
  1059. if (text.trim().length > 0 && backend) {
  1060. backend.createPlaylist(text.trim())
  1061. }
  1062. }
  1063. }
  1064. RowLayout {
  1065. Layout.fillWidth: true
  1066. spacing: 10
  1067. // Cancel button
  1068. Rectangle {
  1069. Layout.fillWidth: true
  1070. Layout.preferredHeight: 45
  1071. radius: 8
  1072. color: cancelCreateArea.pressed ? Components.ThemeManager.buttonBackgroundHover : Components.ThemeManager.cardColor
  1073. border.color: Components.ThemeManager.borderColor
  1074. border.width: 1
  1075. Text {
  1076. anchors.centerIn: parent
  1077. text: "Cancel"
  1078. color: Components.ThemeManager.textPrimary
  1079. font.pixelSize: 14
  1080. }
  1081. MouseArea {
  1082. id: cancelCreateArea
  1083. anchors.fill: parent
  1084. onClicked: {
  1085. newPlaylistNameField.text = ""
  1086. createPlaylistDialog.close()
  1087. }
  1088. }
  1089. }
  1090. // Create button
  1091. Rectangle {
  1092. Layout.fillWidth: true
  1093. Layout.preferredHeight: 45
  1094. radius: 8
  1095. color: createArea.pressed ? "#1e40af" : "#2563eb"
  1096. opacity: newPlaylistNameField.text.trim().length > 0 ? 1.0 : 0.5
  1097. Text {
  1098. anchors.centerIn: parent
  1099. text: "Create"
  1100. color: "white"
  1101. font.pixelSize: 14
  1102. font.bold: true
  1103. }
  1104. MouseArea {
  1105. id: createArea
  1106. anchors.fill: parent
  1107. enabled: newPlaylistNameField.text.trim().length > 0
  1108. onClicked: {
  1109. if (backend) {
  1110. backend.createPlaylist(newPlaylistNameField.text.trim())
  1111. }
  1112. }
  1113. }
  1114. }
  1115. }
  1116. }
  1117. onOpened: {
  1118. newPlaylistNameField.text = ""
  1119. newPlaylistNameField.forceActiveFocus()
  1120. }
  1121. }
  1122. // Delete Playlist Confirmation Dialog
  1123. Popup {
  1124. id: deletePlaylistDialog
  1125. modal: true
  1126. x: (parent.width - width) / 2
  1127. y: (parent.height - height) / 2
  1128. width: 320
  1129. height: 180
  1130. closePolicy: Popup.CloseOnEscape | Popup.CloseOnPressOutside
  1131. background: Rectangle {
  1132. color: Components.ThemeManager.surfaceColor
  1133. radius: 16
  1134. border.color: Components.ThemeManager.borderColor
  1135. border.width: 1
  1136. }
  1137. contentItem: ColumnLayout {
  1138. anchors.fill: parent
  1139. anchors.margins: 20
  1140. spacing: 15
  1141. Label {
  1142. text: "Delete Playlist?"
  1143. font.pixelSize: 18
  1144. font.bold: true
  1145. color: Components.ThemeManager.textPrimary
  1146. Layout.alignment: Qt.AlignHCenter
  1147. }
  1148. Label {
  1149. text: "Are you sure you want to delete\n\"" + selectedPlaylist + "\"?"
  1150. font.pixelSize: 14
  1151. color: Components.ThemeManager.textSecondary
  1152. horizontalAlignment: Text.AlignHCenter
  1153. Layout.alignment: Qt.AlignHCenter
  1154. }
  1155. RowLayout {
  1156. Layout.fillWidth: true
  1157. spacing: 10
  1158. // Cancel button
  1159. Rectangle {
  1160. Layout.fillWidth: true
  1161. Layout.preferredHeight: 45
  1162. radius: 8
  1163. color: cancelDeleteArea.pressed ? Components.ThemeManager.buttonBackgroundHover : Components.ThemeManager.cardColor
  1164. border.color: Components.ThemeManager.borderColor
  1165. border.width: 1
  1166. Text {
  1167. anchors.centerIn: parent
  1168. text: "Cancel"
  1169. color: Components.ThemeManager.textPrimary
  1170. font.pixelSize: 14
  1171. }
  1172. MouseArea {
  1173. id: cancelDeleteArea
  1174. anchors.fill: parent
  1175. onClicked: deletePlaylistDialog.close()
  1176. }
  1177. }
  1178. // Delete button
  1179. Rectangle {
  1180. Layout.fillWidth: true
  1181. Layout.preferredHeight: 45
  1182. radius: 8
  1183. color: confirmDeleteArea.pressed ? "#991b1b" : "#dc2626"
  1184. Text {
  1185. anchors.centerIn: parent
  1186. text: "Delete"
  1187. color: "white"
  1188. font.pixelSize: 14
  1189. font.bold: true
  1190. }
  1191. MouseArea {
  1192. id: confirmDeleteArea
  1193. anchors.fill: parent
  1194. onClicked: {
  1195. if (backend && selectedPlaylist) {
  1196. backend.deletePlaylist(selectedPlaylist)
  1197. }
  1198. deletePlaylistDialog.close()
  1199. }
  1200. }
  1201. }
  1202. }
  1203. }
  1204. }
  1205. // ==================== Backend Signal Handlers ====================
  1206. Connections {
  1207. target: backend
  1208. function onPlaylistCreated(success, message) {
  1209. if (success) {
  1210. playlistModel.refresh()
  1211. }
  1212. newPlaylistNameField.text = ""
  1213. createPlaylistDialog.close()
  1214. }
  1215. function onPlaylistDeleted(success, message) {
  1216. if (success) {
  1217. playlistModel.refresh()
  1218. showPlaylistList() // Navigate back to list
  1219. }
  1220. }
  1221. function onPatternAddedToPlaylist(success, message) {
  1222. if (success) {
  1223. playlistModel.refresh()
  1224. // Refresh current playlist patterns if we're viewing one
  1225. if (selectedPlaylist) {
  1226. currentPlaylistPatterns = playlistModel.getPatternsForPlaylist(selectedPlaylist)
  1227. currentPlaylistRawPatterns = playlistModel.getRawPatternsForPlaylist(selectedPlaylist)
  1228. }
  1229. }
  1230. }
  1231. function onPlaylistModified(success, message) {
  1232. if (success) {
  1233. playlistModel.refresh()
  1234. // Refresh current playlist patterns
  1235. if (selectedPlaylist) {
  1236. currentPlaylistPatterns = playlistModel.getPatternsForPlaylist(selectedPlaylist)
  1237. currentPlaylistRawPatterns = playlistModel.getRawPatternsForPlaylist(selectedPlaylist)
  1238. }
  1239. }
  1240. }
  1241. }
  1242. }