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

MachineSelector.qml « PrinterSelector « qml « resources - github.com/Ultimaker/Cura.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 12f495f7a86111b16959cb14ed75ce83530c1432 (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
// Copyright (c) 2022 Ultimaker B.V.
// Cura is released under the terms of the LGPLv3 or higher.

import QtQuick 2.7
import QtQuick.Controls 2.3

import UM 1.5 as UM
import Cura 1.1 as Cura

Cura.ExpandablePopup
{
    id: machineSelector

    property bool isNetworkPrinter: Cura.MachineManager.activeMachineHasNetworkConnection
    property bool isConnectedCloudPrinter: Cura.MachineManager.activeMachineHasCloudConnection
    property bool isCloudRegistered: Cura.MachineManager.activeMachineHasCloudRegistration
    property bool isGroup: Cura.MachineManager.activeMachineIsGroup

    readonly property string connectionStatus: {
        if (isNetworkPrinter)
        {
            return "printer_connected"
        }
        else if (isConnectedCloudPrinter && Cura.API.connectionStatus.isInternetReachable)
        {
            return "printer_cloud_connected"
        }
        else if (isCloudRegistered)
        {
            return "printer_cloud_not_available"
        }
        else
        {
            return ""
        }
    }

    function getConnectionStatusMessage() {
        if (connectionStatus == "printer_cloud_not_available")
        {
            if(Cura.API.connectionStatus.isInternetReachable)
            {
                if (Cura.API.account.isLoggedIn)
                {
                    if (Cura.MachineManager.activeMachineIsLinkedToCurrentAccount)
                    {
                        return catalog.i18nc("@status", "The cloud printer is offline. Please check if the printer is turned on and connected to the internet.")
                    }
                    else
                    {
                        return catalog.i18nc("@status", "This printer is not linked to your account. Please visit the Ultimaker Digital Factory to establish a connection.")
                    }
                }
                else
                {
                    return catalog.i18nc("@status", "The cloud connection is currently unavailable. Please sign in to connect to the cloud printer.")
                }
            } else
            {
                return catalog.i18nc("@status", "The cloud connection is currently unavailable. Please check your internet connection.")
            }
        }
        else
        {
            return ""
        }
    }

    contentPadding: UM.Theme.getSize("default_lining").width
    contentAlignment: Cura.ExpandablePopup.ContentAlignment.AlignLeft

    UM.I18nCatalog
    {
        id: catalog
        name: "cura"
    }

    headerItem: Cura.IconWithText
    {
        text:
        {
            if (isNetworkPrinter && Cura.MachineManager.activeMachineNetworkGroupName != "")
            {
                return Cura.MachineManager.activeMachineNetworkGroupName
            }
            if(Cura.MachineManager.activeMachine != null)
            {
                return Cura.MachineManager.activeMachine.name
            }
            return ""
        }
        source:
        {
            if (isGroup)
            {
                return UM.Theme.getIcon("PrinterTriple", "medium")
            }
            else if (isNetworkPrinter || isCloudRegistered)
            {
                return UM.Theme.getIcon("Printer", "medium")
            }
            else
            {
                return ""
            }
        }
        font: UM.Theme.getFont("medium")
        iconColor: UM.Theme.getColor("machine_selector_printer_icon")
        iconSize: source != "" ? UM.Theme.getSize("machine_selector_icon").width: 0

        UM.RecolorImage
        {
            id: connectionStatusImage
            anchors
            {
                bottom: parent.bottom
                bottomMargin: - Math.round(height * 1 / 6)
                left: parent.left
                leftMargin: iconSize - Math.round(width * 5 / 6)
            }

            source:
            {
                if (connectionStatus == "printer_connected")
                {
                    return UM.Theme.getIcon("CheckBlueBG", "low")
                }
                else if (connectionStatus == "printer_cloud_connected" || connectionStatus == "printer_cloud_not_available")
                {
                    return UM.Theme.getIcon("CloudBadge", "low")
                }
                else
                {
                    return ""
                }
            }

            width: UM.Theme.getSize("printer_status_icon").width
            height: UM.Theme.getSize("printer_status_icon").height

            color: connectionStatus == "printer_cloud_not_available" ? UM.Theme.getColor("cloud_unavailable") : UM.Theme.getColor("primary")

            visible: isNetworkPrinter || isCloudRegistered

            // Make a themable circle in the background so we can change it in other themes
            Rectangle
            {
                id: iconBackground
                anchors.centerIn: parent
                width: parent.width - 1.5  //1.5 pixels smaller, (at least sqrt(2), regardless of screen pixel scale) so that the circle doesn't show up behind the icon due to anti-aliasing.
                height: parent.height - 1.5
                radius: width / 2
                color: UM.Theme.getColor("connection_badge_background")
                z: parent.z - 1
            }

        }

        MouseArea // Connection status tooltip hover area
        {
            id: connectionStatusTooltipHoverArea
            anchors.fill: parent
            hoverEnabled: getConnectionStatusMessage() !== ""
            acceptedButtons: Qt.NoButton // react to hover only, don't steal clicks

            onEntered:
            {
                machineSelector.mouseArea.entered() // we want both this and the outer area to be entered
                tooltip.tooltipText = getConnectionStatusMessage()
                tooltip.show()
            }
            onExited: { tooltip.hide() }
        }

        UM.ToolTip
        {
            id: tooltip

            width: 250 * screenScaleFactor
            tooltipText: getConnectionStatusMessage()
            arrowSize: UM.Theme.getSize("button_tooltip_arrow").width
            x: connectionStatusImage.x - UM.Theme.getSize("narrow_margin").width
            y: connectionStatusImage.y + connectionStatusImage.height + UM.Theme.getSize("narrow_margin").height
            z: popup.z + 1
            targetPoint: Qt.point(
                connectionStatusImage.x + Math.round(connectionStatusImage.width / 2),
                connectionStatusImage.y
            )
        }
    }

    contentItem: Item
    {
        id: popup
        width: UM.Theme.getSize("machine_selector_widget_content").width
        height: Math.min(machineSelectorList.contentHeight + separator.height + buttonRow.height, UM.Theme.getSize("machine_selector_widget_content").height) //Maximum height is the theme entry.

        MachineSelectorList
        {
            id: machineSelectorList
            anchors
            {
                left: parent.left
                leftMargin: UM.Theme.getSize("default_lining").width
                right: parent.right
                rightMargin: UM.Theme.getSize("default_lining").width
                top: parent.top
                bottom: separator.top
            }
            clip: true
        }

        Rectangle
        {
            id: separator
            anchors.bottom: buttonRow.top
            width: parent.width
            height: UM.Theme.getSize("default_lining").height
            color: UM.Theme.getColor("lining")
        }

        Row
        {
            id: buttonRow

            anchors.bottom: parent.bottom
            anchors.horizontalCenter: parent.horizontalCenter
            padding: UM.Theme.getSize("default_margin").width
            spacing: UM.Theme.getSize("default_margin").width

            Cura.SecondaryButton
            {
                id: addPrinterButton
                leftPadding: UM.Theme.getSize("default_margin").width
                rightPadding: UM.Theme.getSize("default_margin").width
                text: catalog.i18nc("@button", "Add printer")
                // The maximum width of the button is half of the total space, minus the padding of the parent, the left
                // padding of the component and half the spacing because of the space between buttons.
                fixedWidthMode: true
                width: UM.Theme.getSize("machine_selector_widget_content").width / 2 - leftPadding
                onClicked:
                {
                    toggleContent()
                    Cura.Actions.addMachine.trigger()
                }
            }

            Cura.SecondaryButton
            {
                id: managePrinterButton
                leftPadding: UM.Theme.getSize("default_margin").width
                rightPadding: UM.Theme.getSize("default_margin").width
                text: catalog.i18nc("@button", "Manage printers")
                fixedWidthMode: true
                // The maximum width of the button is half of the total space, minus the padding of the parent, the right
                // padding of the component and half the spacing because of the space between buttons.
                width: UM.Theme.getSize("machine_selector_widget_content").width / 2 - leftPadding
                onClicked:
                {
                    toggleContent()
                    Cura.Actions.configureMachines.trigger()
                }
            }
        }
    }
}