MonitorContextMenu.qml 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  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. // Due to an issue with the ordering if print jobs caused by the Qt list models,
  39. // we hide the 'move to top' feature for now as it's not displayed on the appropriate elements.
  40. // Solving the ordering issue will cost more time than we currently have available.
  41. PrintJobContextMenuItem {
  42. onClicked: {
  43. sendToTopConfirmationDialog.visible = true;
  44. popUp.close();
  45. }
  46. text: catalog.i18nc("@label", "Move to top");
  47. visible: {
  48. // if (printJob && (printJob.state == "queued" || printJob.state == "error") && !isAssigned(printJob)) {
  49. // if (OutputDevice && OutputDevice.queuedPrintJobs[0]) {
  50. // return OutputDevice.queuedPrintJobs[0].key != printJob.key;
  51. // }
  52. // }
  53. return false;
  54. }
  55. }
  56. PrintJobContextMenuItem {
  57. onClicked: {
  58. deleteConfirmationDialog.visible = true;
  59. popUp.close();
  60. }
  61. text: catalog.i18nc("@label", "Delete");
  62. visible: {
  63. if (!printJob) {
  64. return false;
  65. }
  66. var states = ["queued", "error", "sent_to_printer"];
  67. return states.indexOf(printJob.state) !== -1;
  68. }
  69. }
  70. PrintJobContextMenuItem {
  71. enabled: visible && !(printJob.state == "pausing" || printJob.state == "resuming");
  72. onClicked: {
  73. if (printJob.state == "paused") {
  74. printJob.setState("resume");
  75. popUp.close();
  76. return;
  77. }
  78. if (printJob.state == "printing") {
  79. printJob.setState("pause");
  80. popUp.close();
  81. return;
  82. }
  83. }
  84. text: {
  85. if (!printJob) {
  86. return "";
  87. }
  88. switch(printJob.state) {
  89. case "paused":
  90. return catalog.i18nc("@label", "Resume");
  91. case "pausing":
  92. return catalog.i18nc("@label", "Pausing...");
  93. case "resuming":
  94. return catalog.i18nc("@label", "Resuming...");
  95. default:
  96. catalog.i18nc("@label", "Pause");
  97. }
  98. }
  99. visible: {
  100. if (!printJob) {
  101. return false;
  102. }
  103. var states = ["printing", "pausing", "paused", "resuming"];
  104. return states.indexOf(printJob.state) !== -1;
  105. }
  106. }
  107. PrintJobContextMenuItem {
  108. enabled: visible && printJob.state !== "aborting";
  109. onClicked: {
  110. abortConfirmationDialog.visible = true;
  111. popUp.close();
  112. }
  113. text: printJob && printJob.state == "aborting" ? catalog.i18nc("@label", "Aborting...") : catalog.i18nc("@label", "Abort");
  114. visible: {
  115. if (!printJob) {
  116. return false;
  117. }
  118. var states = ["pre_print", "printing", "pausing", "paused", "resuming"];
  119. return states.indexOf(printJob.state) !== -1;
  120. }
  121. }
  122. }
  123. }
  124. }
  125. MessageDialog {
  126. id: sendToTopConfirmationDialog
  127. Component.onCompleted: visible = false
  128. icon: StandardIcon.Warning
  129. onYes: OutputDevice.sendJobToTop(printJob.key)
  130. standardButtons: StandardButton.Yes | StandardButton.No
  131. 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) : ""
  132. title: catalog.i18nc("@window:title", "Move print job to top")
  133. }
  134. MessageDialog {
  135. id: deleteConfirmationDialog
  136. Component.onCompleted: visible = false
  137. icon: StandardIcon.Warning
  138. onYes: OutputDevice.deleteJobFromQueue(printJob.key)
  139. standardButtons: StandardButton.Yes | StandardButton.No
  140. 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) : ""
  141. title: catalog.i18nc("@window:title", "Delete print job")
  142. }
  143. MessageDialog {
  144. id: abortConfirmationDialog
  145. Component.onCompleted: visible = false
  146. icon: StandardIcon.Warning
  147. onYes: printJob.setState("abort")
  148. standardButtons: StandardButton.Yes | StandardButton.No
  149. 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) : ""
  150. title: catalog.i18nc("@window:title", "Abort print")
  151. }
  152. function switchPopupState() {
  153. popUp.visible ? popUp.close() : popUp.open()
  154. }
  155. function open() {
  156. popUp.open()
  157. }
  158. function close() {
  159. popUp.close()
  160. }
  161. function isAssigned(job) {
  162. if (!job) {
  163. return false;
  164. }
  165. return job.assignedPrinter ? true : false;
  166. }
  167. }