CheckBox.qml 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. overrideState: NativeStyle.StyleItem.NeverHovered
  27. readonly property bool __ignoreNotCustomizable: true
  28. }
  29. NativeStyle.CheckBox {
  30. id: hoverCheckBox
  31. control: control
  32. x: indicator.x
  33. y: indicator.y
  34. z: 99 // Needs to be above the "unhovered" indicator
  35. width: indicator.width
  36. height: indicator.height
  37. useNinePatchImage: false
  38. overrideState: NativeStyle.StyleItem.AlwaysHovered
  39. opacity: control.hovered ? 1 : 0
  40. visible: opacity !== 0
  41. Behavior on opacity { NumberAnimation { duration: hoverCheckBox.transitionDuration } }
  42. }
  43. contentItem: CheckLabel {
  44. text: control.text
  45. font: control.font
  46. color: control.palette.windowText
  47. // For some reason, the other styles set padding here (in the delegate), instead of in
  48. // the control above. And they also adjust the indicator position by setting x and y
  49. // explicitly (instead of using insets). So we follow the same pattern to ensure that
  50. // setting a custom contentItem delegate from the app will end up looking the same for
  51. // all styles. But this should probably be fixed for all styles (to make them work the
  52. // same way as e.g Buttons).
  53. leftPadding: {
  54. if (nativeIndicator)
  55. indicator.contentPadding.left
  56. else
  57. indicator && !mirrored ? indicator.width + spacing : 0
  58. }
  59. topPadding: nativeIndicator ? indicator.contentPadding.top : 0
  60. rightPadding: {
  61. if (nativeIndicator)
  62. indicator.contentPadding.right
  63. else
  64. indicator && mirrored ? indicator.width + spacing : 0
  65. }
  66. readonly property bool __ignoreNotCustomizable: true
  67. }
  68. }