From c3c64c750047c2ce0b81b3381808c004d216682a Mon Sep 17 00:00:00 2001 From: Ronan Abhamon Date: Thu, 1 Dec 2016 14:56:20 +0100 Subject: [PATCH] feat(ui/modules/Linphone/Contact/Avatar): uses the `RoundedImage` component --- .../ui/modules/Common/Image/RoundedImage.qml | 17 ++++++---- tests/ui/modules/Linphone/Contact/Avatar.qml | 34 +++++-------------- .../Linphone/Styles/Contact/AvatarStyle.qml | 7 ++-- 3 files changed, 22 insertions(+), 36 deletions(-) diff --git a/tests/ui/modules/Common/Image/RoundedImage.qml b/tests/ui/modules/Common/Image/RoundedImage.qml index d07435865..8da2e4284 100644 --- a/tests/ui/modules/Common/Image/RoundedImage.qml +++ b/tests/ui/modules/Common/Image/RoundedImage.qml @@ -3,8 +3,11 @@ import QtQuick 2.7 // =================================================================== Item { + id: item + property alias source: image.source - property color colorMask: '#00000000' + property color backgroundColor: '#00000000' + property color foregroundColor: '#00000000' // vec4(0.812, 0.843, 0.866, 1.0) 0.9 Item { @@ -27,23 +30,25 @@ Item { layer { effect: ShaderEffect { + property color backgroundColor: item.backgroundColor + property color foregroundColor: item.foregroundColor property var image: imageContainer - property var color: colorMask fragmentShader: ' uniform lowp sampler2D image; uniform lowp sampler2D mask; - uniform lowp vec4 color; + uniform lowp vec4 backgroundColor; + uniform lowp vec4 foregroundColor; uniform lowp float qt_Opacity; varying highp vec2 qt_TexCoord0; void main () { vec4 tex = texture2D(image, qt_TexCoord0); + vec4 interpolation = mix(backgroundColor, vec4(tex.rgb, 1.0), tex.a); + interpolation = mix(interpolation, vec4(foregroundColor.rgb, 1.0), foregroundColor.a); - gl_FragColor = mix(tex, vec4(color.rgb, 1.0), color.a) * - texture2D(mask, qt_TexCoord0) * - qt_Opacity; + gl_FragColor = interpolation * texture2D(mask, qt_TexCoord0) * qt_Opacity; } ' } diff --git a/tests/ui/modules/Linphone/Contact/Avatar.qml b/tests/ui/modules/Linphone/Contact/Avatar.qml index ddeb65ba5..2e232b36f 100644 --- a/tests/ui/modules/Linphone/Contact/Avatar.qml +++ b/tests/ui/modules/Linphone/Contact/Avatar.qml @@ -1,6 +1,7 @@ import QtQuick 2.7 import QtGraphicalEffects 1.0 +import Common 1.0 import Linphone 1.0 import Linphone.Styles 1.0 import Utils 1.0 @@ -8,12 +9,14 @@ import Utils 1.0 // =================================================================== Item { - property alias image: imageToFilter.source + property alias image: roundedImage.source property alias presenceLevel: presenceLevel.level property string username property var _initialsRegex: /^\s*([^\s\.]+)(?:[\s\.]+([^\s\.]+))?/ + // ----------------------------------------------------------------- + function _computeInitials () { var result = username.match(_initialsRegex) @@ -29,16 +32,8 @@ Item { ) } - // Image mask. (Circle) - Rectangle { - id: mask + // ----------------------------------------------------------------- - anchors.fill: parent - color: AvatarStyle.mask.color - radius: AvatarStyle.mask.radius - } - - // Initials. Text { anchors.centerIn: parent color: AvatarStyle.initials.color @@ -55,24 +50,13 @@ Item { text: _computeInitials() } - Image { + RoundedImage { + id: roundedImage + anchors.fill: parent - id: imageToFilter - fillMode: Image.PreserveAspectFit - - // Image must be invisible. - // The only visible image is the OpacityMask! - visible: false + backgroundColor: AvatarStyle.backgroundColor } - // Avatar. - OpacityMask { - anchors.fill: imageToFilter - maskSource: mask - source: imageToFilter - } - - // Presence. PresenceLevel { id: presenceLevel diff --git a/tests/ui/modules/Linphone/Styles/Contact/AvatarStyle.qml b/tests/ui/modules/Linphone/Styles/Contact/AvatarStyle.qml index 4e535af68..ee2df2959 100644 --- a/tests/ui/modules/Linphone/Styles/Contact/AvatarStyle.qml +++ b/tests/ui/modules/Linphone/Styles/Contact/AvatarStyle.qml @@ -6,14 +6,11 @@ import Common 1.0 // =================================================================== QtObject { + property color backgroundColor: Colors.r + property QtObject initials: QtObject { property color color: Colors.k property int fontSize: 10 property int ratio: 30 } - - property QtObject mask: QtObject { - property color color: Colors.r - property int radius: 500 - } }