Button.qml 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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.Button {
  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. 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. icon.width: 24
  25. icon.height: 24
  26. contentItem: IconLabel {
  27. spacing: control.spacing
  28. mirrored: control.mirrored
  29. display: control.display
  30. icon: control.icon
  31. defaultIconColor: control.enabled && control.flat && control.highlighted ? control.palette.highlight
  32. : control.enabled && (control.down || control.checked || control.highlighted) && !control.flat
  33. ? control.palette.brightText : control.flat ? control.palette.windowText : control.palette.buttonText
  34. text: control.text
  35. font: control.font
  36. color: defaultIconColor
  37. }
  38. background: NinePatchImage {
  39. source: Imagine.url + "button-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. {"mirrored": control.mirrored},
  49. {"flat": control.flat},
  50. {"hovered": control.enabled && control.hovered}
  51. ]
  52. }
  53. }
  54. }