Debian Codegraph @

src/GUI/qml/Menu.qml

raw
1 import QtQuick 2.4
2 import FlightGear 1.0
3
4 Item {
5 id: root
6 visible: false
7
8 function show()
9 {
10 computeMenuWidth();
11 visible = true;
12 }
13
14 function close()
15 {
16 visible = false;
17 }
18
19 function computeMenuWidth()
20 {
21 var minWidth = 0;
22 for (var i = 0; i < items.length; i++) {
23 minWidth = Math.max(minWidth, items[i].minWidth());
24 }
25
26 menuFrame.width = minWidth;
27 }
28
29 property alias items: contentBox.children
30
31 // underlying mouse area to close menu when clicking outside
32 // this also eats hover events
33 MouseArea {
34 x: -1000
35 y: -1000
36 width: 2000
37 height: 2000
38 hoverEnabled: true
39 onClicked: root.close()
40 }
41
42 width: 1
43 height: 1
44
45 Rectangle {
46 id: menuFrame
47 border.width: 1
48 border.color: Style.minorFrameColor
49 height: contentBox.childrenRect.height + 2
50 color: Style.panelBackground
51
52 // width is computed during show(), but if we don't see a valid
53 // value here, the Column doesn't position the items until
54 // slightly late
55 width: 100
56
57
58 Column {
59 id: contentBox
60 x: 1
61 y: 1
62 width: parent.width - 2
63
64 // helper function called by BaseMenuItem on its parent, i.e,
65 // us, to request closing the menu
66 function requestClose()
67 {
68 root.close();
69 }
70
71 function getMenu() {
72 return root;
73 }
74
75 // menu items get inserted here
76 }
77 }
78 }