forked from SaschaHeyer/Qt-Code-Editor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcolorwizard.cpp
34 lines (28 loc) · 993 Bytes
/
colorwizard.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
#include "colorwizard.h"
#include <QColor>
#include <QPixmap>
#include <QVector>
QVector<QColor> ColorWizard::highlight(const QColor &bg, const QColor &fg,
int noColors)
{
QVector<QColor> colors;
const int HUE_BASE = (bg.hue() == -1) ? 90 : bg.hue();
int h, s, v;
for (int i = 0; i < noColors; i++)
{
h = int(HUE_BASE + (360.0 / noColors * i)) % 360;
s = 240;
v = int(qMax(bg.value(), fg.value()) * 0.85);
// take care of corner cases
const int M = 35;
if ( (h < bg.hue() + M &&h > bg.hue() - M)
|| (h < fg.hue() + M &&h > fg.hue() - M))
{
h = ((bg.hue() + fg.hue()) / (i + 1)) % 360;
s = ((bg.saturation() + fg.saturation() + 2 * i) / 2) % 256;
v = ((bg.value() + fg.value() + 2 * i) / 2) % 256;
}
colors.append(QColor::fromHsv(h, s, v));
}
return colors;
}