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

source code of qtdeclarative/src/quickcontrolsimpl/qquickcolor.cpp