blob: 3538200a14007cf2c4ad58d61bd7608b7f5b73aa [file] [log] [blame]
Sébastien Blin1f915762020-08-03 13:27:42 -04001
2/*
3 * Copyright (C) 2020 by Savoir-faire Linux
4 * Author: Mingrui Zhang <mingrui.zhang@savoirfairelinux.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19import QtQuick 2.14
20import QtQuick.Controls 2.14
21import QtQuick.Layouts 1.14
22import net.jami.Models 1.0
23
24import "../../commoncomponents"
25
26ItemDelegate {
27 id: smartListItemDelegate
ababidf651a22020-07-30 13:38:57 +020028 height: 72
Sébastien Blin1f915762020-08-03 13:27:42 -040029
ababidf651a22020-07-30 13:38:57 +020030 property int lastInteractionPreferredWidth: 80
Sébastien Blin1f915762020-08-03 13:27:42 -040031 Connections {
32 target: conversationSmartListView
33
34
35 /*
36 * Hack, make sure that smartListItemDelegate does not show extra item
37 * when searching new contacts.
38 */
39 function onForceUpdatePotentialInvalidItem() {
40 smartListItemDelegate.visible = conversationSmartListView.model.rowCount(
41 ) <= index ? false : true
42 }
43
44
45 /*
46 * When currentIndex is -1, deselect items, if not, change select item
47 */
48 function onCurrentIndexIsChanged() {
49 if (conversationSmartListView.currentIndex === -1
50 || conversationSmartListView.currentIndex !== index) {
51 itemSmartListBackground.color = Qt.binding(function () {
52 return InCall ? Qt.lighter(JamiTheme.selectionBlue,
ababidf651a22020-07-30 13:38:57 +020053 1.8) : JamiTheme.backgroundColor
Sébastien Blin1f915762020-08-03 13:27:42 -040054 })
55 } else {
56 itemSmartListBackground.color = Qt.binding(function () {
57 return InCall ? Qt.lighter(JamiTheme.selectionBlue,
58 1.8) : JamiTheme.releaseColor
59 })
60 }
61 }
62
63 function onNeedToShowChatView(accountId, convUid) {
64 if (convUid === UID) {
65 conversationSmartListView.needToAccessMessageWebView(
66 DisplayID == DisplayName ? "" : DisplayID,
67 DisplayName, UID, CallStackViewShouldShow,
ababi76b94aa2020-08-24 17:46:30 +020068 IsAudioOnly, CallState)
Sébastien Blin1f915762020-08-03 13:27:42 -040069 }
70 }
71 }
72
73 ConversationSmartListUserImage {
74 id: conversationSmartListUserImage
75
76 anchors.left: parent.left
77 anchors.verticalCenter: parent.verticalCenter
ababidf651a22020-07-30 13:38:57 +020078 anchors.leftMargin: 16
Sébastien Blin1f915762020-08-03 13:27:42 -040079 }
80
Sébastien Blin1f915762020-08-03 13:27:42 -040081
ababidf651a22020-07-30 13:38:57 +020082 RowLayout {
83 id: rowUsernameAndLastInteractionDate
Sébastien Blin1f915762020-08-03 13:27:42 -040084 anchors.left: conversationSmartListUserImage.right
ababidf651a22020-07-30 13:38:57 +020085 anchors.leftMargin: 16
Sébastien Blin1f915762020-08-03 13:27:42 -040086 anchors.top: parent.top
ababi0b686642020-08-18 17:21:28 +020087 anchors.topMargin: conversationSmartListUserLastInteractionMessage.text !== "" ?
88 16 : parent.height/2-conversationSmartListUserName.height/2
ababidf651a22020-07-30 13:38:57 +020089 anchors.right: parent.right
90 anchors.rightMargin: 10
Sébastien Blin1f915762020-08-03 13:27:42 -040091
ababidf651a22020-07-30 13:38:57 +020092 Text {
93 id: conversationSmartListUserName
ababi0b686642020-08-18 17:21:28 +020094 Layout.alignment: conversationSmartListUserLastInteractionMessage.text !== "" ?
95 Qt.AlignLeft : Qt.AlignLeft | Qt.AlignVCenter
Sébastien Blin1f915762020-08-03 13:27:42 -040096
ababidf651a22020-07-30 13:38:57 +020097 TextMetrics {
98 id: textMetricsConversationSmartListUserName
99 font: conversationSmartListUserName.font
100 elide: Text.ElideRight
101 elideWidth: LastInteractionDate ? (smartListItemDelegate.width - lastInteractionPreferredWidth - conversationSmartListUserImage.width-32) :
102 smartListItemDelegate.width - lastInteractionPreferredWidth
103 text: DisplayName
104 }
105 text: textMetricsConversationSmartListUserName.elidedText
106 font.pointSize: JamiTheme.menuFontSize
107 }
Sébastien Blin1f915762020-08-03 13:27:42 -0400108
ababidf651a22020-07-30 13:38:57 +0200109 Text {
110 id: conversationSmartListUserLastInteractionDate
111 Layout.alignment: Qt.AlignRight
112 TextMetrics {
113 id: textMetricsConversationSmartListUserLastInteractionDate
114 font: conversationSmartListUserLastInteractionDate.font
115 elide: Text.ElideRight
116 elideWidth: lastInteractionPreferredWidth
117 text: LastInteractionDate
Sébastien Blin1f915762020-08-03 13:27:42 -0400118 }
119
ababidf651a22020-07-30 13:38:57 +0200120 text: textMetricsConversationSmartListUserLastInteractionDate.elidedText
121 font.pointSize: JamiTheme.textFontSize
122 color: JamiTheme.faddedLastInteractionFontColor
Sébastien Blin1f915762020-08-03 13:27:42 -0400123 }
124 }
125
Sébastien Blin1f915762020-08-03 13:27:42 -0400126
ababidf651a22020-07-30 13:38:57 +0200127 Text {
128 id: conversationSmartListUserLastInteractionMessage
129 anchors.left: conversationSmartListUserImage.right
130 anchors.leftMargin: 16
131 anchors.bottom: rowUsernameAndLastInteractionDate.bottom
132 anchors.bottomMargin: -20
Sébastien Blin1f915762020-08-03 13:27:42 -0400133
ababidf651a22020-07-30 13:38:57 +0200134 TextMetrics {
135 id: textMetricsConversationSmartListUserLastInteractionMessage
136 font: conversationSmartListUserLastInteractionMessage.font
137 elide: Text.ElideRight
138 elideWidth: LastInteractionDate ? (smartListItemDelegate.width - lastInteractionPreferredWidth - conversationSmartListUserImage.width-32) :
139 smartListItemDelegate.width - lastInteractionPreferredWidth
ababi76b94aa2020-08-24 17:46:30 +0200140 text: InCall ? ClientWrapper.utilsAdaptor.getCallStatusStr(CallState) : (Draft ? Draft : LastInteraction)
Sébastien Blin1f915762020-08-03 13:27:42 -0400141 }
ababidf651a22020-07-30 13:38:57 +0200142
143 font.hintingPreference: Font.PreferNoHinting
144 text: textMetricsConversationSmartListUserLastInteractionMessage.elidedText
145 font.pointSize: JamiTheme.textFontSize
146 color: Draft ? JamiTheme.draftRed : JamiTheme.faddedLastInteractionFontColor
Sébastien Blin1f915762020-08-03 13:27:42 -0400147 }
148
ababidf651a22020-07-30 13:38:57 +0200149
150
Sébastien Blin1f915762020-08-03 13:27:42 -0400151 background: Rectangle {
152 id: itemSmartListBackground
ababidf651a22020-07-30 13:38:57 +0200153 color: InCall ? Qt.lighter(JamiTheme.selectionBlue, 1.8) : JamiTheme.backgroundColor
Sébastien Blin1f915762020-08-03 13:27:42 -0400154 implicitWidth: conversationSmartListView.width
ababidf651a22020-07-30 13:38:57 +0200155 implicitHeight: parent.height
Sébastien Blin1f915762020-08-03 13:27:42 -0400156 border.width: 0
157 }
158
159 MouseArea {
160 id: mouseAreaSmartListItemDelegate
161
162 anchors.fill: parent
163 hoverEnabled: true
164 acceptedButtons: Qt.LeftButton | Qt.RightButton
165
166 onPressed: {
167 if (!InCall) {
168 itemSmartListBackground.color = JamiTheme.pressColor
169 }
170 }
171 onDoubleClicked: {
172 if (!InCall) {
173 ConversationsAdapter.selectConversation(ClientWrapper.utilsAdaptor.getCurrAccId(),
174 UID, false)
175 CallAdapter.placeCall()
176 }
177 }
178 onReleased: {
179 if (!InCall) {
180 itemSmartListBackground.color = JamiTheme.releaseColor
181 }
182 if (mouse.button === Qt.RightButton) {
Ming Rui Zhang96808872020-08-27 12:59:09 -0400183 smartListContextMenu.parent = mouseAreaSmartListItemDelegate
Sébastien Blin1f915762020-08-03 13:27:42 -0400184
185 /*
186 * Make menu pos at mouse.
187 */
188 var relativeMousePos = mapToItem(itemSmartListBackground,
189 mouse.x, mouse.y)
190 smartListContextMenu.x = relativeMousePos.x
191 smartListContextMenu.y = relativeMousePos.y
192 smartListContextMenu.responsibleAccountId = ClientWrapper.utilsAdaptor.getCurrAccId()
193 smartListContextMenu.responsibleConvUid = UID
Ming Rui Zhang96808872020-08-27 12:59:09 -0400194 smartListContextMenu.contactType = ContactType
Sébastien Blin1f915762020-08-03 13:27:42 -0400195 userProfile.responsibleConvUid = UID
196 userProfile.aliasText = DisplayName
197 userProfile.registeredNameText = DisplayID
198 userProfile.idText = URI
199 userProfile.contactPicBase64 = Picture
ababidf651a22020-07-30 13:38:57 +0200200 smartListContextMenu.openMenu()
Sébastien Blin1f915762020-08-03 13:27:42 -0400201 } else if (mouse.button === Qt.LeftButton) {
202 conversationSmartListView.currentIndex = index
ababi0b686642020-08-18 17:21:28 +0200203 conversationSmartListView.needToSelectItems(UID)
Sébastien Blin1f915762020-08-03 13:27:42 -0400204 conversationSmartListView.needToGrabFocus()
205 }
206 }
207 onEntered: {
208 if (!InCall) {
209 itemSmartListBackground.color = JamiTheme.hoverColor
210 }
211 }
212 onExited: {
213 if (!InCall) {
214 if (conversationSmartListView.currentIndex !== index
215 || conversationSmartListView.currentIndex === -1) {
216 itemSmartListBackground.color = Qt.binding(function () {
217 return InCall ? Qt.lighter(JamiTheme.selectionBlue,
ababidf651a22020-07-30 13:38:57 +0200218 1.8) : JamiTheme.backgroundColor
Sébastien Blin1f915762020-08-03 13:27:42 -0400219 })
220 } else {
221 itemSmartListBackground.color = Qt.binding(function () {
222 return InCall ? Qt.lighter(JamiTheme.selectionBlue,
223 1.8) : JamiTheme.releaseColor
224 })
225 }
226 }
227 }
228 }
Sébastien Blin1f915762020-08-03 13:27:42 -0400229}