swift
rgbcolor.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright (C) 2015 swift Project Community / Contributors
2 // SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1
3 
5 
6 #ifndef SWIFT_MISC_RGBCOLOR_H
7 #define SWIFT_MISC_RGBCOLOR_H
8 
9 #include <QColor>
10 #include <QMetaType>
11 #include <QPixmap>
12 #include <QString>
13 
14 #include "misc/metaclass.h"
15 #include "misc/propertyindexref.h"
16 #include "misc/swiftmiscexport.h"
17 #include "misc/valueobject.h"
18 
20 
21 namespace swift::misc
22 {
26  class SWIFT_MISC_EXPORT CRgbColor : public CValueObject<CRgbColor>
27  {
28  public:
31  {
32  IndexRed = swift::misc::CPropertyIndexRef::GlobalIndexCRgbColor,
33  IndexGreen,
34  IndexBlue,
35  IndexWebHex
36  };
37 
39  CRgbColor() = default;
40 
42  CRgbColor(const QString &color, bool isName = false);
43 
45  CRgbColor(int r, int g, int b);
46 
48  CRgbColor(const QColor &color);
49 
51  QColor toQColor() const;
52 
54  bool setQColor(const QColor &color);
55 
57  int red() const;
58 
60  double normalizedRed() const;
61 
63  QString redHex(int digits = 2) const;
64 
66  int green() const;
67 
69  double normalizedGreen() const;
70 
72  QString greenHex(int digits = 2) const;
73 
75  int blue() const;
76 
78  double normalizedBlue() const;
79 
81  QString blueHex(int digits = 2) const;
82 
84  QString hex(bool withHash = false) const;
85 
87  int packed() const;
88 
90  static CRgbColor fromPacked(int rgb);
91 
93  void setByString(const QString &color, bool isName = false);
94 
96  bool isValid() const;
97 
100  double colorDistance(const CRgbColor &color) const;
101 
103  void setInvalid();
104 
106  CIcons::IconIndex toIcon() const;
107 
109  QPixmap toPixmap() const;
110 
112  QString convertToQString(bool i18n = false) const;
113 
115  QVariant propertyByIndex(swift::misc::CPropertyIndexRef index) const;
116 
118  void setPropertyByIndex(swift::misc::CPropertyIndexRef index, const QVariant &variant);
119 
121  int comparePropertyByIndex(CPropertyIndexRef index, const CRgbColor &compareValue) const;
122 
124  int compare(const CRgbColor &color) const;
125 
126  private:
127  int m_r = -1;
128  int m_g = -1;
129  int m_b = -1;
130 
132  double colorRange() const;
133 
134  static QString intToHex(int h, int digits = 2);
135 
137  CRgbColor,
138  SWIFT_METAMEMBER(r),
139  SWIFT_METAMEMBER(g),
140  SWIFT_METAMEMBER(b));
141  };
142 } // namespace swift::misc
143 
144 Q_DECLARE_METATYPE(swift::misc::CRgbColor)
145 
146 #endif // SWIFT_MISC_RGBCOLOR_H
IconIndex
Index for each icon, allows to send them via DBus, efficiently store them, etc.
Definition: icons.h:32
Non-owning reference to a CPropertyIndex with a subset of its features.
CRgbColor()=default
Constructor.
Mix of the most commonly used mixin classes.
Definition: valueobject.h:114
ColumnIndex
Base class enums.
Definition: mixinindex.h:44
#define SWIFT_METAMEMBER(MEMBER,...)
Macro to define an element within a metaclass.
Definition: metaclass.h:73
#define SWIFT_METACLASS(CLASS,...)
Macro to define a nested metaclass that describes the attributes of its enclosing class.
Definition: metaclass.h:53
Free functions in swift::misc.
SWIFT_MISC_EXPORT QString intToHex(int value, int digits=2)
Int to hex value.
#define SWIFT_MISC_EXPORT
Export a class or function from the library.
#define SWIFT_DECLARE_VALUEOBJECT_MIXINS(Namespace, Class)
Explicit template declaration of mixins for a CValueObject subclass to be placed near the top of the ...
Definition: valueobject.h:65