AccountWidget.qml 4.9 KB

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