blob: e290ce087abbbc666d2aa4e9df0d761316708baa [file] [log] [blame]
Edric Milaret7153eed2015-06-03 15:29:03 -04001/***************************************************************************
2 * Copyright (C) 2015 by Savoir-Faire Linux *
3 * 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"
26
27SelectAreaDialog::SelectAreaDialog() :
28 rubberBand_(nullptr)
29{
30 setWindowFlags(Qt::Widget | Qt::FramelessWindowHint);
31 setWindowState(Qt::WindowFullScreen);
32 setParent(0);
33 setAutoFillBackground(false);
34 setAttribute(Qt::WA_NoSystemBackground, false);
35 setAttribute(Qt::WA_TranslucentBackground, true);
36 setAttribute(Qt::WA_PaintOnScreen);
37 grabMouse();
38 rubberBand_ = new QRubberBand(QRubberBand::Rectangle,0);
39 QApplication::setOverrideCursor(Qt::CrossCursor);
40 QScreen *screen = QGuiApplication::primaryScreen();
41 if (screen)
42 originalPixmap_ = screen->grabWindow(0);
43}
44
45void
46SelectAreaDialog::mousePressEvent(QMouseEvent* event)
47{
48 if (rubberBand_) {
49 origin_ = event->globalPos();
50 rubberBand_->setGeometry(QRect(origin_, QSize()));
51 rubberBand_->show();
52 }
53}
54
55void
56SelectAreaDialog::mouseMoveEvent(QMouseEvent* event)
57{
58 if (rubberBand_)
59 rubberBand_->setGeometry(QRect(origin_, event->globalPos()));
60}
61
62void
63SelectAreaDialog::mouseReleaseEvent(QMouseEvent* event)
64{
65 Q_UNUSED(event)
66
67 if(rubberBand_) {
68 QApplication::restoreOverrideCursor();
69 releaseMouse();
70 Video::SourceModel::instance()->setDisplay(0, rubberBand_->rect());
71 delete rubberBand_;
72 rubberBand_ = nullptr;
73 reject();
74 }
75}
76
77void
78SelectAreaDialog::paintEvent(QPaintEvent* event) {
79 Q_UNUSED(event)
80 QPainter painter(this);
81
82 painter.drawPixmap(QPoint(0, 0), originalPixmap_);
83}