RoundButton.qml 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. icon.color: control.enabled && control.flat && control.highlighted ? control.palette.highlight
  26. : control.enabled && (control.down || control.checked || control.highlighted) && !control.flat
  27. ? control.palette.brightText : control.flat ? control.palette.windowText : control.palette.buttonText
  28. contentItem: IconLabel {
  29. spacing: control.spacing
  30. mirrored: control.mirrored
  31. display: control.display
  32. icon: control.icon
  33. text: control.text
  34. font: control.font
  35. color: control.enabled && control.flat && control.highlighted ? control.palette.highlight
  36. : control.enabled && (control.down || control.checked || control.highlighted) && !control.flat
  37. ? control.palette.brightText : control.flat ? control.palette.windowText : control.palette.buttonText
  38. }
  39. background: NinePatchImage {
  40. // ### TODO: radius?
  41. source: Imagine.url + "roundbutton-background"
  42. NinePatchImageSelector on source {
  43. states: [
  44. {"disabled": !control.enabled},
  45. {"pressed": control.down},
  46. {"checked": control.checked},
  47. {"checkable": control.checkable},
  48. {"focused": control.visualFocus},
  49. {"highlighted": control.highlighted},
  50. {"flat": control.flat},
  51. {"mirrored": control.mirrored},
  52. {"hovered": control.enabled && control.hovered}
  53. ]
  54. }
  55. }
  56. }