This repository has been archived on 2021-06-24. You can view files and clone it, but cannot push or open issues or pull requests.
ui/qml/widgets/ContactList.qml

174 lines
4.9 KiB
QML
Raw Normal View History

import QtGraphicalEffects 1.0
import QtQuick 2.7
import QtQuick.Controls 2.4
import QtQuick.Controls.Material 2.0
import QtQuick.Layouts 1.3
import "../opaque" as Opaque
import "../opaque/theme"
ColumnLayout {
id: root
property alias dualPane: myprof.dualPane
spacing: 10
MouseArea {
anchors.fill: parent
onClicked: {
forceActiveFocus()
}
}
MyProfile { // CURRENT PROFILE INFO AND CONTROL BAR
id: myprof
}
Opaque.IconTextField {
id: searchAddText
anchors.horizontalCenter: parent.horizontalCenter
Layout.minimumWidth: parent.width - 60
Layout.maximumWidth: parent.width - 60
//: ex: "... paste an address here to add a contact ..."
placeholderText: qsTr("paste-address-to-add-contact")
horizontalAlignment: TextInput.AlignHCenter
icon: gcd.assetPath + "core/search-24px.svg"
onTextChanged: {
if (text != "") {
gcd.importString(text)
text = ""
}
}
}
Flickable { // THE ACTUAL CONTACT LIST
id: sv
//Layout.alignment: Qt.AlignLeft | Qt.AlignTop
clip: true
Layout.minimumHeight: 100
//Layout.maximumHeight: parent.height - 30
Layout.fillHeight: true
Layout.minimumWidth: parent.width
Layout.maximumWidth: parent.width
contentWidth: colContacts.width
contentHeight: colContacts.height
boundsBehavior: Flickable.StopAtBounds
maximumFlickVelocity: 400
ScrollBar.vertical: ScrollBar {
policy: ScrollBar.AsNeeded
background: Rectangle {
implicitWidth: 6
color: Theme.backgroundMainColor
}
contentItem: Rectangle {
implicitWidth: 6
implicitHeight:1
color: Theme.backgroundPaneColor
}
}
ColumnLayout {
id: colContacts
width: root.width
spacing: 0
Connections { // ADD/REMOVE CONTACT ENTRIES
target: gcd
onAddContact: function(handle, displayName, image, badge, status, blocked, loading, lastMsgTs) {
for (var i = 0; i < contactsModel.count; i++) {
if (contactsModel.get(i)["_handle"] == handle) {
return
}
}
var index = contactsModel.count
for (var i = 0; i < contactsModel.count; i++) {
if (contactsModel.get(i)["_lastMsgTs"] < lastMsgTs) {
index = i
break
}
}
var newContact = {
"_handle": handle,
"_displayName": displayName + (blocked ? " (blocked)" : "" ),
"_image": image,
"_badge": badge,
"_status": status,
"_blocked": blocked,
"_loading": loading,
"_loading": loading,
"_lastMsgTs": lastMsgTs
}
contactsModel.insert(index, newContact)
}
onRemoveContact: function(handle) {
for(var i = 0; i < contactsModel.count; i++){
if(contactsModel.get(i)["_handle"] == handle) {
console.log("deleting contact " + contactsModel.get(i)["_handle"])
contactsModel.remove(i)
return
}
}
}
onIncContactUnreadCount: function(handle) {
var ts = Math.round((new Date()).getTime() / 1000);
for(var i = 0; i < contactsModel.count; i++){
if(contactsModel.get(i)["_handle"] == handle) {
var contact = contactsModel.get(i)
contact["_lastMsgTs"] = ts
contactsModel.move(i, 0, 1)
}
}
}
onResetProfile: function() {
contactsModel.clear()
}
}
ListModel { // CONTACT OBJECTS ARE STORED HERE ...
id: contactsModel
}
Repeater {
model: contactsModel // ... AND DISPLAYED HERE
delegate: ContactRow {
handle: _handle
displayName: _displayName
image: _image
badge: _badge
status: _status
blocked: _blocked
loading: _loading
}
}
}
}
}