blob: ed8943aa7b6098a0d2f1f262e184638b30766985 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QGraphicsItem>
#include <QPainter>
#include <QDebug>
#include "listitemcache.h"
ListItemCache::ListItemCache()
{
}
ListItemCache::~ListItemCache()
{
QPixmapCache::remove(m_cacheKey);
}
void ListItemCache::draw(QPainter * painter)
{
QRectF irect = sourceBoundingRect(Qt::LogicalCoordinates);
QRectF vrect = painter->clipPath().boundingRect();
if (vrect.intersects(irect)) {
QRectF newVisibleRect = irect.intersected(vrect);
QPixmap pixmap;
if (!QPixmapCache::find(m_cacheKey, &pixmap) ||
m_visibleRect.toRect() != newVisibleRect.toRect()) {
//qDebug() << "ListItemCache: caching" << m_visibleRect
// << "->" << newVisibleRect;
pixmap = QPixmap(sourceBoundingRect().toRect().size());
pixmap.fill(Qt::transparent);
QPainter pixmapPainter(&pixmap);
drawSource(&pixmapPainter);
pixmapPainter.end();
m_cacheKey = QPixmapCache::insert(pixmap);
m_visibleRect = newVisibleRect;
}
//qDebug() << "ListItemCache: blitting" << m_visibleRect;
painter->drawPixmap(0, 0, pixmap);
}
}
void ListItemCache::sourceChanged(ChangeFlags)
{
QPixmapCache::remove(m_cacheKey);
}
|