| 1005 | } |
| 1006 | |
| 1007 | void KDiff3App::slotFilePrint() |
| 1008 | { |
| 1009 | #ifdef QT_NO_PRINTER |
| 1010 | slotStatusMsg(i18n("Printing not implemented.")); |
| 1011 | #else |
| 1012 | assert(m_pDiffTextWindow1 != nullptr && m_pDiffTextWindow2 != nullptr); |
| 1013 | QPrinter printer; |
| 1014 | QPointer<QPrintDialog> printDialog = QPointer<QPrintDialog>(new QPrintDialog(&printer, this)); |
| 1015 | |
| 1016 | LineRef firstSelectionD3LIdx; |
| 1017 | LineRef lastSelectionD3LIdx; |
| 1018 | |
| 1019 | m_pDiffTextWindow1->getSelectionRange(&firstSelectionD3LIdx, &lastSelectionD3LIdx, eD3LLineCoords); |
| 1020 | |
| 1021 | if(!firstSelectionD3LIdx.isValid()) |
| 1022 | { |
| 1023 | m_pDiffTextWindow2->getSelectionRange(&firstSelectionD3LIdx, &lastSelectionD3LIdx, eD3LLineCoords); |
| 1024 | } |
| 1025 | if(!firstSelectionD3LIdx.isValid() && m_pDiffTextWindow3 != nullptr) |
| 1026 | { |
| 1027 | m_pDiffTextWindow3->getSelectionRange(&firstSelectionD3LIdx, &lastSelectionD3LIdx, eD3LLineCoords); |
| 1028 | } |
| 1029 | |
| 1030 | printDialog->setOption(QPrintDialog::PrintCurrentPage); |
| 1031 | |
| 1032 | if(firstSelectionD3LIdx.isValid()) |
| 1033 | { |
| 1034 | printDialog->setOption(QPrintDialog::PrintSelection); |
| 1035 | printDialog->setPrintRange(QAbstractPrintDialog::Selection); |
| 1036 | } |
| 1037 | |
| 1038 | if(!firstSelectionD3LIdx.isValid()) |
| 1039 | printDialog->setPrintRange(QAbstractPrintDialog::AllPages); |
| 1040 | printDialog->setFromTo(0, 0); |
| 1041 | |
| 1042 | qint32 currentFirstLine = m_pDiffTextWindow1->getFirstLine(); |
| 1043 | qint32 currentFirstD3LIdx = m_pDiffTextWindow1->convertLineToDiff3LineIdx(currentFirstLine); |
| 1044 | |
| 1045 | // do some printer initialization |
| 1046 | printer.setFullPage(false); |
| 1047 | |
| 1048 | // initialize the printer using the print dialog |
| 1049 | if(printDialog->exec() == QDialog::Accepted) |
| 1050 | { |
| 1051 | slotStatusMsg(i18n("Printing...")); |
| 1052 | // create a painter to paint on the printer object |
| 1053 | RLPainter painter(&printer, gOptions->m_bRightToLeftLanguage, width(), fontMetrics().horizontalAdvance('W')); |
| 1054 | |
| 1055 | QPaintDevice* pPaintDevice = painter.device(); |
| 1056 | qint32 dpiy = pPaintDevice->logicalDpiY(); |
| 1057 | qint32 columnDistance = qRound((0.5 / 2.54) * dpiy); // 0.5 cm between the columns |
| 1058 | |
| 1059 | qint32 columns = m_bTripleDiff ? 3 : 2; |
| 1060 | qint32 columnWidth = (pPaintDevice->width() - (columns - 1) * columnDistance) / columns; |
| 1061 | |
| 1062 | QFont f = gOptions->defaultFont(); |
| 1063 | f.setPointSizeF(f.pointSizeF() - 1); // Print with slightly smaller font. |
| 1064 | painter.setFont(f); |
nothing calls this directly
no test coverage detected