| 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 | |
| 4 | #include "qquicksaturationlightnesspicker_p.h" |
| 5 | #include "qquickabstractcolorpicker_p_p.h" |
| 6 | |
| 7 | #include <QtQuickTemplates2/private/qquickcontrol_p_p.h> |
| 8 | #include <QtQuickTemplates2/private/qquickdeferredexecute_p_p.h> |
| 9 | |
| 10 | QT_BEGIN_NAMESPACE |
| 11 | |
| 12 | class QQuickSaturationLightnessPickerPrivate : public QQuickAbstractColorPickerPrivate |
| 13 | { |
| 14 | Q_DECLARE_PUBLIC(QQuickSaturationLightnessPicker) |
| 15 | |
| 16 | public: |
| 17 | explicit QQuickSaturationLightnessPickerPrivate(); |
| 18 | }; |
| 19 | QQuickSaturationLightnessPickerPrivate::QQuickSaturationLightnessPickerPrivate() |
| 20 | { |
| 21 | m_hsl = true; |
| 22 | } |
| 23 | |
| 24 | QQuickSaturationLightnessPicker::QQuickSaturationLightnessPicker(QQuickItem *parent) |
| 25 | : QQuickAbstractColorPicker(*(new QQuickSaturationLightnessPickerPrivate), parent) |
| 26 | { |
| 27 | } |
| 28 | |
| 29 | QColor QQuickSaturationLightnessPicker::colorAt(const QPointF &pos) |
| 30 | { |
| 31 | const qreal w = width(); |
| 32 | const qreal h = height(); |
| 33 | if (w <= 0 || h <= 0) |
| 34 | return color(); |
| 35 | const qreal x = qBound(min: .0, val: pos.x(), max: w); |
| 36 | const qreal y = qBound(min: .0, val: pos.y(), max: h); |
| 37 | const qreal saturation = 1.0 - (y / h); |
| 38 | const qreal lightness = x / w; |
| 39 | |
| 40 | return QColor::fromHslF(h: hue(), s: saturation, l: lightness); |
| 41 | } |
| 42 | |
| 43 | QT_END_NAMESPACE |
| 44 |
