qTox  Version: nightly | Commit: bc751c8e1cac455f9690654fcfe0f560d2d7dfdd
screengrabberoverlayitem.cpp
Go to the documentation of this file.
1 /*
2  Copyright © 2015-2019 by The qTox Project Contributors
3 
4  This file is part of qTox, a Qt-based graphical interface for Tox.
5 
6  qTox is libre software: you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  qTox is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with qTox. If not, see <http://www.gnu.org/licenses/>.
18 */
19 
21 
22 #include <QGraphicsSceneMouseEvent>
23 #include <QPainter>
24 #include <QPen>
25 #include <QStyleOptionGraphicsItem>
26 
27 #include "screenshotgrabber.h"
28 
30  : screnshootGrabber(grabber)
31 {
32 
33  QBrush overlayBrush(QColor(0x00, 0x00, 0x00, 0x70)); // Translucent black
34 
35  setCursor(QCursor(Qt::CrossCursor));
36  setBrush(overlayBrush);
37  setPen(QPen(Qt::NoPen));
38 }
39 
41 {
42 }
43 
45 {
46  QRect oldRect = chosenRect;
47  chosenRect = rect;
48  update(oldRect.united(rect));
49 }
50 
51 void ScreenGrabberOverlayItem::mousePressEvent(QGraphicsSceneMouseEvent* event)
52 {
53  if (event->button() == Qt::LeftButton)
54  this->screnshootGrabber->beginRectChooser(event);
55 }
56 
57 void ScreenGrabberOverlayItem::paint(QPainter* painter, const QStyleOptionGraphicsItem*, QWidget*)
58 {
59  painter->setBrush(brush());
60  painter->setPen(pen());
61 
62  QRectF self = rect();
63  qreal leftX = chosenRect.x();
64  qreal rightX = chosenRect.x() + chosenRect.width();
65  qreal topY = chosenRect.y();
66  qreal bottomY = chosenRect.y() + chosenRect.height();
67 
68  painter->drawRect(0, 0, leftX, self.height()); // Left of chosen
69  painter->drawRect(rightX, 0, self.width() - rightX, self.height()); // Right of chosen
70  painter->drawRect(leftX, 0, chosenRect.width(), topY); // Top of chosen
71  painter->drawRect(leftX, bottomY, chosenRect.width(),
72  self.height() - bottomY); // Bottom of chosen
73 }
ScreenshotGrabber
Definition: screenshotgrabber.h:36
ScreenGrabberOverlayItem::paint
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) final
Definition: screengrabberoverlayitem.cpp:57
ScreenGrabberOverlayItem::ScreenGrabberOverlayItem
ScreenGrabberOverlayItem(ScreenshotGrabber *grabber)
Definition: screengrabberoverlayitem.cpp:29
screengrabberoverlayitem.h
screenshotgrabber.h
ScreenGrabberOverlayItem::setChosenRect
void setChosenRect(QRect rect)
Definition: screengrabberoverlayitem.cpp:44
ScreenGrabberOverlayItem::chosenRect
QRect chosenRect
Definition: screengrabberoverlayitem.h:43
ScreenshotGrabber::beginRectChooser
void beginRectChooser(QGraphicsSceneMouseEvent *event)
Definition: screenshotgrabber.cpp:258
ScreenGrabberOverlayItem::screnshootGrabber
ScreenshotGrabber * screnshootGrabber
Definition: screengrabberoverlayitem.h:41
ScreenGrabberOverlayItem::mousePressEvent
void mousePressEvent(QGraphicsSceneMouseEvent *event) final
Definition: screengrabberoverlayitem.cpp:51
ScreenGrabberOverlayItem::~ScreenGrabberOverlayItem
~ScreenGrabberOverlayItem()
Definition: screengrabberoverlayitem.cpp:40