CheckDelegate.qml 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. // Copyright (C) 2023 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
  7. import QtQuick.Controls.impl
  8. import QtQuick.NativeStyle as NativeStyle
  9. T.CheckDelegate {
  10. id: control
  11. readonly property bool __nativeIndicator: indicator instanceof NativeStyle.StyleItem
  12. readonly property bool __notCustomizable: true
  13. readonly property Item __focusFrameTarget: indicator
  14. readonly property Item __focusFrameStyleItem: indicator
  15. implicitWidth: Math.max(implicitBackgroundWidth + leftInset + rightInset,
  16. implicitContentWidth + leftPadding + rightPadding)
  17. implicitHeight: Math.max(implicitBackgroundHeight + topInset + bottomInset,
  18. implicitContentHeight + topPadding + bottomPadding,
  19. implicitIndicatorHeight + topPadding + bottomPadding)
  20. spacing: 6
  21. padding: 6
  22. contentItem: NativeStyle.DefaultItemDelegateIconLabel {
  23. color: control.highlighted ? control.palette.button : control.palette.windowText
  24. readonly property bool __ignoreNotCustomizable: true
  25. }
  26. indicator: NativeStyle.CheckDelegate {
  27. x: control.text
  28. ? (control.mirrored ? control.leftPadding : control.width - width - control.rightPadding)
  29. : control.leftPadding + (control.availableWidth - width) / 2
  30. // The rendering gets messed up when rendering on sub-pixel positions.
  31. y: control.topPadding + Math.round((control.availableHeight - height) / 2)
  32. contentWidth: control.implicitContentWidth
  33. contentHeight: control.implicitContentHeight
  34. control: control
  35. useNinePatchImage: false
  36. overrideState: NativeStyle.StyleItem.NeverHovered
  37. readonly property bool __ignoreNotCustomizable: true
  38. }
  39. NativeStyle.CheckDelegate {
  40. id: hoverCheckDelegate
  41. control: control
  42. x: control.indicator.x
  43. y: control.indicator.y
  44. z: control.indicator.z + 1
  45. width: control.indicator.width
  46. height: control.indicator.height
  47. useNinePatchImage: false
  48. overrideState: NativeStyle.StyleItem.AlwaysHovered
  49. opacity: control.hovered ? 1 : 0
  50. visible: opacity !== 0
  51. Behavior on opacity {
  52. NumberAnimation {
  53. duration: hoverCheckDelegate.transitionDuration
  54. }
  55. }
  56. }
  57. background: Rectangle {
  58. implicitWidth: 100
  59. implicitHeight: 20
  60. color: Qt.darker(control.highlighted
  61. ? control.palette.highlight : control.palette.button, control.down ? 1.05 : 1)
  62. readonly property bool __ignoreNotCustomizable: true
  63. }
  64. }