2 * Copyright (c) 2007, Aconex. All Rights Reserved.
3 * Copyright (c) 2013, Red Hat, Inc.
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2 of the License, or (at your
8 * option) any later version.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 #include "colorscheme.h"
19 ColorScheme::ColorScheme()
21 my
.isModified
= false;
22 my
.name
= QString::null
;
25 bool ColorScheme::lookupScheme(QString name
)
27 for (int i
= 0; i
< globalSettings
.colorSchemes
.size(); i
++)
28 if (name
== globalSettings
.colorSchemes
[i
].name())
33 ColorScheme
*ColorScheme::findScheme(QString name
)
35 for (int i
= 0; i
< globalSettings
.colorSchemes
.size(); i
++)
36 if (name
== globalSettings
.colorSchemes
[i
].name())
37 return &globalSettings
.colorSchemes
[i
];
41 bool ColorScheme::removeScheme(QString name
)
43 for (int i
= 0; i
< globalSettings
.colorSchemes
.size(); i
++)
44 if (name
== globalSettings
.colorSchemes
[i
].name()) {
45 globalSettings
.colorSchemes
.removeAt(i
);
51 static inline int hexval(float f
)
53 return ((int)(0.5 + f
*256) < 256 ? (int)(0.5 + f
*256) : 256);
56 QColor
ColorScheme::colorSpec(QString name
)
61 if (rgbi
.left(5) != "rgbi:")
62 color
.setNamedColor(name
);
65 if (sscanf((const char *)rgbi
.toLatin1(), "rgbi:%f/%f/%f", &fr
, &fg
, &fb
) == 3)
66 color
.setRgb(hexval(fr
), hexval(fg
), hexval(fb
));
67 // else return color as-is, i.e. invalid.
72 void ColorScheme::clear()
75 my
.colorNames
.clear();
78 void ColorScheme::setColorNames(QStringList colorNames
)
80 my
.colorNames
= colorNames
;
81 for (int i
= 0; i
< colorNames
.size(); i
++)
82 my
.colors
<< QColor(colorNames
.at(i
));
85 void ColorScheme::addColor(QColor color
)
87 my
.colors
.append(color
);
88 my
.colorNames
.append(color
.name());
91 void ColorScheme::addColor(QString name
)
93 my
.colors
.append(colorSpec(name
));
94 my
.colorNames
.append(name
);