SaveButton.qml 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. // Copyright (c) 2015 Ultimaker B.V.
  2. // Cura is released under the terms of the AGPLv3 or higher.
  3. import QtQuick 2.2
  4. import QtQuick.Controls 1.1
  5. import QtQuick.Controls.Styles 1.1
  6. import QtQuick.Layouts 1.1
  7. import UM 1.1 as UM
  8. Rectangle {
  9. id: base;
  10. property real progress: UM.Backend.progress;
  11. property bool activity: Printer.getPlatformActivity;
  12. Behavior on progress { NumberAnimation { duration: 250; } }
  13. property variant printDuration: PrintInformation.currentPrintTime;
  14. property real printMaterialAmount: PrintInformation.materialAmount;
  15. Rectangle{
  16. id: background
  17. implicitWidth: base.width;
  18. implicitHeight: parent.height;
  19. color: UM.Theme.colors.save_button_background;
  20. border.width: UM.Theme.sizes.save_button_border.width
  21. border.color: UM.Theme.colors.save_button_border
  22. Rectangle {
  23. id: infoBox
  24. width: parent.width - UM.Theme.sizes.default_margin.width * 2;
  25. height: UM.Theme.sizes.save_button_slicing_bar.height
  26. anchors.top: parent.top
  27. anchors.topMargin: UM.Theme.sizes.default_margin.height;
  28. anchors.left: parent.left
  29. anchors.leftMargin: UM.Theme.sizes.default_margin.width;
  30. border.width: UM.Theme.sizes.save_button_border.width
  31. border.color: UM.Theme.colors.save_button_border
  32. color: UM.Theme.colors.save_button_estimated_text_background;
  33. Label {
  34. id: label;
  35. anchors.verticalCenter: parent.verticalCenter
  36. anchors.left: parent.left
  37. anchors.leftMargin: UM.Theme.sizes.save_button_text_margin.width;
  38. visible: base.progress >= 0 && base.progress < 0.99 ? false : true
  39. color: UM.Theme.colors.save_button_estimated_text;
  40. font: UM.Theme.fonts.small;
  41. text: {
  42. if(base.activity == false) {
  43. //: Save button label
  44. return qsTr("Please load a 3D model");
  45. } else if (base.progress < 0.99) {
  46. //: Save button label
  47. return qsTr("Calculating Print-time");
  48. } else if (base.printDuration.days > 0 || base.progress == null){
  49. return qsTr("");
  50. }
  51. else if (base.progress > 0.99){
  52. //: Save button label
  53. return qsTr("Estimated Print-time");
  54. }
  55. return "";
  56. }
  57. }
  58. Label {
  59. id: printDurationLabel
  60. anchors.verticalCenter: parent.verticalCenter
  61. anchors.left: label.right;
  62. anchors.leftMargin: UM.Theme.sizes.save_button_text_margin.width;
  63. color: UM.Theme.colors.save_button_printtime_text;
  64. font: UM.Theme.fonts.small;
  65. visible: base.activity == false || base.progress < 0.99 ? false : true
  66. text: (!base.printDuration || !base.printDuration.valid) ? "" : base.printDuration.getDisplayString(UM.DurationFormat.Long);
  67. }
  68. Label {
  69. id: printMaterialLabel
  70. anchors.verticalCenter: parent.verticalCenter
  71. anchors.left: printDurationLabel.right;
  72. anchors.leftMargin: UM.Theme.sizes.save_button_text_margin.width;
  73. color: base.printDuration.days > 0 ? UM.Theme.colors.save_button_estimated_text : UM.Theme.colors.save_button_printtime_text;
  74. font: UM.Theme.fonts.small;
  75. property bool mediumLengthDuration: base.printDuration.hours > 9 && base.printMaterialAmount > 9.99 && base.printDuration.days == 0
  76. width: mediumLengthDuration ? 50 : undefined
  77. elide: mediumLengthDuration ? Text.ElideRight : Text.ElideNone
  78. visible: base.activity == false || base.progress < 0.99 ? false : true
  79. //: Print material amount save button label
  80. text: base.printMaterialAmount < 0 ? "" : qsTr("%1m of Material").arg(base.printMaterialAmount);
  81. }
  82. }
  83. Rectangle {
  84. id: infoBoxOverlay
  85. anchors {
  86. left: infoBox.left;
  87. top: infoBox.top;
  88. bottom: infoBox.bottom;
  89. }
  90. width: Math.max(infoBox.width * base.progress);
  91. color: UM.Theme.colors.save_button_active
  92. visible: progress > 0.99 ? false : true
  93. }
  94. Button {
  95. id: saveToButton
  96. anchors.top: infoBox.bottom
  97. anchors.topMargin: UM.Theme.sizes.save_button_text_margin.height;
  98. anchors.left: parent.left
  99. anchors.leftMargin: UM.Theme.sizes.default_margin.width;
  100. tooltip: UM.OutputDeviceManager.activeDeviceDescription;
  101. enabled: progress > 0.99 && base.activity == true
  102. width: infoBox.width/6*4.5
  103. height: UM.Theme.sizes.save_button_save_to_button.height
  104. text: UM.OutputDeviceManager.activeDeviceShortDescription;
  105. style: ButtonStyle {
  106. background: Rectangle {
  107. color: !control.enabled ? UM.Theme.colors.save_button_inactive : control.hovered ? UM.Theme.colors.save_button_active_hover : UM.Theme.colors.save_button_active;
  108. Label {
  109. anchors.centerIn: parent
  110. color: UM.Theme.colors.save_button_safe_to_text;
  111. font: UM.Theme.fonts.sidebar_save_to;
  112. text: control.text;
  113. }
  114. }
  115. label: Item { }
  116. }
  117. onClicked: UM.OutputDeviceManager.requestWriteToDevice(UM.OutputDeviceManager.activeDevice)
  118. }
  119. Button {
  120. id: deviceSelectionMenu;
  121. anchors.top: infoBox.bottom
  122. anchors.topMargin: UM.Theme.sizes.save_button_text_margin.height
  123. anchors.right: parent.right
  124. anchors.rightMargin: UM.Theme.sizes.default_margin.width;
  125. tooltip: qsTr("Select the active output device");
  126. width: infoBox.width/6*1.3 - UM.Theme.sizes.save_button_text_margin.height;
  127. height: UM.Theme.sizes.save_button_save_to_button.height
  128. iconSource: UM.Theme.icons[UM.OutputDeviceManager.activeDeviceIconName];
  129. style: ButtonStyle {
  130. background: Rectangle {
  131. color: UM.Theme.colors.save_button_background;
  132. border.width: control.hovered ? UM.Theme.sizes.save_button_border.width : 0
  133. border.color: UM.Theme.colors.save_button_border
  134. Rectangle {
  135. id: deviceSelectionIcon
  136. color: UM.Theme.colors.save_button_background;
  137. anchors.left: parent.left
  138. anchors.leftMargin: UM.Theme.sizes.save_button_text_margin.width / 2;
  139. anchors.verticalCenter: parent.verticalCenter;
  140. width: parent.height - UM.Theme.sizes.save_button_text_margin.width ;
  141. height: parent.height - UM.Theme.sizes.save_button_text_margin.width;
  142. UM.RecolorImage {
  143. anchors.fill: parent;
  144. sourceSize.width: width;
  145. sourceSize.height: height;
  146. color: UM.Theme.colors.save_button_active
  147. source: control.iconSource;
  148. }
  149. }
  150. Label {
  151. id: deviceSelectionArrow
  152. anchors.right: parent.right;
  153. anchors.rightMargin: UM.Theme.sizes.save_button_text_margin.height
  154. anchors.verticalCenter: parent.verticalCenter;
  155. text: "▼";
  156. font: UM.Theme.fonts.tiny;
  157. color: UM.Theme.colors.save_button_active;
  158. }
  159. }
  160. label: Item { }
  161. }
  162. menu: Menu {
  163. id: devicesMenu;
  164. Instantiator {
  165. model: devicesModel;
  166. MenuItem {
  167. text: model.description
  168. checkable: true;
  169. checked: model.id == UM.OutputDeviceManager.activeDevice;
  170. exclusiveGroup: devicesMenuGroup;
  171. onTriggered: {
  172. UM.OutputDeviceManager.setActiveDevice(model.id);
  173. }
  174. }
  175. onObjectAdded: devicesMenu.insertItem(index, object)
  176. onObjectRemoved: devicesMenu.removeItem(object)
  177. }
  178. ExclusiveGroup { id: devicesMenuGroup; }
  179. }
  180. }
  181. }
  182. UM.OutputDevicesModel {
  183. id: devicesModel;
  184. }
  185. }