Changeset View
Standalone View
src/kcolorcombo.h
Show All 22 Lines | |||||
23 | // layout management added Oct 1997 by Mario Weilguni | 23 | // layout management added Oct 1997 by Mario Weilguni | ||
24 | // <mweilguni@sime.com> | 24 | // <mweilguni@sime.com> | ||
25 | 25 | | |||
26 | #ifndef KCOLORCOMBO_H | 26 | #ifndef KCOLORCOMBO_H | ||
27 | #define KCOLORCOMBO_H | 27 | #define KCOLORCOMBO_H | ||
28 | 28 | | |||
29 | #include <QComboBox> | 29 | #include <QComboBox> | ||
30 | #include <QList> | 30 | #include <QList> | ||
31 | #include <QPair> | ||||
31 | 32 | | |||
32 | #include <kwidgetsaddons_export.h> | 33 | #include <kwidgetsaddons_export.h> | ||
33 | 34 | | |||
34 | class KColorComboPrivate; | 35 | class KColorComboPrivate; | ||
35 | 36 | | |||
36 | /** | 37 | /** | ||
37 | * @class KColorCombo kcolorcombo.h KColorCombo | 38 | * @class KColorCombo kcolorcombo.h KColorCombo | ||
38 | * | 39 | * | ||
39 | * Combobox for colors. | 40 | * Combobox for colors. | ||
40 | * | 41 | * | ||
41 | * The combobox provides some preset colors to be selected, and an entry to | 42 | * The combobox provides some preset colors to be selected, and an entry to | ||
42 | * select a custom color using a color dialog. | 43 | * select a custom color using a color dialog. | ||
43 | * | 44 | * | ||
44 | * \image html kcolorcombo.png "KColorCombo Widget" | 45 | * \image html kcolorcombo.png "KColorCombo Widget" | ||
45 | */ | 46 | */ | ||
46 | class KWIDGETSADDONS_EXPORT KColorCombo : public QComboBox | 47 | class KWIDGETSADDONS_EXPORT KColorCombo : public QComboBox | ||
47 | { | 48 | { | ||
48 | Q_OBJECT | 49 | Q_OBJECT | ||
49 | Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY activated USER true) | 50 | Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY activated USER true) | ||
50 | Q_PROPERTY(QList<QColor> colors READ colors WRITE setColors) | 51 | Q_PROPERTY(QList<QColor> colors READ colors WRITE setColors) | ||
52 | Q_PROPERTY(QList<QPair<QString, QColor>> namedColors READ namedColors WRITE setNamedColors) | ||||
patrickelectric: This is just a suggestion and not something that's necessary to do, but maybe it could help to… | |||||
Good suggestion, I will be thinking how to do it as this would alter the use of lists within the code. araujoluis: Good suggestion, I will be thinking how to do it as this would alter the use of lists within… | |||||
Is a simple tuple list really the best way to represent colours? Knowing what most designers like, a better data structure would encapsulate named groups of optionally named colours. cblack: Is a simple tuple list really the best way to represent colours? Knowing what most designers… | |||||
I believe that yes, each color has its own representation, and the way it was proposed, if the color is not available, the name used is the hex value of the color. araujoluis: I believe that yes, each color has its own representation, and the way it was proposed, if the… | |||||
51 | 53 | | |||
52 | public: | 54 | public: | ||
53 | /** | 55 | /** | ||
54 | * Constructs a color combo box. | 56 | * Constructs a color combo box. | ||
55 | */ | 57 | */ | ||
56 | explicit KColorCombo(QWidget *parent = nullptr); | 58 | explicit KColorCombo(QWidget *parent = nullptr); | ||
57 | ~KColorCombo() override; | 59 | ~KColorCombo() override; | ||
58 | 60 | | |||
61 | /** ColorList used in named colors list */ | ||||
The comment still says "struct". Maybe clarify that this list is actually used as a map. (I guess since mapping would happen in both directions, using a QMap isn't useful?) cfeck: The comment still says "struct". Maybe clarify that this list is actually used as a map.
(I… | |||||
araujoluis: Done! | |||||
Using QMap would cause me a problem, consider the following code block: for (int i = 0; i <STANDARD_PALETTE_SIZE; ++ i) { if (standardColor (i) == color) { q-> setCurrentIndex (i + 1); I need variable i for iteration with the call q-> setCurrentIndex (i + 1) and this method would not be available with QMap. araujoluis: Using QMap would cause me a problem, consider the following code block:
```
for (int i = 0; i… | |||||
62 | using ColorList = QList<QPair<QString, QColor>>; | ||||
broulik: Do we really want to leak this `struct` into public API? | |||||
broulik try a solution in several ways, but it looks like this was the most convenient one found so far. araujoluis: broulik try a solution in several ways, but it looks like this was the most convenient one… | |||||
tcanabrava: QPair<QString, QColor> - no need for a struct.
| |||||
araujoluis: Done! | |||||
63 | | ||||
59 | /** | 64 | /** | ||
60 | * Selects the color @p col. | 65 | * Selects the color @p col. | ||
61 | */ | 66 | */ | ||
62 | void setColor(const QColor &col); | 67 | void setColor(const QColor &col); | ||
63 | 68 | | |||
64 | /** | 69 | /** | ||
65 | * Returns the currently selected color. | 70 | * Returns the currently selected color. | ||
66 | **/ | 71 | **/ | ||
Show All 9 Lines | |||||
76 | * Set a custom list of colors to choose from, in place of the standard | 81 | * Set a custom list of colors to choose from, in place of the standard | ||
77 | * list. | 82 | * list. | ||
78 | * @param colors list of colors. If empty, the selection list reverts to | 83 | * @param colors list of colors. If empty, the selection list reverts to | ||
79 | * the standard list. | 84 | * the standard list. | ||
80 | **/ | 85 | **/ | ||
81 | void setColors(const QList<QColor> &colors); | 86 | void setColors(const QList<QColor> &colors); | ||
82 | 87 | | |||
83 | /** | 88 | /** | ||
89 | * Set a custom list of named colors to choose from, in place of the | ||||
90 | * standard list. | ||||
91 | * @param colors list os named colors. If empty, the selection list | ||||
cfeck: typos: of; selection | |||||
araujoluis: Done! | |||||
92 | * reverts to the standard list. | ||||
93 | **/ | ||||
94 | void setNamedColors(const ColorList &colors); | ||||
95 | | ||||
96 | /** | ||||
97 | * Inserts a named color at a specific position in the standard list. | ||||
cfeck: Sentence misses a full stop. | |||||
98 | * @param index position in the list | ||||
99 | * @param namedColor name and color | ||||
100 | **/ | ||||
101 | void insertNamedColor(int index, const QPair<QString, QColor> &namedColor); | ||||
102 | | ||||
103 | /** | ||||
84 | * Return the list of colors available for selection. | 104 | * Return the list of colors available for selection. | ||
85 | * @return list of colors | 105 | * @return list of colors | ||
86 | **/ | 106 | **/ | ||
87 | QList<QColor> colors() const; | 107 | QList<QColor> colors() const; | ||
88 | 108 | | |||
89 | /** | 109 | /** | ||
110 | * Return the list of named colors available for selection. | ||||
cfeck: typo: selection | |||||
araujoluis: Done! | |||||
111 | * If list of named color is empty, returns named colors in hex format. | ||||
This sentence is confusing. I guess you wanted to write "if there are no named colors, the returned list is empty." (to clarify that it won't return the standard list). cfeck: This sentence is confusing. I guess you wanted to write "if there are no named colors, the… | |||||
araujoluis: Done! | |||||
112 | * @return list of named colors | ||||
113 | **/ | ||||
114 | QList<QPair<QString, QColor>> namedColors() const; | ||||
115 | | ||||
116 | /** | ||||
90 | * Clear the color list and don't show it, till the next setColor() call | 117 | * Clear the color list and don't show it, till the next setColor() call | ||
91 | **/ | 118 | **/ | ||
92 | void showEmptyList(); | 119 | void showEmptyList(); | ||
93 | 120 | | |||
94 | Q_SIGNALS: | 121 | Q_SIGNALS: | ||
95 | /** | 122 | /** | ||
96 | * Emitted when a new color box has been selected. | 123 | * Emitted when a new color box has been selected. | ||
97 | */ | 124 | */ | ||
Show All 20 Lines |
This is just a suggestion and not something that's necessary to do, but maybe it could help to create a simple class to replace QPair: