| 910 | } |
| 911 | |
| 912 | void DatapickerImageView::print(QPrinter* printer) { |
| 913 | const QRectF& scene_rect = sceneRect(); |
| 914 | const int w = Worksheet::convertFromSceneUnits(scene_rect.width(), Worksheet::Unit::Millimeter); |
| 915 | const int h = Worksheet::convertFromSceneUnits(scene_rect.height(), Worksheet::Unit::Millimeter); |
| 916 | printer->setPageSize(QPageSize(QSizeF(w, h), QPageSize::Millimeter)); |
| 917 | printer->setPageMargins(QMarginsF(0, 0, 0, 0), QPageLayout::Millimeter); |
| 918 | printer->setPrintRange(QPrinter::PageRange); |
| 919 | printer->setCreator(QStringLiteral("LabPlot ") + QLatin1String(LVERSION)); |
| 920 | |
| 921 | QPainter painter(printer); |
| 922 | QRectF targetRect(0, 0, painter.device()->width(), painter.device()->height()); |
| 923 | painter.setRenderHint(QPainter::Antialiasing); |
| 924 | painter.begin(printer); |
| 925 | painter.save(); |
| 926 | painter.scale(targetRect.width() / scene_rect.width(), targetRect.height() / scene_rect.height()); |
| 927 | |
| 928 | // canvas |
| 929 | if (m_image->isLoaded) { |
| 930 | if (m_image->plotImageType() == DatapickerImage::PlotImageType::OriginalImage) { |
| 931 | QImage todraw = m_image->originalPlotImage.scaled(scene_rect.width(), scene_rect.height(), Qt::IgnoreAspectRatio, Qt::SmoothTransformation); |
| 932 | painter.drawImage(scene_rect.topLeft(), todraw); |
| 933 | } else if (m_image->plotImageType() == DatapickerImage::PlotImageType::ProcessedImage) { |
| 934 | QImage todraw = m_image->processedPlotImage.scaled(scene_rect.width(), scene_rect.height(), Qt::IgnoreAspectRatio, Qt::SmoothTransformation); |
| 935 | painter.drawImage(scene_rect.topLeft(), todraw); |
| 936 | } else |
| 937 | painter.fillRect(scene_rect, Qt::white); |
| 938 | } else { |
| 939 | painter.setBrush(QBrush(Qt::gray)); |
| 940 | painter.drawRect(scene_rect); |
| 941 | } |
| 942 | |
| 943 | painter.restore(); |
| 944 | m_image->setPrinting(true); |
| 945 | bool magnificationActive = false; |
| 946 | if (m_image->m_magnificationWindow && m_image->m_magnificationWindow->isVisible()) { |
| 947 | magnificationActive = true; |
| 948 | m_image->m_magnificationWindow->setVisible(false); |
| 949 | } |
| 950 | scene()->render(&painter, QRectF(), scene_rect); |
| 951 | m_image->setPrinting(false); |
| 952 | painter.end(); |
| 953 | |
| 954 | if (magnificationActive) |
| 955 | m_image->m_magnificationWindow->setVisible(true); |
| 956 | } |
| 957 | |
| 958 | void DatapickerImageView::updateBackground() { |
| 959 | invalidateScene(sceneRect(), QGraphicsScene::BackgroundLayer); |
nothing calls this directly
no test coverage detected