File: MonitorContextMenu.qml

package info (click to toggle)
cura 5.0.0-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 122,888 kB
  • sloc: python: 44,572; sh: 81; xml: 32; makefile: 16
file content (179 lines) | stat: -rw-r--r-- 6,867 bytes parent folder | download
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
// 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
{
    property alias target: popUp.target

    property var printJob: null

    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: {
                        if (printJob && (printJob.state == "queued" || printJob.state == "error") && !isAssigned(printJob)) {
                            if (OutputDevice && OutputDevice.queuedPrintJobs[0]) {
                                return OutputDevice.queuedPrintJobs[0].key != printJob.key;
                            }
                        }
                        return false;
                    }
                }

                PrintJobContextMenuItem {
                    onClicked: {
                        deleteConfirmationDialog.visible = true;
                        popUp.close();
                    }
                    text: catalog.i18nc("@label", "Delete");
                    visible: {
                        if (!printJob) {
                            return false;
                        }
                        var states = ["queued", "error", "sent_to_printer"];
                        return states.indexOf(printJob.state) !== -1;
                    }
                }

                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: {
                        if (!printJob) {
                            return false;
                        }
                        var states = ["printing", "pausing", "paused", "resuming"];
                        return states.indexOf(printJob.state) !== -1;
                    }
                }

                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: {
                        if (!printJob) {
                            return false;
                        }
                        var states = ["pre_print", "printing", "pausing", "paused", "resuming"];
                        return states.indexOf(printJob.state) !== -1;
                    }
                }
            }
        }
    }

    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;
    }
}