RoundButton.qml 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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.impl
  7. import QtQuick.Controls.Imagine
  8. import QtQuick.Controls.Imagine.impl
  9. T.RoundButton {
  10. id: control
  11. implicitWidth: Math.max(implicitBackgroundWidth + leftInset + rightInset,
  12. implicitContentWidth + leftPadding + rightPadding)
  13. implicitHeight: Math.max(implicitBackgroundHeight + topInset + bottomInset,
  14. implicitContentHeight + topPadding + bottomPadding)
  15. topPadding: background ? background.topPadding : 0
  16. leftPadding: background ? background.leftPadding : 0
  17. rightPadding: background ? background.rightPadding : 0
  18. bottomPadding: background ? background.bottomPadding : 0
  19. topInset: background ? -background.topInset || 0 : 0
  20. leftInset: background ? -background.leftInset || 0 : 0
  21. rightInset: background ? -background.rightInset || 0 : 0
  22. bottomInset: background ? -background.bottomInset || 0 : 0
  23. icon.width: 24
  24. icon.height: 24
  25. contentItem: IconLabel {
  26. spacing: control.spacing
  27. mirrored: control.mirrored
  28. display: control.display
  29. icon: control.icon
  30. defaultIconColor: control.enabled && control.flat && control.highlighted ? control.palette.highlight
  31. : control.enabled && (control.down || control.checked || control.highlighted) && !control.flat
  32. ? control.palette.brightText : control.flat ? control.palette.windowText : control.palette.buttonText
  33. text: control.text
  34. font: control.font
  35. color: defaultIconColor
  36. }
  37. background: NinePatchImage {
  38. // ### TODO: radius?
  39. source: Imagine.url + "roundbutton-background"
  40. NinePatchImageSelector on source {
  41. states: [
  42. {"disabled": !control.enabled},
  43. {"pressed": control.down},
  44. {"checked": control.checked},
  45. {"checkable": control.checkable},
  46. {"focused": control.visualFocus},
  47. {"highlighted": control.highlighted},
  48. {"flat": control.flat},
  49. {"mirrored": control.mirrored},
  50. {"hovered": control.enabled && control.hovered}
  51. ]
  52. }
  53. }
  54. }