Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qquickcontext2dtile.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3// Qt-Security score:significant reason:default
4
6
8
9QQuickContext2DTile::QQuickContext2DTile()
10 : m_dirty(true)
11 , m_rect(QRect(0, 0, 1, 1))
12 , m_device(nullptr)
13{
14}
15
17{
18 if (m_painter.isActive())
19 m_painter.end();
20}
21
22QPainter* QQuickContext2DTile::createPainter(bool smooth, bool antialiasing)
23{
24 if (m_painter.isActive())
25 m_painter.end();
26
28 if (m_device) {
29 m_painter.begin(m_device);
30 m_painter.resetTransform();
31 m_painter.setCompositionMode(QPainter::CompositionMode_Source);
32
33#ifdef QQUICKCONTEXT2D_DEBUG
34 int v = 100;
35 int gray = (m_rect.x() / m_rect.width() + m_rect.y() / m_rect.height()) % 2;
36 if (gray)
37 v = 150;
38 m_painter.fillRect(QRect(0, 0, m_rect.width(), m_rect.height()), QColor(v, v, v, 255));
39#endif
40
41 if (antialiasing)
42 m_painter.setRenderHints(QPainter::Antialiasing | QPainter::TextAntialiasing, true);
43 else
44 m_painter.setRenderHints(QPainter::Antialiasing | QPainter::TextAntialiasing, false);
45
46 if (smooth)
47 m_painter.setRenderHint(QPainter::SmoothPixmapTransform, true);
48 else
49 m_painter.setRenderHint(QPainter::SmoothPixmapTransform, false);
50
51 m_painter.setCompositionMode(QPainter::CompositionMode_SourceOver);
52 m_painter.translate(-m_rect.left(), -m_rect.top());
53 m_painter.setClipRect(m_rect);
54 m_painter.setClipping(false);
55 return &m_painter;
56 }
57
58 return nullptr;
59}
60
65
69
70void QQuickContext2DImageTile::setRect(const QRect& r)
71{
72 if (m_rect == r)
73 return;
74 m_rect = r;
75 m_dirty = true;
76 if (m_image.size() != r.size()) {
77 m_image = QImage(r.size(), QImage::Format_ARGB32_Premultiplied);
78 }
79 m_device = &m_image;
80}
81
82QT_END_NAMESPACE
void setRect(const QRect &r) override
virtual QPainter * createPainter(bool smooth, bool antialiasing)