blob: 36bc91f10e132e63e3403174ddfbc9d64f09e088 [file] [log] [blame]
Edric Milaret7153eed2015-06-03 15:29:03 -04001/***************************************************************************
Edric Milaretbab169d2016-01-07 15:13:33 -05002 * Copyright (C) 2015-2016 by Savoir-faire Linux *
Edric Milaret7153eed2015-06-03 15:29:03 -04003 * Author: Edric Ladent Milaret <edric.ladent-milaret@savoirfairelinux.com>*
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 3 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program. If not, see <http://www.gnu.org/licenses/>. *
17 **************************************************************************/
18
19#include "selectareadialog.h"
20
21#include <QApplication>
22#include <QScreen>
23#include <QPainter>
24
25#include "video/sourcemodel.h"
Edric Milaret0e1074d2015-12-08 12:08:52 -050026#include "media/video.h"
27#include "callmodel.h"
Edric Milaret7153eed2015-06-03 15:29:03 -040028
29SelectAreaDialog::SelectAreaDialog() :
30 rubberBand_(nullptr)
31{
32 setWindowFlags(Qt::Widget | Qt::FramelessWindowHint);
33 setWindowState(Qt::WindowFullScreen);
34 setParent(0);
35 setAutoFillBackground(false);
36 setAttribute(Qt::WA_NoSystemBackground, false);
37 setAttribute(Qt::WA_TranslucentBackground, true);
38 setAttribute(Qt::WA_PaintOnScreen);
39 grabMouse();
40 rubberBand_ = new QRubberBand(QRubberBand::Rectangle,0);
41 QApplication::setOverrideCursor(Qt::CrossCursor);
42 QScreen *screen = QGuiApplication::primaryScreen();
43 if (screen)
44 originalPixmap_ = screen->grabWindow(0);
45}
46
47void
48SelectAreaDialog::mousePressEvent(QMouseEvent* event)
49{
50 if (rubberBand_) {
51 origin_ = event->globalPos();
52 rubberBand_->setGeometry(QRect(origin_, QSize()));
53 rubberBand_->show();
54 }
55}
56
57void
58SelectAreaDialog::mouseMoveEvent(QMouseEvent* event)
59{
60 if (rubberBand_)
61 rubberBand_->setGeometry(QRect(origin_, event->globalPos()));
62}
63
64void
65SelectAreaDialog::mouseReleaseEvent(QMouseEvent* event)
66{
67 Q_UNUSED(event)
68
69 if(rubberBand_) {
70 QApplication::restoreOverrideCursor();
71 releaseMouse();
Edric Milaret0e1074d2015-12-08 12:08:52 -050072 if (auto call = CallModel::instance().selectedCall()) {
73 if (auto outVideo = call->firstMedia<Media::Video>(Media::Media::Direction::OUT)) {
74 outVideo->sourceModel()->setDisplay(0, rubberBand_->rect());
75 }
76 }
Edric Milaret7153eed2015-06-03 15:29:03 -040077 delete rubberBand_;
78 rubberBand_ = nullptr;
79 reject();
80 }
81}
82
83void
84SelectAreaDialog::paintEvent(QPaintEvent* event) {
85 Q_UNUSED(event)
86 QPainter painter(this);
87
88 painter.drawPixmap(QPoint(0, 0), originalPixmap_);
89}