Commit 7153eed5 authored by Edric Milaret's avatar Edric Milaret

video: add screen sharing

- add the ability to share screen entirely
or only a specific area with right click

Refs #74614

Change-Id: Ief64f88d862ede0fe7cd82af82a49e5b43d6532c
parent 465a3149
......@@ -40,7 +40,8 @@ SOURCES += main.cpp\
wizarddialog.cpp \
windowscontactbackend.cpp \
historydelegate.cpp \
contactdelegate.cpp
contactdelegate.cpp \
selectareadialog.cpp
HEADERS += mainwindow.h \
callwidget.h \
......@@ -56,7 +57,8 @@ HEADERS += mainwindow.h \
wizarddialog.h \
windowscontactbackend.h \
historydelegate.h \
contactdelegate.h
contactdelegate.h \
selectareadialog.h
FORMS += mainwindow.ui \
callwidget.ui \
......
/***************************************************************************
* Copyright (C) 2015 by Savoir-Faire Linux *
* Author: Edric Ladent Milaret <edric.ladent-milaret@savoirfairelinux.com>*
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 3 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
**************************************************************************/
#include "selectareadialog.h"
#include <QApplication>
#include <QScreen>
#include <QPainter>
#include "video/sourcemodel.h"
SelectAreaDialog::SelectAreaDialog() :
rubberBand_(nullptr)
{
setWindowFlags(Qt::Widget | Qt::FramelessWindowHint);
setWindowState(Qt::WindowFullScreen);
setParent(0);
setAutoFillBackground(false);
setAttribute(Qt::WA_NoSystemBackground, false);
setAttribute(Qt::WA_TranslucentBackground, true);
setAttribute(Qt::WA_PaintOnScreen);
grabMouse();
rubberBand_ = new QRubberBand(QRubberBand::Rectangle,0);
QApplication::setOverrideCursor(Qt::CrossCursor);
QScreen *screen = QGuiApplication::primaryScreen();
if (screen)
originalPixmap_ = screen->grabWindow(0);
}
void
SelectAreaDialog::mousePressEvent(QMouseEvent* event)
{
if (rubberBand_) {
origin_ = event->globalPos();
rubberBand_->setGeometry(QRect(origin_, QSize()));
rubberBand_->show();
}
}
void
SelectAreaDialog::mouseMoveEvent(QMouseEvent* event)
{
if (rubberBand_)
rubberBand_->setGeometry(QRect(origin_, event->globalPos()));
}
void
SelectAreaDialog::mouseReleaseEvent(QMouseEvent* event)
{
Q_UNUSED(event)
if(rubberBand_) {
QApplication::restoreOverrideCursor();
releaseMouse();
Video::SourceModel::instance()->setDisplay(0, rubberBand_->rect());
delete rubberBand_;
rubberBand_ = nullptr;
reject();
}
}
void
SelectAreaDialog::paintEvent(QPaintEvent* event) {
Q_UNUSED(event)
QPainter painter(this);
painter.drawPixmap(QPoint(0, 0), originalPixmap_);
}
/***************************************************************************
* Copyright (C) 2015 by Savoir-Faire Linux *
* Author: Edric Ladent Milaret <edric.ladent-milaret@savoirfairelinux.com>*
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 3 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
**************************************************************************/
#ifndef SELECTAREADIALOG_H
#define SELECTAREADIALOG_H
#include <QDialog>
#include <QMouseEvent>
#include <QRubberBand>
#include <QDialog>
#include <QPixmap>
class SelectAreaDialog : public QDialog
{
Q_OBJECT
public:
SelectAreaDialog();
protected:
void mousePressEvent(QMouseEvent* event);
void mouseMoveEvent(QMouseEvent* event);
void mouseReleaseEvent(QMouseEvent* event);
void paintEvent(QPaintEvent* event);
private:
QPoint origin_;
QDialog transDialog_;
QRubberBand* rubberBand_;
QPixmap originalPixmap_;
};
#endif // SELECTAREADIALOG_H
......@@ -18,7 +18,10 @@
#include "videowidget.h"
#include <QDebug>
#include <QApplication>
#include <QDesktopWidget>
#include "selectareadialog.h"
VideoWidget::VideoWidget(QWidget *parent) :
QWidget(parent)
......@@ -39,6 +42,10 @@ VideoWidget::VideoWidget(QWidget *parent) :
pal.setColor(QPalette::Background, Qt::black);
this->setAutoFillBackground(true);
this->setPalette(pal);
this->setContextMenuPolicy(Qt::CustomContextMenu);
connect(this, SIGNAL(customContextMenuRequested(const QPoint&)),
this, SLOT(showContextMenu(const QPoint&)));
}
VideoWidget::~VideoWidget()
......@@ -155,3 +162,24 @@ VideoWidget::mouseDoubleClickEvent(QMouseEvent *e) {
this->show();
}
}
void
VideoWidget::showContextMenu(const QPoint& pos)
{
QPoint globalPos = this->mapToGlobal(pos);
QMenu menu;
auto shareAction = new QAction("Share entire screen", this);
menu.addAction(shareAction);
connect(shareAction, &QAction::triggered, [=]() {
Video::SourceModel::instance()->setDisplay(0, QApplication::desktop()->rect());
});
auto shareAreaAction = new QAction("Share screen area", this);
menu.addAction(shareAreaAction);
connect(shareAreaAction, &QAction::triggered, [=]() {
SelectAreaDialog selec;
selec.exec();
});
menu.exec(globalPos);
}
......@@ -21,12 +21,14 @@
#include <QWidget>
#include <QPainter>
#include <video/renderer.h>
#include <video/previewmanager.h>
#include <callmodel.h>
#include <QMutex>
#include <QPixmap>
#include <QMenu>
#include "video/renderer.h"
#include "video/previewmanager.h"
#include "video/sourcemodel.h"
#include "callmodel.h"
class VideoWidget : public QWidget
{
......@@ -44,8 +46,13 @@ public slots:
void frameFromDistant();
void renderingStopped();
protected slots:
void mouseDoubleClickEvent(QMouseEvent *e);
private slots:
void showContextMenu(const QPoint &pos);
private:
Video::Renderer* previewRenderer_;
Video::Renderer* renderer_;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment