RoundButton.qml 3.2 KB

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