Tumbler.qml 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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.Controls.impl
  6. import QtQuick.Templates as T
  7. T.Tumbler {
  8. id: control
  9. implicitWidth: Math.max(implicitBackgroundWidth + leftInset + rightInset,
  10. implicitContentWidth + leftPadding + rightPadding)
  11. implicitHeight: Math.max(implicitBackgroundHeight + topInset + bottomInset,
  12. implicitContentHeight + topPadding + bottomPadding)
  13. readonly property real __delegateHeight: availableHeight / visibleItemCount
  14. delegate: Text {
  15. text: modelData
  16. color: control.visualFocus ? control.palette.highlight : control.palette.text
  17. font: control.font
  18. opacity: 1.0 - Math.abs(Tumbler.displacement) / (control.visibleItemCount / 2)
  19. horizontalAlignment: Text.AlignHCenter
  20. verticalAlignment: Text.AlignVCenter
  21. // We use required property here to satisfy qmllint, but that means
  22. // we also need to declare the index for the attached properties
  23. // (see QQuickTumblerAttachedPrivate::init).
  24. required property var modelData
  25. required property int index
  26. }
  27. contentItem: TumblerView {
  28. implicitWidth: 60
  29. implicitHeight: 200
  30. model: control.model
  31. delegate: control.delegate
  32. path: Path {
  33. startX: control.contentItem.width / 2
  34. startY: -control.__delegateHeight / 2
  35. PathLine {
  36. x: control.contentItem.width / 2
  37. y: (control.visibleItemCount + 1) * control.__delegateHeight - control.__delegateHeight / 2
  38. }
  39. }
  40. }
  41. background: Rectangle {
  42. visible: Qt.styleHints.accessibility.contrastPreference === Qt.HighContrast
  43. border.color: control.visualFocus ? control.palette.highlight : control.palette.windowText
  44. border.width: control.visualFocus ? 2 : 1
  45. }
  46. }