ManageButton.qml 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. // Copyright (c) 2021 Ultimaker B.V.
  2. // Cura is released under the terms of the LGPLv3 or higher.
  3. import QtQuick 2.15
  4. import QtQuick.Controls 2.15
  5. import QtQuick.Layouts 1.1
  6. import UM 1.6 as UM
  7. import Cura 1.6 as Cura
  8. Item
  9. {
  10. id: manageButton
  11. property bool button_style: true
  12. property string text
  13. property bool busy: false
  14. property bool confirmed: false
  15. implicitWidth: childrenRect.width
  16. implicitHeight: childrenRect.height
  17. signal clicked()
  18. property Component primaryButton: Component
  19. {
  20. Cura.PrimaryButton
  21. {
  22. text: manageButton.text
  23. onClicked: manageButton.clicked()
  24. }
  25. }
  26. property Component secondaryButton: Component
  27. {
  28. Cura.SecondaryButton
  29. {
  30. text: manageButton.text
  31. onClicked: manageButton.clicked()
  32. }
  33. }
  34. property Component busyButton: Component
  35. {
  36. Item
  37. {
  38. height: UM.Theme.getSize("action_button").height
  39. width: childrenRect.width
  40. UM.ColorImage
  41. {
  42. id: busyIndicator
  43. visible: parent.visible
  44. height: UM.Theme.getSize("action_button").height - 2 * UM.Theme.getSize("narrow_margin").height
  45. width: height
  46. anchors.left: parent.left
  47. anchors.verticalCenter: parent.verticalCenter
  48. source: UM.Theme.getIcon("Spinner")
  49. color: UM.Theme.getColor("primary")
  50. RotationAnimator
  51. {
  52. target: busyIndicator
  53. running: parent.visible
  54. from: 0
  55. to: 360
  56. loops: Animation.Infinite
  57. duration: 2500
  58. }
  59. }
  60. Label
  61. {
  62. visible: parent.visible
  63. anchors.left: busyIndicator.right
  64. anchors.leftMargin: UM.Theme.getSize("narrow_margin").width
  65. anchors.verticalCenter: parent.verticalCenter
  66. text: manageButton.text
  67. font: UM.Theme.getFont("medium_bold")
  68. color: UM.Theme.getColor("primary")
  69. }
  70. }
  71. }
  72. property Component confirmButton: Component
  73. {
  74. Item
  75. {
  76. height: UM.Theme.getSize("action_button").height
  77. width: childrenRect.width
  78. Label
  79. {
  80. anchors.verticalCenter: parent.verticalCenter
  81. text: manageButton.text
  82. font: UM.Theme.getFont("medium_bold")
  83. color: UM.Theme.getColor("primary")
  84. }
  85. }
  86. }
  87. Loader
  88. {
  89. sourceComponent:
  90. {
  91. if (busy) { return manageButton.busyButton; }
  92. else if (confirmed) { return manageButton.confirmButton; }
  93. else if (manageButton.button_style) { return manageButton.primaryButton; }
  94. else { return manageButton.secondaryButton; }
  95. }
  96. }
  97. }