| 34 | {} |
| 35 | |
| 36 | void PrintPlotManager::printPlots(QList<PlotWidget *> plotList, QString toolName) |
| 37 | { |
| 38 | // select folder where to save |
| 39 | bool useNativeDialogs = Preferences::get("general_use_native_dialogs").toBool(); |
| 40 | QString folderPath = QFileDialog::getExistingDirectory(nullptr, "Select Folder", "", |
| 41 | (useNativeDialogs ? QFileDialog::Options() |
| 42 | : QFileDialog::ShowDirsOnly | |
| 43 | QFileDialog::DontResolveSymlinks | |
| 44 | QFileDialog::DontUseNativeDialog)); |
| 45 | |
| 46 | if(!folderPath.isEmpty()) { |
| 47 | // use current date and tool name to crete the file name |
| 48 | QString date = QDateTime::currentDateTime().toString("yyyy-MM-dd-hh-mm-ss"); |
| 49 | QString fileName = QString(folderPath + "/Scopy-" + toolName + "-" + date + ".pdf"); |
| 50 | |
| 51 | if(!fileName.isEmpty()) { |
| 52 | QPdfWriter pdfWriter(fileName); |
| 53 | pdfWriter.setResolution(85); |
| 54 | |
| 55 | int widthInPixels = 500; |
| 56 | int heightInPixels = 400; |
| 57 | pdfWriter.setPageSize(QPageSize(QSize(widthInPixels / 3.78, heightInPixels / 3.78), |
| 58 | QPageSize::Millimeter)); // 1 inch = 25.4mm |
| 59 | |
| 60 | QPainter painter(&pdfWriter); |
| 61 | painter.setRenderHint(QPainter::Antialiasing); |
| 62 | |
| 63 | if(!plotList.isEmpty()) { |
| 64 | plotList.first()->printPlot(&painter, m_printWithSymbols); |
| 65 | // if there is more than one plot save it to same file |
| 66 | for(int i = 1; i < plotList.length(); i++) { |
| 67 | pdfWriter.newPage(); |
| 68 | plotList.at(i)->printPlot(&painter, m_printWithSymbols); |
| 69 | } |
| 70 | } |
| 71 | } |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | void PrintPlotManager::setPrintWithSymbols(bool printWithSymbols) { m_printWithSymbols = printWithSymbols; } |
| 76 | |