Add ImageItem.

This commit is contained in:
Black Hat
2018-09-06 16:22:00 +08:00
parent 75e2d6dbed
commit bd5c119f53
6 changed files with 146 additions and 9 deletions

View File

@@ -142,12 +142,24 @@ Item {
spacing: 12
ImageStatus {
// ImageStatus {
// Layout.preferredWidth: height
// Layout.fillHeight: true
// source: avatar ? "image://mxc/" + avatar : ""
// displayText: name
// }
ImageItem {
id: imageItem
Layout.preferredWidth: height
Layout.fillHeight: true
source: avatar ? "image://mxc/" + avatar : ""
displayText: name
hint: name || "No Name"
defaultColor: stringToColor(name || "No Name")
image: avatar
}
ColumnLayout {
@@ -212,4 +224,17 @@ Item {
}
}
}
function stringToColor(str) {
var hash = 0;
for (var i = 0; i < str.length; i++) {
hash = str.charCodeAt(i) + ((hash << 5) - hash);
}
var colour = '#';
for (var j = 0; j < 3; j++) {
var value = (hash >> (j * 8)) & 0xFF;
colour += ('00' + value.toString(16)).substr(-2);
}
return colour;
}
}