AccountWidget.qml 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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.height > accountWidget.height ? signInButton.height : accountWidget.height
  12. width: signInButton.width > accountWidget.width ? 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: signInButton.hovered ? UM.Theme.getColor("primary_text") : 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. }
  29. contentItem: Label
  30. {
  31. id: label
  32. text: signInButton.text
  33. font: UM.Theme.getFont("default")
  34. color: signInButton.hovered ? UM.Theme.getColor("main_window_header_background") : UM.Theme.getColor("primary_text")
  35. width: contentWidth
  36. verticalAlignment: Text.AlignVCenter
  37. renderType: Text.NativeRendering
  38. }
  39. }
  40. Button
  41. {
  42. id: accountWidget
  43. anchors.verticalCenter: parent.verticalCenter
  44. implicitHeight: UM.Theme.getSize("main_window_header").height
  45. implicitWidth: UM.Theme.getSize("main_window_header").height
  46. hoverEnabled: true
  47. visible: loggedIn
  48. text: (loggedIn && profile["profile_image_url"] == "") ? profile["username"].charAt(0).toUpperCase() : ""
  49. background: AvatarImage
  50. {
  51. id: avatar
  52. width: Math.round(0.8 * accountWidget.width)
  53. height: Math.round(0.8 * accountWidget.height)
  54. anchors.verticalCenter: accountWidget.verticalCenter
  55. anchors.horizontalCenter: accountWidget.horizontalCenter
  56. source: (loggedIn && profile["profile_image_url"]) ? profile["profile_image_url"] : ""
  57. outlineColor: loggedIn ? UM.Theme.getColor("account_widget_outline_active") : UM.Theme.getColor("lining")
  58. }
  59. contentItem: Item
  60. {
  61. anchors.verticalCenter: accountWidget.verticalCenter
  62. anchors.horizontalCenter: accountWidget.horizontalCenter
  63. visible: avatar.source == ""
  64. Rectangle
  65. {
  66. id: initialCircle
  67. anchors.centerIn: parent
  68. width: Math.min(parent.width, parent.height)
  69. height: width
  70. radius: width
  71. color: accountWidget.hovered ? UM.Theme.getColor("primary_text") : "transparent"
  72. border.width: 1
  73. border.color: UM.Theme.getColor("primary_text")
  74. }
  75. Label
  76. {
  77. id: initialLabel
  78. anchors.verticalCenter: parent.verticalCenter
  79. anchors.horizontalCenter: parent.horizontalCenter
  80. text: accountWidget.text
  81. font: UM.Theme.getFont("large_bold")
  82. color: accountWidget.hovered ? UM.Theme.getColor("main_window_header_background") : UM.Theme.getColor("primary_text")
  83. verticalAlignment: Text.AlignVCenter
  84. horizontalAlignment: Text.AlignHCenter
  85. renderType: Text.NativeRendering
  86. }
  87. }
  88. onClicked: popup.opened ? popup.close() : popup.open()
  89. }
  90. Popup
  91. {
  92. id: popup
  93. y: parent.height + UM.Theme.getSize("default_arrow").height
  94. x: parent.width - width
  95. closePolicy: Popup.CloseOnEscape | Popup.CloseOnPressOutsideParent
  96. opacity: opened ? 1 : 0
  97. Behavior on opacity { NumberAnimation { duration: 100 } }
  98. contentItem: AccountDetails
  99. {
  100. id: panel
  101. profile: Cura.API.account.userProfile
  102. loggedIn: Cura.API.account.isLoggedIn
  103. profileImage: Cura.API.account.profileImageUrl
  104. }
  105. background: UM.PointingRectangle
  106. {
  107. color: UM.Theme.getColor("tool_panel_background")
  108. borderColor: UM.Theme.getColor("lining")
  109. borderWidth: UM.Theme.getSize("default_lining").width
  110. target: Qt.point(width - (accountWidget.width / 2), -10)
  111. arrowSize: UM.Theme.getSize("default_arrow").width
  112. }
  113. }
  114. }