SyncButton.qml 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. // Copyright (c) 2018 Ultimaker B.V.
  2. // Cura is released under the terms of the LGPLv3 or higher.
  3. import QtQuick 2.7
  4. import QtQuick.Controls 1.4
  5. import QtQuick.Controls.Styles 1.4
  6. import UM 1.2 as UM
  7. import Cura 1.0 as Cura
  8. Button
  9. {
  10. id: base
  11. property var outputDevice: null
  12. property var matched: updateOnSync()
  13. text: matched == true ? "Yes" : "No"
  14. width: parent.width
  15. height: parent.height
  16. function updateOnSync() {
  17. if (outputDevice != undefined) {
  18. for (var index in outputDevice.uniqueConfigurations) {
  19. var configuration = outputDevice.uniqueConfigurations[index]
  20. if (Cura.MachineManager.matchesConfiguration(configuration)) {
  21. base.matched = true;
  22. return;
  23. }
  24. }
  25. }
  26. base.matched = false;
  27. }
  28. style: ButtonStyle
  29. {
  30. background: Rectangle
  31. {
  32. color:
  33. {
  34. if(control.pressed)
  35. {
  36. return UM.Theme.getColor("sidebar_header_active");
  37. }
  38. else if(control.hovered)
  39. {
  40. return UM.Theme.getColor("sidebar_header_hover");
  41. }
  42. else
  43. {
  44. return UM.Theme.getColor("sidebar_header_bar");
  45. }
  46. }
  47. Behavior on color { ColorAnimation { duration: 50; } }
  48. UM.RecolorImage
  49. {
  50. id: downArrow
  51. anchors.verticalCenter: parent.verticalCenter
  52. anchors.right: parent.right
  53. anchors.rightMargin: UM.Theme.getSize("default_margin").width
  54. width: UM.Theme.getSize("standard_arrow").width
  55. height: UM.Theme.getSize("standard_arrow").height
  56. sourceSize.width: width
  57. sourceSize.height: height
  58. color: UM.Theme.getColor("text_emphasis")
  59. source: UM.Theme.getIcon("arrow_bottom")
  60. }
  61. UM.RecolorImage {
  62. id: sidebarComboBoxLabel
  63. anchors.left: parent.left
  64. anchors.leftMargin: UM.Theme.getSize("default_margin").width
  65. anchors.verticalCenter: parent.verticalCenter;
  66. width: UM.Theme.getSize("printer_sync_icon").width
  67. height: UM.Theme.getSize("printer_sync_icon").height
  68. color: control.matched ? UM.Theme.getColor("printer_config_matched") : UM.Theme.getColor("printer_config_mismatch")
  69. source: UM.Theme.getIcon("tab_status_connected")
  70. sourceSize.width: width
  71. sourceSize.height: height
  72. }
  73. }
  74. label: Label {}
  75. }
  76. onClicked:
  77. {
  78. panelVisible = !panelVisible
  79. }
  80. Connections {
  81. target: outputDevice
  82. onUniqueConfigurationsChanged: {
  83. updateOnSync()
  84. }
  85. }
  86. Connections {
  87. target: Cura.MachineManager
  88. onCurrentConfigurationChanged: {
  89. updateOnSync()
  90. }
  91. }
  92. }