Multi screen support

This commit is contained in:
ArsenArsen 2017-07-01 17:24:03 +02:00
parent 6a234a059e
commit 635f59fb5d
4 changed files with 33 additions and 26 deletions

View File

@ -18,10 +18,10 @@ CropEditor::CropEditor(QPixmap *image, QObject *parent) : QObject(parent) {
pixmapItem->setScale(1 / ratio);
scene->addItem(pixmapItem);
scene->setSceneRect(image->rect());
// view->show();
// view->resize(pixmapItem->pixmap().width(), pixmapItem->pixmap().height());
// view->move(0, 0);
view->showFullScreen();
view->resize(image->width(), image->height());
view->setMinimumSize(image->size());
view->move(0, 0);
view->show();
connect(scene, &CropScene::closedWithRect, this, &CropEditor::crop);
}

View File

@ -88,6 +88,7 @@ int main(int argc, char *argv[]) {
Worker::init();
a.connect(&a, &QApplication::aboutToQuit, Worker::end);
a.connect(&a, &QApplication::aboutToQuit, [] { stillAlive = false; });
screenshotutil::fullscreen()->save("/home/arsen/test.png", "PNG");
if (!parser.isSet(h)) w.show();
return a.exec();
}

View File

@ -8,9 +8,27 @@
#include <platformbackend.hpp>
QPixmap *screenshotutil::fullscreen(bool cursor) {
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 = new QPixmap(width, height);
image->fill(Qt::transparent);
QPainter painter(image);
width = 0;
for (QScreen *screen : QApplication::screens()) {
QPixmap *currentScreen = window(0, screen);
painter.drawPixmap(width, 0, currentScreen->copy());
delete currentScreen;
width += screen->size().width();
}
painter.end();
#ifdef PLATFORM_CAPABILITY_CURSOR
if (cursor) {
QPixmap *noCursor = window(0);
QPixmap *noCursor = image;
QScopedPointer<QPixmap> p(noCursor);
QPixmap *withCursor = new QPixmap(*noCursor);
QPainter painter(withCursor);
@ -20,11 +38,10 @@ QPixmap *screenshotutil::fullscreen(bool cursor) {
return withCursor;
}
#endif
return window(0);
return image;
}
QPixmap *screenshotutil::window(WId wid) {
QScreen *w = QApplication::primaryScreen();
QPixmap *screenshotutil::window(WId wid, QScreen *w) {
QPixmap screen = w->grabWindow(wid);
QPixmap *pm = new QPixmap(screen.size());
screen.swap(*pm);
@ -36,21 +53,9 @@ void screenshotutil::toClipboard(QString value) {
}
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);
#ifdef PLATFORM_CAPABILITY_CURSOR
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();
painter.drawPixmap(QCursor::pos() - std::get<0>(cursorData) - area.topLeft().toPoint(), std::get<1>(cursorData));
painter.end();
return withCursor;
}
}
#endif
return new QPixmap(scr->grabWindow(0, area.x(), area.y(), area.width(), area.height()));
QPixmap *cropped = new QPixmap;
QPixmap *scr = fullscreen(cursor);
scr->copy(x, y, w, h).swap(*cropped);
delete scr;
return cropped;
}

View File

@ -1,12 +1,13 @@
#ifndef SCREENSHOTUTIL_HPP
#define SCREENSHOTUTIL_HPP
#include <QApplication>
#include <QWidget>
namespace screenshotutil {
QPixmap *fullscreen(bool cursor = true);
QPixmap *fullscreenArea(bool cursor = true, qreal x = 0, qreal y = 0, qreal w = -1, qreal h = -1);
QPixmap *window(WId wid);
QPixmap *window(WId wid, QScreen *w = QApplication::primaryScreen());
void toClipboard(QString value);
}