Menu.qml 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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.Templates as T
  6. import QtQuick.Controls.impl
  7. import QtQuick.Controls.FluentWinUI3.impl as Impl
  8. import QtQuick.Effects
  9. T.Menu {
  10. id: control
  11. implicitWidth: Math.max(implicitBackgroundWidth + leftInset + rightInset,
  12. implicitContentWidth + leftPadding + rightPadding)
  13. implicitHeight: Math.max(implicitBackgroundHeight + topInset + bottomInset,
  14. implicitContentHeight + topPadding + bottomPadding)
  15. leftPadding: 5
  16. topPadding: 5
  17. rightPadding: 5
  18. bottomPadding: 5
  19. margins: 0
  20. overlap: 4
  21. readonly property var __config: Config.controls.popup["normal"]
  22. readonly property bool __isHighContrast: Application.styleHints.accessibility.contrastPreference === Qt.HighContrast
  23. leftInset: -__config.background.leftShadow
  24. topInset: -__config.background.topShadow
  25. rightInset: -__config.background.rightShadow
  26. bottomInset: -__config.background.bottomShadow
  27. delegate: MenuItem { }
  28. contentItem: ListView {
  29. implicitHeight: contentHeight
  30. model: control.contentModel
  31. interactive: Window.window
  32. ? contentHeight + control.topPadding + control.bottomPadding > control.height
  33. : false
  34. currentIndex: control.currentIndex
  35. spacing: 4
  36. clip: true
  37. ScrollIndicator.vertical: ScrollIndicator {}
  38. }
  39. property real __heightScale: 1
  40. height: __heightScale * implicitHeight
  41. enter: Transition {
  42. NumberAnimation { property: "__heightScale"; from: 0.33; to: 1; easing.type: Easing.OutCubic; duration: 250 }
  43. }
  44. background: Impl.StyleImage {
  45. implicitWidth: 200 + imageConfig.leftShadow + imageConfig.rightShadow
  46. implicitHeight: 30 + imageConfig.topShadow + imageConfig.bottomShadow
  47. imageConfig: control.__config.background
  48. drawShadowWithinBounds: true
  49. Rectangle {
  50. x: -control.leftInset
  51. y: -control.topInset
  52. implicitWidth: parent.width + control.leftInset + control.rightInset
  53. implicitHeight: parent.height + control.topInset + control.bottomInset
  54. visible: control.__isHighContrast
  55. radius: 8
  56. color: control.palette.window
  57. border.color: control.palette.text
  58. border.width: 2
  59. }
  60. }
  61. T.Overlay.modal: Rectangle {
  62. color: "transparent"
  63. }
  64. T.Overlay.modeless: Rectangle {
  65. color: "transparent"
  66. }
  67. }