KShare/screenshotutil.cpp

51 lines
1.6 KiB
C++
Raw Normal View History

2017-04-23 15:05:48 +02:00
#include "screenshotutil.hpp"
#include <QApplication>
#include <QClipboard>
#include <QDebug>
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()) {
QRect geo = screen->geometry();
2017-07-03 16:00:49 +02:00
width = qMax(geo.left() + geo.width(), width);
height = qMax(geo.top() + geo.height(), height);
2017-07-01 17:24:03 +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()) {
QPixmap currentScreen = window(0, screen);
// Hack for https://bugreports.qt.io/browse/QTBUG-58110
static QStringList qVer = QString(qVersion()).split('.');
if (qVer.at(0).toInt() == 5 && qVer.at(1).toInt() < 9) currentScreen = currentScreen.copy(screen->geometry());
painter.drawPixmap(screen->geometry().topLeft(), 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));
}
#endif
painter.end();
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
}