10 #include <QStringBuilder>
32 QPixmap pixmap(QSize(16, 16));
34 p.setBackground(QBrush(this->
toQColor()));
36 p.drawRect(0, 0, 16, 16);
48 return CIcons::StandardIconError16;
74 double c =
red() * 1.0;
75 return c / colorRange();
84 double c =
green() * 1.0;
85 return c / colorRange();
94 double c =
blue() * 1.0;
95 return c / colorRange();
104 return withHash ? u
'#' % h : h;
110 return static_cast<int>(
toQColor().rgb() & qRgba(255, 255, 255, 0));
117 if (color.isEmpty()) {
return; }
120 const QColor q(color);
127 const QString c(color.trimmed());
130 if (c.startsWith(
"#"))
135 q.setNamedColor(
"#" + c);
146 if (*
this == color) {
return 0.0; }
152 return (rd * rd + bd * bd + gd * gd) / 3.0;
170 if (index.
isMyself()) {
return QVariant::fromValue(*
this); }
174 case IndexBlue:
return QVariant::fromValue(
blue());
175 case IndexRed:
return QVariant::fromValue(
red());
176 case IndexGreen:
return QVariant::fromValue(
green());
177 case IndexWebHex:
return QVariant::fromValue(
hex());
192 case IndexBlue: m_b = variant.toInt();
break;
193 case IndexRed: m_r = variant.toInt();
break;
194 case IndexGreen: m_g = variant.toInt();
break;
195 case IndexWebHex: this->
setByString(variant.toString());
break;
206 case IndexBlue:
return Compare::compare(m_b, compareValue.m_b);
207 case IndexRed:
return Compare::compare(m_r, compareValue.m_r);
208 case IndexGreen:
return Compare::compare(m_g, compareValue.m_g);
209 case IndexWebHex:
return this->
compare(compareValue);
210 default: Q_ASSERT_X(
false, Q_FUNC_INFO,
"Missing compare");
break;
217 int c = Compare::compare(m_r, color.m_r);
218 if (c != 0) {
return c; }
219 c = Compare::compare(m_g, color.m_g);
220 if (c != 0) {
return c; }
221 return Compare::compare(m_b, color.m_b);
224 double CRgbColor::colorRange()
const
226 if (!this->
isValid()) {
return 255; }
227 if (m_b < 256 && m_g < 256 && m_r < 256) {
return 255; }
228 if (m_b < 4096 && m_g < 4096 && m_r < 4096) {
return 4095; }
IconIndex
Index for each icon, allows to send them via DBus, efficiently store them, etc.
Non-owning reference to a CPropertyIndex with a subset of its features.
CastType frontCasted() const
First element casted to given type, usually the PropertIndex enum.
bool isMyself() const
Myself index, used with nesting.
QString blueHex(int digits=2) const
Blue as hex.
double normalizedBlue() const
Blue 0..1.
QVariant propertyByIndex(swift::misc::CPropertyIndexRef index) const
Property by index.
QString hex(bool withHash=false) const
Hex value.
void setInvalid()
Mark as invalid.
QPixmap toPixmap() const
Icon as pixmap.
QColor toQColor() const
To QColor.
bool setQColor(const QColor &color)
Set by QColor.
QString convertToQString(bool i18n=false) const
Cast as QString.
int packed() const
Value packed in 24 bit integer.
static CRgbColor fromPacked(int rgb)
Construct from packed 24 bit integer value.
double normalizedRed() const
Red 0..1.
double colorDistance(const CRgbColor &color) const
Color distance [0..1] http://stackoverflow.com/questions/4754506/color-similarity-distance-in-rgba-co...
void setPropertyByIndex(swift::misc::CPropertyIndexRef index, const QVariant &variant)
Set property by index.
void setByString(const QString &color, bool isName=false)
Hex or color name.
int comparePropertyByIndex(CPropertyIndexRef index, const CRgbColor &compareValue) const
Compare for index.
double normalizedGreen() const
Green 0..1.
QString redHex(int digits=2) const
Red as hex.
CRgbColor()=default
Constructor.
int compare(const CRgbColor &color) const
Compare with other color.
QString greenHex(int digits=2) const
Green as hex.
CIcons::IconIndex toIcon() const
Representing icon.
bool isValid() const
Valid?
ColumnIndex
Base class enums.
void setPropertyByIndex(CPropertyIndexRef index, const QVariant &variant)
Set property by index.
QVariant propertyByIndex(CPropertyIndexRef index) const
Property by index.
Free functions in swift::misc.
SWIFT_MISC_EXPORT QString intToHex(int value, int digits=2)
Int to hex value.
#define SWIFT_DEFINE_VALUEOBJECT_MIXINS(Namespace, Class)
Explicit template definition of mixins for a CValueObject subclass.