blob: 3ae5714e390a0e9d803343deb59ae760bfbc879d [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
26
agsantosc5687502020-09-03 21:19:10 -040027// ScreenRubberBand as a seperate frameless window,
28// is to simulate the whole screen area and provide the user
29// the ability to select certain area of it.
30
31// Typically, it is used for video screen sharing.
Sébastien Blin1f915762020-08-03 13:27:42 -040032Window {
33 id: screenRubberBandWindow
34
35 property int screenNumber: 0
36
37 flags: Qt.FramelessWindowHint | Qt.WindowStaysOnTopHint | Qt.WA_TranslucentBackground
38
39
agsantosc5687502020-09-03 21:19:10 -040040 // Opacity with 0.7 window that will fill the entire screen,
41 // provide the users to select the area that they
42 // want to share.
Sébastien Blin1f915762020-08-03 13:27:42 -040043 color: Qt.rgba(0, 0, 0, 0.7)
44
45
agsantosc5687502020-09-03 21:19:10 -040046 // Rect for selection.
Sébastien Blin1f915762020-08-03 13:27:42 -040047 Rectangle {
48 id: recSelect
49
50 height: 0
51 width: 0
52
53 border.color: JamiTheme.rubberBandSelectionBlue
54 border.width: 1
55 color: JamiTheme.rubberBandSelectionBlue
56 opacity: 0.3
57 visible: false
58 }
59
60 MouseArea {
61 id: screenRubberBandMouseArea
62
63 property int originalX: 0
64 property int originalY: 0
65
66 anchors.fill: parent
67 hoverEnabled: true
68 cursorShape: Qt.CrossCursor
69
70
agsantosc5687502020-09-03 21:19:10 -040071 // Geo changing for user selection.
Sébastien Blin1f915762020-08-03 13:27:42 -040072 onPressed: {
73 originalX = mouseX
74 originalY = mouseY
75 recSelect.x = mouseX
76 recSelect.y = mouseY
77 recSelect.visible = true
78 }
79
80 onMouseXChanged: {
81 if (originalX - mouseX >= 0) {
82 recSelect.x = mouseX
83 recSelect.width = originalX - recSelect.x
84 } else if (mouseX - recSelect.x > 0) {
85 recSelect.width = mouseX - recSelect.x
86 }
87 }
88
89 onMouseYChanged: {
90 if (originalY - mouseY >= 0) {
91 recSelect.y = mouseY
92 recSelect.height = originalY - recSelect.y
93 } else if (mouseY - recSelect.y > 0) {
94 recSelect.height = mouseY - recSelect.y
95 }
96 }
97
98 onReleased: {
99 recSelect.visible = false
100 AvAdapter.shareScreenArea(screenNumber, recSelect.x, recSelect.y,
101 recSelect.width, recSelect.height)
102 screenRubberBandWindow.close()
103 }
104 }
105}