TabButton.qml 3.8 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. icon.color: control.down ? __pressedText : control.hovered ? __hoveredText : control.palette.buttonText
  26. readonly property string __currentState: [
  27. checked && "checked",
  28. !enabled && "disabled",
  29. enabled && !down && hovered && "hovered",
  30. down && "pressed"
  31. ].filter(Boolean).join("_") || "normal"
  32. readonly property var __config: Config.controls.tabbutton[__currentState] || {}
  33. readonly property color __pressedText: Application.styleHints.colorScheme == Qt.Light
  34. ? Qt.rgba(control.palette.buttonText.r, control.palette.buttonText.g, control.palette.buttonText.b, 0.447)
  35. : Qt.rgba(control.palette.buttonText.r, control.palette.buttonText.g, control.palette.buttonText.b, 0.529)
  36. readonly property color __hoveredText: Application.styleHints.colorScheme == Qt.Light
  37. ? Qt.rgba(control.palette.buttonText.r, control.palette.buttonText.g, control.palette.buttonText.b, 0.62)
  38. : Qt.rgba(control.palette.buttonText.r, control.palette.buttonText.g, control.palette.buttonText.b, 0.7725)
  39. readonly property Item __focusFrameTarget: control
  40. contentItem: IconLabel {
  41. spacing: control.spacing
  42. mirrored: control.mirrored
  43. display: control.display
  44. alignment: control.__config.label.textVAlignment | control.__config.label.textHAlignment
  45. text: control.text
  46. font: control.font
  47. icon: control.icon
  48. color: control.icon.color
  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. }