| <large>libXpertMassCore and libXpertMassGui Developer Documentation</large>

- libXpertMassGui
- ColorSelector

# MsXpS::libXpertMassGui::ColorSelector Class

class MsXpS::libXpertMassGui::ColorSelector

The ColorSelector class provides a pool of colors that are associated to a boolean value that is a flag indicating if the colors are in use or not. More...

Header: | `#include <ColorSelector.hpp>`

- List of all members, including inherited members
- ColorSelector is part of Color selector.

## Public Functions

| ColorSelector()
virtual | ~ColorSelector()
void | addColor(const QColor &color)

## Static Public Members

QColor | chooseColor(bool allow_used = false)
QColor | getColor(bool make_random = true)
QColor | getColor(const QColor &color)
QColor | getRandomColor()
bool | isUsedColor(const QColor &color)
void | releaseColor(const QColor &color)

## Static Protected Members

std::vector<MsXpS::libXpertMassGui::ColorUsagePair> | m_usageOfColors

## Detailed Description

Facilities allow for recycling colors when they are not used anymore.

## Member Function Documentation

### ColorSelector::ColorSelector()

Constructs a ColorSelector instance.

### `[virtual noexcept]` ColorSelector::~ColorSelector()

Destructs this ColorSelector instance.

### void ColorSelector::addColor(const QColor &color)

Add color to the vector of colors.

If color is not already in the member vector of colors, it is added to it with a usage flag set to false.

### `[static]` QColor ColorSelector::chooseColor(bool allow_used = false)

Returns a color.

The user is provided with the color-choosing dialog. The choosed color is checked for its presence in the pool of colors.

If the color is found in the pool of colors and allow_used is true, the color is returned. Else, the user is provided a new opportunity to select an unused color. In that case, the new color is added to the pool of colors and the usage flag is set to true.

### `[static]` QColor ColorSelector::getColor(bool make_random = true)

Returns a color.

If there is a color in the pool that is not used, it is returned and its use flag is set to true.

If there is not a single color in the pool that is available for use, a new color needs to be prepared. Either make_random is true and a random color is created, put in the pool with the use flag set to true and returned, or the user is provided with the standard color-choosing dialog.

See also chooseColor().

### `[static]` QColor ColorSelector::getColor(const QColor &color)

Returns a color matching.

color is searched for in the pool of colors. If it is found, it is returned and the usage flag is set to true (it might have been true already). If color is not found in the pool, then it is added to the pool, its usage flag is set to true and that same color is returned.

### `[static]` QColor ColorSelector::getRandomColor()

Returns a new color randomly created.

The color is generated from random H,S,V triplets.

### `[static]` bool ColorSelector::isUsedColor(const QColor &color)

Returns true if color is in the pool of colors and its usage flag is true, otherwise returns false.

### `[static]` void ColorSelector::releaseColor(const QColor &color)

Releases color.

color is searched for in the pool of colors. If it is not found, color is added to the pool with its usage flag set to false. If color is found, its usage flag is set to false (it might have been false already).

## Member Variable Documentation

### std::vector<MsXpS::libXpertMassGui::ColorUsagePair> ColorSelector::m_usageOfColors

Pool of available colors associated to their usage status.

The pool of colors is in the form of a static vector of ColorUsagePair instances.