svgui  1.9
ColourDatabase.h
Go to the documentation of this file.
00001 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*-  vi:set ts=8 sts=4 sw=4: */
00002 
00003 /*
00004     Sonic Visualiser
00005     An audio file viewer and annotation editor.
00006     Centre for Digital Music, Queen Mary, University of London.
00007     This file copyright 2007 QMUL.
00008     
00009     This program is free software; you can redistribute it and/or
00010     modify it under the terms of the GNU General Public License as
00011     published by the Free Software Foundation; either version 2 of the
00012     License, or (at your option) any later version.  See the file
00013     COPYING included with this distribution for more information.
00014 */
00015 
00016 #ifndef _COLOUR_DATABASE_H_
00017 #define _COLOUR_DATABASE_H_
00018 
00019 #include <QObject>
00020 #include <QString>
00021 #include <QColor>
00022 #include <QSize>
00023 #include <QPixmap>
00024 #include <vector>
00025 
00026 class ColourDatabase : public QObject
00027 {
00028     Q_OBJECT
00029 
00030 public:
00031     static ColourDatabase *getInstance();
00032 
00033     int getColourCount() const;
00034     QString getColourName(int c) const;
00035     QColor getColour(int c) const;
00036     QColor getColour(QString name) const;
00037     int getColourIndex(QString name) const; // -1 -> not found
00038     int getColourIndex(QColor c) const; // returns first index of possibly many
00039     bool haveColour(QColor c) const;
00040 
00041     bool useDarkBackground(int c) const;
00042     void setUseDarkBackground(int c, bool dark);
00043 
00044     int addColour(QColor, QString); // returns index
00045     void removeColour(QString);
00046 
00047     // returned colour is not necessarily in database
00048     QColor getContrastingColour(int c) const;
00049 
00050     // for use in XML export
00051     void getStringValues(int index,
00052                          QString &colourName,
00053                          QString &colourSpec,
00054                          QString &darkbg) const;
00055 
00056     // for use in XML import
00057     int putStringValues(QString colourName,
00058                         QString colourSpec,
00059                         QString darkbg);
00060 
00061     // for use by PropertyContainer getPropertyRangeAndValue methods
00062     void getColourPropertyRange(int *min, int *max) const;
00063 
00064     QPixmap getExamplePixmap(int index, QSize size) const;
00065     
00066 signals:
00067     void colourDatabaseChanged();
00068 
00069 protected:
00070     ColourDatabase();
00071 
00072     struct ColourRec {
00073         QColor colour;
00074         QString name;
00075         bool darkbg;
00076     };
00077     
00078     typedef std::vector<ColourRec> ColourList;
00079     ColourList m_colours;
00080 
00081     static ColourDatabase m_instance;
00082 };
00083 
00084 #endif