Menu.qml 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. // Copyright (C) 2017 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.Imagine
  7. import QtQuick.Controls.Imagine.impl
  8. import QtQuick.Window
  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. topMargin: background ? background.topInset : 0
  16. leftMargin: background ? background.leftInset : 0
  17. rightMargin: background ? background.rightInset : 0
  18. bottomMargin: background ? background.bottomInset : 0
  19. topPadding: background ? background.topPadding : 0
  20. leftPadding: background ? background.leftPadding : 0
  21. rightPadding: background ? background.rightPadding : 0
  22. bottomPadding: background ? background.bottomPadding : 0
  23. topInset: background ? -background.topInset || 0 : 0
  24. leftInset: background ? -background.leftInset || 0 : 0
  25. rightInset: background ? -background.rightInset || 0 : 0
  26. bottomInset: background ? -background.bottomInset || 0 : 0
  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. clip: true
  35. currentIndex: control.currentIndex
  36. T.ScrollIndicator.vertical: ScrollIndicator { }
  37. }
  38. background: NinePatchImage {
  39. source: Imagine.url + "menu-background"
  40. NinePatchImageSelector on source {
  41. states: [
  42. {"modal": control.modal},
  43. {"dim": control.dim}
  44. ]
  45. }
  46. }
  47. T.Overlay.modal: NinePatchImage {
  48. source: Imagine.url + "menu-overlay"
  49. NinePatchImageSelector on source {
  50. states: [
  51. {"modal": true}
  52. ]
  53. }
  54. }
  55. T.Overlay.modeless: NinePatchImage {
  56. source: Imagine.url + "menu-overlay"
  57. NinePatchImageSelector on source {
  58. states: [
  59. {"modal": false}
  60. ]
  61. }
  62. }
  63. }