| 57 | #include "Global/QtCompat.h" |
| 58 | |
| 59 | NATRON_NAMESPACE_ENTER |
| 60 | QImage |
| 61 | NodeGraph::getFullSceneScreenShot() |
| 62 | { |
| 63 | _imp->isDoingPreviewRender = true; |
| 64 | |
| 65 | // The bbox of all nodes in the nodegraph |
| 66 | QRectF sceneR = _imp->calcNodesBoundingRect(); |
| 67 | |
| 68 | // The visible portion of the nodegraph |
| 69 | QRectF viewRect = visibleSceneRect(); |
| 70 | |
| 71 | // Make sure the visible rect is included in the scene rect |
| 72 | sceneR = sceneR.united(viewRect); |
| 73 | |
| 74 | int navWidth = std::ceil(width() * NATRON_NAVIGATOR_BASE_WIDTH); |
| 75 | int navHeight = std::ceil(height() * NATRON_NAVIGATOR_BASE_HEIGHT); |
| 76 | |
| 77 | // Make sceneR and viewRect keep the same aspect ratio as the navigator |
| 78 | double xScale = navWidth / sceneR.width(); |
| 79 | double yScale = navHeight / sceneR.height(); |
| 80 | double scaleFactor = std::max( 0.001, std::min(xScale, yScale) ); |
| 81 | int sceneW_navPixelCoord = std::floor(sceneR.width() * scaleFactor); |
| 82 | int sceneH_navPixelCoord = std::floor(sceneR.height() * scaleFactor); |
| 83 | |
| 84 | // Render the scene in an image with the same aspect ratio as the scene rect |
| 85 | QImage renderImage(sceneW_navPixelCoord, sceneH_navPixelCoord, QImage::Format_ARGB32_Premultiplied); |
| 86 | |
| 87 | // Fill the background |
| 88 | renderImage.fill( QColor(71, 71, 71, 255) ); |
| 89 | |
| 90 | // Offset the visible rect corner as an offset relative to the scene rect corner |
| 91 | viewRect.setX( viewRect.x() - sceneR.x() ); |
| 92 | viewRect.setY( viewRect.y() - sceneR.y() ); |
| 93 | viewRect.setWidth( viewRect.width() - sceneR.x() ); |
| 94 | viewRect.setHeight( viewRect.height() - sceneR.y() ); |
| 95 | |
| 96 | QRectF viewRect_navCoordinates = viewRect; |
| 97 | viewRect_navCoordinates.setLeft(viewRect.left() * scaleFactor); |
| 98 | viewRect_navCoordinates.setBottom(viewRect.bottom() * scaleFactor); |
| 99 | viewRect_navCoordinates.setRight(viewRect.right() * scaleFactor); |
| 100 | viewRect_navCoordinates.setTop(viewRect.top() * scaleFactor); |
| 101 | |
| 102 | // Paint the visible portion with a highlight |
| 103 | QPainter painter(&renderImage); |
| 104 | |
| 105 | // Remove the overlays from the scene before rendering it |
| 106 | scene()->removeItem(_imp->_cacheSizeText); |
| 107 | scene()->removeItem(_imp->_navigator); |
| 108 | |
| 109 | // Render into the QImage with downscaling |
| 110 | scene()->render(&painter, renderImage.rect(), sceneR, Qt::KeepAspectRatio); |
| 111 | |
| 112 | // Add the overlays back |
| 113 | scene()->addItem(_imp->_navigator); |
| 114 | scene()->addItem(_imp->_cacheSizeText); |
| 115 | |
| 116 | // Fill the highlight with a semi transparent whitish grey |
nothing calls this directly
no test coverage detected