Menu.qml 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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.Window
  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. // The insets are found by examining the MultiEffect.itemRect, which
  16. // contains the drop shadow offsets. Note: the insets are hard-coded
  17. // to avoid a binding loop to implicit size.
  18. leftInset: -32
  19. topInset: -32
  20. rightInset: -32
  21. bottomInset: -32
  22. leftPadding: 5
  23. topPadding: 5
  24. rightPadding: 5
  25. bottomPadding: 5
  26. margins: 0
  27. overlap: 4
  28. delegate: MenuItem { }
  29. contentItem: ListView {
  30. implicitHeight: contentHeight
  31. model: control.contentModel
  32. interactive: Window.window
  33. ? contentHeight + control.topPadding + control.bottomPadding > control.height
  34. : false
  35. currentIndex: control.currentIndex
  36. spacing: 2
  37. ScrollIndicator.vertical: ScrollIndicator {}
  38. }
  39. background: Item {
  40. implicitWidth: 200 - control.leftInset - control.rightInset
  41. implicitHeight: 20 - control.topInset - control.bottomInset
  42. MultiEffect {
  43. x: -control.leftInset
  44. y: -control.topInset
  45. width: source.width
  46. height: source.height
  47. source: Rectangle {
  48. width: control.background.width + control.leftInset + control.rightInset
  49. height: control.background.height + control.topInset + control.bottomInset
  50. radius: 8
  51. color: Qt.lighter(control.palette.window, 1.15)
  52. border.color: Qt.darker(control.palette.window, 1.12)
  53. visible: false
  54. }
  55. shadowScale: 1.04
  56. shadowOpacity: 0.1
  57. shadowColor: 'black'
  58. shadowEnabled: true
  59. shadowHorizontalOffset: 0
  60. shadowVerticalOffset: 6
  61. }
  62. }
  63. T.Overlay.modal: Rectangle {
  64. color: "transparent"
  65. }
  66. T.Overlay.modeless: Rectangle {
  67. color: "transparent"
  68. }
  69. }