MenuItem.qml 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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.impl
  7. import QtQuick.Controls.Imagine
  8. import QtQuick.Controls.Imagine.impl
  9. T.MenuItem {
  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. implicitIndicatorHeight + topPadding + bottomPadding)
  16. spacing: 6 // ###
  17. topPadding: background ? background.topPadding : 0
  18. leftPadding: background ? background.leftPadding : 0
  19. rightPadding: background ? background.rightPadding : 0
  20. bottomPadding: background ? background.bottomPadding : 0
  21. topInset: background ? -background.topInset || 0 : 0
  22. leftInset: background ? -background.leftInset || 0 : 0
  23. rightInset: background ? -background.rightInset || 0 : 0
  24. bottomInset: background ? -background.bottomInset || 0 : 0
  25. icon.width: 24
  26. icon.height: 24
  27. icon.color: control.palette.windowText
  28. contentItem: IconLabel {
  29. readonly property real arrowPadding: control.subMenu && control.arrow ? control.arrow.width + control.spacing : 0
  30. readonly property real indicatorPadding: control.checkable && control.indicator ? control.indicator.width + control.spacing : 0
  31. leftPadding: !control.mirrored ? indicatorPadding : arrowPadding
  32. rightPadding: control.mirrored ? indicatorPadding : arrowPadding
  33. spacing: control.spacing
  34. mirrored: control.mirrored
  35. display: control.display
  36. alignment: Qt.AlignLeft
  37. icon: control.icon
  38. text: control.text
  39. font: control.font
  40. color: control.palette.windowText
  41. }
  42. arrow: Image {
  43. x: control.mirrored ? control.leftPadding : control.width - width - control.rightPadding
  44. y: control.topPadding + (control.availableHeight - height) / 2
  45. visible: control.subMenu
  46. source: Imagine.url + "menuitem-arrow"
  47. ImageSelector on source {
  48. states: [
  49. {"disabled": !control.enabled},
  50. {"pressed": control.down},
  51. {"checked": control.checked},
  52. {"focused": control.visualFocus},
  53. {"highlighted": control.highlighted},
  54. {"mirrored": control.mirrored},
  55. {"hovered": control.enabled && control.hovered}
  56. ]
  57. }
  58. }
  59. indicator: Image {
  60. x: control.text ? (control.mirrored ? control.width - width - control.rightPadding : control.leftPadding) : control.leftPadding + (control.availableWidth - width) / 2
  61. y: control.topPadding + (control.availableHeight - height) / 2
  62. visible: control.checkable
  63. source: Imagine.url + "menuitem-indicator"
  64. ImageSelector on source {
  65. states: [
  66. {"disabled": !control.enabled},
  67. {"pressed": control.down},
  68. {"checked": control.checked},
  69. {"focused": control.visualFocus},
  70. {"highlighted": control.highlighted},
  71. {"mirrored": control.mirrored},
  72. {"hovered": control.enabled && control.hovered}
  73. ]
  74. }
  75. }
  76. background: NinePatchImage {
  77. source: Imagine.url + "menuitem-background"
  78. NinePatchImageSelector on source {
  79. states: [
  80. {"disabled": !control.enabled},
  81. {"pressed": control.down},
  82. {"checked": control.checked},
  83. {"focused": control.visualFocus},
  84. {"highlighted": control.highlighted},
  85. {"mirrored": control.mirrored},
  86. {"hovered": control.enabled && control.hovered}
  87. ]
  88. }
  89. }
  90. }