comparison layer/ColourDatabase.h @ 1445:ad86aa712d11 single-point

Add getNearbyColourIndex to ColourDatabase; tweak getContrastingColour for bright colours; add comments
author Chris Cannam
date Tue, 30 Apr 2019 14:02:03 +0100
parents 05d614f6e46d
children 57a4ee52ad69
comparison
equal deleted inserted replaced
1444:8e6a24110996 1445:ad86aa712d11
28 Q_OBJECT 28 Q_OBJECT
29 29
30 public: 30 public:
31 static ColourDatabase *getInstance(); 31 static ColourDatabase *getInstance();
32 32
33 /**
34 * Return the number of colours in the database.
35 */
33 int getColourCount() const; 36 int getColourCount() const;
37
38 /**
39 * Return the name of the colour at index c.
40 */
34 QString getColourName(int c) const; 41 QString getColourName(int c) const;
42
43 /**
44 * Return the colour at index c.
45 */
35 QColor getColour(int c) const; 46 QColor getColour(int c) const;
47
48 /**
49 * Return the colour with the given name, if found in the
50 * database. If not found, return Qt::black.
51 */
36 QColor getColour(QString name) const; 52 QColor getColour(QString name) const;
37 int getColourIndex(QString name) const; // -1 -> not found 53
38 int getColourIndex(QColor c) const; // returns first index of possibly many 54 /**
55 * Return the index of the colour with the given name, if found in
56 * the database. If not found, return -1.
57 */
58 int getColourIndex(QString name) const;
59
60 /**
61 * Return the index of the given colour, if found in the
62 * database. If not found, return -1. Note that it is possible for
63 * a colour to appear more than once in the database: names have
64 * to be unique in the database, but colours don't. This always
65 * returns the first match.
66 */
67 int getColourIndex(QColor c) const;
68
69 /**
70 * Return true if the given colour exists in the database.
71 */
39 bool haveColour(QColor c) const; 72 bool haveColour(QColor c) const;
40 73
74 /**
75 * Return the index of the colour in the database that is closest
76 * to the given one, by some simplistic measure (Manhattan
77 * distance in RGB space). This always returns some valid index,
78 * unless the database is empty, in which case it returns -1.
79 */
80 int getNearbyColourIndex(QColor c) const;
81
82 /**
83 * Add a colour to the database, with the associated name. Return
84 * the index of the colour in the database. Names are unique
85 * within the database: if another colour exists already with the
86 * given name, its colour value is replaced with the given
87 * one. Colours may appear more than once under different names.
88 */
89 int addColour(QColor c, QString name);
90
91 /**
92 * Remove the colour with the given name from the database.
93 */
94 void removeColour(QString);
95
96 /**
97 * Return true if the colour at index c is marked as using a dark
98 * background. Such colours are presumably "bright" ones, but all
99 * this reports is whether the colour has been marked with
100 * setUseDarkBackground, not any intrinsic property of the colour.
101 */
41 bool useDarkBackground(int c) const; 102 bool useDarkBackground(int c) const;
103
104 /**
105 * Mark the colour at index c as using a dark
106 * background. Generally this should be called for "bright"
107 * colours.
108 */
42 void setUseDarkBackground(int c, bool dark); 109 void setUseDarkBackground(int c, bool dark);
43 110
44 int addColour(QColor, QString); // returns index 111 /**
45 void removeColour(QString); 112 * Return a colour that contrasts with the one at index c,
46 113 * according to some simplistic algorithm. The returned colour is
47 // returned colour is not necessarily in database 114 * not necessarily in the database; pass it to
115 * getNearbyColourIndex if you need one that is.
116 */
48 QColor getContrastingColour(int c) const; 117 QColor getContrastingColour(int c) const;
49 118
50 // for use in XML export 119 // for use in XML export
51 void getStringValues(int index, 120 void getStringValues(int index,
52 QString &colourName, 121 QString &colourName,
59 QString darkbg); 128 QString darkbg);
60 129
61 // for use by PropertyContainer getPropertyRangeAndValue methods 130 // for use by PropertyContainer getPropertyRangeAndValue methods
62 void getColourPropertyRange(int *min, int *max) const; 131 void getColourPropertyRange(int *min, int *max) const;
63 132
64 QPixmap getExamplePixmap(int index, QSize size) const; 133 /**
134 * Generate a swatch pixmap illustrating the colour at index c.
135 */
136 QPixmap getExamplePixmap(int c, QSize size) const;
65 137
66 signals: 138 signals:
67 void colourDatabaseChanged(); 139 void colourDatabaseChanged();
68 140
69 protected: 141 protected: