KShare/screenshotutil.cpp

32 lines
880 B
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() {
2017-05-13 23:33:36 +02:00
QPixmap *noCursor = window(0);
QScopedPointer<QPixmap> p(noCursor);
2017-05-13 23:39:38 +02:00
QPixmap *withCursor = new QPixmap(*noCursor);
2017-05-13 23:33:36 +02:00
QPainter painter(withCursor);
auto cursorData = PlatformBackend::inst().getCursor();
2017-05-13 23:39:38 +02:00
painter.drawPixmap(QCursor::pos() - std::get<0>(cursorData), std::get<1>(cursorData));
painter.end();
2017-05-13 23:33:36 +02:00
return withCursor;
}
2017-04-23 15:05:48 +02:00
2017-05-06 13:21:12 +02:00
QPixmap *screenshotutil::window(long wid) {
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) {
QApplication::clipboard()->setText(value);
2017-04-23 15:05:48 +02:00
}