2017-04-23 15:05:48 +02:00
|
|
|
#include "screenshotutil.hpp"
|
|
|
|
|
|
|
|
#include <QApplication>
|
|
|
|
#include <QClipboard>
|
2017-05-13 23:33:36 +02:00
|
|
|
#include <QPainter>
|
2017-04-23 15:05:48 +02:00
|
|
|
#include <QPixmap>
|
|
|
|
#include <QScreen>
|
2017-05-13 23:33:36 +02:00
|
|
|
#include <platformbackend.hpp>
|
2017-04-23 15:05:48 +02:00
|
|
|
|
2017-05-15 14:10:00 +02:00
|
|
|
QPixmap *screenshotutil::fullscreen(bool cursor) {
|
|
|
|
if (cursor) {
|
|
|
|
QPixmap *noCursor = window(0);
|
|
|
|
QScopedPointer<QPixmap> p(noCursor);
|
|
|
|
QPixmap *withCursor = new QPixmap(*noCursor);
|
|
|
|
QPainter painter(withCursor);
|
|
|
|
auto cursorData = PlatformBackend::inst().getCursor();
|
|
|
|
painter.drawPixmap(QCursor::pos() - std::get<0>(cursorData), std::get<1>(cursorData));
|
|
|
|
painter.end();
|
|
|
|
return withCursor;
|
|
|
|
}
|
|
|
|
return window(0);
|
2017-05-09 17:26:00 +02:00
|
|
|
}
|
2017-04-23 15:05:48 +02:00
|
|
|
|
2017-05-19 22:32:23 +02:00
|
|
|
QPixmap *screenshotutil::window(WId wid) {
|
2017-05-09 17:26:00 +02:00
|
|
|
QScreen *w = QApplication::primaryScreen();
|
|
|
|
QPixmap screen = w->grabWindow(wid);
|
|
|
|
QPixmap *pm = new QPixmap(screen.size());
|
|
|
|
screen.swap(*pm);
|
|
|
|
return pm;
|
2017-04-23 15:05:48 +02:00
|
|
|
}
|
|
|
|
|
2017-05-06 13:21:12 +02:00
|
|
|
void screenshotutil::toClipboard(QString value) {
|
2017-05-09 17:26:00 +02:00
|
|
|
QApplication::clipboard()->setText(value);
|
2017-04-23 15:05:48 +02:00
|
|
|
}
|
2017-05-19 22:32:23 +02:00
|
|
|
|
|
|
|
QPixmap *screenshotutil::fullscreenArea(bool cursor, qreal x, qreal y, qreal w, qreal h) {
|
|
|
|
auto scr = QApplication::primaryScreen();
|
|
|
|
QRectF area(x, y, w < 0 ? scr->size().width() : w, h < 0 ? scr->size().height() : h);
|
|
|
|
if (cursor) {
|
|
|
|
QPointF point = QCursor::pos(scr);
|
|
|
|
if (area.contains(point)) {
|
|
|
|
QPixmap noCursor = scr->grabWindow(0, area.x(), area.y(), area.width(), area.height());
|
|
|
|
QPixmap *withCursor = new QPixmap(noCursor);
|
|
|
|
QPainter painter(withCursor);
|
|
|
|
auto cursorData = PlatformBackend::inst().getCursor();
|
2017-06-07 10:25:00 +02:00
|
|
|
painter.drawPixmap(QCursor::pos() - std::get<0>(cursorData) - area.topLeft().toPoint(), std::get<1>(cursorData));
|
2017-05-19 22:32:23 +02:00
|
|
|
painter.end();
|
|
|
|
return withCursor;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return new QPixmap(scr->grabWindow(0, area.x(), area.y(), area.width(), area.height()));
|
|
|
|
}
|