| 1 | // Copyright (C) 2016 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 QCOLORDIALOG_H |
| 5 | #define QCOLORDIALOG_H |
| 6 | |
| 7 | #include <QtWidgets/qtwidgetsglobal.h> |
| 8 | |
| 9 | #include <QtWidgets/qdialog.h> |
| 10 | |
| 11 | QT_REQUIRE_CONFIG(colordialog); |
| 12 | |
| 13 | QT_BEGIN_NAMESPACE |
| 14 | |
| 15 | class QColorDialogPrivate; |
| 16 | |
| 17 | class Q_WIDGETS_EXPORT QColorDialog : public QDialog |
| 18 | { |
| 19 | Q_OBJECT |
| 20 | Q_DECLARE_PRIVATE(QColorDialog) |
| 21 | Q_PROPERTY(QColor currentColor READ currentColor WRITE setCurrentColor |
| 22 | NOTIFY currentColorChanged) |
| 23 | Q_PROPERTY(ColorDialogOptions options READ options WRITE setOptions) |
| 24 | |
| 25 | public: |
| 26 | enum ColorDialogOption { |
| 27 | ShowAlphaChannel = 0x00000001, |
| 28 | NoButtons = 0x00000002, |
| 29 | DontUseNativeDialog = 0x00000004, |
| 30 | NoEyeDropperButton = 0x00000008, |
| 31 | }; |
| 32 | Q_ENUM(ColorDialogOption) |
| 33 | |
| 34 | Q_DECLARE_FLAGS(ColorDialogOptions, ColorDialogOption) |
| 35 | |
| 36 | explicit QColorDialog(QWidget *parent = nullptr); |
| 37 | explicit QColorDialog(const QColor &initial, QWidget *parent = nullptr); |
| 38 | ~QColorDialog(); |
| 39 | |
| 40 | void setCurrentColor(const QColor &color); |
| 41 | QColor currentColor() const; |
| 42 | |
| 43 | QColor selectedColor() const; |
| 44 | |
| 45 | void setOption(ColorDialogOption option, bool on = true); |
| 46 | bool testOption(ColorDialogOption option) const; |
| 47 | void setOptions(ColorDialogOptions options); |
| 48 | ColorDialogOptions options() const; |
| 49 | |
| 50 | using QDialog::open; |
| 51 | void open(QObject *receiver, const char *member); |
| 52 | |
| 53 | void setVisible(bool visible) override; |
| 54 | |
| 55 | static QColor getColor(const QColor &initial = Qt::white, |
| 56 | QWidget *parent = nullptr, |
| 57 | const QString &title = QString(), |
| 58 | ColorDialogOptions options = ColorDialogOptions()); |
| 59 | |
| 60 | static int customCount(); |
| 61 | static QColor customColor(int index); |
| 62 | static void setCustomColor(int index, QColor color); |
| 63 | static QColor standardColor(int index); |
| 64 | static void setStandardColor(int index, QColor color); |
| 65 | |
| 66 | Q_SIGNALS: |
| 67 | void currentColorChanged(const QColor &color); |
| 68 | void colorSelected(const QColor &color); |
| 69 | |
| 70 | protected: |
| 71 | void changeEvent(QEvent *event) override; |
| 72 | void done(int result) override; |
| 73 | |
| 74 | private: |
| 75 | Q_DISABLE_COPY(QColorDialog) |
| 76 | }; |
| 77 | |
| 78 | Q_DECLARE_OPERATORS_FOR_FLAGS(QColorDialog::ColorDialogOptions) |
| 79 | |
| 80 | QT_END_NAMESPACE |
| 81 | |
| 82 | #endif // QCOLORDIALOG_H |
| 83 | |