TabButton.qml 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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 as Impl
  7. import QtQuick.Templates as T
  8. T.TabButton {
  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: 16
  24. icon.height: 16
  25. readonly property string __currentState: [
  26. checked && "checked",
  27. !enabled && "disabled",
  28. enabled && !down && hovered && "hovered",
  29. down && "pressed"
  30. ].filter(Boolean).join("_") || "normal"
  31. readonly property var __config: Config.controls.tabbutton[__currentState] || {}
  32. readonly property Item __focusFrameTarget: control
  33. contentItem: IconLabel {
  34. spacing: control.spacing
  35. mirrored: control.mirrored
  36. display: control.display
  37. alignment: control.__config.label.textVAlignment | control.__config.label.textHAlignment
  38. text: control.text
  39. font: control.font
  40. icon: control.icon
  41. defaultIconColor: control.down ? pressedText : control.hovered ? hoveredText : control.palette.buttonText
  42. color: defaultIconColor
  43. readonly property color pressedText: Application.styleHints.colorScheme === Qt.Light
  44. ? Qt.rgba(control.palette.buttonText.r, control.palette.buttonText.g, control.palette.buttonText.b, 0.447)
  45. : Qt.rgba(control.palette.buttonText.r, control.palette.buttonText.g, control.palette.buttonText.b, 0.529)
  46. readonly property color hoveredText: Application.styleHints.colorScheme === Qt.Light
  47. ? Qt.rgba(control.palette.buttonText.r, control.palette.buttonText.g, control.palette.buttonText.b, 0.62)
  48. : Qt.rgba(control.palette.buttonText.r, control.palette.buttonText.g, control.palette.buttonText.b, 0.7725)
  49. }
  50. background: Impl.StyleImage {
  51. imageConfig: control.__config.background
  52. property Rectangle selector: Rectangle {
  53. parent: control.background
  54. x: (parent.width - implicitWidth) / 2
  55. y: parent.height - height
  56. height: 3
  57. implicitWidth: 16
  58. radius: height * 0.5
  59. color: control.palette.accent
  60. visible: control.checked
  61. states: State {
  62. name: "checked"
  63. when: control.checked
  64. PropertyChanges {
  65. target: control.background.selector
  66. width: 16
  67. }
  68. }
  69. transitions: Transition {
  70. to: "checked"
  71. ParallelAnimation {
  72. NumberAnimation { target: control.background.selector; property: "opacity"; from: 0; to: 1; easing.type: Easing.Linear; duration: 83}
  73. NumberAnimation { target: control.background.selector; property: "scale"; from: 0.33; to: 1; easing.type: Easing.InOutCubic; duration: 167}
  74. }
  75. }
  76. }
  77. }
  78. }