blob: 506af487368e10ff70ae7eab46259e46b49c23d4 [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.Window 2.14
21import QtQuick.Controls 2.14
22import QtQuick.Layouts 1.14
23import QtQuick.Controls.Universal 2.12
24import net.jami.Models 1.0
25
26import "../js/screenrubberbandcreation.js" as ScreenRubberBandCreation
27
28import "../../commoncomponents"
29
30
31/*
32 * SelectScreenWindow as a seperate window,
33 * is to make user aware of which screen they want to share,
34 * during the video call, if the context menu item is selected.
35 */
36Window {
37 id: selectScreenWindow
38
39 property int minWidth: 650
40 property int minHeight: 500
41
42 property int selectedScreenNumber: -1
43
44
45 /*
46 * Decide whether to show screen area or entire screen.
47 */
48 property bool selectArea: false
49
50
51 /*
52 * How many rows the ScrollView should have.
53 */
54 function calculateRepeaterModel() {
55 var numberOfScreens = Qt.application.screens.length
56
57 if (numberOfScreens % 2 === 1)
58 return numberOfScreens / 2 + 1
59 else
60 return numberOfScreens / 2
61 }
62
63 function calculateScreenNumber(index) {
64 if (index === 0 || index === 1)
65 return index
66 if (index % 2 === 0)
67 return index * 2
68 else
69 return index * 2 + 1
70 }
71
72 minimumWidth: minWidth
73 minimumHeight: minHeight
74
75 title: "Screen sharing"
76
77
78 /*
79 * Note: Qt.application.screens[0] is the app's current existing screen.
80 */
81 screen: Qt.application.screens[0]
82
83 Rectangle {
84 id: selectScreenWindowRect
85
86 anchors.fill: parent
87
88 Text {
89 id: screenListText
90
91 anchors.top: selectScreenWindowRect.top
92 anchors.topMargin: 20
93 anchors.horizontalCenter: selectScreenWindowRect.horizontalCenter
94
95 font.pointSize: JamiTheme.textFontSize + 2
96 font.bold: true
97 text: qsTr("Choose A Screen to Share")
98 }
99
100 ScrollView {
101 id: screenSelectionScrollView
102
103 anchors.centerIn: selectScreenWindowRect
104
105 width: selectScreenWindowRect.width - 50
106 height: selectScreenWindowRect.height - 150
107
108 clip: true
109
110 ScrollBar.horizontal.policy: ScrollBar.AlwaysOff
111
112
113 /*
114 * Column of rows repeater (two screen captures in a row).
115 */
116 Column {
117 id: screenSelectionScrollViewColumn
118
119 spacing: 10
120
121 Repeater {
122 id: screenInfo
123
124 model: calculateRepeaterModel()
125
126 Row {
127 id: screenInfoRow
128
129 spacing: 20
130
131 Connections {
132 target: selectScreenWindow
133
134 function onSelectedScreenNumberChanged() {
135
136
137 /*
138 * Recover from green state.
139 */
140 screenSelectionRectOdd.borderColor = JamiTheme.tabbarBorderColor
141 screenSelectionRectEven.borderColor = JamiTheme.tabbarBorderColor
142 }
143 }
144
145
146 /*
147 * To make sure that two screen captures in one row,
148 * a repeater of two rect is needed, which one in charge
149 * of odd number screen, one in charge of even number screen.
150 */
151 Rectangle {
152 id: screenSelectionRectOdd
153
154 property string borderColor: JamiTheme.tabbarBorderColor
155
156 height: screenSelectionScrollView.height
157 width: screenSelectionScrollView.width / 2 - screenInfoRow.spacing / 2
158
159 radius: 10
160 border.color: borderColor
161
162 Image {
163 id: screenShotOdd
164
165 anchors.top: screenSelectionRectOdd.top
166 anchors.topMargin: 10
167 anchors.horizontalCenter: screenSelectionRectOdd.horizontalCenter
168
169 height: screenSelectionRectOdd.height - 50
170 width: screenSelectionRectOdd.width - 50
171
172 fillMode: Image.PreserveAspectFit
173 mipmap: true
174
175 Component.onCompleted: {
176 screenShotOdd.source = "data:image/png;base64,"
177 + AvAdapter.captureScreen(
178 calculateScreenNumber(index))
179 }
180 }
181
182 Text {
183 id: screenNameOdd
184
185 anchors.top: screenShotOdd.bottom
186 anchors.topMargin: 10
187 anchors.horizontalCenter: screenSelectionRectOdd.horizontalCenter
188
189 font.pointSize: JamiTheme.textFontSize - 2
190 text: qsTr("Screen") + " " + (calculateScreenNumber(
191 index) + 1)
192 }
193
194 MouseArea {
195 anchors.fill: parent
196 acceptedButtons: Qt.LeftButton
197
198 onClicked: {
199 if (selectedScreenNumber == -1
200 || selectedScreenNumber !== calculateScreenNumber(
201 index)) {
202 selectedScreenNumber = calculateScreenNumber(
203 index)
204 screenSelectionRectOdd.borderColor
205 = JamiTheme.screenSelectionBorderGreen
206 }
207 }
208 }
209 }
210
211 Rectangle {
212 id: screenSelectionRectEven
213
214 property string borderColor: JamiTheme.tabbarBorderColor
215
216 height: screenSelectionScrollView.height
217 width: screenSelectionScrollView.width / 2 - screenInfoRow.spacing / 2
218
219 radius: 10
220 border.color: borderColor
221
222 visible: (Qt.application.screens.length) % 2 != 1
223
224 Image {
225 id: screenShotEven
226
227 anchors.top: screenSelectionRectEven.top
228 anchors.topMargin: 10
229 anchors.horizontalCenter: screenSelectionRectEven.horizontalCenter
230
231 height: screenSelectionRectEven.height - 50
232 width: screenSelectionRectEven.width - 50
233
234 fillMode: Image.PreserveAspectFit
235 mipmap: true
236
237 Component.onCompleted: {
238 if (screenSelectionRectEven.visible)
239 screenShotEven.source = "data:image/png;base64,"
240 + AvAdapter.captureScreen(
241 calculateScreenNumber(
242 index + 1))
243 }
244 }
245
246 Text {
247 id: screenNameEven
248
249 anchors.top: screenShotEven.bottom
250 anchors.topMargin: 10
251 anchors.horizontalCenter: screenSelectionRectEven.horizontalCenter
252
253 font.pointSize: JamiTheme.textFontSize - 2
254 text: qsTr(
255 "Screen") + " " + (calculateScreenNumber(
256 index + 1) + 1)
257 }
258
259 MouseArea {
260 anchors.fill: parent
261 acceptedButtons: Qt.LeftButton
262
263 onClicked: {
264 if (selectedScreenNumber == -1
265 || selectedScreenNumber !== calculateScreenNumber(
266 index + 1)) {
267 selectedScreenNumber = calculateScreenNumber(
268 index + 1)
269 screenSelectionRectEven.borderColor
270 = JamiTheme.screenSelectionBorderGreen
271 }
272 }
273 }
274 }
275 }
276 }
277 }
278
279 background: Rectangle {
280 id: screenSelectionScrollViewBackground
281
282 radius: 10
283 border.color: JamiTheme.tabbarBorderColor
284 }
285 }
286 }
287
288 HoverableButton {
289 id: selectButton
290
291 anchors.bottom: selectScreenWindowRect.bottom
292 anchors.bottomMargin: 10
293 anchors.horizontalCenter: selectScreenWindowRect.horizontalCenter
294
295 visible: selectedScreenNumber != -1
296
297 text: qsTr("Share Screen")
298 radius: 10
299
300 onClicked: {
301 if (selectArea) {
302 selectScreenWindow.hide()
303 ScreenRubberBandCreation.createScreenRubberBandWindowObject(
304 selectScreenWindow, selectedScreenNumber)
305 ScreenRubberBandCreation.showScreenRubberBandWindow()
306
307
308 /*
309 * Destory selectScreenWindow once screenRubberBand is closed.
310 */
311 ScreenRubberBandCreation.connectOnClosingEvent(function () {
312 selectScreenWindow.close()
313 })
314 } else {
315 AvAdapter.shareEntireScreen(selectedScreenNumber)
316 selectScreenWindow.close()
317 }
318 }
319 }
320}