AccountWidget.qml 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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: loggedIn ? profile["profile_image_url"] : UM.Theme.getImage("avatar_no_user")
  22. outlineColor: loggedIn ? UM.Theme.getColor("account_widget_outline_active") : UM.Theme.getColor("lining")
  23. }
  24. onClicked: popup.opened ? popup.close() : popup.open()
  25. Popup
  26. {
  27. id: popup
  28. y: parent.height + UM.Theme.getSize("default_arrow").height
  29. x: parent.width - width
  30. closePolicy: Popup.CloseOnEscape | Popup.CloseOnPressOutsideParent
  31. contentItem: AccountDetails
  32. {
  33. id: panel
  34. profile: Cura.API.account.userProfile
  35. loggedIn: Cura.API.account.isLoggedIn
  36. }
  37. background: UM.PointingRectangle
  38. {
  39. opacity: visible ? 1 : 0
  40. Behavior on opacity { NumberAnimation { duration: 100 } }
  41. color: UM.Theme.getColor("tool_panel_background")
  42. borderColor: UM.Theme.getColor("lining")
  43. borderWidth: UM.Theme.getSize("default_lining").width
  44. target: Qt.point(width - (accountWidget.width / 2), -10)
  45. arrowSize: UM.Theme.getSize("default_arrow").width
  46. }
  47. }
  48. }