2015-03-10 01:32:30 +08:00
|
|
|
/*
|
2015-06-06 09:40:08 +08:00
|
|
|
Copyright © 2015 by The qTox Project
|
|
|
|
|
2015-03-10 01:32:30 +08:00
|
|
|
This file is part of qTox, a Qt-based graphical interface for Tox.
|
|
|
|
|
2015-06-06 09:40:08 +08:00
|
|
|
qTox is libre software: you can redistribute it and/or modify
|
2015-03-10 01:32:30 +08:00
|
|
|
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.
|
2015-06-06 09:40:08 +08:00
|
|
|
|
|
|
|
qTox is distributed in the hope that it will be useful,
|
2015-03-10 01:32:30 +08:00
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2015-06-06 09:40:08 +08:00
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
2015-03-10 01:32:30 +08:00
|
|
|
|
2015-06-06 09:40:08 +08:00
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with qTox. If not, see <http://www.gnu.org/licenses/>.
|
2015-03-10 01:32:30 +08:00
|
|
|
*/
|
|
|
|
|
2015-03-25 09:48:26 +08:00
|
|
|
#include "screengrabberoverlayitem.h"
|
2015-03-10 01:32:30 +08:00
|
|
|
|
|
|
|
#include <QGraphicsSceneMouseEvent>
|
|
|
|
#include <QPainter>
|
|
|
|
#include <QPen>
|
2015-03-25 22:58:50 +08:00
|
|
|
#include <QStyleOptionGraphicsItem>
|
2015-03-10 01:32:30 +08:00
|
|
|
|
|
|
|
#include "screenshotgrabber.h"
|
|
|
|
|
|
|
|
ScreenGrabberOverlayItem::ScreenGrabberOverlayItem(ScreenshotGrabber* grabber)
|
|
|
|
: screnshootGrabber(grabber)
|
|
|
|
{
|
2015-06-06 09:40:08 +08:00
|
|
|
|
2015-03-10 01:32:30 +08:00
|
|
|
QBrush overlayBrush(QColor(0x00, 0x00, 0x00, 0x70)); // Translucent black
|
2015-06-06 09:40:08 +08:00
|
|
|
|
2015-03-10 01:32:30 +08:00
|
|
|
setCursor(QCursor(Qt::CrossCursor));
|
|
|
|
setBrush(overlayBrush);
|
|
|
|
setPen(QPen(Qt::NoPen));
|
2015-06-06 09:40:08 +08:00
|
|
|
|
2015-03-10 01:32:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
ScreenGrabberOverlayItem::~ScreenGrabberOverlayItem()
|
|
|
|
{
|
2015-06-06 09:40:08 +08:00
|
|
|
|
2015-03-10 01:32:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void ScreenGrabberOverlayItem::setChosenRect(QRect rect)
|
|
|
|
{
|
2015-03-25 22:58:50 +08:00
|
|
|
QRect oldRect = chosenRect;
|
|
|
|
chosenRect = rect;
|
|
|
|
update(oldRect.united(rect));
|
2015-03-10 01:32:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void ScreenGrabberOverlayItem::mousePressEvent(QGraphicsSceneMouseEvent* event)
|
|
|
|
{
|
|
|
|
if (event->button() == Qt::LeftButton)
|
|
|
|
this->screnshootGrabber->beginRectChooser(event);
|
2015-06-06 09:40:08 +08:00
|
|
|
|
2015-03-10 01:32:30 +08:00
|
|
|
}
|
|
|
|
|
2015-05-16 20:01:56 +08:00
|
|
|
void ScreenGrabberOverlayItem::paint(QPainter* painter, const QStyleOptionGraphicsItem*, QWidget*)
|
2015-03-10 01:32:30 +08:00
|
|
|
{
|
|
|
|
painter->setBrush(brush());
|
|
|
|
painter->setPen(pen());
|
2015-06-06 09:40:08 +08:00
|
|
|
|
2015-03-10 01:32:30 +08:00
|
|
|
QRectF self = rect();
|
|
|
|
qreal leftX = chosenRect.x();
|
|
|
|
qreal rightX = chosenRect.x() + chosenRect.width();
|
|
|
|
qreal topY = chosenRect.y();
|
|
|
|
qreal bottomY = chosenRect.y() + chosenRect.height();
|
2015-06-06 09:40:08 +08:00
|
|
|
|
2015-03-10 01:32:30 +08:00
|
|
|
painter->drawRect(0, 0, leftX, self.height()); // Left of chosen
|
|
|
|
painter->drawRect(rightX, 0, self.width() - rightX, self.height()); // Right of chosen
|
|
|
|
painter->drawRect(leftX, 0, chosenRect.width(), topY); // Top of chosen
|
|
|
|
painter->drawRect(leftX, bottomY, chosenRect.width(), self.height() - bottomY); // Bottom of chosen
|
|
|
|
}
|