RadioButton.qml 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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.Templates as T
  6. import QtQuick.Controls.Imagine
  7. import QtQuick.Controls.Imagine.impl
  8. T.RadioButton {
  9. id: control
  10. implicitWidth: Math.max(implicitBackgroundWidth + leftInset + rightInset,
  11. implicitContentWidth + leftPadding + rightPadding)
  12. implicitHeight: Math.max(implicitBackgroundHeight + topInset + bottomInset,
  13. implicitContentHeight + topPadding + bottomPadding,
  14. implicitIndicatorHeight + topPadding + bottomPadding)
  15. spacing: 6 // ###
  16. topPadding: background ? background.topPadding : 0
  17. leftPadding: background ? background.leftPadding : 0
  18. rightPadding: background ? background.rightPadding : 0
  19. bottomPadding: background ? background.bottomPadding : 0
  20. topInset: background ? -background.topInset || 0 : 0
  21. leftInset: background ? -background.leftInset || 0 : 0
  22. rightInset: background ? -background.rightInset || 0 : 0
  23. bottomInset: background ? -background.bottomInset || 0 : 0
  24. indicator: Image {
  25. x: control.text ? (control.mirrored ? control.width - width - control.rightPadding : control.leftPadding) : control.leftPadding + (control.availableWidth - width) / 2
  26. y: control.topPadding + (control.availableHeight - height) / 2
  27. source: Imagine.url + "radiobutton-indicator"
  28. ImageSelector on source {
  29. states: [
  30. {"disabled": !control.enabled},
  31. {"pressed": control.down},
  32. {"checked": control.checked},
  33. {"focused": control.visualFocus},
  34. {"mirrored": control.mirrored},
  35. {"hovered": control.enabled && control.hovered}
  36. ]
  37. }
  38. }
  39. contentItem: Text {
  40. leftPadding: control.indicator && !control.mirrored ? control.indicator.width + control.spacing : 0
  41. rightPadding: control.indicator && control.mirrored ? control.indicator.width + control.spacing : 0
  42. text: control.text
  43. font: control.font
  44. color: control.palette.windowText
  45. elide: Text.ElideRight
  46. verticalAlignment: Text.AlignVCenter
  47. }
  48. background: NinePatchImage {
  49. source: Imagine.url + "radiobutton-background"
  50. NinePatchImageSelector on source {
  51. states: [
  52. {"disabled": !control.enabled},
  53. {"pressed": control.down},
  54. {"checked": control.checked},
  55. {"focused": control.visualFocus},
  56. {"mirrored": control.mirrored},
  57. {"hovered": control.enabled && control.hovered}
  58. ]
  59. }
  60. }
  61. }