AccountWidget.qml 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. // Copyright (c) 2018 Ultimaker B.V.
  2. // Cura is released under the terms of the LGPLv3 or higher.
  3. import QtQuick 2.10
  4. import QtQuick.Controls 2.3
  5. import UM 1.5 as UM
  6. import Cura 1.1 as Cura
  7. Item
  8. {
  9. property var profile: Cura.API.account.userProfile
  10. property var loggedIn: Cura.API.account.isLoggedIn
  11. height: signInButton.visible ? signInButton.height : accountWidget.height
  12. width: signInButton.visible ? signInButton.width : accountWidget.width
  13. Button
  14. {
  15. id: signInButton
  16. anchors.verticalCenter: parent.verticalCenter
  17. text: catalog.i18nc("@action:button", "Sign in")
  18. height: Math.round(0.5 * UM.Theme.getSize("main_window_header").height)
  19. onClicked: popup.opened ? popup.close() : popup.open()
  20. visible: !loggedIn
  21. hoverEnabled: true
  22. background: Rectangle
  23. {
  24. radius: UM.Theme.getSize("action_button_radius").width
  25. color: UM.Theme.getColor("main_window_header_background")
  26. border.width: UM.Theme.getSize("default_lining").width
  27. border.color: UM.Theme.getColor("primary_text")
  28. Rectangle
  29. {
  30. anchors.fill: parent
  31. radius: parent.radius
  32. color: UM.Theme.getColor("primary_text")
  33. opacity: signInButton.hovered ? 0.2 : 0
  34. Behavior on opacity { NumberAnimation { duration: 100 } }
  35. }
  36. }
  37. contentItem: UM.Label
  38. {
  39. id: label
  40. text: signInButton.text
  41. color: UM.Theme.getColor("primary_text")
  42. width: contentWidth
  43. }
  44. }
  45. Button
  46. {
  47. id: accountWidget
  48. anchors.verticalCenter: parent.verticalCenter
  49. implicitHeight: Math.round(0.5 * UM.Theme.getSize("main_window_header").height)
  50. implicitWidth: Math.round(0.5 * UM.Theme.getSize("main_window_header").height)
  51. hoverEnabled: true
  52. visible: loggedIn
  53. text: (loggedIn && profile["profile_image_url"] == "") ? profile["username"].charAt(0).toUpperCase() : ""
  54. background: AvatarImage
  55. {
  56. id: avatar
  57. width: accountWidget.width
  58. height: accountWidget.height
  59. anchors.verticalCenter: accountWidget.verticalCenter
  60. anchors.horizontalCenter: accountWidget.horizontalCenter
  61. source: (loggedIn && profile["profile_image_url"]) ? profile["profile_image_url"] : ""
  62. outlineColor: loggedIn ? UM.Theme.getColor("account_widget_outline_active") : UM.Theme.getColor("lining")
  63. }
  64. contentItem: Item
  65. {
  66. anchors.verticalCenter: accountWidget.verticalCenter
  67. anchors.horizontalCenter: accountWidget.horizontalCenter
  68. visible: avatar.source == ""
  69. Rectangle
  70. {
  71. id: initialCircle
  72. anchors.centerIn: parent
  73. width: Math.min(accountWidget.width, accountWidget.height)
  74. height: width
  75. radius: width
  76. color: UM.Theme.getColor("main_window_header_background")
  77. border.width: UM.Theme.getSize("default_lining").width
  78. border.color: UM.Theme.getColor("primary_text")
  79. Rectangle
  80. {
  81. id: initialCircleFill
  82. anchors.fill: parent
  83. radius: parent.radius
  84. color: UM.Theme.getColor("primary_text")
  85. opacity: accountWidget.hovered ? 0.2 : 0
  86. Behavior on opacity { NumberAnimation { duration: 100 } }
  87. }
  88. }
  89. UM.Label
  90. {
  91. id: initialLabel
  92. anchors.verticalCenter: parent.verticalCenter
  93. anchors.horizontalCenter: parent.horizontalCenter
  94. text: accountWidget.text
  95. font: UM.Theme.getFont("large_bold")
  96. color: UM.Theme.getColor("primary_text")
  97. horizontalAlignment: Text.AlignHCenter
  98. }
  99. }
  100. onClicked: {
  101. if (popup.opened)
  102. {
  103. popup.close()
  104. } else {
  105. Cura.API.account.popupOpened()
  106. popup.open()
  107. }
  108. }
  109. }
  110. Popup
  111. {
  112. id: popup
  113. y: parent.height + UM.Theme.getSize("default_arrow").height
  114. x: parent.width - width
  115. closePolicy: Popup.CloseOnEscape | Popup.CloseOnPressOutsideParent
  116. onOpened: Cura.API.account.popupOpened()
  117. opacity: opened ? 1 : 0
  118. Behavior on opacity { NumberAnimation { duration: 100 } }
  119. padding: 0
  120. contentItem: AccountDetails
  121. {}
  122. background: UM.PointingRectangle
  123. {
  124. color: UM.Theme.getColor("tool_panel_background")
  125. borderColor: UM.Theme.getColor("lining")
  126. borderWidth: UM.Theme.getSize("default_lining").width
  127. target: Qt.point(width - ((signInButton.visible ? signInButton.width : accountWidget.width) / 2), -10)
  128. arrowSize: UM.Theme.getSize("default_arrow").width
  129. }
  130. }
  131. }