SwipeDelegate.qml 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. // Copyright (C) 2024 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. T.SwipeDelegate {
  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. implicitIndicatorHeight + topPadding + bottomPadding)
  14. spacing: __config.spacing || 0
  15. topPadding: __config.topPadding || 0
  16. leftPadding: __config.leftPadding || 0
  17. rightPadding: __config.rightPadding || 0
  18. bottomPadding: __config.bottomPadding || 0
  19. icon.width: 16
  20. icon.height: 16
  21. readonly property string __currentState: [
  22. !control.enabled && "disabled",
  23. control.highlighted && "highlighted",
  24. control.enabled && !control.down && control.hovered && "hovered",
  25. control.down && "pressed"
  26. ].filter(Boolean).join("_") || "normal"
  27. readonly property var __config: Config.controls.itemdelegate[__currentState] || {}
  28. readonly property Item __focusFrameTarget: control
  29. swipe.transition: Transition { SmoothedAnimation { duration: 167; easing.type: Easing.OutCubic } }
  30. contentItem: IconLabel {
  31. spacing: control.spacing
  32. mirrored: control.mirrored
  33. display: control.display
  34. alignment: control.display === IconLabel.IconOnly || control.display === IconLabel.TextUnderIcon ? Qt.AlignCenter : Qt.AlignLeft
  35. icon: control.icon
  36. defaultIconColor: control.down ? pressedText : control.palette.buttonText
  37. text: control.text
  38. font: control.font
  39. color: defaultIconColor
  40. readonly property color pressedText: Application.styleHints.colorScheme === Qt.Light
  41. ? Color.transparent(control.palette.buttonText, 0.62)
  42. : Color.transparent(control.palette.buttonText, 0.7725)
  43. }
  44. background: Rectangle {
  45. implicitWidth: control.__config.background.width
  46. implicitHeight: control.__config.background.height
  47. readonly property bool lightScheme: Application.styleHints.colorScheme === Qt.Light
  48. readonly property color bakcgroundColorTint: control.down
  49. ? lightScheme ? Color.transparent("black", 0.02) : Color.transparent("white", 0.04)
  50. : control.hovered || control.highlighted
  51. ? lightScheme ? Color.transparent("black", 0.04) : Color.transparent("white", 0.06)
  52. : "transparent"
  53. color: Qt.tint(control.palette.window, bakcgroundColorTint)
  54. }
  55. }