Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 1 | /* |
| 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 | |
| 19 | import QtQuick 2.15 |
| 20 | import QtQuick.Window 2.15 |
| 21 | import QtQuick.Controls 2.15 |
| 22 | import QtQuick.Controls.Universal 2.12 |
| 23 | import QtQuick.Layouts 1.3 |
| 24 | import QtGraphicalEffects 1.14 |
| 25 | import QtQuick.Controls.Styles 1.4 |
| 26 | import net.jami.Models 1.0 |
| 27 | |
| 28 | import "../../commoncomponents" |
| 29 | |
| 30 | ItemDelegate { |
| 31 | id: deviceItemDelegate |
| 32 | |
| 33 | property string deviceName : "" |
ababi | 6fa0861 | 2020-08-10 19:13:28 +0200 | [diff] [blame] | 34 | property string deviceId : "" |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 35 | property bool isCurrent : false |
| 36 | |
| 37 | property bool editable : false |
| 38 | |
| 39 | signal btnRemoveDeviceClicked |
| 40 | |
ababi | 6fa0861 | 2020-08-10 19:13:28 +0200 | [diff] [blame] | 41 | function btnEditDeviceEnter() { |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 42 | btnEditDevice.enterBtn() |
| 43 | } |
| 44 | |
ababi | 6fa0861 | 2020-08-10 19:13:28 +0200 | [diff] [blame] | 45 | function btnEditDeviceExit() { |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 46 | btnEditDevice.exitBtn() |
| 47 | } |
| 48 | |
ababi | 6fa0861 | 2020-08-10 19:13:28 +0200 | [diff] [blame] | 49 | function btnEditPress() { |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 50 | btnEditDevice.pressBtn() |
| 51 | } |
| 52 | |
ababi | 6fa0861 | 2020-08-10 19:13:28 +0200 | [diff] [blame] | 53 | function btnEditRelease() { |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 54 | btnEditDevice.releaseBtn() |
| 55 | } |
| 56 | |
ababi | 6fa0861 | 2020-08-10 19:13:28 +0200 | [diff] [blame] | 57 | function toggleEditable() { |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 58 | editable = !editable |
ababi | 6fa0861 | 2020-08-10 19:13:28 +0200 | [diff] [blame] | 59 | if (editable) { |
| 60 | ClientWrapper.settingsAdaptor.setDeviceName(elidedTextDeviceName.text) |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 61 | } |
| 62 | } |
| 63 | |
| 64 | highlighted: ListView.isCurrentItem |
| 65 | |
ababi | 6fa0861 | 2020-08-10 19:13:28 +0200 | [diff] [blame] | 66 | RowLayout { |
| 67 | id: layoutDeviceItemDelegate |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 68 | anchors.fill: parent |
ababi | 6fa0861 | 2020-08-10 19:13:28 +0200 | [diff] [blame] | 69 | spacing: 8 |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 70 | |
ababi | 6fa0861 | 2020-08-10 19:13:28 +0200 | [diff] [blame] | 71 | Image { |
| 72 | Layout.leftMargin: 16 |
| 73 | Layout.alignment: Qt.AlignVCenter |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 74 | |
ababi | 6fa0861 | 2020-08-10 19:13:28 +0200 | [diff] [blame] | 75 | Layout.minimumWidth: 24 |
| 76 | Layout.preferredWidth: 24 |
| 77 | Layout.maximumWidth: 24 |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 78 | |
ababi | 6fa0861 | 2020-08-10 19:13:28 +0200 | [diff] [blame] | 79 | Layout.minimumHeight: 24 |
| 80 | Layout.preferredHeight: 24 |
| 81 | Layout.maximumHeight: 24 |
| 82 | source: "qrc:/images/icons/baseline-desktop_windows-24px.svg" |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 83 | } |
| 84 | |
ababi | 6fa0861 | 2020-08-10 19:13:28 +0200 | [diff] [blame] | 85 | ColumnLayout { |
| 86 | id: col |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 87 | Layout.fillWidth: true |
ababi | 6fa0861 | 2020-08-10 19:13:28 +0200 | [diff] [blame] | 88 | Layout.alignment: Qt.AlignLeft | Qt.AlignVCenter |
| 89 | Layout.leftMargin: 16 |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 90 | |
ababi | 6fa0861 | 2020-08-10 19:13:28 +0200 | [diff] [blame] | 91 | RowLayout { |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 92 | Layout.fillWidth: true |
ababi | 6fa0861 | 2020-08-10 19:13:28 +0200 | [diff] [blame] | 93 | Layout.alignment: Qt.AlignVCenter |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 94 | |
ababi | 6fa0861 | 2020-08-10 19:13:28 +0200 | [diff] [blame] | 95 | InfoLineEdit { |
| 96 | id: editDeviceName |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 97 | |
ababi | 6fa0861 | 2020-08-10 19:13:28 +0200 | [diff] [blame] | 98 | Layout.preferredWidth: col.width - 100 |
| 99 | Layout.maximumWidth: col.width - 100 |
| 100 | Layout.minimumWidth: col.width - 100 |
| 101 | fieldLayoutWidth: col.width - 100 |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 102 | |
ababi | 6fa0861 | 2020-08-10 19:13:28 +0200 | [diff] [blame] | 103 | Layout.minimumHeight: 24 |
| 104 | Layout.preferredHeight: 24 |
| 105 | Layout.maximumHeight: 24 |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 106 | |
ababi | 6fa0861 | 2020-08-10 19:13:28 +0200 | [diff] [blame] | 107 | fieldLayoutHeight: 24 |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 108 | |
ababi | 6fa0861 | 2020-08-10 19:13:28 +0200 | [diff] [blame] | 109 | Layout.alignment: Qt.AlignLeft |
| 110 | font.pointSize: JamiTheme.textFontSize |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 111 | font.kerning: true |
ababi | 6fa0861 | 2020-08-10 19:13:28 +0200 | [diff] [blame] | 112 | |
| 113 | horizontalAlignment: Text.AlignLeft |
| 114 | verticalAlignment: Text.AlignVCenter |
| 115 | |
| 116 | readOnly: !editable |
| 117 | |
| 118 | backgroundColor: "white" |
| 119 | |
| 120 | text: elidedTextDeviceName.elidedText |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 121 | } |
| 122 | |
ababi | 6fa0861 | 2020-08-10 19:13:28 +0200 | [diff] [blame] | 123 | TextMetrics { |
| 124 | id: elidedTextDeviceName |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 125 | |
ababi | 6fa0861 | 2020-08-10 19:13:28 +0200 | [diff] [blame] | 126 | elide: Text.ElideRight |
| 127 | elideWidth: deviceItemDelegate.width - 80 |
| 128 | |
| 129 | text: deviceName |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 130 | } |
| 131 | |
ababi | 6fa0861 | 2020-08-10 19:13:28 +0200 | [diff] [blame] | 132 | Label { |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 133 | id: labelThisDevice |
ababi | 6fa0861 | 2020-08-10 19:13:28 +0200 | [diff] [blame] | 134 | Layout.fillWidth: true |
| 135 | Layout.rightMargin: 16 |
| 136 | Layout.minimumHeight: 24 |
| 137 | Layout.preferredHeight: 24 |
| 138 | Layout.maximumHeight: 24 |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 139 | |
ababi | 6fa0861 | 2020-08-10 19:13:28 +0200 | [diff] [blame] | 140 | Layout.alignment: Qt.AlignRight |
| 141 | horizontalAlignment: Text.AlignRight |
| 142 | verticalAlignment: Text.AlignVCenter |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 143 | |
| 144 | visible: isCurrent |
| 145 | |
ababi | 6fa0861 | 2020-08-10 19:13:28 +0200 | [diff] [blame] | 146 | font.pointSize: JamiTheme.textFontSize |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 147 | font.kerning: true |
| 148 | font.italic: true |
| 149 | color: "green" |
| 150 | text: qsTr("this device") |
| 151 | } |
| 152 | } |
ababi | 6fa0861 | 2020-08-10 19:13:28 +0200 | [diff] [blame] | 153 | |
| 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 Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 167 | } |
| 168 | |
ababi | 6fa0861 | 2020-08-10 19:13:28 +0200 | [diff] [blame] | 169 | HoverableRadiusButton { |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 170 | id: btnEditDevice |
| 171 | |
ababi | 6fa0861 | 2020-08-10 19:13:28 +0200 | [diff] [blame] | 172 | Layout.alignment: Qt.AlignVCenter | Qt.AlignRight |
| 173 | Layout.rightMargin: 8 |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 174 | |
ababi | 6fa0861 | 2020-08-10 19:13:28 +0200 | [diff] [blame] | 175 | Layout.minimumWidth: 32 |
| 176 | Layout.preferredWidth: 32 |
| 177 | Layout.maximumWidth: 32 |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 178 | |
ababi | 6fa0861 | 2020-08-10 19:13:28 +0200 | [diff] [blame] | 179 | Layout.minimumHeight: 32 |
| 180 | Layout.preferredHeight: 32 |
| 181 | Layout.maximumHeight: 32 |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 182 | |
ababi | 6fa0861 | 2020-08-10 19:13:28 +0200 | [diff] [blame] | 183 | buttonImageHeight: height - 8 |
| 184 | buttonImageWidth: width - 8 |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 185 | |
ababi | 6fa0861 | 2020-08-10 19:13:28 +0200 | [diff] [blame] | 186 | radius: height / 2 |
| 187 | width: 25 |
| 188 | height: 25 |
| 189 | |
| 190 | backgroundColor: "transparent" |
| 191 | |
| 192 | source: { |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 193 | 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) { |
ababi | 6fa0861 | 2020-08-10 19:13:28 +0200 | [diff] [blame] | 204 | if (editable) { |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 205 | 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 Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 222 | } |
| 223 | } |