CheckDelegate.qml 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. icon.width: 16
  23. icon.height: 16
  24. contentItem: NativeStyle.DefaultItemDelegateIconLabel {
  25. color: control.highlighted ? control.palette.button : control.palette.windowText
  26. readonly property bool __ignoreNotCustomizable: true
  27. }
  28. indicator: NativeStyle.CheckDelegate {
  29. x: control.text
  30. ? (control.mirrored ? control.leftPadding : control.width - width - control.rightPadding)
  31. : control.leftPadding + (control.availableWidth - width) / 2
  32. // The rendering gets messed up when rendering on sub-pixel positions.
  33. y: control.topPadding + Math.round((control.availableHeight - height) / 2)
  34. contentWidth: control.implicitContentWidth
  35. contentHeight: control.implicitContentHeight
  36. control: control
  37. useNinePatchImage: false
  38. overrideState: NativeStyle.StyleItem.NeverHovered
  39. readonly property bool __ignoreNotCustomizable: true
  40. }
  41. NativeStyle.CheckDelegate {
  42. id: hoverCheckDelegate
  43. control: control
  44. x: control.indicator.x
  45. y: control.indicator.y
  46. z: control.indicator.z + 1
  47. width: control.indicator.width
  48. height: control.indicator.height
  49. useNinePatchImage: false
  50. overrideState: NativeStyle.StyleItem.AlwaysHovered
  51. opacity: control.hovered ? 1 : 0
  52. visible: opacity !== 0
  53. Behavior on opacity {
  54. NumberAnimation {
  55. duration: hoverCheckDelegate.transitionDuration
  56. }
  57. }
  58. }
  59. background: Rectangle {
  60. implicitWidth: 100
  61. implicitHeight: 20
  62. color: Qt.darker(control.highlighted
  63. ? control.palette.highlight : control.palette.button, control.down ? 1.05 : 1)
  64. readonly property bool __ignoreNotCustomizable: true
  65. }
  66. }