blob: 1261587e826f4c87c064b3f3a555c45ce8c184fc [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)) {
Edric Milaret96826052016-02-02 10:24:14 -050074 int x, y, width, height;
75 QRect realRect;
76 rubberBand_->geometry().getRect(&x, &y, &width, &height);
77 realRect.setX(x);
78 realRect.setY(y);
79 realRect.setWidth(width);
80 realRect.setHeight(height);
81 outVideo->sourceModel()->setDisplay(0, realRect);
Edric Milaret0e1074d2015-12-08 12:08:52 -050082 }
83 }
Edric Milaret7153eed2015-06-03 15:29:03 -040084 delete rubberBand_;
85 rubberBand_ = nullptr;
86 reject();
87 }
88}
89
90void
91SelectAreaDialog::paintEvent(QPaintEvent* event) {
92 Q_UNUSED(event)
93 QPainter painter(this);
94
95 painter.drawPixmap(QPoint(0, 0), originalPixmap_);
96}