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
37/*!
38 \internal
39
40 This property holds the original color of the image.
41
42 This allows avoiding colorization if the \c color set by the style or user
43 is the same as the default color.
44*/
45QColor QQuickColorImage::defaultColor() const
46{
47 return m_defaultColor;
48}
49
50void QQuickColorImage::setDefaultColor(const QColor &color)
51{
52 if (m_defaultColor == color)
53 return;
54
55 m_defaultColor = color;
56 emit defaultColorChanged();
57}
58
59void QQuickColorImage::resetDefaultColor()
60{
61 setDefaultColor(Qt::transparent);
62}
63
64void QQuickColorImage::pixmapChange()
65{
66 QQuickImage::pixmapChange();
67 if (m_color.alpha() > 0 && m_color != m_defaultColor) {
68 QQuickImageBasePrivate *d = static_cast<QQuickImageBasePrivate *>(QQuickItemPrivate::get(this));
69 QImage image = d->currentPix->image();
70 if (!image.isNull()) {
71 QPainter painter(&image);
72 painter.setCompositionMode(QPainter::CompositionMode_SourceIn);
73 painter.fillRect(image.rect(), m_color);
74 d->currentPix->setImage(image);
75 }
76 }
77}
78
79QT_END_NAMESPACE
80
81#include "moc_qquickcolorimage_p.cpp"
Combined button and popup list for selecting options.