VolumeSlider.qml 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. opacity: 0.3
  27. color: "#000000"
  28. source: _point
  29. }
  30. Rectangle {
  31. id: _point
  32. visible: root.sellected
  33. width: 16
  34. height: 16
  35. radius: height / 2
  36. anchors.horizontalCenter: root.horizontalCenter
  37. anchors.verticalCenter: _progress.top
  38. anchors.verticalCenterOffset: root.width * (0.5 - Math.abs(value - 0.5))
  39. color: "#FFFFFF"
  40. }
  41. Rectangle {
  42. height: 1
  43. width: 4
  44. anchors.verticalCenter: root.verticalCenter
  45. anchors.left: _point.right
  46. anchors.leftMargin: 1
  47. color: Math.abs(value - 0.5) > 0.04? (Style.darkHeader? "#C4C4C4" : "#505050") : (Style.darkHeader? "#505050" : "#AAAAAA")
  48. }
  49. Rectangle {
  50. height: 1
  51. width: 4
  52. anchors.verticalCenter: root.verticalCenter
  53. anchors.right: _point.left
  54. anchors.rightMargin: 1
  55. color: Math.abs(value - 0.5) > 0.04? (Style.darkHeader? "#C4C4C4" : "#505050") : (Style.darkHeader? "#505050" : "#AAAAAA")
  56. }
  57. MouseArea {
  58. id: _mouse
  59. anchors.centerIn: root
  60. width: Math.max(root.width, _point.width)
  61. height: root.height + _point.height
  62. hoverEnabled: true
  63. onMouseXChanged: {
  64. if (pressed) {
  65. var value = 1 - (mouseY - _point.height / 2) / root.height
  66. value = Math.max(0, Math.min(1, value))
  67. root.seek(value)
  68. }
  69. }
  70. onWheel: {
  71. root.seek(value + 0.05 * wheel.angleDelta.y / 120)
  72. }
  73. }
  74. }