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
qquickcolor.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
8
9QQuickColor::QQuickColor(QObject *parent) :
10 QObject(parent)
11{
12}
13
14QColor QQuickColor::transparent(const QColor &color, qreal opacity) const
15{
16 const auto rgbColor = color.toRgb();
17 return QColor(rgbColor.red(), rgbColor.green(), rgbColor.blue(),
18 int(qreal(255) * qBound(qreal(0), opacity, qreal(1))));
19}
20
21QColor QQuickColor::blend(const QColor &a, const QColor &b, qreal factor) const
22{
23 if (factor <= 0.0)
24 return a;
25 if (factor >= 1.0)
26 return b;
27
28 const auto rgbA = a.toRgb();
29 const auto rgbB = b.toRgb();
30 QColor color;
31 color.setRedF(rgbA.redF() * (1.0 - factor) + rgbB.redF() * factor);
32 color.setGreenF(rgbA.greenF() * (1.0 - factor) + rgbB.greenF() * factor);
33 color.setBlueF(rgbA.blueF() * (1.0 - factor) + rgbB.blueF() * factor);
34 return color;
35}
36
37QT_END_NAMESPACE
38
39#include "moc_qquickcolor_p.cpp"