CheckDelegate.qml 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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.impl
  7. import QtQuick.Controls.Imagine
  8. import QtQuick.Controls.Imagine.impl
  9. T.CheckDelegate {
  10. id: control
  11. implicitWidth: Math.max(implicitBackgroundWidth + leftInset + rightInset,
  12. implicitContentWidth + leftPadding + rightPadding)
  13. implicitHeight: Math.max(implicitBackgroundHeight + topInset + bottomInset,
  14. implicitContentHeight + topPadding + bottomPadding,
  15. implicitIndicatorHeight + topPadding + bottomPadding)
  16. spacing: 12 // ###
  17. topPadding: background ? background.topPadding : 0
  18. leftPadding: background ? background.leftPadding : 0
  19. rightPadding: background ? background.rightPadding : 0
  20. bottomPadding: background ? background.bottomPadding : 0
  21. topInset: background ? -background.topInset || 0 : 0
  22. leftInset: background ? -background.leftInset || 0 : 0
  23. rightInset: background ? -background.rightInset || 0 : 0
  24. bottomInset: background ? -background.bottomInset || 0 : 0
  25. icon.width: 24
  26. icon.height: 24
  27. icon.color: control.palette.text
  28. indicator: Image {
  29. x: control.mirrored ? control.leftPadding : control.width - width - control.rightPadding
  30. y: control.topPadding + (control.availableHeight - height) / 2
  31. source: Imagine.url + "checkdelegate-indicator"
  32. ImageSelector on source {
  33. states: [
  34. {"disabled": !control.enabled},
  35. {"pressed": control.down},
  36. {"checked": control.checkState === Qt.Checked},
  37. {"partially-checked": control.checkState === Qt.PartiallyChecked},
  38. {"focused": control.visualFocus},
  39. {"highlighted": control.highlighted},
  40. {"mirrored": control.mirrored},
  41. {"hovered": control.enabled && control.hovered}
  42. ]
  43. }
  44. }
  45. contentItem: IconLabel {
  46. leftPadding: control.mirrored ? control.indicator.width + control.spacing : 0
  47. rightPadding: !control.mirrored ? control.indicator.width + control.spacing : 0
  48. spacing: control.spacing
  49. mirrored: control.mirrored
  50. display: control.display
  51. alignment: control.display === IconLabel.IconOnly || control.display === IconLabel.TextUnderIcon ? Qt.AlignCenter : Qt.AlignLeft
  52. icon: control.icon
  53. text: control.text
  54. font: control.font
  55. color: control.palette.text
  56. }
  57. background: NinePatchImage {
  58. source: Imagine.url + "checkdelegate-background"
  59. NinePatchImageSelector on source {
  60. states: [
  61. {"disabled": !control.enabled},
  62. {"pressed": control.down},
  63. {"checked": control.checkState === Qt.Checked},
  64. {"partially-checked": control.checkState === Qt.PartiallyChecked},
  65. {"focused": control.visualFocus},
  66. {"highlighted": control.highlighted},
  67. {"mirrored": control.mirrored},
  68. {"hovered": control.enabled && control.hovered}
  69. ]
  70. }
  71. }
  72. }