diff --git a/cropeditor/cropeditor.cpp b/cropeditor/cropeditor.cpp index 852df46..7868f4c 100644 --- a/cropeditor/cropeditor.cpp +++ b/cropeditor/cropeditor.cpp @@ -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); } diff --git a/main.cpp b/main.cpp index 6e5e926..e38db55 100644 --- a/main.cpp +++ b/main.cpp @@ -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(); } diff --git a/screenshotutil.cpp b/screenshotutil.cpp index 50284b3..786f2e1 100644 --- a/screenshotutil.cpp +++ b/screenshotutil.cpp @@ -8,9 +8,27 @@ #include 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 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; } diff --git a/screenshotutil.hpp b/screenshotutil.hpp index 14e29a6..70e36c1 100644 --- a/screenshotutil.hpp +++ b/screenshotutil.hpp @@ -1,12 +1,13 @@ #ifndef SCREENSHOTUTIL_HPP #define SCREENSHOTUTIL_HPP +#include #include 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); }