KShare/screenshotutil.cpp

47 lines
1.3 KiB
C++
Raw Normal View History

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
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;
}
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()) {
QPixmap currentScreen = window(0, screen);
painter.drawPixmap(width, 0, currentScreen);
2017-07-01 17:24:03 +02:00
width += screen->size().width();
}
#ifdef PLATFORM_CAPABILITY_CURSOR
if (cursor) {
auto cursorData = PlatformBackend::inst().getCursor();
painter.drawPixmap(QCursor::pos() - std::get<0>(cursorData), std::get<1>(cursorData));
}
painter.end();
#endif
2017-07-01 17:24:03 +02:00
return image;
}
2017-04-23 15:05:48 +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) {
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) {
return fullscreen(cursor).copy(x, y, w, h);
2017-05-19 22:32:23 +02:00
}