RadioDelegate.qml 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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.RadioDelegate {
  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: 12
  15. spacing: 12
  16. icon.width: 24
  17. icon.height: 24
  18. icon.color: control.palette.text
  19. contentItem: IconLabel {
  20. leftPadding: control.mirrored ? control.indicator.width + control.spacing : 0
  21. rightPadding: !control.mirrored ? control.indicator.width + control.spacing : 0
  22. spacing: control.spacing
  23. mirrored: control.mirrored
  24. display: control.display
  25. alignment: control.display === IconLabel.IconOnly || control.display === IconLabel.TextUnderIcon ? Qt.AlignCenter : Qt.AlignLeft
  26. icon: control.icon
  27. text: control.text
  28. font: control.font
  29. color: control.palette.text
  30. }
  31. // keep in sync with RadioButton.qml (shared RadioIndicator.qml was removed for performance reasons)
  32. indicator: Rectangle {
  33. implicitWidth: 28
  34. implicitHeight: 28
  35. x: control.mirrored ? control.leftPadding : control.width - width - control.rightPadding
  36. y: control.topPadding + (control.availableHeight - height) / 2
  37. radius: width / 2
  38. color: control.down ? control.palette.light : control.palette.base
  39. border.width: control.visualFocus ? 2 : 1
  40. border.color: {
  41. if (control.visualFocus)
  42. return control.palette.highlight
  43. else if (Qt.styleHints.accessibility.contrastPreference !== Qt.HighContrast)
  44. return control.palette.mid
  45. else
  46. return Color.blend(control.palette.dark, control.palette.base,
  47. control.enabled ? 0.0 : 0.5)
  48. }
  49. Rectangle {
  50. x: (parent.width - width) / 2
  51. y: (parent.height - height) / 2
  52. width: 20
  53. height: 20
  54. radius: width / 2
  55. color: control.palette.text
  56. visible: control.checked
  57. }
  58. }
  59. background: Rectangle {
  60. implicitWidth: 100
  61. implicitHeight: 40
  62. visible: control.down || control.highlighted
  63. color: control.down ? control.palette.midlight : control.palette.light
  64. }
  65. }