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