Files
neochat/qml/component/ImageStatus.qml
Black Hat cfa8043596 A lot of improvements.
Fix laggish RoomListView when dragging.
Remove per-room timer and add timer in RoomForm.
Remove singleton module and use file as singleton.
Minor UI tweak in RoomListView.
Pass room to RoomListView via "currentRoom" delegate property and remove
RoomListForm-wide currentRoom.
Put menu files in a separate folder.
Show initial image in ImageStatus when avatar is not loaded.
Add about page.
Merge all setting pages into Setting.qml.
Add option to rearrange rooms by activity.
Add option to use RichText parser.
Add document url.
2018-08-24 13:25:41 +08:00

75 lines
2.0 KiB
QML

import QtQuick 2.9
import QtQuick.Controls 2.2
import QtGraphicalEffects 1.0
import QtQuick.Controls.Material 2.2
Item {
property bool round: true
property string source: ""
property string displayText: ""
readonly property bool showImage: source
readonly property bool showInitial: !showImage && displayText || avatar.status != Image.Ready
id: item
Image {
id: avatar
width: item.width
height: item.width
visible: showImage
source: item.source
mipmap: true
layer.enabled: true
fillMode: Image.PreserveAspectCrop
sourceSize.width: item.width
layer.effect: OpacityMask {
maskSource: Item {
width: avatar.width
height: avatar.width
Rectangle {
anchors.centerIn: parent
width: avatar.width
height: avatar.width
radius: round? avatar.width / 2 : 0
}
}
}
}
Label {
anchors.fill: parent
color: "white"
visible: showInitial
text: showInitial ? getInitials(displayText)[0] : ""
font.pixelSize: 22
font.bold: true
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
background: Rectangle {
anchors.fill: parent
radius: round? width / 2 : 0
color: showInitial ? stringToColor(displayText) : Material.accent
}
}
function getInitials(text) {
if (!text) return "N"
return text.toUpperCase().replace(/[^a-zA-Z- ]/g, "").match(/\b\w/g);
}
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;
}
}