MonitorContextMenu.qml 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. // Copyright (c) 2022 Ultimaker B.V.
  2. // Cura is released under the terms of the LGPLv3 or higher.
  3. import QtQuick 2.3
  4. import QtQuick.Controls 2.15
  5. import UM 1.5 as UM
  6. import Cura 1.6 as Cura
  7. /**
  8. * A MonitorInfoBlurb is an extension of the GenericPopUp used to show static information (vs. interactive context
  9. * menus). It accepts some text (text), an item to link to to (target), and a specification of which side of the target
  10. * to appear on (direction). It also sets the GenericPopUp's color to black, to differentiate itself from a menu.
  11. */
  12. Item
  13. {
  14. property alias target: popUp.target
  15. property var printJob: null
  16. GenericPopUp
  17. {
  18. id: popUp
  19. // Which way should the pop-up point? Default is up, but will flip when required
  20. direction: "up"
  21. // Use dark grey for info blurbs and white for context menus
  22. color: UM.Theme.getColor("monitor_context_menu")
  23. contentItem: Item
  24. {
  25. id: contentWrapper
  26. implicitWidth: childrenRect.width
  27. implicitHeight: menuItems.height + UM.Theme.getSize("default_margin").height
  28. Column
  29. {
  30. id: menuItems
  31. width: 144 * screenScaleFactor
  32. anchors
  33. {
  34. top: parent.top
  35. topMargin: Math.floor(UM.Theme.getSize("default_margin").height / 2)
  36. }
  37. spacing: Math.floor(UM.Theme.getSize("default_margin").height / 2)
  38. PrintJobContextMenuItem {
  39. onClicked: {
  40. sendToTopConfirmationDialog.visible = true;
  41. popUp.close();
  42. }
  43. text: catalog.i18nc("@label", "Move to top");
  44. visible: {
  45. if (printJob && (printJob.state == "queued" || printJob.state == "error") && !isAssigned(printJob)) {
  46. if (OutputDevice && OutputDevice.queuedPrintJobs[0]) {
  47. return OutputDevice.queuedPrintJobs[0].key != printJob.key;
  48. }
  49. }
  50. return false;
  51. }
  52. }
  53. PrintJobContextMenuItem {
  54. onClicked: {
  55. deleteConfirmationDialog.visible = true;
  56. popUp.close();
  57. }
  58. text: catalog.i18nc("@label", "Delete");
  59. visible: {
  60. if (!printJob) {
  61. return false;
  62. }
  63. var states = ["queued", "error", "sent_to_printer"];
  64. return states.indexOf(printJob.state) !== -1;
  65. }
  66. }
  67. PrintJobContextMenuItem {
  68. enabled: visible && !(printJob.state == "pausing" || printJob.state == "resuming");
  69. onClicked: {
  70. if (printJob.state == "paused") {
  71. printJob.setState("resume");
  72. popUp.close();
  73. return;
  74. }
  75. if (printJob.state == "printing") {
  76. printJob.setState("pause");
  77. popUp.close();
  78. return;
  79. }
  80. }
  81. text: {
  82. if (!printJob) {
  83. return "";
  84. }
  85. switch(printJob.state) {
  86. case "paused":
  87. return catalog.i18nc("@label", "Resume");
  88. case "pausing":
  89. return catalog.i18nc("@label", "Pausing...");
  90. case "resuming":
  91. return catalog.i18nc("@label", "Resuming...");
  92. default:
  93. catalog.i18nc("@label", "Pause");
  94. }
  95. }
  96. visible: {
  97. if (!printJob) {
  98. return false;
  99. }
  100. var states = ["printing", "pausing", "paused", "resuming"];
  101. return states.indexOf(printJob.state) !== -1;
  102. }
  103. }
  104. PrintJobContextMenuItem {
  105. enabled: visible && printJob.state !== "aborting";
  106. onClicked: {
  107. abortConfirmationDialog.visible = true;
  108. popUp.close();
  109. }
  110. text: printJob && printJob.state == "aborting" ? catalog.i18nc("@label", "Aborting...") : catalog.i18nc("@label", "Abort");
  111. visible: {
  112. if (!printJob) {
  113. return false;
  114. }
  115. var states = ["pre_print", "printing", "pausing", "paused", "resuming"];
  116. return states.indexOf(printJob.state) !== -1;
  117. }
  118. }
  119. }
  120. }
  121. }
  122. Cura.MessageDialog
  123. {
  124. id: sendToTopConfirmationDialog
  125. onAccepted: OutputDevice.sendJobToTop(printJob.key)
  126. standardButtons: Dialog.Yes | Dialog.No
  127. 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) : ""
  128. title: catalog.i18nc("@window:title", "Move print job to top")
  129. }
  130. Cura.MessageDialog
  131. {
  132. id: deleteConfirmationDialog
  133. onAccepted: OutputDevice.deleteJobFromQueue(printJob.key)
  134. standardButtons: Dialog.Yes | Dialog.No
  135. 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) : ""
  136. title: catalog.i18nc("@window:title", "Delete print job")
  137. }
  138. Cura.MessageDialog
  139. {
  140. id: abortConfirmationDialog
  141. onAccepted: printJob.setState("abort")
  142. standardButtons: Dialog.Yes | Dialog.No
  143. 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) : ""
  144. title: catalog.i18nc("@window:title", "Abort print")
  145. }
  146. function switchPopupState() {
  147. popUp.visible ? popUp.close() : popUp.open()
  148. }
  149. function open() {
  150. popUp.open()
  151. }
  152. function close() {
  153. popUp.close()
  154. }
  155. function isAssigned(job) {
  156. if (!job) {
  157. return false;
  158. }
  159. return job.assignedPrinter ? true : false;
  160. }
  161. }