#include <ColourDatabase.h>

Inheritance diagram for ColourDatabase:
Inheritance graph
Collaboration diagram for ColourDatabase:
Collaboration graph

Classes

struct  ColourRec
 

Public Types

enum  WithBackgroundMode { WithAnyBackground, WithDarkBackground, WithLightBackground }
 

Signals

void colourDatabaseChanged ()
 

Public Member Functions

int getColourCount () const
 Return the number of colours in the database. More...
 
QString getColourName (int c) const
 Return the name of the colour at index c. More...
 
QColor getColour (int c) const
 Return the colour at index c. More...
 
QColor getColour (QString name) const
 Return the colour with the given name, if found in the database. More...
 
int getColourIndex (QString name) const
 Return the index of the colour with the given name, if found in the database. More...
 
int getColourIndex (QColor c) const
 Return the index of the given colour, if found in the database. More...
 
bool haveColour (QColor c) const
 Return true if the given colour exists in the database. More...
 
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 measure. More...
 
int addColour (QColor c, QString name)
 Add a colour to the database, with the associated name. More...
 
void removeColour (QString)
 Remove the colour with the given name from the database. More...
 
bool useDarkBackground (int c) const
 Return true if the colour at index c is marked as using a dark background. More...
 
void setUseDarkBackground (int c, bool dark)
 Mark the colour at index c as using a dark background. More...
 
QColor getContrastingColour (int c) const
 Return a colour that contrasts with the one at index c, according to some simple algorithm. More...
 
void getStringValues (int index, QString &colourName, QString &colourSpec, QString &darkbg) const
 
int putStringValues (QString colourName, QString colourSpec, QString darkbg)
 
void getColourPropertyRange (int *min, int *max) const
 
QPixmap getExamplePixmap (int c, QSize size) const
 Generate a swatch pixmap illustrating the colour at index c. More...
 

Static Public Member Functions

static ColourDatabasegetInstance ()
 

Protected Types

typedef std::vector< ColourRecColourList
 

Protected Member Functions

 ColourDatabase ()
 

Protected Attributes

ColourList m_colours
 

Static Protected Attributes

static ColourDatabase m_instance
 

Detailed Description

Definition at line 26 of file ColourDatabase.h.

Member Typedef Documentation

typedef std::vector<ColourRec> ColourDatabase::ColourList
protected

Definition at line 157 of file ColourDatabase.h.

Member Enumeration Documentation

Enumerator
WithAnyBackground 
WithDarkBackground 
WithLightBackground 

Definition at line 74 of file ColourDatabase.h.

Constructor & Destructor Documentation

ColourDatabase::ColourDatabase ( )
protected

Definition at line 32 of file ColourDatabase.cpp.

Member Function Documentation

int ColourDatabase::getColourCount ( ) const

Return the number of colours in the database.

Definition at line 37 of file ColourDatabase.cpp.

References m_colours.

Referenced by getColourPropertyRange(), ColourComboBox::rebuild(), and SingleColourLayer::setDefaultColourFor().

QString ColourDatabase::getColourName ( int  c) const

Return the name of the colour at index c.

Definition at line 43 of file ColourDatabase.cpp.

References m_colours.

Referenced by SingleColourLayer::getPropertyValueLabel(), getStringValues(), and ColourComboBox::rebuild().

QColor ColourDatabase::getColour ( int  c) const

Return the colour at index c.

Definition at line 50 of file ColourDatabase.cpp.

References m_colours.

Referenced by SingleColourLayer::getBaseQColor(), getContrastingColour(), getExamplePixmap(), and getStringValues().

QColor ColourDatabase::getColour ( QString  name) const

Return the colour with the given name, if found in the database.

If not found, return Qt::black.

Definition at line 57 of file ColourDatabase.cpp.

References m_colours.

int ColourDatabase::getColourIndex ( QString  name) const
int ColourDatabase::getColourIndex ( QColor  c) const

Return the index of the given colour, if found in the database.

If not found, return -1. Note that it is possible for a colour to appear more than once in the database: names have to be unique in the database, but colours don't. This always returns the first match.

Definition at line 79 of file ColourDatabase.cpp.

References m_colours.

bool ColourDatabase::haveColour ( QColor  c) const

Return true if the given colour exists in the database.

int ColourDatabase::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 measure.

This always returns some valid index, unless the database is empty, in which case it returns -1.

Definition at line 91 of file ColourDatabase.cpp.

References m_colours, WithDarkBackground, and WithLightBackground.

int ColourDatabase::addColour ( QColor  c,
QString  name 
)

Add a colour to the database, with the associated name.

Return the index of the colour in the database. Names are unique within the database: if another colour exists already with the given name, its colour value is replaced with the given one. Colours may appear more than once under different names.

Definition at line 200 of file ColourDatabase.cpp.

References ColourDatabase::ColourRec::colour, colourDatabaseChanged(), ColourDatabase::ColourRec::darkbg, m_colours, and ColourDatabase::ColourRec::name.

Referenced by ColourComboBox::comboActivated(), and putStringValues().

void ColourDatabase::removeColour ( QString  name)

Remove the colour with the given name from the database.

Definition at line 223 of file ColourDatabase.cpp.

References m_colours.

bool ColourDatabase::useDarkBackground ( int  c) const

Return true if the colour at index c is marked as using a dark background.

Such colours are presumably "bright" ones, but all this reports is whether the colour has been marked with setUseDarkBackground, not any intrinsic property of the colour.

Definition at line 183 of file ColourDatabase.cpp.

References m_colours.

Referenced by getExamplePixmap(), getStringValues(), SingleColourLayer::hasLightBackground(), and SingleColourLayer::setDefaultColourFor().

void ColourDatabase::setUseDarkBackground ( int  c,
bool  dark 
)

Mark the colour at index c as using a dark background.

Generally this should be called for "bright" colours.

Definition at line 190 of file ColourDatabase.cpp.

References colourDatabaseChanged(), and m_colours.

Referenced by ColourComboBox::comboActivated(), and putStringValues().

QColor ColourDatabase::getContrastingColour ( int  c) const

Return a colour that contrasts with the one at index c, according to some simple algorithm.

The returned colour is not necessarily in the database; pass it to getNearbyColourIndex if you need one that is.

Definition at line 149 of file ColourDatabase.cpp.

References getColour().

void ColourDatabase::getStringValues ( int  index,
QString &  colourName,
QString &  colourSpec,
QString &  darkbg 
) const
int ColourDatabase::putStringValues ( QString  colourName,
QString  colourSpec,
QString  darkbg 
)
void ColourDatabase::getColourPropertyRange ( int *  min,
int *  max 
) const

Definition at line 273 of file ColourDatabase.cpp.

References getColourCount(), and getInstance().

Referenced by SingleColourLayer::getPropertyRangeAndValue().

QPixmap ColourDatabase::getExamplePixmap ( int  c,
QSize  size 
) const

Generate a swatch pixmap illustrating the colour at index c.

Definition at line 284 of file ColourDatabase.cpp.

References getColour(), and useDarkBackground().

Referenced by SingleColourLayer::getLayerPresentationPixmap(), and ColourComboBox::rebuild().

void ColourDatabase::colourDatabaseChanged ( )
signal

Referenced by addColour(), and setUseDarkBackground().

Member Data Documentation

ColourDatabase ColourDatabase::m_instance
staticprotected

Definition at line 160 of file ColourDatabase.h.

Referenced by getInstance().


The documentation for this class was generated from the following files: