CheckBox.qml 3.0 KB

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