ManageButton.qml 3.7 KB

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