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 "qquickcolordialogimpl_p.h"
5#include "qquickcolordialogimpl_p_p.h"
6
7#include "qquickcolordialogutils_p.h"
8
9#include <QtQuickTemplates2/private/qquickslider_p.h>
10
11#include <qpa/qplatformintegration.h>
12#include <qpa/qplatformservices.h>
13#include <private/qguiapplication_p.h>
14
15QT_BEGIN_NAMESPACE
16
17QColor grabScreenColor(const QPoint &p)
18{
19 QScreen *screen = QGuiApplication::screenAt(point: p);
20 if (!screen)
21 screen = QGuiApplication::primaryScreen();
22 const QRect screenRect = screen->geometry();
23 const QPixmap pixmap =
24 screen->grabWindow(window: 0, x: p.x() - screenRect.x(), y: p.y() - screenRect.y(), w: 1, h: 1);
25 const QImage i = pixmap.toImage();
26 return i.pixel(x: 0, y: 0);
27}
28
29bool QQuickEyeDropperEventFilter::eventFilter(QObject *obj, QEvent *event)
30{
31 switch (event->type()) {
32 case QEvent::MouseMove: {
33 m_lastPosition = static_cast<QMouseEvent *>(event)->globalPosition().toPoint();
34 m_update(m_lastPosition);
35 return true;
36 }
37 case QEvent::MouseButtonRelease: {
38 m_lastPosition = static_cast<QMouseEvent *>(event)->globalPosition().toPoint();
39 m_leave(m_lastPosition, QQuickEyeDropperEventFilter::LeaveReason::Default);
40 return true;
41 }
42 case QEvent::MouseButtonPress:
43 return true;
44 case QEvent::KeyPress: {
45 auto keyEvent = static_cast<QKeyEvent *>(event);
46#if QT_CONFIG(shortcut)
47 if (keyEvent->matches(key: QKeySequence::Cancel))
48 m_leave(m_lastPosition, QQuickEyeDropperEventFilter::LeaveReason::Cancel);
49 else
50#endif
51 if (keyEvent->key() == Qt::Key_Return || keyEvent->key() == Qt::Key_Enter) {
52 m_leave(m_lastPosition, QQuickEyeDropperEventFilter::LeaveReason::Default);
53 } else if (keyEvent->key() == Qt::Key_Escape) {
54 m_leave(m_lastPosition, QQuickEyeDropperEventFilter::LeaveReason::Cancel);
55 }
56 keyEvent->accept();
57 return true;
58 }
59 default:
60 return QObject::eventFilter(watched: obj, event);
61 }
62}
63
64QQuickColorDialogImplPrivate::QQuickColorDialogImplPrivate() = default;
65
66QQuickColorDialogImplPrivate::~QQuickColorDialogImplPrivate()
67{
68 if (m_eyeDropperMode)
69 eyeDropperLeave(pos: QCursor::pos(), actionOnLeave: QQuickEyeDropperEventFilter::LeaveReason::Default);
70}
71
72void QQuickColorDialogImplPrivate::handleClick(QQuickAbstractButton *button)
73{
74 Q_Q(QQuickColorDialogImpl);
75 const auto c = q->color();
76 if (buttonRole(button) == QPlatformDialogHelper::AcceptRole && c.isValid()) {
77 q->setColor(c);
78 q->accept();
79 }
80 QQuickDialogPrivate::handleClick(button);
81}
82
83QQuickColorDialogImplAttached *QQuickColorDialogImplPrivate::attachedOrWarn()
84{
85 Q_Q(QQuickColorDialogImpl);
86 QQuickColorDialogImplAttached *attached = static_cast<QQuickColorDialogImplAttached *>(
87 qmlAttachedPropertiesObject<QQuickColorDialogImpl>(obj: q, create: false));
88 if (!attached)
89 qmlWarning(me: q) << "Expected ColorDialogImpl attached object to be present on" << this;
90 return attached;
91}
92
93void QQuickColorDialogImplPrivate::eyeDropperEnter()
94{
95 Q_Q(QQuickColorDialogImpl);
96 if (m_eyeDropperMode)
97 return;
98
99 if (m_eyeDropperWindow.isNull()) {
100 if (window.isNull()) {
101 qWarning() << "No window found, cannot enter eyeDropperMode.";
102 return;
103 }
104
105 m_eyeDropperWindow = window;
106 }
107
108 if (auto *platformServices = QGuiApplicationPrivate::platformIntegration()->services();
109 platformServices && platformServices->hasCapability(capability: QPlatformServices::Capability::ColorPicking)) {
110 if (auto *colorPickerService = platformServices->colorPicker(parent: m_eyeDropperWindow)) {
111 q->connect(sender: colorPickerService, signal: &QPlatformServiceColorPicker::colorPicked, context: q,
112 slot: [q, colorPickerService](const QColor &color) {
113 colorPickerService->deleteLater();
114 q->setColor(color);
115 });
116 colorPickerService->pickColor();
117 return;
118 }
119 }
120
121 m_eyeDropperPreviousColor = q->color();
122
123 if (!bool(eyeDropperEventFilter))
124 eyeDropperEventFilter.reset(p: new QQuickEyeDropperEventFilter(
125 [this](QPoint pos, QQuickEyeDropperEventFilter::LeaveReason c) {
126 eyeDropperLeave(pos, actionOnLeave: c);
127 },
128 [this](QPoint pos) { eyeDropperPointerMoved(pos); }));
129
130 if (m_eyeDropperWindow->setMouseGrabEnabled(true)) {
131#if QT_CONFIG(cursor)
132 QGuiApplication::setOverrideCursor(Qt::CrossCursor);
133#endif
134 m_eyeDropperWindow->installEventFilter(filterObj: eyeDropperEventFilter.get());
135 m_eyeDropperMode = true;
136 }
137}
138
139void QQuickColorDialogImplPrivate::eyeDropperLeave(
140 const QPoint &pos, QQuickEyeDropperEventFilter::LeaveReason actionOnLeave)
141{
142 Q_Q(QQuickColorDialogImpl);
143
144 if (!m_eyeDropperMode)
145 return;
146
147 if (!m_eyeDropperWindow) {
148 qWarning() << "Window not set, cannot leave eyeDropperMode.";
149 return;
150 }
151
152 const QColor colorToUse = actionOnLeave == QQuickEyeDropperEventFilter::LeaveReason::Cancel
153 ? m_eyeDropperPreviousColor
154 : grabScreenColor(p: pos);
155 q->setColor(colorToUse);
156
157 m_eyeDropperWindow->removeEventFilter(obj: eyeDropperEventFilter.get());
158 m_eyeDropperWindow->setMouseGrabEnabled(false);
159#if QT_CONFIG(cursor)
160 QGuiApplication::restoreOverrideCursor();
161#endif
162
163 m_eyeDropperMode = false;
164 m_eyeDropperWindow.clear();
165}
166
167void QQuickColorDialogImplPrivate::eyeDropperPointerMoved(const QPoint &pos)
168{
169 Q_Q(QQuickColorDialogImpl);
170 q->setColor(grabScreenColor(p: pos));
171}
172
173void QQuickColorDialogImplPrivate::alphaSliderMoved()
174{
175 Q_Q(QQuickColorDialogImpl);
176 if (auto attached = attachedOrWarn())
177 q->setAlpha(attached->alphaSlider()->value());
178}
179
180QQuickColorDialogImpl::QQuickColorDialogImpl(QObject *parent)
181 : QQuickDialog(*(new QQuickColorDialogImplPrivate), parent)
182{
183}
184
185QQuickColorDialogImplAttached *QQuickColorDialogImpl::qmlAttachedProperties(QObject *object)
186{
187 return new QQuickColorDialogImplAttached(object);
188}
189
190QColor QQuickColorDialogImpl::color() const
191{
192 Q_D(const QQuickColorDialogImpl);
193 return d->m_hsl ? QColor::fromHslF(h: d->m_hsva.h, s: d->m_hsva.s, l: d->m_hsva.l, a: d->m_hsva.a)
194 : QColor::fromHsvF(h: d->m_hsva.h, s: d->m_hsva.s, v: d->m_hsva.v, a: d->m_hsva.a);
195}
196
197void QQuickColorDialogImpl::setColor(const QColor &c)
198{
199 Q_D(QQuickColorDialogImpl);
200 if (const QColor old = color(); old.spec() == c.spec() && old == c)
201 return;
202
203 // If we get a QColor from an Hsv or Hsl color system,
204 // we want to get the raw values without the risk of QColor converting them,
205 // and possible deleting relevant information for achromatic cases.
206 if (c.spec() == QColor::Spec::Hsv) {
207 d->m_hsva.h = qBound(min: .0, val: c.hsvHueF(), max: 1.0);
208 if (d->m_hsl) {
209 const auto sl = getSaturationAndLightness(saturation: c.hsvSaturationF(), value: c.valueF());
210 d->m_hsva.s = qBound(min: .0, val: sl.first, max: 1.0);
211 d->m_hsva.l = qBound(min: .0, val: sl.second, max: 1.0);
212 } else {
213 d->m_hsva.s = qBound(min: .0, val: c.hsvSaturationF(), max: 1.0);
214 d->m_hsva.v = qBound(min: .0, val: c.valueF(), max: 1.0);
215 }
216 } else if (c.spec() == QColor::Spec::Hsl) {
217 d->m_hsva.h = qBound(min: .0, val: c.hslHueF(), max: 1.0);
218 if (d->m_hsl) {
219 d->m_hsva.s = qBound(min: .0, val: c.hslSaturationF(), max: 1.0);
220 d->m_hsva.l = qBound(min: .0, val: c.lightnessF(), max: 1.0);
221 } else {
222 const auto sv = getSaturationAndValue(saturation: c.hslSaturationF(), lightness: c.lightnessF());
223 d->m_hsva.s = qBound(min: .0, val: sv.first, max: 1.0);
224 d->m_hsva.v = qBound(min: .0, val: sv.second, max: 1.0);
225 }
226 } else {
227 d->m_hsva.h = qBound(min: .0, val: d->m_hsl ? c.hslHueF() : c.hsvHueF(), max: 1.0);
228 d->m_hsva.s = qBound(min: .0, val: d->m_hsl ? c.hslSaturationF() : c.hsvSaturationF(), max: 1.0);
229 d->m_hsva.v = qBound(min: .0, val: d->m_hsl ? c.lightnessF() : c.valueF(), max: 1.0);
230 }
231
232 d->m_hsva.a = c.alphaF();
233
234 emit colorChanged(color: color());
235}
236
237int QQuickColorDialogImpl::red() const
238{
239 return color().red();
240}
241
242void QQuickColorDialogImpl::setRed(int red)
243{
244 Q_D(QQuickColorDialogImpl);
245
246 auto c = color();
247
248 if (c.red() == red)
249 return;
250
251 c.setRed(red);
252
253 d->m_hsva.h = d->m_hsl ? c.hslHueF() : c.hsvHueF();
254 d->m_hsva.s = d->m_hsl ? c.hslSaturationF() : c.hsvSaturationF();
255 d->m_hsva.v = d->m_hsl ? c.lightnessF() : c.valueF();
256 d->m_hsva.a = c.alphaF();
257
258 emit colorChanged(color: c);
259}
260
261int QQuickColorDialogImpl::green() const
262{
263 return color().green();
264}
265
266void QQuickColorDialogImpl::setGreen(int green)
267{
268 Q_D(QQuickColorDialogImpl);
269
270 auto c = color();
271
272 if (c.green() == green)
273 return;
274
275 c.setGreen(green);
276
277 d->m_hsva.h = d->m_hsl ? c.hslHueF() : c.hsvHueF();
278 d->m_hsva.s = d->m_hsl ? c.hslSaturationF() : c.hsvSaturationF();
279 d->m_hsva.v = d->m_hsl ? c.lightnessF() : c.valueF();
280 d->m_hsva.a = c.alphaF();
281
282 emit colorChanged(color: c);
283}
284
285int QQuickColorDialogImpl::blue() const
286{
287 return color().blue();
288}
289
290void QQuickColorDialogImpl::setBlue(int blue)
291{
292 Q_D(QQuickColorDialogImpl);
293
294 auto c = color();
295
296 if (c.blue() == blue)
297 return;
298
299 c.setBlue(blue);
300
301 d->m_hsva.h = d->m_hsl ? c.hslHueF() : c.hsvHueF();
302 d->m_hsva.s = d->m_hsl ? c.hslSaturationF() : c.hsvSaturationF();
303 d->m_hsva.v = d->m_hsl ? c.lightnessF() : c.valueF();
304 d->m_hsva.a = c.alphaF();
305
306 emit colorChanged(color: c);
307}
308
309qreal QQuickColorDialogImpl::alpha() const
310{
311 Q_D(const QQuickColorDialogImpl);
312 return d->m_hsva.a;
313}
314
315void QQuickColorDialogImpl::setAlpha(qreal alpha)
316{
317 Q_D(QQuickColorDialogImpl);
318
319 if (!qt_is_finite(d: alpha))
320 return;
321
322 alpha = qBound(min: .0, val: alpha, max: 1.0);
323
324 if (qFuzzyCompare(p1: d->m_hsva.a, p2: alpha))
325 return;
326
327 d->m_hsva.a = alpha;
328
329 emit colorChanged(color: color());
330}
331
332qreal QQuickColorDialogImpl::hue() const
333{
334 Q_D(const QQuickColorDialogImpl);
335 return d->m_hsva.h;
336}
337
338void QQuickColorDialogImpl::setHue(qreal hue)
339{
340 Q_D(QQuickColorDialogImpl);
341
342 if (!qt_is_finite(d: hue))
343 return;
344
345 d->m_hsva.h = hue;
346
347 emit colorChanged(color: color());
348}
349
350qreal QQuickColorDialogImpl::saturation() const
351{
352 Q_D(const QQuickColorDialogImpl);
353 return d->m_hsva.s;
354}
355
356void QQuickColorDialogImpl::setSaturation(qreal saturation)
357{
358 Q_D(QQuickColorDialogImpl);
359 if (!qt_is_finite(d: saturation))
360 return;
361
362 d->m_hsva.s = saturation;
363
364 emit colorChanged(color: color());
365}
366
367qreal QQuickColorDialogImpl::value() const
368{
369 Q_D(const QQuickColorDialogImpl);
370 return d->m_hsl ? getSaturationAndValue(saturation: d->m_hsva.s, lightness: d->m_hsva.l).second : d->m_hsva.v;
371}
372
373void QQuickColorDialogImpl::setValue(qreal value)
374{
375 Q_D(QQuickColorDialogImpl);
376 if (!qt_is_finite(d: value))
377 return;
378
379 d->m_hsva.v = value;
380
381 if (d->m_hsl)
382 d->m_hsva.s = getSaturationAndValue(saturation: d->m_hsva.s, lightness: d->m_hsva.l).first;
383
384 d->m_hsl = false;
385 emit colorChanged(color: color());
386}
387
388qreal QQuickColorDialogImpl::lightness() const
389{
390 Q_D(const QQuickColorDialogImpl);
391 return d->m_hsl ? d->m_hsva.l : getSaturationAndLightness(saturation: d->m_hsva.s, value: d->m_hsva.v).second;
392}
393
394void QQuickColorDialogImpl::setLightness(qreal lightness)
395{
396 Q_D(QQuickColorDialogImpl);
397 if (!qt_is_finite(d: lightness))
398 return;
399
400 d->m_hsva.l = lightness;
401
402 if (!d->m_hsl)
403 d->m_hsva.s = getSaturationAndLightness(saturation: d->m_hsva.s, value: d->m_hsva.v).first;
404
405 d->m_hsl = true;
406 emit colorChanged(color: color());
407}
408
409bool QQuickColorDialogImpl::isHsl() const
410{
411 Q_D(const QQuickColorDialogImpl);
412 return d->m_hsl;
413}
414
415void QQuickColorDialogImpl::setHsl(bool hsl)
416{
417 Q_D(QQuickColorDialogImpl);
418
419 if (d->m_hsl == hsl)
420 return;
421
422 d->m_hsl = hsl;
423 emit specChanged();
424}
425
426QSharedPointer<QColorDialogOptions> QQuickColorDialogImpl::options() const
427{
428 Q_D(const QQuickColorDialogImpl);
429 return d->options;
430}
431
432void QQuickColorDialogImpl::setOptions(const QSharedPointer<QColorDialogOptions> &options)
433{
434 Q_D(QQuickColorDialogImpl);
435 d->options = options;
436
437 QQuickColorDialogImplAttached *attached = d->attachedOrWarn();
438
439 if (attached) {
440 const auto *integration = QGuiApplicationPrivate::platformIntegration();
441 const bool canSupportEyeDropper =
442 integration->hasCapability(cap: QPlatformIntegration::ScreenWindowGrabbing)
443 || integration->services()->hasCapability(capability: QPlatformServices::Capability::ColorPicking);
444 const bool offscreen = qgetenv(varName: "QT_QPA_PLATFORM").compare(a: QLatin1String("offscreen"), cs: Qt::CaseInsensitive) == 0;
445 const bool noEyeDropperButton = (d->options && d->options->options() & QColorDialogOptions::NoEyeDropperButton);
446 attached->eyeDropperButton()->setVisible(!noEyeDropperButton && canSupportEyeDropper && !offscreen);
447
448 if (d->options) {
449 attached->buttonBox()->setVisible(
450 !(d->options->options() & QColorDialogOptions::NoButtons));
451
452 const bool showAlpha = d->options->options() & QColorDialogOptions::ShowAlphaChannel;
453 attached->alphaSlider()->setVisible(showAlpha);
454 attached->colorInputs()->setShowAlpha(showAlpha);
455 }
456 }
457}
458
459void QQuickColorDialogImpl::invokeEyeDropper()
460{
461 Q_D(QQuickColorDialogImpl);
462 d->eyeDropperEnter();
463}
464
465QQuickColorDialogImplAttached::QQuickColorDialogImplAttached(QObject *parent)
466 : QObject(*(new QQuickColorDialogImplAttachedPrivate), parent)
467{
468 if (!qobject_cast<QQuickColorDialogImpl *>(object: parent)) {
469 qmlWarning(me: this) << "ColorDialogImpl attached properties should only be "
470 << "accessed through the root ColorDialogImpl instance";
471 }
472}
473
474QQuickDialogButtonBox *QQuickColorDialogImplAttached::buttonBox() const
475{
476 Q_D(const QQuickColorDialogImplAttached);
477 return d->buttonBox;
478}
479
480void QQuickColorDialogImplAttached::setButtonBox(QQuickDialogButtonBox *buttonBox)
481{
482 Q_D(QQuickColorDialogImplAttached);
483 if (d->buttonBox == buttonBox)
484 return;
485
486 if (d->buttonBox) {
487 QQuickColorDialogImpl *colorDialogImpl = qobject_cast<QQuickColorDialogImpl *>(object: parent());
488 if (colorDialogImpl) {
489 auto dialogPrivate = QQuickDialogPrivate::get(dialog: colorDialogImpl);
490 QObjectPrivate::disconnect(sender: d->buttonBox, signal: &QQuickDialogButtonBox::accepted,
491 receiverPrivate: dialogPrivate, slot: &QQuickDialogPrivate::handleAccept);
492 QObjectPrivate::disconnect(sender: d->buttonBox, signal: &QQuickDialogButtonBox::rejected,
493 receiverPrivate: dialogPrivate, slot: &QQuickDialogPrivate::handleReject);
494 QObjectPrivate::disconnect(sender: d->buttonBox, signal: &QQuickDialogButtonBox::clicked,
495 receiverPrivate: dialogPrivate, slot: &QQuickDialogPrivate::handleClick);
496 }
497 }
498
499 d->buttonBox = buttonBox;
500
501 if (d->buttonBox) {
502 QQuickColorDialogImpl *colorDialogImpl = qobject_cast<QQuickColorDialogImpl *>(object: parent());
503 if (colorDialogImpl) {
504 auto dialogPrivate = QQuickDialogPrivate::get(dialog: colorDialogImpl);
505 QObjectPrivate::connect(sender: d->buttonBox, signal: &QQuickDialogButtonBox::accepted,
506 receiverPrivate: dialogPrivate, slot: &QQuickDialogPrivate::handleAccept);
507 QObjectPrivate::connect(sender: d->buttonBox, signal: &QQuickDialogButtonBox::rejected,
508 receiverPrivate: dialogPrivate, slot: &QQuickDialogPrivate::handleReject);
509 QObjectPrivate::connect(sender: d->buttonBox, signal: &QQuickDialogButtonBox::clicked,
510 receiverPrivate: dialogPrivate, slot: &QQuickDialogPrivate::handleClick);
511 }
512 }
513
514 emit buttonBoxChanged();
515}
516
517QQuickAbstractButton *QQuickColorDialogImplAttached::eyeDropperButton() const
518{
519 Q_D(const QQuickColorDialogImplAttached);
520 return d->eyeDropperButton;
521}
522
523void QQuickColorDialogImplAttached::setEyeDropperButton(QQuickAbstractButton *eyeDropperButton)
524{
525 Q_D(QQuickColorDialogImplAttached);
526 Q_ASSERT(!d->eyeDropperButton);
527 if (d->eyeDropperButton == eyeDropperButton)
528 return;
529
530 d->eyeDropperButton = eyeDropperButton;
531 if (auto dialog = qobject_cast<QQuickColorDialogImpl *>(object: parent()))
532 connect(sender: d->eyeDropperButton, signal: &QQuickAbstractButton::clicked, context: dialog, slot: &QQuickColorDialogImpl::invokeEyeDropper);
533 emit eyeDropperButtonChanged();
534}
535
536QQuickAbstractColorPicker *QQuickColorDialogImplAttached::colorPicker() const
537{
538 Q_D(const QQuickColorDialogImplAttached);
539 return d->colorPicker;
540}
541void QQuickColorDialogImplAttached::setColorPicker(QQuickAbstractColorPicker *colorPicker)
542{
543 Q_D(QQuickColorDialogImplAttached);
544 if (d->colorPicker == colorPicker)
545 return;
546
547 if (d->colorPicker) {
548 QQuickColorDialogImpl *colorDialogImpl = qobject_cast<QQuickColorDialogImpl *>(object: parent());
549 if (colorDialogImpl) {
550 QObject::disconnect(sender: d->colorPicker, signal: &QQuickAbstractColorPicker::colorPicked,
551 receiver: colorDialogImpl, slot: &QQuickColorDialogImpl::setColor);
552 }
553 }
554
555 d->colorPicker = colorPicker;
556
557 if (d->colorPicker) {
558 QQuickColorDialogImpl *colorDialogImpl = qobject_cast<QQuickColorDialogImpl *>(object: parent());
559 if (colorDialogImpl) {
560 QObject::connect(sender: d->colorPicker, signal: &QQuickAbstractColorPicker::colorPicked,
561 context: colorDialogImpl, slot: &QQuickColorDialogImpl::setColor);
562 }
563 }
564
565 emit colorPickerChanged();
566}
567
568QQuickSlider *QQuickColorDialogImplAttached::alphaSlider() const
569{
570 Q_D(const QQuickColorDialogImplAttached);
571 return d->alphaSlider;
572}
573
574void QQuickColorDialogImplAttached::setAlphaSlider(QQuickSlider *alphaSlider)
575{
576 Q_D(QQuickColorDialogImplAttached);
577 if (d->alphaSlider == alphaSlider)
578 return;
579
580 if (d->alphaSlider) {
581 QQuickColorDialogImpl *colorDialogImpl = qobject_cast<QQuickColorDialogImpl *>(object: parent());
582 if (colorDialogImpl) {
583 auto dialogPrivate = QQuickColorDialogImplPrivate::get(dialog: colorDialogImpl);
584 QObjectPrivate::disconnect(sender: d->alphaSlider, signal: &QQuickSlider::moved,
585 receiverPrivate: dialogPrivate, slot: &QQuickColorDialogImplPrivate::alphaSliderMoved);
586 }
587 }
588
589 d->alphaSlider = alphaSlider;
590
591 if (d->alphaSlider) {
592 QQuickColorDialogImpl *colorDialogImpl = qobject_cast<QQuickColorDialogImpl *>(object: parent());
593 if (colorDialogImpl) {
594 auto dialogPrivate = QQuickColorDialogImplPrivate::get(dialog: colorDialogImpl);
595 QObjectPrivate::connect(sender: d->alphaSlider, signal: &QQuickSlider::moved,
596 receiverPrivate: dialogPrivate, slot: &QQuickColorDialogImplPrivate::alphaSliderMoved);
597 }
598 }
599
600 emit alphaSliderChanged();
601}
602
603QQuickColorInputs *QQuickColorDialogImplAttached::colorInputs() const
604{
605 Q_D(const QQuickColorDialogImplAttached);
606 return d->colorInputs;
607}
608
609void QQuickColorDialogImplAttached::setColorInputs(QQuickColorInputs *colorInputs)
610{
611 Q_D(QQuickColorDialogImplAttached);
612
613 if (d->colorInputs == colorInputs)
614 return;
615
616 if (d->colorInputs) {
617 QQuickColorDialogImpl *colorDialogImpl = qobject_cast<QQuickColorDialogImpl *>(object: parent());
618 if (colorDialogImpl)
619 QObject::disconnect(sender: d->colorInputs, signal: &QQuickColorInputs::colorModified,
620 receiver: colorDialogImpl, slot: &QQuickColorDialogImpl::setColor);
621 }
622
623 d->colorInputs = colorInputs;
624
625 if (d->colorInputs) {
626 QQuickColorDialogImpl *colorDialogImpl = qobject_cast<QQuickColorDialogImpl *>(object: parent());
627 if (colorDialogImpl)
628 QObject::connect(sender: d->colorInputs, signal: &QQuickColorInputs::colorModified,
629 context: colorDialogImpl, slot: &QQuickColorDialogImpl::setColor);
630 }
631
632 emit colorInputsChanged();
633}
634
635QT_END_NAMESPACE
636

source code of qtdeclarative/src/quickdialogs/quickdialogsquickimpl/qquickcolordialogimpl.cpp