mirror of
https://invent.kde.org/graphics/okular
synced 2024-09-12 20:51:17 +00:00
QtQuick: remove unnecessary use of QQuickPixmapItem
It was already ported to render into a pixmap, so just pass that pixmap as a texture.
This commit is contained in:
parent
77dfe3ddc6
commit
374d953e39
|
@ -24,6 +24,7 @@
|
|||
#include <QTimer>
|
||||
#include <QStyleOptionGraphicsItem>
|
||||
#include <QQuickWindow>
|
||||
#include <QSGSimpleTextureNode>
|
||||
|
||||
#include <core/bookmarkmanager.h>
|
||||
#include <core/document.h>
|
||||
|
@ -37,7 +38,7 @@
|
|||
#define REDRAW_TIMEOUT 250
|
||||
|
||||
PageItem::PageItem(QQuickItem *parent)
|
||||
: QQuickPaintedItem(parent),
|
||||
: QQuickItem(parent),
|
||||
Okular::View( QLatin1String( "PageView" ) ),
|
||||
m_page(nullptr),
|
||||
m_smooth(false),
|
||||
|
@ -308,16 +309,27 @@ void PageItem::geometryChanged(const QRectF &newGeometry,
|
|||
}
|
||||
}
|
||||
|
||||
void PageItem::paint(QPainter *painter)
|
||||
QSGNode * PageItem::updatePaintNode(QSGNode* node, QQuickItem::UpdatePaintNodeData* /*data*/)
|
||||
{
|
||||
if (!m_documentItem || !m_page) {
|
||||
return;
|
||||
if (!window() || m_buffer.isNull()) {
|
||||
delete node;
|
||||
return nullptr;
|
||||
}
|
||||
QSGSimpleTextureNode *n = static_cast<QSGSimpleTextureNode *>(node);
|
||||
if (!n) {
|
||||
n = new QSGSimpleTextureNode();
|
||||
n->setOwnsTexture(true);
|
||||
}
|
||||
|
||||
const bool setAA = m_smooth && !(painter->renderHints() & QPainter::Antialiasing);
|
||||
if (setAA) {
|
||||
painter->save();
|
||||
painter->setRenderHint(QPainter::Antialiasing, true);
|
||||
n->setTexture(window()->createTextureFromImage(m_buffer));
|
||||
n->setRect(boundingRect());
|
||||
return n;
|
||||
}
|
||||
|
||||
void PageItem::paint()
|
||||
{
|
||||
if (!m_documentItem || !m_page || !window()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Observer *observer = m_isThumbnail ? m_documentItem.data()->thumbnailObserver() : m_documentItem.data()->pageviewObserver();
|
||||
|
@ -334,22 +346,27 @@ void PageItem::paint(QPainter *painter)
|
|||
const int flags = PagePainter::Accessibility | PagePainter::Highlights | PagePainter::Annotations;
|
||||
// Simply using the limits as described by textureSize will, at times, result in the page painter
|
||||
// attempting to write outside the data area, unsurprisingly resulting in a crash.
|
||||
QRect limits(QPoint(0, 0), textureSize().isValid() ? textureSize() : QSize(width(), height()));
|
||||
QRect limits(QPoint(0, 0), QSize(width(), height()));
|
||||
if(limits.width() > width())
|
||||
limits.setWidth(width());
|
||||
if(limits.height() > height())
|
||||
limits.setHeight(height());
|
||||
|
||||
QPixmap pix(width()*dpr, height()*dpr);
|
||||
QSize size(width()*dpr, height()*dpr);
|
||||
if (size.isNull()) {
|
||||
return;
|
||||
}
|
||||
|
||||
QPixmap pix(size);
|
||||
pix.setDevicePixelRatio(dpr);
|
||||
QPainter p(&pix);
|
||||
p.setRenderHint(QPainter::Antialiasing, m_smooth);
|
||||
PagePainter::paintPageOnPainter(&p, m_page, observer, flags, width(), height(), limits);
|
||||
p.end();
|
||||
painter->drawPixmap(QPoint(), pix);
|
||||
|
||||
if (setAA) {
|
||||
painter->restore();
|
||||
}
|
||||
m_buffer = pix.toImage();
|
||||
|
||||
update();
|
||||
}
|
||||
|
||||
//Protected slots
|
||||
|
@ -357,7 +374,7 @@ void PageItem::delayedRedraw()
|
|||
{
|
||||
if (m_documentItem && m_page) {
|
||||
m_intentionalDraw = true;
|
||||
update();
|
||||
paint();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -20,13 +20,15 @@
|
|||
#ifndef QPAGEITEM_H
|
||||
#define QPAGEITEM_H
|
||||
|
||||
#include <QQuickPaintedItem>
|
||||
#include <QQuickItem>
|
||||
#include <QPointer>
|
||||
#include <QImage>
|
||||
|
||||
#include <core/document.h>
|
||||
#include <core/view.h>
|
||||
|
||||
class QTimer;
|
||||
class QSGTexture;
|
||||
|
||||
class DocumentItem;
|
||||
|
||||
|
@ -35,7 +37,7 @@ namespace Okular {
|
|||
class Page;
|
||||
}
|
||||
|
||||
class PageItem : public QQuickPaintedItem, public Okular::View
|
||||
class PageItem : public QQuickItem, public Okular::View
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
|
@ -105,6 +107,7 @@ public:
|
|||
void setBookmarked(bool bookmarked);
|
||||
|
||||
QStringList bookmarks() const;
|
||||
void paint();
|
||||
|
||||
/**
|
||||
* loads a page bookmark and tries to ensure the bookmarked position is visible
|
||||
|
@ -135,11 +138,11 @@ public:
|
|||
*/
|
||||
Q_INVOKABLE void removeBookmark(const QString &bookmark);
|
||||
|
||||
void paint(QPainter *painter) override;
|
||||
|
||||
void geometryChanged(const QRectF &newGeometry,
|
||||
const QRectF &oldGeometry) override;
|
||||
|
||||
QSGNode * updatePaintNode(QSGNode * , QQuickItem::UpdatePaintNodeData * ) override;
|
||||
|
||||
Q_SIGNALS:
|
||||
void flickableChanged();
|
||||
void implicitWidthChanged();
|
||||
|
@ -171,6 +174,7 @@ private:
|
|||
QTimer *m_redrawTimer;
|
||||
QPointer<QQuickItem> m_flickable;
|
||||
Okular::DocumentViewport m_viewPort;
|
||||
QImage m_buffer;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in a new issue