Welcome to mirror list, hosted at ThFree Co, Russian Federation.

Marketplace.qml « qml « resources « Marketplace « plugins - github.com/Ultimaker/Cura.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: c04b24cc1333a6cbd09cff3dcd08e1198cff34d0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
// Copyright (c) 2021 Ultimaker B.V.
// Cura is released under the terms of the LGPLv3 or higher.

import QtQuick 2.15
import QtQuick.Controls 2.15
import QtQuick.Layouts 1.15
import QtQuick.Window 2.2

import UM 1.2 as UM
import Cura 1.6 as Cura
import Marketplace 1.0 as Marketplace

Window
{
    id: marketplaceDialog
    property variant catalog: UM.I18nCatalog { name: "cura" }
    property variant restartManager: Marketplace.RestartManager { }

    signal searchStringChanged(string new_search)

    minimumWidth: UM.Theme.getSize("modal_window_minimum").width
    minimumHeight: UM.Theme.getSize("modal_window_minimum").height
    width: minimumWidth
    height: minimumHeight

    onVisibleChanged:
    {
        pageSelectionTabBar.currentIndex = 0; //Go back to the initial tab.
        while(contextStack.depth > 1)
        {
            contextStack.pop(); //Do NOT use the StackView.Immediate transition here, since it causes the window to stay empty. Seemingly a Qt bug: https://bugreports.qt.io/browse/QTBUG-60670?
        }
    }

    Connections
    {
        target: Cura.API.account
        function onLoginStateChanged()
        {
            close();
        }
    }

    title: "Marketplace" //Seen by Ultimaker as a brand name, so this doesn't get translated.
    modality: Qt.NonModal

    // Background color
    Rectangle
    {
        anchors.fill: parent
        color: UM.Theme.getColor("main_background")

        //The Marketplace can have a page in front of everything with package details. The stack view controls its visibility.
        StackView
        {
            id: contextStack
            anchors.fill: parent

            initialItem: packageBrowse

            ColumnLayout
            {
                id: packageBrowse

                spacing: UM.Theme.getSize("default_margin").height

                // Page title.
                Item
                {
                    Layout.preferredWidth: parent.width
                    Layout.preferredHeight: childrenRect.height + UM.Theme.getSize("default_margin").height

                    Label
                    {
                        id: pageTitle
                        anchors
                        {
                            left: parent.left
                            leftMargin: UM.Theme.getSize("default_margin").width
                            right: parent.right
                            rightMargin: UM.Theme.getSize("default_margin").width
                            bottom: parent.bottom
                        }

                        font: UM.Theme.getFont("large")
                        color: UM.Theme.getColor("text")
                        text: content.item ? content.item.pageTitle: catalog.i18nc("@title", "Loading...")
                    }
                }

                OnboardBanner
                {
                    visible: content.item && content.item.bannerVisible
                    text: content.item && content.item.bannerText
                    icon: content.item && content.item.bannerIcon
                    onRemove: content.item && content.item.onRemoveBanner
                    readMoreUrl: content.item && content.item.bannerReadMoreUrl
                }

                // Search & Top-Level Tabs
                Item
                {
                    Layout.preferredHeight: childrenRect.height
                    Layout.preferredWidth: parent.width - 2 * UM.Theme.getSize("thin_margin").width
                    RowLayout
                    {
                        width: parent.width
                        height: UM.Theme.getSize("button_icon").height + UM.Theme.getSize("default_margin").height
                        spacing: UM.Theme.getSize("thin_margin").width

                        Item
                        {
                            Layout.preferredHeight: parent.height
                            Layout.preferredWidth: searchBar.visible ? UM.Theme.getSize("thin_margin").width : 0
                            Layout.fillWidth: ! searchBar.visible
                        }

                        Cura.SearchBar
                        {
                            id: searchBar
                            Layout.preferredHeight: UM.Theme.getSize("button_icon").height
                            Layout.fillWidth: true
                            onTextEdited: searchStringChanged(text)
                        }

                        // Page selection.
                        TabBar
                        {
                            id: pageSelectionTabBar
                            Layout.alignment: Qt.AlignRight
                            height: UM.Theme.getSize("button_icon").height
                            spacing: 0
                            background: Rectangle { color: "transparent" }

                            onCurrentIndexChanged:
                            {
                                searchBar.text = "";
                                searchBar.visible = currentItem.hasSearch;
                                content.source = currentItem.sourcePage;
                            }

                            PackageTypeTab
                            {
                                id: pluginTabText
                                width: implicitWidth
                                text: catalog.i18nc("@button", "Plugins")
                                property string sourcePage: "Plugins.qml"
                                property bool hasSearch: true
                            }
                            PackageTypeTab
                            {
                                id: materialsTabText
                                width: implicitWidth
                                text: catalog.i18nc("@button", "Materials")
                                property string sourcePage: "Materials.qml"
                                property bool hasSearch: true
                            }
                            ManagePackagesButton
                            {
                                property string sourcePage: "ManagedPackages.qml"
                                property bool hasSearch: false

                                Cura.NotificationIcon
                                {
                                    anchors
                                    {
                                        horizontalCenter: parent.right
                                        verticalCenter: parent.top
                                    }
                                    visible: CuraApplication.getPackageManager().packagesWithUpdate.length > 0

                                    labelText:
                                    {
                                        const itemCount = CuraApplication.getPackageManager().packagesWithUpdate.length
                                        return itemCount > 9 ? "9+" : itemCount
                                    }
                                }
                            }
                        }

                        TextMetrics
                        {
                            id: pluginTabTextMetrics
                            text: pluginTabText.text
                            font: pluginTabText.font
                        }
                        TextMetrics
                        {
                            id: materialsTabTextMetrics
                            text: materialsTabText.text
                            font: materialsTabText.font
                        }
                    }
                }

                FontMetrics
                {
                    id: fontMetrics
                    font: UM.Theme.getFont("default")
                }

                Cura.TertiaryButton
                {
                    text: catalog.i18nc("@info", "Search in the browser")
                    iconSource: UM.Theme.getIcon("LinkExternal")
                    visible: pageSelectionTabBar.currentItem.hasSearch
                    isIconOnRightSide: true
                    height: fontMetrics.height
                    textFont: fontMetrics.font
                    textColor: UM.Theme.getColor("text")

                    onClicked: content.item && Qt.openUrlExternally(content.item.searchInBrowserUrl)
                }

                // Page contents.
                Rectangle
                {
                    Layout.preferredWidth: parent.width
                    Layout.fillHeight: true
                    color: UM.Theme.getColor("detail_background")

                    // Page contents.
                    Loader
                    {
                        id: content
                        anchors.fill: parent
                        anchors.margins: UM.Theme.getSize("default_margin").width
                        source: "Plugins.qml"

                        Connections
                        {
                            target: content
                            function onLoaded()
                            {
                                pageTitle.text = content.item.pageTitle
                                searchStringChanged.connect(handleSearchStringChanged)
                            }
                            function handleSearchStringChanged(new_search)
                            {
                                content.item.model.searchString = new_search
                            }
                        }
                    }
                }
            }
        }
    }

    Rectangle
    {
        height: quitButton.height + 2 * UM.Theme.getSize("default_margin").width
        color: UM.Theme.getColor("primary")
        visible: restartManager.showRestartNotification
        anchors
        {
            left: parent.left
            right: parent.right
            bottom: parent.bottom
        }

        RowLayout
        {
            anchors
            {
                left: parent.left
                right: parent.right
                verticalCenter: parent.verticalCenter
                margins: UM.Theme.getSize("default_margin").width
            }
            spacing: UM.Theme.getSize("default_margin").width
            UM.RecolorImage
            {
                id: bannerIcon
                source: UM.Theme.getIcon("Plugin")

                color: UM.Theme.getColor("primary_button_text")
                implicitWidth: UM.Theme.getSize("banner_icon_size").width
                implicitHeight: UM.Theme.getSize("banner_icon_size").height
            }
            Text
            {
                color: UM.Theme.getColor("primary_button_text")
                text: catalog.i18nc("@button", "In order to use the package you will need to restart Cura")
                font: UM.Theme.getFont("default")
                renderType: Text.NativeRendering
                Layout.fillWidth: true
            }
            Cura.SecondaryButton
            {
                id: quitButton
                text: catalog.i18nc("@info:button, %1 is the application name", "Quit %1").arg(CuraApplication.applicationDisplayName)
                onClicked:
                {
                    marketplaceDialog.hide();
                    CuraApplication.closeApplication();
                }
            }
        }
    }
}