AccountWidget.qml 5.3 KB

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