Update and improve HAvatar code

This commit is contained in:
miruka 2019-04-28 11:32:02 -04:00
parent be4b15e484
commit 83272b9580
8 changed files with 34 additions and 38 deletions

View File

@ -3,25 +3,21 @@ import QtQuick.Controls 2.0
import QtQuick.Layouts 1.4
import "../base" as Base
Item {
property bool invisible: false
Rectangle {
property bool hidden: false
property var name: null // null, string or PyQtFuture
property var imageSource: null
property int dimmension: 48
property int dimension: 48
readonly property string resolvedName:
! name ? "?" :
typeof(name) == "string" ? name :
(name.value ? name.value : "?")
id: root
width: dimmension
height: invisible ? 1 : dimmension
width: dimension
height: hidden ? 1 : dimension
opacity: hidden ? 0 : 1
Rectangle {
id: letterRectangle
anchors.fill: parent
visible: ! invisible && imageSource === null
color: resolvedName === "?" ?
Base.HStyle.avatar.background.unknown :
Qt.hsla(
@ -32,22 +28,22 @@ Item {
)
HLabel {
z: 1
anchors.centerIn: parent
visible: ! hidden
text: resolvedName.charAt(0)
color: Base.HStyle.avatar.letter
font.pixelSize: letterRectangle.height / 1.4
}
font.pixelSize: parent.height / 1.4
}
Image {
id: avatarImage
HImage {
z: 2
anchors.fill: parent
visible: ! invisible && imageSource !== null
visible: ! hidden && imageSource !== null
Component.onCompleted: if (imageSource) {source = imageSource}
asynchronous: true
mipmap: true
fillMode: Image.PreserveAspectCrop
sourceSize.width: root.dimmension
sourceSize.width: dimension
}
}

View File

@ -21,7 +21,7 @@ Base.HGlassRectangle {
Base.HAvatar {
id: bannerAvatar
dimmension: banner.Layout.preferredHeight
dimension: banner.Layout.preferredHeight
}
Base.HLabel {

View File

@ -16,8 +16,8 @@ RowLayout {
Base.HAvatar {
id: avatar
name: displayName
invisible: combine
dimmension: 28
hidden: combine
dimension: 28
}
Base.HLabel {

View File

@ -9,7 +9,7 @@ Row {
layoutDirection: isOwn ? Qt.RightToLeft : Qt.LeftToRight
anchors.right: isOwn ? parent.right : undefined
Base.HAvatar { id: avatar; invisible: combine; name: displayName }
Base.HAvatar { id: avatar; hidden: combine; name: displayName }
ColumnLayout {
spacing: 0

View File

@ -21,7 +21,7 @@ Base.HGlassRectangle {
Base.HAvatar {
id: avatar
Layout.alignment: Qt.AlignTop
dimmension: root.Layout.minimumHeight
dimension: root.Layout.minimumHeight
name: displayName
}

View File

@ -21,7 +21,7 @@ Base.HGlassRectangle {
Base.HAvatar {
id: avatar
name: Backend.getUserDisplayName(chatPage.userId)
dimmension: root.Layout.minimumHeight
dimension: root.Layout.minimumHeight
}
ScrollView {

View File

@ -12,7 +12,7 @@ ColumnLayout {
id: row
spacing: 0
Base.HAvatar { id: avatar; name: displayName; dimmension: 36 }
Base.HAvatar { id: avatar; name: displayName; dimension: 36 }
ColumnLayout {
Layout.fillWidth: true

View File

@ -16,7 +16,7 @@ MouseArea {
id: row
spacing: 1
Base.HAvatar { id: avatar; name: displayName; dimmension: root.height }
Base.HAvatar { id: avatar; name: displayName; dimension: root.height }
ColumnLayout {
spacing: 0