1 | /* |
2 | This file is part of the KDE libraries |
3 | SPDX-FileCopyrightText: 1997 Martin Jones <mjones@kde.org> |
4 | SPDX-FileCopyrightText: 2007 David Jarvie <djarvie@kde.org> |
5 | |
6 | SPDX-License-Identifier: LGPL-2.0-or-later |
7 | */ |
8 | //----------------------------------------------------------------------------- |
9 | // KDE color selection combo box |
10 | |
11 | // layout management added Oct 1997 by Mario Weilguni |
12 | // <mweilguni@sime.com> |
13 | |
14 | #ifndef KCOLORCOMBO_H |
15 | #define KCOLORCOMBO_H |
16 | |
17 | #include <QComboBox> |
18 | #include <QList> |
19 | |
20 | #include <kwidgetsaddons_export.h> |
21 | |
22 | #include <memory> |
23 | |
24 | /*! |
25 | * \class KColorCombo |
26 | * \inmodule KWidgetsAddons |
27 | * |
28 | * \brief Combobox for colors. |
29 | * |
30 | * The combobox provides some preset colors to be selected, and an entry to |
31 | * select a custom color using a color dialog. |
32 | * |
33 | * \image kcolorcombo.png "KColorCombo Widget" |
34 | */ |
35 | class KWIDGETSADDONS_EXPORT KColorCombo : public QComboBox |
36 | { |
37 | Q_OBJECT |
38 | |
39 | /*! |
40 | * \property KColorCombo::color |
41 | */ |
42 | Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY activated USER true) |
43 | |
44 | /*! |
45 | * \property KColorCombo::colors |
46 | */ |
47 | Q_PROPERTY(QList<QColor> colors READ colors WRITE setColors) |
48 | |
49 | public: |
50 | /*! |
51 | * Constructs a color combo box. |
52 | */ |
53 | explicit KColorCombo(QWidget *parent = nullptr); |
54 | ~KColorCombo() override; |
55 | |
56 | /*! |
57 | * Selects the color \a col. |
58 | */ |
59 | void setColor(const QColor &col); |
60 | |
61 | /*! |
62 | * Returns the currently selected color. |
63 | */ |
64 | QColor color() const; |
65 | |
66 | /*! |
67 | * Find whether the currently selected color is a custom color selected |
68 | * using a color dialog. |
69 | */ |
70 | bool isCustomColor() const; |
71 | |
72 | /*! |
73 | * Set a custom list of colors to choose from, in place of the standard |
74 | * list. |
75 | * |
76 | * \a colors list of colors. If empty, the selection list reverts to |
77 | * the standard list. |
78 | */ |
79 | void setColors(const QList<QColor> &colors); |
80 | |
81 | /*! |
82 | * Return the list of colors available for selection. |
83 | */ |
84 | QList<QColor> colors() const; |
85 | |
86 | /*! |
87 | * Clear the color list and don't show it, till the next setColor() call |
88 | */ |
89 | void showEmptyList(); |
90 | |
91 | Q_SIGNALS: |
92 | /*! |
93 | * Emitted when a new color box has been selected. |
94 | */ |
95 | void activated(const QColor &col); |
96 | /*! |
97 | * Emitted when a new item has been highlighted. |
98 | */ |
99 | void highlighted(const QColor &col); |
100 | |
101 | protected: |
102 | void paintEvent(QPaintEvent *event) override; |
103 | |
104 | private: |
105 | friend class KColorComboPrivate; |
106 | std::unique_ptr<class KColorComboPrivate> const d; |
107 | |
108 | Q_DISABLE_COPY(KColorCombo) |
109 | }; |
110 | |
111 | #endif // KCOLORCOMBO_H |
112 | |