diff options
author | link2xt <link2xt@testrun.org> | 2021-08-22 11:54:36 +0000 |
---|---|---|
committer | link2xt <link2xt@testrun.org> | 2021-08-22 11:54:36 +0000 |
commit | 3f524a1aadede291f9e54a73232336fa98b26a06 (patch) | |
tree | ff1971fedbbb96b0150e660592ce387ba600f459 /qml/ChatlistItem.qml | |
parent | 6d828b2ba8ad4b0586853cbdf4f1b32b8a2bf753 (diff) | |
download | kdeltachat-3f524a1aadede291f9e54a73232336fa98b26a06.tar.gz kdeltachat-3f524a1aadede291f9e54a73232336fa98b26a06.zip |
Move chatlist item to a separate QML file
Diffstat (limited to 'qml/ChatlistItem.qml')
-rw-r--r-- | qml/ChatlistItem.qml | 109 |
1 files changed, 109 insertions, 0 deletions
diff --git a/qml/ChatlistItem.qml b/qml/ChatlistItem.qml new file mode 100644 index 0000000..284f9d2 --- /dev/null +++ b/qml/ChatlistItem.qml @@ -0,0 +1,109 @@ +import QtQuick 2.12 +import QtQuick.Controls 2.12 +import QtQuick.Layouts 1.12 +import QtQml.Models 2.1 +import org.kde.kirigami 2.13 as Kirigami + +import DeltaChat 1.0 + +Kirigami.AbstractListItem { + id: root + + property DcContext context + property int chatId + property string chatName + property string avatarSource + property string username + property int freshMsgCnt + property bool isContactRequest + property bool isPinned + + RowLayout { + Kirigami.Avatar { + source: root.avatarSource + name: root.chatName + color: root.context.getChat(root.chatId).getColor() + MouseArea { + anchors.fill: parent + acceptedButtons: Qt.RightButton + onClicked: { + if (mouse.button === Qt.RightButton) + contextMenu.popup() + } + + Menu { + id: contextMenu + + Action { + icon.name: "pin" + text: "Pin chat" + onTriggered: root.context.setChatVisibility(root.chatId, 2) + } + Action { + text: "Unpin chat" + onTriggered: root.context.setChatVisibility(root.chatId, 0) + } + Action { + text: "Archive chat" + onTriggered: root.context.setChatVisibility(root.chatId, 1) + } + Action { + text: "Unarchive chat" + onTriggered: root.context.setChatVisibility(root.chatId, 0) + } + Action { + icon.name: "delete" + text: "Delete chat" + onTriggered: root.context.deleteChat(root.chatId) + } + } + } + } + + ColumnLayout { + Layout.fillWidth: true + + Label { + text: root.context.getChat(root.chatId).getName() + font.weight: Font.Bold + Layout.fillWidth: true + } + Label { + text: root.username + font: Kirigami.Theme.smallFont + Layout.fillWidth: true + } + } + + Label { + text: root.isContactRequest ? "NEW" : root.freshMsgCnt + visible: root.freshMsgCnt > 0 || root.isContactRequest + + // Align label in the center of a badge. + verticalAlignment: Text.AlignVCenter + horizontalAlignment: Text.AlignHCenter + + // Make sure badge is not too narrow. + Layout.minimumWidth: height + + background: Rectangle { + color: Kirigami.Theme.alternateBackgroundColor + radius: 0.25 * height + } + } + + // "Pinned" badge + Rectangle { + visible: root.isPinned + color: Kirigami.Theme.alternateBackgroundColor + width: Kirigami.Units.gridUnit + height: Kirigami.Units.gridUnit + radius: 0.25 * height + Kirigami.Icon { + source: "pin" + height: Kirigami.Units.gridUnit + width: Kirigami.Units.gridUnit + } + } + } +} |