-
Notifications
You must be signed in to change notification settings - Fork 0
/
colormanager.cpp
48 lines (37 loc) · 920 Bytes
/
colormanager.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include "colormanager.h"
#include <QPainter>
QColor ColorManager::getColor(QString element)
{
int index = elements.indexOf(element);
if (index>=0) return colors.at(index);
QColor newColor = getNewColor();
elements.append(element);
colors.append(newColor);
return newColor;
}
QColor ColorManager::getNewColor()
{
QColor color = defColors.at(elements.count()%defColors.count()).toRgb();
if (!rgb)
{
int r = color.red();
int b = color.blue();
color.setRed(b);
color.setBlue(r);
}
return color;
}
bool ColorManager::getRgb() const
{
return rgb;
}
void ColorManager::setRgb(bool value)
{
rgb = value;
}
int getColor(QImage mask, QColor color, int x, int y)
{
return color == Qt::red ? qRed(mask.pixel(x,y)) :
color == Qt::blue ? qBlue(mask.pixel(x,y)) :
qGreen(mask.pixel(x,y));
}