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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
|
/*
* Copyright (c) 2007, Aconex. All Rights Reserved.
* Copyright (c) 2013, Red Hat, Inc.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*/
#include "colorscheme.h"
#include "main.h"
ColorScheme::ColorScheme()
{
my.isModified = false;
my.name = QString::null;
}
bool ColorScheme::lookupScheme(QString name)
{
for (int i = 0; i < globalSettings.colorSchemes.size(); i++)
if (name == globalSettings.colorSchemes[i].name())
return true;
return false;
}
ColorScheme *ColorScheme::findScheme(QString name)
{
for (int i = 0; i < globalSettings.colorSchemes.size(); i++)
if (name == globalSettings.colorSchemes[i].name())
return &globalSettings.colorSchemes[i];
return NULL;
}
bool ColorScheme::removeScheme(QString name)
{
for (int i = 0; i < globalSettings.colorSchemes.size(); i++)
if (name == globalSettings.colorSchemes[i].name()) {
globalSettings.colorSchemes.removeAt(i);
return true;
}
return false;
}
static inline int hexval(float f)
{
return ((int)(0.5 + f*256) < 256 ? (int)(0.5 + f*256) : 256);
}
QColor ColorScheme::colorSpec(QString name)
{
QColor color;
QString rgbi = name;
if (rgbi.left(5) != "rgbi:")
color.setNamedColor(name);
else {
float fr, fg, fb;
if (sscanf((const char *)rgbi.toAscii(), "rgbi:%f/%f/%f", &fr, &fg, &fb) == 3)
color.setRgb(hexval(fr), hexval(fg), hexval(fb));
// else return color as-is, i.e. invalid.
}
return color;
}
void ColorScheme::clear()
{
my.colors.clear();
my.colorNames.clear();
}
void ColorScheme::setColorNames(QStringList colorNames)
{
my.colorNames = colorNames;
for (int i = 0; i < colorNames.size(); i++)
my.colors << QColor(colorNames.at(i));
}
void ColorScheme::addColor(QColor color)
{
my.colors.append(color);
my.colorNames.append(color.name());
}
void ColorScheme::addColor(QString name)
{
my.colors.append(colorSpec(name));
my.colorNames.append(name);
}
|