RoundButton.qml 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. Material.elevation: control.down ? 8 : 2
  24. Material.background: flat ? "transparent" : undefined
  25. contentItem: IconLabel {
  26. spacing: control.spacing
  27. mirrored: control.mirrored
  28. display: control.display
  29. icon: control.icon
  30. defaultIconColor: !control.enabled ? control.Material.hintTextColor
  31. : control.flat && control.highlighted ? control.Material.accentColor
  32. : control.highlighted ? control.Material.primaryHighlightedTextColor
  33. : control.Material.foreground
  34. text: control.text
  35. font: control.font
  36. color: defaultIconColor
  37. }
  38. // TODO: Add a proper ripple/ink effect for mouse/touch input and focus state
  39. background: Rectangle {
  40. implicitWidth: control.Material.buttonHeight
  41. implicitHeight: control.Material.buttonHeight
  42. radius: control.radius
  43. color: control.Material.buttonColor(control.Material.theme, control.Material.background,
  44. control.Material.accent, control.enabled, control.flat, control.highlighted, false /*checked*/)
  45. Rectangle {
  46. width: parent.width
  47. height: parent.height
  48. radius: control.radius
  49. visible: enabled && (control.hovered || control.visualFocus)
  50. color: control.Material.rippleColor
  51. }
  52. Rectangle {
  53. width: parent.width
  54. height: parent.height
  55. radius: control.radius
  56. visible: control.down
  57. color: control.Material.rippleColor
  58. }
  59. // The layer is disabled when the button color is transparent so that you can do
  60. // Material.background: "transparent" and get a proper flat button without needing
  61. // to set Material.elevation as well
  62. layer.enabled: control.enabled && color.a > 0 && !control.flat
  63. layer.effect: ElevationEffect {
  64. elevation: control.Material.elevation
  65. }
  66. }
  67. }