AccountWidget.qml 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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 2.1
  5. import UM 1.4 as UM
  6. import Cura 1.1 as Cura
  7. Button
  8. {
  9. id: accountWidget
  10. property var profile: Cura.API.account.userProfile
  11. property var loggedIn: Cura.API.account.isLoggedIn
  12. implicitHeight: UM.Theme.getSize("main_window_header").height
  13. implicitWidth: UM.Theme.getSize("main_window_header").height
  14. background: AvatarImage
  15. {
  16. id: avatar
  17. width: Math.round(0.8 * accountWidget.width)
  18. height: Math.round(0.8 * accountWidget.height)
  19. anchors.verticalCenter: accountWidget.verticalCenter
  20. anchors.horizontalCenter: accountWidget.horizontalCenter
  21. source:
  22. {
  23. if(loggedIn)
  24. {
  25. if(profile["profile_image_url"])
  26. {
  27. return profile["profile_image_url"]
  28. }
  29. return UM.Theme.getImage("avatar_no_user")
  30. }
  31. return UM.Theme.getImage("avatar_no_user")
  32. }
  33. outlineColor: loggedIn ? UM.Theme.getColor("account_widget_outline_active") : UM.Theme.getColor("lining")
  34. }
  35. onClicked: popup.opened ? popup.close() : popup.open()
  36. Popup
  37. {
  38. id: popup
  39. y: parent.height + UM.Theme.getSize("default_arrow").height
  40. x: parent.width - width
  41. closePolicy: Popup.CloseOnEscape | Popup.CloseOnPressOutsideParent
  42. opacity: opened ? 1 : 0
  43. Behavior on opacity { NumberAnimation { duration: 100 } }
  44. contentItem: AccountDetails
  45. {
  46. id: panel
  47. profile: Cura.API.account.userProfile
  48. loggedIn: Cura.API.account.isLoggedIn
  49. profileImage: Cura.API.account.profileImageUrl
  50. }
  51. background: UM.PointingRectangle
  52. {
  53. color: UM.Theme.getColor("tool_panel_background")
  54. borderColor: UM.Theme.getColor("lining")
  55. borderWidth: UM.Theme.getSize("default_lining").width
  56. target: Qt.point(width - (accountWidget.width / 2), -10)
  57. arrowSize: UM.Theme.getSize("default_arrow").width
  58. }
  59. }
  60. }