VolumeSlider.qml 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. import QtQuick 2.0
  2. Rectangle {
  3. id: root
  4. width: 6
  5. property real value: 0.3
  6. property bool sellected: _mouse.containsMouse | _mouse.pressed
  7. signal seek(real value)
  8. color: "#404040"
  9. radius: width / 2
  10. Rectangle {
  11. id: _progress
  12. anchors.left: root.left
  13. anchors.bottom: root.bottom
  14. height: root.height * value + width * (0.5 - Math.abs(value - 0.5))
  15. width: root.width
  16. radius: root.radius
  17. color: sellected? "#FCE165" : "#AAAAAA"
  18. }
  19. Rectangle {
  20. id: _point
  21. visible: root.sellected
  22. width: 16
  23. height: 16
  24. radius: height / 2
  25. anchors.horizontalCenter: root.horizontalCenter
  26. anchors.verticalCenter: _progress.top
  27. anchors.verticalCenterOffset: root.width * (0.5 - Math.abs(value - 0.5))
  28. color: "#FFFFFF"
  29. }
  30. Rectangle {
  31. height: 1
  32. width: 4
  33. anchors.verticalCenter: root.verticalCenter
  34. anchors.left: _point.right
  35. anchors.leftMargin: 1
  36. color: Math.abs(value - 0.5) > 0.04? "#C4C4C4" : "#505050"
  37. }
  38. Rectangle {
  39. height: 1
  40. width: 4
  41. anchors.verticalCenter: root.verticalCenter
  42. anchors.right: _point.left
  43. anchors.rightMargin: 1
  44. color: Math.abs(value - 0.5) > 0.04? "#C4C4C4" : "#505050"
  45. }
  46. MouseArea {
  47. id: _mouse
  48. anchors.centerIn: root
  49. width: Math.max(root.width, _point.width)
  50. height: root.height + _point.height
  51. hoverEnabled: true
  52. onMouseXChanged: {
  53. if (pressed) {
  54. var value = 1 - (mouseY - _point.height / 2) / root.height
  55. value = Math.max(0, Math.min(1, value))
  56. root.seek(value)
  57. }
  58. }
  59. onWheel: {
  60. root.seek(value + 0.05 * wheel.angleDelta.y / 120)
  61. }
  62. }
  63. }