From 83272b9580655f829ef242351f900f0c27069386 Mon Sep 17 00:00:00 2001 From: miruka Date: Sun, 28 Apr 2019 11:32:02 -0400 Subject: [PATCH] Update and improve HAvatar code --- harmonyqml/components/base/HAvatar.qml | 56 +++++++++---------- harmonyqml/components/chat/Banner.qml | 2 +- harmonyqml/components/chat/EventContent.qml | 4 +- harmonyqml/components/chat/MessageContent.qml | 2 +- harmonyqml/components/chat/RoomHeader.qml | 2 +- harmonyqml/components/chat/SendBox.qml | 2 +- .../components/sidePane/AccountDelegate.qml | 2 +- .../components/sidePane/RoomDelegate.qml | 2 +- 8 files changed, 34 insertions(+), 38 deletions(-) diff --git a/harmonyqml/components/base/HAvatar.qml b/harmonyqml/components/base/HAvatar.qml index 310799df..72896473 100644 --- a/harmonyqml/components/base/HAvatar.qml +++ b/harmonyqml/components/base/HAvatar.qml @@ -3,51 +3,47 @@ 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( - Backend.hueFromString(resolvedName), - Base.HStyle.avatar.background.saturation, - Base.HStyle.avatar.background.lightness, - Base.HStyle.avatar.background.alpha - ) + color: resolvedName === "?" ? + Base.HStyle.avatar.background.unknown : + Qt.hsla( + Backend.hueFromString(resolvedName), + Base.HStyle.avatar.background.saturation, + Base.HStyle.avatar.background.lightness, + Base.HStyle.avatar.background.alpha + ) - HLabel { - anchors.centerIn: parent - text: resolvedName.charAt(0) - color: Base.HStyle.avatar.letter - font.pixelSize: letterRectangle.height / 1.4 - } + HLabel { + z: 1 + anchors.centerIn: parent + visible: ! hidden + + text: resolvedName.charAt(0) + color: Base.HStyle.avatar.letter + 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 } } diff --git a/harmonyqml/components/chat/Banner.qml b/harmonyqml/components/chat/Banner.qml index 641a9ec1..79878aba 100644 --- a/harmonyqml/components/chat/Banner.qml +++ b/harmonyqml/components/chat/Banner.qml @@ -21,7 +21,7 @@ Base.HGlassRectangle { Base.HAvatar { id: bannerAvatar - dimmension: banner.Layout.preferredHeight + dimension: banner.Layout.preferredHeight } Base.HLabel { diff --git a/harmonyqml/components/chat/EventContent.qml b/harmonyqml/components/chat/EventContent.qml index 0a2c473f..c87e7f47 100644 --- a/harmonyqml/components/chat/EventContent.qml +++ b/harmonyqml/components/chat/EventContent.qml @@ -16,8 +16,8 @@ RowLayout { Base.HAvatar { id: avatar name: displayName - invisible: combine - dimmension: 28 + hidden: combine + dimension: 28 } Base.HLabel { diff --git a/harmonyqml/components/chat/MessageContent.qml b/harmonyqml/components/chat/MessageContent.qml index 5cd84bcb..27b9e4b2 100644 --- a/harmonyqml/components/chat/MessageContent.qml +++ b/harmonyqml/components/chat/MessageContent.qml @@ -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 diff --git a/harmonyqml/components/chat/RoomHeader.qml b/harmonyqml/components/chat/RoomHeader.qml index 914901c2..e1687cad 100644 --- a/harmonyqml/components/chat/RoomHeader.qml +++ b/harmonyqml/components/chat/RoomHeader.qml @@ -21,7 +21,7 @@ Base.HGlassRectangle { Base.HAvatar { id: avatar Layout.alignment: Qt.AlignTop - dimmension: root.Layout.minimumHeight + dimension: root.Layout.minimumHeight name: displayName } diff --git a/harmonyqml/components/chat/SendBox.qml b/harmonyqml/components/chat/SendBox.qml index f53a058c..aed87627 100644 --- a/harmonyqml/components/chat/SendBox.qml +++ b/harmonyqml/components/chat/SendBox.qml @@ -21,7 +21,7 @@ Base.HGlassRectangle { Base.HAvatar { id: avatar name: Backend.getUserDisplayName(chatPage.userId) - dimmension: root.Layout.minimumHeight + dimension: root.Layout.minimumHeight } ScrollView { diff --git a/harmonyqml/components/sidePane/AccountDelegate.qml b/harmonyqml/components/sidePane/AccountDelegate.qml index 9659a45a..c65145f9 100644 --- a/harmonyqml/components/sidePane/AccountDelegate.qml +++ b/harmonyqml/components/sidePane/AccountDelegate.qml @@ -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 diff --git a/harmonyqml/components/sidePane/RoomDelegate.qml b/harmonyqml/components/sidePane/RoomDelegate.qml index cbc37665..623892b7 100644 --- a/harmonyqml/components/sidePane/RoomDelegate.qml +++ b/harmonyqml/components/sidePane/RoomDelegate.qml @@ -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