Tumbler.qml 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. // Copyright (C) 2017 The Qt Company Ltd.
  2. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
  3. // Qt-Security score:significant reason:default
  4. import QtQuick
  5. import QtQuick.Templates as T
  6. import QtQuick.Controls.impl
  7. import QtQuick.Controls.Imagine
  8. import QtQuick.Controls.Imagine.impl
  9. T.Tumbler {
  10. id: control
  11. implicitWidth: Math.max(implicitBackgroundWidth + leftInset + rightInset,
  12. implicitContentWidth + leftPadding + rightPadding)
  13. implicitHeight: Math.max(implicitBackgroundHeight + topInset + bottomInset,
  14. implicitContentHeight + topPadding + bottomPadding)
  15. topInset: background ? -background.topInset || 0 : 0
  16. leftInset: background ? -background.leftInset || 0 : 0
  17. rightInset: background ? -background.rightInset || 0 : 0
  18. bottomInset: background ? -background.bottomInset || 0 : 0
  19. readonly property real __delegateHeight: availableHeight / visibleItemCount
  20. delegate: Text {
  21. text: modelData
  22. font: control.font
  23. color: control.palette.text
  24. opacity: (1.0 - Math.abs(Tumbler.displacement) / (control.visibleItemCount / 2)) * (control.enabled ? 1 : 0.6)
  25. horizontalAlignment: Text.AlignHCenter
  26. verticalAlignment: Text.AlignVCenter
  27. required property var modelData
  28. required property int index
  29. }
  30. contentItem: TumblerView {
  31. implicitWidth: 60
  32. implicitHeight: 200
  33. model: control.model
  34. delegate: control.delegate
  35. path: Path {
  36. startX: control.contentItem.width / 2
  37. startY: -control.__delegateHeight / 2
  38. PathLine {
  39. x: control.contentItem.width / 2
  40. y: (control.visibleItemCount + 1) * control.__delegateHeight - control.__delegateHeight / 2
  41. }
  42. }
  43. property real delegateHeight: control.availableHeight / control.visibleItemCount
  44. }
  45. background: NinePatchImage {
  46. source: Imagine.url + "tumbler-background"
  47. NinePatchImageSelector on source {
  48. states: [
  49. {"disabled": !control.enabled},
  50. {"focused": control.visualFocus},
  51. {"mirrored": control.mirrored},
  52. {"hovered": control.enabled && control.hovered}
  53. ]
  54. }
  55. }
  56. }