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