Debian Codegraph @

src/GUI/qml/PathListDelegate.qml

raw
1 import QtQuick 2.4
2 import FlightGear.Launcher 1.0
3 import FlightGear 1.0
4
5 Item {
6 id: delegateRoot
7
8 signal performDelete();
9 signal performMove(var newIndex);
10
11 property alias deletePromptText: confirmDeletePath.promptText
12 property int modelCount: 0
13
14 height: childrenRect.height
15
16 Item {
17 id: divider
18 visible: model.index > 0 // divider before each item except the first
19 height: Style.margin
20 width: parent.width
21
22 Rectangle {
23 color: Style.frameColor
24 height: 1
25 width: parent.width - Style.strutSize
26 anchors.centerIn: parent
27 }
28 }
29
30 // this is the main visible content
31 Item {
32 id: contentRect
33 anchors.top: divider.bottom
34 // color: "#cfcfcf"
35
36 height: Math.max(label.implicitHeight, pathDeleteButton.height)
37 width: delegateRoot.width
38
39 Checkbox {
40 id: enableCheckbox
41 checked: model.enabled
42 anchors.left: parent.left
43 height: parent.height
44 onCheckedChanged: {
45 if (model.enabled !== checked) {
46 model.enabled = checked;
47 }
48 }
49 }
50
51 MouseArea {
52 id: pathDelegateHover
53 anchors.left: enableCheckbox.right
54 anchors.leftMargin: Style.margin
55 anchors.right: parent.right
56 height: parent.height
57
58 hoverEnabled: true
59 acceptedButtons: Qt.NoButton
60
61 // it's important that the button and text are children of the
62 // MouseArea, so nested containsMouse logic works
63 ClickableText {
64 id: label
65 text: model.path
66 onClicked: {
67 // open the location
68 _addOns.openDirectory(model.path)
69 }
70 anchors.left: parent.left
71 anchors.right: reorderButton.left
72 anchors.rightMargin: Style.margin
73 height: contentRect.height
74
75 verticalAlignment: Text.AlignVCenter
76 wrapMode: Text.WordWrap
77
78 font.strikeout: enableCheckbox.checked === false
79 }
80
81 DeleteButton {
82 id: pathDeleteButton
83 anchors.right: parent.right
84 visible: pathDelegateHover.containsMouse
85 onClicked: {
86 confirmDeletePath.visible = true
87 }
88 }
89
90 DragToReorderButton {
91 id: reorderButton
92 anchors.right: pathDeleteButton.left
93 anchors.rightMargin: Style.margin
94 visible: pathDelegateHover.containsMouse && (canMoveDown || canMoveUp)
95
96 canMoveUp: model.index > 0
97 canMoveDown: model.index < (delegateRoot.modelCount - 1)
98
99 onMoveUp: {
100 if (model.index === 0)
101 return;
102 delegateRoot.performMove(model.index - 1)
103 }
104
105 onMoveDown: {
106 delegateRoot.performMove(model.index + 1)
107 }
108 }
109 } // of MouseArea for hover
110
111 YesNoPanel {
112 id: confirmDeletePath
113 visible: false
114 anchors.fill: parent
115 yesText: qsTr("Remove")
116 noText: qsTr("Cancel")
117 yesIsDestructive: true
118
119 onAccepted: {
120 delegateRoot.performDelete()
121 }
122
123 onRejected: {
124 confirmDeletePath.visible = false
125 }
126
127 Rectangle {
128 anchors.fill: parent
129 z: -1
130 }
131 }
132 }
133 }
134