From 046491ffffdfc861f72f081df79e1f258d1801dc Mon Sep 17 00:00:00 2001 From: Ognjen Date: Sun, 28 Oct 2018 18:25:49 +0100 Subject: [PATCH 1/4] Add screenshot tool --- sources/imagearea.cpp | 11 +++++++++++ sources/imagearea.h | 6 ++++++ sources/mainwindow.cpp | 9 +++++++++ sources/mainwindow.h | 1 + 4 files changed, 27 insertions(+) diff --git a/sources/imagearea.cpp b/sources/imagearea.cpp index 386a82b..d8a19a7 100644 --- a/sources/imagearea.cpp +++ b/sources/imagearea.cpp @@ -66,6 +66,7 @@ #include #include #include +#include ImageArea::ImageArea(const bool &isOpen, const QString &filePath, QWidget *parent) : QWidget(parent), mIsEdited(false), mIsPaint(false), mIsResize(false) @@ -636,3 +637,13 @@ void ImageArea::pushUndoCommand(UndoCommand *command) if(command != 0) mUndoStack->push(command); } + +void ImageArea::takeScreenshot() +{ + qDebug() << "shot"; + QScreen *screen = QGuiApplication::primaryScreen(); + QPixmap pixmap = screen->grabWindow(0); + QImage im = pixmap.toImage(); + this->getImage()->swap(im); + this->update(); +} diff --git a/sources/imagearea.h b/sources/imagearea.h index 263b7c8..2f149f7 100644 --- a/sources/imagearea.h +++ b/sources/imagearea.h @@ -164,6 +164,11 @@ class ImageArea : public QWidget * */ void pushUndoCommand(UndoCommand *command); + /** + * @brief Take screenshot of parent screen. + * + */ + void takeScreenshot(); private: /** @@ -193,6 +198,7 @@ class ImageArea : public QWidget */ void makeFormatsFilters(); + QImage *mImage, /**< Main image. */ mImageCopy; /**< Copy of main image, need for events. */ // ????????????? AdditionalTools *mAdditionalTools; diff --git a/sources/mainwindow.cpp b/sources/mainwindow.cpp index 12a6d66..b519903 100644 --- a/sources/mainwindow.cpp +++ b/sources/mainwindow.cpp @@ -408,6 +408,10 @@ void MainWindow::initializeMainMenu() mToolsMenu->addMenu(zoomMenu); + QAction *screenshotQtAction = new QAction(tr("Screenshot"), this); + connect(screenshotQtAction, SIGNAL(triggered()), this, SLOT(takeScreenshot())); + mToolsMenu->addAction(screenshotQtAction); + QMenu *aboutMenu = menuBar()->addMenu(tr("&About")); QAction *aboutAction = new QAction(tr("&About EasyPaint"), this); @@ -860,3 +864,8 @@ void MainWindow::helpAct() .arg(tr("version")).arg("0.1.0").arg(tr("Site")).arg(tr("Authors")) .arg(tr("If you like EasyPaint and you want to share your opinion, or send a bug report, or want to suggest new features, we are waiting for you on our tracker."))); } + +void MainWindow::takeScreenshot() +{ + getCurrentImageArea()->takeScreenshot(); +} diff --git a/sources/mainwindow.h b/sources/mainwindow.h index 8e4cd9e..7b9b141 100644 --- a/sources/mainwindow.h +++ b/sources/mainwindow.h @@ -144,6 +144,7 @@ private slots: void clearImageSelection(); void restorePreviousInstrument(); void setInstrument(InstrumentsEnum instrument); + void takeScreenshot(); signals: void sendInstrumentChecked(InstrumentsEnum); From 43dd70bc552a8912c6fbe988069bda5b48a27d17 Mon Sep 17 00:00:00 2001 From: Ognjen Date: Mon, 29 Oct 2018 09:04:57 +0100 Subject: [PATCH 2/4] Resize canvas after screenshot --- sources/imagearea.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/sources/imagearea.cpp b/sources/imagearea.cpp index d8a19a7..d9055ed 100644 --- a/sources/imagearea.cpp +++ b/sources/imagearea.cpp @@ -640,10 +640,9 @@ void ImageArea::pushUndoCommand(UndoCommand *command) void ImageArea::takeScreenshot() { - qDebug() << "shot"; QScreen *screen = QGuiApplication::primaryScreen(); QPixmap pixmap = screen->grabWindow(0); - QImage im = pixmap.toImage(); - this->getImage()->swap(im); - this->update(); + QImage image = pixmap.toImage(); + mAdditionalTools->resizeCanvas(image.width(), image.height(), false); + this->getImage()->swap(image); } From 3bf51b754d874a89fb3d19d9839d408a9e308c8a Mon Sep 17 00:00:00 2001 From: Ognjen Date: Mon, 29 Oct 2018 09:51:22 +0100 Subject: [PATCH 3/4] Hide window on screenshot --- sources/imagearea.cpp | 9 ++++++++- sources/imagearea.h | 5 +++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/sources/imagearea.cpp b/sources/imagearea.cpp index d9055ed..7141d88 100644 --- a/sources/imagearea.cpp +++ b/sources/imagearea.cpp @@ -638,11 +638,18 @@ void ImageArea::pushUndoCommand(UndoCommand *command) mUndoStack->push(command); } -void ImageArea::takeScreenshot() +void ImageArea::_takeScreenshot() { QScreen *screen = QGuiApplication::primaryScreen(); QPixmap pixmap = screen->grabWindow(0); QImage image = pixmap.toImage(); mAdditionalTools->resizeCanvas(image.width(), image.height(), false); this->getImage()->swap(image); + this->topLevelWidget()->show(); +} + +void ImageArea::takeScreenshot() +{ + this->topLevelWidget()->hide(); + QTimer::singleShot(1000, this, &ImageArea::_takeScreenshot); } diff --git a/sources/imagearea.h b/sources/imagearea.h index 2f149f7..f797340 100644 --- a/sources/imagearea.h +++ b/sources/imagearea.h @@ -197,6 +197,11 @@ class ImageArea : public QWidget * */ void makeFormatsFilters(); + /** + * @brief Take screenshot of parent screen. + * + */ + void _takeScreenshot(); QImage *mImage, /**< Main image. */ From 4b549dc1705c3cd32bcadf8a318d046e3728729e Mon Sep 17 00:00:00 2001 From: Ognjen Date: Mon, 29 Oct 2018 11:57:16 +0100 Subject: [PATCH 4/4] Find parent screen --- sources/imagearea.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/sources/imagearea.cpp b/sources/imagearea.cpp index 7141d88..8b144cf 100644 --- a/sources/imagearea.cpp +++ b/sources/imagearea.cpp @@ -66,6 +66,7 @@ #include #include #include +#include #include ImageArea::ImageArea(const bool &isOpen, const QString &filePath, QWidget *parent) : @@ -640,16 +641,16 @@ void ImageArea::pushUndoCommand(UndoCommand *command) void ImageArea::_takeScreenshot() { - QScreen *screen = QGuiApplication::primaryScreen(); + QScreen *screen = QGuiApplication::screens().at(QApplication::desktop()->screenNumber(this)); QPixmap pixmap = screen->grabWindow(0); QImage image = pixmap.toImage(); mAdditionalTools->resizeCanvas(image.width(), image.height(), false); this->getImage()->swap(image); - this->topLevelWidget()->show(); + this->topLevelWidget()->showNormal(); } void ImageArea::takeScreenshot() { - this->topLevelWidget()->hide(); + this->topLevelWidget()->showMinimized(); QTimer::singleShot(1000, this, &ImageArea::_takeScreenshot); }