ManageButton.qml 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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. RowLayout
  9. {
  10. id: manageButton
  11. property alias primaryText: primaryButton.text
  12. property alias secondaryText: secondaryButton.text
  13. property string busyPrimaryText: busyMessageText.text
  14. property string busySecondaryText: busyMessageText.text
  15. property string mainState: "primary"
  16. property bool enabled: true
  17. property bool busy
  18. signal clicked(bool primary_action)
  19. Cura.PrimaryButton
  20. {
  21. id: primaryButton
  22. visible: false
  23. enabled: manageButton.enabled
  24. onClicked:
  25. {
  26. manageButton.clicked(true)
  27. }
  28. }
  29. Cura.SecondaryButton
  30. {
  31. id: secondaryButton
  32. visible: false
  33. enabled: manageButton.enabled
  34. onClicked:
  35. {
  36. manageButton.clicked(false)
  37. }
  38. }
  39. Item
  40. {
  41. id: busyMessage
  42. visible: false
  43. height: UM.Theme.getSize("action_button").height
  44. width: childrenRect.width
  45. BusyIndicator
  46. {
  47. id: busyIndicator
  48. visible: parent.visible
  49. width: height
  50. anchors.left: parent.left
  51. anchors.top: parent.top
  52. anchors.bottom: parent.bottom
  53. palette.dark: UM.Theme.getColor("text")
  54. RotationAnimator
  55. {
  56. target: busyIndicator.contentItem
  57. running: busyIndicator.visible && busyIndicator.running
  58. from: 0
  59. to: 360
  60. loops: Animation.Infinite
  61. duration: 2500
  62. }
  63. }
  64. Label
  65. {
  66. id: busyMessageText
  67. visible: parent.visible
  68. text: manageButton.mainState == "primary" ? manageButton.busyPrimaryText : manageButton.busySecondaryText
  69. anchors.left: busyIndicator.right
  70. anchors.verticalCenter: parent.verticalCenter
  71. font: UM.Theme.getFont("default")
  72. color: UM.Theme.getColor("text")
  73. }
  74. }
  75. states:
  76. [
  77. State
  78. {
  79. name: "primary"
  80. PropertyChanges
  81. {
  82. target: primaryButton
  83. visible: true
  84. }
  85. PropertyChanges
  86. {
  87. target: secondaryButton
  88. visible: false
  89. }
  90. PropertyChanges
  91. {
  92. target: busyMessage
  93. visible: false
  94. }
  95. },
  96. State
  97. {
  98. name: "secondary"
  99. PropertyChanges
  100. {
  101. target: primaryButton
  102. visible: false
  103. }
  104. PropertyChanges
  105. {
  106. target: secondaryButton
  107. visible: true
  108. }
  109. PropertyChanges
  110. {
  111. target: busyMessage
  112. visible: false
  113. }
  114. },
  115. State
  116. {
  117. name: "hidden"
  118. PropertyChanges
  119. {
  120. target: manageButton
  121. visible: false
  122. }
  123. },
  124. State
  125. {
  126. name: "busy"
  127. PropertyChanges
  128. {
  129. target: primaryButton
  130. visible: false
  131. }
  132. PropertyChanges
  133. {
  134. target: secondaryButton
  135. visible: false
  136. }
  137. PropertyChanges
  138. {
  139. target: busyMessage
  140. visible: manageButton.visible
  141. }
  142. }
  143. ]
  144. }