ScrollBar.qml 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /**
  2. * Copyright (c) 2011 Nokia Corporation.
  3. */
  4. import QtQuick 1.0
  5. Item {
  6. id: scrollBar
  7. property Flickable flickableItem: null
  8. property int defaultWidth: 5
  9. property real defaultOpacity: 0.5
  10. anchors {
  11. fill: flickableItem
  12. margins: defaultWidth
  13. }
  14. clip: true
  15. Rectangle {
  16. id: barRect
  17. x: parent.width - width
  18. y: parent.height * (flickableItem ? flickableItem.contentY : 0)
  19. / (flickableItem ? flickableItem.contentHeight : 1);
  20. width: scrollBar.defaultWidth
  21. height: flickableItem.visibleArea.heightRatio * flickableItem.height
  22. opacity: defaultOpacity
  23. color: "#8855ff"
  24. Behavior on opacity { NumberAnimation { duration: 100 } }
  25. Connections {
  26. target: flickableItem
  27. onMovementStarted: {
  28. if (hideTimer.running) {
  29. hideTimer.stop();
  30. }
  31. barRect.opacity = scrollBar.defaultOpacity;
  32. }
  33. onMovementEnded: hideTimer.restart();
  34. }
  35. Timer {
  36. id: hideTimer
  37. repeat: false
  38. running: false
  39. interval: 750
  40. onTriggered: barRect.opacity = 0;
  41. }
  42. }
  43. Component.onCompleted: hideTimer.start();
  44. }