ToolButton.qml 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. // Copyright (C) 2024 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.Controls.impl
  6. import QtQuick.Controls.FluentWinUI3.impl
  7. import QtQuick.Templates as T
  8. T.ToolButton {
  9. id: control
  10. implicitWidth: Math.max(implicitBackgroundWidth + leftInset + rightInset,
  11. implicitContentWidth + leftPadding + rightPadding)
  12. implicitHeight: Math.max(implicitBackgroundHeight + topInset + bottomInset,
  13. implicitContentHeight + topPadding + bottomPadding)
  14. spacing: __config.spacing || 0
  15. topPadding: __config.topPadding || 0
  16. bottomPadding: __config.bottomPadding || 0
  17. leftPadding: __config.leftPadding || 0
  18. rightPadding: __config.rightPadding || 0
  19. topInset: -__config.topInset || 0
  20. bottomInset: -__config.bottomInset || 0
  21. leftInset: -__config.leftInset || 0
  22. rightInset: -__config.rightInset || 0
  23. icon.width: __config.icon.width
  24. icon.height: __config.icon.height
  25. icon.color: __buttonText
  26. readonly property color __buttonText: {
  27. if (control.down) {
  28. return (control.checked || control.highlighted)
  29. ? Application.styleHints.colorScheme == Qt.Light
  30. ? Qt.rgba(1, 1, 1, 0.7) : Qt.rgba(0, 0, 0, 0.5)
  31. : (Application.styleHints.colorScheme === Qt.Light
  32. ? Qt.rgba(control.palette.buttonText.r, control.palette.buttonText.g, control.palette.buttonText.b, 0.62)
  33. : Qt.rgba(control.palette.buttonText.r, control.palette.buttonText.g, control.palette.buttonText.b, 0.7725))
  34. } else if (control.checked || control.highlighted) {
  35. return (Application.styleHints.colorScheme === Qt.Dark && !control.enabled)
  36. ? Qt.rgba(1, 1, 1, 0.5302)
  37. : (Application.styleHints.colorScheme === Qt.Dark ? "black" : "white")
  38. } else {
  39. return control.palette.buttonText
  40. }
  41. }
  42. readonly property string __currentState: [
  43. control.checked && "checked",
  44. !control.enabled && "disabled",
  45. control.enabled && !control.down && control.hovered && "hovered",
  46. down && "pressed"
  47. ].filter(Boolean).join("_") || "normal"
  48. readonly property var __config: Config.controls.toolbutton[__currentState] || {}
  49. readonly property Item __focusFrameTarget: control
  50. contentItem: IconLabel {
  51. spacing: control.spacing
  52. mirrored: control.mirrored
  53. display: control.display
  54. icon: control.icon
  55. text: control.text
  56. font: control.font
  57. color: control.icon.color
  58. }
  59. background: ButtonBackground {
  60. control: control
  61. implicitHeight: control.__config.background.height
  62. implicitWidth: implicitHeight
  63. radius: control.__config.background.topOffset
  64. subtle: !(control.checked || control.highlighted) || control.flat
  65. }
  66. }