main.qml 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. import QtQuick 2.15
  2. import QtQuick.Window 2.15
  3. import QtGraphicalEffects 1.15
  4. import DMusic 1.0
  5. import "pages"
  6. Window {
  7. id: _window
  8. visible: true
  9. flags: Config.csd? Qt.FramelessWindowHint | Qt.Window : Qt.Window
  10. width: 1280 + 20
  11. height: 720 + 20
  12. minimumWidth: 520 + shadowRadius * 2
  13. minimumHeight: 300 + shadowRadius * 2
  14. property real shadowRadius: (Config.csd && !maximized)? 10 : 0
  15. property bool maximized: visibility == 4
  16. property bool needReadWH: false
  17. title: "DMusic"
  18. function updateConfigWidth() { Config.width = _window.width - _window.shadowRadius * 2 }
  19. function updateConfigHeight() { Config.height = _window.height - _window.shadowRadius * 2 }
  20. function maximize() {
  21. visibility = visibility == 2 ? 4 : 2
  22. }
  23. function minimize() {
  24. _window.showMinimized()
  25. }
  26. color: "transparent"
  27. Component.onCompleted: {
  28. if (Config.width == Screen.desktopAvailableWidth && Config.height == Screen.desktopAvailableHeight) {
  29. visibility = 4
  30. } else {
  31. _window.width = Config.width + shadowRadius * 2
  32. _window.height = Config.height + shadowRadius * 2
  33. }
  34. widthChanged.connect(updateConfigWidth)
  35. heightChanged.connect(updateConfigHeight)
  36. }
  37. DropShadow {
  38. anchors.fill: _root
  39. enabled: Config.csd && !maximized
  40. opacity: 0.6
  41. samples: 20
  42. radius: shadowRadius
  43. transparentBorder: true
  44. color: "#000000"
  45. source: Rectangle {
  46. width: _root.width
  47. height: _root.height
  48. color: "#000000"
  49. radius: 7.5
  50. }
  51. }
  52. Rectangle {
  53. id: _root
  54. width: _window.width - shadowRadius * 2
  55. height: _window.height - shadowRadius * 2
  56. x: shadowRadius
  57. y: shadowRadius
  58. color: Style.window.background
  59. focus: true
  60. MouseArea {
  61. anchors.fill: parent
  62. onClicked: _root.focus = true
  63. }
  64. PageSwitcher {
  65. id: _pages
  66. anchors.left: _root.left
  67. anchors.top: _title.bottom
  68. anchors.right: _root.right
  69. anchors.bottom: _player.top
  70. }
  71. Title {
  72. id: _title
  73. width: _root.width
  74. windowSize: Qt.size(_root.width, _root.height)
  75. clientSideDecorations: Config.csd
  76. maximized: _window.maximized
  77. }
  78. ListModel {
  79. id: _messages
  80. }
  81. Column {
  82. spacing: 15
  83. anchors.bottom: _player.top
  84. anchors.bottomMargin: 15
  85. anchors.horizontalCenter: parent.horizontalCenter
  86. add: Transition {
  87. NumberAnimation { property: "opacity"; from: 0; to: 1; duration: 200 }
  88. }
  89. Repeater {
  90. model: _messages
  91. Message {
  92. text: elementText
  93. details: elementDetails
  94. isError: elementIsError
  95. anchors.horizontalCenter: parent.horizontalCenter
  96. onClosed: _messages.remove(index)
  97. }
  98. }
  99. }
  100. Messages {
  101. id: _messagesReciever
  102. onMessage: _messages.append({ "elementText": text, "elementDetails": details, "elementIsError": false })
  103. onError: _messages.append({ "elementText": text, "elementDetails": details, "elementIsError": true })
  104. Component.onCompleted: init()
  105. }
  106. Player {
  107. id: _player
  108. width: _root.width
  109. height: 66
  110. anchors.bottom: parent.bottom
  111. }
  112. Rectangle {
  113. visible: !Style.darkHeader
  114. height: Style.window.border.width
  115. anchors.left: _player.left
  116. anchors.right: _player.right
  117. anchors.verticalCenter: _player.top
  118. color: Style.window.border.color
  119. }
  120. Shortcut { sequence: "Space"; onActivated: AudioPlayer.playing? AudioPlayer.pause() : AudioPlayer.play(); context: Qt.ApplicationShortcut }
  121. Shortcut { sequence: "Right"; onActivated: AudioPlayer.next(); context: Qt.ApplicationShortcut }
  122. Shortcut { sequence: "Left"; onActivated: AudioPlayer.prev(); context: Qt.ApplicationShortcut }
  123. Shortcut { sequence: "D"; onActivated: AudioPlayer.next(); context: Qt.ApplicationShortcut }
  124. Shortcut { sequence: "A"; onActivated: AudioPlayer.prev(); context: Qt.ApplicationShortcut }
  125. Shortcut { sequence: "Ctrl+S"; onActivated: PlayingTrackInfo.save(); context: Qt.ApplicationShortcut }
  126. Shortcut { sequence: "Up"; onActivated: AudioPlayer.volume += 0.05; context: Qt.ApplicationShortcut }
  127. Shortcut { sequence: "Down"; onActivated: AudioPlayer.volume -= 0.05; context: Qt.ApplicationShortcut }
  128. Shortcut { sequence: "M"; onActivated: AudioPlayer.muted = !AudioPlayer.muted; context: Qt.ApplicationShortcut }
  129. Shortcut { sequence: "S"; onActivated: AudioPlayer.shuffle = !AudioPlayer.shuffle; context: Qt.ApplicationShortcut }
  130. Shortcut { sequence: "C"; onActivated: AudioPlayer.loop = (AudioPlayer.loop + 1) % 3; context: Qt.ApplicationShortcut }
  131. Shortcut { sequence: "Ctrl+Y"; onActivated: Qt.openUrlExternally(PlayingTrackInfo.page); context: Qt.ApplicationShortcut }
  132. layer.enabled: Config.csd && visibility != 4
  133. layer.effect: OpacityMask {
  134. maskSource: Rectangle {
  135. width: _root.width
  136. height: _root.height
  137. radius: 7.5
  138. }
  139. }
  140. }
  141. }