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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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