10 #include <QStringBuilder>
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; }
147 if (*
this == color) {
return 0.0; }
153 return (rd * rd + bd * bd + gd * gd) / 3.0;
193 case IndexBlue: m_b = variant.
toInt();
break;
194 case IndexRed: m_r = variant.
toInt();
break;
195 case IndexGreen: m_g = variant.
toInt();
break;
207 case IndexBlue:
return Compare::compare(m_b, compareValue.m_b);
208 case IndexRed:
return Compare::compare(m_r, compareValue.m_r);
209 case IndexGreen:
return Compare::compare(m_g, compareValue.m_g);
210 case IndexWebHex:
return this->
compare(compareValue);
211 default: Q_ASSERT_X(
false, Q_FUNC_INFO,
"Missing compare");
break;
218 int c = Compare::compare(m_r, color.m_r);
219 if (c != 0) {
return c; }
220 c = Compare::compare(m_g, color.m_g);
221 if (c != 0) {
return c; }
222 return Compare::compare(m_b, color.m_b);
225 double CRgbColor::colorRange()
const
227 if (!this->
isValid()) {
return 255; }
228 if (m_b < 256 && m_g < 256 && m_r < 256) {
return 255; }
229 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.
QColor fromString(QAnyStringView name)
bool isValid() const const
void drawRect(const QRect &rectangle)
void setBackground(const QBrush &brush)
void setBrush(QColor color)
bool isEmpty() const const
bool startsWith(QChar c, Qt::CaseSensitivity cs) const const
QString trimmed() const const
QVariant fromValue(T &&value)
int toInt(bool *ok) const const
QString toString() const const
#define SWIFT_DEFINE_VALUEOBJECT_MIXINS(Namespace, Class)
Explicit template definition of mixins for a CValueObject subclass.