AccountWidget.qml 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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 bool 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. maskColor: UM.Theme.getColor("main_window_header_background")
  64. }
  65. contentItem: Item
  66. {
  67. anchors.verticalCenter: accountWidget.verticalCenter
  68. anchors.horizontalCenter: accountWidget.horizontalCenter
  69. visible: avatar.source == ""
  70. Rectangle
  71. {
  72. id: initialCircle
  73. anchors.centerIn: parent
  74. width: Math.min(accountWidget.width, accountWidget.height)
  75. height: width
  76. radius: width
  77. color: UM.Theme.getColor("main_window_header_background")
  78. border.width: UM.Theme.getSize("default_lining").width
  79. border.color: UM.Theme.getColor("primary_text")
  80. Rectangle
  81. {
  82. id: initialCircleFill
  83. anchors.fill: parent
  84. radius: parent.radius
  85. color: UM.Theme.getColor("primary_text")
  86. opacity: accountWidget.hovered ? 0.2 : 0
  87. Behavior on opacity { NumberAnimation { duration: 100 } }
  88. }
  89. }
  90. UM.Label
  91. {
  92. id: initialLabel
  93. anchors.verticalCenter: parent.verticalCenter
  94. anchors.horizontalCenter: parent.horizontalCenter
  95. text: accountWidget.text
  96. font: UM.Theme.getFont("large_bold")
  97. color: UM.Theme.getColor("primary_text")
  98. horizontalAlignment: Text.AlignHCenter
  99. }
  100. }
  101. onClicked: {
  102. if (popup.opened)
  103. {
  104. popup.close()
  105. } else {
  106. Cura.API.account.popupOpened()
  107. popup.open()
  108. }
  109. }
  110. }
  111. Popup
  112. {
  113. id: popup
  114. y: parent.height + UM.Theme.getSize("default_arrow").height
  115. x: parent.width - width
  116. closePolicy: Popup.CloseOnEscape | Popup.CloseOnPressOutsideParent
  117. onOpened: Cura.API.account.popupOpened()
  118. opacity: opened ? 1 : 0
  119. Behavior on opacity { NumberAnimation { duration: 100 } }
  120. padding: 0
  121. contentItem: AccountDetails
  122. {}
  123. background: UM.PointingRectangle
  124. {
  125. color: UM.Theme.getColor("tool_panel_background")
  126. borderColor: UM.Theme.getColor("lining")
  127. borderWidth: UM.Theme.getSize("default_lining").width
  128. target: Qt.point(width - ((signInButton.visible ? signInButton.width : accountWidget.width) / 2), -10)
  129. arrowSize: UM.Theme.getSize("default_arrow").width
  130. }
  131. }
  132. }