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