Debian Codegraph @

src/GUI/qml/CatalogDelegate.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 // don't show the delegate for newly added catalogs, until the
9 // adding process is complete
10 visible: !model.isNewlyAdded
11
12 implicitWidth: 300
13 height: childrenRect.height
14
15 Item {
16 id: divider
17 visible: model.index > 0 // divider before each item except the first
18 height: Style.margin
19 width: parent.width
20
21 Rectangle {
22 color: Style.frameColor
23 height: 1
24 width: parent.width - Style.strutSize
25 anchors.centerIn: parent
26 }
27 }
28
29 function isDisabled()
30 {
31 return (model.status !== CatalogListModel.Ok) ||
32 (enableCheckbox.checked === false);
33 }
34
35 Item
36 {
37 anchors.top: divider.bottom
38 height: catalogTextColumn.childrenRect.height + Style.margin * 2
39 width: parent.width
40
41
42 Column {
43 id: catalogTextColumn
44
45 y: Style.margin
46 anchors.left: parent.left
47 anchors.leftMargin: Style.margin
48 anchors.right: catalogDeleteButton.left
49 anchors.rightMargin: Style.margin
50 spacing: Style.margin
51
52 Row {
53 spacing: Style.margin
54 height: headingText.height
55
56 Checkbox {
57 id: enableCheckbox
58 checked: model.enabled
59 height: parent.height
60
61 function setChecked(b)
62 {
63 model.enabled = b;
64 }
65
66 // only allow the user to toggle enable/disable if
67 // the catalog is valid
68 visible: (model.status === CatalogListModel.Ok)
69 }
70
71 StyledText {
72 id: headingText
73 font.pixelSize: Style.subHeadingFontPixelSize
74 font.bold: true
75 width: catalogTextColumn.width - enableCheckbox.width
76 text: model.name
77 font.strikeout: delegateRoot.isDisabled();
78 }
79 }
80
81 StyledText {
82 id: normalDescription
83 visible: model.status === CatalogListModel.Ok
84 width: parent.width
85 text: model.description
86 wrapMode: Text.WordWrap
87 }
88
89 StyledText {
90 id: badVersionDescription
91 visible: model.status === CatalogListModel.IncompatibleVersion
92 width: parent.width
93 wrapMode: Text.WordWrap
94 text: qsTr("This hangar is not compatible with this version of FlightGear")
95 }
96
97 ClickableText {
98 id: errorDescription
99 visible: (model.status !== CatalogListModel.Ok) && (model.status !== CatalogListModel.IncompatibleVersion)
100 width: parent.width
101 wrapMode: Text.WordWrap
102 text: qsTr("This hangar is currently disabled due to a problem. " +
103 "Click here to try updating the hangar information from the server. "
104 + "(An Internet connection is required for this)");
105 onClicked: {
106 _addOns.catalogs.refreshCatalog(model.index)
107 }
108 }
109
110 StyledText {
111 width: parent.width
112 text: model.url
113 }
114
115 }
116
117 DeleteButton {
118 id: catalogDeleteButton
119 anchors.right: parent.right
120 anchors.rightMargin: Style.margin
121 anchors.verticalCenter: parent.verticalCenter
122 visible: delegateHover.containsMouse
123
124 onClicked: {
125 confirmDeleteHangar.visible = true;
126 }
127 }
128
129 MouseArea {
130 id: delegateHover
131 anchors.fill: parent
132 hoverEnabled: true
133 acceptedButtons: Qt.NoButton
134 }
135
136 YesNoPanel {
137 id: confirmDeleteHangar
138 visible: false
139 anchors.fill: parent
140 anchors.margins: 1 // don't cover the border
141
142 yesText: qsTr("Remove")
143 noText: qsTr("Cancel")
144 yesIsDestructive: true
145 promptText: qsTr("Remove this hangar? (Downloaded aircraft will be deleted from your computer)");
146 onAccepted: {
147 _addOns.catalogs.removeCatalog(model.index);
148 }
149
150 onRejected: {
151 confirmDeleteHangar.visible = false
152 }
153
154 Rectangle {
155 anchors.fill: parent
156 z: -1
157 }
158 }
159 }
160
161 }