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

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

import QtQuick 2.3
import QtQuick.Controls 2.15
import UM 1.5 as UM
import Cura 1.6 as Cura

/**
 * A MonitorInfoBlurb is an extension of the GenericPopUp used to show static information (vs. interactive context
 * menus). It accepts some text (text), an item to link to to (target), and a specification of which side of the target
 * to appear on (direction). It also sets the GenericPopUp's color to black, to differentiate itself from a menu.
 */
Item
{
    id: monitorContextMenu
    property alias target: popUp.target

    property var printJob: null

    //Everything in the pop-up only gets evaluated when showing the pop-up.
    //However we want to show the button for showing the pop-up only if there is anything visible inside it.
    //So compute here the visibility of the menu items, so that we can use it for the visibility of the button.
    property bool sendToTopVisible:
    {
        return printJob
            && (printJob.state == "queued" || printJob.state == "error")
            && !isAssigned(printJob)
            && OutputDevice
            && OutputDevice.queuedPrintJobs.length > 0
            && OutputDevice.canWriteOthersPrintJobs
            && OutputDevice.queuedPrintJobs[0].key != printJob.key;
    }
    
    property bool deleteVisible:
    {
        if(!printJob)
        {
            return false;
        }
        if(printJob.isMine)
        {
            if(!OutputDevice.canWriteOwnPrintJobs)
            {
                return false;
            }
        }
        else
        {
            if(!OutputDevice.canWriteOthersPrintJobs)
            {
                return false;
            }
        }
        var states = ["queued", "error", "sent_to_printer"];
        return states.indexOf(printJob.state) !== -1;
    }
    
    property bool pauseVisible:
    {
        if(!printJob)
        {
            return false;
        }
        if(printJob.isMine)
        {
            if(!OutputDevice.canWriteOwnPrintJobs)
            {
                return false;
            }
        }
        else
        {
            if(!OutputDevice.canWriteOthersPrintJobs)
            {
                return false;
            }
        }
        var states = ["printing", "pausing", "paused", "resuming"];
        return states.indexOf(printJob.state) !== -1;
    }

    property bool abortVisible:
    {
        if(!printJob)
        {
            return false;
        }
        if(printJob.isMine)
        {
            if(!OutputDevice.canWriteOwnPrintJobs)
            {
                return false;
            }
        }
        else
        {
            if(!OutputDevice.canWriteOthersPrintJobs)
            {
                return false;
            }
        }
        var states = ["pre_print", "printing", "pausing", "paused", "resuming"];
        return states.indexOf(printJob.state) !== -1;
    }

    property bool hasItems: sendToTopVisible || deleteVisible || pauseVisible || abortVisible

    GenericPopUp
    {
        id: popUp

        // Which way should the pop-up point? Default is up, but will flip when required
        direction: "up"

        // Use dark grey for info blurbs and white for context menus
        color: UM.Theme.getColor("monitor_context_menu")

        contentItem: Item
        {
            id: contentWrapper
            implicitWidth: childrenRect.width
            implicitHeight: menuItems.height + UM.Theme.getSize("default_margin").height

            Column
            {
                id: menuItems
                width: 144 * screenScaleFactor

                anchors
                {
                    top: parent.top
                    topMargin: Math.floor(UM.Theme.getSize("default_margin").height / 2)
                }

                spacing: Math.floor(UM.Theme.getSize("default_margin").height / 2)

                PrintJobContextMenuItem
                {
                    onClicked:
                    {
                        sendToTopConfirmationDialog.visible = true;
                        popUp.close();
                    }
                    text: catalog.i18nc("@label", "Move to top");
                    visible: monitorContextMenu.sendToTopVisible
                }

                PrintJobContextMenuItem
                {
                    onClicked:
                    {
                        deleteConfirmationDialog.visible = true;
                        popUp.close();
                    }
                    text: catalog.i18nc("@label", "Delete");
                    visible: monitorContextMenu.deleteVisible
                }

                PrintJobContextMenuItem
                {
                    enabled: visible && !(printJob.state == "pausing" || printJob.state == "resuming");
                    onClicked:
                    {
                        if (printJob.state == "paused")
                        {
                            printJob.setState("resume");
                            popUp.close();
                            return;
                        }
                        if (printJob.state == "printing")
                        {
                            printJob.setState("pause");
                            popUp.close();
                            return;
                        }
                    }
                    text:
                    {
                        if(!printJob)
                        {
                            return "";
                        }
                        switch(printJob.state)
                        {
                            case "paused":
                                return catalog.i18nc("@label", "Resume");
                            case "pausing":
                                return catalog.i18nc("@label", "Pausing...");
                            case "resuming":
                                return catalog.i18nc("@label", "Resuming...");
                            default:
                                catalog.i18nc("@label", "Pause");
                        }
                    }
                    visible: monitorContextMenu.pauseVisible
                }

                PrintJobContextMenuItem
                {
                    enabled: visible && printJob.state !== "aborting";
                    onClicked:
                    {
                        abortConfirmationDialog.visible = true;
                        popUp.close();
                    }
                    text: printJob && printJob.state == "aborting" ? catalog.i18nc("@label", "Aborting...") : catalog.i18nc("@label", "Abort");
                    visible: monitorContextMenu.abortVisible
                }
            }
        }
    }

    Cura.MessageDialog
    {
        id: sendToTopConfirmationDialog
        onAccepted: OutputDevice.sendJobToTop(printJob.key)
        standardButtons: Dialog.Yes | Dialog.No
        text: printJob && printJob.name ? catalog.i18nc("@label %1 is the name of a print job.", "Are you sure you want to move %1 to the top of the queue?").arg(printJob.name) : ""
        title: catalog.i18nc("@window:title", "Move print job to top")
    }

    Cura.MessageDialog
    {
        id: deleteConfirmationDialog
        onAccepted: OutputDevice.deleteJobFromQueue(printJob.key)
        standardButtons: Dialog.Yes | Dialog.No
        text: printJob && printJob.name ? catalog.i18nc("@label %1 is the name of a print job.", "Are you sure you want to delete %1?").arg(printJob.name) : ""
        title: catalog.i18nc("@window:title", "Delete print job")
    }

    Cura.MessageDialog
    {
        id: abortConfirmationDialog
        onAccepted: printJob.setState("abort")
        standardButtons: Dialog.Yes | Dialog.No
        text: printJob && printJob.name ? catalog.i18nc("@label %1 is the name of a print job.", "Are you sure you want to abort %1?").arg(printJob.name) : ""
        title: catalog.i18nc("@window:title", "Abort print")
    }

    function switchPopupState() {
        popUp.visible ? popUp.close() : popUp.open()
    }
    function open() {
        popUp.open()
    }
    function close() {
        popUp.close()
    }
    function isAssigned(job) {
        if (!job) {
            return false;
        }
        return job.assignedPrinter ? true : false;
    }
}