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/ContactRow.qml

254 lines
7.0 KiB
QML

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 CustomQmlTypes 1.0
import "../styles"
import QtQuick.Controls 1.4
import QtQuick.Controls.Styles 1.4
Item { // LOTS OF NESTING TO DEAL WITH QT WEIRDNESS, SORRY
id: crItem
anchors.left: parent.left
anchors.right: parent.right
height: 48 * logscale + 3
implicitHeight: height
property real logscale: 4 * Math.log10(gcd.themeScale + 1)
property alias displayName: cn.text
property alias image: imgProfile.source
property string handle
property int badge
property bool isActive
property bool isHover
property bool background: true
property string type // profile or contact or button
property string tag // profile version/type
// Profile
property bool defaultPassword
// Contact
property bool blocked
property bool loading
property alias status: imgProfile.status
property string server
Rectangle { // CONTACT ENTRY BACKGROUND COLOR
id: crRect
anchors.left: parent.left
anchors.right: parent.right
height: 48 * logscale + 3
width: parent.width
color: background ? (isHover ? "#D2D2F3" : (isActive ? "#D2D2F3" : "#D2C0DD")) : windowItem.cwtch_background_color
ContactPicture {
id: imgProfile
showStatus: type == "contact"
button: type == "button"
}
ColumnLayout {
anchors.left: imgProfile.right
anchors.right: loading ? loadingProgress.left : rectUnread.left
anchors.verticalCenter: parent.verticalCenter
Label { // CONTACT NAME
id: cn
leftPadding: 10
rightPadding: 10
//wrapMode: Text.WordWrap
font.pixelSize: 16 * gcd.themeScale
font.strikeout: blocked
textFormat: Text.PlainText
//fontSizeMode: Text.HorizontalFit
elide: Text.ElideRight
color: "#000000"
}
Label { // Onion
id: onion
text: handle
leftPadding: 10
rightPadding: 10
font.pixelSize: 10 * gcd.themeScale
font.strikeout: blocked
textFormat: Text.PlainText
//fontSizeMode: Text.HorizontalFit
elide: Text.ElideRight
color: "#000000"
}
}
Rectangle { // UNREAD MESSAGES?
id: rectUnread
height: txtmetric.tightBoundingRect.height + 8 * gcd.themeScale
width: txtmetric.tightBoundingRect.width + 8 * gcd.themeScale
radius: 8 * gcd.themeScale
color: "#4B3557"
visible: badge != 0
anchors.verticalCenter: parent.verticalCenter
anchors.right: parent.right
anchors.rightMargin: 9 * gcd.themeScale
Label {
id: lblUnread
anchors.verticalCenter: parent.verticalCenter
anchors.horizontalCenter: parent.horizontalCenter
color: "#FFFFFF"
font.pixelSize: 12 * gcd.themeScale
text: txtmetric.text
}
TextMetrics {
id: txtmetric
text: badge
font: lblUnread.font
}
}
// Profile
Image {// Profle Type
id: profiletype
source: tag == "v1-userPassword" ? "qrc:/qml/images/fontawesome/solid/lock.svg" : "qrc:/qml/images/fontawesome/solid/lock-open.svg"
anchors.right: parent.right
anchors.verticalCenter: parent.verticalCenter
anchors.leftMargin: 1 * gcd.themeScale
anchors.rightMargin: (20 * gcd.themeScale) + parent.height
height: parent.height * 0.5
width: height
visible: type == "profile"
}
// Contact
ProgressBar { // LOADING ?
id: loadingProgress
property bool running
running: loading
visible: loading
anchors.right: rectUnread.left
anchors.verticalCenter: parent.verticalCenter
anchors.leftMargin: 1 * gcd.themeScale
anchors.rightMargin: 1 * gcd.themeScale
height: cn.height/2
width: 100 * gcd.themeScale
indeterminate: true
style: ProgressBarStyle {
progress: CwtchProgress { running: loadingProgress.running}
}
}
}
MouseArea { // ONCLICK: LOAD CONVERSATION WITH THIS CONTACT
anchors.fill: parent
hoverEnabled: true
onClicked: {
if (type == "contact") {
if (displayName != "me") {
gcd.broadcast("ResetMessagePane")
isActive = true
theStack.pane = theStack.messagePane
gcd.loadMessagesPane(handle)
badge = 0
if (handle.length == 32) {
gcd.requestGroupSettings(handle)
}
}
} else if (type == "profile") {
gcd.broadcast("ResetMessagePane")
gcd.broadcast("ResetProfile")
gcd.selectedProfile = handle
gcd.loadProfile(handle)
parentStack.pane = parentStack.profilePane
} else if (type == "button") { // Add profile button
profileAddEditPane.reset()
parentStack.pane = parentStack.addEditProfilePane
}
}
onEntered: {
isHover = true
}
onExited: {
isHover = false
}
}
SimpleButton {// Edit BUTTON
id: btnEdit
icon: "solid/user-edit"
anchors.right: parent.right
//rectUnread.left
anchors.verticalCenter: parent.verticalCenter
anchors.leftMargin: 1 * gcd.themeScale
anchors.rightMargin: 20 * gcd.themeScale
height: parent.height * 0.75
visible: type == "profile"
onClicked: {
profileAddEditPane.load(handle, displayName, tag)
parentStack.pane = parentStack.addEditProfilePane
}
}
Connections { // UPDATE UNREAD MESSAGES COUNTER
target: gcd
onResetMessagePane: function() {
isActive = false
}
onUpdateContactStatus: function(_handle, _status, _loading) {
if (handle == _handle) {
status = _status
loadingProgress.visible = loadingProgress.running = loading = _loading
}
}
onUpdateContactBlocked: function(_handle, _blocked) {
if (handle == _handle) {
blocked = _blocked
}
}
onUpdateContactDisplayName: function(_handle, _displayName) {
if (handle == _handle) {
displayName = _displayName + (_blocked == true ? " (blocked)" : "")
}
}
onIncContactUnreadCount: function(handle) {
if (handle == _handle && gcd.selectedConversation != handle) {
badge++
}
}
}
}