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-07-02 20:51:15 +02:00
|
|
|
QPixmap screenshotutil::fullscreen(bool cursor) {
|
2017-07-01 17:24:03 +02:00
|
|
|
int height = 0, width = 0;
|
|
|
|
for (QScreen *screen : QApplication::screens()) {
|
|
|
|
width += screen->size().width();
|
|
|
|
int h = screen->size().height();
|
|
|
|
height = h > height ? h : height;
|
|
|
|
}
|
2017-07-02 20:51:15 +02:00
|
|
|
QPixmap image(width, height);
|
|
|
|
image.fill(Qt::transparent);
|
|
|
|
QPainter painter(&image);
|
2017-07-01 17:24:03 +02:00
|
|
|
width = 0;
|
|
|
|
for (QScreen *screen : QApplication::screens()) {
|
2017-07-02 20:51:15 +02:00
|
|
|
QPixmap currentScreen = window(0, screen);
|
|
|
|
painter.drawPixmap(width, 0, currentScreen);
|
2017-07-01 17:24:03 +02:00
|
|
|
width += screen->size().width();
|
|
|
|
}
|
2017-06-27 11:33:11 +02:00
|
|
|
#ifdef PLATFORM_CAPABILITY_CURSOR
|
2017-05-15 14:10:00 +02:00
|
|
|
if (cursor) {
|
|
|
|
auto cursorData = PlatformBackend::inst().getCursor();
|
|
|
|
painter.drawPixmap(QCursor::pos() - std::get<0>(cursorData), std::get<1>(cursorData));
|
|
|
|
}
|
2017-07-02 20:51:15 +02:00
|
|
|
painter.end();
|
2017-06-27 11:33:11 +02:00
|
|
|
#endif
|
2017-07-01 17:24:03 +02:00
|
|
|
return image;
|
2017-05-09 17:26:00 +02:00
|
|
|
}
|
2017-04-23 15:05:48 +02:00
|
|
|
|
2017-07-02 20:51:15 +02:00
|
|
|
QPixmap screenshotutil::window(WId wid, QScreen *w) {
|
|
|
|
return w->grabWindow(wid);
|
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
|
|
|
|
2017-07-02 20:51:15 +02:00
|
|
|
QPixmap screenshotutil::fullscreenArea(bool cursor, qreal x, qreal y, qreal w, qreal h) {
|
|
|
|
return fullscreen(cursor).copy(x, y, w, h);
|
2017-05-19 22:32:23 +02:00
|
|
|
}
|