MCPcopy Create free account
hub / github.com/TeXworks/texworks / paint

Method paint

modules/QtPDF/src/PDFDocumentView.cpp:1935–2101  ·  view source on GitHub ↗

An overloaded paint method allows us to handle rendering via asynchronous calls to backend functions.

Source from the content-addressed store, hash-verified

1933// An overloaded paint method allows us to handle rendering via asynchronous
1934// calls to backend functions.
1935void PDFPageGraphicsItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
1936{
1937 // Really, there is an X scaling factor and a Y scaling factor, but we assume
1938 // that the X scaling factor is equal to the Y scaling factor.
1939 qreal scaleFactor = painter->transform().m11();
1940 QTransform scaleT = QTransform::fromScale(scaleFactor, scaleFactor);
1941 QRect pageRect = scaleT.mapRect(boundingRect()).toAlignedRect();
1942 QSharedPointer<Backend::Page> page(_page.toStrongRef());
1943 QSharedPointer<QImage> renderedPage;
1944
1945 if (!page)
1946 return;
1947
1948 // If this is the first time this `PDFPageGraphicsItem` has come into view,
1949 // `_linksLoaded` will be `false`. We then load all of the links on the page.
1950 if (!_linksLoaded)
1951 {
1952 page->asyncLoadLinks(this);
1953 _linksLoaded = true;
1954 }
1955
1956 if (!_annotationsLoaded) {
1957 // FIXME: Load annotations asynchronously?
1958 addAnnotations(page->loadAnnotations());
1959 _annotationsLoaded = true;
1960 }
1961
1962 if ( _zoomLevel != scaleFactor )
1963 _zoomLevel = scaleFactor;
1964
1965 // get a pointer to the parent view (if any)
1966 PDFDocumentView * view = (widget ? qobject_cast<PDFDocumentView*>(widget->parent()) : nullptr);
1967
1968 painter->save();
1969
1970 if (view && view->pageMode() == PDFDocumentView::PageMode_Presentation) {
1971 // NOTE: There is no point in clipping here as we always display the whole
1972 // page, anyway. Hence, the images all have the correct size (no tiling) and
1973 // are usually completely visible.
1974
1975 // The transformation matrix of the `painter` object contains information
1976 // such as the current zoom level of the widget viewing this PDF page. We
1977 // throw away the scaling information because that has already been
1978 // applied during page rendering. (Note: we don't support rotation/skewing,
1979 // so we only care about the translational part)
1980 QTransform pageT = painter->transform();
1981 painter->setTransform(QTransform::fromTranslate(pageT.dx(), pageT.dy()));
1982 if (page->transition() && page->transition()->isRunning()) {
1983 // Get and draw the current frame of the transition
1984 // NOTE: In the (unlikely) case that the two pages we are transitioning
1985 // between are not the same size, the frame image will be padded to
1986 // encompass both pages. In that case, we (may) need to paint the image
1987 // outside the boundaries of this graphics item (unfortunately, that can't
1988 // be helped, but it should not cause too many problems as there should be
1989 // no other items visible below it).
1990 // NOTE: Don't use QRect::center() here to align the respective centers as
1991 // round-off errors can introduce a shift of +-1px.
1992 QImage img(page->transition()->getImage());

Callers

nothing calls this directly

Calls 10

asyncLoadLinksMethod · 0.80
parentMethod · 0.80
transitionMethod · 0.80
isRunningMethod · 0.80
getTileImageMethod · 0.80
leftMethod · 0.80
topMethod · 0.80
loadAnnotationsMethod · 0.45
saveMethod · 0.45
getImageMethod · 0.45

Tested by

no test coverage detected