Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 1 | |
| 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 | */ |
| 19 | import QtQuick 2.14 |
| 20 | import QtQuick.Controls 2.14 |
| 21 | import QtQuick.Layouts 1.14 |
| 22 | import net.jami.Models 1.0 |
| 23 | |
| 24 | import "../../commoncomponents" |
| 25 | |
| 26 | ItemDelegate { |
| 27 | id: smartListItemDelegate |
ababi | df651a2 | 2020-07-30 13:38:57 +0200 | [diff] [blame] | 28 | height: 72 |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 29 | |
ababi | df651a2 | 2020-07-30 13:38:57 +0200 | [diff] [blame] | 30 | property int lastInteractionPreferredWidth: 80 |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 31 | 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, |
ababi | df651a2 | 2020-07-30 13:38:57 +0200 | [diff] [blame] | 53 | 1.8) : JamiTheme.backgroundColor |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 54 | }) |
| 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, |
| 68 | IsAudioOnly, CallStateStr) |
| 69 | } |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | ConversationSmartListUserImage { |
| 74 | id: conversationSmartListUserImage |
| 75 | |
| 76 | anchors.left: parent.left |
| 77 | anchors.verticalCenter: parent.verticalCenter |
ababi | df651a2 | 2020-07-30 13:38:57 +0200 | [diff] [blame] | 78 | anchors.leftMargin: 16 |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 79 | } |
| 80 | |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 81 | |
ababi | df651a2 | 2020-07-30 13:38:57 +0200 | [diff] [blame] | 82 | RowLayout { |
| 83 | id: rowUsernameAndLastInteractionDate |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 84 | anchors.left: conversationSmartListUserImage.right |
ababi | df651a2 | 2020-07-30 13:38:57 +0200 | [diff] [blame] | 85 | anchors.leftMargin: 16 |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 86 | anchors.top: parent.top |
ababi | 0b68664 | 2020-08-18 17:21:28 +0200 | [diff] [blame] | 87 | anchors.topMargin: conversationSmartListUserLastInteractionMessage.text !== "" ? |
| 88 | 16 : parent.height/2-conversationSmartListUserName.height/2 |
ababi | df651a2 | 2020-07-30 13:38:57 +0200 | [diff] [blame] | 89 | anchors.right: parent.right |
| 90 | anchors.rightMargin: 10 |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 91 | |
ababi | df651a2 | 2020-07-30 13:38:57 +0200 | [diff] [blame] | 92 | Text { |
| 93 | id: conversationSmartListUserName |
ababi | 0b68664 | 2020-08-18 17:21:28 +0200 | [diff] [blame] | 94 | Layout.alignment: conversationSmartListUserLastInteractionMessage.text !== "" ? |
| 95 | Qt.AlignLeft : Qt.AlignLeft | Qt.AlignVCenter |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 96 | |
ababi | df651a2 | 2020-07-30 13:38:57 +0200 | [diff] [blame] | 97 | 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 Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 108 | |
ababi | df651a2 | 2020-07-30 13:38:57 +0200 | [diff] [blame] | 109 | 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 Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 118 | } |
| 119 | |
ababi | df651a2 | 2020-07-30 13:38:57 +0200 | [diff] [blame] | 120 | text: textMetricsConversationSmartListUserLastInteractionDate.elidedText |
| 121 | font.pointSize: JamiTheme.textFontSize |
| 122 | color: JamiTheme.faddedLastInteractionFontColor |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 123 | } |
| 124 | } |
| 125 | |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 126 | |
ababi | df651a2 | 2020-07-30 13:38:57 +0200 | [diff] [blame] | 127 | Text { |
| 128 | id: conversationSmartListUserLastInteractionMessage |
| 129 | anchors.left: conversationSmartListUserImage.right |
| 130 | anchors.leftMargin: 16 |
| 131 | anchors.bottom: rowUsernameAndLastInteractionDate.bottom |
| 132 | anchors.bottomMargin: -20 |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 133 | |
ababi | df651a2 | 2020-07-30 13:38:57 +0200 | [diff] [blame] | 134 | 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 |
| 140 | text: InCall ? CallStateStr : (Draft ? Draft : LastInteraction) |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 141 | } |
ababi | df651a2 | 2020-07-30 13:38:57 +0200 | [diff] [blame] | 142 | |
| 143 | font.hintingPreference: Font.PreferNoHinting |
| 144 | text: textMetricsConversationSmartListUserLastInteractionMessage.elidedText |
| 145 | font.pointSize: JamiTheme.textFontSize |
| 146 | color: Draft ? JamiTheme.draftRed : JamiTheme.faddedLastInteractionFontColor |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 147 | } |
| 148 | |
ababi | df651a2 | 2020-07-30 13:38:57 +0200 | [diff] [blame] | 149 | |
| 150 | |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 151 | background: Rectangle { |
| 152 | id: itemSmartListBackground |
ababi | df651a2 | 2020-07-30 13:38:57 +0200 | [diff] [blame] | 153 | color: InCall ? Qt.lighter(JamiTheme.selectionBlue, 1.8) : JamiTheme.backgroundColor |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 154 | implicitWidth: conversationSmartListView.width |
ababi | df651a2 | 2020-07-30 13:38:57 +0200 | [diff] [blame] | 155 | implicitHeight: parent.height |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 156 | 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 Zhang | 9680887 | 2020-08-27 12:59:09 -0400 | [diff] [blame^] | 183 | smartListContextMenu.parent = mouseAreaSmartListItemDelegate |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 184 | |
| 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 Zhang | 9680887 | 2020-08-27 12:59:09 -0400 | [diff] [blame^] | 194 | smartListContextMenu.contactType = ContactType |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 195 | userProfile.responsibleConvUid = UID |
| 196 | userProfile.aliasText = DisplayName |
| 197 | userProfile.registeredNameText = DisplayID |
| 198 | userProfile.idText = URI |
| 199 | userProfile.contactPicBase64 = Picture |
ababi | df651a2 | 2020-07-30 13:38:57 +0200 | [diff] [blame] | 200 | smartListContextMenu.openMenu() |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 201 | } else if (mouse.button === Qt.LeftButton) { |
| 202 | conversationSmartListView.currentIndex = index |
ababi | 0b68664 | 2020-08-18 17:21:28 +0200 | [diff] [blame] | 203 | conversationSmartListView.needToSelectItems(UID) |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 204 | 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, |
ababi | df651a2 | 2020-07-30 13:38:57 +0200 | [diff] [blame] | 218 | 1.8) : JamiTheme.backgroundColor |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 219 | }) |
| 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 Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 229 | } |