diff --git a/sources/imagearea.cpp b/sources/imagearea.cpp index 386a82b..8b144cf 100644 --- a/sources/imagearea.cpp +++ b/sources/imagearea.cpp @@ -66,6 +66,8 @@ #include #include #include +#include +#include ImageArea::ImageArea(const bool &isOpen, const QString &filePath, QWidget *parent) : QWidget(parent), mIsEdited(false), mIsPaint(false), mIsResize(false) @@ -636,3 +638,19 @@ void ImageArea::pushUndoCommand(UndoCommand *command) if(command != 0) mUndoStack->push(command); } + +void ImageArea::_takeScreenshot() +{ + 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()->showNormal(); +} + +void ImageArea::takeScreenshot() +{ + this->topLevelWidget()->showMinimized(); + QTimer::singleShot(1000, this, &ImageArea::_takeScreenshot); +} diff --git a/sources/imagearea.h b/sources/imagearea.h index 263b7c8..f797340 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: /** @@ -192,6 +197,12 @@ class ImageArea : public QWidget * */ void makeFormatsFilters(); + /** + * @brief Take screenshot of parent screen. + * + */ + void _takeScreenshot(); + QImage *mImage, /**< Main image. */ mImageCopy; /**< Copy of main image, need for events. */ // ????????????? 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);