blob: b6383601da02ca47a83ea4b2d9c25fdfa3af63de [file] [log] [blame]
Sébastien Blin1f915762020-08-03 13:27:42 -04001/*
2 * Copyright (C) 2019-2020 by Savoir-faire Linux
3 * Author: Yang Wang <yang.wang@savoirfairelinux.com>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19import QtQuick 2.15
20import QtQuick.Window 2.15
21import QtQuick.Controls 2.15
22import QtQuick.Controls.Universal 2.12
23import QtQuick.Layouts 1.3
24import QtGraphicalEffects 1.14
25import QtQuick.Controls.Styles 1.4
26import net.jami.Models 1.0
27
28import "../../commoncomponents"
29
30ItemDelegate {
31 id: deviceItemDelegate
32
33 property string deviceName : ""
ababi6fa08612020-08-10 19:13:28 +020034 property string deviceId : ""
Sébastien Blin1f915762020-08-03 13:27:42 -040035 property bool isCurrent : false
36
37 property bool editable : false
38
39 signal btnRemoveDeviceClicked
40
ababi6fa08612020-08-10 19:13:28 +020041 function btnEditDeviceEnter() {
Sébastien Blin1f915762020-08-03 13:27:42 -040042 btnEditDevice.enterBtn()
43 }
44
ababi6fa08612020-08-10 19:13:28 +020045 function btnEditDeviceExit() {
Sébastien Blin1f915762020-08-03 13:27:42 -040046 btnEditDevice.exitBtn()
47 }
48
ababi6fa08612020-08-10 19:13:28 +020049 function btnEditPress() {
Sébastien Blin1f915762020-08-03 13:27:42 -040050 btnEditDevice.pressBtn()
51 }
52
ababi6fa08612020-08-10 19:13:28 +020053 function btnEditRelease() {
Sébastien Blin1f915762020-08-03 13:27:42 -040054 btnEditDevice.releaseBtn()
55 }
56
ababi6fa08612020-08-10 19:13:28 +020057 function toggleEditable() {
Sébastien Blin1f915762020-08-03 13:27:42 -040058 editable = !editable
ababi6fa08612020-08-10 19:13:28 +020059 if (editable) {
60 ClientWrapper.settingsAdaptor.setDeviceName(elidedTextDeviceName.text)
Sébastien Blin1f915762020-08-03 13:27:42 -040061 }
62 }
63
64 highlighted: ListView.isCurrentItem
65
ababi6fa08612020-08-10 19:13:28 +020066 RowLayout {
67 id: layoutDeviceItemDelegate
Sébastien Blin1f915762020-08-03 13:27:42 -040068 anchors.fill: parent
ababi6fa08612020-08-10 19:13:28 +020069 spacing: 8
Sébastien Blin1f915762020-08-03 13:27:42 -040070
ababi6fa08612020-08-10 19:13:28 +020071 Image {
72 Layout.leftMargin: 16
73 Layout.alignment: Qt.AlignVCenter
Sébastien Blin1f915762020-08-03 13:27:42 -040074
ababi6fa08612020-08-10 19:13:28 +020075 Layout.minimumWidth: 24
76 Layout.preferredWidth: 24
77 Layout.maximumWidth: 24
Sébastien Blin1f915762020-08-03 13:27:42 -040078
ababi6fa08612020-08-10 19:13:28 +020079 Layout.minimumHeight: 24
80 Layout.preferredHeight: 24
81 Layout.maximumHeight: 24
82 source: "qrc:/images/icons/baseline-desktop_windows-24px.svg"
Sébastien Blin1f915762020-08-03 13:27:42 -040083 }
84
ababi6fa08612020-08-10 19:13:28 +020085 ColumnLayout {
86 id: col
Sébastien Blin1f915762020-08-03 13:27:42 -040087 Layout.fillWidth: true
ababi6fa08612020-08-10 19:13:28 +020088 Layout.alignment: Qt.AlignLeft | Qt.AlignVCenter
89 Layout.leftMargin: 16
Sébastien Blin1f915762020-08-03 13:27:42 -040090
ababi6fa08612020-08-10 19:13:28 +020091 RowLayout {
Sébastien Blin1f915762020-08-03 13:27:42 -040092 Layout.fillWidth: true
ababi6fa08612020-08-10 19:13:28 +020093 Layout.alignment: Qt.AlignVCenter
Sébastien Blin1f915762020-08-03 13:27:42 -040094
ababi6fa08612020-08-10 19:13:28 +020095 InfoLineEdit {
96 id: editDeviceName
Sébastien Blin1f915762020-08-03 13:27:42 -040097
ababi6fa08612020-08-10 19:13:28 +020098 Layout.preferredWidth: col.width - 100
99 Layout.maximumWidth: col.width - 100
100 Layout.minimumWidth: col.width - 100
101 fieldLayoutWidth: col.width - 100
Sébastien Blin1f915762020-08-03 13:27:42 -0400102
ababi6fa08612020-08-10 19:13:28 +0200103 Layout.minimumHeight: 24
104 Layout.preferredHeight: 24
105 Layout.maximumHeight: 24
Sébastien Blin1f915762020-08-03 13:27:42 -0400106
ababi6fa08612020-08-10 19:13:28 +0200107 fieldLayoutHeight: 24
Sébastien Blin1f915762020-08-03 13:27:42 -0400108
ababi6fa08612020-08-10 19:13:28 +0200109 Layout.alignment: Qt.AlignLeft
110 font.pointSize: JamiTheme.textFontSize
Sébastien Blin1f915762020-08-03 13:27:42 -0400111 font.kerning: true
ababi6fa08612020-08-10 19:13:28 +0200112
113 horizontalAlignment: Text.AlignLeft
114 verticalAlignment: Text.AlignVCenter
115
116 readOnly: !editable
117
118 backgroundColor: "white"
119
120 text: elidedTextDeviceName.elidedText
Sébastien Blin1f915762020-08-03 13:27:42 -0400121 }
122
ababi6fa08612020-08-10 19:13:28 +0200123 TextMetrics {
124 id: elidedTextDeviceName
Sébastien Blin1f915762020-08-03 13:27:42 -0400125
ababi6fa08612020-08-10 19:13:28 +0200126 elide: Text.ElideRight
127 elideWidth: deviceItemDelegate.width - 80
128
129 text: deviceName
Sébastien Blin1f915762020-08-03 13:27:42 -0400130 }
131
ababi6fa08612020-08-10 19:13:28 +0200132 Label {
Sébastien Blin1f915762020-08-03 13:27:42 -0400133 id: labelThisDevice
ababi6fa08612020-08-10 19:13:28 +0200134 Layout.fillWidth: true
135 Layout.rightMargin: 16
136 Layout.minimumHeight: 24
137 Layout.preferredHeight: 24
138 Layout.maximumHeight: 24
Sébastien Blin1f915762020-08-03 13:27:42 -0400139
ababi6fa08612020-08-10 19:13:28 +0200140 Layout.alignment: Qt.AlignRight
141 horizontalAlignment: Text.AlignRight
142 verticalAlignment: Text.AlignVCenter
Sébastien Blin1f915762020-08-03 13:27:42 -0400143
144 visible: isCurrent
145
ababi6fa08612020-08-10 19:13:28 +0200146 font.pointSize: JamiTheme.textFontSize
Sébastien Blin1f915762020-08-03 13:27:42 -0400147 font.kerning: true
148 font.italic: true
149 color: "green"
150 text: qsTr("this device")
151 }
152 }
ababi6fa08612020-08-10 19:13:28 +0200153
154 ElidedTextLabel {
155 id: labelDeviceId
156
157 Layout.fillWidth: true
158
159 Layout.minimumHeight: 24
160 Layout.preferredHeight: 24
161 Layout.maximumHeight: 24
162
163 maxWidth: deviceItemDelegate.width - 80
164 eText: deviceId === "" ? qsTr("Device Id") : deviceId
165 }
166
Sébastien Blin1f915762020-08-03 13:27:42 -0400167 }
168
ababi6fa08612020-08-10 19:13:28 +0200169 HoverableRadiusButton {
Sébastien Blin1f915762020-08-03 13:27:42 -0400170 id: btnEditDevice
171
ababi6fa08612020-08-10 19:13:28 +0200172 Layout.alignment: Qt.AlignVCenter | Qt.AlignRight
173 Layout.rightMargin: 8
Sébastien Blin1f915762020-08-03 13:27:42 -0400174
ababi6fa08612020-08-10 19:13:28 +0200175 Layout.minimumWidth: 32
176 Layout.preferredWidth: 32
177 Layout.maximumWidth: 32
Sébastien Blin1f915762020-08-03 13:27:42 -0400178
ababi6fa08612020-08-10 19:13:28 +0200179 Layout.minimumHeight: 32
180 Layout.preferredHeight: 32
181 Layout.maximumHeight: 32
Sébastien Blin1f915762020-08-03 13:27:42 -0400182
ababi6fa08612020-08-10 19:13:28 +0200183 buttonImageHeight: height - 8
184 buttonImageWidth: width - 8
Sébastien Blin1f915762020-08-03 13:27:42 -0400185
ababi6fa08612020-08-10 19:13:28 +0200186 radius: height / 2
187 width: 25
188 height: 25
189
190 backgroundColor: "transparent"
191
192 source: {
Sébastien Blin1f915762020-08-03 13:27:42 -0400193 if(isCurrent) {
194 var path = editable ? "qrc:/images/icons/round-edit-24px.svg" : "qrc:/images/icons/round-save_alt-24px.svg"
195 return path
196 } else {
197 return "qrc:/images/icons/round-remove_circle-24px.svg"
198 }
199 }
200
201 ToolTip.visible: isHovering
202 ToolTip.text: {
203 if(isCurrent) {
ababi6fa08612020-08-10 19:13:28 +0200204 if (editable) {
Sébastien Blin1f915762020-08-03 13:27:42 -0400205 return qsTr("Edit Device Name")
206 } else {
207 return qsTr("Save new device name")
208 }
209 } else {
210 return qsTr("Unlink Device From Account")
211 }
212 }
213
214 onClicked: {
215 if(isCurrent) {
216 toggleEditable()
217 } else {
218 btnRemoveDeviceClicked()
219 }
220 }
221 }
Sébastien Blin1f915762020-08-03 13:27:42 -0400222 }
223}