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
qquickcolorimage.cpp
Go to the documentation of this file.
1// Copyright (C) 2017 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
7#include <QtQuick/private/qquickimagebase_p_p.h>
8
10
11QQuickColorImage::QQuickColorImage(QQuickItem *parent)
12 : QQuickImage(parent)
13{
14}
15
16QColor QQuickColorImage::color() const
17{
18 return m_color;
19}
20
21void QQuickColorImage::setColor(const QColor &color)
22{
23 if (m_color == color)
24 return;
25
26 m_color = color;
27 if (isComponentComplete())
28 load();
29 emit colorChanged();
30}
31
32void QQuickColorImage::resetColor()
33{
34 setColor(Qt::transparent);
35}
36
37QColor QQuickColorImage::defaultColor() const
38{
39 return m_defaultColor;
40}
41
42void QQuickColorImage::setDefaultColor(const QColor &color)
43{
44 if (m_defaultColor == color)
45 return;
46
47 m_defaultColor = color;
48 emit defaultColorChanged();
49}
50
51void QQuickColorImage::resetDefaultColor()
52{
53 setDefaultColor(Qt::transparent);
54}
55
56void QQuickColorImage::pixmapChange()
57{
58 QQuickImage::pixmapChange();
59 if (m_color.alpha() > 0 && m_color != m_defaultColor) {
60 QQuickImageBasePrivate *d = static_cast<QQuickImageBasePrivate *>(QQuickItemPrivate::get(this));
61 QImage image = d->currentPix->image();
62 if (!image.isNull()) {
63 QPainter painter(&image);
64 painter.setCompositionMode(QPainter::CompositionMode_SourceIn);
65 painter.fillRect(image.rect(), m_color);
66 d->currentPix->setImage(image);
67 }
68 }
69}
70
71QT_END_NAMESPACE
72
73#include "moc_qquickcolorimage_p.cpp"