AccountWidget.qml 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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.4 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. }
  35. }
  36. contentItem: Label
  37. {
  38. id: label
  39. text: signInButton.text
  40. font: UM.Theme.getFont("default")
  41. color: UM.Theme.getColor("primary_text")
  42. width: contentWidth
  43. verticalAlignment: Text.AlignVCenter
  44. renderType: Text.NativeRendering
  45. }
  46. }
  47. Button
  48. {
  49. id: accountWidget
  50. anchors.verticalCenter: parent.verticalCenter
  51. implicitHeight: Math.round(0.5 * UM.Theme.getSize("main_window_header").height)
  52. implicitWidth: Math.round(0.5 * UM.Theme.getSize("main_window_header").height)
  53. hoverEnabled: true
  54. visible: loggedIn
  55. text: (loggedIn && profile["profile_image_url"] == "") ? profile["username"].charAt(0).toUpperCase() : ""
  56. background: AvatarImage
  57. {
  58. id: avatar
  59. width: accountWidget.width
  60. height: accountWidget.height
  61. anchors.verticalCenter: accountWidget.verticalCenter
  62. anchors.horizontalCenter: accountWidget.horizontalCenter
  63. source: (loggedIn && profile["profile_image_url"]) ? profile["profile_image_url"] : ""
  64. outlineColor: loggedIn ? UM.Theme.getColor("account_widget_outline_active") : UM.Theme.getColor("lining")
  65. }
  66. contentItem: Item
  67. {
  68. anchors.verticalCenter: accountWidget.verticalCenter
  69. anchors.horizontalCenter: accountWidget.horizontalCenter
  70. visible: avatar.source == ""
  71. Rectangle
  72. {
  73. id: initialCircle
  74. anchors.centerIn: parent
  75. width: Math.min(accountWidget.width, accountWidget.height)
  76. height: width
  77. radius: width
  78. color: UM.Theme.getColor("main_window_header_background")
  79. border.width: UM.Theme.getSize("default_lining").width
  80. border.color: UM.Theme.getColor("primary_text")
  81. Rectangle
  82. {
  83. id: initialCircleFill
  84. anchors.fill: parent
  85. radius: parent.radius
  86. color: UM.Theme.getColor("primary_text")
  87. opacity: accountWidget.hovered ? 0.2 : 0
  88. }
  89. }
  90. 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. verticalAlignment: Text.AlignVCenter
  99. horizontalAlignment: Text.AlignHCenter
  100. renderType: Text.NativeRendering
  101. }
  102. }
  103. onClicked: {
  104. if (popup.opened)
  105. {
  106. popup.close()
  107. } else {
  108. Cura.API.account.popupOpened()
  109. popup.open()
  110. }
  111. }
  112. }
  113. Popup
  114. {
  115. id: popup
  116. y: parent.height + UM.Theme.getSize("default_arrow").height
  117. x: parent.width - width
  118. closePolicy: Popup.CloseOnEscape | Popup.CloseOnPressOutsideParent
  119. onOpened: Cura.API.account.popupOpened()
  120. opacity: opened ? 1 : 0
  121. Behavior on opacity { NumberAnimation { duration: 100 } }
  122. padding: 0
  123. contentItem: AccountDetails
  124. {}
  125. background: UM.PointingRectangle
  126. {
  127. color: UM.Theme.getColor("tool_panel_background")
  128. borderColor: UM.Theme.getColor("lining")
  129. borderWidth: UM.Theme.getSize("default_lining").width
  130. target: Qt.point(width - ((signInButton.visible ? signInButton.width : accountWidget.width) / 2), -10)
  131. arrowSize: UM.Theme.getSize("default_arrow").width
  132. }
  133. }
  134. }