FlickPager.qml 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. import QtQuick 2.0
  2. Item {
  3. id: root
  4. property Component content: null
  5. property color color: "#ffffffff"
  6. property alias flickable: flick
  7. QtObject {
  8. id: d
  9. property Item flickItem: null
  10. }
  11. Flickable {
  12. id: flick
  13. anchors.top: arrowUp.bottom
  14. anchors.bottom:arrowDown.top
  15. anchors.left: parent.left
  16. anchors.right: parent.right
  17. contentWidth: d.flickItem.width
  18. contentHeight: d.flickItem.height
  19. }
  20. FlickPagerArrow {
  21. id: arrowUp
  22. anchors.top: parent.top
  23. source: "arrow-141-16"
  24. active: flick.contentY > 0 && root.height > 0
  25. onClicked: {
  26. flick.contentY -= (flick.contentY - flick.height) < 0 ? flick.contentY : flick.height
  27. }
  28. gradient: Gradient {
  29. GradientStop { position: 0.0; color: root.color }
  30. GradientStop { position: 0.8; color: root.color }
  31. GradientStop { position: 1.0; color: "#00ffffff" }
  32. }
  33. }
  34. FlickPagerArrow {
  35. id: arrowDown
  36. anchors.bottom: parent.bottom
  37. source: "arrow-203-16"
  38. active: flick.contentY < (flick.contentHeight - flick.height) && root.height > 0
  39. onClicked: {
  40. flick.contentY += (flick.contentY + flick.height*2) >= flick.contentHeight ? flick.contentHeight - flick.contentY - flick.height : flick.height
  41. }
  42. gradient: Gradient {
  43. GradientStop { position: 0.0; color: "#00ffffff" }
  44. GradientStop { position: 0.2; color: root.color }
  45. GradientStop { position: 1.0; color: root.color }
  46. }
  47. }
  48. onContentChanged: {
  49. if(d.flickItem != null) {
  50. d.flickItem.destroy()
  51. }
  52. if(content != null) {
  53. d.flickItem = content.createObject(flick.contentItem)
  54. }
  55. }
  56. }