RoundButton.qml 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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.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. topInset: 6
  16. leftInset: 6
  17. rightInset: 6
  18. bottomInset: 6
  19. padding: 12
  20. spacing: 6
  21. icon.width: 24
  22. icon.height: 24
  23. icon.color: !enabled ? Material.hintTextColor :
  24. flat && highlighted ? Material.accentColor :
  25. highlighted ? Material.primaryHighlightedTextColor : Material.foreground
  26. Material.elevation: control.down ? 8 : 2
  27. Material.background: flat ? "transparent" : undefined
  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.Material.hintTextColor :
  36. control.flat && control.highlighted ? control.Material.accentColor :
  37. control.highlighted ? control.Material.primaryHighlightedTextColor : control.Material.foreground
  38. }
  39. // TODO: Add a proper ripple/ink effect for mouse/touch input and focus state
  40. background: Rectangle {
  41. implicitWidth: control.Material.buttonHeight
  42. implicitHeight: control.Material.buttonHeight
  43. radius: control.radius
  44. color: control.Material.buttonColor(control.Material.theme, control.Material.background,
  45. control.Material.accent, control.enabled, control.flat, control.highlighted, false /*checked*/)
  46. Rectangle {
  47. width: parent.width
  48. height: parent.height
  49. radius: control.radius
  50. visible: enabled && (control.hovered || control.visualFocus)
  51. color: control.Material.rippleColor
  52. }
  53. Rectangle {
  54. width: parent.width
  55. height: parent.height
  56. radius: control.radius
  57. visible: control.down
  58. color: control.Material.rippleColor
  59. }
  60. // The layer is disabled when the button color is transparent so that you can do
  61. // Material.background: "transparent" and get a proper flat button without needing
  62. // to set Material.elevation as well
  63. layer.enabled: control.enabled && color.a > 0 && !control.flat
  64. layer.effect: ElevationEffect {
  65. elevation: control.Material.elevation
  66. }
  67. }
  68. }