Button.qml 2.6 KB

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