ToolboxProgressButton.qml 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. // Copyright (c) 2018 Ultimaker B.V.
  2. // Toolbox is released under the terms of the LGPLv3 or higher.
  3. import QtQuick 2.2
  4. import QtQuick.Controls 1.4
  5. import QtQuick.Controls.Styles 1.4
  6. import UM 1.1 as UM
  7. Item
  8. {
  9. id: base
  10. property var active: false
  11. property var complete: false
  12. property var readyLabel: catalog.i18nc("@action:button", "Install")
  13. property var activeLabel: catalog.i18nc("@action:button", "Cancel")
  14. property var completeLabel: catalog.i18nc("@action:button", "Installed")
  15. property var readyAction: null // Action when button is ready and clicked (likely install)
  16. property var activeAction: null // Action when button is active and clicked (likely cancel)
  17. property var completeAction: null // Action when button is complete and clicked (likely go to installed)
  18. width: UM.Theme.getSize("toolbox_action_button").width
  19. height: UM.Theme.getSize("toolbox_action_button").height
  20. Button
  21. {
  22. id: button
  23. text:
  24. {
  25. if (complete)
  26. {
  27. return completeLabel
  28. }
  29. else if (active)
  30. {
  31. return activeLabel
  32. }
  33. else
  34. {
  35. return readyLabel
  36. }
  37. }
  38. onClicked:
  39. {
  40. if (complete)
  41. {
  42. return completeAction()
  43. }
  44. else if (active)
  45. {
  46. return activeAction()
  47. }
  48. else
  49. {
  50. return readyAction()
  51. }
  52. }
  53. style: ButtonStyle
  54. {
  55. background: Rectangle
  56. {
  57. implicitWidth: UM.Theme.getSize("toolbox_action_button").width
  58. implicitHeight: UM.Theme.getSize("toolbox_action_button").height
  59. color:
  60. {
  61. if (base.complete)
  62. {
  63. return "transparent"
  64. }
  65. else
  66. {
  67. if (control.hovered)
  68. {
  69. return UM.Theme.getColor("primary_hover")
  70. }
  71. else
  72. {
  73. return UM.Theme.getColor("primary")
  74. }
  75. }
  76. }
  77. border
  78. {
  79. width:
  80. {
  81. if (base.complete)
  82. {
  83. UM.Theme.getSize("default_lining").width
  84. }
  85. else
  86. {
  87. return 0
  88. }
  89. }
  90. color:
  91. {
  92. if (control.hovered)
  93. {
  94. return UM.Theme.getColor("primary_hover")
  95. }
  96. else
  97. {
  98. return UM.Theme.getColor("lining")
  99. }
  100. }
  101. }
  102. }
  103. label: Label
  104. {
  105. text: control.text
  106. color:
  107. {
  108. if (base.complete)
  109. {
  110. return UM.Theme.getColor("text")
  111. }
  112. else
  113. {
  114. if (control.hovered)
  115. {
  116. return UM.Theme.getColor("button_text_hover")
  117. }
  118. else
  119. {
  120. return UM.Theme.getColor("button_text")
  121. }
  122. }
  123. }
  124. verticalAlignment: Text.AlignVCenter
  125. horizontalAlignment: Text.AlignHCenter
  126. font:
  127. {
  128. if (base.complete)
  129. {
  130. return UM.Theme.getFont("default")
  131. }
  132. else
  133. {
  134. return UM.Theme.getFont("default_bold")
  135. }
  136. }
  137. }
  138. }
  139. }
  140. AnimatedImage
  141. {
  142. id: loader
  143. visible: active
  144. source: visible ? "../images/loading.gif" : ""
  145. width: UM.Theme.getSize("toolbox_loader").width
  146. height: UM.Theme.getSize("toolbox_loader").height
  147. anchors.right: button.left
  148. anchors.rightMargin: UM.Theme.getSize("default_margin").width
  149. anchors.verticalCenter: button.verticalCenter
  150. }
  151. }