DefaultRadioButton.qml 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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.RadioButton {
  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.RadioButton {
  21. control: control
  22. contentWidth: contentItem.implicitWidth
  23. contentHeight: contentItem.implicitHeight
  24. useNinePatchImage: false
  25. readonly property bool __ignoreNotCustomizable: true
  26. }
  27. contentItem: CheckLabel {
  28. text: control.text
  29. font: control.font
  30. color: control.palette.windowText
  31. // For some reason, the other styles set padding here (in the delegate), instead of in
  32. // the control above. And they also adjust the indicator position by setting x and y
  33. // explicitly (instead of using insets). So we follow the same pattern to ensure that
  34. // setting a custom contentItem delegate from the app will end up looking the same for
  35. // all styles. But this should probably be fixed for all styles (to make them work the
  36. // same way as e.g Buttons).
  37. leftPadding: {
  38. if (nativeIndicator)
  39. indicator.contentPadding.left
  40. else
  41. indicator && !mirrored ? indicator.width + spacing : 0
  42. }
  43. rightPadding: {
  44. if (nativeIndicator)
  45. indicator.contentPadding.right
  46. else
  47. indicator && mirrored ? indicator.width + spacing : 0
  48. }
  49. readonly property bool __ignoreNotCustomizable: true
  50. }
  51. }