2022-08-10 08:27:45 +00:00
|
|
|
import QtQuick 2.14
|
2022-09-27 21:26:26 +00:00
|
|
|
import QtQuick.Controls 2.14
|
2022-08-10 08:27:45 +00:00
|
|
|
import QtQuick.Layouts 1.14
|
|
|
|
import QtQml.Models 2.14
|
|
|
|
|
|
|
|
import utils 1.0
|
|
|
|
|
|
|
|
import StatusQ.Core 0.1
|
2022-11-11 12:58:23 +00:00
|
|
|
import StatusQ.Controls 0.1
|
2022-08-10 08:27:45 +00:00
|
|
|
|
|
|
|
import "../controls"
|
|
|
|
|
|
|
|
import SortFilterProxyModel 0.2
|
|
|
|
|
2022-09-27 21:26:26 +00:00
|
|
|
Control {
|
2022-08-10 08:27:45 +00:00
|
|
|
id: root
|
|
|
|
|
|
|
|
property string bio
|
|
|
|
property string userSocialLinksJson
|
|
|
|
|
|
|
|
onUserSocialLinksJsonChanged: d.buildSocialLinksModel()
|
|
|
|
|
|
|
|
QtObject {
|
|
|
|
id: d
|
|
|
|
|
|
|
|
// Unfortunately, nim can't expose temporary QObjects thorugh slots
|
|
|
|
// The only way to expose static models on demand is through json strings (see getContactDetailsAsJson)
|
|
|
|
// Model is built here manually, which I know is completely wrong..
|
|
|
|
function buildSocialLinksModel() {
|
|
|
|
socialLinksModel.clear()
|
|
|
|
|
|
|
|
if (root.userSocialLinksJson == "") return
|
|
|
|
|
|
|
|
try {
|
|
|
|
let links = JSON.parse(root.userSocialLinksJson)
|
|
|
|
for (let i=0; i<links.length; i++) {
|
|
|
|
let obj = links[i]
|
2022-12-05 14:21:20 +00:00
|
|
|
const url = obj.url
|
2023-03-08 01:56:41 +00:00
|
|
|
const type = ProfileUtils.linkTextToType(obj.text)
|
2022-08-10 08:27:45 +00:00
|
|
|
socialLinksModel.append({
|
2023-03-08 01:56:41 +00:00
|
|
|
"text": type === Constants.socialLinkType.custom ? obj.text : ProfileUtils.stripSocialLinkPrefix(url, type),
|
2022-12-05 14:21:20 +00:00
|
|
|
"url": url,
|
|
|
|
"linkType": type,
|
|
|
|
"icon": obj.icon
|
2022-08-10 08:27:45 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (e) {
|
|
|
|
console.warn("can't parse userSocialLinksJson", e)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ListModel {
|
|
|
|
id: socialLinksModel
|
|
|
|
}
|
|
|
|
|
|
|
|
SortFilterProxyModel {
|
|
|
|
id: sortedSocialLinksModel
|
|
|
|
|
|
|
|
sourceModel: socialLinksModel
|
|
|
|
filters: ExpressionFilter {
|
|
|
|
expression: model.text !== "" && model.url !== ""
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-27 21:26:26 +00:00
|
|
|
contentItem: ColumnLayout {
|
2022-08-10 08:27:45 +00:00
|
|
|
spacing: 20
|
|
|
|
|
2022-11-11 12:58:23 +00:00
|
|
|
StatusScrollView {
|
|
|
|
id: scrollView
|
2023-05-31 20:58:23 +00:00
|
|
|
|
2022-11-11 16:46:35 +00:00
|
|
|
visible: root.bio
|
2022-11-11 12:58:23 +00:00
|
|
|
padding: 0
|
2023-05-31 20:58:23 +00:00
|
|
|
rightPadding: ScrollBar.vertical.visible ? 16 : 0
|
2022-12-01 09:41:05 +00:00
|
|
|
|
2022-11-11 12:58:23 +00:00
|
|
|
Layout.maximumHeight: 108
|
2022-08-10 08:27:45 +00:00
|
|
|
Layout.fillWidth: true
|
2022-12-01 09:41:05 +00:00
|
|
|
|
2023-05-31 20:58:23 +00:00
|
|
|
contentWidth: availableWidth
|
|
|
|
|
|
|
|
ScrollBar.vertical.policy: bioText.height > scrollView.availableHeight
|
|
|
|
? ScrollBar.AlwaysOn : ScrollBar.AlwaysOff
|
2022-11-11 12:58:23 +00:00
|
|
|
|
|
|
|
StatusBaseText {
|
|
|
|
id: bioText
|
2023-08-08 13:54:36 +00:00
|
|
|
text: root.bio.trim()
|
2022-11-11 12:58:23 +00:00
|
|
|
wrapMode: Text.Wrap
|
|
|
|
font.weight: Font.Medium
|
|
|
|
lineHeight: 1.2
|
|
|
|
width: scrollView.availableWidth
|
|
|
|
}
|
2022-08-10 08:27:45 +00:00
|
|
|
}
|
|
|
|
|
2022-09-27 21:26:26 +00:00
|
|
|
StatusCenteredFlow {
|
2022-08-10 08:27:45 +00:00
|
|
|
Layout.fillWidth: true
|
|
|
|
Layout.fillHeight: true
|
|
|
|
|
2022-09-27 21:26:26 +00:00
|
|
|
spacing: Style.current.halfPadding
|
2022-08-10 08:27:45 +00:00
|
|
|
visible: repeater.count > 0
|
|
|
|
|
|
|
|
Repeater {
|
|
|
|
id: repeater
|
|
|
|
|
|
|
|
model: sortedSocialLinksModel
|
|
|
|
delegate: SocialLinkPreview {
|
2022-08-16 17:22:19 +00:00
|
|
|
height: 32
|
2022-08-10 08:27:45 +00:00
|
|
|
text: model.text
|
|
|
|
url: model.url
|
2022-12-05 14:21:20 +00:00
|
|
|
icon: model.icon
|
2022-08-10 08:27:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|