2020-08-19 17:47:59 +03:00
|
|
|
/*
|
2020-10-19 20:34:47 +03:00
|
|
|
Copyright (C) 2020 Sebastian J. Wolf and other contributors
|
2020-08-19 17:47:59 +03:00
|
|
|
|
|
|
|
This file is part of Fernschreiber.
|
|
|
|
|
|
|
|
Fernschreiber is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
Fernschreiber is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with Fernschreiber. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
2020-10-31 22:49:03 +03:00
|
|
|
import QtQuick 2.6
|
2020-08-19 17:47:59 +03:00
|
|
|
import QtGraphicalEffects 1.0
|
|
|
|
import Sailfish.Silica 1.0
|
2020-11-08 07:00:13 +03:00
|
|
|
import WerkWolf.Fernschreiber 1.0
|
2020-08-19 17:47:59 +03:00
|
|
|
|
|
|
|
Item {
|
|
|
|
|
|
|
|
id: profileThumbnail
|
|
|
|
|
2020-11-08 07:00:13 +03:00
|
|
|
property alias photoData: file.fileInformation
|
2020-08-19 17:47:59 +03:00
|
|
|
property string replacementStringHint: "X"
|
2020-10-19 13:20:02 +03:00
|
|
|
property int radius: width / 2
|
|
|
|
property int imageStatus: -1
|
2020-08-19 17:47:59 +03:00
|
|
|
|
|
|
|
function getReplacementString() {
|
|
|
|
if (replacementStringHint.length > 2) {
|
|
|
|
// Remove all emoji images
|
|
|
|
var strippedText = replacementStringHint.replace(/\<[^>]+\>/g, "").trim();
|
|
|
|
if (strippedText.length > 0) {
|
|
|
|
var textElements = strippedText.split(" ");
|
|
|
|
if (textElements.length > 1) {
|
|
|
|
return textElements[0].charAt(0) + textElements[textElements.length - 1].charAt(0);
|
|
|
|
} else {
|
|
|
|
return textElements[0].charAt(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return replacementStringHint;
|
|
|
|
}
|
|
|
|
|
2020-11-08 07:00:13 +03:00
|
|
|
TDLibFile {
|
|
|
|
id: file
|
|
|
|
tdlib: tdLibWrapper
|
|
|
|
autoLoad: true
|
2020-08-19 17:47:59 +03:00
|
|
|
}
|
|
|
|
|
2020-09-21 23:10:03 +03:00
|
|
|
Component {
|
|
|
|
id: profileImageComponent
|
|
|
|
Item {
|
|
|
|
width: parent.width
|
|
|
|
height: width
|
2020-11-08 07:00:13 +03:00
|
|
|
visible: opacity > 0
|
|
|
|
opacity: singleImage.status === Image.Ready ? 1 : 0
|
|
|
|
Behavior on opacity { FadeAnimation {} }
|
2020-09-21 23:10:03 +03:00
|
|
|
|
|
|
|
Image {
|
|
|
|
id: singleImage
|
|
|
|
width: parent.width - Theme.paddingSmall
|
|
|
|
height: parent.height - Theme.paddingSmall
|
|
|
|
anchors.centerIn: parent
|
2020-11-08 07:00:13 +03:00
|
|
|
source: file.path
|
2020-09-21 23:10:03 +03:00
|
|
|
fillMode: Image.PreserveAspectCrop
|
|
|
|
autoTransform: true
|
|
|
|
asynchronous: true
|
|
|
|
visible: false
|
2020-10-19 13:20:02 +03:00
|
|
|
onStatusChanged: {
|
|
|
|
profileThumbnail.imageStatus = status
|
|
|
|
}
|
2020-09-21 23:10:03 +03:00
|
|
|
}
|
2020-08-19 17:47:59 +03:00
|
|
|
|
2020-09-21 23:10:03 +03:00
|
|
|
Rectangle {
|
|
|
|
id: profileThumbnailMask
|
|
|
|
width: parent.width - Theme.paddingSmall
|
|
|
|
height: parent.height - Theme.paddingSmall
|
|
|
|
color: Theme.primaryColor
|
2020-10-19 13:20:02 +03:00
|
|
|
radius: profileThumbnail.radius
|
2020-09-21 23:10:03 +03:00
|
|
|
anchors.centerIn: singleImage
|
|
|
|
visible: false
|
|
|
|
}
|
2020-08-19 17:47:59 +03:00
|
|
|
|
2020-09-21 23:10:03 +03:00
|
|
|
OpacityMask {
|
|
|
|
source: singleImage
|
|
|
|
maskSource: profileThumbnailMask
|
|
|
|
anchors.fill: singleImage
|
|
|
|
}
|
|
|
|
}
|
2020-08-19 17:47:59 +03:00
|
|
|
}
|
|
|
|
|
2020-09-21 23:10:03 +03:00
|
|
|
Loader {
|
|
|
|
id: profileImageLoader
|
2020-11-08 07:00:13 +03:00
|
|
|
active: file.isDownloadingCompleted
|
2020-09-21 23:10:03 +03:00
|
|
|
asynchronous: true
|
|
|
|
width: parent.width
|
|
|
|
sourceComponent: profileImageComponent
|
2020-08-19 17:47:59 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
Item {
|
|
|
|
width: parent.width - Theme.paddingSmall
|
|
|
|
height: parent.height - Theme.paddingSmall
|
2020-11-08 07:00:13 +03:00
|
|
|
visible: !profileImageLoader.item || !profileImageLoader.item.visible
|
2020-08-19 17:47:59 +03:00
|
|
|
|
|
|
|
Rectangle {
|
|
|
|
id: replacementThumbnailBackground
|
|
|
|
anchors.fill: parent
|
|
|
|
color: (Theme.colorScheme === Theme.LightOnDark) ? Theme.darkSecondaryColor : Theme.lightSecondaryColor
|
|
|
|
radius: parent.width / 2
|
|
|
|
opacity: 0.8
|
|
|
|
}
|
|
|
|
|
|
|
|
Text {
|
|
|
|
anchors.centerIn: replacementThumbnailBackground
|
|
|
|
text: getReplacementString()
|
|
|
|
color: Theme.primaryColor
|
|
|
|
font.bold: true
|
2020-10-07 23:17:44 +03:00
|
|
|
font.pixelSize: ( profileThumbnail.height >= Theme.itemSizeSmall ) ? Theme.fontSizeLarge : Theme.fontSizeMedium
|
2020-08-19 17:47:59 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|