Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 1 | |
| 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 | */ |
| 19 | import QtQuick 2.14 |
| 20 | import QtQuick.Window 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 | |
agsantos | c568750 | 2020-09-03 21:19:10 -0400 | [diff] [blame^] | 27 | // 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 Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 32 | Window { |
| 33 | id: screenRubberBandWindow |
| 34 | |
| 35 | property int screenNumber: 0 |
| 36 | |
| 37 | flags: Qt.FramelessWindowHint | Qt.WindowStaysOnTopHint | Qt.WA_TranslucentBackground |
| 38 | |
| 39 | |
agsantos | c568750 | 2020-09-03 21:19:10 -0400 | [diff] [blame^] | 40 | // 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 Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 43 | color: Qt.rgba(0, 0, 0, 0.7) |
| 44 | |
| 45 | |
agsantos | c568750 | 2020-09-03 21:19:10 -0400 | [diff] [blame^] | 46 | // Rect for selection. |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 47 | 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 | |
agsantos | c568750 | 2020-09-03 21:19:10 -0400 | [diff] [blame^] | 71 | // Geo changing for user selection. |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 72 | 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 | } |