Button.qml 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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.Button {
  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. readonly property string __currentState: [
  26. (control.checked || control.highlighted) && "checked",
  27. !control.enabled && "disabled",
  28. control.enabled && !control.down && control.hovered && "hovered",
  29. control.down && "pressed"
  30. ].filter(Boolean).join("_") || "normal"
  31. readonly property var __config: (control.flat && Config.controls.flatbutton
  32. ? Config.controls.flatbutton[__currentState]
  33. : Config.controls.button[__currentState]) || {}
  34. readonly property Item __focusFrameTarget: control
  35. contentItem: IconLabel {
  36. spacing: control.spacing
  37. mirrored: control.mirrored
  38. display: control.display
  39. alignment: control.__config.label.textVAlignment | control.__config.label.textHAlignment
  40. icon: control.icon
  41. text: control.text
  42. font: control.font
  43. color: defaultIconColor
  44. defaultIconColor: {
  45. if (Application.styleHints.accessibility.contrastPreference === Qt.HighContrast) {
  46. return (control.enabled && ((control.flat && (control.down || control.hovered))
  47. || ((control.highlighted || control.checked) && !control.down)))
  48. ? control.palette.button
  49. : control.enabled && (control.hovered || control.down)
  50. ? control.palette.highlight
  51. : control.palette.buttonText
  52. }
  53. if (control.down) {
  54. return (control.checked || control.highlighted)
  55. ? Application.styleHints.colorScheme === Qt.Light
  56. ? Color.transparent("white", 0.7) : Color.transparent("black", 0.5)
  57. : (Application.styleHints.colorScheme === Qt.Light
  58. ? Color.transparent(control.palette.buttonText, 0.62)
  59. : Color.transparent(control.palette.buttonText, 0.7725))
  60. } else if (control.checked || control.highlighted) {
  61. return (Application.styleHints.colorScheme === Qt.Dark && !control.enabled)
  62. ? Color.transparent("white", 0.5302)
  63. : (Application.styleHints.colorScheme === Qt.Dark ? "black" : "white")
  64. } else {
  65. return control.palette.buttonText
  66. }
  67. }
  68. }
  69. background: ButtonBackground {
  70. control: control
  71. implicitHeight: control.__config.background.height
  72. implicitWidth: control.__config.background.width
  73. radius: control.__config.background.topOffset
  74. subtle: control.flat
  75. }
  76. }