VolumeSlider.qml 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. import QtQuick 2.15
  2. import QtGraphicalEffects 1.15
  3. import DMusic 1.0
  4. Rectangle {
  5. id: root
  6. width: 6
  7. property real value: 0.3
  8. property bool sellected: _mouse.containsMouse | _mouse.pressed
  9. signal seek(real value)
  10. color: Style.panel.item.background
  11. radius: width / 2
  12. Rectangle {
  13. id: _progress
  14. anchors.left: root.left
  15. anchors.bottom: root.bottom
  16. height: root.height * value + width * (0.5 - Math.abs(value - 0.5))
  17. width: root.width
  18. radius: root.radius
  19. color: sellected? Style.panel.accent : Style.panel.item.foreground
  20. }
  21. DropShadow {
  22. visible: root.sellected && Style.panel.item.dropShadow
  23. anchors.fill: _point
  24. radius: 3.0
  25. samples: 7
  26. transparentBorder: true
  27. opacity: 0.3
  28. color: "#000000"
  29. source: _point
  30. }
  31. Rectangle {
  32. id: _point
  33. visible: root.sellected
  34. width: 16
  35. height: 16
  36. radius: height / 2
  37. anchors.horizontalCenter: root.horizontalCenter
  38. anchors.verticalCenter: _progress.top
  39. anchors.verticalCenterOffset: root.width * (0.5 - Math.abs(value - 0.5))
  40. color: "#FFFFFF"
  41. }
  42. Rectangle {
  43. height: 1
  44. width: 4
  45. anchors.verticalCenter: root.verticalCenter
  46. anchors.left: _point.right
  47. anchors.leftMargin: 1
  48. color: Math.abs(value - 0.5) > 0.04? (Style.darkHeader? "#C4C4C4" : "#505050") : (Style.darkHeader? "#505050" : "#AAAAAA")
  49. }
  50. Rectangle {
  51. height: 1
  52. width: 4
  53. anchors.verticalCenter: root.verticalCenter
  54. anchors.right: _point.left
  55. anchors.rightMargin: 1
  56. color: Math.abs(value - 0.5) > 0.04? (Style.darkHeader? "#C4C4C4" : "#505050") : (Style.darkHeader? "#505050" : "#AAAAAA")
  57. }
  58. MouseArea {
  59. id: _mouse
  60. anchors.centerIn: root
  61. width: Math.max(root.width, _point.width)
  62. height: root.height + _point.height
  63. hoverEnabled: true
  64. onMouseXChanged: {
  65. if (pressed) {
  66. var value = 1 - (mouseY - _point.height / 2) / root.height
  67. value = Math.max(0, Math.min(1, value))
  68. root.seek(value)
  69. }
  70. }
  71. onWheel: {
  72. root.seek(value + 0.05 * wheel.angleDelta.y / 120)
  73. }
  74. }
  75. }