status-desktop/ui/app/AppLayouts/Chat/panels/ContactListPanel.qml

73 lines
2.3 KiB
QML
Raw Normal View History

2020-12-11 20:38:10 +00:00
import QtQuick 2.13
import QtQuick.Controls 2.3
import StatusQ.Components 0.1
import StatusQ.Controls 0.1
2020-12-11 20:38:10 +00:00
import utils 1.0
2020-12-11 20:38:10 +00:00
ScrollView {
id: contactListPanel
property alias model: groupMembers.model
2020-12-11 20:38:10 +00:00
property string searchString
property bool selectMode: true
property var onItemChecked
property var selectedPubKeys: []
2020-12-11 20:38:10 +00:00
ScrollBar.horizontal.policy: ScrollBar.AlwaysOff
ScrollBar.vertical.policy: groupMembers.contentHeight > groupMembers.height ? ScrollBar.AlwaysOn : ScrollBar.AlwaysOff
2020-12-11 20:38:10 +00:00
ListView {
id: groupMembers
2020-12-11 20:38:10 +00:00
anchors.fill: parent
spacing: 0
clip: true
delegate: StatusListItem {
id: contactDelegate
property bool isChecked: selectedPubKeys.indexOf(model.pubKey) !== -1
title: !model.name.endsWith(".eth") && !!model.localNickname ?
model.localNickname : Utils.removeStatusEns(model.name)
image.source: Global.getProfileImage(model.pubKey) || model.identicon
image.isIdenticon: !!model.identicon
visible: {
2020-12-11 20:38:10 +00:00
if (selectMode) {
return !searchString || model.name.toLowerCase().includes(searchString)
}
return checkbox.checked
2020-12-11 20:38:10 +00:00
}
height: visible ? implicitHeight : 0
function contactToggled(pubKey) {
if (contactListPanel.selectMode) {
let pubkeys = contactListPanel.selectedPubKeys
let idx = pubkeys.indexOf(pubKey)
if (idx === -1) {
pubkeys.push(pubKey)
} else if (idx > -1) {
pubkeys.splice(idx, 1);
}
contactListPanel.selectedPubKeys = pubkeys
}
}
components: [
StatusCheckBox {
id: checkbox
visible: contactListPanel.selectMode
checked: selectedPubKeys.indexOf(model.pubKey) !== -1
onClicked: {
contactDelegate.contactToggled(model.pubKey)
}
}
]
onClicked: {
contactDelegate.contactToggled(model.pubKey)
2020-12-11 20:38:10 +00:00
}
}
}
}