Tumbler.qml 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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.Universal
  7. import QtQuick.Controls.impl
  8. T.Tumbler {
  9. id: control
  10. implicitWidth: Math.max(implicitBackgroundWidth + leftInset + rightInset,
  11. implicitContentWidth + leftPadding + rightPadding)
  12. implicitHeight: Math.max(implicitBackgroundHeight + topInset + bottomInset,
  13. implicitContentHeight + topPadding + bottomPadding)
  14. readonly property real __delegateHeight: availableHeight / visibleItemCount
  15. delegate: Text {
  16. text: modelData
  17. font: control.font
  18. color: control.Universal.foreground
  19. opacity: (1.0 - Math.abs(Tumbler.displacement) / (control.visibleItemCount / 2)) * (control.enabled ? 1 : 0.6)
  20. horizontalAlignment: Text.AlignHCenter
  21. verticalAlignment: Text.AlignVCenter
  22. required property var modelData
  23. required property int index
  24. }
  25. contentItem: TumblerView {
  26. implicitWidth: 60
  27. implicitHeight: 200
  28. model: control.model
  29. delegate: control.delegate
  30. path: Path {
  31. startX: control.contentItem.width / 2
  32. startY: -control.__delegateHeight / 2
  33. PathLine {
  34. x: control.contentItem.width / 2
  35. y: (control.visibleItemCount + 1) * control.__delegateHeight - control.__delegateHeight / 2
  36. }
  37. }
  38. property real delegateHeight: control.availableHeight / control.visibleItemCount
  39. }
  40. }