DefaultCheckBox.qml 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. // Copyright (C) 2020 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.CheckBox {
  10. id: control
  11. readonly property bool nativeIndicator: indicator instanceof NativeStyle.StyleItem
  12. readonly property bool __notCustomizable: true
  13. implicitWidth: Math.max(implicitBackgroundWidth + leftInset + rightInset,
  14. implicitContentWidth + leftPadding + rightPadding)
  15. implicitHeight: Math.max(implicitBackgroundHeight + topInset + bottomInset,
  16. implicitContentHeight + topPadding + bottomPadding,
  17. implicitIndicatorHeight + topPadding + bottomPadding)
  18. spacing: nativeIndicator ? 0 : 6
  19. padding: nativeIndicator ? 0 : 6
  20. indicator: NativeStyle.CheckBox {
  21. control: control
  22. y: control.topPadding + (control.availableHeight - height) >> 1
  23. contentWidth: contentItem.implicitWidth
  24. contentHeight: contentItem.implicitHeight
  25. useNinePatchImage: false
  26. readonly property bool __ignoreNotCustomizable: true
  27. }
  28. contentItem: CheckLabel {
  29. text: control.text
  30. font: control.font
  31. color: control.palette.windowText
  32. // For some reason, the other styles set padding here (in the delegate), instead of in
  33. // the control above. And they also adjust the indicator position by setting x and y
  34. // explicitly (instead of using insets). So we follow the same pattern to ensure that
  35. // setting a custom contentItem delegate from the app will end up looking the same for
  36. // all styles. But this should probably be fixed for all styles (to make them work the
  37. // same way as e.g Buttons).
  38. leftPadding: {
  39. if (nativeIndicator)
  40. indicator.contentPadding.left
  41. else
  42. indicator && !mirrored ? indicator.width + spacing : 0
  43. }
  44. topPadding: nativeIndicator ? indicator.contentPadding.top : 0
  45. rightPadding: {
  46. if (nativeIndicator)
  47. indicator.contentPadding.right
  48. else
  49. indicator && mirrored ? indicator.width + spacing : 0
  50. }
  51. readonly property bool __ignoreNotCustomizable: true
  52. }
  53. }