From cf4c4d5c7582c4382f44a23f2e8bbe3ce2524d52 Mon Sep 17 00:00:00 2001 From: Ronan Abhamon Date: Tue, 13 Sep 2016 12:02:37 +0200 Subject: [PATCH] fix(Avatar): supports images --- tests/ui/components/contact/Avatar.qml | 33 +++++++++++++++++---- tests/ui/views/mainWindow/searchContact.qml | 5 ++++ 2 files changed, 33 insertions(+), 5 deletions(-) diff --git a/tests/ui/components/contact/Avatar.qml b/tests/ui/components/contact/Avatar.qml index 3cd001690..44be3fff5 100644 --- a/tests/ui/components/contact/Avatar.qml +++ b/tests/ui/components/contact/Avatar.qml @@ -1,14 +1,22 @@ import QtQuick 2.7 +import QtGraphicalEffects 1.0 -Rectangle { +// =================================================================== + +Item { property string username - property string image + property alias image: imageToFilter.source - color: '#8F8F8F' - radius: 20 + Rectangle { + anchors.fill: parent + color: '#8F8F8F' + id: avatar + radius: 20 + } Text { anchors.centerIn: parent + color: '#FFFFFF' text: (function () { var spaceIndex = username.indexOf(' ') var firstLetter = username.charAt(0) @@ -19,6 +27,21 @@ Rectangle { return firstLetter + username.charAt(spaceIndex + 1) })() - color: '#FFFFFF' + } + + Image { + anchors.fill: parent + id: imageToFilter + fillMode: Image.PreserveAspectFit + + // Image must be invisible. + // The only visible image is the OpacityMask! + visible: false + } + + OpacityMask { + anchors.fill: imageToFilter + source: imageToFilter + maskSource: avatar } } diff --git a/tests/ui/views/mainWindow/searchContact.qml b/tests/ui/views/mainWindow/searchContact.qml index ebe83e04e..db9e119a2 100644 --- a/tests/ui/views/mainWindow/searchContact.qml +++ b/tests/ui/views/mainWindow/searchContact.qml @@ -117,6 +117,11 @@ ColumnLayout { $presence: 'disconnected' $username: 'Cecelia Cyler' } + ListElement { + $image: '' + $presence: 'disconnected' + $username: 'Toto' + } ListElement { $image: '' $presence: 'absent'