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
qquicksaturationlightnesspicker.cpp
Go to the documentation of this file.
1// Copyright (C) 2022 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
7
8#include <QtQuickTemplates2/private/qquickcontrol_p_p.h>
9#include <QtQuickTemplates2/private/qquickdeferredexecute_p_p.h>
10
12
14{
15 Q_DECLARE_PUBLIC(QQuickSaturationLightnessPicker)
16
17public:
19};
20QQuickSaturationLightnessPickerPrivate::QQuickSaturationLightnessPickerPrivate()
21{
22 m_hsl = true;
23}
24
25QQuickSaturationLightnessPicker::QQuickSaturationLightnessPicker(QQuickItem *parent)
26 : QQuickAbstractColorPicker(*(new QQuickSaturationLightnessPickerPrivate), parent)
27{
28}
29
30QColor QQuickSaturationLightnessPicker::colorAt(const QPointF &pos)
31{
32 const qreal w = width();
33 const qreal h = height();
34 if (w <= 0 || h <= 0)
35 return color();
36 const qreal x = qBound(.0, pos.x(), w);
37 const qreal y = qBound(.0, pos.y(), h);
38 const qreal saturation = 1.0 - (y / h);
39 const qreal lightness = x / w;
40
41 return QColor::fromHslF(hue(), saturation, lightness);
42}
43
44QT_END_NAMESPACE