Sébastien Blin | 8940f3c | 2020-07-23 17:03:11 -0400 | [diff] [blame] | 1 | |
| 2 | /* |
| 3 | * Copyright (C) 2020 by Savoir-faire Linux |
| 4 | * Author: Sébastien Blin <sebastien.blin@savoirfairelinux.com> |
| 5 | * Author: Mingrui Zhang <mingrui.zhang@savoirfairelinux.com> |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; either version 3 of the License, or |
| 10 | * (at your option) any later version. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | * GNU General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License |
| 18 | * along with this program. If not, see <https://www.gnu.org/licenses/>. |
| 19 | */ |
| 20 | import QtQuick 2.14 |
| 21 | import QtQuick.Controls 2.14 |
| 22 | import QtQuick.Layouts 1.14 |
| 23 | import QtQuick.Controls.Universal 2.12 |
| 24 | import net.jami.Models 1.0 |
| 25 | |
| 26 | import "../../commoncomponents" |
| 27 | |
| 28 | Popup { |
| 29 | id: contactPickerPopup |
| 30 | |
| 31 | property int type: ContactPicker.ContactPickerType.JAMICONFERENCE |
| 32 | |
| 33 | |
| 34 | /* |
| 35 | * Important to keep it one, since enum in c++ starts at one for conferences. |
| 36 | */ |
| 37 | enum ContactPickerType { |
| 38 | JAMICONFERENCE = 1, |
| 39 | SIPTRANSFER |
| 40 | } |
| 41 | |
| 42 | contentWidth: 250 |
| 43 | contentHeight: contactPickerPopupRectColumnLayout.height + 50 |
| 44 | |
| 45 | padding: 0 |
| 46 | |
| 47 | modal: true |
| 48 | |
| 49 | contentItem: Rectangle { |
| 50 | id: contactPickerPopupRect |
| 51 | |
| 52 | width: 250 |
| 53 | |
| 54 | HoverableButton { |
| 55 | id: closeButton |
| 56 | |
| 57 | anchors.top: contactPickerPopupRect.top |
| 58 | anchors.topMargin: 5 |
| 59 | anchors.right: contactPickerPopupRect.right |
| 60 | anchors.rightMargin: 5 |
| 61 | |
| 62 | width: 30 |
| 63 | height: 30 |
| 64 | |
| 65 | radius: 30 |
| 66 | source: "qrc:/images/icons/ic_close_black_24dp.png" |
| 67 | |
| 68 | onClicked: { |
| 69 | contactPickerPopup.close() |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | ColumnLayout { |
| 74 | id: contactPickerPopupRectColumnLayout |
| 75 | |
| 76 | anchors.top: contactPickerPopupRect.top |
| 77 | anchors.topMargin: 15 |
| 78 | |
| 79 | Text { |
| 80 | id: contactPickerTitle |
| 81 | |
| 82 | Layout.alignment: Qt.AlignCenter |
| 83 | Layout.preferredWidth: contactPickerPopupRect.width |
| 84 | Layout.preferredHeight: 30 |
| 85 | |
| 86 | font.pointSize: JamiTheme.textFontSize |
| 87 | font.bold: true |
| 88 | |
| 89 | horizontalAlignment: Text.AlignHCenter |
| 90 | verticalAlignment: Text.AlignVCenter |
| 91 | |
| 92 | text: type === ContactPicker.ContactPickerType.JAMICONFERENCE ? qsTr("Add to conference") : qsTr("Transfer this call") |
| 93 | } |
| 94 | |
| 95 | ContactSearchBar { |
| 96 | id: contactPickerContactSearchBar |
| 97 | |
| 98 | Layout.alignment: Qt.AlignCenter |
| 99 | Layout.topMargin: 5 |
| 100 | Layout.bottomMargin: 5 |
| 101 | Layout.preferredWidth: contactPickerPopupRect.width - 10 |
| 102 | Layout.preferredHeight: 35 |
| 103 | |
| 104 | onContactSearchBarTextChanged: { |
| 105 | ContactAdapter.setSearchFilter(text) |
| 106 | } |
| 107 | |
| 108 | Component.onCompleted: { |
| 109 | contactPickerContactSearchBar.setPlaceholderString( |
| 110 | qsTr("Search contacts")) |
| 111 | } |
| 112 | } |
| 113 | |
| 114 | ListView { |
| 115 | id: contactPickerListView |
| 116 | |
| 117 | Layout.alignment: Qt.AlignCenter |
| 118 | Layout.preferredWidth: contactPickerPopupRect.width |
| 119 | Layout.preferredHeight: 200 |
| 120 | |
| 121 | model: ContactAdapter.getContactSelectableModel(type) |
| 122 | |
| 123 | clip: true |
| 124 | |
| 125 | delegate: ContactPickerItemDelegate { |
| 126 | id: contactPickerItemDelegate |
| 127 | } |
| 128 | |
| 129 | ScrollIndicator.vertical: ScrollIndicator {} |
| 130 | } |
| 131 | } |
| 132 | |
| 133 | radius: 10 |
| 134 | color: "white" |
| 135 | } |
| 136 | |
| 137 | onAboutToShow: { |
| 138 | // Reset the model on each show. |
| 139 | contactPickerListView.model = ContactAdapter.getContactSelectableModel( |
| 140 | type) |
| 141 | } |
| 142 | |
| 143 | background: Rectangle { |
| 144 | color: "transparent" |
| 145 | } |
| 146 | } |