screen sharing - area selection

This commit is contained in:
ingvar1995 2017-07-13 21:02:42 +03:00
parent 2ff41313f8
commit ace663804e
3 changed files with 73 additions and 36 deletions

View file

@ -1,5 +1,5 @@
from PyQt5 import QtCore, QtGui, QtWidgets
from widgets import RubberBand, create_menu, QRightClickButton, CenteredWidget, LineEdit
from widgets import RubberBandWindow, create_menu, QRightClickButton, CenteredWidget, LineEdit
from profile import Profile
import smileys
import util
@ -71,38 +71,12 @@ class MessageArea(QtWidgets.QPlainTextEdit):
self.insertPlainText(text)
class ScreenShotWindow(QtWidgets.QWidget):
def __init__(self, parent):
super(ScreenShotWindow, self).__init__()
self.parent = parent
self.setMouseTracking(True)
self.setWindowFlags(self.windowFlags() | QtCore.Qt.FramelessWindowHint | QtCore.Qt.WindowStaysOnTopHint)
self.showFullScreen()
self.setWindowOpacity(0.5)
self.rubberband = RubberBand()
self.rubberband.setWindowFlags(self.rubberband.windowFlags() | QtCore.Qt.FramelessWindowHint)
self.rubberband.setAttribute(QtCore.Qt.WA_TranslucentBackground)
class ScreenShotWindow(RubberBandWindow):
def closeEvent(self, *args):
if self.parent.isHidden():
self.parent.show()
def mousePressEvent(self, event):
self.origin = event.pos()
self.rubberband.setGeometry(QtCore.QRect(self.origin, QtCore.QSize()))
self.rubberband.show()
QtWidgets.QWidget.mousePressEvent(self, event)
def mouseMoveEvent(self, event):
if self.rubberband.isVisible():
self.rubberband.setGeometry(QtCore.QRect(self.origin, event.pos()).normalized())
left = QtGui.QRegion(QtCore.QRect(0, 0, self.rubberband.x(), self.height()))
right = QtGui.QRegion(QtCore.QRect(self.rubberband.x() + self.rubberband.width(), 0, self.width(), self.height()))
top = QtGui.QRegion(0, 0, self.width(), self.rubberband.y())
bottom = QtGui.QRegion(0, self.rubberband.y() + self.rubberband.height(), self.width(), self.height())
self.setMask(left + right + top + bottom)
def mouseReleaseEvent(self, event):
if self.rubberband.isVisible():
self.rubberband.hide()
@ -121,13 +95,6 @@ class ScreenShotWindow(QtWidgets.QWidget):
Profile.get_instance().send_screenshot(bytes(byte_array.data()))
self.close()
def keyPressEvent(self, event):
if event.key() == QtCore.Qt.Key_Escape:
self.rubberband.setHidden(True)
self.close()
else:
super(ScreenShotWindow, self).keyPressEvent(event)
class SmileyWindow(QtWidgets.QWidget):
"""

View file

@ -2,7 +2,7 @@ from PyQt5 import QtCore, QtGui, QtWidgets
from settings import *
from profile import Profile
from util import curr_directory, copy
from widgets import CenteredWidget, DataLabel, LineEdit
from widgets import CenteredWidget, DataLabel, LineEdit, RubberBandWindow
import pyaudio
import toxes
import plugin_support
@ -802,6 +802,18 @@ class AudioSettings(CenteredWidget):
settings.save()
class DesktopAreaSelectionWindow(RubberBandWindow):
def mouseReleaseEvent(self, event):
if self.rubberband.isVisible():
self.rubberband.hide()
rect = self.rubberband.geometry()
width, height = rect.width(), rect.height()
if width >= 8 and height >= 8:
self.parent.save(width, height)
self.close()
class VideoSettings(CenteredWidget):
"""
Audio calls settings form
@ -812,6 +824,7 @@ class VideoSettings(CenteredWidget):
self.initUI()
self.retranslateUi()
self.center()
self.desktopAreaSelection = None
def initUI(self):
self.setObjectName("videoSettingsForm")
@ -831,6 +844,9 @@ class VideoSettings(CenteredWidget):
self.input = QtWidgets.QComboBox(self)
self.input.setGeometry(QtCore.QRect(25, 30, 350, 30))
self.input.currentIndexChanged.connect(self.selectionChanged)
self.button = QtWidgets.QPushButton(self)
self.button.clicked.connect(self.button_clicked)
self.button.setGeometry(QtCore.QRect(25, 70, 350, 30))
import cv2
self.devices = [-1]
screen = QtWidgets.QApplication.primaryScreen()
@ -859,6 +875,10 @@ class VideoSettings(CenteredWidget):
def retranslateUi(self):
self.setWindowTitle(QtWidgets.QApplication.translate("videoSettingsForm", "Video settings"))
self.in_label.setText(QtWidgets.QApplication.translate("videoSettingsForm", "Device:"))
self.button.setText(QtWidgets.QApplication.translate("videoSettingsForm", "Select region"))
def button_clicked(self):
self.desktopAreaSelection = DesktopAreaSelectionWindow(self)
def closeEvent(self, event):
try:
@ -871,7 +891,21 @@ class VideoSettings(CenteredWidget):
except Exception as ex:
print('Saving video settings error: ' + str(ex))
def save(self, width, height):
self.desktopAreaSelection = None
settings = Settings.get_instance()
settings.video['device'] = -1
settings.video['width'] = width
settings.video['height'] = height
settings.save()
def selectionChanged(self):
if self.input.currentIndex() == 0:
self.button.setVisible(True)
self.video_size.setVisible(False)
else:
self.button.setVisible(False)
self.video_size.setVisible(True)
width, height = self.frame_max_sizes[self.input.currentIndex()]
self.video_size.clear()
dims = [

View file

@ -77,6 +77,42 @@ class RubberBand(QtWidgets.QRubberBand):
self.painter.end()
class RubberBandWindow(QtWidgets.QWidget):
def __init__(self, parent):
super().__init__()
self.parent = parent
self.setMouseTracking(True)
self.setWindowFlags(self.windowFlags() | QtCore.Qt.FramelessWindowHint | QtCore.Qt.WindowStaysOnTopHint)
self.showFullScreen()
self.setWindowOpacity(0.5)
self.rubberband = RubberBand()
self.rubberband.setWindowFlags(self.rubberband.windowFlags() | QtCore.Qt.FramelessWindowHint)
self.rubberband.setAttribute(QtCore.Qt.WA_TranslucentBackground)
def mousePressEvent(self, event):
self.origin = event.pos()
self.rubberband.setGeometry(QtCore.QRect(self.origin, QtCore.QSize()))
self.rubberband.show()
QtWidgets.QWidget.mousePressEvent(self, event)
def mouseMoveEvent(self, event):
if self.rubberband.isVisible():
self.rubberband.setGeometry(QtCore.QRect(self.origin, event.pos()).normalized())
left = QtGui.QRegion(QtCore.QRect(0, 0, self.rubberband.x(), self.height()))
right = QtGui.QRegion(QtCore.QRect(self.rubberband.x() + self.rubberband.width(), 0, self.width(), self.height()))
top = QtGui.QRegion(0, 0, self.width(), self.rubberband.y())
bottom = QtGui.QRegion(0, self.rubberband.y() + self.rubberband.height(), self.width(), self.height())
self.setMask(left + right + top + bottom)
def keyPressEvent(self, event):
if event.key() == QtCore.Qt.Key_Escape:
self.rubberband.setHidden(True)
self.close()
else:
super().keyPressEvent(event)
def create_menu(menu):
"""
:return translated menu