RadioButton.qml 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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.Controls.impl
  6. import QtQuick.Templates as T
  7. T.RadioButton {
  8. id: control
  9. implicitWidth: Math.max(implicitBackgroundWidth + leftInset + rightInset,
  10. implicitContentWidth + leftPadding + rightPadding)
  11. implicitHeight: Math.max(implicitBackgroundHeight + topInset + bottomInset,
  12. implicitContentHeight + topPadding + bottomPadding,
  13. implicitIndicatorHeight + topPadding + bottomPadding)
  14. padding: 6
  15. spacing: 6
  16. // keep in sync with RadioDelegate.qml (shared RadioIndicator.qml was removed for performance reasons)
  17. indicator: Rectangle {
  18. implicitWidth: 28
  19. implicitHeight: 28
  20. x: control.text ? (control.mirrored ? control.width - width - control.rightPadding : control.leftPadding) : control.leftPadding + (control.availableWidth - width) / 2
  21. y: control.topPadding + (control.availableHeight - height) / 2
  22. radius: width / 2
  23. color: control.down ? control.palette.light : control.palette.base
  24. border.width: control.visualFocus ? 2 : 1
  25. border.color: {
  26. if (control.visualFocus)
  27. return control.palette.highlight
  28. else if (Qt.styleHints.accessibility.contrastPreference !== Qt.HighContrast)
  29. return control.palette.mid
  30. else
  31. return Color.blend(control.palette.dark, control.palette.base,
  32. control.enabled ? 0.0 : 0.5)
  33. }
  34. Rectangle {
  35. x: (parent.width - width) / 2
  36. y: (parent.height - height) / 2
  37. width: 20
  38. height: 20
  39. radius: width / 2
  40. color: control.palette.text
  41. visible: control.checked
  42. }
  43. }
  44. contentItem: CheckLabel {
  45. leftPadding: control.indicator && !control.mirrored ? control.indicator.width + control.spacing : 0
  46. rightPadding: control.indicator && control.mirrored ? control.indicator.width + control.spacing : 0
  47. text: control.text
  48. font: control.font
  49. color: control.palette.windowText
  50. }
  51. }