MonitorContextMenu.qml 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. // Copyright (c) 2018 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.0
  5. import QtQuick.Dialogs 1.1
  6. import UM 1.3 as UM
  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("print");
  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. MessageDialog {
  123. id: sendToTopConfirmationDialog
  124. Component.onCompleted: visible = false
  125. icon: StandardIcon.Warning
  126. onYes: OutputDevice.sendJobToTop(printJob.key)
  127. standardButtons: StandardButton.Yes | StandardButton.No
  128. 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) : ""
  129. title: catalog.i18nc("@window:title", "Move print job to top")
  130. }
  131. MessageDialog {
  132. id: deleteConfirmationDialog
  133. Component.onCompleted: visible = false
  134. icon: StandardIcon.Warning
  135. onYes: OutputDevice.deleteJobFromQueue(printJob.key)
  136. standardButtons: StandardButton.Yes | StandardButton.No
  137. 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) : ""
  138. title: catalog.i18nc("@window:title", "Delete print job")
  139. }
  140. MessageDialog {
  141. id: abortConfirmationDialog
  142. Component.onCompleted: visible = false
  143. icon: StandardIcon.Warning
  144. onYes: printJob.setState("abort")
  145. standardButtons: StandardButton.Yes | StandardButton.No
  146. 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) : ""
  147. title: catalog.i18nc("@window:title", "Abort print")
  148. }
  149. function switchPopupState() {
  150. popUp.visible ? popUp.close() : popUp.open()
  151. }
  152. function open() {
  153. popUp.open()
  154. }
  155. function close() {
  156. popUp.close()
  157. }
  158. function isAssigned(job) {
  159. if (!job) {
  160. return false;
  161. }
  162. return job.assignedPrinter ? true : false;
  163. }
  164. }