Multi screen support
This commit is contained in:
parent
6a234a059e
commit
635f59fb5d
@ -18,10 +18,10 @@ CropEditor::CropEditor(QPixmap *image, QObject *parent) : QObject(parent) {
|
|||||||
pixmapItem->setScale(1 / ratio);
|
pixmapItem->setScale(1 / ratio);
|
||||||
scene->addItem(pixmapItem);
|
scene->addItem(pixmapItem);
|
||||||
scene->setSceneRect(image->rect());
|
scene->setSceneRect(image->rect());
|
||||||
// view->show();
|
view->resize(image->width(), image->height());
|
||||||
// view->resize(pixmapItem->pixmap().width(), pixmapItem->pixmap().height());
|
view->setMinimumSize(image->size());
|
||||||
// view->move(0, 0);
|
view->move(0, 0);
|
||||||
view->showFullScreen();
|
view->show();
|
||||||
|
|
||||||
connect(scene, &CropScene::closedWithRect, this, &CropEditor::crop);
|
connect(scene, &CropScene::closedWithRect, this, &CropEditor::crop);
|
||||||
}
|
}
|
||||||
|
1
main.cpp
1
main.cpp
@ -88,6 +88,7 @@ int main(int argc, char *argv[]) {
|
|||||||
Worker::init();
|
Worker::init();
|
||||||
a.connect(&a, &QApplication::aboutToQuit, Worker::end);
|
a.connect(&a, &QApplication::aboutToQuit, Worker::end);
|
||||||
a.connect(&a, &QApplication::aboutToQuit, [] { stillAlive = false; });
|
a.connect(&a, &QApplication::aboutToQuit, [] { stillAlive = false; });
|
||||||
|
screenshotutil::fullscreen()->save("/home/arsen/test.png", "PNG");
|
||||||
if (!parser.isSet(h)) w.show();
|
if (!parser.isSet(h)) w.show();
|
||||||
return a.exec();
|
return a.exec();
|
||||||
}
|
}
|
||||||
|
@ -8,9 +8,27 @@
|
|||||||
#include <platformbackend.hpp>
|
#include <platformbackend.hpp>
|
||||||
|
|
||||||
QPixmap *screenshotutil::fullscreen(bool cursor) {
|
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
|
#ifdef PLATFORM_CAPABILITY_CURSOR
|
||||||
if (cursor) {
|
if (cursor) {
|
||||||
QPixmap *noCursor = window(0);
|
QPixmap *noCursor = image;
|
||||||
QScopedPointer<QPixmap> p(noCursor);
|
QScopedPointer<QPixmap> p(noCursor);
|
||||||
QPixmap *withCursor = new QPixmap(*noCursor);
|
QPixmap *withCursor = new QPixmap(*noCursor);
|
||||||
QPainter painter(withCursor);
|
QPainter painter(withCursor);
|
||||||
@ -20,11 +38,10 @@ QPixmap *screenshotutil::fullscreen(bool cursor) {
|
|||||||
return withCursor;
|
return withCursor;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
return window(0);
|
return image;
|
||||||
}
|
}
|
||||||
|
|
||||||
QPixmap *screenshotutil::window(WId wid) {
|
QPixmap *screenshotutil::window(WId wid, QScreen *w) {
|
||||||
QScreen *w = QApplication::primaryScreen();
|
|
||||||
QPixmap screen = w->grabWindow(wid);
|
QPixmap screen = w->grabWindow(wid);
|
||||||
QPixmap *pm = new QPixmap(screen.size());
|
QPixmap *pm = new QPixmap(screen.size());
|
||||||
screen.swap(*pm);
|
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) {
|
QPixmap *screenshotutil::fullscreenArea(bool cursor, qreal x, qreal y, qreal w, qreal h) {
|
||||||
auto scr = QApplication::primaryScreen();
|
QPixmap *cropped = new QPixmap;
|
||||||
QRectF area(x, y, w < 0 ? scr->size().width() : w, h < 0 ? scr->size().height() : h);
|
QPixmap *scr = fullscreen(cursor);
|
||||||
#ifdef PLATFORM_CAPABILITY_CURSOR
|
scr->copy(x, y, w, h).swap(*cropped);
|
||||||
if (cursor) {
|
delete scr;
|
||||||
QPointF point = QCursor::pos(scr);
|
return cropped;
|
||||||
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()));
|
|
||||||
}
|
}
|
||||||
|
@ -1,12 +1,13 @@
|
|||||||
#ifndef SCREENSHOTUTIL_HPP
|
#ifndef SCREENSHOTUTIL_HPP
|
||||||
#define SCREENSHOTUTIL_HPP
|
#define SCREENSHOTUTIL_HPP
|
||||||
|
|
||||||
|
#include <QApplication>
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
|
|
||||||
namespace screenshotutil {
|
namespace screenshotutil {
|
||||||
QPixmap *fullscreen(bool cursor = true);
|
QPixmap *fullscreen(bool cursor = true);
|
||||||
QPixmap *fullscreenArea(bool cursor = true, qreal x = 0, qreal y = 0, qreal w = -1, qreal h = -1);
|
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);
|
void toClipboard(QString value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user