Cura/resources/qml/Account/AccountWidget.qml
Konstantinos Karmas d844c5f70a Fix alignment of the ApplicationSwitcher button
The sign in button has a different size when you are logged in, where the account avatar was being drawn in the middle of the Sign In button. This was causing a weird alignment of the ApplicationSwitcher next to it, as it was adding an extra margin.

This is now fixed by making sure that the width of the button that has to do with account adjusts according to whether you are logged in or not. This makes the ApplicationSwitcher icon move when you log in but looks more natural relatively to the account button.

CURA-8421
2021-09-20 16:57:16 +02:00

150 lines
4.9 KiB
QML

// Copyright (c) 2018 Ultimaker B.V.
// Cura is released under the terms of the LGPLv3 or higher.
import QtQuick 2.10
import QtQuick.Controls 2.3
import UM 1.4 as UM
import Cura 1.1 as Cura
Item
{
property var profile: Cura.API.account.userProfile
property var loggedIn: Cura.API.account.isLoggedIn
height: signInButton.visible ? signInButton.height : accountWidget.height
width: signInButton.visible ? signInButton.width : accountWidget.width
Button
{
id: signInButton
anchors.verticalCenter: parent.verticalCenter
text: catalog.i18nc("@action:button", "Sign in")
height: Math.round(0.5 * UM.Theme.getSize("main_window_header").height)
onClicked: popup.opened ? popup.close() : popup.open()
visible: !loggedIn
hoverEnabled: true
background: Rectangle
{
radius: UM.Theme.getSize("action_button_radius").width
color: signInButton.hovered ? UM.Theme.getColor("primary_text") : UM.Theme.getColor("main_window_header_background")
border.width: UM.Theme.getSize("default_lining").width
border.color: UM.Theme.getColor("primary_text")
}
contentItem: Label
{
id: label
text: signInButton.text
font: UM.Theme.getFont("default")
color: signInButton.hovered ? UM.Theme.getColor("main_window_header_background") : UM.Theme.getColor("primary_text")
width: contentWidth
verticalAlignment: Text.AlignVCenter
renderType: Text.NativeRendering
}
}
Button
{
id: accountWidget
anchors.verticalCenter: parent.verticalCenter
// anchors.horizontalCenter: signInButton.horizontalCenter
implicitHeight: Math.round(0.5 * UM.Theme.getSize("main_window_header").height)
implicitWidth: Math.round(0.5 * UM.Theme.getSize("main_window_header").height)
hoverEnabled: true
visible: loggedIn
text: (loggedIn && profile["profile_image_url"] == "") ? profile["username"].charAt(0).toUpperCase() : ""
background: AvatarImage
{
id: avatar
width: accountWidget.width
height: accountWidget.height
anchors.verticalCenter: accountWidget.verticalCenter
anchors.horizontalCenter: accountWidget.horizontalCenter
source: (loggedIn && profile["profile_image_url"]) ? profile["profile_image_url"] : ""
outlineColor: loggedIn ? UM.Theme.getColor("account_widget_outline_active") : UM.Theme.getColor("lining")
}
contentItem: Item
{
anchors.verticalCenter: accountWidget.verticalCenter
anchors.horizontalCenter: accountWidget.horizontalCenter
visible: avatar.source == ""
Rectangle
{
id: initialCircle
anchors.centerIn: parent
width: Math.min(accountWidget.width, accountWidget.height)
height: width
radius: width
color: accountWidget.hovered ? UM.Theme.getColor("primary_text") : "transparent"
border.width: 1
border.color: UM.Theme.getColor("primary_text")
}
Label
{
id: initialLabel
anchors.verticalCenter: parent.verticalCenter
anchors.horizontalCenter: parent.horizontalCenter
text: accountWidget.text
font: UM.Theme.getFont("large_bold")
color: accountWidget.hovered ? UM.Theme.getColor("main_window_header_background") : UM.Theme.getColor("primary_text")
verticalAlignment: Text.AlignVCenter
horizontalAlignment: Text.AlignHCenter
renderType: Text.NativeRendering
}
}
onClicked: {
if (popup.opened)
{
popup.close()
} else {
Cura.API.account.popupOpened()
popup.open()
}
}
}
Popup
{
id: popup
y: parent.height + UM.Theme.getSize("default_arrow").height
x: parent.width - width
closePolicy: Popup.CloseOnEscape | Popup.CloseOnPressOutsideParent
onOpened: Cura.API.account.popupOpened()
opacity: opened ? 1 : 0
Behavior on opacity { NumberAnimation { duration: 100 } }
padding: 0
contentItem: AccountDetails
{}
background: UM.PointingRectangle
{
color: UM.Theme.getColor("tool_panel_background")
borderColor: UM.Theme.getColor("lining")
borderWidth: UM.Theme.getSize("default_lining").width
target: Qt.point(width - ((signInButton.visible ? signInButton.width : accountWidget.width) / 2), -10)
arrowSize: UM.Theme.getSize("default_arrow").width
}
}
}