1// Copyright (c) 2019 Ultimaker B.V.
2// Toolbox is released under the terms of the LGPLv3 or higher.
3
4import QtQuick 2.10
5import QtQuick.Controls 1.4
6
7import UM 1.5 as UM
8
9Item
10{
11    id: base
12
13    property var packageData
14    property var technicalDataSheetUrl: packageData.links.technicalDataSheet
15    property var safetyDataSheetUrl: packageData.links.safetyDataSheet
16    property var printingGuidelinesUrl: packageData.links.printingGuidelines
17    property var materialWebsiteUrl: packageData.links.website
18
19    height: childrenRect.height
20    onVisibleChanged: packageData.type === "material" && (compatibilityItem.visible || dataSheetLinks.visible)
21
22    Column
23    {
24        id: compatibilityItem
25        visible: packageData.has_configs
26        width: parent.width
27        // This is a bit of a hack, but the whole QML is pretty messy right now. This needs a big overhaul.
28        height: visible ? heading.height + table.height: 0
29
30        Label
31        {
32            id: heading
33            width: parent.width
34            text: catalog.i18nc("@label", "Compatibility")
35            wrapMode: Text.WordWrap
36            color: UM.Theme.getColor("text_medium")
37            font: UM.Theme.getFont("medium")
38            renderType: Text.NativeRendering
39        }
40
41        TableView
42        {
43            id: table
44            width: parent.width
45            frameVisible: false
46
47            // Workaround for scroll issues (QTBUG-49652)
48            flickableItem.interactive: false
49            Component.onCompleted:
50            {
51                for (var i = 0; i < flickableItem.children.length; ++i)
52                {
53                    flickableItem.children[i].enabled = false
54                }
55            }
56            selectionMode: 0
57            model: packageData.supported_configs
58            headerDelegate: Rectangle
59            {
60                color: UM.Theme.getColor("main_background")
61                height: UM.Theme.getSize("toolbox_chart_row").height
62                Label
63                {
64                    anchors.verticalCenter: parent.verticalCenter
65                    elide: Text.ElideRight
66                    text: styleData.value || ""
67                    color: UM.Theme.getColor("text")
68                    font: UM.Theme.getFont("default_bold")
69                    renderType: Text.NativeRendering
70                }
71                Rectangle
72                {
73                    anchors.bottom: parent.bottom
74                    height: UM.Theme.getSize("default_lining").height
75                    width: parent.width
76                    color: "black"
77                }
78            }
79            rowDelegate: Item
80            {
81                height: UM.Theme.getSize("toolbox_chart_row").height
82                Label
83                {
84                    anchors.verticalCenter: parent.verticalCenter
85                    elide: Text.ElideRight
86                    text: styleData.value || ""
87                    color: UM.Theme.getColor("text_medium")
88                    font: UM.Theme.getFont("default")
89                    renderType: Text.NativeRendering
90                }
91            }
92            itemDelegate: Item
93            {
94                height: UM.Theme.getSize("toolbox_chart_row").height
95                Label
96                {
97                    anchors.verticalCenter: parent.verticalCenter
98                    elide: Text.ElideRight
99                    text: styleData.value || ""
100                    color: UM.Theme.getColor("text_medium")
101                    font: UM.Theme.getFont("default")
102                    renderType: Text.NativeRendering
103                }
104            }
105
106            Component
107            {
108                id: columnTextDelegate
109                Label
110                {
111                    anchors.fill: parent
112                    verticalAlignment: Text.AlignVCenter
113                    text: styleData.value || ""
114                    elide: Text.ElideRight
115                    color: UM.Theme.getColor("text_medium")
116                    font: UM.Theme.getFont("default")
117                    renderType: Text.NativeRendering
118                }
119            }
120
121            TableViewColumn
122            {
123                role: "machine"
124                title: catalog.i18nc("@label:table_header", "Machine")
125                width: Math.floor(table.width * 0.25)
126                delegate: columnTextDelegate
127            }
128            TableViewColumn
129            {
130                role: "print_core"
131                title: "Print Core" //This term should not be translated.
132                width: Math.floor(table.width * 0.2)
133            }
134            TableViewColumn
135            {
136                role: "build_plate"
137                title: catalog.i18nc("@label:table_header", "Build Plate")
138                width: Math.floor(table.width * 0.225)
139            }
140            TableViewColumn
141            {
142                role: "support_material"
143                title: catalog.i18nc("@label:table_header", "Support")
144                width: Math.floor(table.width * 0.225)
145            }
146            TableViewColumn
147            {
148                role: "quality"
149                title: catalog.i18nc("@label:table_header", "Quality")
150                width: Math.floor(table.width * 0.1)
151            }
152        }
153    }
154
155    Label
156    {
157        id: dataSheetLinks
158        anchors.top: compatibilityItem.bottom
159        anchors.topMargin: UM.Theme.getSize("narrow_margin").height
160        visible: base.technicalDataSheetUrl !== undefined ||
161                    base.safetyDataSheetUrl !== undefined ||
162                    base.printingGuidelinesUrl !== undefined ||
163                    base.materialWebsiteUrl !== undefined
164
165        text:
166        {
167            var result = ""
168            if (base.technicalDataSheetUrl !== undefined)
169            {
170                var tds_name = catalog.i18nc("@action:label", "Technical Data Sheet")
171                result += "<a href='%1'>%2</a>".arg(base.technicalDataSheetUrl).arg(tds_name)
172            }
173            if (base.safetyDataSheetUrl !== undefined)
174            {
175                if (result.length > 0)
176                {
177                    result += "<br/>"
178                }
179                var sds_name = catalog.i18nc("@action:label", "Safety Data Sheet")
180                result += "<a href='%1'>%2</a>".arg(base.safetyDataSheetUrl).arg(sds_name)
181            }
182            if (base.printingGuidelinesUrl !== undefined)
183            {
184                if (result.length > 0)
185                {
186                    result += "<br/>"
187                }
188                var pg_name = catalog.i18nc("@action:label", "Printing Guidelines")
189                result += "<a href='%1'>%2</a>".arg(base.printingGuidelinesUrl).arg(pg_name)
190            }
191            if (base.materialWebsiteUrl !== undefined)
192            {
193                if (result.length > 0)
194                {
195                    result += "<br/>"
196                }
197                var pg_name = catalog.i18nc("@action:label", "Website")
198                result += "<a href='%1'>%2</a>".arg(base.materialWebsiteUrl).arg(pg_name)
199            }
200
201            return result
202        }
203        font: UM.Theme.getFont("default")
204        color: UM.Theme.getColor("text")
205        linkColor: UM.Theme.getColor("text_link")
206        onLinkActivated: UM.UrlUtil.openUrl(link, ["http", "https"])
207        renderType: Text.NativeRendering
208    }
209}
210