| 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 | #ifndef QQUICKCOLORDIALOGIMPL_P_P_H |
| 5 | #define QQUICKCOLORDIALOGIMPL_P_P_H |
| 6 | |
| 7 | // |
| 8 | // W A R N I N G |
| 9 | // ------------- |
| 10 | // |
| 11 | // This file is not part of the Qt API. It exists purely as an |
| 12 | // implementation detail. This header file may change from version to |
| 13 | // version without notice, or even be removed. |
| 14 | // |
| 15 | // We mean it. |
| 16 | // |
| 17 | |
| 18 | #include "qquickcolordialogimpl_p.h" |
| 19 | #include "qquickabstractcolorpicker_p.h" |
| 20 | #include "qquickcolorinputs_p.h" |
| 21 | |
| 22 | #include <QtQuickTemplates2/private/qquickdialog_p_p.h> |
| 23 | #include <QtQuickTemplates2/private/qquickdialogbuttonbox_p.h> |
| 24 | #include <QtQuickTemplates2/private/qquickabstractbutton_p.h> |
| 25 | #include <QtQuickTemplates2/private/qquickslider_p.h> |
| 26 | |
| 27 | #include <QtCore/qpointer.h> |
| 28 | |
| 29 | QT_BEGIN_NAMESPACE |
| 30 | |
| 31 | class QQuickEyeDropperEventFilter : public QObject |
| 32 | { |
| 33 | public: |
| 34 | enum class LeaveReason { Default, Cancel }; |
| 35 | explicit QQuickEyeDropperEventFilter(std::function<void(QPoint, LeaveReason)> callOnLeave, |
| 36 | std::function<void(QPoint)> callOnUpdate) |
| 37 | : m_leave(callOnLeave), m_update(callOnUpdate) |
| 38 | { |
| 39 | } |
| 40 | |
| 41 | protected: |
| 42 | bool eventFilter(QObject *obj, QEvent *event) override; |
| 43 | |
| 44 | private: |
| 45 | std::function<void(QPoint, LeaveReason)> m_leave; |
| 46 | std::function<void(QPoint)> m_update; |
| 47 | QPoint m_lastPosition; |
| 48 | }; |
| 49 | |
| 50 | class QQuickColorDialogImplPrivate : public QQuickDialogPrivate |
| 51 | { |
| 52 | public: |
| 53 | Q_DECLARE_PUBLIC(QQuickColorDialogImpl); |
| 54 | |
| 55 | public: |
| 56 | explicit QQuickColorDialogImplPrivate(); |
| 57 | ~QQuickColorDialogImplPrivate(); |
| 58 | |
| 59 | static QQuickColorDialogImplPrivate *get(QQuickColorDialogImpl *dialog) |
| 60 | { |
| 61 | return dialog->d_func(); |
| 62 | } |
| 63 | |
| 64 | QQuickColorDialogImplAttached *attachedOrWarn(); |
| 65 | |
| 66 | void handleClick(QQuickAbstractButton *button) override; |
| 67 | |
| 68 | void eyeDropperEnter(); |
| 69 | void eyeDropperLeave(const QPoint &pos, QQuickEyeDropperEventFilter::LeaveReason actionOnLeave); |
| 70 | void eyeDropperPointerMoved(const QPoint &pos); |
| 71 | |
| 72 | void alphaSliderMoved(); |
| 73 | |
| 74 | QSharedPointer<QColorDialogOptions> options; |
| 75 | HSVA m_hsva; |
| 76 | std::unique_ptr<QQuickEyeDropperEventFilter> eyeDropperEventFilter; |
| 77 | QPointer<QQuickWindow> m_eyeDropperWindow; |
| 78 | QColor m_eyeDropperPreviousColor; |
| 79 | bool m_eyeDropperMode = false; |
| 80 | bool m_showAlpha = false; |
| 81 | bool m_hsl = false; |
| 82 | }; |
| 83 | |
| 84 | class QQuickColorDialogImplAttachedPrivate : public QObjectPrivate |
| 85 | { |
| 86 | public: |
| 87 | QPointer<QQuickDialogButtonBox> buttonBox; |
| 88 | QPointer<QQuickAbstractButton> eyeDropperButton; |
| 89 | QPointer<QQuickColorInputs> colorInputs; |
| 90 | QPointer<QQuickAbstractColorPicker> colorPicker; |
| 91 | QPointer<QQuickSlider> alphaSlider; |
| 92 | |
| 93 | Q_DECLARE_PUBLIC(QQuickColorDialogImplAttached) |
| 94 | }; |
| 95 | |
| 96 | QT_END_NAMESPACE |
| 97 | |
| 98 | #endif // QQUICKCOLORDIALOGIMPL_P_P_H |
| 99 |
