#include "jkqtpexampleapplication.h" #include #include #include #include #include #include "jkqtplotter/jkqtplotter.h" JKQTPExampleApplication::JKQTPExampleApplication(int &argc, char **argv, bool _waitForScreenshotReady): QApplication(argc, argv), waitForScreenshotReady(_waitForScreenshotReady), readyForScreenshot(!_waitForScreenshotReady), saveScreenshot(false), saveSmallScreenshot(false), saveScreenshotPlot(false), saveSmallScreenshotPlot(false), scaleDownFromHighDPI(false), iterateFunctorSteps(false), iterateFunctorStepsSupressInitial(false), screenshotBasename("screenshot") { screenshotDir=QDir::current(); //for (int i=0; i &f) { functors< maxX) maxX = x; if(y < minY) minY = y; if(y > maxY) maxY = y; } if (minX > maxX || minY > maxY) ofTheKing=QRect(); else ofTheKing.setCoords(minX, minY, maxX+1, maxY+1); return ofTheKing; } int JKQTPExampleApplication::exec() { readCmdLine(); QList plotterList; auto checkPlottersResizeDone=[plotterList]() { if (plotterList.isEmpty()) return true; for (JKQTPlotter* p: plotterList) { if (p->isResizeTimerRunning()) return false; } return true; }; for (QWidget* w: allWidgets()) { JKQTPlotter* plot=dynamic_cast(w); if (plot) plotterList<windowTitle().toLower()windowTitle().toLower(); if (a) return true; if (b) return false; return a(w); QString bn=screenshotBasename.value(iVisible, screenshotBasename.value(0)); if (iVisible>0 && screenshotBasename.value(iVisible, "")=="") { bn+=QString("_win%1").arg(iVisible, 2, 10, QLatin1Char('0')); } if (w) { QPixmap pix_win=w->grab(); /*QPixmap pix; if (screenshotIncludeWindowTitle) { pix=w->screen()->grabWindow(0, w->frameGeometry().x(), w->frameGeometry().y(), w->frameGeometry().width(), w->frameGeometry().height()); } else { pix=pix_win; }*/ if (saveScreenshot || (saveScreenshotPlot&&!plot)) { if (scaleDownFromHighDPI && pix_win.devicePixelRatio()>1.0) { pix_win.scaled((QSizeF(pix_win.size())/pix_win.devicePixelRatio()).toSize()).save(screenshotDir.absoluteFilePath(bn+".png")); } else { pix_win.save(screenshotDir.absoluteFilePath(bn+".png")); } } if (saveSmallScreenshot || (saveSmallScreenshotPlot&&!plot)) { QPixmap img=pix_win.scaledToWidth(150, Qt::SmoothTransformation); img.save(screenshotDir.absoluteFilePath(bn+"_small.png")); } } if (plot) { QString bnp=bn+"_plot"; QImage gr=plot->grabPixelImage(); if (saveScreenshotPlot) { QString fn=bn+".png"; if (saveScreenshot) fn=bnp+".png"; if (scaleDownFromHighDPI && gr.devicePixelRatio()>1.0) { gr.scaled((QSizeF(gr.size())/gr.devicePixelRatio()).toSize()).save(screenshotDir.absoluteFilePath(fn)); } else { gr.save(screenshotDir.absoluteFilePath(fn)); } } if (saveSmallScreenshotPlot) { QString fn=bn+"_small.png"; if (saveSmallScreenshot) fn=bnp+"_small.png"; QImage img=gr.scaledToWidth(150, Qt::SmoothTransformation); img.save(screenshotDir.absoluteFilePath(fn)); } } }; if (iterateFunctorSteps) { QVector> localfunctors=functors; if (!iterateFunctorStepsSupressInitial) localfunctors.prepend([](){}); int iVisible=0; //std::cout<isVisible()) { saveWidget(w, iVisible); iVisible++; } } } return 0; } else if (saveScreenshot||saveSmallScreenshot||saveScreenshotPlot||saveSmallScreenshotPlot) { //std::cout<<"non-functor-mode\n"; //JKQTPlotter::setGlobalResizeDelay(10); QElapsedTimer timer; timer.start(); while(timer.elapsed()isVisible()) { saveWidget(w, iVisible); iVisible++; } } return 0; } else { return QApplication::exec(); } } void JKQTPExampleApplication::notifyReadyForScreenshot() { readyForScreenshot=true; }