Chris@376
|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
|
Chris@376
|
2
|
Chris@376
|
3 /*
|
Chris@376
|
4 Sonic Visualiser
|
Chris@376
|
5 An audio file viewer and annotation editor.
|
Chris@376
|
6 Centre for Digital Music, Queen Mary, University of London.
|
Chris@376
|
7 This file copyright 2007 QMUL.
|
Chris@376
|
8
|
Chris@376
|
9 This program is free software; you can redistribute it and/or
|
Chris@376
|
10 modify it under the terms of the GNU General Public License as
|
Chris@376
|
11 published by the Free Software Foundation; either version 2 of the
|
Chris@376
|
12 License, or (at your option) any later version. See the file
|
Chris@376
|
13 COPYING included with this distribution for more information.
|
Chris@376
|
14 */
|
Chris@376
|
15
|
Chris@1407
|
16 #ifndef SV_COLOUR_DATABASE_H
|
Chris@1407
|
17 #define SV_COLOUR_DATABASE_H
|
Chris@376
|
18
|
Chris@376
|
19 #include <QObject>
|
Chris@376
|
20 #include <QString>
|
Chris@376
|
21 #include <QColor>
|
Chris@376
|
22 #include <QSize>
|
Chris@376
|
23 #include <QPixmap>
|
Chris@376
|
24 #include <vector>
|
Chris@376
|
25
|
Chris@376
|
26 class ColourDatabase : public QObject
|
Chris@376
|
27 {
|
Chris@376
|
28 Q_OBJECT
|
Chris@376
|
29
|
Chris@376
|
30 public:
|
Chris@376
|
31 static ColourDatabase *getInstance();
|
Chris@376
|
32
|
Chris@1445
|
33 /**
|
Chris@1445
|
34 * Return the number of colours in the database.
|
Chris@1445
|
35 */
|
Chris@376
|
36 int getColourCount() const;
|
Chris@1445
|
37
|
Chris@1445
|
38 /**
|
Chris@1445
|
39 * Return the name of the colour at index c.
|
Chris@1445
|
40 */
|
Chris@376
|
41 QString getColourName(int c) const;
|
Chris@1445
|
42
|
Chris@1445
|
43 /**
|
Chris@1445
|
44 * Return the colour at index c.
|
Chris@1445
|
45 */
|
Chris@376
|
46 QColor getColour(int c) const;
|
Chris@1445
|
47
|
Chris@1445
|
48 /**
|
Chris@1445
|
49 * Return the colour with the given name, if found in the
|
Chris@1445
|
50 * database. If not found, return Qt::black.
|
Chris@1445
|
51 */
|
Chris@376
|
52 QColor getColour(QString name) const;
|
Chris@1445
|
53
|
Chris@1445
|
54 /**
|
Chris@1445
|
55 * Return the index of the colour with the given name, if found in
|
Chris@1445
|
56 * the database. If not found, return -1.
|
Chris@1445
|
57 */
|
Chris@1445
|
58 int getColourIndex(QString name) const;
|
Chris@1445
|
59
|
Chris@1445
|
60 /**
|
Chris@1445
|
61 * Return the index of the given colour, if found in the
|
Chris@1445
|
62 * database. If not found, return -1. Note that it is possible for
|
Chris@1445
|
63 * a colour to appear more than once in the database: names have
|
Chris@1445
|
64 * to be unique in the database, but colours don't. This always
|
Chris@1445
|
65 * returns the first match.
|
Chris@1445
|
66 */
|
Chris@1445
|
67 int getColourIndex(QColor c) const;
|
Chris@1445
|
68
|
Chris@1445
|
69 /**
|
Chris@1445
|
70 * Return true if the given colour exists in the database.
|
Chris@1445
|
71 */
|
Chris@376
|
72 bool haveColour(QColor c) const;
|
Chris@376
|
73
|
Chris@1578
|
74 enum WithBackgroundMode {
|
Chris@1578
|
75 WithAnyBackground,
|
Chris@1578
|
76 WithDarkBackground,
|
Chris@1578
|
77 WithLightBackground
|
Chris@1578
|
78 };
|
Chris@1578
|
79
|
Chris@1445
|
80 /**
|
Chris@1445
|
81 * Return the index of the colour in the database that is closest
|
Chris@1578
|
82 * to the given one, by some simple measure. This always returns
|
Chris@1578
|
83 * some valid index, unless the database is empty, in which case
|
Chris@1578
|
84 * it returns -1.
|
Chris@1445
|
85 */
|
Chris@1578
|
86 int getNearbyColourIndex(QColor c,
|
Chris@1578
|
87 WithBackgroundMode mode = WithAnyBackground) const;
|
Chris@1445
|
88
|
Chris@1445
|
89 /**
|
Chris@1445
|
90 * Add a colour to the database, with the associated name. Return
|
Chris@1445
|
91 * the index of the colour in the database. Names are unique
|
Chris@1445
|
92 * within the database: if another colour exists already with the
|
Chris@1445
|
93 * given name, its colour value is replaced with the given
|
Chris@1445
|
94 * one. Colours may appear more than once under different names.
|
Chris@1445
|
95 */
|
Chris@1445
|
96 int addColour(QColor c, QString name);
|
Chris@1445
|
97
|
Chris@1445
|
98 /**
|
Chris@1445
|
99 * Remove the colour with the given name from the database.
|
Chris@1445
|
100 */
|
Chris@1445
|
101 void removeColour(QString);
|
Chris@1445
|
102
|
Chris@1445
|
103 /**
|
Chris@1445
|
104 * Return true if the colour at index c is marked as using a dark
|
Chris@1445
|
105 * background. Such colours are presumably "bright" ones, but all
|
Chris@1445
|
106 * this reports is whether the colour has been marked with
|
Chris@1445
|
107 * setUseDarkBackground, not any intrinsic property of the colour.
|
Chris@1445
|
108 */
|
Chris@376
|
109 bool useDarkBackground(int c) const;
|
Chris@1445
|
110
|
Chris@1445
|
111 /**
|
Chris@1445
|
112 * Mark the colour at index c as using a dark
|
Chris@1445
|
113 * background. Generally this should be called for "bright"
|
Chris@1445
|
114 * colours.
|
Chris@1445
|
115 */
|
Chris@376
|
116 void setUseDarkBackground(int c, bool dark);
|
Chris@376
|
117
|
Chris@1445
|
118 /**
|
Chris@1445
|
119 * Return a colour that contrasts with the one at index c,
|
Chris@1578
|
120 * according to some simple algorithm. The returned colour is not
|
Chris@1578
|
121 * necessarily in the database; pass it to getNearbyColourIndex if
|
Chris@1578
|
122 * you need one that is.
|
Chris@1445
|
123 */
|
Chris@376
|
124 QColor getContrastingColour(int c) const;
|
Chris@376
|
125
|
Chris@376
|
126 // for use in XML export
|
Chris@376
|
127 void getStringValues(int index,
|
Chris@376
|
128 QString &colourName,
|
Chris@376
|
129 QString &colourSpec,
|
Chris@376
|
130 QString &darkbg) const;
|
Chris@376
|
131
|
Chris@376
|
132 // for use in XML import
|
Chris@376
|
133 int putStringValues(QString colourName,
|
Chris@376
|
134 QString colourSpec,
|
Chris@376
|
135 QString darkbg);
|
Chris@376
|
136
|
Chris@376
|
137 // for use by PropertyContainer getPropertyRangeAndValue methods
|
Chris@376
|
138 void getColourPropertyRange(int *min, int *max) const;
|
Chris@376
|
139
|
Chris@1445
|
140 /**
|
Chris@1445
|
141 * Generate a swatch pixmap illustrating the colour at index c.
|
Chris@1445
|
142 */
|
Chris@1445
|
143 QPixmap getExamplePixmap(int c, QSize size) const;
|
Chris@376
|
144
|
Chris@376
|
145 signals:
|
Chris@376
|
146 void colourDatabaseChanged();
|
Chris@376
|
147
|
Chris@376
|
148 protected:
|
Chris@376
|
149 ColourDatabase();
|
Chris@376
|
150
|
Chris@376
|
151 struct ColourRec {
|
Chris@376
|
152 QColor colour;
|
Chris@376
|
153 QString name;
|
Chris@376
|
154 bool darkbg;
|
Chris@376
|
155 };
|
Chris@376
|
156
|
Chris@376
|
157 typedef std::vector<ColourRec> ColourList;
|
Chris@376
|
158 ColourList m_colours;
|
Chris@376
|
159
|
Chris@376
|
160 static ColourDatabase m_instance;
|
Chris@376
|
161 };
|
Chris@376
|
162
|
Chris@376
|
163 #endif
|