ToolButton.qml 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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.ToolButton {
  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. padding: 6
  16. spacing: 6
  17. icon.width: 24
  18. icon.height: 24
  19. icon.color: !enabled ? Material.hintTextColor : checked || highlighted ? Material.accent : Material.foreground
  20. contentItem: IconLabel {
  21. spacing: control.spacing
  22. mirrored: control.mirrored
  23. display: control.display
  24. icon: control.icon
  25. text: control.text
  26. font: control.font
  27. color: !control.enabled ? control.Material.hintTextColor :
  28. control.checked || control.highlighted ? control.Material.accent : control.Material.foreground
  29. }
  30. background: Ripple {
  31. implicitWidth: control.Material.touchTarget
  32. implicitHeight: control.Material.touchTarget
  33. readonly property bool square: control.contentItem.width <= control.contentItem.height
  34. x: (parent.width - width) / 2
  35. y: (parent.height - height) / 2
  36. clip: !square
  37. width: square ? parent.height / 2 : parent.width
  38. height: square ? parent.height / 2 : parent.height
  39. pressed: control.pressed
  40. anchor: control
  41. active: control.enabled && (control.down || control.visualFocus || control.hovered)
  42. color: control.Material.rippleColor
  43. }
  44. }