2018-12-07 01:18:42 +00:00
|
|
|
import QtQuick 2.12
|
2018-12-22 14:25:03 +00:00
|
|
|
import QtQuick.Controls 2.12
|
2018-12-03 11:55:42 +00:00
|
|
|
import QtGraphicalEffects 1.0
|
|
|
|
|
2019-05-17 07:01:01 +00:00
|
|
|
import Spectral.Setting 0.1
|
|
|
|
|
2018-12-03 11:55:42 +00:00
|
|
|
Item {
|
|
|
|
property string hint: "H"
|
|
|
|
property string source: ""
|
|
|
|
readonly property url realSource: source ? "image://mxc/" + source : ""
|
|
|
|
|
|
|
|
id: root
|
|
|
|
|
|
|
|
Image {
|
|
|
|
anchors.fill: parent
|
|
|
|
|
|
|
|
id: image
|
|
|
|
visible: realSource
|
2019-03-02 07:33:37 +00:00
|
|
|
source: width < 1 ? "" : realSource
|
2018-12-03 11:55:42 +00:00
|
|
|
sourceSize.width: width
|
|
|
|
sourceSize.height: width
|
|
|
|
fillMode: Image.PreserveAspectCrop
|
|
|
|
layer.enabled: true
|
|
|
|
layer.effect: OpacityMask {
|
|
|
|
maskSource: Rectangle {
|
|
|
|
width: image.width
|
|
|
|
height: image.width
|
|
|
|
|
|
|
|
radius: width / 2
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Rectangle {
|
|
|
|
anchors.fill: parent
|
|
|
|
|
|
|
|
visible: !realSource || image.status != Image.Ready
|
|
|
|
|
|
|
|
radius: height / 2
|
2019-05-17 07:01:01 +00:00
|
|
|
color: MPalette.accent
|
2019-04-23 02:57:35 +00:00
|
|
|
antialiasing: true
|
2018-12-03 11:55:42 +00:00
|
|
|
|
|
|
|
Label {
|
|
|
|
anchors.centerIn: parent
|
|
|
|
|
|
|
|
color: "white"
|
|
|
|
text: hint[0].toUpperCase()
|
|
|
|
font.pixelSize: root.width / 2
|
2019-05-10 11:26:17 +00:00
|
|
|
font.weight: Font.Light
|
|
|
|
horizontalAlignment: Text.AlignHCenter
|
|
|
|
verticalAlignment: Text.AlignVCenter
|
2018-12-03 11:55:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-17 07:01:01 +00:00
|
|
|
// 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;
|
|
|
|
// }
|
2018-12-03 11:55:42 +00:00
|
|
|
}
|