ColourDatabase.h
Go to the documentation of this file.
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
2 
3 /*
4  Sonic Visualiser
5  An audio file viewer and annotation editor.
6  Centre for Digital Music, Queen Mary, University of London.
7  This file copyright 2007 QMUL.
8 
9  This program is free software; you can redistribute it and/or
10  modify it under the terms of the GNU General Public License as
11  published by the Free Software Foundation; either version 2 of the
12  License, or (at your option) any later version. See the file
13  COPYING included with this distribution for more information.
14 */
15 
16 #ifndef SV_COLOUR_DATABASE_H
17 #define SV_COLOUR_DATABASE_H
18 
19 #include <QObject>
20 #include <QString>
21 #include <QColor>
22 #include <QSize>
23 #include <QPixmap>
24 #include <vector>
25 
26 class ColourDatabase : public QObject
27 {
28  Q_OBJECT
29 
30 public:
31  static ColourDatabase *getInstance();
32 
36  int getColourCount() const;
37 
41  QString getColourName(int c) const;
42 
46  QColor getColour(int c) const;
47 
52  QColor getColour(QString name) const;
53 
58  int getColourIndex(QString name) const;
59 
67  int getColourIndex(QColor c) const;
68 
72  bool haveColour(QColor c) const;
73 
78  };
79 
86  int getNearbyColourIndex(QColor c,
88 
96  int addColour(QColor c, QString name);
97 
101  void removeColour(QString);
102 
109  bool useDarkBackground(int c) const;
110 
116  void setUseDarkBackground(int c, bool dark);
117 
124  QColor getContrastingColour(int c) const;
125 
126  // for use in XML export
127  void getStringValues(int index,
128  QString &colourName,
129  QString &colourSpec,
130  QString &darkbg) const;
131 
132  // for use in XML import
133  int putStringValues(QString colourName,
134  QString colourSpec,
135  QString darkbg);
136 
137  // for use by PropertyContainer getPropertyRangeAndValue methods
138  void getColourPropertyRange(int *min, int *max) const;
139 
143  QPixmap getExamplePixmap(int c, QSize size) const;
144 
145 signals:
146  void colourDatabaseChanged();
147 
148 protected:
149  ColourDatabase();
150 
151  struct ColourRec {
152  QColor colour;
153  QString name;
154  bool darkbg;
155  };
156 
157  typedef std::vector<ColourRec> ColourList;
158  ColourList m_colours;
159 
161 };
162 
163 #endif
QString getColourName(int c) const
Return the name of the colour at index c.
QColor getContrastingColour(int c) const
Return a colour that contrasts with the one at index c, according to some simple algorithm.
void colourDatabaseChanged()
int getNearbyColourIndex(QColor c, WithBackgroundMode mode=WithAnyBackground) const
Return the index of the colour in the database that is closest to the given one, by some simple measu...
void removeColour(QString)
Remove the colour with the given name from the database.
QColor getColour(int c) const
Return the colour at index c.
bool useDarkBackground(int c) const
Return true if the colour at index c is marked as using a dark background.
std::vector< ColourRec > ColourList
void getColourPropertyRange(int *min, int *max) const
static ColourDatabase m_instance
int putStringValues(QString colourName, QString colourSpec, QString darkbg)
void setUseDarkBackground(int c, bool dark)
Mark the colour at index c as using a dark background.
int getColourCount() const
Return the number of colours in the database.
int getColourIndex(QString name) const
Return the index of the colour with the given name, if found in the database.
void getStringValues(int index, QString &colourName, QString &colourSpec, QString &darkbg) const
bool haveColour(QColor c) const
Return true if the given colour exists in the database.
int addColour(QColor c, QString name)
Add a colour to the database, with the associated name.
ColourList m_colours
static ColourDatabase * getInstance()
QPixmap getExamplePixmap(int c, QSize size) const
Generate a swatch pixmap illustrating the colour at index c.