105QColor QQuickAbstractColorPicker::color()
const
107 Q_D(
const QQuickAbstractColorPicker);
108 return d->m_hsl ? QColor::fromHslF(d->m_hsva.h, d->m_hsva.s, d->m_hsva.l, d->m_hsva.a)
109 : QColor::fromHsvF(d->m_hsva.h, d->m_hsva.s, d->m_hsva.v, d->m_hsva.a);
112void QQuickAbstractColorPicker::setColor(
const QColor &c)
114 Q_D(QQuickAbstractColorPicker);
127 if (d->m_hsl && c.spec() == QColor::Spec::Hsv) {
128 const auto sl = getSaturationAndLightness(c.hsvSaturationF(), c.valueF());
129 d->m_hsva.h = qBound(.0, c.hsvHueF(), 1.0);
130 d->m_hsva.s = qBound(.0, sl.first, 1.0);
131 d->m_hsva.l = qBound(.0, sl.second, 1.0);
132 }
else if (!d->m_hsl && c.spec() == QColor::Spec::Hsl) {
133 const auto sv = getSaturationAndValue(c.hslSaturationF(), c.lightnessF());
134 d->m_hsva.h = qBound(.0, c.hslHueF(), 1.0);
135 d->m_hsva.s = qBound(.0, sv.first, 1.0);
136 d->m_hsva.v = qBound(.0, sv.second, 1.0);
138 d->m_hsva.h = qBound(.0, d->m_hsl ? c.hslHueF() : c.hsvHueF(), 1.0);
139 d->m_hsva.s = qBound(.0, d->m_hsl ? c.hslSaturationF() : c.hsvSaturationF(), 1.0);
140 d->m_hsva.v = qBound(.0, d->m_hsl ? c.lightnessF() : c.valueF(), 1.0);
143 d->m_hsva.a = qBound(.0, c.alphaF(), 1.0);
145 emit colorChanged(color());
154void QQuickAbstractColorPicker::setAlpha(qreal alpha)
156 Q_D(QQuickAbstractColorPicker);
158 if (!qt_is_finite(alpha))
161 alpha = qBound(.0, alpha, 1.0);
163 if (qFuzzyCompare(d->m_hsva.a, alpha))
168 emit colorChanged(color());
194void QQuickAbstractColorPicker::setSaturation(qreal saturation)
196 Q_D(QQuickAbstractColorPicker);
197 if (!qt_is_finite(saturation))
200 d->m_hsva.s = saturation;
202 emit colorChanged(color());
209void QQuickAbstractColorPicker::setValue(qreal value)
211 Q_D(QQuickAbstractColorPicker);
212 if (!qt_is_finite(value))
215 const auto sv = d->m_hsl ? getSaturationAndValue(d->m_hsva.s, d->m_hsva.l)
216 : std::pair<qreal, qreal>(d->m_hsva.s, value);
217 d->m_hsva.s = sv.first;
218 d->m_hsva.v = sv.second;
220 emit colorChanged(color());
228void QQuickAbstractColorPicker::setLightness(qreal lightness)
230 Q_D(QQuickAbstractColorPicker);
231 if (!qt_is_finite(lightness))
234 const auto sl = !d->m_hsl ? getSaturationAndLightness(d->m_hsva.s, d->m_hsva.v)
235 : std::pair<qreal, qreal>(d->m_hsva.s, lightness);
236 d->m_hsva.s = sl.first;
237 d->m_hsva.l = sl.second;
239 emit colorChanged(color());
276void QQuickAbstractColorPicker::setHandle(QQuickItem *handle)
278 Q_D(QQuickAbstractColorPicker);
279 if (handle == d->m_handle)
282 if (!d->m_handle.isExecuting())
285 const qreal oldImplicitHandleWidth = implicitHandleWidth();
286 const qreal oldImplicitHandleHeight = implicitHandleHeight();
288 d->removeImplicitSizeListener(d->m_handle);
289 QQuickControlPrivate::hideOldItem(d->m_handle);
290 d->m_handle = handle;
293 if (!handle->parentItem())
294 handle->setParentItem(
this);
295 d->addImplicitSizeListener(handle);
298 if (!qFuzzyCompare(oldImplicitHandleWidth, implicitHandleWidth()))
299 emit implicitHandleWidthChanged();
300 if (!qFuzzyCompare(oldImplicitHandleHeight, implicitHandleHeight()))
301 emit implicitHandleHeightChanged();
302 if (!d->m_handle.isExecuting())
303 emit handleChanged();