From 531e54f238b4c883a840c5bd76923af7791032f4 Mon Sep 17 00:00:00 2001 From: Pascal Precht Date: Thu, 8 Jul 2021 12:39:46 +0200 Subject: [PATCH] feat(StatusListItem): support letter identicons This adds support for letter identicons by using the `icon.isLetterIdenticon` flag: ```qml StatusListItem { title: "Some name" icon.isLetterIdenticon: true icon.background.color: "orange" } ``` Closes #239 --- sandbox/ListItems.qml | 6 ++++++ src/StatusQ/Components/StatusListItem.qml | 22 ++++++++++++++++++++-- src/StatusQ/Core/StatusIconSettings.qml | 1 + 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/sandbox/ListItems.qml b/sandbox/ListItems.qml index 6c24063b..cbbfef3f 100644 --- a/sandbox/ListItems.qml +++ b/sandbox/ListItems.qml @@ -230,6 +230,12 @@ GridLayout { type: StatusListItem.Type.Secondary } + StatusListItem { + title: "Title" + icon.isLetterIdenticon: true + icon.background.color: "orange" + } + StatusDescriptionListItem { title: "Title" subTitle: "Subtitle" diff --git a/src/StatusQ/Components/StatusListItem.qml b/src/StatusQ/Components/StatusListItem.qml index 7e5e8da4..44c54312 100644 --- a/src/StatusQ/Components/StatusListItem.qml +++ b/src/StatusQ/Components/StatusListItem.qml @@ -34,6 +34,7 @@ Rectangle { height: 20 width: 20 rotation: 0 + isLetterIdenticon: false background: StatusIconBackgroundSettings { width: 40 height: 40 @@ -78,8 +79,15 @@ Rectangle { anchors.left: parent.left anchors.leftMargin: statusListItem.leftPadding anchors.verticalCenter: parent.verticalCenter - sourceComponent: !!statusListItem.icon.name ? statusRoundedIcon : statusRoundedImage - active: !!statusListItem.icon.name || !!statusListItem.image.source.toString() + sourceComponent: { + if (statusListItem.icon.isLetterIdenticon) { + return statusLetterIdenticon + } + return !!statusListItem.icon.name ? statusRoundedIcon : statusRoundedImage + } + active: statusListItem.icon.isLetterIdenticon || + !!statusListItem.icon.name || + !!statusListItem.image.source.toString() } Component { @@ -104,6 +112,16 @@ Rectangle { } } + Component { + id: statusLetterIdenticon + StatusLetterIdenticon { + width: statusListItem.icon.background.width + height: statusListItem.icon.background.height + color: statusListItem.icon.background.color + name: statusListItem.title + } + } + Item { anchors.left: iconOrImage.active ? iconOrImage.right : parent.left anchors.leftMargin: statusListItem.leftPadding diff --git a/src/StatusQ/Core/StatusIconSettings.qml b/src/StatusQ/Core/StatusIconSettings.qml index 95ab3698..d292a05f 100644 --- a/src/StatusQ/Core/StatusIconSettings.qml +++ b/src/StatusQ/Core/StatusIconSettings.qml @@ -10,5 +10,6 @@ QtObject { property color color property url source property int rotation + property bool isLetterIdenticon property StatusIconBackgroundSettings background: StatusIconBackgroundSettings {} }