Button.qml 3.6 KB

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