Button.qml 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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.Material
  8. import QtQuick.Controls.Material.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. topInset: 6
  16. bottomInset: 6
  17. verticalPadding: Material.buttonVerticalPadding
  18. leftPadding: Material.buttonLeftPadding(flat, hasIcon && (display !== AbstractButton.TextOnly))
  19. rightPadding: Material.buttonRightPadding(flat, hasIcon && (display !== AbstractButton.TextOnly),
  20. (text !== "") && (display !== AbstractButton.IconOnly))
  21. spacing: 8
  22. icon.width: 24
  23. icon.height: 24
  24. icon.color: !enabled ? Material.hintTextColor :
  25. (control.flat && control.highlighted) || (control.checked && !control.highlighted) ? Material.accentColor :
  26. highlighted ? Material.primaryHighlightedTextColor : Material.foreground
  27. readonly property bool hasIcon: icon.name.length > 0 || icon.source.toString().length > 0
  28. Material.elevation: control.down ? 8 : 2
  29. Material.roundedScale: Material.FullScale
  30. contentItem: IconLabel {
  31. spacing: control.spacing
  32. mirrored: control.mirrored
  33. display: control.display
  34. icon: control.icon
  35. text: control.text
  36. font: control.font
  37. color: !control.enabled ? control.Material.hintTextColor :
  38. (control.flat && control.highlighted) || (control.checked && !control.highlighted) ? control.Material.accentColor :
  39. control.highlighted ? control.Material.primaryHighlightedTextColor : control.Material.foreground
  40. }
  41. background: Rectangle {
  42. implicitWidth: 64
  43. implicitHeight: control.Material.buttonHeight
  44. radius: control.Material.roundedScale === Material.FullScale ? height / 2 : control.Material.roundedScale
  45. color: control.Material.buttonColor(control.Material.theme, control.Material.background,
  46. control.Material.accent, control.enabled, control.flat, control.highlighted, control.checked)
  47. // The layer is disabled when the button color is transparent so you can do
  48. // Material.background: "transparent" and get a proper flat button without needing
  49. // to set Material.elevation as well
  50. layer.enabled: control.enabled && color.a > 0 && !control.flat
  51. layer.effect: RoundedElevationEffect {
  52. elevation: control.Material.elevation
  53. roundedScale: control.background.radius
  54. }
  55. Ripple {
  56. clip: true
  57. clipRadius: parent.radius
  58. width: parent.width
  59. height: parent.height
  60. pressed: control.pressed
  61. anchor: control
  62. active: enabled && (control.down || control.visualFocus || control.hovered)
  63. color: control.flat && control.highlighted ? control.Material.highlightedRippleColor : control.Material.rippleColor
  64. }
  65. }
  66. }